Skip to content

Commit

Permalink
syscall: define Syscall6 in terms of RawSyscall6 on linux
Browse files Browse the repository at this point in the history
This is an exact copy of CL 388478 after fixing #52472 in CL 401654.

For #51087
For #52472

Change-Id: I6c6bd7ddcab1512c682e6b44f61c7bcde97f5c58
Reviewed-on: https://go-review.googlesource.com/c/go/+/401655
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
  • Loading branch information
prattmic committed Apr 22, 2022
1 parent 534a911 commit 808d40d
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 242 deletions.
26 changes: 0 additions & 26 deletions src/syscall/asm_linux_386.s
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,6 @@
// instead of the glibc-specific "CALL 0x10(GS)".
#define INVOKE_SYSCALL INT $0x80

// func Syscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr);
TEXT ·Syscall6(SB),NOSPLIT,$0-40
CALL runtime·entersyscall(SB)
MOVL trap+0(FP), AX // syscall entry
MOVL a1+4(FP), BX
MOVL a2+8(FP), CX
MOVL a3+12(FP), DX
MOVL a4+16(FP), SI
MOVL a5+20(FP), DI
MOVL a6+24(FP), BP
INVOKE_SYSCALL
CMPL AX, $0xfffff001
JLS ok6
MOVL $-1, r1+28(FP)
MOVL $0, r2+32(FP)
NEGL AX
MOVL AX, err+36(FP)
CALL runtime·exitsyscall(SB)
RET
ok6:
MOVL AX, r1+28(FP)
MOVL DX, r2+32(FP)
MOVL $0, err+36(FP)
CALL runtime·exitsyscall(SB)
RET

// func rawVforkSyscall(trap, a1 uintptr) (r1, err uintptr)
TEXT ·rawVforkSyscall(SB),NOSPLIT|NOFRAME,$0-16
MOVL trap+0(FP), AX // syscall entry
Expand Down
26 changes: 0 additions & 26 deletions src/syscall/asm_linux_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,6 @@

#define SYS_gettimeofday 96

// func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
TEXT ·Syscall6(SB),NOSPLIT,$0-80
CALL runtime·entersyscall<ABIInternal>(SB)
MOVQ a1+8(FP), DI
MOVQ a2+16(FP), SI
MOVQ a3+24(FP), DX
MOVQ a4+32(FP), R10
MOVQ a5+40(FP), R8
MOVQ a6+48(FP), R9
MOVQ trap+0(FP), AX // syscall entry
SYSCALL
CMPQ AX, $0xfffffffffffff001
JLS ok6
MOVQ $-1, r1+56(FP)
MOVQ $0, r2+64(FP)
NEGQ AX
MOVQ AX, err+72(FP)
CALL runtime·exitsyscall<ABIInternal>(SB)
RET
ok6:
MOVQ AX, r1+56(FP)
MOVQ DX, r2+64(FP)
MOVQ $0, err+72(FP)
CALL runtime·exitsyscall<ABIInternal>(SB)
RET

// func rawVforkSyscall(trap, a1 uintptr) (r1, err uintptr)
TEXT ·rawVforkSyscall(SB),NOSPLIT|NOFRAME,$0-32
MOVQ a1+8(FP), DI
Expand Down
31 changes: 0 additions & 31 deletions src/syscall/asm_linux_arm.s
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,6 @@
// System calls for arm, Linux
//

// func Syscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr);
// Actually Syscall5 but the rest of the code expects it to be named Syscall6.
TEXT ·Syscall6(SB),NOSPLIT,$0-40
BL runtime·entersyscall(SB)
MOVW trap+0(FP), R7 // syscall entry
MOVW a1+4(FP), R0
MOVW a2+8(FP), R1
MOVW a3+12(FP), R2
MOVW a4+16(FP), R3
MOVW a5+20(FP), R4
MOVW a6+24(FP), R5
SWI $0
MOVW $0xfffff001, R6
CMP R6, R0
BLS ok6
MOVW $-1, R1
MOVW R1, r1+28(FP)
MOVW $0, R2
MOVW R2, r2+32(FP)
RSB $0, R0, R0
MOVW R0, err+36(FP)
BL runtime·exitsyscall(SB)
RET
ok6:
MOVW R0, r1+28(FP)
MOVW R1, r2+32(FP)
MOVW $0, R0
MOVW R0, err+36(FP)
BL runtime·exitsyscall(SB)
RET

#define SYS__LLSEEK 140 /* from zsysnum_linux_arm.go */
// func seek(fd int, offset int64, whence int) (newoffset int64, errno int)
// Implemented in assembly to avoid allocation when
Expand Down
26 changes: 0 additions & 26 deletions src/syscall/asm_linux_arm64.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,6 @@

#include "textflag.h"

TEXT ·Syscall6(SB),NOSPLIT,$0-80
BL runtime·entersyscall<ABIInternal>(SB)
MOVD a1+8(FP), R0
MOVD a2+16(FP), R1
MOVD a3+24(FP), R2
MOVD a4+32(FP), R3
MOVD a5+40(FP), R4
MOVD a6+48(FP), R5
MOVD trap+0(FP), R8 // syscall entry
SVC
CMN $4095, R0
BCC ok
MOVD $-1, R4
MOVD R4, r1+56(FP) // r1
MOVD ZR, r2+64(FP) // r2
NEG R0, R0
MOVD R0, err+72(FP) // errno
BL runtime·exitsyscall<ABIInternal>(SB)
RET
ok:
MOVD R0, r1+56(FP) // r1
MOVD R1, r2+64(FP) // r2
MOVD ZR, err+72(FP) // errno
BL runtime·exitsyscall<ABIInternal>(SB)
RET

// func rawVforkSyscall(trap, a1 uintptr) (r1, err uintptr)
TEXT ·rawVforkSyscall(SB),NOSPLIT,$0-32
MOVD a1+8(FP), R0
Expand Down
24 changes: 0 additions & 24 deletions src/syscall/asm_linux_mips64x.s
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,6 @@
// System calls for mips64, Linux
//

TEXT ·Syscall6(SB),NOSPLIT,$0-80
JAL runtime·entersyscall(SB)
MOVV a1+8(FP), R4
MOVV a2+16(FP), R5
MOVV a3+24(FP), R6
MOVV a4+32(FP), R7
MOVV a5+40(FP), R8
MOVV a6+48(FP), R9
MOVV trap+0(FP), R2 // syscall entry
SYSCALL
BEQ R7, ok6
MOVV $-1, R1
MOVV R1, r1+56(FP) // r1
MOVV R0, r2+64(FP) // r2
MOVV R2, err+72(FP) // errno
JAL runtime·exitsyscall(SB)
RET
ok6:
MOVV R2, r1+56(FP) // r1
MOVV R3, r2+64(FP) // r2
MOVV R0, err+72(FP) // errno
JAL runtime·exitsyscall(SB)
RET

// func rawVforkSyscall(trap, a1 uintptr) (r1, err uintptr)
TEXT ·rawVforkSyscall(SB),NOSPLIT|NOFRAME,$0-32
MOVV a1+8(FP), R4
Expand Down
30 changes: 0 additions & 30 deletions src/syscall/asm_linux_mipsx.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,6 @@
// System calls for mips, Linux
//

// func Syscall6(trap trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr);
// 5th and 6th arg go at sp+16, sp+20.
// Note that frame size of 20 means that 24 bytes gets reserved on stack.
TEXT ·Syscall6(SB),NOSPLIT,$20-40
NO_LOCAL_POINTERS
JAL runtime·entersyscall(SB)
MOVW a1+4(FP), R4
MOVW a2+8(FP), R5
MOVW a3+12(FP), R6
MOVW a4+16(FP), R7
MOVW a5+20(FP), R8
MOVW a6+24(FP), R9
MOVW R8, 16(R29)
MOVW R9, 20(R29)
MOVW trap+0(FP), R2 // syscall entry
SYSCALL
BEQ R7, ok6
MOVW $-1, R1
MOVW R1, r1+28(FP) // r1
MOVW R0, r2+32(FP) // r2
MOVW R2, err+36(FP) // errno
JAL runtime·exitsyscall(SB)
RET
ok6:
MOVW R2, r1+28(FP) // r1
MOVW R3, r2+32(FP) // r2
MOVW R0, err+36(FP) // errno
JAL runtime·exitsyscall(SB)
RET

// func Syscall9(trap trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2, err uintptr);
// Actually Syscall8 but the rest of the code expects it to be named Syscall9.
TEXT ·Syscall9(SB),NOSPLIT,$28-52
Expand Down
24 changes: 0 additions & 24 deletions src/syscall/asm_linux_ppc64x.s
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,6 @@
// System calls for ppc64, Linux
//

