fix(libSceAudioOut): park guest audio calls at exit before the port tables are destroyed #6000
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6000"
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 isnisk on 2026-10-14T18:45:24Z.
What
Fixes #5864.
libSceAudioOutregistered no shutdown callback, so a guest mixer thread kept callingsceAudioOut2ContextPushwhile exit ran the static destructors, and mixed from the freedg_portstable (SIGSEGV inAudioOut2MixPortsin the report).sceAudioOut2ContextAdvance,sceAudioOut2ContextPush,sceAudioOut2ContextDestroy,sceAudioOut2PortCreate,sceAudioOut2PortDestroy,sceAudioOut2PortGetState,sceAudioOut2PortSetAttributes,sceAudioOutOutputandsceAudioOutOutputs.LibcAwaitExit_nid_postfix, as the AGC entry points do since5550ca63d, instead of returning an error the title might retry.sceAudioOut2ContextAdvance(added inbb4ec482d) also wakes on the shutdown token:grainReadybecomes acondition_variable_any. Without that, the callback would wait forever for a push whose advance is parked.The SDL devices are not closed at shutdown: the device callback reads only its heap-allocated context, which the exit does not free.
Relation to #5971: it gives the AudioOut2 port table process lifetime, and its debt entry records that the host does not stop the guest threads. This PR stops them. The two change different lines of
AudioOut2Port.cppand do not depend on each other.Tested
Ubuntu 26.04 under WSL2, GCC 15.2.0, Release,
SDL_AUDIODRIVER=dummy, on this branch rebased on73efd9407.audio_out_shutdown_tests(four ctest cases): a thread keeps pushing (AudioOut2) or outputting (AudioOut) while another thread requests exit; anatexithandler, which runs after the shutdown callbacks and before the library's static destructors, checks that the thread has stopped. A third case has a push waiting for an advance during exit and checks that the exit finishes; a fourth callssceAudioOut2ContextAdvanceafter the exit request and checks that it does not return.the mixer thread kept outputting audio after the audio shutdown,the exit did not finish,an advance after the exit request returned); with it they pass, 50 repetitions each.audio_out*tests pass; no compiler warnings;check_test_registration.pyandcheck_conventions.pypass.Not tested: Windows (no MinGW toolchain here), the full test suite (nothing else links
libSceAudioOut), a title run. The reporter of #5864 offered to run Hades II on this branch.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T18:51:52Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAudioOut/CMakeLists.txtL137core/libs/prx/libSceAudioOut/src/AudioOut.cppL386-387, L407-408Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-10-15T08:24:46Z.
Regression: after this PR the Peace Walker launcher exits before it starts the game (LoadExec hand-over)
Title: METAL GEAR SOLID: Peace Walker (PPSA18216), Master Collection launcher,
sceSystemServiceLoadExecof/app0/mgspw/mgspw.elfSystem: Linux, RTX 3080 Ti (NVIDIA 615.71.09)
What happens
On
maind92a8dad3(this PR is in it), pressing through the launcher menu ends with the hand-over arguments and then the process dies:The converted game executable (
mgspw.mgspw.elf.elf) is never started. It starts normally when I run it directly. Onmainb72378b0f, a few hours earlier, the same hand-over worked: the log continued with the new process'sHostCpu.cppline.Check
The only change between those two that touches shutdown is this PR. With
e7219e4bcreverted on top ofd92a8dad3(plus some unrelated AGC PRs), the same launcher run hands over and the game starts (twoHostCpu.cpplines in the log, one per process).What I did not check
I did not run plain
mainwithout my AGC PRs, and I have not read the audio code beyond this PR's description. My guess is thatLoadExecruns the library shutdown beforefexecve, and a guest thread's guarded audio call then parks onLibcAwaitExitand ends up throwingProcessShutdownthrough guest frames. That would end the process before the exec. It is a guess, not something I traced.AI-assisted; the runs are from my machine.
Imported from boykopovar/AnyPS5. Originally posted by isnisk on 2026-10-15T13:13:55Z.
@mrfelek thanks, your guess is right, and it's this PR's fault.
sceSystemServiceLoadExecruns the library shutdown without marking an exit as requested. Since this PR, a guest audio call after the shutdown token is set goes toLibcAwaitExit_nid_postfix, which parks the thread only once an exit is requested and otherwise throwsProcessShutdownback into the title. The launcher's mixer thread pushes every few milliseconds, so it reaches that during the hand-over, before thefexecve. I assumed the library shutdown only runs on exit and didn't check LoadExec.#6237 fixes it at the source: LoadExec starts the shutdown the way exit does, so the thread parks until the process is replaced (the AGC entry points had the same gap, which is how #6237 found it on MGS4). I reproduced your stop with a test that pushes AudioOut2 audio across a LoadExec: on
main489466d3f0 of 10 runs relaunch, all with your'15ProcessShutdown'terminate; with #6237 merged on top, 30 of 30 do. Details on #6237. A Peace Walker run on #6237 would confirm it on the title.AI-assisted: yes (Claude Code).