From 352d329c44d99b5c6cb325940006ca52f88195f3 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 9 Apr 2021 16:08:28 -0400 Subject: [PATCH] runtime: move zero-sized frame check from newproc to newproc1 If GOEXPERIMENT=regabidefer is enabled, newproc currently checks that the call frame for new goroutines is empty. But there's one place in the runtime (debugCallWrap), where we call newproc1, and it happens to pass a non-empty frame. The current check didn't catch that. Move the empty call frame check from newproc to newproc1 to catch this. Updates #40724. Change-Id: I9998faf1e07e7b7af88e06a8177127f998c40252 Reviewed-on: https://go-review.googlesource.com/c/go/+/309034 Trust: Austin Clements Run-TryBot: Austin Clements TryBot-Result: Go Bot Reviewed-by: Than McIntosh Reviewed-by: Cherry Zhang Reviewed-by: Michael Knyszek --- src/runtime/debug_test.go | 8 ++++++-- src/runtime/proc.go | 14 ++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/runtime/debug_test.go b/src/runtime/debug_test.go index c4c41f95f2d..7f9e460303f 100644 --- a/src/runtime/debug_test.go +++ b/src/runtime/debug_test.go @@ -9,8 +9,12 @@ // spends all of its time in the race runtime, which isn't a safe // point. -//go:build amd64 && linux && !race -// +build amd64,linux,!race +// TODO(register args): We skip this under GOEXPERIMENT=regabidefer +// because debugCallWrap passes a non-empty frame to newproc1, +// triggering a panic. + +//go:build amd64 && linux && !race && !goexperiment.regabidefer +// +build amd64,linux,!race,!goexperiment.regabidefer package runtime_test diff --git a/src/runtime/proc.go b/src/runtime/proc.go index d545a143a03..6c1c5dd9175 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -4020,12 +4020,6 @@ func malg(stacksize int32) *g { // //go:nosplit func newproc(siz int32, fn *funcval) { - if goexperiment.RegabiDefer && siz != 0 { - // TODO: When we commit to GOEXPERIMENT=regabidefer, - // rewrite newproc's comment, since it will no longer - // have a funny stack layout or need to be nosplit. - throw("go with non-empty frame") - } argp := add(unsafe.Pointer(&fn), sys.PtrSize) gp := getg() pc := getcallerpc() @@ -4051,6 +4045,14 @@ func newproc(siz int32, fn *funcval) { // //go:systemstack func newproc1(fn *funcval, argp unsafe.Pointer, narg int32, callergp *g, callerpc uintptr) *g { + if goexperiment.RegabiDefer && narg != 0 { + // TODO: When we commit to GOEXPERIMENT=regabidefer, + // rewrite the comments for newproc and newproc1. + // newproc will no longer have a funny stack layout or + // need to be nosplit. + throw("go with non-empty frame") + } + _g_ := getg() if fn == nil {