gpu(native): no copy-back into a pool the view left, or into a freed range (#339) #387

Manually merged
github merged 3 commits from github-bot/gh-384 into main 2026-11-28 00:42:33 +00:00 AGit
Owner

@⁠AnastasisKon on GitHub · 2026-11-27 15:57 UTC · original
AnastasisKon:vibe/pool-link-corruption-339-567a86 → main · +45 −0 · 3 files · 3 commits · merged 2026-11-28 00:38 UTC

What this changes

Refs #340 (not Closes: the GPU-write case below is still open).

Before a GPU-written texture is written back into title memory, the copy now checks that the address still belongs where the view was placed:

  • if the title unmapped the range and remapped it into another pool since the view was placed (Title::placed against the pool's own resolve), the copy is skipped and logged once per texture, instead of writing over whatever holds the range now;
  • with VICTORY_TRACE_FREED=1, a copy-back into a range the title's allocator freed is logged through native::freed::check and skipped; native::freed::overlaps is the new silent predicate behind that test.

Either write would land on whatever occupies the range now, which is one way a freed block's link ends up with a garbage offset — the fault at image+0x4dac5bf described on #340. docs/native-host.md gains the section that explains the fault, names the two host-side suspects, and says what stays open: a GPU write landing in a range after the title freed and reused it, which the host cannot see because the title's allocator reports no frees.

How it was tested

  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: all pass — victory-hle 321, native_probe 17, victory-loader 29, 0 failed.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: no warnings on this tree (victory-gpu re-checked).
  • cargo xtask policy: 387 files ok.
  • Ran the game: not possible on this Mac, which has no copy of the title. What a run has to show: with VICTORY_TRACE_FREED=1, copy-backs skipped and logged, no new "not copied back" warning for a texture that is still alive, and no crash at image+0x4dac5bf on a machine that hit it before.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md: the section says which suspect this closes and which stays open
  • New diagnostics are behind a VICTORY_* variable and documented: no new variable; the new skip logs under the existing VICTORY_TRACE_FREED=1
**@⁠AnastasisKon** on GitHub · 2026-11-27 15:57 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/384) `AnastasisKon:vibe/pool-link-corruption-339-567a86` → `main` · +45 −0 · 3 files · 3 commits · merged 2026-11-28 00:38 UTC ## What this changes Refs #340 (not `Closes`: the GPU-write case below is still open). Before a GPU-written texture is written back into title memory, the copy now checks that the address still belongs where the view was placed: - if the title unmapped the range and remapped it into another pool since the view was placed (`Title::placed` against the pool's own `resolve`), the copy is skipped and logged once per texture, instead of writing over whatever holds the range now; - with `VICTORY_TRACE_FREED=1`, a copy-back into a range the title's allocator freed is logged through `native::freed::check` and skipped; `native::freed::overlaps` is the new silent predicate behind that test. Either write would land on whatever occupies the range now, which is one way a freed block's link ends up with a garbage offset — the fault at `image+0x4dac5bf` described on #340. `docs/native-host.md` gains the section that explains the fault, names the two host-side suspects, and says what stays open: a GPU write landing in a range after the title freed and reused it, which the host cannot see because the title's allocator reports no frees. ## How it was tested - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory`: all pass — victory-hle 321, native_probe 17, victory-loader 29, 0 failed. - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`: no warnings on this tree (`victory-gpu` re-checked). - [x] `cargo xtask policy`: 387 files ok. - [ ] Ran the game: not possible on this Mac, which has no copy of the title. What a run has to show: with `VICTORY_TRACE_FREED=1`, copy-backs skipped and logged, no new "not copied back" warning for a texture that is still alive, and no crash at `image+0x4dac5bf` on a machine that hit it before. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md: the section says which suspect this closes and which stays open - [x] New diagnostics are behind a `VICTORY_*` variable and documented: no new variable; the new skip logs under the existing `VICTORY_TRACE_FREED=1`
write_back resolved the texture's title address through the current pool
table and copied into whatever held it then. When the title unmapped the
range and remapped it into another pool after the view was placed, the
copy wrote over the new occupant, one way a freed block's link ends up
with a garbage offset (the image+0x4dac5bf crashes). The copy is now
skipped, logged once per texture, when the address no longer resolves to
the pool recorded at placement (Title::placed).

docs/native-host.md records the #339 analysis: the crash shape (r8 = rcx
+ 0x0000ffff00000000, the low 32 bits a garbage offset used as an
address), the two host-side suspects, and why only the copy-back one is
checkable on the native host: pool map/unmap events only, no block-level
write-watch.

