From 73d20f8186a091c8d7e81b621136770981cf8e44 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Sat, 16 Nov 2019 17:08:11 -0500 Subject: [PATCH] runtime: always use Go signal stack in non-cgo program When initializing an M, we set up its signal stack to the gsignal stack if an alternate signal stack is not already set. On Android, an alternate signal stack is always set, even cgo is not used. This breaks the logic of saving/fetching G on the signal stack during VDSO, which assumes the signal stack is allocated by Go if cgo is not used (if cgo is used, we use TLS for saving G). When cgo is not used, we can always use the Go signal stack, even if an alternate signal stack is already set. Since cgo is not used, no one other than the Go runtime will care. Fixes #35554. Change-Id: Ia9d84cd55cb35097f3df46f37996589c86f10e0f Reviewed-on: https://go-review.googlesource.com/c/go/+/207445 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/signal_unix.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go index f42de36acc2..756467f4dfc 100644 --- a/src/runtime/signal_unix.go +++ b/src/runtime/signal_unix.go @@ -1016,13 +1016,15 @@ func minitSignals() { // stack to the gsignal stack. If the alternate signal stack is set // for the thread (the case when a non-Go thread sets the alternate // signal stack and then calls a Go function) then set the gsignal -// stack to the alternate signal stack. Record which choice was made -// in newSigstack, so that it can be undone in unminit. +// stack to the alternate signal stack. We also set the alternate +// signal stack to the gsignal stack if cgo is not used (regardless +// of whether it is already set). Record which choice was made in +// newSigstack, so that it can be undone in unminit. func minitSignalStack() { _g_ := getg() var st stackt sigaltstack(nil, &st) - if st.ss_flags&_SS_DISABLE != 0 { + if st.ss_flags&_SS_DISABLE != 0 || !iscgo { signalstack(&_g_.m.gsignal.stack) _g_.m.newSigstack = true } else {