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_arm.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_arm.s')
| -rw-r--r-- | src/pkg/runtime/sys_linux_arm.s | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/pkg/runtime/sys_linux_arm.s b/src/pkg/runtime/sys_linux_arm.s index 0112cf9158..38bcebfa1a 100644 --- a/src/pkg/runtime/sys_linux_arm.s +++ b/src/pkg/runtime/sys_linux_arm.s @@ -296,7 +296,8 @@ TEXT runtime·sigaltstack(SB),7,$0 TEXT runtime·sigtramp(SB),7,$24 // this might be called in external code context, // where g and m are not set. - // first save R0, becuase cgo_load_gm will clobber it + // first save R0, because cgo_load_gm will clobber it + // TODO(adonovan): call runtime·badsignal if m=0, like other platforms? MOVW R0, 4(R13) MOVW cgo_load_gm(SB), R0 CMP $0, R0 |
