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..fd47931b6b0cfae2ea96c8efdb32727c2cdf373c 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) { |
+ OS::Free(mbase, allocated); |
+ 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; |