diff options
| author | Ian Lance Taylor <iant@golang.org> | 2016-06-07 21:46:25 -0700 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2016-06-13 21:43:19 +0000 |
| commit | 84d8aff94cf48439047c7edc68ae2ea0aac6ddf5 (patch) | |
| tree | 0d7fd4e7b480ce2f9972646e9abe9463c3bc7a4d /src/runtime/sys_linux_amd64.s | |
| parent | 5701174c52a2d42621ec3c5c59dca3bde9a14bc6 (diff) | |
| download | go-84d8aff94cf48439047c7edc68ae2ea0aac6ddf5.tar.xz | |
runtime: collect stack trace if SIGPROF arrives on non-Go thread
Fixes #15994.
Change-Id: I5aca91ab53985ac7dcb07ce094ec15eb8ec341f8
Reviewed-on: https://go-review.googlesource.com/23891
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/sys_linux_amd64.s')
| -rw-r--r-- | src/runtime/sys_linux_amd64.s | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/runtime/sys_linux_amd64.s b/src/runtime/sys_linux_amd64.s index 031e412673..8a8f3cce8b 100644 --- a/src/runtime/sys_linux_amd64.s +++ b/src/runtime/sys_linux_amd64.s @@ -253,7 +253,7 @@ TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0 get_tls(CX) MOVQ g(CX),AX TESTQ AX, AX - JZ sigtramp // g == nil + JZ sigtrampnog // g == nil MOVQ g_m(AX), AX TESTQ AX, AX JZ sigtramp // g.m == nil @@ -276,8 +276,8 @@ TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0 // Jump to a function in runtime/cgo. // That function, written in C, will call the user's traceback // function with proper unwind info, and will then call back here. - // The first three arguments are already in registers. - // Set the last three arguments now. + // The first three arguments, and the fifth, are already in registers. + // Set the two remaining arguments now. MOVQ runtime·cgoTraceback(SB), CX MOVQ $runtime·sigtramp(SB), R9 MOVQ _cgo_callers(SB), AX @@ -286,6 +286,30 @@ TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0 sigtramp: JMP runtime·sigtramp(SB) +sigtrampnog: + // Signal arrived on a non-Go thread. If this is SIGPROF, get a + // stack trace. + CMPL DI, $27 // 27 == SIGPROF + JNZ sigtramp + + // Lock sigprofCallersUse. + MOVL $0, AX + MOVL $1, CX + MOVQ $runtime·sigprofCallersUse(SB), BX + LOCK + CMPXCHGL CX, 0(BX) + JNZ sigtramp // Skip stack trace if already locked. + + // Jump to the traceback function in runtime/cgo. + // It will call back to sigprofNonGo, which will ignore the + // arguments passed in registers. + // First three arguments to traceback function are in registers already. + MOVQ runtime·cgoTraceback(SB), CX + MOVQ $runtime·sigprofCallers(SB), R8 + MOVQ $runtime·sigprofNonGo(SB), R9 + MOVQ _cgo_callers(SB), AX + JMP AX + // For cgo unwinding to work, this function must look precisely like // the one in glibc. The glibc source code is: // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/x86_64/sigaction.c |
