feat(libkernel): add chroot and clock_settime with FreeBSD argument checks #4890

Closed
nabilfp wants to merge 2 commits from upstream-pr/4890 into main
nabilfp commented 2026-10-13 02:05:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nabilfp on 2026-10-13T02:05:28Z.


What

Adds chroot (AKknh8Cx-V8, libkernel_sys) and clock_settime (d7nUj1LOdDU, libkernel), carried from @screamm's branch screamm:feat/libkernel-ps5mc-set for #3632, keeping the commits as offered. The branch's other two commits (getpriority, chflags) are carried by open PRs #4374 and #4379, so this PR takes only the remaining two.

  • chroot(path) follows FreeBSD 11.4 sys_chroot/change_dir up to the lookup: EFAULT for a null path, ENOENT for an empty or missing one, ENOTDIR for a path that is not a directory or passes through a file. Any directory that is found throws, naming it, because the guest resolver's root is fixed and the mount aliases (/app0, /savedata0) are host paths that do not move with it. Porpoise (PPSA99764) imports it.
  • clock_settime(clock, ts) follows FreeBSD 11.4 kern_clock_settime for a root caller: EFAULT for a null time, EINVAL for any clock but CLOCK_REALTIME, a negative tv_sec or a tv_nsec outside 0 to 999999999. A valid CLOCK_REALTIME request throws, naming the requested time, since the host clock is never set and no guest clock offset is kept. PS5MC (PPSA99420) imports it.

Both NIDs were confirmed with tools/nid_names.py (AKknh8Cx-V8 → chroot, d7nUj1LOdDU → clock_settime). Debt entries were placed in the per-library files docs/dev/debt/libkernel_sys.md and docs/dev/debt/libkernel.md.

Tested

Not built or run here: this host has no SDL2 submodule and no audio/X11 development files (no password for sudo), so CMake configure fails before the libraries can be built. g++ -std=c++20 -fsyntax-only passes for all four changed files, and python3 tools/check_conventions.py --base main passes. The behaviour and the tests in guest_kernel_sys and guest_freebsd_clocks are the ones tested on Windows by @screamm on the source branch, as described in #3632.

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
  • Unblocks: PPSA99420 and PPSA99764 #3632
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4837332827 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4890). Originally posted by [nabilfp](https://github.com/nabilfp) on 2026-10-13T02:05:28Z. --- ### What Adds `chroot` (`AKknh8Cx-V8`, libkernel_sys) and `clock_settime` (`d7nUj1LOdDU`, libkernel), carried from @screamm's branch `screamm:feat/libkernel-ps5mc-set` for #3632, keeping the commits as offered. The branch's other two commits (`getpriority`, `chflags`) are carried by open PRs #4374 and #4379, so this PR takes only the remaining two. - `chroot(path)` follows FreeBSD 11.4 `sys_chroot`/`change_dir` up to the lookup: `EFAULT` for a null path, `ENOENT` for an empty or missing one, `ENOTDIR` for a path that is not a directory or passes through a file. Any directory that is found throws, naming it, because the guest resolver's root is fixed and the mount aliases (`/app0`, `/savedata0`) are host paths that do not move with it. Porpoise (PPSA99764) imports it. - `clock_settime(clock, ts)` follows FreeBSD 11.4 `kern_clock_settime` for a root caller: `EFAULT` for a null time, `EINVAL` for any clock but `CLOCK_REALTIME`, a negative `tv_sec` or a `tv_nsec` outside 0 to 999999999. A valid `CLOCK_REALTIME` request throws, naming the requested time, since the host clock is never set and no guest clock offset is kept. PS5MC (PPSA99420) imports it. Both NIDs were confirmed with `tools/nid_names.py` (`AKknh8Cx-V8` → `chroot`, `d7nUj1LOdDU` → `clock_settime`). Debt entries were placed in the per-library files `docs/dev/debt/libkernel_sys.md` and `docs/dev/debt/libkernel.md`. ### Tested Not built or run here: this host has no SDL2 submodule and no audio/X11 development files (no password for `sudo`), so CMake configure fails before the libraries can be built. `g++ -std=c++20 -fsyntax-only` passes for all four changed files, and `python3 tools/check_conventions.py --base main` passes. The behaviour and the tests in `guest_kernel_sys` and `guest_freebsd_clocks` are the ones tested on Windows by @screamm on the source branch, as described in #3632. ### 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 - [x] Unblocks: PPSA99420 and PPSA99764 #3632 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-13 02:20:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T02:20:28Z.


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.

Pull request Conflicting files (lines on main) Same exports Same new files
#3891 docs/dev/debt/libkernel.md L162-163
#4156 docs/dev/debt/libkernel.md L162-163
#4396 docs/dev/debt/libkernel.md L162-163
#4397 docs/dev/debt/libkernel.md L162-163
#4422 docs/dev/debt/libkernel.md L162-163
#4423 docs/dev/debt/libkernel.md L162-163
#4424 docs/dev/debt/libkernel.md L162-163
#4520 docs/dev/debt/libkernel.md L162-163
#4521 docs/dev/debt/libkernel.md L162-163
#4522 docs/dev/debt/libkernel.md L162-163
#4523 docs/dev/debt/libkernel.md L162-163
#4566 docs/dev/debt/libkernel.md L162-163
#4599 docs/dev/debt/libkernel.md L162-163
#4718 docs/dev/debt/libkernel.md L162-163
#4740 docs/dev/debt/libkernel.md L162-163
#4749 docs/dev/debt/libkernel.md L162-163
#4760 docs/dev/debt/libkernel.md L162-163
#4796 docs/dev/debt/libkernel.md L163
#4813 docs/dev/debt/libkernel.md L162-163
#4877 core/libs/prx/libkernel_sys/Export.cpp L40
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6136790290 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4890#issuecomment-6136790290). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T02:20:28Z. --- <!-- pr-overlap --> 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**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #3891 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4156 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4396 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4397 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4422 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4423 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4424 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4520 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4521 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4522 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4523 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4566 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4599 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4718 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4740 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4749 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4760 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4796 | `docs/dev/debt/libkernel.md` [L163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L163) | | | | #4813 | `docs/dev/debt/libkernel.md` [L162-163](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/docs/dev/debt/libkernel.md#L162-L163) | | | | #4877 | `core/libs/prx/libkernel_sys/Export.cpp` [L40](https://github.com/boykopovar/AnyPS5/blob/834de1ab102b597a9e1b88cc5c62040aecdec849/core/libs/prx/libkernel_sys/Export.cpp#L40) | | |
nabilfp commented 2026-10-13 02:37:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nabilfp on 2026-10-13T02:37:29Z.


Closing this carry to stay within the one-open-PR intake limit while I open an original fix. The work itself is correct and free for anyone to carry: chroot (commit 643f4cbdd, tests + debt entry) and clock_settime (commit 53485d5a5, tests + debt entry) on nabilfp:feat/libkernel-chroot-clock-settime.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6136976603 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4890#issuecomment-6136976603). Originally posted by [nabilfp](https://github.com/nabilfp) on 2026-10-13T02:37:29Z. --- Closing this carry to stay within the one-open-PR intake limit while I open an original fix. The work itself is correct and free for anyone to carry: `chroot` (commit `643f4cbdd`, tests + debt entry) and `clock_settime` (commit `53485d5a5`, tests + debt entry) on `nabilfp:feat/libkernel-chroot-clock-settime`.

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