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

Open
github-bot wants to merge 3 commits from github-bot/gh-41 into main AGit
Owner

@⁠Andretuta on GitHub · 2026-11-24 02:05 UTC · original
ubiquitarianism:old-pr/7189 → main · +170 −4 · 4 files · 3 commits · draft

Carried over from old PR 7189 by rafaelpssz in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/7189, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
rafaelpssz: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Claimed in the coordination issue: https://github.com/ItsNotRexed/Leonida/issues/7049#issuecomment-7106564862

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

  • @Pipodi: #6953 and the boot-chain measurements this was used against.
  • @NiiRoZz: #7075/#7076, which got the run far enough to need it.
  • @dadsmallbuk1: tested it on an RTX 5090 with a native MSVC build (ctest -R ^startup_trace$ pass, the six new checks).
  • @illusionart453-max: an independent native MSVC build and run (32/32).
  • @JoaoPauluu: the Wine run that found module_offset(0) naming the null page as the executable, and the guard now in registry.cpp.
  • @TheHoracio: tested on RX 7800 XT.
  • @Jadiac5: tested on RX 9070 XT.
  • @DeSunShine: tested on RTX 4090.
  • @itaskaev2: tested on RTX 4080 SUPER.
  • @SirKingg: an integration check with six other PRs' hunks in a Windows Sandbox, and the tail-jump case: a null tail jump pushes no return address, so the field named the wrong frame.
  • @sds-228: the same finding in review, with the two ways out (verify the instruction, or narrow the field). d077c5a4c does both.
**@⁠Andretuta** on GitHub · 2026-11-24 02:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/41) `ubiquitarianism:old-pr/7189` → `main` · +170 −4 · 4 files · 3 commits · draft > Carried over from **old PR 7189** by `rafaelpssz` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/7189`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `rafaelpssz`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Claimed in the coordination issue: https://github.com/ItsNotRexed/Leonida/issues/7049#issuecomment-7106564862 ### 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 - `@Pipodi`: `#6953` and the boot-chain measurements this was used against. - `@NiiRoZz`: `#7075`/#7076, which got the run far enough to need it. - `@dadsmallbuk1`: tested it on an RTX 5090 with a native MSVC build (`ctest -R ^startup_trace$` pass, the six new checks). - `@illusionart453-max`: an independent native MSVC build and run (32/32). - `@JoaoPauluu`: the Wine run that found `module_offset(0)` naming the null page as the executable, and the guard now in `registry.cpp`. - `@TheHoracio`: tested on RX 7800 XT. - `@Jadiac5`: tested on RX 9070 XT. - `@DeSunShine`: tested on RTX 4090. - `@itaskaev2`: tested on RTX 4080 SUPER. - `@SirKingg`: an integration check with six other PRs' hunks in a Windows Sandbox, and the tail-jump case: a null tail jump pushes no return address, so the field named the wrong frame. - `@sds-228`: the same finding in review, with the two ways out (verify the instruction, or narrow the field). `d077c5a4c` does both.
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 <[email protected]>
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 #7189.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reported by SirKingg and sds-228 on #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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:42:00 +00:00
This pull request has changes conflicting with the target branch.
  • runtime/shims/startup_trace.h
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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