Crash reports: show the bytes of an instruction the CPU refused #198

Manually merged
github merged 1 commit from gh-pr/198/head into gh-pr/198/base 2026-11-26 03:54:21 +00:00
Owner

@⁠Dufftwt on GitHub · 2026-11-24 01:21 UTC · original
Dufftwt:fix/crash-report-instruction-bytes → main · +53 −0 · 1 files · 1 commits · merged 2026-11-24 07:53 UTC

What's wrong

When the CPU refuses an instruction (0xc000001d illegal instruction, 0xc0000096 privileged instruction), the crash report gives only its address:

VIctory: unhandled exception 0xc000001d at victory-image-b99f876b74d4a77f.dll+0x4ecc84a

The address doesn't say which instruction failed. On Intel hosts that is the first question every one of these reports raises, because the console's Zen 2 CPU has instructions Intel CPUs lack: clwb, clzero, monitorx/mwaitx, rdpru, SSE4a. The loader emulates the ones it knows, and the next one it doesn't know shows up as exactly this line. So far reporters have had to guess (#103 suggests "SHA-NI, SSE4a, or RDPID" for what turned out to be clwb) or dump the bytes by hand (#7). The reply in #106 asks for the address and the CPU model "to tell which encoding" it was, and #85's local patch logged the bytes for the same reason.

What the fix does

For these two exceptions, report in crash.rs now adds the bytes at the faulting address to the end of the report's first line:

  • It shows up to 15 bytes (the longest x86 instruction) as hex.
  • It never reads past the end of the faulting address's page, because the next page may not be mapped. The emulation in emulate_amd_only already reads instruction bytes under the same rule.

Other exceptions, the register lines and the stack lines don't change.

How it behaves after the fix

The report names the instruction by itself, in the console output and in crashes.log alike:

VIctory: unhandled exception 0xc000001d at victory-image-….dll+0x4ecc84a (code 66 0f ae 30 …)

0f 01 fd is rdpru, 66 0f ae /6 is clwb, and so on, so whoever reads the report can tell which instruction is missing without a debugger or the title's files.

Tests

The new test instruction_bytes_stop_at_the_end_of_their_page covers the byte reader:

  • From the start of a page, it gives 15 bytes.
  • For an instruction in the last 3 bytes of a page whose next page is PAGE_NOACCESS, it gives exactly those 3 bytes and doesn't fault.

I ran cargo test --workspace on GitHub's windows-latest with Rust 1.98.1 from rust-toolchain.toml:

  • This PR: everything passes. victory-loader has 19 passed, the other crates have 0 failed.
  • The report line itself: a throwaway test, used only on my CI branch, hands report an illegal instruction at the bytes of rdpru. On main it prints
    VIctory: unhandled exception 0xc000001d at victory_loader-….exe+0xf9cf0
    
    and with this PR
    VIctory: unhandled exception 0xc000001d at victory_loader-….exe+0xfd3e0 (code 0f 01 fd 48 89 c1 90 90 90 90 90 90 90 90 90)
    
  • I ran with --test-threads=1. With 4 threads, the shader crate's GPU tests sometimes crash on that runner (STATUS_ACCESS_VIOLATION), on unmodified main as well.

Not tested: a real illegal instruction on an Intel host, or the title.

Related: #7, #85, #102, #103, #106 (Intel hosts, 0xc000001d). #34 adds rdpru and clzero loops; this change doesn't overlap it.

