fix(libkernel): fill every buffer of readv from a pipe on Windows #4864

Merged
milescoviello merged 1 commit from upstream-pr/4864 into main 2026-10-14 01:24:56 +00:00
milescoviello commented 2026-10-13 00:32:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-13T00:32:27Z.


What

Fixes #4858. Carries @DavidSamir's fix branch from that issue (DavidSamir:fix/libkernel-readv-pipe-windows, ab3d8369), keeping the commit and its authorship; it cherry-picks onto current main without changes.

On Windows, readv and sceKernelReadv on a pipe filled only the first buffer and returned, however much was waiting, because TransferIovecs stops after the first transfer on a descriptor that is not a disk file, so that it never waits on an empty pipe for the next buffer; that also stopped it when the next buffer's bytes were already there. FreeBSD's readv(2) "scatters the input data into the iovcnt buffers", and the Linux build returns everything that is waiting. The fix keeps filling buffers while bytes are already available, still without waiting for more after the first transfer. Linux is unchanged.

guest_file_vector gains pipe checks with several buffer sizes and amounts waiting.

Tested

  • @simonbronk ran it on Windows: Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, this PR (665e6f178) merged onto main 0aa4cb1c2.
    • With main's Stdio.cpp and the new checks, guest_file_vector fails at line 212.
    • With this PR, guest_file_vector passes 20/20 and the full ctest passes 1098/1098.
  • From the issue: Windows 11, WinLibs MinGW-w64 GCC 15.2.0, Release: with main's Stdio.cpp the new checks fail at the first one and with the fix guest_file_vector passes 5/5; a 33-line pipe probe matches the Linux build in every blocking case; a 188-line probe over the file, directory, vector and mapping functions differs only in readv from a pipe; no timing difference on files or small pipe reads; eleven catalog titles end the same way with both sets of libraries; full ctest 1001/1001.
  • Linux, added for this carry: Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on main 1c5e6287. guest_file_vector, guest_filesystem, guest_kernel_fcntl and guest_poll pass, and all 324 guest_* tests pass in two runs. The new checks also pass with main's Stdio.cpp, as expected since only the Windows path changes.
  • tools/check_conventions.py --base upstream/main passes.

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 in TechnicalDebt
  • 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
  • Unblocks: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4836652102 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4864). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-13T00:32:27Z. --- ### What Fixes #4858. Carries @DavidSamir's fix branch from that issue (`DavidSamir:fix/libkernel-readv-pipe-windows`, `ab3d8369`), keeping the commit and its authorship; it cherry-picks onto current `main` without changes. On Windows, `readv` and `sceKernelReadv` on a pipe filled only the first buffer and returned, however much was waiting, because `TransferIovecs` stops after the first transfer on a descriptor that is not a disk file, so that it never waits on an empty pipe for the next buffer; that also stopped it when the next buffer's bytes were already there. FreeBSD's `readv(2)` "scatters the input data into the iovcnt buffers", and the Linux build returns everything that is waiting. The fix keeps filling buffers while bytes are already available, still without waiting for more after the first transfer. Linux is unchanged. `guest_file_vector` gains pipe checks with several buffer sizes and amounts waiting. ### Tested - @simonbronk [ran it on Windows](https://github.com/boykopovar/AnyPS5/pull/4864#issuecomment-6155326615): Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, this PR (`665e6f178`) merged onto `main` `0aa4cb1c2`. - With `main`'s `Stdio.cpp` and the new checks, `guest_file_vector` fails at line 212. - With this PR, `guest_file_vector` passes 20/20 and the full `ctest` passes 1098/1098. - From the issue: Windows 11, WinLibs MinGW-w64 GCC 15.2.0, Release: with `main`'s `Stdio.cpp` the new checks fail at the first one and with the fix `guest_file_vector` passes 5/5; a 33-line pipe probe matches the Linux build in every blocking case; a 188-line probe over the file, directory, vector and mapping functions differs only in `readv` from a pipe; no timing difference on files or small pipe reads; eleven catalog titles end the same way with both sets of libraries; full `ctest` 1001/1001. - Linux, added for this carry: Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on `main` 1c5e6287. `guest_file_vector`, `guest_filesystem`, `guest_kernel_fcntl` and `guest_poll` pass, and all 324 `guest_*` tests pass in two runs. The new checks also pass with `main`'s `Stdio.cpp`, as expected since only the Windows path changes. - `tools/check_conventions.py --base upstream/main` passes. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] Unblocks: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
simonbronk commented 2026-10-13 21:14:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-13T21:14:16Z.


Tested this carry on Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, full build, this PR (665e6f178) merged onto current main 0aa4cb1c2 (AI-assisted: Claude Code).

  • With main's Stdio.cpp and the new checks kept: guest_file_vector fails (File vector check failed at line 212, exit 0xc0000409).
  • With this PR: guest_file_vector passes 20/20 (--repeat until-fail:20), and the full ctest passes 1098/1098.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6155326615 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4864#issuecomment-6155326615). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-13T21:14:16Z. --- Tested this carry on Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, full build, this PR (`665e6f178`) merged onto current `main` `0aa4cb1c2` (AI-assisted: Claude Code). - With `main`'s `Stdio.cpp` and the new checks kept: `guest_file_vector` fails (`File vector check failed at line 212`, exit 0xc0000409). - With this PR: `guest_file_vector` passes 20/20 (`--repeat until-fail:20`), and the full `ctest` passes 1098/1098.
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!4864
No description provided.