fix(agc): read committed guest pages on Windows without faulting on released pages #10575

Merged
Mouhand-Kaddo merged 2 commits from upstream-pr/10575 into main 2026-10-27 18:55:21 +00:00
Mouhand-Kaddo commented 2026-10-24 10:44:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-24T10:44:52Z.


What

On Windows, Demon's Souls (PPSA01342) stops with an access violation while it loads the tutorial level, on main and with #7844:

FATAL: unhandled exception 0xc0000005 on thread ...
  rip ucrtbase.dll+0xee2bb
  read of 0x00000000000f0000
    GuestMemory::ReadCommitted / EqualsCommitted  <- cachedTexture <- resolveImageTables <- ShaderResources <- Draw

The title samples a texture at 0x38400 of 352 MiB (DCC keys at 0xc47000000200) that lies in no registered guest allocation. ReadCommitted and EqualsCommitted first find the readable pages of the range, then copy or compare them. On Linux that range is the executable image and stays mapped. On Windows it covers host heap pages that other threads release between the check and the copy, so the memcpy faults.

On Windows these two functions now read through ReadProcessMemory: the whole range first, then page by page if that fails. A page that cannot be read counts as uncommitted, as it would have a moment earlier: zero in a copy, left out of a comparison. Linux keeps the direct copy. The texture still takes whatever host bytes are readable there, as before; the debt entry records that.

This is separate from #7844 (host import budget), but on Windows both are needed to reach the level: #7844 removes the import refusals, and this removes the crash.

Risk: Windows only, two functions. ReadProcessMemory on the own process copies in the kernel instead of memcpy; a failed whole read falls back to per-page reads. The compare buffer lives in HostThreadLocal, since a thread_local destructor in a PRX runs after emulated TLS has freed the object on Windows.

Tested

