Repository navigation
runtime, d3d12: both runtimes write an import call trace, and a tool compares two (RT-CALL-TRACE, D3D12-CALL-TRACE) - #2807
ubiquitarianism wants to merge 9 commits into
Conversation
Rules both runtimes read (gta6rt includes it, leonida-loader parses it) so their LEONIDA_CALL_TRACE traces are comparable. Not run in game.
Reads the LEONIDA_CALL_TRACE v1 traces of gta6rt and leonida.exe, pairs threads (main; then by start address and common call prefix), aligns each pair's calls and reports the first divergences: calls one side never makes, different return classes, different call counts, threads on one side only, and the calls still open at the end of each thread. Streams the input (about 150 bytes per call). Tested: python -I tests/test_call_trace_diff.py (Ran 76 tests, OK); tests/test_text_write_line_endings.py OK; two synthetic 1M-call traces: 14.0 s / 336 MB peak. Not run in game.
…ALL_TRACE) Every IAT slot of the title image and its DLLs (normal and delay) is traced by import identity when LEONIDA_CALL_TRACE=<new file> is set (size cap LEONIDA_CALL_TRACE_MAX_MB, default 4096); unset, wrap returns the address unchanged and no thunk block is allocated. Per-import 24-byte thunk into the common stub (entry-only E / wrapped C+R), writer and rules as in tools/call_trace_rules.def (hash in the header). New leonida-loader call_trace module with 23 tests (stub bytes against their assembler source, 20 integer args, floats, struct return, last error, panic through the stubs, nesting, classes, 4 threads across a view boundary, killed child, size cap). Tested: cargo test -p leonida-loader: 96 + 2 + 1 passed; cargo test -p leonida-hle: 211 passed, 2 ignored; build -p leonida --profile diag --features diagnostics,mimalloc ok. Not run in game.
LEONIDA_CALL_TRACE=<path> (cap LEONIDA_CALL_TRACE_MAX_MB, default 4096) records every call through the import tables of the main image and the title DLLs in the shared v1 format, with the rules of tools/call_trace_rules.def. Each import slot gets a 24-byte thunk to one of two common stubs (entry-only: jump, real return address; wrap: frame, C and R lines), registered with RtlAddFunctionTable. The file is created new, written through 4 MiB mapped views. Shims read their caller through RT_CALLER(), which sees through the wrap frame; unset, wrap() returns its target. runtime/test/call_trace_test.cpp (ctest call_trace) and tests/test_call_trace_rules.py cover it. Tested: full runtime build (RelWithDebInfo) passes; ctest on the 149 non-GPU tests that cannot open a Vulkan device or window: 100% tests passed, 0 tests failed out of 149; python tests of the rules, line endings, docs env vars pass. Not run in game.
…s, unset-switch no-ops) Tested: cargo test -p leonida-loader: 99 + 2 + 1 passed; cargo test -p leonida-hle: 211 passed, 2 ignored; build -p leonida --profile diag --features diagnostics,mimalloc ok. Not run in game.
…skip __vdecl math From the second review: a wrap frame would end the title's stack walks at the stub and SVML vector math passes arguments in YMM registers the stubs do not keep. Not run in game.
Tested: Ran 79 tests in 22.512s ... OK (test_call_trace_diff.py); Ran 3 tests in 15.268s ... OK (test_text_write_line_endings.py). Not run in game.
…ed writer lock) Tested: cargo test -p leonida-loader: 102 + 2 + 1 passed; cargo test -p leonida-hle: 211 passed, 2 ignored; build -p leonida --profile diag --features diagnostics,mimalloc ok. Not run in game.
…lock, caller in helpers) The entry stub's RUNTIME_FUNCTION now ends before its final jmp [r10], so a stack walk there finds the return address. The writer lock is taken with a 10 ms bound: a dropped record is counted and the next one writes `# dropped <count>`. The next view is mapped ahead so a failed remap still ends the file in `# truncated`. title_free_impl and create_file_w take the caller from the exported shim; a failed VirtualProtect deletes the function table; pe_loader builds the module name only when tracing. Rules: 205, hash 873cd3bb78a70bc5. Tested: full runtime build passes; ctest on the 149 non-GPU tests: 100% tests passed, 0 tests failed out of 149; xmem alone: 1/1 passed; xs_proxy_mock|xmem_: 100% tests passed, 0 tests failed out of 13; python -I tests/test_call_trace_rules.py OK. Not run in game.
|
Verified by OreoFR on macOS 27.2.1, Apple M5, head MEASURED
READ IN CODE
ASSUMED
AI-assisted: Claude Code |
|
Verified in all three layers it touches, on Windows, and none of them fails.
Python (the two suites it adds): C++: Those three error lines are the test doing its job - it drives the refusal paths and prints them - and Rust (six files under That failure is not this pull request's: it is What I could not test: a real import call trace from a title - that needs the game and the two runtimes the note describes, and this is a 24 GB desktop, not the 8 GB laptop the trace was written for. The diff tool and its rules are what the 88 Python tests cover, and they are green. One thing worth saying about the size: +6,558 across 23 files is a lot to review, and the shape helps - 795 lines of C++ test, 1,189 of Python tests, 731 of tool, 236 of rules, and the rest is the runtime hooks the notes describe. The tests are two thirds of it, which is the right ratio for a diagnostic that has to be trusted. AI-assisted: yes - DeepSeek v4.1 (flash), which ran all three layers on the machine above. Written with an AI assistant. |
KelboLive
left a comment
There was a problem hiding this comment.
The tracer is sound. Off costs nothing — wrap returns the target and allocates no thunk (call_trace.h:700) — and on is one atomic per call plus a bounded writer lock, with the line formatted and sequenced inside the lock (:442-520), so lines cannot interleave. The stream is capped (:361, call_trace.rs:796) and goes through 4 MiB mapped views, so RAM does not grow with the trace. Every test I ran passes: call_trace ctest, 79 test_call_trace_diff tests, 9 test_call_trace_rules, 29 Rust call_trace tests. Mutation: removing the return comparison in compare_thread (tools/call_trace_diff.py:519) fails 12 tests, so the diff's core is genuinely pinned.
One unbounded path, and it is a real inconsistency between the two runtimes:
call_trace.rs:865treats an unparsable or0LEONIDA_CALL_TRACE_MAX_MBas 4096 silently, andmb.saturating_mul(1 << 20)turns a parseable but huge value into no cap at all.gta6rtrefuses both cases with a message and exit 2, and its test asserts that (call_trace.h:577-590). Make the Rust parser match the C++ one, and never let a value saturate to "unbounded".
Two more, in the tool:
rules differ,truncated=yesand a missing header only warn and can still exit 0 (test_differing_rules_print_a_warningasserts exactly that). A script reads 0 as "identical", so give those a distinct exit code — a rules mismatch means the traces are not comparable at all. A warning when both sides report the samestack=would also help.case_dropped_record's wall-clock< 100 msis load-dependent (the body already saw it fail under-j8); assert the drop count and the# droppedordering, keep the timing as a print.
Documentation worth one line in the README: the trace records identity and the return class, no arguments and no strings — so a divergence that lives only in an argument is invisible to the diff (a hash of the first argument qwords would be safe, unlike strings). And RT_CALLER's 0x140 duplicates the stub's 0x138 frame by hand — a static_assert against the blob would keep them tied.
|
A heads-up for this pull request: the page of D3D12 switches ( Nothing checks that today, so the page has drifted before (it was a name behind when this was measured). A test that checks it is waiting to be opened (DOCS-SWITCHES-PAGE-CHECK), and it would make this pull request's CI red until the page is written again. One command does that: It writes the page with the names in it and nothing else; the diff is the new rows. |
|
Confirmed the Rust/C++ trace-cap mismatch under Wine on AI-assisted with OpenAI Codex. |
Claimed in the coordination issue as: RT-CALL-TRACE and D3D12-CALL-TRACE (#2570 (comment))
What and why
When gta6rt and leonida.exe stop at different places in the boot, there is no record of which import call they first handled differently. With
LEONIDA_CALL_TRACE=<new file>set, both runtimes now record every call through the import tables of the title's image and its DLLs (normal and delay-load) in one shared v1 text format. Unset, nothing changes:wrapreturns the import's address and no thunk block is allocated.tools/call_trace_rules.def: the rules both runtimes read (gta6rt includes it, leonida-loader parses it), so the two traces are comparable. Stack walks andRtlCaptureContext2are entry-only (a wrap frame would end the title's stack walk at the stub), and__vdeclvector math is skipped (its YMM arguments are not kept by the stubs).Eline, real return address) or wrapped (CandRlines with the return class). The stubs are registered for unwinding; the entry stub's unwind range ends before its final jump.LEONIDA_CALL_TRACE_MAX_MB(default 4096). The writer lock is taken with a bound of about 10 ms; a record that cannot get it is dropped and the next one writes# dropped N.RT_CALLER(), which sees through the wrap frame.tools/call_trace_diff.pypairs the two traces' threads (main first, then by start address and common call prefix), aligns each pair's calls and reports the first divergences: calls one side never makes, different return classes, different call counts, threads on one side only and calls still open at the end. It streams its input (two synthetic 1M-call traces: 14.0 s, 336 MB peak).Not run in game.
Tested
Windows 11 (26200), Visual Studio 18 (2026) MSVC, AMD Radeon RX 6800 (driver 32.0.21030.2001), rebased on
mainat66b5d0433:cargo test --profile diag -p leonida-loader --lib -- call_trace: 29 passedctest: 205 of 205 passed, 2 disabled (gameinput,gameinput_script, no SDL3 here)python -I tests/test_call_trace_diff.py,tests/test_call_trace_rules.py: OK;python -m compileall -q tools tests: OKscripts/check_no_game_data.pyon the changed files: OKOne full
ctest -j 8run failedcall_trace(and the unrelatedwindows_crash_monitor); both passed alone and in the next full-j 8run.case_dropped_recordchecks that a dropped call takes under 100 ms of wall time, which a machine running eight test jobs can exceed. The failing run's output was not kept, so that cause is likely, not confirmed.