fix(libkernel_sys): fail fchdir on a kqueue descriptor with EINVAL #9994

Merged
xXPBSXx merged 3 commits from upstream-pr/9994 into main 2026-11-08 15:03:31 +00:00
xXPBSXx commented 2026-10-23 03:23:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-23T03:23:02Z.


What

DescriptorHasNoVnode_nid_no_patch now also reports a kqueue descriptor (IsKqueueDescriptor) as having no vnode, so fchdir on it fails with EINVAL. guest_kernel_sys gets the case. The helper has one caller, fchdir_nid_postfix.

FreeBSD 11.4 getvnode/sys_fchdir (sys/kern/vfs_syscalls.c). Found by comparing against that source, not from a title.

Fixes: #9993

Tested

Head c76ff24b4d, rebased onto main f26434afa3; git merge-tree against current main d8db8faef5 is clean. The diff is 2 files, +6/-1: DescriptorControl.cpp +2/-1 and GuestKernelSys.cpp +4. The rebase dropped exactly one hunk of the earlier head c55d6d7333: the declaration int kqueue_nid_postfix(); in GuestKernelSys.cpp, which main now declares in the library headers. The other hunks are unchanged.

  • Windows 10 Pro 19045, MinGW-w64 GCC 15.2, Release, on main f26434afa3 with this head (ninja exit code 0): guest_kernel_sys passes 3 of 3 runs.
  • Without the change in DescriptorControl.cpp (taken from main, same build directory, test kept; ninja exit code 0): guest_kernel_sys fails 3 of 3 runs with exit code 0xc0000409.
  • The family kernel_sys|kqueue|equeue|file_event|fchdir|chdir|descriptor has 23 tests on main now (the earlier description named 16) and passes 23 of 23 with this head.
  • check_conventions --base upstream/main passes.
  • Not run here: macOS, a title, a console (on Linux and macOS the placeholder is /dev/null, and the new check does not depend on the host). Measured by others: jotitadev on bare-metal Linux x86_64 (Intel i7-8700, Ubuntu 26.04, kernel 7.0, glibc 2.43, GCC 15.2, Release, BUILD_TESTING=ON, full build), head c76ff24b4ddf1c7efbd28f44305d5f455c8d48b9 merged onto main abed03546: guest_kernel_sys passes 3 of 3, the 27 tests matching kernel_sys|kqueue|equeue|file_event|fchdir|chdir|descriptor pass, and with DescriptorControl.cpp from main and the new test kept guest_kernel_sys aborts at line 889 with guest errno 20 (review); and at the earlier head c55d6d7333 (the current head only drops one local declaration from the test): jotitadev on macOS 27.2 (Apple M2 Max, x86_64 under Rosetta 2, on #8658): guest_kernel_sys fails without the fix at line 461 with guest errno 20 and passes 3 of 3 with it, and the eight related tests pass; JJenkx on Windows 11 Enterprise 22H2: the same red at line 461 without the fix, and with it the test stops later at line 840 on the existing link symbolic-link loop, which also fails on main.

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
  • 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 #9993
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4977327978 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9994). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-23T03:23:02Z. --- ### What `DescriptorHasNoVnode_nid_no_patch` now also reports a kqueue descriptor (`IsKqueueDescriptor`) as having no vnode, so `fchdir` on it fails with `EINVAL`. `guest_kernel_sys` gets the case. The helper has one caller, `fchdir_nid_postfix`. FreeBSD 11.4 `getvnode`/`sys_fchdir` (sys/kern/vfs_syscalls.c). Found by comparing against that source, not from a title. Fixes: #9993 ### Tested Head `c76ff24b4d`, rebased onto `main` `f26434afa3`; `git merge-tree` against current `main` `d8db8faef5` is clean. The diff is 2 files, +6/-1: `DescriptorControl.cpp` +2/-1 and `GuestKernelSys.cpp` +4. The rebase dropped exactly one hunk of the earlier head `c55d6d7333`: the declaration `int kqueue_nid_postfix();` in `GuestKernelSys.cpp`, which `main` now declares in the library headers. The other hunks are unchanged. - Windows 10 Pro 19045, MinGW-w64 GCC 15.2, Release, on `main` `f26434afa3` with this head (ninja exit code 0): `guest_kernel_sys` passes 3 of 3 runs. - Without the change in `DescriptorControl.cpp` (taken from `main`, same build directory, test kept; ninja exit code 0): `guest_kernel_sys` fails 3 of 3 runs with exit code 0xc0000409. - The family `kernel_sys|kqueue|equeue|file_event|fchdir|chdir|descriptor` has 23 tests on `main` now (the earlier description named 16) and passes 23 of 23 with this head. - `check_conventions --base upstream/main` passes. - Not run here: macOS, a title, a console (on Linux and macOS the placeholder is `/dev/null`, and the new check does not depend on the host). Measured by others: jotitadev on bare-metal Linux x86_64 (Intel i7-8700, Ubuntu 26.04, kernel 7.0, glibc 2.43, GCC 15.2, Release, `BUILD_TESTING=ON`, full build), head `c76ff24b4ddf1c7efbd28f44305d5f455c8d48b9` merged onto `main` `abed03546`: `guest_kernel_sys` passes 3 of 3, the 27 tests matching `kernel_sys|kqueue|equeue|file_event|fchdir|chdir|descriptor` pass, and with `DescriptorControl.cpp` from `main` and the new test kept `guest_kernel_sys` aborts at line 889 with guest errno 20 ([review](https://github.com/boykopovar/AnyPS5/pull/9994#pullrequestreview-5661629653)); and at the earlier head `c55d6d7333` (the current head only drops one local declaration from the test): jotitadev on macOS 27.2 (Apple M2 Max, x86_64 under Rosetta 2, on #8658): `guest_kernel_sys` fails without the fix at line 461 with guest errno 20 and passes 3 of 3 with it, and the eight related tests pass; JJenkx on Windows 11 Enterprise 22H2: the same red at line 461 without the fix, and with it the test stops later at line 840 on the existing `link` symbolic-link loop, which also fails on `main`. ### Checklist - [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) - [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 #9993 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-23 03:27:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T03:27:16Z.

