Repository navigation
fix(libkernel): answer read, write, lseek, fsync and flock on a kqueue descriptor as FreeBSD does - #10014
Conversation
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed exact head b01e5ae against current main 9d6adeb. 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.
|
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.
|
jotitadev
left a comment
There was a problem hiding this comment.
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. Head b01e5ae181. main does not build on macOS, so the platform is #8658 (feat/macos-port) @ fa063d8b07 with 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_kqueue |
guest_kernel_sys |
|
|---|---|---|
| #8658 alone | pass | pass |
| #8658 + this PR's test only | 3/3 abort (SIGABRT) | – |
| #8658 + this PR | 5/5 pass | 5/5 pass |
So the new KqueueDescriptorOperations case 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.
…e descriptor as FreeBSD does A kqueue's file operations (kern_event.c kqueueops) refuse read and write with EOPNOTSUPP through invfo_rdwr, and a kqueue is not seekable, has no vnode for fsync, and is refused by flock. The host placeholder behind a kqueue descriptor is a null device on every host, so read returned end of file, write EBADF, lseek 0, fsync EBADF and flock 0. These calls now fail with EOPNOTSUPP, EOPNOTSUPP, ESPIPE, EINVAL (fsync and fdatasync) and EOPNOTSUPP. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
b01e5ae to
5ba5164
Compare
|
Tested head
One case now differs from 11.4: a zero-length read. For the follow-up the description mentions (vector and positioned calls), here is what they do today on a kqueue, where 11.4 gives:
AI-assisted: yes (Claude Code); results above were run on this machine. |
FreeBSD 11.4 dofileread returns 0 for uio_resid == 0 before it calls fo_read, so read(kq, buf, 0) is 0 and only a non-empty read reaches the kqueue's EOPNOTSUPP. dofilewrite has no such shortcut, so a zero-length write stays EOPNOTSUPP. guest_kqueue gets both cases. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Re-tested AI-assisted: yes (Claude Code); results above were run on this machine. |
|
Merged AI-assisted (Claude Code). |
…r the merge of main Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Merged
Tested on the exact head
Could you take another look at the new head? AI-assisted (Claude Code). |
The staging buffer was sized by the guest's nevents, so a request for INT_MAX events allocated about 64 GiB before the queue reported how many were pending. It's now bounded at 1024 events; kevent may return fewer than requested, and events left in the queue come back on the next call. The test covers an INT_MAX request and a 1030-event queue, and moves away from the end of StandardInput and the start of main, where #9575 and #10014 also add tests.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Merged Tested on Windows 10 Pro (19045), WinLibs GCC 15.2.0 r7, Release, head
This head merges cleanly with AI-assisted (Claude Code). |
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 feat: macOS host support (Apple Silicon via Rosetta 2, Vulkan on MoltenVK) #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