OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 15 matching lines...) Expand all Loading... |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Platform specific code for POSIX goes here. This is not a platform on its | 28 // Platform specific code for POSIX goes here. This is not a platform on its |
29 // own but contains the parts which are the same across POSIX platforms Linux, | 29 // own but contains the parts which are the same across POSIX platforms Linux, |
30 // Mac OS, FreeBSD and OpenBSD. | 30 // Mac OS, FreeBSD and OpenBSD. |
31 | 31 |
32 #include "platform-posix.h" | 32 #include "platform-posix.h" |
33 | 33 |
34 #include <dlfcn.h> | 34 #include <dlfcn.h> |
35 #include <pthread.h> | 35 #include <pthread.h> |
36 #if V8_OS_FREEBSD || V8_OS_OPENBSD | 36 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
37 #include <pthread_np.h> // for pthread_set_name_np | 37 #include <pthread_np.h> // for pthread_set_name_np |
38 #endif | 38 #endif |
39 #include <sched.h> // for sched_yield | 39 #include <sched.h> // for sched_yield |
40 #include <unistd.h> | 40 #include <unistd.h> |
41 #include <errno.h> | 41 #include <errno.h> |
42 #include <time.h> | 42 #include <time.h> |
43 | 43 |
44 #include <sys/mman.h> | 44 #include <sys/mman.h> |
45 #include <sys/socket.h> | 45 #include <sys/socket.h> |
46 #include <sys/resource.h> | 46 #include <sys/resource.h> |
47 #include <sys/time.h> | 47 #include <sys/time.h> |
48 #include <sys/types.h> | 48 #include <sys/types.h> |
49 #include <sys/stat.h> | 49 #include <sys/stat.h> |
50 #if V8_OS_LINUX | 50 #if defined(__linux__) |
51 #include <sys/prctl.h> // for prctl | 51 #include <sys/prctl.h> // for prctl |
52 #elif V8_OS_BSD4 | 52 #endif |
| 53 #if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || \ |
| 54 defined(__NetBSD__) || defined(__OpenBSD__) |
53 #include <sys/sysctl.h> // for sysctl | 55 #include <sys/sysctl.h> // for sysctl |
54 #endif | 56 #endif |
55 | 57 |
56 #include <arpa/inet.h> | 58 #include <arpa/inet.h> |
57 #include <netinet/in.h> | 59 #include <netinet/in.h> |
58 #include <netdb.h> | 60 #include <netdb.h> |
59 | 61 |
60 #undef MAP_TYPE | 62 #undef MAP_TYPE |
61 | 63 |
62 #if V8_OS_ANDROID && !defined(V8_ANDROID_LOG_STDOUT) | 64 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) |
63 #define LOG_TAG "v8" | 65 #define LOG_TAG "v8" |
64 #include <android/log.h> | 66 #include <android/log.h> |
65 #endif | 67 #endif |
66 | 68 |
67 #include "v8.h" | 69 #include "v8.h" |
68 | 70 |
69 #include "codegen.h" | 71 #include "codegen.h" |
70 #include "platform.h" | 72 #include "platform.h" |
71 | 73 |
72 namespace v8 { | 74 namespace v8 { |
73 namespace internal { | 75 namespace internal { |
74 | 76 |
75 // 0 is never a valid thread id. | 77 // 0 is never a valid thread id. |
76 static const pthread_t kNoThread = (pthread_t) 0; | 78 static const pthread_t kNoThread = (pthread_t) 0; |
77 | 79 |
78 | 80 |
79 uint64_t OS::CpuFeaturesImpliedByPlatform() { | 81 uint64_t OS::CpuFeaturesImpliedByPlatform() { |
80 #if V8_OS_DARWIN | 82 #if defined(__APPLE__) |
81 // Mac OS X requires all these to install so we can assume they are present. | 83 // Mac OS X requires all these to install so we can assume they are present. |
82 // These constants are defined by the CPUid instructions. | 84 // These constants are defined by the CPUid instructions. |
83 const uint64_t one = 1; | 85 const uint64_t one = 1; |
84 return (one << SSE2) | (one << CMOV) | (one << RDTSC) | (one << CPUID); | 86 return (one << SSE2) | (one << CMOV) | (one << RDTSC) | (one << CPUID); |
85 #else | 87 #else |
86 return 0; // Nothing special about the other systems. | 88 return 0; // Nothing special about the other systems. |
87 #endif | 89 #endif |
88 } | 90 } |
89 | 91 |
90 | 92 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 void OS::Free(void* address, const size_t size) { | 128 void OS::Free(void* address, const size_t size) { |
127 // TODO(1240712): munmap has a return value which is ignored here. | 129 // TODO(1240712): munmap has a return value which is ignored here. |
128 int result = munmap(address, size); | 130 int result = munmap(address, size); |
129 USE(result); | 131 USE(result); |
130 ASSERT(result == 0); | 132 ASSERT(result == 0); |
131 } | 133 } |
132 | 134 |
133 | 135 |
134 // Get rid of writable permission on code allocations. | 136 // Get rid of writable permission on code allocations. |
135 void OS::ProtectCode(void* address, const size_t size) { | 137 void OS::ProtectCode(void* address, const size_t size) { |
136 #if V8_OS_CYGWIN | 138 #if defined(__CYGWIN__) |
137 DWORD old_protect; | 139 DWORD old_protect; |
138 VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect); | 140 VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect); |
139 #elif V8_OS_NACL | 141 #elif defined(__native_client__) |
140 // The Native Client port of V8 uses an interpreter, so | 142 // The Native Client port of V8 uses an interpreter, so |
141 // code pages don't need PROT_EXEC. | 143 // code pages don't need PROT_EXEC. |
142 mprotect(address, size, PROT_READ); | 144 mprotect(address, size, PROT_READ); |
143 #else | 145 #else |
144 mprotect(address, size, PROT_READ | PROT_EXEC); | 146 mprotect(address, size, PROT_READ | PROT_EXEC); |
145 #endif | 147 #endif |
146 } | 148 } |
147 | 149 |
148 | 150 |
149 // Create guard pages. | 151 // Create guard pages. |
150 void OS::Guard(void* address, const size_t size) { | 152 void OS::Guard(void* address, const size_t size) { |
151 #if V8_OS_CYGWIN | 153 #if defined(__CYGWIN__) |
152 DWORD oldprotect; | 154 DWORD oldprotect; |
153 VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect); | 155 VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect); |
154 #else | 156 #else |
155 mprotect(address, size, PROT_NONE); | 157 mprotect(address, size, PROT_NONE); |
156 #endif | 158 #endif |
157 } | 159 } |
158 | 160 |
159 | 161 |
160 void* OS::GetRandomMmapAddr() { | 162 void* OS::GetRandomMmapAddr() { |
161 #if V8_OS_NACL | 163 #if defined(__native_client__) |
162 // TODO(bradchen): restore randomization once Native Client gets | 164 // TODO(bradchen): restore randomization once Native Client gets |
163 // smarter about using mmap address hints. | 165 // smarter about using mmap address hints. |
164 // See http://code.google.com/p/nativeclient/issues/3341 | 166 // See http://code.google.com/p/nativeclient/issues/3341 |
165 return NULL; | 167 return NULL; |
166 #endif | 168 #endif |
167 Isolate* isolate = Isolate::UncheckedCurrent(); | 169 Isolate* isolate = Isolate::UncheckedCurrent(); |
168 // Note that the current isolate isn't set up in a call path via | 170 // Note that the current isolate isn't set up in a call path via |
169 // CpuFeatures::Probe. We don't care about randomization in this case because | 171 // CpuFeatures::Probe. We don't care about randomization in this case because |
170 // the code page is immediately freed. | 172 // the code page is immediately freed. |
171 if (isolate != NULL) { | 173 if (isolate != NULL) { |
172 #if V8_HOST_ARCH_64_BIT | 174 #if V8_TARGET_ARCH_X64 |
173 uint64_t rnd1 = V8::RandomPrivate(isolate); | 175 uint64_t rnd1 = V8::RandomPrivate(isolate); |
174 uint64_t rnd2 = V8::RandomPrivate(isolate); | 176 uint64_t rnd2 = V8::RandomPrivate(isolate); |
175 uint64_t raw_addr = (rnd1 << 32) ^ rnd2; | 177 uint64_t raw_addr = (rnd1 << 32) ^ rnd2; |
176 // Currently available CPUs have 48 bits of virtual addressing. Truncate | 178 // Currently available CPUs have 48 bits of virtual addressing. Truncate |
177 // the hint address to 46 bits to give the kernel a fighting chance of | 179 // the hint address to 46 bits to give the kernel a fighting chance of |
178 // fulfilling our placement request. | 180 // fulfilling our placement request. |
179 raw_addr &= V8_UINT64_C(0x3ffffffff000); | 181 raw_addr &= V8_UINT64_C(0x3ffffffff000); |
180 #else | 182 #else |
181 uint32_t raw_addr = V8::RandomPrivate(isolate); | 183 uint32_t raw_addr = V8::RandomPrivate(isolate); |
182 | 184 |
183 raw_addr &= 0x3ffff000; | 185 raw_addr &= 0x3ffff000; |
184 | 186 |
185 #if V8_OS_SOLARIS | 187 # ifdef __sun |
186 // For our Solaris/illumos mmap hint, we pick a random address in the bottom | 188 // For our Solaris/illumos mmap hint, we pick a random address in the bottom |
187 // half of the top half of the address space (that is, the third quarter). | 189 // half of the top half of the address space (that is, the third quarter). |
188 // Because we do not MAP_FIXED, this will be treated only as a hint -- the | 190 // Because we do not MAP_FIXED, this will be treated only as a hint -- the |
189 // system will not fail to mmap() because something else happens to already | 191 // system will not fail to mmap() because something else happens to already |
190 // be mapped at our random address. We deliberately set the hint high enough | 192 // be mapped at our random address. We deliberately set the hint high enough |
191 // to get well above the system's break (that is, the heap); Solaris and | 193 // to get well above the system's break (that is, the heap); Solaris and |
192 // illumos will try the hint and if that fails allocate as if there were | 194 // illumos will try the hint and if that fails allocate as if there were |
193 // no hint at all. The high hint prevents the break from getting hemmed in | 195 // no hint at all. The high hint prevents the break from getting hemmed in |
194 // at low values, ceding half of the address space to the system heap. | 196 // at low values, ceding half of the address space to the system heap. |
195 raw_addr += 0x80000000; | 197 raw_addr += 0x80000000; |
196 #else | 198 # else |
197 // The range 0x20000000 - 0x60000000 is relatively unpopulated across a | 199 // The range 0x20000000 - 0x60000000 is relatively unpopulated across a |
198 // variety of ASLR modes (PAE kernel, NX compat mode, etc) and on macos | 200 // variety of ASLR modes (PAE kernel, NX compat mode, etc) and on macos |
199 // 10.6 and 10.7. | 201 // 10.6 and 10.7. |
200 raw_addr += 0x20000000; | 202 raw_addr += 0x20000000; |
201 #endif // V8_OS_SOLARIS | 203 # endif |
202 #endif // V8_HOST_ARCH_64_BIT | 204 #endif |
203 return reinterpret_cast<void*>(raw_addr); | 205 return reinterpret_cast<void*>(raw_addr); |
204 } | 206 } |
205 return NULL; | 207 return NULL; |
206 } | 208 } |
207 | 209 |
208 | 210 |
209 size_t OS::AllocateAlignment() { | 211 size_t OS::AllocateAlignment() { |
210 return getpagesize(); | 212 return getpagesize(); |
211 } | 213 } |
212 | 214 |
(...skipping 17 matching lines...) Expand all Loading... |
230 abort(); | 232 abort(); |
231 } | 233 } |
232 | 234 |
233 | 235 |
234 void OS::DebugBreak() { | 236 void OS::DebugBreak() { |
235 #if V8_HOST_ARCH_ARM | 237 #if V8_HOST_ARCH_ARM |
236 asm("bkpt 0"); | 238 asm("bkpt 0"); |
237 #elif V8_HOST_ARCH_MIPS | 239 #elif V8_HOST_ARCH_MIPS |
238 asm("break"); | 240 asm("break"); |
239 #elif V8_HOST_ARCH_IA32 | 241 #elif V8_HOST_ARCH_IA32 |
240 #if V8_OS_NACL | 242 #if defined(__native_client__) |
241 asm("hlt"); | 243 asm("hlt"); |
242 #else | 244 #else |
243 asm("int $3"); | 245 asm("int $3"); |
244 #endif // V8_OS_NACL | 246 #endif // __native_client__ |
245 #elif V8_HOST_ARCH_X64 | 247 #elif V8_HOST_ARCH_X64 |
246 asm("int $3"); | 248 asm("int $3"); |
247 #else | 249 #else |
248 #error Unsupported host architecture. | 250 #error Unsupported host architecture. |
249 #endif | 251 #endif |
250 } | 252 } |
251 | 253 |
252 | 254 |
253 // ---------------------------------------------------------------------------- | 255 // ---------------------------------------------------------------------------- |
254 // Math functions | 256 // Math functions |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 | 379 |
378 void OS::Print(const char* format, ...) { | 380 void OS::Print(const char* format, ...) { |
379 va_list args; | 381 va_list args; |
380 va_start(args, format); | 382 va_start(args, format); |
381 VPrint(format, args); | 383 VPrint(format, args); |
382 va_end(args); | 384 va_end(args); |
383 } | 385 } |
384 | 386 |
385 | 387 |
386 void OS::VPrint(const char* format, va_list args) { | 388 void OS::VPrint(const char* format, va_list args) { |
387 #if V8_OS_ANDROID && !defined(V8_ANDROID_LOG_STDOUT) | 389 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) |
388 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args); | 390 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args); |
389 #else | 391 #else |
390 vprintf(format, args); | 392 vprintf(format, args); |
391 #endif | 393 #endif |
392 } | 394 } |
393 | 395 |
394 | 396 |
395 void OS::FPrint(FILE* out, const char* format, ...) { | 397 void OS::FPrint(FILE* out, const char* format, ...) { |
396 va_list args; | 398 va_list args; |
397 va_start(args, format); | 399 va_start(args, format); |
398 VFPrint(out, format, args); | 400 VFPrint(out, format, args); |
399 va_end(args); | 401 va_end(args); |
400 } | 402 } |
401 | 403 |
402 | 404 |
403 void OS::VFPrint(FILE* out, const char* format, va_list args) { | 405 void OS::VFPrint(FILE* out, const char* format, va_list args) { |
404 #if V8_OS_ANDROID && !defined(V8_ANDROID_LOG_STDOUT) | 406 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) |
405 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args); | 407 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args); |
406 #else | 408 #else |
407 vfprintf(out, format, args); | 409 vfprintf(out, format, args); |
408 #endif | 410 #endif |
409 } | 411 } |
410 | 412 |
411 | 413 |
412 void OS::PrintError(const char* format, ...) { | 414 void OS::PrintError(const char* format, ...) { |
413 va_list args; | 415 va_list args; |
414 va_start(args, format); | 416 va_start(args, format); |
415 VPrintError(format, args); | 417 VPrintError(format, args); |
416 va_end(args); | 418 va_end(args); |
417 } | 419 } |
418 | 420 |
419 | 421 |
420 void OS::VPrintError(const char* format, va_list args) { | 422 void OS::VPrintError(const char* format, va_list args) { |
421 #if V8_OS_ANDROID && !defined(V8_ANDROID_LOG_STDOUT) | 423 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) |
422 __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, args); | 424 __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, args); |
423 #else | 425 #else |
424 vfprintf(stderr, format, args); | 426 vfprintf(stderr, format, args); |
425 #endif | 427 #endif |
426 } | 428 } |
427 | 429 |
428 | 430 |
429 int OS::SNPrintF(Vector<char> str, const char* format, ...) { | 431 int OS::SNPrintF(Vector<char> str, const char* format, ...) { |
430 va_list args; | 432 va_list args; |
431 va_start(args, format); | 433 va_start(args, format); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 OS::MemMoveFunction CreateMemMoveFunction(); | 465 OS::MemMoveFunction CreateMemMoveFunction(); |
464 | 466 |
465 // Copy memory area. No restrictions. | 467 // Copy memory area. No restrictions. |
466 void OS::MemMove(void* dest, const void* src, size_t size) { | 468 void OS::MemMove(void* dest, const void* src, size_t size) { |
467 if (size == 0) return; | 469 if (size == 0) return; |
468 // Note: here we rely on dependent reads being ordered. This is true | 470 // Note: here we rely on dependent reads being ordered. This is true |
469 // on all architectures we currently support. | 471 // on all architectures we currently support. |
470 (*memmove_function)(dest, src, size); | 472 (*memmove_function)(dest, src, size); |
471 } | 473 } |
472 | 474 |
473 #elif V8_HOST_ARCH_ARM | 475 #elif defined(V8_HOST_ARCH_ARM) |
474 void OS::MemCopyUint16Uint8Wrapper(uint16_t* dest, | 476 void OS::MemCopyUint16Uint8Wrapper(uint16_t* dest, |
475 const uint8_t* src, | 477 const uint8_t* src, |
476 size_t chars) { | 478 size_t chars) { |
477 uint16_t *limit = dest + chars; | 479 uint16_t *limit = dest + chars; |
478 while (dest < limit) { | 480 while (dest < limit) { |
479 *dest++ = static_cast<uint16_t>(*src++); | 481 *dest++ = static_cast<uint16_t>(*src++); |
480 } | 482 } |
481 } | 483 } |
482 | 484 |
483 | 485 |
484 OS::MemCopyUint8Function OS::memcopy_uint8_function = &OS::MemCopyUint8Wrapper; | 486 OS::MemCopyUint8Function OS::memcopy_uint8_function = &OS::MemCopyUint8Wrapper; |
485 OS::MemCopyUint16Uint8Function OS::memcopy_uint16_uint8_function = | 487 OS::MemCopyUint16Uint8Function OS::memcopy_uint16_uint8_function = |
486 &OS::MemCopyUint16Uint8Wrapper; | 488 &OS::MemCopyUint16Uint8Wrapper; |
487 // Defined in codegen-arm.cc. | 489 // Defined in codegen-arm.cc. |
488 OS::MemCopyUint8Function CreateMemCopyUint8Function( | 490 OS::MemCopyUint8Function CreateMemCopyUint8Function( |
489 OS::MemCopyUint8Function stub); | 491 OS::MemCopyUint8Function stub); |
490 OS::MemCopyUint16Uint8Function CreateMemCopyUint16Uint8Function( | 492 OS::MemCopyUint16Uint8Function CreateMemCopyUint16Uint8Function( |
491 OS::MemCopyUint16Uint8Function stub); | 493 OS::MemCopyUint16Uint8Function stub); |
492 #endif | 494 #endif |
493 | 495 |
494 | 496 |
495 void OS::PostSetUp() { | 497 void OS::PostSetUp() { |
496 #if V8_TARGET_ARCH_IA32 | 498 #if V8_TARGET_ARCH_IA32 |
497 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction(); | 499 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction(); |
498 if (generated_memmove != NULL) { | 500 if (generated_memmove != NULL) { |
499 memmove_function = generated_memmove; | 501 memmove_function = generated_memmove; |
500 } | 502 } |
501 #elif V8_HOST_ARCH_ARM | 503 #elif defined(V8_HOST_ARCH_ARM) |
502 OS::memcopy_uint8_function = | 504 OS::memcopy_uint8_function = |
503 CreateMemCopyUint8Function(&OS::MemCopyUint8Wrapper); | 505 CreateMemCopyUint8Function(&OS::MemCopyUint8Wrapper); |
504 OS::memcopy_uint16_uint8_function = | 506 OS::memcopy_uint16_uint8_function = |
505 CreateMemCopyUint16Uint8Function(&OS::MemCopyUint16Uint8Wrapper); | 507 CreateMemCopyUint16Uint8Function(&OS::MemCopyUint16Uint8Wrapper); |
506 #endif | 508 #endif |
507 init_fast_sin_function(); | 509 init_fast_sin_function(); |
508 init_fast_cos_function(); | 510 init_fast_cos_function(); |
509 init_fast_tan_function(); | 511 init_fast_tan_function(); |
510 init_fast_log_function(); | 512 init_fast_log_function(); |
511 // fast_exp is initialized lazily. | 513 // fast_exp is initialized lazily. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 set_name(options.name()); | 546 set_name(options.name()); |
545 } | 547 } |
546 | 548 |
547 | 549 |
548 Thread::~Thread() { | 550 Thread::~Thread() { |
549 delete data_; | 551 delete data_; |
550 } | 552 } |
551 | 553 |
552 | 554 |
553 static void SetThreadName(const char* name) { | 555 static void SetThreadName(const char* name) { |
554 #if V8_OS_FREEBSD || V8_OS_OPENBSD | 556 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
555 pthread_set_name_np(pthread_self(), name); | 557 pthread_set_name_np(pthread_self(), name); |
556 #elif V8_OS_NETBSD | 558 #elif defined(__NetBSD__) |
557 STATIC_ASSERT(Thread::kMaxThreadNameLength <= PTHREAD_MAX_NAMELEN_NP); | 559 STATIC_ASSERT(Thread::kMaxThreadNameLength <= PTHREAD_MAX_NAMELEN_NP); |
558 pthread_setname_np(pthread_self(), "%s", name); | 560 pthread_setname_np(pthread_self(), "%s", name); |
559 #elif V8_OS_DARWIN | 561 #elif defined(__APPLE__) |
560 // pthread_setname_np is only available in 10.6 or later, so test | 562 // pthread_setname_np is only available in 10.6 or later, so test |
561 // for it at runtime. | 563 // for it at runtime. |
562 int (*dynamic_pthread_setname_np)(const char*); | 564 int (*dynamic_pthread_setname_np)(const char*); |
563 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = | 565 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = |
564 dlsym(RTLD_DEFAULT, "pthread_setname_np"); | 566 dlsym(RTLD_DEFAULT, "pthread_setname_np"); |
565 if (dynamic_pthread_setname_np == NULL) | 567 if (dynamic_pthread_setname_np == NULL) |
566 return; | 568 return; |
567 | 569 |
568 // Mac OS X does not expose the length limit of the name, so hardcode it. | 570 // Mac OS X does not expose the length limit of the name, so hardcode it. |
569 static const int kMaxNameLength = 63; | 571 static const int kMaxNameLength = 63; |
(...skipping 26 matching lines...) Expand all Loading... |
596 } | 598 } |
597 | 599 |
598 | 600 |
599 void Thread::Start() { | 601 void Thread::Start() { |
600 int result; | 602 int result; |
601 pthread_attr_t attr; | 603 pthread_attr_t attr; |
602 memset(&attr, 0, sizeof(attr)); | 604 memset(&attr, 0, sizeof(attr)); |
603 result = pthread_attr_init(&attr); | 605 result = pthread_attr_init(&attr); |
604 ASSERT_EQ(0, result); | 606 ASSERT_EQ(0, result); |
605 // Native client uses default stack size. | 607 // Native client uses default stack size. |
606 #if !V8_OS_NACL | 608 #if !defined(__native_client__) |
607 if (stack_size_ > 0) { | 609 if (stack_size_ > 0) { |
608 result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); | 610 result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); |
609 ASSERT_EQ(0, result); | 611 ASSERT_EQ(0, result); |
610 } | 612 } |
611 #endif | 613 #endif |
612 result = pthread_create(&data_->thread_, &attr, ThreadEntry, this); | 614 result = pthread_create(&data_->thread_, &attr, ThreadEntry, this); |
613 ASSERT_EQ(0, result); | 615 ASSERT_EQ(0, result); |
614 result = pthread_attr_destroy(&attr); | 616 result = pthread_attr_destroy(&attr); |
615 ASSERT_EQ(0, result); | 617 ASSERT_EQ(0, result); |
616 ASSERT(data_->thread_ != kNoThread); | 618 ASSERT(data_->thread_ != kNoThread); |
617 USE(result); | 619 USE(result); |
618 } | 620 } |
619 | 621 |
620 | 622 |
621 void Thread::Join() { | 623 void Thread::Join() { |
622 pthread_join(data_->thread_, NULL); | 624 pthread_join(data_->thread_, NULL); |
623 } | 625 } |
624 | 626 |
625 | 627 |
626 void Thread::YieldCPU() { | 628 void Thread::YieldCPU() { |
627 int result = sched_yield(); | 629 int result = sched_yield(); |
628 ASSERT_EQ(0, result); | 630 ASSERT_EQ(0, result); |
629 USE(result); | 631 USE(result); |
630 } | 632 } |
631 | 633 |
632 | 634 |
633 static Thread::LocalStorageKey PthreadKeyToLocalKey(pthread_key_t pthread_key) { | 635 static Thread::LocalStorageKey PthreadKeyToLocalKey(pthread_key_t pthread_key) { |
634 #if V8_OS_CYGWIN | 636 #if defined(__CYGWIN__) |
635 // We need to cast pthread_key_t to Thread::LocalStorageKey in two steps | 637 // We need to cast pthread_key_t to Thread::LocalStorageKey in two steps |
636 // because pthread_key_t is a pointer type on Cygwin. This will probably not | 638 // because pthread_key_t is a pointer type on Cygwin. This will probably not |
637 // work on 64-bit platforms, but Cygwin doesn't support 64-bit anyway. | 639 // work on 64-bit platforms, but Cygwin doesn't support 64-bit anyway. |
638 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t)); | 640 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t)); |
639 intptr_t ptr_key = reinterpret_cast<intptr_t>(pthread_key); | 641 intptr_t ptr_key = reinterpret_cast<intptr_t>(pthread_key); |
640 return static_cast<Thread::LocalStorageKey>(ptr_key); | 642 return static_cast<Thread::LocalStorageKey>(ptr_key); |
641 #else | 643 #else |
642 return static_cast<Thread::LocalStorageKey>(pthread_key); | 644 return static_cast<Thread::LocalStorageKey>(pthread_key); |
643 #endif | 645 #endif |
644 } | 646 } |
645 | 647 |
646 | 648 |
647 static pthread_key_t LocalKeyToPthreadKey(Thread::LocalStorageKey local_key) { | 649 static pthread_key_t LocalKeyToPthreadKey(Thread::LocalStorageKey local_key) { |
648 #if V8_OS_CYGWIN | 650 #if defined(__CYGWIN__) |
649 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t)); | 651 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t)); |
650 intptr_t ptr_key = static_cast<intptr_t>(local_key); | 652 intptr_t ptr_key = static_cast<intptr_t>(local_key); |
651 return reinterpret_cast<pthread_key_t>(ptr_key); | 653 return reinterpret_cast<pthread_key_t>(ptr_key); |
652 #else | 654 #else |
653 return static_cast<pthread_key_t>(local_key); | 655 return static_cast<pthread_key_t>(local_key); |
654 #endif | 656 #endif |
655 } | 657 } |
656 | 658 |
657 | 659 |
658 #ifdef V8_FAST_TLS_SUPPORTED | 660 #ifdef V8_FAST_TLS_SUPPORTED |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 return ntohl(value); | 990 return ntohl(value); |
989 } | 991 } |
990 | 992 |
991 | 993 |
992 Socket* OS::CreateSocket() { | 994 Socket* OS::CreateSocket() { |
993 return new POSIXSocket(); | 995 return new POSIXSocket(); |
994 } | 996 } |
995 | 997 |
996 | 998 |
997 } } // namespace v8::internal | 999 } } // namespace v8::internal |
OLD | NEW |