fix(libkernel_sys): fail fpathconf with EOPNOTSUPP and fchdir with EINVAL on a ksem id, as FreeBSD 11.4 does #24484

Merged
brajankw merged 1 commit from upstream-pr/24484 into main 2026-11-21 13:13:27 +00:00
brajankw commented 2026-11-20 17:23:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-20T17:23:53Z.


What

A ksem id is a host null device descriptor here, so fpathconf answered it as a file and fchdir failed with ENOTDIR. FreeBSD 11.4's kern_fpathconf answers _PC_ASYNC_IO for any descriptor and fails with EOPNOTSUPP for one without a vnode that is neither a pipe nor a socket, and sys_fchdir takes the vnode through getvnode, which fails with EINVAL.

  • DescriptorHasNoVnode_nid_no_patch now counts a ksem id, which gives fchdir its EINVAL.
  • fpathconf uses DescriptorHasNoVnode_nid_no_patch in place of its own kqueue check. So any other descriptor that it finds without a vnode, such as a host block device, also gets EOPNOTSUPP there instead of file values, as kern_fpathconf gives. Pipes and sockets are answered before, as they were.
  • IsKsemDescriptor, which this uses, is replaced by DuplicateKsemDescriptor in open #22191. The two merge without a textual conflict, but whichever lands second needs a rebase that keeps a ksem predicate, or the build breaks. I will rebase this as soon as #22191 lands.
  • Tests: the ksem cases in GuestKernelSys.cpp, through both fpathconf exports and fchdir.
  • Debt: no fragment.

Tested

