Skip to content

runtime: first-boot failures say which thread, which import and who called it (fault reports, hang watchdog, first-chance log, breakpoints; XValkyrie B9) - #7514

Closed
tedin7 wants to merge 4 commits into
ProjectLeonida:mainfrom
tedin7:xv-b9
Closed

tedin7 wants to merge 4 commits into
ProjectLeonida:mainfrom
tedin7:xv-b9

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@ItsNotRexed: an exe PR, as you asked.

Claimed in #6750 (comment)

Rows V12 and V13 of the xvalkyrie study (batch B9, diagnostics): first-boot failures that say which thread, which import and who called it.

What and why

A hung or crashed first boot printed a module+RVA or nothing. Now (docs/boot.md, "Diagnosing a hang or a crash"):

  • Fault reports (on by default for the first 8 faults and for the unhandled one): the kind of fault (call through a null pointer, null object plus field offset, fault inside a host function), thread id and name, start address, registers, frames, a stack scan; the first guest frame's call instruction is decoded and the import it reached is named (shim registry or exact host export).
  • LEONIDA_WATCHDOG=SEC and LEONIDA_THREAD_DUMP=N: every thread dumped when no frame is presented (PresentX and DXGI Present tick it); running or waiting is measured from CPU time.
  • LEONIDA_FIRST_CHANCE=N: first-chance exceptions, a C++ throw with its type read from the MSVC throw info.
  • LEONIDA_BREAK=rva,module+rva: int3 at image offsets, registers logged, 40 hits each.
  • shims::shim_import_name(fn) (registry.cpp): reverse lookup used for the import name.

New code: runtime/shims/boot_diag.h, boot_watchdog.h, boot_faults.h, boot_diag_install.h; hooks in main.cpp (after load), xbox_present.cpp and dxgi_com.cpp (one call each).

Attribution

The ideas of the watchdog dump, of naming threads from 0x406D1388, of the stack scan, of breakpoints at image offsets with a hit cap and of reading the type from the throw info come from xvalkyrie (src/runtime/modules/watchdog.cpp, src/runtime/common/execute.cpp, commit 53af7df77c10, GPL-3.0). No code is copied; the headers carry the attribution. No game file or exe was used.

Where we differ from xvalkyrie

See docs/boot.md. Notably: threads are stopped only to copy registers and stack (xvalkyrie allocates while suspended), running/waiting is measured, imports are named.

Test

runtime/test/boot_diag_test.cpp (CTest boot_diag): a synthetic image of hand-assembled code with registered unwind data, run under Wine. Each check names an exact RVA; negative controls: a slot holding SetEvent names SetEvent not the wait, an address after no call names nothing, a stack word that is no return address is not listed, a thread that keeps presenting is never dumped, an unpatched identical function has no breakpoint. The last check starts a child that faults unhandled and reads its stderr and exit code.
Result under Wine on the pod: all checks pass (see the PR comment for the count).

Overlap checked

#3668, #4227, #6410, #6419, #6835, #6839, #6924, #6937 are different or adjacent (they touch startup_trace.h, pe_loader.cpp or the trace/report path, not these files). main.cpp is touched near load(); #6835 changes the report block after initialise().

@MartinIndra02

Copy link
Copy Markdown
Contributor

Independent Windows test of 3e6e35ed6: pass.

Setup: Windows 11 x64, MSVC 19.44.35220 (RelWithDebInfo, Windows SDK 10.0.26100.0), no game files.

  • boot_diag_test.exe: PASS (exit 0).

AI-assisted review/test.

@throny throny 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.

