libkernel: readv from a pipe fills only the first buffer on Windows; fix branch ready #4858
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-13T00:24:43Z.
On Windows,
readvandsceKernelReadvon a pipe fill only the first buffer and return, however much is waiting. FreeBSD's readv(2) "scatters the input data into the iovcnt buffers", and the Linux build returns everything that is there. A caller that reads a header and its body in onereadvgets the header alone on Windows and takes the body for missing.Cause.
TransferIovecsstops after the first transfer when the descriptor is not a disk file (!whole), so that it never waits on an empty pipe for the second buffer. That also stops it when the second buffer's bytes are already waiting.Observed on
main0428328b7, Windows 11 (10.0.26300), WinLibs GCC 15.2.0 r7, Release, on a pipe frompipe()with buffers of 3, 5 and 16 bytes:The rows were run in this order on one pipe, so on Windows each row also had the bytes the rows before it left behind.
I have not found a title that stops on this. It came out of running one probe of the file functions on the Windows build and on the Linux build and comparing the two outputs.
Fix, ready to cherry-pick.
DavidSamir:fix/libkernel-readv-pipe-windows(ab3d83692, one commit onmain0428328b7, two files, +16/-1). I can't open it as a PR while #4532 is open (one open PR without a merged one).Windows only. After a buffer has been filled from a descriptor that is not a disk file,
TransferIovecsgoes on to the next buffer when the descriptor is a pipe with bytes waiting (PeekNamedPipe), and returns as before when nothing is waiting. It still never waits once it has read something: with three bytes in the pipe and two more arriving 300 ms later,readvreturns the three at once. Disk files, positioned reads, writes, sockets and/dev/urandomdo not reach the new check.Not changed, and seen while testing:
readvon an empty pipe thatfcntlhas set non-blocking fails withEINVALon Windows wherereadfails withEAGAIN, because the vector path does not have the mappingsceKernelReadhas. That is a separate fix, which I am preparing.guest_file_vectorgains checks on its pipe: with five bytes waitingsceKernelReadvinto buffers of 3 and 4 must return 5 withstuandvw; with ten waitingreadvmust return 7 and the nextsceKernelReadvthe remaining 3. The existing check, three bytes into the same buffers with the write end open, still has to return 3 without waiting.Checked on Windows (ab3d83692 on
main0428328b7, Windows 11 10.0.26300, WinLibs GCC 15.2.0 r7, Release, full builds):Stdio.cppas onmainand the test kept,guest_file_vectorfails at the first new check (File vector check failed at line 212). With the fix it passes 5/5 (--repeat until-fail:5), andguest_filesystem,guest_poll,guest_dup,guest_standard_streams,file_streams,guest_aioandguest_kernel_fcntlpass 3/3.main's libraries, the branch's and on the Linux build: every blocking case (2, 3, 5, 8, 12 and 36 bytes waiting, zero-length buffers in the middle, a single buffer, an empty pipe that gets five bytes after 150 ms, three bytes now and two later, a duplicate of the read end, the write end closed, the end of the pipe, a closed descriptor, the write end, a file,/dev/urandom) gives the same result on the branch as on the Linux build, and none of them takes longer than 400 ms. The two lines that differ from Linux are the non-blocking empty pipe above, the same withmain's libraries.readvfrom a pipe. A probe of 122 lines over the descriptor functions is identical in both.readvon a file 4.2 to 4.4 µs with both sets of libraries; write three bytes to a pipe andreadvthem 1.16 to 1.24 µs with both; write ten bytes and read them all, which takes fourreadvcalls withmain's libraries and one with the branch's, 2.84 to 3.04 µs and 2.85 to 3.04 µs.pollin both (#3644). I do not know whether any of them callsreadvon a pipe.ctest --parallel 4: 1001 of 1001 pass (7 skipped, no display).tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branchreports no overlap with open pull requests.Checked on Linux (same commit, WSL2 Ubuntu 24.04, GCC 13.3.0, Release):
guest_file_vectorpasses 3/3, so the new checks match the existing Linux behaviour. Only that target andlibswere built there.Not checked on a console or with a commercial title.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-13T00:32:34Z.
Carried in #4864, keeping your commit and authorship. I added the full Linux run (Ubuntu 24.04, GCC 13.3): all 324
guest_*tests pass in two runs, and the newguest_file_vectorchecks also pass withmain'sStdio.cpp, so Linux is unchanged. The Windows results in the PR are yours from this issue. Thanks for the branch.AI-assisted: yes