Skip to content

fix(libSceSystemService): run guest exit handlers first on LoadExec exit - #4872

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
David-cmrg:fix/systemservice-loadexec-exit-order
Oct 13, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
David-cmrg:fix/systemservice-loadexec-exit-order

Conversation

@David-cmrg

Copy link
Copy Markdown
Contributor

What

Fixes #4846.

sceSystemServiceLoadExec("exit") ran LibcRunShutdown_nid_postfix() and then std::exit(0). The title's own exit handlers (__cxa_atexit, run by CxaFinalize_nid_no_patch from the host atexit entry registered at the first guest registration) then ran after the host exit handlers registered later, among them the destructors of host statics such as the GuestAllocations registry. A guest destructor that frees heap memory then reads the destroyed registry. In ProsperoEden the freed entry reads as pinned, so the free waits APS5_PIN_WAIT_MS and the process aborts.

It now exits through LibcExit_nid_no_patch(0), like exit, a return from main and sceSystemServiceKillApp: shutdown, then the guest exit handlers, then std::exit, and it waits when another thread already started exiting. That is the order guest_exit_order requires ("guest exit handlers must run before the host exit handlers").

guest_system_exit now registers a guest exit handler before its host atexit handler and requires that the guest one ran first.

Tested

Fedora 44, GCC 16.2.1, Release.

#4786 changes the same function (a relaunch for the title's own eboot.bin) and keeps LibcRunShutdown_nid_postfix(); std::exit(0); there, so the two PRs touch the same lines.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes (Claude Opus 5.5)

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Needs a rebase: core/libs/prx/libSceSystemService/Export.cpp conflicts with main now. It gets a full build once it is clean.

@David-cmrg
David-cmrg force-pushed the fix/systemservice-loadexec-exit-order branch from 9a5090a to 9f9c351 Compare October 13, 2026 10:05
@David-cmrg

Copy link
Copy Markdown
Contributor Author

Rebased onto 77b9f7270. The conflict was main's new launch code in sceSystemServiceLoadExec. The change now only replaces the "exit" branch's LibcRunShutdown_nid_postfix(); std::exit(0); with LibcExit_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, including guest_system_relaunch. guest_system_exit fails 3/3 with main's Export.cpp and passes 3/3 with the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libc: a guest free during exit waits 60 s for a lease and aborts after the AGC driver shut down (ProsperoEden quitting)

2 participants