]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: don't re-raise ignored signal
authorCherry Mui <cherryyz@google.com>
Sat, 27 Apr 2024 01:47:19 +0000 (21:47 -0400)
committerCherry Mui <cherryyz@google.com>
Mon, 6 May 2024 21:13:43 +0000 (21:13 +0000)
If a signal lands on a non-Go thread, and Go code doesn't want to
handle it, currently we re-raise the signal in the signal handler
after uninstalling our handler, so the C code can handle it.

But if there is no C signal handler and the signal is ignored,
there is no need to re-raise the signal. Just ignore it. This
avoids uninstalling and reinstalling our handler, which, for some
reason, changes errno when TSAN is used. And TSAN does not like
errno being changed in the signal handler.

Not really sure if this is the bset of complete fix, but it does
fix the immediate problem, and it seems a reasonable thing to do
by itself.

Test case is CL 581722.

Fixes #66427.

Change-Id: I7a043d53059f1ff4080f4fc8ef4065d76ee7d78a
Reviewed-on: https://go-review.googlesource.com/c/go/+/582077
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/runtime/signal_unix.go

index 6ca87561e8ad01c54f30e04774e5729c7455a074..f115980c34fd3692e4b50662b4d3525c20332d2f 100644 (file)
@@ -953,10 +953,17 @@ func raisebadsignal(sig uint32, c *sigctxt) {
        }
 
        var handler uintptr
+       var flags int32
        if sig >= _NSIG {
                handler = _SIG_DFL
        } else {
                handler = atomic.Loaduintptr(&fwdSig[sig])
+               flags = sigtable[sig].flags
+       }
+
+       // If the signal is ignored, raising the signal is no-op.
+       if handler == _SIG_IGN || (handler == _SIG_DFL && flags&_SigIgn != 0) {
+               return
        }
 
        // Reset the signal handler and raise the signal.