Commit cbdf9ade authored by Ben Shi's avatar Ben Shi Committed by Cherry Zhang

runtime: save/restore callee saved registers in arm64's sigtramp

ARM64's R19-R29 and F8-F15 are callee saved registers, which
should be saved in the beginning of sigtramp, and restored at
the end.

fixes #31827

Change-Id: I622e03f1a13fec969d3a11b6a303a8a492e02bcd
Reviewed-on: https://go-review.googlesource.com/c/go/+/177045
Run-TryBot: Ben Shi <powerman1st@163.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent 38c129b4
......@@ -5,15 +5,11 @@
package sanitizers_test
import (
"runtime"
"strings"
"testing"
)
func TestTSAN(t *testing.T) {
if runtime.GOARCH == "arm64" {
t.Skip("skipping test; see https://golang.org/issue/25682")
}
t.Parallel()
requireOvercommit(t)
config := configure("thread")
......
......@@ -41,7 +41,7 @@ TEXT runtime·read_trampoline(SB),NOSPLIT,$0
MOVD 8(R0), R1 // arg 2 buf
MOVW 16(R0), R2 // arg 3 count
MOVW 0(R0), R0 // arg 1 fd
BL libc_read(SB)
BL libc_read(SB)
RET
TEXT runtime·exit_trampoline(SB),NOSPLIT|NOFRAME,$0
......@@ -72,7 +72,7 @@ TEXT runtime·mmap_trampoline(SB),NOSPLIT,$0
MOVD $-1, R2
CMP R0, R2
BNE ok
BL libc_error(SB)
BL libc_error(SB)
MOVW (R0), R1
MOVD $0, R0
ok:
......@@ -84,8 +84,8 @@ TEXT runtime·munmap_trampoline(SB),NOSPLIT,$0
MOVD 8(R0), R1 // arg 2 len
MOVD 0(R0), R0 // arg 1 addr
BL libc_munmap(SB)
CMP $0, R0
BEQ 2(PC)
CMP $0, R0
BEQ 2(PC)
BL notok<>(SB)
RET
......@@ -145,22 +145,28 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
BL (R11)
RET
TEXT runtime·sigtramp(SB),NOSPLIT,$0
// Reserve space for callee-save registers and arguments.
SUB $(8*16), RSP
// Save callee-save registers.
MOVD R19, (8*4)(RSP)
MOVD R20, (8*5)(RSP)
MOVD R21, (8*6)(RSP)
MOVD R22, (8*7)(RSP)
MOVD R23, (8*8)(RSP)
MOVD R24, (8*9)(RSP)
MOVD R25, (8*10)(RSP)
MOVD R26, (8*11)(RSP)
MOVD R27, (8*12)(RSP)
MOVD g, (8*13)(RSP)
MOVD R29, (8*14)(RSP)
TEXT runtime·sigtramp(SB),NOSPLIT,$192
// Save callee-save registers in the case of signal forwarding.
// Please refer to https://golang.org/issue/31827 .
MOVD R19, 8*4(RSP)
MOVD R20, 8*5(RSP)
MOVD R21, 8*6(RSP)
MOVD R22, 8*7(RSP)
MOVD R23, 8*8(RSP)
MOVD R24, 8*9(RSP)
MOVD R25, 8*10(RSP)
MOVD R26, 8*11(RSP)
MOVD R27, 8*12(RSP)
MOVD g, 8*13(RSP)
MOVD R29, 8*14(RSP)
FMOVD F8, 8*15(RSP)
FMOVD F9, 8*16(RSP)
FMOVD F10, 8*17(RSP)
FMOVD F11, 8*18(RSP)
FMOVD F12, 8*19(RSP)
FMOVD F13, 8*20(RSP)
FMOVD F14, 8*21(RSP)
FMOVD F15, 8*22(RSP)
// Save arguments.
MOVW R0, (8*1)(RSP) // sig
......@@ -174,9 +180,9 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$0
BEQ 2(PC)
BL runtime·load_g(SB)
MOVD RSP, R6
CMP $0, g
BEQ nog
MOVD RSP, R6
CMP $0, g
BEQ nog
// iOS always use the main stack to run the signal handler.
// We need to switch to gsignal ourselves.
MOVD g_m(g), R11
......@@ -221,8 +227,14 @@ nog:
MOVD (8*12)(RSP), R27
MOVD (8*13)(RSP), g
MOVD (8*14)(RSP), R29
ADD $(8*16), RSP
FMOVD (8*15)(RSP), F8
FMOVD (8*16)(RSP), F9
FMOVD (8*17)(RSP), F10
FMOVD (8*18)(RSP), F11
FMOVD (8*19)(RSP), F12
FMOVD (8*20)(RSP), F13
FMOVD (8*21)(RSP), F14
FMOVD (8*22)(RSP), F15
RET
......@@ -234,7 +246,7 @@ TEXT runtime·sigprocmask_trampoline(SB),NOSPLIT,$0
MOVD 16(R0), R2 // arg 3 old
MOVW 0(R0), R0 // arg 1 how
BL libc_pthread_sigmask(SB)
CMP $0, R0
CMP $0, R0
BEQ 2(PC)
BL notok<>(SB)
RET
......@@ -279,7 +291,7 @@ TEXT runtime·kevent_trampoline(SB),NOSPLIT,$0
MOVD $-1, R2
CMP R0, R2
BNE ok
BL libc_error(SB)
BL libc_error(SB)
MOVW (R0), R0 // errno
NEG R0, R0 // caller wants it as a negative error code
ok:
......@@ -308,60 +320,60 @@ TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0
// mstart_stub is the first function executed on a new thread started by pthread_create.
// It just does some low-level setup and then calls mstart.
// Note: called with the C calling convention.
TEXT runtime·mstart_stub(SB),NOSPLIT,$0
TEXT runtime·mstart_stub(SB),NOSPLIT,$160
// R0 points to the m.
// We are already on m's g0 stack.
// Save callee-save registers.
SUB $144, RSP
MOVD R19, 0(RSP)
MOVD R20, 8(RSP)
MOVD R21, 16(RSP)
MOVD R22, 24(RSP)
MOVD R23, 32(RSP)
MOVD R24, 40(RSP)
MOVD R25, 48(RSP)
MOVD R26, 56(RSP)
MOVD R27, 64(RSP)
MOVD g, 72(RSP)
FMOVD F8, 80(RSP)
FMOVD F9, 88(RSP)
FMOVD F10, 96(RSP)
FMOVD F11, 104(RSP)
FMOVD F12, 112(RSP)
FMOVD F13, 120(RSP)
FMOVD F14, 128(RSP)
FMOVD F15, 136(RSP)
MOVD R19, 8(RSP)
MOVD R20, 16(RSP)
MOVD R21, 24(RSP)
MOVD R22, 32(RSP)
MOVD R23, 40(RSP)
MOVD R24, 48(RSP)
MOVD R25, 56(RSP)
MOVD R26, 64(RSP)
MOVD R27, 72(RSP)
MOVD g, 80(RSP)
MOVD R29, 88(RSP)
FMOVD F8, 96(RSP)
FMOVD F9, 104(RSP)
FMOVD F10, 112(RSP)
FMOVD F11, 120(RSP)
FMOVD F12, 128(RSP)
FMOVD F13, 136(RSP)
FMOVD F14, 144(RSP)
FMOVD F15, 152(RSP)
MOVD m_g0(R0), g
BL runtime·mstart(SB)
BL runtime·mstart(SB)
// Restore callee-save registers.
MOVD 0(RSP), R19
MOVD 8(RSP), R20
MOVD 16(RSP), R21
MOVD 24(RSP), R22
MOVD 32(RSP), R23
MOVD 40(RSP), R24
MOVD 48(RSP), R25
MOVD 56(RSP), R26
MOVD 64(RSP), R27
MOVD 72(RSP), g
FMOVD 80(RSP), F8
FMOVD 88(RSP), F9
FMOVD 96(RSP), F10
FMOVD 104(RSP), F11
FMOVD 112(RSP), F12
FMOVD 120(RSP), F13
FMOVD 128(RSP), F14
FMOVD 136(RSP), F15
ADD $144, RSP
MOVD 8(RSP), R19
MOVD 16(RSP), R20
MOVD 24(RSP), R21
MOVD 32(RSP), R22
MOVD 40(RSP), R23
MOVD 48(RSP), R24
MOVD 56(RSP), R25
MOVD 64(RSP), R26
MOVD 72(RSP), R27
MOVD 80(RSP), g
MOVD 88(RSP), R29
FMOVD 96(RSP), F8
FMOVD 104(RSP), F9
FMOVD 112(RSP), F10
FMOVD 120(RSP), F11
FMOVD 128(RSP), F12
FMOVD 136(RSP), F13
FMOVD 144(RSP), F14
FMOVD 152(RSP), F15
// Go is all done with this OS thread.
// Tell pthread everything is ok (we never join with this thread, so
// the value here doesn't really matter).
MOVD $0, R0
MOVD $0, R0
RET
......
......@@ -316,7 +316,29 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
BL (R11)
RET
TEXT runtime·sigtramp(SB),NOSPLIT,$24
TEXT runtime·sigtramp(SB),NOSPLIT,$192
// Save callee-save registers in the case of signal forwarding.
// Please refer to https://golang.org/issue/31827 .
MOVD R19, 8*4(RSP)
MOVD R20, 8*5(RSP)
MOVD R21, 8*6(RSP)
MOVD R22, 8*7(RSP)
MOVD R23, 8*8(RSP)
MOVD R24, 8*9(RSP)
MOVD R25, 8*10(RSP)
MOVD R26, 8*11(RSP)
MOVD R27, 8*12(RSP)
MOVD g, 8*13(RSP)
MOVD R29, 8*14(RSP)
FMOVD F8, 8*15(RSP)
FMOVD F9, 8*16(RSP)
FMOVD F10, 8*17(RSP)
FMOVD F11, 8*18(RSP)
FMOVD F12, 8*19(RSP)
FMOVD F13, 8*20(RSP)
FMOVD F14, 8*21(RSP)
FMOVD F15, 8*22(RSP)
// this might be called in external code context,
// where g is not set.
// first save R0, because runtime·load_g will clobber it
......@@ -330,6 +352,28 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$24
MOVD R2, 24(RSP)
MOVD $runtime·sigtrampgo(SB), R0
BL (R0)
// Restore callee-save registers.
MOVD 8*4(RSP), R19
MOVD 8*5(RSP), R20
MOVD 8*6(RSP), R21
MOVD 8*7(RSP), R22
MOVD 8*8(RSP), R23
MOVD 8*9(RSP), R24
MOVD 8*10(RSP), R25
MOVD 8*11(RSP), R26
MOVD 8*12(RSP), R27
MOVD 8*13(RSP), g
MOVD 8*14(RSP), R29
FMOVD 8*15(RSP), F8
FMOVD 8*16(RSP), F9
FMOVD 8*17(RSP), F10
FMOVD 8*18(RSP), F11
FMOVD 8*19(RSP), F12
FMOVD 8*20(RSP), F13
FMOVD 8*21(RSP), F14
FMOVD 8*22(RSP), F15
RET
TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
......
......@@ -276,7 +276,29 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
BL (R11)
RET
TEXT runtime·sigtramp(SB),NOSPLIT,$24
TEXT runtime·sigtramp(SB),NOSPLIT,$192
// Save callee-save registers in the case of signal forwarding.
// Please refer to https://golang.org/issue/31827 .
MOVD R19, 8*4(RSP)
MOVD R20, 8*5(RSP)
MOVD R21, 8*6(RSP)
MOVD R22, 8*7(RSP)
MOVD R23, 8*8(RSP)
MOVD R24, 8*9(RSP)
MOVD R25, 8*10(RSP)
MOVD R26, 8*11(RSP)
MOVD R27, 8*12(RSP)
MOVD g, 8*13(RSP)
MOVD R29, 8*14(RSP)
FMOVD F8, 8*15(RSP)
FMOVD F9, 8*16(RSP)
FMOVD F10, 8*17(RSP)
FMOVD F11, 8*18(RSP)
FMOVD F12, 8*19(RSP)
FMOVD F13, 8*20(RSP)
FMOVD F14, 8*21(RSP)
FMOVD F15, 8*22(RSP)
// this might be called in external code context,
// where g is not set.
// first save R0, because runtime·load_g will clobber it
......@@ -290,6 +312,28 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$24
MOVD R1, 16(RSP)
MOVD R2, 24(RSP)
BL runtime·sigtrampgo(SB)
// Restore callee-save registers.
MOVD 8*4(RSP), R19
MOVD 8*5(RSP), R20
MOVD 8*6(RSP), R21
MOVD 8*7(RSP), R22
MOVD 8*8(RSP), R23
MOVD 8*9(RSP), R24
MOVD 8*10(RSP), R25
MOVD 8*11(RSP), R26
MOVD 8*12(RSP), R27
MOVD 8*13(RSP), g
MOVD 8*14(RSP), R29
FMOVD 8*15(RSP), F8
FMOVD 8*16(RSP), F9
FMOVD 8*17(RSP), F10
FMOVD 8*18(RSP), F11
FMOVD 8*19(RSP), F12
FMOVD 8*20(RSP), F13
FMOVD 8*21(RSP), F14
FMOVD 8*22(RSP), F15
RET
TEXT runtime·mmap(SB),NOSPLIT,$0
......
......@@ -219,7 +219,29 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
BL (R11) // Alignment for ELF ABI?
RET
TEXT runtime·sigtramp(SB),NOSPLIT,$32
TEXT runtime·sigtramp(SB),NOSPLIT,$192
// Save callee-save registers in the case of signal forwarding.
// Please refer to https://golang.org/issue/31827 .
MOVD R19, 8*4(RSP)
MOVD R20, 8*5(RSP)
MOVD R21, 8*6(RSP)
MOVD R22, 8*7(RSP)
MOVD R23, 8*8(RSP)
MOVD R24, 8*9(RSP)
MOVD R25, 8*10(RSP)
MOVD R26, 8*11(RSP)
MOVD R27, 8*12(RSP)
MOVD g, 8*13(RSP)
MOVD R29, 8*14(RSP)
FMOVD F8, 8*15(RSP)
FMOVD F9, 8*16(RSP)
FMOVD F10, 8*17(RSP)
FMOVD F11, 8*18(RSP)
FMOVD F12, 8*19(RSP)
FMOVD F13, 8*20(RSP)
FMOVD F14, 8*21(RSP)
FMOVD F15, 8*22(RSP)
// If called from an external code context, g will not be set.
// Save R0, since runtime·load_g will clobber it.
MOVW R0, 8(RSP) // signum
......@@ -231,6 +253,28 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$32
MOVD R1, 16(RSP)
MOVD R2, 24(RSP)
BL runtime·sigtrampgo(SB)
// Restore callee-save registers.
MOVD 8*4(RSP), R19
MOVD 8*5(RSP), R20
MOVD 8*6(RSP), R21
MOVD 8*7(RSP), R22
MOVD 8*8(RSP), R23
MOVD 8*9(RSP), R24
MOVD 8*10(RSP), R25
MOVD 8*11(RSP), R26
MOVD 8*12(RSP), R27
MOVD 8*13(RSP), g
MOVD 8*14(RSP), R29
FMOVD 8*15(RSP), F8
FMOVD 8*16(RSP), F9
FMOVD 8*17(RSP), F10
FMOVD 8*18(RSP), F11
FMOVD 8*19(RSP), F12
FMOVD 8*20(RSP), F13
FMOVD 8*21(RSP), F14
FMOVD 8*22(RSP), F15
RET
// int32 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment