Skip to content

Watch: mapped image memory is not tracked as GPU memory - #2237

Open
denkencar-sketch wants to merge 1 commit into
Marvisak:mainfrom
denkencar-sketch:fix/watch-image-memory
Open

denkencar-sketch wants to merge 1 commit into
Marvisak:mainfrom
denkencar-sketch:fix/watch-image-memory

Conversation

@denkencar-sketch

Copy link
Copy Markdown

Summary

runtime_memory(at, true) accepts "anything but plain committed private memory", which includes committed MEM_IMAGE memory: the title's own .rdata or .data. From reading shadow::loose (a 4 MiB-aligned shadow) I expect it can reach such memory, and span .text as well; I have not run that path. A tracked page is made PAGE_READONLY when taken, which also removes execute access from code that shares its 64 KiB page. The next instruction fetch there is an execute access violation, which the guard handler ignores (it only handles writes), and the process crashes.

Change

Mapped images are refused, as plain heap memory already is. It leaves MEM_FREE as it is (that is #1849's change), so the two do not overlap. An untracked shadow is refreshed as any plain memory is.

Testing

watch::tests::image_memory_is_not_tracked calls track on a static in this test binary's image and on one of its functions: on main both are tracked; with this change neither is. The test never takes the pages, so it cannot make code unexecutable. cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings is clean.

Not tried: the loose-shadow path in the game, so I have not seen a title's data actually land in a tracked page. The premise (image memory passes runtime_memory) is what the test shows. modules::dstorage::tests::a_page_list_filled_after_its_request_starts fails now and then on main too (5 of 20 runs of cargo test -p victory-hle --lib); it is unrelated.

AI-assisted.

runtime_memory(at, true) accepted anything but plain committed private memory, so committed MEM_IMAGE memory (the title's .rdata or .data, via a loose shadow) was tracked. Tracked pages are made read-only when taken, which takes execute access from code sharing the 64 KiB page, and the next instruction fetch there faults in a way on_write ignores. Image memory is now refused, as the C heap is.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib watch:: — 7 passed, 0 failed (including image_memory_is_not_tracked)
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean guard excluding mapped MEM_IMAGE pages from GPU memory tracking with unit test coverage. Looks good.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch: mapped image memory (MEM_IMAGE) is not tracked as GPU memory — guarding it would strip execute access from code sharing a 64 KiB page. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Same cluster; one-line predicate change plus test.

@MamaLeVrai

Copy link
Copy Markdown

Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head 74e33471 into main 940d32f in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with --all-features: clean. cargo test --workspace --locked: 702 passed, 0 failed, 10 ignored, two runs (main alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. runtime_memory in crates/victory-gpu/src/watch.rs now also rejects MEM_IMAGE regions, so a shadow window that reaches into a mapped image is not write-guarded. Guarding such a page would take execute access from code that shares the 64 KiB granule with data. The runtime's GPU memory is reserved or mapped, never image memory, so what this is meant to track still passes.

image_memory_is_not_tracked covers a static in the test binary's image and a function address. CI check passes, and the branch merges cleanly.

For the maintainers: #1849 (MEM_FREE) and #2345 (every region of the range) change the same predicate. They combine without conflict in meaning, but whichever lands second needs a trivial rebase.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants