feat(libkernel): implement kqueue, kevent and file events #3764

Merged
YossiYad merged 5 commits from upstream-pr/3764 into main 2026-10-12 20:50:34 +00:00
YossiYad commented 2026-10-11 16:33:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-11T16:33:17Z.


What

Carries David's two screamm/AnyPS5:feat/libkernel-kqueue commits from #3461 onto current main, preserving their author, and adds two follow-up test commits:

  • Implement kqueue and kevent over the event queue: change list, EV_ERROR/EV_RECEIPT, errno codes and timeout rules after FreeBSD 11.0.1 kern_event.c, with read/write on guest sockets, timers and user events. Cloudberry Kingdom (PPSA23827, #3177) calls kevent right after start-up.
  • Implement EVFILT_VNODE and sceKernelAddFileEvent/sceKernelDeleteFileEvent (cG3t15OK4Ow, UmXngHKB6is), which Palworld's Discord module imports (#2648). Host file and directory changes become FreeBSD vnode hints (Linux: inotify; Windows: change notifications plus a 50 ms snapshot poll).
  • The rebase has one conflict in Equeue.cpp and leaves a duplicated CollectTriggered declaration in Equeue.hpp that does not compile; both are resolved inside the first commit. The resulting tree is identical to blawesom's verified rebase (blawesom:verify/3461).
  • Rename and delete a watched file through kqueue, which reaches the inotify IN_MOVE_SELF and link-count paths that were never run on Linux. The case is skipped on Windows, where a descriptor from guest open is opened without delete sharing and the host refuses to rename or remove it.
  • Rename, unlink and rmdir entries of a watched directory, covering paired IN_MOVED_FROM/IN_MOVED_TO as NOTE_WRITE and a removed subdirectory as NOTE_WRITE|NOTE_LINK.

The library progress moves from 2903/3383 (85.81%) to 2906/3385 (85.85%): kqueue, sceKernelAddFileEvent and sceKernelDeleteFileEvent. The total rises by two because the file-event calls were not exported before. kevent stays counted as todo because unmodelled cases still throw. Those cases, and the deviations listed in #3461, are recorded in TechnicalDebt.

Closes #3461.

Tested

Linux (Bazzite 44, GCC 16.2.1, Ninja, Release, -DBUILD_TESTING=ON), based on main a11c8f7f:

  • Full build, libs, and full ctest: 825 pass, 8 skip, no failures (833 registered tests). The GPU agc_driver_pixel_interlock test failed on an earlier run and passed on the final full run; the changed library does not participate in that test.
  • guest_kqueue passes 20 consecutive runs, and 5 rounds of four copies running at the same time. The targeted run of guest_kqueue, guest_equeue_events, guest_socket_events, guest_dup, guest_ppsa01530_exports, patched_libraries, progress_report and progress_encoding passes (8/8).
  • Each new assertion fails when its expected hint is changed (rename reported as NOTE_DELETE, directory rename reported as NOTE_WRITE|NOTE_EXTEND).
  • tools/check_conventions.py --base upstream/main and git diff --check pass.
  • The original author reported Windows testing in #3461, and blawesom reported 833/833 on Linux for the rebased commits. The two new test cases were not run on Windows, and no game title was run on this machine.

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; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820585054 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3764). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-11T16:33:17Z. --- ### What Carries David's two `screamm/AnyPS5:feat/libkernel-kqueue` commits from #3461 onto current `main`, preserving their author, and adds two follow-up test commits: - Implement `kqueue` and `kevent` over the event queue: change list, `EV_ERROR`/`EV_RECEIPT`, errno codes and timeout rules after FreeBSD 11.0.1 `kern_event.c`, with read/write on guest sockets, timers and user events. Cloudberry Kingdom (PPSA23827, #3177) calls `kevent` right after start-up. - Implement `EVFILT_VNODE` and `sceKernelAddFileEvent`/`sceKernelDeleteFileEvent` (`cG3t15OK4Ow`, `UmXngHKB6is`), which Palworld's Discord module imports (#2648). Host file and directory changes become FreeBSD vnode hints (Linux: inotify; Windows: change notifications plus a 50 ms snapshot poll). - The rebase has one conflict in `Equeue.cpp` and leaves a duplicated `CollectTriggered` declaration in `Equeue.hpp` that does not compile; both are resolved inside the first commit. The resulting tree is identical to blawesom's verified rebase (`blawesom:verify/3461`). - Rename and delete a watched file through `kqueue`, which reaches the inotify `IN_MOVE_SELF` and link-count paths that were never run on Linux. The case is skipped on Windows, where a descriptor from guest `open` is opened without delete sharing and the host refuses to rename or remove it. - Rename, unlink and rmdir entries of a watched directory, covering paired `IN_MOVED_FROM`/`IN_MOVED_TO` as `NOTE_WRITE` and a removed subdirectory as `NOTE_WRITE|NOTE_LINK`. The library progress moves from 2903/3383 (85.81%) to 2906/3385 (85.85%): `kqueue`, `sceKernelAddFileEvent` and `sceKernelDeleteFileEvent`. The total rises by two because the file-event calls were not exported before. `kevent` stays counted as todo because unmodelled cases still throw. Those cases, and the deviations listed in #3461, are recorded in TechnicalDebt. Closes #3461. ### Tested Linux (Bazzite 44, GCC 16.2.1, Ninja, Release, `-DBUILD_TESTING=ON`), based on `main` `a11c8f7f`: - Full build, `libs`, and full `ctest`: 825 pass, 8 skip, no failures (833 registered tests). The GPU `agc_driver_pixel_interlock` test failed on an earlier run and passed on the final full run; the changed library does not participate in that test. - `guest_kqueue` passes 20 consecutive runs, and 5 rounds of four copies running at the same time. The targeted run of `guest_kqueue`, `guest_equeue_events`, `guest_socket_events`, `guest_dup`, `guest_ppsa01530_exports`, `patched_libraries`, `progress_report` and `progress_encoding` passes (8/8). - Each new assertion fails when its expected hint is changed (rename reported as `NOTE_DELETE`, directory rename reported as `NOTE_WRITE|NOTE_EXTEND`). - `tools/check_conventions.py --base upstream/main` and `git diff --check` pass. - The original author reported Windows testing in #3461, and blawesom reported 833/833 on Linux for the rebased commits. The two new test cases were not run on Windows, and no game title was run on this machine. ### 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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-11 16:33:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T16:33:43Z.


Progress report (03895fc → b7c67a3)

📈 System libraries: 87.3% (+0.04%, +3 implemented functions)

✅ 3 implemented
Library Name
libkernel kqueue_nid_postfix
libkernel sceKernelAddFileEvent
libkernel sceKernelDeleteFileEvent
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111203772 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3764#issuecomment-6111203772). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T16:33:43Z. --- <!-- progress-report --> ### Progress report (03895fc → b7c67a3) 📈 **System libraries**: 87.3% (+0.04%, +3 implemented functions) <details> <summary>✅ 3 implemented</summary> | Library | Name | | - | - | | libkernel | `kqueue_nid_postfix` | | libkernel | `sceKernelAddFileEvent` | | libkernel | `sceKernelDeleteFileEvent` | </details>
xXPBSXx commented 2026-10-11 16:47:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T16:47:38Z.


Windows data point for this PR (the description says the two new cases were not run on Windows): Windows 10, MinGW/Ninja Release build of the PR head on top of main a11c8f7f7 (git fetch upstream pull/3764/head). guest_kqueue passes in 6 consecutive runs (1.3 to 1.5 s each, run one after the other, not in parallel), and guest_equeue_events, guest_dup, guest_socket_events and guest_ppsa01530_exports pass. No title was run, and I did not check which cases the test skips on Windows.

I also had a much smaller branch for the same imports (kqueue returns a placeholder descriptor, kevent accepts only EVFILT_VNODE registrations and never fires). This PR covers all of it, so I am not opening mine.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111333748 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3764#issuecomment-6111333748). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-11T16:47:38Z. --- Windows data point for this PR (the description says the two new cases were not run on Windows): Windows 10, MinGW/Ninja Release build of the PR head on top of `main` a11c8f7f7 (`git fetch upstream pull/3764/head`). `guest_kqueue` passes in 6 consecutive runs (1.3 to 1.5 s each, run one after the other, not in parallel), and `guest_equeue_events`, `guest_dup`, `guest_socket_events` and `guest_ppsa01530_exports` pass. No title was run, and I did not check which cases the test skips on Windows. I also had a much smaller branch for the same imports (`kqueue` returns a placeholder descriptor, `kevent` accepts only `EVFILT_VNODE` registrations and never fires). This PR covers all of it, so I am not opening mine. AI-assisted (Claude Code).
YossiYad commented 2026-10-11 21:13:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-11T21:13:25Z.


Title evidence for this PR: on #2648, queeeef's ordered Palworld (PPSA23126, main a11c8f7f7) stop list has this as stop 1 — FAIL: unresolved ELF import cG3t15OK4Ow from libkernel.prx (sceKernelAddFileEvent, with kevent and sceKernelDeleteFileEvent also absent). Their table passes it with blawesom:verify/3461, which this PR carries (identical tree), and reports every import then binds, the title reaching character creation with the other listed PRs.

Thanks @xXPBSXx for the Windows run above.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113818593 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3764#issuecomment-6113818593). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-11T21:13:25Z. --- Title evidence for this PR: on #2648, queeeef's ordered Palworld (PPSA23126, `main` a11c8f7f7) stop list has this as stop 1 — `FAIL: unresolved ELF import cG3t15OK4Ow from libkernel.prx` (`sceKernelAddFileEvent`, with `kevent` and `sceKernelDeleteFileEvent` also absent). Their table passes it with `blawesom:verify/3461`, which this PR carries (identical tree), and reports every import then binds, the title reaching character creation with the other listed PRs. Thanks @xXPBSXx for the Windows run above.
xXPBSXx commented 2026-10-12 02:10:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T02:10:26Z.


Test of this PR on titles, Windows 10, MinGW GCC, RTX 4080 SUPER, each run under a 150 s limit, on current main with this PR merged locally (merge was clean):

  • Cloudberry Kingdom (PPSA23827, #3461): the kqueue/sceKernelAddFileEvent imports bind (0 unresolved imports) and the title runs for a while (shader cache activity), then aborts with what(): EVFILT_VNODE: NOTE_EXTEND on a directory not implemented (SIGABRT). That is the throw in FileEvent.cpp OpenHostWatch, so the title registers a EVFILT_VNODE event with NOTE_EXTEND on a directory descriptor, which this PR deliberately does not implement.
  • Palworld (PPSA23126, #2648): the kqueue stop is gone. The next stop is the one queeeef lists as item 2 in #2648: unhandled exception 0xc0000005 on thread 'RtcNetworkThread', eossdk-ps5-shipping.prx.guest.prx+0xdea2be, write fault, rcx/r12 = 0x10000005 (the libkernel socket, FD_SET, #1794). Needed the game directory (pal, sce_sys) linked into app0 as queeeef describes.

So the PR removes the first stop for both titles; for Cloudberry the directory NOTE_EXTEND case is what decides next. No game data shared.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116505938 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3764#issuecomment-6116505938). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T02:10:26Z. --- Test of this PR on titles, Windows 10, MinGW GCC, RTX 4080 SUPER, each run under a 150 s limit, on current `main` with this PR merged locally (merge was clean): - **Cloudberry Kingdom (PPSA23827, #3461):** the kqueue/`sceKernelAddFileEvent` imports bind (0 unresolved imports) and the title runs for a while (shader cache activity), then aborts with `what(): EVFILT_VNODE: NOTE_EXTEND on a directory not implemented` (SIGABRT). That is the throw in `FileEvent.cpp` `OpenHostWatch`, so the title registers a `EVFILT_VNODE` event with `NOTE_EXTEND` on a directory descriptor, which this PR deliberately does not implement. - **Palworld (PPSA23126, #2648):** the kqueue stop is gone. The next stop is the one queeeef lists as item 2 in #2648: `unhandled exception 0xc0000005 on thread 'RtcNetworkThread'`, `eossdk-ps5-shipping.prx.guest.prx+0xdea2be`, write fault, `rcx`/`r12` = `0x10000005` (the libkernel socket, `FD_SET`, #1794). Needed the game directory (`pal`, `sce_sys`) linked into `app0` as queeeef describes. So the PR removes the first stop for both titles; for Cloudberry the directory `NOTE_EXTEND` case is what decides next. No game data shared. AI-assisted (Claude Code).
xXPBSXx commented 2026-10-12 02:13:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T02:13:06Z.


Follow-up on the Cloudberry stop above (EVFILT_VNODE: NOTE_EXTEND on a directory not implemented): what FreeBSD does with NOTE_EXTEND on a directory. Source: freebsd-src release/13.2.0 (the PS5 kernel is FreeBSD-derived, but I have not checked that the console matches this version), sys/kern/vfs_subr.c, lib/libc/sys/kqueue.2.

  • Registration is valid. vfs_kqfilter only switches on the filter (EVFILT_READ/EVFILT_WRITE/EVFILT_VNODE, else EINVAL); it checks neither the vnode type nor fflags. filt_vfsvnode just masks the posted hint against the registered flags: if (kn->kn_sfflags & hint) kn->kn_fflags |= hint;. So a directory with NOTE_EXTEND registers without error and simply may never fire.
  • When it fires on a directory. kqueue(2): "For directory, reports that a directory entry was added or removed, as the result of rename operation. The NOTE_EXTEND event is not reported when a name is changed inside the directory." In code the only place is vop_rename_post: hint = NOTE_WRITE; if (a->a_fdvp == a->a_tdvp) {...} else { hint |= NOTE_EXTEND; ...}, delivered to the source and the target directory, i.e. only when an entry moves between two different directories.
  • Create/remove do not raise it. vop_create_post, vop_remove_post, vop_mknod_post, vop_symlink_post, vop_link_post post NOTE_WRITE on the directory; vop_mkdir_post/vop_rmdir_post post NOTE_WRITE | NOTE_LINK.

Suggestion to the author: since the Linux path in this PR already posts NOTE_WRITE | NOTE_EXTEND for a move between directories (the moves[...] handling), the Windows directory path could accept the NOTE_EXTEND registration the same way instead of throwing, and post NOTE_WRITE for added or removed entries as it does now. Whether Windows can tell a cross-directory move from a remove plus an add is for the author to judge; if it cannot, registering without ever delivering NOTE_EXTEND on directories would be the documented gap (a TechnicalDebt line), which matches how the other vnode cases are handled in this PR. Cloudberry only needs the registration to succeed to get past this point; I cannot tell from the stop whether it waits for the event.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116529746 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3764#issuecomment-6116529746). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T02:13:06Z. --- Follow-up on the Cloudberry stop above (`EVFILT_VNODE: NOTE_EXTEND on a directory not implemented`): what FreeBSD does with `NOTE_EXTEND` on a directory. Source: freebsd-src `release/13.2.0` (the PS5 kernel is FreeBSD-derived, but I have not checked that the console matches this version), `sys/kern/vfs_subr.c`, `lib/libc/sys/kqueue.2`. - **Registration is valid.** `vfs_kqfilter` only switches on the filter (`EVFILT_READ`/`EVFILT_WRITE`/`EVFILT_VNODE`, else `EINVAL`); it checks neither the vnode type nor `fflags`. `filt_vfsvnode` just masks the posted hint against the registered flags: `if (kn->kn_sfflags & hint) kn->kn_fflags |= hint;`. So a directory with `NOTE_EXTEND` registers without error and simply may never fire. - **When it fires on a directory.** `kqueue(2)`: "For directory, reports that a directory entry was added or removed, as the result of rename operation. The NOTE_EXTEND event is not reported when a name is changed inside the directory." In code the only place is `vop_rename_post`: `hint = NOTE_WRITE; if (a->a_fdvp == a->a_tdvp) {...} else { hint |= NOTE_EXTEND; ...}`, delivered to the source and the target directory, i.e. only when an entry moves between two different directories. - **Create/remove do not raise it.** `vop_create_post`, `vop_remove_post`, `vop_mknod_post`, `vop_symlink_post`, `vop_link_post` post `NOTE_WRITE` on the directory; `vop_mkdir_post`/`vop_rmdir_post` post `NOTE_WRITE | NOTE_LINK`. Suggestion to the author: since the Linux path in this PR already posts `NOTE_WRITE | NOTE_EXTEND` for a move between directories (the `moves[...]` handling), the Windows directory path could accept the `NOTE_EXTEND` registration the same way instead of throwing, and post `NOTE_WRITE` for added or removed entries as it does now. Whether Windows can tell a cross-directory move from a remove plus an add is for the author to judge; if it cannot, registering without ever delivering `NOTE_EXTEND` on directories would be the documented gap (a TechnicalDebt line), which matches how the other vnode cases are handled in this PR. Cloudberry only needs the registration to succeed to get past this point; I cannot tell from the stop whether it waits for the event. AI-assisted (Claude Code).
Dextroid17 commented 2026-10-12 19:08:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T19:08:42Z.

Review: COMMENTED


Linux build and run, and the one arm the Cloudberry stop turns on

I built this head on Linux and ran its own suite, a control against the parent implementation, and a probe for the registration the title stops at. Nothing below asks you to change something I have not measured on Linux — the one Windows-side suggestion is labelled as the part only you can judge. I have no PR against this path.

Refs in my checkout: the branch's own base (merge-base with upstream/main) is 33067ca0c, the head I built is 58c940edc, and upstream/main was 1acfa7f78 while I worked.

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON \
  -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build --target guest_kqueue_tests --parallel 16
ctest --test-dir build -R '^guest_kqueue$'                                    -> Passed 1.47 sec
./build/tests/guest_kqueue_tests   (five consecutive runs)                    -> exit 0 each
ctest -R '^(guest_kqueue|guest_equeue_events|guest_dup|guest_ppsa01530_exports|guest_socket_events)$'
  -> 100% tests passed out of 5, total 2.06 s

Control, meaning the parent implementation with this PR's own test kept: Equeue.cpp, Equeue.hpp, File/src/Open.cpp and File/src/Stdio.cpp taken from 33067ca0c, Equeue/src/FileEvent.cpp and Equeue/src/Kqueue.cpp removed. The test cannot run there, and it fails at link, not at run:

GuestKqueue.cpp:(.text.unlikely+0x678): undefined reference to `sceKernelAddFileEvent'
GuestKqueue.cpp:(.text.unlikely+0x9f0): undefined reference to `sceKernelDeleteFileEvent'
collect2: error: ld returned 1 exit status

7 undefined references in all (4 sceKernelAddFileEvent, 3 sceKernelDeleteFileEvent). kqueue_nid_postfix and kevent_nid_postfix are not among them: 33067ca0c already exports both as throwing stubs (core/libs/prx/libkernel/Equeue/Equeue.cpp:318, :323), so on the parent those two halves are runtime throws while the file-event pair does not exist to link against at all.

The Windows refusal, and the Linux arm that does not have it

Reading the registration as valid, and the recommendation that follows, were first put by @xXPBSXx earlier in this thread; what I can add is the Linux measurement behind them and the line-level check against the source the debt entry pins.

core/libs/prx/libkernel/Equeue/src/FileEvent.cpp:289-293, inside the #ifdef _WIN32 block that opens at :120 and closes at :479:

int OpenHostWatch(int descriptor, std::uint32_t notes, HostWatch& host) {
    if (const auto directory = File::DirectoryDescriptorPath(descriptor)) {
        if ((notes & NOTE_EXTEND) != 0) {
            NotImplemented_nid_no_patch("EVFILT_VNODE: NOTE_EXTEND on a directory");

The Linux OpenHostWatch at the same file's :447 takes that argument unnamed (int OpenHostWatch(int descriptor, std::uint32_t, HostWatch& host)), so the notes are never consulted on that path. I put Cloudberry's registration through the guest API on Linux:

1. register a DIRECTORY with NOTE_WRITE|NOTE_EXTEND:
   kevent -> 0   threw=no
2. rename INTO the watched directory:   poll -> 1  fflags=0x00000006   (NOTE_WRITE|NOTE_EXTEND)  MATCH
3. rename OUT of the watched directory: poll -> 1  fflags=0x00000006                              MATCH
4. rename WITHIN the watched directory: poll -> 1  fflags=0x00000002   (NOTE_WRITE only)          MATCH

So the registration is not refused on Linux, and that arm already delivers NOTE_EXTEND for an entry moved across the directory boundary (FileEvent.cpp:426-428). The console's own system software is FreeBSD-derived, so FreeBSD's kernel source is the reference for these semantics rather than an analogy, and it agrees the registration is legal: in sys/kern/vfs_subr.c at the commit the debt entry pins (34bd34750187), vfs_kqfilter (:4937) switches only on the filter and answers EINVAL for an unknown one, checking neither the vnode type nor fflags, and filt_vfsvnode (:5032) only masks the posted hint (:5038-5039, if (kn->kn_sfflags & hint) then kn->kn_fflags |= hint;) — a directory registered with NOTE_EXTEND registers fine and simply may never fire.

That makes the Windows throw a portability gap rather than a modelled refusal: the same registration is a working configuration on the Linux half of this same file. Accepting it on the Windows side, posting the NOTE_WRITE the directory handles already report for an added or removed entry and recording the undelivered NOTE_EXTEND in the debt entry as the file already does for its other cases, should clear the throw that is this title's current stop without inventing semantics — whether Cloudberry then waits for the event is not something the stop shows. Whether Windows can tell a cross-directory move from a remove plus an add is the part only you can judge. I cannot test any of the Windows half: I have no Windows machine here.

The arm the test does not cover

core/libs/tests/GuestKqueue.cpp:343 registers a directory with NoteWrite | NoteLink | NoteDelete | NoteRename — NOTE_EXTEND is not in that set — and its only rename case (:350-352) is within the directory, which is the moves[cookie] > 1 half of FileEvent.cpp:427. The NOTE_EXTEND half, an entry moved into or out of the watched directory, is exercised by no test on either host, and it is the arm that decides what this title needs. A case in DirectoryWatch() would cover it.

One caveat on that arm, measured at the host level with the library's own 16384-byte read buffer and directory mask (inotify_batch_probe.c): the "within" vs "across" classification is a property of a single read() chunk, so a pair split across two reads reports both halves as cross-directory.

rounds=200    rename_pairs=400   paired=800    singles=0
rounds=2000   rename_pairs=4000  paired=7984   singles=16     (repeated run: 16 again)

16 of 4000 is 0.4%, which is consistent with the split pairs needing more than one read chunk (about 512 events) of backlog to occur at all; the guest then sees a spurious NOTE_EXTEND rather than a missing event. Worth a debt sentence beside the Linux hint mapping, not a change.

Rebase state

git merge-tree --write-tree pr-3764 upstream/main exits 1 with four conflicting files: core/libs/prx/libkernel/CMakeLists.txt (main adds File/src/DescriptorControl.cpp where this adds the two new sources), File/src/Open.cpp and File/src/Stdio.cpp (main added the socket forwarding if (d >= GuestSockets::FirstDescriptor) return GuestSockets::Close(d) ... and KernelCloseSocket_nid_no_patch(d, &socketError) where this adds EqueueDescriptorClosed(d);), and docs/dev/TechnicalDebt.md (both sides append entries to the same list). All four are additive; the only judgement is where EqueueDescriptorClosed(d) belongs relative to main's new socket line.

Things that check out, so nobody has to re-derive them

  • The debt entry's citations resolve at its pinned commit: vfs_subr.c:5032 is filt_vfsvnode, vfs_kqfilter is at :4937, and the rename rule is at :4671-4691 — hint = NOTE_WRITE when both parents are the same directory (plus NOTE_LINK when a directory is replaced), hint |= NOTE_EXTEND when they differ (plus NOTE_LINK when the moved vnode is itself a directory). vop_create_post (:4608) and vop_remove_post (:4664-4665) post NOTE_WRITE on the directory, vop_mkdir_post (:4637) and vop_rmdir_post (:4713-4714) post NOTE_WRITE | NOTE_LINK, which is what the Linux mapping and DirectoryWatch() expect.
  • "adds whole when they share a bit with the requested fflags" is measurable and right. Re-registering a directory with NOTE_WRITE only and then moving an entry in across the boundary still reports 0x00000006, because TriggerVnode (FileEvent.cpp:486-488) tests the intersection and then ORs the whole hint — filt_vfsvnode's shape. I read it as stale registration notes first; the source says otherwise and the debt entry already states it.
  • The carried commits keep their author (David <[email protected]> on both, matching screamm/AnyPS5 feat/libkernel-kqueue's cd21c720e and a289fb403), and the change's own library sources are byte-identical to blawesom:verify/3461's head (FileEvent.cpp 02bfd335, Kqueue.cpp a60b3dbb; Equeue.cpp and Equeue.hpp do not differ at all). The body's "the resulting tree is identical" is literally not so — the branch is rebased onto newer main and adds two test commits, so the trees differ by 341 files — but the carried change itself is the same, which is the part that matters.
  • The merge bar here is a named title, and it is named twice over: Cloudberry Kingdom (PPSA23827) and Palworld (PPSA23126), with the log lines in #3461 and the two title runs above. No other open PR contains sceKernelAddFileEvent, sceKernelDeleteFileEvent or EVFILT_VNODE (the search API returns this PR only), so the checklist's no-duplicate line holds.
  • CI does not compile the Windows half of this change for a PR: the linux and windows jobs are gated (push || workflow_dispatch) && full == 'true' (.github/workflows/build.yml:191-193, :238-240), which is why gh pr checks 3764 reports both as skipping. The Windows evidence is @xXPBSXx's manual runs; the Linux run is what I have added here.

What I could not check: anything on Windows (the throw itself, and whether the directory handles can distinguish a cross-directory move); a title run, since the stop is on the platform I cannot run and no game data is staged here; and whether the console's kernel matches the FreeBSD 11 source the debt cites.

AI-assisted review; every number above comes from a command run here.

Hermes Agent 🤖 at your service

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5494984099 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3764#pullrequestreview-5494984099). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T19:08:42Z. **Review:** COMMENTED --- **Linux build and run, and the one arm the Cloudberry stop turns on** I built this head on Linux and ran its own suite, a control against the parent implementation, and a probe for the registration the title stops at. Nothing below asks you to change something I have not measured on Linux — the one Windows-side suggestion is labelled as the part only you can judge. I have no PR against this path. Refs in my checkout: the branch's own base (merge-base with `upstream/main`) is `33067ca0c`, the head I built is `58c940edc`, and `upstream/main` was `1acfa7f78` while I worked. ``` cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON \ -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DANYPS5_ENABLE_SPIRV_TOOLS=ON cmake --build build --target guest_kqueue_tests --parallel 16 ctest --test-dir build -R '^guest_kqueue$' -> Passed 1.47 sec ./build/tests/guest_kqueue_tests (five consecutive runs) -> exit 0 each ctest -R '^(guest_kqueue|guest_equeue_events|guest_dup|guest_ppsa01530_exports|guest_socket_events)$' -> 100% tests passed out of 5, total 2.06 s ``` Control, meaning the parent implementation with this PR's own test kept: `Equeue.cpp`, `Equeue.hpp`, `File/src/Open.cpp` and `File/src/Stdio.cpp` taken from `33067ca0c`, `Equeue/src/FileEvent.cpp` and `Equeue/src/Kqueue.cpp` removed. The test cannot run there, and it fails at **link**, not at run: ``` GuestKqueue.cpp:(.text.unlikely+0x678): undefined reference to `sceKernelAddFileEvent' GuestKqueue.cpp:(.text.unlikely+0x9f0): undefined reference to `sceKernelDeleteFileEvent' collect2: error: ld returned 1 exit status ``` 7 undefined references in all (4 `sceKernelAddFileEvent`, 3 `sceKernelDeleteFileEvent`). `kqueue_nid_postfix` and `kevent_nid_postfix` are *not* among them: `33067ca0c` already exports both as throwing stubs (`core/libs/prx/libkernel/Equeue/Equeue.cpp:318`, `:323`), so on the parent those two halves are runtime throws while the file-event pair does not exist to link against at all. **The Windows refusal, and the Linux arm that does not have it** Reading the registration as valid, and the recommendation that follows, were first put by @xXPBSXx earlier in this thread; what I can add is the Linux measurement behind them and the line-level check against the source the debt entry pins. `core/libs/prx/libkernel/Equeue/src/FileEvent.cpp:289-293`, inside the `#ifdef _WIN32` block that opens at `:120` and closes at `:479`: ```c int OpenHostWatch(int descriptor, std::uint32_t notes, HostWatch& host) { if (const auto directory = File::DirectoryDescriptorPath(descriptor)) { if ((notes & NOTE_EXTEND) != 0) { NotImplemented_nid_no_patch("EVFILT_VNODE: NOTE_EXTEND on a directory"); ``` The Linux `OpenHostWatch` at the same file's `:447` takes that argument **unnamed** (`int OpenHostWatch(int descriptor, std::uint32_t, HostWatch& host)`), so the notes are never consulted on that path. I put Cloudberry's registration through the guest API on Linux: ``` 1. register a DIRECTORY with NOTE_WRITE|NOTE_EXTEND: kevent -> 0 threw=no 2. rename INTO the watched directory: poll -> 1 fflags=0x00000006 (NOTE_WRITE|NOTE_EXTEND) MATCH 3. rename OUT of the watched directory: poll -> 1 fflags=0x00000006 MATCH 4. rename WITHIN the watched directory: poll -> 1 fflags=0x00000002 (NOTE_WRITE only) MATCH ``` So the registration is not refused on Linux, and that arm already *delivers* `NOTE_EXTEND` for an entry moved across the directory boundary (`FileEvent.cpp:426-428`). The console's own system software is FreeBSD-derived, so FreeBSD's kernel source is the reference for these semantics rather than an analogy, and it agrees the registration is legal: in `sys/kern/vfs_subr.c` at the commit the debt entry pins (`34bd34750187`), `vfs_kqfilter` (`:4937`) switches only on the filter and answers `EINVAL` for an unknown one, checking neither the vnode type nor `fflags`, and `filt_vfsvnode` (`:5032`) only masks the posted hint (`:5038-5039`, `if (kn->kn_sfflags & hint)` then `kn->kn_fflags |= hint;`) — a directory registered with `NOTE_EXTEND` registers fine and simply may never fire. That makes the Windows throw a portability gap rather than a modelled refusal: the same registration is a working configuration on the Linux half of this same file. Accepting it on the Windows side, posting the `NOTE_WRITE` the directory handles already report for an added or removed entry and recording the undelivered `NOTE_EXTEND` in the debt entry as the file already does for its other cases, should clear the throw that is this title's current stop without inventing semantics — whether Cloudberry then waits for the event is not something the stop shows. Whether Windows can tell a cross-directory move from a remove plus an add is the part only you can judge. I cannot test any of the Windows half: I have no Windows machine here. **The arm the test does not cover** `core/libs/tests/GuestKqueue.cpp:343` registers a directory with `NoteWrite | NoteLink | NoteDelete | NoteRename` — `NOTE_EXTEND` is not in that set — and its only rename case (`:350-352`) is within the directory, which is the `moves[cookie] > 1` half of `FileEvent.cpp:427`. The `NOTE_EXTEND` half, an entry moved into or out of the watched directory, is exercised by no test on either host, and it is the arm that decides what this title needs. A case in `DirectoryWatch()` would cover it. One caveat on that arm, measured at the host level with the library's own 16384-byte read buffer and directory mask (`inotify_batch_probe.c`): the "within" vs "across" classification is a property of a single `read()` chunk, so a pair split across two reads reports both halves as cross-directory. ``` rounds=200 rename_pairs=400 paired=800 singles=0 rounds=2000 rename_pairs=4000 paired=7984 singles=16 (repeated run: 16 again) ``` 16 of 4000 is 0.4%, which is consistent with the split pairs needing more than one read chunk (about 512 events) of backlog to occur at all; the guest then sees a spurious `NOTE_EXTEND` rather than a missing event. Worth a debt sentence beside the Linux hint mapping, not a change. **Rebase state** `git merge-tree --write-tree pr-3764 upstream/main` exits 1 with four conflicting files: `core/libs/prx/libkernel/CMakeLists.txt` (main adds `File/src/DescriptorControl.cpp` where this adds the two new sources), `File/src/Open.cpp` and `File/src/Stdio.cpp` (main added the socket forwarding `if (d >= GuestSockets::FirstDescriptor) return GuestSockets::Close(d) ...` and `KernelCloseSocket_nid_no_patch(d, &socketError)` where this adds `EqueueDescriptorClosed(d);`), and `docs/dev/TechnicalDebt.md` (both sides append entries to the same list). All four are additive; the only judgement is where `EqueueDescriptorClosed(d)` belongs relative to main's new socket line. **Things that check out, so nobody has to re-derive them** - The debt entry's citations resolve at its pinned commit: `vfs_subr.c:5032` is `filt_vfsvnode`, `vfs_kqfilter` is at `:4937`, and the rename rule is at `:4671-4691` — `hint = NOTE_WRITE` when both parents are the same directory (plus `NOTE_LINK` when a directory is replaced), `hint |= NOTE_EXTEND` when they differ (plus `NOTE_LINK` when the moved vnode is itself a directory). `vop_create_post` (`:4608`) and `vop_remove_post` (`:4664-4665`) post `NOTE_WRITE` on the directory, `vop_mkdir_post` (`:4637`) and `vop_rmdir_post` (`:4713-4714`) post `NOTE_WRITE | NOTE_LINK`, which is what the Linux mapping and `DirectoryWatch()` expect. - "adds whole when they share a bit with the requested `fflags`" is measurable and right. Re-registering a directory with `NOTE_WRITE` only and then moving an entry in across the boundary still reports `0x00000006`, because `TriggerVnode` (`FileEvent.cpp:486-488`) tests the intersection and then ORs the whole hint — `filt_vfsvnode`'s shape. I read it as stale registration notes first; the source says otherwise and the debt entry already states it. - The carried commits keep their author (`David <[email protected]>` on both, matching `screamm/AnyPS5 feat/libkernel-kqueue`'s `cd21c720e` and `a289fb403`), and the change's own library sources are byte-identical to `blawesom:verify/3461`'s head (`FileEvent.cpp` `02bfd335`, `Kqueue.cpp` `a60b3dbb`; `Equeue.cpp` and `Equeue.hpp` do not differ at all). The body's "the resulting tree is identical" is literally not so — the branch is rebased onto newer main and adds two test commits, so the trees differ by 341 files — but the carried change itself is the same, which is the part that matters. - The merge bar here is a named title, and it is named twice over: Cloudberry Kingdom (PPSA23827) and Palworld (PPSA23126), with the log lines in #3461 and the two title runs above. No other open PR contains `sceKernelAddFileEvent`, `sceKernelDeleteFileEvent` or `EVFILT_VNODE` (the search API returns this PR only), so the checklist's no-duplicate line holds. - CI does not compile the Windows half of this change for a PR: the `linux` and `windows` jobs are gated `(push || workflow_dispatch) && full == 'true'` (`.github/workflows/build.yml:191-193`, `:238-240`), which is why `gh pr checks 3764` reports both as skipping. The Windows evidence is @xXPBSXx's manual runs; the Linux run is what I have added here. **What I could not check:** anything on Windows (the throw itself, and whether the directory handles can distinguish a cross-directory move); a title run, since the stop is on the platform I cannot run and no game data is staged here; and whether the console's kernel matches the FreeBSD 11 source the debt cites. AI-assisted review; every number above comes from a command run here. Hermes Agent 🤖 at your service
adriadam10 commented 2026-10-12 20:48:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:48:28Z.


Rebased onto current main (conflicts in libkernel/CMakeLists.txt, File/src/Open.cpp, File/src/Stdio.cpp, and the TechnicalDebt entries, which now live in docs/dev/debt/libkernel.md and libSceNet.md). The four commits are kept; I added one on top:

  • FileEvent.cpp: a directory registered with NOTE_EXTEND is no longer refused on Windows. FreeBSD's vfs_kqfilter checks neither the vnode type nor fflags, and this is the throw Cloudberry Kingdom (PPSA23827) stops at in @xXPBSXx's run. Windows never delivers it (the directory handle cannot tell a move between directories from a removal plus an addition); the debt entry says so. Suggested in this thread by @xXPBSXx and @Dextroid17.

Checked on Linux: build and ctest of libkernel + core/libs on the rebased head are green (guest_kqueue, guest_equeue_events, guest_dup, guest_socket_events, guest_ppsa01530_exports 10/10 repeated; guest_kernel_fcntl aborted once in the parallel full run and passes repeated). guest_kqueue does not link without the change. Not checked here: Windows and any title run; the NOTE_EXTEND arm for a move between directories has no test.

Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132353418 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3764#issuecomment-6132353418). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-12T20:48:28Z. --- Rebased onto current `main` (conflicts in `libkernel/CMakeLists.txt`, `File/src/Open.cpp`, `File/src/Stdio.cpp`, and the TechnicalDebt entries, which now live in `docs/dev/debt/libkernel.md` and `libSceNet.md`). The four commits are kept; I added one on top: - `FileEvent.cpp`: a directory registered with `NOTE_EXTEND` is no longer refused on Windows. FreeBSD's `vfs_kqfilter` checks neither the vnode type nor `fflags`, and this is the throw Cloudberry Kingdom (PPSA23827) stops at in @xXPBSXx's run. Windows never delivers it (the directory handle cannot tell a move between directories from a removal plus an addition); the debt entry says so. Suggested in this thread by @xXPBSXx and @Dextroid17. Checked on Linux: build and ctest of `libkernel` + `core/libs` on the rebased head are green (`guest_kqueue`, `guest_equeue_events`, `guest_dup`, `guest_socket_events`, `guest_ppsa01530_exports` 10/10 repeated; `guest_kernel_fcntl` aborted once in the parallel full run and passes repeated). `guest_kqueue` does not link without the change. Not checked here: Windows and any title run; the `NOTE_EXTEND` arm for a move between directories has no test. Merging once CI is green.
github-actions[bot] commented 2026-10-12 20:51:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T20:51:54Z.


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.

Pull request Conflicting files (lines on main) Same exports Same new files
#4101 docs/dev/debt/libkernel.md L93
#4391 core/libs/prx/libkernel/CMakeLists.txt L1023
core/libs/prx/libkernel/File/src/Open.cpp L223
core/libs/prx/libkernel/File/src/Stdio.cpp L498, L546-547, L572-574, L579, L595
#4640 core/libs/prx/libkernel/File/src/Stdio.cpp L579
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132403218 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3764#issuecomment-6132403218). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T20:51:54Z. --- <!-- pr-overlap --> 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**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4101 | `docs/dev/debt/libkernel.md` [L93](https://github.com/boykopovar/AnyPS5/blob/c8debc778879d9ec234121906152440d7d735cea/docs/dev/debt/libkernel.md#L93) | | | | #4391 | `core/libs/prx/libkernel/CMakeLists.txt` [L1023](https://github.com/boykopovar/AnyPS5/blob/c8debc778879d9ec234121906152440d7d735cea/core/libs/prx/libkernel/CMakeLists.txt#L1023)<br>`core/libs/prx/libkernel/File/src/Open.cpp` [L223](https://github.com/boykopovar/AnyPS5/blob/c8debc778879d9ec234121906152440d7d735cea/core/libs/prx/libkernel/File/src/Open.cpp#L223)<br>`core/libs/prx/libkernel/File/src/Stdio.cpp` [L498](https://github.com/boykopovar/AnyPS5/blob/c8debc778879d9ec234121906152440d7d735cea/core/libs/prx/libkernel/File/src/Stdio.cpp#L498), [L546-547](https://github.com/boykopovar/AnyPS5/blob/c8debc778879d9ec234121906152440d7d735cea/core/libs/prx/libkernel/File/src/Stdio.cpp#L546-L547), [L572-574](https://github.com/boykopovar/AnyPS5/blob/c8debc778879d9ec234121906152440d7d735cea/core/libs/prx/libkernel/File/src/Stdio.cpp#L572-L574), [L579](https://github.com/boykopovar/AnyPS5/blob/c8debc778879d9ec234121906152440d7d735cea/core/libs/prx/libkernel/File/src/Stdio.cpp#L579), [L595](https://github.com/boykopovar/AnyPS5/blob/c8debc778879d9ec234121906152440d7d735cea/core/libs/prx/libkernel/File/src/Stdio.cpp#L595) | | | | #4640 | `core/libs/prx/libkernel/File/src/Stdio.cpp` [L579](https://github.com/boykopovar/AnyPS5/blob/c8debc778879d9ec234121906152440d7d735cea/core/libs/prx/libkernel/File/src/Stdio.cpp#L579) | | |
MarcZX10 commented 2026-10-12 21:04:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T21:04:07Z.


The overlap bot flagged my #4640 because it also updates the Windows dup2 block in Stdio.cpp. I rebased #4640 onto current main and preserved the existing EqueueDescriptorClosed(to) plus the directory-descriptor bookkeeping while adding the standard-handle save/restore. There is no API dependency between the PRs, but the shared hunk may need a rebase after either lands.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132576565 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3764#issuecomment-6132576565). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T21:04:07Z. --- The overlap bot flagged my #4640 because it also updates the Windows `dup2` block in `Stdio.cpp`. I rebased #4640 onto current main and preserved the existing `EqueueDescriptorClosed(to)` plus the directory-descriptor bookkeeping while adding the standard-handle save/restore. There is no API dependency between the PRs, but the shared hunk may need a rebase after either lands.
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!3764
No description provided.