fix(kernel): return guest errors from scalar file operations #2144

Closed
erick-dsnk wants to merge 4 commits from upstream-pr/2144 into main
erick-dsnk commented 2026-10-09 09:58:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by erick-dsnk on 2026-10-09T09:58:20Z.


What

Return encoded guest errors from sceKernelRead, sceKernelWrite, and sceKernelLseek for invalid descriptors, buffers, offsets, and whence values. Translate host errno symbols to guest constants so host-specific numbering (including EAGAIN) does not leak into the guest ABI. Zero-length null-buffer operations still reach the native call so invalid descriptors report EBADF.

For sceKernelLseek, whence values outside 0–4 return guest EINVAL. FreeBSD 11 defines 3 and 4 as SEEK_DATA and SEEK_HOLE; these valid modes throw as unsupported because sparse-file seeking is not implemented. The console behavior of those modes is unverified and recorded in TechnicalDebt.

Tested

Linux x86-64: incremental full libs build; guest_file_vector, guest_filesystem, and guest_aio tests passed; conventions check against the PR base passed. The new seek regression failed when tested against the old 0–2 guard and passed after restoring the fix.

Windows 11 results were reported for the previous head 757cadfe; that run does not cover this seek-mode correction. The current head was not runtime-tested on Windows.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-up work goes in a new pull request
  • No comments in code except technical-debt comments
  • Unimplemented paths throw
  • No investigation notes, reports or images added to the repository
  • No third-party code added
  • Generic behavior
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4798890054 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2144). Originally posted by [erick-dsnk](https://github.com/erick-dsnk) on 2026-10-09T09:58:20Z. --- ### What Return encoded guest errors from `sceKernelRead`, `sceKernelWrite`, and `sceKernelLseek` for invalid descriptors, buffers, offsets, and whence values. Translate host errno symbols to guest constants so host-specific numbering (including `EAGAIN`) does not leak into the guest ABI. Zero-length null-buffer operations still reach the native call so invalid descriptors report `EBADF`. For `sceKernelLseek`, whence values outside 0–4 return guest `EINVAL`. FreeBSD 11 defines 3 and 4 as `SEEK_DATA` and `SEEK_HOLE`; these valid modes throw as unsupported because sparse-file seeking is not implemented. The console behavior of those modes is unverified and recorded in TechnicalDebt. ### Tested Linux x86-64: incremental full `libs` build; `guest_file_vector`, `guest_filesystem`, and `guest_aio` tests passed; conventions check against the PR base passed. The new seek regression failed when tested against the old 0–2 guard and passed after restoring the fix. Windows 11 results were reported for the previous head `757cadfe`; that run does not cover this seek-mode correction. The current head was not runtime-tested on Windows. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-up work goes in a new pull request - [x] No comments in code except technical-debt comments - [x] Unimplemented paths throw - [x] No investigation notes, reports or images added to the repository - [x] No third-party code added - [x] Generic behavior - [x] Depends on: none - [x] AI-assisted: yes
rmz-24 commented 2026-10-09 11:49:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-09T11:49:45Z.


Windows results for 757cadfe: Windows 11 Pro 25H2 (10.0.26200.9457), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build plus libs.

  • guest_file_vector passes.
  • All 159 guest_* tests pass.
  • With Open.cpp reset to the base (3bd74c15) and the new test kept, guest_file_vector fails, as it should: sceKernelLseek: invalid whence=3 is thrown at the test's sceKernelLseek(file, 0, 3).

One semantic point on that case. In FreeBSD 11, whence 3 and 4 are valid: SEEK_DATA and SEEK_HOLE (sys/sys/unistd.h), handled by kern_lseek through FIOSEEKDATA/FIOSEEKHOLE (sys/kern/vfs_vnops.c). Returning EINVAL for them makes a supported request look invalid, and the test now asserts that. Keeping the throw for 3 and 4 (or implementing them) and returning EINVAL only for values outside 0-4 would match FreeBSD and the rule that unsupported cases throw. The test could then use, for example, whence = 5 for its EINVAL case.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6080266987 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2144#issuecomment-6080266987). Originally posted by [rmz-24](https://github.com/rmz-24) on 2026-10-09T11:49:45Z. --- Windows results for 757cadfe: Windows 11 Pro 25H2 (10.0.26200.9457), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build plus `libs`. - `guest_file_vector` passes. - All 159 `guest_*` tests pass. - With `Open.cpp` reset to the base (3bd74c15) and the new test kept, `guest_file_vector` fails, as it should: `sceKernelLseek: invalid whence=3` is thrown at the test's `sceKernelLseek(file, 0, 3)`. One semantic point on that case. In FreeBSD 11, `whence` 3 and 4 are valid: `SEEK_DATA` and `SEEK_HOLE` (`sys/sys/unistd.h`), handled by `kern_lseek` through `FIOSEEKDATA`/`FIOSEEKHOLE` (`sys/kern/vfs_vnops.c`). Returning `EINVAL` for them makes a supported request look invalid, and the test now asserts that. Keeping the throw for 3 and 4 (or implementing them) and returning `EINVAL` only for values outside 0-4 would match FreeBSD and the rule that unsupported cases throw. The test could then use, for example, `whence = 5` for its `EINVAL` case. AI-assisted: yes
oneandonlydean commented 2026-10-09 20:15:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:15:06Z.


Which title hits one of the read/write/lseek throws on main? Please add the title ID and the log line; that's what makes this change of behaviour needed. Separately, NativeRead/NativeWrite (Open.cpp:31-54) now return EINVAL above INT_MAX bytes; that's a Windows host limit, not something the console reports, so keep the throw there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088515911 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2144#issuecomment-6088515911). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:15:06Z. --- Which title hits one of the read/write/lseek throws on main? Please add the title ID and the log line; that's what makes this change of behaviour needed. Separately, `NativeRead`/`NativeWrite` (`Open.cpp:31-54`) now return EINVAL above INT_MAX bytes; that's a Windows host limit, not something the console reports, so keep the throw there.
oneandonlydean commented 2026-10-10 05:17:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:17:56Z.


Which title hits one of the read/write/lseek throws on main? That question is still open. Please also rebase instead of merging main (c6f88c39); it conflicts in Open.cpp again.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094138465 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2144#issuecomment-6094138465). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T05:17:56Z. --- Which title hits one of the read/write/lseek throws on main? That question is still open. Please also rebase instead of merging main (c6f88c39); it conflicts in `Open.cpp` again.
github-actions[bot] commented 2026-10-10 08:01:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T08:01:55Z.


Progress report (32064d3 → c6f88c3)

📉 System libraries: 85.65% (-0.04%, -1 reverted functions)

⚠️ 1 went back to stubs
Library Name
libkernel sceKernelLseek
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095444318 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2144#issuecomment-6095444318). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T08:01:55Z. --- <!-- progress-report --> ### Progress report (32064d3 → c6f88c3) 📉 **System libraries**: 85.65% (-0.04%, -1 reverted functions) <details> <summary>⚠️ 1 went back to stubs</summary> | Library | Name | | - | - | | libkernel | `sceKernelLseek` | </details>
Mouhand-Kaddo commented 2026-10-10 10:05:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T10:05:28Z.


Additional platform validation on standalone PR head c6f88c391556eaff4fc9072b6f41be441cb1e79d:

Windows: passed — Windows 11, supported WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; CMake 4.3.1 / Ninja.

Release / BUILD_TESTING=ON: built the selected test targets; 3 CTest cases, 0 failures, 0 CTest skips.

Tests: guest_filesystem, guest_aio, guest_file_vector.

Reproduce after building the test targets: ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^guest_(file_vector|filesystem|aio)$".

Integration limitation: a local merge against main 948a526c2 has source conflicts; these results validate the standalone PR head, not a resolved merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096396974 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2144#issuecomment-6096396974). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-10T10:05:28Z. --- <!-- anyps5-platform-validation:c6f88c391556eaff4fc9072b6f41be441cb1e79d --> Additional platform validation on standalone PR head `c6f88c391556eaff4fc9072b6f41be441cb1e79d`: **Windows: passed** — Windows 11, supported WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; CMake 4.3.1 / Ninja. Release / `BUILD_TESTING=ON`: built the selected test targets; 3 CTest cases, 0 failures, 0 CTest skips. Tests: `guest_filesystem`, `guest_aio`, `guest_file_vector`. Reproduce after building the test targets: `ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^guest_(file_vector|filesystem|aio)$"`. Integration limitation: a local merge against main `948a526c2` has source conflicts; these results validate the standalone PR head, not a resolved merge.
adriadam10 commented 2026-10-10 23:59:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:59:01Z.

Review: CHANGES_REQUESTED


Thanks for the work and the Windows runs. Before this can land:

  • oneandonlydean asked twice (2026-10-09, 2026-10-10) which title hits one of the sceKernelRead/sceKernelWrite/sceKernelLseek throws on main; please add the title ID and the log line. This is a behaviour change (throw → error return) and needs that evidence.
  • The PR conflicts with main in core/libs/prx/libkernel/File/src/Open.cpp. Please rebase instead of merging main (drop c6f88c39); PRs must not contain merge commits.
  • SceErrorFromErrno (Open.cpp:152) maps every unlisted errno to EIO. That is a plausible but unverified result where main threw; either list only errnos the console is known to return and throw for the rest, or cite the source for the fallback.
  • The progress report flags sceKernelLseek as reverted to a stub (whence 3/4 throw). Keep it counted by implementing SEEK_DATA/SEEK_HOLE, or say in the PR why the regression is intended.
  • docs/dev/TechnicalDebt.md:264 is the line you add; after rebasing, keep it away from the end of its section to avoid adjacency conflicts.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5481254220 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2144#pullrequestreview-5481254220). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T23:59:01Z. **Review:** CHANGES_REQUESTED --- Thanks for the work and the Windows runs. Before this can land: - `oneandonlydean` asked twice (2026-10-09, 2026-10-10) which title hits one of the `sceKernelRead`/`sceKernelWrite`/`sceKernelLseek` throws on `main`; please add the title ID and the log line. This is a behaviour change (throw → error return) and needs that evidence. - The PR conflicts with `main` in `core/libs/prx/libkernel/File/src/Open.cpp`. Please rebase instead of merging `main` (drop `c6f88c39`); PRs must not contain merge commits. - `SceErrorFromErrno` (`Open.cpp:152`) maps every unlisted errno to `EIO`. That is a plausible but unverified result where `main` threw; either list only errnos the console is known to return and throw for the rest, or cite the source for the fallback. - The progress report flags `sceKernelLseek` as reverted to a stub (whence 3/4 throw). Keep it counted by implementing `SEEK_DATA`/`SEEK_HOLE`, or say in the PR why the regression is intended. - `docs/dev/TechnicalDebt.md:264` is the line you add; after rebasing, keep it away from the end of its section to avoid adjacency conflicts.
oneandonlydean commented 2026-10-13 08:05:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T08:05:14Z.


Closing: main already returns the guest error from sceKernelRead, sceKernelWrite and sceKernelLseek when the host call fails (#1307, ce0239c94), and the points from 10-10 are still open. If a title still reaches the null-buffer or whence throws on main, please reopen rebased with its ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141140256 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2144#issuecomment-6141140256). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T08:05:14Z. --- Closing: main already returns the guest error from `sceKernelRead`, `sceKernelWrite` and `sceKernelLseek` when the host call fails (#1307, `ce0239c94`), and the points from 10-10 are still open. If a title still reaches the null-buffer or whence throws on main, please reopen rebased with its ID and the log line.

Pull request closed

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!2144
No description provided.