Fix flag to switch write protection of code pages on/off.

TBR=iposva@google.com

Review URL: https://codereview.chromium.org//138913016

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32549 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
fschneider@google.com 2014-02-11 10:17:03 +00:00
parent e53a075ecc
commit 78fbacbd87
7 changed files with 24 additions and 2 deletions

View file

@ -70,6 +70,7 @@ DECLARE_FLAG(bool, trace_deoptimization);
DECLARE_FLAG(bool, trace_deoptimization_verbose);
DECLARE_FLAG(bool, verbose_stacktrace);
DECLARE_FLAG(charp, coverage_dir);
DECLARE_FLAG(bool, write_protect_code);
static const char* kGetterPrefix = "get:";
static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix);
@ -10228,7 +10229,9 @@ RawCode* Code::FinalizeCode(const char* name,
bool status =
VirtualMemory::Protect(reinterpret_cast<void*>(instrs.raw_ptr()),
instrs.raw()->Size(),
VirtualMemory::kReadExecute);
FLAG_write_protect_code
? VirtualMemory::kReadExecute
: VirtualMemory::kReadWriteExecute);
ASSERT(status);
}
return code.raw();

View file

@ -17,6 +17,8 @@
namespace dart {
DECLARE_FLAG(bool, write_protect_code);
static RawLibrary* CreateDummyLibrary(const String& library_name) {
return Library::New(library_name);
}
@ -2486,6 +2488,11 @@ TEST_CASE(CodeImmutability) {
#endif
EXPECT_EQ(3, retval);
EXPECT_EQ(instructions.raw(), Instructions::FromEntryPoint(entry_point));
if (!FLAG_write_protect_code) {
// Since this test is expected to crash, crash if write protection of code
// is switched off.
OS::DebugBreak();
}
}

View file

@ -13,12 +13,12 @@ namespace dart {
class VirtualMemory {
public:
// Read-write-execute is not available because it is never used.
enum Protection {
kNoAccess,
kReadOnly,
kReadWrite,
kReadExecute,
kReadWriteExecute
};
// The reserved memory is unmapped on destruction.

View file

@ -94,6 +94,9 @@ bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) {
case kReadExecute:
prot = PROT_READ | PROT_EXEC;
break;
case kReadWriteExecute:
prot = PROT_READ | PROT_WRITE | PROT_EXEC;
break;
}
return (mprotect(reinterpret_cast<void*>(page_address),
end_address - page_address,

View file

@ -94,6 +94,9 @@ bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) {
case kReadExecute:
prot = PROT_READ | PROT_EXEC;
break;
case kReadWriteExecute:
prot = PROT_READ | PROT_WRITE | PROT_EXEC;
break;
}
return (mprotect(reinterpret_cast<void*>(page_address),
end_address - page_address,

View file

@ -94,6 +94,9 @@ bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) {
case kReadExecute:
prot = PROT_READ | PROT_EXEC;
break;
case kReadWriteExecute:
prot = PROT_READ | PROT_WRITE | PROT_EXEC;
break;
}
return (mprotect(reinterpret_cast<void*>(page_address),
end_address - page_address,

View file

@ -82,6 +82,9 @@ bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) {
case kReadExecute:
prot = PAGE_EXECUTE_READ;
break;
case kReadWriteExecute:
prot = PAGE_EXECUTE_READWRITE;
break;
}
DWORD old_prot = 0;
bool result = VirtualProtect(reinterpret_cast<void*>(page_address),