Skip to content

Windows: fiber stack-overflow diagnostic via VEH; un-skip #369 - #850

Merged
ropoctl merged 1 commit into
withlang-dev:mainfrom
ropoctl:windows-369-veh
Aug 19, 2026
Merged

ropoctl merged 1 commit into
withlang-dev:mainfrom
ropoctl:windows-369-veh

Conversation

@ropoctl

@ropoctl ropoctl commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Implements the Windows side of the fiber stack-overflow diagnostic and un-skips test/behavior/behav_async_stack_overflow.w.

Problem

The POSIX fiber core (rt/fiber_core_darwin.w) catches guard-page stack overflow with a SIGSEGV handler on a sigaltstack. Windows has no POSIX signals, so a guard-page fault surfaces as a Structured Exception — the existing rt_fiber_install_signal_handlers was a no-op stub and the guard page was never armed, so an overflowing fiber just crashed without the diagnostic. That is why #369 was skip-windows.

Fix (rt/windows_x86_64.w, rt/fiber_core_windows.w)

  • Arm the guard page. allocate_stack_region now calls VirtualProtect(region, page, PAGE_READWRITE | PAGE_GUARD). PAGE_GUARD raises STATUS_GUARD_PAGE_VIOLATION on first touch and auto-commits the page, giving the handler real stack to run on — the Windows analogue of the POSIX sigaltstack.
  • Register a vectored exception handler. rt_fiber_install_signal_handlers calls AddVectoredExceptionHandler. with_fiber_veh reads EXCEPTION_POINTERS, matches STATUS_GUARD_PAGE_VIOLATION / access-violation against the current fiber's guard region, prints fatal: fiber stack overflow (fiber #N) and exits 134 — matching the POSIX diagnostic text and the unified panic-exit convention (Valid program with passing asserts can abort with exit 134 while printf-based equivalent exits 0 #59).

Verification

Windows CI builds stage1→stage3 from source (the stage compilers embed this runtime) and runs build :test with the test un-skipped: behav_async_stack_overflow.w recurses on a 16 KiB fiber stack and asserts expect-exit: 134 / expect-stderr: fiber stack overflow.

Closes #369.

…er (withlang-dev#369)

The POSIX fiber core catches guard-page stack overflow with a SIGSEGV
handler on a sigaltstack. Windows has no POSIX signals, so a guard-page
fault surfaces as a Structured Exception. Bridge it:

- allocate_stack_region arms the guard page with PAGE_GUARD via
  VirtualProtect. PAGE_GUARD raises STATUS_GUARD_PAGE_VIOLATION on first
  touch and auto-commits the page, giving the handler stack room — the
  Windows analogue of the POSIX sigaltstack.
- rt_fiber_install_signal_handlers registers a vectored exception handler
  (AddVectoredExceptionHandler). with_fiber_veh reads EXCEPTION_POINTERS,
  matches STATUS_GUARD_PAGE_VIOLATION / access-violation against the
  current fiber's guard region, prints 'fatal: fiber stack overflow
  (fiber #N)' and exits 134 — matching the POSIX diagnostic and the
  unified panic-exit convention.

Un-skips test/behavior/behav_async_stack_overflow.w on Windows.
@ropoctl
ropoctl merged commit 0caeed0 into withlang-dev:main Aug 19, 2026
3 checks passed
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.

Windows async stack overflow handler does not produce controlled runtime diagnostic

1 participant