Skip to content

Commit

Permalink
syscall, runtime/internal/syscall: zero r2 before mips linux syscalls
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Rongronggg9 authored and mengzhuo committed Nov 24, 2022
1 parent 7a9ce74 commit 2c7c98c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/runtime/internal/syscall/asm_linux_mips64x.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ TEXT ·Syscall6(SB),NOSPLIT,$0-80
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
Expand Down
1 change: 1 addition & 0 deletions src/runtime/internal/syscall/asm_linux_mipsx.s
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ TEXT ·Syscall6(SB),NOSPLIT,$20-40
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
Expand Down
5 changes: 3 additions & 2 deletions src/syscall/asm_linux_mips64x.s
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ TEXT ·rawSyscallNoError(SB),NOSPLIT,$0-48
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
2 changes: 2 additions & 0 deletions src/syscall/asm_linux_mipsx.s
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ TEXT ·Syscall9(SB),NOSPLIT,$28-52
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
Expand Down Expand Up @@ -66,6 +67,7 @@ TEXT ·rawSyscallNoError(SB),NOSPLIT,$20-24
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
Expand Down

0 comments on commit 2c7c98c

Please sign in to comment.