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
This commit is contained in:
vegorov@chromium.org 2011-08-02 13:34:52 +00:00
parent a547d333f0
commit 9f24cd0eef
5 changed files with 17 additions and 0 deletions

View File

@ -255,6 +255,7 @@ OS::MemCopyFunction CreateMemCopyFunction() {
ASSERT(desc.reloc_size == 0);
CPU::FlushICache(buffer, actual_size);
OS::ProtectCode(buffer, actual_size);
return FUNCTION_CAST<OS::MemCopyFunction>(buffer);
}

View File

@ -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.
void OS::Guard(void* address, const size_t size) {
mprotect(address, size, PROT_NONE);

View File

@ -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) {
DWORD oldprotect;
VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect);

View File

@ -207,6 +207,9 @@ class OS {
bool is_executable);
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.
static void Guard(void* address, const size_t size);

View File

@ -132,6 +132,7 @@ ModuloFunction CreateModuloFunction() {
CodeDesc desc;
masm.GetCode(&desc);
OS::ProtectCode(buffer, actual_size);
// Call the function from C++ through this pointer.
return FUNCTION_CAST<ModuloFunction>(buffer);
}