Add configurable toggle to mark code segments as writable (#100)

This commit is contained in:
Emma 2023-01-23 22:44:59 +00:00 committed by GitHub
parent aea9714bd0
commit 4ecd1bffda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -37,6 +37,10 @@ DEFINE_bool(disable_instruction_infocache, false,
"Disables caching records of called instructions/mmio accesses.",
"CPU");
DEFINE_bool(writable_code_segments, false,
"Enables a program to write to its own code segments in memory.",
"CPU");
DEFINE_bool(
enable_early_precompilation, false,
"Enable pre-compiling guest functions that we know we've called/that "
@ -1080,7 +1084,10 @@ bool XexModule::LoadContinue() {
switch (desc.info) {
case XEX_SECTION_CODE:
case XEX_SECTION_READONLY_DATA:
heap->Protect(address, size, kMemoryProtectRead);
heap->Protect(address, size,
cvars::writable_code_segments
? kMemoryProtectRead | kMemoryProtectWrite
: kMemoryProtectRead);
break;
case XEX_SECTION_DATA:
heap->Protect(address, size, kMemoryProtectRead | kMemoryProtectWrite);