Skip to content

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

Merged
ehartford merged 1 commit into
fix-compiler-main-source-budgetfrom
fix-369-fiber-stack-overflow
Sep 1, 2026
Merged

ehartford merged 1 commit into
fix-compiler-main-source-budgetfrom
fix-369-fiber-stack-overflow

Conversation

@ropoctl

@ropoctl ropoctl commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

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 those fields 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.

Changes

  • 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 frame larger than one page on a fiber, which forces __chkstk to probe against the fiber's stack bounds; returns normally on a correct backend. Portable and unremarkable off Windows.

Both verified on a native Windows x64 host (overflow → exit 134 + diagnostic; large-frame → exit 0), and the large-frame test is also green natively on Linux.

@ropoctl
ropoctl force-pushed the fix-369-fiber-stack-overflow branch from f512012 to 43e1d99 Compare August 31, 2026 15:38
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.
@ropoctl
ropoctl force-pushed the fix-369-fiber-stack-overflow branch from 43e1d99 to a86bed5 Compare August 31, 2026 18:58
@ropoctl
ropoctl changed the base branch from main to fix-compiler-main-source-budget August 31, 2026 18:58
@ehartford
ehartford merged commit a720cdc into fix-compiler-main-source-budget Sep 1, 2026
5 checks passed
@ehartford
ehartford deleted the fix-369-fiber-stack-overflow branch September 24, 2026 16:56
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