| 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 <dlfcn.h> | 9 #include <dlfcn.h> |
| 10 #include <errno.h> | 10 #include <errno.h> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) | 40 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) |
| 41 #define LOG_TAG "v8" | 41 #define LOG_TAG "v8" |
| 42 #include <android/log.h> // NOLINT | 42 #include <android/log.h> // NOLINT |
| 43 #endif | 43 #endif |
| 44 | 44 |
| 45 #include <cmath> | 45 #include <cmath> |
| 46 #include <cstdlib> | 46 #include <cstdlib> |
| 47 | 47 |
| 48 #include "src/base/lazy-instance.h" | 48 #include "src/base/lazy-instance.h" |
| 49 #include "src/base/macros.h" | 49 #include "src/base/macros.h" |
| 50 #include "src/platform.h" | 50 #include "src/base/platform/platform.h" |
| 51 #include "src/platform/time.h" | 51 #include "src/base/platform/time.h" |
| 52 #include "src/utils/random-number-generator.h" | 52 #include "src/base/utils/random-number-generator.h" |
| 53 | 53 |
| 54 #ifdef V8_FAST_TLS_SUPPORTED | 54 #ifdef V8_FAST_TLS_SUPPORTED |
| 55 #include "src/base/atomicops.h" | 55 #include "src/base/atomicops.h" |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 namespace v8 { | 58 namespace v8 { |
| 59 namespace internal { | 59 namespace base { |
| 60 | 60 |
| 61 namespace { | 61 namespace { |
| 62 | 62 |
| 63 // 0 is never a valid thread id. | 63 // 0 is never a valid thread id. |
| 64 const pthread_t kNoThread = (pthread_t) 0; | 64 const pthread_t kNoThread = (pthread_t) 0; |
| 65 | 65 |
| 66 bool g_hard_abort = false; | 66 bool g_hard_abort = false; |
| 67 | 67 |
| 68 const char* g_gc_fake_mmap = NULL; | 68 const char* g_gc_fake_mmap = NULL; |
| 69 | 69 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 void OS::Guard(void* address, const size_t size) { | 192 void OS::Guard(void* address, const size_t size) { |
| 193 #if V8_OS_CYGWIN | 193 #if V8_OS_CYGWIN |
| 194 DWORD oldprotect; | 194 DWORD oldprotect; |
| 195 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect); | 195 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect); |
| 196 #else | 196 #else |
| 197 mprotect(address, size, PROT_NONE); | 197 mprotect(address, size, PROT_NONE); |
| 198 #endif | 198 #endif |
| 199 } | 199 } |
| 200 | 200 |
| 201 | 201 |
| 202 static base::LazyInstance<RandomNumberGenerator>::type | 202 static LazyInstance<RandomNumberGenerator>::type |
| 203 platform_random_number_generator = LAZY_INSTANCE_INITIALIZER; | 203 platform_random_number_generator = LAZY_INSTANCE_INITIALIZER; |
| 204 | 204 |
| 205 | 205 |
| 206 void OS::Initialize(int64_t random_seed, bool hard_abort, | 206 void OS::Initialize(int64_t random_seed, bool hard_abort, |
| 207 const char* const gc_fake_mmap) { | 207 const char* const gc_fake_mmap) { |
| 208 if (random_seed) { | 208 if (random_seed) { |
| 209 platform_random_number_generator.Pointer()->SetSeed(random_seed); | 209 platform_random_number_generator.Pointer()->SetSeed(random_seed); |
| 210 } | 210 } |
| 211 g_hard_abort = hard_abort; | 211 g_hard_abort = hard_abort; |
| 212 g_gc_fake_mmap = gc_fake_mmap; | 212 g_gc_fake_mmap = gc_fake_mmap; |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 intptr_t ptr_key = static_cast<intptr_t>(local_key); | 619 intptr_t ptr_key = static_cast<intptr_t>(local_key); |
| 620 return reinterpret_cast<pthread_key_t>(ptr_key); | 620 return reinterpret_cast<pthread_key_t>(ptr_key); |
| 621 #else | 621 #else |
| 622 return static_cast<pthread_key_t>(local_key); | 622 return static_cast<pthread_key_t>(local_key); |
| 623 #endif | 623 #endif |
| 624 } | 624 } |
| 625 | 625 |
| 626 | 626 |
| 627 #ifdef V8_FAST_TLS_SUPPORTED | 627 #ifdef V8_FAST_TLS_SUPPORTED |
| 628 | 628 |
| 629 static base::Atomic32 tls_base_offset_initialized = 0; | 629 static Atomic32 tls_base_offset_initialized = 0; |
| 630 intptr_t kMacTlsBaseOffset = 0; | 630 intptr_t kMacTlsBaseOffset = 0; |
| 631 | 631 |
| 632 // It's safe to do the initialization more that once, but it has to be | 632 // It's safe to do the initialization more that once, but it has to be |
| 633 // done at least once. | 633 // done at least once. |
| 634 static void InitializeTlsBaseOffset() { | 634 static void InitializeTlsBaseOffset() { |
| 635 const size_t kBufferSize = 128; | 635 const size_t kBufferSize = 128; |
| 636 char buffer[kBufferSize]; | 636 char buffer[kBufferSize]; |
| 637 size_t buffer_size = kBufferSize; | 637 size_t buffer_size = kBufferSize; |
| 638 int ctl_name[] = { CTL_KERN , KERN_OSRELEASE }; | 638 int ctl_name[] = { CTL_KERN , KERN_OSRELEASE }; |
| 639 if (sysctl(ctl_name, 2, buffer, &buffer_size, NULL, 0) != 0) { | 639 if (sysctl(ctl_name, 2, buffer, &buffer_size, NULL, 0) != 0) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 655 #if V8_HOST_ARCH_IA32 | 655 #if V8_HOST_ARCH_IA32 |
| 656 kMacTlsBaseOffset = 0x48; | 656 kMacTlsBaseOffset = 0x48; |
| 657 #else | 657 #else |
| 658 kMacTlsBaseOffset = 0x60; | 658 kMacTlsBaseOffset = 0x60; |
| 659 #endif | 659 #endif |
| 660 } else { | 660 } else { |
| 661 // 11.x.x (Lion) changed the offset. | 661 // 11.x.x (Lion) changed the offset. |
| 662 kMacTlsBaseOffset = 0; | 662 kMacTlsBaseOffset = 0; |
| 663 } | 663 } |
| 664 | 664 |
| 665 base::Release_Store(&tls_base_offset_initialized, 1); | 665 Release_Store(&tls_base_offset_initialized, 1); |
| 666 } | 666 } |
| 667 | 667 |
| 668 | 668 |
| 669 static void CheckFastTls(Thread::LocalStorageKey key) { | 669 static void CheckFastTls(Thread::LocalStorageKey key) { |
| 670 void* expected = reinterpret_cast<void*>(0x1234CAFE); | 670 void* expected = reinterpret_cast<void*>(0x1234CAFE); |
| 671 Thread::SetThreadLocal(key, expected); | 671 Thread::SetThreadLocal(key, expected); |
| 672 void* actual = Thread::GetExistingThreadLocal(key); | 672 void* actual = Thread::GetExistingThreadLocal(key); |
| 673 if (expected != actual) { | 673 if (expected != actual) { |
| 674 V8_Fatal(__FILE__, __LINE__, | 674 V8_Fatal(__FILE__, __LINE__, |
| 675 "V8 failed to initialize fast TLS on current kernel"); | 675 "V8 failed to initialize fast TLS on current kernel"); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 | 716 |
| 717 | 717 |
| 718 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 718 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { |
| 719 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); | 719 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); |
| 720 int result = pthread_setspecific(pthread_key, value); | 720 int result = pthread_setspecific(pthread_key, value); |
| 721 ASSERT_EQ(0, result); | 721 ASSERT_EQ(0, result); |
| 722 USE(result); | 722 USE(result); |
| 723 } | 723 } |
| 724 | 724 |
| 725 | 725 |
| 726 } } // namespace v8::internal | 726 } } // namespace v8::base |
| OLD | NEW |