inline_scan: follow a list copied before the cursor load (INLINE-SCAN-COPY-BEFORE-LOAD) #2318

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

@⁠syfyra on GitHub · 2026-11-26 13:46 UTC · original
syfyra:fix/inline-scan-copy-before-load → main · +45 −3 · 2 files · 1 commits · draft

Claimed in the coordination issue as: INLINE-SCAN-COPY-BEFORE-LOAD (#1608)

What and why

tools/inline_scan.py exists to say whether every inline command-list write checks the cursor limit; "UNCHECKED 0" is the answer the day-one check in docs/design.md reads as "a cursor-at-limit layer sees every command". classify() walks backwards from a store-back mov [rbx+18h],rax and accepted the cursor load mov rax,[rcx+18h] only if rcx was already known to hold the list at that point of the walk. When this is copied first:

mov rbx,rcx
mov rax,qword ptr [rcx+18h]
mov dword ptr [rax],4002C400h
...
add rax,10h
mov qword ptr [rbx+18h],rax
mov byte ptr [rbx+0000000000000140h],0

the walk meets the load before the copy, so the load was taken for another structure's +18h, load_traced was False and the write was reported as unrelated. The summary said UNCHECKED 0 and counted it among the "cursor-like stores with no list field nearby". The same write with the list in rbx throughout, or with the copy after the load, is UNCHECKED, and the checked form of this exact shape is already a test (test_list_copied_to_another_register_is_followed), found only because the compare pass runs forwards over the final register set.

The load's base is now recorded and checked after the walk, against every register the list was copied through. A load from a register that never held the list still marks the site as another structure. Checked sites do not depend on the load, so the change can only move a site from unrelated to UNCHECKED; the counts in docs/d3d12_command_objects.md (every DLL site checked) cannot change, but I could not re-run them here (no game files).

Tested

Windows 11, Python 3.14.7, synthetic dumpbin-style listings only:

  • python -I tests/test_inline_scan.py: 16 tests OK. New test_list_copied_before_the_cursor_load_is_still_unchecked runs the unchecked write with the copy before and after the load; on main the copy-before-load case fails (list is False), with the fix both are UNCHECKED with the cursor traced and size 0x10. New test_cursor_loaded_from_another_structure_is_not_a_list keeps a load through a register that is never a copy of the list (rsi) out of the list sites.
  • python -I tests/test_cpu_feature_scan.py (imports inline_scan) OK; the test of open #536 (test_inline_scan_extra.py) also passes on this branch.
  • python -m compileall; scripts/check_no_game_data.py on both files.
  • Merges cleanly with open #2273, which changes read_lines and main in the same file (different topic).

GPUs tested: n/a (CPU-only tool)

AI-assisted: yes (Claude Code, 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)

🤖 Generated with Claude Code

**@⁠syfyra** on GitHub · 2026-11-26 13:46 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2318) `syfyra:fix/inline-scan-copy-before-load` → `main` · +45 −3 · 2 files · 1 commits · draft Claimed in the coordination issue as: INLINE-SCAN-COPY-BEFORE-LOAD (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why `tools/inline_scan.py` exists to say whether every inline command-list write checks the cursor limit; "UNCHECKED 0" is the answer the day-one check in `docs/design.md` reads as "a cursor-at-limit layer sees every command". `classify()` walks backwards from a store-back `mov [rbx+18h],rax` and accepted the cursor load `mov rax,[rcx+18h]` only if rcx was already known to hold the list at that point of the walk. When `this` is copied first: mov rbx,rcx mov rax,qword ptr [rcx+18h] mov dword ptr [rax],4002C400h ... add rax,10h mov qword ptr [rbx+18h],rax mov byte ptr [rbx+0000000000000140h],0 the walk meets the load before the copy, so the load was taken for another structure's `+18h`, `load_traced` was False and the write was reported as `unrelated`. The summary said `UNCHECKED 0` and counted it among the "cursor-like stores with no list field nearby". The same write with the list in rbx throughout, or with the copy after the load, is UNCHECKED, and the checked form of this exact shape is already a test (`test_list_copied_to_another_register_is_followed`), found only because the compare pass runs forwards over the final register set. The load's base is now recorded and checked after the walk, against every register the list was copied through. A load from a register that never held the list still marks the site as another structure. Checked sites do not depend on the load, so the change can only move a site from `unrelated` to `UNCHECKED`; the counts in `docs/d3d12_command_objects.md` (every DLL site checked) cannot change, but I could not re-run them here (no game files). ### Tested Windows 11, Python 3.14.7, synthetic dumpbin-style listings only: - `python -I tests/test_inline_scan.py`: 16 tests OK. New `test_list_copied_before_the_cursor_load_is_still_unchecked` runs the unchecked write with the copy before and after the load; on `main` the copy-before-load case fails (`list` is False), with the fix both are UNCHECKED with the cursor traced and size 0x10. New `test_cursor_loaded_from_another_structure_is_not_a_list` keeps a load through a register that is never a copy of the list (rsi) out of the list sites. - `python -I tests/test_cpu_feature_scan.py` (imports `inline_scan`) OK; the test of open #536 (`test_inline_scan_extra.py`) also passes on this branch. - `python -m compileall`; `scripts/check_no_game_data.py` on both files. - Merges cleanly with open #2273, which changes `read_lines` and `main` in the same file (different topic). GPUs tested: n/a (CPU-only tool) AI-assisted: yes (Claude Code, 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) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
classify() walks back from a cursor store-back and took the load
`mov rax,[rcx+18h]` as the list's cursor only if rcx was already in
`bases` at that point. A copy `mov rbx,rcx` that comes before the load is
met after it on the way back, so the load counted as another structure's
+18h, the site lost load_traced and an unchecked write of that shape was
reported as `unrelated`: the summary said "UNCHECKED 0" for a write that
never checks. A checked write of the same shape was already found,
because the compare pass runs forwards over the final `bases`.

Record the load's base and check it once the walk has collected every
register the list was copied through. A load from a register that never
held the list is still another structure, as before.

Tested: new test_list_copied_before_the_cursor_load_is_still_unchecked
(fails before the fix for the copy-before-load order, passes after) and
test_cursor_loaded_from_another_structure_is_not_a_list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:50:09 +00:00
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 17:57 UTC · original · reviewed

Windows 11: 16/16 inline scan tests passed on synthetic inputs, including the new copied-list case. No findings from these checks.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-26 17:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2318#pullrequestreview-6078689668) · **reviewed** Windows 11: 16/16 inline scan tests passed on synthetic inputs, including the new copied-list case. No findings from these checks. AI-assisted.
Author
Owner

@⁠wavehs on GitHub · 2026-11-26 18:54 UTC · original · reviewed

macOS arm64 check of #2318 (INLINE-SCAN-COPY-BEFORE-LOAD). A pure-Python survey tool and its test; no GPU, no build.

Tested head 1efc62909 with its diff applied to a copy of main bdbc7e923 (branch 86 commits behind; git apply / git merge-tree clean).

Environment: Apple M3 Pro, arm64, macOS 27.2.1, CPython 3.15.2.

Result

  • python -I tests/test_inline_scan.py: 16 tests, OK.
  • Negative control (new test kept, tools/inline_scan.py put back to main's): 1 failure, test_list_copied_before_the_cursor_load_is_still_unchecked [copy before the load] - the site is reported checked/not a list, exactly the bug the test describes. The [copy after the load] subtest stays green on main, which is right: the old code already followed that direction.
  • The semantic suite was not run: tools/inline_scan.py is a standalone listing survey, not imported by tools/rdna2spirv.py or the build, so no shader result can change.

Review of the change

  • Deferring the base check is the correct fix for a backward walk. bases is filled from mov dst,src only when src is already in bases (tools/inline_scan.py:91-92), and a copy that precedes the load in program order is seen after the load in the reversed walk, so checking lm.group(2) in bases at load time could only ever see copies that follow it. The deferred check at :105-108 is the same predicate applied once the whole window is walked, and broken = True on failure keeps the site out of the load-traced class, which is what the second new test (rsi never a copy) pins.
  • load_base is only consulted when a load was found, so the load is None paths are unchanged.

Finding: the copy closure is still one hop, and the new test cannot see it. bases grows only when a copy's source is already in bases, and in a reversed walk a chained copy is processed before its source is added, so mov rbx,rcx; mov r9,rbx; mov rax,[r9+18h] never connects r9 to the list. I ran that on the merged tree:

one hop  (mov rbx,rcx; mov rax,[rbx+18h])   -> list True,  load_traced True,  UNCHECKED
two hops (mov rbx,rcx; mov r9,rbx; mov rax,[r9+18h]) -> list False, load_traced False

The two-hop site is not counted as a list write at all (list: False), so it disappears from the UNCHECKED n totals rather than being miscounted as checked. This is pre-existing - the old code missed the same shape - but the PR's whole purpose is making the copy-before-load direction right, and a two-deep copy is the natural next shape in the same code style. The cheap fix is to record (dst, src) edges instead of eagerly adding to bases, then close over them after the walk (repeat for dst, src in edges: if src in bases: bases.add(dst) until nothing changes) and run the deferred check last. That also keeps the new one-hop behaviour. I did not measure how many sites in a real listing this affects; a listing that shows one would settle it.

No game files. AI-assisted.

**@⁠wavehs** on GitHub · 2026-11-26 18:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2318#pullrequestreview-6079210677) · **reviewed** **macOS arm64 check of #2318** (INLINE-SCAN-COPY-BEFORE-LOAD). A pure-Python survey tool and its test; no GPU, no build. Tested head `1efc62909` with its diff applied to a copy of `main` `bdbc7e923` (branch 86 commits behind; `git apply` / `git merge-tree` clean). Environment: Apple M3 Pro, arm64, macOS 27.2.1, CPython 3.15.2. **Result** - `python -I tests/test_inline_scan.py`: 16 tests, OK. - Negative control (new test kept, `tools/inline_scan.py` put back to `main`'s): 1 failure, `test_list_copied_before_the_cursor_load_is_still_unchecked [copy before the load]` - the site is reported `checked`/not a list, exactly the bug the test describes. The `[copy after the load]` subtest stays green on `main`, which is right: the old code already followed that direction. - The semantic suite was not run: `tools/inline_scan.py` is a standalone listing survey, not imported by `tools/rdna2spirv.py` or the build, so no shader result can change. **Review of the change** - Deferring the base check is the correct fix for a backward walk. `bases` is filled from `mov dst,src` only when `src` is already in `bases` (`tools/inline_scan.py:91-92`), and a copy that precedes the load in program order is seen *after* the load in the reversed walk, so checking `lm.group(2) in bases` at load time could only ever see copies that follow it. The deferred check at `:105-108` is the same predicate applied once the whole window is walked, and `broken = True` on failure keeps the site out of the load-traced class, which is what the second new test (`rsi` never a copy) pins. - `load_base` is only consulted when a load was found, so the `load is None` paths are unchanged. **Finding: the copy closure is still one hop, and the new test cannot see it.** `bases` grows only when a copy's *source* is already in `bases`, and in a reversed walk a chained copy is processed before its source is added, so `mov rbx,rcx; mov r9,rbx; mov rax,[r9+18h]` never connects `r9` to the list. I ran that on the merged tree: ``` one hop (mov rbx,rcx; mov rax,[rbx+18h]) -> list True, load_traced True, UNCHECKED two hops (mov rbx,rcx; mov r9,rbx; mov rax,[r9+18h]) -> list False, load_traced False ``` The two-hop site is not counted as a list write at all (`list: False`), so it disappears from the `UNCHECKED n` totals rather than being miscounted as checked. This is pre-existing - the old code missed the same shape - but the PR's whole purpose is making the copy-before-load direction right, and a two-deep copy is the natural next shape in the same code style. The cheap fix is to record `(dst, src)` edges instead of eagerly adding to `bases`, then close over them after the walk (repeat `for dst, src in edges: if src in bases: bases.add(dst)` until nothing changes) and run the deferred check last. That also keeps the new one-hop behaviour. I did not measure how many sites in a real listing this affects; a listing that shows one would settle it. No game files. AI-assisted.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2318'
git switch 'github-bot/gh-2318'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2318'
git switch 'github-bot/gh-2318'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2318'
git switch 'main'
git merge --squash 'github-bot/gh-2318'
git switch 'main'
git merge --ff-only 'github-bot/gh-2318'
git switch 'main'
git merge 'github-bot/gh-2318'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.