Skip to content

fix(agc): exclude host arena holes from write-watch proofs - #3594

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Scramblrrrr:codex/windows-host-write-watch-exclusion
Oct 11, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Scramblrrrr:codex/windows-host-write-watch-exclusion

Conversation

@Scramblrrrr

Copy link
Copy Markdown
Contributor

What

Windows reserves the guest arena around existing host mappings. WriteTracker initializes coverage for the arena address interval, including those excluded host regions. A range inside a host-owned hole can therefore be reported as write-watched and sent to GetWriteWatch even though it was not allocated with MEM_WRITE_WATCH. Native copied-read reuse testing exposed error 87; debugger address layouts did not reproduce it.

Reject host-region overlaps before collecting or accepting write-watch proofs, including bulk unchanged queries. Collection returns zero (tracking unavailable), and eligibility/unchanged proofs return false, so callers take their existing fresh-copy or comparison path. The existing store path already excludes these regions. No exception suppression or assumption that untracked memory is unchanged is introduced.

The Windows regression enumerates an actual host exclusion inside the arena rather than depending on ASLR placement of a heap allocation. It checks eligibility, collection and both unchanged-query APIs, plus ordinary host-heap rejection and unchanged bytes. Guest memory is not dereferenced during arena enumeration. Related #2863 optimizes queue-worker write-watch walks; this correction addresses excluded-region eligibility. Depends on: none.

Tested

Head 56d08f2, base main a11c8f7. Windows 11, Ryzen 7800X3D, Release MinGW GCC 15.2, SPIRV-Tools OFF.

  • Fresh build and agc_driver_graphics: PASS, final run 4.81 seconds.
  • Negative control: kept the new regression, rebuilt main's GuestMemory.cpp; fails with an arena host hole was reported as write-watched (0.36 seconds). Restored the fix, explicitly rebuilt, and repeated the passing test.
  • Conventions and diff checks pass. Linux/macOS were not run locally; host exclusions are Windows-only.

The correction was also tested in the separate 007 performance integration: six selected Vulkan checks passed. That experimental stack and its title data are not part of this PR. Its game runs still hit a host-memory guard and no visible frame was verified; this fix does not establish playability or solve memory pressure.

Checklist

  • Based on current main; no equivalent excluded-region proof fix found in open PRs
  • One topic per PR
  • No new code comments
  • Unimplemented paths retain errors; unavailable proofs are rejected
  • No investigation files, title data or images added
  • No new third-party code
  • Generic behavior
  • Depends on: none
  • AI-assisted: yes, Codex; author responsible for review

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked on Linux merged onto current main: libSceAgcDriver build and ctest (390/390, agc_driver_graphics passes). The fix and its test are _WIN32-only; reviewed the code: the overlap check runs before the collect memo path and before the tracker lock, and Watched/UnchangedSince/UnchangedSinceAll now reject the excluded ranges, matching the existing store path. The Windows run with the negative control in the description covers the runtime behaviour. Merging once CI is green.

@adriadam10
adriadam10 merged commit 8a13a1b into boykopovar:main Oct 11, 2026
15 checks passed
oneandonlydean added a commit that referenced this pull request Oct 12, 2026
StoredOver still read block stamps for a range in a host region inside the guest arena interval, which Watched reports as unwatched since #3594.
Scramblrrrr pushed a commit to Scramblrrrr/AnyPS5 that referenced this pull request Oct 12, 2026
On Windows agc_write_tracking has failed since boykopovar#3594 with

    write tracking test failed: an unwatched range reads as not stored over

from the check in CheckSharedBlock:

    if (!Watched(outside, unwatched.size())) Require(StoredOver(outside, unwatched.size(), TrackerGeneration()), "an unwatched range reads as not stored over");

The host stack array lies in a host hole of the guest arena. boykopovar#3594 made
Watched, collectWrites, UnchangedSince, UnchangedSinceAll and storeOwn
reject ranges overlapping such holes, but StoredOver, MarkWritten,
WrittenSince, ChangedBlocks and ImportWatched still accepted them through
WriteTracker::covers(), so StoredOver proved a range not stored over while
Watched called it unwatched (boykopovar#4087).

The exclusion now lives in WriteTracker::covers() on Windows, which every
query already asks, and the per-function checks are removed. Host holes
are padded to the allocation granularity and the tracker blocks are 64 KiB
from the arena base, so no block is shared between a hole and arena
memory, and ranges outside the holes get the same answers as before.

A new case enumerates the arena for a host hole and checks every query
against it; on the previous code StoredOver, MarkWritten, StoreOwnBytes,
WrittenSince and ChangedBlocks fail it.

Fixes boykopovar#4087

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Scramblrrrr pushed a commit to Scramblrrrr/AnyPS5 that referenced this pull request Oct 12, 2026
On Windows agc_write_tracking has failed since boykopovar#3594 with

    write tracking test failed: an unwatched range reads as not stored over

from the check in CheckSharedBlock:

    if (!Watched(outside, unwatched.size())) Require(StoredOver(outside, unwatched.size(), TrackerGeneration()), "an unwatched range reads as not stored over");

The host stack array lies in a host hole of the guest arena. boykopovar#3594 made
Watched, collectWrites, UnchangedSince, UnchangedSinceAll and storeOwn
reject ranges overlapping such holes, but StoredOver, MarkWritten,
WrittenSince, ChangedBlocks and ImportWatched still accepted them through
WriteTracker::covers(), so StoredOver proved a range not stored over while
Watched called it unwatched (boykopovar#4087).

The exclusion now lives in WriteTracker::covers() on Windows, which every
query already asks, and the per-function checks are removed. Host holes
are padded to the allocation granularity and the tracker blocks are 64 KiB
from the arena base, so no block is shared between a hole and arena
memory, and ranges outside the holes get the same answers as before.

A new case enumerates the arena for a host hole and checks every query
against it; on the previous code StoredOver, MarkWritten, StoreOwnBytes,
WrittenSince and ChangedBlocks fail it.

Fixes boykopovar#4087

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
oneandonlydean pushed a commit that referenced this pull request Oct 12, 2026
On Windows agc_write_tracking has failed since #3594 with

    write tracking test failed: an unwatched range reads as not stored over

from the check in CheckSharedBlock:

    if (!Watched(outside, unwatched.size())) Require(StoredOver(outside, unwatched.size(), TrackerGeneration()), "an unwatched range reads as not stored over");

The host stack array lies in a host hole of the guest arena. #3594 made
Watched, collectWrites, UnchangedSince, UnchangedSinceAll and storeOwn
reject ranges overlapping such holes, but StoredOver, MarkWritten,
WrittenSince, ChangedBlocks and ImportWatched still accepted them through
WriteTracker::covers(), so StoredOver proved a range not stored over while
Watched called it unwatched (#4087).

The exclusion now lives in WriteTracker::covers() on Windows, which every
query already asks, and the per-function checks are removed. Host holes
are padded to the allocation granularity and the tracker blocks are 64 KiB
from the arena base, so no block is shared between a hole and arena
memory, and ranges outside the holes get the same answers as before.

A new case enumerates the arena for a host hole and checks every query
against it; on the previous code StoredOver, MarkWritten, StoreOwnBytes,
WrittenSince and ChangedBlocks fail it.

Fixes #4087

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants