diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp index 2488387a1..94eb68cef 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp @@ -580,7 +580,6 @@ uint64_t CloneHandler(FEXCore::Core::CpuStateFrame *Frame, FEX::HLE::clone3_args if (!AnyFlagsSet(flags, CLONE_THREAD)) { // Has an unsupported flag // Fall to a handler that can handle this case - auto Thread = Frame->Thread; args->SignalMask = ~0ULL; ::syscall(SYS_rt_sigprocmask, SIG_SETMASK, &args->SignalMask, &args->SignalMask, sizeof(args->SignalMask)); @@ -590,9 +589,7 @@ uint64_t CloneHandler(FEXCore::Core::CpuStateFrame *Frame, FEX::HLE::clone3_args args->StackSize = FEX::LinuxEmulation::Threads::STACK_SIZE; args->NewStack = FEX::LinuxEmulation::Threads::AllocateStackObject(); - Thread->CTX->LockBeforeFork(Frame->Thread); - - FEX::HLE::_SyscallHandler->LockBeforeFork(); + FEX::HLE::_SyscallHandler->LockBeforeFork(Frame->Thread); uint64_t Result{}; if (args->Type == TYPE_CLONE2) { @@ -829,7 +826,8 @@ uint64_t UnimplementedSyscallSafe(FEXCore::Core::CpuStateFrame *Frame, uint64_t return -ENOSYS; } -void SyscallHandler::LockBeforeFork() { +void SyscallHandler::LockBeforeFork(FEXCore::Core::InternalThreadState *Thread) { + Thread->CTX->LockBeforeFork(Thread); VMATracking.Mutex.lock(); } @@ -841,6 +839,8 @@ void SyscallHandler::UnlockAfterFork(FEXCore::Core::InternalThreadState *LiveThr VMATracking.Mutex.unlock(); } + CTX->UnlockAfterFork(LiveThread, Child); + // Clear all the other threads that are being tracked TM.UnlockAfterFork(LiveThread, Child); } diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.h index 7a6030a4e..0ad035479 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.h +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.h @@ -303,7 +303,7 @@ public: FEXCore::HLE::AOTIRCacheEntryLookupResult LookupAOTIRCacheEntry(FEXCore::Core::InternalThreadState *Thread, uint64_t GuestAddr) final override; ///// FORK tracking ///// - void LockBeforeFork(); + void LockBeforeFork(FEXCore::Core::InternalThreadState *Thread); void UnlockAfterFork(FEXCore::Core::InternalThreadState *LiveThread, bool Child); SourcecodeResolver *GetSourcecodeResolver() override { return this; } diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp index 3a766b381..34446ed05 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp @@ -233,9 +233,8 @@ namespace FEX::HLE { uint64_t Mask{~0ULL}; ::syscall(SYS_rt_sigprocmask, SIG_SETMASK, &Mask, &Mask, sizeof(Mask)); - Thread->CTX->LockBeforeFork(Frame->Thread); - FEX::HLE::_SyscallHandler->LockBeforeFork(); + FEX::HLE::_SyscallHandler->LockBeforeFork(Frame->Thread); const bool IsVFork = flags & CLONE_VFORK; pid_t Result{}; diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp index 259de7b35..6c6852ec8 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp @@ -185,8 +185,6 @@ namespace FEX::HLE { } void ThreadManager::UnlockAfterFork(FEXCore::Core::InternalThreadState *LiveThread, bool Child) { - CTX->UnlockAfterFork(LiveThread, Child); - if (!Child) return; // This function is called after fork