d3d12_device_calls: forget a slot a store or a call may have replaced (carry of #2343) #3093

Merged
leonida/mandy
MoonEyes merged 3 commits from carry/2343 into main 2026-12-02 13:05:58 +00:00

Pull request successfully merged and closed

MoonEyes commented 2026-12-02 10:31:01 +00:00

Claimed in the coordination issue as: D3D12-DEVICE-CALLS-STALE-SLOT (the original author's item ID, claimed at https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7194420859)

What and why

Carry of #2343 (syfyra), unchanged since 2026-11-26. Branch = main + the author's head (commit kept, merged without conflicts) + one commit of mine.

tools/d3d12_device_calls.py followed a [reg+disp] slot that held the device and dropped it only on a plain store to the slot's exact address. #2343 also forgets the slot when a call is given its address (an out-pointer) and when any store, SSE/AVX stores and partial stores included, touches its bytes, so a later call through the slot is not reported as a device slot.

Review defect fixed in my commit: the reviewers (lixonik, aslan2142) showed that an EVEX 64-byte store such as vmovups [rsp+20h],zmm0 covers the device spill at [rsp+40h], but VEX/EVEX stores were sized 32 bytes, so slot 6 was still reported. The decoder keeps neither VEX.L nor EVEX.L'L, so every VEX/EVEX store now takes 64 bytes (forgetting a slot only loses a site). A ZMM case is added to the existing store table in tests/test_d3d12_device_calls.py.

The other review remarks (mark Ready for Review, fresh CI) need no code. This carry does not change how the decoder reads EVEX compressed disp8 displacements; the new test uses a disp32 form.

Tested

Windows 11, Python 3.14.0, no GPU, no game files, on main 80910637f plus this branch:

  • python -I tests/test_d3d12_device_calls.py: 21 tests OK.
  • python -I tests/test_gdk_runtime_calls.py: 25 tests OK.
  • python -m compileall -q on both changed files: OK.
  • Red: with main's tools/d3d12_device_calls.py restored, the same test file gives 6 failures in the two new tests (the call-given-the-slot case, and the movups, vmovdqu, ZMM and 4-byte-store cases). With the PR's original source, the ZMM subtest fails, as the reviewers reported (that run also shows 3 other failures from main's newer CLI tests, which the original source predates).
  • python -I scripts/check_no_game_data.py on both changed files: clean.

Not run: the full suite, CI.

GPUs tested: n/a (unit tests only)

AI-assisted: yes. Models: Claude Opus 5.5 in Claude Code (carry, conflict resolution, fixes, tests); separate read-only reviewer agent: Claude Opus 5.5.

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

Supersedes #2343 once merged; the original stays open until a maintainer decides.

🤖 Generated with Claude Code

Claimed in the coordination issue as: D3D12-DEVICE-CALLS-STALE-SLOT (the original author's item ID, claimed at https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7194420859) ### What and why Carry of #2343 (syfyra), unchanged since 2026-11-26. Branch = `main` + the author's head (commit kept, merged without conflicts) + one commit of mine. `tools/d3d12_device_calls.py` followed a `[reg+disp]` slot that held the device and dropped it only on a plain store to the slot's exact address. #2343 also forgets the slot when a call is given its address (an out-pointer) and when any store, SSE/AVX stores and partial stores included, touches its bytes, so a later call through the slot is not reported as a device slot. Review defect fixed in my commit: the reviewers (lixonik, aslan2142) showed that an EVEX 64-byte store such as `vmovups [rsp+20h],zmm0` covers the device spill at `[rsp+40h]`, but VEX/EVEX stores were sized 32 bytes, so slot 6 was still reported. The decoder keeps neither VEX.L nor EVEX.L'L, so every VEX/EVEX store now takes 64 bytes (forgetting a slot only loses a site). A ZMM case is added to the existing store table in `tests/test_d3d12_device_calls.py`. The other review remarks (mark Ready for Review, fresh CI) need no code. This carry does not change how the decoder reads EVEX compressed disp8 displacements; the new test uses a disp32 form. ### Tested Windows 11, Python 3.14.0, no GPU, no game files, on main 80910637f plus this branch: - `python -I tests/test_d3d12_device_calls.py`: 21 tests OK. - `python -I tests/test_gdk_runtime_calls.py`: 25 tests OK. - `python -m compileall -q` on both changed files: OK. - Red: with `main`'s `tools/d3d12_device_calls.py` restored, the same test file gives 6 failures in the two new tests (the call-given-the-slot case, and the movups, vmovdqu, ZMM and 4-byte-store cases). With the PR's original source, the ZMM subtest fails, as the reviewers reported (that run also shows 3 other failures from main's newer CLI tests, which the original source predates). - `python -I scripts/check_no_game_data.py` on both changed files: clean. Not run: the full suite, CI. GPUs tested: n/a (unit tests only) AI-assisted: yes. Models: Claude Opus 5.5 in Claude Code (carry, conflict resolution, fixes, tests); separate read-only reviewer agent: Claude Opus 5.5. ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) Supersedes #2343 once merged; the original stays open until a maintainer decides. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
OreoFR commented 2026-12-02 12:18:57 +00:00

Verified by OreoFR (oreofr-agent, AI-assisted; third-party red/green). Head 9b9e6f3c843bdadc91e40c2181a617f0ec2cd807 merged into main f6dd2242e02b5f579d245f1c19dd5150d42e00a1 with no conflicts. Windows 11, Python 3.12, CPU only.

  • Green: tests/test_d3d12_device_calls.py OK; tests/test_gdk_runtime_calls.py OK.
  • Red, with main's tools/d3d12_device_calls.py restored and this PR's tests kept: test_d3d12_device_calls.py FAILED (failures=6), as the description says; test_gdk_runtime_calls.py still OK.
    Safe to merge: it merges cleanly, CI is green, and it touches only a tool and its test. Not merged by me.
**Verified by OreoFR** (oreofr-agent, AI-assisted; third-party red/green). Head `9b9e6f3c843bdadc91e40c2181a617f0ec2cd807` merged into main `f6dd2242e02b5f579d245f1c19dd5150d42e00a1` with no conflicts. Windows 11, Python 3.12, CPU only. - Green: `tests/test_d3d12_device_calls.py` OK; `tests/test_gdk_runtime_calls.py` OK. - Red, with main's `tools/d3d12_device_calls.py` restored and this PR's tests kept: `test_d3d12_device_calls.py` FAILED (failures=6), as the description says; `test_gdk_runtime_calls.py` still OK. Safe to merge: it merges cleanly, CI is green, and it touches only a tool and its test. Not merged by me.
MoonEyes commented 2026-12-02 12:49:01 +00:00

Merging. Head 9b9e6f3c8 merges cleanly with main 23a51c494 and does not force a rebase of #2566. Moon's own pull request, merged on green CI at his instruction. An independent read-only check by a separate agent on head 9b9e6f3c8 found every CI check green including no-game-data, no conflict with current main, no open review or unanswered question, and for a carry the original author's commits kept as ancestors. Merged by MoonEyes.

AI-assisted (Claude Code).

Merging. Head `9b9e6f3c8` merges cleanly with `main` `23a51c494` and does not force a rebase of #2566. Moon's own pull request, merged on green CI at his instruction. An independent read-only check by a separate agent on head 9b9e6f3c8 found every CI check green including no-game-data, no conflict with current main, no open review or unanswered question, and for a carry the original author's commits kept as ancestors. Merged by MoonEyes. AI-assisted (Claude Code).
Kal0s-design commented 2026-12-02 12:55:29 +00:00

Ran natively on Windows 11, Python 3.13, head 9b9e6f3c8 merged into current main (23a51c494, no conflicts). py -3.13 -I tests/test_d3d12_device_calls.py OK; red/green already shown above, so I only probed which other writes to the slot end it.

Throwaway probe (not committed) reusing the PR's spilled_device helper: spill the device to [rsp+0x40], run one instruction, reload, call slot 6. "kept" = slot 6 still reported.

instruction between spill and reload this PR main
nop (baseline) kept kept
mov qword [rsp+0x40],0 ends ends
mov word [rsp+0x40],dx ends ends
mov byte [rsp+0x47],0 ends kept
xchg [rsp+0x40],rdx ends ends
vmovups [rsp+0x40],zmm0 (EVEX, disp8) ends kept
and qword [rsp+0x40],0 (48 83 64 24 40 00) kept kept
or qword [rsp+0x40],-1 kept kept
xor [rsp+0x40],rdx kept kept
setz byte [rsp+0x40] kept kept
cmpxchg [rsp+0x40],rdx kept kept
pop qword [rsp+0x40] kept kept
lea r9,[rsp+0x38] + call (out struct that covers 0x40) kept kept

Not a regression, main keeps all of them too, but the new docstring line ("any store over a slot's bytes ends it") reads wider than the code. Read-modify-write forms (and/or/xor/add/sub [m], 0x80/0x81/0x83 with a memory operand, setcc [m], cmpxchg, xadd) never reach overwrite(). and qword ptr [rsp+N],0 is the short form MSVC often emits for p = nullptr with a stack slot, so it is the one most likely to show up in a real image. Either widening the doc wording to "plain and SSE/AVX stores" or sending memory-destination ALU ops through overwrite() would do; the latter only loses sites, in line with the PR's own rule. The out-pointer check also matches only a slot at exactly the address passed, not a buffer that covers it (last row); that one is rarer.

Not checked: real images, EVEX compressed disp8 (stated as out of scope in the body), Linux.

GPUs tested: n/a (CPU-only tests).

AI-assisted: yes (Claude Code).

Ran natively on Windows 11, Python 3.13, head `9b9e6f3c8` merged into current `main` (`23a51c494`, no conflicts). `py -3.13 -I tests/test_d3d12_device_calls.py` OK; red/green already shown above, so I only probed which other writes to the slot end it. Throwaway probe (not committed) reusing the PR's `spilled_device` helper: spill the device to `[rsp+0x40]`, run one instruction, reload, call slot 6. "kept" = slot 6 still reported. | instruction between spill and reload | this PR | `main` | |---|---|---| | `nop` (baseline) | kept | kept | | `mov qword [rsp+0x40],0` | ends | ends | | `mov word [rsp+0x40],dx` | ends | ends | | `mov byte [rsp+0x47],0` | ends | kept | | `xchg [rsp+0x40],rdx` | ends | ends | | `vmovups [rsp+0x40],zmm0` (EVEX, disp8) | ends | kept | | `and qword [rsp+0x40],0` (`48 83 64 24 40 00`) | **kept** | kept | | `or qword [rsp+0x40],-1` | **kept** | kept | | `xor [rsp+0x40],rdx` | **kept** | kept | | `setz byte [rsp+0x40]` | **kept** | kept | | `cmpxchg [rsp+0x40],rdx` | **kept** | kept | | `pop qword [rsp+0x40]` | **kept** | kept | | `lea r9,[rsp+0x38]` + call (out struct that covers `0x40`) | **kept** | kept | Not a regression, `main` keeps all of them too, but the new docstring line ("any store over a slot's bytes ends it") reads wider than the code. Read-modify-write forms (`and/or/xor/add/sub [m]`, `0x80/0x81/0x83` with a memory operand, `setcc [m]`, `cmpxchg`, `xadd`) never reach `overwrite()`. `and qword ptr [rsp+N],0` is the short form MSVC often emits for `p = nullptr` with a stack slot, so it is the one most likely to show up in a real image. Either widening the doc wording to "plain and SSE/AVX stores" or sending memory-destination ALU ops through `overwrite()` would do; the latter only loses sites, in line with the PR's own rule. The out-pointer check also matches only a slot at exactly the address passed, not a buffer that covers it (last row); that one is rarer. Not checked: real images, EVEX compressed disp8 (stated as out of scope in the body), Linux. GPUs tested: n/a (CPU-only tests). AI-assisted: yes (Claude Code).
Sign in to join this conversation.
No description provided.