fix(libkernel_sys): build and check fchdir search permission on macOS #6667

Merged
DavidSamir merged 4 commits from upstream-pr/6667 into main 2026-10-19 08:18:14 +00:00
DavidSamir commented 2026-10-16 03:23:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-16T03:23:13Z.


What

libkernel_sys does not build on macOS since unlinkat (55ddffe26): its rmdir and unlink paths call ::rmdir and ::unlink outside the Windows branch, but <unistd.h>, <fcntl.h> and <cerrno> are included only under __linux__:

core/libs/prx/libkernel_sys/Export.cpp:543:15: error: no member named 'rmdir' in the global namespace
core/libs/prx/libkernel_sys/Export.cpp:569:15: error: no member named 'unlink' in the global namespace

They are now included on every host but Windows, the split the code that uses them already makes.

The same __linux__ guard kept fchdir's search-permission check (0e4d94ce3) off macOS, so a guest could change into a directory it may not search, where FreeBSD's change_dir fails with EACCES and keeps the working directory. faccessat(fd, ".", X_OK, AT_EACCESS) is POSIX and behaves the same on macOS, so the check now runs on every host but Windows, and so does the test case that covers it. The fchdir debt entry still said the check was not modelled; it now says where it runs.

Four commits: the header fix, the fchdir check, its test, the debt entry.

Tested

macOS 26.7.1, Apple M2, AppleClang 21.0.0, x86-64 build under Rosetta, Release.

main does not build libc and libkernel on macOS for other reasons as well (#4627, #4630, #6124 and mugurc's macOS branches address them), so the tests ran in a local tree of main ce991f1ec with those merged. On macOS, fchdir also needs the directory-descriptor path lookup through F_GETPATH that mugurc's feat/libkernel-files-macos branch adds; on main alone the lookup reads /proc/self/fd, which macOS does not have.

  • main's Export.cpp: libkernel_sys fails to compile with the errors above.
  • Header fix only: builds; guest_kernel_sys passes 3 runs of 3.
  • Header fix and the test case enabled on macOS, without the fchdir change: guest_kernel_sys aborts (3 of 3), as fchdir into the directory without search permission succeeds.
  • This branch: guest_kernel_sys passes 5 runs of 5.
  • tools/check_conventions.py --base origin/main and git diff --check pass.

Windows 11 (WinLibs GCC 15.2.0 r7, UCRT, Release) and Ubuntu 24.04 under WSL2 (GCC 13.3.0, Release), head e44e828f6 merged onto main 5d9dcc42d: guest_kernel_sys pass 3 runs of 3 with the change, and 3 runs of 3 with libkernel_sys/Export.cpp as on main and the tests kept. It passes either way there, as the change alters only the macOS path; on Linux the included headers and the check are unchanged, and on Windows none of the changed lines are compiled.

Overlap: #6222 changes the same include guard inside its macOS work. #6044 moves GuestKernelSys.cpp, and #6447 edits another entry of libkernel_sys.md; whichever lands second rebases.

Checklist

  • Based on current main; no other open PR implements the same functions (see Overlap above)
  • 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: none (every title on macOS needs libkernel_sys to build)
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4883011407 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6667). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-16T03:23:13Z. --- ### What libkernel_sys does not build on macOS since `unlinkat` (55ddffe26): its `rmdir` and `unlink` paths call `::rmdir` and `::unlink` outside the Windows branch, but `<unistd.h>`, `<fcntl.h>` and `<cerrno>` are included only under `__linux__`: ``` core/libs/prx/libkernel_sys/Export.cpp:543:15: error: no member named 'rmdir' in the global namespace core/libs/prx/libkernel_sys/Export.cpp:569:15: error: no member named 'unlink' in the global namespace ``` They are now included on every host but Windows, the split the code that uses them already makes. The same `__linux__` guard kept `fchdir`'s search-permission check (0e4d94ce3) off macOS, so a guest could change into a directory it may not search, where FreeBSD's `change_dir` fails with `EACCES` and keeps the working directory. `faccessat(fd, ".", X_OK, AT_EACCESS)` is POSIX and behaves the same on macOS, so the check now runs on every host but Windows, and so does the test case that covers it. The `fchdir` debt entry still said the check was not modelled; it now says where it runs. Four commits: the header fix, the `fchdir` check, its test, the debt entry. ### Tested macOS 26.7.1, Apple M2, AppleClang 21.0.0, x86-64 build under Rosetta, Release. `main` does not build libc and libkernel on macOS for other reasons as well (#4627, #4630, #6124 and mugurc's macOS branches address them), so the tests ran in a local tree of `main` ce991f1ec with those merged. On macOS, `fchdir` also needs the directory-descriptor path lookup through `F_GETPATH` that mugurc's `feat/libkernel-files-macos` branch adds; on `main` alone the lookup reads `/proc/self/fd`, which macOS does not have. - `main`'s `Export.cpp`: libkernel_sys fails to compile with the errors above. - Header fix only: builds; `guest_kernel_sys` passes 3 runs of 3. - Header fix and the test case enabled on macOS, without the `fchdir` change: `guest_kernel_sys` aborts (3 of 3), as `fchdir` into the directory without search permission succeeds. - This branch: `guest_kernel_sys` passes 5 runs of 5. - `tools/check_conventions.py --base origin/main` and `git diff --check` pass. Windows 11 (WinLibs GCC 15.2.0 r7, UCRT, Release) and Ubuntu 24.04 under WSL2 (GCC 13.3.0, Release), head `e44e828f6` merged onto `main` 5d9dcc42d: `guest_kernel_sys` pass 3 runs of 3 with the change, and 3 runs of 3 with `libkernel_sys/Export.cpp` as on `main` and the tests kept. It passes either way there, as the change alters only the macOS path; on Linux the included headers and the check are unchanged, and on Windows none of the changed lines are compiled. Overlap: #6222 changes the same include guard inside its macOS work. #6044 moves `GuestKernelSys.cpp`, and #6447 edits another entry of `libkernel_sys.md`; whichever lands second rebases. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (see Overlap above) - [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: none (every title on macOS needs libkernel_sys to build) - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-16 03:26:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T03:26:22Z.

