fix(libkernel): report a host-only descriptor as not open to fcntl and ioctl #12474

Merged
milescoviello merged 2 commits from upstream-pr/12474 into main 2026-11-01 10:38:28 +00:00
milescoviello commented 2026-10-28 15:12:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-28T15:12:55Z.


What

Dusklight (PPSA99305 1.0.0, the catalog's Twilight Princess port) aborts 8 s in, after the first menu press:

terminate called after throwing an instance of 'std::runtime_error'
  what():  fcntl: descriptor 87 is neither a file, a directory, a pipe, a socket nor a character device

Just before, the title tries to open /proc/self/fd, which fails, and then calls fcntl on descriptor numbers it never opened. Guest descriptors are host descriptor numbers here, so one of those numbers is a descriptor the emulator's own process holds, of a kind a guest can't create: an anonymous inode such as an epoll or an eventfd (libkernel's kevent helpers create both, and host libraries hold others). I didn't identify which component held descriptor 87. Classify in File/src/DescriptorControl.cpp throws for any kind it doesn't recognise, so fcntl ends the title.

How

On Linux, Classify now reports a descriptor of any other kind as not open, as it already does for a closed one, so fcntl and ioctl return EBADF. A guest can't create such a descriptor there: its files, directories, pipes, sockets and character devices (guest shared memory is a regular file, and guest kqueues are backed by /dev/null descriptors) are the kinds Classify keeps, so the rest belong to the host. On the console the guest's descriptor table holds only what the title opened, and FreeBSD's fcntl and ioctl return EBADF for any other number. The host descriptor itself is left alone.

Other hosts keep the throw. On macOS a guest named shm_open descriptor also reports S_IFMT 0, so the same rule would hide a descriptor the guest owns there (rooklz's table). On Windows, guest descriptors are CRT descriptors, and the emulator's own objects are handles outside that table.

Tested

Linux (Ubuntu 26.04.1, GCC 15.2).

  • Refreshed onto main 52c09d567d (MarcZX10's review): head f83a259550. git range-diff shows both commits unchanged. main had changed DescriptorControl.cpp and GuestKernelFcntl.cpp, and the rebase merged cleanly.
    • The 14 tests matching ^(guest_kernel_fcntl|guest_kernel_fcntl_sync|guest_closed_standard_descriptors|guest_socket_descriptor_flags|guest_socket_descriptors|guest_dup|guest_shm_open|guest_named_shm_.*|guest_stdio_variadic)$ pass 3 of 3.
    • Negative control: with main's DescriptorControl.cpp and this PR's test (35868b94bf), guest_kernel_fcntl aborts: fcntl: descriptor 6 is neither a file, a directory, a pipe, a socket nor a character device.
    • All 983 ^guest_ tests pass at this head.

Earlier, on main 04fefebe90:

  • New case in guest_kernel_fcntl (Linux only): for a host epoll descriptor and a host eventfd, fcntl F_GETFD, F_GETFL and F_SETFD and ioctl FIONREAD return -1 with EBADF, and the host descriptor keeps its FD_CLOEXEC. A guest named shm_open descriptor still answers: F_GETFL gives O_RDWR, and F_SETFD then F_GETFD give back FD_CLOEXEC. It passes 3 of 3 at this head (e821de8aca). The first version of the test alone on main (cfa15a24ab) fails, as fcntl throws.
  • Area: all 948 ^guest_ tests pass at this head.
  • Dusklight (PPSA99305 1.0.0), release libraries of 5396a73723, whose Linux code is this head's, 120 s with pad input: it runs the full 120 s past the fcntl call. Its launcher menu and settings tabs follow the input, and it reports "No disc image found", as there is none here. On main 446bd8776c the same run aborts at 8 s as above.
  • Windows 11 VM (WinLibs GCC 15.2, Release): guest_kernel_fcntl passes 3 of 3 at this head and on main 04fefebe90 (the new case is Linux only).

Not tested on macOS: as rooklz found, SharedMemory.cpp doesn't build there on main.

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: PPSA99305 #12708 (Dusklight, past its fcntl abort)
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5052882271 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12474). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-28T15:12:55Z. --- ### What Dusklight (PPSA99305 1.0.0, the catalog's Twilight Princess port) aborts 8 s in, after the first menu press: ``` terminate called after throwing an instance of 'std::runtime_error' what(): fcntl: descriptor 87 is neither a file, a directory, a pipe, a socket nor a character device ``` Just before, the title tries to open `/proc/self/fd`, which fails, and then calls `fcntl` on descriptor numbers it never opened. Guest descriptors are host descriptor numbers here, so one of those numbers is a descriptor the emulator's own process holds, of a kind a guest can't create: an anonymous inode such as an epoll or an eventfd (libkernel's kevent helpers create both, and host libraries hold others). I didn't identify which component held descriptor 87. `Classify` in `File/src/DescriptorControl.cpp` throws for any kind it doesn't recognise, so `fcntl` ends the title. ### How On Linux, `Classify` now reports a descriptor of any other kind as not open, as it already does for a closed one, so `fcntl` and `ioctl` return `EBADF`. A guest can't create such a descriptor there: its files, directories, pipes, sockets and character devices (guest shared memory is a regular file, and guest kqueues are backed by `/dev/null` descriptors) are the kinds `Classify` keeps, so the rest belong to the host. On the console the guest's descriptor table holds only what the title opened, and FreeBSD's `fcntl` and `ioctl` return `EBADF` for any other number. The host descriptor itself is left alone. Other hosts keep the throw. On macOS a guest named `shm_open` descriptor also reports `S_IFMT` 0, so the same rule would hide a descriptor the guest owns there ([rooklz's table](https://github.com/boykopovar/AnyPS5/pull/12474#pullrequestreview-5685890735)). On Windows, guest descriptors are CRT descriptors, and the emulator's own objects are handles outside that table. ### Tested Linux (Ubuntu 26.04.1, GCC 15.2). - **Refreshed onto `main` `52c09d567d`** (MarcZX10's review): head `f83a259550`. `git range-diff` shows both commits unchanged. `main` had changed `DescriptorControl.cpp` and `GuestKernelFcntl.cpp`, and the rebase merged cleanly. - The 14 tests matching `^(guest_kernel_fcntl|guest_kernel_fcntl_sync|guest_closed_standard_descriptors|guest_socket_descriptor_flags|guest_socket_descriptors|guest_dup|guest_shm_open|guest_named_shm_.*|guest_stdio_variadic)$` pass 3 of 3. - Negative control: with `main`'s `DescriptorControl.cpp` and this PR's test (`35868b94bf`), `guest_kernel_fcntl` aborts: `fcntl: descriptor 6 is neither a file, a directory, a pipe, a socket nor a character device`. - All 983 `^guest_` tests pass at this head. Earlier, on `main` `04fefebe90`: - **New case in `guest_kernel_fcntl`** (Linux only): for a host epoll descriptor and a host eventfd, `fcntl` `F_GETFD`, `F_GETFL` and `F_SETFD` and `ioctl` `FIONREAD` return -1 with `EBADF`, and the host descriptor keeps its `FD_CLOEXEC`. A guest named `shm_open` descriptor still answers: `F_GETFL` gives `O_RDWR`, and `F_SETFD` then `F_GETFD` give back `FD_CLOEXEC`. It passes 3 of 3 at this head (`e821de8aca`). The first version of the test alone on `main` (`cfa15a24ab`) fails, as `fcntl` throws. - **Area:** all 948 `^guest_` tests pass at this head. - **Dusklight (PPSA99305 1.0.0)**, release libraries of `5396a73723`, whose Linux code is this head's, 120 s with pad input: it runs the full 120 s past the `fcntl` call. Its launcher menu and settings tabs follow the input, and it reports "No disc image found", as there is none here. On `main` `446bd8776c` the same run aborts at 8 s as above. - **Windows 11 VM** (WinLibs GCC 15.2, Release): `guest_kernel_fcntl` passes 3 of 3 at this head and on `main` `04fefebe90` (the new case is Linux only). Not tested on macOS: as rooklz found, `SharedMemory.cpp` doesn't build there on `main`. ### 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: PPSA99305 #12708 (Dusklight, past its `fcntl` abort) - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-28 15:27:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T15:27:21Z.

Review: APPROVED


Reviewed exact head 5396a7372354d247c689d201e08886917b4a7610. On non-Windows hosts, Classify now maps an fstat result with no supported guest descriptor kind to “not open”; actual EBADF handling remains unchanged, and recognized file, directory, pipe, socket and character-device paths are preserved. The Linux-only regression checks epoll/eventfd behavior through fcntl and ioctl and confirms host descriptor flags remain intact. The author reports the focused test and all 948 guest tests on Linux plus the focused Windows run; my exact-head syntax, diff-check and merge-tree checks pass. Hosted Windows and policy checks are green; platform jobs marked skipped are not treated as executed. I found no blocker.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5685218225 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12474#pullrequestreview-5685218225). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T15:27:21Z. **Review:** APPROVED --- Reviewed exact head `5396a7372354d247c689d201e08886917b4a7610`. On non-Windows hosts, `Classify` now maps an `fstat` result with no supported guest descriptor kind to “not open”; actual `EBADF` handling remains unchanged, and recognized file, directory, pipe, socket and character-device paths are preserved. The Linux-only regression checks epoll/eventfd behavior through `fcntl` and `ioctl` and confirms host descriptor flags remain intact. The author reports the focused test and all 948 guest tests on Linux plus the focused Windows run; my exact-head syntax, diff-check and merge-tree checks pass. Hosted Windows and policy checks are green; platform jobs marked skipped are not treated as executed. I found no blocker.
rooklz commented 2026-10-28 16:11:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T16:11:48Z.

Review: COMMENTED


Reviewed head 5396a73723 on macOS 26.2, host side only. It merges cleanly onto main f8f5b24b77 and check_conventions passes. The Linux reasoning holds. I have one scope question about macOS.

What fstat reports for each descriptor kind (small C probes; Linux was a gcc:latest container):

descriptor Linux S_IFMT macOS S_IFMT Classify at this head
memfd_create / /dev/shm (guest shm_open on Linux) 0100000 n/a File
epoll, eventfd, inotify, timerfd, signalfd, pidfd 0 n/a not open (EBADF)
O_PATH|O_NOFOLLOW on a symlink 0120000 n/a not open
host kqueue() n/a 010000 Pipe (already, before this PR)
POSIX shm_open object (arm64 and x86_64) n/a 0 not open
/dev/null 020000 020000 Device

On Linux every descriptor the guest can create still lands in a kept kind, because guest shm is S_IFREG. So the premise "the rest belong to the host" is true there.

On macOS the only new outcome this PR produces is for S_IFMT == 0, and that is exactly what a guest named shm_open returns there. OpenNamedFile's non-Windows branch (SharedMemory.cpp L599-637) calls the host ::shm_open. Before this PR, fcntl(F_GETFD/F_GETFL/F_SETFD) or ioctl on such a descriptor threw, which is a loud and recorded gap. At this head it quietly returns EBADF for a descriptor the guest opened, while FreeBSD kern_fcntl answers F_GETFD/F_GETFL on a shm descriptor. IsHostSharedMemoryDescriptor returns false on macOS (#else arm), so nothing else catches it first. The host side agrees: fcntl(F_GETFD)=1 and F_GETFL=2 on that descriptor.

Two caveats. I can't run this end to end on macOS: on main, libkernel's CreateAnonymousFile uses memfd_create/MFD_CLOEXEC unguarded, so SharedMemory.cpp doesn't compile there (-fsyntax-only: use of undeclared identifier 'MFD_CLOEXEC'), and CI's macOS lanes are relinker-only. Also, the Dusklight evidence is Linux only.

Suggestion: limit the new return std::nullopt; to Linux, where anonymous inodes are the only kinds it reaches, and keep the throw elsewhere:

    if (S_ISSOCK(status.st_mode)) return Kind::Socket;
#ifdef __linux__
    return std::nullopt;
#else
    throw std::runtime_error(std::string(function) + ": descriptor " + std::to_string(fd) + " is neither a file, a directory, a pipe, a socket nor a character device");
#endif

You could also keep it as is and say in the body/debt that on macOS a guest named shm descriptor now reads as not open. Either is fine with me, but the current body says "On Linux and macOS ... A guest can't create such a descriptor", which isn't true on macOS.

Non-blocking, and present before this PR: on macOS a host kqueue() reports S_IFIFO, so host-only kqueues (FileEvent.cpp L449) are classified as Pipe rather than not open. The EBADF reasoning in this PR wouldn't reach them there.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5685890735 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12474#pullrequestreview-5685890735). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T16:11:48Z. **Review:** COMMENTED --- Reviewed head `5396a73723` on macOS 26.2, host side only. It merges cleanly onto `main` `f8f5b24b77` and `check_conventions` passes. The Linux reasoning holds. I have one scope question about macOS. **What `fstat` reports for each descriptor kind** (small C probes; Linux was a `gcc:latest` container): | descriptor | Linux `S_IFMT` | macOS `S_IFMT` | `Classify` at this head | |---|---|---|---| | `memfd_create` / `/dev/shm` (guest `shm_open` on Linux) | `0100000` | n/a | File | | epoll, eventfd, inotify, timerfd, signalfd, pidfd | `0` | n/a | not open (`EBADF`) | | `O_PATH\|O_NOFOLLOW` on a symlink | `0120000` | n/a | not open | | host `kqueue()` | n/a | `010000` | **Pipe** (already, before this PR) | | POSIX `shm_open` object (arm64 and x86_64) | n/a | **`0`** | **not open** | | `/dev/null` | `020000` | `020000` | Device | On Linux every descriptor the guest can create still lands in a kept kind, because guest shm is `S_IFREG`. So the premise "the rest belong to the host" is true there. On macOS the only new outcome this PR produces is for `S_IFMT == 0`, and that is exactly what a guest **named** `shm_open` returns there. `OpenNamedFile`'s non-Windows branch (`SharedMemory.cpp` L599-637) calls the host `::shm_open`. Before this PR, `fcntl(F_GETFD/F_GETFL/F_SETFD)` or `ioctl` on such a descriptor threw, which is a loud and recorded gap. At this head it quietly returns `EBADF` for a descriptor the guest opened, while FreeBSD `kern_fcntl` answers `F_GETFD`/`F_GETFL` on a shm descriptor. `IsHostSharedMemoryDescriptor` returns `false` on macOS (`#else` arm), so nothing else catches it first. The host side agrees: `fcntl(F_GETFD)=1` and `F_GETFL=2` on that descriptor. Two caveats. I can't run this end to end on macOS: on `main`, libkernel's `CreateAnonymousFile` uses `memfd_create`/`MFD_CLOEXEC` unguarded, so `SharedMemory.cpp` doesn't compile there (`-fsyntax-only`: `use of undeclared identifier 'MFD_CLOEXEC'`), and CI's macOS lanes are relinker-only. Also, the Dusklight evidence is Linux only. **Suggestion:** limit the new `return std::nullopt;` to Linux, where anonymous inodes are the only kinds it reaches, and keep the throw elsewhere: ```cpp if (S_ISSOCK(status.st_mode)) return Kind::Socket; #ifdef __linux__ return std::nullopt; #else throw std::runtime_error(std::string(function) + ": descriptor " + std::to_string(fd) + " is neither a file, a directory, a pipe, a socket nor a character device"); #endif ``` You could also keep it as is and say in the body/debt that on macOS a guest named shm descriptor now reads as not open. Either is fine with me, but the current body says "On Linux and macOS ... A guest can't create such a descriptor", which isn't true on macOS. Non-blocking, and present before this PR: on macOS a host `kqueue()` reports `S_IFIFO`, so host-only kqueues (`FileEvent.cpp` L449) are classified as `Pipe` rather than not open. The `EBADF` reasoning in this PR wouldn't reach them there. AI-assisted: yes
MarcZX10 commented 2026-10-28 16:14:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T16:14:36Z.

Review: CHANGES_REQUESTED


After my earlier review, I checked the macOS descriptor case raised in the latest review. This head changes every unrecognized fstat type to nullopt, and OpenNamedFile uses host shm_open on macOS. IsHostSharedMemoryDescriptor only recognizes the Linux and Windows implementations, so a guest-created named shared-memory descriptor on macOS reaches the new EBADF path in fcntl/ioctl instead of remaining a valid guest descriptor. The PR description currently claims the change is safe on macOS, but that case contradicts the claim.

Please either scope this fallback to Linux, where this PR's epoll/eventfd regression is demonstrated, or explicitly recognize and preserve guest-created shared-memory descriptors on macOS before classifying unknown host descriptors as closed. Please add a regression for the chosen behavior and correct the platform claim. Until that is addressed I am changing my review to request changes; the Linux behavior remains supported by the reported tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5685929892 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12474#pullrequestreview-5685929892). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T16:14:36Z. **Review:** CHANGES_REQUESTED --- After my earlier review, I checked the macOS descriptor case raised in the latest review. This head changes every unrecognized `fstat` type to `nullopt`, and `OpenNamedFile` uses host `shm_open` on macOS. `IsHostSharedMemoryDescriptor` only recognizes the Linux and Windows implementations, so a guest-created named shared-memory descriptor on macOS reaches the new `EBADF` path in `fcntl`/`ioctl` instead of remaining a valid guest descriptor. The PR description currently claims the change is safe on macOS, but that case contradicts the claim. Please either scope this fallback to Linux, where this PR's epoll/eventfd regression is demonstrated, or explicitly recognize and preserve guest-created shared-memory descriptors on macOS before classifying unknown host descriptors as closed. Please add a regression for the chosen behavior and correct the platform claim. Until that is addressed I am changing my review to request changes; the Linux behavior remains supported by the reported tests.
XairRrR commented 2026-10-29 03:50:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T03:50:44Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The Linux-only change to Classify is correct and the new regression fails without it, but the Unblocks line names no Game bring-up discussion, which CONTRIBUTING requires.

What I ran

  • Head: e821de8aca108cd1ab22688e6f19285c81ec2c9b
  • main: b433c40f2f46aa2e59e19806010a839ac8572d64
  • Tree: head merged into main with --no-ff in a clean worktree (no conflicts). Release, GCC 16.2.1, Ninja, on Arch Linux 7.2.11-zen, Intel Core i9-14900KF.
git diff --check origin/main...refs/review/12474
python3 tools/check_conventions.py --base origin/main
cmake --build build -j10 --target guest_kernel_fcntl_tests guest_kernel_fcntl_sync_tests
cmake --build build -j10 --target libs
cmake --build build -j10
ctest --test-dir build -j4 --output-on-failure --repeat until-fail:3 \
  -R '^(guest_kernel_fcntl|guest_kernel_fcntl_sync|guest_closed_standard_descriptors|guest_socket_descriptor_flags|guest_socket_descriptors|guest_dup|guest_shm_open|guest_named_shm_.*|guest_stdio_variadic)$'
ctest --test-dir build -j4 --output-on-failure -R '^guest_'
# negative control
git checkout origin/main -- core/libs/prx/libkernel/File/src/DescriptorControl.cpp
cmake --build build -j10 --target guest_kernel_fcntl_tests guest_freebsd_clocks_tests guest_socket_options_tests
ctest --test-dir build --output-on-failure -R '^(guest_kernel_fcntl|guest_freebsd_clocks|guest_socket_options_multicast)$'
git checkout HEAD -- core/libs/prx/libkernel/File/src/DescriptorControl.cpp

Results

Check Result
Merge into main Clean
git diff --check Clean
check_conventions.py All conventions checks passed.
Build: fcntl tests, libs, full tree Pass
14 focused fcntl, dup, socket-descriptor and shm tests, 3 runs each 14/14 pass, guest_kernel_fcntl 0.00 s
^guest_ (983 tests) 980 pass, 1 skipped (guest_net_ctl), 2 fail: guest_freebsd_clocks and guest_socket_options_multicast. Both fail the same way with main's DescriptorControl.cpp restored, so this change does not cause them. The multicast one fails because the sandbox has no network.
Negative control guest_kernel_fcntl aborts without the production change
Area run
99% tests passed, 2 tests failed out of 983
The following tests did not run:
	2129 - guest_net_ctl (Skipped)
The following tests FAILED:
	2445 - guest_freebsd_clocks (Subprocess aborted)
	2542 - guest_socket_options_multicast (Subprocess aborted)

guest_socket_options_multicast: joining 224.0.0.251 through INADDR_ANY failed (errno 5).

Negative control

I restored only core/libs/prx/libkernel/File/src/DescriptorControl.cpp from main and kept the new test. guest_kernel_fcntl then aborts on the first host-only descriptor:

Output
terminate called after throwing an instance of 'std::runtime_error'
  what():  fcntl: descriptor 6 is neither a file, a directory, a pipe, a socket nor a character device

When I put the merged file back, the test passes again.

Findings

Blocking

  • The Unblocks line has no Game bring-up discussion. CONTRIBUTING.md L64 says a PR that fixes a stop seen on a title names "the title ID and its Game bring-up discussion (Unblocks: PPSA01325 #3232)". The body has Unblocks: Dusklight (PPSA99305) past its fcntl abort, with no discussion number. I found no Game bring-up discussion for PPSA99305 or Dusklight. Its only mention is in the import list of #7971, which is in Ideas. Fix: open a Game bring-up discussion for PPSA99305 (with the fcntl abort log) and change the line to Unblocks: PPSA99305 #<number>. This is a change to the PR body only; the code needs nothing.

Non-blocking

  • The fcntl debt entry does not describe the new outcome. docs/dev/debt/libkernel.md L284 lists which kinds fcntl handles. It says nothing about a descriptor of another kind. With this PR, such a descriptor answers EBADF on Linux and still throws on Windows and macOS (DescriptorControl.cpp L304-L308). The rule also only hides host descriptors whose kind no guest call creates. The runtime's own epoll, eventfd, inotify and userfaultfd descriptors (EdgeWatch.cpp, FileEvent.cpp, GuestWriteWatch.cpp) now read as closed. Its own regular files, pipes, sockets and character devices (GPU device nodes, for example) still answer fcntl as open guest descriptors, where a console would return EBADF. Dusklight imports execv, execvp and posix_spawnp, so its loop over descriptors after /proc/self/fd fails looks like a pre-spawn cleanup. If it closes what fcntl accepts, it could still reach those. Adding a sentence to that entry would record this gap. L247 already notes that the host table holds the runtime's own files.

The earlier macOS concern (rooklz and MarcZX10, on 5396a73723) is resolved at this head. The fallback is #ifdef __linux__, other hosts keep the throw, and the test now checks that a guest named shm_open descriptor still answers F_GETFL, F_SETFD and F_GETFD. On Linux I found nothing a guest can open that fstat reports as anything but a regular file, directory, FIFO, character device or socket. The only O_PATH and anonymous-inode descriptors under core/ are the runtime's own.

Not verified

  • Dusklight itself: I did not launch it.
  • macOS and Windows builds: the change keeps the throw there, and only CI's Windows job ran it.
  • guest_freebsd_clocks: I did not find out why it fails on this machine. It fails the same way with main's DescriptorControl.cpp.

To get this to a good state

  1. Open a Game bring-up discussion for PPSA99305 and put its number on the Unblocks line.
  2. Optionally, add a sentence to the fcntl entry in docs/dev/debt/libkernel.md about descriptors of other kinds (EBADF on Linux, a throw elsewhere) and about the runtime's own files, pipes, sockets and devices still answering as open.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5692627821 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12474#pullrequestreview-5692627821). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T03:50:44Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The Linux-only change to `Classify` is correct and the new regression fails without it, but the `Unblocks` line names no Game bring-up discussion, which CONTRIBUTING requires. ## What I ran - Head: `e821de8aca108cd1ab22688e6f19285c81ec2c9b` - `main`: `b433c40f2f46aa2e59e19806010a839ac8572d64` - Tree: head merged into `main` with `--no-ff` in a clean worktree (no conflicts). Release, GCC 16.2.1, Ninja, on Arch Linux 7.2.11-zen, Intel Core i9-14900KF. ```sh git diff --check origin/main...refs/review/12474 python3 tools/check_conventions.py --base origin/main cmake --build build -j10 --target guest_kernel_fcntl_tests guest_kernel_fcntl_sync_tests cmake --build build -j10 --target libs cmake --build build -j10 ctest --test-dir build -j4 --output-on-failure --repeat until-fail:3 \ -R '^(guest_kernel_fcntl|guest_kernel_fcntl_sync|guest_closed_standard_descriptors|guest_socket_descriptor_flags|guest_socket_descriptors|guest_dup|guest_shm_open|guest_named_shm_.*|guest_stdio_variadic)$' ctest --test-dir build -j4 --output-on-failure -R '^guest_' # negative control git checkout origin/main -- core/libs/prx/libkernel/File/src/DescriptorControl.cpp cmake --build build -j10 --target guest_kernel_fcntl_tests guest_freebsd_clocks_tests guest_socket_options_tests ctest --test-dir build --output-on-failure -R '^(guest_kernel_fcntl|guest_freebsd_clocks|guest_socket_options_multicast)$' git checkout HEAD -- core/libs/prx/libkernel/File/src/DescriptorControl.cpp ``` ## Results | Check | Result | |---|---| | Merge into `main` | Clean | | `git diff --check` | Clean | | `check_conventions.py` | `All conventions checks passed.` | | Build: fcntl tests, `libs`, full tree | Pass | | 14 focused fcntl, dup, socket-descriptor and shm tests, 3 runs each | 14/14 pass, `guest_kernel_fcntl` 0.00 s | | `^guest_` (983 tests) | 980 pass, 1 skipped (`guest_net_ctl`), 2 fail: `guest_freebsd_clocks` and `guest_socket_options_multicast`. Both fail the same way with `main`'s `DescriptorControl.cpp` restored, so this change does not cause them. The multicast one fails because the sandbox has no network. | | Negative control | `guest_kernel_fcntl` aborts without the production change | <details><summary>Area run</summary> ``` 99% tests passed, 2 tests failed out of 983 The following tests did not run: 2129 - guest_net_ctl (Skipped) The following tests FAILED: 2445 - guest_freebsd_clocks (Subprocess aborted) 2542 - guest_socket_options_multicast (Subprocess aborted) ``` `guest_socket_options_multicast`: `joining 224.0.0.251 through INADDR_ANY failed (errno 5)`. </details> ## Negative control I restored only `core/libs/prx/libkernel/File/src/DescriptorControl.cpp` from `main` and kept the new test. `guest_kernel_fcntl` then aborts on the first host-only descriptor: <details><summary>Output</summary> ``` terminate called after throwing an instance of 'std::runtime_error' what(): fcntl: descriptor 6 is neither a file, a directory, a pipe, a socket nor a character device ``` </details> When I put the merged file back, the test passes again. ## Findings ### Blocking - **The `Unblocks` line has no Game bring-up discussion.** [CONTRIBUTING.md L64](https://github.com/boykopovar/AnyPS5/blob/b433c40f2f46aa2e59e19806010a839ac8572d64/CONTRIBUTING.md#L64-L64) says a PR that fixes a stop seen on a title names "the title ID and its Game bring-up discussion (`Unblocks: PPSA01325 #3232`)". The body has `Unblocks: Dusklight (PPSA99305) past its fcntl abort`, with no discussion number. I found no Game bring-up discussion for PPSA99305 or Dusklight. Its only mention is in the import list of [#7971](https://github.com/boykopovar/AnyPS5/discussions/7971), which is in Ideas. Fix: open a Game bring-up discussion for PPSA99305 (with the `fcntl` abort log) and change the line to `Unblocks: PPSA99305 #<number>`. This is a change to the PR body only; the code needs nothing. ### Non-blocking - **The fcntl debt entry does not describe the new outcome.** [docs/dev/debt/libkernel.md L284](https://github.com/boykopovar/AnyPS5/blob/b433c40f2f46aa2e59e19806010a839ac8572d64/docs/dev/debt/libkernel.md#L284-L284) lists which kinds `fcntl` handles. It says nothing about a descriptor of another kind. With this PR, such a descriptor answers `EBADF` on Linux and still throws on Windows and macOS ([DescriptorControl.cpp L304-L308](https://github.com/boykopovar/AnyPS5/blob/e821de8aca108cd1ab22688e6f19285c81ec2c9b/core/libs/prx/libkernel/File/src/DescriptorControl.cpp#L304-L308)). The rule also only hides host descriptors whose kind no guest call creates. The runtime's own epoll, eventfd, inotify and userfaultfd descriptors (`EdgeWatch.cpp`, `FileEvent.cpp`, `GuestWriteWatch.cpp`) now read as closed. Its own regular files, pipes, sockets and character devices (GPU device nodes, for example) still answer `fcntl` as open guest descriptors, where a console would return `EBADF`. Dusklight imports `execv`, `execvp` and `posix_spawnp`, so its loop over descriptors after `/proc/self/fd` fails looks like a pre-spawn cleanup. If it closes what `fcntl` accepts, it could still reach those. Adding a sentence to that entry would record this gap. [L247](https://github.com/boykopovar/AnyPS5/blob/b433c40f2f46aa2e59e19806010a839ac8572d64/docs/dev/debt/libkernel.md#L247-L247) already notes that the host table holds the runtime's own files. The earlier macOS concern (rooklz and MarcZX10, on `5396a73723`) is resolved at this head. The fallback is `#ifdef __linux__`, other hosts keep the throw, and the test now checks that a guest named `shm_open` descriptor still answers `F_GETFL`, `F_SETFD` and `F_GETFD`. On Linux I found nothing a guest can open that `fstat` reports as anything but a regular file, directory, FIFO, character device or socket. The only `O_PATH` and anonymous-inode descriptors under `core/` are the runtime's own. ## Not verified - Dusklight itself: I did not launch it. - macOS and Windows builds: the change keeps the throw there, and only CI's Windows job ran it. - `guest_freebsd_clocks`: I did not find out why it fails on this machine. It fails the same way with `main`'s `DescriptorControl.cpp`. ## To get this to a good state 1. Open a Game bring-up discussion for PPSA99305 and put its number on the `Unblocks` line. 2. Optionally, add a sentence to the fcntl entry in `docs/dev/debt/libkernel.md` about descriptors of other kinds (`EBADF` on Linux, a throw elsewhere) and about the runtime's own files, pipes, sockets and devices still answering as open.
XairRrR commented 2026-10-29 04:03:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T04:03:57Z.

Review: APPROVED


Re-checked — approved

The PR body's Unblocks line now names the Game bring-up discussion #12708 for PPSA99305, which resolves my only blocking finding; the code and main are the same commits I built and tested last time.

What changed since my last review

  • Description: the checklist line now reads Unblocks: PPSA99305 #12708 (Dusklight, past its fcntl abort).
  • New discussion: #12708 is in the Game bring-up category. It has the title ID, the fcntl abort log from main, the setup, and a link to this PR.
  • Commits: none. The head is still e821de8aca.
  • main: it has not moved since my last review (b433c40f2f), so last time's merge, build, test and negative-control results apply unchanged.

What I ran

  • Head: e821de8aca108cd1ab22688e6f19285c81ec2c9b
  • main: b433c40f2f46aa2e59e19806010a839ac8572d64
git fetch origin main pull/12474/head:refs/review/12474
git rev-parse origin/main refs/review/12474
git merge-tree --write-tree origin/main refs/review/12474   # clean, exit 0
gh api graphql -f query='{repository(owner:"boykopovar",name:"AnyPS5"){discussion(number:12708){title category{name} body}}}'

I did not rebuild or rerun the tests. No code, test or build file changed, and both SHAs are the ones I tested in my last review.

Previous findings

  • Blocking: the Unblocks line has no Game bring-up discussion. Resolved. The line follows the form in CONTRIBUTING.md L64 (Unblocks: PPSA01325 #3232). #12708 is a Game bring-up discussion titled "Game bring-up: Dusklight (PPSA99305): …", and it lists this PR under "Pull requests from this title".
  • Non-blocking: the fcntl debt entry does not describe the new outcome. Still open. docs/dev/debt/libkernel.md L284 still does not say that another kind of descriptor gets EBADF on Linux and still throws elsewhere. It also does not say that the runtime's own files, pipes, sockets and devices still answer as open. This does not block the merge; a follow-up could add it.

New findings

Blocking

None.

Non-blocking

None.

Not verified

  • Dusklight itself: I did not launch it. The discussion's Linux run is author-reported.
  • macOS and Windows: as before, the change keeps the throw there, and only CI's Windows job has run it.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5692711491 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12474#pullrequestreview-5692711491). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T04:03:57Z. **Review:** APPROVED --- # Re-checked — approved The PR body's `Unblocks` line now names the Game bring-up discussion #12708 for PPSA99305, which resolves my only blocking finding; the code and `main` are the same commits I built and tested last time. ## What changed since my last review - **Description:** the checklist line now reads `Unblocks: PPSA99305 #12708 (Dusklight, past its fcntl abort)`. - **New discussion:** [#12708](https://github.com/boykopovar/AnyPS5/discussions/12708) is in the Game bring-up category. It has the title ID, the `fcntl` abort log from `main`, the setup, and a link to this PR. - **Commits:** none. The head is still `e821de8aca`. - **`main`:** it has not moved since my last review (`b433c40f2f`), so last time's merge, build, test and negative-control results apply unchanged. ## What I ran - Head: `e821de8aca108cd1ab22688e6f19285c81ec2c9b` - `main`: `b433c40f2f46aa2e59e19806010a839ac8572d64` ```sh git fetch origin main pull/12474/head:refs/review/12474 git rev-parse origin/main refs/review/12474 git merge-tree --write-tree origin/main refs/review/12474 # clean, exit 0 gh api graphql -f query='{repository(owner:"boykopovar",name:"AnyPS5"){discussion(number:12708){title category{name} body}}}' ``` I did not rebuild or rerun the tests. No code, test or build file changed, and both SHAs are the ones I tested in my last review. ## Previous findings - **Blocking: the `Unblocks` line has no Game bring-up discussion.** Resolved. The line follows the form in [CONTRIBUTING.md L64](https://github.com/boykopovar/AnyPS5/blob/b433c40f2f46aa2e59e19806010a839ac8572d64/CONTRIBUTING.md#L64-L64) (`Unblocks: PPSA01325 #3232`). #12708 is a Game bring-up discussion titled "Game bring-up: Dusklight (PPSA99305): …", and it lists this PR under "Pull requests from this title". - **Non-blocking: the fcntl debt entry does not describe the new outcome.** Still open. [docs/dev/debt/libkernel.md L284](https://github.com/boykopovar/AnyPS5/blob/b433c40f2f46aa2e59e19806010a839ac8572d64/docs/dev/debt/libkernel.md#L284-L284) still does not say that another kind of descriptor gets `EBADF` on Linux and still throws elsewhere. It also does not say that the runtime's own files, pipes, sockets and devices still answer as open. This does not block the merge; a follow-up could add it. ## New findings ### Blocking None. ### Non-blocking None. ## Not verified - Dusklight itself: I did not launch it. The discussion's Linux run is author-reported. - macOS and Windows: as before, the change keeps the throw there, and only CI's Windows job has run it.
MarcZX10 commented 2026-10-29 05:19:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T05:19:15Z.

Review: CHANGES_REQUESTED


Re-checked — changes requested

The author corrected the macOS descriptor classification and added the title bring-up discussion requested by review; the remaining blocker is that current main changed the same implementation and test files after this branch’s base, so the integrated behavior and regression test need a fresh run.

What I ran

  • Compared head e821de8aca108cd1ab22688e6f19285c81ec2c9b with current main 52c09d567d2fa453494dd720fcf53a98149468e4.
  • Ran git merge-tree --write-tree and inspected the same-path changes on current main.
  • Checked the latest author reply adding Unblocks: PPSA99305 #12708, the prior Linux/macOS findings, and hosted checks.

Results

Check Result
Current-main preview Clean merge preview; tree ee3f1a0826...
Branch base Merge base 04fefebe901d9ff4b29acc7d6c4c28d66643d86f; current main has 332 later commits
Same files changed on current main core/libs/prx/libkernel/File/src/DescriptorControl.cpp and core/libs/tests/GuestKernelFcntl.cpp
Prior focused test evidence The current-head behavior and new regression were independently reviewed/tested on the older integrated base; the latest independent review approved after the Unblocks line was fixed
Raw output
$ git merge-tree --write-tree refs/review/main-20261029b refs/review/pr-12474-20261029
ee3f1a0826...
exit=0
merge-base: 04fefebe901d9ff4b29acc7d6c4c28d66643d86f
current main: 52c09d567d2fa453494dd720fcf53a98149468e4
changed-path intersection:
core/libs/prx/libkernel/File/src/DescriptorControl.cpp
core/libs/tests/GuestKernelFcntl.cpp

Negative control

  • The prior independent report says the new Linux regression fails without the classification change. I did not repeat it after current main changed these files.

Findings

Blocking

  • Current main changes both DescriptorControl.cpp and GuestKernelFcntl.cpp after this branch’s base. The preview merges cleanly, but the previous focused build/test did not include those current changes. Please refresh the branch and rerun the focused descriptor/fcntl test on the integrated head before this review can be cleared.

Non-blocking

  • The earlier macOS finding is addressed by keeping the unknown-kind behavior Linux-only, and the Unblocks checklist now points to the PPSA99305 Game bring-up discussion #12708. The merge preview is clean.

Sources

Not verified

  • I did not rerun the focused test, host-platform probe, or negative control on the current-main tree. Hosted macOS/product coverage is not claimed here.

To get this to a good state

Rebase onto current main, rerun the focused descriptor/fcntl test, and update the Tested section with the exact head and base. The previous functional and checklist findings are otherwise resolved.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5693197839 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12474#pullrequestreview-5693197839). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T05:19:15Z. **Review:** CHANGES_REQUESTED --- # Re-checked — changes requested The author corrected the macOS descriptor classification and added the title bring-up discussion requested by review; the remaining blocker is that current `main` changed the same implementation and test files after this branch’s base, so the integrated behavior and regression test need a fresh run. ## What I ran - Compared head `e821de8aca108cd1ab22688e6f19285c81ec2c9b` with current `main` `52c09d567d2fa453494dd720fcf53a98149468e4`. - Ran `git merge-tree --write-tree` and inspected the same-path changes on current `main`. - Checked the latest author reply adding `Unblocks: PPSA99305 #12708`, the prior Linux/macOS findings, and hosted checks. ## Results | Check | Result | |---|---| | Current-main preview | Clean merge preview; tree `ee3f1a0826...` | | Branch base | Merge base `04fefebe901d9ff4b29acc7d6c4c28d66643d86f`; current main has 332 later commits | | Same files changed on current main | `core/libs/prx/libkernel/File/src/DescriptorControl.cpp` and `core/libs/tests/GuestKernelFcntl.cpp` | | Prior focused test evidence | The current-head behavior and new regression were independently reviewed/tested on the older integrated base; the latest independent review approved after the `Unblocks` line was fixed | <details> <summary>Raw output</summary> ```text $ git merge-tree --write-tree refs/review/main-20261029b refs/review/pr-12474-20261029 ee3f1a0826... exit=0 merge-base: 04fefebe901d9ff4b29acc7d6c4c28d66643d86f current main: 52c09d567d2fa453494dd720fcf53a98149468e4 changed-path intersection: core/libs/prx/libkernel/File/src/DescriptorControl.cpp core/libs/tests/GuestKernelFcntl.cpp ``` </details> ## Negative control - The prior independent report says the new Linux regression fails without the classification change. I did not repeat it after current `main` changed these files. ## Findings ### Blocking - Current `main` changes both `DescriptorControl.cpp` and `GuestKernelFcntl.cpp` after this branch’s base. The preview merges cleanly, but the previous focused build/test did not include those current changes. Please refresh the branch and rerun the focused descriptor/fcntl test on the integrated head before this review can be cleared. ### Non-blocking - The earlier macOS finding is addressed by keeping the unknown-kind behavior Linux-only, and the `Unblocks` checklist now points to the PPSA99305 Game bring-up discussion #12708. The merge preview is clean. ## Sources - [Current contribution rules](https://github.com/boykopovar/AnyPS5/blob/52c09d567d2fa453494dd720fcf53a98149468e4/CONTRIBUTING.md#L57-L66) - [Implementation at PR head](https://github.com/boykopovar/AnyPS5/blob/e821de8aca108cd1ab22688e6f19285c81ec2c9b/core/libs/prx/libkernel/File/src/DescriptorControl.cpp) - [Focused regression test at PR head](https://github.com/boykopovar/AnyPS5/blob/e821de8aca108cd1ab22688e6f19285c81ec2c9b/core/libs/tests/GuestKernelFcntl.cpp) - [Game bring-up discussion](https://github.com/boykopovar/AnyPS5/discussions/12708) ## Not verified - I did not rerun the focused test, host-platform probe, or negative control on the current-main tree. Hosted macOS/product coverage is not claimed here. ## To get this to a good state Rebase onto current `main`, rerun the focused descriptor/fcntl test, and update the Tested section with the exact head and base. The previous functional and checklist findings are otherwise resolved.
MarcZX10 commented 2026-10-29 05:37:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T05:37:25Z.

Review: APPROVED


Re-checked — approved

The current-main rebase resolves my integration blocker. The Linux-only fallback, preservation of guest shm_open descriptors, title context, and regression coverage now agree with the reported behavior.

What I ran

  • Reviewed exact head f83a259550f2892184ff476913a0f95b3aa81dfd against current main 52c09d567d2fa453494dd720fcf53a98149468e4.
  • Ran git merge-tree --write-tree, git diff --check, and python3 tools/check_conventions.py --base refs/review/main-20261029c --head refs/review/pr-12474-latest.
  • Checked the author’s focused test report and the current hosted check state.

Results

Check Result
Current-main merge preview Clean
git diff --check Passed
Conventions Passed
Focused descriptor/fcntl tests Author reports 14 tests pass 3 of 3 on this head
Negative control Author reports the new guest_kernel_fcntl regression aborts with main’s implementation
Full ^guest_ suite Still building per the latest update; I did not run it locally
Hosted checks Eligibility, conventions, labels, and report pass; Windows is still in progress; Linux/product jobs are skipped

The focused regression and clean integration are sufficient for approval. The full suite and Windows job remain pending; I am not counting either as completed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5693326884 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12474#pullrequestreview-5693326884). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T05:37:25Z. **Review:** APPROVED --- # Re-checked — approved The current-main rebase resolves my integration blocker. The Linux-only fallback, preservation of guest `shm_open` descriptors, title context, and regression coverage now agree with the reported behavior. ## What I ran - Reviewed exact head `f83a259550f2892184ff476913a0f95b3aa81dfd` against current `main` `52c09d567d2fa453494dd720fcf53a98149468e4`. - Ran `git merge-tree --write-tree`, `git diff --check`, and `python3 tools/check_conventions.py --base refs/review/main-20261029c --head refs/review/pr-12474-latest`. - Checked the author’s focused test report and the current hosted check state. ## Results | Check | Result | |---|---| | Current-main merge preview | Clean | | `git diff --check` | Passed | | Conventions | Passed | | Focused descriptor/fcntl tests | Author reports 14 tests pass 3 of 3 on this head | | Negative control | Author reports the new `guest_kernel_fcntl` regression aborts with `main`’s implementation | | Full `^guest_` suite | Still building per the latest update; I did not run it locally | | Hosted checks | Eligibility, conventions, labels, and report pass; Windows is still in progress; Linux/product jobs are skipped | The focused regression and clean integration are sufficient for approval. The full suite and Windows job remain pending; I am not counting either as completed.
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!12474
No description provided.