**@⁠Dufftwt** on GitHub · 2026-11-24 01:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/198) `Dufftwt:fix/crash-report-instruction-bytes` → `main` · +53 −0 · 1 files · 1 commits · merged 2026-11-24 07:53 UTC ## What's wrong When the CPU refuses an instruction (`0xc000001d` illegal instruction, `0xc0000096` privileged instruction), the crash report gives only its address: ``` VIctory: unhandled exception 0xc000001d at victory-image-b99f876b74d4a77f.dll+0x4ecc84a ``` The address doesn't say which instruction failed. On Intel hosts that is the first question every one of these reports raises, because the console's Zen 2 CPU has instructions Intel CPUs lack: `clwb`, `clzero`, `monitorx`/`mwaitx`, `rdpru`, SSE4a. The loader emulates the ones it knows, and the next one it doesn't know shows up as exactly this line. So far reporters have had to guess (#103 suggests "SHA-NI, SSE4a, or RDPID" for what turned out to be `clwb`) or dump the bytes by hand (#7). The reply in #106 asks for the address and the CPU model "to tell which encoding" it was, and #85's local patch logged the bytes for the same reason. ## What the fix does For these two exceptions, `report` in `crash.rs` now adds the bytes at the faulting address to the end of the report's first line: - It shows up to 15 bytes (the longest x86 instruction) as hex. - It never reads past the end of the faulting address's page, because the next page may not be mapped. The emulation in `emulate_amd_only` already reads instruction bytes under the same rule. Other exceptions, the register lines and the stack lines don't change. ## How it behaves after the fix The report names the instruction by itself, in the console output and in `crashes.log` alike: ``` VIctory: unhandled exception 0xc000001d at victory-image-….dll+0x4ecc84a (code 66 0f ae 30 …) ``` `0f 01 fd` is `rdpru`, `66 0f ae /6` is `clwb`, and so on, so whoever reads the report can tell which instruction is missing without a debugger or the title's files. ## Tests The new test `instruction_bytes_stop_at_the_end_of_their_page` covers the byte reader: - From the start of a page, it gives 15 bytes. - For an instruction in the last 3 bytes of a page whose next page is `PAGE_NOACCESS`, it gives exactly those 3 bytes and doesn't fault. I ran `cargo test --workspace` on GitHub's `windows-latest` with Rust 1.98.1 from `rust-toolchain.toml`: - **This PR:** everything passes. `victory-loader` has 19 passed, the other crates have 0 failed. - **The report line itself:** a throwaway test, used only on my CI branch, hands `report` an illegal instruction at the bytes of `rdpru`. On `main` it prints ``` VIctory: unhandled exception 0xc000001d at victory_loader-….exe+0xf9cf0 ``` and with this PR ``` VIctory: unhandled exception 0xc000001d at victory_loader-….exe+0xfd3e0 (code 0f 01 fd 48 89 c1 90 90 90 90 90 90 90 90 90) ``` - I ran with `--test-threads=1`. With 4 threads, the shader crate's GPU tests sometimes crash on that runner (`STATUS_ACCESS_VIOLATION`), on unmodified `main` as well. **Not tested:** a real illegal instruction on an Intel host, or the title. Related: #7, #85, #102, #103, #106 (Intel hosts, `0xc000001d`). #34 adds `rdpru` and `clzero` loops; this change doesn't overlap it.
An illegal or privileged instruction is reported by its address only,
which does not say which instruction it was. On an Intel host that is
the question every such report raises (clwb, clzero, rdpru, an SSE4a
form...), and reporters have had to guess or dump the bytes by hand.

The report's first line now ends with up to 15 bytes at the faulting
address, as hex, read no further than the end of that page, so the
report names the instruction by itself.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:54:19 +00:00
github manually merged commit babe2db61f into gh-pr/198/base 2026-11-26 03:54:21 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:30 UTC · original

Tested babe2db under Wine 11.22 + vkd3d-proton 3.1 (Arch Linux x86_64, AMD RX 9060 XT, RADV 26.3.1), Windows build of the loader:

  • victory_loader (lib): 19 passed, 0 failed — one more than before, the new instruction-bytes test.
  • tests/crash_log.rs: 1 passed (first_chance_breakpoint_logging).
  • The Linux build of the loader cannot run these tests (they parse the test binary as PE, and it is ELF); the Windows build under Wine is the right check here.

No game data used.

**@⁠DaviTostes** on GitHub · 2026-11-24 01:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/198#issuecomment-7119164168) Tested `babe2db` under **Wine 11.22 + vkd3d-proton 3.1** (Arch Linux x86_64, AMD RX 9060 XT, RADV 26.3.1), Windows build of the loader: - `victory_loader` (lib): **19 passed, 0 failed** — one more than before, the new instruction-bytes test. - `tests/crash_log.rs`: **1 passed** (`first_chance_breakpoint_logging`). - The Linux build of the loader cannot run these tests (they parse the test binary as PE, and it is ELF); the Windows build under Wine is the right check here. No game data used.
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!198
No description provided.