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> |
| 11 #include <limits.h> |
11 #include <pthread.h> | 12 #include <pthread.h> |
12 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) | 13 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
13 #include <pthread_np.h> // for pthread_set_name_np | 14 #include <pthread_np.h> // for pthread_set_name_np |
14 #endif | 15 #endif |
15 #include <sched.h> // for sched_yield | 16 #include <sched.h> // for sched_yield |
16 #include <time.h> | 17 #include <time.h> |
17 #include <unistd.h> | 18 #include <unistd.h> |
18 | 19 |
19 #include <sys/mman.h> | 20 #include <sys/mman.h> |
20 #include <sys/resource.h> | 21 #include <sys/resource.h> |
(...skipping 13 matching lines...) Expand all Loading... |
34 #include <netdb.h> | 35 #include <netdb.h> |
35 #include <netinet/in.h> | 36 #include <netinet/in.h> |
36 | 37 |
37 #undef MAP_TYPE | 38 #undef MAP_TYPE |
38 | 39 |
39 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) | 40 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) |
40 #define LOG_TAG "v8" | 41 #define LOG_TAG "v8" |
41 #include <android/log.h> // NOLINT | 42 #include <android/log.h> // NOLINT |
42 #endif | 43 #endif |
43 | 44 |
44 #include "src/v8.h" | 45 #include <cmath> |
| 46 #include <cstdlib> |
45 | 47 |
46 #include "src/base/lazy-instance.h" | 48 #include "src/base/lazy-instance.h" |
| 49 #include "src/base/macros.h" |
47 #include "src/platform.h" | 50 #include "src/platform.h" |
| 51 #include "src/platform/time.h" |
48 #include "src/utils/random-number-generator.h" | 52 #include "src/utils/random-number-generator.h" |
49 | 53 |
50 #ifdef V8_FAST_TLS_SUPPORTED | 54 #ifdef V8_FAST_TLS_SUPPORTED |
51 #include "src/base/atomicops.h" | 55 #include "src/base/atomicops.h" |
52 #endif | 56 #endif |
53 | 57 |
54 namespace v8 { | 58 namespace v8 { |
55 namespace internal { | 59 namespace internal { |
56 | 60 |
| 61 namespace { |
| 62 |
57 // 0 is never a valid thread id. | 63 // 0 is never a valid thread id. |
58 static const pthread_t kNoThread = (pthread_t) 0; | 64 const pthread_t kNoThread = (pthread_t) 0; |
| 65 |
| 66 bool g_hard_abort = false; |
| 67 |
| 68 const char* g_gc_fake_mmap = NULL; |
| 69 |
| 70 } // namespace |
59 | 71 |
60 | 72 |
61 int OS::NumberOfProcessorsOnline() { | 73 int OS::NumberOfProcessorsOnline() { |
62 return static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN)); | 74 return static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN)); |
63 } | 75 } |
64 | 76 |
65 | 77 |
66 // Maximum size of the virtual memory. 0 means there is no artificial | 78 // Maximum size of the virtual memory. 0 means there is no artificial |
67 // limit. | 79 // limit. |
68 | 80 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 #else | 196 #else |
185 mprotect(address, size, PROT_NONE); | 197 mprotect(address, size, PROT_NONE); |
186 #endif | 198 #endif |
187 } | 199 } |
188 | 200 |
189 | 201 |
190 static base::LazyInstance<RandomNumberGenerator>::type | 202 static base::LazyInstance<RandomNumberGenerator>::type |
191 platform_random_number_generator = LAZY_INSTANCE_INITIALIZER; | 203 platform_random_number_generator = LAZY_INSTANCE_INITIALIZER; |
192 | 204 |
193 | 205 |
194 void OS::SetRandomSeed(int64_t seed) { | 206 void OS::Initialize(int64_t random_seed, bool hard_abort, |
195 platform_random_number_generator.Pointer()->SetSeed(seed); | 207 const char* const gc_fake_mmap) { |
| 208 if (random_seed) { |
| 209 platform_random_number_generator.Pointer()->SetSeed(random_seed); |
| 210 } |
| 211 g_hard_abort = hard_abort; |
| 212 g_gc_fake_mmap = gc_fake_mmap; |
196 } | 213 } |
197 | 214 |
198 | 215 |
| 216 const char* OS::GetGCFakeMMapFile() { |
| 217 return g_gc_fake_mmap; |
| 218 } |
| 219 |
| 220 |
199 void* OS::GetRandomMmapAddr() { | 221 void* OS::GetRandomMmapAddr() { |
200 #if V8_OS_NACL | 222 #if V8_OS_NACL |
201 // TODO(bradchen): restore randomization once Native Client gets | 223 // TODO(bradchen): restore randomization once Native Client gets |
202 // smarter about using mmap address hints. | 224 // smarter about using mmap address hints. |
203 // See http://code.google.com/p/nativeclient/issues/3341 | 225 // See http://code.google.com/p/nativeclient/issues/3341 |
204 return NULL; | 226 return NULL; |
205 #endif | 227 #endif |
206 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ | 228 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ |
207 defined(THREAD_SANITIZER) | 229 defined(THREAD_SANITIZER) |
208 // Dynamic tools do not support custom mmap addresses. | 230 // Dynamic tools do not support custom mmap addresses. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 268 } |
247 | 269 |
248 | 270 |
249 void OS::Sleep(int milliseconds) { | 271 void OS::Sleep(int milliseconds) { |
250 useconds_t ms = static_cast<useconds_t>(milliseconds); | 272 useconds_t ms = static_cast<useconds_t>(milliseconds); |
251 usleep(1000 * ms); | 273 usleep(1000 * ms); |
252 } | 274 } |
253 | 275 |
254 | 276 |
255 void OS::Abort() { | 277 void OS::Abort() { |
256 if (FLAG_hard_abort) { | 278 if (g_hard_abort) { |
257 V8_IMMEDIATE_CRASH(); | 279 V8_IMMEDIATE_CRASH(); |
258 } | 280 } |
259 // Redirect to std abort to signal abnormal program termination. | 281 // Redirect to std abort to signal abnormal program termination. |
260 abort(); | 282 abort(); |
261 } | 283 } |
262 | 284 |
263 | 285 |
264 void OS::DebugBreak() { | 286 void OS::DebugBreak() { |
265 #if V8_HOST_ARCH_ARM | 287 #if V8_HOST_ARCH_ARM |
266 asm("bkpt 0"); | 288 asm("bkpt 0"); |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 | 717 |
696 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 718 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { |
697 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); | 719 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); |
698 int result = pthread_setspecific(pthread_key, value); | 720 int result = pthread_setspecific(pthread_key, value); |
699 ASSERT_EQ(0, result); | 721 ASSERT_EQ(0, result); |
700 USE(result); | 722 USE(result); |
701 } | 723 } |
702 | 724 |
703 | 725 |
704 } } // namespace v8::internal | 726 } } // namespace v8::internal |
OLD | NEW |