fix(libkernel): answer read, write, lseek, fsync and flock on a kqueue descriptor as FreeBSD does #10014
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10014"
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?
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-23T04:03:27Z.
What
sceKernelRead,sceKernelWrite,sceKernelLseek,sceKernelFsync,sceKernelFdatasyncandflocknow fail on a kqueue descriptor withEOPNOTSUPP,EOPNOTSUPP,ESPIPE,EINVAL,EINVALandEOPNOTSUPP, using the existingIsKqueueDescriptor.guest_kqueuegets the cases.readv,writev,preadandpwriteon a kqueue descriptor are not changed here.FreeBSD 11.4
kqueueops,invfo_rdwr,kern_fsync,sys_flock; found by comparing the descriptor operations against that source, not from a title. A second commit,8deb85d957, finishes a zero-length read on a kqueue descriptor with 0 instead ofEOPNOTSUPP: FreeBSD 11.4'sdofilereadreturns 0 foruio_resid == 0before it callsfo_read(sys_generic.c:367, "Finish zero length reads right here"), so only a non-empty read reaches the kqueue'sEOPNOTSUPP.dofilewritehas no such shortcut, so a zero-length write staysEOPNOTSUPP.guest_kqueuegets both cases.Fixes: #10013
Tested
Head
5ba5164c72, rebased ontomainbd8e13428a;git merge-treeagainst currentmaine7e3e9c198is clean. The diff is 3 files, +22/-4:Open.cpp+3/-1,Stdio.cpp+3/-3 andGuestKqueue.cpp+16. The rebase dropped exactly one hunk of the earlier headb01e5ae181: the local declarations oflseek_nid_postfix,fsync_nid_postfix,fdatasync_nid_postfixandflock_nid_postfixinGuestKqueue.cpp, whichmainnow declares in the library headers. The other hunks are unchanged.mainbd8e13428awith this head (ninja exit code 0):guest_kqueuepasses 3 of 3 runs.Open.cppandStdio.cpp(both taken frommain, same build directory, test kept; ninja exit code 0):guest_kqueuefails 3 of 3 runs with exit code 0xc0000409.file|posix|shm|kqueue|equeue|pipe|truncate|lseek|flock|fsync|vector|socket_read|dup|fcntl|descriptor|stdio|aio|kernel_syshas 153 tests onmainnow (the earlier description named 112); with this head 151 pass and 2 are skipped (the named shared memory testsguest_named_shm_windows_short_tempandguest_named_shm_windows_long_short_temp, which skip in this configuration); ctest reports100% tests passed, 0 tests failed out of 153, counting the skips as passed.check_conventions --base upstream/mainpasses.5ba5164c72merged ontomain9c435c2812,guest_kqueue,guest_kernel_fcntlandguest_filesystempass 3 of 3 on both hosts, andguest_kqueuefails withOpen.cppandStdio.cppfrommain; at the current head8deb85d957merged ontomain504ea3b53b,guest_kqueuepasses 3 of 3 on both hosts and still fails withmain'sOpen.cpp/Stdio.cpp, and a probe gives 0 forsceKernelRead(kq, buf, 0)andread(kq, buf, 0)and0x8002002dforsceKernelWrite(kq, buf, 0). Measured by jotitadev on macOS 27.2 (Apple M2 Max, x86_64 under Rosetta 2, on #8658) at the earlier headb01e5ae181(5ba5164c72only drops four local declarations fromGuestKqueue.cpp; the zero-length-read commit8deb85d957came after and was not run on macOS): the new test aborts 3 of 3 without the fix, andguest_kqueueandguest_kernel_syspass 5 of 5 with it. During development one run ofguest_kqueueright after a rebuild failed 3/3; the cause was not identified. It did not occur in the three runs with this head above; that is all I can say about it.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)AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T04:08:47Z.
Review: APPROVED
Reviewed exact head b01e5ae1815e92e26dda5f3297520a7efc79caad against current main
9d6adeb550. The targeted guards consistently route kqueue descriptors through the requested FreeBSD-compatible errors for read/write, seek, fsync/fdatasync, and flock; the new guest_kqueue case covers each path and closes its descriptor. The code reuses IsKqueueDescriptor and existing error mappings, and the PR explicitly scopes out readv/writev/pread/pwrite. I ran git diff --check and the repository convention check against current main; both pass. I could not run the native guest_kqueue binary in this environment. The reported Windows run and 112-test kernel/file family are author-reported, including the disclosed unexplained initial failure; the hosted product build jobs are skipped by repository policy. I found no blocking issue in the reviewed diff.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-23T05:59:06Z.
Review: COMMENTED
macOS test: Apple M2 Max, macOS 27.2
Apple M2 Max, macOS 27.2, Apple clang (Xcode 27), x86-64 Release build under Rosetta 2,
BUILD_TESTING=ON. Headb01e5ae181.maindoes not build on macOS, so the platform is #8658 (feat/macos-port) @fa063d8b07with this PR's diff applied (clean apply).On macOS the kqueue placeholder is also
/dev/null, so the same calls reach the host device without the change.guest_kqueueguest_kernel_sysSo the new
KqueueDescriptorOperationscase catches the bug on macOS as well, and the fix holds there.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.