fix(libkernel): handle FIOCLEX and FIONCLEX in ioctl #4505
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4505"
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 milescoviello on 2026-10-12T13:47:49Z.
What
ioctl()on a file, directory, pipe or character device threwioctl: request 0x20006601 on a file is not implementedforFIOCLEX(and the same forFIONCLEX), although the close-on-exec flag those requests change is already kept for these descriptors and reported byfcntl(F_GETFD).FreeBSD 11.4 handles both requests in
kern_ioctl()for every descriptor, before the request reaches the file's own ioctl, by changing the flagF_GETFDreads (sys/kern/sys_generic.c):and
kern_fcntl()(sys/kern/kern_descrip.c):td->td_retval[0] = (fde->fde_flags & UF_EXCLOSE) ? FD_CLOEXEC : 0;.Both requests now set or clear that flag and return 0; the TechnicalDebt entry for
ioctllists them. libuv up to 1.43 sets close-on-exec this way on FreeBSD (uv__cloexecisuv__cloexec_ioctlthere), next to theFIONBIOcalls already handled. Guest sockets are unchanged: they do not keep a close-on-exec flag (F_GETFDfails withEINVALon them).Tested
Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on
mainc6efe068.guest_kernel_fcntlnow sets and clears the flag withFIOCLEX/FIONCLEXon a file and on both ends of a pipe and reads it back withF_GETFD.DescriptorControl.cppthe test aborts withioctl: request 0x20006601 on a file is not implemented, fd=6.guest_kernel_fcntlpasses, also in 300 repeated runs; allguest_*tests exceptguest_video_out_*pass (306/306, three runs).Not tested on Windows; the change does not depend on the host.
Note: my #4480 edits the
fcntlentry right above theioctlone indocs/dev/debt/libkernel.md, so whichever of the two lands second needs a one-line rebase there; the code files merge cleanly. Both are rebased onto the per-library debt files from #4411.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T15:32:24Z.
Review: COMMENTED
Built and run on this host (CachyOS, GCC 16.2.1 — not your Ubuntu 24.04 / GCC 13.3, so this is a cross-compiler reproduction of the same Red/Green states rather than a config-identical rerun). Head
089d559ee, parentc6efe068a, checked out in a worktree: at the headguest_kernel_fcntlreports100% tests passed out of 1and a direct run exits 0; with the parent'sDescriptorControl.cppand the head's test file it aborts with the old throw —ioctl: request 0x20006601 on a file is not implemented, fd=5here,fd=6in your own red line, so the descriptor number is harness-dependent rather than part of the text.Three things a run cannot show:
sys/sys/filio.h:44-45definesFIOCLEX _IO('f', 1)andFIONCLEX _IO('f', 2), which evaluate to0x20006601/0x20006602— the values added here.Socket/src/Udp.cppforwards anything below the guest socket range toFile::Ioctl—if (descriptor < GuestSockets::FirstDescriptor) return File::Ioctl(descriptor, request, argument);— descriptors are minted from0x10000000upward, anddup/dup2throw rather than cross that boundary. So a socket never reaches the new branch and keeps itsFIONBIO/FIONREADpath withENOTTYfor everything else.SetCloseOnExecalready exists onmain(File/src/DescriptorControl.cpp:314; 316 at this head —Materialize(fd).closeOnExec = valueunder the file's mutex), andfcntl(F_GETFD)already materialises an unseen descriptor the same way. So the branch adds a new writer of existing state rather than new state, and the only consumer of that flag anywhere in the tree isF_GETFD.Coverage note, informational: the added assertions cover a file — both requests, with
F_GETFDreadback — and one request on each pipe end, while the body says the throw appeared on a file, directory, pipe or character device.Directory,DeviceandRandomDeviceall resolve throughClassifybefore the new branch, so they follow from the branch's position; the test just does not pin them.Written with AI assistance.
Hermes Agent 🤖 at your service
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T15:33:26Z.
Windows test of head
089d559eemerged onto currentmain(d592d54e1, clean merge; built together with two other open PRs, so the run is for the combination): Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build 0 errors,-j2.guest_kernel_fcntl(the test this PR changes) passes, withguest_dup,guest_polland the socket tests. The 22 tests matchingguest_udp|guest_kernel_fcntl|guest_time_conversion|guest_ioctl|guest_socket|guest_dup|guest_pollall pass.Not checked: that the test fails without the change, Linux, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T17:46:15Z.
Windows was the half this change needed, and I could not build it here. The three facts in my review — the FreeBSD
filio.hconstants, the socket-range forwarding, andSetCloseOnExecbeing existing state — were all read from source, so your run at the same head (089d559ee) is the first evidence the branch compiles and passes on its target.What is still open on that side, both cheap while the tree is up:
DescriptorControl.cpp— on this host it aborts with the old throw (ioctl: request 0x20006601 on a file is not implemented, fd=5) — is what separates "the branch is correct" from "the branch is compiled".Directory,DeviceandRandomDeviceall resolve throughClassifybefore the new branch, so they follow from its position — the test just does not pin them.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:22:41Z.
Closing: no title is shown to send
FIOCLEXorFIONCLEX. Main throwsioctl: request 0x20006601 on a file is not implementedthere, so reopen with the title ID and that line when one does.Pull request closed