Commit 8f9902da authored by Clément Chigot's avatar Clément Chigot Committed by Ian Lance Taylor

syscall: add AIX operating system

This commit adds AIX operating system to syscall package for ppc64
architecture.
It also adds the file syscall_aix.go in the runtime package for
syscalls needed during fork and exec.

Updates: #25893

Change-Id: I301b1051b178a3efb7bbc39cdbd8e00b594d65ef
Reviewed-on: https://go-review.googlesource.com/c/138720
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent c870d56f
// Copyright 2018 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 runtime
import "unsafe"
// This file handles some syscalls from the syscall package
// Especially, syscalls use during forkAndExecInChild which must not split the stack
//go:cgo_import_dynamic libc_chdir chdir "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_chroot chroot "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_dup2 dup2 "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_execve execve "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_fcntl fcntl "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_fork fork "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_ioctl ioctl "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_setgid setgid "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_setgroups setgroups "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_setsid setsid "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_setuid setuid "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_setpgid setpgid "libc.a/shr_64.o"
//go:linkname libc_chdir libc_chdir
//go:linkname libc_chroot libc_chroot
//go:linkname libc_dup2 libc_dup2
//go:linkname libc_execve libc_execve
//go:linkname libc_fcntl libc_fcntl
//go:linkname libc_fork libc_fork
//go:linkname libc_ioctl libc_ioctl
//go:linkname libc_setgid libc_setgid
//go:linkname libc_setgroups libc_setgroups
//go:linkname libc_setsid libc_setsid
//go:linkname libc_setuid libc_setuid
//go:linkname libc_setpgid libc_setpgid
var (
libc_chdir,
libc_chroot,
libc_dup2,
libc_execve,
libc_fcntl,
libc_fork,
libc_ioctl,
libc_setgid,
libc_setgroups,
libc_setsid,
libc_setuid,
libc_setpgid libFunc
)
// In syscall_syscall6 and syscall_rawsyscall6, r2 is always 0
// as it's never used on AIX
// TODO: remove r2 from zsyscall_aix_$GOARCH.go
// Syscall is needed because some packages (like net) need it too.
// The best way is to return EINVAL and let Golang handles its failure
// If the syscall can't fail, this function can redirect it to a real syscall.
//go:linkname syscall_Syscall syscall.Syscall
//go:nosplit
func syscall_Syscall(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
return 0, 0, _EINVAL
}
// This is syscall.RawSyscall, it exists to satisfy some build dependency,
// but it doesn't work.
//go:linkname syscall_RawSyscall syscall.RawSyscall
func syscall_RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
panic("RawSyscall not available on AIX")
}
//go:linkname syscall_syscall6 syscall.syscall6
//go:nosplit
func syscall_syscall6(fn, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
c := getg().m.libcall
c.fn = uintptr(unsafe.Pointer(fn))
c.n = nargs
c.args = uintptr(noescape(unsafe.Pointer(&a1)))
entersyscallblock()
asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
exitsyscall()
return c.r1, 0, c.err
}
//go:linkname syscall_rawSyscall6 syscall.rawSyscall6
//go:nosplit
func syscall_rawSyscall6(fn, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
c := getg().m.libcall
c.fn = uintptr(unsafe.Pointer(fn))
c.n = nargs
c.args = uintptr(noescape(unsafe.Pointer(&a1)))
asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
return c.r1, 0, c.err
}
//go:linkname syscall_chdir syscall.chdir
//go:nosplit
func syscall_chdir(path uintptr) (err uintptr) {
_, err = syscall1(&libc_chdir, path)
return
}
//go:linkname syscall_chroot1 syscall.chroot1
//go:nosplit
func syscall_chroot1(path uintptr) (err uintptr) {
_, err = syscall1(&libc_chroot, path)
return
}
// like close, but must not split stack, for fork.
//go:linkname syscall_close syscall.close
//go:nosplit
func syscall_close(fd int32) int32 {
_, err := syscall1(&libc_close, uintptr(fd))
return int32(err)
}
//go:linkname syscall_dup2child syscall.dup2child
//go:nosplit
func syscall_dup2child(old, new uintptr) (val, err uintptr) {
val, err = syscall2(&libc_dup2, old, new)
return
}
//go:linkname syscall_execve syscall.execve
//go:nosplit
func syscall_execve(path, argv, envp uintptr) (err uintptr) {
_, err = syscall3(&libc_execve, path, argv, envp)
return
}
// like exit, but must not split stack, for fork.
//go:linkname syscall_exit syscall.exit
//go:nosplit
func syscall_exit(code uintptr) {
syscall1(&libc_exit, code)
}
//go:linkname syscall_fcntl1 syscall.fcntl1
//go:nosplit
func syscall_fcntl1(fd, cmd, arg uintptr) (val, err uintptr) {
val, err = syscall3(&libc_fcntl, fd, cmd, arg)
return
}
//go:linkname syscall_forkx syscall.forkx
//go:nosplit
func syscall_forkx(flags uintptr) (pid uintptr, err uintptr) {
pid, err = syscall1(&libc_fork, flags)
return
}
//go:linkname syscall_getpid syscall.getpid
//go:nosplit
func syscall_getpid() (pid, err uintptr) {
pid, err = syscall0(&libc_getpid)
return
}
//go:linkname syscall_ioctl syscall.ioctl
//go:nosplit
func syscall_ioctl(fd, req, arg uintptr) (err uintptr) {
_, err = syscall3(&libc_ioctl, fd, req, arg)
return
}
//go:linkname syscall_setgid syscall.setgid
//go:nosplit
func syscall_setgid(gid uintptr) (err uintptr) {
_, err = syscall1(&libc_setgid, gid)
return
}
//go:linkname syscall_setgroups1 syscall.setgroups1
//go:nosplit
func syscall_setgroups1(ngid, gid uintptr) (err uintptr) {
_, err = syscall2(&libc_setgroups, ngid, gid)
return
}
//go:linkname syscall_setsid syscall.setsid
//go:nosplit
func syscall_setsid() (pid, err uintptr) {
pid, err = syscall0(&libc_setsid)
return
}
//go:linkname syscall_setuid syscall.setuid
//go:nosplit
func syscall_setuid(uid uintptr) (err uintptr) {
_, err = syscall1(&libc_setuid, uid)
return
}
//go:linkname syscall_setpgid syscall.setpgid
//go:nosplit
func syscall_setpgid(pid, pgid uintptr) (err uintptr) {
_, err = syscall2(&libc_setpgid, pid, pgid)
return
}
//go:linkname syscall_write1 syscall.write1
//go:nosplit
func syscall_write1(fd, buf, nbyte uintptr) (n, err uintptr) {
n, err = syscall3(&libc_write, fd, buf, nbyte)
return
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,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 darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris // +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris
package syscall package syscall
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,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 darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris // +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris
// Unix environment variables. // Unix environment variables.
......
// Copyright 2015 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
package syscall
import "unsafe"
//go:cgo_import_dynamic libc_Getpgid getpgid "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_Getpgrp getpgrp "libc.a/shr_64.o"
//go:linkname libc_Getpgid libc_Getpgid
//go:linkname libc_Getpgrp libc_Getpgrp
var (
libc_Getpgid,
libc_Getpgrp libcFunc
)
func Getpgid(pid int) (pgid int, err error) {
r0, _, e1 := syscall6(uintptr(unsafe.Pointer(&libc_Getpgid)), 1, uintptr(pid), 0, 0, 0, 0, 0)
pgid = int(r0)
if e1 != 0 {
err = e1
}
return
}
func Getpgrp() (pgrp int) {
r0, _, _ := syscall6(uintptr(unsafe.Pointer(&libc_Getpgrp)), 0, 0, 0, 0, 0, 0, 0)
pgrp = int(r0)
return
}
var Ioctl = ioctl
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,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 darwin dragonfly freebsd linux netbsd openbsd solaris // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
package syscall_test package syscall_test
......
// Copyright 2018 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"
// On AIX, there is no flock() system call, we emulate it.
// Moreover, we can't call the default fcntl syscall because the arguments
// must be integer and it's not possible to transform a pointer (lk)
// to a int value.
// It's easier to call syscall6 than to transform fcntl for every GOOS.
func fcntlFlock(fd, cmd int, lk *Flock_t) (err error) {
_, _, e1 := syscall6(uintptr(unsafe.Pointer(&libc_fcntl)), 3, uintptr(fd), uintptr(cmd), uintptr(unsafe.Pointer(lk)), 0, 0, 0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
func Flock(fd int, op int) (err error) {
lk := &Flock_t{}
if (op & LOCK_UN) != 0 {
lk.Type = F_UNLCK
} else if (op & LOCK_EX) != 0 {
lk.Type = F_WRLCK
} else if (op & LOCK_SH) != 0 {
lk.Type = F_RDLCK
} else {
return nil
}
if (op & LOCK_NB) != 0 {
err = fcntlFlock(fd, F_SETLK, lk)
if err != nil && (err == EAGAIN || err == EACCES) {
return EWOULDBLOCK
}
return err
}
return fcntlFlock(fd, F_SETLKW, lk)
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,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 darwin dragonfly solaris // +build aix darwin dragonfly solaris
package syscall package syscall
......
...@@ -20,6 +20,16 @@ fi ...@@ -20,6 +20,16 @@ fi
uname=$(uname) uname=$(uname)
includes_AIX='
#include <net/if.h>
#include <net/netopt.h>
#include <netinet/ip_mroute.h>
#include <sys/mman.h>
#include <sys/protosw.h>
#include <sys/ptrace.h>
#include <sys/stropts.h>
'
includes_Darwin=' includes_Darwin='
#define _DARWIN_C_SOURCE #define _DARWIN_C_SOURCE
#define KERNEL #define KERNEL
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,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 darwin dragonfly freebsd linux netbsd openbsd // +build aix darwin dragonfly freebsd linux netbsd openbsd
package syscall_test package syscall_test
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,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 darwin dragonfly freebsd linux netbsd openbsd solaris // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
// Socket control messages // Socket control messages
......
This diff is collapsed.
// Copyright 2018 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
func (iov *Iovec) SetLen(length int) {
iov.Len = uint64(length)
}
func (msghdr *Msghdr) SetControllen(length int) {
msghdr.Controllen = uint32(length)
}
func (cmsg *Cmsghdr) SetLen(length int) {
cmsg.Len = uint32(length)
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,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 darwin dragonfly freebsd linux netbsd openbsd solaris // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
package syscall package syscall
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,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 darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris // +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris
package syscall package syscall
......
// Copyright 2018 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 ignore
/*
Input to cgo -godefs. See also mkerrors.sh and mkall.sh
*/
// +godefs map struct_in_addr [4]byte /* in_addr */
// +godefs map struct_in6_addr [16]byte /* in6_addr */
package syscall
/*
#include <sys/types.h>
#include <sys/time.h>
#include <sys/limits.h>
#include <sys/un.h>
#include <sys/utsname.h>
#include <sys/ptrace.h>
#include <sys/statfs.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/icmp6.h>
#include <dirent.h>
#include <fcntl.h>
#include <gcrypt.h>
enum {
sizeofPtr = sizeof(void*),
};
union sockaddr_all {
struct sockaddr s1; // this one gets used for fields
struct sockaddr_in s2; // these pad it out
struct sockaddr_in6 s3;
struct sockaddr_un s4;
};
struct sockaddr_any {
struct sockaddr addr;
char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];
};
*/
import "C"
// Machine characteristics; for internal use.
const (
sizeofPtr = C.sizeofPtr
sizeofShort = C.sizeof_short
sizeofInt = C.sizeof_int
sizeofLong = C.sizeof_long
sizeofLongLong = C.sizeof_longlong
PathMax = C.PATH_MAX
)
// Basic types
type (
_C_short C.short
_C_int C.int
_C_long C.long
_C_long_long C.longlong
)
// Time
type Timespec C.struct_timespec
type Timeval C.struct_timeval
type Timeval32 C.struct_timeval32
type Timezone C.struct_timezone
// Processes
type Rusage C.struct_rusage
type Rlimit C.struct_rlimit
type Pid_t C.pid_t
type _Gid_t C.gid_t
// Files
type Flock_t C.struct_flock
type Stat_t C.struct_stat
type Statfs_t C.struct_statfs
type Fsid64_t C.fsid64_t
type StTimespec_t C.st_timespec_t
type Dirent C.struct_dirent
// Sockets
type RawSockaddrInet4 C.struct_sockaddr_in
type RawSockaddrInet6 C.struct_sockaddr_in6
type RawSockaddrUnix C.struct_sockaddr_un
type RawSockaddr C.struct_sockaddr
type RawSockaddrAny C.struct_sockaddr_any
type _Socklen C.socklen_t
type Cmsghdr C.struct_cmsghdr
type ICMPv6Filter C.struct_icmp6_filter
type Iovec C.struct_iovec
type IPMreq C.struct_ip_mreq
type IPv6Mreq C.struct_ipv6_mreq
type Linger C.struct_linger
type Msghdr C.struct_msghdr
const (
SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
SizeofSockaddrAny = C.sizeof_struct_sockaddr_any
SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un
SizeofLinger = C.sizeof_struct_linger
SizeofIPMreq = C.sizeof_struct_ip_mreq
SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
SizeofMsghdr = C.sizeof_struct_msghdr
SizeofCmsghdr = C.sizeof_struct_cmsghdr
SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
)
// Ptrace requests
const (
PTRACE_TRACEME = C.PT_TRACE_ME
PTRACE_CONT = C.PT_CONTINUE
PTRACE_KILL = C.PT_KILL
)
// Routing and interface messages
const (
SizeofIfMsghdr = C.sizeof_struct_if_msghdr
)
type IfMsgHdr C.struct_if_msghdr
// Misc
type Utsname C.struct_utsname
const (
_AT_FDCWD = C.AT_FDCWD
_AT_REMOVEDIR = C.AT_REMOVEDIR
_AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW
)
This diff is collapsed.
This diff is collapsed.
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs types_aix.go | go run mkpost.go
package syscall
const (
sizeofPtr = 0x8
sizeofShort = 0x2
sizeofInt = 0x4
sizeofLong = 0x8
sizeofLongLong = 0x8
PathMax = 0x3ff
)
type (
_C_short int16
_C_int int32
_C_long int64
_C_long_long int64
)
type Timespec struct {
Sec int64
Nsec int64
}
type Timeval struct {
Sec int64
Usec int32
Pad_cgo_0 [4]byte
}
type Timeval32 struct {
Sec int32
Usec int32
}
type Timezone struct {
Minuteswest int32
Dsttime int32
}
type Rusage struct {
Utime Timeval
Stime Timeval
Maxrss int64
Ixrss int64
Idrss int64
Isrss int64
Minflt int64
Majflt int64
Nswap int64
Inblock int64
Oublock int64
Msgsnd int64
Msgrcv int64
Nsignals int64
Nvcsw int64
Nivcsw int64
}
type Rlimit struct {
Cur uint64
Max uint64
}
type Pid_t int32
type _Gid_t uint32
type Flock_t struct {
Type int16
Whence int16
Sysid uint32
Pid int32
Vfs int32
Start int64
Len int64
}
type Stat_t struct {
Dev uint64
Ino uint64
Mode uint32
Nlink int16
Flag uint16
Uid uint32
Gid uint32
Rdev uint64
Ssize int32
Pad_cgo_0 [4]byte
Atim StTimespec_t
Mtim StTimespec_t
Ctim StTimespec_t
Blksize int64
Blocks int64
Vfstype int32
Vfs uint32
Type uint32
Gen uint32
Reserved [9]uint32
Padto_ll uint32
Size int64
}
type Statfs_t struct {
Version int32
Type int32
Bsize uint64
Blocks uint64
Bfree uint64
Bavail uint64
Files uint64
Ffree uint64
Fsid Fsid64_t
Vfstype int32
Pad_cgo_0 [4]byte
Fsize uint64
Vfsnumber int32
Vfsoff int32
Vfslen int32
Vfsvers int32
Fname [32]uint8
Fpack [32]uint8
Name_max int32
Pad_cgo_1 [4]byte
}
type Fsid64_t struct {
Val [2]uint64
}
type StTimespec_t struct {
Sec int64
Nsec int32
Pad_cgo_0 [4]byte
}
type Dirent struct {
Offset uint64
Ino uint64
Reclen uint16
Namlen uint16
Name [256]uint8
Pad_cgo_0 [4]byte
}
type RawSockaddrInet4 struct {
Len uint8
Family uint8
Port uint16
Addr [4]byte /* in_addr */
Zero [8]uint8
}
type RawSockaddrInet6 struct {
Len uint8
Family uint8
Port uint16
Flowinfo uint32
Addr [16]byte /* in6_addr */
Scope_id uint32
}
type RawSockaddrUnix struct {
Len uint8
Family uint8
Path [1023]uint8
}
type RawSockaddr struct {
Len uint8
Family uint8
Data [14]uint8
}
type RawSockaddrAny struct {
Addr RawSockaddr
Pad [1012]uint8
}
type _Socklen uint32
type Cmsghdr struct {
Len uint32
Level int32
Type int32
}
type ICMPv6Filter struct {
Filt [8]uint32
}
type Iovec struct {
Base *byte
Len uint64
}
type IPMreq struct {
Multiaddr [4]byte /* in_addr */
Interface [4]byte /* in_addr */
}
type IPv6Mreq struct {
Multiaddr [16]byte /* in6_addr */
Interface uint32
}
type Linger struct {
Onoff int32
Linger int32
}
type Msghdr struct {
Name *byte
Namelen uint32
Pad_cgo_0 [4]byte
Iov *Iovec
Iovlen int32
Pad_cgo_1 [4]byte
Control *byte
Controllen uint32
Flags int32
}
const (
SizeofSockaddrInet4 = 0x10
SizeofSockaddrInet6 = 0x1c
SizeofSockaddrAny = 0x404
SizeofSockaddrUnix = 0x401
SizeofLinger = 0x8
SizeofIPMreq = 0x8
SizeofIPv6Mreq = 0x14
SizeofMsghdr = 0x30
SizeofCmsghdr = 0xc
SizeofICMPv6Filter = 0x20
)
const (
PTRACE_TRACEME = 0x0
PTRACE_CONT = 0x7
PTRACE_KILL = 0x8
)
const (
SizeofIfMsghdr = 0x10
)
type IfMsgHdr struct {
Msglen uint16
Version uint8
Type uint8
Addrs int32
Flags int32
Index uint16
Addrlen uint8
Pad_cgo_0 [1]byte
}
type Utsname struct {
Sysname [32]uint8
Nodename [32]uint8
Release [32]uint8
Version [32]uint8
Machine [32]uint8
}
const (
_AT_FDCWD = -0x2
_AT_REMOVEDIR = 0x1
_AT_SYMLINK_NOFOLLOW = 0x1
)
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