fix(libc): watch direct memory mapped over its reservation on macOS #3478
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3478"
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 fable-void on 2026-10-11T11:14:37Z.
What
On macOS, the write watch stops reporting writes to direct memory that is mapped over an address range reserved and registered before. On current
main(0f863c10), the new test stops at:Registercopied the protection it had recorded for pages it already watched over the protection the kernel had just reported. A reservation is registered asPROT_NONE; when direct memory is mapped over it read-write and registered again, the stalePROT_NONEstayed, andCollectonly write-protects pages withPROT_WRITE, so the memory reported one write and then none.maindoes not build the libraries on macOS yet; in a macOS build of the libraries with this write watch, Hollow Knight: Silksong (PPSA12544) blinks its title menu text and loses glyphs.Registernow keeps a recorded protection only where its own write protection explains what the kernel reports, and takes the kernel's protection otherwise. A protected page that was mapped again also loses its protected mark, soeraseno longer restores the old protection over the new mapping. The kernel is read under the lock, so a concurrentCollectcannot protect a page between the read and the merge.mugurc's
macos-portbranch keeps the recorded protection only for protected pages, which covers the reservation case; with that version the second half of the test stops ata protected page reserved again reports its old protection.Tested
macOS on Apple silicon,
core/libs/tests/write_watchconfigured and built as in thewrite-watchjob, natively (arm64) and as x86-64 (under Rosetta 2),ctest --repeat until-fail:3: 6 of 6 pass on both.write_watch_mappedfails onmainwith the line above on both. The sameRegisterchange in a macOS build of the libraries stopped the blinking menu text in PPSA12544.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-11T11:52:55Z.
Checked the diff and the CI: the
write-watchjob passes on macos-15 and macos-15-intel with the newwrite_watch_mappedtest registered in ctest. ReadRegisterthrough both cases in the test (a reservation mapped read-write keeps the kernel protection; a protected page reserved again dropsProtected, soeraseno longer restores the old protection), and the lock now covers the kernel read. Merging.