Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: src/platform-posix.cc

Issue 347223004: Remove dependency from platform.h implementations on isolate (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform.h ('k') | src/platform-win32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 25 matching lines...) Expand all
36 36
37 #undef MAP_TYPE 37 #undef MAP_TYPE
38 38
39 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) 39 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
40 #define LOG_TAG "v8" 40 #define LOG_TAG "v8"
41 #include <android/log.h> // NOLINT 41 #include <android/log.h> // NOLINT
42 #endif 42 #endif
43 43
44 #include "src/v8.h" 44 #include "src/v8.h"
45 45
46 #include "src/isolate-inl.h" 46 #include "src/base/lazy-instance.h"
47 #include "src/platform.h" 47 #include "src/platform.h"
48 #include "src/utils/random-number-generator.h"
48 49
49 #ifdef V8_FAST_TLS_SUPPORTED 50 #ifdef V8_FAST_TLS_SUPPORTED
50 #include "src/base/atomicops.h" 51 #include "src/base/atomicops.h"
51 #endif 52 #endif
52 53
53 namespace v8 { 54 namespace v8 {
54 namespace internal { 55 namespace internal {
55 56
56 // 0 is never a valid thread id. 57 // 0 is never a valid thread id.
57 static const pthread_t kNoThread = (pthread_t) 0; 58 static const pthread_t kNoThread = (pthread_t) 0;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 void OS::Guard(void* address, const size_t size) { 180 void OS::Guard(void* address, const size_t size) {
180 #if V8_OS_CYGWIN 181 #if V8_OS_CYGWIN
181 DWORD oldprotect; 182 DWORD oldprotect;
182 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect); 183 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect);
183 #else 184 #else
184 mprotect(address, size, PROT_NONE); 185 mprotect(address, size, PROT_NONE);
185 #endif 186 #endif
186 } 187 }
187 188
188 189
190 static base::LazyInstance<RandomNumberGenerator>::type
191 platform_random_number_generator = LAZY_INSTANCE_INITIALIZER;
192
193
194 void OS::SetRandomSeed(int64_t seed) {
195 platform_random_number_generator.Pointer()->SetSeed(seed);
196 }
197
198
189 void* OS::GetRandomMmapAddr() { 199 void* OS::GetRandomMmapAddr() {
190 #if V8_OS_NACL 200 #if V8_OS_NACL
191 // TODO(bradchen): restore randomization once Native Client gets 201 // TODO(bradchen): restore randomization once Native Client gets
192 // smarter about using mmap address hints. 202 // smarter about using mmap address hints.
193 // See http://code.google.com/p/nativeclient/issues/3341 203 // See http://code.google.com/p/nativeclient/issues/3341
194 return NULL; 204 return NULL;
195 #endif 205 #endif
196 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ 206 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
197 defined(THREAD_SANITIZER) 207 defined(THREAD_SANITIZER)
198 // Dynamic tools do not support custom mmap addresses. 208 // Dynamic tools do not support custom mmap addresses.
199 return NULL; 209 return NULL;
200 #endif 210 #endif
201 Isolate* isolate = Isolate::UncheckedCurrent(); 211 uintptr_t raw_addr;
202 // Note that the current isolate isn't set up in a call path via 212 platform_random_number_generator.Pointer()->NextBytes(&raw_addr,
203 // CpuFeatures::Probe. We don't care about randomization in this case because 213 sizeof(raw_addr));
204 // the code page is immediately freed.
205 if (isolate != NULL) {
206 uintptr_t raw_addr;
207 isolate->random_number_generator()->NextBytes(&raw_addr, sizeof(raw_addr));
208 #if V8_TARGET_ARCH_X64 214 #if V8_TARGET_ARCH_X64
209 // Currently available CPUs have 48 bits of virtual addressing. Truncate 215 // Currently available CPUs have 48 bits of virtual addressing. Truncate
210 // the hint address to 46 bits to give the kernel a fighting chance of 216 // the hint address to 46 bits to give the kernel a fighting chance of
211 // fulfilling our placement request. 217 // fulfilling our placement request.
212 raw_addr &= V8_UINT64_C(0x3ffffffff000); 218 raw_addr &= V8_UINT64_C(0x3ffffffff000);
213 #else 219 #else
214 raw_addr &= 0x3ffff000; 220 raw_addr &= 0x3ffff000;
215 221
216 # ifdef __sun 222 # ifdef __sun
217 // For our Solaris/illumos mmap hint, we pick a random address in the bottom 223 // For our Solaris/illumos mmap hint, we pick a random address in the bottom
218 // half of the top half of the address space (that is, the third quarter). 224 // half of the top half of the address space (that is, the third quarter).
219 // Because we do not MAP_FIXED, this will be treated only as a hint -- the 225 // Because we do not MAP_FIXED, this will be treated only as a hint -- the
220 // system will not fail to mmap() because something else happens to already 226 // system will not fail to mmap() because something else happens to already
221 // be mapped at our random address. We deliberately set the hint high enough 227 // be mapped at our random address. We deliberately set the hint high enough
222 // to get well above the system's break (that is, the heap); Solaris and 228 // to get well above the system's break (that is, the heap); Solaris and
223 // illumos will try the hint and if that fails allocate as if there were 229 // illumos will try the hint and if that fails allocate as if there were
224 // no hint at all. The high hint prevents the break from getting hemmed in 230 // no hint at all. The high hint prevents the break from getting hemmed in
225 // at low values, ceding half of the address space to the system heap. 231 // at low values, ceding half of the address space to the system heap.
226 raw_addr += 0x80000000; 232 raw_addr += 0x80000000;
227 # else 233 # else
228 // The range 0x20000000 - 0x60000000 is relatively unpopulated across a 234 // The range 0x20000000 - 0x60000000 is relatively unpopulated across a
229 // variety of ASLR modes (PAE kernel, NX compat mode, etc) and on macos 235 // variety of ASLR modes (PAE kernel, NX compat mode, etc) and on macos
230 // 10.6 and 10.7. 236 // 10.6 and 10.7.
231 raw_addr += 0x20000000; 237 raw_addr += 0x20000000;
232 # endif 238 # endif
233 #endif 239 #endif
234 return reinterpret_cast<void*>(raw_addr); 240 return reinterpret_cast<void*>(raw_addr);
235 }
236 return NULL;
237 } 241 }
238 242
239 243
240 size_t OS::AllocateAlignment() { 244 size_t OS::AllocateAlignment() {
241 return static_cast<size_t>(sysconf(_SC_PAGESIZE)); 245 return static_cast<size_t>(sysconf(_SC_PAGESIZE));
242 } 246 }
243 247
244 248
245 void OS::Sleep(int milliseconds) { 249 void OS::Sleep(int milliseconds) {
246 useconds_t ms = static_cast<useconds_t>(milliseconds); 250 useconds_t ms = static_cast<useconds_t>(milliseconds);
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 695
692 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { 696 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
693 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); 697 pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
694 int result = pthread_setspecific(pthread_key, value); 698 int result = pthread_setspecific(pthread_key, value);
695 ASSERT_EQ(0, result); 699 ASSERT_EQ(0, result);
696 USE(result); 700 USE(result);
697 } 701 }
698 702
699 703
700 } } // namespace v8::internal 704 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform.h ('k') | src/platform-win32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698