feat(libkernel_sys): export _openat #8701

Merged
nikowolf123 merged 2 commits from upstream-pr/8701 into main 2026-10-24 11:55:33 +00:00
nikowolf123 commented 2026-10-20 21:31:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-20T21:31:48Z.


What

Exports _openat from libkernel_sys. It forwards to openat.

_openat(fd, path, flags, ...) reads the mode argument only when O_CREAT (0x200) is set, as openat and _open do, and calls openat with the same descriptor, path, flags and mode. So it returns what openat returns: a new descriptor, or -1 with errno set to

  • EINVAL (22) for the access mode O_ACCMODE (3) or for O_CREAT | O_EXCL | O_DIRECTORY, before the path is looked at; then EFAULT (14) for a null path and ENOENT (2) for an empty one;
  • for AT_FDCWD (-100) or an absolute path, the errors of open, which it passes the path to;
  • for any other relative path, EBADF (9) for a descriptor that is not open, ENOTDIR (20) for one that is not a directory, EMLINK (31) for O_NOFOLLOW on a symbolic link, as open does, and otherwise the error of the host open, such as EEXIST (17) for O_CREAT | O_EXCL on an existing file.

Sources:

openat here is not a cancellation point (Thread cancellation in docs/dev/debt/libkernel.md: file and socket calls are not cancellation points), so forwarding to it leaves _openat without one, as in FreeBSD.

Unverified: the console's _openat is taken to be FreeBSD's and was not checked on a PS5. The openat entry of docs/dev/debt/libkernel_sys.md now names _openat too, so its gaps and its closing "Console behaviour is unverified" cover _openat.

