Commit 9f78aa77 authored by Clément Chigot's avatar Clément Chigot Committed by Ian Lance Taylor

runtime: add AIX operating system

This commit adds AIX operating system to runtime package for ppc64
architecture.

Only new files and minor changes are in this commit. Others
modifications in files like asm_ppc64.s  will be in separate commits.

Updates: #25893

Change-Id: I9c5e073f5f3debb43b004ad1167694a5afd31cfd
Reviewed-on: https://go-review.googlesource.com/c/138716
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 c216c3aa
......@@ -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_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.
// +build ignore
/*
Input to cgo -godefs
GOARCH=ppc64 go tool cgo -godefs defs_aix.go > defs_aix_ppc64_tmp.go
This is only an helper to create defs_aix_ppc64.go
Go runtime functions require the "linux" name of fields (ss_sp, si_addr, etc)
However, AIX structures don't provide such names and must be modified.
TODO(aix): create a script to automatise defs_aix creation.
Modifications made:
- sigset replaced by a [4]uint64 array
- add sigset_all variable
- siginfo.si_addr uintptr instead of *byte
- add (*timeval) set_usec
- stackt.ss_sp uintptr instead of *byte
- stackt.ss_size uintptr instead of uint64
- sigcontext.sc_jmpbuf context64 instead of jumbuf
- ucontext.__extctx is a uintptr because we don't need extctx struct
- ucontext.uc_mcontext: replace jumbuf structure by context64 structure
- sigaction.sa_handler represents union field as both are uintptr
- tstate.* replace *byte by uintptr
*/
package runtime
/*
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <sys/signal.h>
#include <sys/mman.h>
#include <sys/thread.h>
#include <sys/resource.h>
#include <unistd.h>
#include <fcntl.h>
#include <pthread.h>
#include <semaphore.h>
*/
import "C"
const (
_EPERM = C.EPERM
_ENOENT = C.ENOENT
_EINTR = C.EINTR
_EAGAIN = C.EAGAIN
_ENOMEM = C.ENOMEM
_EACCES = C.EACCES
_EFAULT = C.EFAULT
_EINVAL = C.EINVAL
_ETIMEDOUT = C.ETIMEDOUT
_PROT_NONE = C.PROT_NONE
_PROT_READ = C.PROT_READ
_PROT_WRITE = C.PROT_WRITE
_PROT_EXEC = C.PROT_EXEC
_MAP_ANONYMOUS = C.MAP_ANONYMOUS
_MAP_PRIVATE = C.MAP_PRIVATE
_MAP_FIXED = C.MAP_FIXED
_MADV_DONTNEED = C.MADV_DONTNEED
_SIGHUP = C.SIGHUP
_SIGINT = C.SIGINT
_SIGQUIT = C.SIGQUIT
_SIGILL = C.SIGILL
_SIGTRAP = C.SIGTRAP
_SIGABRT = C.SIGABRT
_SIGBUS = C.SIGBUS
_SIGFPE = C.SIGFPE
_SIGKILL = C.SIGKILL
_SIGUSR1 = C.SIGUSR1
_SIGSEGV = C.SIGSEGV
_SIGUSR2 = C.SIGUSR2
_SIGPIPE = C.SIGPIPE
_SIGALRM = C.SIGALRM
_SIGCHLD = C.SIGCHLD
_SIGCONT = C.SIGCONT
_SIGSTOP = C.SIGSTOP
_SIGTSTP = C.SIGTSTP
_SIGTTIN = C.SIGTTIN
_SIGTTOU = C.SIGTTOU
_SIGURG = C.SIGURG
_SIGXCPU = C.SIGXCPU
_SIGXFSZ = C.SIGXFSZ
_SIGVTALRM = C.SIGVTALRM
_SIGPROF = C.SIGPROF
_SIGWINCH = C.SIGWINCH
_SIGIO = C.SIGIO
_SIGPWR = C.SIGPWR
_SIGSYS = C.SIGSYS
_SIGTERM = C.SIGTERM
_SIGEMT = C.SIGEMT
_SIGWAITING = C.SIGWAITING
_FPE_INTDIV = C.FPE_INTDIV
_FPE_INTOVF = C.FPE_INTOVF
_FPE_FLTDIV = C.FPE_FLTDIV
_FPE_FLTOVF = C.FPE_FLTOVF
_FPE_FLTUND = C.FPE_FLTUND
_FPE_FLTRES = C.FPE_FLTRES
_FPE_FLTINV = C.FPE_FLTINV
_FPE_FLTSUB = C.FPE_FLTSUB
_BUS_ADRALN = C.BUS_ADRALN
_BUS_ADRERR = C.BUS_ADRERR
_BUS_OBJERR = C.BUS_OBJERR
_SEGV_MAPERR = C.SEGV_MAPERR
_SEGV_ACCERR = C.SEGV_ACCERR
_ITIMER_REAL = C.ITIMER_REAL
_ITIMER_VIRTUAL = C.ITIMER_VIRTUAL
_ITIMER_PROF = C.ITIMER_PROF
_O_RDONLY = C.O_RDONLY
_SS_DISABLE = C.SS_DISABLE
_SI_USER = C.SI_USER
_SIG_BLOCK = C.SIG_BLOCK
_SIG_UNBLOCK = C.SIG_UNBLOCK
_SIG_SETMASK = C.SIG_SETMASK
_SA_SIGINFO = C.SA_SIGINFO
_SA_RESTART = C.SA_RESTART
_SA_ONSTACK = C.SA_ONSTACK
_PTHREAD_CREATE_DETACHED = C.PTHREAD_CREATE_DETACHED
__SC_PAGE_SIZE = C._SC_PAGE_SIZE
__SC_NPROCESSORS_ONLN = C._SC_NPROCESSORS_ONLN
_F_SETFD = C.F_SETFD
_F_SETFL = C.F_SETFL
_F_GETFD = C.F_GETFD
_F_GETFL = C.F_GETFL
_FD_CLOEXEC = C.FD_CLOEXEC
)
type sigset C.sigset_t
type siginfo C.siginfo_t
type timespec C.struct_timespec
type timestruc C.struct_timestruc_t
type timeval C.struct_timeval
type itimerval C.struct_itimerval
type stackt C.stack_t
type sigcontext C.struct_sigcontext
type ucontext C.ucontext_t
type _Ctype_struct___extctx uint64 // ucontext use a pointer to this structure but it shouldn't be used
type jmpbuf C.struct___jmpbuf
type context64 C.struct___context64
type sigactiont C.struct_sigaction
type tstate C.struct_tstate
type rusage C.struct_rusage
type pthread C.pthread_t
type pthread_attr C.pthread_attr_t
type semt C.sem_t
// 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 aix
package runtime
const (
_EPERM = 0x1
_ENOENT = 0x2
_EINTR = 0x4
_EAGAIN = 0xb
_ENOMEM = 0xc
_EACCES = 0xd
_EFAULT = 0xe
_EINVAL = 0x16
_ETIMEDOUT = 0x4e
_PROT_NONE = 0x0
_PROT_READ = 0x1
_PROT_WRITE = 0x2
_PROT_EXEC = 0x4
_MAP_ANONYMOUS = 0x10
_MAP_PRIVATE = 0x2
_MAP_FIXED = 0x100
_MADV_DONTNEED = 0x4
_SIGHUP = 0x1
_SIGINT = 0x2
_SIGQUIT = 0x3
_SIGILL = 0x4
_SIGTRAP = 0x5
_SIGABRT = 0x6
_SIGBUS = 0xa
_SIGFPE = 0x8
_SIGKILL = 0x9
_SIGUSR1 = 0x1e
_SIGSEGV = 0xb
_SIGUSR2 = 0x1f
_SIGPIPE = 0xd
_SIGALRM = 0xe
_SIGCHLD = 0x14
_SIGCONT = 0x13
_SIGSTOP = 0x11
_SIGTSTP = 0x12
_SIGTTIN = 0x15
_SIGTTOU = 0x16
_SIGURG = 0x10
_SIGXCPU = 0x18
_SIGXFSZ = 0x19
_SIGVTALRM = 0x22
_SIGPROF = 0x20
_SIGWINCH = 0x1c
_SIGIO = 0x17
_SIGPWR = 0x1d
_SIGSYS = 0xc
_SIGTERM = 0xf
_SIGEMT = 0x7
_SIGWAITING = 0x27
_FPE_INTDIV = 0x14
_FPE_INTOVF = 0x15
_FPE_FLTDIV = 0x16
_FPE_FLTOVF = 0x17
_FPE_FLTUND = 0x18
_FPE_FLTRES = 0x19
_FPE_FLTINV = 0x1a
_FPE_FLTSUB = 0x1b
_BUS_ADRALN = 0x1
_BUS_ADRERR = 0x2
_BUS_OBJERR = 0x3
_
_SEGV_MAPERR = 0x32
_SEGV_ACCERR = 0x33
_ITIMER_REAL = 0x0
_ITIMER_VIRTUAL = 0x1
_ITIMER_PROF = 0x2
_O_RDONLY = 0x0
_SS_DISABLE = 0x2
_SI_USER = 0x0
_SIG_BLOCK = 0x0
_SIG_UNBLOCK = 0x1
_SIG_SETMASK = 0x2
_SA_SIGINFO = 0x100
_SA_RESTART = 0x8
_SA_ONSTACK = 0x1
_PTHREAD_CREATE_DETACHED = 0x1
__SC_PAGE_SIZE = 0x30
__SC_NPROCESSORS_ONLN = 0x48
_F_SETFD = 0x2
_F_SETFL = 0x4
_F_GETFD = 0x1
_F_GETFL = 0x3
_FD_CLOEXEC = 0x1
)
type sigset [4]uint64
var sigset_all = sigset{^uint64(0), ^uint64(0), ^uint64(0), ^uint64(0)}
type siginfo struct {
si_signo int32
si_errno int32
si_code int32
si_pid int32
si_uid uint32
si_status int32
si_addr uintptr
si_band int64
si_value [2]int32 // [8]byte
__si_flags int32
__pad [3]int32
}
type timespec struct {
tv_sec int64
tv_nsec int64
}
type timeval struct {
tv_sec int64
tv_usec int32
pad_cgo_0 [4]byte
}
func (tv *timeval) set_usec(x int32) {
tv.tv_usec = x
}
type itimerval struct {
it_interval timeval
it_value timeval
}
type stackt struct {
ss_sp uintptr
ss_size uintptr
ss_flags int32
__pad [4]int32
pas_cgo_0 [4]byte
}
type sigcontext struct {
sc_onstack int32
pad_cgo_0 [4]byte
sc_mask sigset
sc_uerror int32
sc_jmpbuf context64
}
type ucontext struct {
__sc_onstack int32
pad_cgo_0 [4]byte
uc_sigmask sigset
__sc_error int32
pad_cgo_1 [4]byte
uc_mcontext context64
uc_link *ucontext
uc_stack stackt
__extctx uintptr // pointer to struct __extctx but we don't use it
__extctx_magic int32
__pad int32
}
type context64 struct {
gpr [32]uint64
msr uint64
iar uint64
lr uint64
ctr uint64
cr uint32
xer uint32
fpscr uint32
fpscrx uint32
except [1]uint64
fpr [32]float64
fpeu uint8
fpinfo uint8
fpscr24_31 uint8
pad [1]uint8
excp_type int32
}
type sigactiont struct {
sa_handler uintptr // a union of two pointer
sa_mask sigset
sa_flags int32
pad_cgo_0 [4]byte
}
type pthread uint32
type pthread_attr *byte
type semt int32
......@@ -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 js,wasm linux nacl netbsd openbsd solaris windows
// +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris windows
package runtime
......
......@@ -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
......
......@@ -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 nacl netbsd openbsd plan9 solaris windows
// +build aix darwin nacl netbsd openbsd plan9 solaris windows
package runtime
......
// 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"
)
// Don't split the stack as this method may be invoked without a valid G, which
// prevents us from allocating more stack.
//go:nosplit
func sysAlloc(n uintptr, sysStat *uint64) unsafe.Pointer {
p, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANONYMOUS|_MAP_PRIVATE, -1, 0)
if err != 0 {
if err == _EACCES {
print("runtime: mmap: access denied\n")
exit(2)
}
if err == _EAGAIN {
print("runtime: mmap: too much locked memory (check 'ulimit -l').\n")
exit(2)
}
//println("sysAlloc failed: ", err)
return nil
}
mSysStatInc(sysStat, n)
return p
}
func sysUnused(v unsafe.Pointer, n uintptr) {
madvise(v, n, _MADV_DONTNEED)
}
func sysUsed(v unsafe.Pointer, n uintptr) {
}
// Don't split the stack as this function may be invoked without a valid G,
// which prevents us from allocating more stack.
//go:nosplit
func sysFree(v unsafe.Pointer, n uintptr, sysStat *uint64) {
mSysStatDec(sysStat, n)
munmap(v, n)
}
func sysFault(v unsafe.Pointer, n uintptr) {
mmap(v, n, _PROT_NONE, _MAP_ANONYMOUS|_MAP_PRIVATE|_MAP_FIXED, -1, 0)
}
func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
p, err := mmap(v, n, _PROT_NONE, _MAP_ANONYMOUS|_MAP_PRIVATE, -1, 0)
if err != 0 {
return nil
}
return p
}
func sysMap(v unsafe.Pointer, n uintptr, sysStat *uint64) {
mSysStatInc(sysStat, n)
// AIX does not allow mapping a range that is already mapped.
// So always unmap first even if it is already unmapped.
munmap(v, n)
p, err := mmap(v, n, _PROT_READ|_PROT_WRITE, _MAP_ANONYMOUS|_MAP_FIXED|_MAP_PRIVATE, -1, 0)
if err == _ENOMEM {
throw("runtime: out of memory")
}
if p != v || err != 0 {
throw("runtime: cannot map pages in arena address space")
}
}
......@@ -10,6 +10,7 @@
// +build !linux !arm64
// +build !js
// +build !darwin
// +build !aix
package runtime
......
......@@ -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 js,wasm linux nacl netbsd openbsd solaris windows
// +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris windows
package runtime
......@@ -166,8 +166,8 @@ func poll_runtime_pollWait(pd *pollDesc, mode int) int {
if err != 0 {
return err
}
// As for now only Solaris uses level-triggered IO.
if GOOS == "solaris" {
// As for now only Solaris and AIX use level-triggered IO.
if GOOS == "solaris" || GOOS == "aix" {
netpollarm(pd, mode)
}
for !netpollblock(pd, int32(mode), false) {
......
// 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 is based on the former libgo/runtime/netpoll_select.c implementation
// except that it uses poll instead of select and is written in Go.
// It's also based on Solaris implementation for the arming mechanisms
//go:cgo_import_dynamic libc_poll poll "libc.a/shr_64.o"
//go:linkname libc_poll libc_poll
var libc_poll libFunc
//go:nosplit
func poll(pfds *pollfd, npfds uintptr, timeout uintptr) (int32, int32) {
r, err := syscall3(&libc_poll, uintptr(unsafe.Pointer(pfds)), npfds, timeout)
return int32(r), int32(err)
}
//go:nosplit
func fcntl(fd, cmd int32, arg uintptr) int32 {
r, _ := syscall3(&libc_fcntl, uintptr(fd), uintptr(cmd), arg)
return int32(r)
}
// pollfd represents the poll structure for AIX operating system.
type pollfd struct {
fd int32
events int16
revents int16
}
const _POLLIN = 0x0001
const _POLLOUT = 0x0002
const _POLLHUP = 0x2000
const _POLLERR = 0x4000
const _O_NONBLOCK = 0x4
var (
pfds []pollfd
pds []*pollDesc
mtxpoll mutex
mtxset mutex
rdwake int32
wrwake int32
pendingUpdates int32
)
const pollVerbose = false
func netpollinit() {
var p [2]int32
// Create the pipe we use to wakeup poll.
if err := pipe(&p[0]); err < 0 {
throw("netpollinit: failed to create pipe")
}
rdwake = p[0]
wrwake = p[1]
fl := uintptr(fcntl(rdwake, _F_GETFL, 0))
fcntl(rdwake, _F_SETFL, fl|_O_NONBLOCK)
fcntl(rdwake, _F_SETFD, _FD_CLOEXEC)
fl = uintptr(fcntl(wrwake, _F_GETFL, 0))
fcntl(wrwake, _F_SETFL, fl|_O_NONBLOCK)
fcntl(wrwake, _F_SETFD, _FD_CLOEXEC)
// Pre-allocate array of pollfd structures for poll.
if pollVerbose {
println("*** allocating")
}
pfds = make([]pollfd, 1, 128)
if pollVerbose {
println("*** allocating done", &pfds[0])
}
// Poll the read side of the pipe.
pfds[0].fd = rdwake
pfds[0].events = _POLLIN
pds = make([]*pollDesc, 1, 128)
pds[0] = nil
}
func netpolldescriptor() uintptr {
// Both fd must be returned
if rdwake > 0xFFFF || wrwake > 0xFFFF {
throw("netpolldescriptor: invalid fd number")
}
return uintptr(rdwake<<16 | wrwake)
}
// netpollwakeup writes on wrwake to wakeup poll before any changes.
func netpollwakeup() {
if pendingUpdates == 0 {
pendingUpdates = 1
if pollVerbose {
println("*** writing 1 byte")
}
b := [1]byte{0}
write(uintptr(wrwake), unsafe.Pointer(&b[0]), 1)
}
}
func netpollopen(fd uintptr, pd *pollDesc) int32 {
if pollVerbose {
println("*** netpollopen", fd)
}
lock(&mtxpoll)
netpollwakeup()
lock(&mtxset)
unlock(&mtxpoll)
pd.user = uint32(len(pfds))
pfds = append(pfds, pollfd{fd: int32(fd)})
pds = append(pds, pd)
unlock(&mtxset)
return 0
}
func netpollclose(fd uintptr) int32 {
if pollVerbose {
println("*** netpollclose", fd)
}
lock(&mtxpoll)
netpollwakeup()
lock(&mtxset)
unlock(&mtxpoll)
for i := 0; i < len(pfds); i++ {
if pfds[i].fd == int32(fd) {
pfds[i] = pfds[len(pfds)-1]
pfds = pfds[:len(pfds)-1]
pds[i] = pds[len(pds)-1]
pds[i].user = uint32(i)
pds = pds[:len(pds)-1]
break
}
}
unlock(&mtxset)
return 0
}
func netpollarm(pd *pollDesc, mode int) {
if pollVerbose {
println("*** netpollarm", pd.fd, mode)
}
lock(&mtxpoll)
netpollwakeup()
lock(&mtxset)
unlock(&mtxpoll)
switch mode {
case 'r':
pfds[pd.user].events |= _POLLIN
case 'w':
pfds[pd.user].events |= _POLLOUT
}
unlock(&mtxset)
}
//go:nowritebarrierrec
func netpoll(block bool) gList {
timeout := ^uintptr(0)
if !block {
timeout = 0
return gList{}
}
if pollVerbose {
println("*** netpoll", block)
}
retry:
lock(&mtxpoll)
lock(&mtxset)
pendingUpdates = 0
unlock(&mtxpoll)
if pollVerbose {
println("*** netpoll before poll")
}
n, e := poll(&pfds[0], uintptr(len(pfds)), timeout)
if pollVerbose {
println("*** netpoll after poll", n)
}
if n < 0 {
if e != _EINTR {
println("errno=", e, " len(pfds)=", len(pfds))
throw("poll failed")
}
if pollVerbose {
println("*** poll failed")
}
unlock(&mtxset)
goto retry
}
// Check if some descriptors need to be changed
if n != 0 && pfds[0].revents&(_POLLIN|_POLLHUP|_POLLERR) != 0 {
var b [1]byte
for read(rdwake, unsafe.Pointer(&b[0]), 1) == 1 {
if pollVerbose {
println("*** read 1 byte from pipe")
}
}
// Do not look at the other fds in this case as the mode may have changed
// XXX only additions of flags are made, so maybe it is ok
unlock(&mtxset)
goto retry
}
var toRun gList
for i := 0; i < len(pfds) && n > 0; i++ {
pfd := &pfds[i]
var mode int32
if pfd.revents&(_POLLIN|_POLLHUP|_POLLERR) != 0 {
mode += 'r'
pfd.events &= ^_POLLIN
}
if pfd.revents&(_POLLOUT|_POLLHUP|_POLLERR) != 0 {
mode += 'w'
pfd.events &= ^_POLLOUT
}
if mode != 0 {
if pollVerbose {
println("*** netpollready i=", i, "revents=", pfd.revents, "events=", pfd.events, "pd=", pds[i])
}
netpollready(&toRun, pds[i], mode)
n--
}
}
unlock(&mtxset)
if block && toRun.empty() {
goto retry
}
if pollVerbose {
println("*** netpoll returning end")
}
return toRun
}
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.
// +build aix
package runtime
import (
"unsafe"
)
const (
threadStackSize = 0x100000 // size of a thread stack allocated by OS
)
// funcDescriptor is a structure representing a function descriptor
// A variable with this type is always created in assembler
type funcDescriptor struct {
fn uintptr
toc uintptr
envPointer uintptr // unused in Golang
}
type mOS struct {
waitsema uintptr // semaphore for parking on locks
perrno uintptr // pointer to tls errno
}
//go:nosplit
func semacreate(mp *m) {
if mp.waitsema != 0 {
return
}
var sem *semt
// Call libc's malloc rather than malloc. This will
// allocate space on the C heap. We can't call mallocgc
// here because it could cause a deadlock.
sem = (*semt)(malloc(unsafe.Sizeof(*sem)))
if sem_init(sem, 0, 0) != 0 {
throw("sem_init")
}
mp.waitsema = uintptr(unsafe.Pointer(sem))
}
//go:nosplit
func semasleep(ns int64) int32 {
_m_ := getg().m
if ns >= 0 {
var ts timespec
if clock_gettime(_CLOCK_REALTIME, &ts) != 0 {
throw("clock_gettime")
}
ts.tv_sec += ns / 1e9
ts.tv_nsec += ns % 1e9
if ts.tv_nsec >= 1e9 {
ts.tv_sec++
ts.tv_nsec -= 1e9
}
if r, err := sem_timedwait((*semt)(unsafe.Pointer(_m_.waitsema)), &ts); r != 0 {
if err == _ETIMEDOUT || err == _EAGAIN || err == _EINTR {
return -1
}
println("sem_timedwait err ", err, " ts.tv_sec ", ts.tv_sec, " ts.tv_nsec ", ts.tv_nsec, " ns ", ns, " id ", _m_.id)
throw("sem_timedwait")
}
return 0
}
for {
r1, err := sem_wait((*semt)(unsafe.Pointer(_m_.waitsema)))
if r1 == 0 {
break
}
if err == _EINTR {
continue
}
throw("sem_wait")
}
return 0
}
//go:nosplit
func semawakeup(mp *m) {
if sem_post((*semt)(unsafe.Pointer(mp.waitsema))) != 0 {
throw("sem_post")
}
}
func osinit() {
ncpu = int32(sysconf(__SC_NPROCESSORS_ONLN))
physPageSize = sysconf(__SC_PAGE_SIZE)
}
// Ms related functions
func mpreinit(mp *m) {
mp.gsignal = malg(32 * 1024) // AIX wants >= 8K
mp.gsignal.m = mp
}
// errno address must be retrieved by calling _Errno libc function.
// This will return a pointer to errno
func miniterrno() {
mp := getg().m
r, _ := syscall0(&libc__Errno)
mp.perrno = r
}
func minit() {
miniterrno()
minitSignals()
}
func unminit() {
unminitSignals()
}
// tstart is a function descriptor to _tstart defined in assembly.
var tstart funcDescriptor
func newosproc(mp *m) {
var (
attr pthread_attr
oset sigset
tid pthread
)
if pthread_attr_init(&attr) != 0 {
throw("pthread_attr_init")
}
if pthread_attr_setstacksize(&attr, threadStackSize) != 0 {
throw("pthread_attr_getstacksize")
}
if pthread_attr_setdetachstate(&attr, _PTHREAD_CREATE_DETACHED) != 0 {
throw("pthread_attr_setdetachstate")
}
// Disable signals during create, so that the new thread starts
// with signals disabled. It will enable them in minit.
sigprocmask(_SIG_SETMASK, &sigset_all, &oset)
var ret int32
for tries := 0; tries < 20; tries++ {
// pthread_create can fail with EAGAIN for no reasons
// but it will be ok if it retries.
ret = pthread_create(&tid, &attr, &tstart, unsafe.Pointer(mp))
if ret != _EAGAIN {
break
}
usleep(uint32(tries+1) * 1000) // Milliseconds.
}
sigprocmask(_SIG_SETMASK, &oset, nil)
if ret != 0 {
print("runtime: failed to create new OS thread (have ", mcount(), " already; errno=", ret, ")\n")
if ret == _EAGAIN {
println("runtime: may need to increase max user processes (ulimit -u)")
}
throw("newosproc")
}
}
func exitThread(wait *uint32) {
// We should never reach exitThread on AIX because we let
// libc clean up threads.
throw("exitThread")
}
var urandom_dev = []byte("/dev/urandom\x00")
//go:nosplit
func getRandomData(r []byte) {
fd := open(&urandom_dev[0], 0 /* O_RDONLY */, 0)
n := read(fd, unsafe.Pointer(&r[0]), int32(len(r)))
closefd(fd)
extendRandom(r, int(n))
}
func goenvs() {
goenvs_unix()
}
/* SIGNAL */
const (
_NSIG = 256
)
// sigtramp is a function descriptor to _sigtramp defined in assembly
var sigtramp funcDescriptor
//go:nosplit
//go:nowritebarrierrec
func setsig(i uint32, fn uintptr) {
var sa sigactiont
sa.sa_flags = _SA_SIGINFO | _SA_ONSTACK | _SA_RESTART
sa.sa_mask = sigset_all
if fn == funcPC(sighandler) {
fn = uintptr(unsafe.Pointer(&sigtramp))
}
sa.sa_handler = fn
sigaction(uintptr(i), &sa, nil)
}
//go:nosplit
//go:nowritebarrierrec
func setsigstack(i uint32) {
throw("Not yet implemented\n")
}
//go:nosplit
//go:nowritebarrierrec
func getsig(i uint32) uintptr {
var sa sigactiont
sigaction(uintptr(i), nil, &sa)
return sa.sa_handler
}
// setSignaltstackSP sets the ss_sp field of a stackt.
//go:nosplit
func setSignalstackSP(s *stackt, sp uintptr) {
*(*uintptr)(unsafe.Pointer(&s.ss_sp)) = sp
}
func (c *sigctxt) fixsigcode(sig uint32) {
}
func sigaddset(mask *sigset, i int) {
(*mask)[(i-1)/64] |= 1 << ((uint32(i) - 1) & 63)
}
func sigdelset(mask *sigset, i int) {
(*mask)[(i-1)/64] &^= 1 << ((uint32(i) - 1) & 63)
}
const (
_CLOCK_REALTIME = 9
_CLOCK_MONOTONIC = 10
)
//go:nosplit
func nanotime() int64 {
tp := &timespec{}
if clock_gettime(_CLOCK_REALTIME, tp) != 0 {
throw("syscall clock_gettime failed")
}
return tp.tv_sec*1000000000 + tp.tv_nsec
}
func walltime() (sec int64, nsec int32) {
ts := &timespec{}
if clock_gettime(_CLOCK_REALTIME, ts) != 0 {
throw("syscall clock_gettime failed")
}
return ts.tv_sec, int32(ts.tv_nsec)
}
......@@ -1172,8 +1172,8 @@ func mstart() {
mstart1()
// Exit this thread.
if GOOS == "windows" || GOOS == "solaris" || GOOS == "plan9" || GOOS == "darwin" {
// Window, Solaris, Darwin and Plan 9 always system-allocate
if GOOS == "windows" || GOOS == "solaris" || GOOS == "plan9" || GOOS == "darwin" || GOOS == "aix" {
// Window, Solaris, Darwin, AIX and Plan 9 always system-allocate
// the stack, but put it in _g_.stack before mstart,
// so the logic above hasn't set osStack yet.
osStack = true
......
// 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.
#include "textflag.h"
// _rt0_ppc64_aix is a function descriptor of the entrypoint function
// __start. This name is needed by cmd/link.
DATA _rt0_ppc64_aix+0(SB)/8, $__start<>(SB)
DATA _rt0_ppc64_aix+8(SB)/8, $TOC(SB)
GLOBL _rt0_ppc64_aix(SB), NOPTR, $16
// The starting function must return in the loader to
// initialise some librairies, especially libthread which
// creates the main thread and adds the TLS in R13
// R19 contains a function descriptor to the loader function
// which needs to be called.
// This code is similar to the __start function in C
TEXT __start<>(SB),NOSPLIT,$-8
XOR R0, R0
MOVD $libc___n_pthreads(SB), R4
MOVD 0(R4), R4
MOVD $libc___mod_init(SB), R5
MOVD 0(R5), R5
MOVD 0(R19), R0
MOVD R2, 40(R1)
MOVD 8(R19), R2
MOVD R18, R3
MOVD R0, CTR
BL (CTR) // Return to AIX loader
// Launch rt0_go
MOVD 40(R1), R2
MOVD R14, R3 // argc
MOVD R15, R4 // argv
MOVD $runtime·rt0_go(SB), R12
MOVD R12, CTR
BR (CTR)
......@@ -6,7 +6,7 @@
// We need a fast system call to provoke the race,
// and Close(-1) is nearly universally fast.
// +build darwin dragonfly freebsd linux netbsd openbsd plan9
// +build aix darwin dragonfly freebsd linux netbsd openbsd plan9
package runtime_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.
// +build aix
package runtime
import (
"runtime/internal/sys"
"unsafe"
)
type sigctxt struct {
info *siginfo
ctxt unsafe.Pointer
}
//go:nosplit
//go:nowritebarrierrec
func (c *sigctxt) regs() *context64 { return &(*ucontext)(c.ctxt).uc_mcontext }
func (c *sigctxt) r0() uint64 { return c.regs().gpr[0] }
func (c *sigctxt) r1() uint64 { return c.regs().gpr[1] }
func (c *sigctxt) r2() uint64 { return c.regs().gpr[2] }
func (c *sigctxt) r3() uint64 { return c.regs().gpr[3] }
func (c *sigctxt) r4() uint64 { return c.regs().gpr[4] }
func (c *sigctxt) r5() uint64 { return c.regs().gpr[5] }
func (c *sigctxt) r6() uint64 { return c.regs().gpr[6] }
func (c *sigctxt) r7() uint64 { return c.regs().gpr[7] }
func (c *sigctxt) r8() uint64 { return c.regs().gpr[8] }
func (c *sigctxt) r9() uint64 { return c.regs().gpr[9] }
func (c *sigctxt) r10() uint64 { return c.regs().gpr[10] }
func (c *sigctxt) r11() uint64 { return c.regs().gpr[11] }
func (c *sigctxt) r12() uint64 { return c.regs().gpr[12] }
func (c *sigctxt) r13() uint64 { return c.regs().gpr[13] }
func (c *sigctxt) r14() uint64 { return c.regs().gpr[14] }
func (c *sigctxt) r15() uint64 { return c.regs().gpr[15] }
func (c *sigctxt) r16() uint64 { return c.regs().gpr[16] }
func (c *sigctxt) r17() uint64 { return c.regs().gpr[17] }
func (c *sigctxt) r18() uint64 { return c.regs().gpr[18] }
func (c *sigctxt) r19() uint64 { return c.regs().gpr[19] }
func (c *sigctxt) r20() uint64 { return c.regs().gpr[20] }
func (c *sigctxt) r21() uint64 { return c.regs().gpr[21] }
func (c *sigctxt) r22() uint64 { return c.regs().gpr[22] }
func (c *sigctxt) r23() uint64 { return c.regs().gpr[23] }
func (c *sigctxt) r24() uint64 { return c.regs().gpr[24] }
func (c *sigctxt) r25() uint64 { return c.regs().gpr[25] }
func (c *sigctxt) r26() uint64 { return c.regs().gpr[26] }
func (c *sigctxt) r27() uint64 { return c.regs().gpr[27] }
func (c *sigctxt) r28() uint64 { return c.regs().gpr[28] }
func (c *sigctxt) r29() uint64 { return c.regs().gpr[29] }
func (c *sigctxt) r30() uint64 { return c.regs().gpr[30] }
func (c *sigctxt) r31() uint64 { return c.regs().gpr[31] }
func (c *sigctxt) sp() uint64 { return c.regs().gpr[1] }
//go:nosplit
//go:nowritebarrierrec
func (c *sigctxt) pc() uint64 { return c.regs().iar }
func (c *sigctxt) ctr() uint64 { return c.regs().ctr }
func (c *sigctxt) link() uint64 { return c.regs().lr }
func (c *sigctxt) xer() uint32 { return c.regs().xer }
func (c *sigctxt) ccr() uint32 { return c.regs().cr }
func (c *sigctxt) fpscr() uint32 { return c.regs().fpscr }
func (c *sigctxt) fpscrx() uint32 { return c.regs().fpscrx }
// TODO(aix): find trap equivalent
func (c *sigctxt) trap() uint32 { return 0x0 }
func (c *sigctxt) sigcode() uint32 { return uint32(c.info.si_code) }
func (c *sigctxt) sigaddr() uint64 { return uint64(c.info.si_addr) }
func (c *sigctxt) fault() uintptr { return uintptr(c.sigaddr()) }
func (c *sigctxt) set_r0(x uint64) { c.regs().gpr[0] = x }
func (c *sigctxt) set_r12(x uint64) { c.regs().gpr[12] = x }
func (c *sigctxt) set_r30(x uint64) { c.regs().gpr[30] = x }
func (c *sigctxt) set_pc(x uint64) { c.regs().iar = x }
func (c *sigctxt) set_sp(x uint64) { c.regs().gpr[1] = x }
func (c *sigctxt) set_link(x uint64) { c.regs().lr = x }
func (c *sigctxt) set_sigcode(x uint32) { c.info.si_code = int32(x) }
func (c *sigctxt) set_sigaddr(x uint64) {
*(*uintptr)(add(unsafe.Pointer(c.info), 2*sys.PtrSize)) = uintptr(x)
}
......@@ -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 linux
// +build aix linux
// +build ppc64 ppc64le
package runtime
......
......@@ -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 runtime
......
......@@ -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
......
This diff is collapsed.
......@@ -8,6 +8,7 @@
// +build !nacl
// +build !js
// +build !darwin
// +build !aix
package runtime
......
......@@ -8,6 +8,7 @@
// +build !nacl
// +build !freebsd
// +build !darwin
// +build !aix
package runtime
......
// 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 aix
// +build ppc64 ppc64le
//
// System calls and other sys.stuff for ppc64, Aix
//
#include "go_asm.h"
#include "go_tls.h"
#include "textflag.h"
#include "asm_ppc64x.h"
// This function calls a C function with the function descriptor in R12
TEXT runtime·callCfunction(SB), NOSPLIT|NOFRAME,$0
MOVD 0(R12), R12
MOVD R2, 40(R1)
MOVD 0(R12), R0
MOVD 8(R12), R2
MOVD R0, CTR
BR (CTR)
// asmsyscall6 calls a library function with a function descriptor
// stored in libcall_fn and store the results in libcall struture
// Up to 6 arguments can be passed to this C function
// Called by runtime.asmcgocall
// It reserves a stack of 288 bytes for the C function.
// NOT USING GO CALLING CONVENTION
TEXT runtime·asmsyscall6(SB),NOSPLIT,$256
MOVD R3, 48(R1) // Save libcall for later
MOVD libcall_fn(R3), R12
MOVD libcall_args(R3), R9
MOVD 0(R9), R3
MOVD 8(R9), R4
MOVD 16(R9), R5
MOVD 24(R9), R6
MOVD 32(R9), R7
MOVD 40(R9), R8
BL runtime·callCfunction(SB)
// Restore R0 and TOC
XOR R0, R0
MOVD 40(R1), R2
// Store result in libcall
MOVD 48(R1), R5
MOVD R3, (libcall_r1)(R5)
MOVD $-1, R6
CMP R6, R3
BNE skiperrno
// Save errno in libcall
BL runtime·load_g(SB)
MOVD g_m(g), R4
MOVD (m_mOS + mOS_perrno)(R4), R9
MOVW 0(R9), R9
MOVD R9, (libcall_err)(R5)
RET
skiperrno:
// Reset errno if no error has been returned
MOVD R0, (libcall_err)(R5)
RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
MOVW sig+8(FP), R3
MOVD info+16(FP), R4
MOVD ctx+24(FP), R5
MOVD fn+0(FP), R12
MOVD R12, CTR
BL (CTR)
RET
// runtime.sigtramp is a function descriptor to the real sigtramp.
DATA runtime·sigtramp+0(SB)/8, $runtime·_sigtramp(SB)
DATA runtime·sigtramp+8(SB)/8, $TOC(SB)
DATA runtime·sigtramp+16(SB)/8, $0
GLOBL runtime·sigtramp(SB), NOPTR, $24
// This funcion must not have any frame as we want to control how
// every registers are used.
TEXT runtime·_sigtramp(SB),NOSPLIT|NOFRAME,$0
MOVD LR, R0
MOVD R0, 16(R1)
// initialize essential registers (just in case)
BL runtime·reginit(SB)
// Note that we are executing on altsigstack here, so we have
// more stack available than NOSPLIT would have us believe.
// To defeat the linker, we make our own stack frame with
// more space.
SUB $128+FIXED_FRAME, R1
// Save registers
MOVD R31, 56(R1)
MOVD g, 64(R1)
MOVD R29, 72(R1)
BL runtime·load_g(SB)
// Save m->libcall. We need to do this because we
// might get interrupted by a signal in runtime·asmcgocall.
// save m->libcall
MOVD g_m(g), R6
MOVD (m_libcall+libcall_fn)(R6), R7
MOVD R7, 80(R1)
MOVD (m_libcall+libcall_args)(R6), R7
MOVD R7, 88(R1)
MOVD (m_libcall+libcall_n)(R6), R7
MOVD R7, 96(R1)
MOVD (m_libcall+libcall_r1)(R6), R7
MOVD R7, 104(R1)
MOVD (m_libcall+libcall_r2)(R6), R7
MOVD R7, 112(R1)
// save errno, it might be EINTR; stuff we do here might reset it.
MOVD (m_mOS+mOS_perrno)(R6), R8
MOVD 0(R8), R8
MOVD R8, 120(R1)
MOVW R3, FIXED_FRAME+0(R1)
MOVD R4, FIXED_FRAME+8(R1)
MOVD R5, FIXED_FRAME+16(R1)
MOVD $runtime·sigtrampgo(SB), R12
MOVD R12, CTR
BL (CTR)
MOVD g_m(g), R6
// restore libcall
MOVD 80(R1), R7
MOVD R7, (m_libcall+libcall_fn)(R6)
MOVD 88(R1), R7
MOVD R7, (m_libcall+libcall_args)(R6)
MOVD 96(R1), R7
MOVD R7, (m_libcall+libcall_n)(R6)
MOVD 104(R1), R7
MOVD R7, (m_libcall+libcall_r1)(R6)
MOVD 112(R1), R7
MOVD R7, (m_libcall+libcall_r2)(R6)
// restore errno
MOVD (m_mOS+mOS_perrno)(R6), R7
MOVD 120(R1), R8
MOVD R8, 0(R7)
// restore registers
MOVD 56(R1),R31
MOVD 64(R1),g
MOVD 72(R1),R29
// Don't use RET because we need to restore R31 !
ADD $128+FIXED_FRAME, R1
MOVD 16(R1), R0
MOVD R0, LR
BR (LR)
// runtime.tstart is a function descriptor to the real tstart.
DATA runtime·tstart+0(SB)/8, $runtime·_tstart(SB)
DATA runtime·tstart+8(SB)/8, $TOC(SB)
DATA runtime·tstart+16(SB)/8, $0
GLOBL runtime·tstart(SB), NOPTR, $24
TEXT runtime·_tstart(SB),NOSPLIT,$0
XOR R0, R0 // reset R0
// set g
MOVD m_g0(R3), g
BL runtime·save_g(SB)
MOVD R3, g_m(g)
// Layout new m scheduler stack on os stack.
MOVD R1, R3
MOVD R3, (g_stack+stack_hi)(g)
SUB $(const_threadStackSize), R3 // stack size
MOVD R3, (g_stack+stack_lo)(g)
ADD $const__StackGuard, R3
MOVD R3, g_stackguard0(g)
MOVD R3, g_stackguard1(g)
BL runtime·mstart(SB)
MOVD R0, R3
RET
// Runs on OS stack, called from runtime·osyield.
TEXT runtime·osyield1(SB),NOSPLIT,$0
MOVD $libc_sched_yield(SB), R12
MOVD 0(R12), R12
MOVD R2, 40(R1)
MOVD 0(R12), R0
MOVD 8(R12), R2
MOVD R0, CTR
BL (CTR)
MOVD 40(R1), R2
RET
......@@ -5,6 +5,7 @@
// +build !darwin
// +build !windows
// +build !freebsd
// +build !aix
package runtime
......
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