fix(libc): run guest finalizers before driver shutdown #5978
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5978"
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 MarcZX10 on 2026-10-14T17:59:39Z.
What
For an explicit guest
exit()or return from main, run the guest's C++ finalizers before the AGC/VideoOut shutdown callbacks. This keeps those drivers available to finalizers that use them. The shutdown callbacks still run once, after the finalizers, including when a finalizer calls nestedexit().This is the explicit guest-exit path from #5931. Host window-close requests continue through #5843's no-handler path. Depends on #5843 (which depends on #5236).
Tested
main8cd937e29;git diff --checkand the template-aware conventions check pass.tests/guest_system_exit_testssuccessfully (712 build steps, includinglibc.prx,libSceSystemService.prx, and the test executable).guest_exit_finalizers_before_shutdown,guest_system_exit,guest_return_from_main,guest_system_relaunch, andguest_nested_exit. All five processes aborted before test logic at the emulator host-CPU guard: this Xeon E5-1620 v2 lacks LZCNT, BMI1/2, MOVBE, AVX2, and FMA. No CTest case is reported as passing on this host.Process.cppprobe passed on the pre-rebase head; it has not been rerun on this rebased head. No Windows or title runtime was tested.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 repositoryImported from boykopovar/AnyPS5. Originally posted by ahmad3a4 on 2026-10-14T18:19:56Z.
Windows validation of #5843 + this PR, from the #5931 report:
Setup: Windows 11 Pro (26200), Core i5-13400 (passes the CPU guard), WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON.mained835aa7, then #5843 (e0748f37, carrying #5236 as 9655d0c8), then this PR (c6b42bf8) merged on top.Conflicts when this PR goes on top of #5843:
Process.cpp: #5843 hasStartExit()runningLibcRunShutdown_nid_postfix(), and this PR hasBeginExit()without it. I kept the nameStartExit, took the shutdown out of it, and calledLibcRunShutdown_nid_postfix()inLibcExitWithoutHandlers_nid_no_patchbefore the flush. Without that call, a resolution that just takes this PR's version would leave the window-close path terminating without running the AGC/VideoOut shutdown callbacks.libSceSystemService/CMakeLists.txt: I kept #5843'sguest_system_exit/guest_requested_exitexpectations ("Guest shutdown completed", plus the FAIL expression), addedguest_exit_finalizers_before_shutdown, and put it in the WindowsPATHlist as well.Results:
guest_system_exit,guest_requested_exit,guest_exit_finalizers_before_shutdown,guest_nested_exit,guest_return_from_main,guest_quick_exit,guest_immediate_exit,guest_system_relaunch,guest_system_exit_parametersandguest_thread_atexit.WM_CLOSEafter it presents 300 to 600 frames: 3 of 3 runs end with exit code 0 and no abort. Onmaine34c4792it was 4 of 4exit thread cannot wait for itselfaborts with0xC0000409.guest_exit_finalizers_before_shutdown, since Syobon has no exit of its own.Linux not run.
AI-assisted.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T00:56:19Z.
Rebased onto current
main(8cd937e29) and resolved the exit-path conflicts. The currentStartExit()preserves the newer host-window-close flow; explicitLibcExit_nid_no_patch()runs guest C++ finalizers beforeLibcRunShutdown_nid_postfix(), whileLibcExitWithoutHandlers_nid_no_patch()still runs shutdown callbacks before terminating. The new finalizer-order test and existing guest exit/relaunch/nested-exit tests compile. I ran those five CTests, but all abort at the existing host CPU feature guard before their test bodies on this Xeon E5-1620 v2, so I am not claiming a passing runtime test here. Current conventions check passes; hosted checks are running.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T01:10:39Z.
Hosted checks have now finished: Ubuntu, Windows and macOS relinker jobs all pass; register-context and write-watch jobs pass as well. Linux and Windows full-build jobs were skipped by path filters. The five local exit CTests still stop at this host’s CPU-feature guard before their test bodies, so I am not claiming a local runtime pass. The Windows title results earlier in this thread remain @ahmad3a4’s separate validation of the prior stacked head.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T01:34:24Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceSystemService/CMakeLists.txtcore/libs/tests/GuestSystemExit.cppcore/libs/prx/libc/src/Process.cppImported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-15T01:58:46Z.
The CTest half, on a host with AVX2 (Ubuntu 24.04, i7-13700K, GCC 13.3, Release),
mainab9a47684with #5843 and this PR merged. The only conflict was the test registrations inlibSceSystemService/CMakeLists.txt, where I kept both sides. All nine exit tests pass:guest_system_exit,guest_requested_exit,guest_system_exit_parameters,guest_quick_exit,guest_immediate_exit,guest_return_from_main,guest_system_relaunch,guest_nested_exitand the newguest_exit_finalizers_before_shutdown.With Syobon Action (PPSA47402), closing the window 20 s in exits 0 with #5843 alone and with both PRs;
mainaborts withexit thread cannot wait for itself. I couldn't drive the title's ownexit()path from outside, so that part of this PR isn't covered by the title run.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by dogukanatlihan on 2026-10-15T18:02:39Z.
I prepared a small supplemental regression for the nested-exit coverage request. It extends
guest_nested_exitto require a live shutdown token in the remaining finalizer, exactly one shutdown marker afterward, and the existing nested exit status 7.Windows 11 Pro build 26300, i7-14700K, WinLibs GCC 15.2.0 r7, Release:
shutdown; the enhanced CTest fails as expected.eb8146b73+ this PRf619f964e: child exits 7 and records exactlyremaining handler\nshutdown\n.guest_requested_exit,guest_system_exit,guest_exit_finalizers_before_shutdown, the enhancedguest_nested_exit, andpatched_libraries.The runtime build used main
fa9365ca7plus the existing #6452 build prerequisite. The patch was prepared on03c4cb5e7; the three relevant source files are unchanged between those bases, and the tested patched copies matched the prepared copies by hash. This is local stack validation, not a GitHub merge-commit CI result.The production changes remain the work of the existing PR authors. The supplemental test patch below addresses the remaining coverage request.
Supplemental test patch
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T21:15:32Z.
The latest Windows relinker job built successfully and passed 176/177 CTest cases. Its only failure is
build_eligibility: two tests timed out in the nested Node harness at the 20-second subprocess limit; the other relinker tests passed. This test is outside the changed files, andtools.tests.test_build_eligibilitypasses locally on Linux (7/7). GitHub does not allow rerunning this workflow run (run ... cannot be rerun; its workflow file may be broken), so the Windows result remains a CI failure rather than a confirmed transient.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T21:21:24Z.
Update: the Windows full-build job on current
main(e16b2bc) completed successfully in run 38806909876, so thebuild_eligibilitytimeout is intermittent rather than a consistent baseline failure. The harness reuse change is in #6583; I will report its Windows result when that check completes.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T21:39:00Z.
Follow-up: PR #6583 now passes the
build_eligibilityrelinker suite on all three hosted platforms: Ubuntu (2m29s), macOS (2m57s), and Windows (6m35s). Eligibility and conventions also pass. This is the amended single-Node harness head; it addresses the nested-process timeout observed on this PR and #5978.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T21:53:21Z.
The current Windows relinker check has the same
build_eligibilitysubprocess timeout as #6184: the nested Node harness hit the 20-second limit (two scenarios in this run), while the other 176/177 CTest cases passed. PR #6583 keeps one Node process alive across the scenarios; its current head passes the eligibility relinker suite on Ubuntu, macOS and Windows. Since #6583 is still open, this remains a proposed follow-up; a rerun after it merges would confirm the fix on this PR.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T05:21:49Z.
The current Windows relinker failure is in the shared
build_eligibilityCTest, not the AGC changes: theauthor_with_a_commit_in_main_runs_the_relinkerscenario times out after 20 seconds while its Node subprocess runs. All other 176/177 Windows relinker tests passed; Linux, macOS, conventions and eligibility checks pass. This same timeout is present on #5978. I found #6484 already exercises better timeout diagnostics for this test and its Windows relinker check passes. I have not changed your branch or opened a duplicate; the runner may be intermittently overloaded, and the failing run is from Oct 15. Could you rerun the Windows relinker job on the current head to establish whether it reproduces?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T05:23:17Z.
Update: the current head of #6583 (
e192246) has green Ubuntu, macOS and Windows relinker checks. Its single-Node harness directly addresses the nested Node timeout reported here and on #5978. #6583 remains open; after it lands onmain, rerunning this PR's Windows relinker check will verify the timeout is resolved. No further action is needed on this branch until then.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T08:47:58Z.
The only failing check in this run is
build_eligibility: its Node harness exceeded the 20-second subprocess timeout. This is unrelated to this PR's source changes. #6583 addresses the repeated Node startup that caused these Windows timeouts, and its Windows relinker check passed. I cannot rerun the workflow from this account (pushpermission is unavailable); once #6583 lands, this PR should be rerun against updatedmain.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T15:34:37Z.
The latest Windows check confirms the same
build_eligibility20-second Node harness timeout as #6184; the other tests pass. #6583 reuses a single Node process and has green Windows relinker checks. Once #6583 lands, please rerun this PR’s check to confirm the timeout is gone.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T16:42:54Z.
I rechecked the current Windows relinker failure: it is the same
build_eligibility20-second Node harness timeout as #6184, while the other relinker tests pass. Open PR #6583 reuses one Node process and has green Ubuntu/macOS/Windows checks, but it has not merged yet. I cannot dispatch a workflow rerun without repository admin rights. Once #6583 lands, this Windows job needs a fresh run against the current head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T17:13:49Z.
I rebased the two existing commits onto current
mainin011e8ef82and22f1c9957so the current build eligibility harness is used. Both commits remain MarcZX100-authored, with no co-author added. The fresh eligibility, conventions and report checks are running; the old Windows timeout run could not be rerun because GitHub reports its workflow file may be broken. I will report the current-head result when it completes.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T19:58:33Z.
Rebased onto current
main(only conflict: the test registrations inlibSceSystemService/CMakeLists.txt, kept both sides) and added one commit: the new--exit-order*modes and--relaunch-driverinGuestSystemExit.cppnow parse withfirstArgumentlike the rest ofmain().Checked on the rebased head: build and scoped ctest green for all exit tests (
guest_exit_finalizers_before_shutdown,guest_nested_exit,guest_requested_exit,guest_return_from_main,guest_system_relaunch,guest_system_exit*). Reverting theProcess.cppchange makesguest_nested_exitandguest_exit_finalizers_before_shutdownfail. Windows and title runs by @ahmad3a4, @milescoviello and @dogukanatlihan cover what we can't run here; merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T20:02:42Z.
Thanks for the rebase and for adding the
firstArgumentparsing fix to the new exit modes. The scoped exit tests and the negative control make the finalizer regression clear. I have no further changes to request; I’ll wait for the full Build result.