feat(libkernel): implement execv, execvp and execve process replacement #9669

Merged
fogydes merged 163 commits from upstream-pr/9669 into main 2026-10-26 15:36:56 +00:00
fogydes commented 2026-10-22 07:37:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-22T07:37:18Z.


What

execv, execvp and execve (libkernel) replace the running process image with the already-converted executable of the requested guest program instead of throwing. The path resolves with the same rules posix_spawn uses: it must be under /app0/, /app0/eboot.bin maps to the running image itself, anything else is found beside the running image under its flattened name, and execvp walks the guest PATH (FreeBSD 11's _PATH_DEFPATH when unset). Argument validation follows FreeBSD 11.4's exec_copyin_args and execvPe: EBADF for a null path (measured on a console) and EFAULT for a null argv; an empty argv, a null envp and entries without = are copied through; the combined string bytes of the arguments and of execve's envp (or the host environ for the implicit execv/execvp environment) beyond 262144 return E2BIG; the lookup also rejects a regular file without execute permission with EACCES (a 0644 file measured on a console; on Windows the check runs libc access's ACL FILE_EXECUTE since host files carry no Unix mode bits) and a path through a regular file with ENOTDIR, and the PATH search keeps going past non-regular or inexecutable candidates, keeping their EACCES, ending with EACCES or ENOENT. On Linux the image is genuinely replaced through the host fexecve on an O_CLOEXEC descriptor of the converted target: the pid, descriptors and working directory survive as POSIX requires, buffers are discarded and no exit handlers run; a converted target that is not an x86-64 Linux ELF returns ENOEXEC (measured on a console) and one that rejects execute permission EACCES, while a target that cannot be opened still throws like LoadExec, leaving the process intact. On Windows there is no replace; the converted target is validated as an x86-64 PE image first and a non-image returns ENOEXEC before the relay starts; the replacement reuses the LoadExec relay: the converted target starts suspended with the duplicated parent handle (ANYPS5_LOADEXEC_PARENT), descriptors 0-2 and the caller's argv (ANYPS5_LOADEXEC_ARGV_SKIP=1), its environment inheriting the host variables with execve's envp overriding same-named host ones (the envp alone is not reproduced and the new image's guest environment table still starts empty, both recorded in the debt; a follow-up can seed it from the relay), and the caller then terminates itself (TerminateProcess) with status 0 and no exit handlers; because the replacement's entry waits for the caller to die before it starts, the caller cannot wait for the replacement's exit status, so a posix_spawn parent waiting on an execed child reads 0, not the replacement's own status (recorded in the debt; a follow-up could re-register the parent's wait handle), and a failing relay terminates the suspended child and throws; the host pid changes and descriptors beyond 0-2 do not survive, both inherited from the LoadExec model. On both hosts the registered shutdown and atexit/__cxa_atexit handlers do not run across a successful exec, and a missing converted executable still throws (NotImplemented_nid_no_patch) like posix_spawn. A target outside /app0/ also still throws the round-mean error; the byte limit and the null-argv EFAULT are not measured on a console.

Tested

Windows 11 x64, MinGW-w64 GCC 15.2: the exec_arguments start-to-end relay test passes (the first image validates the rejections: null path EBADF and null argv EFAULT, an empty argv and a null envp accepted, an unpaired env entry copied, each with an absent path returning ENOENT, oversized argv and oversized envp each rejected with E2BIG, the execvp PATH miss ENOENT, the missing-conversion throw, a path beyond a regular file rejected with ENOTDIR and a converted target without an executable image rejected with ENOEXEC, then it execs picker/second.bin through execve; the replacement verifies entry/getargv arguments including spaces, quotes, backslashes and Unicode, the exact envp list (EXEC_SECOND set, inherited PATH absent, relay variables removed), the image-directory cwd reset, the first/launch/second event order with no shutdown/guest-exit/host-exit handler run, and two distinct host pids; return code 0 from the terminated caller); guest_execvp passes with its validation battery rewritten for the new behaviour, and guest_waitpid, guest_posix_spawn and loadexec_arguments pass unchanged. Linux x64 Debian (gcc 14.2, WSL2): the same five tests pass, with exec_arguments additionally rejecting a 0644 regular file with EACCES in the POSIX build, keeping pid retention (the replacement keeps the pid, return code 37 from the replacement) and the POSIX cwd preservation. No real title run end to end.

Checklist

  • Based on current main; no other open PR implements the same functions
  • 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 under Silent stubs in their library's technical debt file
  • 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: #9133
  • Fixes: none
  • Unblocks: PPSA97358 (execv); PPSA85300 (execvp, discussion #7971)
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4963819922 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9669). Originally posted by [fogydes](https://github.com/fogydes) on 2026-10-22T07:37:18Z. --- ### What `execv`, `execvp` and `execve` (libkernel) replace the running process image with the already-converted executable of the requested guest program instead of throwing. The path resolves with the same rules `posix_spawn` uses: it must be under `/app0/`, `/app0/eboot.bin` maps to the running image itself, anything else is found beside the running image under its flattened name, and `execvp` walks the guest `PATH` (FreeBSD 11's `_PATH_DEFPATH` when unset). Argument validation follows FreeBSD 11.4's `exec_copyin_args` and `execvPe`: `EBADF` for a null path (measured on a console) and `EFAULT` for a null `argv`; an empty `argv`, a null `envp` and entries without `=` are copied through; the combined string bytes of the arguments and of `execve`'s `envp` (or the host `environ` for the implicit `execv`/`execvp` environment) beyond 262144 return `E2BIG`; the lookup also rejects a regular file without execute permission with `EACCES` (a 0644 file measured on a console; on Windows the check runs libc `access`'s ACL `FILE_EXECUTE` since host files carry no Unix mode bits) and a path through a regular file with `ENOTDIR`, and the `PATH` search keeps going past non-regular or inexecutable candidates, keeping their `EACCES`, ending with `EACCES` or `ENOENT`. On Linux the image is genuinely replaced through the host `fexecve` on an `O_CLOEXEC` descriptor of the converted target: the pid, descriptors and working directory survive as POSIX requires, buffers are discarded and no exit handlers run; a converted target that is not an x86-64 Linux ELF returns `ENOEXEC` (measured on a console) and one that rejects execute permission `EACCES`, while a target that cannot be opened still throws like LoadExec, leaving the process intact. On Windows there is no replace; the converted target is validated as an x86-64 PE image first and a non-image returns `ENOEXEC` before the relay starts; the replacement reuses the LoadExec relay: the converted target starts suspended with the duplicated parent handle (`ANYPS5_LOADEXEC_PARENT`), descriptors 0-2 and the caller's argv (`ANYPS5_LOADEXEC_ARGV_SKIP=1`), its environment inheriting the host variables with `execve`'s `envp` overriding same-named host ones (the `envp` alone is not reproduced and the new image's guest environment table still starts empty, both recorded in the debt; a follow-up can seed it from the relay), and the caller then terminates itself (`TerminateProcess`) with status 0 and no exit handlers; because the replacement's entry waits for the caller to die before it starts, the caller cannot wait for the replacement's exit status, so a `posix_spawn` parent waiting on an execed child reads 0, not the replacement's own status (recorded in the debt; a follow-up could re-register the parent's wait handle), and a failing relay terminates the suspended child and throws; the host pid changes and descriptors beyond 0-2 do not survive, both inherited from the LoadExec model. On both hosts the registered shutdown and `atexit`/`__cxa_atexit` handlers do not run across a successful exec, and a missing converted executable still throws (`NotImplemented_nid_no_patch`) like `posix_spawn`. A target outside `/app0/` also still throws the round-mean error; the byte limit and the null-argv `EFAULT` are not measured on a console. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 x64, MinGW-w64 GCC 15.2: the `exec_arguments` start-to-end relay test passes (the first image validates the rejections: null path `EBADF` and null argv `EFAULT`, an empty `argv` and a null `envp` accepted, an unpaired env entry copied, each with an absent path returning `ENOENT`, oversized `argv` and oversized `envp` each rejected with `E2BIG`, the `execvp` `PATH` miss `ENOENT`, the missing-conversion throw, a path beyond a regular file rejected with `ENOTDIR` and a converted target without an executable image rejected with `ENOEXEC`, then it execs `picker/second.bin` through `execve`; the replacement verifies entry/getargv arguments including spaces, quotes, backslashes and Unicode, the exact envp list (`EXEC_SECOND` set, inherited `PATH` absent, relay variables removed), the image-directory cwd reset, the `first/launch/second` event order with no shutdown/guest-exit/host-exit handler run, and two distinct host pids; return code 0 from the terminated caller); `guest_execvp` passes with its validation battery rewritten for the new behaviour, and `guest_waitpid`, `guest_posix_spawn` and `loadexec_arguments` pass unchanged. Linux x64 Debian (gcc 14.2, WSL2): the same five tests pass, with `exec_arguments` additionally rejecting a 0644 regular file with `EACCES` in the POSIX build, keeping pid retention (the replacement keeps the pid, return code 37 from the replacement) and the POSIX cwd preservation. No real title run end to end. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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: #9133 - [x] Fixes: none - [x] Unblocks: PPSA97358 (`execv`); PPSA85300 (`execvp`, discussion #7971) - [x] GPUs tested: n/a - [x] AI-assisted: yes
fogydes commented 2026-10-22 07:51:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-22T07:51:33Z.


Same flag as on #9133, and the cause is the same commit: the progress report only counts a function as implemented when its body — directly or through any helper — no longer reaches NotImplemented_nid_no_patch (tools/progress.py, the STUB_WRAPPER closure feeding scan_library). Nothing actually reverted. waitpid comes from the posix_spawn branch this one depends on, and its Linux arm throws for child-death signals 16/29/30 (no console mapping, recorded in docs/dev/debt/libkernel.md), so the classifier moves it back to stubs.

The three exec functions themselves stay in the todo count for the same rule: their resolution paths still throw for the cases the convention reserves NotImplemented_nid_no_patch for — a program outside /app0/ and a requested guest program with no converted executable available. Those throws are deliberate and debt-documented; everything the converted image exists for is implemented and covered by guest_execvp and the new exec_arguments relay test.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6335654679 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9669#issuecomment-6335654679). Originally posted by [fogydes](https://github.com/fogydes) on 2026-10-22T07:51:33Z. --- Same flag as on #9133, and the cause is the same commit: the progress report only counts a function as implemented when its body — directly or through any helper — no longer reaches `NotImplemented_nid_no_patch` (`tools/progress.py`, the `STUB_WRAPPER` closure feeding `scan_library`). Nothing actually reverted. `waitpid` comes from the posix_spawn branch this one depends on, and its Linux arm throws for child-death signals 16/29/30 (no console mapping, recorded in `docs/dev/debt/libkernel.md`), so the classifier moves it back to stubs. The three `exec` functions themselves stay in the todo count for the same rule: their resolution paths still throw for the cases the convention reserves `NotImplemented_nid_no_patch` for — a program outside `/app0/` and a requested guest program with no converted executable available. Those throws are deliberate and debt-documented; everything the converted image exists for is implemented and covered by `guest_execvp` and the new `exec_arguments` relay test.
fogydes commented 2026-10-22 08:12:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-22T08:12:52Z.


The relinker matrix on the head of this PR fails exactly once: conventions_function_bodies_shard_11 (Timeout) on job 119700497742, 229/230 tests pass, and the windows, ubuntu relinker and relinker-asan jobs pass.

Nothing in the diff plausibly slows that shard: adding three exec exports to libkernel does not touch the function-body scanner's input in bulk. Per CONTRIBUTING, ctest runs in parallel on CI, so a slow test competes for the cores and times out on some attempts and not on others; a 120 s budget crossing on a macOS runner is the usual shape. I would re-run the failed job; if the shard timeout reproduces on several PRs in a row, the shard is near its budget and the right move per CODCONTRIBUTING would be splitting/shrinking it rather than raising the timeout.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6336032562 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9669#issuecomment-6336032562). Originally posted by [fogydes](https://github.com/fogydes) on 2026-10-22T08:12:52Z. --- The relinker matrix on the head of this PR fails exactly once: `conventions_function_bodies_shard_11 (Timeout)` on [job 119700497742](https://github.com/boykopovar/AnyPS5/actions/runs/39741770486/job/119700497742), 229/230 tests pass, and the windows, ubuntu relinker and relinker-asan jobs pass. Nothing in the diff plausibly slows that shard: adding three exec exports to libkernel does not touch the function-body scanner's input in bulk. Per CONTRIBUTING, ctest runs in parallel on CI, so a slow test competes for the cores and times out on some attempts and not on others; a 120 s budget crossing on a macOS runner is the usual shape. I would re-run the failed job; if the shard timeout reproduces on several PRs in a row, the shard is near its budget and the right move per CODCONTRIBUTING would be splitting/shrinking it rather than raising the timeout.
MarcZX10 commented 2026-10-22 09:03:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T09:03:02Z.

Review: DISMISSED


The process replacement path has a concrete E2BIG gap: the byte total always uses the inherited environ, even for execve, where the supplied envp replaces it. A large envp with a small inherited environment therefore bypasses the advertised 262144-byte check; the current oversized-input test exercises argv only. Please select the environment vector based on implicitEnvironment, include that vector in the total, and add an execve case whose envp alone exceeds the limit.\n\nReview validation: exact-head diff-check passed; python3 tools/check_conventions.py --base upstream/main passed; hosted Linux/Windows relinker jobs and their new test_exec_arguments coverage passed. The macOS clang relinker job built successfully and ran 229/230 tests; conventions_function_bodies_shard_11 timed out at 30 seconds. I inspected its log; this is a timeout, not an assertion failure. Local runtime fixture execution was not repeated in this environment.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5611721904 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9669#pullrequestreview-5611721904). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T09:03:02Z. **Review:** DISMISSED --- The process replacement path has a concrete E2BIG gap: the byte total always uses the inherited environ, even for execve, where the supplied envp replaces it. A large envp with a small inherited environment therefore bypasses the advertised 262144-byte check; the current oversized-input test exercises argv only. Please select the environment vector based on implicitEnvironment, include that vector in the total, and add an execve case whose envp alone exceeds the limit.\n\nReview validation: exact-head diff-check passed; `python3 tools/check_conventions.py --base upstream/main` passed; hosted Linux/Windows relinker jobs and their new `test_exec_arguments` coverage passed. The macOS clang relinker job built successfully and ran 229/230 tests; `conventions_function_bodies_shard_11` timed out at 30 seconds. I inspected its log; this is a timeout, not an assertion failure. Local runtime fixture execution was not repeated in this environment.
MarcZX10 commented 2026-10-22 11:39:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T11:39:45Z.


I found a live overlap with #9526: both branches add a docs/dev/debt/libc.md entry at the same insertion point, and their pairwise three-way merge currently conflicts in that file. Please coordinate landing order with #9526’s author and declare Depends on if either branch must land first; retain both debt entries when rebasing. This is a documentation insertion conflict, not an overlap in the process-replacement implementation.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6339834425 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9669#issuecomment-6339834425). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T11:39:45Z. --- I found a live overlap with #9526: both branches add a `docs/dev/debt/libc.md` entry at the same insertion point, and their pairwise three-way merge currently conflicts in that file. Please coordinate landing order with #9526’s author and declare `Depends on` if either branch must land first; retain both debt entries when rebasing. This is a documentation insertion conflict, not an overlap in the process-replacement implementation.
harisibrar1 commented 2026-10-22 13:08:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T13:08:01Z.

Review: COMMENTED


Checked against main 3ca07d086d, FreeBSD releng/11.4 sys/kern/kern_exec.c (exec_copyin_args), sys/sys/syslimits.h and lib/libc/gen/exec.c. I didn't repeat the envp E2BIG point @MarcZX10 already raised:

  • execve's envp replaces the emulator's host environment, and the guest never sees it. fexecve(..., environment) (Process.cpp:679) and the Windows block built only from the guest entries (:440) start the replacement without LD_LIBRARY_PATH, DISPLAY, WAYLAND_DISPLAY, XDG_RUNTIME_DIR, HOME and APS5_*/ANYPS5_* on Linux, and without SystemRoot, PATH and TEMP on Windows. Meanwhile the new image's guest environment still starts empty (emptyEnvironment and libc's static table), so getenv("FOO") after execve(..., {"FOO=1", NULL}) returns NULL. The test passes because SecondEnvironment() (GuestExecHost.cpp:98-110) copies the host's LD_LIBRARY_PATH and the test root into the guest envp. Could the host environment be kept as is, with the guest envp passed separately and seeded into the guest table? Or throw for a non-empty envp until that exists, and record it in the debt file.
  • On Windows, waiters see exit status 0 as soon as exec happens. The caller ends with TerminateProcess(GetCurrentProcess(), 0) (:448), and #9133's WaitChildProcess_nid_no_patch waits on that handle. So a parent that posix_spawns a.bin, which then execvs b.bin, gets status 0 from waitpid immediately, and b.bin's real exit code is never reported. test_exec_arguments.py:92 asserts this (0 on Windows, 37 on Linux). Could the caller wait on the replacement and exit with its code? If that's out of scope, it should at least be in the debt entry.
  • Some errno results are not FreeBSD 11.4's. In exec_copyin_args (kern_exec.c:1172-1262), only a NULL argv gives EFAULT. An empty argv is accepted, but here it returns EFAULT (:654). A NULL envv is accepted (if (envv)), but execve here returns EFAULT (:695). An env entry without = is copied unchecked, but here it returns EFAULT (:660). ARG_MAX (262144) counts only string bytes including the NUL, so adding sizeof(char*) per entry (:314) makes argv = path + 29,999 × "a" (about 60 KB of strings) fail with E2BIG. Since the console behaviour is unverified, could these follow FreeBSD or throw, rather than return errors of their own? GuestExecHost.cpp:127/129/131 would need updating to match.
  • On Linux, the ELF/X_OK check on the converted file (:669-677) is reported to the guest as EACCES/ENOEXEC. That file is the relinker's output, so a failure is a host packaging problem. LoadExec.cpp:158 on main throws for the same check, and throwing here would match it.
  • Minor: ExecProgramFound (:245-262) takes the first PATH entry that merely exists. A directory or data file earlier in PATH then throws, where FreeBSD's execvPe would keep searching after EACCES.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5614689903 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9669#pullrequestreview-5614689903). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-22T13:08:01Z. **Review:** COMMENTED --- Checked against main 3ca07d086d, FreeBSD releng/11.4 `sys/kern/kern_exec.c` (`exec_copyin_args`), `sys/sys/syslimits.h` and `lib/libc/gen/exec.c`. I didn't repeat the envp E2BIG point @MarcZX10 already raised: - **execve's envp replaces the emulator's host environment, and the guest never sees it.** `fexecve(..., environment)` (Process.cpp:679) and the Windows block built only from the guest entries (:440) start the replacement without LD_LIBRARY_PATH, DISPLAY, WAYLAND_DISPLAY, XDG_RUNTIME_DIR, HOME and `APS5_*`/`ANYPS5_*` on Linux, and without SystemRoot, PATH and TEMP on Windows. Meanwhile the new image's guest environment still starts empty (`emptyEnvironment` and libc's static table), so `getenv("FOO")` after `execve(..., {"FOO=1", NULL})` returns NULL. The test passes because `SecondEnvironment()` (`GuestExecHost.cpp:98-110`) copies the host's LD_LIBRARY_PATH and the test root into the guest envp. Could the host environment be kept as is, with the guest envp passed separately and seeded into the guest table? Or throw for a non-empty envp until that exists, and record it in the debt file. - **On Windows, waiters see exit status 0 as soon as exec happens.** The caller ends with `TerminateProcess(GetCurrentProcess(), 0)` (:448), and #9133's `WaitChildProcess_nid_no_patch` waits on that handle. So a parent that `posix_spawn`s a.bin, which then `execv`s b.bin, gets status 0 from `waitpid` immediately, and b.bin's real exit code is never reported. `test_exec_arguments.py:92` asserts this (0 on Windows, 37 on Linux). Could the caller wait on the replacement and exit with its code? If that's out of scope, it should at least be in the debt entry. - **Some errno results are not FreeBSD 11.4's.** In `exec_copyin_args` (kern_exec.c:1172-1262), only a NULL argv gives EFAULT. An empty argv is accepted, but here it returns EFAULT (:654). A NULL envv is accepted (`if (envv)`), but execve here returns EFAULT (:695). An env entry without `=` is copied unchecked, but here it returns EFAULT (:660). ARG_MAX (262144) counts only string bytes including the NUL, so adding `sizeof(char*)` per entry (:314) makes argv = path + 29,999 × "a" (about 60 KB of strings) fail with E2BIG. Since the console behaviour is unverified, could these follow FreeBSD or throw, rather than return errors of their own? `GuestExecHost.cpp:127/129/131` would need updating to match. - **On Linux, the ELF/X_OK check on the converted file (:669-677) is reported to the guest as EACCES/ENOEXEC.** That file is the relinker's output, so a failure is a host packaging problem. `LoadExec.cpp:158` on main throws for the same check, and throwing here would match it. - Minor: `ExecProgramFound` (:245-262) takes the first PATH entry that merely exists. A directory or data file earlier in PATH then throws, where FreeBSD's `execvPe` would keep searching after EACCES. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
jotitadev commented 2026-10-23 04:42:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-23T04:42:24Z.

Review: COMMENTED


macOS check of the non-Windows branches (M2 Max, macOS 27.2, Apple clang 21, x86-64 under Rosetta). main doesn't link on macOS, so I applied this PR's diff (head be747c9a03, docs excluded) onto the macOS port in #8658 (4e0468722f); the only conflict was one adjacent extern declaration in libkernel/System/src/Process.cpp.

Two files don't compile on macOS:

  • libkernel/System/src/Process.cpp:802 (ExecProgram): error: use of undeclared identifier 'fexecve'. macOS has no fexecve, so the #else branch needs an Apple path, for example execve on the validated path.
  • libSceLibcInternal/Spawn.cpp:124,127 (OwnExecutable, __APPLE__ branch): error: use of undeclared identifier '_NSGetExecutablePath'. It is declared in <mach-o/dyld.h>, not <crt_externs.h>. A one-line test file compiles with the first header and fails with the second.

Two runtime problems on macOS in the same #else branches:

  • ExecOwnExecutable() in Process.cpp and OwnExecutablePath() in GuestExecvp.cpp read /proc/self/exe, which doesn't exist on macOS (read_symlink gives ENOENT). Every exec* call would therefore throw exec: cannot read /proc/self/exe. Spawn.cpp already has the _NSGetExecutablePath branch; these two could reuse it.
  • The header check before fexecve accepts only an x86-64 ELF (7f 45 4c 46, machine 62). On macOS the relinker writes a Mach-O executable (MacOsMachOPatcher in #8658's Conversion.cpp), so a converted target would fail with ENOEXEC even after the compile errors above are fixed.

libc/src/Process.cpp, GuestPosixSpawn.cpp and GuestExecvp.cpp compile on macOS. I did not link or run the exec tests. The PR currently conflicts with main, so this is for the next rebase.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5623974135 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9669#pullrequestreview-5623974135). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-23T04:42:24Z. **Review:** COMMENTED --- macOS check of the non-Windows branches (M2 Max, macOS 27.2, Apple clang 21, x86-64 under Rosetta). `main` doesn't link on macOS, so I applied this PR's diff (head `be747c9a03`, docs excluded) onto the macOS port in #8658 (`4e0468722f`); the only conflict was one adjacent `extern` declaration in `libkernel/System/src/Process.cpp`. Two files don't compile on macOS: - `libkernel/System/src/Process.cpp:802` (`ExecProgram`): `error: use of undeclared identifier 'fexecve'`. macOS has no `fexecve`, so the `#else` branch needs an Apple path, for example `execve` on the validated path. - `libSceLibcInternal/Spawn.cpp:124,127` (`OwnExecutable`, `__APPLE__` branch): `error: use of undeclared identifier '_NSGetExecutablePath'`. It is declared in `<mach-o/dyld.h>`, not `<crt_externs.h>`. A one-line test file compiles with the first header and fails with the second. Two runtime problems on macOS in the same `#else` branches: - `ExecOwnExecutable()` in `Process.cpp` and `OwnExecutablePath()` in `GuestExecvp.cpp` read `/proc/self/exe`, which doesn't exist on macOS (`read_symlink` gives `ENOENT`). Every `exec*` call would therefore throw `exec: cannot read /proc/self/exe`. `Spawn.cpp` already has the `_NSGetExecutablePath` branch; these two could reuse it. - The header check before `fexecve` accepts only an x86-64 ELF (`7f 45 4c 46`, machine 62). On macOS the relinker writes a Mach-O executable (`MacOsMachOPatcher` in #8658's `Conversion.cpp`), so a converted target would fail with `ENOEXEC` even after the compile errors above are fixed. `libc/src/Process.cpp`, `GuestPosixSpawn.cpp` and `GuestExecvp.cpp` compile on macOS. I did not link or run the exec tests. The PR currently conflicts with `main`, so this is for the next rebase. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
adriadam10 commented 2026-10-24 02:34:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T02:34:58Z.

Review: CHANGES_REQUESTED


Thanks for this. Points to fix before it can land:

  • core/libs/prx/libkernel/System/src/Process.cpp:656: the E2BIG total always adds environ, even for execve, where the supplied envp replaces it. A small inherited environment plus an envp over 262144 bytes passes. Measure environment when !implicitEnvironment and environ otherwise, and add an execve test where envp alone exceeds the limit (the current test covers argv only). Same point as @MarcZX10's review.
  • Process.cpp:679 (and the Windows block at :440): execve hands the replacement only the guest envp, so it starts without the emulator's host variables (LD_LIBRARY_PATH, DISPLAY, WAYLAND_DISPLAY, XDG_RUNTIME_DIR, HOME, APS5_*/ANYPS5_* on Linux; SystemRoot, PATH, TEMP on Windows), which the converted program needs to start. Please see @harisibrar1's review and keep the host runtime variables in the replacement environment.
  • Process.cpp:679: fexecve does not exist on macOS (use of undeclared identifier 'fexecve', per @jotitadev's build), and the relinker (macos-latest, clang++) job is red. The #else branch needs an Apple path (e.g. execve on the validated path) or an explicit throw recorded in the debt file.
  • The branch conflicts with main, and docs/dev/debt/libc.md collides with #9526 at the same insertion point; keep both entries when rebasing. It is also stacked on #9133, which is still open, so it can only land after it.

Welcome back once these are addressed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636441363 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9669#pullrequestreview-5636441363). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-24T02:34:58Z. **Review:** CHANGES_REQUESTED --- Thanks for this. Points to fix before it can land: - `core/libs/prx/libkernel/System/src/Process.cpp:656`: the E2BIG total always adds `environ`, even for `execve`, where the supplied `envp` replaces it. A small inherited environment plus an `envp` over 262144 bytes passes. Measure `environment` when `!implicitEnvironment` and `environ` otherwise, and add an `execve` test where `envp` alone exceeds the limit (the current test covers argv only). Same point as @MarcZX10's review. - `Process.cpp:679` (and the Windows block at `:440`): `execve` hands the replacement only the guest `envp`, so it starts without the emulator's host variables (`LD_LIBRARY_PATH`, `DISPLAY`, `WAYLAND_DISPLAY`, `XDG_RUNTIME_DIR`, `HOME`, `APS5_*`/`ANYPS5_*` on Linux; `SystemRoot`, `PATH`, `TEMP` on Windows), which the converted program needs to start. Please see @harisibrar1's review and keep the host runtime variables in the replacement environment. - `Process.cpp:679`: `fexecve` does not exist on macOS (`use of undeclared identifier 'fexecve'`, per @jotitadev's build), and the `relinker (macos-latest, clang++)` job is red. The `#else` branch needs an Apple path (e.g. `execve` on the validated path) or an explicit throw recorded in the debt file. - The branch conflicts with `main`, and `docs/dev/debt/libc.md` collides with #9526 at the same insertion point; keep both entries when rebasing. It is also stacked on #9133, which is still open, so it can only land after it. Welcome back once these are addressed.
adriadam10 commented 2026-10-24 06:33:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T06:33:44Z.

Review: CHANGES_REQUESTED


Thanks for the update. The E2BIG count, the macOS path and the conflicts are fixed. One point is still open:

  • core/libs/prx/libkernel/System/src/Process.cpp:794 (ExecProgram) and ExecReplaceWindows (:477): execve starts the replacement with only the guest envp, and the guest environ here is an empty array (environ_nid_postfix, :579). So a converted program that calls execv/execve starts without LD_LIBRARY_PATH, DISPLAY, WAYLAND_DISPLAY, XDG_RUNTIME_DIR, HOME and APS5_*/ANYPS5_* on Linux, or SystemRoot, PATH and TEMP on Windows, which the relinked program needs to start. GuestExecHost.cpp:190 pins that the host PATH is dropped. Keep the host runtime variables in the replacement environment (add them to the guest envp unless it sets them), and change the test to assert they arrive. The debt line then no longer needs "the inherited environment is lost".
  • This is stacked on #9133, which is still open, so it can only land after it.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5637173722 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9669#pullrequestreview-5637173722). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-24T06:33:44Z. **Review:** CHANGES_REQUESTED --- Thanks for the update. The E2BIG count, the macOS path and the conflicts are fixed. One point is still open: - `core/libs/prx/libkernel/System/src/Process.cpp:794` (`ExecProgram`) and `ExecReplaceWindows` (`:477`): `execve` starts the replacement with only the guest `envp`, and the guest `environ` here is an empty array (`environ_nid_postfix`, `:579`). So a converted program that calls `execv`/`execve` starts without `LD_LIBRARY_PATH`, `DISPLAY`, `WAYLAND_DISPLAY`, `XDG_RUNTIME_DIR`, `HOME` and `APS5_*`/`ANYPS5_*` on Linux, or `SystemRoot`, `PATH` and `TEMP` on Windows, which the relinked program needs to start. `GuestExecHost.cpp:190` pins that the host `PATH` is dropped. Keep the host runtime variables in the replacement environment (add them to the guest `envp` unless it sets them), and change the test to assert they arrive. The debt line then no longer needs "the inherited environment is lost". - This is stacked on #9133, which is still open, so it can only land after it.
adriadam10 commented 2026-10-25 18:36:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-25T18:36:11Z.

Review: CHANGES_REQUESTED


The environment point is met on this head (host environ kept, guest envp overriding same-named entries, asserted in the test). New measurements from @rooklz on a PS5 contradict three error paths here:

  • core/libs/prx/libkernel/System/src/Process.cpp:817: a null path must give EBADF (9), not EFAULT; update GuestExecHost.cpp:124 and the debt line. A null argv is not covered by the measurement, so keep what FreeBSD says for it and say so in the debt line.
  • Process.cpp:341-345 and :835: a regular file without the execute bit must fail with EACCES (0644 file measured), not pass the lookup and then throw in the Linux access(X_OK) check. The debt line "a regular guest file passes without execute-bit checks" is false against the console.
  • Process.cpp:337: a path through a regular file (file/x) gives ENOTDIR, not ENOENT.
  • A 0755 file that is not an executable image gives ENOEXEC on the console; the guest-file case should return it instead of throwing where the converted target can be told apart.

E2BIG before the path lookup and the directory → EACCES rows already match. The execvp row with PATH set at run time is unresolved by that measurement; keep the debt line honest about it. The branch also conflicts with main and sits on #9133; we will rebase once the errno points are in.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644674101 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9669#pullrequestreview-5644674101). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-25T18:36:11Z. **Review:** CHANGES_REQUESTED --- The environment point is met on this head (host `environ` kept, guest `envp` overriding same-named entries, asserted in the test). New measurements from @rooklz on a PS5 contradict three error paths here: - `core/libs/prx/libkernel/System/src/Process.cpp:817`: a null path must give `EBADF` (9), not `EFAULT`; update `GuestExecHost.cpp:124` and the debt line. A null `argv` is not covered by the measurement, so keep what FreeBSD says for it and say so in the debt line. - `Process.cpp:341-345` and `:835`: a regular file without the execute bit must fail with `EACCES` (0644 file measured), not pass the lookup and then throw in the Linux `access(X_OK)` check. The debt line "a regular guest file passes without execute-bit checks" is false against the console. - `Process.cpp:337`: a path through a regular file (`file/x`) gives `ENOTDIR`, not `ENOENT`. - A 0755 file that is not an executable image gives `ENOEXEC` on the console; the guest-file case should return it instead of throwing where the converted target can be told apart. `E2BIG` before the path lookup and the directory → `EACCES` rows already match. The `execvp` row with `PATH` set at run time is unresolved by that measurement; keep the debt line honest about it. The branch also conflicts with `main` and sits on #9133; we will rebase once the errno points are in.
adriadam10 commented 2026-10-26 10:11:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-26T10:11:22Z.

Review: CHANGES_REQUESTED


The null path now returns EBADF (Process.cpp:805, asserted at GuestExecHost.cpp:124, debt line updated). Three of @rooklz's console measurements are still not followed:

  • Process.cpp:312-316 and :334: a regular file without the execute bit must fail with EACCES (0644 file measured). The lookup only checks is_regular_file, and the Linux path then throws at :824 (access(X_OK)). Check the mode bits in the lookup and return EACCES (for execvp, keep it as the remembered EACCES like the other candidates). The debt line "a regular guest file passes without execute-bit checks" is false against the console and needs to change.
  • Process.cpp:308: a path through a regular file (file/x) gives ENOTDIR (20), not ENOENT. Add a test row.
  • Process.cpp:824: a 0755 file that is not an executable image gives ENOEXEC on the console. Where the converted target can be told apart (not an x86-64 ELF), return ENOEXEC instead of throwing, and cover it in GuestExecvp.cpp or GuestExecHost.cpp.

If you disagree with any of these, say why and we will judge it on that. The Windows and WSL runs you listed are noted; the full Build still runs in the merge queue.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5650374010 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9669#pullrequestreview-5650374010). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-26T10:11:22Z. **Review:** CHANGES_REQUESTED --- The null path now returns `EBADF` (`Process.cpp:805`, asserted at `GuestExecHost.cpp:124`, debt line updated). Three of @rooklz's console measurements are still not followed: - `Process.cpp:312-316` and `:334`: a regular file without the execute bit must fail with `EACCES` (0644 file measured). The lookup only checks `is_regular_file`, and the Linux path then throws at `:824` (`access(X_OK)`). Check the mode bits in the lookup and return `EACCES` (for `execvp`, keep it as the remembered `EACCES` like the other candidates). The debt line "a regular guest file passes without execute-bit checks" is false against the console and needs to change. - `Process.cpp:308`: a path through a regular file (`file/x`) gives `ENOTDIR` (20), not `ENOENT`. Add a test row. - `Process.cpp:824`: a 0755 file that is not an executable image gives `ENOEXEC` on the console. Where the converted target can be told apart (not an x86-64 ELF), return `ENOEXEC` instead of throwing, and cover it in `GuestExecvp.cpp` or `GuestExecHost.cpp`. If you disagree with any of these, say why and we will judge it on that. The Windows and WSL runs you listed are noted; the full Build still runs in the merge queue.
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!9669
No description provided.