Review: APPROVED


Reviewed the exact PR diff and the corresponding current-main helper declaration/call path. The change makes kqueue descriptors fail the no-vnode predicate before the character-device placeholder can make them appear vnode-backed; the regression exercises fchdir(kqueue()) and checks EINVAL. The issue supplies FreeBSD 11.4 source basis and Windows before/after observations, and the PR reports Windows 10 red/green results (3/3 plus a 16-test related family). The eligibility, intake, conventions, labels, and report checks pass; product build and runtime jobs are skipped by repository policy. I attempted the focused Linux target using the available build, but compilation stopped in unrelated Socket/src/Udp.cpp because /tmp is out of space, so I did not obtain an additional local test result.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5623545341 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9994#pullrequestreview-5623545341). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T03:27:16Z. **Review:** APPROVED --- Reviewed the exact PR diff and the corresponding current-main helper declaration/call path. The change makes kqueue descriptors fail the no-vnode predicate before the character-device placeholder can make them appear vnode-backed; the regression exercises `fchdir(kqueue())` and checks `EINVAL`. The issue supplies FreeBSD 11.4 source basis and Windows before/after observations, and the PR reports Windows 10 red/green results (3/3 plus a 16-test related family). The `eligibility`, `intake`, `conventions`, `labels`, and `report` checks pass; product build and runtime jobs are skipped by repository policy. I attempted the focused Linux target using the available build, but compilation stopped in unrelated `Socket/src/Udp.cpp` because `/tmp` is out of space, so I did not obtain an additional local test result.
MarcZX10 commented 2026-10-23 04:02:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T04:02:18Z.

Review: APPROVED


Reviewed the complete diff and its sole helper caller: the new predicate only adjusts the fchdir fallback for a kqueue descriptor, returning the documented FreeBSD EINVAL case without changing unrelated descriptor classification. I also checked the uncomparable overlap report: the three other open PRs touching DescriptorControl.cpp change different helpers/regions, and the shared GuestKernelSys.cpp changes are in unrelated test sections.

Exact-head local checks passed: both changed C++ translation units compiled with GCC 12.2 -std=c++20 -Wall -Wextra -Werror -fsyntax-only; conventions, test-registration audit (172 scripts), and diff check passed. Hosted eligibility, conventions, intake, labels and report checks pass; product builds are skipped. I could not run the guest test here because the host CPU does not meet the project test runtime gate. The PR reports the Windows negative control (3/3 failures before, 3/3 pass after) and a 16-test kernel/kqueue family pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5623736428 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9994#pullrequestreview-5623736428). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T04:02:18Z. **Review:** APPROVED --- Reviewed the complete diff and its sole helper caller: the new predicate only adjusts the `fchdir` fallback for a kqueue descriptor, returning the documented FreeBSD EINVAL case without changing unrelated descriptor classification. I also checked the uncomparable overlap report: the three other open PRs touching DescriptorControl.cpp change different helpers/regions, and the shared GuestKernelSys.cpp changes are in unrelated test sections. Exact-head local checks passed: both changed C++ translation units compiled with GCC 12.2 `-std=c++20 -Wall -Wextra -Werror -fsyntax-only`; conventions, test-registration audit (172 scripts), and diff check passed. Hosted eligibility, conventions, intake, labels and report checks pass; product builds are skipped. I could not run the guest test here because the host CPU does not meet the project test runtime gate. The PR reports the Windows negative control (3/3 failures before, 3/3 pass after) and a 16-test kernel/kqueue family pass.
jotitadev commented 2026-10-23 04:27:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-23T04:27:30Z.

Review: COMMENTED


