Commit d6b56bb3 authored by Austin Clements's avatar Austin Clements

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 <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarAlex Brainman <alex.brainman@gmail.com>
parent 7001ac53
...@@ -698,10 +698,12 @@ func minit() { ...@@ -698,10 +698,12 @@ func minit() {
print("runtime: VirtualQuery failed; errno=", getlasterror(), "\n") print("runtime: VirtualQuery failed; errno=", getlasterror(), "\n")
throw("VirtualQuery for stack base failed") throw("VirtualQuery for stack base failed")
} }
// Add 8K of slop for calling C functions that don't have // The system leaves an 8K PAGE_GUARD region at the bottom of
// stack checks. We shouldn't be anywhere near this bound // the stack (in theory VirtualQuery isn't supposed to include
// anyway. // that, but it does). Add an additional 8K of slop for
base := mbi.allocationBase + 8*1024 // calling C functions that don't have stack checks. We
// shouldn't be anywhere near this bound anyway.
base := mbi.allocationBase + 16<<10
// Sanity check the stack bounds. // Sanity check the stack bounds.
g0 := getg() g0 := getg()
if base > g0.stack.hi || g0.stack.hi-base > 64<<20 { if base > g0.stack.hi || g0.stack.hi-base > 64<<20 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment