fix(libSceSystemService): pass LoadExec arguments as the whole guest argv #5083
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5083"
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 Dripl1x on 2026-10-13T11:09:26Z.
What
sceSystemServiceLoadExecwith a nonempty argument list now starts the new executable with that list as its whole guestargv, with no program name in front.mainpasses the list after the host path, so the guest sees the host path asargv[0]and every argument one position later.This follows the published PS5 RetroArch console transcript: a restart with one argument enters with
argc=1,argv[0]="--ps5-relaunch=1", and a launch from the home screen withargc=1,argv[0]=""(its caller). It is published console evidence, not a console run performed for this PR.fexecve. The PID is kept.maindoes.Title
RetroArch (PPSA99169) needs this when a game returns to ES-DE. YossiYad ran the whole frontend chain on Linux (comment). The title was converted with
--executable picker/picker.bin --executable es-de/es-de.binand started in its game mode, withnova.nes(GPL NES homebrew) and ES-DE as the frontend. After the game quits, RetroArch starts ES-DE throughsceSystemServiceLoadExec.main, ES-DE gets the host path as an extra argument. It printsUnknown option '/…/run/es-de.es-de.bin.elf'and returns at once, its log showsstart: arguments for ES-DE 2, and the title goes back to the picker. A game can never return to ES-DE.start: arguments for ES-DE 1, then starts and renders. It then stops on an unrelated AGC stop (#5245).Related:
GuestSystemExit.cppkeeps #5284's nested-exit modes, written in the samefirstArgumentform as the other modes, andlibSceSystemService/CMakeLists.txtkeeps #5158's test next toloadexec_arguments.libSceSystemServicenow linkslibSceAgcDriveronmain, soloadexec_argumentsalso copies that library beside the converted fixture."exit"branch of the same function. A trial merge conflicts only on the technical-debt line both rewrite, and the checklist declares the order.GuestSystemExit.cpp'smain, where this PR rewrites the argument checks into thefirstArgumentform, and carries #5236's debt line. A trial merge conflicts on those lines only. Whichever lands second rebases, and its new mode would take the same form.main'sexecv. This PR's Linux replacement keeps descriptors 0 to 2 as they are, so it needs the samedup2beforeclose_range. As agreed with its author, whichever of the two lands second adds it.Tested
Windows 11, Ryzen 7 5800H, WinLibs MinGW-w64 GCC 15.2.0 r7; Ubuntu 26.04 under WSL, GCC 15.2.0. Release,
BUILD_TESTING=ON, the root configuration with the bundled dependency sources;FFMPEG_PREBUILT_DIRpointed at an already unpacked package. Heada1b80121conmain84b01f9cd.relinker,libc,libkernel,libSceAgcDriver,libSceSystemService, the fixture library and the test targets. Then ranloadexec_arguments,guest_system_exit_parameters,guest_system_exit,guest_quick_exit,guest_immediate_exit,guest_return_from_main,guest_system_relaunch,guest_nested_exit,relinker_conversionandrelinker_executables, and on Windows alsoguest_system_service_path_boundary. 11 of 11 pass on Windows (3.47 s) and the 10 that exist on Linux pass (1.13 s).loadexec_argumentsandguest_system_relaunchalso passed 10 repeated runs on Windows.loadexec_argumentsconverts two synthetic0xFE10images with the actual relinker (--executable picker/second.bin) and runs first -> second -> first against the built libraries, under a work directory with Cyrillic and CJK characters. It checks:getargc/getargvfor an empty first argument, spaces, quotes with trailing backslashes, Cyrillic and CJK;/app0resource, and that only the shutdown callbacks run before the handover;/app0,..and unconverted targets are rejected before shutdown.Export.cppfrommainand the new test,loadexec_argumentsfails on both systems withLoadExec fixture: entry argument count.git diff --checkpass.Not tested: a console, macOS, the full test suite. RetroArch was run by YossiYad on Linux as quoted above, not for this rebased head. Full PR builds need a collaborator's manual Build run.
Checklist
main; no other open PR implements this argument handover.mdfiles or images added to the repository🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T11:44:59Z.
Review note (static):
git merge-treeof the current head againstmainreports four conflicts:core/libs/prx/libSceSystemService/Export.cpp,core/libs/tests/GuestSystemExit.cpp,core/relinker/main.cppanddocs/dev/debt/libSceSystemService.md. The description says the stack includes the prerequisite commits of #4872 and #4786 (the branch has three commits, the first from #4872), so it also overlaps those open pull requests and needs a rebase onto current main before it can be reviewed in full. Smaller point: the description reports 15/15 CTests on Windows and in WSL, but also that RetroArch itself has not been run and that the automatic conversion policy needs a review; it might be easier to review if the relinker discovery (secondary executables) and the runtime replacement were separate pull requests.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by AaravMehta-07 on 2026-10-13T12:24:37Z.
Source review found a Windows-only path-boundary gap in the current LoadExec path:
ConvertedExecutableNamerejects/-delimited..components, but Windows also treats backslashes as separators. A guest path such as/app0/..\..\outsidecan therefore reachPrepareLaunchas a single component and resolve outside the executable directory. This PR's current refactor leaves that conversion/containment path unchanged.I am holding a separate containment fix because it overlaps this refactor. Could your refactor go first, with the narrow guard and exported-API regression test rebased afterward? This is a source finding only; I have not reproduced it in the guest runtime yet.
The investigation, proposed patch and this comment are AI-assisted.
Imported from boykopovar/AnyPS5. Originally posted by AaravMehta-07 on 2026-10-13T13:05:40Z.
Runtime follow-up: the path-boundary case is now reproduced through the actual Windows
sceSystemServiceLoadExecexport. A probe using a benign copy of its own test executable outside the sibling directory reaches a registered shutdown callback on main. That callback exits with code 86 beforeStartHostExecutable, so the test does not launch an outside executable. With the parent-directory guard, the probe throws before shutdown and all five focused SystemService/SystemExit tests pass (0.56 seconds total).Exact overlap follow-up: the complete live hunk/export/new-file scanner reports no overlap, including with #5083. Your current diff changes the outer LoadExec body but leaves
PrepareLaunchunchanged; this guard changes the path-preparation helpers. The initial broad file-level concern was therefore cleared by the more precise check. The independently tested guard is submitted as #5158, with this distinction documented and no semantic dependency on your refactor. I will rebase if future edits introduce a conflict.The patch and test are AI-assisted; no commercial-title or PS5 hardware result is claimed.
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-13T17:53:32Z.
Updated to
9d4464a0c, rebased ontomain8cf6a0bc3. What changed since the review notes above:mainand no longer carries the #4872/#4786 commits. Following the split suggestion, automatic executable discovery is removed from this PR; it now only changes howsceSystemServiceLoadExechands its argument list to an executable converted with the existing--executableoption.core/relinker/main.cppanddocs/user/USAGE.mdare no longer touched.CxaFinalize_nid_no_patchcall this PR added to the launch branch is removed, here and in the new replacement path. The old process now ends after its shutdown callbacks without guest exit handlers or host destructors, as the launch path inmaindoes. A trialgit merge-treewith #5236 (d9649f61b) conflicts only on thesceSystemServiceLoadExecline ofdocs/dev/debt/libSceSystemService.md;Export.cppandGuestSystemExit.cppmerge cleanly.git merge-treewith #5158 (2f453805a) conflicts only on the test registration lines oflibSceSystemService/CMakeLists.txt.Neither #5236 nor #5158 is a prerequisite of this PR. I suggest they go first, since they are smaller, and I rebase this one after either merges; say so if you prefer another order.
Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7; Ubuntu 26.04 under WSL, GCC 15.2.0; Release,
BUILD_TESTING=ON, root configuration. Nine tests pass on both systems. WithExport.cppfrommainand the new test,loadexec_argumentsfails on both withLoadExec fixture: entry argument count. Local paths in the logs are replaced with<build>and<source>.Windows with the change (9 of 9)
Windows control: Export.cpp from main, new test
Linux with the change (9 of 9)
Linux control: Export.cpp from main, new test
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-13T18:49:27Z.
The PR overlap report now lists #5158, #5236 and #5284 against this PR, so the checklist declares the order proposed above:
Depends on: #5158, #5236, #5284. None is a functional prerequisite; each conflicts on adjacent lines only, and this PR is rebased after each of them merges.@MarcZX100 for #5284 (
37ea3b651): a trialgit merge-treeconflicts only incore/libs/tests/GuestSystemExit.cpp, where your--nested-exit-driverand--nested-exitmodes sit next to the mode checks this PR changes. The resolution keeps both; in the rebased version your two checks readargc > firstArgumentandargv[firstArgument]like the others.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T19:16:27Z.
Thanks for the separate merge-tree check and confirming the conflict keeps both changes. The ordering you declared works for me: #5284 is adjacent test-mode coverage rather than a functional prerequisite, and I can rebase it if #5083 lands first.
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-13T23:49:02Z.
Which titles pass an argument vector to
sceSystemServiceLoadExec, from a static survey of the homebrew catalog (no title was run):sceSystemServiceLoadExec; 37 have the call("exit", NULL)./app0/eboot.bin;/app0/eboot.binand/mnt/sandbox/PPSA99995_000/app0/eboot.bin;/app0/eboot.binand a vector that holds only the terminating null.Method: the 65 release archives listed in ps5-homebrew-catalog were downloaded (SHA-256 equal to the catalog records), 63 of them hold an
eboot.bin, which was unwrapped from its fake-signed container. Nothing was run. Imports come fromrelinker --registryandtools/import_audit.pyonmainbfc10637d. Call arguments are read from the instructions before each call site (objdump), which recovers a value only where the compiler loads a constant right before the call, so every count below is a lower bound.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T23:54:48Z.
Thanks for adding this survey. It gives useful evidence that the array-address call pattern occurs in real homebrew binaries, including explicit
/app0/eboot.binpaths. As you note, the static call-site scan is a lower bound and does not recover the vector contents at runtime, so I read it as evidence of usage rather than a title-level runtime result. The current host regression and control still demonstrate the argument-vector behavior itself.AI-assisted: yes; reviewed by MarcZX100.
Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-14T08:06:11Z.
Linux run of the full RetroArch frontend chain this PR is about: RetroArch (PPSA99169, catalog release) converted with
--executable picker/picker.bin --executable es-de/es-de.bin, Bazzite 44, GCC 16.2, Release, RX 7700 XT (RADV). Head9d4464a0cmerged intomain315260903.The run uses the title's game mode, the way ES-DE starts a game:
app0/game-request.txtnamesnova.nes(Nova the Squirrel, GPL NES homebrew) withfceummand/app0/es-de/es-de.binas the frontend,args.txtholds--max-frames=600, and the title starts with--ps5-mode=game. RetroArch runs the game, quits with status 0 after 11 s, and starts ES-DE throughsceSystemServiceLoadExec.mainalone: ES-DE printsUnknown option '/…/run/es-de.es-de.bin.elf'and returns at once. Itses-de-ps5.logshowsstart: arguments for ES-DE 2andES-DE returned 0, and the title goes back to the picker, so a game can never return to ES-DE.start: arguments for ES-DE 1, and ES-DE starts and renders. It then stops on an unrelated AGC stop,last provoking vertex with explicit per-vertex triangle-strip interpolation is unsupported(#5245).Merging into current
mainconflicts incore/libs/tests/GuestSystemExit.cppandcore/libs/prx/libSceSystemService/CMakeLists.txt. For this run I took this PR's side of both; the runtime build had no tests.One interaction with #5699, which I opened: after a guest
dup2onto descriptor 2 (RetroArch points stderr atapp0/trace.txt), the host standard error #4792 keeps is close-on-exec, so the next executable's runtime output goes to the title's file. In this run ES-DE's terminate report landed intrace.txt, not on the console. #5699 puts the kept descriptor back on 2 beforeexecv.Replacehere keeps descriptors 0 to 2 as they are and callsfexecve, so it needs the samedup2beforeclose_range. Whichever of the two lands second can add it; I can update #5699 if this one goes in first.Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-14T15:52:19Z.
@YossiYad thank you for the run. It is the title evidence this PR lacked: on
main, ES-DE started by RetroArch after a game takes the host path inargv[0]for an option and returns at once, and with this PR it starts. I've quoted it in the description.Rebased onto
main84b01f9cd, nowa1b80121c:GuestSystemExit.cppkeeps #5284's nested-exit modes, written in thefirstArgumentform of the other modes.libSceSystemService/CMakeLists.txtkeeps #5158's path-boundary test next toloadexec_arguments.libSceSystemServicenow linkslibSceAgcDriveronmain, soloadexec_argumentsalso copies that library beside the converted fixture. Without it the converted fixture failed to load on Linux.main'sExport.cpp,loadexec_argumentsstill fails on both withLoadExec fixture: entry argument count.On #5699: agreed. Whichever lands second adds the
dup2of the kept host standard error beforeclose_rangeinReplace. If #5699 is merged first, I'll add it here with your test covering it.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:39:52Z.
Checked on Linux with the PR merged onto current
main: build and tests green (312/312 in scope), includingloadexec_arguments,guest_system_exit*,guest_system_relaunchandguest_nested_exit. WithExport.cppreverted tomain,loadexec_argumentsfails, so the test covers the change. The Windows entry stub andCreateProcessWpath are covered byloadexec_argumentson the dispatched Windows Build; merging once that is green. Thanks @YossiYad for the title run.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T18:02:25Z.
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/tests/GuestSystemExit.cppL171-172