Skip to content

Commit

Permalink
Merge pull request #4181 from Sonicadvance1/remove_exitreason
Browse files Browse the repository at this point in the history
FEXCore: Removes ExitReason from InternalThreadState
  • Loading branch information
Sonicadvance1 authored Nov 29, 2024
2 parents 56fadec + f7a076e commit f59fc0f
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 44 deletions.
2 changes: 1 addition & 1 deletion FEXCore/Source/Interface/Context/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 2 additions & 8 deletions FEXCore/Source/Interface/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,17 +363,14 @@ void ContextImpl::HandleCallback(FEXCore::Core::InternalThreadState* Thread, uin
static_cast<ContextImpl*>(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) {
Expand Down Expand Up @@ -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
Expand All @@ -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<ContextImpl*>(Thread->CTX)->Dispatcher->ExecuteDispatch(Thread->CurrentFrame);
Expand Down
14 changes: 2 additions & 12 deletions FEXCore/include/FEXCore/Core/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -73,7 +65,7 @@ using CodeRangeInvalidationFn = std::function<void(uint64_t start, uint64_t Leng

using CustomIREntrypointHandler = std::function<void(uintptr_t Entrypoint, IR::IREmitter*)>;

using ExitHandler = std::function<void(Core::InternalThreadState* Thread, ExitReason)>;
using ExitHandler = std::function<void(Core::InternalThreadState* Thread)>;

using AOTIRCodeFileWriterFn = std::function<void(const fextl::string& fileid, const fextl::string& filename)>;
using AOTIRLoaderCBFn = std::function<int(const fextl::string&)>;
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion FEXCore/include/FEXCore/Debug/InternalThreadState.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ struct InternalThreadState : public FEXCore::Allocator::FEXAllocOperators {
NonMovableUniquePtr<FEXCore::IR::PassManager> PassManager;
NonMovableUniquePtr<JITSymbolBuffer> SymbolBuffer;

FEXCore::Context::ExitReason ExitReason {FEXCore::Context::ExitReason::EXIT_WAITING};
std::shared_ptr<FEXCore::CompileService> CompileService;

std::shared_mutex ObjectCacheRefCounter {};
Expand Down
15 changes: 2 additions & 13 deletions Source/Tools/FEXLoader/FEXLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/GdbServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f59fc0f

Please sign in to comment.