Skip to content

fix(libkernel): return EFAULT from sceKernelRead and sceKernelWrite for a null buffer - #7025

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/kernel-read-write-null
Oct 17, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/kernel-read-write-null

Conversation

@milescoviello

@milescoviello milescoviello commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What

sceKernelRead and sceKernelWrite threw std::invalid_argument for a null buffer, even with a byte count of 0. The POSIX read, _read, write and _write in Stdio.cpp already handle a null buffer: a non-zero count fails with EFAULT, and a zero count is treated as an empty buffer, so the descriptor is still checked.

The sceKernel entry points now do the same: 0x8002000e for a null buffer with a non-zero count, otherwise a zero-length transfer on the descriptor (0, or 0x80020009 for a descriptor that isn't open). The guest socket path is unchanged.

This is the same approximation the POSIX wrappers use. FreeBSD looks the descriptor up first and fails with EFAULT only when it copies through the buffer. So on a closed descriptor it reports EBADF, and a read at end of file returns 0.

I don't know of a title that hits this. I found it while going through the argument throws in libkernel.

Tested

Ubuntu 24.04, GCC 13.3, Release, on main 6a32550.

Not checked: macOS, a console.

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: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

… null buffer

read and write already fail with EFAULT for a null buffer and a
non-zero length and treat a zero-length null buffer as empty. The
sceKernel entry points threw std::invalid_argument for both. They now
do the same as read and write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libkernel/File/src/Open.cpp
PR 6044 core/libs/tests/GuestPosixScalarIo.cpp

@screamm

screamm commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Windows cross-validation of the whole series (stacked on main 5f61879) is in #7023 (comment): this PR's test passes 3/3, and with only this PR's source reverted it fails with main's throw. Suite, conventions and two title runs show no regression.

Written with Claude Code assistance (validation by a subagent, reviewed in this session).

@oneandonlydean oneandonlydean self-assigned this Oct 17, 2026
@oneandonlydean
oneandonlydean merged commit de056cf into boykopovar:main Oct 17, 2026
10 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.

3 participants