feat(kernel): implement vectored file IO on Windows #1131
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1131"
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 orbz22 on 2026-10-07T13:22:28Z.
What
sceKernelReadv,sceKernelWritev,sceKernelPreadvandsceKernelPwritevthrewnot implemented on Windows(listed in TechnicalDebt). On Windows they now gather the iovecs into one host buffer (writes) or read into one and scatter it (reads), so each call is a single_read/_writeor a single positionedReadFile/WriteFile. Argument checks and error codes follow the Linux path:EINVALforiovcntoutside 0..1024 or a negative offset,EFAULTfor a null iovec array, guest write destinations are opened throughGuestArena::HostWriteas on Linux. In addition, an iovec with a null base and non-zero length returnsEFAULTand a total length aboveINT64_MAXreturnsEINVAL, which the Linux kernel reports itself.CheckIovecsandOpenIovecsmove out of the Linux-only block so both paths use them.Positioned transfers and the file offset.
NativePositioned(Windows) usedReadFile/WriteFilewith anOVERLAPPEDoffset on a synchronous handle, which also moves the handle's file pointer.preadv/pwritevmust leave it unchanged (GuestFileVector.cppchecks this), so the helper now saves the pointer and restores it after the transfer, and returnsESPIPEfor handles that are not disk files. The same helper backspread/pwriteon Windows, so those now keep the offset too, as they do on POSIX and on the Linux path. Concurrentread/writeon the same descriptor from another thread can still observe the pointer between the transfer and the restore; there is no way to avoid that with a shared CRT descriptor short of reopening the file.guest_file_vectorwas registered only on Linux; it now runs on Windows too, withlibkernel's directory onPATH.Tested
Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), CMake 4.4.4, Ninja 1.13.2, rebased on
cea1ef13.ctest -R '^guest_file_vector$' --repeat until-fail:3: passed 3/3. WithStdio.cppfrommainthe same executable terminates on thenot implemented on Windowsexception.--target libs, fullctest: 396/396 passed.guest_file_vectoris still registered there.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_01UTjpbMX7BUFMZZaxJE98zV
Imported from boykopovar/AnyPS5. Originally posted by KSWORK2001 on 2026-10-07T21:05:31Z.
I was implementing the same four exports today (before noticing this pull request - not opening a duplicate) and independently hit and confirmed the file-pointer finding: with
NativePositionedfrommain, my run ofguest_file_vectorfailed atGuestFileVector.cppline 69 (sceKernelLseek == 10after apreadv), and the save/restore fixes it. Same toolchain here (WinLibs r7 GCC 15.2.0, Windows 11); fullctest399/399 with the fix in place.Two deltas I noticed between this gather-into-one-buffer design and direct per-iovec transfers, for the reviewer's judgement:
NativeTransferthrowsNativeTransfer: nbytes exceeds platform limitfor a total aboveINT_MAX, and the throw terminates the process per project policy. On the console a legalreadv/writevis bounded only bySSIZE_MAX(which this pull request already returnsEINVALfor), so an iovec set summing to between 2 GiB and 8 EiB transfers on the console and throws here. Per-iovec transfers chunked at theDWORDlimit avoid the bound.std::max<std::size_t>(total, 1)); withKERNEL_IOV_MAX1024 entries that is a large transient allocation and a double copy for big saves, where per-iovec_read/_writeneeds neither.Happy to hand over my per-iovec variant (it also early-outs a pipe
readvwithPeekNamedPipeonce no bytes remain, which the single-call design gets for free) if any of this is wanted here; otherwise this works as merged.Written with AI assistance (ZCode).
Imported from boykopovar/AnyPS5. Originally posted by orbz22 on 2026-10-08T00:49:08Z.
Thanks for checking this independently and for both points. Both are fixed in 3b264868:
INT_MAXbytes, so a total above 2 GiB no longer reaches the throw.preadv/pwritevadvance the offset by the bytes done, and the sumoffset + totalis checked for overflow (EINVAL).Since the transfer is no longer a single call, a
readvon a pipe stops after one read; otherwise a second_readwould block once the available bytes were consumed. A short read on a pipe is allowed, so I used that instead ofPeekNamedPipe. A partial transfer followed by an error returns the byte count.New checks in
GuestFileVector.cpp: a zero-length iovec between two buffers forreadvandpreadv;readvon a pipe holding fewer bytes than the iovecs (this hangs if the loop does not stop);preadv/pwritevon a pipe returnESPIPE.guest_file_vectorpasses on Windows (WinLibs GCC 15.2.0 r7).Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T07:59:54Z.
Checked: Linux build + full ctest (424/424) on main + this PR; Windows CI job runs
guest_file_vectorand passes (including the new gapped-iovec and pipe cases); argument checks and error codes match the Linux path;offset + totaloverflow and the pipe short-read case are handled.Added by us (commit
e8697e693, nothing in the code changed):### FunctionalTechnicalDebt line for the deviations this PR introduces: the file pointer is restored after a positioned transfer, so a concurrentread/writeon the same descriptor can see it moved in between; non-disk handles returnESPIPE;readvon a pipe or console stops after the first iovec read; a failure after the first transfer returns the bytes already done.Remaining, not blocking: the PR description still says the iovecs are gathered into one host buffer / a single
_read/_write. That was true before 3b264868; please update it. The >2 GiB chunking isn't covered by any test.Merging once CI is green on the rebased head.