feat(libkernel_sys): implement _execve export #14275

Closed
bipinkrish wants to merge 0 commits from upstream-pr/14275 into main
bipinkrish commented 2026-11-01 06:04:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by bipinkrish on 2026-11-01T06:04:21Z.


What

_execve (NID -3nj+K1elI0) in libkernel_sys threw through NotImplemented_nid_no_patch. It now follows FreeBSD 11.4's exec_copyin_args and exec_check_permissions argument ladder up to the point of activation:

  • A null argv is EFAULT before the pathname is read; the pathname is copied in page-sized pieces through GuestCopyIn_nid_no_patch and refuses past PATH_MAX 1024 with ENAMETOOLONG.
  • Every argv entry and, when not null, every envp entry is read through checked guest reads; an unreadable entry or string is EFAULT. Lengths are charged to one shared ARG_MAX stringspace of 262144 bytes counting each terminating NUL, so an entry that no longer fits turns the call into E2BIG.
  • An empty or null pathname is ENOENT; FreeBSD would instead execute the file open on descriptor 0 (args->fd is never set for exec_copyin_args), which stays unmodelled.
  • The path is resolved by the guest resolver, which refuses a file prefix with ENOTDIR.
  • In exec_check_permissions order: no execute bits or a non-regular file is EACCES (the mode-bit gate is POSIX-only), a zero-size file is ENOEXEC, refusal through ExecutePermission is EACCES, and a file the host cannot reopen for reading is EACCES, matching FreeBSD's VOP_OPEN(vp, FREAD) at kern_exec.c L1677.
  • An image whose first bytes are the ELF magic, the PS4 SELF magic 4F 15 3D 1D or the PS5 SELF magic 54 14 F5 EE (both measured) throws, naming the path, since replacing the running relinked image is not modelled. A #! script throws, since script interpreters are not modelled. Every other format is ENOEXEC.

Unmodelled FreeBSD paths: MNT_NOEXEC, ETXTBSY for a vnode open for writing, #! interpreter-name parsing and redirection, the Windows mode-bit gate and resolver search-permission checks. The console's own acceptance of plain ELF images is unverified.

The declaration takes the FreeBSD parameter list const char* path, char* const* argv, char* const* envp, and the debt entry moves _execve from the NID table of pending exports to an implementation bullet. _execvpe (ScfDTOqLOMw) stays a pending placeholder for a follow-up PR.

Tested

Linux, a local build with the new guest_kernel_sys_execve test: the EFAULT ladder (null argv, unreadable argv and envp entries, unreadable strings, checked before the pathname), a 1023-byte path resolving to ENOENT while a 1024-byte path is ENAMETOOLONG, a missing path and a directory (ENOENT and EACCES), a zero-size file is ENOEXEC, a mode-0644 file is EACCES (#ifndef _WIN32), 128 argument strings of 2048 bytes charge the shared ARG_MAX stringspace into E2BIG, and ELF, PS4 and PS5 SELF images and a #! script throw with their exact messages. ctest -R 'guest_kernel_sys': 27/27 passed. No GPU or console testing (n/a).

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5104879272 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14275). Originally posted by [bipinkrish](https://github.com/bipinkrish) on 2026-11-01T06:04:21Z. --- ### What `_execve` (NID `-3nj+K1elI0`) in `libkernel_sys` threw through `NotImplemented_nid_no_patch`. It now follows FreeBSD 11.4's [`exec_copyin_args`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_exec.c#L1172-L1253) and [`exec_check_permissions`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_exec.c#L1617-L1680) argument ladder up to the point of activation: - A null `argv` is `EFAULT` before the pathname is read; the pathname is copied in page-sized pieces through `GuestCopyIn_nid_no_patch` and refuses past `PATH_MAX` 1024 with `ENAMETOOLONG`. - Every `argv` entry and, when not null, every `envp` entry is read through checked guest reads; an unreadable entry or string is `EFAULT`. Lengths are charged to one shared `ARG_MAX` stringspace of 262144 bytes counting each terminating NUL, so an entry that no longer fits turns the call into `E2BIG`. - An empty or null pathname is `ENOENT`; FreeBSD would instead execute the file open on descriptor 0 (`args->fd` is never set for `exec_copyin_args`), which stays unmodelled. - The path is resolved by the guest resolver, which refuses a file prefix with `ENOTDIR`. - In `exec_check_permissions` order: no execute bits or a non-regular file is `EACCES` (the mode-bit gate is POSIX-only), a zero-size file is `ENOEXEC`, refusal through `ExecutePermission` is `EACCES`, and a file the host cannot reopen for reading is `EACCES`, matching FreeBSD's `VOP_OPEN(vp, FREAD)` at [kern_exec.c L1677](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_exec.c#L1677). - An image whose first bytes are the `ELF` magic, the PS4 `SELF` magic `4F 15 3D 1D` or the PS5 `SELF` magic `54 14 F5 EE` ([both measured](https://github.com/boykopovar/AnyPS5/discussions/2433)) throws, naming the path, since replacing the running relinked image is not modelled. A `#!` script throws, since script interpreters are not modelled. Every other format is `ENOEXEC`. Unmodelled FreeBSD paths: `MNT_NOEXEC`, `ETXTBSY` for a vnode open for writing, `#!` interpreter-name parsing and redirection, the Windows mode-bit gate and resolver search-permission checks. The console's own acceptance of plain `ELF` images is unverified. The declaration takes the FreeBSD parameter list `const char* path, char* const* argv, char* const* envp`, and the [debt entry](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/debt/libkernel_sys.md) moves `_execve` from the NID table of pending exports to an implementation bullet. `_execvpe` (`ScfDTOqLOMw`) stays a pending placeholder for a follow-up PR. ### Tested Linux, a local build with the new `guest_kernel_sys_execve` test: the `EFAULT` ladder (null `argv`, unreadable `argv` and `envp` entries, unreadable strings, checked before the pathname), a 1023-byte path resolving to `ENOENT` while a 1024-byte path is `ENAMETOOLONG`, a missing path and a directory (`ENOENT` and `EACCES`), a zero-size file is `ENOEXEC`, a mode-0644 file is `EACCES` (`#ifndef _WIN32`), 128 argument strings of 2048 bytes charge the shared `ARG_MAX` stringspace into `E2BIG`, and `ELF`, PS4 and PS5 `SELF` images and a `#!` script throw with their exact messages. `ctest -R 'guest_kernel_sys'`: 27/27 passed. No GPU or console testing (n/a). ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes

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!14275
No description provided.