OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "utils/random-number-generator.h" | 47 #include "utils/random-number-generator.h" |
48 #if V8_OS_CYGIN || V8_OS_WIN | 48 #if V8_OS_CYGIN || V8_OS_WIN |
49 #include "win32-headers.h" | 49 #include "win32-headers.h" |
50 #endif | 50 #endif |
51 | 51 |
52 namespace v8 { | 52 namespace v8 { |
53 namespace internal { | 53 namespace internal { |
54 | 54 |
55 class RandomAddressGenerator V8_FINAL { | 55 class RandomAddressGenerator V8_FINAL { |
56 public: | 56 public: |
57 V8_INLINE(uintptr_t NextAddress()) { | 57 V8_INLINE uintptr_t NextAddress() { |
58 LockGuard<Mutex> lock_guard(&mutex_); | 58 LockGuard<Mutex> lock_guard(&mutex_); |
59 uintptr_t address = rng_.NextInt(); | 59 uintptr_t address = rng_.NextInt(); |
60 #if V8_HOST_ARCH_64_BIT | 60 #if V8_HOST_ARCH_64_BIT |
61 address = (address << 32) + static_cast<uintptr_t>(rng_.NextInt()); | 61 address = (address << 32) + static_cast<uintptr_t>(rng_.NextInt()); |
62 #endif | 62 #endif |
63 return address; | 63 return address; |
64 } | 64 } |
65 | 65 |
66 private: | 66 private: |
67 Mutex mutex_; | 67 Mutex mutex_; |
68 RandomNumberGenerator rng_; | 68 RandomNumberGenerator rng_; |
69 }; | 69 }; |
70 | 70 |
71 typedef LazyInstance<RandomAddressGenerator, | 71 typedef LazyInstance<RandomAddressGenerator, |
72 DefaultConstructTrait<RandomAddressGenerator>, | 72 DefaultConstructTrait<RandomAddressGenerator>, |
73 ThreadSafeInitOnceTrait>::type LazyRandomAddressGenerator; | 73 ThreadSafeInitOnceTrait>::type LazyRandomAddressGenerator; |
74 | 74 |
75 #define LAZY_RANDOM_ADDRESS_GENERATOR_INITIALIZER LAZY_INSTANCE_INITIALIZER | 75 #define LAZY_RANDOM_ADDRESS_GENERATOR_INITIALIZER LAZY_INSTANCE_INITIALIZER |
76 | 76 |
77 | 77 |
78 static V8_INLINE(void* GenerateRandomAddress()) { | 78 static V8_INLINE void* GenerateRandomAddress() { |
79 #if V8_OS_NACL | 79 #if V8_OS_NACL |
80 // TODO(bradchen): Restore randomization once Native Client gets smarter | 80 // TODO(bradchen): Restore randomization once Native Client gets smarter |
81 // about using mmap address hints. | 81 // about using mmap address hints. |
82 // See http://code.google.com/p/nativeclient/issues/3341 | 82 // See http://code.google.com/p/nativeclient/issues/3341 |
83 return NULL; | 83 return NULL; |
84 #else // V8_OS_NACL | 84 #else // V8_OS_NACL |
85 LazyRandomAddressGenerator random_address_generator = | 85 LazyRandomAddressGenerator random_address_generator = |
86 LAZY_RANDOM_ADDRESS_GENERATOR_INITIALIZER; | 86 LAZY_RANDOM_ADDRESS_GENERATOR_INITIALIZER; |
87 uintptr_t address = random_address_generator.Pointer()->NextAddress(); | 87 uintptr_t address = random_address_generator.Pointer()->NextAddress(); |
88 | 88 |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 | 501 |
502 // static | 502 // static |
503 size_t VirtualMemory::GetPageSize() { | 503 size_t VirtualMemory::GetPageSize() { |
504 static const size_t kPageSize = getpagesize(); | 504 static const size_t kPageSize = getpagesize(); |
505 return kPageSize; | 505 return kPageSize; |
506 } | 506 } |
507 | 507 |
508 #endif // V8_OS_CYGWIN || V8_OS_WIN | 508 #endif // V8_OS_CYGWIN || V8_OS_WIN |
509 | 509 |
510 } } // namespace v8::internal | 510 } } // namespace v8::internal |
OLD | NEW |