fix(mem): a thread's stack page refused at the commit limit waits for commit, then the thread goes on #1885

Open
d4nkn3ss wants to merge 5 commits from d4nkn3ss/Longshot:fix/stack-commit-limit into main
Contributor

Summary

When the PC runs out of memory (Windows' commit limit: RAM plus the page file), Longshot could crash with a "stack overflow" (0xc00000fd) on whichever game thread happened to need one more page of stack. The thread wasn't deep in anything. A thread's stack is only reserved (the guest's 64 MB), and Windows commits each page as the stack grows. At the commit limit it can't, and it raises a stack overflow with nearly all of the stack unused. Guest memory already waits there for the renderer's textures to give commit back (commit_wait); a thread's stack didn't. That was the first crash in #1772: a 24 GB PC at its limit, 0xc00000fd on PreActorModelCompose, in ucrtbase.dll, after the log's mem: commit of 0x10000 bytes at the commit limit made after ... lines.

Now a first vectored handler takes that one stack overflow. It acts only when more than 64 KB of the thread's reservation is left. It waits for commit as a guest page does (up to 5 s), sets the guard page again below the stack, and the thread goes on. If commit never comes back, the out-of-memory line and notice come first, then the crash report as before. A stack that really ran out goes straight to the crash report. Windows only.

On main: run the game with a per-process commit limit below what it needs, a Job object with JOB_OBJECT_LIMIT_PROCESS_MEMORY at 14 GB here, and load a save: 2 of 3 starts crashed with 0xc00000fd (on rmbl::VibrationThread and GeneralFormatAsync_, both in ucrtbase.dll). A real PC gets there with a small fixed page file.

See #1772, and likely #1919 (the same signature on the Resource Control thread, v3.0.0). #1772's later crash, in nvoglv64.dll under VRAM and commit pressure, isn't this one: see Risks.

Read first: stack_on_touch() in host/mkw_glue.c and its registration in hos_commit_init(); then tests/test_stack_commit.py and tests/stack_commit_test.c.

Testing

