From 1cbf3fa8e4f871a6af1d1c62bfe2e323756817c0 Mon Sep 17 00:00:00 2001 From: Pouare514 Date: Fri, 2 Oct 2026 22:08:52 +0200 Subject: [PATCH 1/4] feat(libc): implement at_quick_exit and quick_exit --- .../prx/libSceSystemService/CMakeLists.txt | 5 +++- core/libs/prx/libc/src/Process.cpp | 23 +++++++++++++++++++ core/libs/tests/GuestSystemExit.cpp | 15 ++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/core/libs/prx/libSceSystemService/CMakeLists.txt b/core/libs/prx/libSceSystemService/CMakeLists.txt index ff18d4bad..de42305b7 100644 --- a/core/libs/prx/libSceSystemService/CMakeLists.txt +++ b/core/libs/prx/libSceSystemService/CMakeLists.txt @@ -15,12 +15,15 @@ if(BUILD_TESTING) configure_windows_unwind(guest_system_exit_tests) add_test(NAME guest_system_exit_parameters COMMAND guest_system_exit_tests) add_test(NAME guest_system_exit COMMAND guest_system_exit_tests --exit) + add_test(NAME guest_quick_exit COMMAND guest_system_exit_tests --quick-exit) add_test(NAME guest_immediate_exit COMMAND guest_system_exit_tests --immediate) add_test(NAME guest_return_from_main COMMAND guest_system_exit_tests --return-from-main) set_tests_properties(guest_system_exit PROPERTIES PASS_REGULAR_EXPRESSION "Guest shutdown and atexit completed") + set_tests_properties(guest_quick_exit PROPERTIES + PASS_REGULAR_EXPRESSION "Guest quick_exit handlers completed") if(WIN32) - set_tests_properties(guest_system_exit guest_system_exit_parameters guest_immediate_exit guest_return_from_main PROPERTIES ENVIRONMENT_MODIFICATION + set_tests_properties(guest_system_exit guest_system_exit_parameters guest_immediate_exit guest_return_from_main guest_quick_exit PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$") endif() add_test_executable(guest_system_service_tests ${LIBS_INCLUDE_DIR}/tests/GuestSystemService.cpp) diff --git a/core/libs/prx/libc/src/Process.cpp b/core/libs/prx/libc/src/Process.cpp index 48526ffff..d8ce47284 100644 --- a/core/libs/prx/libc/src/Process.cpp +++ b/core/libs/prx/libc/src/Process.cpp @@ -162,4 +162,27 @@ int APS5_VABI atexit_nid_postfix(GuestExitCallback func) { return result; } +namespace { +std::mutex quickExitMutex; +std::vector quickExitCallbacks; +} + +int APS5_VABI at_quick_exit_nid_postfix(GuestExitCallback func) { + if (func == nullptr) + return 0; + std::lock_guard lock(quickExitMutex); + quickExitCallbacks.push_back(func); + return 0; +} + +[[noreturn]] void APS5_VABI quick_exit_nid_postfix(int status) { + std::vector callbacks; + { + std::lock_guard lock(quickExitMutex); + callbacks = std::move(quickExitCallbacks); + } + for (auto it = callbacks.rbegin(); it != callbacks.rend(); ++it) (*it)(); + _Exit_nid_postfix(status); +} + } diff --git a/core/libs/tests/GuestSystemExit.cpp b/core/libs/tests/GuestSystemExit.cpp index 5afefa49e..a10647cd9 100644 --- a/core/libs/tests/GuestSystemExit.cpp +++ b/core/libs/tests/GuestSystemExit.cpp @@ -8,6 +8,9 @@ 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); +using GuestQuickExitCallback = void (APS5_VABI*)(); +extern "C" int APS5_VABI at_quick_exit_nid_postfix(GuestQuickExitCallback); +extern "C" void APS5_VABI quick_exit_nid_postfix(int); namespace { bool cleaned = false; void Cleanup() { cleaned = true; } @@ -15,6 +18,12 @@ void VerifyExit() { if (!cleaned) std::_Exit(1); std::puts("Guest shutdown and atexit completed"); } +int quickOrder = 0; +void APS5_VABI QuickSecond() { quickOrder = 1; } +void APS5_VABI QuickFirst() { + if (quickOrder != 1) std::_Exit(1); + std::puts("Guest quick_exit handlers completed"); +} void Require(bool value) { if (!value) std::abort(); } void UnexpectedCleanup() { std::_Exit(3); } } @@ -29,6 +38,12 @@ int main(int argc, char** argv) { catchReturnFromMain_nid_postfix(0); return 2; } + if (argc > 1 && std::strcmp(argv[1], "--quick-exit") == 0) { + Require(at_quick_exit_nid_postfix(QuickFirst) == 0); + Require(at_quick_exit_nid_postfix(QuickSecond) == 0); + quick_exit_nid_postfix(0); + return 2; + } if (argc > 1) { LibcRegisterShutdown_nid_postfix(Cleanup); Require(std::atexit(VerifyExit) == 0); From 2be3860983b6a483edd5f1f32067f0d217d7e9c0 Mon Sep 17 00:00:00 2001 From: Pouare514 Date: Sun, 4 Oct 2026 15:24:44 +0200 Subject: [PATCH 2/4] fix(tests): flush stdout in QuickFirst so ctest pipe captures handler output --- core/libs/tests/GuestSystemExit.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/core/libs/tests/GuestSystemExit.cpp b/core/libs/tests/GuestSystemExit.cpp index a10647cd9..3a22d960f 100644 --- a/core/libs/tests/GuestSystemExit.cpp +++ b/core/libs/tests/GuestSystemExit.cpp @@ -23,6 +23,7 @@ void APS5_VABI QuickSecond() { quickOrder = 1; } void APS5_VABI QuickFirst() { if (quickOrder != 1) std::_Exit(1); std::puts("Guest quick_exit handlers completed"); + std::fflush(stdout); } void Require(bool value) { if (!value) std::abort(); } void UnexpectedCleanup() { std::_Exit(3); } From 630cf0cf391dd832522ec4895135d12f9a865b58 Mon Sep 17 00:00:00 2001 From: Pouare514 Date: Mon, 5 Oct 2026 00:53:03 +0200 Subject: [PATCH 3/4] fix(libc): drop duplicate quick_exit stub clashing with the real export --- core/libs/prx/libc/Export.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/core/libs/prx/libc/Export.cpp b/core/libs/prx/libc/Export.cpp index 6df7bf8db..17128de2e 100644 --- a/core/libs/prx/libc/Export.cpp +++ b/core/libs/prx/libc/Export.cpp @@ -160,12 +160,6 @@ std::uint64_t APS5_VABI libcCyberUnknown14(void) { return 0; } -APS5_EXPORT("qdGFBoLVNKI", libcCyberUnknown15); -std::uint64_t APS5_VABI libcCyberUnknown15(void) { - NotImplemented_nid_no_patch("qdGFBoLVNKI"); - return 0; -} - APS5_EXPORT("vEaqE-7IZYc", libcCyberUnknown16); std::uint64_t APS5_VABI libcCyberUnknown16(void) { NotImplemented_nid_no_patch("vEaqE-7IZYc"); From 9e7032513964f5478fe64722f3da38e8988549a9 Mon Sep 17 00:00:00 2001 From: Pouare514 Date: Mon, 5 Oct 2026 01:10:56 +0200 Subject: [PATCH 4/4] chore: drop stray AudioIn hunk --- core/libs/prx/libSceAudioIn/Export.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/libs/prx/libSceAudioIn/Export.cpp b/core/libs/prx/libSceAudioIn/Export.cpp index 3c31aaa40..cdd232455 100644 --- a/core/libs/prx/libSceAudioIn/Export.cpp +++ b/core/libs/prx/libSceAudioIn/Export.cpp @@ -122,7 +122,7 @@ int APS5_VABI sceAudioInInput(int handle, void* dest) { if (device != 0) { captured = capture(device, out, bytes, deadline); } else { - std::this_thread::sleep_until(wake); + while (Clock::now() < wake) std::this_thread::sleep_until(wake); } std::memset(out + captured, 0, bytes - captured); lock.lock();