Skip to content

Commit fa44af7

Browse files
cherrymuiianlancetaylor
authored andcommitted
[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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> (cherry picked from commit d286e61) Reviewed-on: https://go-review.googlesource.com/c/go/+/262557 Trust: Cherry Zhang <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Austin Clements <[email protected]>
1 parent b5a3989 commit fa44af7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/runtime/signal_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,15 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
435435
return
436436
}
437437

438+
setg(g.m.gsignal)
439+
438440
// If some non-Go code called sigaltstack, adjust.
439441
var gsignalStack gsignalStack
440442
setStack := adjustSignalStack(sig, g.m, &gsignalStack)
441443
if setStack {
442444
g.m.gsignal.stktopsp = getcallersp()
443445
}
444446

445-
setg(g.m.gsignal)
446-
447447
if g.stackguard0 == stackFork {
448448
signalDuringFork(sig)
449449
}

0 commit comments

Comments
 (0)