Skip to content

startup trace: a call through a null pointer names its caller (null_call_from) - #7189

Open
rafaelpssz wants to merge 3 commits into
ProjectLeonida:mainfrom
rafaelpssz:feat/trace-null-call
Open

rafaelpssz wants to merge 3 commits into
ProjectLeonida:mainfrom
rafaelpssz:feat/trace-null-call

Conversation

@rafaelpssz

@rafaelpssz rafaelpssz commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Claimed in the coordination issue: #7049 (comment)

What and why

A call through a null pointer faults on the instruction fetch at address 0. Until now, --trace logged it as "at":"0x0","access":"execute","address":"0x0","stack":[]. stack_from stops at once because Rip is 0, so the trace couldn't say who made the call. That's the most common shape of a boot stop right now: a console vtable slot past the end of a PC proxy's table, or an unset out-pointer the title calls through.

A call has already pushed its return address. When an access violation is at an address in the first 64 KiB, the handler now:

  • reads the frame on top of the stack from [rsp], as stack_from already does for a leaf function;
  • walks the stack from that frame;
  • names the frame (module+RVA) with one of two fields.

null_call_from is used only when the call is proven. The instruction before the frame must be an indirect call (FF /2, register or memory), and its operand, evaluated with the registers of the fault, must be the faulting address. A fault on the fetch at a call's target comes before any instruction of the target runs, so those registers are still the call's own.

null_transfer_return is used otherwise: a direct call, an indirect call to some other address, or nothing recognizable. A tail jump through null pushes nothing, so the frame on the stack belongs to whoever entered the jumping function. The field says where that code would have returned to and makes no claim about who made the transfer.

One case still reads as a call and is not: a tail jump through the same register the enclosing call went through. The README and the header say so.

Nothing else changes, and the handler still only records. If [rsp] isn't readable, the event is logged as before.

before: {"kind":"exception","code":"0xc0000005","at":"0x0","access":"execute","address":"0x0","stack":[]}
after:  {"kind":"exception","code":"0xc0000005","at":"0x0","access":"execute","address":"0x0",
         "null_call_from":"a.exe+0x1e86853","stack":["a.exe+0x1e86853","a.exe+0x5c5ffc6",...]}

(The addresses above are made-up examples.) On the retail executable this turned the empty event into the caller. Its disassembly is a call through device vtable offset 0x428 = slot 133, which is the stop #6953 fixes. It took one run instead of a debugger session (integration run in #7049).

Changes

  • runtime/shims/startup_trace.h: the null-page case in log_exception, faulting_call_ends_at (the check above), and the header's event examples.
  • runtime/test/startup_trace_test.cpp: the synthetic image makes four transfers to address 0:
    • call rax with rax 0: null_call_from, the instruction after the call, and the stack starts there;
    • call [rip+slot] with a zero slot: null_call_from too;
    • jmp rcx with rcx 0, reached by a direct call: null_transfer_return, no null_call_from;
    • the same jump reached by call rax to a real function: null_transfer_return, no null_call_from.
      The existing in-image read fault gets neither field.
  • runtime/README.md: the field in the startup-trace event table.
  • runtime/shims/registry.cpp: module_offset does no module lookup for an address in the first 64 KiB. Under Wine, GetModuleHandleExW(FROM_ADDRESS, 0) answers with the executable, so a fault at 0 was named exe+(0 - base) (JoaoPauluu's finding and fix).

Tested

Windows 11 Pro 26200, clang-cl/xwin cross build (MSVC 14.44 headers), RelWithDebInfo:

  • startup_trace_test: 42 checks, 0 failed (d077c5a4c).
  • With d077c5a4c's change to startup_trace.h reverted, 4 of the 42 fail: both jumps are attributed to the enclosing call, which is the misattribution the reviewers reported.
  • Before that, without the first change to startup_trace.h, 2 of the then 32 failed: null_call_from … and the null call's stack starts at its caller.
  • Not run for d077c5a4c: MSVC, and the retail executable (the earlier retail result below was for 4524c0136; that call is an indirect call through a vtable slot, the form the new check accepts).
  • gta6rt builds. With the change, a retail --run --trace on my own copy logged null_call_from for the slot-133 call, as described above. No game data here.

Thanks

An access violation at an address in the first 64 KiB (a call through a null
or null-page pointer) used to be logged as "at":"0x0" with an empty stack:
the unwinder had no instruction to start from. The call has just pushed its
return address, so the trace now starts from that frame, as for a leaf
function, adds it as "null_call_from" (module+RVA) and walks the stack from
there.

startup_trace_test builds a leaf stub that does xor eax,eax / call rax and
checks the new field and the stack's first frame (2 of the 32 checks fail
without the change).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dadsmallbuk1

