2016-03-01 15:57:46 -07:00
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
2014-11-21 11:39:01 -07:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
2015-11-02 12:09:24 -07:00
|
|
|
import (
|
|
|
|
"runtime/internal/atomic"
|
|
|
|
"unsafe"
|
|
|
|
)
|
2014-11-21 11:39:01 -07:00
|
|
|
|
2016-05-06 09:26:37 -06:00
|
|
|
type mOS struct {
|
|
|
|
waitsemacount uint32
|
|
|
|
notesig *int8
|
|
|
|
errstr *byte
|
2016-11-11 12:49:11 -07:00
|
|
|
ignoreHangup bool
|
2016-05-06 09:26:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func closefd(fd int32) int32
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func open(name *byte, mode, perm int32) int32
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func pread(fd int32, buf unsafe.Pointer, nbytes int32, offset int64) int32
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func pwrite(fd int32, buf unsafe.Pointer, nbytes int32, offset int64) int32
|
|
|
|
|
|
|
|
func seek(fd int32, offset int64, whence int32) int64
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func exits(msg *byte)
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func brk_(addr unsafe.Pointer) int32
|
|
|
|
|
|
|
|
func sleep(ms int32) int32
|
|
|
|
|
|
|
|
func rfork(flags int32) int32
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func plan9_semacquire(addr *uint32, block int32) int32
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func plan9_tsemacquire(addr *uint32, ms int32) int32
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func plan9_semrelease(addr *uint32, count int32) int32
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func notify(fn unsafe.Pointer) int32
|
|
|
|
|
|
|
|
func noted(mode int32) int32
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func nsec(*int64) int64
|
|
|
|
|
|
|
|
//go:noescape
|
2016-10-25 07:44:58 -06:00
|
|
|
func sigtramp(ureg, note unsafe.Pointer)
|
2016-05-06 09:26:37 -06:00
|
|
|
|
|
|
|
func setfpmasks()
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func tstart_plan9(newm *m)
|
|
|
|
|
|
|
|
func errstr() string
|
|
|
|
|
|
|
|
type _Plink uintptr
|
|
|
|
|
|
|
|
//go:linkname os_sigpipe os.sigpipe
|
|
|
|
func os_sigpipe() {
|
|
|
|
throw("too many writes on closed pipe")
|
|
|
|
}
|
|
|
|
|
|
|
|
func sigpanic() {
|
|
|
|
g := getg()
|
|
|
|
if !canpanic(g) {
|
|
|
|
throw("unexpected signal during runtime execution")
|
|
|
|
}
|
|
|
|
|
|
|
|
note := gostringnocopy((*byte)(unsafe.Pointer(g.m.notesig)))
|
|
|
|
switch g.sig {
|
|
|
|
case _SIGRFAULT, _SIGWFAULT:
|
|
|
|
i := index(note, "addr=")
|
|
|
|
if i >= 0 {
|
|
|
|
i += 5
|
|
|
|
} else if i = index(note, "va="); i >= 0 {
|
|
|
|
i += 3
|
|
|
|
} else {
|
|
|
|
panicmem()
|
|
|
|
}
|
|
|
|
addr := note[i:]
|
|
|
|
g.sigcode1 = uintptr(atolwhex(addr))
|
|
|
|
if g.sigcode1 < 0x1000 || g.paniconfault {
|
|
|
|
panicmem()
|
|
|
|
}
|
|
|
|
print("unexpected fault address ", hex(g.sigcode1), "\n")
|
|
|
|
throw("fault")
|
|
|
|
case _SIGTRAP:
|
|
|
|
if g.paniconfault {
|
|
|
|
panicmem()
|
|
|
|
}
|
|
|
|
throw(note)
|
|
|
|
case _SIGINTDIV:
|
|
|
|
panicdivide()
|
|
|
|
case _SIGFLOAT:
|
|
|
|
panicfloat()
|
|
|
|
default:
|
|
|
|
panic(errorString(note))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func atolwhex(p string) int64 {
|
|
|
|
for hasprefix(p, " ") || hasprefix(p, "\t") {
|
|
|
|
p = p[1:]
|
|
|
|
}
|
|
|
|
neg := false
|
|
|
|
if hasprefix(p, "-") || hasprefix(p, "+") {
|
|
|
|
neg = p[0] == '-'
|
|
|
|
p = p[1:]
|
|
|
|
for hasprefix(p, " ") || hasprefix(p, "\t") {
|
|
|
|
p = p[1:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var n int64
|
|
|
|
switch {
|
|
|
|
case hasprefix(p, "0x"), hasprefix(p, "0X"):
|
|
|
|
p = p[2:]
|
|
|
|
for ; len(p) > 0; p = p[1:] {
|
|
|
|
if '0' <= p[0] && p[0] <= '9' {
|
|
|
|
n = n*16 + int64(p[0]-'0')
|
|
|
|
} else if 'a' <= p[0] && p[0] <= 'f' {
|
|
|
|
n = n*16 + int64(p[0]-'a'+10)
|
|
|
|
} else if 'A' <= p[0] && p[0] <= 'F' {
|
|
|
|
n = n*16 + int64(p[0]-'A'+10)
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case hasprefix(p, "0"):
|
|
|
|
for ; len(p) > 0 && '0' <= p[0] && p[0] <= '7'; p = p[1:] {
|
|
|
|
n = n*8 + int64(p[0]-'0')
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
for ; len(p) > 0 && '0' <= p[0] && p[0] <= '9'; p = p[1:] {
|
|
|
|
n = n*10 + int64(p[0]-'0')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if neg {
|
|
|
|
n = -n
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
runtime: use a proper type, sigset, for m.sigmask
Replace the cross platform but unsafe [4]uintptr type with a OS
specific type, sigset. Most OSes already define sigset, and this
change defines a suitable sigset for the OSes that don't (darwin,
openbsd). The OSes that don't use m.sigmask (windows, plan9, nacl)
now defines sigset as the empty type, struct{}.
The gain is strongly typed access to m.sigmask, saving a dynamic
size sanity check and unsafe.Pointer casting. Also, some storage is
saved for each M, since [4]uinptr was conservative for most OSes.
The cost is that OSes that don't need m.sigmask has to define sigset.
completes ./all.bash with GOOS linux, on amd64
completes ./make.bash with GOOSes openbsd, android, plan9, windows,
darwin, solaris, netbsd, freebsd, dragonfly, all amd64.
With GOOS=nacl ./make.bash failed with a seemingly unrelated error.
[Replay of CL 16942 by Elias Naur.]
Change-Id: I98f144d626033ae5318576115ed635415ac71b2c
Reviewed-on: https://go-review.googlesource.com/17033
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
2015-11-17 03:41:06 -07:00
|
|
|
type sigset struct{}
|
|
|
|
|
2014-11-21 11:39:01 -07:00
|
|
|
// Called to initialize a new m (including the bootstrap m).
|
|
|
|
// Called on the parent thread (main thread in case of bootstrap), can allocate memory.
|
|
|
|
func mpreinit(mp *m) {
|
|
|
|
// Initialize stack and goroutine for note handling.
|
|
|
|
mp.gsignal = malg(32 * 1024)
|
|
|
|
mp.gsignal.m = mp
|
2016-04-19 20:35:10 -06:00
|
|
|
mp.notesig = (*int8)(mallocgc(_ERRMAX, nil, true))
|
2014-11-21 11:39:01 -07:00
|
|
|
// Initialize stack for handling strings from the
|
|
|
|
// errstr system call, as used in package syscall.
|
2016-04-19 20:35:10 -06:00
|
|
|
mp.errstr = (*byte)(mallocgc(_ERRMAX, nil, true))
|
2014-11-21 11:39:01 -07:00
|
|
|
}
|
|
|
|
|
runtime: don't always unblock all signals
Ian proposed an improved way of handling signals masks in Go, motivated
by a problem where the Android java runtime expects certain signals to
be blocked for all JVM threads. Discussion here
https://groups.google.com/forum/#!topic/golang-dev/_TSCkQHJt6g
Ian's text is used in the following:
A Go program always needs to have the synchronous signals enabled.
These are the signals for which _SigPanic is set in sigtable, namely
SIGSEGV, SIGBUS, SIGFPE.
A Go program that uses the os/signal package, and calls signal.Notify,
needs to have at least one thread which is not blocking that signal,
but it doesn't matter much which one.
Unix programs do not change signal mask across execve. They inherit
signal masks across fork. The shell uses this fact to some extent;
for example, the job control signals (SIGTTIN, SIGTTOU, SIGTSTP) are
blocked for commands run due to backquote quoting or $().
Our current position on signal masks was not thought out. We wandered
into step by step, e.g., http://golang.org/cl/7323067 .
This CL does the following:
Introduce a new platform hook, msigsave, that saves the signal mask of
the current thread to m.sigsave.
Call msigsave from needm and newm.
In minit grab set up the signal mask from m.sigsave and unblock the
essential synchronous signals, and SIGILL, SIGTRAP, SIGPROF, SIGSTKFLT
(for systems that have it).
In unminit, restore the signal mask from m.sigsave.
The first time that os/signal.Notify is called, start a new thread whose
only purpose is to update its signal mask to make sure signals for
signal.Notify are unblocked on at least one thread.
The effect on Go programs will be that if they are invoked with some
non-synchronous signals blocked, those signals will normally be
ignored. Previously, those signals would mostly be ignored. A change
in behaviour will occur for programs started with any of these signals
blocked, if they receive the signal: SIGHUP, SIGINT, SIGQUIT, SIGABRT,
SIGTERM. Previously those signals would always cause a crash (unless
using the os/signal package); with this change, they will be ignored
if the program is started with the signal blocked (and does not use
the os/signal package).
./all.bash completes successfully on linux/amd64.
OpenBSD is missing the implementation.
Change-Id: I188098ba7eb85eae4c14861269cc466f2aa40e8c
Reviewed-on: https://go-review.googlesource.com/10173
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-05-18 03:00:24 -06:00
|
|
|
func msigsave(mp *m) {
|
|
|
|
}
|
|
|
|
|
2016-01-12 16:34:03 -07:00
|
|
|
func msigrestore(sigmask sigset) {
|
2015-11-13 14:21:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func sigblock() {
|
|
|
|
}
|
|
|
|
|
2014-11-21 11:39:01 -07:00
|
|
|
// Called to initialize a new m (including the bootstrap m).
|
2016-01-27 13:49:13 -07:00
|
|
|
// Called on the new thread, cannot allocate memory.
|
2014-11-21 11:39:01 -07:00
|
|
|
func minit() {
|
2016-03-25 06:50:35 -06:00
|
|
|
if atomic.Load(&exiting) != 0 {
|
|
|
|
exits(&emptystatus[0])
|
|
|
|
}
|
2014-11-21 11:39:01 -07:00
|
|
|
// Mask all SSE floating-point exceptions
|
|
|
|
// when running on the 64-bit kernel.
|
|
|
|
setfpmasks()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called from dropm to undo the effect of an minit.
|
|
|
|
func unminit() {
|
|
|
|
}
|
|
|
|
|
|
|
|
var sysstat = []byte("/dev/sysstat\x00")
|
|
|
|
|
|
|
|
func getproccount() int32 {
|
|
|
|
var buf [2048]byte
|
|
|
|
fd := open(&sysstat[0], _OREAD, 0)
|
|
|
|
if fd < 0 {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
ncpu := int32(0)
|
|
|
|
for {
|
|
|
|
n := read(fd, unsafe.Pointer(&buf), int32(len(buf)))
|
|
|
|
if n <= 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
for i := int32(0); i < n; i++ {
|
|
|
|
if buf[i] == '\n' {
|
|
|
|
ncpu++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-13 17:37:04 -06:00
|
|
|
closefd(fd)
|
2014-11-21 11:39:01 -07:00
|
|
|
if ncpu == 0 {
|
|
|
|
ncpu = 1
|
|
|
|
}
|
|
|
|
return ncpu
|
|
|
|
}
|
|
|
|
|
2016-07-18 19:40:02 -06:00
|
|
|
var devswap = []byte("/dev/swap\x00")
|
|
|
|
var pagesize = []byte(" pagesize\n")
|
|
|
|
|
|
|
|
func getPageSize() uintptr {
|
|
|
|
var buf [2048]byte
|
|
|
|
var pos int
|
|
|
|
fd := open(&devswap[0], _OREAD, 0)
|
|
|
|
if fd < 0 {
|
|
|
|
// There's not much we can do if /dev/swap doesn't
|
|
|
|
// exist. However, nothing in the memory manager uses
|
|
|
|
// this on Plan 9, so it also doesn't really matter.
|
|
|
|
return minPhysPageSize
|
|
|
|
}
|
|
|
|
for pos < len(buf) {
|
|
|
|
n := read(fd, unsafe.Pointer(&buf[pos]), int32(len(buf)-pos))
|
|
|
|
if n <= 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
pos += int(n)
|
|
|
|
}
|
|
|
|
closefd(fd)
|
|
|
|
text := buf[:pos]
|
|
|
|
// Find "<n> pagesize" line.
|
|
|
|
bol := 0
|
|
|
|
for i, c := range text {
|
|
|
|
if c == '\n' {
|
|
|
|
bol = i + 1
|
|
|
|
}
|
|
|
|
if bytesHasPrefix(text[i:], pagesize) {
|
|
|
|
// Parse number at the beginning of this line.
|
|
|
|
return uintptr(_atoi(text[bol:]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Again, the page size doesn't really matter, so use a fallback.
|
|
|
|
return minPhysPageSize
|
|
|
|
}
|
|
|
|
|
|
|
|
func bytesHasPrefix(s, prefix []byte) bool {
|
|
|
|
if len(s) < len(prefix) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i, p := range prefix {
|
|
|
|
if s[i] != p {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2014-11-21 11:39:01 -07:00
|
|
|
var pid = []byte("#c/pid\x00")
|
|
|
|
|
|
|
|
func getpid() uint64 {
|
|
|
|
var b [20]byte
|
|
|
|
fd := open(&pid[0], 0, 0)
|
|
|
|
if fd >= 0 {
|
|
|
|
read(fd, unsafe.Pointer(&b), int32(len(b)))
|
2015-04-13 17:37:04 -06:00
|
|
|
closefd(fd)
|
2014-11-21 11:39:01 -07:00
|
|
|
}
|
|
|
|
c := b[:]
|
|
|
|
for c[0] == ' ' || c[0] == '\t' {
|
|
|
|
c = c[1:]
|
|
|
|
}
|
2014-12-29 09:35:42 -07:00
|
|
|
return uint64(_atoi(c))
|
2014-11-21 11:39:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func osinit() {
|
|
|
|
initBloc()
|
|
|
|
ncpu = getproccount()
|
2016-07-18 19:40:02 -06:00
|
|
|
physPageSize = getPageSize()
|
2014-11-21 11:39:01 -07:00
|
|
|
getg().m.procid = getpid()
|
|
|
|
notify(unsafe.Pointer(funcPC(sigtramp)))
|
|
|
|
}
|
|
|
|
|
|
|
|
func crash() {
|
|
|
|
notify(nil)
|
|
|
|
*(*int)(nil) = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
2014-12-09 15:40:40 -07:00
|
|
|
func getRandomData(r []byte) {
|
2015-03-01 10:08:15 -07:00
|
|
|
extendRandom(r, 0)
|
2014-11-21 11:39:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func goenvs() {
|
|
|
|
}
|
|
|
|
|
2015-12-26 10:51:59 -07:00
|
|
|
func initsig(preinit bool) {
|
2014-11-21 11:39:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func osyield() {
|
|
|
|
sleep(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func usleep(µs uint32) {
|
|
|
|
ms := int32(µs / 1000)
|
|
|
|
if ms == 0 {
|
|
|
|
ms = 1
|
|
|
|
}
|
|
|
|
sleep(ms)
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func nanotime() int64 {
|
|
|
|
var scratch int64
|
|
|
|
ns := nsec(&scratch)
|
|
|
|
// TODO(aram): remove hack after I fix _nsec in the pc64 kernel.
|
|
|
|
if ns == 0 {
|
|
|
|
return scratch
|
|
|
|
}
|
|
|
|
return ns
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func itoa(buf []byte, val uint64) []byte {
|
|
|
|
i := len(buf) - 1
|
|
|
|
for val >= 10 {
|
|
|
|
buf[i] = byte(val%10 + '0')
|
|
|
|
i--
|
|
|
|
val /= 10
|
|
|
|
}
|
|
|
|
buf[i] = byte(val + '0')
|
|
|
|
return buf[i:]
|
|
|
|
}
|
|
|
|
|
|
|
|
var goexits = []byte("go: exit ")
|
2016-03-25 06:50:35 -06:00
|
|
|
var emptystatus = []byte("\x00")
|
|
|
|
var exiting uint32
|
2014-11-21 11:39:01 -07:00
|
|
|
|
|
|
|
func goexitsall(status *byte) {
|
|
|
|
var buf [_ERRMAX]byte
|
2016-03-25 06:50:35 -06:00
|
|
|
if !atomic.Cas(&exiting, 0, 1) {
|
|
|
|
return
|
|
|
|
}
|
2016-03-09 09:16:05 -07:00
|
|
|
getg().m.locks++
|
2014-11-21 11:39:01 -07:00
|
|
|
n := copy(buf[:], goexits)
|
|
|
|
n = copy(buf[n:], gostringnocopy(status))
|
|
|
|
pid := getpid()
|
2015-11-02 12:09:24 -07:00
|
|
|
for mp := (*m)(atomic.Loadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
|
2016-03-25 06:50:35 -06:00
|
|
|
if mp.procid != 0 && mp.procid != pid {
|
2014-11-21 11:39:01 -07:00
|
|
|
postnote(mp.procid, buf[:])
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 09:16:05 -07:00
|
|
|
getg().m.locks--
|
2014-11-21 11:39:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var procdir = []byte("/proc/")
|
|
|
|
var notefile = []byte("/note\x00")
|
|
|
|
|
|
|
|
func postnote(pid uint64, msg []byte) int {
|
|
|
|
var buf [128]byte
|
|
|
|
var tmp [32]byte
|
|
|
|
n := copy(buf[:], procdir)
|
|
|
|
n += copy(buf[n:], itoa(tmp[:], pid))
|
|
|
|
copy(buf[n:], notefile)
|
|
|
|
fd := open(&buf[0], _OWRITE, 0)
|
|
|
|
if fd < 0 {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
len := findnull(&msg[0])
|
2015-10-15 15:33:50 -06:00
|
|
|
if write(uintptr(fd), unsafe.Pointer(&msg[0]), int32(len)) != int64(len) {
|
2015-04-13 17:37:04 -06:00
|
|
|
closefd(fd)
|
2014-11-21 11:39:01 -07:00
|
|
|
return -1
|
|
|
|
}
|
2015-04-13 17:37:04 -06:00
|
|
|
closefd(fd)
|
2014-11-21 11:39:01 -07:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func exit(e int) {
|
|
|
|
var status []byte
|
|
|
|
if e == 0 {
|
2016-03-25 06:50:35 -06:00
|
|
|
status = emptystatus
|
2014-11-21 11:39:01 -07:00
|
|
|
} else {
|
|
|
|
// build error string
|
|
|
|
var tmp [32]byte
|
2015-05-12 08:54:39 -06:00
|
|
|
status = append(itoa(tmp[:len(tmp)-1], uint64(e)), 0)
|
2014-11-21 11:39:01 -07:00
|
|
|
}
|
|
|
|
goexitsall(&status[0])
|
|
|
|
exits(&status[0])
|
|
|
|
}
|
|
|
|
|
2015-03-29 08:20:54 -06:00
|
|
|
// May run with m.p==nil, so write barriers are not allowed.
|
runtime: disallow write barriers in handoffp and callees
handoffp by definition runs without a P, so it's not allowed to have
write barriers. It doesn't have any right now, but mark it
nowritebarrier to disallow any creeping in in the future. handoffp in
turns calls startm, newm, and newosproc, all of which are "below Go"
and make sense to run without a P, so disallow write barriers in these
as well.
For most functions, we've done this because they may race with
stoptheworld() and hence must not have write barriers. For these
functions, it's a little different: the world can't stop while we're
in handoffp, so this race isn't present. But we implement this
restriction with a somewhat broader rule that you can't have a write
barrier without a P. We like this rule because it's simple and means
that our write barriers can depend on there being a P, even though
this rule is actually a little broader than necessary. Hence, even
though there's no danger of the race in these functions, we want to
adhere to the broader rule.
Change-Id: Ie22319c30eea37d703eb52f5c7ca5da872030b88
Reviewed-on: https://go-review.googlesource.com/8130
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
2015-03-26 13:50:22 -06:00
|
|
|
//go:nowritebarrier
|
2014-11-21 11:39:01 -07:00
|
|
|
func newosproc(mp *m, stk unsafe.Pointer) {
|
|
|
|
if false {
|
|
|
|
print("newosproc mp=", mp, " ostk=", &mp, "\n")
|
|
|
|
}
|
|
|
|
pid := rfork(_RFPROC | _RFMEM | _RFNOWAIT)
|
|
|
|
if pid < 0 {
|
2014-12-27 21:58:00 -07:00
|
|
|
throw("newosproc: rfork failed")
|
2014-11-21 11:39:01 -07:00
|
|
|
}
|
|
|
|
if pid == 0 {
|
|
|
|
tstart_plan9(mp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
2015-10-21 19:36:05 -06:00
|
|
|
func semacreate(mp *m) {
|
2014-11-21 11:39:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func semasleep(ns int64) int {
|
|
|
|
_g_ := getg()
|
|
|
|
if ns >= 0 {
|
|
|
|
ms := timediv(ns, 1000000, nil)
|
|
|
|
if ms == 0 {
|
|
|
|
ms = 1
|
|
|
|
}
|
|
|
|
ret := plan9_tsemacquire(&_g_.m.waitsemacount, ms)
|
|
|
|
if ret == 1 {
|
|
|
|
return 0 // success
|
|
|
|
}
|
|
|
|
return -1 // timeout or interrupted
|
|
|
|
}
|
|
|
|
for plan9_semacquire(&_g_.m.waitsemacount, 1) < 0 {
|
|
|
|
// interrupted; try again (c.f. lock_sema.go)
|
|
|
|
}
|
|
|
|
return 0 // success
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func semawakeup(mp *m) {
|
|
|
|
plan9_semrelease(&mp.waitsemacount, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func read(fd int32, buf unsafe.Pointer, n int32) int32 {
|
|
|
|
return pread(fd, buf, n, -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func write(fd uintptr, buf unsafe.Pointer, n int32) int64 {
|
|
|
|
return int64(pwrite(int32(fd), buf, n, -1))
|
|
|
|
}
|
|
|
|
|
|
|
|
func memlimit() uint64 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
var _badsignal = []byte("runtime: signal received on thread not created by Go.\n")
|
|
|
|
|
2016-03-01 16:21:55 -07:00
|
|
|
// This runs on a foreign stack, without an m or a g. No stack split.
|
2014-11-21 11:39:01 -07:00
|
|
|
//go:nosplit
|
|
|
|
func badsignal2() {
|
|
|
|
pwrite(2, unsafe.Pointer(&_badsignal[0]), int32(len(_badsignal)), -1)
|
|
|
|
exits(&_badsignal[0])
|
|
|
|
}
|
|
|
|
|
runtime: minor simplifications to signal code
Change setsig, setsigstack, getsig, raise, raiseproc to take uint32 for
signal number parameter, as that is the type mostly used for signal
numbers. Same for dieFromSignal, sigInstallGoHandler, raisebadsignal.
Remove setsig restart parameter, as it is always either true or
irrelevant.
Don't check the handler in setsigstack, as the only caller does that
anyhow.
Don't bother to convert the handler from sigtramp to sighandler in
getsig, as it will never be called when the handler is sigtramp or
sighandler.
Don't check the return value from rt_sigaction in the GNU/Linux version
of setsigstack; no other setsigstack checks it, and it never fails.
Change-Id: I6bbd677e048a77eddf974dd3d017bc3c560fbd48
Reviewed-on: https://go-review.googlesource.com/29953
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-09-27 23:24:51 -06:00
|
|
|
func raisebadsignal(sig uint32) {
|
2015-07-21 23:34:48 -06:00
|
|
|
badsignal2()
|
|
|
|
}
|
|
|
|
|
2014-12-29 09:35:42 -07:00
|
|
|
func _atoi(b []byte) int {
|
2014-11-21 11:39:01 -07:00
|
|
|
n := 0
|
|
|
|
for len(b) > 0 && '0' <= b[0] && b[0] <= '9' {
|
|
|
|
n = n*10 + int(b[0]) - '0'
|
|
|
|
b = b[1:]
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
2016-05-04 01:42:13 -06:00
|
|
|
|
|
|
|
func signame(sig uint32) string {
|
|
|
|
if sig >= uint32(len(sigtable)) {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return sigtable[sig].name
|
|
|
|
}
|