Skip to content

Commit bd580a0

Browse files
committed
runtime: add a maymorestack hook that moves the stack
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 <[email protected]> Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 35c7234 commit bd580a0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/runtime/debug.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,22 @@ func mayMoreStackPreempt() {
9595
g.stackguard0 = stackPreempt
9696
}
9797
}
98+
99+
// mayMoreStackMove is a maymorestack hook that forces stack movement
100+
// at every possible point.
101+
//
102+
// See mayMoreStackPreempt.
103+
//
104+
//go:nosplit
105+
//go:linkname mayMoreStackMove
106+
func mayMoreStackMove() {
107+
// Don't do anything on the g0 or gsignal stack.
108+
g := getg()
109+
if g == g.m.g0 || g == g.m.gsignal {
110+
return
111+
}
112+
// Force stack movement, unless the stack is already poisoned.
113+
if g.stackguard0 < stackPoisonMin {
114+
g.stackguard0 = stackForceMove
115+
}
116+
}

0 commit comments

Comments
 (0)