Windows 11 Pro 26300, i7-13700K, 32 GiB, AMD Radeon RX 6900 XT, driver 32.0.21045.16010, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, on main 887a9640b.

  • New RunVanishedPageReadTests in agc_driver_graphics: an arena page released after Accessible cached it as readable. Without the change the test exits with 0xc0000005 in ucrtbase (the same fault as the title); with it, the page reads as zero and is skipped in a comparison. Linux keeps the direct copy, so the test is Windows-only. It requires the guest arena rather than returning when it is missing; under gdb a breakpoint on it is hit and agc_driver_graphics_tests ends with Graphics validation tests passed.
  • ctest -R agc -j 8: 998 of 1001 pass. agc_driver_sample_order, agc_driver_sample_order_grid_reference and agc_driver_sample_order_recipe_depth_locations fail the same way with main's GuestMemory.cpp on this GPU.
  • agc_driver_image_sint8, agc_driver_image_srgb_load, agc_driver_image_table (texture reads through these functions) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: the layer loads, no was not found line, pass, no VUID- on main or with this change.
  • host_thread_local and prx_thread_local_destructors pass. The destructor check fails on a build with the raw thread_local vector: equalsCommittedBytes registers a thread_local destructor.
  • tools/check_conventions.py --base upstream/main passes.
  • Demon's Souls PPSA01342 01.004.000, relinked with --windows --to-intel, 1080p (+r_Wants4K = WantsPerf in a copy of the renderconfig_ps5_*.txt files), a new character, main menu → Continue → Continue Offline, warm shader cache, SDL_AUDIODRIVER=dummy:
    • main (default import budget 8127 MiB): the access violation above while loading (1 run; 855,847 imports refused).
    • #7844 alone (12158 MiB): the same access violation in 2 of 3 runs; the third reached the level.
    • #7844 with this change: 1 run, reaches the level (the opening tunnel with the HUD) and runs 14 min without a crash, no import refused. An earlier version of the change, which read only registered guest allocations and was dropped because tests sample unregistered host memory, also reached the level in 1 run of 24 min, where the left stick moved the character.
  • A separate crash in title code (DemonsSouls.exe+0x84dc42, a pointer holding what look like half-float texels) happens early at start-up on main and with #7844 alike; this change does not touch it.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA01342 #1283 (loading the tutorial level on Windows, with #7844)
  • GPUs tested: AMD Radeon RX 6900 XT, driver 32.0.21045.16010, Windows 11
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4994716976 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10575). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-24T10:44:52Z. --- ### What On Windows, Demon's Souls (PPSA01342) stops with an access violation while it loads the tutorial level, on `main` and with #7844: ```text FATAL: unhandled exception 0xc0000005 on thread ... rip ucrtbase.dll+0xee2bb read of 0x00000000000f0000 GuestMemory::ReadCommitted / EqualsCommitted <- cachedTexture <- resolveImageTables <- ShaderResources <- Draw ``` The title samples a texture at `0x38400` of 352 MiB (DCC keys at `0xc47000000200`) that lies in no registered guest allocation. `ReadCommitted` and `EqualsCommitted` first find the readable pages of the range, then copy or compare them. On Linux that range is the executable image and stays mapped. On Windows it covers host heap pages that other threads release between the check and the copy, so the `memcpy` faults. On Windows these two functions now read through `ReadProcessMemory`: the whole range first, then page by page if that fails. A page that cannot be read counts as uncommitted, as it would have a moment earlier: zero in a copy, left out of a comparison. Linux keeps the direct copy. The texture still takes whatever host bytes are readable there, as before; the debt entry records that. This is separate from #7844 (host import budget), but on Windows both are needed to reach the level: #7844 removes the import refusals, and this removes the crash. Risk: Windows only, two functions. `ReadProcessMemory` on the own process copies in the kernel instead of `memcpy`; a failed whole read falls back to per-page reads. The compare buffer lives in `HostThreadLocal`, since a `thread_local` destructor in a PRX runs after emulated TLS has freed the object on Windows. ### Tested Windows 11 Pro 26300, i7-13700K, 32 GiB, AMD Radeon RX 6900 XT, driver 32.0.21045.16010, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, on `main` 887a9640b. - New `RunVanishedPageReadTests` in `agc_driver_graphics`: an arena page released after `Accessible` cached it as readable. Without the change the test exits with `0xc0000005` in `ucrtbase` (the same fault as the title); with it, the page reads as zero and is skipped in a comparison. Linux keeps the direct copy, so the test is Windows-only. It requires the guest arena rather than returning when it is missing; under `gdb` a breakpoint on it is hit and `agc_driver_graphics_tests` ends with `Graphics validation tests passed`. - `ctest -R agc -j 8`: 998 of 1001 pass. `agc_driver_sample_order`, `agc_driver_sample_order_grid_reference` and `agc_driver_sample_order_recipe_depth_locations` fail the same way with `main`'s `GuestMemory.cpp` on this GPU. - `agc_driver_image_sint8`, `agc_driver_image_srgb_load`, `agc_driver_image_table` (texture reads through these functions) with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`: the layer loads, no `was not found` line, pass, no `VUID-` on `main` or with this change. - `host_thread_local` and `prx_thread_local_destructors` pass. The destructor check fails on a build with the raw `thread_local` vector: `equalsCommittedBytes registers a thread_local destructor`. - `tools/check_conventions.py --base upstream/main` passes. - Demon's Souls PPSA01342 01.004.000, relinked with `--windows --to-intel`, 1080p (`+r_Wants4K = WantsPerf` in a copy of the `renderconfig_ps5_*.txt` files), a new character, main menu → Continue → Continue Offline, warm shader cache, `SDL_AUDIODRIVER=dummy`: - `main` (default import budget 8127 MiB): the access violation above while loading (1 run; 855,847 imports refused). - #7844 alone (12158 MiB): the same access violation in 2 of 3 runs; the third reached the level. - #7844 with this change: 1 run, reaches the level (the opening tunnel with the HUD) and runs 14 min without a crash, no import refused. An earlier version of the change, which read only registered guest allocations and was dropped because tests sample unregistered host memory, also reached the level in 1 run of 24 min, where the left stick moved the character. - A separate crash in title code (`DemonsSouls.exe+0x84dc42`, a pointer holding what look like half-float texels) happens early at start-up on `main` and with #7844 alike; this change does not touch it. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: PPSA01342 #1283 (loading the tutorial level on Windows, with #7844) - [x] GPUs tested: AMD Radeon RX 6900 XT, driver 32.0.21045.16010, Windows 11 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-24 10:59:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T10:59:24Z.

Review: APPROVED


Reviewed exact head 4201b8212a0c4d6a0b09b6274467192993c80ebb. The Windows-specific paths use ReadProcessMemory for the current process and retry page-sized ranges after a partial or failed large read; failed pages are zero-filled for copies and omitted from equality comparisons, which matches the committed-memory behavior described by the tests. The change leaves non-Windows reads unchanged. Diff check is clean, and hosted conventions/labels pass; build and register-context jobs are skipped by the current workflow policy. I reviewed the supplied Windows reproduction and test report but could not run the Windows-specific regression locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638002551 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10575#pullrequestreview-5638002551). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T10:59:24Z. **Review:** APPROVED --- Reviewed exact head `4201b8212a0c4d6a0b09b6274467192993c80ebb`. The Windows-specific paths use `ReadProcessMemory` for the current process and retry page-sized ranges after a partial or failed large read; failed pages are zero-filled for copies and omitted from equality comparisons, which matches the committed-memory behavior described by the tests. The change leaves non-Windows reads unchanged. Diff check is clean, and hosted conventions/labels pass; build and register-context jobs are skipped by the current workflow policy. I reviewed the supplied Windows reproduction and test report but could not run the Windows-specific regression locally.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10575
No description provided.