[pr-fix] Replay: the frame recorder no longer crashes on Windows 10 when a command list closes #281

Manually merged
TrustNo1 merged 2 commits from cafe/recorder-close into main 2026-12-05 04:48:01 +00:00 AGit
Contributor

What it changes

  • On main, with the frame recorder on (DARNER_RECORD), the game closed at start with an access violation (0xc0000005): a write into D3D12Core.dll from the recorder's list_close.
  • The D3D12 runtime used on Windows 10 (Agility SDK D3D12Core.dll 1.620) sets a command list's table pointer again on Close, not only on Reset. The recorder then took the runtime's own table for its shim and wrote into it. list_reset already puts the shim back after Reset; this does the same after Close (5 lines in replay/record.rs).

How it was tested

  • RTX 2080 Ti, Windows 10 22H2 (19045), Series S profile, DLSS Performance, hardware RT.
  • Before: access violation at start. After: a 53-submission frame was recorded and replayed many times; two replays give the same picture to the pixel.
  • Changes no default; only runs with the recorder on take this path.
  • On f3840d73d + this commit:
    • build and clippy: OK
    • darner-gpu lib tests: 1188 pass, 5 fail, all in code this commit doesn't touch. Tests that need Shader Model 6.6 can't run on Windows 10's own D3D12, so they were skipped.
  • Not tested: Windows 11 (harmless there: it only puts back a shim that was already in place).

Checked for overlap

No open PR changes replay/record.rs. gtahub PR 45 and PR 46 (Intel replay work) touch other replay files.

## What it changes - On main, with the frame recorder on (`DARNER_RECORD`), the game closed at start with an access violation (0xc0000005): a write into `D3D12Core.dll` from the recorder's `list_close`. - The D3D12 runtime used on Windows 10 (Agility SDK `D3D12Core.dll` 1.620) sets a command list's table pointer again on `Close`, not only on `Reset`. The recorder then took the runtime's own table for its shim and wrote into it. `list_reset` already puts the shim back after `Reset`; this does the same after `Close` (5 lines in `replay/record.rs`). ## How it was tested - RTX 2080 Ti, Windows 10 22H2 (19045), Series S profile, DLSS Performance, hardware RT. - Before: access violation at start. After: a 53-submission frame was recorded and replayed many times; two replays give the same picture to the pixel. - Changes no default; only runs with the recorder on take this path. - On f3840d73d + this commit: - build and clippy: OK - `darner-gpu` lib tests: 1188 pass, 5 fail, all in code this commit doesn't touch. Tests that need Shader Model 6.6 can't run on Windows 10's own D3D12, so they were skipped. - Not tested: Windows 11 (harmless there: it only puts back a shim that was already in place). ## Checked for overlap No open PR changes `replay/record.rs`. gtahub PR 45 and PR 46 (Intel replay work) touch other replay files.
First-time contributor

Independent Windows build, gate, and code-read review of 2ea0fd2e4 (based on main f3840d73d). Not run in-game or on Windows 10.

Environment

  • Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (x86_64-pc-windows-msvc), MSVC 19.44.35230.

