Skip to content

A fatal exception says where it happened: library+offset in last-fault.txt and on stderr (Windows) - #1266

Merged
Hona merged 3 commits into
devfrom
hitch/crash-record-place
Nov 25, 2026
Merged

Hona merged 3 commits into
devfrom
hitch/crash-record-place

Conversation

@Hona

@Hona Hona commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

A fatal exception on Windows ends the app with its code and, for a window, a 64-byte record that holds the code and nothing else. Neither says where it happened. A launch from a script gets no Windows report either (it inherits an error mode in which none is written), and a fault in a launch's first half second comes before the profile's record can be written at all.

This makes the app say the place itself, with no debugger attached.

flowchart LR
    F[exception] -->|"only with OPENCODE_RUNE_FAULT_FIRST_CHANCE=1"| V[vectored handler: 'first chance' line]
    F --> W{Windows walks the stack<br/>to the thread's start}
    W -->|reached| H[unhandled_filter]
    W -->|"not reached: the process ends, no call"| X[exit with the code]
    H --> R[record_fault: last-exit.bin, code only]
    H --> P[place::write: 'fatal exception' line]
    V --> L["&lt;logs&gt;/last-fault.txt + stderr"]
    P --> L
    H --> T[TerminateProcess with the code]
Loading

What a fault leaves, in <logs>/last-fault.txt and on stderr (from a run of this branch's Windows build, a read of address 8 made in a system library from outside):

opencode-rune 0.0.0-pr-1266-2613: fatal exception 0xC0000005 (read of 0x0000000000000008) on thread 19804 at ntdll.dll+0x16C451
opencode-rune:   #00 ntdll.dll+0x16C451
opencode-rune:   #01 kernel32.dll+0x2DDA7
opencode-rune:   #02 ntdll.dll+0xC9C5C
  • Where it is written from: last_exit/place.rs, called by the existing unhandled-exception filter after the 64-byte record, on the faulting thread.
  • What it holds: the exception's code; for an access violation or in-page error, read / write / execute and the address touched; the thread's id; the faulting instruction and up to 24 frames above it, each as library+offset. An offset becomes a function with the build's debug file.
  • Inside a process that is going down: fixed static buffers, no allocation, no lock of the app's, and no call that takes the loader's lock. A library is found with RtlPcToFileHeader and named by the file its image is mapped from (NtQueryVirtualMemory); the frames come from RtlCaptureStackBackTrace. After a stack overflow only the first line is written: the walk needs stack that thread no longer has.
  • No personal data: of a library's path only the last component is written, never its folder. The file sits in the log folder (made at the fault if it is not there yet), so Export logs packs it.
  • Headless runs too: a headless run still keeps no exit record, but it now arms the filter so that a fatal exception in it says where. Its exit code is unchanged (the exception's code).
  • A second, earlier witness, off unless set: Windows calls the unhandled-exception filter only when it can walk the faulting thread's stack down to the thread's start. A fault that leaves the stack unwalkable (a jump into the middle of code, a smashed stack) ends the process with its code and no call. With OPENCODE_RUNE_FAULT_FIRST_CHANCE=1 a vectored handler writes the same fields marked first chance for 0xC0000005, 0xC000001D, 0xC0000409 and 0xC00000FD, at most eight a process, before any stack is walked. It is a diagnostic arm: a first-chance exception may be one some frame then handles. Unset, no handler is installed.
  • Not in it: the thread's name (reading it allocates); macOS and Linux (their signal handler is unchanged).

Shown on this branch's Windows x64 build

A fault made from outside in a running app: one thread started in its process, no debugger, nothing written into it. Then the exit code (all 32 bits), stderr and <logs>/last-fault.txt were read back.

  • After build: head 888ca1af63, Windows x64 artifact of PR CI run 45706128174 (based on 397ae99209, Rune pin d5c7a5ad2; PR CI compiled macOS, Windows x64, Windows arm64 and Linux x64 plus guardrails, with Linux arm64 skipped).
  • Before build: published 0.0.0-dev-490, commit 5381921190 (Rune pin 4d8df909), release run 45613776234.
Fault Run Exit code Lines on stderr last-fault.txt
read of address 8 in ntdll headless 0xC0000005 fatal exception 0xC0000005 (read of 0x…08) … at ntdll.dll+0x16C451, 3 frames the same 4 lines
read of address 8 in ntdll real window 0xC0000005 the same the same 4 lines
breakpoint in padding between two functions of the app's library, at an offset chosen beforehand (+0x3119) headless 0x80000003 fatal exception 0x80000003 … at opencode-desktop.dll+0x3119, 3 frames the same 4 lines
the same real window 0x80000003 the same the same 4 lines
ud2 in the middle of a function of the app's library (+0x2162): a stack Windows cannot walk headless, switch unset 0xC000001D none none
the same headless, switch set 0xC000001D first chance: exception 0xC000001D … at opencode-desktop.dll+0x2162 the same 2 lines
the same real window, switch set 0xC000001D the same the same 2 lines
read of address 8 in ntdll headless, switch set 0xC0000005 the first chance record, then the fatal exception record both, 8 lines
read of address 8 in ntdll, on before build 0.0.0-dev-490 (5381921190, run 45613776234) headless 0xC0000005 none none
  • Web check (scripts/web.ps1 -Check) on head 888ca1af63: exit 0 (Finished dev profile … in 1m 24s; web clock: 1095 files in 49 crates, no std::time::Instant or SystemTime::now).
  • Note added after merge (2e366c0613): merged without dev taken in after fix(deps): pin rune to 5342f14d (93 commits): window buttons on Wayland without server decorations, smaller backdrop blur copies #1257 (affe876fca, Rune pin 5342f14d1) landed (branch head 888ca1af63 was based on 397ae99209, Rune pin d5c7a5ad2); no files overlapped with the intervening dev commits (only last_exit/ changed). First built with the new pin (5342f14d1) by run 45715407465 (check build chore: check build of dev 2e366c0613 (NEVER MERGE) #1280, head 53abad895a), completed green (guardrails, macOS, Windows x64 and arm64, Linux x64; Linux arm64 skipped).
  • Not shown by a run: a stack overflow (first line only, by reading); Windows arm64 (it compiles; the frames come from the same capture call); Linux arm64 (skipped in PR CI).

@Hona
Hona marked this pull request as ready for review November 25, 2026 22:35
@Hona
Hona merged commit 2e366c0 into dev Nov 25, 2026
7 checks passed
@Hona
Hona deleted the hitch/crash-record-place branch November 25, 2026 22:36
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.

1 participant