Commit 9f24cd0e authored by vegorov@chromium.org's avatar vegorov@chromium.org

Mark optimized modulo and memcpy code pages -w after writing them.

BUG=91245

Review URL: http://codereview.chromium.org/7538028

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8780 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a547d333
...@@ -255,6 +255,7 @@ OS::MemCopyFunction CreateMemCopyFunction() { ...@@ -255,6 +255,7 @@ OS::MemCopyFunction CreateMemCopyFunction() {
ASSERT(desc.reloc_size == 0); ASSERT(desc.reloc_size == 0);
CPU::FlushICache(buffer, actual_size); CPU::FlushICache(buffer, actual_size);
OS::ProtectCode(buffer, actual_size);
return FUNCTION_CAST<OS::MemCopyFunction>(buffer); return FUNCTION_CAST<OS::MemCopyFunction>(buffer);
} }
......
...@@ -70,6 +70,12 @@ intptr_t OS::MaxVirtualMemory() { ...@@ -70,6 +70,12 @@ intptr_t OS::MaxVirtualMemory() {
} }
// Get rid of writable permission on code allocations.
void OS::ProtectCode(void* address, const size_t size) {
mprotect(address, size, PROT_READ | PROT_EXEC);
}
// Create guard pages. // Create guard pages.
void OS::Guard(void* address, const size_t size) { void OS::Guard(void* address, const size_t size) {
mprotect(address, size, PROT_NONE); mprotect(address, size, PROT_NONE);
......
...@@ -957,6 +957,12 @@ void OS::Free(void* address, const size_t size) { ...@@ -957,6 +957,12 @@ void OS::Free(void* address, const size_t size) {
} }
void OS::ProtectCode(void* address, const size_t size) {
DWORD old_protect;
VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect);
}
void OS::Guard(void* address, const size_t size) { void OS::Guard(void* address, const size_t size) {
DWORD oldprotect; DWORD oldprotect;
VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect); VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect);
......
...@@ -207,6 +207,9 @@ class OS { ...@@ -207,6 +207,9 @@ class OS {
bool is_executable); bool is_executable);
static void Free(void* address, const size_t size); static void Free(void* address, const size_t size);
// Mark code segments non-writable.
static void ProtectCode(void* address, const size_t size);
// Assign memory as a guard page so that access will cause an exception. // Assign memory as a guard page so that access will cause an exception.
static void Guard(void* address, const size_t size); static void Guard(void* address, const size_t size);
......
...@@ -132,6 +132,7 @@ ModuloFunction CreateModuloFunction() { ...@@ -132,6 +132,7 @@ ModuloFunction CreateModuloFunction() {
CodeDesc desc; CodeDesc desc;
masm.GetCode(&desc); masm.GetCode(&desc);
OS::ProtectCode(buffer, actual_size);
// Call the function from C++ through this pointer. // Call the function from C++ through this pointer.
return FUNCTION_CAST<ModuloFunction>(buffer); return FUNCTION_CAST<ModuloFunction>(buffer);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment