fix(libc): resolve only the read traps that cover the faulting page #18848
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18848"
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 krishalivaibhav on 2026-11-12T12:20:28Z.
What
On macOS, a fault on a read-trapped page ran the resolver for every trap linked to it through shared pages, not only the traps covering the faulting page (
takeTrapsgrew transitively). Images whose boundaries fall mid-page form such chains. In PPSA02070 seven linear targets are packed back to back with mid-page boundaries, and a 720-byte CPU write into a buffer on the last target's tail page would store the whole chain (~140 MB) every frame. Details in #18785.takeTrapstakes only the traps that overlap the requested pages.resolveruns it after its own range, so its pages are never given back unresolved. This closes the gap the libc debt entry listed ("a resolver that touches the pages of a trap it was not called for gets them without that trap ever being resolved"). The handler never runs the resolver nested: the watch's signals are notSA_NODEFER, and the resolver must not run inside the handler._resolvingare reserved up front (4096) so the handler does not allocate. Past that, the old gap remains; the debt entry says so.CheckReadTrapcovers two traps that share a page: with a resolver that stores its whole range, a fault on the first runs both in order on the resolver thread and gives the shared page back; with a resolver that stores only part of its range, it runs only the first, the shared page stays trapped, and a later read runs the second exactly once.Also on
GuestWriteWatch.cpp:843: #15729 changes the same condition for another reason (aGpuMutexholder bypass); whichever lands second needs a trivial rebase.Tested
macOS 27.3 (Apple M2, x86-64 under Rosetta 2), Release.
write_watch_*ctest entries pass, including the new cases. Everywrite_watch_testsmode also passes run directly, andwrite_watch_backing_tests sharedpasses 5 out of 5.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)