Repository navigation
Conversation
…, from the file alone (RT-566) tools/d3d12_device_calls.py follows D3D12XboxCreateDevice's (or D3D12CreateDevice's) out-pointer to the globals and stack slots that hold the device, and counts per vtable slot the `mov v,[device]` then `call [v+disp]` / `call reg` / dispatch-with-rax sites, with the register that holds the device (rcx, or rdx for the console's return-buffer form) and an argument-count estimate. What it can't follow (vtable loads with no matched call, the device handed to other functions or stored to non-stack memory, creator out-pointers it can't follow) is counted, not guessed. Slots 0-43 carry the PC method names; past 43 only the slots the repository has measured are named. The text report holds slot numbers and counts only; --out is required. Tested on a hand-built PE (tests/test_d3d12_device_calls.py); docs/retail_boot_chain.md §5 has the method and its limits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
AI-assisted Windows review of From the repository root, use import sys
sys.path[:0] = ["tests", "tools"]
from test_d3d12_device_calls import Asm, build_image
from d3d12_device_calls import scan
image, funcs = build_image()
data = bytearray(image)
site = data.index(bytes.fromhex("ff 15"), funcs["dispatch"], funcs["stack"])
helper = 0x1f00
data[helper] = 0xc3 # ret
a = Asm(site)
a.rel(bytes.fromhex("e8"), helper)
a.raw(bytes.fromhex("90")) # keep the original instruction span
data[site:site + 6] = a.code
for blob in (image, bytes(data)):
print([s["slot"] for s in scan(blob)["slots"]])Both scans report |
…patch routine (ItsNotRexed#7998 review) A direct call with a method pointer left in rax was counted as that slot whatever the call reached, so a helper that only returns made a slot appear (shdann's repro on ItsNotRexed#7998). The target, or for `call [rip+p]` the code the file's pointer p holds, must now reach `jmp rax` or `call rax` within 16 instructions without writing rax, calling or returning first (conditional branches allowed): the CFG no-op dispatch and a guard check that ends in `jmp rax`. Verified targets are cached. Any other target goes to a new "dispatch calls to unverified targets" count, never a slot. The fixture's GUARD pointer now holds a `jmp rax` stub; new functions call a guard-check stub (slot counted) and a helper that only returns (not counted, reported as not resolved), and shdann's patch is a test. The census on the 1.0.2.1 executable is unchanged: all 83 sites are `call [vtable+disp]`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested bf8294a on Linux, Python 3.12.16: pass
One thing at tools/d3d12_device_calls.py:532: a jmp rel32 inside the walked function takes the tail call path, so with the device in rcx it counts as passed to another call (a jmp rel8 does not). Treat an E9 whose target is inside [start, stop) like ends_flow? |
tupacfan04
left a comment
There was a problem hiding this comment.
Real defect: the direct-call dispatch heuristic over-counts device calls.
tools/d3d12_device_calls.py:208-209:
elif (op in (0xE8, 0xE9) or (indirect and base == RIP)) and RAX in meth:
slot, vload = meth[RAX] # dispatch routine, method in raxRAX in meth only means RAX currently holds a vtable method pointer. The code does not verify that the direct call target is a dispatch routine or that it invokes the method. A direct call rel32 (or jmp rel32) to an ordinary function while RAX still holds a method is reported as a device vtable call at that method's slot.
Synthetic repro with the PR's own image builder — add this function and one .pdata entry:
mov rcx,[rip+DEVICE] ; device
mov rax,[rcx] ; vtable
mov rax,[rax+0x70] ; slot 14 method in RAX
call unrelated ; direct E8, not a dispatch
retddc.scan() reports 5 sites, slot 14 = 2; the correct result is 4 sites, slot 14 = 1 (only the existing copy calls slot 14). The direct target only calls another object's vtable slot 3; it never uses the device.
The tests miss the branch: the positive dispatch test (tests/test_d3d12_device_calls.py:110) uses an indirect call [rip+GUARD] through a data address; test_the_unrelated_vtable_call_is_not_counted (:200) checks the function itself; the passed test (:131-135) makes a direct call but never loads a method into RAX. Add a method-in-RAX + direct call negative case. Fix: follow the direct target and confirm it dispatches RAX, or report the form as unresolved instead of counting it.
Secondary coverage gaps: a creator out-pointer in a non-volatile memory slot is recorded as "memory slot" but survives_call() only preserves RSP/framed RBP slots, so an intervening call silently loses it; NO_PDATA_WINDOW and the no-.pdata walk are not exercised; conditional branches are treated as fall-through with no branch-liveness test.
Otherwise coherent: retry/decoder, creator following, lea out-pointer, global/stack-slot handling, slot naming, CLI/report tests, and the nine tests pass. Synthetic/file-only; no game files. AI-assisted (OpenCode).
|
Thanks @shdann for the review and the repro, and @tupacfan04, who flagged the same defect at the old head. You were right: a method left in Fixed in
Your script on the fixture from
The fixture in New test: Census on my 1.0.2.1 copy is unchanged: 83 sites across 42 slots, 12 not resolved. All 83 sites are AI-assisted (Claude Code, Claude Opus 5.5). |
Claimed in the coordination issue as RT-566: #7804 (comment) (earlier claimed by pulria).
What and why
The boot chain (
docs/retail_boot_chain.md) finds the next device slot by running the title, one stop at a time. This PR addstools/d3d12_device_calls.py, which lists everyID3D12Devicevtable slot the executable calls, from the file alone. Slot owners can see which slots are coming before the run reaches them. This is a measurement, not a claim on any slot.--outis required. The tool writes two files there and prints the text one:<exe>.device_calls.txt: slot numbers and counts only<exe>.device_calls.json: the same, plus each site's RVA for local follow-uptools/gdk_runtime_calls.py's x86-64 decoder andtools/import_call_sites.py's import-table reader.docs/retail_boot_chain.md§5 explains how to run it and what it shows.Method
Find the creator calls. These are the
D3D12XboxCreateDevice/D3D12CreateDevicecall sites, in any of three forms:call [rip+IAT]callto the import thunkcall regaftermov reg,[rip+IAT]Follow the out-pointer in
r9.lea r9,[rip+G]makesGa device global.lea r9,[reg+disp]means that slot holds the device after the call.Walk the functions that reference a device global (bounds from
.pdata).Count the sites. A site is a vtable load from the device (
mov v,[dev]) followed by one of:call [v+disp]mov m,[v+disp], thencall mraxThe slot is
disp / 8. Ajmpin place of the call counts as a tail jump.Record where the device is at each site:
rcx, orrdxfor the return-buffer form (§3.1). The argument count is an estimate.Slot names:
ID3D12Devicenames. The console keeps that order at the slots where it was measured (8, 9, 14, 26, 36).runtime/shims/d3d12_xs_device.handdocs/retail_boot_chain.md§3 already name get a name.Limits
Each slot's count is a lower bound.
The tool does not see:
It counts what it can't resolve, instead of guessing:
The census on my 1.0.2.1 copy
Slot numbers and counts only:
D3D12XboxCreateDevicecall site; its out-pointer is a global.QueryInterfaceReleaseCreateCommandQueue(console measured)CreateCommandAllocator(console measured)CreateDescriptorHeap(console measured)GetDescriptorHandleIncrementSizeCreateRootSignatureCreateConstantBufferViewCreateShaderResourceViewCreateUnorderedAccessViewCreateRenderTargetViewCreateDepthStencilViewCopyDescriptorsSimpleGetResourceAllocationInfoGetCustomHeapProperties(console measured)CreateCommittedResourceCreateFence(console measured)CreateQueryHeapCreateCommandSignatureCreateCommandQueueXCreateComputePipelineState(console form)CreateComputePipelineStatefrom native codeCreateCommandListXSetFrameIntervalXScheduleFrameEventXWaitFrameEventXCreatePlacedResourceX(shape)How this compares with the docs and open PRs:
rdx(return-buffer) form appears at slots 25, 26 and 108 only. That agrees with d3d12_xs: device slot 26 takes the return buffer in RCX and the device in RDX, as the retail executable calls it (RT-5) #6964 and d3d12_xs: device slot 25 cleans the Xbox layout word and flag bits on a copy before the PC GetResourceAllocationInfo (retail boot chain stop 16) #7110 for 25 and 26, and with pulria's note on 108.Tests
python -I tests/test_d3d12_device_calls.py(9 tests) runs on a PE built by hand: one import,.pdata, eight functions. It checks that:call [v+disp8]call raxthrough a copied globalrdx--outis required.Other checks:
python3 -I -m compileall -q make_game.py tools testspasses.tests/test_gdk_runtime_calls.pyandtests/test_import_call_sites.pypass.test_docs_repo_pathspasses with the new paths.test_docs_cli_flagsandtest_docs_linksfail exactly as onmain, on files this PR doesn't touch.Tested on Linux with Python 3.14. No GPU or driver is involved: this is a static read of the file, and the census run takes about 5 s.
Checklist
python -I, writes only under--out.AI-assisted (Claude Code, Claude Opus 5.5).