From aea4a88e00678aeedd12f76b274fc9edcfb93ada Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 1 Sep 2023 01:53:07 -0700 Subject: [PATCH] Syscalls: Fix telemetry with exit_group Picked up on more games exiting with exit_group that I want to ensure their telemetry data gets saved. Implement support for this. --- .../FEXLoader/LinuxSyscalls/SignalDelegator.cpp | 14 +++++++++----- .../FEXLoader/LinuxSyscalls/SignalDelegator.h | 2 ++ .../FEXLoader/LinuxSyscalls/Syscalls/Thread.cpp | 4 ++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Source/Tools/FEXLoader/LinuxSyscalls/SignalDelegator.cpp b/Source/Tools/FEXLoader/LinuxSyscalls/SignalDelegator.cpp index 6def2faf0..fd797d5d0 100644 --- a/Source/Tools/FEXLoader/LinuxSyscalls/SignalDelegator.cpp +++ b/Source/Tools/FEXLoader/LinuxSyscalls/SignalDelegator.cpp @@ -1540,15 +1540,11 @@ namespace FEX::HLE { (Handler.DefaultBehaviour == DEFAULT_COREDUMP || Handler.DefaultBehaviour == DEFAULT_TERM)) { -#ifndef FEX_DISABLE_TELEMETRY // In the case of signals that cause coredump or terminate, save telemetry early. // FEX is hard crashing at this point and won't hit regular shutdown routines. // Add the signal to the crash mask. CrashMask |= (1ULL << Signal); - if (!ApplicationName.empty()) { - FEXCore::Telemetry::Shutdown(ApplicationName); - } -#endif + SaveTelemetry(); // Reassign back to DFL and crash signal(Signal, SIG_DFL); @@ -1564,6 +1560,14 @@ namespace FEX::HLE { } } + void SignalDelegator::SaveTelemetry() { +#ifndef FEX_DISABLE_TELEMETRY + if (!ApplicationName.empty()) { + FEXCore::Telemetry::Shutdown(ApplicationName); + } +#endif + } + bool SignalDelegator::InstallHostThunk(int Signal) { SignalHandler &SignalHandler = HostHandlers[Signal]; // If the host thunk is already installed for this, just return diff --git a/Source/Tools/FEXLoader/LinuxSyscalls/SignalDelegator.h b/Source/Tools/FEXLoader/LinuxSyscalls/SignalDelegator.h index aaad3c0d8..fd6232b4e 100644 --- a/Source/Tools/FEXLoader/LinuxSyscalls/SignalDelegator.h +++ b/Source/Tools/FEXLoader/LinuxSyscalls/SignalDelegator.h @@ -104,6 +104,8 @@ namespace FEX::HLE { void SignalThread(FEXCore::Core::InternalThreadState *Thread, FEXCore::Core::SignalEvent Event) override; FEX_CONFIG_OPT(ParanoidTSO, PARANOIDTSO); + + void SaveTelemetry(); protected: // Called from the thunk handler to handle the signal void HandleGuestSignal(FEXCore::Core::InternalThreadState *Thread, int Signal, void *Info, void *UContext) override; diff --git a/Source/Tools/FEXLoader/LinuxSyscalls/Syscalls/Thread.cpp b/Source/Tools/FEXLoader/LinuxSyscalls/Syscalls/Thread.cpp index 6f4661f62..1342f27d1 100644 --- a/Source/Tools/FEXLoader/LinuxSyscalls/Syscalls/Thread.cpp +++ b/Source/Tools/FEXLoader/LinuxSyscalls/Syscalls/Thread.cpp @@ -574,6 +574,10 @@ namespace FEX::HLE { REGISTER_SYSCALL_IMPL_PASS_FLAGS(exit_group, SyscallFlags::OPTIMIZETHROUGH | SyscallFlags::NOSYNCSTATEONENTRY | SyscallFlags::NORETURN, [](FEXCore::Core::CpuStateFrame *Frame, int status) -> uint64_t { + + // Save telemetry if we're exiting. + FEX::HLE::_SyscallHandler->GetSignalDelegator()->SaveTelemetry(); + syscall(SYSCALL_DEF(exit_group), status); // This will never be reached std::terminate();