]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make runtime.callers walk calling G, not g0
authorAustin Clements <austin@google.com>
Wed, 20 May 2015 15:50:48 +0000 (11:50 -0400)
committerAustin Clements <austin@google.com>
Thu, 21 May 2015 16:06:37 +0000 (16:06 +0000)
Currently runtime.callers invokes gentraceback with the pc and sp of
the G it is called from, but always passes g0 even if it was called
from a regular g. Right now this has no ill effects because
runtime.callers does not use either callback argument or the
_TraceJumpStack flag, but it makes the code fragile and will break
some upcoming changes.

Fix this by lifting the getg() call outside of the systemstack in
runtime.callers.

Change-Id: I4e1e927961c0e0cd4dcf28693be47df7bae9e122
Reviewed-on: https://go-review.googlesource.com/10292
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
Reviewed-by: Rick Hudson <rlh@golang.org>
src/runtime/traceback.go

index 12b2a536036805f224463bd5320bc65b7873f458..5ed601e6f3b8b9fa7f739cf60679e3cf666a4abd 100644 (file)
@@ -531,9 +531,10 @@ func traceback1(pc, sp, lr uintptr, gp *g, flags uint) {
 func callers(skip int, pcbuf []uintptr) int {
        sp := getcallersp(unsafe.Pointer(&skip))
        pc := uintptr(getcallerpc(unsafe.Pointer(&skip)))
+       gp := getg()
        var n int
        systemstack(func() {
-               n = gentraceback(pc, sp, 0, getg(), skip, &pcbuf[0], len(pcbuf), nil, nil, 0)
+               n = gentraceback(pc, sp, 0, gp, skip, &pcbuf[0], len(pcbuf), nil, nil, 0)
        })
        return n
 }