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

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

Issue 23548024: Introduce a RandonNumberGenerator class. Refactor the random/private_random uses in Isolate/Context. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE Created 7 years, 3 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-openbsd.cc ('k') | src/platform-solaris.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 // 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 #undef MAP_TYPE 62 #undef MAP_TYPE
63 63
64 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) 64 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
65 #define LOG_TAG "v8" 65 #define LOG_TAG "v8"
66 #include <android/log.h> 66 #include <android/log.h>
67 #endif 67 #endif
68 68
69 #include "v8.h" 69 #include "v8.h"
70 70
71 #include "codegen.h" 71 #include "codegen.h"
72 #include "isolate-inl.h"
72 #include "platform.h" 73 #include "platform.h"
73 74
74 namespace v8 { 75 namespace v8 {
75 namespace internal { 76 namespace internal {
76 77
77 // 0 is never a valid thread id. 78 // 0 is never a valid thread id.
78 static const pthread_t kNoThread = (pthread_t) 0; 79 static const pthread_t kNoThread = (pthread_t) 0;
79 80
80 81
81 uint64_t OS::CpuFeaturesImpliedByPlatform() { 82 uint64_t OS::CpuFeaturesImpliedByPlatform() {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // TODO(bradchen): restore randomization once Native Client gets 165 // TODO(bradchen): restore randomization once Native Client gets
165 // smarter about using mmap address hints. 166 // smarter about using mmap address hints.
166 // See http://code.google.com/p/nativeclient/issues/3341 167 // See http://code.google.com/p/nativeclient/issues/3341
167 return NULL; 168 return NULL;
168 #endif 169 #endif
169 Isolate* isolate = Isolate::UncheckedCurrent(); 170 Isolate* isolate = Isolate::UncheckedCurrent();
170 // Note that the current isolate isn't set up in a call path via 171 // Note that the current isolate isn't set up in a call path via
171 // CpuFeatures::Probe. We don't care about randomization in this case because 172 // CpuFeatures::Probe. We don't care about randomization in this case because
172 // the code page is immediately freed. 173 // the code page is immediately freed.
173 if (isolate != NULL) { 174 if (isolate != NULL) {
175 uintptr_t raw_addr;
176 isolate->random_number_generator()->NextBytes(&raw_addr, sizeof(raw_addr));
174 #if V8_TARGET_ARCH_X64 177 #if V8_TARGET_ARCH_X64
175 uint64_t rnd1 = V8::RandomPrivate(isolate);
176 uint64_t rnd2 = V8::RandomPrivate(isolate);
177 uint64_t raw_addr = (rnd1 << 32) ^ rnd2;
178 // Currently available CPUs have 48 bits of virtual addressing. Truncate 178 // Currently available CPUs have 48 bits of virtual addressing. Truncate
179 // 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
180 // fulfilling our placement request. 180 // fulfilling our placement request.
181 raw_addr &= V8_UINT64_C(0x3ffffffff000); 181 raw_addr &= V8_UINT64_C(0x3ffffffff000);
182 #else 182 #else
183 uint32_t raw_addr = V8::RandomPrivate(isolate);
184
185 raw_addr &= 0x3ffff000; 183 raw_addr &= 0x3ffff000;
186 184
187 # ifdef __sun 185 # ifdef __sun
188 // For our Solaris/illumos mmap hint, we pick a random address in the bottom 186 // For our Solaris/illumos mmap hint, we pick a random address in the bottom
189 // half of the top half of the address space (that is, the third quarter). 187 // half of the top half of the address space (that is, the third quarter).
190 // Because we do not MAP_FIXED, this will be treated only as a hint -- the 188 // Because we do not MAP_FIXED, this will be treated only as a hint -- the
191 // system will not fail to mmap() because something else happens to already 189 // system will not fail to mmap() because something else happens to already
192 // be mapped at our random address. We deliberately set the hint high enough 190 // be mapped at our random address. We deliberately set the hint high enough
193 // to get well above the system's break (that is, the heap); Solaris and 191 // to get well above the system's break (that is, the heap); Solaris and
194 // illumos will try the hint and if that fails allocate as if there were 192 // illumos will try the hint and if that fails allocate as if there were
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 731
734 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { 732 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
735 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); 733 pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
736 int result = pthread_setspecific(pthread_key, value); 734 int result = pthread_setspecific(pthread_key, value);
737 ASSERT_EQ(0, result); 735 ASSERT_EQ(0, result);
738 USE(result); 736 USE(result);
739 } 737 }
740 738
741 739
742 } } // namespace v8::internal 740 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-openbsd.cc ('k') | src/platform-solaris.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698