Copy link
Copy Markdown

Tested cd6277c on NVIDIA GeForce RTX 5090, driver 617.42, Windows 11 (26200), Intel i9-13900K, native MSVC 2022 RelWithDebInfo: pass.

  • ctest -R ^startup_trace$: 1/1 pass. The six new checks pass: the null call reaches the handler, it is an execute fault at 0x0, null_call_from names the instruction after the call as module+RVA, the stack starts at the caller, and a fault inside the image isn't counted as a null call.
  • Code read: only the exception record gains a field. The handler still returns EXCEPTION_CONTINUE_SEARCH; the return address is read from Rsp after an IsBadReadPtr check, on a copy of the CONTEXT.
  • This would have named the caller in my retail boot run earlier today (Coordinating who works on what (40) (moved to #7049) #6910), where one crash was an execute fault outside every module.

AI-assisted (Claude Code).

@rafaelpssz

Copy link
Copy Markdown
Collaborator Author

@dadsmallbuk1 thanks for testing it on the 5090 with MSVC, added to Thanks.

@illusionart453-max

Copy link
Copy Markdown

Independent native Windows/MSVC 19.44, SDK 10.0.26100, RelWithDebInfo at cd6277c: configured isolated CPU runtime, built and ran startup_trace_test: 32 checks, 0 failed. The null-call execute-fault, module+RVA caller, stack-start caller, and final-exit ordering checks passed. Build emitted MSB8029 for TEMP placement; no C++ source warning observed. No Vulkan/GPU coverage, no game files. AI-assisted (Codex).

@JoaoPauluu

Copy link
Copy Markdown

Tested cd6277c22 under Wine: the feature works, but startup_trace_test fails 4 of 32 checks there, because of how an address of 0x0 gets named under Wine. A one-line guard in module_offset fixes it (below).

Setup: CachyOS, Wine 11.21; clang-cl 23.1.5 + xwin 0.10.0 cross build (SDK 10.0.26100), RelWithDebInfo, -DLEONIDA_VULKAN_HEADERS_FETCH=ON. The head merges cleanly with main 8575d36ed. RTX 3060, NVIDIA 620.70.06, which plays no part here.

ctest -R ^startup_trace$ under Wine: fails, 32 check(s), 4 failed. The 4 are the four null-call checks after "reached the test's handler". On main the same test passes under Wine (26 check(s), 0 failed).

The null-call event the test writes (synthetic image) shows why:

{"kind":"exception","code":"0xc0000005","at":"host:startup_trace_test.exe+0xfffffffec0000000","access":"execute","address":"0x0","null_call_from":"trace_image.bin+0x1244","stack":["trace_image.bin+0x1244",...]}

null_call_from, access and the stack are all right. But at isn't "0x0", so the test's lookup for "at":"0x0" finds nothing and the other three checks fail with it. where(0) → shims::module_offset(0) falls through to GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, 0) (runtime/shims/registry.cpp:351). On Windows that fails for address 0. Wine treats a null lpModuleName as "the process's executable" even with FROM_ADDRESS, so the address comes out as the exe plus 0 - base.

A guard there fixes it. With this change on top of the PR, the test passes under Wine with 32 check(s), 0 failed:

-    if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+    if (address >= 0x10000 && GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,

(0x10000 matches your kNullPageEnd.) The bug was already on main: any fault at a null-page Rip was mis-named under Wine. Your test is the first to depend on it, so the Runtime workflow's wine job should fail on this PR as it stands. It's queued, not run, at the moment.

Retail executable (my own 1.0.2.1 copy, --run under Wine): the trace has two access violations, both data reads (access":"read", one in gta6rt.exe host code, one in the title), and neither gets null_call_from. A data fault at a null address doesn't trigger the new field, as intended, since the check is on ExceptionAddress, not on the faulting data address. The run doesn't reach the slot-133 null call you saw on Windows, because Wine stops earlier (the RT-259 stop in #7232), so the positive case on retail is untested here. The run also hung once WineDbg attached (exit 124 from my 180 s timeout). That's Wine's crash handler, not the PR.

Counts and error classes only from the retail run. AI-assisted (Claude Code).

Under Wine, GetModuleHandleExW(FROM_ADDRESS, 0) answers with the
executable, so a fault at address 0 was named exe+(0 - base) instead of
0x0 and the null-call checks of startup_trace_test failed there (4 of 32).
No module can sit in the first 64 KiB; skip the lookup below 0x10000, as
JoaoPauluu proposed on ProjectLeonida#7189.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rafaelpssz

Copy link
Copy Markdown
Collaborator Author

@JoaoPauluu thanks, exact diagnosis. Your guard is in as 4524c01 (registry.cpp, address >= 0x10000 before GetModuleHandleExW). startup_trace_test is still 32/32 on Windows (clang-cl/xwin). Added you to Thanks, along with @illusionart453-max for the independent MSVC run.

@TheHoracio

Copy link
Copy Markdown
Contributor

Tested 4524c0136 on AMD Radeon RX 7800 XT (RDNA3), Windows 11, MSVC 2022 RelWithDebInfo: pass. scripts/build_runtime.ps1 and the device/proxy subset of ctest: 26/26. No game files. (AI-assisted run.)

Merges into a branch with #4313/#7021/#7240 with a single trivial conflict in runtime/shims/startup_trace.h (the example-line comment block); taking this PR's lines resolves it.

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 4524c01 on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass

  • MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo. Built startup_trace_test (no GPU used; the card is only the machine it ran on). The earlier native runs in the thread were on cd6277c22; this is the current head with the registry.cpp guard.
  • ctest -R ^startup_trace: pass; the exe by hand: 32 check(s), 0 failed.
  • Negative control: runtime/shims/startup_trace.h put back to the merge base (4da521d), test kept: 32 check(s), 2 failed (null_call_from names the instruction after the call, as module+RVA and the null call's stack starts at its caller). Restored: 0 failed.
  • Native Windows fails the GetModuleHandleExW lookup at address 0 anyway, so the new address >= 0x10000 guard in registry.cpp changes nothing here; it is for Wine, which this run does not cover.
  • Not done: Wine, a negative control for the registry.cpp guard. Not run against the retail executable.

AI-assisted (Claude Code).

@DeSunShine

Copy link
Copy Markdown
Contributor

Tested 4524c0136 merged into main dde82f27e on NVIDIA GeForce RTX 4090 (driver 621.24), Windows 11 Pro 26200, MSVC (VS Build Tools 18) + Ninja, Vulkan SDK 1.4.363: pass.

  • ctest -R "startup_trace|tiny_game" --output-on-failure: 11/11 passed (startup_trace and the run_tiny_game* tests).

AI-assisted (Claude Code).

@itaskaev2

Copy link
Copy Markdown

Tested 4524c013 (contains main e0a8293f) on native Windows 11 (26300), NVIDIA GeForce RTX 4080 SUPER, driver 616.92, MSVC 19.51 (14.51.36231), Ninja, RelWithDebInfo, full runtime/ build: pass. This adds an MSVC 19.51 run of the current head, which includes the Wine guard in registry.cpp. The earlier native runs were on cd6277c2.
AI-assisted (Claude Code), no game files.

  • ctest -R startup_trace: pass. startup_trace_test.exe gives 32 check(s), 0 failed, including:
    • ok the call through a null pointer is an exception at 0x0
    • ok null_call_from names the instruction after the call, as module+RVA
    • ok the null call's stack starts at its caller
    • ok a fault inside the image is not a null call
  • Negative control 1: I put runtime/shims/startup_trace.h back to e0a8293f and kept the test. The result is 32 check(s), 2 failed, exit 1:
    • FAIL null_call_from names the instruction after the call, as module+RVA
    • FAIL the null call's stack starts at its caller
  • Negative control 2: I put runtime/shims/registry.cpp back to e0a8293f. On native Windows that gives 32 check(s), 0 failed. So the address >= 0x10000 guard changes nothing on Windows, where GetModuleHandleExW(FROM_ADDRESS, 0) finds no module. That matches the description: the guard is for Wine.
  • Full ctest (-j 4): 264 of 268 pass or skip. The 4 failures are not from this PR:
    • d3d12_indirect_dispatch_count, d3d12_indirect_rt and xbox_present (a crash; RTSS is running) fail on main here.
    • d3d12_vulkan_device stops at tiles == 1. It does the same on current main dde82f27, and it passes on 1cc6e3c1. So it is a regression on main in that range, not this PR.

@SirKingg

Copy link
Copy Markdown
Contributor

Independent Windows Sandbox integration check of 4524c0136 with #8379, #2490, #6582, #8461, #6964 and #8258 code/test hunks in a temporary checkout. The header's synthetic example conflicted with the TLS branch and was excluded; the tracing logic and synthetic tests were applied. A clean runtime rebuild was required because an earlier comparison build had not tracked header dependencies correctly.

Only counts, error classes and public slot names are shared; traces and analysis stay local. AI-assisted.

@SirKingg

Copy link
Copy Markdown
Contributor

One diagnostic edge case: a null tail jump does not push a return address. In a synthetic mapped function that tail-jumps through null, this handler reports the host function that entered the mapped function as null_call_from, not the mapped jump that transferred to null. The synthetic startup-trace test reproduced this on Windows/MSVC; no game data is involved.

Could this field be described as a possible return-frame origin rather than a proven null-call site, or otherwise guard against tail transfers? The retail slot-133 measurement is unaffected: its recovered return address was independently checked to follow a call. I also reported the finding on #9065. AI-assisted.

@sds-228 sds-228 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runtime/shims/startup_trace.h:194-200 treats [rsp] as a pushed return address for any access violation below the null-page limit. For call rax that is correct, but a tail jump through null pushes nothing, so null_call_from can name an unrelated frame; the test only covers the call form. Please either verify the instruction before attributing the caller, or narrow the field and documentation to what can be proven.

AI-assisted (OpenCode).

…call is proven

Reported by SirKingg and sds-228 on ProjectLeonida#7189: the handler took the top of the stack as the return address of the
faulting call for any access violation in the null page. A tail jump through null pushes nothing, so the field
named the frame that had entered the jumping function, as if that call had gone to null.

The frame is now `null_call_from` only when the instruction before it is an indirect call (FF /2, register or
memory, with SIB, displacement and REX) whose operand, evaluated with the registers of the fault, is the faulting
address. A fault on the fetch at a call's target comes before any instruction of the target, so those registers are
the call's own. Otherwise (a direct call, an indirect call to some other address, nothing recognizable) the frame is
`null_transfer_return`: where that code would have returned to, with no claim about who made the transfer. `stack`
starts at that frame in both cases. One case still reads as a call: a tail jump through the same register the
enclosing call went through; README and the header say so.

startup_trace_test: four transfers to address 0 in a synthetic image (call rax, call [rip+slot], and a jmp rcx
reached by a direct call and by an indirect call to a real function). Red before the change at the four jump
checks (both jumps were attributed to the enclosing call), green after: 42 checks, 0 failed (clang-cl).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@rafaelpssz

Copy link
Copy Markdown
Collaborator Author

@SirKingg @sds-228 you are right, and thanks for the synthetic repro. The handler took [rsp] as the faulting call's return address for any fault in the null page. A tail jump through null pushes nothing, so it named the frame that had entered the jumping function.

d077c5a4c does both things sds-228 offered:

Verify the instruction. The frame is null_call_from only when the instruction before it is an indirect call (FF /2, register or memory, with SIB, displacement and REX) whose operand is the faulting address. The operand is evaluated with the registers of the fault. That is sound for a real null call: the fault is on the fetch at the target, before any instruction of the target runs, so the registers are still the call's own.

Narrow the field. Everything else is null_transfer_return: a direct call, an indirect call to some other address, or nothing recognizable. It says where that code would have returned to and nothing about who made the transfer. stack starts at that frame in both cases.

One case still reads as a call: a tail jump through the same register the enclosing call went through (host call rax, then xor eax,eax; jmp rax in the callee). The registers cannot tell those apart. The README row and the header comment state it. SirKingg, if your synthetic function jumps through rax and the host reached it by call rax, that is this case.

The test now makes four transfers to 0: call rax, call [rip+slot], and a jmp rcx reached by a direct call and by an indirect call to a real function. With the change reverted, 4 of the 42 checks fail, with both jumps attributed to the enclosing call. Not run: MSVC and the retail executable for this commit.

@TheHoracio @Jadiac5 @DeSunShine @itaskaev2 thanks for the runs on 4524c0136; you are in Thanks.

@rafaelpssz rafaelpssz reopened this Nov 23, 2026

@sds-228 sds-228 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The earlier concern about naming a tail jump as a call is resolved at this head: the handler now verifies the instruction before the return frame (an indirect call whose operand matches the faulting address) and reports tail transfers separately, with synthetic tests for register and memory calls and direct and indirect tail jumps. Approving. AI-assisted (OpenCode).

@fortkolbast1

Copy link
Copy Markdown

Tested d077c5a4c on Windows 11 26200, MSVC 14.51 (VS 18 Build Tools), CMake 4.4.4, Vulkan SDK 1.4.363 (no GPU work, no game files).

Built startup_trace_test alone from this head (configure + build, exit 0) and ran it: 42 checks, 0 failed, including the new cases:

ok    a call through a null slot in memory ([rip+disp]) is attributed too
ok    a null jump under a direct call is not attributed to that call
ok    it names the frame the jumping function would return to
ok    and the stack still starts at that frame
ok    a null jump under an indirect call to a real function is not attributed
ok    it names the frame the jumping function would return to (indirect)
ok    exit comes last

So a fault at Rip = 0 now names its caller, and the two negative controls (a null jump under a direct or indirect call to a real function) are not misattributed.

No checked: on this head before this run.

Approved by @fortkolbast1. AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.