Skip to content

Commit d6b56bb

Browse files
committed
runtime: account for guard zone in Windows stack size
Windows includes an 8K guard in system-allocated thread stacks, which we currently don't account for when setting the g0 stack bounds. As a result, if we do overflow the g0 stack bounds, we'll get a STATUS_GUARD_PAGE_VIOLATION exception, which we're not expecting. Fix the g0 stack bounds to include a total of 16K of slop to account for this 8K guard. Updates #21382. Change-Id: Ia89b741b1413328e4681a237f5a7ee645531fe16 Reviewed-on: https://go-review.googlesource.com/122516 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Alex Brainman <[email protected]>
1 parent 7001ac5 commit d6b56bb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/runtime/os_windows.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,12 @@ func minit() {
698698
print("runtime: VirtualQuery failed; errno=", getlasterror(), "\n")
699699
throw("VirtualQuery for stack base failed")
700700
}
701-
// Add 8K of slop for calling C functions that don't have
702-
// stack checks. We shouldn't be anywhere near this bound
703-
// anyway.
704-
base := mbi.allocationBase + 8*1024
701+
// The system leaves an 8K PAGE_GUARD region at the bottom of
702+
// the stack (in theory VirtualQuery isn't supposed to include
703+
// that, but it does). Add an additional 8K of slop for
704+
// calling C functions that don't have stack checks. We
705+
// shouldn't be anywhere near this bound anyway.
706+
base := mbi.allocationBase + 16<<10
705707
// Sanity check the stack bounds.
706708
g0 := getg()
707709
if base > g0.stack.hi || g0.stack.hi-base > 64<<20 {

0 commit comments

Comments
 (0)