fix(libkernel): poll files on standard descriptors as vnodes #10456

Merged
alnsx merged 5 commits from upstream-pr/10456 into main 2026-10-25 23:09:32 +00:00
alnsx commented 2026-10-24 01:29:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alnsx on 2026-10-24T01:29:59Z.


What

select and poll applied the standard-stream fallback before checking whether descriptors 0–2 referred to files. An empty file duplicated onto stdin therefore reported no readiness, even at EOF.

Check for a vnode first, so redirected files use the same readiness rules as files at any other descriptor. Tests cover all three standard descriptors, read/write readiness, exclusion of priority events, EOF and stream restoration.

This follows the existing FreeBSD model: selscan polls the file object and vop_stdpoll supplies ordinary read/write readiness. This also applies to files inherited through host redirection. Console behavior remains unmeasured.

Tested

Linux 7.2.6, GCC 13.3, Release; base e13027a1f399062d663d095ab1db139b91de0887, SPIRV-Tools disabled.

  • Both new regressions fail with the base implementation: select returns 0 instead of 2; poll returns 0 instead of 1.
  • With the fix, 8/8 focused tests pass: select, poll, filesystem, socket descriptor flags, three standard-stream cases and kqueue.
  • All libraries and the relinker rebuild successfully. Whitespace and scoped conventions checks pass; debt-length warnings remain.
  • After merging main 0119103fa9, head 7eecb44157 rebuilds all libraries/relinker and passes the same 8 focused tests (Linux, 2026-10-25). This includes the merged #9365 documentation corrections.
  • Windows, macOS and console execution not tested; no game-unblocking claim.
ctest --test-dir build -R '^(guest_select|guest_poll|guest_filesystem|guest_standard_streams.*|guest_kqueue|guest_socket_descriptor_flags)$' -V

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:4991415622 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10456). Originally posted by [alnsx](https://github.com/alnsx) on 2026-10-24T01:29:59Z. --- ### What `select` and `poll` applied the standard-stream fallback before checking whether descriptors 0–2 referred to files. An empty file duplicated onto stdin therefore reported no readiness, even at EOF. Check for a vnode first, so redirected files use the same readiness rules as files at any other descriptor. Tests cover all three standard descriptors, read/write readiness, exclusion of priority events, EOF and stream restoration. This follows the existing FreeBSD model: [`selscan`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/sys_generic.c) polls the file object and [`vop_stdpoll`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/vfs_default.c) supplies ordinary read/write readiness. This also applies to files inherited through host redirection. Console behavior remains unmeasured. ### Tested Linux 7.2.6, GCC 13.3, Release; base `e13027a1f399062d663d095ab1db139b91de0887`, SPIRV-Tools disabled. - Both new regressions fail with the base implementation: select returns 0 instead of 2; poll returns 0 instead of 1. - With the fix, 8/8 focused tests pass: select, poll, filesystem, socket descriptor flags, three standard-stream cases and kqueue. - All libraries and the relinker rebuild successfully. Whitespace and scoped conventions checks pass; debt-length warnings remain. - After merging main `0119103fa9`, head `7eecb44157` rebuilds all libraries/relinker and passes the same 8 focused tests (Linux, 2026-10-25). This includes the merged #9365 documentation corrections. - Windows, macOS and console execution not tested; no game-unblocking claim. ```sh ctest --test-dir build -R '^(guest_select|guest_poll|guest_filesystem|guest_standard_streams.*|guest_kqueue|guest_socket_descriptor_flags)$' -V ``` <!-- 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. --> ### 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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
harisibrar1 commented 2026-10-24 05:02:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T05:02:09Z.

Review: COMMENTED


Checked against main 6c52b649e7 and FreeBSD 11.4 vop_stdpoll/selscan:

  • The reorder looks right to me. File::IsVnode only accepts regular files, directories and archived files (S_ISREG/S_ISDIR on Linux, FILE_TYPE_DISK on Windows), so a pipe or terminal on 0-2 still takes the standard-stream fallback, and the vnode readiness matches vop_stdpoll (no POLLPRI, no POLLHUP).
  • One behaviour change I'd like spelled out in the debt: IsVnode can't tell a guest dup2 from a host redirection. Launching with < file on Linux now makes fd 0 always readable, and Dungeons (PPSA16064) selects on fd 0, so it would start reading host stdin. With > log.txt, fd 1 and 2 become readable too. Main's poll entry (docs/dev/debt/libkernel.md:213) still says 0-2 follow the console model "whatever the host attaches to them", which is no longer true for files. Could that line be updated together with the select one?
  • The rewritten select entry drops two sentences that still describe current code: the /dev/random/randomdev_poll set-reporting rule and the kqueue_poll sentence. Could they be kept, with only the standard-descriptor part changed?
  • The branch merges cleanly with current main. #10501's pselect goes through select_nid_postfix, so it picks this up; #9945's NUL handles are character devices and keep the fallback (from reading only, not run on Windows).

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636928403 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10456#pullrequestreview-5636928403). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T05:02:09Z. **Review:** COMMENTED --- Checked against main 6c52b649e7 and FreeBSD 11.4 `vop_stdpoll`/`selscan`: - The reorder looks right to me. `File::IsVnode` only accepts regular files, directories and archived files (`S_ISREG`/`S_ISDIR` on Linux, `FILE_TYPE_DISK` on Windows), so a pipe or terminal on 0-2 still takes the standard-stream fallback, and the vnode readiness matches `vop_stdpoll` (no POLLPRI, no POLLHUP). - One behaviour change I'd like spelled out in the debt: `IsVnode` can't tell a guest `dup2` from a host redirection. Launching with `< file` on Linux now makes fd 0 always readable, and Dungeons (PPSA16064) selects on fd 0, so it would start reading host stdin. With `> log.txt`, fd 1 and 2 become readable too. Main's poll entry (`docs/dev/debt/libkernel.md:213`) still says 0-2 follow the console model "whatever the host attaches to them", which is no longer true for files. Could that line be updated together with the select one? - The rewritten select entry drops two sentences that still describe current code: the `/dev/random`/`randomdev_poll` set-reporting rule and the `kqueue_poll` sentence. Could they be kept, with only the standard-descriptor part changed? - The branch merges cleanly with current main. #10501's pselect goes through `select_nid_postfix`, so it picks this up; #9945's NUL handles are character devices and keep the fallback (from reading only, not run on Windows). Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
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!10456
No description provided.