diff options
author | Cherry Zhang <cherryyz@google.com> | 2019-10-31 10:32:31 -0400 |
---|---|---|
committer | Cherry Zhang <cherryyz@google.com> | 2019-11-05 18:58:41 +0000 |
commit | f07cbc7f88e5e15e41ec8b9c2b850d2179e0834e (patch) | |
tree | e49406289dc2b3e6f9f8cf3733d3f287f2f462da /src/runtime/sys_linux_arm.s | |
parent | fb05264fe1626c9d0b6d00d51e6c4d8d213d6dc7 (diff) | |
download | go-f07cbc7f88e5e15e41ec8b9c2b850d2179e0834e.tar.gz go-f07cbc7f88e5e15e41ec8b9c2b850d2179e0834e.zip |
runtime: don't fetch G from signal stack when using cgo
When using cgo, we save G to TLS, and when a signal happens, we
load G from TLS in sigtramp. This should give us a valid G. Don't
try to fetch from the signal stack. In particular, C code may
change the signal stack or call our signal handler directly (e.g.
TSAN), so we are not necessarily running on the original gsignal
stack where we saved G.
Also skip saving G on the signal stack when using cgo.
Updates #35249.
Change-Id: I40749ce6682709bd4ebfdfd9f23bd0f317fc197d
Reviewed-on: https://go-review.googlesource.com/c/go/+/204519
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/sys_linux_arm.s')
-rw-r--r-- | src/runtime/sys_linux_arm.s | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/runtime/sys_linux_arm.s b/src/runtime/sys_linux_arm.s index 9ef8c9258b..b8dc202d4c 100644 --- a/src/runtime/sys_linux_arm.s +++ b/src/runtime/sys_linux_arm.s @@ -277,21 +277,28 @@ noswitch: // during VDSO code we can find the g. // If we don't have a signal stack, we won't receive signal, // so don't bother saving g. + // When using cgo, we already saved g on TLS, also don't save + // g here. + MOVB runtime·iscgo(SB), R6 + CMP $0, R6 + BNE nosaveg MOVW m_gsignal(R5), R6 // g.m.gsignal CMP $0, R6 - BEQ 3(PC) + BEQ nosaveg MOVW (g_stack+stack_lo)(R6), R6 // g.m.gsignal.stack.lo MOVW g, (R6) BL (R11) - CMP $0, R6 // R6 is unchanged by C code - BEQ 3(PC) MOVW $0, R1 - MOVW R1, (R6) // clear g slot + MOVW R1, (R6) // clear g slot, R6 is unchanged by C code JMP finish +nosaveg: + BL (R11) + JMP finish + fallback: MOVW $SYS_clock_gettime, R7 SWI $0 @@ -344,21 +351,28 @@ noswitch: // during VDSO code we can find the g. // If we don't have a signal stack, we won't receive signal, // so don't bother saving g. + // When using cgo, we already saved g on TLS, also don't save + // g here. + MOVB runtime·iscgo(SB), R6 + CMP $0, R6 + BNE nosaveg MOVW m_gsignal(R5), R6 // g.m.gsignal CMP $0, R6 - BEQ 3(PC) + BEQ nosaveg MOVW (g_stack+stack_lo)(R6), R6 // g.m.gsignal.stack.lo MOVW g, (R6) BL (R11) - CMP $0, R6 // R6 is unchanged by C code - BEQ 3(PC) MOVW $0, R1 - MOVW R1, (R6) // clear g slot + MOVW R1, (R6) // clear g slot, R6 is unchanged by C code JMP finish +nosaveg: + BL (R11) + JMP finish + fallback: MOVW $SYS_clock_gettime, R7 SWI $0 |