fix(libkernel): report O_RDWR from F_GETFL on both ends of a pipe #8544

Merged
Retr0G28 merged 3 commits from upstream-pr/8544 into main 2026-10-23 22:55:31 +00:00
Retr0G28 commented 2026-10-20 16:07:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Retr0G28 on 2026-10-20T16:07:24Z.


What

fcntl(F_GETFL) on a pipe end reported O_RDONLY for the read end and O_WRONLY for the write end, because the access mode came from the host, where pipe ends are one-way. FreeBSD 11 pipes are bidirectional: kern_pipe opens both ends with finit(..., FREAD | FWRITE, ...) (sys/kern/sys_pipe.c), and kern_fcntl builds F_GETFL from OFLAGS(fp->f_flag) (sys/kern/kern_descrip.c), so both ends report O_RDWR.

The guest descriptor table now marks descriptors created by pipe. The mark follows dup, dup2 and F_DUPFD with the shared status flags, an entry made by open replaces it, and close drops it. F_GETFL reports O_RDWR for a marked descriptor and still asks the host for every other descriptor, so a FIFO opened with O_RDONLY keeps reporting O_RDONLY, as on FreeBSD. The sentence about this gap is cut from the fcntl entry in docs/dev/debt/libkernel.md.

Test changes:

  • guest_kernel_fcntl (PipeFlagsRoundTrip) now expects O_RDWR on both ends, with and without O_NONBLOCK, and on an F_DUPFD copy of the write end.
  • guest_dup now expects O_RDWR | O_NONBLOCK in its shared-status-flags case.

Tested

Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release, -DBUILD_TESTING=ON, on main 77e31219c.

  • Before the fix, guest_kernel_fcntl with the new expectations fails (exit 0xc0000409 from the failed Require). With this PR it passes.
  • ctest -R "fcntl|pipe|dup|poll|select|kqueue|stdio|descriptor|socket" -E "^agc_": 40 of 40 pass when run serially.
  • Every guest_ test (547): the only failures that remain when run alone are guest_module_dir and guest_module_identity. They fail the same way on main on this machine (Windows Defender blocks a file they generate, WinError 225).
  • python tools/check_conventions.py --base origin/main reports no errors. The one warning is the existing length of the fcntl debt entry, which this PR shortens.
  • Linux: @xXPBSXx ran the PR head on WSL2 Ubuntu 24.04 (GCC 13.3.0): guest_dup and guest_kernel_fcntl pass, and both fail with main's DescriptorControl and Stdio.cpp (comment below). Not run on bare-metal Linux.
  • No title or homebrew run.

