From c70864c53ab817e10209c149718bc59bafc73a89 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Sun, 19 Jul 2026 00:16:37 +0000 Subject: [PATCH] VM: skip preCommitStackMemory before stackPointerAtVMEntry is set on Windows On Windows, StackBounds reports the full stack reserve via GetCurrentThreadStackLimits. During VM construction m_stackPointerAtVMEntry is null, so updateStackLimits() computes the soft limit as stack.end() + softReservedZoneSize and preCommitStackMemory() then touches every page down to it, committing nearly the entire reserve. For embedders with a large main-thread reserve (Bun links /STACK:0x1200000 = 18MB) this forces ~18MB of commit charge at process start; when the host is commit-constrained the guard-page grow fails and the process dies with EXCEPTION_STACK_OVERFLOW (0xC00000FD) inside preCommitStackMemory. The pre-entry commit is unnecessary: LLInt/JIT code cannot run before the JSLock is acquired, and JSLock::didAcquireLock() calls setStackPointerAtVMEntry(), which re-runs updateStackLimits() with the maxPerThreadStackUsage cap applied. Gate preCommitStackMemory on m_stackPointerAtVMEntry so the commit is bounded by maxPerThreadStackUsage and only happens once the VM is actually entered. --- Source/JavaScriptCore/runtime/VM.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/JavaScriptCore/runtime/VM.cpp b/Source/JavaScriptCore/runtime/VM.cpp index 59e31e4c15561..69595a77e9f9c 100644 --- a/Source/JavaScriptCore/runtime/VM.cpp +++ b/Source/JavaScriptCore/runtime/VM.cpp @@ -1217,7 +1217,15 @@ void VM::updateStackLimits() // In contrast, we do not need to worry about VM::m_stackLimit because that limit is // used exclusively by C++ code, and the C++ compiler will automatically commit the // needed stack pages. - preCommitStackMemory(newSoftStackLimit); + // + // LLInt/JIT code cannot run before the VM has been entered, at which point + // setStackPointerAtVMEntry() recomputes the limit here against maxPerThreadStackUsage. + // Skipping the pre-entry commit avoids eagerly committing the entire stack reserve + // (StackBounds on Windows reports the full reserve via GetCurrentThreadStackLimits), + // which raises EXCEPTION_STACK_OVERFLOW on commit-constrained hosts when the reserve + // is large. + if (m_stackPointerAtVMEntry) + preCommitStackMemory(newSoftStackLimit); #endif } }