Reviewers: Chris Evans, Mads Ager, Vyacheslav Egorov,
Description: Mark optimized modulo and memcpy code pages -w after writing them. BUG=91245 Please review this at http://codereview.chromium.org/7545016/ SVN Base: http://v8.googlecode.com/svn/trunk/ Affected files: M src/ia32/codegen-ia32.cc M src/platform-posix.cc M src/platform-win32.cc M src/platform.h M src/x64/codegen-x64.cc Index: src/ia32/codegen-ia32.cc =================================================================== --- src/ia32/codegen-ia32.cc (revision 8697) +++ src/ia32/codegen-ia32.cc (working copy) @@ -255,6 +255,7 @@ ASSERT(desc.reloc_size == 0); CPU::FlushICache(buffer, actual_size); + OS::ProtectCode(buffer, actual_size); return FUNCTION_CAST<OS::MemCopyFunction>(buffer); } Index: src/platform-posix.cc =================================================================== --- src/platform-posix.cc (revision 8697) +++ src/platform-posix.cc (working copy) @@ -70,6 +70,12 @@ } +// 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); Index: src/platform-win32.cc =================================================================== --- src/platform-win32.cc (revision 8697) +++ src/platform-win32.cc (working copy) @@ -957,6 +957,12 @@ } +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); Index: src/platform.h =================================================================== --- src/platform.h (revision 8697) +++ src/platform.h (working copy) @@ -207,6 +207,9 @@ 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); Index: src/x64/codegen-x64.cc =================================================================== --- src/x64/codegen-x64.cc (revision 8697) +++ src/x64/codegen-x64.cc (working copy) @@ -132,6 +132,7 @@ CodeDesc desc; masm.GetCode(&desc); + OS::ProtectCode(buffer, actual_size); // Call the function from C++ through this pointer. return FUNCTION_CAST<ModuloFunction>(buffer); } -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev
