runtime: M-targeted signals for BSDs

For these, we split up the existing runtime.raise assembly
implementation into its constituent "get thread ID" and "signal
thread" parts. This lets us implement signalM and reimplement raise in
pure Go. (NetBSD conveniently already had lwp_self.)

We also change minit to store the procid directly, rather than
depending on newosproc to do so. This is because newosproc isn't
called for the bootstrap M, but we need a procid for every M. This is
also simpler overall.

For #10958, #24543.

Change-Id: Ie5f1fcada6a33046375066bcbe054d1f784d39c0
Reviewed-on: https://go-review.googlesource.com/c/go/+/201402
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Austin Clements 2019-10-14 17:05:56 -04:00
parent 334291d1f6
commit 8714e39497
21 changed files with 160 additions and 78 deletions

View file

@ -47,9 +47,10 @@ func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, nds
func lwp_tramp()
func raise(sig uint32)
func raiseproc(sig uint32)
func lwp_kill(tid int32, sig int)
//go:noescape
func getcontext(ctxt unsafe.Pointer)
@ -361,3 +362,17 @@ func sysauxv(auxv []uintptr) {
}
}
}
// raise sends signal to the calling thread.
//
// It must be nosplit because it is used by the signal handler before
// it definitely has a Go stack.
//
//go:nosplit
func raise(sig uint32) {
lwp_kill(lwp_self(), int(sig))
}
func signalM(mp *m, sig int) {
lwp_kill(int32(mp.procid), sig)
}