Repository navigation
fix(libkernel): report EINVAL for getdirentries on a non-directory - #7152
Conversation
sceKernelGetdirentries on a descriptor that is not a directory returned ENOTDIR from the host getdents64 on Linux, and ENOTDIR for every descriptor missing from the directory table on Windows, including invalid ones. FreeBSD 11.4's kern_getdirentries returns EINVAL when the vnode is not a directory. Return EINVAL for a regular file on both hosts and EBADF for an invalid descriptor on Windows. Test getdents and getdirentries on a regular file and list the pipe case, which still fails with ESPIPE on Linux, in the library's technical debt file. Written with AI assistance (Claude). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Full CI on 9dc6542 (run 39039630866): Linux passes, but Windows fails 2 existing tests that still expect the old errors. Both abort with 0xc0000409 at a
Both pass on main 47a266c. The new errors look right to us ( |
…ests guest_directory_close expected ENOTDIR from getdents on a descriptor number reused by a regular file, and guest_directory_buffer expected ENOTDIR for descriptor -1. kern_getdirentries returns EINVAL for a vnode that is not a directory and getvnode returns EBADF for a descriptor that is not open, which is what sceKernelGetdirentries now reports on Windows. Written with AI assistance (Claude). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Updated both expectations in b808658: Windows 11, MinGW-w64 GCC 15.2.0 UCRT, full build with no failures: 🤖 Addressed by Claude Code |
…inux The Linux path mapped ENOTDIR from getdents64 to EINVAL, but a pipe or FIFO still failed with ESPIPE from the lseek that reads the base offset first. FreeBSD 11.4's kern_getdirentries returns EINVAL for any descriptor that is not a directory vnode, pipes included, and EBADF for one that is not open. Check the descriptor with fstat before the lseek: EBADF and other host errors are passed through, and anything that is not a directory returns EINVAL. The getdents64 error line is unchanged again, and the technical debt entry is removed since no difference is left. Written with AI assistance (Claude). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jotitadev
left a comment
There was a problem hiding this comment.
Linux run of the fstat path, since the description notes it was not compiled or run locally (and CI skipped the Linux job on this head).
Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, full build.
Head d915e5835 merged onto main 5de7a46e0 (clean merge).
guest_filesystempasses, so on LinuxsceKernelGetdentson a regular file returns0x80020016andgetdents/getdirentriesreturn -1 with errno 22. The other directory and filesystem tests (ctest -R "filesystem|directory|getdents|dirent", 6 tests) also pass.GuestFilesystem.cpponly, onmain:guest_filesystemaborts, so the new checks cover the Linux change too.- Non-GPU suite (
ctest -E "^agc|gpu|vulkan|video_out"): 697/697, same asmain.
guest_directory_close and guest_directory_buffer are only registered on Windows, so the two updated expectations are not exercised here.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Upstream (boykopovar#7152) made getdents and getdirentries refuse a plain file with EINVAL, and guest_filesystem now checks it. The macOS implementation is separate from Linux's and reached openat(fd, "."), which fails with ENOTDIR and aborted the test. It now checks that the descriptor is a directory first, as the Linux branch does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream (boykopovar#7152) made getdents and getdirentries refuse a plain file with EINVAL, and guest_filesystem now checks it. The macOS implementation is separate from Linux's and reached openat(fd, "."), which fails with ENOTDIR and aborted the test. It now checks that the descriptor is a directory first, as the Linux branch does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 47ba2ef)
Upstream (boykopovar#7152) made getdents and getdirentries refuse a plain file with EINVAL, and guest_filesystem now checks it. The macOS implementation is separate from Linux's and reached openat(fd, "."), which fails with ENOTDIR and aborted the test. It now checks that the descriptor is a directory first, as the Linux branch does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
getdirentriesandgetdentson a descriptor that is not a directory returnedENOTDIR: from the hostgetdents64on Linux, and for every descriptor missing from the directory table on Windows, invalid ones included. FreeBSD 11.4'skern_getdirentries(vfs_syscalls.c) returnsEINVALwhen the vnode is not a directory, andEBADFfor a descriptor that is not open.fstatbefore thelseekthat reads the base offset. A host error such asEBADFis passed through, and anything that is not a directory (regular file, pipe, FIFO, device) returnsEINVAL. Thegetdents64error line is unchanged.EBADFwhen_get_osfhandlerejects it andEINVALotherwise. Every guest descriptor kind (files, sockets, kqueues,/dev/random, shared memory) holds a CRT descriptor, so a valid non-directory descriptor getsEINVAL.With the
fstatcheck a pipe no longer fails withESPIPEon Linux, so no difference is left to list in the technical debt. The macOSgetdirentries64path proposed in #6222 is not covered. Not measured on a console.Tested
guest_filesystem,guest_directory_closeandguest_directory_bufferpass (the new checks:sceKernelGetdents,getdentsandgetdirentrieson a regular file return0x80020016/ -1 witherrno22; the two Windows directory tests now expectEINVALandEBADF), and the non-GPU suite passes 733/733.python3 tools/check_conventions.py --base origin/main: passed.fstatcheck) was not compiled here. The same new checks run there; no test opens a pipe.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code