From f7a076e00c6b6bc30f85b0fcd9998d2e972a0af7 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Thu, 28 Nov 2024 20:55:11 -0800 Subject: [PATCH] FEXCore: Removes ExitReason from InternalThreadState FEXCore hasn't been returning anything other than EXIT_SHUTDOWN for a long time, so this ended up just moving data around for no reason. This isn't going to be used for further GdbServer work anyway, so just completely remove it. --- FEXCore/Source/Interface/Context/Context.h | 2 +- FEXCore/Source/Interface/Core/Core.cpp | 10 ++-------- FEXCore/include/FEXCore/Core/Context.h | 14 ++------------ .../include/FEXCore/Debug/InternalThreadState.h | 1 - Source/Tools/FEXLoader/FEXLoader.cpp | 15 ++------------- .../LinuxEmulation/LinuxSyscalls/GdbServer.cpp | 10 +--------- 6 files changed, 8 insertions(+), 44 deletions(-) diff --git a/FEXCore/Source/Interface/Context/Context.h b/FEXCore/Source/Interface/Context/Context.h index 4ff08764f0..857e1a8217 100644 --- a/FEXCore/Source/Interface/Context/Context.h +++ b/FEXCore/Source/Interface/Context/Context.h @@ -84,7 +84,7 @@ class ContextImpl final : public FEXCore::Context::Context { void SetExitHandler(ExitHandler handler) override; ExitHandler GetExitHandler() const override; - ExitReason RunUntilExit(FEXCore::Core::InternalThreadState* Thread) override; + void RunUntilExit(FEXCore::Core::InternalThreadState* Thread) override; void ExecuteThread(FEXCore::Core::InternalThreadState* Thread) override; diff --git a/FEXCore/Source/Interface/Core/Core.cpp b/FEXCore/Source/Interface/Core/Core.cpp index 0dc9ed9de7..385e998865 100644 --- a/FEXCore/Source/Interface/Core/Core.cpp +++ b/FEXCore/Source/Interface/Core/Core.cpp @@ -363,17 +363,14 @@ void ContextImpl::HandleCallback(FEXCore::Core::InternalThreadState* Thread, uin static_cast(Thread->CTX)->Dispatcher->ExecuteJITCallback(Thread->CurrentFrame, RIP); } -FEXCore::Context::ExitReason ContextImpl::RunUntilExit(FEXCore::Core::InternalThreadState* Thread) { +void ContextImpl::RunUntilExit(FEXCore::Core::InternalThreadState* Thread) { ExecutionThread(Thread); CoreShuttingDown.store(true); if (CustomExitHandler) { - CustomExitHandler(Thread, FEXCore::Context::ExitReason::EXIT_SHUTDOWN); - return Thread->ExitReason; + CustomExitHandler(Thread); } - - return FEXCore::Context::ExitReason::EXIT_SHUTDOWN; } void ContextImpl::ExecuteThread(FEXCore::Core::InternalThreadState* Thread) { @@ -871,7 +868,6 @@ uintptr_t ContextImpl::CompileBlock(FEXCore::Core::CpuStateFrame* Frame, uint64_ } void ContextImpl::ExecutionThread(FEXCore::Core::InternalThreadState* Thread) { - Thread->ExitReason = FEXCore::Context::ExitReason::EXIT_WAITING; if (Thread->StartPaused) { // Parent thread doesn't need to wait to run @@ -880,8 +876,6 @@ void ContextImpl::ExecutionThread(FEXCore::Core::InternalThreadState* Thread) { Thread->RunningEvents.WaitingToStart = false; - Thread->ExitReason = FEXCore::Context::ExitReason::EXIT_NONE; - Thread->RunningEvents.Running = true; static_cast(Thread->CTX)->Dispatcher->ExecuteDispatch(Thread->CurrentFrame); diff --git a/FEXCore/include/FEXCore/Core/Context.h b/FEXCore/include/FEXCore/Core/Context.h index 8094d20311..c6db1adeb1 100644 --- a/FEXCore/include/FEXCore/Core/Context.h +++ b/FEXCore/include/FEXCore/Core/Context.h @@ -44,14 +44,6 @@ class IREmitter; namespace FEXCore::Context { class Context; -enum ExitReason { - EXIT_NONE, - EXIT_WAITING, - EXIT_ASYNC_RUN, - EXIT_SHUTDOWN, - EXIT_DEBUG, - EXIT_UNKNOWNERROR, -}; enum OperatingMode { MODE_32BIT, @@ -73,7 +65,7 @@ using CodeRangeInvalidationFn = std::function; -using ExitHandler = std::function; +using ExitHandler = std::function; using AOTIRCodeFileWriterFn = std::function; using AOTIRLoaderCBFn = std::function; @@ -112,10 +104,8 @@ class Context { * has shutdown. * * @param CTX The context that we created - * - * @return The ExitReason for the parentthread. */ - FEX_DEFAULT_VISIBILITY virtual ExitReason RunUntilExit(FEXCore::Core::InternalThreadState* Thread) = 0; + FEX_DEFAULT_VISIBILITY virtual void RunUntilExit(FEXCore::Core::InternalThreadState* Thread) = 0; /** * @brief Executes the supplied thread context on the current thread until a return is requested diff --git a/FEXCore/include/FEXCore/Debug/InternalThreadState.h b/FEXCore/include/FEXCore/Debug/InternalThreadState.h index 5ce663de39..b5a888bf12 100644 --- a/FEXCore/include/FEXCore/Debug/InternalThreadState.h +++ b/FEXCore/include/FEXCore/Debug/InternalThreadState.h @@ -101,7 +101,6 @@ struct InternalThreadState : public FEXCore::Allocator::FEXAllocOperators { NonMovableUniquePtr PassManager; NonMovableUniquePtr SymbolBuffer; - FEXCore::Context::ExitReason ExitReason {FEXCore::Context::ExitReason::EXIT_WAITING}; std::shared_ptr CompileService; std::shared_mutex ObjectCacheRefCounter {}; diff --git a/Source/Tools/FEXLoader/FEXLoader.cpp b/Source/Tools/FEXLoader/FEXLoader.cpp index 925a06b671..053af847f4 100644 --- a/Source/Tools/FEXLoader/FEXLoader.cpp +++ b/Source/Tools/FEXLoader/FEXLoader.cpp @@ -604,16 +604,9 @@ int main(int argc, char** argv, char** const envp) { SyscallHandler->DeserializeSeccompFD(ParentThread, FEXSeccompFD); - FEXCore::Context::ExitReason ShutdownReason = FEXCore::Context::ExitReason::EXIT_SHUTDOWN; - // There might already be an exit handler, leave it installed if (!CTX->GetExitHandler()) { - CTX->SetExitHandler([&](FEXCore::Core::InternalThreadState* Thread, FEXCore::Context::ExitReason reason) { - if (reason != FEXCore::Context::ExitReason::EXIT_DEBUG) { - ShutdownReason = reason; - SyscallHandler->TM.Stop(); - } - }); + CTX->SetExitHandler([&](FEXCore::Core::InternalThreadState* Thread) { SyscallHandler->TM.Stop(); }); } const bool AOTEnabled = AOTIRLoad() || AOTIRCapture() || AOTIRGenerate(); @@ -704,9 +697,5 @@ int main(int argc, char** argv, char** const envp) { FEXCore::Allocator::ReenableSBRKAllocations(SBRKPointer); - if (ShutdownReason == FEXCore::Context::ExitReason::EXIT_SHUTDOWN) { - return ProgramStatus; - } else { - return -64 | ShutdownReason; - } + return ProgramStatus; } diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/GdbServer.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/GdbServer.cpp index 001b946623..91fa1ef08c 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/GdbServer.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/GdbServer.cpp @@ -96,15 +96,7 @@ GdbServer::GdbServer(FEXCore::Context::Context* ctx, FEX::HLE::SignalDelegator* // Pass all signals by default std::fill(PassSignals.begin(), PassSignals.end(), true); - ctx->SetExitHandler([this](FEXCore::Core::InternalThreadState* Thread, FEXCore::Context::ExitReason ExitReason) { - if (ExitReason == FEXCore::Context::ExitReason::EXIT_DEBUG) { - this->Break(Thread, SIGTRAP); - } - - if (ExitReason == FEXCore::Context::ExitReason::EXIT_SHUTDOWN) { - CoreShuttingDown = true; - } - }); + ctx->SetExitHandler([this](FEXCore::Core::InternalThreadState* Thread) { CoreShuttingDown = true; }); // This is a total hack as there is currently no way to resume once hitting a segfault // But it's semi-useful for debugging.