Skip to content

Windows async stack overflow handler does not produce controlled runtime diagnostic #369

Closed

Description

@ehartford

Summary

Fix Windows async stack overflow so it produces the same controlled runtime diagnostic as Darwin/Linux instead of a raw Windows exception. The current test is intentionally skipped on Windows after GitHub comment 2026-06-09T21:49:06Z, but the skip is only a paper-over until the async backend migration can provide a real Windows-safe stack overflow path.

Spec

§14.2 says each fiber has a real stack. §14.19 says fiber stacks have guard-page overflow detection where the platform supports it, and stack overflow must be diagnosed by the runtime rather than escaping as undefined process failure. The behavior fixture expects:

exit 134
stderr contains "fiber stack overflow"

Current state

test/behavior/behav_async_stack_overflow.w still encodes the desired behavior with //! expect-exit: 134 and //! expect-stderr: fiber stack overflow, but now has //! skip-windows for issue #369 (test/behavior/behav_async_stack_overflow.w:1). The original issue records native Windows failure as exit code -1073741819 and explains that a VirtualProtect(PAGE_NOACCESS) / VEH attempt could not run because the exception handler uses the exhausted current stack.

The fiber cores are platform-specific. Windows has a fixed FIBER_STACK_SIZE and FIBER_ALT_STACK_SIZE (rt/fiber_core_windows.w:26, rt/fiber_core_windows.w:61), installs stack overflow handlers through rt_fiber_install_signal_handlers (rt/fiber_core_windows.w:453), and records current-fiber stack metadata (rt/fiber_core_windows.w:437). Darwin has the parallel substrate (rt/fiber_core_darwin.w:27, rt/fiber_core_darwin.w:454). The async backend migration plan explicitly calls for replacing direct fiber_core_* calls with a backend interface in docs/async-proposal.md.

Implementation plan

  1. Implement this as part of the async backend split in docs/async-proposal.md, not as another local VEH patch. Add a Windows backend abstraction that can detect guard-page stack overflow on a usable handler stack.
  2. In rt/fiber_core_windows.w, separate stack allocation/protection from scheduler bookkeeping so the backend can install either fibers/ucontext-equivalent guard handling or a Windows-specific trampoline with a known-safe emergency stack.
  3. Preserve the existing runtime diagnostic surface: route the detected overflow to the same path that emits fiber stack overflow and exits 134 on non-Windows.
  4. Remove the //! skip-windows directive from test/behavior/behav_async_stack_overflow.w only after native Windows produces the controlled diagnostic.
  5. Do not solve this by increasing FIBER_STACK_SIZE, increasing the compiler executable stack reserve, or accepting Windows raw exception codes. Those are symptom workarounds.
  6. Document the Windows backend behavior in docs/async-proposal.md or the runtime source comments so future guard-page changes do not reintroduce current-stack VEH assumptions.

Test plan

Run with test test/behavior/behav_async_stack_overflow.w on native Windows and non-Windows hosts.

Add a Windows-specific regression note in the fixture once the skip is removed, keeping //! expect-exit: 134 and //! expect-stderr: fiber stack overflow.

Run the existing Windows async cancellation tests, especially test/behavior/behav_async_cancel.w, test/behavior/behav_async_cancel_nested_unwind.w, and test/behavior/behav_async_cancel_await_cleans_children.w.

Acceptance criteria

  • Native Windows no longer skips test/behavior/behav_async_stack_overflow.w.
  • Stack overflow exits 134 and stderr contains fiber stack overflow.
  • Normal fiber stack size and compiler stack reserve are not increased as a workaround.
  • Existing async cancellation and panic tests remain green.
  • with build && with build :fixpoint && with build :test pass on the affected platforms.

Dependencies

Depends on the async backend migration in docs/async-proposal.md.

Activity

  1. ehartford commented on Jun 9, 2026

    @ehartford
    ContributorAuthor

    Temporary paper-over landed in 768af7e: the test runner now supports a narrow //! skip-windows:\ directive, and only \ est/behavior/behav_async_stack_overflow.w\ uses it. The test still keeps \expect-exit: 134\ and \expect-stderr: fiber stack overflow\ for non-Windows platforms. This keeps #369 open for the real fix via the async backend migration in \docs/async-proposal.md; it does not accept raw Windows \

  2. added this to the post-v0.16.0 milestone on Jul 16, 2026
  3. ehartford commented on Jul 16, 2026

    @ehartford
    ContributorAuthor

    Blocked on #676 (minicoro fiber-backend migration, per docs/feature_plans/async-proposal.md): the Windows async stack-overflow diagnostic should be implemented against minicoro's Windows backend, not the current Darwin-only backend. Both are milestone post-v0.16.0.

  4. ropoctl commented on Aug 17, 2026

    @ropoctl
    Collaborator

    Root cause pinned (native Windows x86_64), so a future implementer has the exact entry point.

    The diagnostic path itself exists: rt/fiber_core_windows.w:462 with_fiber_stack_overflow_handler checks the fault address against the fiber's guard page and writes "fatal: fiber stack overflow (fiber #...". It is registered at fiber_core_windows.w:481 via rt_fiber_install_signal_handlers(...).

    The gap: that install hook is a no-op stub on Windows. rt/windows_x86_64.w:384:

    pub unsafe fn rt_fiber_install_signal_handlers(alt_stack: *mut u8, alt_stack_size: i64, handler: i64) -> Unit:
        let _ = alt_stack
        let _ = alt_stack_size
        let _ = handler
    

    The handler is modeled on POSIX signals (sig: i32, fault addr from a ucontext), copied from fiber_core_darwin.w. Windows delivers a guard-page fault as an SEH exception (STATUS_GUARD_PAGE_VIOLATION / EXCEPTION_ACCESS_VIOLATION 0xC0000005), not a signal — so with nothing installed, a fiber overflow crashes via the default unhandled-exception path. Neither the diagnostic nor the exit-134 convention is produced, which is exactly what test/behavior/behav_async_stack_overflow.w asserts (expect-stderr: fiber stack overflow, expect-exit: 134).

    Secondary: allocate_stack_region (fiber_core_windows.w:363) rt_mmaps page_sz + size and returns region + page_sz, but never VirtualProtects the reserved guard page to PAGE_NOACCESS/PAGE_GUARD, so the guard isn't armed on Windows either.

    Fix outline (own scoped task; isolated batch + drop-audit + native VM verify):

    1. VirtualProtect the guard page PAGE_NOACCESS (or PAGE_GUARD) in allocate_stack_region.
    2. Implement rt_fiber_install_signal_handlers on Windows via AddVectoredExceptionHandler.
    3. In the VEH, read EXCEPTION_POINTERS → fault address, match it against the faulting fiber's guard page, write the diagnostic, exit 134.

    The behavior test stays skip-windows under this issue until (1)-(3) land — the skip is a genuine feature gap, not a stale gate.

  5. added 2 commits that reference this issue on Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions