OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Platform-specific code for POSIX goes here. This is not a platform on its | 5 // Platform-specific code for POSIX goes here. This is not a platform on its |
6 // own, but contains the parts which are the same across the POSIX platforms | 6 // own, but contains the parts which are the same across the POSIX platforms |
7 // Linux, MacOS, FreeBSD, OpenBSD, NetBSD and QNX. | 7 // Linux, MacOS, FreeBSD, OpenBSD, NetBSD and QNX. |
8 | 8 |
9 #include <errno.h> | 9 #include <errno.h> |
10 #include <limits.h> | 10 #include <limits.h> |
11 #include <pthread.h> | 11 #include <pthread.h> |
12 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) | 12 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
13 #include <pthread_np.h> // for pthread_set_name_np | 13 #include <pthread_np.h> // for pthread_set_name_np |
14 #endif | 14 #endif |
15 #include <sched.h> // for sched_yield | 15 #include <sched.h> // for sched_yield |
16 #include <time.h> | 16 #include <time.h> |
17 #include <unistd.h> | 17 #include <unistd.h> |
18 | 18 |
19 #include <sys/mman.h> | 19 #include <sys/mman.h> |
20 #include <sys/resource.h> | 20 #include <sys/resource.h> |
21 #include <sys/stat.h> | 21 #include <sys/stat.h> |
22 #if !defined(__pnacl__) | |
23 #include <sys/syscall.h> | |
24 #endif | |
25 #include <sys/time.h> | 22 #include <sys/time.h> |
26 #include <sys/types.h> | 23 #include <sys/types.h> |
27 #if defined(__linux__) && !defined(__pnacl__) | |
28 #include <sys/prctl.h> // NOLINT, for prctl | |
29 #endif | |
30 #if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || \ | 24 #if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || \ |
31 defined(__NetBSD__) || defined(__OpenBSD__) | 25 defined(__NetBSD__) || defined(__OpenBSD__) |
32 #include <sys/sysctl.h> // NOLINT, for sysctl | 26 #include <sys/sysctl.h> // NOLINT, for sysctl |
33 #endif | 27 #endif |
34 | 28 |
35 #undef MAP_TYPE | 29 #undef MAP_TYPE |
36 | 30 |
37 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) | 31 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) |
38 #define LOG_TAG "v8" | 32 #define LOG_TAG "v8" |
39 #include <android/log.h> // NOLINT | 33 #include <android/log.h> // NOLINT |
40 #endif | 34 #endif |
41 | 35 |
42 #include <cmath> | 36 #include <cmath> |
43 #include <cstdlib> | 37 #include <cstdlib> |
44 | 38 |
45 #include "src/base/lazy-instance.h" | 39 #include "src/base/lazy-instance.h" |
46 #include "src/base/macros.h" | 40 #include "src/base/macros.h" |
47 #include "src/base/platform/platform.h" | 41 #include "src/base/platform/platform.h" |
48 #include "src/base/platform/time.h" | 42 #include "src/base/platform/time.h" |
49 #include "src/base/utils/random-number-generator.h" | 43 #include "src/base/utils/random-number-generator.h" |
50 | 44 |
51 #ifdef V8_FAST_TLS_SUPPORTED | 45 #ifdef V8_FAST_TLS_SUPPORTED |
52 #include "src/base/atomicops.h" | 46 #include "src/base/atomicops.h" |
53 #endif | 47 #endif |
54 | 48 |
55 #if V8_OS_MACOSX | 49 #if V8_OS_MACOSX |
56 #include <dlfcn.h> | 50 #include <dlfcn.h> |
57 #endif | 51 #endif |
58 | 52 |
| 53 #if V8_OS_LINUX |
| 54 #include <sys/prctl.h> // NOLINT, for prctl |
| 55 #endif |
| 56 |
| 57 #if !V8_OS_NACL |
| 58 #include <sys/syscall.h> |
| 59 #endif |
| 60 |
59 namespace v8 { | 61 namespace v8 { |
60 namespace base { | 62 namespace base { |
61 | 63 |
62 namespace { | 64 namespace { |
63 | 65 |
64 // 0 is never a valid thread id. | 66 // 0 is never a valid thread id. |
65 const pthread_t kNoThread = (pthread_t) 0; | 67 const pthread_t kNoThread = (pthread_t) 0; |
66 | 68 |
67 bool g_hard_abort = false; | 69 bool g_hard_abort = false; |
68 | 70 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 void OS::DebugBreak() { | 218 void OS::DebugBreak() { |
217 #if V8_HOST_ARCH_ARM | 219 #if V8_HOST_ARCH_ARM |
218 asm("bkpt 0"); | 220 asm("bkpt 0"); |
219 #elif V8_HOST_ARCH_ARM64 | 221 #elif V8_HOST_ARCH_ARM64 |
220 asm("brk 0"); | 222 asm("brk 0"); |
221 #elif V8_HOST_ARCH_MIPS | 223 #elif V8_HOST_ARCH_MIPS |
222 asm("break"); | 224 asm("break"); |
223 #elif V8_HOST_ARCH_MIPS64 | 225 #elif V8_HOST_ARCH_MIPS64 |
224 asm("break"); | 226 asm("break"); |
225 #elif V8_HOST_ARCH_IA32 | 227 #elif V8_HOST_ARCH_IA32 |
226 #if defined(__native_client__) | 228 #if V8_OS_NACL |
227 asm("hlt"); | 229 asm("hlt"); |
228 #else | 230 #else |
229 asm("int $3"); | 231 asm("int $3"); |
230 #endif // __native_client__ | 232 #endif // V8_OS_NACL |
231 #elif V8_HOST_ARCH_X64 | 233 #elif V8_HOST_ARCH_X64 |
232 asm("int $3"); | 234 asm("int $3"); |
233 #else | 235 #else |
234 #error Unsupported host architecture. | 236 #error Unsupported host architecture. |
235 #endif | 237 #endif |
236 } | 238 } |
237 | 239 |
238 | 240 |
239 // ---------------------------------------------------------------------------- | 241 // ---------------------------------------------------------------------------- |
240 // Math functions | 242 // Math functions |
(...skipping 20 matching lines...) Expand all Loading... |
261 return 0; | 263 return 0; |
262 #endif | 264 #endif |
263 } | 265 } |
264 | 266 |
265 | 267 |
266 // ---------------------------------------------------------------------------- | 268 // ---------------------------------------------------------------------------- |
267 // POSIX date/time support. | 269 // POSIX date/time support. |
268 // | 270 // |
269 | 271 |
270 int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) { | 272 int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) { |
| 273 #if V8_OS_NACL |
| 274 // Optionally used in Logger::ResourceEvent. |
| 275 return -1; |
| 276 #else |
271 struct rusage usage; | 277 struct rusage usage; |
272 | 278 |
273 if (getrusage(RUSAGE_SELF, &usage) < 0) return -1; | 279 if (getrusage(RUSAGE_SELF, &usage) < 0) return -1; |
274 *secs = usage.ru_utime.tv_sec; | 280 *secs = usage.ru_utime.tv_sec; |
275 *usecs = usage.ru_utime.tv_usec; | 281 *usecs = usage.ru_utime.tv_usec; |
276 return 0; | 282 return 0; |
| 283 #endif |
277 } | 284 } |
278 | 285 |
279 | 286 |
280 double OS::TimeCurrentMillis() { | 287 double OS::TimeCurrentMillis() { |
281 return Time::Now().ToJsTime(); | 288 return Time::Now().ToJsTime(); |
282 } | 289 } |
283 | 290 |
284 | 291 |
285 class TimezoneCache {}; | 292 class TimezoneCache {}; |
286 | 293 |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 | 669 |
663 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 670 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { |
664 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); | 671 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); |
665 int result = pthread_setspecific(pthread_key, value); | 672 int result = pthread_setspecific(pthread_key, value); |
666 DCHECK_EQ(0, result); | 673 DCHECK_EQ(0, result); |
667 USE(result); | 674 USE(result); |
668 } | 675 } |
669 | 676 |
670 | 677 |
671 } } // namespace v8::base | 678 } } // namespace v8::base |
OLD | NEW |