fix(libc): back the main image's writable mappings with anonymous memory on Linux #1176
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1176"
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 EdouardSence on 2026-10-07T16:44:07Z.
What
On Linux with RADV, the main executable's writable segments are never host-imported. amdgpu userptr refuses file-backed VMAs (libdrm sets
AMDGPU_GEM_USERPTR_ANONONLY, the same cause #943 describes for memfd direct memory), and the executable'srw-pPT_LOAD mappings are file-backedMAP_PRIVATE. They become writable image mirrors, andAcquireRegisteredcompares every 64 KiB block of them on each address-based build.On PPSA21567 that is ~133 MiB per build. Sampling the queue worker with
eu-stack(80 samples during the intro), 70 were inAcquireRegistered→compareBlocks→compareBlock(memcmp), and the threeRefreshPoolhelpers sat at 100% doing the same.This change: at libc load, before guest code runs, each
rw-pmapping of/proc/self/exeis replaced by an anonymous copy at the same address (mmapanonymous,memcpy,mremap(MREMAP_FIXED)). Contents, address and protection are unchanged; RELRO and read-only mappings are untouched. The ranges then import like any other anonymous memory and no writable mirror is created. Windows is unchanged.New test
guest_image_anonymous(Linux): an executable linked with libc checks that norw-pmapping of its own file remains and that its initialized data is intact and writable. It fails without the change and passes with it.Tested
ctest: 399/399 pass onmain4b16995dwith the change.astrobot(93faece1) with #943 cherry-picked,udmabuf.size_limit_mb=8192,APS5_NO_SNAPSHOT_CHECK=1, warm shader and pipeline caches,APS5_PROFILE_DRAW=1, no input (intro):[drawkinds]BDAresourcesper drawupstream mainalone can't reach this point on RADV (it stops onunsupported descriptor role Gds, then on the address-copy limit without #943), so the numbers are from that stack.Not caused by this change, recorded for completeness: on that stack both arms end in an amdgpu GPU page fault and ring timeout (without the change once in a 15 min run, at ~3 min,
SQC (data)permission fault; with it in 2 of 3 runs at ~50 s and ~150 s). After the device is lost the process hangs instead of exiting.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 adriadam10 on 2026-10-08T08:41:33Z.
Checked on current main: build + ctest 425/425 green;
guest_image_anonymouspasses and fails without theGuestAllocations.cppchange. Reviewed the remap: onlyrw-pmappings of the exe are replaced (RELRO and anonymous bss untouched), same address/protection, failures throw. Linux and Windows CI green. The title-level timings can't be reproduced here; merging.