mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #405 from Pouare514/feat/libc-quick-exit
feat(libc): implement at_quick_exit and quick_exit
This commit is contained in:
@@ -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:$<TARGET_FILE_DIR:libc>")
|
||||
endif()
|
||||
add_test_executable(guest_system_service_tests ${LIBS_INCLUDE_DIR}/tests/GuestSystemService.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");
|
||||
|
||||
@@ -162,4 +162,27 @@ int APS5_VABI atexit_nid_postfix(GuestExitCallback func) {
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::mutex quickExitMutex;
|
||||
std::vector<GuestExitCallback> 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<GuestExitCallback> callbacks;
|
||||
{
|
||||
std::lock_guard lock(quickExitMutex);
|
||||
callbacks = std::move(quickExitCallbacks);
|
||||
}
|
||||
for (auto it = callbacks.rbegin(); it != callbacks.rend(); ++it) (*it)();
|
||||
_Exit_nid_postfix(status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,13 @@ 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");
|
||||
std::fflush(stdout);
|
||||
}
|
||||
void Require(bool value) { if (!value) std::abort(); }
|
||||
void UnexpectedCleanup() { std::_Exit(3); }
|
||||
}
|
||||
@@ -29,6 +39,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);
|
||||
|
||||
Reference in New Issue
Block a user