feat(libkernel_sys): add chroot that keeps the guest root #5191

Merged
p3n1cillin merged 2 commits from upstream-pr/5191 into main 2026-10-13 14:33:01 +00:00
p3n1cillin commented 2026-10-13 14:13:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-13T14:13:45Z.


What

Carries @screamm's two chroot commits from screamm:feat/libkernel-sys-chroot (059d98cf, 15f673ee, author kept), which they offered in #3632 for anyone eligible to carry.

Porpoise (PPSA99764, catalog release) imports chroot (AKknh8Cx-V8) from libkernel_sys.prx. On Windows, current main refuses to load it:

FAIL: unresolved ELF import AKknh8Cx-V8 from libkernel_sys.prx
  • First commit: chroot follows FreeBSD 11.4 sys_chroot/change_dir up to the lookup: EFAULT for a null path, ENOENT for an empty or missing one, and ENOTDIR for a file or a path through a file.
  • Second commit: the title's only call is in put_root_back (Porpoise src/porpoise_jailbreak.cpp). It calls fchdir on the / it opened at start, then chroot("."). So a directory that is already the guest root succeeds without a change, as FreeBSD's pwd_chroot would leave fd_rdir where it is. Any other directory still throws, because the resolver's root and mount aliases are fixed.
  • The details and FreeBSD references are in the commit messages and the libkernel_sys debt entry.

