Repository navigation
feat(libc): write watch on macOS hosts - #1686
Merged
adriadam10 merged 1 commit intoOct 10, 2026
Merged
Conversation
Open
This was referenced Oct 8, 2026
macOS has no counterpart to userfaultfd write-protect or MEM_WRITE_WATCH, so GuestWriteWatch had no backend there and the driver re-read every guest buffer on each use. The macOS backend write-protects watched pages. The first write to a page faults, the SIGBUS/SIGSEGV handler records the page and restores its protection, and Collect reports the recorded pages and protects them again. A page is protected before its record is cleared, under the lock the handler takes, so a write that lands in between is recorded. The lock hands out turns in order: an unfair one starved writers under Rosetta. The protection is real, which adds three entry points: - GuestWriteWatchBeginHostWrite/EndHostWrite lift it around a system call that writes guest memory, which would otherwise fail with EFAULT. GuestArena::HostWrite calls them, as it calls the Windows equivalent. - GuestWriteWatchProtectionChanged tells the watch the protection given to watched pages by mprotect or a new mapping. - GuestWriteWatchProtection reports that protection, since a watched page is read-only between a collection and the next write. Register keeps the recorded protection of a page it already watches: read from the kernel it would be the watch's own read-only protection, and the page would never be watched again. The tests build without the prx libraries and run natively and through Rosetta. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cloud-Multiplayer
force-pushed
the
feat/macos-write-watch
branch
from
October 10, 2026 01:12
d11dc9f to
80b0bab
Compare
|
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.
|
9 tasks done
Collaborator
|
Read the full diff. The new code is all under Note for later: #1960 also edits Merging once CI is green. |
SleglJan
pushed a commit
to SleglJan/AnyPS5
that referenced
this pull request
Oct 10, 2026
…write-watch feat(libc): write watch on macOS hosts
10 tasks done
12 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A
GuestWriteWatchbackend for macOS hosts, as discussed in #1.macOS has no counterpart to
userfaultfdwrite-protect orMEM_WRITE_WATCH, so there is no backend today and the driver re-reads every guest buffer on each use. The backend write-protects watched pages: the first write to a page faults, a SIGBUS/SIGSEGV handler records the page and restores its protection, andCollectreports the recorded pages and protects them again. A page is protected before its record is cleared, under the lock the handler takes, so a write that lands in between is recorded.Because the protection is real, three entry points are added (no-ops on Linux and Windows):
GuestWriteWatchBeginHostWrite/EndHostWritelift the protection around a system call that writes guest memory, which would otherwise fail withEFAULT.GuestArena::HostWritecalls them, next to the Windows equivalent, so the existing file-read sites are covered.GuestWriteWatchProtectionChangedtells the watch the protection given to watched pages bymprotector by a new mapping.GuestWriteWatchProtectionreports that protection, since a watched page is read-only between a collection and the next write.Nothing in
maincalls the last two yet, because the macOS memory paths are not in the tree. They are meant for themprotect/mmap/munmapsites in libkernel's DirectMemory and for themach_vm_regionbranch ofGuestMemoryin the macOS port. This and the other limits are recorded in TechnicalDebt.Two details that came from running titles rather than from design:
Registerkeeps the recorded protection of a page it already watches. Read from the kernel it would be the watch's own read-only protection, and the page would never be watched again. The driver registers buffers repeatedly, so this showed quickly as stale vertex data.Tested
collect,register,host,protection,threads) pass natively (arm64) and as x86-64 through Rosetta, three repetitions each. They build without submodules or the prx libraries;docs/dev/BUILD.mdhas the commands, and awrite-watchjob runs them onmacos-15-intelandmacos-15.mprotectplus signal (21 µs and 3 µs).tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code