syscall, runtime/internal/syscall: zero r2 before mips linux syscalls
All mips variant perform syscalls similarly. R2 (v0) holds r1 and R3
(v1) holds r2 of a syscall. The latter is only used by 2-ret syscalls.
A 1-ret syscall would not touch R3 but keeps it as is, making r2 be a
random value. Always reset it to 0 before SYSCALL to fix the issue.
Fixes #56426
Change-Id: Ie49965c0c3c224c4a895703ac659205cd040ff56
Reviewed-on: https://go-review.googlesource.com/c/go/+/452975
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
diff --git a/src/runtime/internal/syscall/asm_linux_mips64x.s b/src/runtime/internal/syscall/asm_linux_mips64x.s
index 0e88a2d..6b7c524 100644
--- a/src/runtime/internal/syscall/asm_linux_mips64x.s
+++ b/src/runtime/internal/syscall/asm_linux_mips64x.s
@@ -15,6 +15,7 @@
MOVV a4+32(FP), R7
MOVV a5+40(FP), R8
MOVV a6+48(FP), R9
+ MOVV R0, R3 // reset R3 to 0 as 1-ret SYSCALL keeps it
SYSCALL
BEQ R7, ok
MOVV $-1, R1
diff --git a/src/runtime/internal/syscall/asm_linux_mipsx.s b/src/runtime/internal/syscall/asm_linux_mipsx.s
index 050029e..561310f 100644
--- a/src/runtime/internal/syscall/asm_linux_mipsx.s
+++ b/src/runtime/internal/syscall/asm_linux_mipsx.s
@@ -20,6 +20,7 @@
MOVW a6+24(FP), R9
MOVW R8, 16(R29)
MOVW R9, 20(R29)
+ MOVW R0, R3 // reset R3 to 0 as 1-ret SYSCALL keeps it
SYSCALL
BEQ R7, ok
MOVW $-1, R1
diff --git a/src/syscall/asm_linux_mips64x.s b/src/syscall/asm_linux_mips64x.s
index ceafeb6..6c7a6bc 100644
--- a/src/syscall/asm_linux_mips64x.s
+++ b/src/syscall/asm_linux_mips64x.s
@@ -38,7 +38,8 @@
MOVV R0, R8
MOVV R0, R9
MOVV trap+0(FP), R2 // syscall entry
+ MOVV R0, R3 // reset R3 to zero as 1-ret SYSCALL keeps it
SYSCALL
- MOVV R2, r1+32(FP)
- MOVV R3, r2+40(FP)
+ MOVV R2, r1+32(FP) // r1
+ MOVV R3, r2+40(FP) // r2
RET
diff --git a/src/syscall/asm_linux_mipsx.s b/src/syscall/asm_linux_mipsx.s
index 3e5e8b1..99f0154 100644
--- a/src/syscall/asm_linux_mipsx.s
+++ b/src/syscall/asm_linux_mipsx.s
@@ -29,6 +29,7 @@
MOVW R10, 24(R29)
MOVW R11, 28(R29)
MOVW trap+0(FP), R2 // syscall entry
+ MOVW R0, R3 // reset R3 to zero as 1-ret SYSCALL keeps it
SYSCALL
BEQ R7, ok9
MOVW $-1, R1
@@ -66,6 +67,7 @@
MOVW a2+8(FP), R5
MOVW a3+12(FP), R6
MOVW trap+0(FP), R2 // syscall entry
+ MOVW R0, R3 // reset R3 to zero as 1-ret SYSCALL keeps it
SYSCALL
MOVW R2, r1+16(FP) // r1
MOVW R3, r2+20(FP) // r2