Skip to content

Commit

Permalink
Merge pull request FEX-Emu#3441 from Sonicadvance1/remove_signaldeleg…
Browse files Browse the repository at this point in the history
…ation_tls

Moves SignalDelegator TLS tracking to the frontend
  • Loading branch information
Sonicadvance1 authored Feb 24, 2024
2 parents cf06799 + 0a64f8a commit 9b93495
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 15 deletions.
3 changes: 0 additions & 3 deletions FEXCore/Source/Interface/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ namespace FEXCore::Context {
Thread->ThreadManager.TID = FHU::Syscalls::gettid();
Thread->ThreadManager.PID = ::getpid();

SignalDelegation->RegisterTLSState(Thread);
if (ThunkHandler) {
ThunkHandler->RegisterTLSState(Thread);
}
Expand Down Expand Up @@ -428,7 +427,6 @@ namespace FEXCore::Context {
#ifndef _WIN32
Alloc::OSAllocator::UninstallTLSData(Thread);
#endif
SignalDelegation->UninstallTLSState(Thread);
}

FEXCore::Allocator::VirtualFree(reinterpret_cast<void*>(Thread->CurrentFrame->State.DeferredSignalFaultAddress), 4096);
Expand Down Expand Up @@ -915,7 +913,6 @@ namespace FEXCore::Context {
#ifndef _WIN32
Alloc::OSAllocator::UninstallTLSData(Thread);
#endif
SignalDelegation->UninstallTLSState(Thread);
}

static void InvalidateGuestThreadCodeRange(FEXCore::Core::InternalThreadState *Thread, uint64_t Start, uint64_t Length) {
Expand Down
8 changes: 0 additions & 8 deletions FEXCore/include/FEXCore/Core/SignalDelegator.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ namespace Core {
public:
virtual ~SignalDelegator() = default;

/**
* @brief Registers an emulated thread's object to a TLS object
*
* Required to know which thread has received the signal when it occurs
*/
virtual void RegisterTLSState(FEXCore::Core::InternalThreadState *Thread) = 0;
virtual void UninstallTLSState(FEXCore::Core::InternalThreadState *Thread) = 0;

struct SignalDelegatorConfig {
bool SupportsAVX{};

Expand Down
4 changes: 2 additions & 2 deletions Source/Tools/CommonTools/DummyHandlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class DummySignalDelegator final : public FEXCore::SignalDelegator, public FEXCo
}

protected:
void RegisterTLSState(FEXCore::Core::InternalThreadState *Thread) override;
void UninstallTLSState(FEXCore::Core::InternalThreadState *Thread) override;
void RegisterTLSState(FEXCore::Core::InternalThreadState *Thread);
void UninstallTLSState(FEXCore::Core::InternalThreadState *Thread);

private:
FEXCore::Core::InternalThreadState *GetTLSThread();
Expand Down
2 changes: 2 additions & 0 deletions Source/Tools/FEXLoader/FEXLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ int main(int argc, char **argv, char **const envp) {

auto ParentThread = SyscallHandler->TM.CreateThread(Loader.DefaultRIP(), Loader.GetStackPointer());
SyscallHandler->TM.TrackThread(ParentThread);
SignalDelegation->RegisterTLSState(ParentThread);

// Pass in our VDSO thunks
CTX->AppendThunkDefinitions(FEX::VDSO::GetVDSOThunkDefinitions());
Expand Down Expand Up @@ -561,6 +562,7 @@ int main(int argc, char **argv, char **const envp) {

auto ProgramStatus = ParentThread->StatusCode;

SignalDelegation->UninstallTLSState(ParentThread);
CTX->DestroyThread(ParentThread);

DebugServer.reset();
Expand Down
4 changes: 2 additions & 2 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ namespace FEX::HLE {
// Called from the signal trampoline function.
void HandleSignal(int Signal, void *Info, void *UContext);

void RegisterTLSState(FEXCore::Core::InternalThreadState *Thread) override;
void UninstallTLSState(FEXCore::Core::InternalThreadState *Thread) override;
void RegisterTLSState(FEXCore::Core::InternalThreadState *Thread);
void UninstallTLSState(FEXCore::Core::InternalThreadState *Thread);

/**
* @brief Registers a signal handler for the host to handle a signal
Expand Down
6 changes: 6 additions & 0 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ namespace FEX::HLE {
auto CTX = Handler->CTX;
auto Thread = Handler->Thread;
FEXCore::Allocator::free(Handler);
FEX::HLE::_SyscallHandler->GetSignalDelegator()->RegisterTLSState(Thread);
CTX->ExecutionThread(Thread);
FEX::HLE::_SyscallHandler->GetSignalDelegator()->UninstallTLSState(Thread);
FEX::HLE::_SyscallHandler->TM.DestroyThread(Thread);
return nullptr;
}
Expand Down Expand Up @@ -221,10 +223,14 @@ namespace FEX::HLE {
FEX::HLE::_SyscallHandler->TM.TrackThread(Thread);
}

FEX::HLE::_SyscallHandler->GetSignalDelegator()->RegisterTLSState(Thread);

// Start exuting the thread directly
// Our host clone starts in a new stack space, so it can't return back to the JIT space
CTX->ExecutionThread(Thread);

FEX::HLE::_SyscallHandler->GetSignalDelegator()->UninstallTLSState(Thread);

// The rest of the context remains as is and the thread will continue executing
return Thread->StatusCode;
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Tools/TestHarnessRunner/TestHarnessRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ int main(int argc, char **argv, char **const envp) {
return 1;
}
auto ParentThread = CTX->CreateThread(Loader.DefaultRIP(), Loader.GetStackPointer());
SignalDelegation->RegisterTLSState(ParentThread);

if (!ParentThread) {
return 1;
Expand All @@ -324,6 +325,7 @@ int main(int argc, char **argv, char **const envp) {

SyscallHandler.reset();

SignalDelegation->UninstallTLSState(ParentThread);
CTX->DestroyThread(ParentThread, true);
}
#ifndef _WIN32
Expand Down

0 comments on commit 9b93495

Please sign in to comment.