fix(libSceSystemService): give LoadExec's next executable the host standard error #5699
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5699"
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 YossiYad on 2026-10-14T07:21:29Z.
What
#4792 keeps the host's standard error on Linux when a guest redirects descriptor 2: the first redirect keeps a duplicate, the host
stderrand the terminate report write to it, and the guest's stream follows its redirect. The duplicate does not survivesceSystemServiceLoadExec: it is close-on-exec forexecv, andReplacecloses every descriptor above 2 beforefexecve. The next executable starts with descriptor 2 still on the title's redirect and keeps that as its "host" standard error, so its runtime output, the terminate report included, goes into the title's file, or into a pipe whose reader is gone (SIGPIPE).LoadExec.cppReplace(argument list,fexecve): descriptor 2 gets the kept host descriptor after the guest shutdown andfflush, before theclose_rangecalls.Export.cppStartHostExecutable(null list,execv): the same restore right beforeexecv.guest_system_load_exec_standard_errortest (Linux): a forked child with stderr on a pipe moves the guest's descriptor 2 to a second pipe withdup2, then starts itself again throughsceSystemServiceLoadExec("/app0/eboot.bin", ...), once with{"--after-load-exec", NULL}(fexecve, the new image must seeargc == 1andargv[0]equal to the marker) and once with a null list (execv,argc == 1). The new image is recognised by an environment variable. What it writes to stderr must reach the first pipe and nothing the second.Titles.
fexecve): onmainthe third image dies with SIGPIPE 8 s in when AnyPS5 writes[memory] configured flexible memoryto the kept copy of the picker's pipe. With this PR it runs to the limit (@milescoviello, 3 of 3).execv): together with #6237, the second image's output reaches the log again (@milescoviello, 2 of 2).Windows is not changed: both launch paths there use
CreateProcessWand already pass the host standard error handle on (#4640; checked by @screamm).Tested
Linux (Bazzite 44, GCC 16.2.1, Ninja, Release,
-DBUILD_TESTING=ON), head6473318a6onmain92e50418f:guest_system_load_exec_standard_errorpasses 3 of 3. With onlyLoadExec.cppfrommainit aborts, and with onlyExport.cppfrommainit aborts too, so each path is pinned.loadexec_arguments,guest_system_relaunch,guest_nested_exitand theguest_system_exitset pass.tools/check_conventions.py --base upstream/mainpasses.ctest836 of 836 pass; no Windows code changes.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T01:34:17Z.
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/libSceSystemService/CMakeLists.txtL52Some 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/prx/libSceSystemService/Export.cppdocs/dev/debt/libSceSystemService.mdcore/libs/prx/libSceSystemService/CMakeLists.txtcore/libs/prx/libSceSystemService/Export.cppdocs/dev/debt/libSceSystemService.mdImported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-15T10:51:38Z.
A title where this shows: VLC for PS5 (PPSA85300). Its
plat_restartrelaunches itself withsceSystemServiceLoadExec("/app0/eboot.bin", NULL)(platform_ps5.c). Linux, RTX 4070 Ti, NVIDIA 595.99, GCC 13.3, Release,maind92a8dad3, a pad sequence that reaches the restart 18 s in, 60 s runs:mainalone: the process aborts at the relaunch with an unhandledProcessShutdown, before any exec. #6237 is for that.app.elf, but nothing the second image writes reaches the log; it ends at the exec line (2 of 2 runs, one traced).7a4688c71(clean merge): the second image's output appears. It reloads the pipeline cache, hits the shader disk cache and presents frames until the limit, 2 of 2 runs.Not checked on Windows.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T12:09:08Z.
Review: CHANGES_REQUESTED
Checked on current
mainmerged with this head. Two problems:core/libs/prx/libSceSystemService/Export.cpp:186: the descriptor 2 restore only runs inStartHostExecutable(execv). A call whose argument list has a first entry (RetroArch's{"", NULL}, any list) goes throughReplaceinLoadExec.cpp:160(fexecve) before that, so the next image still inherits the title's redirect. The restore needs to happen on that path too, after the shutdown andfflush.core/libs/tests/GuestSystemServiceLoadExecStandardError.cpp:25,43: the test passes{"--after-load-exec"}, which is now the whole guestargv(argc == 1, no program name in front). The re-executed image never seesargc == 2, forks again and loops, printing the host CPU line over and over until killed. Check the new image withargc == 1andargv[0]equal to the marker, and keep a second case with a null list for theexecvpath, so both paths are pinned.Once both paths restore it, the debt line in
docs/dev/debt/libSceSystemService.mdshould also say thatfexecvecloses every descriptor above 2 while descriptor 2 gets the kept host one.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-15T12:54:20Z.
A second title, on the other LoadExec path: RetroArch (PPSA99169). Its picker passes an argument list (
{"", NULL}, then{"--ps5-mode=retroarch", NULL}), so the next image starts throughLoadConvertedExecutable→Replace→fexecveinLoadExec.cpp, notStartHostExecutable. This PR'sdup2is not reached there.Linux, RTX 4070 Ti, NVIDIA 595.99, GCC 13.3, Release, a pad sequence that picks the RetroArch frontend, 60 s runs:
main1d1c7615c: 2 of 2 runs die with SIGPIPE (EXIT-141) 8 s in, in the third image. Under gdb the write is AnyPS5's own[memory] configured flexible memoryline (fprintffrom_configuredFlexibleSize()in libkernel) to fd 6. That isKeepHostStandardError's copy of a descriptor 2 that is the picker's pipe, whose read end the exec closed.7a4688c71merged ontomain: the same, 2 of 2.Replacebefore theclose_rangecalls: 2 of 2 runs reach the limit (3 images, about 2,550 log lines instead of about 1,160). This was a throwaway build:I didn't look at the Windows
CreateProcessWpath. I can rerun RetroArch if you extend the PR.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-15T14:38:19Z.
Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (596.21), MinGW GCC 15.2, PR head 7a4688c71 merged on main
8dc92ae29with #6237 a03e02345:This is a Windows no-regression check only. The
dup2is in the LinuxStartHostExecutable, andguest_system_load_exec_standard_erroris registered only on Linux. After the merge,libSceSystemService.prxdisassembles to the same code with and without this PR, andctest -Nlists no new test, so there is no negative control to run here.PPSA85300 (VLC 0.3.1). Relinked with
--windows-fixed-base 0x400000, 120 s runs. The restart is reached throughAPS5_PAD_INPUT_FILE(Cross, Right, Options in the first-launch setup ->plat_restart->sceSystemServiceLoadExec("/app0/eboot.bin", NULL)).app.exeexits with 0x00000000 at 18-21 s. The newapp.exepresents until the limit: 11753 and 12060 frames.On Windows the relaunched image's own output already reaches the console without this PR. The console log of each run has the start-up block twice (
[time] scheduler tick raised ...,host CPU ...,Transferring control to ELF entry point), even though VLC had moved descriptor 2 toapp0/vlc-ps5.log. libc keeps the host handle as the process's standard error handle (KeepStandardHandle_nid_no_patch), and bothCreateProcessWpaths passGetStdHandle's handles, so the description's "Windows is not changed" holds.The test suite on main + #6237 + this PR (
-j8 --timeout 120 -E '^agc_driver_|^video_out_flip') passes 830/830. The host was shared with other jobs, but nothing timed out.tools/check_conventions.py --base origin/mainpasses andgit diff --checkis clean.From reading current
mainI agree with @adriadam10's review.{"--after-load-exec", nullptr}goes throughLoadConvertedExecutable->Replace(fexecve), so the test never reaches the newdup2inStartHostExecutable. The relaunched image seesargc == 1,argv[0] == "--after-load-exec"and forks again. That part I could not run here.Side observation, not investigated: in all four runs the relaunched VLC appended to the same
app0/vlc-ps5.log, and its start-uprenametovlc-ps5.old.logleft no file. This may be the null-listCreateProcessW(bInheritHandles=TRUE, no handle list) passing the old process's file handle on, but I did not check.No Windows concerns.
Written with Claude Code assistance.
Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-15T15:17:41Z.
@adriadam10 thanks, both points were right. Rebased onto
main92e50418f, new head6473318a6:LoadExec.cppReplace: descriptor 2 gets the kept host descriptor after the shutdown andfflush, before theclose_rangecalls (which would otherwise close the kept descriptor itself). Theexecvpath inExport.cppkeeps its restore.{"--after-load-exec", NULL}(fexecve) it requiresargc == 1andargv[0]equal to the marker; with a null list (execv) it requiresargc == 1. Each case checks that the new image wrote to the host pipe and nothing reached the guest redirect.fexecvecloses every descriptor above 2 while descriptor 2 gets the kept host one, and that theexecvpath keeps the guest's descriptors open.Linux, GCC 16.2.1, Release:
guest_system_load_exec_standard_errorpasses 3 of 3, and the other LoadExec tests (loadexec_arguments,guest_system_relaunch,guest_nested_exit, theguest_system_exitset) pass.LoadExec.cppfrommainthe test aborts, and with onlyExport.cppfrommainit aborts too, so each path is pinned.tools/check_conventions.py --base upstream/mainpasses.@milescoviello the restore is now in
Replacein the same place as your throwaway build, if you want to rerun RetroArch.Could you take another look and merge if it's fine now?
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-15T15:23:30Z.
RetroArch (PPSA99169) on the new head: this fixes it.
Linux (Ubuntu 24.04, GCC 13.3, Release, RTX 4070 Ti, NVIDIA 595.99), the same pad sequence that picks the RetroArch frontend, 60 s runs:
main92e50418fEXIT-141) 8 s in, during the third image (about 1,150 log lines)main92e50418f+ this PR at6473318a6With the PR, the third image (the frontend, started through
Replace→fexecve) scans/app0/cores, reads its core metadata and creates its swapchain. Onmainthe log stops right after the frontend opens/app0/cores. With the PR, the next line there is[memory] configured flexible memory, which is the write gdb caught in my earlier runs.Not checked: Windows, since
CreateProcessWdoesn't go throughReplace.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-15T21:50:15Z.
Rerun on Windows 11 Pro 26220 (RTX 4070 596.21, MinGW GCC 15.2): head
6473318a6merged on main44df21632together with #6237.libstoo); the only failing target isagc_driver_gpu_indirect_arguments_misaligned_writer_ahead_tests, which also fails onmainhere (65536 alignment, #6452/#6478).guest_system_load_exec_standard_error: not built on Windows (registered underCMAKE_SYSTEM_NAME STREQUAL "Linux", usesfork/pipe), so there are no Windows runs and no negative control.guest_system_relaunch,--repeat until-fail:3: 3 of 3 pass.ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip': 836 of 836 pass, 2 skipped.tools/check_conventions.py --base origin/mainandgit diff --checkpass._WIN32ReplaceinLoadExec.cpp(CreateProcessW, suspended, withGetStdHandle's standard handles duplicated into the child), and the null-list path isStartHostExecutableinExport.cpp(CreateProcessW, inheriting handles). The newdup2calls are only in the Linux versions. Windows already hands the host standard error handle on, which is what my earlier VLC runs on7a4688c71showed, so I did not repeat them.Not checked: the Linux paths, and the PPSA85300 / PPSA99169 title runs on this head.
Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-15T21:56:25Z.
@screamm thanks, that answers it: on Windows both launch paths already pass the host standard error on, so the
dup2calls only matter for the Linux paths, which my PPSA99169 runs covered.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-16T07:01:52Z.
@adriadam10 a reminder on this one when you have time. Head
6473318a6has both changes from your review:Replacerestores descriptor 2 before theclose_rangecalls, and the test covers thefexecvepath (argc == 1,argv[0]is the marker) and theexecvpath (null list). Since then:maindies with SIGPIPE 8 s in.ctestpasses 836 of 836. Windows code is unchanged.The PR description now covers both paths. I can't request a review myself (no write access), so this comment is the request. Could you take another look?
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T18:21:55Z.
Review: APPROVED
Re-checked on current
mainmerged with this head. Both points are fixed:Replacerestores descriptor 2 before theclose_rangecalls (LoadExec.cpp:157), and the test pins both thefexecvepath (argc == 1,argv[0]is the marker) and theexecvpath. The new test passes, fails without the source changes, and the rest of thelibSceSystemServicectest scope is green. The debt entry matches the code; merging.