From 8235de9829e12a0c087422905d6e50fb344fe08e Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 30 May 2021 22:30:51 +0100 Subject: [PATCH] {a32,a64}_emit_x64: Fix fast_dispatch_table_lookup call in Unpatch on W^X systems fast_dispatch_table_lookup is in JITted code, and thus execution must be enabled before it can be called. --- src/dynarmic/backend/x64/a32_emit_x64.cpp | 2 ++ src/dynarmic/backend/x64/a64_emit_x64.cpp | 16 +++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/dynarmic/backend/x64/a32_emit_x64.cpp b/src/dynarmic/backend/x64/a32_emit_x64.cpp index 4ed451c9..e2c56b21 100644 --- a/src/dynarmic/backend/x64/a32_emit_x64.cpp +++ b/src/dynarmic/backend/x64/a32_emit_x64.cpp @@ -1680,7 +1680,9 @@ void A32EmitX64::EmitPatchMovRcx(CodePtr target_code_ptr) { void A32EmitX64::Unpatch(const IR::LocationDescriptor& location) { EmitX64::Unpatch(location); if (conf.HasOptimization(OptimizationFlag::FastDispatch)) { + code.DisableWriting(); (*fast_dispatch_table_lookup)(location.Value()) = {}; + code.EnableWriting(); } } diff --git a/src/dynarmic/backend/x64/a64_emit_x64.cpp b/src/dynarmic/backend/x64/a64_emit_x64.cpp index 539d1ed7..d591b716 100644 --- a/src/dynarmic/backend/x64/a64_emit_x64.cpp +++ b/src/dynarmic/backend/x64/a64_emit_x64.cpp @@ -62,7 +62,7 @@ A64EmitX64::A64EmitX64(BlockOfCode& code, A64::UserConfig conf, A64::Jit* jit_in code.PreludeComplete(); ClearFastDispatchTable(); - exception_handler.SetFastmemCallback([this](u64 rip_){ + exception_handler.SetFastmemCallback([this](u64 rip_) { return FastmemCallback(rip_); }); } @@ -990,8 +990,7 @@ void A64EmitX64::EmitMemoryRead(A64EmitContext& ctx, IR::Inst* inst) { Common::BitCast(code.getCurr()), Common::BitCast(wrapped_fn), *fastmem_marker, - } - ); + }); } else { // Use page table ASSERT(conf.page_table); @@ -1045,8 +1044,7 @@ void A64EmitX64::EmitMemoryWrite(A64EmitContext& ctx, IR::Inst* inst) { Common::BitCast(code.getCurr()), Common::BitCast(wrapped_fn), *fastmem_marker, - } - ); + }); } else { // Use page table ASSERT(conf.page_table); @@ -1114,8 +1112,7 @@ void A64EmitX64::EmitA64ReadMemory128(A64EmitContext& ctx, IR::Inst* inst) { Common::BitCast(code.getCurr()), Common::BitCast(wrapped_fn), *fastmem_marker, - } - ); + }); } else { // Use page table ASSERT(conf.page_table); @@ -1187,8 +1184,7 @@ void A64EmitX64::EmitA64WriteMemory128(A64EmitContext& ctx, IR::Inst* inst) { Common::BitCast(code.getCurr()), Common::BitCast(wrapped_fn), *fastmem_marker, - } - ); + }); } else { // Use page table ASSERT(conf.page_table); @@ -1481,7 +1477,9 @@ void A64EmitX64::EmitPatchMovRcx(CodePtr target_code_ptr) { void A64EmitX64::Unpatch(const IR::LocationDescriptor& location) { EmitX64::Unpatch(location); if (conf.HasOptimization(OptimizationFlag::FastDispatch)) { + code.DisableWriting(); (*fast_dispatch_table_lookup)(location.Value()) = {}; + code.EnableWriting(); } }