GPU: avoid faulting when zero-filling protected title memory #1466

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

@⁠fluffyflattershy-afk on GitHub · 2026-11-24 18:15 UTC · original
fluffyflattershy-afk:fix/title-copy-protected-destination → main · +89 −2 · 1 files · 1 commits · open

copy_mapped checks whether a title destination is committed, but committed memory may still be read-only. If ReadProcessMemory fails on that destination, the 4 KiB fallback currently calls write_bytes directly and faults with 0xC0000005. The same raw write is unsafe if the mapping changes after the check.

For title destinations only, zero-fill through the existing kernel copy helper using a fixed 4 KiB zero buffer. The kernel checks the destination at the point of the write. The successful-copy path and the direct zero-fill for host-owned writable destinations are unchanged.

Regression: an isolated child test allocates and initializes one page, marks it PAGE_READONLY, then calls copy_mapped with title_dst=true. On upstream ffe310e it exits -1073741819 (0xC0000005); with this change it succeeds and retains every original byte. A second test confirms an unreadable source still produces zeros in a writable destination. The child suppresses interactive fault dialogs.

Validation: victory-gpu diagnostics tests: 55 passed, 0 failed, 1 ignored benchmark. Clippy all targets with diagnostics and warnings denied passed (Rust separately warned that incremental-cache hard links are unavailable in this environment). Staged asset-policy and whitespace checks passed. Also composed with #322 and #334 on a local test stack: its 65 GPU tests passed, 1 benchmark ignored.

Related to #322, but independently reproduced on main and submitted against main. This addresses a synthetic memory-safety failure; it is not established as the cause of an observed title crash or black world. No game data is included. AI-assisted implementation and testing with Codex.

**@⁠fluffyflattershy-afk** on GitHub · 2026-11-24 18:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/1466) `fluffyflattershy-afk:fix/title-copy-protected-destination` → `main` · +89 −2 · 1 files · 1 commits · open copy_mapped checks whether a title destination is committed, but committed memory may still be read-only. If ReadProcessMemory fails on that destination, the 4 KiB fallback currently calls write_bytes directly and faults with 0xC0000005. The same raw write is unsafe if the mapping changes after the check. For title destinations only, zero-fill through the existing kernel copy helper using a fixed 4 KiB zero buffer. The kernel checks the destination at the point of the write. The successful-copy path and the direct zero-fill for host-owned writable destinations are unchanged. Regression: an isolated child test allocates and initializes one page, marks it PAGE_READONLY, then calls copy_mapped with title_dst=true. On upstream ffe310e it exits -1073741819 (0xC0000005); with this change it succeeds and retains every original byte. A second test confirms an unreadable source still produces zeros in a writable destination. The child suppresses interactive fault dialogs. Validation: victory-gpu diagnostics tests: 55 passed, 0 failed, 1 ignored benchmark. Clippy all targets with diagnostics and warnings denied passed (Rust separately warned that incremental-cache hard links are unavailable in this environment). Staged asset-policy and whitespace checks passed. Also composed with #322 and #334 on a local test stack: its 65 GPU tests passed, 1 benchmark ignored. Related to #322, but independently reproduced on main and submitted against main. This addresses a synthetic memory-safety failure; it is not established as the cause of an observed title crash or black world. No game data is included. AI-assisted implementation and testing with Codex.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:32:50 +00:00
Author
Owner

@⁠acetonahard-code on GitHub · 2026-11-24 19:17 UTC · original

Tested on Windows 11 (26200), RTX 4070 SUPER, driver 621.14, Rust 1.98.1. Base main at ffe310e, PR head 3ee8820.

Reproduced the bug on main: I copied only the new protected_title_copy test module onto main, without the fix.

  • unreadable_source_still_zeroes_a_writable_title_destination passes.
  • copy_to_readonly_title_memory_does_not_fault fails: child exited Some(-1073741819) (0xC0000005), as described.

With this PR:

cargo test -p victory-gpu main this PR
default features 50 passed 52 passed
--features diagnostics 53 passed 55 passed
  • 0 failed and 1 ignored in every run. Both new tests pass.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without --features diagnostics: clean.
  • cargo xtask policy: ok.
  • cargo fmt --check -p victory-gpu gives the same diffs as on main. Only the lines after the new test module shift down. This PR adds no new ones.

Overlap with other PRs: this merges cleanly with #1215. It conflicts with #322 in copy_mapped, which you mention you resolved locally. Whichever lands second will need a rebase.

Small notes, none blocking:

  • In the read-only-destination case, the failure is still counted as copystat::C::Unmapped, but the source was readable. A separate counter, or a comment, would keep the diagnostics honest.
  • The SAFETY comment on read() still says "the destination is mapped writable memory". copy_mapped now relies on the kernel checking the destination too, so that comment could say so.

I didn't test with game data.


Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.

**@⁠acetonahard-code** on GitHub · 2026-11-24 19:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/1466#issuecomment-7141874684) Tested on Windows 11 (26200), RTX 4070 SUPER, driver 621.14, Rust 1.98.1. Base `main` at ffe310e, PR head 3ee8820. **Reproduced the bug on `main`:** I copied only the new `protected_title_copy` test module onto `main`, without the fix. - `unreadable_source_still_zeroes_a_writable_title_destination` passes. - `copy_to_readonly_title_memory_does_not_fault` fails: `child exited Some(-1073741819)` (0xC0000005), as described. **With this PR:** | `cargo test -p victory-gpu` | `main` | this PR | |---|---|---| | default features | 50 passed | 52 passed | | `--features diagnostics` | 53 passed | 55 passed | - 0 failed and 1 ignored in every run. Both new tests pass. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`, with and without `--features diagnostics`: clean. - `cargo xtask policy`: ok. - `cargo fmt --check -p victory-gpu` gives the same diffs as on `main`. Only the lines after the new test module shift down. This PR adds no new ones. **Overlap with other PRs:** this merges cleanly with #1215. It conflicts with #322 in `copy_mapped`, which you mention you resolved locally. Whichever lands second will need a rebase. **Small notes, none blocking:** - In the read-only-destination case, the failure is still counted as `copystat::C::Unmapped`, but the source *was* readable. A separate counter, or a comment, would keep the diagnostics honest. - The `SAFETY` comment on `read()` still says "the destination is mapped writable memory". `copy_mapped` now relies on the kernel checking the destination too, so that comment could say so. I didn't test with game data. --- <sub>Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.</sub>
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:29 UTC · original

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-gpu/src/host.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1466#issuecomment-7149600395) <!-- victory-triage v1 head=3ee8820bb5e3f79c77d3062b7a706e03bd685fa4 verdict=needs-rebase at=2026-11-25T01:29:10Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-gpu/src/host.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/host.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1466'
git switch 'github-bot/gh-1466'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1466'
git switch 'github-bot/gh-1466'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1466'
git switch 'main'
git merge --squash 'github-bot/gh-1466'
git switch 'main'
git merge --ff-only 'github-bot/gh-1466'
git switch 'main'
git merge 'github-bot/gh-1466'
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!1466
No description provided.