Overlap: tools/pr_overlap.py could not compare some open PRs. I checked the ones that touch the same code files (#7121, #6977, #6044, #5021, #6936, #7201, #7530). None changes the access mode F_GETFL reports for a pipe. The rest touch only other lines of docs/dev/debt/libkernel.md.

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:4938683055 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8544). Originally posted by [Retr0G28](https://github.com/Retr0G28) on 2026-10-20T16:07:24Z. --- ### What `fcntl(F_GETFL)` on a `pipe` end reported `O_RDONLY` for the read end and `O_WRONLY` for the write end, because the access mode came from the host, where pipe ends are one-way. FreeBSD 11 pipes are bidirectional: `kern_pipe` opens both ends with `finit(..., FREAD | FWRITE, ...)` (`sys/kern/sys_pipe.c`), and `kern_fcntl` builds `F_GETFL` from `OFLAGS(fp->f_flag)` (`sys/kern/kern_descrip.c`), so both ends report `O_RDWR`. The guest descriptor table now marks descriptors created by `pipe`. The mark follows `dup`, `dup2` and `F_DUPFD` with the shared status flags, an entry made by `open` replaces it, and `close` drops it. `F_GETFL` reports `O_RDWR` for a marked descriptor and still asks the host for every other descriptor, so a FIFO opened with `O_RDONLY` keeps reporting `O_RDONLY`, as on FreeBSD. The sentence about this gap is cut from the fcntl entry in `docs/dev/debt/libkernel.md`. Test changes: - `guest_kernel_fcntl` (`PipeFlagsRoundTrip`) now expects `O_RDWR` on both ends, with and without `O_NONBLOCK`, and on an `F_DUPFD` copy of the write end. - `guest_dup` now expects `O_RDWR | O_NONBLOCK` in its shared-status-flags case. ### Tested Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release, `-DBUILD_TESTING=ON`, on `main` 77e31219c. - Before the fix, `guest_kernel_fcntl` with the new expectations fails (exit 0xc0000409 from the failed `Require`). With this PR it passes. - ctest `-R "fcntl|pipe|dup|poll|select|kqueue|stdio|descriptor|socket" -E "^agc_"`: 40 of 40 pass when run serially. - Every `guest_` test (547): the only failures that remain when run alone are `guest_module_dir` and `guest_module_identity`. They fail the same way on `main` on this machine (Windows Defender blocks a file they generate, WinError 225). - `python tools/check_conventions.py --base origin/main` reports no errors. The one warning is the existing length of the fcntl debt entry, which this PR shortens. - Linux: @xXPBSXx ran the PR head on WSL2 Ubuntu 24.04 (GCC 13.3.0): `guest_dup` and `guest_kernel_fcntl` pass, and both fail with `main`'s `DescriptorControl` and `Stdio.cpp` (comment below). Not run on bare-metal Linux. - No title or homebrew run. Overlap: `tools/pr_overlap.py` could not compare some open PRs. I checked the ones that touch the same code files (#7121, #6977, #6044, #5021, #6936, #7201, #7530). None changes the access mode `F_GETFL` reports for a pipe. The rest touch only other lines of `docs/dev/debt/libkernel.md`. ### 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: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
xXPBSXx commented 2026-10-21 08:45:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T08:45:34Z.


Linux data point for 2d1fa5aea5: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal Linux), GCC 13.3.0, Release, BUILD_TESTING=ON, PR head alone (not merged onto main).

  • With the PR: ctest -R '^(guest_dup|guest_kernel_fcntl)$' passes 3 of 3 (both tests).
  • With DescriptorControl.hpp, DescriptorControl.cpp and Stdio.cpp (libkernel/File) restored to the merge-base (new test cases kept): both fail (Subprocess aborted).
    Not tested: macOS, Windows, a title run.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6311873967 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8544#issuecomment-6311873967). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T08:45:34Z. --- Linux data point for `2d1fa5aea5`: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal Linux), GCC 13.3.0, Release, `BUILD_TESTING=ON`, PR head alone (not merged onto `main`). - With the PR: `ctest -R '^(guest_dup|guest_kernel_fcntl)$'` passes 3 of 3 (both tests). - With `DescriptorControl.hpp`, `DescriptorControl.cpp` and `Stdio.cpp` (libkernel/File) restored to the merge-base (new test cases kept): both fail (`Subprocess aborted`). Not tested: macOS, Windows, a title run. AI-assisted (Claude Code).
DavidSamir commented 2026-10-22 08:50:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T08:50:03Z.


Hi @Retr0G28, a merge-order note: my #9557 (pipe SIGIO owner) and #9561 (O_FSYNC) edit the same fcntl row of docs/dev/debt/libkernel.md as this PR, and they conflict in that file only. Proposal: no dependency either way; whichever merges second keeps every sentence. Does that work for you? I'll record it in their checklists.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6336711167 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8544#issuecomment-6336711167). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T08:50:03Z. --- Hi @Retr0G28, a merge-order note: my #9557 (pipe `SIGIO` owner) and #9561 (`O_FSYNC`) edit the same `fcntl` row of `docs/dev/debt/libkernel.md` as this PR, and they conflict in that file only. Proposal: no dependency either way; whichever merges second keeps every sentence. Does that work for you? I'll record it in their checklists. AI-assisted: yes
Retr0G28 commented 2026-10-22 15:27:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Retr0G28 on 2026-10-22T15:27:48Z.


@DavidSamir Yes, that works for me: no dependency either way, and whichever of us merges second rebases and keeps every sentence of the fcntl row. I checked with git merge-tree: this PR conflicts with #9557 and #9561 only in that row of docs/dev/debt/libkernel.md.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6344533268 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8544#issuecomment-6344533268). Originally posted by [Retr0G28](https://github.com/Retr0G28) on 2026-10-22T15:27:48Z. --- @DavidSamir Yes, that works for me: no dependency either way, and whichever of us merges second rebases and keeps every sentence of the `fcntl` row. I checked with `git merge-tree`: this PR conflicts with #9557 and #9561 only in that row of `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!8544
No description provided.