2014-11-13 19:01:12 -07:00
|
|
|
// Copyright 2011 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
|
|
|
|
|
2015-11-02 12:09:24 -07:00
|
|
|
import (
|
2021-05-13 16:07:57 -06:00
|
|
|
"internal/abi"
|
2015-11-02 12:09:24 -07:00
|
|
|
"runtime/internal/atomic"
|
|
|
|
"unsafe"
|
|
|
|
)
|
2014-11-13 19:01:12 -07:00
|
|
|
|
2016-05-06 09:26:37 -06:00
|
|
|
type mOS struct {
|
|
|
|
waitsemacount uint32
|
|
|
|
}
|
|
|
|
|
2014-11-13 19:01:12 -07:00
|
|
|
const (
|
2015-02-16 02:18:13 -07:00
|
|
|
_ESRCH = 3
|
|
|
|
_EWOULDBLOCK = _EAGAIN
|
|
|
|
_ENOTSUP = 91
|
2014-11-13 19:01:12 -07:00
|
|
|
|
|
|
|
// From OpenBSD's sys/time.h
|
2015-02-16 02:18:13 -07:00
|
|
|
_CLOCK_REALTIME = 0
|
|
|
|
_CLOCK_VIRTUAL = 1
|
|
|
|
_CLOCK_PROF = 2
|
|
|
|
_CLOCK_MONOTONIC = 3
|
2014-11-13 19:01:12 -07:00
|
|
|
)
|
|
|
|
|
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 uint32
|
|
|
|
|
2016-09-23 18:54:51 -06:00
|
|
|
var sigset_all = ^sigset(0)
|
2014-11-13 19:01:12 -07:00
|
|
|
|
|
|
|
// From OpenBSD's <sys/sysctl.h>
|
|
|
|
const (
|
2018-06-29 12:56:48 -06:00
|
|
|
_CTL_KERN = 1
|
|
|
|
_KERN_OSREV = 3
|
|
|
|
|
2019-02-08 01:25:05 -07:00
|
|
|
_CTL_HW = 6
|
|
|
|
_HW_NCPU = 3
|
|
|
|
_HW_PAGESIZE = 7
|
|
|
|
_HW_NCPUONLINE = 25
|
2014-11-13 19:01:12 -07:00
|
|
|
)
|
|
|
|
|
2018-06-29 14:09:01 -06:00
|
|
|
func sysctlInt(mib []uint32) (int32, bool) {
|
|
|
|
var out int32
|
2014-11-13 19:01:12 -07:00
|
|
|
nout := unsafe.Sizeof(out)
|
2018-06-29 14:09:01 -06:00
|
|
|
ret := sysctl(&mib[0], uint32(len(mib)), (*byte)(unsafe.Pointer(&out)), &nout, nil, 0)
|
|
|
|
if ret < 0 {
|
|
|
|
return 0, false
|
|
|
|
}
|
|
|
|
return out, true
|
|
|
|
}
|
2014-11-13 19:01:12 -07:00
|
|
|
|
2022-08-05 07:39:55 -06:00
|
|
|
func sysctlUint64(mib []uint32) (uint64, bool) {
|
|
|
|
var out uint64
|
|
|
|
nout := unsafe.Sizeof(out)
|
|
|
|
ret := sysctl(&mib[0], uint32(len(mib)), (*byte)(unsafe.Pointer(&out)), &nout, nil, 0)
|
|
|
|
if ret < 0 {
|
|
|
|
return 0, false
|
|
|
|
}
|
|
|
|
return out, true
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:linkname internal_cpu_sysctlUint64 internal/cpu.sysctlUint64
|
|
|
|
func internal_cpu_sysctlUint64(mib []uint32) (uint64, bool) {
|
|
|
|
return sysctlUint64(mib)
|
|
|
|
}
|
|
|
|
|
2018-06-29 14:09:01 -06:00
|
|
|
func getncpu() int32 {
|
2019-02-08 01:25:05 -07:00
|
|
|
// Try hw.ncpuonline first because hw.ncpu would report a number twice as
|
|
|
|
// high as the actual CPUs running on OpenBSD 6.4 with hyperthreading
|
|
|
|
// disabled (hw.smt=0). See https://golang.org/issue/30127
|
|
|
|
if n, ok := sysctlInt([]uint32{_CTL_HW, _HW_NCPUONLINE}); ok {
|
|
|
|
return int32(n)
|
|
|
|
}
|
|
|
|
if n, ok := sysctlInt([]uint32{_CTL_HW, _HW_NCPU}); ok {
|
|
|
|
return int32(n)
|
2014-11-13 19:01:12 -07:00
|
|
|
}
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2016-07-18 19:40:02 -06:00
|
|
|
func getPageSize() uintptr {
|
2018-06-29 14:09:01 -06:00
|
|
|
if ps, ok := sysctlInt([]uint32{_CTL_HW, _HW_PAGESIZE}); ok {
|
|
|
|
return uintptr(ps)
|
2016-07-18 19:40:02 -06:00
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2018-06-29 14:09:01 -06:00
|
|
|
func getOSRev() int {
|
|
|
|
if osrev, ok := sysctlInt([]uint32{_CTL_KERN, _KERN_OSREV}); ok {
|
|
|
|
return int(osrev)
|
2018-06-29 12:56:48 -06:00
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2014-11-13 19:01:12 -07:00
|
|
|
//go:nosplit
|
2015-10-21 19:36:05 -06:00
|
|
|
func semacreate(mp *m) {
|
2014-11-13 19:01:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func semasleep(ns int64) int32 {
|
2022-07-20 09:43:30 -06:00
|
|
|
gp := getg()
|
2014-11-13 19:01:12 -07:00
|
|
|
|
|
|
|
// Compute sleep deadline.
|
|
|
|
var tsp *timespec
|
|
|
|
if ns >= 0 {
|
|
|
|
var ts timespec
|
2019-03-13 19:56:37 -06:00
|
|
|
ts.setNsec(ns + nanotime())
|
2014-11-13 19:01:12 -07:00
|
|
|
tsp = &ts
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
2022-07-20 09:43:30 -06:00
|
|
|
v := atomic.Load(&gp.m.waitsemacount)
|
2015-02-23 01:05:30 -07:00
|
|
|
if v > 0 {
|
2022-07-20 09:43:30 -06:00
|
|
|
if atomic.Cas(&gp.m.waitsemacount, v, v-1) {
|
2015-02-23 01:05:30 -07:00
|
|
|
return 0 // semaphore acquired
|
2014-11-13 19:01:12 -07:00
|
|
|
}
|
2015-02-23 01:05:30 -07:00
|
|
|
continue
|
2014-11-13 19:01:12 -07:00
|
|
|
}
|
|
|
|
|
2015-02-23 01:05:30 -07:00
|
|
|
// Sleep until woken by semawakeup or timeout; or abort if waitsemacount != 0.
|
|
|
|
//
|
|
|
|
// From OpenBSD's __thrsleep(2) manual:
|
|
|
|
// "The abort argument, if not NULL, points to an int that will
|
2016-03-01 16:21:55 -07:00
|
|
|
// be examined [...] immediately before blocking. If that int
|
2015-02-23 01:05:30 -07:00
|
|
|
// is non-zero then __thrsleep() will immediately return EINTR
|
|
|
|
// without blocking."
|
2022-07-20 09:43:30 -06:00
|
|
|
ret := thrsleep(uintptr(unsafe.Pointer(&gp.m.waitsemacount)), _CLOCK_MONOTONIC, tsp, 0, &gp.m.waitsemacount)
|
2015-02-16 02:18:13 -07:00
|
|
|
if ret == _EWOULDBLOCK {
|
2014-11-13 19:01:12 -07:00
|
|
|
return -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func semawakeup(mp *m) {
|
2015-11-02 12:09:24 -07:00
|
|
|
atomic.Xadd(&mp.waitsemacount, 1)
|
2014-11-13 19:01:12 -07:00
|
|
|
ret := thrwakeup(uintptr(unsafe.Pointer(&mp.waitsemacount)), 1)
|
2015-02-16 02:18:13 -07:00
|
|
|
if ret != 0 && ret != _ESRCH {
|
2014-11-13 19:01:12 -07:00
|
|
|
// semawakeup can be called on signal stack.
|
|
|
|
systemstack(func() {
|
|
|
|
print("thrwakeup addr=", &mp.waitsemacount, " sem=", mp.waitsemacount, " ret=", ret, "\n")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func osinit() {
|
|
|
|
ncpu = getncpu()
|
2016-07-18 19:40:02 -06:00
|
|
|
physPageSize = getPageSize()
|
2018-06-29 12:56:48 -06:00
|
|
|
haveMapStack = getOSRev() >= 201805 // OpenBSD 6.3
|
2014-11-13 19:01:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var urandom_dev = []byte("/dev/urandom\x00")
|
|
|
|
|
|
|
|
//go:nosplit
|
2014-12-09 15:40:40 -07:00
|
|
|
func getRandomData(r []byte) {
|
2014-11-13 19:01:12 -07:00
|
|
|
fd := open(&urandom_dev[0], 0 /* O_RDONLY */, 0)
|
2014-12-09 15:40:40 -07:00
|
|
|
n := read(fd, unsafe.Pointer(&r[0]), int32(len(r)))
|
2015-04-13 17:37:04 -06:00
|
|
|
closefd(fd)
|
2014-12-09 15:40:40 -07:00
|
|
|
extendRandom(r, int(n))
|
2014-11-13 19:01:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func goenvs() {
|
|
|
|
goenvs_unix()
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2020-08-25 02:04:47 -06:00
|
|
|
gsignalSize := int32(32 * 1024)
|
|
|
|
if GOARCH == "mips64" {
|
|
|
|
gsignalSize = int32(64 * 1024)
|
|
|
|
}
|
|
|
|
mp.gsignal = malg(gsignalSize)
|
2014-11-13 19:01:12 -07:00
|
|
|
mp.gsignal.m = mp
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called to initialize a new m (including the bootstrap m).
|
|
|
|
// Called on the new thread, can not allocate memory.
|
|
|
|
func minit() {
|
2019-10-14 15:05:56 -06:00
|
|
|
getg().m.procid = uint64(getthrid())
|
2016-09-26 12:14:41 -06:00
|
|
|
minitSignals()
|
2014-11-13 19:01:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Called from dropm to undo the effect of an minit.
|
2022-01-30 18:13:43 -07:00
|
|
|
//
|
2015-11-13 14:21:01 -07:00
|
|
|
//go:nosplit
|
2014-11-13 19:01:12 -07:00
|
|
|
func unminit() {
|
2016-09-26 12:35:55 -06:00
|
|
|
unminitSignals()
|
2014-11-13 19:01:12 -07:00
|
|
|
}
|
|
|
|
|
2021-01-15 05:01:37 -07:00
|
|
|
// Called from exitm, but not from drop, to undo the effect of thread-owned
|
|
|
|
// resources in minit, semacreate, or elsewhere. Do not take locks after calling this.
|
|
|
|
func mdestroy(mp *m) {
|
|
|
|
}
|
|
|
|
|
2014-11-13 19:01:12 -07:00
|
|
|
func sigtramp()
|
|
|
|
|
|
|
|
type sigactiont struct {
|
|
|
|
sa_sigaction uintptr
|
|
|
|
sa_mask uint32
|
|
|
|
sa_flags int32
|
|
|
|
}
|
|
|
|
|
2015-12-26 10:51:59 -07: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 23:24:51 -06:00
|
|
|
func setsig(i uint32, fn uintptr) {
|
2014-11-13 19:01:12 -07:00
|
|
|
var sa sigactiont
|
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
|
|
|
sa.sa_flags = _SA_SIGINFO | _SA_ONSTACK | _SA_RESTART
|
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
|
|
|
sa.sa_mask = uint32(sigset_all)
|
2021-05-21 11:37:19 -06:00
|
|
|
if fn == abi.FuncPCABIInternal(sighandler) { // abi.FuncPCABIInternal(sighandler) matches the callers in signal_unix.go
|
2021-05-13 16:07:57 -06:00
|
|
|
fn = abi.FuncPCABI0(sigtramp)
|
2014-11-13 19:01:12 -07:00
|
|
|
}
|
|
|
|
sa.sa_sigaction = fn
|
|
|
|
sigaction(i, &sa, nil)
|
|
|
|
}
|
|
|
|
|
2015-12-26 10:51:59 -07: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 23:24:51 -06:00
|
|
|
func setsigstack(i uint32) {
|
2014-12-27 21:58:00 -07:00
|
|
|
throw("setsigstack")
|
2014-12-19 14:16:17 -07:00
|
|
|
}
|
|
|
|
|
2015-12-26 10:51:59 -07: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 23:24:51 -06:00
|
|
|
func getsig(i uint32) uintptr {
|
2014-11-13 19:01:12 -07:00
|
|
|
var sa sigactiont
|
|
|
|
sigaction(i, nil, &sa)
|
|
|
|
return sa.sa_sigaction
|
|
|
|
}
|
|
|
|
|
2022-10-02 19:32:11 -06:00
|
|
|
// setSignalstackSP sets the ss_sp field of a stackt.
|
2022-01-30 18:13:43 -07:00
|
|
|
//
|
2015-11-13 14:21:01 -07:00
|
|
|
//go:nosplit
|
2016-09-25 14:38:54 -06:00
|
|
|
func setSignalstackSP(s *stackt, sp uintptr) {
|
|
|
|
s.ss_sp = sp
|
2014-11-13 19:01:12 -07:00
|
|
|
}
|
|
|
|
|
2015-12-26 10:51:59 -07:00
|
|
|
//go:nosplit
|
|
|
|
//go:nowritebarrierrec
|
2016-09-27 14:42:28 -06:00
|
|
|
func sigaddset(mask *sigset, i int) {
|
|
|
|
*mask |= 1 << (uint32(i) - 1)
|
2015-07-21 23:34:48 -06:00
|
|
|
}
|
2016-09-25 22:33:27 -06:00
|
|
|
|
2016-09-26 12:14:41 -06:00
|
|
|
func sigdelset(mask *sigset, i int) {
|
|
|
|
*mask &^= 1 << (uint32(i) - 1)
|
|
|
|
}
|
|
|
|
|
2019-03-25 03:34:57 -06:00
|
|
|
//go:nosplit
|
2016-09-25 22:33:27 -06:00
|
|
|
func (c *sigctxt) fixsigcode(sig uint32) {
|
|
|
|
}
|
2018-06-29 12:56:48 -06:00
|
|
|
|
2021-08-13 09:51:46 -06:00
|
|
|
func setProcessCPUProfiler(hz int32) {
|
|
|
|
setProcessCPUProfilerTimer(hz)
|
|
|
|
}
|
|
|
|
|
|
|
|
func setThreadCPUProfiler(hz int32) {
|
|
|
|
setThreadCPUProfilerHz(hz)
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func validSIGPROF(mp *m, c *sigctxt) bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-06-29 12:56:48 -06:00
|
|
|
var haveMapStack = false
|
|
|
|
|
|
|
|
func osStackAlloc(s *mspan) {
|
|
|
|
// OpenBSD 6.4+ requires that stacks be mapped with MAP_STACK.
|
|
|
|
// It will check this on entry to system calls, traps, and
|
|
|
|
// when switching to the alternate system stack.
|
|
|
|
//
|
|
|
|
// This function is called before s is used for any data, so
|
|
|
|
// it's safe to simply re-map it.
|
|
|
|
osStackRemap(s, _MAP_STACK)
|
|
|
|
}
|
|
|
|
|
|
|
|
func osStackFree(s *mspan) {
|
|
|
|
// Undo MAP_STACK.
|
|
|
|
osStackRemap(s, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func osStackRemap(s *mspan, flags int32) {
|
|
|
|
if !haveMapStack {
|
|
|
|
// OpenBSD prior to 6.3 did not have MAP_STACK and so
|
|
|
|
// the following mmap will fail. But it also didn't
|
|
|
|
// require MAP_STACK (obviously), so there's no need
|
|
|
|
// to do the mmap.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
a, err := mmap(unsafe.Pointer(s.base()), s.npages*pageSize, _PROT_READ|_PROT_WRITE, _MAP_PRIVATE|_MAP_ANON|_MAP_FIXED|flags, -1, 0)
|
|
|
|
if err != 0 || uintptr(a) != s.base() {
|
|
|
|
print("runtime: remapping stack memory ", hex(s.base()), " ", s.npages*pageSize, " a=", a, " err=", err, "\n")
|
|
|
|
throw("remapping stack memory failed")
|
|
|
|
}
|
|
|
|
}
|
2019-10-14 15:05:56 -06:00
|
|
|
|
2020-07-06 15:23:26 -06:00
|
|
|
//go:nosplit
|
2019-10-14 15:05:56 -06:00
|
|
|
func raise(sig uint32) {
|
|
|
|
thrkill(getthrid(), int(sig))
|
|
|
|
}
|
|
|
|
|
|
|
|
func signalM(mp *m, sig int) {
|
|
|
|
thrkill(int32(mp.procid), sig)
|
|
|
|
}
|
runtime, syscall: reimplement AllThreadsSyscall using only signals.
In issue 50113, we see that a thread blocked in a system call can result
in a hang of AllThreadsSyscall. To resolve this, we must send a signal
to these threads to knock them out of the system call long enough to run
the per-thread syscall.
Stepping back, if we need to send signals anyway, it should be possible
to implement this entire mechanism on top of signals. This CL does so,
vastly simplifying the mechanism, both as a direct result of
newly-unnecessary code as well as some ancillary simplifications to make
things simpler to follow.
Major changes:
* The rest of the mechanism is moved to os_linux.go, with fields in mOS
instead of m itself.
* 'Fixup' fields and functions are renamed to 'perThreadSyscall' so they
are more precise about their purpose.
* Rather than getting passed a closure, doAllThreadsSyscall takes the
syscall number and arguments. This avoids a lot of hairy behavior:
* The closure may potentially only be live in fields in the M,
hidden from the GC. Not necessary with no closure.
* The need to loan out the race context. A direct RawSyscall6 call
does not require any race context.
* The closure previously conditionally panicked in strange
locations, like a signal handler. Now we simply throw.
* All manual fixup synchronization with mPark, sysmon, templateThread,
sigqueue, etc is gone. The core approach is much simpler:
doAllThreadsSyscall sends a signal to every thread in allm, which
executes the system call from the signal handler. We use (SIGRTMIN +
1), aka SIGSETXID, the same signal used by glibc for this purpose. As
such, we are careful to only handle this signal on non-cgo binaries.
Synchronization with thread creation is a key part of this CL. The
comment near the top of doAllThreadsSyscall describes the required
synchronization semantics and how they are achieved.
Note that current use of allocmLock protects the state mutations of allm
that are also protected by sched.lock. allocmLock is used instead of
sched.lock simply to avoid holding sched.lock for so long.
Fixes #50113
Change-Id: Ic7ea856dc66cf711731540a54996e08fc986ce84
Reviewed-on: https://go-review.googlesource.com/c/go/+/383434
Reviewed-by: Austin Clements <austin@google.com>
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-04 15:15:28 -07:00
|
|
|
|
|
|
|
// sigPerThreadSyscall is only used on linux, so we assign a bogus signal
|
|
|
|
// number.
|
|
|
|
const sigPerThreadSyscall = 1 << 31
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func runPerThreadSyscall() {
|
|
|
|
throw("runPerThreadSyscall only valid on linux")
|
|
|
|
}
|