fix(libkernel): select on kqueues as kqueue_poll answers #7248

Merged
HQasper merged 6 commits from upstream-pr/7248 into main 2026-10-18 04:22:02 +00:00
HQasper commented 2026-10-17 19:28:24 +00:00 (Migrated from github.com)

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


What

Stacked on #7139: its four commits are included unchanged, and only the last commit (fix(libkernel): select on kqueues as kqueue_poll answers) is new here. With #7139, select still reached NotImplemented_nid_no_patch on Windows for a kqueue and for a descriptor that stopped being a socket or a pipe during the wait. On Linux, a kqueue's /dev/null placeholder was reported readable and writable.

  • A kqueue is readable while one of its events is triggered. It is never writable and never in the exception set, as FreeBSD 11.4's kqueue_poll answers. This holds on both hosts and uses the new KernelEqueuePrivate::HasTriggeredEvents and KqueueReadable. Kqueues get their own poll group next to the guest sockets.
  • A descriptor that stops being a socket, a kqueue or a pipe during the wait:
    • if it was closed, the call fails with EBADF;
    • otherwise select starts over with the rest of the timeout, as kern_select looks every descriptor up again in each pass.
  • On Windows, a host descriptor that is still none of the kinds above (after #7139's files, directories, random device and stdio) throws std::runtime_error naming the descriptor when select starts, before it waits. This is what poll does in the same case.
  • select_nid_postfix no longer reaches NotImplemented_nid_no_patch. tools/progress.py --compare of main (55f82fee8) against this branch: +1 implemented (libkernel select_nid_postfix), 3365 → 3366 of 3753 (89.66 % → 89.69 %).
  • docs/dev/debt/libkernel.md: the two select entries describe the above, including the one window where it is not exact. A close that has removed the descriptor from the kqueue, pipe or file tables but not yet closed the host descriptor is seen as an unknown kind: it throws on Windows and is polled through the host on Linux.

Overlaps: #5999 also changes select on Windows, but only for regular files (the part #7139 covers), and keeps the NotImplemented path. This PR touches neither.

Tested

Windows 11 Pro 26300, MinGW-w64 (WinLibs) Release build of this branch on main 55f82fee8. These pass: guest_select, guest_select_wait, guest_kqueue, guest_equeue_events, guest_poll and guest_socket_descriptors. The new kqueue cases in guest_select:

  • an empty kqueue is not ready, and still is not after an EVFILT_USER event is added with EV_CLEAR;
  • when another thread triggers the event while select waits for up to 1 s, select returns 1 with only the read set;
  • once the event is collected with kevent, the kqueue is not ready again.

Without the Socket.cpp change they fail (select on the kqueue ends in NotImplemented, exit 0xc0000409).

Full ctest -j 24 on the same build: 1421 of 1422 pass. The one failure, agc_driver_pixel_lds, is unrelated: it loses the device on this RTX 5090 (NVIDIA 617.42) on plain main 55f82fee8 too.

Linux not tested.

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: #7139
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4903239108 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7248). Originally posted by [HQasper](https://github.com/HQasper) on 2026-10-17T19:28:24Z. --- ### What Stacked on #7139: its four commits are included unchanged, and only the last commit (`fix(libkernel): select on kqueues as kqueue_poll answers`) is new here. With #7139, `select` still reached `NotImplemented_nid_no_patch` on Windows for a kqueue and for a descriptor that stopped being a socket or a pipe during the wait. On Linux, a kqueue's `/dev/null` placeholder was reported readable and writable. - A kqueue is readable while one of its events is triggered. It is never writable and never in the exception set, as FreeBSD 11.4's [`kqueue_poll`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_event.c#L1900-L1924) answers. This holds on both hosts and uses the new `KernelEqueuePrivate::HasTriggeredEvents` and `KqueueReadable`. Kqueues get their own poll group next to the guest sockets. - A descriptor that stops being a socket, a kqueue or a pipe during the wait: - if it was closed, the call fails with `EBADF`; - otherwise `select` starts over with the rest of the timeout, as [`kern_select`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/sys_generic.c#L1129-L1140) looks every descriptor up again in each pass. - On Windows, a host descriptor that is still none of the kinds above (after #7139's files, directories, random device and stdio) throws `std::runtime_error` naming the descriptor when `select` starts, before it waits. This is what `poll` does in the same case. - `select_nid_postfix` no longer reaches `NotImplemented_nid_no_patch`. `tools/progress.py --compare` of `main` (55f82fee8) against this branch: +1 implemented (`libkernel` `select_nid_postfix`), 3365 → 3366 of 3753 (89.66 % → 89.69 %). - `docs/dev/debt/libkernel.md`: the two `select` entries describe the above, including the one window where it is not exact. A close that has removed the descriptor from the kqueue, pipe or file tables but not yet closed the host descriptor is seen as an unknown kind: it throws on Windows and is polled through the host on Linux. Overlaps: #5999 also changes `select` on Windows, but only for regular files (the part #7139 covers), and keeps the `NotImplemented` path. This PR touches neither. ### Tested Windows 11 Pro 26300, MinGW-w64 (WinLibs) Release build of this branch on `main` 55f82fee8. These pass: `guest_select`, `guest_select_wait`, `guest_kqueue`, `guest_equeue_events`, `guest_poll` and `guest_socket_descriptors`. The new kqueue cases in `guest_select`: - an empty kqueue is not ready, and still is not after an `EVFILT_USER` event is added with `EV_CLEAR`; - when another thread triggers the event while `select` waits for up to 1 s, `select` returns 1 with only the read set; - once the event is collected with `kevent`, the kqueue is not ready again. Without the `Socket.cpp` change they fail (`select` on the kqueue ends in `NotImplemented`, exit `0xc0000409`). Full `ctest -j 24` on the same build: 1421 of 1422 pass. The one failure, `agc_driver_pixel_lds`, is unrelated: it loses the device on this RTX 5090 (NVIDIA 617.42) on plain `main` 55f82fee8 too. Linux not tested. ### 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: #7139 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-17 20:34:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T20:34:15Z.


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 docs/dev/debt/libkernel.md
PR 5918 docs/dev/debt/libkernel.md
PR 5999 core/libs/prx/libkernel/Socket/src/Socket.cpp
core/libs/tests/GuestSelect.cpp
docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestSelect.cpp
PR 6222 docs/dev/debt/libkernel.md
PR 6447 core/libs/prx/libkernel/Equeue/Equeue.cpp
core/libs/prx/libkernel/Socket/src/Socket.cpp
PR 6510 core/libs/prx/libkernel/Equeue/Equeue.cpp
core/libs/prx/libkernel/Equeue/Equeue.hpp
core/libs/prx/libkernel/Equeue/src/Kqueue.cpp
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 docs/dev/debt/libkernel.md
PR 6977 docs/dev/debt/libkernel.md
PR 7039 docs/dev/debt/libkernel.md
PR 7049 core/libs/prx/libkernel/Equeue/Equeue.cpp
core/libs/prx/libkernel/Equeue/src/Kqueue.cpp
docs/dev/debt/libkernel.md
PR 7075 core/libs/prx/libkernel/Equeue/src/Kqueue.cpp
docs/dev/debt/libkernel.md
PR 7088 core/libs/prx/libkernel/Equeue/Equeue.hpp
core/libs/prx/libkernel/Equeue/src/Kqueue.cpp
docs/dev/debt/libkernel.md
PR 7121 core/libs/prx/libkernel/Equeue/Equeue.hpp
core/libs/prx/libkernel/Equeue/src/Kqueue.cpp
docs/dev/debt/libkernel.md
PR 7129 core/libs/prx/libkernel/Equeue/Equeue.cpp
core/libs/prx/libkernel/Equeue/Equeue.hpp
core/libs/prx/libkernel/Equeue/src/Kqueue.cpp
docs/dev/debt/libkernel.md
PR 7135 docs/dev/debt/libkernel.md
PR 7273 docs/dev/debt/libkernel.md
PR 7332 docs/dev/debt/libkernel.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6240588669 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7248#issuecomment-6240588669). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T20:34:15Z. --- <!-- 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 4630](https://www.github.com/boykopovar/AnyPS5/pull/4630) | `docs/dev/debt/libkernel.md` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/libkernel.md` | | [PR 5918](https://www.github.com/boykopovar/AnyPS5/pull/5918) | `docs/dev/debt/libkernel.md` | | [PR 5999](https://www.github.com/boykopovar/AnyPS5/pull/5999) | `core/libs/prx/libkernel/Socket/src/Socket.cpp`<br>`core/libs/tests/GuestSelect.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestSelect.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `docs/dev/debt/libkernel.md` | | [PR 6447](https://www.github.com/boykopovar/AnyPS5/pull/6447) | `core/libs/prx/libkernel/Equeue/Equeue.cpp`<br>`core/libs/prx/libkernel/Socket/src/Socket.cpp` | | [PR 6510](https://www.github.com/boykopovar/AnyPS5/pull/6510) | `core/libs/prx/libkernel/Equeue/Equeue.cpp`<br>`core/libs/prx/libkernel/Equeue/Equeue.hpp`<br>`core/libs/prx/libkernel/Equeue/src/Kqueue.cpp`<br>`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) | `docs/dev/debt/libkernel.md` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `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) | `core/libs/prx/libkernel/Equeue/Equeue.cpp`<br>`core/libs/prx/libkernel/Equeue/src/Kqueue.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7075](https://www.github.com/boykopovar/AnyPS5/pull/7075) | `core/libs/prx/libkernel/Equeue/src/Kqueue.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7088](https://www.github.com/boykopovar/AnyPS5/pull/7088) | `core/libs/prx/libkernel/Equeue/Equeue.hpp`<br>`core/libs/prx/libkernel/Equeue/src/Kqueue.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `core/libs/prx/libkernel/Equeue/Equeue.hpp`<br>`core/libs/prx/libkernel/Equeue/src/Kqueue.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7129](https://www.github.com/boykopovar/AnyPS5/pull/7129) | `core/libs/prx/libkernel/Equeue/Equeue.cpp`<br>`core/libs/prx/libkernel/Equeue/Equeue.hpp`<br>`core/libs/prx/libkernel/Equeue/src/Kqueue.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7135](https://www.github.com/boykopovar/AnyPS5/pull/7135) | `docs/dev/debt/libkernel.md` | | [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) | `docs/dev/debt/libkernel.md` |
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!7248
No description provided.