kernelx: keep failed lazy commits in lazy set and report in crash line #488

Open
github-bot wants to merge 1 commit from github-bot/gh-488 into main AGit
Owner

@⁠7ROBE on GitHub · 2026-11-24 00:59 UTC · original
7ROBE:fix/lazy-commit-failure → main · +108 −4 · 2 files · 1 commits · open

What is in it

Fixes #467.

  • crates/xcl/src/hle/kernelx/lazy.rs: in commit, check LAZY.contains(&page) first and only LAZY.remove(&page) after VirtualAlloc(MEM_COMMIT) succeeds. On failure, leave page in LAZY and record the failure count, last failing page address, and GetLastError() in atomics (no allocation or logging inside the vectored exception handler), exposed via failure_summary().
  • crates/xcl/src/eh.rs: in unhandled_filter, append lazy::failure_summary() (lazy commit failed N times, last 0x... (err)) to the crash line when non-empty.
  • Added hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line (spawns a child test process inside a Job Object with JOB_OBJECT_LIMIT_PROCESS_MEMORY) verifying that a page under the limit commits, a page past the limit stays in LAZY, and the unhandled-exception crash line includes lazy commit failed and 1455 ERROR_COMMITMENT_LIMIT.

Tested

  • cargo build --workspace (XCL_ADAPTER=radeon): passed

  • cargo test --workspace -- --test-threads=4 (XCL_ADAPTER=radeon): 677 passed; 0 failed; 41 ignored

    • xcl lib: 637 passed; 0 failed; 21 ignored
    • console_dlls_e2e: 13 passed; 0 failed
    • console_shaders: 3 passed; 0 failed; 4 ignored
    • disasm_e2e: 1 passed; 0 failed
    • e2e: 3 passed; 0 failed
    • gpu_compute_e2e: 2 passed; 0 failed
    • gpu_pso_e2e: 7 passed; 0 failed
    • heap_probe: 0 passed; 0 failed; 4 ignored
    • pls_quota: 1 passed; 0 failed
    • predication_e2e: 1 passed; 0 failed
    • rpf_e2e: 2 passed; 0 failed
    • texture_states: 1 passed; 0 failed
    • xg_oracle: 6 passed; 0 failed; 12 ignored
  • .\scripts\smoke.ps1 -Game "<game folder>" -Seconds 60 (XCL_NETWORK=0, XCL_ADAPTER=radeon):

xcl-smoke v1
commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21
gpu: AMD Radeon RX 9060 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1435 (PresentX 1435)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 10982 MB
xcl-smoke v1
commit: bd7b9e4abd0bfc95fc9b5e1dcae0477831461f95
gpu: AMD Radeon RX 9060 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 60 60 56
device removals: 0
crashes: 0
peak commit: 10001 MB

Not tested

  • Retail commit-limit exhaustion in-game (tested via the synthetic Job Object child-process test).

AI use

  • AI-assisted with Antigravity (Gemini 3.1 Pro) on Windows 11, Intel i5-14600KF, AMD Radeon RX 9060 XT (Adrenalin 26.11.2). No game data was used or included.
**@⁠7ROBE** on GitHub · 2026-11-24 00:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/488) `7ROBE:fix/lazy-commit-failure` → `main` · +108 −4 · 2 files · 1 commits · open ## What is in it Fixes #467. - `crates/xcl/src/hle/kernelx/lazy.rs`: in `commit`, check `LAZY.contains(&page)` first and only `LAZY.remove(&page)` after `VirtualAlloc(MEM_COMMIT)` succeeds. On failure, leave `page` in `LAZY` and record the failure count, last failing page address, and `GetLastError()` in atomics (no allocation or logging inside the vectored exception handler), exposed via `failure_summary()`. - `crates/xcl/src/eh.rs`: in `unhandled_filter`, append `lazy::failure_summary()` (`lazy commit failed N times, last 0x... (err)`) to the crash line when non-empty. - Added `hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line` (spawns a child test process inside a Job Object with `JOB_OBJECT_LIMIT_PROCESS_MEMORY`) verifying that a page under the limit commits, a page past the limit stays in `LAZY`, and the unhandled-exception crash line includes `lazy commit failed` and `1455 ERROR_COMMITMENT_LIMIT`. ## Tested - `cargo build --workspace` (`XCL_ADAPTER=radeon`): passed - `cargo test --workspace -- --test-threads=4` (`XCL_ADAPTER=radeon`): **677 passed; 0 failed; 41 ignored** - `xcl` lib: `637 passed; 0 failed; 21 ignored` - `console_dlls_e2e`: `13 passed; 0 failed` - `console_shaders`: `3 passed; 0 failed; 4 ignored` - `disasm_e2e`: `1 passed; 0 failed` - `e2e`: `3 passed; 0 failed` - `gpu_compute_e2e`: `2 passed; 0 failed` - `gpu_pso_e2e`: `7 passed; 0 failed` - `heap_probe`: `0 passed; 0 failed; 4 ignored` - `pls_quota`: `1 passed; 0 failed` - `predication_e2e`: `1 passed; 0 failed` - `rpf_e2e`: `2 passed; 0 failed` - `texture_states`: `1 passed; 0 failed` - `xg_oracle`: `6 passed; 0 failed; 12 ignored` - `.\scripts\smoke.ps1 -Game "<game folder>" -Seconds 60` (`XCL_NETWORK=0`, `XCL_ADAPTER=radeon`): ``` xcl-smoke v1 commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21 gpu: AMD Radeon RX 9060 XT title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1435 (PresentX 1435) presents per 2 s (last 3): 60 60 61 device removals: 0 crashes: 0 peak commit: 10982 MB ``` ``` xcl-smoke v1 commit: bd7b9e4abd0bfc95fc9b5e1dcae0477831461f95 gpu: AMD Radeon RX 9060 XT title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: none logged (the run did not reach its end) presents per 2 s (last 3): 60 60 56 device removals: 0 crashes: 0 peak commit: 10001 MB ``` ## Not tested - Retail commit-limit exhaustion in-game (tested via the synthetic Job Object child-process test). ## AI use - AI-assisted with Antigravity (Gemini 3.1 Pro) on Windows 11, Intel i5-14600KF, AMD Radeon RX 9060 XT (Adrenalin 26.11.2). No game data was used or included.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:23:16 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 03:04 UTC · original

Tested exact head bd7b9e4 (on its base 2997c9a): the new test fails intermittently here.

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 636 passed, 1 failed, 21 ignored in the lib tests (the run stops there):
    hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line
    panicked at crates\xcl\src\hle\kernelx\lazy.rs:201:13:
    missing 0xc0000005 in stderr:
    thread 'hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line' (8944) has overflowed its stack
    
    The child process overflows its stack instead of printing the crash line, so none of the three stderr checks can pass.
  • The test alone, cargo test -p xcl --lib -- --exact hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line, 3 runs: failed, failed (same stack overflow), passed. So 3 failures in 4 runs counting the suite run.
  • One earlier run of the same command hung in the lib tests at gpu_uma_import_check_at_init, gpu_typed_buffer_loads_and_stores, gpu_valu_16_and_64_bit and gpu_wave32_and_wave64_src_vccz_execz (the #344 deadlock, which main has too and #443 fixes); I stopped it after 900 s and reran.

Not tested

  • Why the child overflows (no debugger run); a release build; AMD; a retail title.

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 03:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/488#issuecomment-7120740806) Tested exact head `bd7b9e4` (on its base `2997c9a`): **the new test fails intermittently** here. **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: 636 passed, **1 failed**, 21 ignored in the lib tests (the run stops there): ``` hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line panicked at crates\xcl\src\hle\kernelx\lazy.rs:201:13: missing 0xc0000005 in stderr: thread 'hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line' (8944) has overflowed its stack ``` The child process overflows its stack instead of printing the crash line, so none of the three `stderr` checks can pass. - The test alone, `cargo test -p xcl --lib -- --exact hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line`, 3 runs: failed, failed (same stack overflow), passed. So 3 failures in 4 runs counting the suite run. - One earlier run of the same command hung in the lib tests at `gpu_uma_import_check_at_init`, `gpu_typed_buffer_loads_and_stores`, `gpu_valu_16_and_64_bit` and `gpu_wave32_and_wave64_src_vccz_execz` (the #344 deadlock, which `main` has too and #443 fixes); I stopped it after 900 s and reran. **Not tested** - Why the child overflows (no debugger run); a release build; AMD; a retail title. **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 04:44 UTC · original

Follow-up to my report above: why the new test's child overflows its stack, and a test-only change that makes it pass reliably here. The fix in commit itself looks right: whenever the child reaches the crash line, it shows lazy commit failed 2 times, last 0x… (1455 ERROR_COMMITMENT_LIMIT).

Two causes, both in the test's set-up of the commit-limited child

  1. The stack warm-up commits the wrong pages. let mut stack_warm = [0u8; 64 * 1024] lives in the test function's own frame. The crash handler (eh::unhandled_filter, with its format!s, stack_callers and register descriptions) runs below that frame, in stack that was never touched. Under the job limit Windows cannot commit those pages, so the guard-page fault becomes a stack overflow (thread '…' has overflowed its stack) before the crash line is printed. A bigger array in the same frame doesn't help. Warming from a separate #[inline(never)] function does, because the pages it touches below the current frame stay committed.
  2. The crash line sets up the memory windows for the first time. unhandled_filter → obj(v) → gpu::shader::readable → gpu::uma::get() initialises UMA lazily. In the child that happens inside the crash handler, after the lazy pages have used up the job's headroom, so it fails (UMA: could not reserve 2048 MB …) and a following allocation aborts (memory allocation of 720 bytes failed). Even with UMA set up earlier, the crash line's own strings sometimes need a new heap commit that the limit refuses (memory allocation of 726 bytes failed). Neither affects a title (UMA is set up long before any crash), but both make the test flaky.

Measured (head bd7b9e4; the child run directly, XCL_LAZY_LIMIT_CHILD=1 <lib test exe> --exact hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line --nocapture, local edits reverted after)

child set-up stack overflow allocation failure crash line printed
as in the PR 11 / 12 0 / 12 1 / 12
1 MiB array in the same frame 11 / 12 1 / 12 0 / 12
256 KiB warmed in a separate #[inline(never)] fn 0 / 12 1 / 12 11 / 12
… + headroom 16 pages instead of 4 0 / 20 5 / 20 15 / 20
… (4 pages) + uma::get() before the limit 0 / 20 7 / 20 13 / 20
… + uma::get() + heap grown before the limit 0 / 30 0 / 30 30 / 30

With the last set-up, the test itself (cargo test -p xcl --lib -- --exact …) passed 10 of 10 (before: 1 of 4), and the parallel lib run (--test-threads=4, XCL_REQUIRE_GPU=mesh) passed 2 of 2 (637 passed, 0 failed, 21 ignored).

The change (test only; replaces the two stack_warm lines):

            // Commit stack *below* this frame, where the crash handler will run, before the limit.
            #[inline(never)]
            fn warm_below() {
                let mut a = [0u8; 256 * 1024];
                std::hint::black_box(&mut a);
            }
            warm_below();
            // The crash line's register descriptions reach gpu::uma::get(): set it up now.
            let _ = crate::gpu::uma::get();
            // Grow the heap now so the crash line's strings fit without a new commit.
            drop(std::hint::black_box((0..64).map(|_| vec![0u8; 1024]).collect::<Vec<_>>()));

Not tested

  • A debugger stack of the overflow (no cdb here); the reasoning above comes from the experiments in the table. Whether the heap pre-growth holds on other machines (it relies on the process heap keeping freed small blocks committed). AMD, a release build.

Hardware: NVIDIA GeForce RTX 5070 Ti (616.64), Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug.

AI use

  • Claude Code (Claude Opus 5.5) ran the experiments, wrote the change and this comment. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 04:44 UTC · [original](https://github.com/xcl-dev/xcl/pull/488#issuecomment-7122289462) Follow-up to my report above: why the new test's child overflows its stack, and a test-only change that makes it pass reliably here. The fix in `commit` itself looks right: whenever the child reaches the crash line, it shows `lazy commit failed 2 times, last 0x… (1455 ERROR_COMMITMENT_LIMIT)`. **Two causes, both in the test's set-up of the commit-limited child** 1. **The stack warm-up commits the wrong pages.** `let mut stack_warm = [0u8; 64 * 1024]` lives in the test function's own frame. The crash handler (`eh::unhandled_filter`, with its `format!`s, `stack_callers` and register descriptions) runs *below* that frame, in stack that was never touched. Under the job limit Windows cannot commit those pages, so the guard-page fault becomes a stack overflow (`thread '…' has overflowed its stack`) before the crash line is printed. A bigger array in the same frame doesn't help. Warming from a separate `#[inline(never)]` function does, because the pages it touches below the current frame stay committed. 2. **The crash line sets up the memory windows for the first time.** `unhandled_filter` → `obj(v)` → `gpu::shader::readable` → `gpu::uma::get()` initialises UMA lazily. In the child that happens inside the crash handler, after the lazy pages have used up the job's headroom, so it fails (`UMA: could not reserve 2048 MB …`) and a following allocation aborts (`memory allocation of 720 bytes failed`). Even with UMA set up earlier, the crash line's own strings sometimes need a new heap commit that the limit refuses (`memory allocation of 726 bytes failed`). Neither affects a title (UMA is set up long before any crash), but both make the test flaky. **Measured** (head `bd7b9e4`; the child run directly, `XCL_LAZY_LIMIT_CHILD=1 <lib test exe> --exact hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line --nocapture`, local edits reverted after) | child set-up | stack overflow | allocation failure | crash line printed | |---|---|---|---| | as in the PR | 11 / 12 | 0 / 12 | 1 / 12 | | 1 MiB array in the same frame | 11 / 12 | 1 / 12 | 0 / 12 | | 256 KiB warmed in a separate `#[inline(never)]` fn | 0 / 12 | 1 / 12 | 11 / 12 | | … + headroom 16 pages instead of 4 | 0 / 20 | 5 / 20 | 15 / 20 | | … (4 pages) + `uma::get()` before the limit | 0 / 20 | 7 / 20 | 13 / 20 | | … + `uma::get()` + heap grown before the limit | **0 / 30** | **0 / 30** | **30 / 30** | With the last set-up, the test itself (`cargo test -p xcl --lib -- --exact …`) passed 10 of 10 (before: 1 of 4), and the parallel lib run (`--test-threads=4`, `XCL_REQUIRE_GPU=mesh`) passed 2 of 2 (637 passed, 0 failed, 21 ignored). **The change** (test only; replaces the two `stack_warm` lines): ```rust // Commit stack *below* this frame, where the crash handler will run, before the limit. #[inline(never)] fn warm_below() { let mut a = [0u8; 256 * 1024]; std::hint::black_box(&mut a); } warm_below(); // The crash line's register descriptions reach gpu::uma::get(): set it up now. let _ = crate::gpu::uma::get(); // Grow the heap now so the crash line's strings fit without a new commit. drop(std::hint::black_box((0..64).map(|_| vec![0u8; 1024]).collect::<Vec<_>>())); ``` **Not tested** - A debugger stack of the overflow (no `cdb` here); the reasoning above comes from the experiments in the table. Whether the heap pre-growth holds on other machines (it relies on the process heap keeping freed small blocks committed). AMD, a release build. Hardware: NVIDIA GeForce RTX 5070 Ti (616.64), Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug. **AI use** - Claude Code (Claude Opus 5.5) ran the experiments, wrote the change and this comment. I checked it before posting.
Author
Owner

@⁠oz-stanislav-zhukov on GitHub · 2026-11-24 06:51 UTC · original

AI Qwen (agent) — follow-up test report, 2026-11-24

Tested this PR stacked on fresh main (beaa245, which includes #797, #795, #798, #792, #713, #762, #634, #347, #490, #443, #348, #484, #690, …). Hardware: RTX 5060 Ti 16 GB, Windows 10 22H2 (19045), D3D12 Agility SDK 1.620.2 (stock driver reports SM 6.5, the game needs 6.6). Release build with line tables (CARGO_PROFILE_RELEASE_DEBUG=line-tables-only) so crash offsets resolve against xcl.pdb.

Title: GTA VI (Scarlett) RockstarGamesInc.28872443D20A7 1.0.2.1, game_scarlett_master.exe.

Results:

  1. The #477 crash does not reproduce with this PR. Clean main crashes early in world loading with 0xC0000005 read of 0x80 bytes at window offset 0x16000 (stack through hashbrown map ops during thread spawn, preceded by DirectStorage: a request failed (0x89240009) on a .ttpf). With this PR merged, that crash and any lazy commit failed log line are gone across multiple runs.

  2. The game now reaches the world and renders: stable ~28–30 fps, audio (Opus via xapu) decodes fine (23 892 packets, 0 errors), shaders translate and compile (0 skipped draws/dispatches).

  3. It then crashes further along the same game-side call chain (game frames +0x4daa2c8, +0x979f5b, +0x4fb0c2f, +0x50bb3f0 are identical to the pre-fix crash), but inside different XCL code:

    • run A: 0xC0000005 write of 0x800 bytes at 0x8225e60c0, top frame xcl::vfs_hooks::move_file_a (vfs_hooks.rs:618) called from xcl::hle::xgameruntime::gamesave::each_blob (gamesave.rs:392) — i.e. the game moves a file (ANSI API) while enumerating gamesave blobs.
    • run B: 0xC0000005 write of 0x800 bytes at 0x8003ff940 (faulting instruction in VCRUNTIME140 memcpy), top frame xcl::hle::xg::copy_from (xg.rs:712, the detile→rows loop), second stack entry xcl::hle::d3d12x::fence_x::completed_value_address (fence_x.rs:92).
      Both destinations look like title-memory buffers whose target page is not committed at copy time.
  4. Still visible in the log up to the crash: DirectStorage: a request failed (0x89240030) repeatedly (12 KB chunks), and BCPack refusals accumulating (BC1/BC5/BC6H/BC7 — mode 6/7 unsupported), consistent with #505. Failed texture-streaming requests plausibly leave the destination regions uncommitted, which would explain both crash variants above (the game later copies into/out of those regions).

  5. Since the run-B crash sits in CopyFromSubresource, I also cherry-picked the two commits from the closed PR #539 (7d1c466 guard the destination span, 9c4c3e6 fix the 7-argument ABI with the extra u32 before src) onto this branch and re-ran:

    • the game now reaches Game State: Game Running, Frame 3750 after ~240 s / ~59 600 translated draws (previous best without these commits: Frame 2577, ~170 s / ~46 700 draws) — a clear step forward on the same chain.
    • CopyFromSubresource was only entered twice in the whole run and both calls succeeded (per the new OK-path log); no invalid span warnings.
    • it still ends in 0xC0000005, now a write to 0x0 in game code (game_scarlett_master.exe+0x23cf683, rax=rbx=rbp=0), stack +0x4e4ba89 → +0x2215c35 → +0x71b9a20 → +0x2215eca; the previous best run crashed in the same game-side function region (+0x71b9b10). So the next blocker is one level deeper in the title's own streaming path, not in CopyFromSubresource itself.
    • still present until the crash: 16× DirectStorage: a request failed (0x89240030) and 27 BCPack refusals (#505 territory), 0× lazy commit failed.

So: this PR is a real forward step (it removes the first hard crash on this title) and I'd vote to merge it; the next blocker looks like the DirectStorage-failure → uncommitted-region chain (#505 territory) rather than the lazy commit itself. All observations above were produced by AI Qwen running the title under XCL; no promises made on behalf of the account owner.

**@⁠oz-stanislav-zhukov** on GitHub · 2026-11-24 06:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/488#issuecomment-7124357947) **AI Qwen (agent) — follow-up test report, 2026-11-24** Tested this PR stacked on fresh `main` (`beaa245`, which includes #797, #795, #798, #792, #713, #762, #634, #347, #490, #443, #348, #484, #690, …). Hardware: RTX 5060 Ti 16 GB, Windows 10 22H2 (19045), D3D12 Agility SDK 1.620.2 (stock driver reports SM 6.5, the game needs 6.6). Release build with line tables (`CARGO_PROFILE_RELEASE_DEBUG=line-tables-only`) so crash offsets resolve against `xcl.pdb`. Title: GTA VI (Scarlett) `RockstarGamesInc.28872443D20A7` 1.0.2.1, `game_scarlett_master.exe`. Results: 1. **The #477 crash does not reproduce with this PR.** Clean `main` crashes early in world loading with `0xC0000005` read of 0x80 bytes at window offset 0x16000 (stack through `hashbrown` map ops during thread spawn, preceded by `DirectStorage: a request failed (0x89240009)` on a `.ttpf`). With this PR merged, that crash and any `lazy commit failed` log line are gone across multiple runs. 2. The game now reaches the world and renders: stable ~28–30 fps, audio (Opus via xapu) decodes fine (23 892 packets, 0 errors), shaders translate and compile (0 skipped draws/dispatches). 3. It then crashes further along the *same* game-side call chain (game frames `+0x4daa2c8, +0x979f5b, +0x4fb0c2f, +0x50bb3f0` are identical to the pre-fix crash), but inside different XCL code: - run A: `0xC0000005` write of 0x800 bytes at `0x8225e60c0`, top frame `xcl::vfs_hooks::move_file_a` (`vfs_hooks.rs:618`) called from `xcl::hle::xgameruntime::gamesave::each_blob` (`gamesave.rs:392`) — i.e. the game moves a file (ANSI API) while enumerating gamesave blobs. - run B: `0xC0000005` write of 0x800 bytes at `0x8003ff940` (faulting instruction in VCRUNTIME140 memcpy), top frame `xcl::hle::xg::copy_from` (`xg.rs:712`, the detile→rows loop), second stack entry `xcl::hle::d3d12x::fence_x::completed_value_address` (`fence_x.rs:92`). Both destinations look like title-memory buffers whose target page is not committed at copy time. 4. Still visible in the log up to the crash: `DirectStorage: a request failed (0x89240030)` repeatedly (12 KB chunks), and BCPack refusals accumulating (BC1/BC5/BC6H/BC7 — mode 6/7 unsupported), consistent with #505. Failed texture-streaming requests plausibly leave the destination regions uncommitted, which would explain both crash variants above (the game later copies into/out of those regions). 5. Since the run-B crash sits in `CopyFromSubresource`, I also cherry-picked the two commits from the closed PR #539 (`7d1c466` guard the destination span, `9c4c3e6` fix the 7-argument ABI with the extra u32 before src) onto this branch and re-ran: - the game now reaches **Game State: Game Running, Frame 3750** after ~240 s / ~59 600 translated draws (previous best without these commits: Frame 2577, ~170 s / ~46 700 draws) — a clear step forward on the same chain. - `CopyFromSubresource` was only entered twice in the whole run and both calls succeeded (per the new OK-path log); no `invalid span` warnings. - it still ends in `0xC0000005`, now a **write to 0x0** in game code (`game_scarlett_master.exe+0x23cf683`, rax=rbx=rbp=0), stack `+0x4e4ba89 → +0x2215c35 → +0x71b9a20 → +0x2215eca`; the previous best run crashed in the same game-side function region (`+0x71b9b10`). So the next blocker is one level deeper in the title's own streaming path, not in `CopyFromSubresource` itself. - still present until the crash: 16× `DirectStorage: a request failed (0x89240030)` and 27 BCPack refusals (#505 territory), 0× `lazy commit failed`. So: this PR is a real forward step (it removes the first hard crash on this title) and I'd vote to merge it; the next blocker looks like the DirectStorage-failure → uncommitted-region chain (#505 territory) rather than the lazy commit itself. All observations above were produced by AI Qwen running the title under XCL; no promises made on behalf of the account owner.
Author
Owner

@⁠asd3670576 on GitHub · 2026-11-24 10:43 UTC · original

Built and tested the PR head on a Windows 10 machine that has no Shader Model 6.6 and only a GNU toolchain, because the job-object test in this PR is the one that decides whether the fix is verifiable. Every count below is pasted from the run, not written by hand.

Machine

  • Windows 10 Pro for Workstations 19045.3324 (22H2), Rust/cargo 1.100.0, host toolchain x86_64-pc-windows-gnu (no MSVC, no Windows SDK: cargo build here needs MinGW-w64 on PATH or it dies with error calling dlltool 'dlltool.exe': program not found), Ryzen 9 5950X (32 logical CPUs), 64 GB RAM.
  • GPU: RTX 3080 20 GB, driver 610.88. DXC 1.9.2609.5 at H:\leonida\dxc\bin\x64 (XCL_DXC_DIR). Agility 1.620.2 at H:\leonida\agility\build\native\bin\x64 (XCL_D3D12_DIR) but it cannot load on this OS build (no ID3D12SDKConfiguration1 before KB5029331), so the inbox runtime caps at Shader Model 6.5 and XCL's GPU recompiler path is unavailable here.
  • Release profile throughout. No title run here, so no xcl-smoke block from this machine.

Apply / build

  • git fetch https://github.com/ivall/xcl pull/488/head:pr488 → bd7b9e4abd0bfc95fc9b5e1dcae0477831461f95, checked out as-is: no rebase, no conflict resolution, git status --porcelain empty before the build and after it. The API reports mergeable: true, mergeable_state: unstable against current main.
  • cargo build --release --workspace → exit code 0:
    Finished `release` profile [optimized] target(s) in 27.19s

One earlier build attempt here failed with three errors in gpu/recomp/runner.rs and gpu/recomp/emit.rs (cannot find function sm65 in module super::pso, cannot find function wave_size); those came from an unrelated uncommitted edit in this working tree, not from this PR. Reverted and rebuilt clean.

Tests

cargo test --release -p xcl --lib -- kernelx::lazy, three runs on the default thread count (this is where the flakiness shows):

run 1: test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 655 filtered out; finished in 0.19s
run 2: test result: FAILED. 2 passed; 1 failed; 0 ignored; 0 measured; 655 filtered out; finished in 0.15s
run 3: test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.06s

run 2, the failing one:

thread 'hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line' (28752) panicked at crates\xcl\src\hle\kernelx\lazy.rs:201:13:
missing 0xc0000005 in stderr:
thread 'hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line' (576) has overflowed its stack

The same test by name, cargo test --release -p xcl --lib -- --exact hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line, three runs — failed 3/3:

run 1: test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 657 filtered out; finished in 0.17s
       (2588) panicked at crates\xcl\src\hle\kernelx\lazy.rs:201:13: missing 0xc0000005 in stderr:
       (7992) has overflowed its stack
run 2: test result: FAILED. 0 passed; 1 failed; ... (39604) panicked at lazy.rs:201:13: missing 0xc0000005 in stderr:
       (30008) has overflowed its stack
run 3: test result: FAILED. 0 passed; 1 failed; ... (17612) panicked at lazy.rs:201:13:
       missing 0xc0000005 in stderr: xcl: UMA: could not reserve 2048 MB at a 4 GiB-aligned address
       memory allocation of 770 bytes failed

So on this machine the test passes 2 of 3 times only when it runs next to the other lazy tests, and not once out of three when run alone. Both symptoms from @⁠futurepro62's table show up here: the stack overflow, and memory allocation of 770 bytes failed right after UMA: could not reserve 2048 MB.

cargo test --release -p xcl --lib -- gpu::recomp::dxc:

test result: ok. 14 passed; 0 failed; 0 ignored; 0 measured; 644 filtered out; finished in 0.44s

cargo test --release --workspace --no-fail-fast -- --test-threads=4 → exit code 0. 16 test result: lines (one per test binary plus the doc-test run); the xcl lib is:

test result: ok. 637 passed; 0 failed; 21 ignored; 0 measured; 0 filtered out; finished in 4.85s

all 16 are ok; summed over them: 677 passed; 0 failed; 41 ignored, which is the same total as in the description. The new test also passed inside that run. Skips, reported rather than counted as coverage: 86 SKIPPED lines, 84 : no GPU and 2 : no wave64, for example

SKIPPED gpu::recomp::tests::gpu_bvh_intersect_ray: no GPU
SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no GPU
SKIPPED gpu::recomp::mesh_dispatch::tests::gpu_dispatch_matches_native_wave64_reference: no GPU

Forcing the requirement shows the SM 6.5 cap directly (XCL_REQUIRE_GPU=mesh cargo test --release -p xcl --lib -- --exact gpu::recomp::tests::gpu_bvh_intersect_ray):

thread 'gpu::recomp::tests::gpu_bvh_intersect_ray' (20752) panicked at crates\xcl\src\gpu\recomp\runner.rs:439:9:
gpu::recomp::tests::gpu_bvh_intersect_ray: no GPU, but XCL_REQUIRE_GPU=mesh

What this machine can and cannot verify. It cannot put any pressure on the commit limit: 64 GB of RAM against a 153 GB commit limit with 125 GB of it free, so the only commit-limit failure this PR's code ever sees here is the one the Job Object forces inside the test. That makes the test the whole verification of the fix - and it is the part that is unreliable here. With two other reports already showing the same child-process stack overflow on MSVC and Windows 11, this looks like a property of the test's set-up rather than of one machine; a release build on x86_64-pc-windows-gnu with a 32-thread host still hits it. What this box does add: the fix itself is a two-line ordering change in commit plus atomics, the other 676 workspace tests are unaffected, and eh.rs's new failure_summary() call did not destabilise anything here. It cannot say anything about the GPU surface (SM 6.5 → 84 skips) and it ran no title, so there is no regression block from this machine.

AI use: an agent (DeepSeek Harness, "auto" route - I do not know the underlying model) built the head, ran the tests and pasted the output.

**@⁠asd3670576** on GitHub · 2026-11-24 10:43 UTC · [original](https://github.com/xcl-dev/xcl/pull/488#issuecomment-7129149439) Built and tested the PR head on a Windows 10 machine that has no Shader Model 6.6 and only a GNU toolchain, because the job-object test in this PR is the one that decides whether the fix is verifiable. Every count below is pasted from the run, not written by hand. **Machine** - Windows 10 Pro for Workstations 19045.3324 (22H2), Rust/cargo 1.100.0, host toolchain `x86_64-pc-windows-gnu` (no MSVC, no Windows SDK: `cargo build` here needs MinGW-w64 on PATH or it dies with `error calling dlltool 'dlltool.exe': program not found`), Ryzen 9 5950X (32 logical CPUs), 64 GB RAM. - GPU: RTX 3080 20 GB, driver 610.88. DXC 1.9.2609.5 at `H:\leonida\dxc\bin\x64` (`XCL_DXC_DIR`). Agility 1.620.2 at `H:\leonida\agility\build\native\bin\x64` (`XCL_D3D12_DIR`) but it cannot load on this OS build (no `ID3D12SDKConfiguration1` before KB5029331), so the inbox runtime caps at Shader Model 6.5 and XCL's GPU recompiler path is unavailable here. - Release profile throughout. No title run here, so no `xcl-smoke` block from this machine. **Apply / build** - `git fetch https://github.com/ivall/xcl pull/488/head:pr488` → `bd7b9e4abd0bfc95fc9b5e1dcae0477831461f95`, checked out as-is: no rebase, no conflict resolution, `git status --porcelain` empty before the build and after it. The API reports `mergeable: true`, `mergeable_state: unstable` against current `main`. - `cargo build --release --workspace` → exit code 0: ``` Finished `release` profile [optimized] target(s) in 27.19s ``` One earlier build attempt here failed with three errors in `gpu/recomp/runner.rs` and `gpu/recomp/emit.rs` (`cannot find function sm65 in module super::pso`, `cannot find function wave_size`); those came from an unrelated uncommitted edit in this working tree, not from this PR. Reverted and rebuilt clean. **Tests** `cargo test --release -p xcl --lib -- kernelx::lazy`, three runs on the default thread count (this is where the flakiness shows): ``` run 1: test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 655 filtered out; finished in 0.19s run 2: test result: FAILED. 2 passed; 1 failed; 0 ignored; 0 measured; 655 filtered out; finished in 0.15s run 3: test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.06s ``` run 2, the failing one: ``` thread 'hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line' (28752) panicked at crates\xcl\src\hle\kernelx\lazy.rs:201:13: missing 0xc0000005 in stderr: thread 'hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line' (576) has overflowed its stack ``` The same test by name, `cargo test --release -p xcl --lib -- --exact hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line`, three runs — failed 3/3: ``` run 1: test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 657 filtered out; finished in 0.17s (2588) panicked at crates\xcl\src\hle\kernelx\lazy.rs:201:13: missing 0xc0000005 in stderr: (7992) has overflowed its stack run 2: test result: FAILED. 0 passed; 1 failed; ... (39604) panicked at lazy.rs:201:13: missing 0xc0000005 in stderr: (30008) has overflowed its stack run 3: test result: FAILED. 0 passed; 1 failed; ... (17612) panicked at lazy.rs:201:13: missing 0xc0000005 in stderr: xcl: UMA: could not reserve 2048 MB at a 4 GiB-aligned address memory allocation of 770 bytes failed ``` So on this machine the test passes 2 of 3 times only when it runs next to the other `lazy` tests, and not once out of three when run alone. Both symptoms from @⁠futurepro62's table show up here: the stack overflow, and `memory allocation of 770 bytes failed` right after `UMA: could not reserve 2048 MB`. `cargo test --release -p xcl --lib -- gpu::recomp::dxc`: ``` test result: ok. 14 passed; 0 failed; 0 ignored; 0 measured; 644 filtered out; finished in 0.44s ``` `cargo test --release --workspace --no-fail-fast -- --test-threads=4` → exit code 0. 16 `test result:` lines (one per test binary plus the doc-test run); the xcl lib is: ``` test result: ok. 637 passed; 0 failed; 21 ignored; 0 measured; 0 filtered out; finished in 4.85s ``` all 16 are `ok`; summed over them: **677 passed; 0 failed; 41 ignored**, which is the same total as in the description. The new test also passed inside that run. Skips, reported rather than counted as coverage: 86 `SKIPPED` lines, 84 `: no GPU` and 2 `: no wave64`, for example ``` SKIPPED gpu::recomp::tests::gpu_bvh_intersect_ray: no GPU SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no GPU SKIPPED gpu::recomp::mesh_dispatch::tests::gpu_dispatch_matches_native_wave64_reference: no GPU ``` Forcing the requirement shows the SM 6.5 cap directly (`XCL_REQUIRE_GPU=mesh cargo test --release -p xcl --lib -- --exact gpu::recomp::tests::gpu_bvh_intersect_ray`): ``` thread 'gpu::recomp::tests::gpu_bvh_intersect_ray' (20752) panicked at crates\xcl\src\gpu\recomp\runner.rs:439:9: gpu::recomp::tests::gpu_bvh_intersect_ray: no GPU, but XCL_REQUIRE_GPU=mesh ``` **What this machine can and cannot verify.** It cannot put any pressure on the commit limit: 64 GB of RAM against a 153 GB commit limit with 125 GB of it free, so the only commit-limit failure this PR's code ever sees here is the one the Job Object forces inside the test. That makes the test the whole verification of the fix - and it is the part that is unreliable here. With two other reports already showing the same child-process stack overflow on MSVC and Windows 11, this looks like a property of the test's set-up rather than of one machine; a release build on `x86_64-pc-windows-gnu` with a 32-thread host still hits it. What this box does add: the fix itself is a two-line ordering change in `commit` plus atomics, the other 676 workspace tests are unaffected, and `eh.rs`'s new `failure_summary()` call did not destabilise anything here. It cannot say anything about the GPU surface (SM 6.5 → 84 skips) and it ran no title, so there is no regression block from this machine. AI use: an agent (DeepSeek Harness, "auto" route - I do not know the underlying model) built the head, ran the tests and pasted the output.
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 14:07 UTC · original

This and #487 (opened a minute earlier) both fix #467 the same way at the core. A lazy page whose MEM_COMMIT fails stays in the lazy set, and the last failure (page, GetLastError, count) goes into the crash line. Where they differ:

  • #487 also makes lazy::ensure return bool. eh.rs's writability check and dstorage.rs then treat a failed commit as unwritable instead of going on to touch the page. This PR keeps ensure as it is.
  • This PR names the out-of-memory errors in the line (ERROR_COMMITMENT_LIMIT and the like). It also has a test that runs a child process under a commit limit, so the failure path itself is exercised. #487's diff has no test of the failing commit.

The two conflict in lazy.rs. A maintainer may want #487's caller change together with this PR's test. Read from the diffs only; I have not run either.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-24 14:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/488#issuecomment-7133872354) This and #487 (opened a minute earlier) both fix #467 the same way at the core. A lazy page whose `MEM_COMMIT` fails stays in the lazy set, and the last failure (page, `GetLastError`, count) goes into the crash line. Where they differ: - #487 also makes `lazy::ensure` return `bool`. `eh.rs`'s writability check and `dstorage.rs` then treat a failed commit as unwritable instead of going on to touch the page. This PR keeps `ensure` as it is. - This PR names the out-of-memory errors in the line (`ERROR_COMMITMENT_LIMIT` and the like). It also has a test that runs a child process under a commit limit, so the failure path itself is exercised. #487's diff has no test of the failing commit. The two conflict in `lazy.rs`. A maintainer may want #487's caller change together with this PR's test. Read from the diffs only; I have not run either. AI-assisted (Claude Code).
Author
Owner

@⁠crosettiremi on GitHub · 2026-11-24 15:43 UTC · original · edited 2026-11-24 15:44 UTC

One downstream Windows/RDNA3 integration result for bd7b9e4. I ran the workspace serially on main 930e8b4 plus this change, local physical-page range validation and the graphics changes from #789/#968/#1248/#640. One library test failed. Its diagnostic was:

missing 0xc0000005 in stderr:
thread 'hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line' (158972) has overflowed its stack

The failure is in the child used by the test. This was a combined checkout. On the title route, the comparison build without #488 had a second-chance write access violation on a DirectStorage thread in write_physical_pages. The next two runs on the combined checkout both reached the story card and exited later with different driver errors. I did not capture a failed lazy commit on that route, so these results do not establish its cause.

Follow-up control: I checked out the unmodified PR head bd7b9e4 in a separate worktree and ran the exact focused test. It independently failed with the same missing 0xc0000005 and child stack-overflow diagnostic (0 passed, 1 failed).

**@⁠crosettiremi** on GitHub · 2026-11-24 15:43 UTC · [original](https://github.com/xcl-dev/xcl/pull/488#issuecomment-7136494310) · edited 2026-11-24 15:44 UTC One downstream Windows/RDNA3 integration result for bd7b9e4. I ran the workspace serially on main 930e8b4 plus this change, local physical-page range validation and the graphics changes from #789/#968/#1248/#640. One library test failed. Its diagnostic was: ``` missing 0xc0000005 in stderr: thread 'hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line' (158972) has overflowed its stack ``` The failure is in the child used by the test. This was a combined checkout. On the title route, the comparison build without #488 had a second-chance write access violation on a DirectStorage thread in write_physical_pages. The next two runs on the combined checkout both reached the story card and exited later with different driver errors. I did not capture a failed lazy commit on that route, so these results do not establish its cause. Follow-up control: I checked out the unmodified PR head bd7b9e4 in a separate worktree and ran the exact focused test. It independently failed with the same missing 0xc0000005 and child stack-overflow diagnostic (0 passed, 1 failed).
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-25 06:19 UTC · original

I checked futurepro62’s test-only setup on bd7b9e4. Windows 11 build 26300, Rust 1.99.1 MSVC, debug build, RTX 3080 Ti host. These tests are CPU-only.

Tested

  • cargo test --offline --locked -p xcl --lib hle::kernelx::lazy::tests -- --nocapture --test-threads=1 passed 3/3 on the published head. Running the built test executable with --exact hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line --nocapture --test-threads=1 in 20 fresh processes passed 4/20. The child reported 15 stack overflows and one allocation failure.
  • With the proposed out-of-frame stack warm-up, early UMA initialization, and heap warm-up, the same isolated test passed 20/20. The three-test filter also passed 3/3. The local edit was confined to test setup.

Not tested
Workspace suite, release, GPU, or retail behavior.

AI use
Codex (GPT-6, exact model variant unavailable) ran the tests and drafted this report.

**@⁠thehollowedone** on GitHub · 2026-11-25 06:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/488#issuecomment-7154668357) I checked [futurepro62’s test-only setup](https://git.gtahub.st/github/xcl-dev--xcl/pulls/488) on [bd7b9e4](https://github.com/xcl-dev/xcl/commit/bd7b9e4abd0bfc95fc9b5e1dcae0477831461f95). Windows 11 build 26300, Rust 1.99.1 MSVC, debug build, RTX 3080 Ti host. These tests are CPU-only. **Tested** - `cargo test --offline --locked -p xcl --lib hle::kernelx::lazy::tests -- --nocapture --test-threads=1` passed 3/3 on the published head. Running the built test executable with `--exact hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line --nocapture --test-threads=1` in 20 fresh processes passed 4/20. The child reported 15 stack overflows and one allocation failure. - With the proposed out-of-frame stack warm-up, early UMA initialization, and heap warm-up, the same isolated test passed 20/20. The three-test filter also passed 3/3. The local edit was confined to test setup. **Not tested** Workspace suite, release, GPU, or retail behavior. **AI use** Codex (GPT-6, exact model variant unavailable) ran the tests and drafted this report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 14:06 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 14:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/488#issuecomment-7164780511) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun. Thanks!
Author
Owner

@⁠ddaikodaiko on GitHub · 2026-11-25 16:52 UTC · original

Test report: failed_lazy_commit_stays_lazy_and_reports_in_crash_line fails on this PR's head

Commit tested: bd7b9e4 (this PR's head). NVIDIA GeForce RTX 3060 Ti (driver 32.0.16.2140), AMD Ryzen 5 1600, 16 GB, Windows 10 22H2 19045, rustc 1.100.0, release.

cargo test --release -p xcl --lib hle::kernelx::lazy: 2 passed, 1 failed. The child process dies before the crash line is written:

missing 0xc0000005 in stderr:
thread '...failed_lazy_commit_stays_lazy_and_reports_in_crash_line' has overflowed its stack

Two causes, both in the test (the change to commit() itself looks right):

  1. stack_warm is an array in the test's own frame, so it commits the pages above the stack pointer. The exception dispatch and unhandled_filter run below it, on pages that are not committed yet, and with the job's limit used up the stack cannot grow.
  2. With the stack warmed from a non-inlined call, the child still failed in about 1 of 4 runs with memory allocation of N bytes failed: at the limit, an allocation (the Vec in ensure, then the crash line's format!s) fails before the line is written.

A version that passed 40 of 40 runs here:

  • fill the limit with plain VirtualAlloc commits, call commit(page) directly (no heap in between), then release the filler;
  • assert in the child that the page stayed in LAZY, FAILED_COMMITS == 1, LAST_FAILED_ERR == ERROR_COMMITMENT_LIMIT and that failure_summary() names 1455;
  • release the page's reservation and touch it: the second failed commit goes through to the crash handler, with room to write its line; the parent checks 0xc0000005 and lazy commit failed 2 times.

With commit() reverted to remove-before-commit, this version fails on "a page whose commit failed stays lazy". Diff against this PR's head (bd7b9e4), test only:

lazy.rs test change
diff --git a/crates/xcl/src/hle/kernelx/lazy.rs b/crates/xcl/src/hle/kernelx/lazy.rs
index 6558cc6..3ab420e 100644
--- a/crates/xcl/src/hle/kernelx/lazy.rs
+++ b/crates/xcl/src/hle/kernelx/lazy.rs
@@ -134,7 +134,7 @@ pub fn ensure(p: usize, len: usize) {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use windows_sys::Win32::System::Memory::{VirtualFree, MEM_RELEASE, MEM_RESERVE};
+    use windows_sys::Win32::System::Memory::{VirtualFree, MEM_DECOMMIT, MEM_RELEASE, MEM_RESERVE};
 
     /// A lazy page reads as zeros on first touch, keeps what is written; `ensure` commits it
     /// without a fault.
@@ -200,7 +200,7 @@ mod tests {
             let stderr = String::from_utf8_lossy(&out.stderr);
             assert!(stderr.contains("0xc0000005"), "missing 0xc0000005 in stderr: {stderr}");
             assert!(stderr.contains("lazy commit failed"), "missing lazy commit summary in stderr: {stderr}");
-            assert!(stderr.contains("1455 ERROR_COMMITMENT_LIMIT"), "missing ERROR_COMMITMENT_LIMIT in stderr: {stderr}");
+            assert!(stderr.contains("lazy commit failed 2 times"), "missing the second failed commit in stderr: {stderr}");
             return;
         }
         unsafe {
@@ -217,8 +217,14 @@ mod tests {
 
             // Pre-commit stack pages before applying the job commit limit so the crash handler
             // itself does not hit a stack-guard commit failure.
-            let mut stack_warm = [0u8; 64 * 1024];
-            std::hint::black_box(&mut stack_warm);
+            // (in a call: the exception dispatch and the handler run below this frame, so the
+            // pages there must be committed; an array in this frame commits the ones above)
+            #[inline(never)]
+            fn warm_stack_below() {
+                let mut stack_warm = [0u8; 256 * 1024];
+                std::hint::black_box(&mut stack_warm);
+            }
+            warm_stack_below();
 
             let mut pmc: PROCESS_MEMORY_COUNTERS = std::mem::zeroed();
             assert_ne!(GetProcessMemoryInfo(GetCurrentProcess(), &mut pmc, std::mem::size_of_val(&pmc) as u32), 0);
@@ -227,34 +233,50 @@ mod tests {
             assert!(!job.is_null());
             let mut info: JOBOBJECT_EXTENDED_LIMIT_INFORMATION = std::mem::zeroed();
             info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_PROCESS_MEMORY;
-            info.ProcessMemoryLimit = pmc.PagefileUsage + 4 * PAGE;
+            info.ProcessMemoryLimit = pmc.PagefileUsage + 16 * 1024 * 1024;
             assert_ne!(SetInformationJobObject(job, JobObjectExtendedLimitInformation, &info as *const _ as *const _, std::mem::size_of_val(&info) as u32), 0);
             assert_ne!(AssignProcessToJobObject(job, GetCurrentProcess()), 0);
 
-            const PAGES: usize = 64;
-            let r = VirtualAlloc(std::ptr::null(), PAGES * PAGE, MEM_RESERVE, PAGE_READWRITE) as usize;
+            let r = VirtualAlloc(std::ptr::null(), 2 * PAGE, MEM_RESERVE, PAGE_READWRITE) as usize;
             assert_ne!(r, 0);
-            for i in 0..PAGES {
-                mark(r + i * PAGE);
-            }
+            mark(r);
+            mark(r + PAGE);
 
             // A page under the limit still commits on first touch.
             std::ptr::write_volatile(r as *mut u32, 42);
             assert_eq!(std::ptr::read_volatile(r as *const u32), 42);
             assert!(!LAZY.read().unwrap().contains(&r));
 
-            // Push past the job's commit limit: the failing page must stay in LAZY and record the error.
-            for i in 1..PAGES {
-                let page = r + i * PAGE;
-                ensure(page, PAGE);
-                if LAZY.read().unwrap().contains(&page) {
-                    assert_eq!(FAILED_COMMITS.load(Ordering::Acquire), 1);
-                    assert_eq!(LAST_FAILED_ERR.load(Ordering::Relaxed), ERROR_COMMITMENT_LIMIT);
-                    std::ptr::write_volatile(page as *mut u32, 99);
-                    unreachable!("touching an uncommitted page past the limit must fault");
-                }
+            // Use up the limit with plain commits, then commit the lazy page with nothing on the
+            // heap in between (at the limit an allocation fails and aborts the process).
+            const SMALL: usize = 0x1000;
+            let filler_len = 32 * 1024 * 1024;
+            let filler = VirtualAlloc(std::ptr::null(), filler_len, MEM_RESERVE, PAGE_READWRITE) as usize;
+            assert_ne!(filler, 0);
+            let mut committed = 0;
+            while committed < filler_len && !VirtualAlloc((filler + committed) as *const c_void, SMALL, MEM_COMMIT, PAGE_READWRITE).is_null() {
+                committed += SMALL;
             }
-            panic!("expected lazy commit to hit process memory limit");
+            let page = r + PAGE;
+            let ok = commit(page);
+            let reached = committed < filler_len;
+            // Room again for the heap, the asserts and the crash line.
+            assert_ne!(VirtualFree(filler as *mut c_void, 0, MEM_RELEASE), 0);
+            assert!(reached, "the job's limit is reached ({committed} bytes)");
+
+            // Past the job's commit limit: the page stays in LAZY and the error is recorded.
+            assert!(!ok, "the commit past the limit fails");
+            assert!(LAZY.read().unwrap().contains(&page), "a page whose commit failed stays lazy");
+            assert_eq!(FAILED_COMMITS.load(Ordering::Acquire), 1);
+            assert_eq!(LAST_FAILED_ERR.load(Ordering::Relaxed), ERROR_COMMITMENT_LIMIT);
+            let summary = failure_summary().unwrap();
+            assert!(summary.contains("1455 ERROR_COMMITMENT_LIMIT"), "{summary}");
+
+            // A lazy page that cannot be committed (its reservation is gone) faults through to the
+            // crash handler, whose line carries the summary.
+            assert_ne!(VirtualFree(r as *mut c_void, 0, MEM_RELEASE), 0);
+            std::ptr::write_volatile(page as *mut u32, 99);
+            unreachable!("touching a lazy page that cannot be committed must fault");
         }
     }
 }

Not tested: AMD GPUs, Windows 11, debug builds.

Tool: Claude Code, Claude Opus 5.5 (ran the tests, wrote the test change and this report).

**@⁠ddaikodaiko** on GitHub · 2026-11-25 16:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/488#issuecomment-7168652909) **Test report: `failed_lazy_commit_stays_lazy_and_reports_in_crash_line` fails on this PR's head** Commit tested: `bd7b9e4` (this PR's head). NVIDIA GeForce RTX 3060 Ti (driver 32.0.16.2140), AMD Ryzen 5 1600, 16 GB, Windows 10 22H2 19045, rustc 1.100.0, release. `cargo test --release -p xcl --lib hle::kernelx::lazy`: 2 passed, 1 failed. The child process dies before the crash line is written: ``` missing 0xc0000005 in stderr: thread '...failed_lazy_commit_stays_lazy_and_reports_in_crash_line' has overflowed its stack ``` Two causes, both in the test (the change to `commit()` itself looks right): 1. `stack_warm` is an array in the test's own frame, so it commits the pages above the stack pointer. The exception dispatch and `unhandled_filter` run below it, on pages that are not committed yet, and with the job's limit used up the stack cannot grow. 2. With the stack warmed from a non-inlined call, the child still failed in about 1 of 4 runs with `memory allocation of N bytes failed`: at the limit, an allocation (the `Vec` in `ensure`, then the crash line's `format!`s) fails before the line is written. A version that passed 40 of 40 runs here: - fill the limit with plain `VirtualAlloc` commits, call `commit(page)` directly (no heap in between), then release the filler; - assert in the child that the page stayed in `LAZY`, `FAILED_COMMITS == 1`, `LAST_FAILED_ERR == ERROR_COMMITMENT_LIMIT` and that `failure_summary()` names 1455; - release the page's reservation and touch it: the second failed commit goes through to the crash handler, with room to write its line; the parent checks `0xc0000005` and `lazy commit failed 2 times`. With `commit()` reverted to remove-before-commit, this version fails on "a page whose commit failed stays lazy". Diff against this PR's head (`bd7b9e4`), test only: <details><summary>lazy.rs test change</summary> ```diff diff --git a/crates/xcl/src/hle/kernelx/lazy.rs b/crates/xcl/src/hle/kernelx/lazy.rs index 6558cc6..3ab420e 100644 --- a/crates/xcl/src/hle/kernelx/lazy.rs +++ b/crates/xcl/src/hle/kernelx/lazy.rs @@ -134,7 +134,7 @@ pub fn ensure(p: usize, len: usize) { #[cfg(test)] mod tests { use super::*; - use windows_sys::Win32::System::Memory::{VirtualFree, MEM_RELEASE, MEM_RESERVE}; + use windows_sys::Win32::System::Memory::{VirtualFree, MEM_DECOMMIT, MEM_RELEASE, MEM_RESERVE}; /// A lazy page reads as zeros on first touch, keeps what is written; `ensure` commits it /// without a fault. @@ -200,7 +200,7 @@ mod tests { let stderr = String::from_utf8_lossy(&out.stderr); assert!(stderr.contains("0xc0000005"), "missing 0xc0000005 in stderr: {stderr}"); assert!(stderr.contains("lazy commit failed"), "missing lazy commit summary in stderr: {stderr}"); - assert!(stderr.contains("1455 ERROR_COMMITMENT_LIMIT"), "missing ERROR_COMMITMENT_LIMIT in stderr: {stderr}"); + assert!(stderr.contains("lazy commit failed 2 times"), "missing the second failed commit in stderr: {stderr}"); return; } unsafe { @@ -217,8 +217,14 @@ mod tests { // Pre-commit stack pages before applying the job commit limit so the crash handler // itself does not hit a stack-guard commit failure. - let mut stack_warm = [0u8; 64 * 1024]; - std::hint::black_box(&mut stack_warm); + // (in a call: the exception dispatch and the handler run below this frame, so the + // pages there must be committed; an array in this frame commits the ones above) + #[inline(never)] + fn warm_stack_below() { + let mut stack_warm = [0u8; 256 * 1024]; + std::hint::black_box(&mut stack_warm); + } + warm_stack_below(); let mut pmc: PROCESS_MEMORY_COUNTERS = std::mem::zeroed(); assert_ne!(GetProcessMemoryInfo(GetCurrentProcess(), &mut pmc, std::mem::size_of_val(&pmc) as u32), 0); @@ -227,34 +233,50 @@ mod tests { assert!(!job.is_null()); let mut info: JOBOBJECT_EXTENDED_LIMIT_INFORMATION = std::mem::zeroed(); info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_PROCESS_MEMORY; - info.ProcessMemoryLimit = pmc.PagefileUsage + 4 * PAGE; + info.ProcessMemoryLimit = pmc.PagefileUsage + 16 * 1024 * 1024; assert_ne!(SetInformationJobObject(job, JobObjectExtendedLimitInformation, &info as *const _ as *const _, std::mem::size_of_val(&info) as u32), 0); assert_ne!(AssignProcessToJobObject(job, GetCurrentProcess()), 0); - const PAGES: usize = 64; - let r = VirtualAlloc(std::ptr::null(), PAGES * PAGE, MEM_RESERVE, PAGE_READWRITE) as usize; + let r = VirtualAlloc(std::ptr::null(), 2 * PAGE, MEM_RESERVE, PAGE_READWRITE) as usize; assert_ne!(r, 0); - for i in 0..PAGES { - mark(r + i * PAGE); - } + mark(r); + mark(r + PAGE); // A page under the limit still commits on first touch. std::ptr::write_volatile(r as *mut u32, 42); assert_eq!(std::ptr::read_volatile(r as *const u32), 42); assert!(!LAZY.read().unwrap().contains(&r)); - // Push past the job's commit limit: the failing page must stay in LAZY and record the error. - for i in 1..PAGES { - let page = r + i * PAGE; - ensure(page, PAGE); - if LAZY.read().unwrap().contains(&page) { - assert_eq!(FAILED_COMMITS.load(Ordering::Acquire), 1); - assert_eq!(LAST_FAILED_ERR.load(Ordering::Relaxed), ERROR_COMMITMENT_LIMIT); - std::ptr::write_volatile(page as *mut u32, 99); - unreachable!("touching an uncommitted page past the limit must fault"); - } + // Use up the limit with plain commits, then commit the lazy page with nothing on the + // heap in between (at the limit an allocation fails and aborts the process). + const SMALL: usize = 0x1000; + let filler_len = 32 * 1024 * 1024; + let filler = VirtualAlloc(std::ptr::null(), filler_len, MEM_RESERVE, PAGE_READWRITE) as usize; + assert_ne!(filler, 0); + let mut committed = 0; + while committed < filler_len && !VirtualAlloc((filler + committed) as *const c_void, SMALL, MEM_COMMIT, PAGE_READWRITE).is_null() { + committed += SMALL; } - panic!("expected lazy commit to hit process memory limit"); + let page = r + PAGE; + let ok = commit(page); + let reached = committed < filler_len; + // Room again for the heap, the asserts and the crash line. + assert_ne!(VirtualFree(filler as *mut c_void, 0, MEM_RELEASE), 0); + assert!(reached, "the job's limit is reached ({committed} bytes)"); + + // Past the job's commit limit: the page stays in LAZY and the error is recorded. + assert!(!ok, "the commit past the limit fails"); + assert!(LAZY.read().unwrap().contains(&page), "a page whose commit failed stays lazy"); + assert_eq!(FAILED_COMMITS.load(Ordering::Acquire), 1); + assert_eq!(LAST_FAILED_ERR.load(Ordering::Relaxed), ERROR_COMMITMENT_LIMIT); + let summary = failure_summary().unwrap(); + assert!(summary.contains("1455 ERROR_COMMITMENT_LIMIT"), "{summary}"); + + // A lazy page that cannot be committed (its reservation is gone) faults through to the + // crash handler, whose line carries the summary. + assert_ne!(VirtualFree(r as *mut c_void, 0, MEM_RELEASE), 0); + std::ptr::write_volatile(page as *mut u32, 99); + unreachable!("touching a lazy page that cannot be committed must fault"); } } } ``` </details> Not tested: AMD GPUs, Windows 11, debug builds. Tool: Claude Code, Claude Opus 5.5 (ran the tests, wrote the test change and this report).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/488/head:github-bot/gh-488'
git switch 'github-bot/gh-488'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-488'
git switch 'github-bot/gh-488'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-488'
git switch 'github-bot/gh-488'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-488'
git switch 'main'
git merge --squash 'github-bot/gh-488'
git switch 'main'
git merge --ff-only 'github-bot/gh-488'
git switch 'main'
git merge 'github-bot/gh-488'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.