kernel: return -1 and errno from POSIX open, close, write and unlink #1207
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1207
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1207/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Nawid3333 on GitHub · 2026-10-08 12:03 UTC · original
Nawid3333:kernel/posix-file-exports→main· +79 −5 · 2 files · 1 commits · closed without mergingProblem
Guest code that calls the POSIX
open,close,writeorunlinkexported by libkernel gets SCEerror codes back instead of -1 and errno. For example
open("/savedata0/missing.dat", O_RDONLY)returns 0x80020002 and leaves errno alone, so a caller that checks for -1 takes the error code for a
file descriptor, and code that looks at errno (
ENOENT→ create the file) never sees it._write()on a negative descriptor, for example the -1 from a failed_open(), ends the emulatorwith "Not implemented (d < 0)".
Cause
InitLibKernel_1_Pthreadbinds the NIDs of the plain POSIX names straight to the sceKernelfunctions:
wuCroIGjt2gopenFileSystem::KernelOpenbY-PO6JhzhQcloseFileSystem::KernelCloseFN4gaPmuFV8writeFileSystem::KernelWriteVAzswvTOCzIunlinkFileSystem::KernelUnlinkThose return SCE error codes and don't set errno. The same file already has POSIX wrappers for
_open,_closeand_write.LibKernel::write(_write) starts withEXIT_NOT_IMPLEMENTED(d < 0), whilecloseandreadreturn -1 with EBADF.Fix
openandcloseNIDs point at the same functions as_openand_close.Posix::unlink(POSIX_CALLaroundKernelUnlink) andPosix::write(POSIX_N_CALLaroundKernelWrite).writedoesn't reuse_write's function because that one returns the size fordescriptors 0-2 without writing anything. The
writeexport printed guest stdout/stderr throughKernelWritebefore this change and still does._write()on a negative descriptor returns -1 with EBADF, asclose()does.Success results don't change. One other visible difference:
close()on descriptors 0-2 now returns0, like
_close(), instead of an SCE EPERM code.Testing
New
TestPosixFileExportsinkernel_file_system: through the export NIDs,openandunlinkof amissing file return -1/ENOENT,
close(-1),write(-1)and_write(-1)return -1/EBADF, andopen/write/close/unlink of a new file return the descriptor, the byte count and 0, with
closeandwriteon the closed descriptor returning -1/EBADF.main3c62359e: without the fix the test stops atPOSIX open returns -1 and ENOENT for a missing file; with it, all new checks pass and the binarygoes on to the existing
Net unknown socket options return protocol-option errorscheck, which failson Windows until #1159 is merged.
libKernel.cppcompiles on allthree, but it doesn't build or run
kernel_file_system.AI use (per the README's AI policy): Claude (Anthropic) found these bindings while scanning the kernel exports for small fixes, wrote the change and the test, and ran the tests above on my machine.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-08 12:07 UTC · original
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
53dd1d14-b5c0-4c50-a8dd-65f85b2c0423📥 Commits
Reviewing files that changed from the base of the PR and between
3c62359e05and8a55299810.📒 Files selected for processing (2)
src/libs/libKernel.cpptests/KernelFileSystemTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.
📝 Walkthrough
Walkthrough
The change adds POSIX
unlinkandwritewrappers and routes the related file API exports through library wrappers. Negative descriptors passed toLibKernel::writenow return-1withEBADF. Tests cover error cases and successful file creation, writing, closing, and removal.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
8a552The file exports preserve successful results and return POSIX-style failures as intended. No actionable merge-blocking issue remains.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.Pull request closed