The entry no longer says that O_NOFOLLOW is ignored. Since 9421484572 (fix(libkernel): fail open with O_NOFOLLOW on a symbolic link), open, and so openat, returns EMLINK for O_NOFOLLOW on a symbolic link unless O_CREAT and O_EXCL are both set (Open.cpp#L219-L230). O_NONBLOCK is still ignored: MapFlags does not pass it to the host open. The entry also says that PPSA99003 opens directory entries through openat, as it said before it named _openat.

The 3.20 libkernel and libkernel_web export lists also have _openat; this PR only adds the libkernel_sys export.

Overlap: the open #9131 rewrites the fchdir entry directly above the openat entry this PR rewrites in docs/dev/debt/libkernel_sys.md, so whichever lands second needs a one-line rebase.

Tested

  • Linux: WSL2 Ubuntu 26.04, GCC 15.2.0, Release, BUILD_TESTING=ON, on this branch (d23dcf9e6) rebased onto main ca74ef217, and again at 673ff23c5 on main 2c4b116da. Built the libkernel_sys, guest_kernel_sys_tests and patched_libraries_tests targets; ctest -R '^(guest_kernel_sys|patched_libraries)$' runs guest_kernel_sys and patched_libraries, which pass.
  • GuestKernelSys.cpp now also calls _openat next to the openat checks: it opens file.txt through a directory descriptor and reads back its byte; it creates alias.bin with O_WRONLY | O_CREAT | O_EXCL and mode 0600 and, outside Windows, checks that the file has mode 0600, so the variadic mode reaches the host open; it reopens alias.bin with O_WRONLY, which on Windows fails if the mode lost its write bit, since NativeOpen then creates the file read-only; then it checks EEXIST (17) for the same exclusive create, EINVAL (22) for O_ACCMODE, EBADF (9) for descriptor -1 and ENOTDIR (20) for a file descriptor.
  • Against main: main has no _openat_nid_postfix, so the updated test does not link there. An earlier revision of this test on main 9a97ac784 failed to link with undefined reference to `_openat_nid_postfix'.
  • tools/check_conventions.py --base origin/main with this title and description: all checks passed.
  • tools/progress.py --module libkernel_sys: 14 of 546 functions done (13 of 545 on main 2c4b116da, where Export.Discovery.cpp declares 527 throwing exports); _openat is the new one.
  • Windows: not built.
  • No title was run.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4942778038 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8701). Originally posted by [nikowolf123](https://github.com/nikowolf123) on 2026-10-20T21:31:48Z. --- ### What Exports `_openat` from libkernel_sys. It forwards to `openat`. `_openat(fd, path, flags, ...)` reads the mode argument only when `O_CREAT` (0x200) is set, as `openat` and `_open` do, and calls `openat` with the same descriptor, path, flags and mode. So it returns what `openat` returns: a new descriptor, or -1 with errno set to - `EINVAL` (22) for the access mode `O_ACCMODE` (3) or for `O_CREAT | O_EXCL | O_DIRECTORY`, before the path is looked at; then `EFAULT` (14) for a null path and `ENOENT` (2) for an empty one; - for `AT_FDCWD` (-100) or an absolute path, the errors of `open`, which it passes the path to; - for any other relative path, `EBADF` (9) for a descriptor that is not open, `ENOTDIR` (20) for one that is not a directory, `EMLINK` (31) for `O_NOFOLLOW` on a symbolic link, as `open` does, and otherwise the error of the host open, such as `EEXIST` (17) for `O_CREAT | O_EXCL` on an existing file. Sources: - The PS5 3.20 libkernel_sys export list has `_openat`, NID `bGVEgWXy6dg` ([libkernel_sys.c#L527-L532](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libkernel_sys.c#L527-L532), [#L8830](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libkernel_sys.c#L8830)), as well as `openat` (`A8Yk5AhNDck`, [#L1808-L1813](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libkernel_sys.c#L1808-L1813), [#L9013](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libkernel_sys.c#L9013)). - FreeBSD 11.4 (`release/11.4.0`, 8c639945a4): libc's own calls to `openat` go to `_openat` ([namespace.h#L84](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/include/namespace.h#L84)). `_openat` is the system call stub that `PSEUDO` generates for each interposed call ([sys/Makefile.inc#L48](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/sys/Makefile.inc#L48), [#L81](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/sys/Makefile.inc#L81), [amd64/SYS.h#L46-L50](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/amd64/SYS.h#L46-L50)). The public `openat` reads the mode only with `O_CREAT` and calls through the interposing table ([openat.c#L47-L62](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/sys/openat.c#L47-L62)), where libthr installs `__thr_openat` ([thr_syscalls.c#L657](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_syscalls.c#L657)), which adds the cancellation point ([#L297-L321](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libthr/thread/thr_syscalls.c#L297-L321)). `openat` here is not a cancellation point (Thread cancellation in `docs/dev/debt/libkernel.md`: file and socket calls are not cancellation points), so forwarding to it leaves `_openat` without one, as in FreeBSD. Unverified: the console's `_openat` is taken to be FreeBSD's and was not checked on a PS5. The `openat` entry of `docs/dev/debt/libkernel_sys.md` now names `_openat` too, so its gaps and its closing "Console behaviour is unverified" cover `_openat`. The entry no longer says that `O_NOFOLLOW` is ignored. Since 9421484572 (`fix(libkernel): fail open with O_NOFOLLOW on a symbolic link`), `open`, and so `openat`, returns `EMLINK` for `O_NOFOLLOW` on a symbolic link unless `O_CREAT` and `O_EXCL` are both set ([Open.cpp#L219-L230](https://github.com/boykopovar/AnyPS5/blob/ca74ef2177eeffe099c7bf71e8e98c65ca817eb8/core/libs/prx/libkernel/File/src/Open.cpp#L219-L230)). `O_NONBLOCK` is still ignored: `MapFlags` does not pass it to the host open. The entry also says that PPSA99003 opens directory entries through `openat`, as it said before it named `_openat`. The 3.20 libkernel and libkernel_web export lists also have `_openat`; this PR only adds the libkernel_sys export. Overlap: the open #9131 rewrites the `fchdir` entry directly above the `openat` entry this PR rewrites in `docs/dev/debt/libkernel_sys.md`, so whichever lands second needs a one-line rebase. ### 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. --> - Linux: WSL2 Ubuntu 26.04, GCC 15.2.0, Release, `BUILD_TESTING=ON`, on this branch (d23dcf9e6) rebased onto `main` ca74ef217, and again at 673ff23c5 on `main` 2c4b116da. Built the `libkernel_sys`, `guest_kernel_sys_tests` and `patched_libraries_tests` targets; `ctest -R '^(guest_kernel_sys|patched_libraries)$'` runs `guest_kernel_sys` and `patched_libraries`, which pass. - `GuestKernelSys.cpp` now also calls `_openat` next to the `openat` checks: it opens `file.txt` through a directory descriptor and reads back its byte; it creates `alias.bin` with `O_WRONLY | O_CREAT | O_EXCL` and mode 0600 and, outside Windows, checks that the file has mode 0600, so the variadic mode reaches the host open; it reopens `alias.bin` with `O_WRONLY`, which on Windows fails if the mode lost its write bit, since `NativeOpen` then creates the file read-only; then it checks `EEXIST` (17) for the same exclusive create, `EINVAL` (22) for `O_ACCMODE`, `EBADF` (9) for descriptor -1 and `ENOTDIR` (20) for a file descriptor. - Against `main`: `main` has no `_openat_nid_postfix`, so the updated test does not link there. An earlier revision of this test on `main` 9a97ac784 failed to link with ``undefined reference to `_openat_nid_postfix'``. - `tools/check_conventions.py --base origin/main` with this title and description: all checks passed. - `tools/progress.py --module libkernel_sys`: 14 of 546 functions done (13 of 545 on `main` 2c4b116da, where `Export.Discovery.cpp` declares 527 throwing exports); `_openat` is the new one. - Windows: not built. - No title was run. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ycbuzi commented 2026-10-21 04:58:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T04:58:02Z.


Windows run of d23dcf9e6c merged onto main 1fd67185b6 (51ebe7d931, clean). Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON.

Built libkernel_sys and guest_kernel_sys_tests; ctest -R "^guest_kernel_sys$" --repeat until-fail:3: passes every repeat (2.5 s a run), with the _openat checks in it (the mode check sits outside Windows by the test's own #ifdef). Not run: patched_libraries on this branch.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6308416360 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8701#issuecomment-6308416360). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T04:58:02Z. --- Windows run of d23dcf9e6c merged onto `main` 1fd67185b6 (51ebe7d931, clean). Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, `BUILD_TESTING=ON`. Built `libkernel_sys` and `guest_kernel_sys_tests`; `ctest -R "^guest_kernel_sys$" --repeat until-fail:3`: passes every repeat (2.5 s a run), with the `_openat` checks in it (the mode check sits outside Windows by the test's own `#ifdef`). Not run: `patched_libraries` on this branch.
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!8701
No description provided.