aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2020-06-15 16:20:53 -0400
committerIan Lance Taylor <iant@golang.org>2020-10-15 18:53:06 +0000
commitfa44af7df1a96235fca2ec10c3129a4d2711ee28 (patch)
tree6189dc385a92c1a7056acec8842a3a8ade410823
parentb5a3989dac97270b89cfce250cbb42695647d5cb (diff)
downloadgo-fa44af7df1a96235fca2ec10c3129a4d2711ee28.tar.gz
go-fa44af7df1a96235fca2ec10c3129a4d2711ee28.zip
[release-branch.go1.14] runtime: set g to gsignal before adjustSignalStack
When a signal is received, the runtime probes whether an alternate signal stack is set, if so, adjust gsignal's stack to point to the alternate signal stack. This is done in adjustSignalStack, which calls sigaltstack "syscall", which is a libc call on darwin through asmcgocall. asmcgocall decides whether to do stack switch based on whether we're running on g0 stack, gsignal stack, or regular g stack. If g is not set to gsignal, asmcgocall may make wrong decision. Set g first. adjustSignalStack is recursively nosplit, so it is okay that temporarily gsignal.stack doesn't match the stack we're running on. Updates #39079. Fixes #41991. Change-Id: I59b2c5dc08c3c951f1098fff038bf2e06d7ca055 Reviewed-on: https://go-review.googlesource.com/c/go/+/238020 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> (cherry picked from commit d286e61b6787fe2b55bf0ec8a814962ebda8d202) Reviewed-on: https://go-review.googlesource.com/c/go/+/262557 Trust: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
-rw-r--r--src/runtime/signal_unix.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go
index f18e6b5785..dbac55c3d1 100644
--- a/src/runtime/signal_unix.go
+++ b/src/runtime/signal_unix.go
@@ -435,6 +435,8 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
return
}
+ setg(g.m.gsignal)
+
// If some non-Go code called sigaltstack, adjust.
var gsignalStack gsignalStack
setStack := adjustSignalStack(sig, g.m, &gsignalStack)
@@ -442,8 +444,6 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
g.m.gsignal.stktopsp = getcallersp()
}
- setg(g.m.gsignal)
-
if g.stackguard0 == stackFork {
signalDuringFork(sig)
}