feat(libc): arm compared and resident guest memory under APS5_ARM_COMPARED and APS5_ARM_RESIDENT #16372
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16372"
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 Nesyth on 2026-11-06T12:55:42Z.
What
On Windows, guest stores into write-protected guest pages fault, and the fault handler marks the pages written. That is how guest memory is tracked without walking
GetWriteWatchor comparing bytes. #361 limited it: a fault resumed in guest code overwrites the System V red zone[rsp-0x80, rsp)of an unframed leaf function. So host-imported shared pages are compared byte by byte instead, and resident runs are not armed.The relinker relocation PR (#16371) frames or relocates every red-zone leaf of a relinked image. With that in place, this PR brings arming back behind two opt-in switches:
APS5_ARM_COMPARED=1: host-imported shared pages are no longer marked compare-when-shared. A clearing collect write-protects them like any other shared page, so a guest store faults instead of every proof comparing their bytes.APS5_ARM_RESIDENT=1: a clearing collect write-protects a settled, write-watched resident span of a run of at least 256 KiB that no guest store has reached since it was armed, and remembers it clean. Later collects there skipGetWriteWatch. The first guest store faults and returns the whole run to write watching for good, so a run the guest keeps writing costs one fault. It is a runtime switch, soAPS5_ABcan toggle it.Both stay off by default. They are safe only for images relinked with
--frame-red-zoneandAPS5_RELINK_RELOCATE_RED_ZONE=1.How
GuestArenaCompareWhenShared_nid_no_patchandGuestArenaCompareResidentWhenShared_nid_no_patchreturn early underAPS5_ARM_COMPARED.WindowsMappings::collectResidentarms a span when the run is watched, settled, unwritten since its last arming and at least 256 KiB long. It requires every view in the span to be resident with the same protection and no host writes, host imports or pins.GuestArenaSetArmResident_nid_no_patch).Tested
Windows 11 Pro 26300, Radeon RX 7900 XTX (AMD Software 26.10.1), Ryzen 7 7800X3D, MinGW-w64 GCC 15.2, Ninja, Release,
BUILD_TESTING=ON, this branch on #16371 onmain65ad958fb9.guest_memory, the newguest_memory_armedregistration (APS5_ARM_RESIDENT=1,APS5_ARM_COMPARED=1;CheckLargeResidentWritesDoNotFaultthen expects the settled span read-only and exactly one fault),agc_rewatched_direct_shared,agc_import_alias_shared,agc_compared_shared_generations, the write tracking tests,agc_runtime_switches, the relinker and red-zone framer tests andcli_args.^agc: 1384 of 1386 pass. The two failures,agc_driver_direct_write_completionandagc_driver_sample_order_grid_reference, also fail on this machine without this branch.--frame-red-zoneandAPS5_RELINK_RELOCATE_RED_ZONE=1(617 red-zone leaves: 441 framed in place, 128 relocated whole),APS5_DRAW_PIPELINE=1in every run (the configuration #15456 makes the default), one binary throughout. No crash and no device loss in any run, with or without the switches.APS5_ARM_RESIDENTwithAPS5_ARM_COMPARED=1in both arms (APS5_AB=30:APS5_ARM_RESIDENT, 30 s phases from 190 s, 18 phase pairs, each B phase against its neighbouring A phases, slope-corrected at equal commits per present): -1.99 +- 0.72 ms, -1.7 +- 0.6% of a 117.5 ms frame. This is resident arming alone; compared-memory arming removes the byte compares that a separate proof otherwise runs (they were about 5% of the committer before arming), but it has no in-run switch, so it is covered by the boots above rather than an A/B.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.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T14:17:49Z.
Review: COMMENTED
Reviewed — no blocking findings
The targeted review found no verified blocking defect, but the review is incomplete because I did not read every changed file or run the build and tests.
What I ran
Reviewed head
605499656c5ecd1d6ea1cd8783052c845276d871using the prepared review artifacts and targeted repository reads throughrepo_read.py. No build or tests were run.Results
Negative control
Not run; no tests were executed.
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Sources
Read
description.md,commits.md,manifest.json, anddiff.patch, plus targeted ranges ofWindowsMappings.hpp,RedZoneFramer.cpp,GuestMemory.cpp, andGuestArena.cppat the pinned head.Not verified
The full text of the remaining changed files was not read, and
files.jsonwas not available through the review reader. Build and test results in the PR description were author-reported and not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T11:03:19Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change based on the inspected code; the author’s reported build and test results were not independently verified.
What I ran
Reviewed head
5b960b195b1154beb98b891de5c36edbc94fc32fusingrepo_read.pyto inspect the prepared diff, changed-file manifest, and targeted code. No build or tests were run.Results
Findings
Blocking
None identified in the code inspected.
Non-blocking
None.
Not verified
The manifest lists 18 changed files, all marked included. The review folder contains no
files/copies, so repository files were read throughrepo_read.py. Read:core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp(changed hunk in diff only);core/libs/prx/libSceAgcDriver/Graphics/include/RuntimeSwitches.hpp;core/libs/prx/libSceAgcDriver/Graphics/src/RuntimeSwitches.cpp;core/libs/prx/libc/include/GuestArena.hpp(changed hunk in diff only);core/libs/prx/libc/include/WindowsMappings.hpp;core/libs/prx/libc/src/GuestArena.cpp(changed hunk in diff only);core/libs/prx/libkernel/CMakeLists.txt(changed hunk in diff only);core/libs/tests/GuestMemory.cpp(changed hunk in diff only);core/relinker/codegen/include/codegen/x86/RedZoneFramer.hpp(changed hunk in diff only);core/relinker/codegen/src/x86/RedZoneFramer.cpp;core/relinker/codegen/tests/RedZoneFramerExecutionTests.cpp(changed hunk in diff only);core/relinker/codegen/tests/RedZoneFramerTests.cpp;core/relinker/elfpatcher/src/windows/WindowsTrampolineBuilder.cpp(changed hunk in diff only);core/relinker/relinker/src/pipeline/Conversion.cpp(changed hunk in diff only); anddocs/dev/ENVIRONMENT.md(changed hunk in diff only). The four changed CMake test registration files were inspected in the diff only. Full files and surrounding callers for those diff-only entries, as well as physical-console behavior and the reported performance measurements, were not independently verified. No tests were run, so test coverage and execution results are not confirmed.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:37:29Z.
Review: COMMENTED
The trial merge onto
c1601e56d5conflicts inWindowsMappings.hppandConversion.cpp. Please revalidate the red-zone framing prerequisite on the resolved branch before enabling either arming switch. Keep distinct native Windows cases for compared and resident mappings, since their protection and proof paths differ. #18293 builds on the same switches, so the exact dependency order belongs in the comparison. I have no native Windows result.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.