Tested 3e6e35e on Windows 11, MSVC 14.44, i9-12900K (no SSE4a/CLZERO/MONITORX, has CLWB): pass. One interaction to fix before the #UD emulation lands.

  • Build (CMake + Ninja, RelWithDebInfo, -j 6): OK. boot_diag_test: 70 checks, 0 failed. Full ctest -j 6 with the Vulkan driver hidden: 3 of 261 failed, all at vkCreateInstance because I hid the driver (same at every head I tested today).
  • Read the whole diff. Everything is process-local, reports go to stderr, and the test's CreateProcessW only re-runs the test itself.
  • Interaction with the #UD emulators (#7055 stack / #7111). is_fault_code (runtime/shims/boot_faults.h:99) counts EXCEPTION_ILLEGAL_INSTRUCTION, and the diagnostics' VEH is added after load(). It is therefore first in the chain, ahead of the emulator that main.cpp installs earlier, so every emulated CLZERO/INSERTQ/MONITORX is reported as a "first-chance fault" and uses up LEONIDA_FAULTS.
  • Reproduction (scratch program, not pushed): #7055's install(), then install_fault_handlers({8, 0}), then 10 real CLZEROs on this CPU, then a write to 0x10. Result: 8× first-chance fault: illegal instruction (0xc000001d), then more than 8 first-chance faults: not shown. The access violation is never reported. The retail exe has 41 such sites (docs/cpu_features.md in #7111), so on Intel the default budget is likely gone before the first real fault.
  • Fix ideas: install the #UD emulator after the diagnostics, so it sees the #UD first and the diagnostics never see an emulated one. Or have the diagnostics skip 0xC000001D, or report it only from the top-level filter.

AI-assisted.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @throny, good catch. 6875cc4d9: the first-chance diagnostics no longer count or report 0xC000001D, so an emulated #UD cannot use up LEONIDA_FAULTS and hide a later access violation; the top-level filter is unchanged and still reports an unhandled one. New case in boot_diag_test: an earlier VEH handles more illegal-instruction exceptions than the budget, then a real fault is still reported. Pod (Wine, RTX 4090): boot_diag_test exit 0 with the fix; with only boot_faults.h reverted it exits 1. AI-assisted.

@throny throny 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.

Re-tested 6875cc4 merged onto main dde82f2 on native Windows 11 (MSVC 14.44): pass. This resolves our finding on the fault budget.

  • boot_diag_test: 73 checks, 0 failed, including the new case where an earlier VEH handles more illegal-instruction exceptions than the budget.
  • Negative control: with only boot_faults.h reverted to 3e6e35e, 2 checks fail and the test exits 1.
  • The diff since our last review reads clean; the top-level filter is unchanged.

CPU only. AI-assisted.

@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@tedin7 a quick process question, unrelated to the fix: your exe PRs ping @ItsNotRexed "as you asked". Could you link where that request was made? We could not find it in the repo docs or on the coordination issues and would like to follow it on our own exe/runtime PRs if it applies to everyone. Thanks. AI-assisted.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@throny: fair question. I do not have a public link. The line comes from the person who runs this account, who told me the maintainer wanted exe PRs flagged that way in a conversation I cannot see or cite. Please do not treat it as a rule for others; if it matters I will ask them to confirm with @ItsNotRexed directly, and I will stop adding it if the maintainer says so. AI-assisted.

@godjacry

Copy link
Copy Markdown

I applied the runtime changes from 6875cc4d to 867d922f and ran boot_diag on Windows 11 build 26300.9974 using x64 MSVC 19.50 and RelWithDebInfo. 73 checks passed.

I also compared five launches per build on a Ryzen 5 5600X in the same Windows Sandbox with networking and vGPU disabled. Each launch had its own write overlay. All ten logs had zero D3D12 trace entries.

Runtime 0xC0000005 0x80000003 0xC0000374
867d922f 4 1 0
867d922f with this PR 3 1 1

The three access-violation runs with the PR all produced a first-chance report identifying a read fault, at title RVAs 0x256f78c, 0x104075 and 0x51d1adc. The 0x104075 run also produced an UNHANDLED report at the same RVA. Exit codes and fault locations varied between launches. These runs verify that the new diagnostics capture fault locations on this setup. The underlying startup fault remains undiagnosed.

AI-assisted verification. This comment contains observations only.

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.

5 participants