From 730fe7e7c63bf822c1362310b07e946c959e5871 Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Thu, 3 Dec 2026 05:27:11 -0500 Subject: [PATCH] Diagnostic: log kill, prctl and thread exit --- tools/fex/patches/0029-diag-ptrace.patch | 69 +++++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/tools/fex/patches/0029-diag-ptrace.patch b/tools/fex/patches/0029-diag-ptrace.patch index 31f4c45293..c7135f7f3e 100644 --- a/tools/fex/patches/0029-diag-ptrace.patch +++ b/tools/fex/patches/0029-diag-ptrace.patch @@ -85,8 +85,57 @@ index d2626fd..1dc85de 100644 switch (ActionMasked) { // Unknown actions behave like RET_KILL_PROCESS. default: +diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Passthrough.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Passthrough.cpp +index 602e175..de49917 100644 +--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Passthrough.cpp ++++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Passthrough.cpp +@@ -13,6 +13,7 @@ $end_info$ + #include "LinuxSyscalls/SignalTrace.h" + + #include ++#include + #include + #include + #include +@@ -303,6 +304,7 @@ static void RegisterCommon(FEX::HLE::SyscallHandler* Handler) { + if (SigTrace::Enabled()) { + SigTrace::Log(::syscall(SYS_gettid), SigTrace::Kill, sig, pid, 0); + } ++ ::dprintf(2, "DDPT %d/%ld kill pid=%d sig=%d\n", ::getpid(), ::syscall(SYS_gettid), pid, sig); + uint64_t Result = ::syscall(SYSCALL_DEF(kill), pid, sig); + SYSCALL_ERRNO(); + }); +@@ -372,6 +374,7 @@ static void RegisterCommon(FEX::HLE::SyscallHandler* Handler) { + if (SigTrace::Enabled()) { + SigTrace::Log(::syscall(SYS_gettid), SigTrace::Kill, sig, tid, 0); + } ++ ::dprintf(2, "DDPT %d/%ld tkill tid=%d sig=%d\n", ::getpid(), ::syscall(SYS_gettid), tid, sig); + uint64_t Result = ::syscall(SYSCALL_DEF(tkill), tid, sig); + SYSCALL_ERRNO(); + }); +@@ -388,6 +391,7 @@ static void RegisterCommon(FEX::HLE::SyscallHandler* Handler) { + if (SigTrace::Enabled()) { + SigTrace::Log(::syscall(SYS_gettid), SigTrace::Kill, sig, tid, tgid); + } ++ if (tgid != ::getpid() || (sig != 10 && sig != 12 && sig < 32)) ::dprintf(2, "DDPT %d/%ld tgkill tgid=%d tid=%d sig=%d\n", ::getpid(), ::syscall(SYS_gettid), tgid, tid, sig); + uint64_t Result = ::syscall(SYSCALL_DEF(tgkill), tgid, tid, sig); + SYSCALL_ERRNO(); + }); +@@ -582,7 +586,11 @@ namespace x64 { + REGISTER_SYSCALL_IMPL_X64(preadv2, SyscallPassthrough6); + REGISTER_SYSCALL_IMPL_X64(pwritev2, SyscallPassthrough6); + REGISTER_SYSCALL_IMPL_X64(io_pgetevents, SyscallPassthrough6); +- REGISTER_SYSCALL_IMPL_X64(pidfd_send_signal, SyscallPassthrough4); ++ REGISTER_SYSCALL_IMPL_X64(pidfd_send_signal, [](FEXCore::Core::CpuStateFrame* Frame, int pidfd, int sig, void* info, unsigned int flags) -> uint64_t { ++ ::dprintf(2, "DDPT %d/%ld pidfd_send_signal fd=%d sig=%d\n", ::getpid(), ::syscall(SYS_gettid), pidfd, sig); ++ uint64_t Result = ::syscall(SYSCALL_DEF(pidfd_send_signal), pidfd, sig, info, flags); ++ SYSCALL_ERRNO(); ++ }); + REGISTER_SYSCALL_IMPL_X64(process_madvise, SyscallPassthrough5); + REGISTER_SYSCALL_IMPL_X64(fadvise64, SyscallPassthrough4); + if (Handler->IsHostKernelVersionAtLeast(6, 5, 0)) { diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp -index de6daa9..6934c59 100644 +index de6daa9..34d110d 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp @@ -5,6 +5,8 @@ tags: LinuxSyscalls|syscalls-shared @@ -98,7 +147,23 @@ index de6daa9..6934c59 100644 #include "CodeLoader.h" #include "LinuxSyscalls/SignalDelegator.h" -@@ -599,6 +601,7 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { +@@ -456,6 +458,7 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { + })); + + REGISTER_SYSCALL_IMPL(exit, [](FEXCore::Core::CpuStateFrame* Frame, int status) -> uint64_t { ++ ::dprintf(2, "DDPT %d/%ld exit status=%d\n", ::getpid(), ::syscall(SYS_gettid), status); + // TLS/DTV teardown is something FEX can't control. Disable glibc checking when we leave a pthread. + // Since this thread is hard stopping, we can't track the TLS/DTV teardown in FEX's thread handling. + FEXCore::Allocator::YesIKnowImNotSupposedToUseTheGlibcAllocator::HardDisable(); +@@ -487,6 +490,7 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { + [](FEXCore::Core::CpuStateFrame* Frame, int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, + unsigned long arg5) -> uint64_t { + uint64_t Result {}; ++ ::dprintf(2, "DDPT %d/%ld prctl op=%d a2=%#lx a3=%#lx\n", ::getpid(), ::syscall(SYS_gettid), option, arg2, arg3); + #ifndef PR_GET_AUXV + #define PR_GET_AUXV 0x41555856 + #endif +@@ -599,6 +603,7 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) { }); REGISTER_SYSCALL_IMPL(exit_group, [](FEXCore::Core::CpuStateFrame* Frame, int status) -> uint64_t {