aboutsummaryrefslogtreecommitdiff
path: root/libgo
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2017-09-20 17:40:11 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2017-09-20 17:40:11 +0000
commit5e525857e9a7390d9a90de91618b133ab6051a9d (patch)
treed50a8f6f9050d90b84b0a3479b6a9d687202e5e6 /libgo
parente18f68c715a58aa7dc267357ff4e957e9bfc3ff6 (diff)
downloadgcc-5e525857e9a7390d9a90de91618b133ab6051a9d.zip
gcc-5e525857e9a7390d9a90de91618b133ab6051a9d.tar.gz
gcc-5e525857e9a7390d9a90de91618b133ab6051a9d.tar.bz2
syscall: workaround for getsockname bug in AIX
Reviewed-on: https://go-review.googlesource.com/64552 From-SVN: r253021
Diffstat (limited to 'libgo')
-rw-r--r--libgo/go/syscall/socket_aix.go89
-rw-r--r--libgo/go/syscall/socket_bsd.go2
-rw-r--r--libgo/go/syscall/syscall_aix_ppc.go49
-rw-r--r--libgo/go/syscall/syscall_aix_ppc64.go49
4 files changed, 188 insertions, 1 deletions
diff --git a/libgo/go/syscall/socket_aix.go b/libgo/go/syscall/socket_aix.go
new file mode 100644
index 0000000..40cf423
--- /dev/null
+++ b/libgo/go/syscall/socket_aix.go
@@ -0,0 +1,89 @@
+// socket_aix.go -- Socket handling specific to AIX.
+
+// Copyright 2017 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.
+
+package syscall
+
+import "unsafe"
+
+const SizeofSockaddrInet4 = 16
+const SizeofSockaddrInet6 = 28
+const SizeofSockaddrUnix = 1025
+
+type RawSockaddrInet4 struct {
+ Len uint8
+ Family uint8
+ Port uint16
+ Addr [4]byte /* in_addr */
+ Zero [8]uint8
+}
+
+func (sa *RawSockaddrInet4) setLen() Socklen_t {
+ sa.Len = SizeofSockaddrInet4
+ return SizeofSockaddrInet4
+}
+
+type RawSockaddrInet6 struct {
+ Len uint8
+ Family uint8
+ Port uint16
+ Flowinfo uint32
+ Addr [16]byte /* in6_addr */
+ Scope_id uint32
+}
+
+func (sa *RawSockaddrInet6) setLen() Socklen_t {
+ sa.Len = SizeofSockaddrInet6
+ return SizeofSockaddrInet6
+}
+
+type RawSockaddrUnix struct {
+ Len uint8
+ Family uint8
+ Path [1023]int8
+}
+
+func (sa *RawSockaddrUnix) setLen(n int) {
+ sa.Len = uint8(3 + n) // 2 for Family, Len; 1 for NUL.
+}
+
+func (sa *RawSockaddrUnix) getLen() (int, error) {
+ // Some versions of AIX have a bug in getsockname (see IV78655).
+ // We can't rely on sa.Len being set correctly.
+ n := SizeofSockaddrUnix - 3 // substract leading Family, Len, terminating NUL.
+ for i := 0; i < n; i++ {
+ if sa.Path[i] == 0 {
+ n = i
+ break
+ }
+ }
+ return n, nil
+}
+
+func (sa *RawSockaddrUnix) adjustAbstract(sl Socklen_t) Socklen_t {
+ return sl
+}
+
+type RawSockaddr struct {
+ Len uint8
+ Family uint8
+ Data [14]int8
+}
+
+// BindToDevice binds the socket associated with fd to device.
+func BindToDevice(fd int, device string) (err error) {
+ return ENOSYS
+}
+
+func anyToSockaddrOS(rsa *RawSockaddrAny) (Sockaddr, error) {
+ return nil, EAFNOSUPPORT
+}
+
+func GetsockoptIPv6MTUInfo(fd, level, opt int) (*IPv6MTUInfo, error) {
+ var value IPv6MTUInfo
+ vallen := Socklen_t(SizeofIPv6MTUInfo)
+ err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
+ return &value, err
+}
diff --git a/libgo/go/syscall/socket_bsd.go b/libgo/go/syscall/socket_bsd.go
index ecdab06..cf3fc4f 100644
--- a/libgo/go/syscall/socket_bsd.go
+++ b/libgo/go/syscall/socket_bsd.go
@@ -4,7 +4,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build aix darwin dragonfly freebsd openbsd netbsd
+// +build darwin dragonfly freebsd openbsd netbsd
package syscall
diff --git a/libgo/go/syscall/syscall_aix_ppc.go b/libgo/go/syscall/syscall_aix_ppc.go
new file mode 100644
index 0000000..83ed1e6
--- /dev/null
+++ b/libgo/go/syscall/syscall_aix_ppc.go
@@ -0,0 +1,49 @@
+// syscall_aix_ppc.go -- AIX 32-bit specific support
+
+// Copyright 2017 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.
+
+package syscall
+
+import "unsafe"
+
+// AIX does not define a specific structure but instead uses separate
+// ptrace calls for the different registers.
+type PtraceRegs struct {
+ Gpr [32]uint32
+ Iar uint32
+ Msr uint32
+ Cr uint32
+ Lr uint32
+ Ctr uint32
+ Xer uint32
+}
+
+func (r *PtraceRegs) PC() uint64 { return uint64(r.Iar) }
+
+func (r *PtraceRegs) SetPC(pc uint64) { r.Iar = uint32(pc) }
+
+func PtraceGetRegs(pid int, regsout *PtraceRegs) (err error) {
+ ptrace(_PT_REGSET, pid, uintptr(unsafe.Pointer(&regsout.Gpr[0])), 0, 0)
+ regsout.Iar = uint32(ptrace(_PT_READ_GPR, pid, 128, 0, 0))
+ regsout.Msr = uint32(ptrace(_PT_READ_GPR, pid, 129, 0, 0))
+ regsout.Cr = uint32(ptrace(_PT_READ_GPR, pid, 130, 0, 0))
+ regsout.Lr = uint32(ptrace(_PT_READ_GPR, pid, 131, 0, 0))
+ regsout.Ctr = uint32(ptrace(_PT_READ_GPR, pid, 132, 0, 0))
+ regsout.Xer = uint32(ptrace(_PT_READ_GPR, pid, 133, 0, 0))
+ return nil
+}
+
+func PtraceSetRegs(pid int, regs *PtraceRegs) (err error) {
+ for i := 0; i < len(regs.Gpr); i++ {
+ ptrace(_PT_WRITE_GPR, pid, uintptr(i), int(regs.Gpr[i]), 0)
+ }
+ ptrace(_PT_WRITE_GPR, pid, 128, int(regs.Iar), 0)
+ ptrace(_PT_WRITE_GPR, pid, 129, int(regs.Msr), 0)
+ ptrace(_PT_WRITE_GPR, pid, 130, int(regs.Cr), 0)
+ ptrace(_PT_WRITE_GPR, pid, 131, int(regs.Lr), 0)
+ ptrace(_PT_WRITE_GPR, pid, 132, int(regs.Ctr), 0)
+ ptrace(_PT_WRITE_GPR, pid, 133, int(regs.Xer), 0)
+ return nil
+}
diff --git a/libgo/go/syscall/syscall_aix_ppc64.go b/libgo/go/syscall/syscall_aix_ppc64.go
new file mode 100644
index 0000000..82388ca
--- /dev/null
+++ b/libgo/go/syscall/syscall_aix_ppc64.go
@@ -0,0 +1,49 @@
+// syscall_aix_ppc64.go -- AIX 64-bit specific support
+
+// Copyright 2017 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.
+
+package syscall
+
+import "unsafe"
+
+// AIX does not define a specific structure but instead uses separate
+// ptrace calls for the different registers.
+type PtraceRegs struct {
+ Gpr [32]uint64
+ Iar uint64
+ Msr uint64
+ Cr uint64
+ Lr uint64
+ Ctr uint64
+ Xer uint64
+}
+
+func (r *PtraceRegs) PC() uint64 { return r.Iar }
+
+func (r *PtraceRegs) SetPC(pc uint64) { r.Iar = pc }
+
+func PtraceGetRegs(pid int, regsout *PtraceRegs) (err error) {
+ ptrace64(_PT_REGSET, int64(pid), int64(uintptr(unsafe.Pointer(&regsout.Gpr[0]))), 0, 0)
+ ptrace64(_PT_READ_GPR, int64(pid), 128, 0, uintptr(unsafe.Pointer(&regsout.Iar)))
+ ptrace64(_PT_READ_GPR, int64(pid), 129, 0, uintptr(unsafe.Pointer(&regsout.Msr)))
+ ptrace64(_PT_READ_GPR, int64(pid), 130, 0, uintptr(unsafe.Pointer(&regsout.Cr)))
+ ptrace64(_PT_READ_GPR, int64(pid), 131, 0, uintptr(unsafe.Pointer(&regsout.Lr)))
+ ptrace64(_PT_READ_GPR, int64(pid), 132, 0, uintptr(unsafe.Pointer(&regsout.Ctr)))
+ ptrace64(_PT_READ_GPR, int64(pid), 133, 0, uintptr(unsafe.Pointer(&regsout.Xer)))
+ return nil
+}
+
+func PtraceSetRegs(pid int, regs *PtraceRegs) (err error) {
+ for i := 0; i < len(regs.Gpr); i++ {
+ ptrace64(_PT_WRITE_GPR, int64(pid), int64(i), 0, uintptr(unsafe.Pointer(&regs.Gpr[i])))
+ }
+ ptrace64(_PT_WRITE_GPR, int64(pid), 128, 0, uintptr(unsafe.Pointer(&regs.Iar)))
+ ptrace64(_PT_WRITE_GPR, int64(pid), 129, 0, uintptr(unsafe.Pointer(&regs.Msr)))
+ ptrace64(_PT_WRITE_GPR, int64(pid), 130, 0, uintptr(unsafe.Pointer(&regs.Cr)))
+ ptrace64(_PT_WRITE_GPR, int64(pid), 131, 0, uintptr(unsafe.Pointer(&regs.Lr)))
+ ptrace64(_PT_WRITE_GPR, int64(pid), 132, 0, uintptr(unsafe.Pointer(&regs.Ctr)))
+ ptrace64(_PT_WRITE_GPR, int64(pid), 133, 0, uintptr(unsafe.Pointer(&regs.Xer)))
+ return nil
+}