Skip to content

Commit 664ac49

Browse files
author
ian
committed
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
1 parent 2be5943 commit 664ac49

File tree

5 files changed

+189
-2
lines changed

5 files changed

+189
-2
lines changed

gcc/go/gofrontend/MERGE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
90fe3da36d904b62d47c00ee40eef4fd2693a5da
1+
84f827669dc76326ed99ebcc982c482aa148d8d8
22

33
The first line of this file holds the git revision number of the last
44
merge done from the gofrontend repository.

libgo/go/syscall/socket_aix.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// socket_aix.go -- Socket handling specific to AIX.
2+
3+
// Copyright 2017 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package syscall
8+
9+
import "unsafe"
10+
11+
const SizeofSockaddrInet4 = 16
12+
const SizeofSockaddrInet6 = 28
13+
const SizeofSockaddrUnix = 1025
14+
15+
type RawSockaddrInet4 struct {
16+
Len uint8
17+
Family uint8
18+
Port uint16
19+
Addr [4]byte /* in_addr */
20+
Zero [8]uint8
21+
}
22+
23+
func (sa *RawSockaddrInet4) setLen() Socklen_t {
24+
sa.Len = SizeofSockaddrInet4
25+
return SizeofSockaddrInet4
26+
}
27+
28+
type RawSockaddrInet6 struct {
29+
Len uint8
30+
Family uint8
31+
Port uint16
32+
Flowinfo uint32
33+
Addr [16]byte /* in6_addr */
34+
Scope_id uint32
35+
}
36+
37+
func (sa *RawSockaddrInet6) setLen() Socklen_t {
38+
sa.Len = SizeofSockaddrInet6
39+
return SizeofSockaddrInet6
40+
}
41+
42+
type RawSockaddrUnix struct {
43+
Len uint8
44+
Family uint8
45+
Path [1023]int8
46+
}
47+
48+
func (sa *RawSockaddrUnix) setLen(n int) {
49+
sa.Len = uint8(3 + n) // 2 for Family, Len; 1 for NUL.
50+
}
51+
52+
func (sa *RawSockaddrUnix) getLen() (int, error) {
53+
// Some versions of AIX have a bug in getsockname (see IV78655).
54+
// We can't rely on sa.Len being set correctly.
55+
n := SizeofSockaddrUnix - 3 // substract leading Family, Len, terminating NUL.
56+
for i := 0; i < n; i++ {
57+
if sa.Path[i] == 0 {
58+
n = i
59+
break
60+
}
61+
}
62+
return n, nil
63+
}
64+
65+
func (sa *RawSockaddrUnix) adjustAbstract(sl Socklen_t) Socklen_t {
66+
return sl
67+
}
68+
69+
type RawSockaddr struct {
70+
Len uint8
71+
Family uint8
72+
Data [14]int8
73+
}
74+
75+
// BindToDevice binds the socket associated with fd to device.
76+
func BindToDevice(fd int, device string) (err error) {
77+
return ENOSYS
78+
}
79+
80+
func anyToSockaddrOS(rsa *RawSockaddrAny) (Sockaddr, error) {
81+
return nil, EAFNOSUPPORT
82+
}
83+
84+
func GetsockoptIPv6MTUInfo(fd, level, opt int) (*IPv6MTUInfo, error) {
85+
var value IPv6MTUInfo
86+
vallen := Socklen_t(SizeofIPv6MTUInfo)
87+
err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
88+
return &value, err
89+
}

libgo/go/syscall/socket_bsd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
66

7-
// +build aix darwin dragonfly freebsd openbsd netbsd
7+
// +build darwin dragonfly freebsd openbsd netbsd
88

99
package syscall
1010

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// syscall_aix_ppc.go -- AIX 32-bit specific support
2+
3+
// Copyright 2017 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package syscall
8+
9+
import "unsafe"
10+
11+
// AIX does not define a specific structure but instead uses separate
12+
// ptrace calls for the different registers.
13+
type PtraceRegs struct {
14+
Gpr [32]uint32
15+
Iar uint32
16+
Msr uint32
17+
Cr uint32
18+
Lr uint32
19+
Ctr uint32
20+
Xer uint32
21+
}
22+
23+
func (r *PtraceRegs) PC() uint64 { return uint64(r.Iar) }
24+
25+
func (r *PtraceRegs) SetPC(pc uint64) { r.Iar = uint32(pc) }
26+
27+
func PtraceGetRegs(pid int, regsout *PtraceRegs) (err error) {
28+
ptrace(_PT_REGSET, pid, uintptr(unsafe.Pointer(&regsout.Gpr[0])), 0, 0)
29+
regsout.Iar = uint32(ptrace(_PT_READ_GPR, pid, 128, 0, 0))
30+
regsout.Msr = uint32(ptrace(_PT_READ_GPR, pid, 129, 0, 0))
31+
regsout.Cr = uint32(ptrace(_PT_READ_GPR, pid, 130, 0, 0))
32+
regsout.Lr = uint32(ptrace(_PT_READ_GPR, pid, 131, 0, 0))
33+
regsout.Ctr = uint32(ptrace(_PT_READ_GPR, pid, 132, 0, 0))
34+
regsout.Xer = uint32(ptrace(_PT_READ_GPR, pid, 133, 0, 0))
35+
return nil
36+
}
37+
38+
func PtraceSetRegs(pid int, regs *PtraceRegs) (err error) {
39+
for i := 0; i < len(regs.Gpr); i++ {
40+
ptrace(_PT_WRITE_GPR, pid, uintptr(i), int(regs.Gpr[i]), 0)
41+
}
42+
ptrace(_PT_WRITE_GPR, pid, 128, int(regs.Iar), 0)
43+
ptrace(_PT_WRITE_GPR, pid, 129, int(regs.Msr), 0)
44+
ptrace(_PT_WRITE_GPR, pid, 130, int(regs.Cr), 0)
45+
ptrace(_PT_WRITE_GPR, pid, 131, int(regs.Lr), 0)
46+
ptrace(_PT_WRITE_GPR, pid, 132, int(regs.Ctr), 0)
47+
ptrace(_PT_WRITE_GPR, pid, 133, int(regs.Xer), 0)
48+
return nil
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// syscall_aix_ppc64.go -- AIX 64-bit specific support
2+
3+
// Copyright 2017 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package syscall
8+
9+
import "unsafe"
10+
11+
// AIX does not define a specific structure but instead uses separate
12+
// ptrace calls for the different registers.
13+
type PtraceRegs struct {
14+
Gpr [32]uint64
15+
Iar uint64
16+
Msr uint64
17+
Cr uint64
18+
Lr uint64
19+
Ctr uint64
20+
Xer uint64
21+
}
22+
23+
func (r *PtraceRegs) PC() uint64 { return r.Iar }
24+
25+
func (r *PtraceRegs) SetPC(pc uint64) { r.Iar = pc }
26+
27+
func PtraceGetRegs(pid int, regsout *PtraceRegs) (err error) {
28+
ptrace64(_PT_REGSET, int64(pid), int64(uintptr(unsafe.Pointer(&regsout.Gpr[0]))), 0, 0)
29+
ptrace64(_PT_READ_GPR, int64(pid), 128, 0, uintptr(unsafe.Pointer(&regsout.Iar)))
30+
ptrace64(_PT_READ_GPR, int64(pid), 129, 0, uintptr(unsafe.Pointer(&regsout.Msr)))
31+
ptrace64(_PT_READ_GPR, int64(pid), 130, 0, uintptr(unsafe.Pointer(&regsout.Cr)))
32+
ptrace64(_PT_READ_GPR, int64(pid), 131, 0, uintptr(unsafe.Pointer(&regsout.Lr)))
33+
ptrace64(_PT_READ_GPR, int64(pid), 132, 0, uintptr(unsafe.Pointer(&regsout.Ctr)))
34+
ptrace64(_PT_READ_GPR, int64(pid), 133, 0, uintptr(unsafe.Pointer(&regsout.Xer)))
35+
return nil
36+
}
37+
38+
func PtraceSetRegs(pid int, regs *PtraceRegs) (err error) {
39+
for i := 0; i < len(regs.Gpr); i++ {
40+
ptrace64(_PT_WRITE_GPR, int64(pid), int64(i), 0, uintptr(unsafe.Pointer(&regs.Gpr[i])))
41+
}
42+
ptrace64(_PT_WRITE_GPR, int64(pid), 128, 0, uintptr(unsafe.Pointer(&regs.Iar)))
43+
ptrace64(_PT_WRITE_GPR, int64(pid), 129, 0, uintptr(unsafe.Pointer(&regs.Msr)))
44+
ptrace64(_PT_WRITE_GPR, int64(pid), 130, 0, uintptr(unsafe.Pointer(&regs.Cr)))
45+
ptrace64(_PT_WRITE_GPR, int64(pid), 131, 0, uintptr(unsafe.Pointer(&regs.Lr)))
46+
ptrace64(_PT_WRITE_GPR, int64(pid), 132, 0, uintptr(unsafe.Pointer(&regs.Ctr)))
47+
ptrace64(_PT_WRITE_GPR, int64(pid), 133, 0, uintptr(unsafe.Pointer(&regs.Xer)))
48+
return nil
49+
}

0 commit comments

Comments
 (0)