diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-02-03 15:53:53 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-02-05 00:06:37 +0000 |
commit | f770366f6d910e4bf92a6f885908afe134d65b23 (patch) | |
tree | ea9a422e604d3fdfe8a3e32fbb479b938df1e000 /src/runtime/signal_unix.go | |
parent | e3f2e9ac4e1ab99e1ebd0bf2a6bd3898633873b1 (diff) | |
download | go-f770366f6d910e4bf92a6f885908afe134d65b23.tar.gz go-f770366f6d910e4bf92a6f885908afe134d65b23.zip |
runtime: don't treat SIGURG as a bad signal
It's possible for the scheduler to try to preempt a goroutine running
on a thread created by C code just as the goroutine returns from Go code
to C code. If that happens, the goroutine will have a nil g,
which would normally cause us to enter the badsignal code.
The badsignal code will allocate an M, reset the signal handler,
and raise the signal. This is all wasted work for SIGURG,
as the default behavior is for the kernel to ignore the signal.
It also means that there is a period of time when preemption requests
are ignored, because the signal handler is reset to the default.
And, finally, it triggers a bug on 386 OpenBSD 6.2. So stop doing it.
No test because there is no real change in behavior (other than on OpenBSD),
the new code is just more efficient
Fixes #36996
Change-Id: I8c1cb9bc09f5ef890cab567924417e2423fc71f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/217617
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/signal_unix.go')
-rw-r--r-- | src/runtime/signal_unix.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go index 3861cace08..d2e6693805 100644 --- a/src/runtime/signal_unix.go +++ b/src/runtime/signal_unix.go @@ -412,6 +412,16 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) { sigprofNonGoPC(c.sigpc()) return } + if sig == sigPreempt && preemptMSupported && debug.asyncpreemptoff == 0 { + // This is probably a signal from preemptM sent + // while executing Go code but received while + // executing non-Go code. + // We got past sigfwdgo, so we know that there is + // no non-Go signal handler for sigPreempt. + // The default behavior for sigPreempt is to ignore + // the signal, so badsignal will be a no-op anyway. + return + } c.fixsigcode(sig) badsignal(uintptr(sig), c) return |