fix(agc): check unregistered host memory with mach_vm_region on macOS, which has no /proc/self/maps #20057
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20057"
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 XIIYAZ on 2026-11-14T14:12:36Z.
What
On macOS, a label stored into unregistered host memory is always refused with reason 3. That makes
agc_driver_unregistered_label_on_gpuandagc_driver_unregistered_label_behind_write_backfail:UnregisteredHostImportimports such memory only whenprivateAnonymousReadWriteconfirms the range is private, anonymous, read-write memory. Outside Windows, that check reads/proc/self/maps. macOS has no/proc, sofopenfails and every range counts as not private.On macOS the check now asks
mach_vm_regionabout the region that contains the range, and requires all of the following:VM_PROT_READ | VM_PROT_WRITE(the Linuxrw-check);VM_INHERIT_COPY; aMAP_SHAREDmapping hasVM_INHERIT_SHARE(the Linuxpcheck);external_pager == 0, so the region is not backed by a file (the Linuxinode == 0check).The region's share mode is not used. Once Metal imports part of a malloc region (here the registered label block beside the test's block), the whole region reports
SM_TRUESHARED, while the memory is still private to the process.What
mach_vm_regionreports for each case the test uses, under Rosetta on an M4:aligned_allocblockMAP_PRIVATE | MAP_ANONMAP_SHARED | MAP_ANONMAP_PRIVATEfile mappingA page made read-only with
mprotectfails the protection check. The test covers that case.Tested
Setup:
-DCMAKE_OSX_ARCHITECTURES=x86_64; tests run under RosettaANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1mainwith the open macOS build fixes appliedResults:
agc_driver_unregistered_label_on_gpuandagc_driver_unregistered_label_behind_write_backfail before this change and pass after it. That includes the cases that must still be refused: read-only,MAP_SHAREDanonymous and private file mappings.ctest -R 'label|write_tracking|unit_flags|shadow_label|recorder_failed|host_import|import'(95 tests): the other failures there are the same before and after. They are different issues (label ordering over the host import and write tracking) and are not changed here.ctest -R '^(agc|shader|job)'(1578 tests,-j 1) and compared it with the same run before this change: the two tests above are fixed and nothing new fails (18 failures before, 16 after).Linux and Windows are unchanged; the new code is under
__APPLE__.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T15:39:14Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected macOS range checks match the stated private, anonymous, read-write requirements.
What I ran
Reviewed head
924f53b864d233bf1e2912191c2ede783b60f872. No build or tests were run. Readreview/description.md,review/commits.md,review/manifest.json,review/diff.patch, and lines 1–90, 4920–5070 ofcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppthroughrepo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full 7,920-line changed file was not read; only the changed regions, surrounding includes, and caller were inspected. Build and test results in the description are author-reported, not independently verified. The diff is the complete change; no other changed files were listed.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-16T23:01:50Z.
Review: COMMENTED
Tested on macOS 27.2 / Apple M4 with MoltenVK 1.4.2 (LunarG Vulkan SDK 1.4.363.1, validation layer 1.4.363), x86-64 build under Rosetta. This is the only GPU I tested.
Head
924f53b864merged alone onto main3b17977ba6, compared with3b17977ba6itself. I ran the 29 AGC tests that fail on main on this Mac, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer, throughctest --test-dir build -R <those 29> -V, three runs per side. Every Vulkan test loggedInsert instance layer "VK_LAYER_KHRONOS_validation"and none loggedwas not found but was requested by env var VK_INSTANCE_LAYERS.agc_driver_unregistered_label_behind_write_backagc_driver_unregistered_label_on_gpuThe other 26 tests gave the same result on both sides.
agc_driver_label_after_import_copyis flaky on main as well: main Failed, Passed, Passed, this PR Failed, Failed, Failed. Every failure on either side is the same timing check ("round N: a CPU read after the label that followed the copy found K of 262144 destination bytes not yet copied"), and it varied the same way across the other PRs I tested in the same session, so I don't attribute it to this change.VUID-lines: identical per test on both sides (30 on main, 30 with this PR, over the three runs). TheVUID-lines on both sides are main's existingVUID-VkDeviceCreateInfo-sType-unique(a duplicatedVkPhysicalDevicePortabilitySubsetFeaturesKHRin the device pNext chain) andVUID-VkSamplerCreateInfo-samplerMipLodBias-04467; this PR adds none.