From bd580a0d10729553a7905481d17eed0436198866 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 27 Sep 2021 10:05:13 -0400 Subject: [PATCH] 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 Run-TryBot: Austin Clements TryBot-Result: Go Bot Reviewed-by: Cherry Mui Reviewed-by: Michael Pratt Reviewed-by: David Chase --- src/runtime/debug.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/runtime/debug.go b/src/runtime/debug.go index c343f430cc..2703a0ce01 100644 --- a/src/runtime/debug.go +++ b/src/runtime/debug.go @@ -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 + } +} -- 2.50.0