From fa893e0b22c71d538aa6052a9fc90afe2f6ee293 Mon Sep 17 00:00:00 2001 From: Mikio Hara Date: Fri, 31 Oct 2014 09:53:30 +0900 Subject: [PATCH] go.net/ipv6: simplify syscall shims This CL replaces syscall duplicates with tiny syscall shims to help to add new platform support, to improve existing platform support. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/166910043 --- ipv6/syscall_linux_386.go | 25 ++++--------- ipv6/syscall_linux_386.s | 56 ------------------------------ ipv6/syscall_nosplit4_linux_386.go | 15 -------- ipv6/syscall_nosplit7_linux_386.go | 15 -------- ipv6/syscall_unix.go | 4 +-- ipv6/thunk_linux_386.s | 8 +++++ 6 files changed, 17 insertions(+), 106 deletions(-) delete mode 100644 ipv6/syscall_linux_386.s delete mode 100644 ipv6/syscall_nosplit4_linux_386.go delete mode 100644 ipv6/syscall_nosplit7_linux_386.go create mode 100644 ipv6/thunk_linux_386.s diff --git a/ipv6/syscall_linux_386.go b/ipv6/syscall_linux_386.go index c062325e..82633a56 100644 --- a/ipv6/syscall_linux_386.go +++ b/ipv6/syscall_linux_386.go @@ -2,9 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// This code is a duplicate of syscall/syscall_linux_386.go with small -// modifications. - package ipv6 import ( @@ -12,30 +9,22 @@ import ( "unsafe" ) -// On x86 Linux, all the socket calls go through an extra indirection, -// I think because the 5-register system call interface can't handle -// the 6-argument calls like sendto and recvfrom. Instead the -// arguments to the underlying system call are the number below and a -// pointer to an array of uintptr. We hide the pointer in the -// socketcall assembly to avoid allocation on every system call. - const ( - // See /usr/include/linux/net.h. - _SETSOCKOPT = 14 - _GETSOCKOPT = 15 + sysGETSOCKOPT = 0xf + sysSETSOCKOPT = 0xe ) -var socketcall func(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno) +func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno) -func getsockopt(fd int, level int, name int, v unsafe.Pointer, l *sysSockoptLen) error { - if _, errno := socketcall(_GETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 { +func getsockopt(fd, level, name int, v unsafe.Pointer, l *sysSockoptLen) error { + if _, errno := socketcall(sysGETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 { return error(errno) } return nil } -func setsockopt(fd int, level int, name int, v unsafe.Pointer, l uintptr) error { - if _, errno := socketcall(_SETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 { +func setsockopt(fd, level, name int, v unsafe.Pointer, l sysSockoptLen) error { + if _, errno := socketcall(sysSETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 { return error(errno) } return nil diff --git a/ipv6/syscall_linux_386.s b/ipv6/syscall_linux_386.s deleted file mode 100644 index 34c0457f..00000000 --- a/ipv6/syscall_linux_386.s +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// This code is a duplicate of syscall/syscall_linux_386.s with small -// modifications. - -#define SYS_SOCKETCALL 102 // from zsysnum_linux_386.go - -// func socketcallnosplit7(call int, a0, a1, a2, a3, a4, a5 uintptr) (n int, errno int) -// Kernel interface gets call sub-number and pointer to a0 for Go 1.1. -TEXT ·socketcallnosplit7(SB),7,$0 - CALL runtime·entersyscall(SB) - MOVL $SYS_SOCKETCALL, AX // syscall entry - MOVL 4(SP), BX // socket call number - LEAL 8(SP), CX // pointer to call arguments - MOVL $0, DX - MOVL $0, SI - MOVL $0, DI - CALL *runtime·_vdso(SB) - CMPL AX, $0xfffff001 - JLS ok1 - MOVL $-1, 32(SP) // n - NEGL AX - MOVL AX, 36(SP) // errno - CALL runtime·exitsyscall(SB) - RET -ok1: - MOVL AX, 32(SP) // n - MOVL $0, 36(SP) // errno - CALL runtime·exitsyscall(SB) - RET - -// func socketcallnosplit4(call int, a0, a1, a2, a3, a4, a5 uintptr) (n int, errno int) -// Kernel interface gets call sub-number and pointer to a0 for Go 1.2. -TEXT ·socketcallnosplit4(SB),4,$0-40 - CALL runtime·entersyscall(SB) - MOVL $SYS_SOCKETCALL, AX // syscall entry - MOVL 4(SP), BX // socket call number - LEAL 8(SP), CX // pointer to call arguments - MOVL $0, DX - MOVL $0, SI - MOVL $0, DI - CALL *runtime·_vdso(SB) - CMPL AX, $0xfffff001 - JLS ok2 - MOVL $-1, 32(SP) // n - NEGL AX - MOVL AX, 36(SP) // errno - CALL runtime·exitsyscall(SB) - RET -ok2: - MOVL AX, 32(SP) // n - MOVL $0, 36(SP) // errno - CALL runtime·exitsyscall(SB) - RET diff --git a/ipv6/syscall_nosplit4_linux_386.go b/ipv6/syscall_nosplit4_linux_386.go deleted file mode 100644 index 6d4ac096..00000000 --- a/ipv6/syscall_nosplit4_linux_386.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build go1.2 - -package ipv6 - -import "syscall" - -func socketcallnosplit4(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno) - -func init() { - socketcall = socketcallnosplit4 -} diff --git a/ipv6/syscall_nosplit7_linux_386.go b/ipv6/syscall_nosplit7_linux_386.go deleted file mode 100644 index 2e4da7b5..00000000 --- a/ipv6/syscall_nosplit7_linux_386.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build go1.1,!go1.2 - -package ipv6 - -import "syscall" - -func socketcallnosplit7(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno) - -func init() { - socketcall = socketcallnosplit7 -} diff --git a/ipv6/syscall_unix.go b/ipv6/syscall_unix.go index a0e221d5..73b949ff 100644 --- a/ipv6/syscall_unix.go +++ b/ipv6/syscall_unix.go @@ -11,14 +11,14 @@ import ( "unsafe" ) -func getsockopt(fd int, level, name int, v unsafe.Pointer, l *sysSockoptLen) error { +func getsockopt(fd, level, name int, v unsafe.Pointer, l *sysSockoptLen) error { if _, _, errno := syscall.Syscall6(syscall.SYS_GETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 { return error(errno) } return nil } -func setsockopt(fd int, level int, name int, v unsafe.Pointer, l uintptr) error { +func setsockopt(fd, level, name int, v unsafe.Pointer, l sysSockoptLen) error { if _, _, errno := syscall.Syscall6(syscall.SYS_SETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 { return error(errno) } diff --git a/ipv6/thunk_linux_386.s b/ipv6/thunk_linux_386.s new file mode 100644 index 00000000..daa78bc0 --- /dev/null +++ b/ipv6/thunk_linux_386.s @@ -0,0 +1,8 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build go1.2 + +TEXT ·socketcall(SB),4,$0-36 + JMP syscall·socketcall(SB)