From 664ac495f9fe9595ce69d0332b000ba9c7737f6d Mon Sep 17 00:00:00 2001 From: ian Date: Wed, 20 Sep 2017 17:40:11 +0000 Subject: [PATCH] syscall: workaround for getsockname bug in AIX Reviewed-on: https://go-review.googlesource.com/64552 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253021 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/go/gofrontend/MERGE | 2 +- libgo/go/syscall/{socket_bsd.go => socket_aix.go} | 18 ++++----- libgo/go/syscall/socket_bsd.go | 2 +- libgo/go/syscall/syscall_aix_ppc.go | 49 +++++++++++++++++++++++ libgo/go/syscall/syscall_aix_ppc64.go | 49 +++++++++++++++++++++++ 5 files changed, 107 insertions(+), 13 deletions(-) copy libgo/go/syscall/{socket_bsd.go => socket_aix.go} (79%) create mode 100644 libgo/go/syscall/syscall_aix_ppc.go create mode 100644 libgo/go/syscall/syscall_aix_ppc64.go 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_bsd.go b/libgo/go/syscall/socket_aix.go similarity index 79% copy from libgo/go/syscall/socket_bsd.go copy to libgo/go/syscall/socket_aix.go index ecdab060701..40cf42365e2 100644 --- a/libgo/go/syscall/socket_bsd.go +++ b/libgo/go/syscall/socket_aix.go @@ -1,18 +1,16 @@ -// socket_bsd.go -- Socket handling specific to *BSD based systems. +// socket_aix.go -- Socket handling specific to AIX. -// Copyright 2010 The Go Authors. All rights reserved. +// 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. -// +build aix darwin dragonfly freebsd openbsd netbsd - package syscall import "unsafe" const SizeofSockaddrInet4 = 16 const SizeofSockaddrInet6 = 28 -const SizeofSockaddrUnix = 110 +const SizeofSockaddrUnix = 1025 type RawSockaddrInet4 struct { Len uint8 @@ -44,7 +42,7 @@ func (sa *RawSockaddrInet6) setLen() Socklen_t { type RawSockaddrUnix struct { Len uint8 Family uint8 - Path [108]int8 + Path [1023]int8 } func (sa *RawSockaddrUnix) setLen(n int) { @@ -52,13 +50,11 @@ func (sa *RawSockaddrUnix) setLen(n int) { } func (sa *RawSockaddrUnix) getLen() (int, error) { - if sa.Len < 3 || sa.Len > SizeofSockaddrUnix { - return 0, EINVAL - } - n := int(sa.Len) - 3 // subtract leading Family, Len, terminating NUL. + // 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 { - // found early NUL; assume Len is overestimating. n = i break } 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 +} -- 2.11.4.GIT