Skip to content

Commit

Permalink
Linux: Also optimize HandleNewClone stack usage
Browse files Browse the repository at this point in the history
Drops from ~1392 bytes of stack usage to ~80 bytes
  • Loading branch information
Sonicadvance1 committed Sep 22, 2024
1 parent 58bcf69 commit f5def7a
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,17 @@ uint64_t HandleNewClone(FEX::HLE::ThreadStateObject* Thread, FEXCore::Context::C
bool CreatedNewThreadObject {};

if (flags & CLONE_THREAD) {
FEXCore::Core::CPUState NewThreadState {};
// Clone copies the parent thread's state
memcpy(&NewThreadState, Frame, sizeof(FEXCore::Core::CPUState));
// Overwrite thread
NewThread = FEX::HLE::_SyscallHandler->TM.CreateThread(0, 0, &Frame->State, GuestArgs->parent_tid,
FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame));

NewThreadState.gregs[FEXCore::X86State::REG_RAX] = 0;
NewThread->Thread->CurrentFrame->State.gregs[FEXCore::X86State::REG_RAX] = 0;
if (GuestArgs->stack == 0) {
// Copies in the original thread's stack
} else {
NewThreadState.gregs[FEXCore::X86State::REG_RSP] = GuestArgs->stack;
NewThread->Thread->CurrentFrame->State.gregs[FEXCore::X86State::REG_RSP] = GuestArgs->stack;
}

// Overwrite thread
NewThread = FEX::HLE::_SyscallHandler->TM.CreateThread(0, 0, &NewThreadState, GuestArgs->parent_tid,
FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame));

// CLONE_PARENT_SETTID, CLONE_CHILD_SETTID, CLONE_CHILD_CLEARTID, CLONE_PIDFD will be handled by kernel
// Call execution thread directly since we already are on the new thread
NewThread->Thread->StartRunning.NotifyAll(); // Clear the start running flag
Expand Down

0 comments on commit f5def7a

Please sign in to comment.