From 67e46ce419c9891053336e1cf4c48f0a91caf69a Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Thu, 3 Dec 2026 07:27:36 -0500 Subject: [PATCH] diag: dump guest stack on blocked SUD traps --- tools/fex/patches/0031-diag-sud.patch | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/fex/patches/0031-diag-sud.patch b/tools/fex/patches/0031-diag-sud.patch index b9321c782b..dce9364420 100644 --- a/tools/fex/patches/0031-diag-sud.patch +++ b/tools/fex/patches/0031-diag-sud.patch @@ -1,5 +1,5 @@ diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.cpp -index 1dc85de..be763fc 100644 +index 1dc85de..dc0b3a1 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Seccomp/SeccompEmulator.cpp @@ -6,6 +6,7 @@ $end_info$ @@ -10,13 +10,20 @@ index 1dc85de..be763fc 100644 #include #include "LinuxSyscalls/Seccomp/BPFEmitter.h" #include "LinuxSyscalls/Seccomp/SeccompEmulator.h" -@@ -365,7 +366,9 @@ SeccompEmulator::ExecuteSyscallUserDispatch(FEXCore::Core::CpuStateFrame* Frame, +@@ -365,7 +366,16 @@ SeccompEmulator::ExecuteSyscallUserDispatch(FEXCore::Core::CpuStateFrame* Frame, if (SUD.Selector) { uint8_t State {}; - if (FaultSafeUserMemAccess::CopyFromUser(&State, reinterpret_cast(SUD.Selector), sizeof(State))) { + const bool SelFault = FaultSafeUserMemAccess::CopyFromUser(&State, reinterpret_cast(SUD.Selector), sizeof(State)); + if (SelFault || State != 0) ::dprintf(2, "DDSUD %d/%ld nr=%lu rip=%#lx off=%#lx len=%#lx sel=%#lx fault=%d state=%u\n", ::getpid(), ::syscall(SYS_gettid), SyscallNumber, PostSyscallRIP, SUD.Offset, SUD.Length, SUD.Selector, SelFault, State); ++ if (SelFault || State != 0) { ++ uint64_t Stk[48] {}; ++ const uint64_t Rsp = Frame->State.gregs[FEXCore::X86State::REG_RSP]; ++ FaultSafeUserMemAccess::CopyFromUser(Stk, reinterpret_cast(Rsp), sizeof(Stk)); ++ ::dprintf(2, "DDSUDCTX %d/%ld mask=%#lx rsp=%#lx rbp=%#lx rdi=%#lx rsi=%#lx\n", ::getpid(), ::syscall(SYS_gettid), static_cast(Thread->SignalInfo.CurrentSignalMask.Val), Rsp, Frame->State.gregs[FEXCore::X86State::REG_RBP], Frame->State.gregs[FEXCore::X86State::REG_RDI], Frame->State.gregs[FEXCore::X86State::REG_RSI]); ++ for (int i = 0; i < 48; i += 6) ::dprintf(2, "DDSTK %d +%#x %#lx %#lx %#lx %#lx %#lx %#lx\n", ::getpid(), i * 8, Stk[i], Stk[i+1], Stk[i+2], Stk[i+3], Stk[i+4], Stk[i+5]); ++ } + if (SelFault) { ForceExitSignal(Thread, SIGSEGV); return {true, SyscallNumber};