libkernel: fcntl and ioctl reject every non-socket descriptor (Yamagi Quake II, XPSemu, VLC, RetroArch); branch ready #3757

Closed
opened 2026-10-11 16:30:49 +00:00 by screamm · 3 comments
screamm commented 2026-10-11 16:30:49 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-11T16:30:49Z.


fcntl, sceKernelFcntl, ioctl and _ioctl work only on libSceNet sockets; every other descriptor gets EBADF. That is observed in Yamagi Quake II's run log (Sys_Error: change stdin to blocking Bad file descriptor) and, by call-site count in the eboots, XPSemu (PPSA97358, 97 fcntl sites, including QEMU's event notifier which exits on failure), VLC (PPSA85300, 43, F_RDAHEAD on every opened file), RetroArch (17), Porpoise (13) and Ruffle (9) all reach it.

Branch ready: screamm:feat/libkernel-fcntl-files (two commits on main a11c8f7f, head 88c9ee8d: feat(libkernel): support fcntl on non-socket descriptors, feat(libkernel): support ioctl on non-socket descriptors). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commits as they are. It touches the same close/dup/pipe code in Stdio.cpp and Open.cpp as the open #3649, #3644 and #3681, so expect textual conflicts.

  • New File/src/DescriptorControl.cpp keeps a per-descriptor close-on-exec flag and a status-flag set shared by duplicates (FreeBSD's open file description), created by open/pipe/dup/dup2 and forgotten by close; descriptors the table has not seen (0 to 2) start from the host's flags. Following FreeBSD 11.4 kern_descrip.c kern_fcntl/kern_dup, fcntl.h, sys_pipe.c, vfs_vnops.c, sys_generic.c, randomdev.c and devfs_vnops.c (8c639945): F_GETFD/F_SETFD; F_GETFL (host access mode plus flags, via NtQueryObject on Windows) and F_SETFL changing only the settable bits; F_DUPFD/F_DUPFD_CLOEXEC (lowest free descriptor at or above the start, EINVAL for a negative start before EBADF), F_DUP2FD* through dup2; F_RDAHEAD/F_READAHEAD on files; unknown commands EINVAL; record locks through the host's POSIX locks on Linux. O_NONBLOCK on a pipe switches the Windows pipe to non-blocking mode (empty read and full write return EAGAIN) and sets the host flag on Linux; on files, directories and the random device it is only recorded because their reads never block. ioctl: FIONBIO on the same flags, FIONREAD (file size minus offset, queued bytes on a pipe read end, 0 on its write end, ENOTTY on the random device), the terminal 't' group ENOTTY.
  • What throws, naming the flag and descriptor kind: changing O_APPEND on a Windows file, O_FSYNC on a file, O_ASYNC on a pipe or character device (no SIGIO), O_NONBLOCK on a Windows console, F_GETOWN/F_SETOWN/F_SETLK_REMOTE, record locks on Windows or character devices, F_GETLK with F_UNLCK, FIONREAD on a directory or character device, any other ioctl request. Sockets keep the previous path unchanged (they still answer F_GETFD/F_SETFD with EINVAL; XPSemu may call those on sockets, left for a follow-up). The fcntl, sceKernelFcntl and ioctl TechnicalDebt entries are updated.
  • guest_kernel_fcntl covers flag round trips on a file, stdin and both pipe ends, F_DUPFD with a start, the EINVAL cases, EAGAIN on an empty and a full non-blocking pipe, the ioctl cases, the throw messages and the unchanged socket path; guest_dup checks that duplicates share status flags and clear close-on-exec. Known pre-existing gap left alone: readv/writev on a non-blocking pipe report 11 (EDEADLK) instead of EAGAIN through the host error mapping in Stdio.cpp.

Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs: guest_kernel_fcntl, guest_dup, guest_udp, guest_socket_pair, guest_socket_read_write, guest_poll, guest_terminal, guest_file_vector, guest_aio 3/3; ctest -j8 -E "^agc_driver_|^video_out_flip" under heavy host load (five other builds): beyond the known windows_exceptions (#3411, fixed by #3415), guest_kernel_sys (#3510), guest_filesystem (#3518) and the guest_ampr_markers flake (#3371), three timeouts (guest_raise_exception, tls_function_coverage_register_address_loads, guest_pthread_start) that pass when rerun serially; with main's Open.cpp two of the nine tests fail; tools/check_conventions.py --base main and git diff --check pass. Not run on Linux.

Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5802963087 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3757). Originally posted by [screamm](https://github.com/screamm) on 2026-10-11T16:30:49Z. --- `fcntl`, `sceKernelFcntl`, `ioctl` and `_ioctl` work only on libSceNet sockets; every other descriptor gets `EBADF`. That is observed in Yamagi Quake II's run log (`Sys_Error: change stdin to blocking Bad file descriptor`) and, by call-site count in the eboots, XPSemu (PPSA97358, 97 `fcntl` sites, including QEMU's event notifier which exits on failure), VLC (PPSA85300, 43, `F_RDAHEAD` on every opened file), RetroArch (17), Porpoise (13) and Ruffle (9) all reach it. **Branch ready:** [`screamm:feat/libkernel-fcntl-files`](https://github.com/screamm/AnyPS5/tree/feat/libkernel-fcntl-files) (two commits on `main` `a11c8f7f`, head `88c9ee8d`: `feat(libkernel): support fcntl on non-socket descriptors`, `feat(libkernel): support ioctl on non-socket descriptors`). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commits as they are. It touches the same `close`/`dup`/`pipe` code in `Stdio.cpp` and `Open.cpp` as the open #3649, #3644 and #3681, so expect textual conflicts. - New `File/src/DescriptorControl.cpp` keeps a per-descriptor close-on-exec flag and a status-flag set shared by duplicates (FreeBSD's open file description), created by `open`/`pipe`/`dup`/`dup2` and forgotten by `close`; descriptors the table has not seen (0 to 2) start from the host's flags. Following FreeBSD 11.4 `kern_descrip.c` `kern_fcntl`/`kern_dup`, `fcntl.h`, `sys_pipe.c`, `vfs_vnops.c`, `sys_generic.c`, `randomdev.c` and `devfs_vnops.c` (`8c639945`): `F_GETFD`/`F_SETFD`; `F_GETFL` (host access mode plus flags, via `NtQueryObject` on Windows) and `F_SETFL` changing only the settable bits; `F_DUPFD`/`F_DUPFD_CLOEXEC` (lowest free descriptor at or above the start, `EINVAL` for a negative start before `EBADF`), `F_DUP2FD*` through `dup2`; `F_RDAHEAD`/`F_READAHEAD` on files; unknown commands `EINVAL`; record locks through the host's POSIX locks on Linux. `O_NONBLOCK` on a pipe switches the Windows pipe to non-blocking mode (empty read and full write return `EAGAIN`) and sets the host flag on Linux; on files, directories and the random device it is only recorded because their reads never block. `ioctl`: `FIONBIO` on the same flags, `FIONREAD` (file size minus offset, queued bytes on a pipe read end, 0 on its write end, `ENOTTY` on the random device), the terminal `'t'` group `ENOTTY`. - What throws, naming the flag and descriptor kind: changing `O_APPEND` on a Windows file, `O_FSYNC` on a file, `O_ASYNC` on a pipe or character device (no `SIGIO`), `O_NONBLOCK` on a Windows console, `F_GETOWN`/`F_SETOWN`/`F_SETLK_REMOTE`, record locks on Windows or character devices, `F_GETLK` with `F_UNLCK`, `FIONREAD` on a directory or character device, any other ioctl request. Sockets keep the previous path unchanged (they still answer `F_GETFD`/`F_SETFD` with `EINVAL`; XPSemu may call those on sockets, left for a follow-up). The `fcntl`, `sceKernelFcntl` and `ioctl` TechnicalDebt entries are updated. - `guest_kernel_fcntl` covers flag round trips on a file, stdin and both pipe ends, `F_DUPFD` with a start, the `EINVAL` cases, `EAGAIN` on an empty and a full non-blocking pipe, the ioctl cases, the throw messages and the unchanged socket path; `guest_dup` checks that duplicates share status flags and clear close-on-exec. Known pre-existing gap left alone: `readv`/`writev` on a non-blocking pipe report 11 (`EDEADLK`) instead of `EAGAIN` through the host error mapping in `Stdio.cpp`. **Tested** on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`: `guest_kernel_fcntl`, `guest_dup`, `guest_udp`, `guest_socket_pair`, `guest_socket_read_write`, `guest_poll`, `guest_terminal`, `guest_file_vector`, `guest_aio` 3/3; `ctest -j8 -E "^agc_driver_|^video_out_flip"` under heavy host load (five other builds): beyond the known `windows_exceptions` (#3411, fixed by #3415), `guest_kernel_sys` (#3510), `guest_filesystem` (#3518) and the `guest_ampr_markers` flake (#3371), three timeouts (`guest_raise_exception`, `tls_function_coverage_register_address_loads`, `guest_pthread_start`) that pass when rerun serially; with `main`'s `Open.cpp` two of the nine tests fail; `tools/check_conventions.py --base main` and `git diff --check` pass. Not run on Linux. Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).
ahir061 commented 2026-10-11 17:05:14 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by ahir061 on 2026-10-11T17:05:14Z.


I can carry this: I’ll open a PR with your two commits unchanged (they apply cleanly on current main a11c8f7f) and add Linux results, since it hasn’t been run there yet. Thanks for writing it up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111495464 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3757#issuecomment-6111495464). Originally posted by [ahir061](https://github.com/ahir061) on 2026-10-11T17:05:14Z. --- I can carry this: I’ll open a PR with your two commits unchanged (they apply cleanly on current main a11c8f7f) and add Linux results, since it hasn’t been run there yet. Thanks for writing it up.
xXPBSXx commented 2026-10-12 04:56:40 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T04:56:40Z.


Another title on this stop: PPSA24423, Windows 10, GCC, RTX 4080 SUPER, main ceb342b94 (no open PR), 60 s run, import audit 0 absent imports. Within the 60 s run (the log shows shader disk cache activity before it) it aborts with

what():  sceKernelFcntl: file descriptors are not implemented, fd=6

The thrown message does not log the fcntl command, so which command the title issues is not known from this run. This is the non-socket descriptor rejection in sceKernelFcntl (Open.cpp) this issue describes, so I did not open a separate issue.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6118017747 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3757#issuecomment-6118017747). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T04:56:40Z. --- Another title on this stop: PPSA24423, Windows 10, GCC, RTX 4080 SUPER, `main` `ceb342b94` (no open PR), 60 s run, import audit 0 absent imports. Within the 60 s run (the log shows shader disk cache activity before it) it aborts with ``` what(): sceKernelFcntl: file descriptors are not implemented, fd=6 ``` The thrown message does not log the `fcntl` command, so which command the title issues is not known from this run. This is the non-socket descriptor rejection in `sceKernelFcntl` (`Open.cpp`) this issue describes, so I did not open a separate issue. AI-assisted (Claude Code).
xXPBSXx commented 2026-10-12 07:53:30 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T07:53:30Z.


Title test of PR #3840, which carries the commits of this issue's branch, Windows 10, MinGW GCC, RTX 4080 SUPER: this PR merged locally onto current main d06c06565 (clean merge, no conflicts). Full build with -j4 succeeded; the ctest subset matching fcntl|ioctl|file|open|descriptor|stdio|pipe|dup|kernel ran 44 tests: 44 passed (video_out_flip_reopen skipped).

PPSA24423 (0 absent imports; stopped on main ceb342b94 at sceKernelFcntl: 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:

what():  AGC graphics: vertex buffer aliases the render target
FATAL: abort() (SIGABRT)

So the title gets past fcntl and reaches rendering. I did not look at the picture and one run only.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6120081257 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3757#issuecomment-6120081257). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T07:53:30Z. --- Title test of PR #3840, which carries the commits of this issue's branch, Windows 10, MinGW GCC, RTX 4080 SUPER: this PR merged locally onto current `main` `d06c06565` (clean merge, no conflicts). Full build with `-j4` succeeded; the `ctest` subset matching `fcntl|ioctl|file|open|descriptor|stdio|pipe|dup|kernel` ran 44 tests: 44 passed (`video_out_flip_reopen` skipped). PPSA24423 (0 absent imports; stopped on `main` `ceb342b94` at `sceKernelFcntl: 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: ``` what(): AGC graphics: vertex buffer aliases the render target FATAL: abort() (SIGABRT) ``` So the title gets past `fcntl` and reaches rendering. I did not look at the picture and one run only. AI-assisted (Claude Code).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#3757
No description provided.