aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/os_dragonfly.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2019-10-14 17:05:56 -0400
committerAustin Clements <austin@google.com>2019-10-26 02:52:28 +0000
commit8714e39497dba141ce7ed83c6a18c3c0def66e77 (patch)
treea0cb6cb5980a58c5bca11c05741016de705fe742 /src/runtime/os_dragonfly.go
parent334291d1f629fb027bfcd7bff6d30e01dd9bf4c5 (diff)
downloadgo-8714e39497dba141ce7ed83c6a18c3c0def66e77.tar.gz
go-8714e39497dba141ce7ed83c6a18c3c0def66e77.zip
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>
Diffstat (limited to 'src/runtime/os_dragonfly.go')
-rw-r--r--src/runtime/os_dragonfly.go25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/runtime/os_dragonfly.go b/src/runtime/os_dragonfly.go
index 3266b2623a..6578fcbeb1 100644
--- a/src/runtime/os_dragonfly.go
+++ b/src/runtime/os_dragonfly.go
@@ -38,9 +38,11 @@ func setitimer(mode int32, new, old *itimerval)
//go:noescape
func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, ndst uintptr) int32
-func raise(sig uint32)
func raiseproc(sig uint32)
+func lwp_gettid() int32
+func lwp_kill(pid, tid int32, sig int)
+
//go:noescape
func sys_umtx_sleep(addr *uint32, val, timeout int32) int32
@@ -151,7 +153,7 @@ func newosproc(mp *m) {
start_func: funcPC(lwp_start),
arg: unsafe.Pointer(mp),
stack: uintptr(stk),
- tid1: unsafe.Pointer(&mp.procid),
+ tid1: nil, // minit will record tid
tid2: nil,
}
@@ -191,10 +193,7 @@ func mpreinit(mp *m) {
// Called to initialize a new m (including the bootstrap m).
// Called on the new thread, cannot allocate memory.
func minit() {
- // m.procid is a uint64, but lwp_start writes an int32. Fix it up.
- _g_ := getg()
- _g_.m.procid = uint64(*(*int32)(unsafe.Pointer(&_g_.m.procid)))
-
+ getg().m.procid = uint64(lwp_gettid())
minitSignals()
}
@@ -288,3 +287,17 @@ func sysauxv(auxv []uintptr) {
}
}
}
+
+// raise sends a 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(-1, lwp_gettid(), int(sig))
+}
+
+func signalM(mp *m, sig int) {
+ lwp_kill(-1, int32(mp.procid), sig)
+}