Co-authored-by: AnastasisKon <[email protected]>
victory_platform::freed keeps the ranges the title frees at the XMem*
surface (XMemFreeDefault's block from its header, released XMemVirtualAlloc
reservations via xmem_posix::forget_physical) as a merged interval set.
Every PoolTable::resolve handing a writable mapping to the GPU and every
texture copy-back is checked against it: a hit is logged once per freed
range with both ranges and a serial, and the copy-back is skipped. GPU
writes are zero-copy on native, so resolve is the only point a GPU write
into freed memory can be seen; the title's own sub-allocator hooks carve
ranges the host never sees, which docs/native-host.md now states.

Tests: victory_platform::freed::tests (merge, overlap, wrap, dedup).

Co-authored-by: AnastasisKon <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 15:59:41 +00:00
github-bot force-pushed github-bot/gh-384 from 370cf66c38 to 256c0fefb3 2026-11-27 16:13:30 +00:00 Compare
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-27 16:20 UTC · original

What this changes
Refs #340

Two commits. (1) Title::write_back no longer copies a GPU-written texture back into whatever holds its title address now: when the address no longer resolves to the pool recorded at view placement (Title::placed vs PoolTable::resolve), the copy is skipped and logged once per texture — one way a freed block's link ends up with a garbage offset (the image+0x4dac5bf crashes). (2) Under VICTORY_TRACE_FREED=1 (main's native::freed from #381), a copy-back into a range the allocator freed is logged via freed::check("texture copy-back") and skipped; adds freed::overlaps. docs/native-host.md records the #340 analysis: crash shape (r8 = rcx + 0x0000ffff00000000, low 32 bits a garbage offset), the two host-side suspects, and why only these are checkable on native (zero-copy GPU writes can only be seen at resolve time; no block-level write-watch exists here).

