feat(libkernel): sceKernelReadv, Writev, Preadv and Pwritev #806

Merged
adriadam10 merged 1 commit from upstream-pr/806 into main 2026-10-06 09:32:10 +00:00
adriadam10 commented 2026-10-06 05:34:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T05:34:15Z.


What

Adds the libkernel vectored I/O exports sceKernelReadv, sceKernelWritev, sceKernelPreadv and sceKernelPwritev. Main does not declare them.

  • Guest SceKernelIovec is { void* base; size_t length; }, laid out like the host struct iovec on Linux x86-64 (static_asserts). The array goes straight to the host readv/writev/preadv/pwritev. Layout from SharpProspero (KernelFile.cs, SceKernelIovec) and shadPS4 (OrbisKernelIovec).
  • Contract: these are the FreeBSD syscalls. iovcnt below 0 or above UIO_MAXIOV (1024) gives EINVAL (FreeBSD copyinuio), a null array with iovcnt != 0 gives EFAULT, and a negative offset in preadv/pwritev gives EINVAL. These checks run before the host call, as main's sceKernelPread does. Host errors use the same errno → 0x8002xxxx mapping as sceKernelPread/sceKernelPwrite. preadv/pwritev leave the file offset unchanged.
  • Read buffers are opened through GuestArena::HostWrite like sceKernelPread, and EFAULT is returned if any of them fails to open.
  • References: shadPS4 file_system.cpp (sceKernelReadv/Writev = posix call + ErrnoToSceKernelError) and prosper hle_file.cpp (k_readv/k_writev/k_preadv/k_pwritev = posix call + SCE error). Both loop per iovec on their own file layer, and neither checks iovcnt before looping. fpPS4 sys_fd.pas has count > IOV_MAX → EINVAL. The host syscall gives the kernel's all-or-nothing semantics, which the per-iovec loops only approximate.
  • Windows: the four exports throw (there is no host readv). They are listed in TechnicalDebt (Functional).

Tested

Linux (GCC Release + Clang dev build). New guest_file_vector test (registered in ctest, non-Windows like guest_directory_entries):

  • readv scatters into two buffers and advances the offset, then returns a short count at EOF and 0 past it.
  • preadv/pwritev work at an offset and leave the file offset unchanged. writev gathers at the current offset, and the file contents are checked.
  • Covers zero-length and iovcnt == 0 calls, EINVAL for iovcnt -1/1025 and a negative offset, EFAULT for a null array, and EBADF after close.

The test fails on main, where the symbols don't exist and it doesn't link. Negative checks: dropping the IOV_MAX check, the null check or the errno mapping, truncating iovcnt, or ignoring the offset each make the test fail. The explicit iovcnt < 0 and negative-offset checks match what the Linux host returns anyway.

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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4754593684 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/806). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-06T05:34:15Z. --- ### What Adds the libkernel vectored I/O exports `sceKernelReadv`, `sceKernelWritev`, `sceKernelPreadv` and `sceKernelPwritev`. Main does not declare them. - Guest `SceKernelIovec` is `{ void* base; size_t length; }`, laid out like the host `struct iovec` on Linux x86-64 (static_asserts). The array goes straight to the host `readv`/`writev`/`preadv`/`pwritev`. Layout from SharpProspero (`KernelFile.cs`, `SceKernelIovec`) and shadPS4 (`OrbisKernelIovec`). - Contract: these are the FreeBSD syscalls. `iovcnt` below 0 or above `UIO_MAXIOV` (1024) gives `EINVAL` (FreeBSD `copyinuio`), a null array with `iovcnt != 0` gives `EFAULT`, and a negative offset in `preadv`/`pwritev` gives `EINVAL`. These checks run before the host call, as main's `sceKernelPread` does. Host errors use the same errno → `0x8002xxxx` mapping as `sceKernelPread`/`sceKernelPwrite`. `preadv`/`pwritev` leave the file offset unchanged. - Read buffers are opened through `GuestArena::HostWrite` like `sceKernelPread`, and `EFAULT` is returned if any of them fails to open. - References: shadPS4 `file_system.cpp` (`sceKernelReadv`/`Writev` = posix call + `ErrnoToSceKernelError`) and prosper `hle_file.cpp` (`k_readv`/`k_writev`/`k_preadv`/`k_pwritev` = posix call + SCE error). Both loop per iovec on their own file layer, and neither checks `iovcnt` before looping. fpPS4 `sys_fd.pas` has `count > IOV_MAX` → `EINVAL`. The host syscall gives the kernel's all-or-nothing semantics, which the per-iovec loops only approximate. - Windows: the four exports throw (there is no host `readv`). They are listed in TechnicalDebt (Functional). ### Tested Linux (GCC Release + Clang dev build). New `guest_file_vector` test (registered in ctest, non-Windows like `guest_directory_entries`): - `readv` scatters into two buffers and advances the offset, then returns a short count at EOF and 0 past it. - `preadv`/`pwritev` work at an offset and leave the file offset unchanged. `writev` gathers at the current offset, and the file contents are checked. - Covers zero-length and `iovcnt == 0` calls, `EINVAL` for `iovcnt` -1/1025 and a negative offset, `EFAULT` for a null array, and `EBADF` after close. The test fails on `main`, where the symbols don't exist and it doesn't link. Negative checks: dropping the `IOV_MAX` check, the null check or the errno mapping, truncating `iovcnt`, or ignoring the offset each make the test fail. The explicit `iovcnt < 0` and negative-offset checks match what the Linux host returns anyway. ### 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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-06 05:47:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-06T05:47:32Z.


Progress report (f55a22e → ab98cd7)

📈 System libraries: 82.33% (+0.02%, +4 implemented functions)

✅ 4 implemented
Library Name
libkernel sceKernelPreadv
libkernel sceKernelPwritev
libkernel sceKernelReadv
libkernel sceKernelWritev
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6010209522 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/806#issuecomment-6010209522). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-06T05:47:32Z. --- <!-- progress-report --> ### Progress report (f55a22e → ab98cd7) 📈 **System libraries**: 82.33% (+0.02%, +4 implemented functions) <details> <summary>✅ 4 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelPreadv` | | libkernel | `sceKernelPwritev` | | libkernel | `sceKernelReadv` | | libkernel | `sceKernelWritev` | </details>
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!806
No description provided.