Remove dependency from platform.h implementations on isolate
BUG=none R=bmeurer@chromium.org LOG=n Review URL: https://codereview.chromium.org/347223004 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21997 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
7833a1321c
commit
c0dd51efdb
@ -43,8 +43,9 @@
|
||||
|
||||
#include "src/v8.h"
|
||||
|
||||
#include "src/isolate-inl.h"
|
||||
#include "src/base/lazy-instance.h"
|
||||
#include "src/platform.h"
|
||||
#include "src/utils/random-number-generator.h"
|
||||
|
||||
#ifdef V8_FAST_TLS_SUPPORTED
|
||||
#include "src/base/atomicops.h"
|
||||
@ -186,6 +187,15 @@ void OS::Guard(void* address, const size_t size) {
|
||||
}
|
||||
|
||||
|
||||
static base::LazyInstance<RandomNumberGenerator>::type
|
||||
platform_random_number_generator = LAZY_INSTANCE_INITIALIZER;
|
||||
|
||||
|
||||
void OS::SetRandomSeed(int64_t seed) {
|
||||
platform_random_number_generator.Pointer()->SetSeed(seed);
|
||||
}
|
||||
|
||||
|
||||
void* OS::GetRandomMmapAddr() {
|
||||
#if V8_OS_NACL
|
||||
// TODO(bradchen): restore randomization once Native Client gets
|
||||
@ -198,13 +208,9 @@ void* OS::GetRandomMmapAddr() {
|
||||
// Dynamic tools do not support custom mmap addresses.
|
||||
return NULL;
|
||||
#endif
|
||||
Isolate* isolate = Isolate::UncheckedCurrent();
|
||||
// Note that the current isolate isn't set up in a call path via
|
||||
// CpuFeatures::Probe. We don't care about randomization in this case because
|
||||
// the code page is immediately freed.
|
||||
if (isolate != NULL) {
|
||||
uintptr_t raw_addr;
|
||||
isolate->random_number_generator()->NextBytes(&raw_addr, sizeof(raw_addr));
|
||||
platform_random_number_generator.Pointer()->NextBytes(&raw_addr,
|
||||
sizeof(raw_addr));
|
||||
#if V8_TARGET_ARCH_X64
|
||||
// Currently available CPUs have 48 bits of virtual addressing. Truncate
|
||||
// the hint address to 46 bits to give the kernel a fighting chance of
|
||||
@ -233,8 +239,6 @@ void* OS::GetRandomMmapAddr() {
|
||||
#endif
|
||||
return reinterpret_cast<void*>(raw_addr);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
size_t OS::AllocateAlignment() {
|
||||
|
@ -19,8 +19,9 @@
|
||||
|
||||
#include "src/v8.h"
|
||||
|
||||
#include "src/isolate-inl.h"
|
||||
#include "src/base/lazy-instance.h"
|
||||
#include "src/platform.h"
|
||||
#include "src/utils/random-number-generator.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
@ -708,12 +709,16 @@ size_t OS::AllocateAlignment() {
|
||||
}
|
||||
|
||||
|
||||
static base::LazyInstance<RandomNumberGenerator>::type
|
||||
platform_random_number_generator = LAZY_INSTANCE_INITIALIZER;
|
||||
|
||||
|
||||
void OS::SetRandomSeed(int64_t seed) {
|
||||
platform_random_number_generator.Pointer()->SetSeed(seed);
|
||||
}
|
||||
|
||||
|
||||
void* OS::GetRandomMmapAddr() {
|
||||
Isolate* isolate = Isolate::UncheckedCurrent();
|
||||
// Note that the current isolate isn't set up in a call path via
|
||||
// CpuFeatures::Probe. We don't care about randomization in this case because
|
||||
// the code page is immediately freed.
|
||||
if (isolate != NULL) {
|
||||
// The address range used to randomize RWX allocations in OS::Allocate
|
||||
// Try not to map pages into the default range that windows loads DLLs
|
||||
// Use a multiple of 64k to prevent committing unused memory.
|
||||
@ -727,13 +732,11 @@ void* OS::GetRandomMmapAddr() {
|
||||
static const intptr_t kAllocationRandomAddressMax = 0x3FFF0000;
|
||||
#endif
|
||||
uintptr_t address =
|
||||
(isolate->random_number_generator()->NextInt() << kPageSizeBits) |
|
||||
(platform_random_number_generator.Pointer()->NextInt() << kPageSizeBits) |
|
||||
kAllocationRandomAddressMin;
|
||||
address &= kAllocationRandomAddressMax;
|
||||
return reinterpret_cast<void *>(address);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void* RandomizedVirtualAlloc(size_t size, int action, int protection) {
|
||||
|
@ -212,6 +212,10 @@ class OS {
|
||||
// Assign memory as a guard page so that access will cause an exception.
|
||||
static void Guard(void* address, const size_t size);
|
||||
|
||||
// Set a fixed random seed for the random number generator used for
|
||||
// GetRandomMmapAddr.
|
||||
static void SetRandomSeed(int64_t seed);
|
||||
|
||||
// Generate a random address to be used for hinting mmap().
|
||||
static void* GetRandomMmapAddr();
|
||||
|
||||
|
@ -71,13 +71,15 @@ class RandomNumberGenerator V8_FINAL {
|
||||
// Fills the elements of a specified array of bytes with random numbers.
|
||||
void NextBytes(void* buffer, size_t buflen);
|
||||
|
||||
// Override the current ssed.
|
||||
void SetSeed(int64_t seed);
|
||||
|
||||
private:
|
||||
static const int64_t kMultiplier = V8_2PART_UINT64_C(0x5, deece66d);
|
||||
static const int64_t kAddend = 0xb;
|
||||
static const int64_t kMask = V8_2PART_UINT64_C(0xffff, ffffffff);
|
||||
|
||||
int Next(int bits) V8_WARN_UNUSED_RESULT;
|
||||
void SetSeed(int64_t seed);
|
||||
|
||||
int64_t seed_;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user