Crash reports: say what an access violation's address holds #204

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

@⁠Dufftwt on GitHub · 2026-11-24 01:24 UTC · original
Dufftwt:fix/crash-report-fault-memory → main · +78 −1 · 1 files · 1 commits · merged 2026-11-24 07:54 UTC

What's wrong

An access violation is reported with the kind of access and the address it touched, and nothing else:

VIctory: unhandled exception 0xc0000005 at victory-image-….dll+0x4e33a92 (write 0x325a0570)

The address alone can't tell apart causes that need completely different fixes:

  • a wild or stale pointer into free memory;
  • a write to memory the title reserved but never committed, e.g. after a commit that Windows refused (#23 is one: the 6.5 GB commit failed with error 1455, and the title went on to use the range);
  • a guard page, e.g. a stack overrun;
  • a write to read-only memory, e.g. the title's code or constants, or execution of data.

Today, finding out which one it was means asking the reporter for a dump and a debugger session. #99 is an example: three runs show "a write below 4 GB" with nothing more to go on.

What the fix does

report in crash.rs now asks VirtualQuery what is at the faulting address, and adds the answer after the address. A new helper, memory_at, turns the answer into one of these:

  • nothing mapped there
  • reserved, never committed
  • a guard page
  • the page's protection (read-only, read-write, read-execute, no access, …), and the module name with offset when the page belongs to a loaded image
  • outside the address space, for addresses VirtualQuery rejects, such as the all-ones address Windows reports for a non-canonical pointer

It only queries the address space; it never reads the faulting address itself, so it can't fault inside the handler. Other exceptions and the rest of the report don't change.

How it behaves after the fix

VIctory: unhandled exception 0xc0000005 at victory-image-….dll+0x4e33a92 (write 0x325a0570: reserved, never committed)

A report now says by itself whether a crash is a bad pointer, an allocation that never got its memory, a stack overrun, or a write to protected memory.

Tests

The new test memory_at_names_what_an_access_hit reserves four pages and commits three of them as read-only, guard and no-access. It checks each description, then checks free memory (after releasing the pages, and address 0), an address past the end of the address space, and the test's own code (read-execute, in victory_loader-….exe+0x…).

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 lines themselves: a throwaway test, used only on my CI branch, hands report four writes: into reserved pages, a guard page, address 0x18, and the all-ones address. On main:
    VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x24440 (write 0x1d19a260570)
    VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x24440 (write 0x1d19a261010)
    VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x24440 (write 0x18)
    VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x24440 (write 0xffffffffffffffff)
    
    With this PR:
    VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x109a0 (write 0x12cb24d0570: reserved, never committed)
    VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x109a0 (write 0x12cb24d1010: a guard page)
    VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x109a0 (write 0x18: nothing mapped there)
    VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x109a0 (write 0xffffffffffffffff: outside the address space)
    
  • 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 crash in the title.

Related: #23, #99. #12 and #34 also edit crash.rs; both already conflict with main, and this change adds no conflict of its own with either. It merges cleanly with #198, which adds the bytes of an illegal instruction to the same report line.

**@⁠Dufftwt** on GitHub · 2026-11-24 01:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/204) `Dufftwt:fix/crash-report-fault-memory` → `main` · +78 −1 · 1 files · 1 commits · merged 2026-11-24 07:54 UTC ## What's wrong An access violation is reported with the kind of access and the address it touched, and nothing else: ``` VIctory: unhandled exception 0xc0000005 at victory-image-….dll+0x4e33a92 (write 0x325a0570) ``` The address alone can't tell apart causes that need completely different fixes: - a wild or stale pointer into **free** memory; - a write to memory the title **reserved but never committed**, e.g. after a commit that Windows refused (#23 is one: the 6.5 GB commit failed with error 1455, and the title went on to use the range); - a **guard page**, e.g. a stack overrun; - a write to **read-only** memory, e.g. the title's code or constants, or execution of data. Today, finding out which one it was means asking the reporter for a dump and a debugger session. #99 is an example: three runs show "a write below 4 GB" with nothing more to go on. ## What the fix does `report` in `crash.rs` now asks `VirtualQuery` what is at the faulting address, and adds the answer after the address. A new helper, `memory_at`, turns the answer into one of these: - `nothing mapped there` - `reserved, never committed` - `a guard page` - the page's protection (`read-only`, `read-write`, `read-execute`, `no access`, …), and the module name with offset when the page belongs to a loaded image - `outside the address space`, for addresses `VirtualQuery` rejects, such as the all-ones address Windows reports for a non-canonical pointer It only queries the address space; it never reads the faulting address itself, so it can't fault inside the handler. Other exceptions and the rest of the report don't change. ## How it behaves after the fix ``` VIctory: unhandled exception 0xc0000005 at victory-image-….dll+0x4e33a92 (write 0x325a0570: reserved, never committed) ``` A report now says by itself whether a crash is a bad pointer, an allocation that never got its memory, a stack overrun, or a write to protected memory. ## Tests The new test `memory_at_names_what_an_access_hit` reserves four pages and commits three of them as read-only, guard and no-access. It checks each description, then checks free memory (after releasing the pages, and address 0), an address past the end of the address space, and the test's own code (`read-execute, in victory_loader-….exe+0x…`). 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 lines themselves:** a throwaway test, used only on my CI branch, hands `report` four writes: into reserved pages, a guard page, address `0x18`, and the all-ones address. On `main`: ``` VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x24440 (write 0x1d19a260570) VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x24440 (write 0x1d19a261010) VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x24440 (write 0x18) VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x24440 (write 0xffffffffffffffff) ``` With this PR: ``` VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x109a0 (write 0x12cb24d0570: reserved, never committed) VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x109a0 (write 0x12cb24d1010: a guard page) VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x109a0 (write 0x18: nothing mapped there) VIctory: unhandled exception 0xc0000005 at victory_loader-….exe+0x109a0 (write 0xffffffffffffffff: outside the address space) ``` - 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 crash in the title. Related: #23, #99. #12 and #34 also edit `crash.rs`; both already conflict with `main`, and this change adds no conflict of its own with either. It merges cleanly with #198, which adds the bytes of an illegal instruction to the same report line.
An access violation is reported with the address it touched and
nothing else, so a read of free memory, a write to memory that was
reserved but whose commit failed, a stack guard page and a write to
code or constants all look the same in a report.

