fix(libkernel): set O_ASYNC through ioctl FIOASYNC on files, directories and the random device, as FreeBSD 11.4 does #22295

Merged
brajankw merged 1 commit from upstream-pr/22295 into main 2026-11-17 12:59:30 +00:00
brajankw commented 2026-11-17 11:20:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-17T11:20:21Z.


What

ioctl(fd, FIOASYNC, &on) threw on files, directories, pipes and devices, because the request had no case in the descriptor ioctl; a kqueue already failed it with ENOTTY. FreeBSD 11.4's kern_ioctl sets or clears FASYNC in the file's flags from the argument (sys/kern/sys_generic.c:828-834). It then asks the file's own handler, and here vn_ioctl returns 0 for VREG and VDIR (sys/kern/vfs_vnops.c), and so does randomdev_ioctl for the random device (sys/dev/random/randomdev.c:306-310). F_GETFL then reports O_ASYNC. The request now goes through the same status change as F_SETFL with O_ASYNC:

  • it is recorded on files (app0.zar files included), directories and the random device;

  • setting it still throws on a pipe, a host socket or another character device, as O_ASYNC already does there, since SIGIO is not delivered; clearing a flag that is not set succeeds.

  • GuestKernelFcntl.cpp: FIOASYNC on a file, a directory and /dev/urandom sets and clears O_ASYNC in F_GETFL. A flag set through a dup shows on the original and the reverse, as the status flags are shared. A null argument fails with EFAULT. On a pipe, clearing succeeds and setting still throws. The unknown-request throw check now uses FIODTYPE (0x4004667a) instead of FIOASYNC.

  • Debt fragment: a new ioctl FIOASYNC entry under Functional, with the pipe and device gap first. Adding this to the ioctl, _ioctl entry would have taken it past 1000 characters.

Tested

