fix(libc): track never-collected pages in the macOS write watch #3703
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3703"
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 utkuhalis on 2026-10-11T15:39:51Z.
What
On macOS,
GuestWriteWatchCollectFreshreported no pages and still returnedtrue, andGuestWriteWatchCollectArmedwas a fullCollect. The Linux watch treats them differently:CollectFreshreports and arms only the ranges no collection has taken since registration, andCollectArmedleaves those ranges alone. On macOS,MarkWritten(Execution/src/GuestMemory.cpp) therefore counted pages that were never armed as clean, and they stayed writable with no tracking. A laterCollectArmedalso took them, which the caller does not expect.The macOS backend now gives each page a fresh bit, set at registration (including a second registration) and cleared when a collection takes the page:
Collecttakes fresh and armed pages, the same as before.CollectFreshreports and arms only fresh pages and, like the Linux version, does not require the whole range to be covered.CollectArmedskips fresh pages.Without
APS5_NO_WRITE_WATCHnothing else changes. With the watch disabled,CollectFreshnow returnsfalse, the same as Linux; it no longer returnstruewithout collecting anything.New
write_watch_freshandwrite_watch_armedtests in the standalone macOS write-watch suite (core/libs/tests/WriteWatch.cpp) check both collections. They mirrorCheckWriteWatchFreshCollectandCheckWriteWatchArmedCollectincore/libs/tests/GuestMemory.cpp, which run only on Linux.Tested
cmake -S core/libs/tests/write_watch), run natively on arm64 and as x86-64 under Rosetta 2 (CMAKE_OSX_ARCHITECTURES=x86_64). All 8write_watch_*tests, includingwrite_watch_mappedfrom #3478, pass with--repeat until-fail:3.write_watch_freshandwrite_watch_armedfail and the other six pass.agc_driver_graphics. Upstream's full build does not compile on macOS, so that test cannot run on this branch as it is.__APPLE__backend and the macOS-only test.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)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:53:05Z.
Checked the diff: the fresh bit is set on every
Registerpath (including re-registering already watched pages), cleared only when a collection takes the page, and kept bySetProtection, host writes and write faults.CollectFreshno longer requires full coverage and returnsfalsewith the watch disabled, matching the Linux watch;CollectArmedskips fresh pages. The newwrite_watch_fresh/write_watch_armedtests are registered in ctest and mirror the Linux ones; thewrite-watchjob passes on macos-15. Merging once the remaining macOS job is green.