The report now adds what VirtualQuery says is at that address: nothing,
reserved but never committed, a guard page, or the page's protection,
with the module for an image's pages.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:54:27 +00:00
github manually merged commit 3390e47328 into gh-pr/204/base 2026-11-26 03:54:31 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 04:45 UTC · original

Thanks @⁠Dufftwt for the access-violation report detail. I tested the open PR at head 3390e47328e057badbb3cf2a2f565a3a05291960 with:

cargo test --locked -p victory-loader --lib memory_at_names_what_an_access_hit -- --test-threads=1

Result: 1 passed, 0 failed. The test exercises VirtualQuery classification for reserved-but-uncommitted, read-only, guard, no-access, released/free, null, and out-of-address-space locations, then checks module naming for an image page. These are synthetic memory-region checks; they do not exercise crash handling in a real title. The test is in crash.rs.

**@⁠jeremygold02** on GitHub · 2026-11-24 04:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/204#issuecomment-7122309483) Thanks @⁠Dufftwt for the access-violation report detail. I tested the open PR at head `3390e47328e057badbb3cf2a2f565a3a05291960` with: ``` cargo test --locked -p victory-loader --lib memory_at_names_what_an_access_hit -- --test-threads=1 ``` Result: 1 passed, 0 failed. The test exercises `VirtualQuery` classification for reserved-but-uncommitted, read-only, guard, no-access, released/free, null, and out-of-address-space locations, then checks module naming for an image page. These are synthetic memory-region checks; they do not exercise crash handling in a real title. The test is in [crash.rs](https://github.com/Marvisak/VIctory/blob/3390e47328e057badbb3cf2a2f565a3a05291960/crates/victory-loader/src/crash.rs).
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!204
No description provided.