From: Ian Lance Taylor Date: Wed, 20 Sep 2017 17:40:11 +0000 (+0000) Subject: syscall: workaround for getsockname bug in AIX X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5e525857e9a7390d9a90de91618b133ab6051a9d;p=gcc.git syscall: workaround for getsockname bug in AIX Reviewed-on: https://go-review.googlesource.com/64552 From-SVN: r253021 --- diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index cca4a16e7ec..27b0be0a345 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -90fe3da36d904b62d47c00ee40eef4fd2693a5da +84f827669dc76326ed99ebcc982c482aa148d8d8 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/libgo/go/syscall/socket_aix.go b/libgo/go/syscall/socket_aix.go new file mode 100644 index 00000000000..40cf42365e2 --- /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 ecdab060701..cf3fc4f8da0 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 00000000000..83ed1e64c3a --- /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(®sout.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 00000000000..82388cad140 --- /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(®sout.Gpr[0]))), 0, 0) + ptrace64(_PT_READ_GPR, int64(pid), 128, 0, uintptr(unsafe.Pointer(®sout.Iar))) + ptrace64(_PT_READ_GPR, int64(pid), 129, 0, uintptr(unsafe.Pointer(®sout.Msr))) + ptrace64(_PT_READ_GPR, int64(pid), 130, 0, uintptr(unsafe.Pointer(®sout.Cr))) + ptrace64(_PT_READ_GPR, int64(pid), 131, 0, uintptr(unsafe.Pointer(®sout.Lr))) + ptrace64(_PT_READ_GPR, int64(pid), 132, 0, uintptr(unsafe.Pointer(®sout.Ctr))) + ptrace64(_PT_READ_GPR, int64(pid), 133, 0, uintptr(unsafe.Pointer(®sout.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(®s.Gpr[i]))) + } + ptrace64(_PT_WRITE_GPR, int64(pid), 128, 0, uintptr(unsafe.Pointer(®s.Iar))) + ptrace64(_PT_WRITE_GPR, int64(pid), 129, 0, uintptr(unsafe.Pointer(®s.Msr))) + ptrace64(_PT_WRITE_GPR, int64(pid), 130, 0, uintptr(unsafe.Pointer(®s.Cr))) + ptrace64(_PT_WRITE_GPR, int64(pid), 131, 0, uintptr(unsafe.Pointer(®s.Lr))) + ptrace64(_PT_WRITE_GPR, int64(pid), 132, 0, uintptr(unsafe.Pointer(®s.Ctr))) + ptrace64(_PT_WRITE_GPR, int64(pid), 133, 0, uintptr(unsafe.Pointer(®s.Xer))) + return nil +}