2014-11-11 17:08:54 -05:00
|
|
|
// Copyright 2009 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"
|
|
|
|
|
|
2016-04-13 11:31:24 -07:00
|
|
|
type mOS struct {
|
2018-06-13 14:39:36 -07:00
|
|
|
initialized bool
|
|
|
|
|
mutex pthreadmutex
|
|
|
|
|
cond pthreadcond
|
|
|
|
|
count int
|
2016-04-13 11:31:24 -07:00
|
|
|
}
|
2014-11-11 17:08:54 -05:00
|
|
|
|
|
|
|
|
func unimplemented(name string) {
|
|
|
|
|
println(name, "not implemented")
|
|
|
|
|
*(*int)(unsafe.Pointer(uintptr(1231))) = 1231
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//go:nosplit
|
2018-06-13 14:39:36 -07:00
|
|
|
func semacreate(mp *m) {
|
|
|
|
|
if mp.initialized {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
mp.initialized = true
|
|
|
|
|
if err := pthread_mutex_init(&mp.mutex, nil); err != 0 {
|
|
|
|
|
throw("pthread_mutex_init")
|
|
|
|
|
}
|
|
|
|
|
if err := pthread_cond_init(&mp.cond, nil); err != 0 {
|
|
|
|
|
throw("pthread_cond_init")
|
|
|
|
|
}
|
2014-11-11 17:08:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//go:nosplit
|
2018-06-13 14:39:36 -07:00
|
|
|
func semasleep(ns int64) int32 {
|
|
|
|
|
mp := getg().m
|
|
|
|
|
pthread_mutex_lock(&mp.mutex)
|
|
|
|
|
for {
|
|
|
|
|
if mp.count > 0 {
|
|
|
|
|
mp.count--
|
|
|
|
|
pthread_mutex_unlock(&mp.mutex)
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
if ns >= 0 {
|
|
|
|
|
var t timespec
|
|
|
|
|
t.set_nsec(ns)
|
2018-06-23 01:15:19 -04:00
|
|
|
err := pthread_cond_timedwait_relative_np(&mp.cond, &mp.mutex, &t)
|
2018-06-13 14:39:36 -07:00
|
|
|
if err == _ETIMEDOUT {
|
|
|
|
|
pthread_mutex_unlock(&mp.mutex)
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
pthread_cond_wait(&mp.cond, &mp.mutex)
|
|
|
|
|
}
|
2015-10-21 18:36:05 -07:00
|
|
|
}
|
2018-06-13 14:39:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
|
func semawakeup(mp *m) {
|
|
|
|
|
pthread_mutex_lock(&mp.mutex)
|
|
|
|
|
mp.count++
|
|
|
|
|
if mp.count > 0 {
|
|
|
|
|
pthread_cond_signal(&mp.cond)
|
|
|
|
|
}
|
|
|
|
|
pthread_mutex_unlock(&mp.mutex)
|
2014-11-11 17:08:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BSD interface for threading.
|
|
|
|
|
func osinit() {
|
2018-04-23 07:30:32 -07:00
|
|
|
// pthread_create delayed until end of goenvs so that we
|
2014-11-11 17:08:54 -05:00
|
|
|
// can look at the environment first.
|
|
|
|
|
|
2015-08-07 11:48:52 -04:00
|
|
|
ncpu = getncpu()
|
2016-07-18 21:40:02 -04:00
|
|
|
physPageSize = getPageSize()
|
2015-08-07 11:48:52 -04:00
|
|
|
}
|
|
|
|
|
|
2016-07-18 21:40:02 -04:00
|
|
|
const (
|
2018-06-07 12:17:40 +02:00
|
|
|
_CTL_HW = 6
|
|
|
|
|
_HW_NCPU = 3
|
|
|
|
|
_HW_PAGESIZE = 7
|
2016-07-18 21:40:02 -04:00
|
|
|
)
|
|
|
|
|
|
2015-08-07 11:48:52 -04:00
|
|
|
func getncpu() int32 {
|
2014-11-11 17:08:54 -05:00
|
|
|
// Use sysctl to fetch hw.ncpu.
|
2016-07-18 21:40:02 -04:00
|
|
|
mib := [2]uint32{_CTL_HW, _HW_NCPU}
|
2014-11-11 17:08:54 -05:00
|
|
|
out := uint32(0)
|
|
|
|
|
nout := unsafe.Sizeof(out)
|
|
|
|
|
ret := sysctl(&mib[0], 2, (*byte)(unsafe.Pointer(&out)), &nout, nil, 0)
|
2015-08-07 11:48:52 -04:00
|
|
|
if ret >= 0 && int32(out) > 0 {
|
|
|
|
|
return int32(out)
|
2014-11-11 17:08:54 -05:00
|
|
|
}
|
2015-08-07 11:48:52 -04:00
|
|
|
return 1
|
2014-11-11 17:08:54 -05:00
|
|
|
}
|
|
|
|
|
|
2016-07-18 21:40:02 -04:00
|
|
|
func getPageSize() uintptr {
|
|
|
|
|
// Use sysctl to fetch hw.pagesize.
|
|
|
|
|
mib := [2]uint32{_CTL_HW, _HW_PAGESIZE}
|
|
|
|
|
out := uint32(0)
|
|
|
|
|
nout := unsafe.Sizeof(out)
|
|
|
|
|
ret := sysctl(&mib[0], 2, (*byte)(unsafe.Pointer(&out)), &nout, nil, 0)
|
|
|
|
|
if ret >= 0 && int32(out) > 0 {
|
|
|
|
|
return uintptr(out)
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-08 15:30:22 -08:00
|
|
|
var urandom_dev = []byte("/dev/urandom\x00")
|
2014-11-11 17:08:54 -05:00
|
|
|
|
|
|
|
|
//go:nosplit
|
2014-12-09 14:40:40 -08:00
|
|
|
func getRandomData(r []byte) {
|
2014-11-11 17:08:54 -05:00
|
|
|
fd := open(&urandom_dev[0], 0 /* O_RDONLY */, 0)
|
2014-12-09 14:40:40 -08:00
|
|
|
n := read(fd, unsafe.Pointer(&r[0]), int32(len(r)))
|
2015-04-13 19:37:04 -04:00
|
|
|
closefd(fd)
|
2014-12-09 14:40:40 -08:00
|
|
|
extendRandom(r, int(n))
|
2014-11-11 17:08:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func goenvs() {
|
|
|
|
|
goenvs_unix()
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-29 10:20:54 -04:00
|
|
|
// May run with m.p==nil, so write barriers are not allowed.
|
2018-04-23 07:30:32 -07:00
|
|
|
//go:nowritebarrierrec
|
|
|
|
|
func newosproc(mp *m) {
|
|
|
|
|
stk := unsafe.Pointer(mp.g0.stack.hi)
|
2014-11-11 17:08:54 -05:00
|
|
|
if false {
|
2015-11-12 14:26:19 -08:00
|
|
|
print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " id=", mp.id, " ostk=", &mp, "\n")
|
2014-11-11 17:08:54 -05:00
|
|
|
}
|
|
|
|
|
|
2018-04-23 07:30:32 -07:00
|
|
|
// Initialize an attribute object.
|
|
|
|
|
var attr pthreadattr
|
|
|
|
|
var err int32
|
|
|
|
|
err = pthread_attr_init(&attr)
|
|
|
|
|
if err != 0 {
|
|
|
|
|
write(2, unsafe.Pointer(&failthreadcreate[0]), int32(len(failthreadcreate)))
|
|
|
|
|
exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-30 07:50:10 -07:00
|
|
|
// Set the stack size we want to use. 64KB for now.
|
|
|
|
|
// TODO: just use OS default size?
|
|
|
|
|
const stackSize = 1 << 16
|
|
|
|
|
if pthread_attr_setstacksize(&attr, stackSize) != 0 {
|
2018-04-23 07:30:32 -07:00
|
|
|
write(2, unsafe.Pointer(&failthreadcreate[0]), int32(len(failthreadcreate)))
|
|
|
|
|
exit(1)
|
|
|
|
|
}
|
2018-04-30 07:50:10 -07:00
|
|
|
//mSysStatInc(&memstats.stacks_sys, stackSize) //TODO: do this?
|
2018-04-23 07:30:32 -07:00
|
|
|
|
|
|
|
|
// Tell the pthread library we won't join with this thread.
|
|
|
|
|
if pthread_attr_setdetachstate(&attr, _PTHREAD_CREATE_DETACHED) != 0 {
|
|
|
|
|
write(2, unsafe.Pointer(&failthreadcreate[0]), int32(len(failthreadcreate)))
|
|
|
|
|
exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finally, create the thread. It starts at mstart_stub, which does some low-level
|
|
|
|
|
// setup and then calls mstart.
|
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 11:41:06 +01:00
|
|
|
var oset sigset
|
2014-11-11 17:08:54 -05:00
|
|
|
sigprocmask(_SIG_SETMASK, &sigset_all, &oset)
|
2018-05-03 10:30:31 -07:00
|
|
|
err = pthread_create(&attr, funcPC(mstart_stub), unsafe.Pointer(mp))
|
2014-11-11 17:08:54 -05:00
|
|
|
sigprocmask(_SIG_SETMASK, &oset, nil)
|
2018-04-23 07:30:32 -07:00
|
|
|
if err != 0 {
|
|
|
|
|
write(2, unsafe.Pointer(&failthreadcreate[0]), int32(len(failthreadcreate)))
|
|
|
|
|
exit(1)
|
2014-11-11 17:08:54 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-23 07:30:32 -07:00
|
|
|
// glue code to call mstart from pthread_create.
|
|
|
|
|
func mstart_stub()
|
|
|
|
|
|
2015-04-08 14:16:26 -04:00
|
|
|
// newosproc0 is a version of newosproc that can be called before the runtime
|
|
|
|
|
// is initialized.
|
|
|
|
|
//
|
2018-04-23 07:30:32 -07:00
|
|
|
// This function is not safe to use after initialization as it does not pass an M as fnarg.
|
2015-04-08 14:16:26 -04:00
|
|
|
//
|
|
|
|
|
//go:nosplit
|
2017-10-10 15:11:05 -07:00
|
|
|
func newosproc0(stacksize uintptr, fn uintptr) {
|
2018-04-23 07:30:32 -07:00
|
|
|
// Initialize an attribute object.
|
|
|
|
|
var attr pthreadattr
|
|
|
|
|
var err int32
|
2018-05-03 10:30:31 -07:00
|
|
|
err = pthread_attr_init(&attr)
|
2018-04-23 07:30:32 -07:00
|
|
|
if err != 0 {
|
|
|
|
|
write(2, unsafe.Pointer(&failthreadcreate[0]), int32(len(failthreadcreate)))
|
|
|
|
|
exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the stack we want to use.
|
2018-05-03 10:30:31 -07:00
|
|
|
if pthread_attr_setstacksize(&attr, stacksize) != 0 {
|
2018-04-23 07:30:32 -07:00
|
|
|
write(2, unsafe.Pointer(&failthreadcreate[0]), int32(len(failthreadcreate)))
|
|
|
|
|
exit(1)
|
|
|
|
|
}
|
2018-04-30 07:50:10 -07:00
|
|
|
mSysStatInc(&memstats.stacks_sys, stacksize)
|
2018-04-23 07:30:32 -07:00
|
|
|
|
|
|
|
|
// Tell the pthread library we won't join with this thread.
|
2018-05-03 10:30:31 -07:00
|
|
|
if pthread_attr_setdetachstate(&attr, _PTHREAD_CREATE_DETACHED) != 0 {
|
2018-04-23 07:30:32 -07:00
|
|
|
write(2, unsafe.Pointer(&failthreadcreate[0]), int32(len(failthreadcreate)))
|
|
|
|
|
exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finally, create the thread. It starts at mstart_stub, which does some low-level
|
|
|
|
|
// setup and then calls mstart.
|
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 11:41:06 +01:00
|
|
|
var oset sigset
|
2015-04-08 14:16:26 -04:00
|
|
|
sigprocmask(_SIG_SETMASK, &sigset_all, &oset)
|
2018-05-03 10:30:31 -07:00
|
|
|
err = pthread_create(&attr, fn, nil)
|
2015-04-08 14:16:26 -04:00
|
|
|
sigprocmask(_SIG_SETMASK, &oset, nil)
|
2018-04-23 07:30:32 -07:00
|
|
|
if err != 0 {
|
2015-04-08 14:16:26 -04:00
|
|
|
write(2, unsafe.Pointer(&failthreadcreate[0]), int32(len(failthreadcreate)))
|
|
|
|
|
exit(1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var failallocatestack = []byte("runtime: failed to allocate stack for the new OS thread\n")
|
|
|
|
|
var failthreadcreate = []byte("runtime: failed to create new OS thread\n")
|
|
|
|
|
|
2015-12-26 09:51:59 -08:00
|
|
|
// Called to do synchronous initialization of Go code built with
|
|
|
|
|
// -buildmode=c-archive or -buildmode=c-shared.
|
|
|
|
|
// None of the Go runtime is initialized.
|
|
|
|
|
//go:nosplit
|
|
|
|
|
//go:nowritebarrierrec
|
|
|
|
|
func libpreinit() {
|
|
|
|
|
initsig(true)
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 17:08:54 -05: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) {
|
|
|
|
|
mp.gsignal = malg(32 * 1024) // OS X wants >= 8K
|
|
|
|
|
mp.gsignal.m = mp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called to initialize a new m (including the bootstrap m).
|
2016-01-27 12:49:13 -08:00
|
|
|
// Called on the new thread, cannot allocate memory.
|
2014-11-11 17:08:54 -05:00
|
|
|
func minit() {
|
2016-01-25 15:22:03 -08:00
|
|
|
// The alternate signal stack is buggy on arm and arm64.
|
|
|
|
|
// The signal handler handles it directly.
|
|
|
|
|
if GOARCH != "arm" && GOARCH != "arm64" {
|
2016-09-25 13:38:54 -07:00
|
|
|
minitSignalStack()
|
2015-12-23 18:38:18 -08:00
|
|
|
}
|
2016-09-26 11:14:41 -07:00
|
|
|
minitSignalMask()
|
2014-11-11 17:08:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Called from dropm to undo the effect of an minit.
|
2015-11-13 16:21:01 -05:00
|
|
|
//go:nosplit
|
2014-11-11 17:08:54 -05:00
|
|
|
func unminit() {
|
2017-10-12 18:41:06 +02:00
|
|
|
// The alternate signal stack is buggy on arm and arm64.
|
|
|
|
|
// See minit.
|
|
|
|
|
if GOARCH != "arm" && GOARCH != "arm64" {
|
|
|
|
|
unminitSignals()
|
|
|
|
|
}
|
2014-11-11 17:08:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
|
func osyield() {
|
|
|
|
|
usleep(1)
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-13 11:31:24 -07:00
|
|
|
const (
|
|
|
|
|
_NSIG = 32
|
|
|
|
|
_SI_USER = 0 /* empirically true, but not what headers say */
|
|
|
|
|
_SIG_BLOCK = 1
|
|
|
|
|
_SIG_UNBLOCK = 2
|
|
|
|
|
_SIG_SETMASK = 3
|
|
|
|
|
_SS_DISABLE = 4
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//extern SigTabTT runtime·sigtab[];
|
|
|
|
|
|
|
|
|
|
type sigset uint32
|
|
|
|
|
|
|
|
|
|
var sigset_all = ^sigset(0)
|
|
|
|
|
|
2015-12-26 09:51:59 -08:00
|
|
|
//go:nosplit
|
|
|
|
|
//go:nowritebarrierrec
|
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 22:24:51 -07:00
|
|
|
func setsig(i uint32, fn uintptr) {
|
2018-05-20 08:57:53 -07:00
|
|
|
var sa usigactiont
|
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 22:24:51 -07:00
|
|
|
sa.sa_flags = _SA_SIGINFO | _SA_ONSTACK | _SA_RESTART
|
2014-11-11 17:08:54 -05:00
|
|
|
sa.sa_mask = ^uint32(0)
|
2018-05-20 08:57:53 -07:00
|
|
|
if fn == funcPC(sighandler) {
|
|
|
|
|
fn = funcPC(sigtramp)
|
|
|
|
|
}
|
2014-11-11 17:08:54 -05:00
|
|
|
*(*uintptr)(unsafe.Pointer(&sa.__sigaction_u)) = fn
|
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 22:24:51 -07:00
|
|
|
sigaction(i, &sa, nil)
|
2014-11-11 17:08:54 -05:00
|
|
|
}
|
|
|
|
|
|
2018-05-20 08:57:53 -07:00
|
|
|
// sigtramp is the callback from libc when a signal is received.
|
|
|
|
|
// It is called with the C calling convention.
|
|
|
|
|
func sigtramp()
|
|
|
|
|
|
2015-12-26 09:51:59 -08:00
|
|
|
//go:nosplit
|
|
|
|
|
//go:nowritebarrierrec
|
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 22:24:51 -07:00
|
|
|
func setsigstack(i uint32) {
|
2015-12-17 14:49:34 -08:00
|
|
|
var osa usigactiont
|
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 22:24:51 -07:00
|
|
|
sigaction(i, nil, &osa)
|
2015-12-17 14:49:34 -08:00
|
|
|
handler := *(*uintptr)(unsafe.Pointer(&osa.__sigaction_u))
|
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 22:24:51 -07:00
|
|
|
if osa.sa_flags&_SA_ONSTACK != 0 {
|
2015-12-17 14:49:34 -08:00
|
|
|
return
|
|
|
|
|
}
|
2018-05-20 08:57:53 -07:00
|
|
|
var sa usigactiont
|
2015-12-17 14:49:34 -08:00
|
|
|
*(*uintptr)(unsafe.Pointer(&sa.__sigaction_u)) = handler
|
|
|
|
|
sa.sa_mask = osa.sa_mask
|
|
|
|
|
sa.sa_flags = osa.sa_flags | _SA_ONSTACK
|
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 22:24:51 -07:00
|
|
|
sigaction(i, &sa, nil)
|
2014-12-19 16:16:17 -05:00
|
|
|
}
|
|
|
|
|
|
2015-12-26 09:51:59 -08:00
|
|
|
//go:nosplit
|
|
|
|
|
//go:nowritebarrierrec
|
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 22:24:51 -07:00
|
|
|
func getsig(i uint32) uintptr {
|
2015-12-17 14:49:34 -08:00
|
|
|
var sa usigactiont
|
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 22:24:51 -07:00
|
|
|
sigaction(i, nil, &sa)
|
2014-11-11 17:08:54 -05:00
|
|
|
return *(*uintptr)(unsafe.Pointer(&sa.__sigaction_u))
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-25 13:38:54 -07:00
|
|
|
// setSignaltstackSP sets the ss_sp field of a stackt.
|
2015-11-13 16:21:01 -05:00
|
|
|
//go:nosplit
|
2016-09-25 13:38:54 -07:00
|
|
|
func setSignalstackSP(s *stackt, sp uintptr) {
|
2016-10-03 16:58:34 -07:00
|
|
|
*(*uintptr)(unsafe.Pointer(&s.ss_sp)) = sp
|
2014-11-11 17:08:54 -05:00
|
|
|
}
|
|
|
|
|
|
2015-12-26 09:51:59 -08:00
|
|
|
//go:nosplit
|
|
|
|
|
//go:nowritebarrierrec
|
2016-09-27 13:42:28 -07:00
|
|
|
func sigaddset(mask *sigset, i int) {
|
|
|
|
|
*mask |= 1 << (uint32(i) - 1)
|
2015-07-21 22:34:48 -07:00
|
|
|
}
|
2016-09-26 11:14:41 -07:00
|
|
|
|
|
|
|
|
func sigdelset(mask *sigset, i int) {
|
|
|
|
|
*mask &^= 1 << (uint32(i) - 1)
|
|
|
|
|
}
|
2015-11-01 04:16:52 -05:00
|
|
|
|
|
|
|
|
//go:linkname executablePath os.executablePath
|
|
|
|
|
var executablePath string
|
|
|
|
|
|
|
|
|
|
func sysargs(argc int32, argv **byte) {
|
|
|
|
|
// skip over argv, envv and the first string will be the path
|
|
|
|
|
n := argc + 1
|
|
|
|
|
for argv_index(argv, n) != nil {
|
|
|
|
|
n++
|
|
|
|
|
}
|
|
|
|
|
executablePath = gostringnocopy(argv_index(argv, n+1))
|
|
|
|
|
|
|
|
|
|
// strip "executable_path=" prefix if available, it's added after OS X 10.11.
|
|
|
|
|
const prefix = "executable_path="
|
|
|
|
|
if len(executablePath) > len(prefix) && executablePath[:len(prefix)] == prefix {
|
|
|
|
|
executablePath = executablePath[len(prefix):]
|
|
|
|
|
}
|
|
|
|
|
}
|