diff options
author | Russ Cox <rsc@golang.org> | 2021-01-27 11:00:21 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2021-02-19 00:01:52 +0000 |
commit | c80da0a33a240469892a0b0713f09607efb28752 (patch) | |
tree | 95560d4243b2e7940b24ee07660faad80e2bc790 | |
parent | a78879ac67d62c4919492fcb5e05c8b21058217d (diff) | |
download | go-git-c80da0a33a240469892a0b0713f09607efb28752.tar.gz |
runtime: handle nil gp in cpuprof
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>
-rw-r--r-- | src/runtime/cpuprof.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/runtime/cpuprof.go b/src/runtime/cpuprof.go index 9bfdfe7c74..e5d0193b9c 100644 --- a/src/runtime/cpuprof.go +++ b/src/runtime/cpuprof.go @@ -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) |