Skip to content

startup: decode the MSVC C++ exception record into a sanitized summary - #1939

Open
tedin7 wants to merge 4 commits into
R0Y00:mainfrom
tedin7:x2w-frontier-throwinfo
Open

tedin7 wants to merge 4 commits into
R0Y00:mainfrom
tedin7:x2w-frontier-throwinfo

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #1758 (and #870)

What this unblocks: the startup debugger can report which HRESULT a C++ exception carried when a run ends on 0xE06D7363, as a short public summary with no address, path or name from the title.

This is the decoder only: it is not wired into tools/startup/debug_launch.py (untouched, so it does not collide with the other open PRs that edit that file). The follow-up that calls it at the first-chance stop is a separate change.

Source: the MSVC runtime header ehdata.h (shipped with the Visual Studio C runtime sources) for the 0xE06D7363 parameters and the _ThrowInfo / _CatchableTypeArray / _CatchableType layout; Raymond Chen, The Old New Thing (Microsoft Dev Blogs), "Decoding the parameters of a thrown C++ exception (0xE06D7363)"; Microsoft Learn, "EXCEPTION_RECORD structure (winnt.h)"; Microsoft Learn, "DXGI_ERROR" and "Direct3D 12 return codes", and winerror.h (Windows SDK) for the HRESULT names and values.

Verification (head 49ca19e34, origin/main 9b45cbb44 merged in with a merge commit):

  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP), x2w_pipe.py win2025 1939 --host proxmox --regex '^startup_msvc_throw_info$':
    • dev: ctest --preset dev -R '^startup_msvc_throw_info$' --no-tests=error --output-on-failure: 1/1 passed (startup_msvc_throw_info).
    • release /O2: ctest --preset release -R '^startup_msvc_throw_info$' --no-tests=error --output-on-failure: 1/1 passed (startup_msvc_throw_info).
  • Linux: python3 -B tests/startup_msvc_throw_info_check.py PASS; tests/docs_links_check.py, tests/bidi_controls_check.py, tests/startup_tools_lint_check.py pass; git diff --check origin/main...HEAD clean.

What it does

tools/startup/msvc_throw_info.py turns a 0xE06D7363 exception record into a sanitized summary. #1758 needs the thrown HRESULT of the BVH builder, whose throw info says the catchable type is the built-in long (.J), without putting addresses or names from the title in a public comment.

decode_throw(exception_code, params, read_mem) follows the public MSVC x64 layout (ehdata.h): params[0] magic, [1] thrown object, [2] _ThrowInfo, [3] image base; _ThrowInfo → RVA of _CatchableTypeArray → RVAs of _CatchableType → RVA of type_info, whose decorated name is at offset 16. read_mem(address, size) -> bytes | None is the only access to memory, so the core has no Win32 dependency: in debug_launch.py it would be the existing read.

The record it returns has:

  • status: ok, not_msvc_exception, missing_parameters (fewer than four, so no image base), bad_magic, no_throw_info, unreadable, bad_throw_info, too_many_types (cap of 16, a safety limit).
  • types: one entry per catchable type. Built-in scalars and a short list of public library classes (std::runtime_error, _com_error, ...) are named; any other class is other, so a class of the title never appears.
  • value, only when the first catchable type is a 32-bit scalar (.J, .H, .I, .K) of size 4: the HRESULT as a public name (E_INVALIDARG, E_OUTOFMEMORY, DXGI_ERROR_DEVICE_REMOVED, DXGI_ERROR_DEVICE_HUNG, D3D12_ERROR_*, common HRESULT_FROM_WIN32(...)), or HRESULT(0x........), with its facility category (win32, dxgi, d3d12, other). A positive number above 65535 is not reported.
  • Never an address, a path, a name from the title or a number over 32 bits. describe(record) gives a one-line form made of those fields only.

Test

tests/startup_msvc_throw_info_check.py builds synthetic exception records in a fake address space (no title data) and checks 89 cases: ten HRESULTs through .J (E_INVALIDARG, E_OUTOFMEMORY, DXGI_ERROR_DEVICE_REMOVED, a generic one, ...), .H and .I, another exception code, wrong magic, three parameters, null throw info and image base, a read that fails at each of the four steps (and a callback that returns short data or raises), an RVA beyond the readable range and one that overflows 64 bits, a negative count, 16 and 17 catchable types, a zero RVA, runtime_error, _com_error, a class of the title, a long of the wrong size, malformed names, a name that ends before unmapped memory, and a sweep that no record contains an address, a path, long hex or a number over 32 bits.

It is registered in CMakeLists.txt after startup_triage_run and in the Python check list of .github/workflows/windows.yml next to startup_triage_run_check.py.

Results (Linux, local; mutation and merge-tree runs at the earlier head 9a3c446)

Not run, not established

  • No real exception record: the layout is the public one as documented, and the test builds records from it, so a difference in a real record would not show here. The first real use is the capture step of startup-runtime: the package BVH builder throws an HRESULT during the post-confirm load #1758.
  • The HRESULT list is short on purpose; a code outside it prints as HRESULT(0x........) with its facility.
  • Rethrows (null throw info) and 32-bit records (three parameters) are reported as such and not decoded.

