Skip to content

Windows: fiber stack-overflow diagnostic + un-skip its test (#369) - #917

Merged
ehartford merged 1 commit into
mainfrom
reland-fiber-369
Sep 1, 2026
Merged

ehartford merged 1 commit into
mainfrom
reland-fiber-369

Conversation

@ropoctl

@ropoctl ropoctl commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Re-lands the #369 Windows fiber stack-overflow diagnostic on current main.

The original PR #907 was merged into the interim stacking base branch fix-compiler-main-source-budget (now stale — based on pre-rfc4648 main), so the change never reached main. This is the same commit rebased onto current main (31f77937); the interim CRLF-budget fix commit drops out by patch-id (already in main via #910).

Windows-x86_64 only: adds VEH-based headroom below the fiber guard page so a stack overflow on a small fiber stack raises the fiber stack overflow diagnostic (exit 134), plus a large-frame regression test, and un-skips behav_async_stack_overflow.

On Windows x64 a running fiber must own the thread's stack description.
The NT_TIB fields in the TEB (StackBase, StackLimit, DeallocationStack,
FiberData) describe the OS thread stack; while a fiber runs on its own
mmap'd stack they are stale. Everything that consults them is then wrong
on a fiber: __chkstk probes (any frame over one page), and SEH/VEH
dispatch. A guard-page fault on the fiber stack degraded to an unhandled
access violation before the vectored handler could attribute it, so the
"fiber stack overflow" diagnostic never printed.

runtime/fiber_asm_windows_x86_64.s: the context switch now saves the four
NT_TIB stack fields into the outgoing context and installs the incoming
context's fields into the TEB, so the OS sees the fiber's real bounds.
Initial-context setup seeds those fields for the first switch in.

rt/fiber_core_windows.w: reserve committed headroom below the guard page.
Windows has no sigaltstack; the vectored handler runs on the faulting
fiber stack, so it needs room beneath the guard to produce the
diagnostic and exit 134.

Tests:
- behav_async_stack_overflow.w: un-skipped on Windows; deep recursion on
  a small fiber stack now reports "fiber stack overflow" and exits 134.
- behav_async_fiber_large_frame.w (new): a single >1-page frame on a
  fiber, which forces __chkstk to probe against the fiber's stack bounds;
  returns normally on a correct backend. Portable; unremarkable off
  Windows.

Both verified on a native Windows x64 host.
@ehartford
ehartford merged commit da63fff into main Sep 1, 2026
5 checks passed
@ehartford
ehartford deleted the reland-fiber-369 branch September 24, 2026 16:57
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