Measured results

  • Gate 1 (cargo clippy --workspace --all-targets --locked -- -D warnings): PASS
  • Gate 2 (cargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASS
  • cargo xtask policy: PASS (asset policy: 555 files ok)
  • cargo test --locked -p darner-gpu --features diagnostics --test replay: PASS (1 passed; 0 failed in 1.04 s)
  • cargo test --locked -p darner-gpu --features diagnostics --lib replay: PASS (32 passed; 0 failed; 1 ignored in 0.63 s)

Finding (blocking)

  • Unbounded 4,144-byte Shim leak and global MADE / VirtualQuery storm on every Close and Reset when Windows 10 swaps open/closed vtables (crates/darner-gpu/src/replay/hook.rs:19-29, 99-132, 159-179):
    • hook::Shim stores only one orig vtable pointer, and MADE: Mutex<BTreeSet<usize>> tracks only created shim addresses without caching (orig_vtbl, state) -> shim.
    • In hook::again (hook.rs:169-177), if (*shim).orig as usize != now, it falls through to install(this, (*shim).state, patch), which locks global MADE, runs readable() (VirtualQuery) twice (hook.rs:116, 120), and Box::leaks a new 4,144-byte Shim (state + orig + pre[4] + table[512]).
    • When Windows 10 D3D12Core.dll sets this->vtbl to a closed-state vtable (VT_CLOSED) on Close and back to an open-state vtable (VT_OPEN) on Reset:
      1. list_close: now = VT_CLOSED != Shim_1.orig (VT_OPEN) → install() leaks Shim_2 (orig = VT_CLOSED).
      2. list_reset: now = VT_OPEN != Shim_2.orig (VT_CLOSED) → install() leaks Shim_3 (orig = VT_OPEN).
      3. Every subsequent Close and Reset of every hooked host command list ping-pongs forever (even while DARNER_RECORD is armed/idle), leaking ~8 KiB per list cycle, growing MADE without bound, and taking global MADE + 2× VirtualQuery on every close/reset.
    • Suggested fix: Cache shims by (orig_vtbl, state) inside hook.rs (or keep a small per-shim alternate pointer) so alternating VT_OPEN <-> VT_CLOSED allocates at most two shims per list and reuses them thereafter, and add a unit test in replay/hook.rs exercising alternating vtbl_a -> vtbl_b -> vtbl_a -> vtbl_b.
  • Other checks look clean: this is guaranteed hooked on entry to list_close, running hook::again even when hr.is_err() keeps of(this) safe, and the other hooked interfaces (device_table, queue_table, library_table) do not swap open/closed vtables.

Verdict: Changes requested (add (orig_vtbl, state) shim reuse in replay/hook.rs so Windows 10 Close/Reset does not leak shims on every list cycle).

AI-assisted: yes (Gemini 4 Neon).

Independent Windows build, gate, and code-read review of `2ea0fd2e4` (based on `main` `f3840d73d`). Not run in-game or on Windows 10. ### Environment - Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (`x86_64-pc-windows-msvc`), MSVC 19.44.35230. ### Measured results - Gate 1 (`cargo clippy --workspace --all-targets --locked -- -D warnings`): **PASS** - Gate 2 (`cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`): **PASS** - `cargo xtask policy`: **PASS** (`asset policy: 555 files ok`) - `cargo test --locked -p darner-gpu --features diagnostics --test replay`: **PASS** (`1 passed; 0 failed` in 1.04 s) - `cargo test --locked -p darner-gpu --features diagnostics --lib replay`: **PASS** (`32 passed; 0 failed; 1 ignored` in 0.63 s) ### Finding (blocking) - **Unbounded 4,144-byte `Shim` leak and global `MADE` / `VirtualQuery` storm on every `Close` and `Reset` when Windows 10 swaps open/closed vtables (`crates/darner-gpu/src/replay/hook.rs:19-29, 99-132, 159-179`):** - `hook::Shim` stores only one `orig` vtable pointer, and `MADE: Mutex<BTreeSet<usize>>` tracks only created shim addresses without caching `(orig_vtbl, state) -> shim`. - In `hook::again` (`hook.rs:169-177`), if `(*shim).orig as usize != now`, it falls through to `install(this, (*shim).state, patch)`, which locks global `MADE`, runs `readable()` (`VirtualQuery`) twice (`hook.rs:116, 120`), and `Box::leak`s a new 4,144-byte `Shim` (`state` + `orig` + `pre[4]` + `table[512]`). - When Windows 10 `D3D12Core.dll` sets `this->vtbl` to a closed-state vtable (`VT_CLOSED`) on `Close` and back to an open-state vtable (`VT_OPEN`) on `Reset`: 1. `list_close`: `now = VT_CLOSED != Shim_1.orig (VT_OPEN)` → `install()` leaks `Shim_2` (`orig = VT_CLOSED`). 2. `list_reset`: `now = VT_OPEN != Shim_2.orig (VT_CLOSED)` → `install()` leaks `Shim_3` (`orig = VT_OPEN`). 3. Every subsequent `Close` and `Reset` of every hooked host command list ping-pongs forever (even while `DARNER_RECORD` is armed/idle), leaking ~8 KiB per list cycle, growing `MADE` without bound, and taking global `MADE` + 2× `VirtualQuery` on every close/reset. - **Suggested fix:** Cache shims by `(orig_vtbl, state)` inside `hook.rs` (or keep a small per-shim alternate pointer) so alternating `VT_OPEN <-> VT_CLOSED` allocates at most two shims per list and reuses them thereafter, and add a unit test in `replay/hook.rs` exercising alternating `vtbl_a -> vtbl_b -> vtbl_a -> vtbl_b`. - Other checks look clean: `this` is guaranteed hooked on entry to `list_close`, running `hook::again` even when `hr.is_err()` keeps `of(this)` safe, and the other hooked interfaces (`device_table`, `queue_table`, `library_table`) do not swap open/closed vtables. **Verdict:** Changes requested (add `(orig_vtbl, state)` shim reuse in `replay/hook.rs` so Windows 10 `Close`/`Reset` does not leak shims on every list cycle). AI-assisted: yes (Gemini 4 Neon).
Windows 10's D3D12Core sets a list's table pointer on Close and back on Reset. Each shim now links to the one made for the object's other table, so the switch reuses two shims instead of leaking a new one (and taking MADE and VirtualQuery) on every Close and Reset.
Author
Contributor

Thanks, good catch: fixed in 91b554973.

Each shim now keeps a link to the shim made for the same object's other table. A list that switches between the open and closed tables (Windows 10's Close/Reset) reuses the same two shims: after the first Close, no new shim, no MADE lock and no VirtualQuery.

  • Added the test switching_between_two_tables_reuses_two_shims (open → closed → open, three rounds: the same two shims each time, and the calls still reach the right table).
  • Tested: cargo test --locked -p darner-gpu --features diagnostics --lib replay::hook (2 passed), cargo clippy --locked --release -p darner-gpu --all-targets --features diagnostics -- -D warnings.
  • Not tested yet: a recording in the game on Windows 10 with this commit.
Thanks, good catch: fixed in 91b554973. Each shim now keeps a link to the shim made for the same object's other table. A list that switches between the open and closed tables (Windows 10's `Close`/`Reset`) reuses the same two shims: after the first `Close`, no new shim, no `MADE` lock and no `VirtualQuery`. - Added the test `switching_between_two_tables_reuses_two_shims` (open → closed → open, three rounds: the same two shims each time, and the calls still reach the right table). - Tested: `cargo test --locked -p darner-gpu --features diagnostics --lib replay::hook` (2 passed), `cargo clippy --locked --release -p darner-gpu --all-targets --features diagnostics -- -D warnings`. - Not tested yet: a recording in the game on Windows 10 with this commit.
TrustNo1 manually merged commit d5cf3c40c7 into main 2026-12-05 04:48:01 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
TrustNo1/Darner!281
No description provided.