inline_scan: follow a list copied before the cursor load (INLINE-SCAN-COPY-BEFORE-LOAD) #2318
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2318"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by syfyra on 2026-11-26T13:46:05Z.
Claimed in the coordination issue as: INLINE-SCAN-COPY-BEFORE-LOAD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193762634)
What and why
tools/inline_scan.pyexists to say whether every inline command-list write checks the cursor limit; "UNCHECKED 0" is the answer the day-one check indocs/design.mdreads as "a cursor-at-limit layer sees every command".classify()walks backwards from a store-backmov [rbx+18h],raxand accepted the cursor loadmov rax,[rcx+18h]only if rcx was already known to hold the list at that point of the walk. Whenthisis copied first:the walk meets the load before the copy, so the load was taken for another structure's
+18h,load_tracedwas False and the write was reported asunrelated. The summary saidUNCHECKED 0and 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
unrelatedtoUNCHECKED; the counts indocs/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. Newtest_list_copied_before_the_cursor_load_is_still_uncheckedruns the unchecked write with the copy before and after the load; onmainthe copy-before-load case fails (listis False), with the fix both are UNCHECKED with the cursor traced and size 0x10. Newtest_cursor_loaded_from_another_structure_is_not_a_listkeeps 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(importsinline_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.pyon both files.read_linesandmainin the same file (different topic).GPUs tested: n/a (CPU-only tool)
AI-assisted: yes (Claude Code, Claude Opus 5.5)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T17:57:38Z.
Review: COMMENTED
Windows 11: 16/16 inline scan tests passed on synthetic inputs, including the new copied-list case. No findings from these checks.
AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by wavehs on 2026-11-26T18:54:20Z.
Review: COMMENTED
macOS arm64 check of #2318 (INLINE-SCAN-COPY-BEFORE-LOAD). A pure-Python survey tool and its test; no GPU, no build.
Tested head
1efc62909with its diff applied to a copy ofmainbdbc7e923(branch 86 commits behind;git apply/git merge-treeclean).Environment: Apple M3 Pro, arm64, macOS 27.2.1, CPython 3.15.2.
Result
python -I tests/test_inline_scan.py: 16 tests, OK.tools/inline_scan.pyput back tomain's): 1 failure,test_list_copied_before_the_cursor_load_is_still_unchecked [copy before the load]- the site is reportedchecked/not a list, exactly the bug the test describes. The[copy after the load]subtest stays green onmain, which is right: the old code already followed that direction.tools/inline_scan.pyis a standalone listing survey, not imported bytools/rdna2spirv.pyor the build, so no shader result can change.Review of the change
basesis filled frommov dst,srconly whensrcis already inbases(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 checkinglm.group(2) in basesat load time could only ever see copies that follow it. The deferred check at:105-108is the same predicate applied once the whole window is walked, andbroken = Trueon failure keeps the site out of the load-traced class, which is what the second new test (rsinever a copy) pins.load_baseis only consulted when a load was found, so theload is Nonepaths are unchanged.Finding: the copy closure is still one hop, and the new test cannot see it.
basesgrows only when a copy's source is already inbases, and in a reversed walk a chained copy is processed before its source is added, somov rbx,rcx; mov r9,rbx; mov rax,[r9+18h]never connectsr9to the list. I ran that on the merged tree:The two-hop site is not counted as a list write at all (
list: False), so it disappears from theUNCHECKED ntotals 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 tobases, then close over them after the walk (repeatfor 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.
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:02:07Z.
Review: COMMENTED
Draft review against current
main: deferring theload_base not in basescheck until after the backwards walk intools/inline_scan.py:94-108looks clean and clean-room verified. Still Draft with no CI run yet — please mark Ready for Review so CI runs green.(AI-assisted review.)
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:28:19Z.
Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.
(AI-assisted triage.)
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T13:04:35Z.
Review: APPROVED
Now ready for review and
MERGEABLE. Clean-room verified: the deferredload_basecheck intools/inline_scan.py:94-108and synthetic regression test intests/test_inline_scan.pyare clean and independently verified on Windows and macOS (@lixonik,@wavehs).Approving — ready to merge once CI runs green on current
main.(AI-assisted review.)