feat(libkernel): EVFILT_VNODE on macOS through the host kqueue #5749

Merged
OleksandrS23 merged 1 commit from upstream-pr/5749 into main 2026-10-14 14:08:19 +00:00
OleksandrS23 commented 2026-10-14 09:15:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by OleksandrS23 on 2026-10-14T09:15:45Z.


What

EVFILT_VNODE, sceKernelAddFileEvent and sceKernelDeleteFileEvent on macOS hosts. FileEvent.cpp used eventfd and inotify on every non-Windows host, so it did not build on macOS (#1).

  • The watch registers EVFILT_VNODE (EV_CLEAR, all mapped notes) on a F_DUPFD_CLOEXEC duplicate of the descriptor in a host kqueue. XNU's notes have FreeBSD's values, so they are passed through masked by MAPPED_NOTES; a static_assert checks the values and <sys/event.h> supplies the constants on macOS.
  • XNU adds NOTE_LINK to NOTE_DELETE when the watched file or directory is removed; FreeBSD's vop_remove_post and vop_rmdir_post report NOTE_DELETE alone, so NOTE_LINK is dropped from a note that carries NOTE_DELETE.
  • The stop event is a pipe registered as EVFILT_READ in the same host kqueue, in place of the Linux eventfd.
  • XNU reports a move between directories to the watched directory as NOTE_WRITE (with NOTE_LINK for a subdirectory), without FreeBSD's NOTE_EXTEND, as on Windows: MoveDirectoryEntries is skipped on macOS as it is on Windows, and a new EVFILT_VNODE on macOS entry in docs/dev/debt/libkernel.md says so. The existing EVFILT_VNODE entry is left untouched, as #5493 edits it.

Linux and Windows code is unchanged.

Host notes measured on macOS 27.0.1 (x86-64 under Rosetta), compared with FreeBSD 11 vop_*_post:

Operation FreeBSD XNU
unlink / rmdir of the watched vnode NOTE_DELETE NOTE_DELETE | NOTE_LINK
link to the watched file NOTE_LINK NOTE_LINK
rename of the watched file NOTE_RENAME NOTE_RENAME
entry created / renamed / removed in the watched directory NOTE_WRITE NOTE_WRITE
subdirectory created / removed NOTE_WRITE | NOTE_LINK NOTE_WRITE | NOTE_LINK
file moved to or from another directory NOTE_WRITE | NOTE_EXTEND NOTE_WRITE
subdirectory moved to another directory NOTE_WRITE | NOTE_EXTEND | NOTE_LINK NOTE_WRITE | NOTE_LINK

Tested

Apple M4 Pro, macOS 27.0.1, x86-64 under Rosetta, AppleClang 21. main does not build libkernel on macOS yet, so the test ran on a local merge of main into mugurc/macos-port with this commit on top (plus local build fixes outside this PR): guest_kqueue passes, 30 of 30 runs (ctest --repeat until-fail:30), and guest_equeue_events passes. Linux and Windows were not built locally; their code paths are unchanged. tools/check_conventions.py passes.

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
  • Unblocks: macOS support #1
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4855636546 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5749). Originally posted by [OleksandrS23](https://github.com/OleksandrS23) on 2026-10-14T09:15:45Z. --- ### What `EVFILT_VNODE`, `sceKernelAddFileEvent` and `sceKernelDeleteFileEvent` on macOS hosts. `FileEvent.cpp` used `eventfd` and inotify on every non-Windows host, so it did not build on macOS (#1). - The watch registers `EVFILT_VNODE` (`EV_CLEAR`, all mapped notes) on a `F_DUPFD_CLOEXEC` duplicate of the descriptor in a host kqueue. XNU's notes have FreeBSD's values, so they are passed through masked by `MAPPED_NOTES`; a `static_assert` checks the values and `<sys/event.h>` supplies the constants on macOS. - XNU adds `NOTE_LINK` to `NOTE_DELETE` when the watched file or directory is removed; FreeBSD's `vop_remove_post` and `vop_rmdir_post` report `NOTE_DELETE` alone, so `NOTE_LINK` is dropped from a note that carries `NOTE_DELETE`. - The stop event is a pipe registered as `EVFILT_READ` in the same host kqueue, in place of the Linux `eventfd`. - XNU reports a move between directories to the watched directory as `NOTE_WRITE` (with `NOTE_LINK` for a subdirectory), without FreeBSD's `NOTE_EXTEND`, as on Windows: `MoveDirectoryEntries` is skipped on macOS as it is on Windows, and a new `EVFILT_VNODE on macOS` entry in `docs/dev/debt/libkernel.md` says so. The existing `EVFILT_VNODE` entry is left untouched, as #5493 edits it. Linux and Windows code is unchanged. Host notes measured on macOS 27.0.1 (x86-64 under Rosetta), compared with FreeBSD 11 `vop_*_post`: | Operation | FreeBSD | XNU | |---|---|---| | unlink / rmdir of the watched vnode | `NOTE_DELETE` | `NOTE_DELETE \| NOTE_LINK` | | `link` to the watched file | `NOTE_LINK` | `NOTE_LINK` | | rename of the watched file | `NOTE_RENAME` | `NOTE_RENAME` | | entry created / renamed / removed in the watched directory | `NOTE_WRITE` | `NOTE_WRITE` | | subdirectory created / removed | `NOTE_WRITE \| NOTE_LINK` | `NOTE_WRITE \| NOTE_LINK` | | file moved to or from another directory | `NOTE_WRITE \| NOTE_EXTEND` | `NOTE_WRITE` | | subdirectory moved to another directory | `NOTE_WRITE \| NOTE_EXTEND \| NOTE_LINK` | `NOTE_WRITE \| NOTE_LINK` | ### Tested Apple M4 Pro, macOS 27.0.1, x86-64 under Rosetta, AppleClang 21. `main` does not build `libkernel` on macOS yet, so the test ran on a local merge of `main` into `mugurc/macos-port` with this commit on top (plus local build fixes outside this PR): `guest_kqueue` passes, 30 of 30 runs (`ctest --repeat until-fail:30`), and `guest_equeue_events` passes. Linux and Windows were not built locally; their code paths are unchanged. `tools/check_conventions.py` passes. ### 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] Unblocks: macOS support #1 - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
adriadam10 commented 2026-10-14 13:28:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T13:28:37Z.


Checked the diff, Linux build and guest_kqueue (passes; the Linux/Windows paths are unchanged apart from the #if regrouping in the test) and the conventions. The macOS branch relies on your measurements (not reproducible here); it is isolated under __APPLE__. Merging once the full build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6169487293 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5749#issuecomment-6169487293). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T13:28:37Z. --- Checked the diff, Linux build and `guest_kqueue` (passes; the Linux/Windows paths are unchanged apart from the `#if` regrouping in the test) and the conventions. The macOS branch relies on your measurements (not reproducible here); it is isolated under `__APPLE__`. Merging once the full build is green.
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!5749
No description provided.