aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/stack.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2021-04-02 15:57:46 -0400
committerAustin Clements <austin@google.com>2021-04-05 16:22:10 +0000
commitef3122e909f8c14a6bddcd77092d36710e16989f (patch)
tree14821c2316ac417faea039c055808e68860dbaed /src/runtime/stack.go
parentaf1789a61c02fa769fcd4ab8addcbb9a160b987b (diff)
downloadgo-ef3122e909f8c14a6bddcd77092d36710e16989f.tar.xz
cmd/internal/obj/x86: simplify huge frame prologue
For stack frames larger than StackBig, the stack split prologue needs to guard against potential wraparound. Currently, it carefully arranges to avoid underflow, but this is complicated and requires a special check for StackPreempt. StackPreempt is no longer the only stack poison value, so this check will incorrectly succeed if the stack bound is poisoned with any other value. This CL simplifies the logic of the check, reduces its length, and accounts for any possible poison value by directly checking for underflow. Change-Id: I917a313102d6a21895ef7c4b0f304fb84b292c81 Reviewed-on: https://go-review.googlesource.com/c/go/+/307010 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src/runtime/stack.go')
-rw-r--r--src/runtime/stack.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/runtime/stack.go b/src/runtime/stack.go
index cdccdcc2c5..babfdfccf0 100644
--- a/src/runtime/stack.go
+++ b/src/runtime/stack.go
@@ -92,6 +92,10 @@ const (
// The stack guard is a pointer this many bytes above the
// bottom of the stack.
+ //
+ // The guard leaves enough room for one _StackSmall frame plus
+ // a _StackLimit chain of NOSPLIT calls plus _StackSystem
+ // bytes for the OS.
_StackGuard = 928*sys.StackGuardMultiplier + _StackSystem
// After a stack split check the SP is allowed to be this
@@ -123,15 +127,16 @@ const (
const (
uintptrMask = 1<<(8*sys.PtrSize) - 1
+ // The values below can be stored to g.stackguard0 to force
+ // the next stack check to fail.
+ // These are all larger than any real SP.
+
// Goroutine preemption request.
- // Stored into g->stackguard0 to cause split stack check failure.
- // Must be greater than any real sp.
// 0xfffffade in hex.
stackPreempt = uintptrMask & -1314
- // Thread is forking.
- // Stored into g->stackguard0 to cause split stack check failure.
- // Must be greater than any real sp.
+ // Thread is forking. Causes a split stack check failure.
+ // 0xfffffb2e in hex.
stackFork = uintptrMask & -1234
// Force a stack movement. Used for debugging.