From: Austin Clements Date: Thu, 9 Feb 2023 19:40:05 +0000 (-0500) Subject: runtime: replace cgoCtxt slice with index in traceback X-Git-Tag: go1.21rc1~1321 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=86b69ef329c346fc6cc9b262e97bbdce7322288c;p=gostls13.git runtime: replace cgoCtxt slice with index in traceback Currently, gentraceback consumes the gp.cgoCtxt slice by copying the slice header and then sub-slicing it as it unwinds. The code for this is nice and clear, but we're about to lift this state into a structure and mutating it is going to introduce write barriers that are disallowed in gentraceback. This CL replaces the mutable slice header with an index into gp.cgoCtxt. For #54466. Change-Id: I6b701bb67d657290a784baaca34ed02d8247ede2 Reviewed-on: https://go-review.googlesource.com/c/go/+/466863 Run-TryBot: Austin Clements Reviewed-by: Michael Pratt TryBot-Result: Gopher Robot --- diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go index b4717ab164..17cd156f1d 100644 --- a/src/runtime/traceback.go +++ b/src/runtime/traceback.go @@ -76,7 +76,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in if usesLR { frame.lr = lr0 } - cgoCtxt := gp.cgoCtxt + cgoCtxt := len(gp.cgoCtxt) - 1 // Index into gp.cgoCtxt printing := pcbuf == nil && callback == nil // If the PC is zero, it's likely a nil function call. @@ -175,7 +175,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in flag = f.flag frame.lr = gp.sched.lr frame.sp = gp.sched.sp - cgoCtxt = gp.cgoCtxt + cgoCtxt = len(gp.cgoCtxt) - 1 case funcID_systemstack: // systemstack returns normally, so just follow the // stack transition. @@ -192,7 +192,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in } gp = gp.m.curg frame.sp = gp.sched.sp - cgoCtxt = gp.cgoCtxt + cgoCtxt = len(gp.cgoCtxt) - 1 flag &^= funcFlag_SPWRITE } } @@ -390,9 +390,9 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in } n++ - if f.funcID == funcID_cgocallback && len(cgoCtxt) > 0 { - ctxt := cgoCtxt[len(cgoCtxt)-1] - cgoCtxt = cgoCtxt[:len(cgoCtxt)-1] + if f.funcID == funcID_cgocallback && cgoCtxt >= 0 { + ctxt := gp.cgoCtxt[cgoCtxt] + cgoCtxt-- // skip only applies to Go frames. // callback != nil only used when we only care