diff options
| author | Alan Donovan <adonovan@google.com> | 2012-09-04 14:40:49 -0400 |
|---|---|---|
| committer | Alan Donovan <adonovan@google.com> | 2012-09-04 14:40:49 -0400 |
| commit | 532dee3842298ad242355fd210efbd658cc93196 (patch) | |
| tree | 5207a9746d6d93e8deac4413d3b67aff4186efda /src/pkg/runtime/sys_linux_amd64.s | |
| parent | b2458ff75c75c9fafe1b5f4e0521d4949cd3754e (diff) | |
| download | go-532dee3842298ad242355fd210efbd658cc93196.tar.xz | |
runtime: discard SIGPROF delivered to non-Go threads.
Signal handlers are global resources but many language
environments (Go, C++ at Google, etc) assume they have sole
ownership of a particular handler. Signal handlers in
mixed-language applications must therefore be robust against
unexpected delivery of certain signals, such as SIGPROF.
The default Go signal handler runtime·sigtramp assumes that it
will never be called on a non-Go thread, but this assumption
is violated by when linking in C++ code that spawns threads.
Specifically, the handler asserts the thread has an associated
"m" (Go scheduler).
This CL is a very simple workaround: discard SIGPROF delivered to non-Go threads. runtime.badsignal(int32) now receives the signal number; if it returns without panicking (e.g. sig==SIGPROF) the signal is discarded.
I don't think there is any really satisfactory solution to the
problem of signal-based profiling in a mixed-language
application. It's not only the issue of handler clobbering,
but also that a C++ SIGPROF handler called in a Go thread
can't unwind the Go stack (and vice versa). The best we can
hope for is not crashing.
Note:
- I've ported this to all POSIX platforms, except ARM-linux which already ignores unexpected signals on m-less threads.
- I've avoided tail-calling runtime.badsignal because AFAICT the 6a/6l don't support it.
- I've avoided hoisting 'push sig' (common to both function calls) because it makes the code harder to read.
- Fixed an (apparently incorrect?) docstring.
R=iant, rsc, minux.ma
CC=golang-dev
https://golang.org/cl/6498057
Diffstat (limited to 'src/pkg/runtime/sys_linux_amd64.s')
| -rw-r--r-- | src/pkg/runtime/sys_linux_amd64.s | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/pkg/runtime/sys_linux_amd64.s b/src/pkg/runtime/sys_linux_amd64.s index e0ca6583c6..88810ff74a 100644 --- a/src/pkg/runtime/sys_linux_amd64.s +++ b/src/pkg/runtime/sys_linux_amd64.s @@ -157,8 +157,10 @@ TEXT runtime·sigtramp(SB),7,$64 // check that m exists MOVQ m(BX), BP CMPQ BP, $0 - JNE 2(PC) + JNE 4(PC) + MOVQ DI, 0(SP) CALL runtime·badsignal(SB) + RET // save g MOVQ g(BX), R10 |
