From 94d36fbc4acdbcff5d4d7ad3869f285294c4181c Mon Sep 17 00:00:00 2001 From: Nick Ripley Date: Mon, 3 Apr 2023 09:32:05 -0400 Subject: [PATCH] runtime: zero saved frame pointer when reusing goroutine stack on arm64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a goroutine stack is reused on arm64, the spot on the stack where the "caller's" frame pointer goes for the topmost frame should be explicitly zeroed. Otherwise, the frame pointer check in adjustframe with debugCheckBP enabled will fail on the topmost frame of a call stack the first time a reused stack is grown. Updates #39524, #58432 Change-Id: Ic1210dc005e3ecdbf9cd5d7b98846566e56df8f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/481636 Reviewed-by: Felix Geisendörfer Reviewed-by: Dmitri Shuralyov Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot Auto-Submit: Dmitri Shuralyov --- src/runtime/proc.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/runtime/proc.go b/src/runtime/proc.go index fafab7f58c..8fab6d46d1 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -4540,12 +4540,14 @@ func newproc1(fn *funcval, callergp *g, callerpc uintptr) *g { totalSize := uintptr(4*goarch.PtrSize + sys.MinFrameSize) // extra space in case of reads slightly beyond frame totalSize = alignUp(totalSize, sys.StackAlign) sp := newg.stack.hi - totalSize - spArg := sp if usesLR { // caller's LR *(*uintptr)(unsafe.Pointer(sp)) = 0 prepGoExitFrame(sp) - spArg += sys.MinFrameSize + } + if GOARCH == "arm64" { + // caller's FP + *(*uintptr)(unsafe.Pointer(sp - goarch.PtrSize)) = 0 } memclrNoHeapPointers(unsafe.Pointer(&newg.sched), unsafe.Sizeof(newg.sched))