From 4ecd1bffdac1969e1431a0a1f2e48cb6c6c8543b Mon Sep 17 00:00:00 2001 From: Emma Date: Mon, 23 Jan 2023 22:44:59 +0000 Subject: [PATCH] Add configurable toggle to mark code segments as writable (#100) --- src/xenia/cpu/xex_module.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/xenia/cpu/xex_module.cc b/src/xenia/cpu/xex_module.cc index 4e997579f..de9ddf26d 100644 --- a/src/xenia/cpu/xex_module.cc +++ b/src/xenia/cpu/xex_module.cc @@ -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);