diff options
| author | Elias Naur <elias.naur@gmail.com> | 2015-05-18 11:00:24 +0200 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2015-05-22 20:24:08 +0000 |
| commit | 84cfba17c2451f1a94ea7d812c1aba91e3606890 (patch) | |
| tree | e855e322892572d2ac2c465a95ad961ec0864156 /src/runtime/runtime2.go | |
| parent | 994b2d46455509f95d60f0abd0d37d3d789f89f2 (diff) | |
| download | go-84cfba17c2451f1a94ea7d812c1aba91e3606890.tar.xz | |
runtime: don't always unblock all signals
Ian proposed an improved way of handling signals masks in Go, motivated
by a problem where the Android java runtime expects certain signals to
be blocked for all JVM threads. Discussion here
https://groups.google.com/forum/#!topic/golang-dev/_TSCkQHJt6g
Ian's text is used in the following:
A Go program always needs to have the synchronous signals enabled.
These are the signals for which _SigPanic is set in sigtable, namely
SIGSEGV, SIGBUS, SIGFPE.
A Go program that uses the os/signal package, and calls signal.Notify,
needs to have at least one thread which is not blocking that signal,
but it doesn't matter much which one.
Unix programs do not change signal mask across execve. They inherit
signal masks across fork. The shell uses this fact to some extent;
for example, the job control signals (SIGTTIN, SIGTTOU, SIGTSTP) are
blocked for commands run due to backquote quoting or $().
Our current position on signal masks was not thought out. We wandered
into step by step, e.g., http://golang.org/cl/7323067 .
This CL does the following:
Introduce a new platform hook, msigsave, that saves the signal mask of
the current thread to m.sigsave.
Call msigsave from needm and newm.
In minit grab set up the signal mask from m.sigsave and unblock the
essential synchronous signals, and SIGILL, SIGTRAP, SIGPROF, SIGSTKFLT
(for systems that have it).
In unminit, restore the signal mask from m.sigsave.
The first time that os/signal.Notify is called, start a new thread whose
only purpose is to update its signal mask to make sure signals for
signal.Notify are unblocked on at least one thread.
The effect on Go programs will be that if they are invoked with some
non-synchronous signals blocked, those signals will normally be
ignored. Previously, those signals would mostly be ignored. A change
in behaviour will occur for programs started with any of these signals
blocked, if they receive the signal: SIGHUP, SIGINT, SIGQUIT, SIGABRT,
SIGTERM. Previously those signals would always cause a crash (unless
using the os/signal package); with this change, they will be ignored
if the program is started with the signal blocked (and does not use
the os/signal package).
./all.bash completes successfully on linux/amd64.
OpenBSD is missing the implementation.
Change-Id: I188098ba7eb85eae4c14861269cc466f2aa40e8c
Reviewed-on: https://go-review.googlesource.com/10173
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/runtime2.go')
| -rw-r--r-- | src/runtime/runtime2.go | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index 83d8062baf..3ee5d5d29d 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -266,6 +266,7 @@ type m struct { // Fields not known to debuggers. procid uint64 // for debuggers, but offset not hard-coded gsignal *g // signal-handling g + sigmask [4]uintptr // storage for saved signal mask tls [4]uintptr // thread-local storage (for x86 extern register) mstartfn func() curg *g // current running goroutine @@ -469,15 +470,16 @@ type sigtabtt struct { } const ( - _SigNotify = 1 << 0 // let signal.Notify have signal, even if from kernel - _SigKill = 1 << 1 // if signal.Notify doesn't take it, exit quietly - _SigThrow = 1 << 2 // if signal.Notify doesn't take it, exit loudly - _SigPanic = 1 << 3 // if the signal is from the kernel, panic - _SigDefault = 1 << 4 // if the signal isn't explicitly requested, don't monitor it - _SigHandling = 1 << 5 // our signal handler is registered - _SigIgnored = 1 << 6 // the signal was ignored before we registered for it - _SigGoExit = 1 << 7 // cause all runtime procs to exit (only used on Plan 9). - _SigSetStack = 1 << 8 // add SA_ONSTACK to libc handler + _SigNotify = 1 << iota // let signal.Notify have signal, even if from kernel + _SigKill // if signal.Notify doesn't take it, exit quietly + _SigThrow // if signal.Notify doesn't take it, exit loudly + _SigPanic // if the signal is from the kernel, panic + _SigDefault // if the signal isn't explicitly requested, don't monitor it + _SigHandling // our signal handler is registered + _SigIgnored // the signal was ignored before we registered for it + _SigGoExit // cause all runtime procs to exit (only used on Plan 9). + _SigSetStack // add SA_ONSTACK to libc handler + _SigUnblock // unblocked in minit ) // Layout of in-memory per-function information prepared by linker |
