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

Unified Diff: src/platform-win32.cc

Issue 53004: Add basic infrastructure for protecting V8's heap when leaving the VM... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 9 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
Index: src/platform-win32.cc
===================================================================
--- src/platform-win32.cc (revision 1577)
+++ src/platform-win32.cc (working copy)
@@ -801,12 +801,12 @@
void* OS::Allocate(const size_t requested,
size_t* allocated,
- bool executable) {
+ bool is_executable) {
// VirtualAlloc rounds allocated size to page size automatically.
size_t msize = RoundUp(requested, GetPageSize());
// Windows XP SP2 allows Data Excution Prevention (DEP).
- int prot = executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
+ int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
LPVOID mbase = VirtualAlloc(NULL, msize, MEM_COMMIT | MEM_RESERVE, prot);
if (mbase == NULL) {
LOG(StringEvent("OS::Allocate", "VirtualAlloc failed"));
@@ -821,13 +821,32 @@
}
-void OS::Free(void* buf, const size_t length) {
+void OS::Free(void* address, const size_t size) {
// TODO(1240712): VirtualFree has a return value which is ignored here.
- VirtualFree(buf, 0, MEM_RELEASE);
- USE(length);
+ VirtualFree(address, 0, MEM_RELEASE);
+ USE(size);
}
+#ifdef ENABLE_HEAP_PROTECTION
+
+void OS::Protect(void* address, size_t size) {
+ // TODO(1240712): VirtualProtect has a return value which is ignored here.
+ DWORD old_protect;
+ VirtualProtect(address, size, PAGE_READONLY, &old_protect);
+}
+
+
+void OS::Unprotect(void* address, size_t size, bool is_executable) {
+ // TODO(1240712): VirtualProtect has a return value which is ignored here.
+ DWORD new_protect = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
+ DWORD old_protect;
+ VirtualProtect(address, size, new_protect, &old_protect);
+}
+
+#endif
+
+
void OS::Sleep(int milliseconds) {
::Sleep(milliseconds);
}
@@ -1299,8 +1318,8 @@
}
-bool VirtualMemory::Commit(void* address, size_t size, bool executable) {
- int prot = executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
+bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
+ int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
if (NULL == VirtualAlloc(address, size, MEM_COMMIT, prot)) {
return false;
}

Powered by Google App Engine
This is Rietveld 408576698