Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

Unified Diff: src/platform-win32.cc

Issue 7352007: Add guard pages in front of platform allocations (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/platform-linux.cc ('K') | « src/platform-macos.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform-win32.cc
===================================================================
--- src/platform-win32.cc (revision 8619)
+++ src/platform-win32.cc (working copy)
@@ -913,11 +913,14 @@
}
LPVOID mbase = VirtualAlloc(reinterpret_cast<void *>(address),
- msize,
+ msize + Page::kPageSize,
Vyacheslav Egorov (Chromium) 2011/07/12 23:23:29 This looks slightly suspicious to me. MemoryAlloc
Cris Neckar 2011/07/14 17:32:28 Done.
MEM_COMMIT | MEM_RESERVE,
prot);
if (mbase == NULL && address != 0)
- mbase = VirtualAlloc(NULL, msize, MEM_COMMIT | MEM_RESERVE, prot);
+ mbase = VirtualAlloc(NULL,
+ msize + Page::kPageSize,
+ MEM_COMMIT | MEM_RESERVE,
+ prot);
if (mbase == NULL) {
LOG(ISOLATE, StringEvent("OS::Allocate", "VirtualAlloc failed"));
@@ -925,8 +928,12 @@
}
ASSERT(IsAligned(reinterpret_cast<size_t>(mbase), OS::AllocateAlignment()));
+ *allocated = msize;
- *allocated = msize;
+ DWORD old_protect;
+ VirtualProtect(mbase, Page::kPageSize, PAGE_READONLY | PAGE_GUARD, &old_protect);
+ mbase = static_cast<BYTE*>(mbase) + Page::kPageSize;
+
UpdateAllocatedSpaceLimits(mbase, static_cast<int>(msize));
return mbase;
}
@@ -934,7 +941,7 @@
void OS::Free(void* address, const size_t size) {
// TODO(1240712): VirtualFree has a return value which is ignored here.
- VirtualFree(address, 0, MEM_RELEASE);
+ VirtualFree(static_cast<BYTE*>(address) - Page::kPageSize, 0, MEM_RELEASE);
USE(size);
}
« src/platform-linux.cc ('K') | « src/platform-macos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698