feat(libkernel): poll files, directories, the random device and stdio as FreeBSD does #7139

Merged
AlexOfTheForest merged 5 commits from upstream-pr/7139 into main 2026-10-18 03:52:13 +00:00
AlexOfTheForest commented 2026-10-17 13:24:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexOfTheForest on 2026-10-17T13:24:10Z.


What

poll threw for every descriptor that is neither a socket nor a pipe: regular files, directories, /dev/random and descriptors 0–2. select already handled the random device and stdio, but gave the wrong answer for the random device when more than one set named it, and on Windows threw for files. Four commits, each following FreeBSD 11.4's source:

  1. feat(libkernel): poll regular files and directories as vop_stdpoll does: a vnode goes to VOP_POLL. vop_stdpoll (UFS) and vop_nopoll both return POLLIN, POLLRDNORM and POLLOUT of the request for every event poll accepts, and never POLLPRI, POLLRDBAND or POLLWRBAND. Files, directories and app0.zar files now get that answer without a host call. File::IsVnode classifies the descriptor without throwing, so host sockets lent by libSceNet still reach their own path.
  2. feat(libkernel): poll the random device as randomdev_poll does: once seeded, randomdev_poll narrows a request containing POLLIN/POLLRDNORM to those bits and returns any other request whole. Two tests that relied on the random device throwing now check the real answer (the "still throws" case uses a kqueue descriptor).
  3. fix(libkernel): answer select on files and the random device as FreeBSD's poll routines do: selscan polls each descriptor once with the flags of every set it is in, then marks the sets whose flags the answer shares. So the random device is only readable when it is in the read set; otherwise it is reported in the write and exception sets it was asked in. Before, it was reported readable and writable together and never exceptional. Files and directories are answered in process (readable, writable, never exceptional) instead of by the host poll, which threw on Windows.
  4. feat(libkernel): poll descriptors 0 to 2 with the console model select uses: descriptor 0 reports nothing; 1 and 2 report POLLOUT, the bit ttydev_poll gives a writable terminal. This matches select's existing model.

The poll and select debt entries are updated. Still throwing in poll: other character devices, kqueue descriptors, and anything that is neither a socket, pipe, file, directory, random device nor 0–2.

Tested

Linux x86_64:

  • guest_poll, guest_select, guest_select_wait and guest_socket_descriptors passed 5 of 5 runs. New cases cover files and directories (requests with and without band bits, a timed wait with no ready event, mixed with a socket), both random devices for each request shape, the select set combinations for the random device, and stdio.
  • All 142 libkernel and libSceNet tests were built and run. guest_tcp and guest_named_shm_concurrency fail identically on unmodified main in this container. guest_sce_net is skipped here (no IPv6 loopback), as on main.
  • Each intermediate commit compiles.
  • tools/check_conventions.py --base upstream/main passes; the progress report is unchanged.
  • Not run on Windows. The Windows file classification uses the GetFileType / directory-descriptor checks fcntl already relies on.

