fix(libSceSystemService): run guest exit handlers first on LoadExec exit #4872
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4872"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by David-cmrg on 2026-10-13T01:08:48Z.
What
Fixes #4846.
sceSystemServiceLoadExec("exit")ranLibcRunShutdown_nid_postfix()and thenstd::exit(0). The title's own exit handlers (__cxa_atexit, run byCxaFinalize_nid_no_patchfrom the hostatexitentry registered at the first guest registration) then ran after the host exit handlers registered later, among them the destructors of host statics such as theGuestAllocationsregistry. A guest destructor that frees heap memory then reads the destroyed registry. In ProsperoEden the freed entry reads as pinned, so the free waitsAPS5_PIN_WAIT_MSand the process aborts.It now exits through
LibcExit_nid_no_patch(0), likeexit, a return frommainandsceSystemServiceKillApp: shutdown, then the guest exit handlers, thenstd::exit, and it waits when another thread already started exiting. That is the orderguest_exit_orderrequires ("guest exit handlers must run before the host exit handlers").guest_system_exitnow registers a guest exit handler before its hostatexithandler and requires that the guest one ran first.Tested
Fedora 44, GCC 16.2.1, Release.
main510a2188c: with the test change alone,guest_system_exitfails 3 of 3; with this change it passes 3 of 3.guest_exit_order,guest_system_exit*,guest_quick_exit,guest_immediate_exit,guest_return_from_main,guest_system_kill_app*andguest_system_service*(11 tests) pass.d53960612(the files this PR touches are unchanged since then), withdataalready in the run folder. The title quits from its launcher after about 19 s.data.#4786 changes the same function (a relaunch for the title's own
eboot.bin) and keepsLibcRunShutdown_nid_postfix(); std::exit(0);there, so the two PRs touch the same lines.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T08:37:55Z.
Needs a rebase:
core/libs/prx/libSceSystemService/Export.cppconflicts with main now. It gets a full build once it is clean.Imported from boykopovar/AnyPS5. Originally posted by David-cmrg on 2026-10-13T10:05:42Z.
Rebased onto
77b9f7270. The conflict was main's new launch code insceSystemServiceLoadExec. The change now only replaces the"exit"branch'sLibcRunShutdown_nid_postfix(); std::exit(0);withLibcExit_nid_no_patch(0). The relaunch and other-executable paths are unchanged.On Linux (GCC 16.2.1, Release), the six
guest_system_*exit tests pass, includingguest_system_relaunch.guest_system_exitfails 3/3 with main'sExport.cppand passes 3/3 with the change.