AI-assisted; commands listed were executed locally.

R0Y00#1758)

tools/startup/msvc_throw_info.py reads the public x64 throw info (magic, thrown object, _ThrowInfo, _CatchableTypeArray, _CatchableType, type_info name) through a read_mem callback and returns a record with no address and no path: the catchable types (built-in scalars and public library classes by name, any other class as other) and, for a thrown 32-bit scalar such as long, the HRESULT as a public name with its facility. It is not wired into debug_launch.py yet.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T11:08:47.818074Z
We couldn’t complete this review. Comment @codex review to try again.
49ca19e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please tighten the public summary allowlist. _describe_value treats every 32-bit scalar with bit 31 set as an HRESULT, then emits its raw hex in both the record and the one-line description. A thrown integer with that bit set can be private application data. Keep named, recognized HRESULTs such as E_INVALIDARG, and classify an unrecognized high-bit value without printing its bits in the shareable output. Add a synthetic scalar sentinel and check both the returned record and describe(). The core can still run independently of the startup debugger.

A thrown 32-bit scalar with bit 31 set is only named when it is a recognized public HRESULT. Any other value is reported as unrecognized_failure with no code, bits or facility, in both the record and describe(). Adds a synthetic sentinel test for both outputs.
@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed in 9a3c446.

  • _describe_value now names only recognized public HRESULTs (E_INVALIDARG and the other table entries keep their name, facility and code).
  • Any other value with bit 31 set is reported as unrecognized_failure (value and category): no code, no bits, no facility, in both the record and describe().
  • Test: synthetic sentinels (0xDEADBEEF, 0x80041234, 0x887A9999, 0xCAFE0001) are checked in the returned record and in the describe() line, in hex, unsigned and signed decimal. It fails on the previous head (mismatch) and passes now.

Verification:

  • python3 -I tests/startup_msvc_throw_info_check.py: PASS locally (Linux).
  • python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1939 --regex startup_msvc_throw_info: Win2025 (Build 26100, MSVC 14.44, WARP), Debug and Release ctest -R startup_msvc_throw_info 1/1 passed each, at 9a3c446.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 requested a review from R0Y00 November 25, 2026 11:18
@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is.

We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here.

AI-assisted; commands listed were executed locally.

@tedin7 tedin7 closed this Nov 25, 2026
@tedin7 tedin7 reopened this Nov 26, 2026
@tedin7
tedin7 marked this pull request as draft November 26, 2026 10:36
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Reopened and brought up to date: origin/main (9b45cbb44) merged into the branch with a merge commit (no force push). One conflict in CMakeLists.txt: main added runtime_startup_triage_run_cli_check at the same place as startup_msvc_throw_info; both tests are kept.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 49ca19e344de2afe87ecafbb4f0241bf0e081891:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 2): 6.76 s (configure 2.52 s)
    • Test (ctest --preset dev -R '^startup_msvc_throw_info$' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (startup_msvc_throw_info 0.11 s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 2): 242.37 s (configure 2.26 s)
    • Test (ctest --preset release -R '^startup_msvc_throw_info$' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (startup_msvc_throw_info 0.10 s)

Linux at the same head: python3 -B tests/startup_msvc_throw_info_check.py PASS (89 checks, including the unrecognized high-bit sentinels from the review: neither the record nor describe() prints their bits); tests/docs_links_check.py, tests/bidi_controls_check.py, tests/startup_tools_lint_check.py pass; git diff --check origin/main...HEAD clean.

The description now starts with the Part of, What this unblocks, Source: and Verification: lines. Still Draft until an independent second check passes.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

@MasterDomino Ready for review: head 49ca19e344de2afe87ecafbb4f0241bf0e081891 (decoder only; it is not wired into debug_launch.py).

Independent Stage-2 check on this exact head, Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP), Proxmox slots, dev and release /O2:

python3 x2w_pipe.py win2025 1939 --host proxmox --regex '^startup_msvc_throw_info$' --keep-release
ctest --preset dev     -R '^startup_msvc_throw_info$' --no-tests=error   -> 1/1 passed (startup_msvc_throw_info)
ctest --preset release -R '^startup_msvc_throw_info$' --no-tests=error   -> 1/1 passed (startup_msvc_throw_info)

Review result: records of a thrown long (named HRESULTs such as E_INVALIDARG and DXGI_ERROR_DEVICE_REMOVED), int, std::runtime_error and a class of the title decode as the public layout says; a failure code that is not a public HRESULT is classified without its bits; a class that is not a public library type is reported as other and never named. Wrong magic, missing image base, shifted throw info, a foreign image base, unreadable memory, a throwing read callback and an over-long name are all refused with a status and no exception; 4000 randomly mutated real records raised nothing and no address, path or title name appeared in any output.

Non-blocking: a thrown number up to 65535 is printed as a number (for example long=5); a private small error code would be visible there. The body already states this limit.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 marked this pull request as ready for review November 26, 2026 11:08
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

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.

2 participants