Implement guard pages for windows page allocator
authorUlf Hermann <ulf.hermann@digia.com>
Tue, 21 Oct 2014 14:51:56 +0000 (16:51 +0200)
committerUlf Hermann <ulf.hermann@digia.com>
Thu, 30 Oct 2014 12:19:41 +0000 (13:19 +0100)
Change-Id: Ia54a259bbf05cca7dc1ed868a75931efa95851b3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/3rdparty/masm/wtf/OSAllocatorWin.cpp

index f95a484..bcd1f6d 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "config.h"
 #include "OSAllocator.h"
+#include "PageBlock.h"
 
 #if OS(WINDOWS)
 
@@ -48,11 +49,20 @@ void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool writable, bool e
     return result;
 }
 
-void* OSAllocator::reserveAndCommit(size_t bytes, Usage, bool writable, bool executable, bool)
+void* OSAllocator::reserveAndCommit(size_t bytes, Usage, bool writable, bool executable,
+                                    bool includesGuardPages)
 {
     void* result = VirtualAlloc(0, bytes, MEM_RESERVE | MEM_COMMIT, protection(writable, executable));
     if (!result)
         CRASH();
+    if (includesGuardPages) {
+        size_t guardSize = pageSize();
+        DWORD oldProtect;
+        if (!VirtualProtect(result, guardSize, protection(false, false), &oldProtect) ||
+            !VirtualProtect(static_cast<char*>(result) + bytes - guardSize, guardSize,
+                            protection(false, false), &oldProtect))
+            CRASH();
+    }
     return result;
 }