fix(libkernel): route vector I/O on guest sockets #3150

Merged
MarcZX10 merged 2 commits from upstream-pr/3150 into main 2026-10-11 05:47:37 +00:00
MarcZX10 commented 2026-10-10 23:19:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T23:19:39Z.


What

Route sceKernelReadv and sceKernelWritev on guest socket descriptors through the socket runtime. Each call gathers or scatters through one send or recv, 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, matching sceKernelRead/sceKernelWrite; in particular, EAGAIN returns SCE_KERNEL_ERROR_EAGAIN instead of being collapsed to EIO. The regression test checks a nonblocking sceKernelReadv with no pending data. The technical-debt entry records the remaining guest socket I/O gap.

Tested

  • Corrected PR head eb9efe109, Linux x86-64, GCC 12.2, Release: built guest_socket_read_write_tests and guest_udp_tests; CTest guest_socket_read_write and guest_udp passed 2/2.
  • Independent Linux run on corrected head eb9efe109 merged with main d31b57a4c, GCC 16.2.1: guest_socket_read_write, guest_udp, guest_socket_pair, and guest_socket_events passed, including the new nonblocking sceKernelReadv EAGAIN case.
  • Windows 11, WinLibs GCC 15.2.0 r7, Release: the same two tests passed 3/3 on the earlier implementation head e096acda merged with main 181420f8. This predates the EAGAIN error-mapping correction.
  • Current-head GitHub checks were green at eb9efe109; the Linux and Windows full workflows are skipped unless a collaborator starts the manual workflow.

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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4815143461 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3150). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T23:19:39Z. --- ### What Route `sceKernelReadv` and `sceKernelWritev` on guest socket descriptors through the socket runtime. Each call gathers or scatters through one `send` or `recv`, 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`, matching `sceKernelRead`/`sceKernelWrite`; in particular, `EAGAIN` returns `SCE_KERNEL_ERROR_EAGAIN` instead of being collapsed to `EIO`. The regression test checks a nonblocking `sceKernelReadv` with no pending data. The technical-debt entry records the remaining guest socket I/O gap. ### Tested - Corrected PR head `eb9efe109`, Linux x86-64, GCC 12.2, Release: built `guest_socket_read_write_tests` and `guest_udp_tests`; CTest `guest_socket_read_write` and `guest_udp` passed 2/2. - Independent Linux run on corrected head `eb9efe109` merged with `main` `d31b57a4c`, GCC 16.2.1: `guest_socket_read_write`, `guest_udp`, `guest_socket_pair`, and `guest_socket_events` passed, including the new nonblocking `sceKernelReadv` EAGAIN case. - Windows 11, WinLibs GCC 15.2.0 r7, Release: the same two tests passed 3/3 on the earlier implementation head `e096acda` merged with `main` `181420f8`. This predates the EAGAIN error-mapping correction. - Current-head GitHub checks were green at `eb9efe109`; the Linux and Windows full workflows are skipped unless a collaborator starts the manual workflow. ### Checklist - [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 (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
Dextroid17 commented 2026-10-10 23:34:40 +00:00 (Migrated from github.com)

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 select timeout, 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 send or recv is the right call, and the reason is worth stating in the code's own terms: readv on 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 — CheckIovecs rejects iovcnt > KERNEL_IOV_MAX (1024) with EINVAL, in both TransferIovecs and the standalone sceKernelReadv/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. ESPIPE is precisely what the specification asks for on a seekless object; the socket-range check runs first, and IsOpen then selects ESPIPE for an open socket and EBADF for a closed one, which is the right pair. Returning the SCE kernel error values from the sceKernel forms rather than an errno is the right half of the split too. The other seekless case is already covered: a pipe gets ESPIPE through 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 timeval overflowed 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 own select reports EINVAL for a timeout it cannot represent. The in-tree check is unrelated — it rejects negative and out-of-range usec, 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5481198738 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3150#pullrequestreview-5481198738). Originally posted by [Dextroid17](https://github.com/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 `select` timeout, 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 `send` or `recv` is the right call, and the reason is worth stating in the code's own terms: `readv` on 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 — `CheckIovecs` rejects `iovcnt > KERNEL_IOV_MAX` (1024) with `EINVAL`, in both `TransferIovecs` and the standalone `sceKernelReadv`/`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.** `ESPIPE` is precisely what the specification asks for on a seekless object; the socket-range check runs first, and `IsOpen` then selects `ESPIPE` for an open socket and `EBADF` for a closed one, which is the right pair. Returning the SCE kernel error values from the `sceKernel` forms rather than an errno is the right half of the split too. The other seekless case is already covered: a pipe gets `ESPIPE` through 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 `timeval` overflowed 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 own `select` reports `EINVAL` for a timeout it cannot represent. The in-tree check is unrelated — it rejects negative and out-of-range `usec`, 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.
fma-rc commented 2026-10-10 23:40:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-10T23:40:28Z.


Ran e096acda merged onto main 181420f8 on Linux (GCC 16.2.1). One case where the vector calls answer differently from the scalar ones on the same socket: in GuestSocketReadWrite.cpp, right after the socket is made non-blocking and sceKernelRead(server, ...) is checked for KernelAgain, I added sceKernelReadv(server, vectorRead, 2) with nothing pending. It returns 0x80020005 (EIO) where sceKernelRead returns 0x80020023.

The socket branch in Stdio.cpp maps the error through SceErrorFromErrno, which turns every errno above 34 except 66 into EIO, so EAGAIN (35) is lost there. I only ran the EAGAIN case.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103404453 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3150#issuecomment-6103404453). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-10T23:40:28Z. --- Ran e096acda merged onto `main` 181420f8 on Linux (GCC 16.2.1). One case where the vector calls answer differently from the scalar ones on the same socket: in `GuestSocketReadWrite.cpp`, right after the socket is made non-blocking and `sceKernelRead(server, ...)` is checked for `KernelAgain`, I added `sceKernelReadv(server, vectorRead, 2)` with nothing pending. It returns `0x80020005` (EIO) where `sceKernelRead` returns `0x80020023`. The socket branch in `Stdio.cpp` maps the error through `SceErrorFromErrno`, which turns every errno above 34 except 66 into EIO, so EAGAIN (35) is lost there. I only ran the EAGAIN case.
reyani-dev commented 2026-10-10 23:57:48 +00:00 (Migrated from github.com)

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 main 181420f8:

  • main with only the test changes: guest_socket_read_write and guest_udp fail (0/2).
  • With the PR: both pass 3/3 (--repeat until-fail:3).

Note: this PR and #3151 conflict with each other (both change the socket paths in Stdio.cpp and GuestSocketReadWrite.cpp), so whichever lands second needs a rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103527018 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3150#issuecomment-6103527018). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-10T23:57:48Z. --- Windows check (Windows 11, WinLibs GCC 15.2.0 r7, Release), this head (e096acda) merged onto `main` 181420f8: - `main` with only the test changes: `guest_socket_read_write` and `guest_udp` fail (0/2). - With the PR: both pass 3/3 (`--repeat until-fail:3`). Note: this PR and #3151 conflict with each other (both change the socket paths in `Stdio.cpp` and `GuestSocketReadWrite.cpp`), so whichever lands second needs a rebase.
oneandonlydean commented 2026-10-11 01:08:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:08:26Z.


The socket branch in sceKernelReadv/sceKernelWritev and TransferIovecs maps the error through SceErrorFromErrno in Stdio.cpp, which turns EAGAIN into EIO: on a non-blocking socket with nothing pending, sceKernelReadv returns 0x80020005 where sceKernelRead returns 0x80020023 (fma-rc's case above). Please map it the way sceKernelRead does (SceKernelError, Open.cpp:172), add that case to the test, and rebase; it conflicts with main in SocketRuntime.hpp.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104053502 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3150#issuecomment-6104053502). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T01:08:26Z. --- The socket branch in `sceKernelReadv`/`sceKernelWritev` and `TransferIovecs` maps the error through `SceErrorFromErrno` in `Stdio.cpp`, which turns `EAGAIN` into `EIO`: on a non-blocking socket with nothing pending, `sceKernelReadv` returns 0x80020005 where `sceKernelRead` returns 0x80020023 (fma-rc's case above). Please map it the way `sceKernelRead` does (`SceKernelError`, `Open.cpp:172`), add that case to the test, and rebase; it conflicts with main in `SocketRuntime.hpp`.
MarcZX10 commented 2026-10-11 01:18:02 +00:00 (Migrated from github.com)

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 main and fixed the guest socket error conversion in the sceKernelReadv/sceKernelWritev paths: they now use SceKernelError(*__error_nid_postfix()), as sceKernelRead does. The regression test sets the accepted socket nonblocking and asserts sceKernelReadv returns SCE_KERNEL_ERROR_EAGAIN when 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, and git diff --check pass. 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104121811 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3150#issuecomment-6104121811). Originally posted by [MarcZX10](https://github.com/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 `main` and fixed the guest socket error conversion in the `sceKernelReadv`/`sceKernelWritev` paths: they now use `SceKernelError(*__error_nid_postfix())`, as `sceKernelRead` does. The regression test sets the accepted socket nonblocking and asserts `sceKernelReadv` returns `SCE_KERNEL_ERROR_EAGAIN` when 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, and `git diff --check` pass. 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.
MarcZX10 commented 2026-10-11 01:36:33 +00:00 (Migrated from github.com)

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 of guest_socket_read_write_tests and guest_udp_tests succeeded, and CTest guest_socket_read_write and guest_udp passed 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104254011 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3150#issuecomment-6104254011). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T01:36:33Z. --- Follow-up validation on the corrected head `eb9efe109`: the Release build of `guest_socket_read_write_tests` and `guest_udp_tests` succeeded, and CTest `guest_socket_read_write` and `guest_udp` passed 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.
fma-rc commented 2026-10-11 01:37:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-11T01:37:25Z.


Ran eb9efe109 merged onto main d31b57a4c on Linux (GCC 16.2.1): guest_socket_read_write, guest_udp, guest_socket_pair and guest_socket_events pass, including the new sceKernelReadv check for SCE_KERNEL_ERROR_EAGAIN on the non-blocking socket.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104260228 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3150#issuecomment-6104260228). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-11T01:37:25Z. --- Ran eb9efe109 merged onto `main` d31b57a4c on Linux (GCC 16.2.1): `guest_socket_read_write`, `guest_udp`, `guest_socket_pair` and `guest_socket_events` pass, including the new `sceKernelReadv` check for `SCE_KERNEL_ERROR_EAGAIN` on the non-blocking socket.
MarcZX10 commented 2026-10-11 03:15:59 +00:00 (Migrated from github.com)

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_pair and guest_socket_events to the Tested section; those complement the local guest_socket_read_write and guest_udp run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104939031 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3150#issuecomment-6104939031). Originally posted by [MarcZX10](https://github.com/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_pair` and `guest_socket_events` to the Tested section; those complement the local `guest_socket_read_write` and `guest_udp` run.
MarcZX10 commented 2026-10-11 04:45:07 +00:00 (Migrated from github.com)

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 sceKernelReadv on a non-blocking guest socket returns SCE_KERNEL_ERROR_EAGAIN as expected. That provides useful independent coverage for the vector-I/O path.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105545959 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3150#issuecomment-6105545959). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T04:45:07Z. --- Thanks for testing the current code on Linux and confirming that `sceKernelReadv` on a non-blocking guest socket returns `SCE_KERNEL_ERROR_EAGAIN` as expected. That provides useful independent coverage for the vector-I/O path.
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!3150
No description provided.