macOS run, since the PR lists Linux/macOS as not run.

  • Machine: Apple M2 Max, macOS 27.2 (26B5091g), Xcode 27 Apple clang, x86_64 build under Rosetta 2, Release.
  • Base: #8658 (feat/macos-port) @ 81490845d2 (main does not build the runtime on macOS yet), plus this PR's diff @ c55d6d7333.
guest_kernel_sys
test only, without the fix fails: Kernel sys check failed at line 461 (guest errno 20)
with the fix 3/3 pass

So the issue is not Windows-only: on macOS the kqueue placeholder is also a character device and fchdir(kqueue()) answers ENOTDIR, as the description expects. The family kernel_sys|kqueue|equeue|file_event|fchdir|chdir|descriptor (non-agc, 8 tests) passes with the change.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5623892687 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9994#pullrequestreview-5623892687). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-23T04:27:30Z. **Review:** COMMENTED --- macOS run, since the PR lists Linux/macOS as not run. - Machine: Apple M2 Max, macOS 27.2 (26B5091g), Xcode 27 Apple clang, x86_64 build under Rosetta 2, Release. - Base: #8658 (`feat/macos-port`) @ 81490845d2 (main does not build the runtime on macOS yet), plus this PR's diff @ c55d6d7333. | | `guest_kernel_sys` | |---|---| | test only, without the fix | fails: `Kernel sys check failed at line 461 (guest errno 20)` | | with the fix | 3/3 pass | So the issue is not Windows-only: on macOS the kqueue placeholder is also a character device and `fchdir(kqueue())` answers `ENOTDIR`, as the description expects. The family `kernel_sys|kqueue|equeue|file_event|fchdir|chdir|descriptor` (non-`agc`, 8 tests) passes with the change. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
jotitadev commented 2026-10-27 02:42:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T02:42:18Z.

Review: COMMENTED


First Linux run, since the description lists Linux as not run.

Bare-metal Linux x86_64: i7-8700, Ubuntu 26.04, kernel 7.0, glibc 2.43, GCC 15.2, Release, BUILD_TESTING=ON, full build. Head c76ff24b4 merged --no-commit onto main abed03546 (clean).

  • guest_kernel_sys: passes 3 of 3.
  • kernel_sys|kqueue|equeue|file_event|fchdir|chdir|descriptor: 27 of 27 pass.
  • Control, DescriptorControl.cpp from main with the new test kept (full rebuild): guest_kernel_sys aborts with Kernel sys check failed at line 889 (guest errno 20). That is the new fchdir(kqueue) check getting ENOTDIR from the /dev/null placeholder instead of EINVAL, the same failure seen on macOS earlier. So the test catches the regression on Linux too.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5661629653 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9994#pullrequestreview-5661629653). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-27T02:42:18Z. **Review:** COMMENTED --- First Linux run, since the description lists Linux as not run. Bare-metal Linux x86_64: i7-8700, Ubuntu 26.04, kernel 7.0, glibc 2.43, GCC 15.2, Release, `BUILD_TESTING=ON`, full build. Head `c76ff24b4` merged `--no-commit` onto `main` `abed03546` (clean). - `guest_kernel_sys`: passes 3 of 3. - `kernel_sys|kqueue|equeue|file_event|fchdir|chdir|descriptor`: 27 of 27 pass. - Control, `DescriptorControl.cpp` from `main` with the new test kept (full rebuild): `guest_kernel_sys` aborts with `Kernel sys check failed at line 889 (guest errno 20)`. That is the new `fchdir(kqueue)` check getting `ENOTDIR` from the `/dev/null` placeholder instead of `EINVAL`, the same failure seen on macOS earlier. So the test catches the regression on Linux too. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-29 08:58:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T08:58:04Z.

Review: CHANGES_REQUESTED


Re-check — changes requested

The new Windows build report confirms that the latest head does not compile when integrated with the reported current main: DescriptorControl.cpp refers to the renamed kqueue predicate, and GuestKernelSys.cpp redeclares kqueueDescriptor. These are integration blockers despite the earlier approval and successful tests on the preceding head.

Please rebase/update onto current main, resolve both compile errors, and rerun the focused Windows guest_kernel_sys test with the negative control on the resulting exact head. The hosted windows check does not compile these two affected translation units, so it does not replace that validation. I have not run a local build or test for this update.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5695119586 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9994#pullrequestreview-5695119586). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T08:58:04Z. **Review:** CHANGES_REQUESTED --- ## Re-check — changes requested The new Windows build report confirms that the latest head does not compile when integrated with the reported current `main`: `DescriptorControl.cpp` refers to the renamed kqueue predicate, and `GuestKernelSys.cpp` redeclares `kqueueDescriptor`. These are integration blockers despite the earlier approval and successful tests on the preceding head. Please rebase/update onto current `main`, resolve both compile errors, and rerun the focused Windows `guest_kernel_sys` test with the negative control on the resulting exact head. The hosted `windows` check does not compile these two affected translation units, so it does not replace that validation. I have not run a local build or test for this update.
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!9994
No description provided.