TEXT ·Syscall6(SB),NOSPLIT,$0-80
BL runtime·entersyscall<ABIInternal>(SB)
MOVD a1+8(FP), R3
MOVD a2+16(FP), R4
MOVD a3+24(FP), R5
MOVD a4+32(FP), R6
MOVD a5+40(FP), R7
MOVD a6+48(FP), R8
MOVD trap+0(FP), R9 // syscall entry
SYSCALL R9
BVC ok6
MOVD $-1, R4
MOVD R4, r1+56(FP) // r1
MOVD R0, r2+64(FP) // r2
MOVD R3, err+72(FP) // errno
BL runtime·exitsyscall<ABIInternal>(SB)
RET
ok6:
MOVD R3, r1+56(FP) // r1
MOVD R0, r2+64(FP) // r2
MOVD R0, err+72(FP) // errno
BL runtime·exitsyscall<ABIInternal>(SB)
RET

// func rawVforkSyscall(trap, a1 uintptr) (r1, err uintptr)
TEXT ·rawVforkSyscall(SB),NOSPLIT|NOFRAME,$0-32
MOVD a1+8(FP), R3
Expand Down
27 changes: 0 additions & 27 deletions src/syscall/asm_linux_riscv64.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,6 @@
// System calls for riscv64, Linux
//

// func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
TEXT ·Syscall6(SB),NOSPLIT,$0-80
CALL runtime·entersyscall(SB)
MOV a1+8(FP), A0
MOV a2+16(FP), A1
MOV a3+24(FP), A2
MOV a4+32(FP), A3
MOV a5+40(FP), A4
MOV a6+48(FP), A5
MOV trap+0(FP), A7 // syscall entry
ECALL
MOV $-4096, T0
BLTU T0, A0, err
MOV A0, r1+56(FP) // r1
MOV A1, r2+64(FP) // r2
MOV ZERO, err+72(FP) // errno
CALL runtime·exitsyscall(SB)
RET
err:
MOV $-1, T0
MOV T0, r1+56(FP) // r1
MOV ZERO, r2+64(FP) // r2
SUB A0, ZERO, A0
MOV A0, err+72(FP) // errno
CALL runtime·exitsyscall(SB)
RET

// func rawVforkSyscall(trap, a1 uintptr) (r1, err uintptr)
TEXT ·rawVforkSyscall(SB),NOSPLIT|NOFRAME,$0-32
MOV a1+8(FP), A0
Expand Down
26 changes: 0 additions & 26 deletions src/syscall/asm_linux_s390x.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,6 @@
// System calls for s390x, Linux
//

// func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
TEXT ·Syscall6(SB),NOSPLIT,$0-80
BL runtime·entersyscall(SB)
MOVD a1+8(FP), R2
MOVD a2+16(FP), R3
MOVD a3+24(FP), R4
MOVD a4+32(FP), R5
MOVD a5+40(FP), R6
MOVD a6+48(FP), R7
MOVD trap+0(FP), R1 // syscall entry
SYSCALL
MOVD $0xfffffffffffff001, R8
CMPUBLT R2, R8, ok6
MOVD $-1, r1+56(FP)
MOVD $0, r2+64(FP)
NEG R2, R2
MOVD R2, err+72(FP) // errno
BL runtime·exitsyscall(SB)
RET
ok6:
MOVD R2, r1+56(FP)
MOVD R3, r2+64(FP)
MOVD $0, err+72(FP) // errno
BL runtime·exitsyscall(SB)
RET

// func rawVforkSyscall(trap, a1 uintptr) (r1, err uintptr)
TEXT ·rawVforkSyscall(SB),NOSPLIT|NOFRAME,$0-32
MOVD $0, R2
Expand Down
12 changes: 10 additions & 2 deletions src/syscall/syscall_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
"unsafe"
)

func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)

// N.B. RawSyscall6 is provided via linkname by runtime/internal/syscall.
//
// Errno is uintptr and thus compatible with the runtime/internal/syscall
Expand Down Expand Up @@ -80,6 +78,16 @@ func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
return
}

//go:uintptrkeepalive
//go:nosplit
//go:linkname Syscall6
func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
runtime_entersyscall()
r1, r2, err = RawSyscall6(trap, a1, a2, a3, a4, a5, a6)
runtime_exitsyscall()
return
}

func rawSyscallNoError(trap, a1, a2, a3 uintptr) (r1, r2 uintptr)

/*
Expand Down

0 comments on commit 808d40d

Please sign in to comment.