Skip to content

Commit

Permalink
fixes golang#32912
Browse files Browse the repository at this point in the history
The crash occurs when go runtime calls a VDSO function (say
__vdso_clock_gettime) and a signal arrives to that thread.
Since VDSO functions temporarily destroy the G register (R10),
Go functions asynchronously executed in that thread (i.e. Go's signal
handler) can try to load data from the destroyed G, which causes
segmentation fault.
  • Loading branch information
nyuichi committed Sep 3, 2019
1 parent d0eaec7 commit 6ccc156
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/runtime/sys_linux_arm.s
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ TEXT runtime·walltime(SB),NOSPLIT,$0-12
MOVW (g_sched+gobuf_sp)(R0), R13 // Set SP to g0 stack

noswitch:
MOVW g, R0
MCR 15, 0, R0, C13, C0, 2

SUB $24, R13 // Space for results
BIC $0x7, R13 // Align for C code

Expand All @@ -247,6 +250,10 @@ noswitch:
B.EQ fallback

BL (R11)

MOVW $0, R0
MCR 15, 0, R0, C13, C0, 2

JMP finish

fallback:
Expand Down Expand Up @@ -288,6 +295,9 @@ TEXT runtime·nanotime(SB),NOSPLIT,$0-8
MOVW (g_sched+gobuf_sp)(R0), R13 // Set SP to g0 stack

noswitch:
MOVW g, R0
MCR 15, 0, R0, C13, C0, 2

SUB $24, R13 // Space for results
BIC $0x7, R13 // Align for C code

Expand All @@ -298,6 +308,10 @@ noswitch:
B.EQ fallback

BL (R11)

MOVW $0, R0
MCR 15, 0, R0, C13, C0, 2

JMP finish

fallback:
Expand Down Expand Up @@ -439,10 +453,21 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$12
// where g is not set.
// first save R0, because runtime·load_g will clobber it
MOVW R0, 4(R13)

MOVB runtime·iscgo(SB), R0
CMP $0, R0
BL.NE runtime·load_g(SB)
B.NE cgo

MRC 15, 0, R0, C13, C0, 2
CMP $0, R0
MOVW.NE R0, g
B gate

cgo:
BL runtime·load_g(SB)
B gate

gate:
MOVW R1, 8(R13)
MOVW R2, 12(R13)
MOVW $runtime·sigtrampgo(SB), R11
Expand Down

0 comments on commit 6ccc156

Please sign in to comment.