Commit 5e525857 by Ian Lance Taylor

syscall: workaround for getsockname bug in AIX

    
    Reviewed-on: https://go-review.googlesource.com/64552

From-SVN: r253021
parent e18f68c7
90fe3da36d904b62d47c00ee40eef4fd2693a5da 84f827669dc76326ed99ebcc982c482aa148d8d8
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.
// 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
}
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build aix darwin dragonfly freebsd openbsd netbsd // +build darwin dragonfly freebsd openbsd netbsd
package syscall package syscall
......
// 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
}
// 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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment