feat(libkernel): report open, read and close notes on watched files #7121

Open
GitamarT045T3R wants to merge 1 commit from upstream-pr/7121 into main
GitamarT045T3R commented 2026-10-17 12:20:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-17T12:20:46Z.


What

EVFILT_VNODE (kevent) and sceKernelAddFileEvent threw for NOTE_OPEN, NOTE_CLOSE, NOTE_CLOSE_WRITE, NOTE_READ, NOTE_REVOKE and unknown bits, and for a descriptor that is not a file, a directory, a pipe or a socket. They now follow FreeBSD 11:

Case FreeBSD 11 source Now
open vop_open_post NOTE_OPEN after a successful open of the file (open, openat, sceKernelOpen)
read vop_read_post, vop_readdir_post NOTE_READ after a successful read, readv, pread, preadv, their sceKernel* forms, AIO read or getdents/getdirentries, zero bytes included
close vop_close_post the close of the last descriptor of an open file reports NOTE_CLOSE, or NOTE_CLOSE_WRITE when it was opened for writing; dup2 onto it counts; a dup still open defers it
own descriptor closefp calls knote_fdclose first a watch registered through the closed descriptor is removed before the close is reported
NOTE_REVOKE, unknown bits vfs_kqfilter does not check fflags accepted; never reported, as no descriptor is revoked
character device no_kqfilter ENODEV (/dev/urandom, the null device)
terminal ttydev_kqfilter EINVAL

Windows and macOS have no host notification for opens, reads or closes, so these notes come from libkernel's own calls on every host: each vnode watch is recorded with the st_dev and st_ino that fstat reports, and the open, read and close paths deliver to the watches of the same file. Nothing is looked up while no watch exists. The last-descriptor test uses the open-file status that dup already shares; the write test asks the host access mode as fcntl(F_GETFL) does. A file read from app0.zar is watched for these notes only, as the archive never changes.

Gaps, in the libkernel debt entry: libc streams (fopen, fread) read through the host C runtime and raise none of these notes; other host processes neither; JIT shared memory is watched as its host file, where FreeBSD shared memory answers EINVAL.

Overlaps: #7088 (kevent read and write on regular files) changes the VnodeWatch constructor, and #7092 (NOTE_LOWAT) the lines next to the removed fflags check in Kqueue.cpp; both merge into this with one-line conflicts, whichever lands second.

Tested

Windows 10 Pro 22H2 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release, BUILD_TESTING=ON, on main e09dbc2b4:

  • guest_kqueue with two new cases. AccessNotes: open, read, read at end of file and pread of another descriptor report NOTE_OPEN then NOTE_READ; closing a duped descriptor reports nothing until the last copy closes (NOTE_CLOSE); a read-write descriptor closes with NOTE_CLOSE_WRITE; dup2 onto an open descriptor reports NOTE_CLOSE; sceKernelAddFileEvent gets NOTE_OPEN with its udata; closing the watched descriptor removes its own watch while a watch through another descriptor gets NOTE_CLOSE; /dev/urandom fails with ENODEV from both calls. DirectoryAccessNotes: open, getdents and close of a directory. FileWatch now checks that NOTE_REVOKE with an unknown bit is accepted and reports nothing. Passes 20 of 20 repeated runs.
  • Before: the same test against main's libkernel fails with EVFILT_VNODE: fflags 1048640 not implemented.
  • Full ctest -j 12: 1379 of 1382 pass. The three others are unrelated: select_tests needs symbolic link privilege on Windows, and agc_driver_f16_fma_denormal_modes and agc_driver_fma_mix_f16_denormal_modes get NVIDIA's f16 NaN (0x7fff) where they expect 0xfe00.
  • python tools/check_conventions.py --base origin/main passes.
  • Not built or run on Linux or macOS; there the device check uses isatty, and the notes come from the same shared code.

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: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4899997248 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7121). Originally posted by [GitamarT045T3R](https://github.com/GitamarT045T3R) on 2026-10-17T12:20:46Z. --- ### What `EVFILT_VNODE` (kevent) and `sceKernelAddFileEvent` threw for `NOTE_OPEN`, `NOTE_CLOSE`, `NOTE_CLOSE_WRITE`, `NOTE_READ`, `NOTE_REVOKE` and unknown bits, and for a descriptor that is not a file, a directory, a pipe or a socket. They now follow FreeBSD 11: | Case | FreeBSD 11 source | Now | | --- | --- | --- | | open | [`vop_open_post`](https://github.com/freebsd/freebsd-src/blob/34bd34750187bae02a0086402c78c031c59dd8b3/sys/kern/vfs_subr.c#L4746) | `NOTE_OPEN` after a successful open of the file (`open`, `openat`, `sceKernelOpen`) | | read | `vop_read_post`, `vop_readdir_post` | `NOTE_READ` after a successful `read`, `readv`, `pread`, `preadv`, their `sceKernel*` forms, AIO read or `getdents`/`getdirentries`, zero bytes included | | close | `vop_close_post` | the close of the last descriptor of an open file reports `NOTE_CLOSE`, or `NOTE_CLOSE_WRITE` when it was opened for writing; `dup2` onto it counts; a `dup` still open defers it | | own descriptor | [`closefp`](https://github.com/freebsd/freebsd-src/blob/34bd34750187bae02a0086402c78c031c59dd8b3/sys/kern/kern_descrip.c#L1155) calls `knote_fdclose` first | a watch registered through the closed descriptor is removed before the close is reported | | `NOTE_REVOKE`, unknown bits | `vfs_kqfilter` does not check `fflags` | accepted; never reported, as no descriptor is revoked | | character device | [`no_kqfilter`](https://github.com/freebsd/freebsd-src/blob/34bd34750187bae02a0086402c78c031c59dd8b3/sys/kern/kern_conf.c#L332) | `ENODEV` (`/dev/urandom`, the null device) | | terminal | [`ttydev_kqfilter`](https://github.com/freebsd/freebsd-src/blob/34bd34750187bae02a0086402c78c031c59dd8b3/sys/kern/tty.c#L703) | `EINVAL` | Windows and macOS have no host notification for opens, reads or closes, so these notes come from libkernel's own calls on every host: each vnode watch is recorded with the `st_dev` and `st_ino` that `fstat` reports, and the open, read and close paths deliver to the watches of the same file. Nothing is looked up while no watch exists. The last-descriptor test uses the open-file status that `dup` already shares; the write test asks the host access mode as `fcntl(F_GETFL)` does. A file read from app0.zar is watched for these notes only, as the archive never changes. Gaps, in the libkernel debt entry: libc streams (`fopen`, `fread`) read through the host C runtime and raise none of these notes; other host processes neither; JIT shared memory is watched as its host file, where FreeBSD shared memory answers `EINVAL`. Overlaps: #7088 (kevent read and write on regular files) changes the `VnodeWatch` constructor, and #7092 (`NOTE_LOWAT`) the lines next to the removed `fflags` check in `Kqueue.cpp`; both merge into this with one-line conflicts, whichever lands second. ### Tested Windows 10 Pro 22H2 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release, `BUILD_TESTING=ON`, on `main` `e09dbc2b4`: - `guest_kqueue` with two new cases. `AccessNotes`: open, read, read at end of file and `pread` of another descriptor report `NOTE_OPEN` then `NOTE_READ`; closing a `dup`ed descriptor reports nothing until the last copy closes (`NOTE_CLOSE`); a read-write descriptor closes with `NOTE_CLOSE_WRITE`; `dup2` onto an open descriptor reports `NOTE_CLOSE`; `sceKernelAddFileEvent` gets `NOTE_OPEN` with its `udata`; closing the watched descriptor removes its own watch while a watch through another descriptor gets `NOTE_CLOSE`; `/dev/urandom` fails with `ENODEV` from both calls. `DirectoryAccessNotes`: open, `getdents` and close of a directory. `FileWatch` now checks that `NOTE_REVOKE` with an unknown bit is accepted and reports nothing. Passes 20 of 20 repeated runs. - Before: the same test against `main`'s libkernel fails with `EVFILT_VNODE: fflags 1048640 not implemented`. - Full `ctest -j 12`: 1379 of 1382 pass. The three others are unrelated: `select_tests` needs symbolic link privilege on Windows, and `agc_driver_f16_fma_denormal_modes` and `agc_driver_fma_mix_f16_denormal_modes` get NVIDIA's f16 NaN (0x7fff) where they expect 0xfe00. - `python tools/check_conventions.py --base origin/main` passes. - Not built or run on Linux or macOS; there the device check uses `isatty`, and the notes come from the same shared code. ### 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: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
jotitadev commented 2026-10-17 15:16:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-17T15:16:34Z.

Review: COMMENTED


Linux run, since the description notes the change was not built or run on Linux or macOS.

Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, full build.
Head 47f1ea309 merged onto main 40315fcf8 (clean merge).

  • guest_kqueue, with the new AccessNotes and DirectoryAccessNotes cases, passes on Linux. The related event, poll, select, AIO and filesystem tests (ctest -R "kqueue|equeue|poll|select|aio|file_event|vnode|filesystem", 18 tests) also pass.
  • Test file only, on main: guest_kqueue aborts with EVFILT_VNODE: fflags 1048640 not implemented, the same failure as on Windows.
  • Non-GPU suite (ctest -E "^agc|gpu|vulkan|video_out"): 682/682, same as main on this machine.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5558428424 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7121#pullrequestreview-5558428424). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-17T15:16:34Z. **Review:** COMMENTED --- Linux run, since the description notes the change was not built or run on Linux or macOS. Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, `BUILD_TESTING=ON`, full build. Head `47f1ea309` merged onto `main` `40315fcf8` (clean merge). - `guest_kqueue`, with the new `AccessNotes` and `DirectoryAccessNotes` cases, passes on Linux. The related event, poll, select, AIO and filesystem tests (`ctest -R "kqueue|equeue|poll|select|aio|file_event|vnode|filesystem"`, 18 tests) also pass. - Test file only, on `main`: `guest_kqueue` aborts with `EVFILT_VNODE: fflags 1048640 not implemented`, the same failure as on Windows. - Non-GPU suite (`ctest -E "^agc|gpu|vulkan|video_out"`): 682/682, same as `main` on this machine. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
GitamarT045T3R commented 2026-10-17 15:40:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-17T15:40:43Z.


@jotitadev thank you for the Linux run; it covers the isatty device check and the inotify host I could not run.

On the overlap table: none of the listed pull requests implements the same notes or exports, and each conflict is two additions next to each other, resolved by keeping both:

  • #7088 (kevent read and write on regular files) adds a filter to the VnodeWatch constructor; whichever lands second passes EVFILT_VNODE in the other's call.
  • #7092 (NOTE_LOWAT) rewrites the lines next to the fflags check this removes from Kqueue.cpp.
  • #7139 (poll as FreeBSD does) appends IsVnode where this appends LastDescriptorOfOpenFile and OpenFileWrites in DescriptorControl.
  • #7075 and #7129 add debt entries next to the EVFILT_VNODE entry this edits.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235924608 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7121#issuecomment-6235924608). Originally posted by [GitamarT045T3R](https://github.com/GitamarT045T3R) on 2026-10-17T15:40:43Z. --- @jotitadev thank you for the Linux run; it covers the `isatty` device check and the inotify host I could not run. On the overlap table: none of the listed pull requests implements the same notes or exports, and each conflict is two additions next to each other, resolved by keeping both: - #7088 (kevent read and write on regular files) adds a filter to the `VnodeWatch` constructor; whichever lands second passes `EVFILT_VNODE` in the other's call. - #7092 (`NOTE_LOWAT`) rewrites the lines next to the `fflags` check this removes from `Kqueue.cpp`. - #7139 (poll as FreeBSD does) appends `IsVnode` where this appends `LastDescriptorOfOpenFile` and `OpenFileWrites` in `DescriptorControl`. - #7075 and #7129 add debt entries next to the `EVFILT_VNODE` entry this edits.
blawesom commented 2026-10-18 10:05:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-18T10:05:37Z.


Rebase handoff — rebased onto current main (authorship unchanged). The conflicts reconcile main's newer NOTE_LOWAT/RequireVnodeNotes evolution with this PR's open/read/close note reporting:

  • Kqueue.cpp: main's lowWater-aware ModifyKnote kept; your NOTE_LOWAT stub is superseded by main's real support
  • FileEvent.cpp/Equeue.hpp: main's RequireVnodeNotes validation removed, per this PR's design — your AddVnodeEvent takes any fflags and passes them to the watch (your test's NoteRevoke | 0x00100000 acceptance documents that), and the auto-merge had half-restored main's validation which broke it
  • DescriptorControl.cpp/.hpp: main's IsVnode kept alongside your LastDescriptorOfOpenFile/OpenFileWrites

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; the kqueue tests pass including the open/read/close coverage; full suite green apart from the known main regression (agc_driver_tessellation segfault — Mesa, #5444), not this PR.

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/7121
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is c5c56b51c.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6248564462 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7121#issuecomment-6248564462). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-18T10:05:37Z. --- **Rebase handoff** — rebased onto current `main` (authorship unchanged). The conflicts reconcile `main`'s newer NOTE_LOWAT/RequireVnodeNotes evolution with this PR's open/read/close note reporting: - `Kqueue.cpp`: `main`'s lowWater-aware `ModifyKnote` kept; your `NOTE_LOWAT` stub is superseded by `main`'s real support - `FileEvent.cpp`/`Equeue.hpp`: `main`'s `RequireVnodeNotes` validation **removed**, per this PR's design — your `AddVnodeEvent` takes any fflags and passes them to the watch (your test's `NoteRevoke | 0x00100000` acceptance documents that), and the auto-merge had half-restored `main`'s validation which broke it - `DescriptorControl.cpp`/`.hpp`: `main`'s `IsVnode` kept alongside your `LastDescriptorOfOpenFile`/`OpenFileWrites` Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): builds; conventions pass; the kqueue tests pass including the open/read/close coverage; **full suite green apart from the known `main` regression** (`agc_driver_tessellation` segfault — Mesa, #5444), not this PR. **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/7121 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `c5c56b51c`.
GitamarT045T3R commented 2026-10-18 12:20:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-18T12:20:43Z.


@blawesom thank you for the rebase and the Linux run. I rebased onto main 0d078f75d myself as 702ba97dd: the code matches your c5c56b51c line for line (main's low-water ModifyKnote kept without the RequireVnodeNotes call, IsVnode kept next to LastDescriptorOfOpenFile and OpenFileWrites), but in your docs/dev/debt/libkernel.md the EVFILT_VNODE entry lost its line break and runs into the sem_timedwait entry, so I kept mine.

On Windows after the rebase: guest_kqueue, guest_select, the AIO and poll tests and guest_filesystem pass 5 of 5; the full ctest is 1476 of 1478, the two others (guest_math, guest_err, "vwarnx stack and floating arguments") failing the same way with main's libkernel.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249845330 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7121#issuecomment-6249845330). Originally posted by [GitamarT045T3R](https://github.com/GitamarT045T3R) on 2026-10-18T12:20:43Z. --- @blawesom thank you for the rebase and the Linux run. I rebased onto `main` `0d078f75d` myself as 702ba97dd: the code matches your c5c56b51c line for line (`main`'s low-water `ModifyKnote` kept without the `RequireVnodeNotes` call, `IsVnode` kept next to `LastDescriptorOfOpenFile` and `OpenFileWrites`), but in your `docs/dev/debt/libkernel.md` the `EVFILT_VNODE` entry lost its line break and runs into the `sem_timedwait` entry, so I kept mine. On Windows after the rebase: `guest_kqueue`, `guest_select`, the AIO and poll tests and `guest_filesystem` pass 5 of 5; the full `ctest` is 1476 of 1478, the two others (`guest_math`, `guest_err`, "vwarnx stack and floating arguments") failing the same way with `main`'s libkernel.
jotitadev commented 2026-10-18 16:56:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T16:56:55Z.

Review: COMMENTED


macOS run of 702ba97dd. main cannot build the libraries on macOS on its own, so I ran it on top of #7332, which includes @mugurc's macOS file code.

Machine: Apple M2 Max, macOS 27.2 (26B5112a), Apple clang 21, full x86-64 build under Rosetta 2. Tree: main d3d8d79c5 + #7332 690c044a6 + this PR (clean merge, no build errors).

guest_kqueue fails 5/5. On #7332 alone it passes. File AccessNotes passes. DirectoryAccessNotes stops at the getdents check: getdents returns 24 bytes, but the knote has no NOTE_READ (fflags 0).

Cause: this PR wraps the Windows and Linux sceKernelGetdirentries returns in EqueueNotedRead. The macOS branch of that function (#elif defined(__APPLE__) in File/src/Stdio.cpp, from mugurc's feat/libkernel-files-macos, carried by #7332 and not on main yet) still ends with return static_cast<int>(written);. Wrapping that return as well fixes it:

     errno = savedErrno;
-    return static_cast<int>(written);
+    return EqueueNotedRead(fd, static_cast<int>(written));
 }

With that line, guest_kqueue passes 5/5 and the non-GPU suite is 706/708 (ctest -E "^agc|video_?out|flip|display" -j4). The two failures are precise_wait and guest_refused_connect, the same host-timing and XNU-backlog failures #7332 has without this PR. Nothing to change here while the macOS branch is not on main. Whichever of this PR and the macOS file code lands second needs the line above. cc @ycarogabriel-lgtm @mugurc

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5563959359 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7121#pullrequestreview-5563959359). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-18T16:56:55Z. **Review:** COMMENTED --- macOS run of `702ba97dd`. `main` cannot build the libraries on macOS on its own, so I ran it on top of #7332, which includes @mugurc's macOS file code. Machine: Apple M2 Max, macOS 27.2 (26B5112a), Apple clang 21, full x86-64 build under Rosetta 2. Tree: `main` d3d8d79c5 + #7332 `690c044a6` + this PR (clean merge, no build errors). **`guest_kqueue` fails 5/5.** On #7332 alone it passes. File `AccessNotes` passes. `DirectoryAccessNotes` stops at the `getdents` check: `getdents` returns 24 bytes, but the knote has no `NOTE_READ` (fflags 0). Cause: this PR wraps the Windows and Linux `sceKernelGetdirentries` returns in `EqueueNotedRead`. The macOS branch of that function (`#elif defined(__APPLE__)` in `File/src/Stdio.cpp`, from mugurc's `feat/libkernel-files-macos`, carried by #7332 and not on `main` yet) still ends with `return static_cast<int>(written);`. Wrapping that return as well fixes it: ```diff errno = savedErrno; - return static_cast<int>(written); + return EqueueNotedRead(fd, static_cast<int>(written)); } ``` With that line, `guest_kqueue` passes 5/5 and the non-GPU suite is 706/708 (`ctest -E "^agc|video_?out|flip|display" -j4`). The two failures are `precise_wait` and `guest_refused_connect`, the same host-timing and XNU-backlog failures #7332 has without this PR. Nothing to change here while the macOS branch is not on `main`. Whichever of this PR and the macOS file code lands second needs the line above. cc @ycarogabriel-lgtm @mugurc Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
ycarogabriel-lgtm commented 2026-10-19 00:13:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycarogabriel-lgtm on 2026-10-19T00:13:34Z.


Ran this on macOS, since it was not built there: Apple M1, macOS 26.6.2 (25G83), x86-64 build under Rosetta 2, AppleClang 21. Merged into the macOS host branch of #7332 (57bccfbfc, main at d71853cf2) together with #7121, #7475, #7490, #7507 and #7612; Release build.

  • Everything builds.
  • guest_kqueue failed in DirectoryAccessNotes: getdents on the listing descriptor delivered no NOTE_READ.
  • The cause is not in this change. #7332 adds a third sceKernelGetdirentries for macOS (#elif defined(__APPLE__) in Stdio.cpp), and only the Windows and Linux versions route their result through EqueueNotedRead.
  • Routing the macOS version's final return the same way makes guest_kqueue pass, 3/3. The rest of the suite without the GPU tests passes as well.
  • If this lands first, #7332 will take that one-line change in its next merge of main. Nothing is needed here.

AI-assisted: yes (Claude Code). I ran the build and tests on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6256923133 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7121#issuecomment-6256923133). Originally posted by [ycarogabriel-lgtm](https://github.com/ycarogabriel-lgtm) on 2026-10-19T00:13:34Z. --- Ran this on macOS, since it was not built there: Apple M1, macOS 26.6.2 (25G83), x86-64 build under Rosetta 2, AppleClang 21. Merged into the macOS host branch of #7332 (`57bccfbfc`, `main` at `d71853cf2`) together with #7121, #7475, #7490, #7507 and #7612; `Release` build. - Everything builds. - `guest_kqueue` failed in `DirectoryAccessNotes`: `getdents` on the listing descriptor delivered no `NOTE_READ`. - The cause is not in this change. #7332 adds a third `sceKernelGetdirentries` for macOS (`#elif defined(__APPLE__)` in `Stdio.cpp`), and only the Windows and Linux versions route their result through `EqueueNotedRead`. - Routing the macOS version's final `return` the same way makes `guest_kqueue` pass, 3/3. The rest of the suite without the GPU tests passes as well. - If this lands first, #7332 will take that one-line change in its next merge of `main`. Nothing is needed here. AI-assisted: yes (Claude Code). I ran the build and tests on my machine.
GitamarT045T3R commented 2026-10-21 16:59:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-21T16:59:24Z.


Rebased onto main cecb540a6 (a5eeb38ff) on top of @adriadam10's rebase. sceKernelGetdirentries on Windows now passes basep to ReadDirectoryDescriptor, and its result still goes through EqueueNotedRead.

The debt change now cuts instead of rewriting, as CONTRIBUTING asks: the EVFILT_VNODE entry only loses the sentence that said these notes throw, and what stays open (libc streams and other host processes raise no access notes, the folded st_ino on Windows, NOTE_REVOKE never reported, JIT shared memory) is a new 779-character entry. check_conventions still warns about the EVFILT_VNODE entry itself, which is 4405 characters on main and 4245 after this; splitting it is not part of this pull request.

macOS (@jotitadev, @ycarogabriel-lgtm): the macOS sceKernelGetdirentries is not on main yet, so nothing changes here; whichever of this and #7332 lands second wraps its return in EqueueNotedRead. On Windows guest_kqueue, guest_select, guest_poll, guest_aio and guest_filesystem pass 5 of 5.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6321694846 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7121#issuecomment-6321694846). Originally posted by [GitamarT045T3R](https://github.com/GitamarT045T3R) on 2026-10-21T16:59:24Z. --- Rebased onto `main` `cecb540a6` (a5eeb38ff) on top of @adriadam10's rebase. `sceKernelGetdirentries` on Windows now passes `basep` to `ReadDirectoryDescriptor`, and its result still goes through `EqueueNotedRead`. The debt change now cuts instead of rewriting, as CONTRIBUTING asks: the `EVFILT_VNODE` entry only loses the sentence that said these notes throw, and what stays open (libc streams and other host processes raise no access notes, the folded `st_ino` on Windows, `NOTE_REVOKE` never reported, JIT shared memory) is a new 779-character entry. `check_conventions` still warns about the `EVFILT_VNODE` entry itself, which is 4405 characters on `main` and 4245 after this; splitting it is not part of this pull request. macOS (@jotitadev, @ycarogabriel-lgtm): the macOS `sceKernelGetdirentries` is not on `main` yet, so nothing changes here; whichever of this and #7332 lands second wraps its return in `EqueueNotedRead`. On Windows `guest_kqueue`, `guest_select`, `guest_poll`, `guest_aio` and `guest_filesystem` pass 5 of 5.
CnRJay commented 2026-11-01 20:03:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T20:03:24Z.

Review: COMMENTED


Correction (2026-11-01): the title-ID/log demand below is not a CONTRIBUTING requirement; Unblocks: none is allowed. The technical points below are unaffected.

1. No title reaches this on main. "Unblocks: none", and the body gives no title ID with a log line showing it registers NOTE_OPEN, NOTE_READ or NOTE_CLOSE on an EVFILT_VNODE watch. The change touches Open.cpp, Stdio.cpp, Aio.cpp and DescriptorControl.cpp, i.e. the read, open and close paths, so it needs a title that makes it matter.

2. Cost on the read path once any watch exists. EqueueNoteRead is cheap while g_accessWatchCount is zero. As soon as one vnode watch is registered anywhere (for any file), every read, pread, readv, AIO read and getdents on every descriptor does DescriptorIdentity (a descriptor stat via FillFileStatFromDescriptor), then takes g_accessMutex and walks the whole g_accessWatches vector. A title that watches one config file would pay a stat plus a global lock on all streaming reads. Could the watch keep the descriptors (or the identity) it cares about so unrelated descriptors return without a stat, or at least filter by a per-descriptor "has an access watch" flag set at open?

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729968402 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7121#pullrequestreview-5729968402). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T20:03:24Z. **Review:** COMMENTED --- **Correction (2026-11-01):** the title-ID/log demand below is not a CONTRIBUTING requirement; `Unblocks: none` is allowed. The technical points below are unaffected. **1. No title reaches this on `main`.** "Unblocks: none", and the body gives no title ID with a log line showing it registers `NOTE_OPEN`, `NOTE_READ` or `NOTE_CLOSE` on an `EVFILT_VNODE` watch. The change touches `Open.cpp`, `Stdio.cpp`, `Aio.cpp` and `DescriptorControl.cpp`, i.e. the read, open and close paths, so it needs a title that makes it matter. **2. Cost on the read path once any watch exists.** `EqueueNoteRead` is cheap while `g_accessWatchCount` is zero. As soon as one vnode watch is registered anywhere (for any file), every `read`, `pread`, `readv`, AIO read and `getdents` on every descriptor does `DescriptorIdentity` (a descriptor stat via `FillFileStatFromDescriptor`), then takes `g_accessMutex` and walks the whole `g_accessWatches` vector. A title that watches one config file would pay a stat plus a global lock on all streaming reads. Could the watch keep the descriptors (or the identity) it cares about so unrelated descriptors return without a stat, or at least filter by a per-descriptor "has an access watch" flag set at open?
einfachama commented 2026-11-20 12:24:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by einfachama on 2026-11-20T12:24:34Z.

Review: COMMENTED


Thanks for this. One concern about reachability with the new ENODEV branch in OpenHostWatch, checked against upstream/main 94dd5d81dd:

  • A guest /dev/null or /dev/zero is never a host device here. Resolve (core/libs/prx/libc/src/General.cpp:400, root join at L421) maps it to an ordinary sandbox path. Only /dev/random and /dev/urandom are special-cased (core/libs/prx/libkernel/File/src/Open.cpp:401).
  • Several internal stand-ins are host /dev/null (NUL on Windows) underneath: random devices (File/src/RandomDevice.cpp:30-32), archived directories (File/src/DirectoryDescriptor.cpp:292-296), ksem (Semaphore/src/Ksem.cpp:60-62) and mqueue (libkernel_sys/Mqueue.cpp:88-90). Archived files (File/src/ArchivedFile.cpp:25-27) skip OpenHostWatch in this PR.

On Linux these reach the S_ISCHR branch and get ENODEV, which FreeBSD does not give them. Could the answer come from the guest-side descriptor type instead, with unknown kinds still throwing?

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5992601367 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7121#pullrequestreview-5992601367). Originally posted by [einfachama](https://github.com/einfachama) on 2026-11-20T12:24:34Z. **Review:** COMMENTED --- Thanks for this. One concern about reachability with the new `ENODEV` branch in `OpenHostWatch`, checked against upstream/main `94dd5d81dd`: - A guest `/dev/null` or `/dev/zero` is never a host device here. `Resolve` (`core/libs/prx/libc/src/General.cpp:400`, root join at L421) maps it to an ordinary sandbox path. Only `/dev/random` and `/dev/urandom` are special-cased (`core/libs/prx/libkernel/File/src/Open.cpp:401`). - Several internal stand-ins are host `/dev/null` (`NUL` on Windows) underneath: random devices (`File/src/RandomDevice.cpp:30-32`), archived directories (`File/src/DirectoryDescriptor.cpp:292-296`), ksem (`Semaphore/src/Ksem.cpp:60-62`) and mqueue (`libkernel_sys/Mqueue.cpp:88-90`). Archived files (`File/src/ArchivedFile.cpp:25-27`) skip `OpenHostWatch` in this PR. On Linux these reach the `S_ISCHR` branch and get `ENODEV`, which FreeBSD does not give them. Could the answer come from the guest-side descriptor type instead, with unknown kinds still throwing?
MarcZX10 commented 2026-11-20 12:39:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T12:39:12Z.

Review: COMMENTED


Reviewed — comments

Nothing blocks this review; the points below are optional.

What I ran

Reviewed head cb750ff85695ea65ff493d321c3242407536895b from the prepared patch and source reader. No build or tests were run in this review.

Results

Check Result Note
Patch and source review passed Changed implementation paths inspected
Build and tests not run Author-reported results were not rerun

Findings

Blocking

None.

Non-blocking

  • LastDescriptorOfOpenFile treats an untracked descriptor as the last descriptor (DescriptorControl.cpp:672). RememberDescriptor is only called along selected libkernel open paths, while standard descriptors and descriptors opened by other host code can be watched and closed through libkernel. In those cases a duplicate may exist without an entry in g_entries, so a close can report NOTE_CLOSE/NOTE_CLOSE_WRITE before the last host descriptor closes. Consider determining last-descriptor status from the host open-file description for untracked descriptors, or making this predicate conservative when the descriptor is not tracked.

Not verified

No commands, build, or tests were run. Author-reported Windows results were not independently verified; Linux/macOS and console behavior were not run. All ten changed files were listed as included in the manifest, but full-file review was limited to the relevant source ranges. review/files.json was not read; the file listing showed the changed files as included and listed no exclusions.

To get this to a good state

Nothing is required. Optional: cover a watched untracked descriptor with a duplicate and confirm that close notes wait for its final close.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5992779464 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7121#pullrequestreview-5992779464). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T12:39:12Z. **Review:** COMMENTED --- # Reviewed — comments Nothing blocks this review; the points below are optional. ## What I ran Reviewed head `cb750ff85695ea65ff493d321c3242407536895b` from the prepared patch and source reader. No build or tests were run in this review. ## Results | Check | Result | Note | | --- | --- | --- | | Patch and source review | passed | Changed implementation paths inspected | | Build and tests | not run | Author-reported results were not rerun | ## Findings ### Blocking None. ### Non-blocking - `LastDescriptorOfOpenFile` treats an untracked descriptor as the last descriptor (`DescriptorControl.cpp:672`). `RememberDescriptor` is only called along selected libkernel open paths, while standard descriptors and descriptors opened by other host code can be watched and closed through libkernel. In those cases a duplicate may exist without an entry in `g_entries`, so a close can report `NOTE_CLOSE`/`NOTE_CLOSE_WRITE` before the last host descriptor closes. Consider determining last-descriptor status from the host open-file description for untracked descriptors, or making this predicate conservative when the descriptor is not tracked. ## Not verified No commands, build, or tests were run. Author-reported Windows results were not independently verified; Linux/macOS and console behavior were not run. All ten changed files were listed as included in the manifest, but full-file review was limited to the relevant source ranges. `review/files.json` was not read; the file listing showed the changed files as included and listed no exclusions. ## To get this to a good state Nothing is required. Optional: cover a watched untracked descriptor with a duplicate and confirm that close notes wait for its final close.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/7121:upstream-pr/7121'
git switch 'upstream-pr/7121'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/7121'
git switch 'upstream-pr/7121'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/7121'
git switch 'upstream-pr/7121'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/7121'
git switch 'main'
git merge --squash 'upstream-pr/7121'
git switch 'main'
git merge --ff-only 'upstream-pr/7121'
git switch 'main'
git merge 'upstream-pr/7121'
git push origin 'main'
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!7121
No description provided.