Skip to content

Commit 6ccc156

Browse files
committed
fixes #32912
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.
1 parent d0eaec7 commit 6ccc156

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/runtime/sys_linux_arm.s

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ TEXT runtime·walltime(SB),NOSPLIT,$0-12
237237
MOVW (g_sched+gobuf_sp)(R0), R13 // Set SP to g0 stack
238238

239239
noswitch:
240+
MOVW g, R0
241+
MCR 15, 0, R0, C13, C0, 2
242+
240243
SUB $24, R13 // Space for results
241244
BIC $0x7, R13 // Align for C code
242245

@@ -247,6 +250,10 @@ noswitch:
247250
B.EQ fallback
248251

249252
BL (R11)
253+
254+
MOVW $0, R0
255+
MCR 15, 0, R0, C13, C0, 2
256+
250257
JMP finish
251258

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

290297
noswitch:
298+
MOVW g, R0
299+
MCR 15, 0, R0, C13, C0, 2
300+
291301
SUB $24, R13 // Space for results
292302
BIC $0x7, R13 // Align for C code
293303

@@ -298,6 +308,10 @@ noswitch:
298308
B.EQ fallback
299309

300310
BL (R11)
311+
312+
MOVW $0, R0
313+
MCR 15, 0, R0, C13, C0, 2
314+
301315
JMP finish
302316

303317
fallback:
@@ -439,10 +453,21 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$12
439453
// where g is not set.
440454
// first save R0, because runtime·load_g will clobber it
441455
MOVW R0, 4(R13)
456+
442457
MOVB runtime·iscgo(SB), R0
443458
CMP $0, R0
444-
BL.NE runtime·load_g(SB)
459+
B.NE cgo
460+
461+
MRC 15, 0, R0, C13, C0, 2
462+
CMP $0, R0
463+
MOVW.NE R0, g
464+
B gate
465+
466+
cgo:
467+
BL runtime·load_g(SB)
468+
B gate
445469

470+
gate:
446471
MOVW R1, 8(R13)
447472
MOVW R2, 12(R13)
448473
MOVW $runtime·sigtrampgo(SB), R11

0 commit comments

Comments
 (0)