fix(gpu): stop copy_mapped on non-writable title destinations instead of faulting #3358

Open
github-bot wants to merge 1 commit from github-bot/gh-3358 into main AGit
Owner

@⁠reeledMarek on GitHub · 2026-11-26 20:25 UTC · original
reeledMarek:fix/gpu-copy-mapped-readonly-dst → main · +79 −6 · 1 files · 1 commits · open

Summary

  • When copy_mapped(dst, src, len, title_dst = true) fails its initial ReadProcessMemory call because the destination contains committed PAGE_READONLY (or execute-only) pages, crate::texture::committed(dst, len) previously returned true (since committed only rejects PAGE_NOACCESS | PAGE_GUARD for readable sources).
  • The fallback loop then failed read() on each 4 KiB piece and executed unsafe { to.write_bytes(0, n) }, causing an immediate access violation on the read-only title destination.
  • Adds a writable(dst, len) check (requiring MEM_COMMIT, no PAGE_NOACCESS | PAGE_GUARD, and a writable base protection) before entering the fallback for title_dst, and routes title_dst zero-fills through read(ZERO_4K.as_ptr(), to, n) so concurrent protection changes cannot fault either.
  • Adds regression test title_copies::title_copies_do_not_fault_on_read_only_destinations using VirtualProtect(..., PAGE_READONLY).

Verification

  • cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings
  • cargo test -p xtask --locked
**@⁠reeledMarek** on GitHub · 2026-11-26 20:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/3358) `reeledMarek:fix/gpu-copy-mapped-readonly-dst` → `main` · +79 −6 · 1 files · 1 commits · open ### Summary - When `copy_mapped(dst, src, len, title_dst = true)` fails its initial `ReadProcessMemory` call because the destination contains committed `PAGE_READONLY` (or execute-only) pages, `crate::texture::committed(dst, len)` previously returned `true` (since `committed` only rejects `PAGE_NOACCESS | PAGE_GUARD` for readable sources). - The fallback loop then failed `read()` on each 4 KiB piece and executed `unsafe { to.write_bytes(0, n) }`, causing an immediate access violation on the read-only title destination. - Adds a `writable(dst, len)` check (requiring `MEM_COMMIT`, no `PAGE_NOACCESS | PAGE_GUARD`, and a writable base protection) before entering the fallback for `title_dst`, and routes `title_dst` zero-fills through `read(ZERO_4K.as_ptr(), to, n)` so concurrent protection changes cannot fault either. - Adds regression test `title_copies::title_copies_do_not_fault_on_read_only_destinations` using `VirtualProtect(..., PAGE_READONLY)`. ### Verification - `cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings` - `cargo test -p xtask --locked`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:26:21 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 20:29 UTC · original · approved these changes

LGTM — verified on Windows against origin/main (63bcca4).

  • Checking writable(dst, len) (instead of only committed) and using read(ZERO_4K.as_ptr(), to, n) on title_dst prevents copy_mapped from faulting on read-only title destination pages during the fallback path.
  • cargo test -p victory-gpu --lib host::title_copies:: -- --test-threads=1: 3 passed, 0 failed (including title_copies_do_not_fault_on_read_only_destinations).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 20:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/3358#pullrequestreview-6080166875) · **approved these changes** LGTM — verified on Windows against `origin/main` (`63bcca4`). - Checking `writable(dst, len)` (instead of only `committed`) and using `read(ZERO_4K.as_ptr(), to, n)` on `title_dst` prevents `copy_mapped` from faulting on read-only title destination pages during the fallback path. - `cargo test -p victory-gpu --lib host::title_copies:: -- --test-threads=1`: 3 passed, 0 failed (including `title_copies_do_not_fault_on_read_only_destinations`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3358/head:github-bot/gh-3358'
git switch 'github-bot/gh-3358'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3358'
git switch 'github-bot/gh-3358'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3358'
git switch 'github-bot/gh-3358'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3358'
git switch 'main'
git merge --squash 'github-bot/gh-3358'
git switch 'main'
git merge --ff-only 'github-bot/gh-3358'
git switch 'main'
git merge 'github-bot/gh-3358'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3358
No description provided.