Skip to content

omega: give Windows console programs the stack their frames need - #6318

Merged
Smotto merged 2 commits into
mainfrom
claude/project-thread-xijdvs
Nov 27, 2026
Merged

Smotto merged 2 commits into
mainfrom
claude/project-thread-xijdvs

Conversation

@Smotto

@Smotto Smotto commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Requested by Jarod · project thread

A Windows program that writes to the console now gets a stack big enough for
its checked frames. Before, a windows_x86_64 program with a local record
holding a 2 MB array compiled cleanly and then crashed with
STATUS_STACK_OVERFLOW (0xC00000FD). A console write is a host import, so the
program runs on the loader's stack, and every image reserved exactly 1 MiB of
it. Nothing compared the checked frames against that supply. The PE writer now
sets SizeOfStackReserve to the frames plus 64 KiB of headroom, rounded up to
64 KiB and never below 1 MiB, so the repro reserves 2 MiB and runs. No build
setting is involved. entry_roots.md says ordinary build files do not choose
stack size, so the compiler sizes the reserve from the WCSU it has already
checked.

On macOS the main thread gets a fixed 8 MiB whatever the image holds, so a
larger frame there is refused at build time with its call path:

hosted native entry: the stack frames on call path machine 1 -> machine 2 -> ... need 9000592 bytes, but the macos_arm64 loader stack supplies 8388608 bytes and keeps 65536 of them for loader and host-call frames; shrink the large locals on that path, because the build cannot choose a larger stack

Linux programs make no host imports. They already run on an owned BSS stack
sized to their demand, and a 12 MB frame runs there today.

NativeTarget::loader_stack_supply_bytes(frame_bytes) gives the supply. For
Windows it computes the reserve, and for Linux and macOS it returns the fixed
8 MiB default. plan_hosted_program_entry (stage 09) checks the frames against
that supply when it picks HostedEntryMode::LoaderStack. Image emission passes
the same reserve to emit_pe_executable. A shared component keeps 1 MiB. The
64 KiB headroom covers frames the checked demand cannot see: the loader's own,
the entry adapter, guard pages and the host imports'. StackDemand now
records peak_path, the internal calls whose frames set the ceiling. The
error shows machine numbers, as other native diagnostics do, because the
native pipeline does not carry source names.

The new loader_stack_supply test builds a windows_x86_64 program with a 2 MB
record and one with a 512 KB record. It checks that their images reserve 2 MiB
and 1 MiB. It also checks that a 9 MB record on macos_arm64 is refused with the
call-path message. A native-stack-demand unit test checks the peak path.

Gate: RC-NATIVE-MATRIX | hosted entries get a loader stack that fits their checked frames, or a refusal naming the call path
Spec: wiki/spec/build/entry_roots.md, wiki/spec/resources/storage.md#stack-demand-and-backing | the reserve comes from WCSU, not a build setting; insufficient fixed supply reports the call path
Proof: mbx test -p omega --test loader_stack_supply 2/2; -p native-stack-demand, -p entry-planning, -p target, -p image-pe, -p image-emission pass; 30 of the application tests that build for Windows fail in the cloud container, and none of their failures mention the loader stack | the Windows repro builds with a 2 MiB reserve

mbx xtask fmt --check --base origin/main is clean. mbx clippy --all-targets --no-deps -- -D warnings is clean on the five changed crates and the new test.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HqP8t5W646wL2ZiV2agFaj

Agent: Claude Code | Model: claude-opus-5-5 | Effort: medium | Tokens: 129.58M in (128.75M cached), 256.1k out | Steps: 586 | Time: 2h46m | Steers: 0

…f crashing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HqP8t5W646wL2ZiV2agFaj
@Smotto Smotto self-assigned this Nov 27, 2026
@Smotto Smotto changed the title omega: refuse Windows frames that overflow the loader stack instead of crashing omega: give Windows console programs the stack their frames need Nov 27, 2026
@Smotto
Smotto merged commit 10d0521 into main Nov 27, 2026
1 check passed
@Smotto
Smotto deleted the claude/project-thread-xijdvs branch November 27, 2026 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants