Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/libs/prx/libc/include/Shutdown.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ extern "C" void LibcRequestShutdown_nid_postfix();
extern "C" void LibcRequestExit_nid_postfix(int code);
extern "C" [[noreturn]] void LibcAwaitExit_nid_postfix();
extern "C" [[noreturn]] void LibcExit_nid_no_patch(int code);
extern "C" [[noreturn]] void LibcTerminate_nid_no_patch(int code);

#endif
10 changes: 10 additions & 0 deletions core/libs/prx/libc/src/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include <mutex>
#include <thread>
#include <vector>
#ifdef _WIN32
#include <windows.h>
#endif
#include <atomic>
#include <stdexcept>
#include "prx/libc/include/Shutdown.hpp"
Expand Down Expand Up @@ -106,6 +109,13 @@ extern "C" {
std::fprintf(stderr, "[libc] _Exit(%d) called from %p\n", code, __builtin_return_address(0));
std::fflush(stderr);
}
LibcTerminate_nid_no_patch(code);
}

[[noreturn]] void LibcTerminate_nid_no_patch(int code) {
#ifdef _WIN32
TerminateProcess(GetCurrentProcess(), static_cast<UINT>(code));
#endif
std::_Exit(code);
}

Expand Down
2 changes: 1 addition & 1 deletion core/libs/prx/libkernel/System/src/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void APS5_VABI exit_nid_postfix(int code) {
}

[[noreturn]] void APS5_VABI _exit_nid_postfix(int status) {
std::_Exit(status);
LibcTerminate_nid_no_patch(status);
}

int APS5_VABI system_nid_postfix(const char* command) {
Expand Down
10 changes: 10 additions & 0 deletions core/libs/tests/GuestSystemExit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <cstdlib>
#include <stdexcept>
#include <cstring>
#ifdef _WIN32
#include <windows.h>
#endif
extern "C" int APS5_VABI sceSystemServiceLoadExec(const char*, const char* const*);
extern "C" void APS5_VABI _Exit_nid_postfix(int);
extern "C" void APS5_VABI catchReturnFromMain_nid_postfix(int);
Expand All @@ -27,11 +30,18 @@ void APS5_VABI QuickFirst() {
}
void Require(bool value) { if (!value) std::abort(); }
void UnexpectedCleanup() { std::_Exit(3); }
#ifdef _WIN32
void WINAPI UnexpectedDetach(PVOID) { TerminateProcess(GetCurrentProcess(), 4); }
#endif
}
int main(int argc, char** argv) {
if (argc > 1 && std::strcmp(argv[1], "--immediate") == 0) {
LibcRegisterShutdown_nid_postfix(UnexpectedCleanup);
Require(std::atexit(UnexpectedCleanup) == 0);
#ifdef _WIN32
auto slot = FlsAlloc(UnexpectedDetach);
Require(slot != FLS_OUT_OF_INDEXES && FlsSetValue(slot, &slot));
#endif
_Exit_nid_postfix(0);
return 2;
}
Expand Down
Loading