From b15e49910aef03236ec651d806e6251ae9d43f11 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Tue, 22 Jul 2025 19:07:28 +0100 Subject: [PATCH] WOW64: Support inline SMC Matches the ARM64EC handling --- Source/Windows/WOW64/Module.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Source/Windows/WOW64/Module.cpp b/Source/Windows/WOW64/Module.cpp index 2c0bb44e4..5e6397aa2 100644 --- a/Source/Windows/WOW64/Module.cpp +++ b/Source/Windows/WOW64/Module.cpp @@ -756,7 +756,19 @@ bool BTCpuResetToConsistentStateImpl(EXCEPTION_POINTERS* Ptrs) { std::scoped_lock Lock(ThreadCreationMutex); FEXCORE_PROFILE_INSTANT_INCREMENT(Thread, AccumulatedSMCCount, 1); if (InvalidationTracker->HandleRWXAccessViolation(FaultAddress)) { - LogMan::Msg::DFmt("Handled self-modifying code: pc: {:X} fault: {:X}", Context->Pc, FaultAddress); + if (CTX->IsAddressInCodeBuffer(Thread, Context->Pc) && !CTX->IsCurrentBlockSingleInst(Thread) && + CTX->IsAddressInCurrentBlock(Thread, FaultAddress & FEXCore::Utils::FEX_PAGE_MASK, FEXCore::Utils::FEX_PAGE_SIZE)) { + Context::ReconstructThreadState(Context); + LogMan::Msg::DFmt("Handled inline self-modifying code: pc: {:X} rip: {:X} fault: {:X}", Context->Pc, + Thread->CurrentFrame->State.rip, FaultAddress); + + // Adjust context to return to the dispatcher, reloading SRA from thread state + const auto& Config = SignalDelegator->GetConfig(); + Context->Pc = Config.AbsoluteLoopTopAddressFillSRA; + Context->X1 = 1; // Set ENTRY_FILL_SRA_SINGLE_INST_REG to force a single step + } else { + LogMan::Msg::DFmt("Handled self-modifying code: pc: {:X} fault: {:X}", Context->Pc, FaultAddress); + } return true; } }