Skip to content

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

Closed
erick-dsnk wants to merge 4 commits into
boykopovar:mainfrom
erick-dsnk:fix/kernel-file-guest-errors
Closed

erick-dsnk wants to merge 4 commits into
boykopovar:mainfrom
erick-dsnk:fix/kernel-file-guest-errors

Conversation

@erick-dsnk

@erick-dsnk erick-dsnk commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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

@rmz-24

rmz-24 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Windows results for 757cadf: 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 (3bd74c1) 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

Copy link
Copy Markdown
Collaborator

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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 9, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 9, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 10, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

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

@github-actions

Copy link
Copy Markdown

Progress report (32064d3 → c6f88c3)

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

⚠️ 1 went back to stubs
Library Name
libkernel sceKernelLseek

@Mouhand-Kaddo

Copy link
Copy Markdown
Contributor

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 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs libkernel needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants