internal,net,os,runtime,syscall: fixes for AIX following update to go1.9
Change-Id: Ic19aa81439de86057d98c7fed6d597e59ede15e8
Reviewed-on: https://go-review.googlesource.com/64551
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/libgo/go/cmd/go/internal/base/signal_unix.go b/libgo/go/cmd/go/internal/base/signal_unix.go
index 4ca3da9..b90f3a2 100644
--- a/libgo/go/cmd/go/internal/base/signal_unix.go
+++ b/libgo/go/cmd/go/internal/base/signal_unix.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
+// +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris
package base
diff --git a/libgo/go/internal/poll/export_posix_test.go b/libgo/go/internal/poll/export_posix_test.go
index 73b2c11..6b9bb8b 100644
--- a/libgo/go/internal/poll/export_posix_test.go
+++ b/libgo/go/internal/poll/export_posix_test.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
+// +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
// Export guts for testing on posix.
// Since testing imports os and os imports internal/poll,
diff --git a/libgo/go/internal/poll/fd_poll_runtime.go b/libgo/go/internal/poll/fd_poll_runtime.go
index bfbe3c7..9de8af1 100644
--- a/libgo/go/internal/poll/fd_poll_runtime.go
+++ b/libgo/go/internal/poll/fd_poll_runtime.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd linux netbsd openbsd windows solaris
+// +build aix darwin dragonfly freebsd linux netbsd openbsd windows solaris
package poll
diff --git a/libgo/go/internal/poll/fd_posix.go b/libgo/go/internal/poll/fd_posix.go
index e0e634c..4e6e355 100644
--- a/libgo/go/internal/poll/fd_posix.go
+++ b/libgo/go/internal/poll/fd_posix.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
+// +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
package poll
diff --git a/libgo/go/internal/poll/fd_posix_test.go b/libgo/go/internal/poll/fd_posix_test.go
index cbe015e..246d498 100644
--- a/libgo/go/internal/poll/fd_posix_test.go
+++ b/libgo/go/internal/poll/fd_posix_test.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
+// +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
package poll_test
diff --git a/libgo/go/internal/poll/fd_unix.go b/libgo/go/internal/poll/fd_unix.go
index c40c701..0b43a19 100644
--- a/libgo/go/internal/poll/fd_unix.go
+++ b/libgo/go/internal/poll/fd_unix.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
+// +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris
package poll
diff --git a/libgo/go/internal/poll/hook_unix.go b/libgo/go/internal/poll/hook_unix.go
index 85e102d..4cf36cc 100644
--- a/libgo/go/internal/poll/hook_unix.go
+++ b/libgo/go/internal/poll/hook_unix.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
+// +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris
package poll
diff --git a/libgo/go/internal/poll/sockopt.go b/libgo/go/internal/poll/sockopt.go
index f86ce70..bb5ea02 100644
--- a/libgo/go/internal/poll/sockopt.go
+++ b/libgo/go/internal/poll/sockopt.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
+// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows
package poll
diff --git a/libgo/go/internal/poll/sockoptip.go b/libgo/go/internal/poll/sockoptip.go
index 5d5dff6..ae59b0c 100644
--- a/libgo/go/internal/poll/sockoptip.go
+++ b/libgo/go/internal/poll/sockoptip.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd linux netbsd openbsd windows
+// +build aix darwin dragonfly freebsd linux netbsd openbsd windows
package poll
diff --git a/libgo/go/internal/poll/sys_cloexec.go b/libgo/go/internal/poll/sys_cloexec.go
index 9ed35bd..fb5f2bc 100644
--- a/libgo/go/internal/poll/sys_cloexec.go
+++ b/libgo/go/internal/poll/sys_cloexec.go
@@ -5,7 +5,7 @@
// This file implements sysSocket and accept for platforms that do not
// provide a fast path for setting SetNonblock and CloseOnExec.
-// +build darwin nacl netbsd openbsd solaris
+// +build aix darwin nacl netbsd openbsd solaris
package poll
diff --git a/libgo/go/net/error_posix.go b/libgo/go/net/error_posix.go
index dd9754c..d0ffaae 100644
--- a/libgo/go/net/error_posix.go
+++ b/libgo/go/net/error_posix.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
+// +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows
package net
diff --git a/libgo/go/os/user/cgo_lookup_unix.go b/libgo/go/os/user/cgo_lookup_unix.go
index 8881366..9670ada 100644
--- a/libgo/go/os/user/cgo_lookup_unix.go
+++ b/libgo/go/os/user/cgo_lookup_unix.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd !android,linux netbsd openbsd solaris
+// +build aix darwin dragonfly freebsd !android,linux netbsd openbsd solaris
// +build cgo
package user
diff --git a/libgo/go/runtime/export_unix_test.go b/libgo/go/runtime/export_unix_test.go
index 54d5770..eecdfb7 100644
--- a/libgo/go/runtime/export_unix_test.go
+++ b/libgo/go/runtime/export_unix_test.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly freebsd linux netbsd openbsd solaris
+// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
package runtime
diff --git a/libgo/go/runtime/netpoll_aix.go b/libgo/go/runtime/netpoll_aix.go
index 8c8e188..b4962cc 100644
--- a/libgo/go/runtime/netpoll_aix.go
+++ b/libgo/go/runtime/netpoll_aix.go
@@ -64,14 +64,14 @@
var p [2]int32
if ps = pollset_create(-1); ps < 0 {
- throw("netpollinit: failed to create pollset")
+ throw("runtime: netpollinit failed to create pollset")
}
// It is not possible to add or remove descriptors from
// the pollset while pollset_poll is active.
// We use a pipe to wakeup pollset_poll when the pollset
// needs to be updated.
if err := libc_pipe(&p[0]); err < 0 {
- throw("netpollinit: failed to create pipe")
+ throw("runtime: netpollinit failed to create pipe")
}
rdwake = p[0]
wrwake = p[1]
@@ -90,12 +90,17 @@
pctl.fd = rdwake
pctl.events = _POLLIN
if pollset_ctl(ps, &pctl, 1) != 0 {
- throw("netpollinit: failed to register pipe")
+ throw("runtime: netpollinit failed to register pipe")
}
mpfds = make(map[int32]*pollDesc)
}
+func netpolldescriptor() uintptr {
+ // ps is not a real file descriptor.
+ return ^uintptr(0)
+}
+
func netpollopen(fd uintptr, pd *pollDesc) int32 {
// pollset_ctl will block if pollset_poll is active
// so wakeup pollset_poll first.
@@ -144,7 +149,7 @@
}
func netpollarm(pd *pollDesc, mode int) {
- throw("unused")
+ throw("runtime: unused")
}
func netpoll(block bool) *g {
@@ -168,7 +173,7 @@
if nfound < 0 {
e := errno()
if e != _EINTR {
- throw("pollset_poll failed")
+ throw("runtime: pollset_poll failed")
}
goto retry
}
diff --git a/libgo/go/syscall/forkpipe_bsd.go b/libgo/go/syscall/forkpipe_bsd.go
index 28897bf..d479284 100644
--- a/libgo/go/syscall/forkpipe_bsd.go
+++ b/libgo/go/syscall/forkpipe_bsd.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin dragonfly netbsd openbsd solaris
+// +build aix darwin dragonfly netbsd openbsd solaris
package syscall
diff --git a/libgo/go/syscall/libcall_aix.go b/libgo/go/syscall/libcall_aix.go
index 992eeb4..072f92a 100644
--- a/libgo/go/syscall/libcall_aix.go
+++ b/libgo/go/syscall/libcall_aix.go
@@ -6,6 +6,136 @@
package syscall
+import (
+ "unsafe"
+)
+
+//sys Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
+//open64at(dirfd _C_int, path *byte, flags _C_int, mode Mode_t) _C_int
+
+//sys ptrace(request int, id int, addr uintptr, data int, buff uintptr) (val int)
+//ptrace(request _C_int, id int, addr uintptr, data _C_int, buff *byte) _C_int
+
+//sys ptrace64(request int, id int64, addr int64, data int, buff uintptr) (err error)
+//ptrace64(request _C_int, id int64, addr int64, data _C_int, buff *byte) _C_int
+
func raw_ptrace(request int, pid int, addr *byte, data *byte) Errno {
+ if request == _PTRACE_TRACEME {
+ // Convert to AIX ptrace call.
+ err := ptrace64(_PT_TRACE_ME, 0, 0, 0, 0)
+ if err != nil {
+ return err.(Errno)
+ }
+ return 0
+ }
return ENOSYS
}
+
+func ptracePeek(pid int, addr uintptr, out []byte) (count int, err error) {
+ n := 0
+ for len(out) > 0 {
+ bsize := len(out)
+ if bsize > 1024 {
+ bsize = 1024
+ }
+ err = ptrace64(_PT_READ_BLOCK, int64(pid), int64(addr), bsize, uintptr(unsafe.Pointer(&out[0])))
+ if err != nil {
+ return 0, err
+ }
+ addr += uintptr(bsize)
+ n += bsize
+ out = out[n:]
+ }
+ return n, nil
+}
+
+func PtracePeekText(pid int, addr uintptr, out []byte) (count int, err error) {
+ return ptracePeek(pid, addr, out)
+}
+
+func PtracePeekData(pid int, addr uintptr, out []byte) (count int, err error) {
+ return ptracePeek(pid, addr, out)
+}
+
+func ptracePoke(pid int, addr uintptr, data []byte) (count int, err error) {
+ n := 0
+ for len(data) > 0 {
+ bsize := len(data)
+ if bsize > 1024 {
+ bsize = 1024
+ }
+ err = ptrace64(_PT_WRITE_BLOCK, int64(pid), int64(addr), bsize, uintptr(unsafe.Pointer(&data[0])))
+ if err != nil {
+ return 0, err
+ }
+ addr += uintptr(bsize)
+ n += bsize
+ data = data[n:]
+ }
+ return n, nil
+}
+
+func PtracePokeText(pid int, addr uintptr, data []byte) (count int, err error) {
+ return ptracePoke(pid, addr, data)
+}
+
+func PtracePokeData(pid int, addr uintptr, data []byte) (count int, err error) {
+ return ptracePoke(pid, addr, data)
+}
+
+func PtraceCont(pid int, signal int) (err error) {
+ return ptrace64(_PT_CONTINUE, int64(pid), 1, signal, 0)
+}
+
+func PtraceSingleStep(pid int) (err error) { return ptrace64(_PT_STEP, int64(pid), 1, 0, 0) }
+
+func PtraceAttach(pid int) (err error) { return ptrace64(_PT_ATTACH, int64(pid), 0, 0, 0) }
+
+func PtraceDetach(pid int) (err error) { return ptrace64(_PT_DETACH, int64(pid), 0, 0, 0) }
+
+//sys reboot(how int) (err error)
+//__linux_reboot(how _C_int) _C_int
+func Reboot(how int) (err error) {
+ return reboot(how)
+}
+
+//sys Acct(path string) (err error)
+//acct(path *byte) _C_int
+
+//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
+//faccessat(dirfd _C_int, pathname *byte, mode _C_int, flags _C_int) _C_int
+
+//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
+//fchmodat(dirfd _C_int, pathname *byte, mode Mode_t, flags _C_int) _C_int
+
+//sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)
+//fchownat(dirfd _C_int, path *byte, owner Uid_t, group Gid_t, flags _C_int) _C_int
+
+//sys Fstatfs(fd int, buf *Statfs_t) (err error)
+//fstatfs64(fd _C_int, buf *Statfs_t) _C_int
+
+//sys Mkdirat(dirfd int, path string, mode uint32) (err error)
+//mkdirat(dirfd _C_int, path *byte, mode Mode_t) _C_int
+
+//sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error)
+//mknodat(dirfd _C_int, path *byte, mode Mode_t, dev _dev_t) _C_int
+
+//sys getdirent(fd int, buf []byte) (n int, err error)
+//getdirent64(fd _C_int, buf *byte, nbyte Size_t) _C_int
+
+func ReadDirent(fd int, buf []byte) (n int, err error) {
+ return getdirent(fd, buf)
+}
+
+//sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
+//renameat(olddirfd _C_int, oldpath *byte, newdirfd _C_int, newpath *byte) _C_int
+
+//sys Statfs(path string, buf *Statfs_t) (err error)
+//statfs64(path *byte, buf *Statfs_t) _C_int
+
+//sys unlinkat(dirfd int, path string, flags int) (err error)
+//unlinkat(dirfd _C_int, path *byte, flags _C_int) _C_int
+
+func Unlinkat(dirfd int, path string) (err error) {
+ return unlinkat(dirfd, path, 0)
+}
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(®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 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(®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
+}