Merges cleanly with main. It touches lines in docs/dev/debt/libkernel.md next to my open kevent-ev-clear and kevent-pipe-write PRs; whichever merges later needs a small rebase.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4900416787 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7139). Originally posted by [AlexOfTheForest](https://github.com/AlexOfTheForest) on 2026-10-17T13:24:10Z. --- ### What `poll` threw for every descriptor that is neither a socket nor a pipe: regular files, directories, `/dev/random` and descriptors 0–2. `select` already handled the random device and stdio, but gave the wrong answer for the random device when more than one set named it, and on Windows threw for files. Four commits, each following FreeBSD 11.4's source: 1. `feat(libkernel): poll regular files and directories as vop_stdpoll does`: a vnode goes to `VOP_POLL`. [`vop_stdpoll`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_default.c#L563-L574) (UFS) and `vop_nopoll` both return `POLLIN`, `POLLRDNORM` and `POLLOUT` of the request for every event `poll` accepts, and never `POLLPRI`, `POLLRDBAND` or `POLLWRBAND`. Files, directories and app0.zar files now get that answer without a host call. `File::IsVnode` classifies the descriptor without throwing, so host sockets lent by libSceNet still reach their own path. 2. `feat(libkernel): poll the random device as randomdev_poll does`: once seeded, [`randomdev_poll`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/dev/random/randomdev.c#L274-L285) narrows a request containing `POLLIN`/`POLLRDNORM` to those bits and returns any other request whole. Two tests that relied on the random device throwing now check the real answer (the "still throws" case uses a kqueue descriptor). 3. `fix(libkernel): answer select on files and the random device as FreeBSD's poll routines do`: [`selscan`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/sys_generic.c#L1178-L1236) polls each descriptor once with the flags of every set it is in, then marks the sets whose flags the answer shares. So the random device is only readable when it is in the read set; otherwise it is reported in the write and exception sets it was asked in. Before, it was reported readable and writable together and never exceptional. Files and directories are answered in process (readable, writable, never exceptional) instead of by the host poll, which threw on Windows. 4. `feat(libkernel): poll descriptors 0 to 2 with the console model select uses`: descriptor 0 reports nothing; 1 and 2 report `POLLOUT`, the bit `ttydev_poll` gives a writable terminal. This matches `select`'s existing model. The poll and select debt entries are updated. Still throwing in `poll`: other character devices, kqueue descriptors, and anything that is neither a socket, pipe, file, directory, random device nor 0–2. ### Tested Linux x86_64: - `guest_poll`, `guest_select`, `guest_select_wait` and `guest_socket_descriptors` passed 5 of 5 runs. New cases cover files and directories (requests with and without band bits, a timed wait with no ready event, mixed with a socket), both random devices for each request shape, the `select` set combinations for the random device, and stdio. - All 142 libkernel and libSceNet tests were built and run. `guest_tcp` and `guest_named_shm_concurrency` fail identically on unmodified `main` in this container. `guest_sce_net` is skipped here (no IPv6 loopback), as on `main`. - Each intermediate commit compiles. - `tools/check_conventions.py --base upstream/main` passes; the progress report is unchanged. - Not run on Windows. The Windows file classification uses the `GetFileType` / directory-descriptor checks `fcntl` already relies on. Merges cleanly with `main`. It touches lines in `docs/dev/debt/libkernel.md` next to my open kevent-ev-clear and kevent-pipe-write PRs; whichever merges later needs a small rebase. ### 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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-17 13:37:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T13:37:16Z.


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
PR 5999 core/libs/tests/GuestSelect.cpp L5
docs/dev/debt/libkernel.md L68-69

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 4630 docs/dev/debt/libkernel.md
PR 5021 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 5918 docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestPoll.cpp
core/libs/tests/GuestSelect.cpp
core/libs/tests/GuestSocketDescriptors.cpp
PR 6222 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 6447 core/libs/prx/libkernel/Socket/src/Socket.cpp
PR 6510 docs/dev/debt/libkernel.md
PR 6534 docs/dev/debt/libkernel.md
PR 6836 docs/dev/debt/libkernel.md
PR 6908 docs/dev/debt/libkernel.md
PR 6962 core/libs/prx/libkernel/Socket/src/Udp.cpp
core/libs/tests/GuestPoll.cpp
docs/dev/debt/libkernel.md
PR 6977 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 7039 docs/dev/debt/libkernel.md
PR 7049 docs/dev/debt/libkernel.md
PR 7088 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 7121 core/libs/prx/libkernel/File/include/DescriptorControl.hpp
core/libs/prx/libkernel/File/src/DescriptorControl.cpp
docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/Socket/src/Udp.cpp
core/libs/tests/GuestPoll.cpp
PR 7273 docs/dev/debt/libkernel.md
PR 7332 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234533693 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7139#issuecomment-6234533693). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T13:37:16Z. --- <!-- 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 | |---|---|---|---| | [PR 5999](https://www.github.com/boykopovar/AnyPS5/pull/5999) | `core/libs/tests/GuestSelect.cpp` [L5](https://github.com/boykopovar/AnyPS5/blob/1e2d9b369b692bb3391160b6ec45291dffeee17b/core/libs/tests/GuestSelect.cpp#L5)<br>`docs/dev/debt/libkernel.md` [L68-69](https://github.com/boykopovar/AnyPS5/blob/1e2d9b369b692bb3391160b6ec45291dffeee17b/docs/dev/debt/libkernel.md#L68-L69) | | | 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 4630](https://www.github.com/boykopovar/AnyPS5/pull/4630) | `docs/dev/debt/libkernel.md` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 5918](https://www.github.com/boykopovar/AnyPS5/pull/5918) | `docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestPoll.cpp`<br>`core/libs/tests/GuestSelect.cpp`<br>`core/libs/tests/GuestSocketDescriptors.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6447](https://www.github.com/boykopovar/AnyPS5/pull/6447) | `core/libs/prx/libkernel/Socket/src/Socket.cpp` | | [PR 6510](https://www.github.com/boykopovar/AnyPS5/pull/6510) | `docs/dev/debt/libkernel.md` | | [PR 6534](https://www.github.com/boykopovar/AnyPS5/pull/6534) | `docs/dev/debt/libkernel.md` | | [PR 6836](https://www.github.com/boykopovar/AnyPS5/pull/6836) | `docs/dev/debt/libkernel.md` | | [PR 6908](https://www.github.com/boykopovar/AnyPS5/pull/6908) | `docs/dev/debt/libkernel.md` | | [PR 6962](https://www.github.com/boykopovar/AnyPS5/pull/6962) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`core/libs/tests/GuestPoll.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7039](https://www.github.com/boykopovar/AnyPS5/pull/7039) | `docs/dev/debt/libkernel.md` | | [PR 7049](https://www.github.com/boykopovar/AnyPS5/pull/7049) | `docs/dev/debt/libkernel.md` | | [PR 7088](https://www.github.com/boykopovar/AnyPS5/pull/7088) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `core/libs/prx/libkernel/File/include/DescriptorControl.hpp`<br>`core/libs/prx/libkernel/File/src/DescriptorControl.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`core/libs/tests/GuestPoll.cpp` | | [PR 7273](https://www.github.com/boykopovar/AnyPS5/pull/7273) | `docs/dev/debt/libkernel.md` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` |
UmillD commented 2026-10-17 14:07:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by UmillD on 2026-10-17T14:07:30Z.


Independent Windows validation of this PR.

  • Windows 11 Home Single Language 10.0.26300, AMD Ryzen 7 9700X; WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, BUILD_TESTING=ON, bundled dependencies. CPU/library tests; no GPU or game execution.
  • PR head acad67d946a1d024fe32bd09c0e77772c0247f95 merged cleanly into pinned main 47a266cf975f00f7fba94013467d03bfa5e355e9. Integrated tree: 1a33b4df145ad04c183c9e25f266ed6c47a65911. No other open PRs or local game patches added.
  • Control uses exactly that main's production sources while keeping this PR's three changed test fixtures. Candidate restores the four integrated production files; the rest of the tree/configuration is identical. Both selected-target builds succeeded, and libc.prx has the same SHA-256 in both phases.
Test Main production + PR fixtures (once) With PR
guest_poll FAIL PASS 5/5
guest_select FAIL PASS 5/5
guest_select_wait PASS PASS 5/5
guest_socket_descriptors FAIL PASS 5/5

On the control, guest_poll aborts with poll: descriptor 4 is neither a socket nor a pipe; guest_select with select on descriptor 5 (neither a socket nor a pipe) not implemented; guest_socket_descriptors with poll: descriptor 3 is neither a socket nor a pipe. All three exit 0xc0000409. These are fixture failures exercising the unsupported paths, not title crashes.

With the PR, the four focused cases pass 20/20 executions, using serial CTest --repeat until-fail:5. They exercise the new file/directory and random-device readiness, stdio handling, mixed descriptors and timed waits.

The neighboring cases guest_dup, guest_kernel_fcntl, guest_udp, guest_socket_read_write and guest_socket_pair also pass once on each phase (5/5 control, 5/5 candidate). No skipped cases, timeouts or memory-guard terminations. CTest ran with -j1 --timeout 30, retaining the tests' existing individual timeout properties.

Scope: focused Windows regression coverage, not a full-suite run, game test or console-semantic measurement. This report does not separately exercise app0.zar readiness. No production or fixture changes were needed locally.

AI-assisted testing and report: yes (Codex).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234870556 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7139#issuecomment-6234870556). Originally posted by [UmillD](https://github.com/UmillD) on 2026-10-17T14:07:30Z. --- Independent **Windows validation** of this PR. - Windows 11 Home Single Language **10.0.26300**, AMD Ryzen 7 9700X; WinLibs GCC **15.2.0 r7 UCRT**, Ninja, Release, `BUILD_TESTING=ON`, bundled dependencies. CPU/library tests; no GPU or game execution. - PR head `acad67d946a1d024fe32bd09c0e77772c0247f95` merged cleanly into pinned `main` `47a266cf975f00f7fba94013467d03bfa5e355e9`. Integrated tree: `1a33b4df145ad04c183c9e25f266ed6c47a65911`. No other open PRs or local game patches added. - Control uses exactly that main's production sources while keeping this PR's three changed test fixtures. Candidate restores the four integrated production files; the rest of the tree/configuration is identical. Both selected-target builds succeeded, and `libc.prx` has the same SHA-256 in both phases. | Test | Main production + PR fixtures (once) | With PR | |---|---|---| | `guest_poll` | FAIL | PASS 5/5 | | `guest_select` | FAIL | PASS 5/5 | | `guest_select_wait` | PASS | PASS 5/5 | | `guest_socket_descriptors` | FAIL | PASS 5/5 | On the control, `guest_poll` aborts with `poll: descriptor 4 is neither a socket nor a pipe`; `guest_select` with `select on descriptor 5 (neither a socket nor a pipe) not implemented`; `guest_socket_descriptors` with `poll: descriptor 3 is neither a socket nor a pipe`. All three exit `0xc0000409`. These are fixture failures exercising the unsupported paths, not title crashes. With the PR, the four focused cases pass **20/20 executions**, using serial CTest `--repeat until-fail:5`. They exercise the new file/directory and random-device readiness, stdio handling, mixed descriptors and timed waits. The neighboring cases `guest_dup`, `guest_kernel_fcntl`, `guest_udp`, `guest_socket_read_write` and `guest_socket_pair` also pass once on each phase (**5/5 control, 5/5 candidate**). No skipped cases, timeouts or memory-guard terminations. CTest ran with `-j1 --timeout 30`, retaining the tests' existing individual timeout properties. Scope: focused Windows regression coverage, **not a full-suite run**, game test or console-semantic measurement. This report does not separately exercise `app0.zar` readiness. No production or fixture changes were needed locally. AI-assisted testing and report: yes (Codex).
HQasper commented 2026-10-17 19:30:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by HQasper on 2026-10-17T19:30:56Z.


Thanks for this, it makes files, directories and the console descriptors behave in select as FreeBSD does.

I stacked a small follow-up on top of it in #7248. It answers kqueues as kqueue_poll does, which also fixes the Linux /dev/null placeholder being reported readable and writable. It also handles a descriptor that is closed or reused during the wait, so select no longer reaches NotImplemented. Your four commits are included unchanged, and I'll rebase once this one is merged. If you would rather take the kqueue part into this PR, just say so and I'll close mine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6239610303 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7139#issuecomment-6239610303). Originally posted by [HQasper](https://github.com/HQasper) on 2026-10-17T19:30:56Z. --- Thanks for this, it makes files, directories and the console descriptors behave in `select` as FreeBSD does. I stacked a small follow-up on top of it in #7248. It answers kqueues as `kqueue_poll` does, which also fixes the Linux `/dev/null` placeholder being reported readable and writable. It also handles a descriptor that is closed or reused during the wait, so `select` no longer reaches `NotImplemented`. Your four commits are included unchanged, and I'll rebase once this one is merged. If you would rather take the kqueue part into this PR, just say so and I'll close mine.
oneandonlydean commented 2026-10-17 21:41:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T21:41:03Z.


This now conflicts with main after today's merges. Could you rebase onto current main? We'll re-run full CI on the new head (and #7248, stacked on this, after it).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6241593672 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7139#issuecomment-6241593672). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T21:41:03Z. --- This now conflicts with main after today's merges. Could you rebase onto current main? We'll re-run full CI on the new head (and #7248, stacked on this, after it).
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!7139
No description provided.