]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add a maymorestack hook that moves the stack
authorAustin Clements <austin@google.com>
Mon, 27 Sep 2021 14:05:13 +0000 (10:05 -0400)
committerAustin Clements <austin@google.com>
Fri, 5 Nov 2021 00:52:09 +0000 (00:52 +0000)
This adds a maymorestack hook that moves the stack at every
cooperative preemption point.

For #48297.

Change-Id: Ic15f9bcbc163345e6422586302d57fda4744caec
Reviewed-on: https://go-review.googlesource.com/c/go/+/359797
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: David Chase <drchase@google.com>
src/runtime/debug.go

index c343f430cc3c9f20e6b01817fede54bb6867ada6..2703a0ce019d3f41f88caefd1fe95b0ff0e1a222 100644 (file)
@@ -95,3 +95,22 @@ func mayMoreStackPreempt() {
                g.stackguard0 = stackPreempt
        }
 }
+
+// mayMoreStackMove is a maymorestack hook that forces stack movement
+// at every possible point.
+//
+// See mayMoreStackPreempt.
+//
+//go:nosplit
+//go:linkname mayMoreStackMove
+func mayMoreStackMove() {
+       // Don't do anything on the g0 or gsignal stack.
+       g := getg()
+       if g == g.m.g0 || g == g.m.gsignal {
+               return
+       }
+       // Force stack movement, unless the stack is already poisoned.
+       if g.stackguard0 < stackPoisonMin {
+               g.stackguard0 = stackForceMove
+       }
+}