]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: save/restore callee-save registers in arm's sigtramp
authorBen Shi <powerman1st@163.com>
Tue, 25 Jun 2019 10:38:21 +0000 (10:38 +0000)
committerBen Shi <powerman1st@163.com>
Sat, 26 Oct 2019 04:00:03 +0000 (04:00 +0000)
ARM's R4-R8 & R10-R11 are callee-save registers, and R9
may be callee-save or not. This CL saves them at the beginning
of sigtramp and restores them in the end.

fixes #32738

Change-Id: Ib7eb80836bc074e2e6a46ae4602ba8a3b96c5456
Reviewed-on: https://go-review.googlesource.com/c/go/+/183777
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/runtime/sys_darwin_arm.s
src/runtime/sys_freebsd_arm.s
src/runtime/sys_linux_arm.s
src/runtime/sys_netbsd_arm.s
src/runtime/sys_openbsd_arm.s

index 4e201fca09746c9a6b1bdfd1fa86d33e123529a3..c08a29e7e074aaf461913b5aa319af6678102398 100644 (file)
@@ -182,14 +182,8 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
 
 TEXT runtime·sigtramp(SB),NOSPLIT,$0
        // Reserve space for callee-save registers and arguments.
-       SUB     $40, R13
-
-       MOVW    R4, 16(R13)
-       MOVW    R5, 20(R13)
-       MOVW    R6, 24(R13)
-       MOVW    R7, 28(R13)
-       MOVW    R8, 32(R13)
-       MOVW    R11, 36(R13)
+       MOVM.DB.W [R4-R11], (R13)
+       SUB     $16, R13
 
        // Save arguments.
        MOVW    R0, 4(R13)      // sig
@@ -238,14 +232,8 @@ nog:
        MOVW    R5, R13
 
        // Restore callee-save registers.
-       MOVW    16(R13), R4
-       MOVW    20(R13), R5
-       MOVW    24(R13), R6
-       MOVW    28(R13), R7
-       MOVW    32(R13), R8
-       MOVW    36(R13), R11
-
-       ADD     $40, R13
+       ADD     $16, R13
+       MOVM.IA.W (R13), [R4-R11]
 
        RET
 
index 8dcdbb56bdb70ac55c84a3bec9830d933f375bf7..1e12f9cfcb0815c4ca0213f691404079331fc496 100644 (file)
@@ -246,7 +246,11 @@ TEXT runtime·asmSigaction(SB),NOSPLIT|NOFRAME,$0
        MOVW    R0, ret+12(FP)
        RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$12
+TEXT runtime·sigtramp(SB),NOSPLIT,$0
+       // Reserve space for callee-save registers and arguments.
+       MOVM.DB.W [R4-R11], (R13)
+       SUB     $16, R13
+
        // this might be called in external code context,
        // where g is not set.
        // first save R0, because runtime·load_g will clobber it
@@ -258,6 +262,11 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$12
        MOVW    R1, 8(R13)
        MOVW    R2, 12(R13)
        BL      runtime·sigtrampgo(SB)
+
+       // Restore callee-save registers.
+       ADD     $16, R13
+       MOVM.IA.W (R13), [R4-R11]
+
        RET
 
 TEXT runtime·mmap(SB),NOSPLIT,$16
index a787440a1514c5f4d0c5a136f845a6d98958788e..9ef8c9258b8949b53581c34bf61216c66370bc15 100644 (file)
@@ -493,7 +493,11 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
        MOVW    R4, R13
        RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$12
+TEXT runtime·sigtramp(SB),NOSPLIT,$0
+       // Reserve space for callee-save registers and arguments.
+       MOVM.DB.W [R4-R11], (R13)
+       SUB     $16, R13
+
        // this might be called in external code context,
        // where g is not set.
        // first save R0, because runtime·load_g will clobber it
@@ -506,6 +510,11 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$12
        MOVW    R2, 12(R13)
        MOVW    $runtime·sigtrampgo(SB), R11
        BL      (R11)
+
+       // Restore callee-save registers.
+       ADD     $16, R13
+       MOVM.IA.W (R13), [R4-R11]
+
        RET
 
 TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
index 64428bee4db002cfb8aba54085d84214ce10f240..678dea57c6803f79b74f76ae2da4285ab3bc3f26 100644 (file)
@@ -300,7 +300,11 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
        MOVW    R4, R13
        RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$12
+TEXT runtime·sigtramp(SB),NOSPLIT,$0
+       // Reserve space for callee-save registers and arguments.
+       MOVM.DB.W [R4-R11], (R13)
+       SUB     $16, R13
+
        // this might be called in external code context,
        // where g is not set.
        // first save R0, because runtime·load_g will clobber it
@@ -312,6 +316,11 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$12
        MOVW    R1, 8(R13)
        MOVW    R2, 12(R13)
        BL      runtime·sigtrampgo(SB)
+
+       // Restore callee-save registers.
+       ADD     $16, R13
+       MOVM.IA.W (R13), [R4-R11]
+
        RET
 
 TEXT runtime·mmap(SB),NOSPLIT,$12
index 2177a7308c3326083c5ec979af25a7b476aad475..11f6e001000d206009d92d3aa71f0db91b10eca5 100644 (file)
@@ -247,7 +247,11 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
        MOVW    R4, R13
        RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$12
+TEXT runtime·sigtramp(SB),NOSPLIT,$0
+       // Reserve space for callee-save registers and arguments.
+       MOVM.DB.W [R4-R11], (R13)
+       SUB     $16, R13
+
        // If called from an external code context, g will not be set.
        // Save R0, since runtime·load_g will clobber it.
        MOVW    R0, 4(R13)              // signum
@@ -258,6 +262,11 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$12
        MOVW    R1, 8(R13)
        MOVW    R2, 12(R13)
        BL      runtime·sigtrampgo(SB)
+
+       // Restore callee-save registers.
+       ADD     $16, R13
+       MOVM.IA.W (R13), [R4-R11]
+
        RET
 
 // int32 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void));