Skip to content

fix(libkernel): return errors from pread instead of aborting - #4719

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
gjonn:fix/pread-posix-errors
Oct 14, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
gjonn:fix/pread-posix-errors

Conversation

@gjonn

@gjonn gjonn commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

What

The POSIX pread export threw on a null buffer, a negative offset and any failed host read, which terminates the process. It now returns -1 and sets the guest errno exactly like pwrite and sceKernelPread on main: EFAULT for a null buffer with a non-zero length, EINVAL for a negative offset, and the mapped host error otherwise (EBADF for an invalid or write-only descriptor).

PPSA01317 stops on its first boot on Windows when a read from its save folder fails, at:

terminate called after throwing an instance of 'std::runtime_error'
  what():  pread_nid_postfix: pread failed, fd=..., errno=...

Tested

Windows 11, MinGW, guest_file_vector adds pread/pwrite checks for a null buffer, a negative offset, descriptor 9999 and a write-only descriptor.

On main:

terminate called after throwing an instance of 'std::invalid_argument'
  what():  pread_nid_postfix: invalid argument
1/1 Test #869: guest_file_vector ................Exit code 0xc0000409***Exception

With the argument checks skipped, the invalid descriptor check on main stops at:

terminate called after throwing an instance of 'std::runtime_error'
  what():  pread_nid_postfix: pread failed, fd=9999, errno=9

With this change:

1/1 Test #869: guest_file_vector ................   Passed    0.05 sec
100% tests passed, 0 tests failed out of 1

guest_aio and guest_shm_open also pass.

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 under Silent stubs in their library's technical debt file
  • 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
  • Unblocks: PPSA01317 Gran Turismo 7 (PPSA01317) #4697
  • AI-assisted: yes

@nicolasfalesy

Copy link
Copy Markdown
Contributor

Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto main 7e181fc together with #4725, #4719, #4585 and #4582 (no conflicts): guest_file_vector passes. With this PR's source change reverted (test kept), it fails on Linux, so the check guards the change on Linux too.

The POSIX pread export threw on a null buffer, a negative offset and
any host read failure, so a refused read terminated the process.
Return -1 and set the guest errno the same way pwrite and
sceKernelPread already do.
@adriadam10

Copy link
Copy Markdown
Collaborator

Rebased onto current main (the partial EBADF handling in pread_nid_postfix overlapped this rewrite; kept this PR's version). guest_file_vector fails without the Stdio.cpp change and passes with it; scoped ctest (libs, libc, libkernel, 217 tests) is green on the rebase; merging once the full build is green.

@adriadam10
adriadam10 force-pushed the fix/pread-posix-errors branch from e8c27ad to 8f39438 Compare October 13, 2026 15:15
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
@oneandonlydean
oneandonlydean merged commit 90d0cb4 into boykopovar:main Oct 14, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants