feat(libkernel): support fcntl and ioctl on non-socket descriptors #3840
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3840"
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 ahir061 on 2026-10-11T17:42:00Z.
What
Carries screamm's
screamm/AnyPS5:feat/libkernel-fcntl-filesfrom #3757 unchanged, with their authorship (two commits onmaina11c8f7f):70dd0c00feat(libkernel): support fcntl on non-socket descriptors88c9ee8dfeat(libkernel): support ioctl on non-socket descriptorsfcntl,sceKernelFcntl,ioctland_ioctlworked only on libSceNet sockets, so every file, pipe and standard stream gotEBADF. Yamagi Quake II stops on it (Sys_Error: change stdin to blocking Bad file descriptor), and XPSemu, VLC, RetroArch, Porpoise and Ruffle callfcntlon such descriptors (#3757).The new
File/src/DescriptorControl.cppkeeps a close-on-exec flag per descriptor and a status-flag set shared by duplicates, following FreeBSD 11.4kern_fcntl/kern_dup. It coversF_GETFD/F_SETFD,F_GETFL/F_SETFL,F_DUPFD/F_DUPFD_CLOEXEC,F_RDAHEAD/F_READAHEADand record locks on Linux.O_NONBLOCKon a pipe makes empty reads and full writes returnEAGAIN.ioctlanswersFIONBIO,FIONREAD(file size minus offset; queued bytes on a pipe's read end) andENOTTYfor the terminal requests. What it does not model throws with the flag and descriptor kind; #3757 lists the cases. Sockets keep their existing path. Thefcntl,sceKernelFcntlandioctlTechnicalDebt entries are updated.It touches the same
close/dup/pipecode inStdio.cppandOpen.cppas #3649, #3644 and #3681, so whichever merges second needs a rebase; I'll keep this one current.Closes #3757.
Tested
BUILD_TESTING=ON, full build includinglibs:guest_kernel_fcntl,guest_dup,guest_udp,guest_socket_pair,guest_socket_read_write,guest_poll,guest_terminal,guest_file_vector,guest_aio3/3.BUILD_TESTING=ON, head88c9ee8d:guest_kernel_fcntl: record locks through the host's POSIX locks, and clearingO_APPENDon a file.main's libkernel,guest_kernel_fcntlaborts (sceKernelFcntl: file descriptors are not implemented, fd=5) andguest_dupaborts; both pass with these commits.guest_truncateandguest_kernel_stack_protect(#3459) abort the same way on unchangedmainin this environment.guest_raise_exceptionpasses but takes 72 s with these commits and 71 s onmain, over its 30 s timeout only because the test machine has a single core.tools/check_conventions.py --base mainpasses.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 repositoryImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T18:00:29Z.
Code review location:
core/libs/prx/libkernel/Socket/src/Udp.cpp; line 494Could this only read the variadic argument for commands that require one, and read the command’s actual argument type?
F_GETFLandF_GETFDhave no third argument, but the non-socket path always callsva_arghere (and readslongat the POSIX branch below). The new tests callfcntl_nid_postfix(file, GetFlags)without a third argument atGuestKernelFcntl.cpp:102and:175; fetching a missing vararg is undefined behavior. Commands that do take an argument also use different promoted types: flag/descriptor commands passint, while lock commands pass a pointer. A command-specific extraction would avoid both mismatches on Windows and POSIX.Imported from boykopovar/AnyPS5. Originally posted by ahir061 on 2026-10-11T18:13:02Z.
Code review location:
core/libs/prx/libkernel/Socket/src/Udp.cpp; line 494Good catch, thanks. Fixed in the latest commit: File::FcntlArgumentOf maps each command to no argument, an int or a pointer, and fcntl and sceKernelFcntl now read only that. F_GETFD, F_GETFL, F_GETOWN and unknown commands read nothing; the flag, descriptor and read-ahead commands read an int; the lock commands read a pointer.
It also fixed a real case: F_READAHEAD with -1 was read as 4294967295 and enabled read-ahead. guest_kernel_fcntl now checks -1 and 4096 through both entry points; it fails before this commit and passes after (Linux, GCC 13.3). The nine related tests pass, the changed files compile with MinGW-w64, and screamm’s two commits are unchanged.
Imported from boykopovar/AnyPS5. Originally posted by ahir061 on 2026-10-11T22:28:11Z.
Rebased onto current main (
11d9c00c). Two conflicts: theioctl, _ioctlTechnicalDebt entry next to the newsendfileentry from #3568 (both kept), and the WindowsNativeWriteinOpen.cpp, where main's shared-memory write path and this PR's pipeENOSPC→EAGAINmapping are now combined: shared-memory descriptors go throughWriteSharedMemory_nid_no_patchfirst, everything else through_writewith the pipe mapping. Re-tested on Linux (Ubuntu 24.04, GCC 13.3): the nine fcntl/ioctl tests andguest_ioctl_getsidpass, and 98 of 99 libkernel tests pass (guest_named_shm_concurrencyfails the same way on unchanged main there, because the run is as root). The changed files compile with MinGW-w64, andtools/check_conventions.pypasses.Imported from boykopovar/AnyPS5. Originally posted by ahir061 on 2026-10-12T06:50:43Z.
Rebased again onto current main (
d06c0656). #3968 (openat) moved sceKernelOpen's open path intoOpenNative; the descriptor registration from this PR now sits at the end ofOpenNative, so descriptors opened throughopenatget the samefcntlandioctlhandling, and the random-device branch registers its descriptor as before. Re-tested on Linux: the nine fcntl/ioctl tests,guest_ioctl_getsidandguest_kernel_sys(openat) pass; the changed files compile with MinGW-w64;tools/check_conventions.pypasses.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T06:54:30Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libkernel/CMakeLists.txtL5core/libs/prx/libkernel/File/src/Stdio.cppL14-15, L421, L526core/libs/prx/libkernel/File/src/Open.cppL206core/libs/prx/libkernel/File/src/Stdio.cppL476, L502, L526, L536core/libs/prx/libkernel/File/src/Stdio.cppL457core/libs/prx/libkernel/File/src/Open.cppL205-206, L303-308docs/dev/TechnicalDebt.mdL596-698Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T07:53:27Z.
Title test for the fcntl/ioctl change (this PR; the commits come from screamm's branch in #3757), Windows 10, MinGW GCC, RTX 4080 SUPER: this PR merged locally onto current
maind06c06565(clean merge, no conflicts). Full build with-j4succeeded; thectestsubset matchingfcntl|ioctl|file|open|descriptor|stdio|pipe|dup|kernelran 44 tests: 44 passed (video_out_flip_reopenskipped).PPSA24423 (0 absent imports; stopped on
mainceb342b94atsceKernelFcntl: file descriptors are not implemented, fd=6, see #3757): with this change the fcntl abort is gone. The run (150 s limit) then ends after about 70 s with a different abort:So the title gets past
fcntland reaches rendering. I did not look at the picture and one run only.AI-assisted (Claude Code).