Review: APPROVED


The macOS-only header guard change matches the POSIX calls used outside the Windows branch, and the fchdir permission check and test are guarded consistently. The reported macOS test results cover the change; the unrelated base-branch macOS build failures are called out. I found no remaining code blocker. The overlap with #6222 is documented and appears to require only a merge resolution, not a dependency.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5542715667 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6667#pullrequestreview-5542715667). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T03:26:22Z. **Review:** APPROVED --- The macOS-only header guard change matches the POSIX calls used outside the Windows branch, and the `fchdir` permission check and test are guarded consistently. The reported macOS test results cover the change; the unrelated base-branch macOS build failures are called out. I found no remaining code blocker. The overlap with #6222 is documented and appears to require only a merge resolution, not a dependency.
github-actions[bot] commented 2026-10-16 03:38:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T03:38:01Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libkernel_sys/Export.cpp
PR 6044 core/libs/tests/GuestKernelSys.cpp
PR 7039 core/libs/tests/GuestKernelSys.cpp
PR 7201 core/libs/prx/libkernel_sys/Export.cpp
PR 7658 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6207526331 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6667#issuecomment-6207526331). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T03:38:01Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestKernelSys.cpp` | | [PR 7039](https://www.github.com/boykopovar/AnyPS5/pull/7039) | `core/libs/tests/GuestKernelSys.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 7658](https://www.github.com/boykopovar/AnyPS5/pull/7658) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` |
DavidSamir commented 2026-10-16 07:33:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-16T07:33:39Z.


Windows and Linux results for e44e828f61, merged onto main 5d9dcc42d2:

Host Toolchain With the change Code as on main, new tests kept Restored
Windows 11 WinLibs GCC 15.2.0 r7 (UCRT), Release guest_kernel_sys 3/3 3/3 1/1
Ubuntu 24.04 (WSL2) GCC 13.3.0, Release guest_kernel_sys 3/3 3/3 1/1

Reverted for the middle column: libkernel_sys/Export.cpp. On both hosts the test passes either way, as expected for a change that only alters the macOS path. This shows the edited shared code still builds and passes on Windows and Linux.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6210484117 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6667#issuecomment-6210484117). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-16T07:33:39Z. --- Windows and Linux results for e44e828f61, merged onto `main` 5d9dcc42d2: | Host | Toolchain | With the change | Code as on `main`, new tests kept | Restored | |---|---|---|---|---| | Windows 11 | WinLibs GCC 15.2.0 r7 (UCRT), Release | `guest_kernel_sys` 3/3 | 3/3 | 1/1 | | Ubuntu 24.04 (WSL2) | GCC 13.3.0, Release | `guest_kernel_sys` 3/3 | 3/3 | 1/1 | Reverted for the middle column: `libkernel_sys/Export.cpp`. On both hosts the test passes either way, as expected for a change that only alters the macOS path. This shows the edited shared code still builds and passes on Windows and Linux. AI-assisted: yes
adriadam10 commented 2026-10-19 08:19:46 +00:00 (Migrated from github.com)

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


Checked the diff against the description: the __linux__ → !_WIN32 guard change in the includes, the fchdir faccessat(fd, ".", X_OK, AT_EACCESS) check and its test case, and the updated fchdir debt entry. Linux behaviour is unchanged and the Windows path isn't compiled. macOS results are from your M2 runs and the third-party macOS runs.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6262854012 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6667#issuecomment-6262854012). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T08:19:46Z. --- Checked the diff against the description: the `__linux__` → `!_WIN32` guard change in the includes, the `fchdir` `faccessat(fd, ".", X_OK, AT_EACCESS)` check and its test case, and the updated `fchdir` debt entry. Linux behaviour is unchanged and the Windows path isn't compiled. macOS results are from your M2 runs and the third-party macOS runs.
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!6667
No description provided.