feat(libSceSystemService): restart the running title in sceSystemServiceLoadExec #1525

Closed
emaurel wants to merge 1 commit from upstream-pr/1525 into main
emaurel commented 2026-10-08 11:03:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by emaurel on 2026-10-08T11:03:40Z.


What

sceSystemServiceLoadExec("/app0/eboot.bin", argv) restarts the running title with the given arguments instead of throwing. Only "exit" was handled before.

  • The argument array is null-terminated and does not include the program name, as shadPS4 reads it (src/core/libraries/system/systemservice.cpp). The restarted title keeps the host argv[0]. Neither point is confirmed on a PS5 title; both are recorded in TechnicalDebt.
  • Any other executable still throws, because the relinker converts only the title's executable.
  • Linux: after the runtime shutdown (LibcRunShutdown), descriptors above 2 are marked close-on-exec, the signal mask and ignored signals are reset, and execv("/proc/self/exe", ...) replaces the process. The PID stays the same.
  • Windows: there is no process replacement. The new process gets an inherited SYNCHRONIZE handle to the old one, named by ANYPS5_LOAD_EXEC_PREVIOUS_PROCESS. libSceSystemService waits on it while loading, before the title runs. The old process runs the shutdown and then terminates. The two processes therefore never hold direct memory at the same time, which matters because it is committed in full (USAGE.md). Arguments are passed as UTF-8, the same encoding the entry stub uses, and are quoted by the CommandLineToArgvW rules. Arguments that are not UTF-8 throw before anything is started.

Tested

  • Windows 10 22H2 (19045), RTX 4060, WinLibs GCC 15.2.0 UCRT r7, Release, -DBUILD_TESTING=ON
    • The new guest_load_exec_restart restarts guest_system_exit_tests with two words, quote"d, trailing\, back\\"slash, ü and an empty argument. The restarted process checks that each argument arrives byte for byte, and that the old process had ended before it ran. The test's shutdown callback sleeps 500 ms, so a missing wait would be caught.
    • The 6 exit tests passed 10 times out of 10.
    • Deleting the wait makes the test fail.
    • The full suite passes 429 of 430. The one failure is agc_driver_srgb8_color_target, which is #1434 (addressed by the open #1441): it fails in 20 of 30 runs on main on this machine, and in 0 of 30 with that issue's Sleep(50) experiment. Its binary loads only libc, libkernel and libSceAgcDriver, none of which this PR changes.
  • Linux, Ubuntu 24.04 (WSL2), GCC 13.3, Release
    • The same test passed 10 times out of 10. The restarted process has the same PID. Before the restart, the old process ignores SIGPIPE and blocks SIGUSR1; the restarted process checks that both are back to their defaults.
    • Dropping an argument, skipping the shutdown, skipping the signal reset, or resetting only the mask each make it fail.
    • With --coverage, the test runs 32 of the 34 lines of the Linux half of LoadExec.cpp. The two lines not run are a pthread_sigmask failure path and the unreachable closing brace.
    • The full suite on lavapipe (Mesa 25.2.8, VK_DRIVER_FILES, GALLIUM_OVERRIDE_CPU_CAPS=avx) passes 434 of 435, with 22 GPU tests skipped. guest_video_out_wqhd_detection hit its 20 s timeout under -j4. Run alone it passes with this change, and it also timed out without it.
  • python3 tools/check_conventions.py --base upstream/main passes.
  • No title or homebrew was tested.

