feat(libc): write watch on macOS hosts #1686
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1686"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Cloud-Multiplayer on 2026-10-08T16:26:04Z.
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
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T01:22:11Z.
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.
main)docs/dev/BUILD.mdL76core/libs/prx/libc/include/GuestWriteWatch.hppL15core/libs/prx/libc/src/GuestWriteWatch.cppL308Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:03:35Z.
Read the full diff. The new code is all under
__APPLE__; Linux and Windows only get the no-op entry points, and the local Linux build and ctest of libs and libc are green. I can't run macOS here, so the fivewrite_watchtests rely on the newwrite-watchjob (macos-15 and macos-15-intel). TechnicalDebt entry and BUILD.md match the code.Note for later: #1960 also edits
GuestWriteWatch.hpp/.cppand conflicts with this PR, so whichever lands second needs a rebase.Merging once CI is green.