Chromium Code Reviews| Index: src/base/platform/platform-posix.cc |
| diff --git a/src/base/platform/platform-posix.cc b/src/base/platform/platform-posix.cc |
| index 3f4165de536c1f2047fc40dc248fd2158413598f..7a8ac973894f0fb539e928f7046e5780119d9bd7 100644 |
| --- a/src/base/platform/platform-posix.cc |
| +++ b/src/base/platform/platform-posix.cc |
| @@ -99,6 +99,20 @@ intptr_t OS::CommitPageSize() { |
| return page_size; |
| } |
| +void* OS::AllocateGuarded(const size_t requested) { |
| + size_t allocated = 0; |
| + const bool is_executable = false; |
| + void* mbase = OS::Allocate(requested, &allocated, is_executable); |
| + if (allocated != requested) { |
|
jochen (gone - plz use gerrit)
2016/11/12 21:05:45
why not allocated >= requested?
Eric Holk
2016/11/14 19:05:56
The goal is to allocate all or none of the request
|
| + OS::Free(mbase, requested); |
| + return nullptr; |
| + } |
| + if (mbase == nullptr) { |
| + return nullptr; |
| + } |
| + OS::Guard(mbase, requested); |
| + return mbase; |
| +} |
| void OS::Free(void* address, const size_t size) { |
| // TODO(1240712): munmap has a return value which is ignored here. |
| @@ -129,6 +143,15 @@ void OS::Guard(void* address, const size_t size) { |
| #endif |
| } |
| +// Make a region of memory readable and writable. |
| +void OS::Unprotect(void* address, const size_t size) { |
| +#if V8_OS_CYGWIN |
| + DWORD oldprotect; |
| + VirtualProtect(address, size, PAGE_READWRITE, &oldprotect); |
| +#else |
| + mprotect(address, size, PROT_READ | PROT_WRITE); |
| +#endif |
| +} |
| static LazyInstance<RandomNumberGenerator>::type |
| platform_random_number_generator = LAZY_INSTANCE_INITIALIZER; |