Checklist

  • Based on current main; no other open pull request implements the same functions (#1269 also edits libSceSystemService/Export.cpp, for DisableMediaPlay/ReenableMediaPlay only)
  • 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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4785773249 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1525). Originally posted by [emaurel](https://github.com/emaurel) on 2026-10-08T11:03:40Z. --- ### What `sceSystemServiceLoadExec("/app0/eboot.bin", argv)` restarts the running title with the given arguments instead of throwing. Only `"exit"` was handled before. - The argument array is null-terminated and does not include the program name, as [shadPS4](https://github.com/shadps4-emu/shadPS4) reads it (`src/core/libraries/system/systemservice.cpp`). The restarted title keeps the host `argv[0]`. Neither point is confirmed on a PS5 title; both are recorded in TechnicalDebt. - Any other executable still throws, because the relinker converts only the title's executable. - **Linux**: after the runtime shutdown (`LibcRunShutdown`), descriptors above 2 are marked close-on-exec, the signal mask and ignored signals are reset, and `execv("/proc/self/exe", ...)` replaces the process. The PID stays the same. - **Windows**: there is no process replacement. The new process gets an inherited `SYNCHRONIZE` handle to the old one, named by `ANYPS5_LOAD_EXEC_PREVIOUS_PROCESS`. libSceSystemService waits on it while loading, before the title runs. The old process runs the shutdown and then terminates. The two processes therefore never hold direct memory at the same time, which matters because it is committed in full (USAGE.md). Arguments are passed as UTF-8, the same encoding the entry stub uses, and are quoted by the `CommandLineToArgvW` rules. Arguments that are not UTF-8 throw before anything is started. ### Tested - **Windows 10 22H2 (19045)**, RTX 4060, WinLibs GCC 15.2.0 UCRT r7, Release, `-DBUILD_TESTING=ON` - The new `guest_load_exec_restart` restarts `guest_system_exit_tests` with `two words`, `quote"d`, `trailing\`, `back\\"slash`, `ü` and an empty argument. The restarted process checks that each argument arrives byte for byte, and that the old process had ended before it ran. The test's shutdown callback sleeps 500 ms, so a missing wait would be caught. - The 6 exit tests passed 10 times out of 10. - Deleting the wait makes the test fail. - The full suite passes 429 of 430. The one failure is `agc_driver_srgb8_color_target`, which is #1434 (addressed by the open #1441): it fails in 20 of 30 runs on `main` on this machine, and in 0 of 30 with that issue's `Sleep(50)` experiment. Its binary loads only libc, libkernel and libSceAgcDriver, none of which this PR changes. - **Linux, Ubuntu 24.04 (WSL2)**, GCC 13.3, Release - The same test passed 10 times out of 10. The restarted process has the same PID. Before the restart, the old process ignores `SIGPIPE` and blocks `SIGUSR1`; the restarted process checks that both are back to their defaults. - Dropping an argument, skipping the shutdown, skipping the signal reset, or resetting only the mask each make it fail. - With `--coverage`, the test runs 32 of the 34 lines of the Linux half of `LoadExec.cpp`. The two lines not run are a `pthread_sigmask` failure path and the unreachable closing brace. - The full suite on lavapipe (Mesa 25.2.8, `VK_DRIVER_FILES`, `GALLIUM_OVERRIDE_CPU_CAPS=avx`) passes 434 of 435, with 22 GPU tests skipped. `guest_video_out_wqhd_detection` hit its 20 s timeout under `-j4`. Run alone it passes with this change, and it also timed out without it. - `python3 tools/check_conventions.py --base upstream/main` passes. - No title or homebrew was tested. ### Checklist - [x] Based on current `main`; no other open pull request implements the same functions (#1269 also edits `libSceSystemService/Export.cpp`, for `DisableMediaPlay`/`ReenableMediaPlay` only) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
klosixgaming-arch commented 2026-10-08 11:15:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T11:15:15Z.

Review: COMMENTED


Solid implementation of sceSystemServiceLoadExec for title restart. The cross-platform approach (execv on Linux, CreateProcess with synchronization on Windows) is well thought out and handles the tricky aspects like signal reset, descriptor management, and process termination ordering.

Strengths:

  • Comprehensive testing covering argument passing, special characters, UTF-8 handling, and edge cases
  • Good documentation in TechnicalDebt about platform differences and unverified behavior
  • Proper synchronization to prevent both processes from holding direct memory simultaneously on Windows

Minor notes:

  1. The PR is marked as draft - appropriate given the complexity
  2. Consider whether the ANYPS5_LOAD_EXEC_PREVIOUS_PROCESS environment variable name should be documented for users who might need to debug restart issues

This looks ready to merge once CI passes and any rebase conflicts are resolved.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5455695369 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1525#pullrequestreview-5455695369). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T11:15:15Z. **Review:** COMMENTED --- Solid implementation of `sceSystemServiceLoadExec` for title restart. The cross-platform approach (execv on Linux, CreateProcess with synchronization on Windows) is well thought out and handles the tricky aspects like signal reset, descriptor management, and process termination ordering. **Strengths:** - Comprehensive testing covering argument passing, special characters, UTF-8 handling, and edge cases - Good documentation in TechnicalDebt about platform differences and unverified behavior - Proper synchronization to prevent both processes from holding direct memory simultaneously on Windows **Minor notes:** 1. The PR is marked as draft - appropriate given the complexity 2. Consider whether the `ANYPS5_LOAD_EXEC_PREVIOUS_PROCESS` environment variable name should be documented for users who might need to debug restart issues This looks ready to merge once CI passes and any rebase conflicts are resolved.
klosixgaming-arch commented 2026-10-08 11:21:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T11:21:47Z.

Review: APPROVED


Excellent implementation of sceSystemServiceLoadExec for title restart. This is a complex feature that requires careful handling of both Linux and Windows process models.

Strengths:

  • Clean separation into dedicated LoadExec.cpp/LoadExec.hpp files
  • Proper platform-specific implementations: execv on Linux, new process creation with inherited handle on Windows
  • Comprehensive test coverage including edge cases (quotes, backslashes, UTF-8 characters, empty arguments)
  • Good handling of signal reset and descriptor cleanup on Linux
  • Thorough documentation of limitations in TechnicalDebt.md

Technical notes:

  • The Windows approach using an inherited SYNCHRONIZE handle via environment variable is a clever solution to the lack of process replacement
  • Proper UTF-8 validation before starting the new process prevents encoding issues
  • Test cases properly verify argument passing, signal reset, and previous process termination

This will improve compatibility with titles that use sceSystemServiceLoadExec for restart functionality. Ready to merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5455776902 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1525#pullrequestreview-5455776902). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T11:21:47Z. **Review:** APPROVED --- Excellent implementation of `sceSystemServiceLoadExec` for title restart. This is a complex feature that requires careful handling of both Linux and Windows process models. **Strengths:** - Clean separation into dedicated `LoadExec.cpp`/`LoadExec.hpp` files - Proper platform-specific implementations: `execv` on Linux, new process creation with inherited handle on Windows - Comprehensive test coverage including edge cases (quotes, backslashes, UTF-8 characters, empty arguments) - Good handling of signal reset and descriptor cleanup on Linux - Thorough documentation of limitations in TechnicalDebt.md **Technical notes:** - The Windows approach using an inherited SYNCHRONIZE handle via environment variable is a clever solution to the lack of process replacement - Proper UTF-8 validation before starting the new process prevents encoding issues - Test cases properly verify argument passing, signal reset, and previous process termination This will improve compatibility with titles that use `sceSystemServiceLoadExec` for restart functionality. Ready to merge.
oneandonlydean commented 2026-10-09 09:22:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:22:13Z.


Which title calls sceSystemServiceLoadExec("/app0/eboot.bin", ...) on main? This adds a lot of process handling, so it needs a title that stops there: the ID and the log line. Otherwise I'll close it until one does.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078119541 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1525#issuecomment-6078119541). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:22:13Z. --- Which title calls `sceSystemServiceLoadExec("/app0/eboot.bin", ...)` on main? This adds a lot of process handling, so it needs a title that stops there: the ID and the log line. Otherwise I'll close it until one does.
adriadam10 commented 2026-10-09 23:52:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:52:53Z.

Review: CHANGES_REQUESTED


Thanks for the thorough work and the Windows/Linux test coverage. As @oneandonlydean asked, this needs a concrete title before it can go in:

  • Which title calls sceSystemServiceLoadExec("/app0/eboot.bin", ...) and stops there on main? Please add the PPSA id and the log line (the NotImplemented_nid_no_patch abort). Neither the PR body nor the linked PRs name one ("No title or homebrew was tested"), and the argument layout (no program name, null-terminated) is only taken from shadPS4, so a real call site would also confirm it.
  • Without that, the process handling added here (LoadExec.cpp, descriptor/signal reset, Windows handle hand-off) can't be justified. If no title reaches it yet, we'd rather keep the throw until one does.

Once a title is named, I'm happy to re-review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5476441960 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1525#pullrequestreview-5476441960). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T23:52:53Z. **Review:** CHANGES_REQUESTED --- Thanks for the thorough work and the Windows/Linux test coverage. As @oneandonlydean asked, this needs a concrete title before it can go in: - Which title calls `sceSystemServiceLoadExec("/app0/eboot.bin", ...)` and stops there on `main`? Please add the PPSA id and the log line (the `NotImplemented_nid_no_patch` abort). Neither the PR body nor the linked PRs name one ("No title or homebrew was tested"), and the argument layout (no program name, null-terminated) is only taken from shadPS4, so a real call site would also confirm it. - Without that, the process handling added here (`LoadExec.cpp`, descriptor/signal reset, Windows handle hand-off) can't be justified. If no title reaches it yet, we'd rather keep the throw until one does. Once a title is named, I'm happy to re-review.
emaurel commented 2026-10-10 08:46:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by emaurel on 2026-10-10T08:46:12Z.


No title on main reaches sceSystemServiceLoadExec("/app0/eboot.bin", ...) as far as I know, so I'm closing this. I'll reopen it with the title ID and the log line if I find one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095810348 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1525#issuecomment-6095810348). Originally posted by [emaurel](https://github.com/emaurel) on 2026-10-10T08:46:12Z. --- No title on main reaches `sceSystemServiceLoadExec("/app0/eboot.bin", ...)` as far as I know, so I'm closing this. I'll reopen it with the title ID and the log line if I find one.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1525
No description provided.