Skip to content

Commit

Permalink
Merge pull request FEX-Emu#4200 from Sonicadvance1/fix_exit
Browse files Browse the repository at this point in the history
LinuxSyscalls: Fixes exit syscall
  • Loading branch information
lioncash authored Dec 9, 2024
2 parents f8b6edf + beec203 commit bdae4f6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,10 @@ void RegisterThread(FEX::HLE::SyscallHandler* Handler) {
}

ThreadObject->StatusCode = status;
FEX::HLE::_SyscallHandler->TM.StopThread(ThreadObject);

return 0;
FEX::HLE::_SyscallHandler->TM.DestroyThread(ThreadObject, true);
syscall(SYSCALL_DEF(exit), status);
// This will never be reached
std::terminate();
});

REGISTER_SYSCALL_IMPL_FLAGS(prctl, SyscallFlags::OPTIMIZETHROUGH | SyscallFlags::NOSYNCSTATEONENTRY,
Expand Down
35 changes: 35 additions & 0 deletions unittests/FEXLinuxTests/tests/syscalls/syscall_exit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <catch2/catch_test_macros.hpp>

#include <unistd.h>
#include <sys/wait.h>
#include <sys/syscall.h>

TEST_CASE("fork - exit") {
int child_pid = ::fork();
if (child_pid == 0) {
::syscall(SYS_exit, 1);
// unreachable
std::terminate();
} else {
int status {};
int exited_child = ::waitpid(child_pid, &status, 0);
bool exited = WIFEXITED(status);
REQUIRE(WIFEXITED(status) == 1);
CHECK(WEXITSTATUS(status) == 1);
}
}

TEST_CASE("fork - signal") {
int child_pid = ::fork();
if (child_pid == 0) {
::syscall(SYS_tgkill, ::getpid(), ::gettid(), SIGKILL);
// unreachable
std::terminate();
} else {
int status {};
int exited_child = ::waitpid(child_pid, &status, 0);
bool exited = WIFEXITED(status);
REQUIRE(WIFSIGNALED(status) == 1);
CHECK(WTERMSIG(status) == SIGKILL);
}
}

0 comments on commit bdae4f6

Please sign in to comment.