[Memory] Add SetRandomMmapSeed function to v8::internal.

- Adds SetRandomMmapSeed method.
- Removes random seed from OS::Initialize signature.

Bug: chromium:756050
Change-Id: I46ef6a92efb8b97541b90383d08776dd73a35a0c
Reviewed-on: https://chromium-review.googlesource.com/836907
Reviewed-by: Bill Budge <bbudge@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Commit-Queue: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50280}
This commit is contained in:
Bill Budge 2017-12-20 06:50:09 -08:00 committed by Commit Bot
parent ff57712b8d
commit 9baef6a7e1
6 changed files with 43 additions and 21 deletions

View File

@ -123,8 +123,13 @@ STATIC_ASSERT_ENUM(MemoryPermission::kReadExecute,
class DefaultMemoryManager {
public:
static size_t AllocatePageSize() { return base::OS::AllocatePageSize(); }
static size_t CommitPageSize() { return base::OS::CommitPageSize(); }
static void SetRandomMmapSeed(int64_t seed) {
base::OS::SetRandomMmapSeed(seed);
}
static void* GetRandomMmapAddr() { return base::OS::GetRandomMmapAddr(); }
static void* AllocatePages(void* address, size_t size, size_t alignment,
@ -174,7 +179,10 @@ size_t AllocatePageSize() { return DefaultMemoryManager::AllocatePageSize(); }
size_t CommitPageSize() { return DefaultMemoryManager::CommitPageSize(); }
// Generate a random address to be used for hinting allocation calls.
void SetRandomMmapSeed(int64_t seed) {
DefaultMemoryManager::SetRandomMmapSeed(seed);
}
void* GetRandomMmapAddr() { return DefaultMemoryManager::GetRandomMmapAddr(); }
void* AllocatePages(void* address, size_t size, size_t alignment,

View File

@ -92,6 +92,9 @@ V8_EXPORT_PRIVATE size_t AllocatePageSize();
// Gets the granularity at which the permissions and release calls can be made.
V8_EXPORT_PRIVATE size_t CommitPageSize();
// Sets the random seed for repeatable sequences of random mmap addresses.
V8_EXPORT_PRIVATE void SetRandomMmapSeed(int64_t seed);
// Generate a random address to be used for hinting allocation calls.
V8_EXPORT_PRIVATE void* GetRandomMmapAddr();

View File

@ -166,11 +166,7 @@ int ReclaimInaccessibleMemory(void* address, size_t size) {
} // namespace
void OS::Initialize(int64_t random_seed, bool hard_abort,
const char* const gc_fake_mmap) {
if (random_seed) {
platform_random_number_generator.Pointer()->SetSeed(random_seed);
}
void OS::Initialize(bool hard_abort, const char* const gc_fake_mmap) {
g_hard_abort = hard_abort;
g_gc_fake_mmap = gc_fake_mmap;
}
@ -205,6 +201,14 @@ size_t OS::CommitPageSize() {
return page_size;
}
// static
void OS::SetRandomMmapSeed(int64_t seed) {
if (seed) {
LockGuard<Mutex> guard(rng_mutex.Pointer());
platform_random_number_generator.Pointer()->SetSeed(seed);
}
}
// static
void* OS::GetRandomMmapAddr() {
uintptr_t raw_addr;

View File

@ -674,8 +674,15 @@ void OS::StrNCpy(char* dest, int length, const char* src, size_t n) {
#undef _TRUNCATE
#undef STRUNCATE
// The allocation alignment is the guaranteed alignment for
// VirtualAlloc'ed blocks of memory.
static LazyInstance<RandomNumberGenerator>::type
platform_random_number_generator = LAZY_INSTANCE_INITIALIZER;
static LazyMutex rng_mutex = LAZY_MUTEX_INITIALIZER;
void OS::Initialize(bool hard_abort, const char* const gc_fake_mmap) {
g_hard_abort = hard_abort;
}
// static
size_t OS::AllocatePageSize() {
static size_t allocate_alignment = 0;
if (allocate_alignment == 0) {
@ -686,6 +693,7 @@ size_t OS::AllocatePageSize() {
return allocate_alignment;
}
// static
size_t OS::CommitPageSize() {
static size_t page_size = 0;
if (page_size == 0) {
@ -697,18 +705,15 @@ size_t OS::CommitPageSize() {
return page_size;
}
static LazyInstance<RandomNumberGenerator>::type
platform_random_number_generator = LAZY_INSTANCE_INITIALIZER;
static LazyMutex rng_mutex = LAZY_MUTEX_INITIALIZER;
void OS::Initialize(int64_t random_seed, bool hard_abort,
const char* const gc_fake_mmap) {
if (random_seed) {
platform_random_number_generator.Pointer()->SetSeed(random_seed);
// static
void OS::SetRandomMmapSeed(int64_t seed) {
if (seed) {
LockGuard<Mutex> guard(rng_mutex.Pointer());
platform_random_number_generator.Pointer()->SetSeed(seed);
}
g_hard_abort = hard_abort;
}
// static
void* OS::GetRandomMmapAddr() {
// The address range used to randomize RWX allocations in OS::Allocate
// Try not to map pages into the default range that windows loads DLLs

View File

@ -113,11 +113,9 @@ class TimezoneCache;
class V8_BASE_EXPORT OS {
public:
// Initialize the OS class.
// - random_seed: Used for the GetRandomMmapAddress() if non-zero.
// - hard_abort: If true, OS::Abort() will crash instead of aborting.
// - gc_fake_mmap: Name of the file for fake gc mmap used in ll_prof.
static void Initialize(int64_t random_seed, bool hard_abort,
const char* const gc_fake_mmap);
static void Initialize(bool hard_abort, const char* const gc_fake_mmap);
// Returns the accumulated user time for thread. This routine
// can be used for profiling. The implementation should
@ -264,6 +262,8 @@ class V8_BASE_EXPORT OS {
static size_t CommitPageSize();
static void SetRandomMmapSeed(int64_t seed);
static void* GetRandomMmapAddr();
V8_WARN_UNUSED_RESULT static void* Allocate(void* address, size_t size,

View File

@ -69,7 +69,9 @@ void V8::InitializeOncePerProcessImpl() {
FLAG_max_semi_space_size = 1;
}
base::OS::Initialize(FLAG_random_seed, FLAG_hard_abort, FLAG_gc_fake_mmap);
base::OS::Initialize(FLAG_hard_abort, FLAG_gc_fake_mmap);
if (FLAG_random_seed) SetRandomMmapSeed(FLAG_random_seed);
Isolate::InitializeOncePerProcess();