From a5bc54d2d5b242a839f657f758b69f05c7207661 Mon Sep 17 00:00:00 2001 From: FrontMage Date: Fri, 22 May 2026 12:56:44 +0800 Subject: [PATCH] Windows: Preserve INT 0x2D exception parameter source --- Source/Windows/ARM64EC/Module.cpp | 2 +- Source/Windows/Common/Exception.h | 4 ++-- Source/Windows/WOW64/Module.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Windows/ARM64EC/Module.cpp b/Source/Windows/ARM64EC/Module.cpp index 51ad45083..2e04181c6 100644 --- a/Source/Windows/ARM64EC/Module.cpp +++ b/Source/Windows/ARM64EC/Module.cpp @@ -496,7 +496,7 @@ static void RethrowGuestException(const EXCEPTION_RECORD& Rec, ARM64_NT_CONTEXT& EFlags &= ~(1 << FEXCore::X86State::RFLAG_TF_RAW_LOC); CTX->SetFlagsFromCompactedEFLAGS(Thread, EFlags); - Args->Rec = FEX::Windows::HandleGuestException(Fault, Rec, Args->Context.Pc, Args->Context.X0); + Args->Rec = FEX::Windows::HandleGuestException(Fault, Rec, Args->Context.Pc, Args->Context.X8, Args->Context.X0); if (Args->Rec.ExceptionCode == EXCEPTION_SINGLE_STEP) { Args->Context.Cpsr &= ~(1 << 21); // PSTATE.SS } else if (Args->Rec.ExceptionCode == EXCEPTION_BREAKPOINT) { diff --git a/Source/Windows/Common/Exception.h b/Source/Windows/Common/Exception.h index b606c4444..7ff206551 100644 --- a/Source/Windows/Common/Exception.h +++ b/Source/Windows/Common/Exception.h @@ -11,7 +11,7 @@ namespace FEX::Windows { template static inline EXCEPTION_RECORD -HandleGuestException(FEXCore::Core::CpuStateFrame::SynchronousFaultDataStruct& Fault, const EXCEPTION_RECORD& Src, TReg& Rip, TReg Cx) { +HandleGuestException(FEXCore::Core::CpuStateFrame::SynchronousFaultDataStruct& Fault, const EXCEPTION_RECORD& Src, TReg& Rip, TReg Rax, TReg Cx) { EXCEPTION_RECORD Dst = Src; Dst.ExceptionAddress = reinterpret_cast(Rip); @@ -53,7 +53,7 @@ HandleGuestException(FEXCore::Core::CpuStateFrame::SynchronousFaultDataStruct& F Dst.ExceptionCode = EXCEPTION_BREAKPOINT; Dst.ExceptionAddress = reinterpret_cast(Rip); Dst.NumberParameters = 1; - Dst.ExceptionInformation[0] = Cx; // RCX/ECX + Dst.ExceptionInformation[0] = Rax; // Note that ExceptionAddress doesn't equal the reported context RIP here, this discrepancy expected and not having it can trigger anti-debug logic. return Dst; default: LogMan::Msg::EFmt("Unknown interrupt: 0x{:X}", Fault.err_code >> 3); break; diff --git a/Source/Windows/WOW64/Module.cpp b/Source/Windows/WOW64/Module.cpp index e49a874f4..c61fe62d8 100644 --- a/Source/Windows/WOW64/Module.cpp +++ b/Source/Windows/WOW64/Module.cpp @@ -932,7 +932,7 @@ bool BTCpuResetToConsistentStateImpl(EXCEPTION_POINTERS* Ptrs) { LogMan::Msg::DFmt("pc: {:X} eip: {:X}", Context->Pc, WowContext.Eip); auto& Fault = Thread->CurrentFrame->SynchronousFaultData; - *Exception = FEX::Windows::HandleGuestException(Fault, *Exception, WowContext.Eip, WowContext.Ecx); + *Exception = FEX::Windows::HandleGuestException(Fault, *Exception, WowContext.Eip, WowContext.Eax, WowContext.Ecx); if (Exception->ExceptionCode == EXCEPTION_SINGLE_STEP) { WowContext.EFlags &= ~(1 << FEXCore::X86State::RFLAG_TF_RAW_LOC); }