Tested:

  • In the game, Windows 11 Pro 26300, RTX 3080 10 GB (NVIDIA 621.14), this PR @ f5cd1405 against main @ 89c3d21e (both built here): an adult save in Hyrule Field, the first teleport to the Market, then quit.
    • Without a limit: 2 starts of this PR, both arrived, both closed normally, no CRASH, FATAL or VK_ERROR line.
    • Under a 14 GB per-process commit limit (a Job object; the game's peak here is 17.0 GB): 3 starts of main and 4 of this PR, interleaved. Every run ends there, since the game can't fit, and main's ended with 0xc00000fd in 2 of 3. None of this PR's did. In one, a stack page was refused and recovered (mem: a thread's stack grew at the commit limit after waiting for commit). They ended instead in NVIDIA's driver (nvoglv64.dll, nvwgf2umx.dll: writes near 0), in the renderer's C++ allocation refused for 5 s, and once in a host write to 0. Those are other allocations failing at the limit; see Measurements and Risks.
  • python -I -B tests/test_stack_commit.py: fails on main (a thread whose stack page was refused at the commit limit died with a stack overflow (0xc00000fd)), passes here.
    • What it checks: the fixture compiles mkw_glue.c's real code from commit_wait to the crash report, with the handlers hos_commit_init registers from it. It puts itself in a Job with a commit limit, fills that, and grows a reserved 64 MB stack while another thread gives commit back after 300 ms.
    • Its other cases: commit never comes back (5 s, the out-of-memory line, then 0xc00000fd), and a stack that really runs out (0xc00000fd at once, not retried).
    • Not held by it: on this Windows 11 build the stack kept growing after one recovery even without the guard page set again, so dropping PAGE_GUARD still passes; so does dropping the 64 KB "really ran out" margin, since the handler stops at the reservation's end either way. Both are kept as Windows expects them (_resetstkoflw sets the guard page again; the margin leaves the crash report its room).
  • The other checks that read host/mkw_glue.c pass as on main: test_commit_limit, test_host_alloc_wait, test_crash_record, test_sampler_stack_walk, test_renderer_new_handler, test_input_background, test_nvn_host_tables. test_profiling_mode and test_slow_frames fail here and on main @ 89c3d21e alike.
  • host/mkw_glue.c with -fsyntax-only -Wall -Wextra: clang (llvm-mingw, Windows) and gcc 14.2 (Linux: Debian under WSL 2), here and on main. The same warnings on both (5 on Windows, 1 on Linux), none in the new code. The Windows game builds and links here; the Linux host wasn't linked.
  • python -I -B tests/run_all.py (Windows, llvm-mingw from the Longshot Builder; mise isn't installed on this PC), this PR on main @ 89c3d21e against main @ 89c3d21e, both run the same way: 764 passed, 65 failed here; 765 passed, 63 failed on main. The 63 fail on both (test_vbytes by its 600 s timeout). The other two:
    • test_stack_commit failed in that first full run, at 24 checks at once: the fixture's thread that gives commit back had an ordinary stack and itself needed a stack page at the limit, so it never gave any back. The fixture now commits that thread's 256 KB of stack up front (in the test commit). After that, 12 copies run at once all passed, and the test commit alone still fails on main.
    • test_recording_admission is flaky on this PC on main too (its parallel case).
    • test_job_queue was run from Git Bash, because started from this PowerShell it gets a Ctrl+C that ends the run: 20 of its 21 pass, Environment.test_ram_file_system fails, as on main.
  • Rebased since onto main @ 2210931c (no change to these files there): test_stack_commit, test_commit_limit, test_host_alloc_wait and test_crash_record pass.

Still to test:

  • Windows 10, any GPU: the same start under a commit limit (a small fixed page file, or a Job object), expecting no 0xc00000fd and, when a stack page is refused, a thread's stack grew at the commit limit (by hand: #1772's reporter is on Windows 10 19045)
  • Windows, AMD or Intel GPU: a normal start, expecting it to play and close as on main (@Beanstalk start the game, load a save and play a minute, Windows AMD and Intel)

Measurements

Verdict: fixed: at the commit limit a thread's stack waits for commit instead of crashing with a stack overflow. On main @ 89c3d21e it crashed so in 2 of 3 starts under a forced limit, this PR in none of 4. A PC that stays at its limit still crashes elsewhere: the driver's and the renderer's own allocations.

Setup: Windows 11 Pro 26300, RTX 3080 10 GB (NVIDIA 621.14), i9-12900K, 64 GB. An adult save in Hyrule Field, the first teleport to the Market. The game runs in a Job object whose per-process commit limit is 14 GB (its peak with no limit is 17.0 GB), one start per run, interleaved. Read from longshot_log.txt and the crash record. Not measured again on main @ 2210931c, which this PR is now on: the commits since 89c3d21e don't touch host/mkw_glue.c, the threads' stacks or the commit waits, so the numbers hold.

under a 14 GB commit limit Before: main @ 89c3d21e After: this PR @ f5cd1405 (on 89c3d21e)
starts 3 4
ended with 0xc00000fd (stack overflow) 2 (rmbl::VibrationThread, GeneralFormatAsync_) 0
a stack page refused, waited for and grown (not handled) 1
ended otherwise 1: a guest write after the out-of-memory notice 4: nvoglv64.dll write 0x10, nvwgf2umx.dll write 0x8, the renderer's allocation refused for 5 s, a host write to 0
[hos host] mem: commit of 0x1000 bytes at the commit limit made after 200 ms (3 so far)
[hos host] mem: a thread's stack grew at the commit limit after waiting for commit

Risks

  • Every thread: the handler sees every thread's stack overflow, the driver's included, but it only acts on one Windows raises with more than 64 KB of the thread's stack left, which a real overflow doesn't leave. A thread that set a stack guarantee over 64 KB with SetThreadStackGuarantee (none of Longshot's do) would have a real overflow carried into its guarantee, and crash a little later with less room.
  • The rest of the limit: a thread waiting for its stack holds for up to 5 s, as a guest page does. This doesn't make a PC at its commit limit keep running: the NVIDIA driver's own allocations and the renderer's still fail there, as in #1772's later nvoglv64.dll crash. The player's way out stays the out-of-memory notice's: a bigger page file.
  • Turning it off: a revert. A player notices nothing unless the PC runs out of memory.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary When the PC runs out of memory (Windows' commit limit: RAM plus the page file), Longshot could crash with a "stack overflow" (`0xc00000fd`) on whichever game thread happened to need one more page of stack. The thread wasn't deep in anything. A thread's stack is only reserved (the guest's 64 MB), and Windows commits each page as the stack grows. At the commit limit it can't, and it raises a stack overflow with nearly all of the stack unused. Guest memory already waits there for the renderer's textures to give commit back (`commit_wait`); a thread's stack didn't. That was the first crash in #1772: a 24 GB PC at its limit, `0xc00000fd` on PreActorModelCompose, in `ucrtbase.dll`, after the log's `mem: commit of 0x10000 bytes at the commit limit made after ...` lines. Now a first vectored handler takes that one stack overflow. It acts only when more than 64 KB of the thread's reservation is left. It waits for commit as a guest page does (up to 5 s), sets the guard page again below the stack, and the thread goes on. If commit never comes back, the out-of-memory line and notice come first, then the crash report as before. A stack that really ran out goes straight to the crash report. Windows only. **On main:** run the game with a per-process commit limit below what it needs, a Job object with `JOB_OBJECT_LIMIT_PROCESS_MEMORY` at 14 GB here, and load a save: 2 of 3 starts crashed with `0xc00000fd` (on `rmbl::VibrationThread` and `GeneralFormatAsync_`, both in `ucrtbase.dll`). A real PC gets there with a small fixed page file. See #1772, and likely #1919 (the same signature on the Resource Control thread, v3.0.0). #1772's later crash, in `nvoglv64.dll` under VRAM and commit pressure, isn't this one: see Risks. Read first: `stack_on_touch()` in `host/mkw_glue.c` and its registration in `hos_commit_init()`; then `tests/test_stack_commit.py` and `tests/stack_commit_test.c`. ## Testing **Tested:** - In the game, Windows 11 Pro 26300, RTX 3080 10 GB (NVIDIA 621.14), this PR @ f5cd1405 against main @ 89c3d21e (both built here): an adult save in Hyrule Field, the first teleport to the Market, then quit. - Without a limit: 2 starts of this PR, both arrived, both closed normally, no `CRASH`, `FATAL` or `VK_ERROR` line. - Under a 14 GB per-process commit limit (a Job object; the game's peak here is 17.0 GB): 3 starts of main and 4 of this PR, interleaved. Every run ends there, since the game can't fit, and main's ended with `0xc00000fd` in 2 of 3. None of this PR's did. In one, a stack page was refused and recovered (`mem: a thread's stack grew at the commit limit after waiting for commit`). They ended instead in NVIDIA's driver (`nvoglv64.dll`, `nvwgf2umx.dll`: writes near 0), in the renderer's C++ allocation refused for 5 s, and once in a host write to 0. Those are other allocations failing at the limit; see Measurements and Risks. - `python -I -B tests/test_stack_commit.py`: fails on main (`a thread whose stack page was refused at the commit limit died with a stack overflow (0xc00000fd)`), passes here. - What it checks: the fixture compiles `mkw_glue.c`'s real code from `commit_wait` to the crash report, with the handlers `hos_commit_init` registers from it. It puts itself in a Job with a commit limit, fills that, and grows a reserved 64 MB stack while another thread gives commit back after 300 ms. - Its other cases: commit never comes back (5 s, the out-of-memory line, then `0xc00000fd`), and a stack that really runs out (`0xc00000fd` at once, not retried). - Not held by it: on this Windows 11 build the stack kept growing after one recovery even without the guard page set again, so dropping `PAGE_GUARD` still passes; so does dropping the 64 KB "really ran out" margin, since the handler stops at the reservation's end either way. Both are kept as Windows expects them (`_resetstkoflw` sets the guard page again; the margin leaves the crash report its room). - The other checks that read `host/mkw_glue.c` pass as on main: test_commit_limit, test_host_alloc_wait, test_crash_record, test_sampler_stack_walk, test_renderer_new_handler, test_input_background, test_nvn_host_tables. test_profiling_mode and test_slow_frames fail here and on main @ 89c3d21e alike. - `host/mkw_glue.c` with `-fsyntax-only -Wall -Wextra`: clang (llvm-mingw, Windows) and gcc 14.2 (Linux: Debian under WSL 2), here and on main. The same warnings on both (5 on Windows, 1 on Linux), none in the new code. The Windows game builds and links here; the Linux host wasn't linked. - `python -I -B tests/run_all.py` (Windows, llvm-mingw from the Longshot Builder; `mise` isn't installed on this PC), this PR on main @ 89c3d21e against main @ 89c3d21e, both run the same way: 764 passed, 65 failed here; 765 passed, 63 failed on main. The 63 fail on both (`test_vbytes` by its 600 s timeout). The other two: - `test_stack_commit` failed in that first full run, at 24 checks at once: the fixture's thread that gives commit back had an ordinary stack and itself needed a stack page at the limit, so it never gave any back. The fixture now commits that thread's 256 KB of stack up front (in the test commit). After that, 12 copies run at once all passed, and the test commit alone still fails on main. - `test_recording_admission` is flaky on this PC on main too (its parallel case). - `test_job_queue` was run from Git Bash, because started from this PowerShell it gets a Ctrl+C that ends the run: 20 of its 21 pass, `Environment.test_ram_file_system` fails, as on main. - Rebased since onto main @ 2210931c (no change to these files there): test_stack_commit, test_commit_limit, test_host_alloc_wait and test_crash_record pass. **Still to test:** - Windows 10, any GPU: the same start under a commit limit (a small fixed page file, or a Job object), expecting no `0xc00000fd` and, when a stack page is refused, `a thread's stack grew at the commit limit` (by hand: #1772's reporter is on Windows 10 19045) - Windows, AMD or Intel GPU: a normal start, expecting it to play and close as on main (`@Beanstalk start the game, load a save and play a minute, Windows AMD and Intel`) ## Measurements **Verdict:** fixed: at the commit limit a thread's stack waits for commit instead of crashing with a stack overflow. On main @ 89c3d21e it crashed so in 2 of 3 starts under a forced limit, this PR in none of 4. A PC that stays at its limit still crashes elsewhere: the driver's and the renderer's own allocations. Setup: Windows 11 Pro 26300, RTX 3080 10 GB (NVIDIA 621.14), i9-12900K, 64 GB. An adult save in Hyrule Field, the first teleport to the Market. The game runs in a Job object whose per-process commit limit is 14 GB (its peak with no limit is 17.0 GB), one start per run, interleaved. Read from `longshot_log.txt` and the crash record. Not measured again on main @ 2210931c, which this PR is now on: the commits since 89c3d21e don't touch `host/mkw_glue.c`, the threads' stacks or the commit waits, so the numbers hold. | under a 14 GB commit limit | Before: main @ 89c3d21e | After: this PR @ f5cd1405 (on 89c3d21e) | |---|---|---| | starts | 3 | 4 | | ended with `0xc00000fd` (stack overflow) | 2 (`rmbl::VibrationThread`, `GeneralFormatAsync_`) | 0 | | a stack page refused, waited for and grown | (not handled) | 1 | | ended otherwise | 1: a guest write after the out-of-memory notice | 4: `nvoglv64.dll` write 0x10, `nvwgf2umx.dll` write 0x8, the renderer's allocation refused for 5 s, a host write to 0 | ``` [hos host] mem: commit of 0x1000 bytes at the commit limit made after 200 ms (3 so far) [hos host] mem: a thread's stack grew at the commit limit after waiting for commit ``` ## Risks - **Every thread:** the handler sees every thread's stack overflow, the driver's included, but it only acts on one Windows raises with more than 64 KB of the thread's stack left, which a real overflow doesn't leave. A thread that set a stack guarantee over 64 KB with `SetThreadStackGuarantee` (none of Longshot's do) would have a real overflow carried into its guarantee, and crash a little later with less room. - **The rest of the limit:** a thread waiting for its stack holds for up to 5 s, as a guest page does. This doesn't make a PC at its commit limit keep running: the NVIDIA driver's own allocations and the renderer's still fail there, as in #1772's later `nvoglv64.dll` crash. The player's way out stays the out-of-memory notice's: a bigger page file. - **Turning it off:** a revert. A player notices nothing unless the PC runs out of memory. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A thread with a reserved 64 MB stack, in a Job object at its commit limit, grows its stack while another thread gives
commit back 300 ms later. On main it dies with 0xc00000fd with most of its stack unused, as #1772's PreActorModelCompose
did at a 24 GB PC's commit limit. The fixture compiles mkw_glue.c's commit waits and the vectored handlers
hos_commit_init registers from them; also checked: commit that never comes back, and a stack that really runs out.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(mem): a thread's stack page refused at the commit limit waits for commit, then the thread goes on
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 4s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
7b79bbc8f8
A thread's stack is only reserved (the guest's 64 MB), each page committed as it grows. At Windows' commit limit the
next guard page can't be committed and Windows raises a stack overflow (0xc00000fd) with the stack nearly unused:
#1772's PreActorModelCompose crash on a 24 GB PC at its limit. A first vectored handler now takes that overflow when
more than 64 KB of the reservation is left: it waits for commit as a guest page does (commit_wait, up to 5 s while the
renderer's textures give commit back), sets the guard page again below the stack, and the thread goes on. Commit that
never comes back gets the out-of-memory line and notice, then the crash report as before; a stack that really ran out
goes straight to it. Windows only.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

Tested in game: Windows 11 Pro 26300, RTX 3080 10 GB (NVIDIA 621.14): an adult save in Hyrule Field, the first teleport to the Market. Without a limit, 2 starts arrived and closed normally. Under a 14 GB per-process commit limit (a Job object; the game peaks at 17.0 GB), interleaved with main @ 89c3d21e: main crashed with 0xc00000fd in 2 of 3 starts, this PR in 0 of 4, with one stack page refused, waited for and grown (mem: a thread's stack grew at the commit limit after waiting for commit). Its runs ended elsewhere at that limit (NVIDIA's driver, the renderer's allocation), as Measurements says.

Tested in game: Windows 11 Pro 26300, RTX 3080 10 GB (NVIDIA 621.14): an adult save in Hyrule Field, the first teleport to the Market. Without a limit, 2 starts arrived and closed normally. Under a 14 GB per-process commit limit (a Job object; the game peaks at 17.0 GB), interleaved with main @ 89c3d21e: main crashed with 0xc00000fd in 2 of 3 starts, this PR in 0 of 4, with one stack page refused, waited for and grown (mem: a thread's stack grew at the commit limit after waiting for commit). Its runs ended elsewhere at that limit (NVIDIA's driver, the renderer's allocation), as Measurements says.
d4nkn3ss changed title from WIP: fix(mem): a thread's stack page refused at the commit limit waits for commit, then the thread goes on to fix(mem): a thread's stack page refused at the commit limit waits for commit, then the thread goes on 2026-11-20 16:35:17 +00:00
Member

Possibly related, for context:

  • PR #77 fix(memory): give commit back near Windows' commit limit instead of crashing — Existing commit-limit wait for guest memory; this extends handling to thread stacks
  • PR #341 fix(hos): wait at the commit limit for the host's own allocations, then say out of memory — Shared commit-limit out-of-memory reporting path
Possibly related, for context: - PR #77 fix(memory): give commit back near Windows' commit limit instead of crashing — Existing commit-limit wait for guest memory; this extends handling to thread stacks - PR #341 fix(hos): wait at the commit limit for the host's own allocations, then say out of memory — Shared commit-limit out-of-memory reporting path
The fixture's frames were 16 KB, so the fault came from a probe far below a stack pointer that had plenty of committed stack
above it, and its hos_log stand-in took 512 bytes. In the game the stack pointer is in the page Windows just committed
(ucrtbase.dll's small frames in #1772 and #1919), with under 4 KB left, and hos_log takes 4.3 KB. The small cases run there;
never small fails on the handler that logs before it has room (it dies in its own log line, with no out-of-memory line).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
stack_on_touch runs on what is left of the page Windows did commit, under 4 KB, with only reserved pages below. Its
commit_wait and hos_log calls (hos_log takes 4.3 KB) ran off that page: on recovery into the one page it had committed, and
when commit never came back into reserved memory, an access violation inside the handler that ended the process with no
out-of-memory line, no notice and no crash report. The wait is now its own quiet loop, the 64 KB below the stack is
committed as guard pages (Windows hands them to the stack as it grows) before any log line, and 1 MB committed at the start
is given back for that 64 KB when 5 s pass, so the line, the notice and the crash report have a stack. A stack with under
128 KB of its reservation left is taken as really run out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
docs(help): Windows' out-of-memory notice, and the 0xc00000fd crash at the commit limit
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 8s
PR description / Description follows the template (pull_request_target) Successful in 10s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 14s
CI / Workflow lint (actionlint) (pull_request) Successful in 14s
Third-party parts / As their notes say (pull_request) Successful in 16s
beanstalk/approval can't be tested as asked: see the farm's comment
CI / Website build and checks (pull_request) Failing after 2m35s
3b1ad48720
Co-Authored-By: Claude Opus 5.5 <[email protected]>
HumanBean left a comment

Recommendation: Wait. Approve once the forge's Windows build compiles the three commits on top (pushed to your branch) and a Windows run at a small page file passes. This PC has no Windows toolchain: the new handler code was only syntax-checked against stub declarations, and the new test cases weren't run here (CI runs them). The cause is right and the design is right. One real bug: the handler runs out of stack in its own log lines. The commits on top fix that. Without them I'd request changes, because the path where commit never comes back would die silently.

Does it fix the cause?

  • #1772, first crash: yes. The crash run's log (longshot_log.1.txt, run 6e14ecec) has vk: commit limit near: 491 MB of commit left, then 8 mem: commit of 0x10000 bytes at the commit limit made after ... lines. The record says 0xc00000fd on PreActorModelCompose in ucrtbase.dll, 28 s in. That is a reserved-only 64 MB stack (hos_thread.c:609) refused its next page, not deep recursion. The later nvoglv64.dll crash isn't this one, and the PR says so.
  • #1919: likely. Same version, same ucrtbase.dll+0x10bfb frame, Resource Control thread, but no log to confirm the limit.
  • #433, 2080 Ti comment: likely. Same PC as #1772 (3800X, 24 GB, Windows 10 19045, 621.24), 0xc00000fd on Resource Control. #433's other reports (Intel Arc, the 3070 laptop, logs that end with a normal close) aren't shown to be this. It shouldn't be closed by this PR.
  • What it doesn't do: a PC that stays at its limit still crashes in the driver's or the renderer's own allocations, as your Risks say. The real fix for the reporter is the page file. The second commit adds a help entry that says so.

The bug: the handler has almost no stack

When Windows can't commit the next guard page, the thread's stack pointer is in the page it just committed. Below that page there is only reserved memory, with no guard page. The exception frames (CONTEXT and record, about 1.5 KB) go there, and then the handler runs on what is left: under 4 KB, often much less.

hos_log takes 4.3 KB of buffers (hos_vlog: 1024 + 1100 + 2200, plus hos_log_redact). So:

  • Commit never comes back: commit_wait's "still refused after 5 s" line, then the handler's own line, run off the page into reserved memory. That is an access violation inside the vectored handler, on a stack with no room to dispatch it, and the process ends without the out-of-memory line, the notice or the crash report. On main, at least the crash report had a chance.
  • Recovery: commit_wait's success line runs into the one 4 KB page just committed. Whether it fits depends on where in the page the fault came. Your in-game recovery fit; it isn't guaranteed.

The test didn't catch this, for two reasons. Its frames are 16 KB, so the fault comes from a ___chkstk_ms probe 16 KB below a stack pointer with plenty of committed stack above it. And its hos_log stand-in takes 512 bytes.

What the commits on top do

  1. test: adds small cases with 512-byte frames, so the stack pointer is in the last committed page, as in ucrtbase.dll. The stand-in hos_log now takes the real one's 4.3 KB. never small should fail on your head (unverified: no Windows here).
  2. fix:
    • Until the stack has room, the handler only makes system calls. The wait is its own loop: commit_wait's 100 x 50 ms, but saying nothing.
    • It commits the 64 KB below StackLimit as PAGE_READWRITE | PAGE_GUARD. Windows hands those guard pages to the stack one at a time as it grows, as SetThreadStackGuarantee's region is handed out, so there is no re-entry and StackLimit stays right. Only then does it log.
    • When 5 s pass, a 1 MB stack_spare committed in hos_commit_init is given back for that 64 KB, so the line, the notice and the crash report have a stack to run on.
    • "Really ran out" is now under 128 KB left, twice the room.
    • VirtualProtect is gone, since the commit is made as guard pages to begin with.
  3. docs: docs/user/common-issues.md, "Windows: an out-of-memory notice, or a crash with 0xc00000fd".

Safety (with the fix)

  • Re-entrancy: a second overflow on the same thread could only come from the handler's own stack use. Before the commit it is a few hundred bytes; after it, the guard pages absorb it. Other threads share nothing but interlocked counters and the one-shot spare (InterlockedExchangePointer).
  • Threads not ours: driver threads go through the same handler. With 128 KB or more left they wait as guest threads do. Real overflows go on as before.
  • Fibers: the TEB's limits are the fiber's, so it holds.
  • Vectored, not SEH: right. It has to run before any frame handler or the unhandled filter, and report_fatal stays last.
  • Linux: everything is under #ifdef _WIN32, and the preprocessed Linux code is unchanged.
  • StackLimit semantics: recovery relies on StackLimit - 1 being reserved when the overflow is raised. Your Windows 11 runs show that, but Windows 10 19045 (the reporter's) is untested.

Switches: none, and none needed: it only acts on an exception that would otherwise end the game.

Before merge

  • The new test cases have not been run: there's no Windows on this PC. Please run python -I -B tests/test_stack_commit.py here, and on your head to see never small fail.
  • Run the game once more under your 14 GB Job limit. Expect mem: a thread's stack grew at the commit limit after waiting N ms for commit (k so far); the line's text changed. Update the PR body's quoted line.
  • Windows 10: a run at a small fixed page file (Beanstalk request below, or the reporter).
**Recommendation: Wait. Approve once the forge's Windows build compiles the three commits on top (pushed to your branch) and a Windows run at a small page file passes.** This PC has no Windows toolchain: the new handler code was only syntax-checked against stub declarations, and the new test cases weren't run here (CI runs them). The cause is right and the design is right. One real bug: the handler runs out of stack in its own log lines. The commits on top fix that. Without them I'd request changes, because the path where commit never comes back would die silently. ### Does it fix the cause? - **#1772, first crash: yes.** The crash run's log (`longshot_log.1.txt`, run 6e14ecec) has `vk: commit limit near: 491 MB of commit left`, then 8 `mem: commit of 0x10000 bytes at the commit limit made after ...` lines. The record says `0xc00000fd` on PreActorModelCompose in `ucrtbase.dll`, 28 s in. That is a reserved-only 64 MB stack (`hos_thread.c:609`) refused its next page, not deep recursion. The later `nvoglv64.dll` crash isn't this one, and the PR says so. - **#1919: likely.** Same version, same `ucrtbase.dll+0x10bfb` frame, Resource Control thread, but no log to confirm the limit. - **#433, 2080 Ti comment: likely.** Same PC as #1772 (3800X, 24 GB, Windows 10 19045, 621.24), `0xc00000fd` on Resource Control. #433's other reports (Intel Arc, the 3070 laptop, logs that end with a normal close) aren't shown to be this. It shouldn't be closed by this PR. - **What it doesn't do:** a PC that stays at its limit still crashes in the driver's or the renderer's own allocations, as your Risks say. The real fix for the reporter is the page file. The second commit adds a help entry that says so. ### The bug: the handler has almost no stack When Windows can't commit the next guard page, the thread's stack pointer is in the page it just committed. Below that page there is only reserved memory, with no guard page. The exception frames (CONTEXT and record, about 1.5 KB) go there, and then the handler runs on what is left: under 4 KB, often much less. `hos_log` takes 4.3 KB of buffers (`hos_vlog`: 1024 + 1100 + 2200, plus `hos_log_redact`). So: - **Commit never comes back:** `commit_wait`'s "still refused after 5 s" line, then the handler's own line, run off the page into reserved memory. That is an access violation inside the vectored handler, on a stack with no room to dispatch it, and the process ends without the out-of-memory line, the notice or the crash report. On main, at least the crash report had a chance. - **Recovery:** `commit_wait`'s success line runs into the one 4 KB page just committed. Whether it fits depends on where in the page the fault came. Your in-game recovery fit; it isn't guaranteed. The test didn't catch this, for two reasons. Its frames are 16 KB, so the fault comes from a `___chkstk_ms` probe 16 KB below a stack pointer with plenty of committed stack above it. And its `hos_log` stand-in takes 512 bytes. ### What the commits on top do 1. **test:** adds `small` cases with 512-byte frames, so the stack pointer is in the last committed page, as in `ucrtbase.dll`. The stand-in `hos_log` now takes the real one's 4.3 KB. `never small` should fail on your head (unverified: no Windows here). 2. **fix:** - Until the stack has room, the handler only makes system calls. The wait is its own loop: `commit_wait`'s 100 x 50 ms, but saying nothing. - It commits the 64 KB below `StackLimit` as `PAGE_READWRITE | PAGE_GUARD`. Windows hands those guard pages to the stack one at a time as it grows, as `SetThreadStackGuarantee`'s region is handed out, so there is no re-entry and `StackLimit` stays right. Only then does it log. - When 5 s pass, a 1 MB `stack_spare` committed in `hos_commit_init` is given back for that 64 KB, so the line, the notice and the crash report have a stack to run on. - "Really ran out" is now under 128 KB left, twice the room. - `VirtualProtect` is gone, since the commit is made as guard pages to begin with. 3. **docs:** `docs/user/common-issues.md`, "Windows: an out-of-memory notice, or a crash with `0xc00000fd`". ### Safety (with the fix) - **Re-entrancy:** a second overflow on the same thread could only come from the handler's own stack use. Before the commit it is a few hundred bytes; after it, the guard pages absorb it. Other threads share nothing but interlocked counters and the one-shot spare (`InterlockedExchangePointer`). - **Threads not ours:** driver threads go through the same handler. With 128 KB or more left they wait as guest threads do. Real overflows go on as before. - **Fibers:** the TEB's limits are the fiber's, so it holds. - **Vectored, not SEH:** right. It has to run before any frame handler or the unhandled filter, and `report_fatal` stays last. - **Linux:** everything is under `#ifdef _WIN32`, and the preprocessed Linux code is unchanged. - **`StackLimit` semantics:** recovery relies on `StackLimit - 1` being reserved when the overflow is raised. Your Windows 11 runs show that, but Windows 10 19045 (the reporter's) is untested. **Switches:** none, and none needed: it only acts on an exception that would otherwise end the game. ### Before merge - The new test cases have not been run: there's no Windows on this PC. Please run `python -I -B tests/test_stack_commit.py` here, and on your head to see `never small` fail. - Run the game once more under your 14 GB Job limit. Expect `mem: a thread's stack grew at the commit limit after waiting N ms for commit (k so far)`; the line's text changed. Update the PR body's quoted line. - Windows 10: a run at a small fixed page file (Beanstalk request below, or the reporter).
@ -225,0 +239,4 @@
static LONG CALLBACK stack_on_touch(EXCEPTION_POINTERS *info) {
if (info->ExceptionRecord->ExceptionCode != EXCEPTION_STACK_OVERFLOW) return EXCEPTION_CONTINUE_SEARCH;
char *const limit = (char *)((NT_TIB *)NtCurrentTeb())->StackLimit;
MEMORY_BASIC_INFORMATION mbi;
Owner

The handler runs on what is left of the page Windows did commit: under 4 KB, less the exception's own frames, with only reserved pages below. commit_wait logs on both of its ends (hos_log, 4.3 KB of buffers in hos_vlog). When commit never comes back, its "still refused after 5 s" line runs into reserved memory. That is an access violation inside the vectored handler, with no room to dispatch it, and the process ends with no out-of-memory line, notice or crash report. Fixed on top: a quiet wait loop (the same 100 x 50 ms), and the 64 KB below StackLimit committed as guard pages before any line.

The handler runs on what is left of the page Windows did commit: under 4 KB, less the exception's own frames, with only reserved pages below. `commit_wait` logs on both of its ends (`hos_log`, 4.3 KB of buffers in `hos_vlog`). When commit never comes back, its "still refused after 5 s" line runs into reserved memory. That is an access violation inside the vectored handler, with no room to dispatch it, and the process ends with no out-of-memory line, notice or crash report. Fixed on top: a quiet wait loop (the same 100 x 50 ms), and the 64 KB below `StackLimit` committed as guard pages before any line.
@ -225,0 +234,4 @@
own loop, as commit_wait's but saying nothing, and the 64 KB is committed as guard pages, which Windows then hands to the
stack one at a time as it grows, as its own. Commit that never came back: stack_spare, 1 MB committed at the start, is given
back for that 64 KB, so the line, the notice and the crash report have a stack to run on */
enum { STACK_ROOM = 0x10000, STACK_SPARE = 1 << 20 };
Owner

With the 64 KB room committed below the stack, "really ran out" is now under 128 KB left (twice the room), so the room never reaches the reservation's last pages. A real overflow leaves a few pages, so it still goes straight to the crash report.

With the 64 KB room committed below the stack, "really ran out" is now under 128 KB left (twice the room), so the room never reaches the reservation's last pages. A real overflow leaves a few pages, so it still goes straight to the crash report.
@ -225,0 +245,4 @@
if (left < 2 * STACK_ROOM) return EXCEPTION_CONTINUE_SEARCH; /* (it really ran out) */
char *const room = limit - STACK_ROOM;
int ms = 0;
while (!VirtualAlloc(room, STACK_ROOM, MEM_COMMIT, PAGE_READWRITE | PAGE_GUARD)) {
Owner

This runs with nothing committed below the stack (the guard page was refused), so this line is where the process dies when commit never comes back. On top, a 1 MB stack_spare committed in hos_commit_init is given back for the 64 KB room once the 5 s are up, so this line, hos_out_of_memory(1) and then report_crash have a stack. For an error other than the commit limit there's no room to say anything, so it goes on to the crash report as on main.

This runs with nothing committed below the stack (the guard page was refused), so this line is where the process dies when commit never comes back. On top, a 1 MB `stack_spare` committed in `hos_commit_init` is given back for the 64 KB room once the 5 s are up, so this line, `hos_out_of_memory(1)` and then `report_crash` have a stack. For an error other than the commit limit there's no room to say anything, so it goes on to the crash report as on main.
@ -0,0 +22,4 @@
/* ---- stand-ins for what the cut code calls ---- */
#define GUEST_SPACE (1ull << 30)
static uint8_t *A64_MEM;
#define HOS_GUEST_SPACE GUEST_SPACE
Owner

The real hos_log takes 4.3 KB of stack, and this stand-in 512 bytes. With it, a handler that logs before it has room passes here and dies in the game. On top, the stand-in takes the real one's size.

The real `hos_log` takes 4.3 KB of stack, and this stand-in 512 bytes. With it, a handler that logs before it has room passes here and dies in the game. On top, the stand-in takes the real one's size.
@ -0,0 +54,4 @@
#include "stack_commit_handlers.inc"
}
/* ---- the case ---- */
Owner

With 16 KB frames the fault comes from a ___chkstk_ms probe up to 16 KB below the stack pointer, so the handler runs with plenty of committed stack above it. The game's faults are in ucrtbase.dll's small frames, with the stack pointer in the last committed page. On top, small cases (512-byte frames) for recovers and never.

With 16 KB frames the fault comes from a `___chkstk_ms` probe up to 16 KB below the stack pointer, so the handler runs with plenty of committed stack above it. The game's faults are in `ucrtbase.dll`'s small frames, with the stack pointer in the last committed page. On top, `small` cases (512-byte frames) for `recovers` and `never`.
Owner

Pushed three commits on top for the review above (test with 512-byte frames, the handler commits room before it logs plus a 1 MB spare, a help-page section). Not compiled on Windows here and no tests run here: CI and a Windows run need to confirm.

@Beanstalk Windows 10 and Windows 11, any GPU: with a small fixed page file (e.g. 2 GB on a 16 GB PC), load a save and teleport between Hyrule Field and the Market for a few minutes. Expect no 0xc00000fd crash; a "mem: a thread's stack grew at the commit limit after waiting" line means it recovered; if the PC stays out of memory, the out-of-memory notice shows before the game closes. Also a normal start on Windows AMD and Intel: play a minute, expect it to play and close as on main.

Pushed three commits on top for the review above (test with 512-byte frames, the handler commits room before it logs plus a 1 MB spare, a help-page section). Not compiled on Windows here and no tests run here: CI and a Windows run need to confirm. @Beanstalk Windows 10 and Windows 11, any GPU: with a small fixed page file (e.g. 2 GB on a 16 GB PC), load a save and teleport between Hyrule Field and the Market for a few minutes. Expect no 0xc00000fd crash; a "mem: a thread's stack grew at the commit limit after waiting" line means it recovered; if the PC stays out of memory, the out-of-memory notice shows before the game closes. Also a normal start on Windows AMD and Intel: play a minute, expect it to play and close as on main.
Member

Beanstalk test farm · ⛔ can't be tested as asked

Commit 3b1ad48 · approved by HumanBean (untrusted) · dashboard

Not run: the farm can't test this as asked, so nothing is built or run:

The requested Windows 10 and 11 commit-limit test requires a fixed small page file or a per-process commit limit, neither of which the farm can configure; it also cannot target Windows versions separately or verify the out-of-memory notice. The alternative can check normal Windows gameplay on AMD and Intel, but cannot establish stack recovery at the commit limit.

⚠️ Note: The recovery and persistent-out-of-memory branches cannot be reliably reached or judged without controlled memory pressure.
⚠️ Note: The farm cannot run the new standalone stack-commit fixture through a gameplay plan.

What it could test instead: The alternative plan loads a save and runs a minute of Hyrule Field gameplay on Windows AMD and Intel PCs, comparing main with the pull request. It takes about 12 minutes per tester and fails on a crash or a 15% increase in p99 frametime. No Intel tester is currently online, so that target will wait. No tester online now matches windows+intel: that target waits for one.

A member of BigBeans can comment @Beanstalk <new words> to ask for something else, or @Beanstalk test it anyway to run the plan regardless.

<!-- beanstalk:sticky --> ### Beanstalk test farm · ⛔ can't be tested as asked Commit `3b1ad48` · approved by HumanBean (untrusted) · [dashboard](https://beanstalk.magicbean.dev/prs/1885) **Not run: the farm can't test this as asked**, so nothing is built or run: > The requested Windows 10 and 11 commit-limit test requires a fixed small page file or a per-process commit limit, neither of which the farm can configure; it also cannot target Windows versions separately or verify the out-of-memory notice. The alternative can check normal Windows gameplay on AMD and Intel, but cannot establish stack recovery at the commit limit. ⚠️ **Note:** The recovery and persistent-out-of-memory branches cannot be reliably reached or judged without controlled memory pressure. ⚠️ **Note:** The farm cannot run the new standalone stack-commit fixture through a gameplay plan. What it could test instead: The alternative plan loads a save and runs a minute of Hyrule Field gameplay on Windows AMD and Intel PCs, comparing main with the pull request. It takes about 12 minutes per tester and fails on a crash or a 15% increase in p99 frametime. No Intel tester is currently online, so that target will wait. No tester online now matches windows+intel: that target waits for one. A member of `BigBeans` can comment `@Beanstalk <new words>` to ask for something else, or `@Beanstalk test it anyway` to run the plan regardless.
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 8s
PR description / Description follows the template (pull_request_target) Successful in 10s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 14s
CI / Workflow lint (actionlint) (pull_request) Successful in 14s
Third-party parts / As their notes say (pull_request) Successful in 16s
beanstalk/approval can't be tested as asked: see the farm's comment
CI / Website build and checks (pull_request) Failing after 2m35s
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
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 'fix/stack-commit-limit:d4nkn3ss-fix/stack-commit-limit'
git switch 'd4nkn3ss-fix/stack-commit-limit'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
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
MagicBeanDev/Longshot!1885
No description provided.