How it was tested
cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings
cargo xtask policy (387 files ok)
cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory — not run in this environment (no Mac)
Ran the game — not run; a world run with VICTORY_TRACE_FREED=1 would exercise the new warnings
Checklist
No game files, game code, disassembly listings or SDK files included
Analysis/guesses marked in docs/native-host.md (#340 section)
New log lines are behind VICTORY_TRACE_FREED / the existing once-per-texture back.logged set

**@⁠AnastasisKon** on GitHub · 2026-11-27 16:20 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/384#issuecomment-7223135863) What this changes Refs #340 Two commits. (1) Title::write_back no longer copies a GPU-written texture back into whatever holds its title address now: when the address no longer resolves to the pool recorded at view placement (Title::placed vs PoolTable::resolve), the copy is skipped and logged once per texture — one way a freed block's link ends up with a garbage offset (the image+0x4dac5bf crashes). (2) Under VICTORY_TRACE_FREED=1 (main's native::freed from #381), a copy-back into a range the allocator freed is logged via freed::check("texture copy-back") and skipped; adds freed::overlaps. docs/native-host.md records the #340 analysis: crash shape (r8 = rcx + 0x0000ffff00000000, low 32 bits a garbage offset), the two host-side suspects, and why only these are checkable on native (zero-copy GPU writes can only be seen at resolve time; no block-level write-watch exists here). How it was tested cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings cargo xtask policy (387 files ok) cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory — not run in this environment (no Mac) Ran the game — not run; a world run with VICTORY_TRACE_FREED=1 would exercise the new warnings Checklist No game files, game code, disassembly listings or SDK files included Analysis/guesses marked in docs/native-host.md (#340 section) New log lines are behind VICTORY_TRACE_FREED / the existing once-per-texture back.logged set
Author
Owner

@⁠alicans on GitHub · 2026-11-27 16:28 UTC · original

Thanks for working on this. Two data points from a 24 GB M4 Pro:

  • None of my runs that crashed at image+0x4dac5bf set VICTORY_TEXTURE_BACK=1, and their logs have no copy-back lines. As far as I can tell, Title::write_back only has work with that switch on (Title::new calls collect_written with it), so neither change here would have acted in those runs.
  • A world load on main 4cf84c83 with #362 and VICTORY_TRACE_FREED=1 logged no use of freed title memory in 81 s. It did not reach the crash either; my memory limit stopped it.

Would a run with VICTORY_TEXTURE_BACK=1 and VICTORY_TRACE_FREED=1 be useful for #340, or is there a path with copy-back off you'd like traced?

**@⁠alicans** on GitHub · 2026-11-27 16:28 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/384#issuecomment-7223300488) Thanks for working on this. Two data points from a 24 GB M4 Pro: - None of my runs that crashed at `image+0x4dac5bf` set `VICTORY_TEXTURE_BACK=1`, and their logs have no copy-back lines. As far as I can tell, `Title::write_back` only has work with that switch on (`Title::new` calls `collect_written` with it), so neither change here would have acted in those runs. - A world load on main `4cf84c83` with #362 and `VICTORY_TRACE_FREED=1` logged no use of freed title memory in 81 s. It did not reach the crash either; my memory limit stopped it. Would a run with `VICTORY_TEXTURE_BACK=1` and `VICTORY_TRACE_FREED=1` be useful for #340, or is there a path with copy-back off you'd like traced?
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 16:44 UTC · original

Reviewed and merged locally with 384/385 together. Tests, Windows clippy, policy and the release build all pass. I haven't pushed it yet because it still needs a game run, and the machine's GPU memory was held by another run when I tried. I'll land it after that run.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 16:44 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/384#issuecomment-7223615389) Reviewed and merged locally with 384/385 together. Tests, Windows clippy, policy and the release build all pass. I haven't pushed it yet because it still needs a game run, and the machine's GPU memory was held by another run when I tried. I'll land it after that run.
github-bot changed title from Vibe/pool link corruption 339 567a86 to gpu(native): no copy-back into a pool the view left, or into a freed range (#339) 2026-11-27 21:43:27 +00:00
alicans points out that none of the runs that crashed at image+0x4dac5bf
set VICTORY_TEXTURE_BACK=1, which is right: Title::write_back is reached
only when the host collects written textures, so with the switch off the
host never writes a texture back and neither guard runs. The bullet now
says so, and that the freed-range one also needs VICTORY_TRACE_FREED=1.
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-27 22:04 UTC · original

@⁠alicans — you are right, and the code says exactly why.

Title::write_back is reached only from the loop over take_written(), and collecting_written() is true only when VICTORY_TEXTURE_BACK=1 (title.rs:248 sets it, host.rs:895 reads it). With the switch off the host never copies a texture back into title memory at all — the one copy_nonoverlapping into a pool mapping in native/textures.rs is inside write_back — so neither skip here can run, never mind be what a crashing run needed. The freed-range half needs a second switch on top: freed::overlaps answers false unless VICTORY_TRACE_FREED=1, so it acts only with both set.

So the honest scope of this PR: it hardens the copy-back path for runs that turn VICTORY_TEXTURE_BACK on — the runs #46 and #453 want to become the default — and it is not an explanation of the crashes in your logs. I have added that sentence to the bullet in docs/native-host.md (f57aac7f) so nobody reads it as a fix for a default run.

What your two data points do settle, though, is worth having on #340: with the switch off, a copy-back cannot be the writer that tramples a freed block's link, which leaves the other suspect — GPU work still writing a range after the title freed and reused it. That is the case the docs list as still open, and catching it needs the title's allocator to report frees, which no interface today provides.

@⁠LakshanSivakumar — the branch has one commit after the copy you merged locally: f57aac7f, the docs sentence above. Nothing else changed, so the merge you tested stands apart from that line; pull it before landing. Your point that this needs a game run still holds, and now the run worth doing is a VICTORY_TEXTURE_BACK=1 world load: with VICTORY_TRACE_FREED=1 too, the useful evidence is a "not copied back"/"skipped" line, or its absence for textures that are alive.

**@⁠AnastasisKon** on GitHub · 2026-11-27 22:04 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/384#issuecomment-7229010806) @⁠alicans — you are right, and the code says exactly why. `Title::write_back` is reached only from the loop over `take_written()`, and `collecting_written()` is true only when `VICTORY_TEXTURE_BACK=1` (`title.rs:248` sets it, `host.rs:895` reads it). With the switch off the host never copies a texture back into title memory at all — the one `copy_nonoverlapping` into a pool mapping in `native/textures.rs` is inside `write_back` — so neither skip here can run, never mind be what a crashing run needed. The freed-range half needs a second switch on top: `freed::overlaps` answers false unless `VICTORY_TRACE_FREED=1`, so it acts only with both set. So the honest scope of this PR: it hardens the copy-back path for runs that turn `VICTORY_TEXTURE_BACK` on — the runs #46 and #453 want to become the default — and it is not an explanation of the crashes in your logs. I have added that sentence to the bullet in `docs/native-host.md` (`f57aac7f`) so nobody reads it as a fix for a default run. What your two data points do settle, though, is worth having on #340: with the switch off, a copy-back cannot be the writer that tramples a freed block's link, which leaves the other suspect — GPU work still writing a range after the title freed and reused it. That is the case the docs list as still open, and catching it needs the title's allocator to report frees, which no interface today provides. @⁠LakshanSivakumar — the branch has one commit after the copy you merged locally: `f57aac7f`, the docs sentence above. Nothing else changed, so the merge you tested stands apart from that line; pull it before landing. Your point that this needs a game run still holds, and now the run worth doing is a `VICTORY_TEXTURE_BACK=1` world load: with `VICTORY_TRACE_FREED=1` too, the useful evidence is a "not copied back"/"skipped" line, or its absence for textures that are alive.
github manually merged commit 70375f8414 into main 2026-11-28 00:42:33 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.