]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime: handle nil gp in cpuprof
authorRuss Cox <rsc@golang.org>
Wed, 27 Jan 2021 16:00:21 +0000 (11:00 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 19 Feb 2021 00:01:52 +0000 (00:01 +0000)
This can happen on Windows when recording profile samples for system threads.

This CL is part of a stack adding windows/arm64
support (#36439), intended to land in the Go 1.17 cycle.
This CL is, however, not windows/arm64-specific.
It is cleanup meant to make the port (and future ports) easier.

Change-Id: I5a7ba32b1900a69f3b7acada9cb6cf8396d8a03f
Reviewed-on: https://go-review.googlesource.com/c/go/+/288797
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/cpuprof.go

index 9bfdfe7c7461a76fef305bd79c63ef71f5c56b62..e5d0193b9cbd4f5c10fc9ca0cac49464658ddec3 100644 (file)
@@ -103,7 +103,16 @@ func (p *cpuProfile) add(gp *g, stk []uintptr) {
                // because otherwise its write barrier behavior may not
                // be correct. See the long comment there before
                // changing the argument here.
-               cpuprof.log.write(&gp.labels, nanotime(), hdr[:], stk)
+               //
+               // Note: it can happen on Windows, where we are calling
+               // p.add with a gp that is not the current g, that gp is nil,
+               // meaning we interrupted a system thread with no g.
+               // Avoid faulting in that case.
+               var tagPtr *unsafe.Pointer
+               if gp != nil {
+                       tagPtr = &gp.labels
+               }
+               cpuprof.log.write(tagPtr, nanotime(), hdr[:], stk)
        }
 
        atomic.Store(&prof.signalLock, 0)