Linux (Debian 13, GCC 14.2.0, Release), on main 47b33132f9.

  • ctest -R '^(guest_kernel_fcntl.*|guest_kernel_ioctl.*|guest_kernel_app_archive.*)$': 6 passed.
  • Negative control: on main, the new test aborts with ioctl: request 0x8004667D on a file is not implemented.
  • Full ctest (6000 tests, -j 12) on this branch and my other five branches of this round, merged onto main 47b33132f9: 5985 passed. All 15 failures also fail on main in the same environment:
    • nine need a .git directory, network access or a passwd entry for the user: conventions_git_errors, test_script_registration, web_library_assets, title_run, title_run_identity, guest_kernel_sys_login, guest_net_ctl, guest_getlogin and guest_getlogin_no_session;
    • six are agc_driver cases (agc_driver_image_table_packed_guards passes when run on its own).
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch:
    • #9566 adds owner-request constants and cases next to the lines this PR changes in DescriptorControl.cpp, and #18457 adds a call next to mine in main() of GuestKernelFcntl.cpp. Neither handles FIOASYNC, so both conflicts are only textual.
    • It failed closed on #7121, #9557, #12682, #12688, #12700 and #12965, which conflict with main; none handles FIOASYNC.
  • Not tested on Windows or macOS. No title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5355859559 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22295). Originally posted by [brajankw](https://github.com/brajankw) on 2026-11-17T11:20:21Z. --- ### What `ioctl(fd, FIOASYNC, &on)` threw on files, directories, pipes and devices, because the request had no case in the descriptor ioctl; a kqueue already failed it with `ENOTTY`. FreeBSD 11.4's `kern_ioctl` sets or clears `FASYNC` in the file's flags from the argument (`sys/kern/sys_generic.c:828-834`). It then asks the file's own handler, and here `vn_ioctl` returns 0 for `VREG` and `VDIR` (`sys/kern/vfs_vnops.c`), and so does `randomdev_ioctl` for the random device (`sys/dev/random/randomdev.c:306-310`). `F_GETFL` then reports `O_ASYNC`. The request now goes through the same status change as `F_SETFL` with `O_ASYNC`: - it is recorded on files (app0.zar files included), directories and the random device; - setting it still throws on a pipe, a host socket or another character device, as `O_ASYNC` already does there, since `SIGIO` is not delivered; clearing a flag that is not set succeeds. - `GuestKernelFcntl.cpp`: `FIOASYNC` on a file, a directory and `/dev/urandom` sets and clears `O_ASYNC` in `F_GETFL`. A flag set through a `dup` shows on the original and the reverse, as the status flags are shared. A null argument fails with `EFAULT`. On a pipe, clearing succeeds and setting still throws. The unknown-request throw check now uses `FIODTYPE` (`0x4004667a`) instead of `FIOASYNC`. - Debt fragment: a new `ioctl FIOASYNC` entry under Functional, with the pipe and device gap first. Adding this to the `ioctl, _ioctl` entry would have taken it past 1000 characters. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux (Debian 13, GCC 14.2.0, Release), on `main` `47b33132f9`. - `ctest -R '^(guest_kernel_fcntl.*|guest_kernel_ioctl.*|guest_kernel_app_archive.*)$'`: 6 passed. - Negative control: on `main`, the new test aborts with `ioctl: request 0x8004667D on a file is not implemented`. - Full `ctest` (6000 tests, `-j 12`) on this branch and my other five branches of this round, merged onto `main` `47b33132f9`: 5985 passed. All 15 failures also fail on `main` in the same environment: - nine need a `.git` directory, network access or a passwd entry for the user: `conventions_git_errors`, `test_script_registration`, `web_library_assets`, `title_run`, `title_run_identity`, `guest_kernel_sys_login`, `guest_net_ctl`, `guest_getlogin` and `guest_getlogin_no_session`; - six are `agc_driver` cases (`agc_driver_image_table_packed_guards` passes when run on its own). - `python3 tools/check_conventions.py --base origin/main`: passed. - `python3 tools/pr_overlap.py --branch`: - #9566 adds owner-request constants and cases next to the lines this PR changes in `DescriptorControl.cpp`, and #18457 adds a call next to mine in `main()` of `GuestKernelFcntl.cpp`. Neither handles `FIOASYNC`, so both conflicts are only textual. - It failed closed on #7121, #9557, #12682, #12688, #12700 and #12965, which conflict with `main`; none handles `FIOASYNC`. - Not tested on Windows or macOS. No title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-17 11:30:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T11:30:52Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 4b9393b5e0:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_kernel_fcntl_tests built cleanly.
  • CTest (guest_kernel_fcntl):
    1/1 Test #5562: guest_kernel_fcntl ...............   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/File/src/DescriptorControl.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5562: guest_kernel_fcntl ...............Subprocess aborted***Exception:   0.66 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • DescriptorControl.cpp: verified handling of command == AsynchronousRequest (0x8004667d) alongside NonblockingRequest, checking GuestCopyIn safely copies the integer argument and returns GuestEfault on invalid/null pointer.
    • DescriptorControl.cpp: verified ChangeStatus correctly sets or clears Asynchronous (0x40) flag and applies the same checks as F_SETFL (throwing on pipes/sockets/unsupported devices when set, allowing clear).
    • DescriptorControl.cpp: verified kqueue check occurs prior to command handling, correctly returning GuestEnotty.
    • GuestKernelFcntl.cpp: verified tests thoroughly exercise ioctl FIOASYNC on files, directories, /dev/urandom, dup-shared status flags, null pointer EFAULT, and pipe throwing/clearing.
    • Technical debt fragment docs/dev/debt/changes/fix-libkernel-ioctl-fioasync.md: verified correct formatting, upstream references to FreeBSD 11.4 kern_ioctl, and adherence to AGENTS.md conventions.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5937630876 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22295#pullrequestreview-5937630876). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T11:30:52Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `4b9393b5e0`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_kernel_fcntl_tests` built cleanly. - **CTest** (`guest_kernel_fcntl`): ``` 1/1 Test #5562: guest_kernel_fcntl ............... Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/File/src/DescriptorControl.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5562: guest_kernel_fcntl ...............Subprocess aborted***Exception: 0.66 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - DescriptorControl.cpp: verified handling of command == AsynchronousRequest (0x8004667d) alongside NonblockingRequest, checking GuestCopyIn safely copies the integer argument and returns GuestEfault on invalid/null pointer. - DescriptorControl.cpp: verified ChangeStatus correctly sets or clears Asynchronous (0x40) flag and applies the same checks as F_SETFL (throwing on pipes/sockets/unsupported devices when set, allowing clear). - DescriptorControl.cpp: verified kqueue check occurs prior to command handling, correctly returning GuestEnotty. - GuestKernelFcntl.cpp: verified tests thoroughly exercise ioctl FIOASYNC on files, directories, /dev/urandom, dup-shared status flags, null pointer EFAULT, and pipe throwing/clearing. - Technical debt fragment docs/dev/debt/changes/fix-libkernel-ioctl-fioasync.md: verified correct formatting, upstream references to FreeBSD 11.4 kern_ioctl, and adherence to AGENTS.md conventions. Looks Good To Me
Sign in to join this conversation.
No reviewers
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!22295
No description provided.