Linux (Debian 13, GCC 14.2.0, Release). Head 58b8da419b, the single commit on main c8f72e905c.

  • Negative control: with only the test change, on main 84e16538d4, guest_kernel_sys aborts at the ksem fpathconf check with errno 22.
  • On 58b8da419b, ctest over guest_kernel_sys, guest_kernel_sys_ksem, guest_kqueue and guest_filesystem: all pass.
  • Full ctest (6393 tests, -j 12) on this branch and my other eleven branches of this round, merged onto main 84e16538d4: 6378 passed. The 15 failures also fail on main in this 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;
    • five agc_driver GPU cases fail the same way on main: prepared_shaders with its indirect, uncached and debug forms, and storage_file_write;
    • agc_driver_image_table_packed_guards is unstable on main as well (2 of 10 runs passed on its own on main 3f4693be43).
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch fix/libkernel-ksem-fpathconf-fchdir: could not compare #7121, #9389, #9557, #9566, #12682, #12688, #12700, #12965, #15037 and #18457, which conflict with main; none of their diffs touches DescriptorHasNoVnode_nid_no_patch, _fpathconf_nid_postfix or fchdir_nid_postfix.
  • 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:5417500099 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24484). Originally posted by [brajankw](https://github.com/brajankw) on 2026-11-20T17:23:53Z. --- ### What A ksem id is a host null device descriptor here, so `fpathconf` answered it as a file and `fchdir` failed with `ENOTDIR`. FreeBSD 11.4's [`kern_fpathconf`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_descrip.c#L1400-L1433) answers `_PC_ASYNC_IO` for any descriptor and fails with `EOPNOTSUPP` for one without a vnode that is neither a pipe nor a socket, and `sys_fchdir` takes the vnode through `getvnode`, which fails with `EINVAL`. - `DescriptorHasNoVnode_nid_no_patch` now counts a ksem id, which gives `fchdir` its `EINVAL`. - `fpathconf` uses `DescriptorHasNoVnode_nid_no_patch` in place of its own kqueue check. So any other descriptor that it finds without a vnode, such as a host block device, also gets `EOPNOTSUPP` there instead of file values, as `kern_fpathconf` gives. Pipes and sockets are answered before, as they were. - `IsKsemDescriptor`, which this uses, is replaced by `DuplicateKsemDescriptor` in open #22191. The two merge without a textual conflict, but whichever lands second needs a rebase that keeps a ksem predicate, or the build breaks. I will rebase this as soon as #22191 lands. - Tests: the ksem cases in `GuestKernelSys.cpp`, through both `fpathconf` exports and `fchdir`. - Debt: no fragment. ### 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). Head `58b8da419b`, the single commit on `main` `c8f72e905c`. - Negative control: with only the test change, on `main` `84e16538d4`, `guest_kernel_sys` aborts at the ksem `fpathconf` check with errno 22. - On `58b8da419b`, `ctest` over `guest_kernel_sys`, `guest_kernel_sys_ksem`, `guest_kqueue` and `guest_filesystem`: all pass. - Full `ctest` (6393 tests, `-j 12`) on this branch and my other eleven branches of this round, merged onto `main` `84e16538d4`: 6378 passed. The 15 failures also fail on `main` in this 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`; - five `agc_driver` GPU cases fail the same way on `main`: `prepared_shaders` with its `indirect`, `uncached` and `debug` forms, and `storage_file_write`; - `agc_driver_image_table_packed_guards` is unstable on `main` as well (2 of 10 runs passed on its own on `main` `3f4693be43`). - `python3 tools/check_conventions.py --base origin/main`: passed. - `python3 tools/pr_overlap.py --branch fix/libkernel-ksem-fpathconf-fchdir`: could not compare #7121, #9389, #9557, #9566, #12682, #12688, #12700, #12965, #15037 and #18457, which conflict with `main`; none of their diffs touches `DescriptorHasNoVnode_nid_no_patch`, `_fpathconf_nid_postfix` or `fchdir_nid_postfix`. - 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-20 18:41:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T18:41:23Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 58b8da419b:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_kernel_sys_tests built cleanly.
  • CTest (guest_kernel_sys):
    1/1 Test #958: guest_kernel_sys .................   Passed    0.21 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/File/src/DescriptorControl.cpp, core/libs/prx/libkernel_sys/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #958: guest_kernel_sys .................Subprocess aborted***Exception:   0.40 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified that DescriptorHasNoVnode_nid_no_patch in core/libs/prx/libkernel/File/src/DescriptorControl.cpp correctly incorporates IsKsemDescriptor(fd), preventing ksem descriptors from being treated as vnodes.
    • Verified that Export.cpp in libkernel_sys correctly rejects fpathconf with EOPNOTSUPP (GuestEopnotsupp = 45) for non-vnode descriptors via DescriptorHasNoVnode_nid_no_patch while preserving PcAsyncIo handling.
    • Verified that fchdir with a ksem descriptor fails with EINVAL (22) in FreeBSD 11.4 / Orbis OS, and that this PR correctly triggers EINVAL via DescriptorHasNoVnode_nid_no_patch without regression.
    • Verified that test additions in core/libs/tests/GuestKernelSys.cpp properly initialize, test fpathconf, _fpathconf, and fchdir on ksem IDs, and safely destroy the semaphore without resource leaks.
    • Verified that no AGENTS.md rules were violated: no prohibited comments added, conventional commit format adhered to, and no unexpected files introduced.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5997688600 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24484#pullrequestreview-5997688600). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-20T18:41:23Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `58b8da419b`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_kernel_sys_tests` built cleanly. - **CTest** (`guest_kernel_sys`): ``` 1/1 Test #958: guest_kernel_sys ................. Passed 0.21 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/File/src/DescriptorControl.cpp`, `core/libs/prx/libkernel_sys/Export.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #958: guest_kernel_sys .................Subprocess aborted***Exception: 0.40 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified that DescriptorHasNoVnode_nid_no_patch in core/libs/prx/libkernel/File/src/DescriptorControl.cpp correctly incorporates IsKsemDescriptor(fd), preventing ksem descriptors from being treated as vnodes. - Verified that Export.cpp in libkernel_sys correctly rejects fpathconf with EOPNOTSUPP (GuestEopnotsupp = 45) for non-vnode descriptors via DescriptorHasNoVnode_nid_no_patch while preserving PcAsyncIo handling. - Verified that fchdir with a ksem descriptor fails with EINVAL (22) in FreeBSD 11.4 / Orbis OS, and that this PR correctly triggers EINVAL via DescriptorHasNoVnode_nid_no_patch without regression. - Verified that test additions in core/libs/tests/GuestKernelSys.cpp properly initialize, test fpathconf, _fpathconf, and fchdir on ksem IDs, and safely destroy the semaphore without resource leaks. - Verified that no AGENTS.md rules were violated: no prohibited comments added, conventional commit format adhered to, and no unexpected files introduced. Looks Good To Me
MarcZX10 commented 2026-11-21 05:33:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T05:33:48Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the inspected code and included tests support the stated ksem behavior.

What I ran

Read the prepared diff and source context at head 58b8da419b44975c89d09f8fece6e3fd988a1c76. I ran no commands; reported test results below are from the PR description.

Results

Check Result Note
Source review passed Three changed files read
Targeted tests not run PR reports four test targets passed
Full test suite not run PR reports 6378 passed, 15 environment or known failures
Other platforms not run Windows and macOS not tested

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read all three changed files listed as reviewed in the manifest: core/libs/prx/libkernel/File/src/DescriptorControl.cpp, core/libs/prx/libkernel_sys/Export.cpp, and core/libs/tests/GuestKernelSys.cpp. No files were excluded by manifest.json. I did not run tests or verify the author-reported results, other platforms, or behavior on a physical console.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6003170517 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24484#pullrequestreview-6003170517). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T05:33:48Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the inspected code and included tests support the stated ksem behavior. ## What I ran Read the prepared diff and source context at head `58b8da419b44975c89d09f8fece6e3fd988a1c76`. I ran no commands; reported test results below are from the PR description. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Three changed files read | | Targeted tests | not run | PR reports four test targets passed | | Full test suite | not run | PR reports 6378 passed, 15 environment or known failures | | Other platforms | not run | Windows and macOS not tested | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I read all three changed files listed as reviewed in the manifest: `core/libs/prx/libkernel/File/src/DescriptorControl.cpp`, `core/libs/prx/libkernel_sys/Export.cpp`, and `core/libs/tests/GuestKernelSys.cpp`. No files were excluded by `manifest.json`. I did not run tests or verify the author-reported results, other platforms, or behavior on a physical console. ## To get this to a good state Nothing is required.
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!24484
No description provided.