aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/signal_unix.go
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2019-10-31 10:32:31 -0400
committerCherry Zhang <cherryyz@google.com>2019-11-05 18:58:41 +0000
commitf07cbc7f88e5e15e41ec8b9c2b850d2179e0834e (patch)
treee49406289dc2b3e6f9f8cf3733d3f287f2f462da /src/runtime/signal_unix.go
parentfb05264fe1626c9d0b6d00d51e6c4d8d213d6dc7 (diff)
downloadgo-f07cbc7f88e5e15e41ec8b9c2b850d2179e0834e.tar.gz
go-f07cbc7f88e5e15e41ec8b9c2b850d2179e0834e.zip
runtime: don't fetch G from signal stack when using cgo
When using cgo, we save G to TLS, and when a signal happens, we load G from TLS in sigtramp. This should give us a valid G. Don't try to fetch from the signal stack. In particular, C code may change the signal stack or call our signal handler directly (e.g. TSAN), so we are not necessarily running on the original gsignal stack where we saved G. Also skip saving G on the signal stack when using cgo. Updates #35249. Change-Id: I40749ce6682709bd4ebfdfd9f23bd0f317fc197d Reviewed-on: https://go-review.googlesource.com/c/go/+/204519 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/signal_unix.go')
-rw-r--r--src/runtime/signal_unix.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go
index 6563186392..fab8574d1c 100644
--- a/src/runtime/signal_unix.go
+++ b/src/runtime/signal_unix.go
@@ -360,9 +360,11 @@ func preemptM(mp *m) {
func sigFetchG(c *sigctxt) *g {
switch GOARCH {
case "arm", "arm64":
- if inVDSOPage(c.sigpc()) {
- // Before making a VDSO call we save the g to the bottom of the
- // signal stack. Fetch from there.
+ if !iscgo && inVDSOPage(c.sigpc()) {
+ // When using cgo, we save the g on TLS and load it from there
+ // in sigtramp. Just use that.
+ // Otherwise, before making a VDSO call we save the g to the
+ // bottom of the signal stack. Fetch from there.
// TODO: in efence mode, stack is sysAlloc'd, so this wouldn't
// work.
sp := getcallersp()