AnyPS5/docs/dev
Elijah De Guzman 80b0bab279 feat(libc): write watch on macOS hosts
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>
2026-10-09 21:11:40 -04:00
..
ARCHITECTURE.md feat(shader): implement s_swappc_b64 fetch-shader call 2026-10-08 20:05:24 +02:00
BUILD.md feat(libc): write watch on macOS hosts 2026-10-09 21:11:40 -04:00
CONVENTIONS.md refactor(docs): separated user and dev in docs + compatibility file 2026-09-28 22:58:17 +03:00
HW_ORACLE.md feat(hw-oracle): make the group segment size an option 2026-10-09 12:47:59 -03:00
PROGRESS.md fix(progress): exclude library test fixtures from function counts 2026-10-08 17:30:43 +05:30
TechnicalDebt.md feat(libc): write watch on macOS hosts 2026-10-09 21:11:40 -04:00