From d286e61b6787fe2b55bf0ec8a814962ebda8d202 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Mon, 15 Jun 2020 16:20:53 -0400 Subject: [PATCH] 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. May fix #39079. Change-Id: I59b2c5dc08c3c951f1098fff038bf2e06d7ca055 Reviewed-on: https://go-review.googlesource.com/c/go/+/238020 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/signal_unix.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go index 5aedbf7778..ba3e21ae2e 100644 --- a/src/runtime/signal_unix.go +++ b/src/runtime/signal_unix.go @@ -432,6 +432,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) @@ -439,8 +441,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) } -- 2.50.0