Tested

  • Porpoise PPSA99764 on Windows 11 (MinGW GCC 15.2.0), on main 3faa9cb40 with #4863 (its next stop is VideoOut: port already open). Before, it does not load. After, it loads and runs for the whole 60 s run with no exception. On Linux the weak import already resolves; the same title stops there on the VideoOut open that #4863 fixes.
  • guest_kernel_sys (from the commits) and guest_filesystem pass on Windows; python tools/check_conventions.py --base origin/main passes. The commits apply to current main without changes.

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 to build; Porpoise also needs #4863 to keep running
  • Unblocks: Porpoise (PPSA99764) on Windows, part of #3632
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4844566593 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5191). Originally posted by [p3n1cillin](https://github.com/p3n1cillin) on 2026-10-13T14:13:45Z. --- ### What Carries @screamm's two `chroot` commits from `screamm:feat/libkernel-sys-chroot` (`059d98cf`, `15f673ee`, author kept), which they offered in #3632 for anyone eligible to carry. Porpoise (PPSA99764, catalog release) imports `chroot` (`AKknh8Cx-V8`) from `libkernel_sys.prx`. On Windows, current `main` refuses to load it: ``` FAIL: unresolved ELF import AKknh8Cx-V8 from libkernel_sys.prx ``` - **First commit:** `chroot` follows FreeBSD 11.4 `sys_chroot`/`change_dir` up to the lookup: `EFAULT` for a null path, `ENOENT` for an empty or missing one, and `ENOTDIR` for a file or a path through a file. - **Second commit:** the title's only call is in `put_root_back` (Porpoise `src/porpoise_jailbreak.cpp`). It calls `fchdir` on the `/` it opened at start, then `chroot(".")`. So a directory that is already the guest root succeeds without a change, as FreeBSD's `pwd_chroot` would leave `fd_rdir` where it is. Any other directory still throws, because the resolver's root and mount aliases are fixed. - The details and FreeBSD references are in the commit messages and the `libkernel_sys` debt entry. ### Tested - Porpoise PPSA99764 on Windows 11 (MinGW GCC 15.2.0), on `main` `3faa9cb40` with #4863 (its next stop is `VideoOut: port already open`). Before, it does not load. After, it loads and runs for the whole 60 s run with no exception. On Linux the weak import already resolves; the same title stops there on the VideoOut open that #4863 fixes. - `guest_kernel_sys` (from the commits) and `guest_filesystem` pass on Windows; `python tools/check_conventions.py --base origin/main` passes. The commits apply to current `main` without changes. ### Checklist - [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 to build; Porpoise also needs #4863 to keep running - [x] Unblocks: Porpoise (PPSA99764) on Windows, part of #3632 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-13 14:15:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T14:15:06Z.


Progress report (8c772ad → 41b0ca5)

➖ System libraries: 88.04% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel_sys chroot_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147577690 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5191#issuecomment-6147577690). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T14:15:06Z. --- <!-- progress-report --> ### Progress report (8c772ad → 41b0ca5) ➖ **System libraries**: 88.04% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel_sys | `chroot_nid_postfix` | </details>
adriadam10 commented 2026-10-13 14:17:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:17:10Z.


Checked on main merged with the PR: guest_kernel_sys passes (partial build, 24 libs tests green) and fails to link without the change. The chroot errors, the root-no-op and the throw for other directories match the debt entry. The Porpoise log in the description covers the only call site. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147619719 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5191#issuecomment-6147619719). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T14:17:10Z. --- Checked on main merged with the PR: `guest_kernel_sys` passes (partial build, 24 libs tests green) and fails to link without the change. The `chroot` errors, the root-no-op and the throw for other directories match the debt entry. The Porpoise log in the description covers the only call site. Merging once the full Build is green.
MarcZX10 commented 2026-10-13 14:17:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T14:17:39Z.


Linux validation on the exact PR head: GCC 12.2, Release, BUILD_TESTING=ON; built guest_kernel_sys_tests, and CTest guest_kernel_sys passed (1/1). This confirms the focused guest test on Linux; it does not add Windows or console coverage.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147630646 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5191#issuecomment-6147630646). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T14:17:39Z. --- Linux validation on the exact PR head: GCC 12.2, Release, `BUILD_TESTING=ON`; built `guest_kernel_sys_tests`, and CTest `guest_kernel_sys` passed (1/1). This confirms the focused guest test on Linux; it does not add Windows or console coverage.
adriadam10 commented 2026-10-13 14:32:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:32:41Z.


Checked on main merged with the PR: guest_kernel_sys passes (24 libs tests green) and fails to link without the change. The chroot errors, the no-op for the guest root and the throw for other directories match the FreeBSD references and the debt entry. Porpoise's only call site (fchdir then chroot(".")) is covered. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147948946 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5191#issuecomment-6147948946). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T14:32:41Z. --- Checked on main merged with the PR: `guest_kernel_sys` passes (24 libs tests green) and fails to link without the change. The `chroot` errors, the no-op for the guest root and the throw for other directories match the FreeBSD references and the debt entry. Porpoise's only call site (`fchdir` then `chroot(".")`) is covered. Merging once the full Build is green.
p3n1cillin commented 2026-10-13 14:34:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-13T14:34:53Z.


Linux run: Ubuntu in WSL2, GCC 15.2.0, Ninja Release, BUILD_TESTING=ON, full build of a local test head 838d4fd85. That head is main 3faa9cb40 with this PR, my other open libkernel PRs (#5013, #5061, #5078, #5098, #5183–#5187, #5191) and the open PRs the catalog titles need (#4377, #4379, #4374, #4383, #3798, #4467, #4863, #4105). All 123 libkernel and 69 libc tests pass, including guest_system_configuration, guest_getrlimit, guest_kernel_fcntl, guest_freebsd_clocks, guest_kernel_sys and guest_filesystem. Not built alone on Linux; no title run on Linux.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147993428 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5191#issuecomment-6147993428). Originally posted by [p3n1cillin](https://github.com/p3n1cillin) on 2026-10-13T14:34:53Z. --- Linux run: Ubuntu in WSL2, GCC 15.2.0, Ninja Release, `BUILD_TESTING=ON`, full build of a local test head `838d4fd85`. That head is `main` `3faa9cb40` with this PR, my other open libkernel PRs (#5013, #5061, #5078, #5098, #5183–#5187, #5191) and the open PRs the catalog titles need (#4377, #4379, #4374, #4383, #3798, #4467, #4863, #4105). All 123 libkernel and 69 libc tests pass, including `guest_system_configuration`, `guest_getrlimit`, `guest_kernel_fcntl`, `guest_freebsd_clocks`, `guest_kernel_sys` and `guest_filesystem`. Not built alone on Linux; no title run on Linux.
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!5191
No description provided.