fix(libkernel): route vector I/O on guest sockets #3150
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3150"
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 MarcZX10 on 2026-10-10T23:19:39Z.
What
Route
sceKernelReadvandsceKernelWritevon guest socket descriptors through the socket runtime. Each call gathers or scatters through onesendorrecv, preserving datagram boundaries and normal stream short-transfer behavior. Positioned I/O is covered separately.The socket vector error path translates the guest errno with
SceKernelError, matchingsceKernelRead/sceKernelWrite; in particular,EAGAINreturnsSCE_KERNEL_ERROR_EAGAINinstead of being collapsed toEIO. The regression test checks a nonblockingsceKernelReadvwith no pending data. The technical-debt entry records the remaining guest socket I/O gap.Tested
eb9efe109, Linux x86-64, GCC 12.2, Release: builtguest_socket_read_write_testsandguest_udp_tests; CTestguest_socket_read_writeandguest_udppassed 2/2.eb9efe109merged withmaind31b57a4c, GCC 16.2.1:guest_socket_read_write,guest_udp,guest_socket_pair, andguest_socket_eventspassed, including the new nonblockingsceKernelReadvEAGAIN case.e096acdamerged withmain181420f8. This predates the EAGAIN error-mapping correction.eb9efe109; the Linux and Windows full workflows are skipped unless a collaborator starts the manual workflow.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)Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-10T23:34:40Z.
Review: COMMENTED
Two libkernel fixes on one surface — a file API pointed at a guest socket — and a third on the
selecttimeout, where a large valid duration must not turn into an immediate return. They are read together because they arrived together, though the first two are the pair.#3150, vector I/O. Gathering or scattering through a single
sendorrecvis the right call, and the reason is worth stating in the code's own terms:readvon a datagram must not concatenate two datagrams into one buffer, and one send preserves that boundary where a loop over the iovecs would not. The iovec count is already bounded before the socket branch —CheckIovecsrejectsiovcnt > KERNEL_IOV_MAX(1024) withEINVAL, in bothTransferIovecsand the standalonesceKernelReadv/sceKernelWritev— so the guest's vector count is not relying on the host's limit matching its own. Declaring positioned I/O as covered separately, with #3151 arriving to do exactly that, is a tidy split.#3151, positioned I/O.
ESPIPEis precisely what the specification asks for on a seekless object; the socket-range check runs first, andIsOpenthen selectsESPIPEfor an open socket andEBADFfor a closed one, which is the right pair. Returning the SCE kernel error values from thesceKernelforms rather than an errno is the right half of the split too. The other seekless case is already covered: a pipe getsESPIPEthrough the host path, natively on Linux and through the non-disk branch of the Windows positioned path.#3152, the timeout overflow. This is the most interesting of the three because the symptom is inverted: a valid large
timevaloverflowed into a deadline in the past, turning a long wait into no wait at all. Computing the range before the conversion, saturating at the clock's maximum, and rounding the remaining microseconds without an overflowing addition are the three places it had to be fixed, and the regression covers the boundary set that would have caught each. One question, and this is the only one of the three without an entry to answer it in: saturation means an oversized timeout waits essentially forever, whereas the host's ownselectreportsEINVALfor a timeout it cannot represent. The in-tree check is unrelated — it rejects negative and out-of-rangeusec, not a large valid duration — so whether the saturation is the console's behaviour or a deliberate divergence is still open, and a line saying which would stop a reader taking it for an oversight.All three name what they fixed and what they left, which is what makes a set like this reviewable as a set rather than a pile.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-10T23:40:28Z.
Ran e096acda merged onto
main181420f8on Linux (GCC 16.2.1). One case where the vector calls answer differently from the scalar ones on the same socket: inGuestSocketReadWrite.cpp, right after the socket is made non-blocking andsceKernelRead(server, ...)is checked forKernelAgain, I addedsceKernelReadv(server, vectorRead, 2)with nothing pending. It returns0x80020005(EIO) wheresceKernelReadreturns0x80020023.The socket branch in
Stdio.cppmaps the error throughSceErrorFromErrno, which turns every errno above 34 except 66 into EIO, so EAGAIN (35) is lost there. I only ran the EAGAIN case.Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T23:57:48Z.
Windows check (Windows 11, WinLibs GCC 15.2.0 r7, Release), this head (e096acda) merged onto
main181420f8:mainwith only the test changes:guest_socket_read_writeandguest_udpfail (0/2).--repeat until-fail:3).Note: this PR and #3151 conflict with each other (both change the socket paths in
Stdio.cppandGuestSocketReadWrite.cpp), so whichever lands second needs a rebase.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:08:26Z.
The socket branch in
sceKernelReadv/sceKernelWritevandTransferIovecsmaps the error throughSceErrorFromErrnoinStdio.cpp, which turnsEAGAINintoEIO: on a non-blocking socket with nothing pending,sceKernelReadvreturns 0x80020005 wheresceKernelReadreturns 0x80020023 (fma-rc's case above). Please map it the waysceKernelReaddoes (SceKernelError,Open.cpp:172), add that case to the test, and rebase; it conflicts with main inSocketRuntime.hpp.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T01:18:02Z.
Thanks for identifying the mismatch and for the independent Linux and Windows checks. I rebased #3150 onto current
mainand fixed the guest socket error conversion in thesceKernelReadv/sceKernelWritevpaths: they now useSceKernelError(*__error_nid_postfix()), assceKernelReaddoes. The regression test sets the accepted socket nonblocking and assertssceKernelReadvreturnsSCE_KERNEL_ERROR_EAGAINwhen no data is pending.Pushed as
eb9efe109(fix(libkernel): preserve vector socket error codes). C++20 syntax checks for the changed implementation and test, conventions, andgit diff --checkpass. The runtime tests have not yet been rerun on this corrected head; I updated the PR description to distinguish the earlier passing run from the new test.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T01:36:33Z.
Follow-up validation on the corrected head
eb9efe109: the Release build ofguest_socket_read_write_testsandguest_udp_testssucceeded, and CTestguest_socket_read_writeandguest_udppassed 2/2. The current-head GitHub checks are green; Linux and Windows full workflows remain skipped as manual approval workflows. I updated the PR description to distinguish this run from the earlier Windows run on the pre-correction head.Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-11T01:37:25Z.
Ran
eb9efe109merged ontomaind31b57a4con Linux (GCC 16.2.1):guest_socket_read_write,guest_udp,guest_socket_pairandguest_socket_eventspass, including the newsceKernelReadvcheck forSCE_KERNEL_ERROR_EAGAINon the non-blocking socket.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T03:15:59Z.
Thanks for running the corrected head against the additional socket tests. I added your Linux GCC 16.2.1 results for
guest_socket_pairandguest_socket_eventsto the Tested section; those complement the localguest_socket_read_writeandguest_udprun.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T04:45:07Z.
Thanks for testing the current code on Linux and confirming that
sceKernelReadvon a non-blocking guest socket returnsSCE_KERNEL_ERROR_EAGAINas expected. That provides useful independent coverage for the vector-I/O path.