]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: replace cgoCtxt slice with index in traceback
authorAustin Clements <austin@google.com>
Thu, 9 Feb 2023 19:40:05 +0000 (14:40 -0500)
committerAustin Clements <austin@google.com>
Fri, 10 Mar 2023 17:59:27 +0000 (17:59 +0000)
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 <austin@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/runtime/traceback.go

index b4717ab164bd14299291fa4927724c174658e186..17cd156f1d13f57afaa2997ccee2b83cb8a26f6d 100644 (file)
@@ -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