[fuchsia] Don't expose runtime threads
Expose only the worker threads that have a P assigned so that
applications can use them to install thread profiles.
While I'm here, name all known threads to help with tracing go
processes.
Bug: 105041
Change-Id: I99eb0a18f623a5ffa77c8cf6d9de315696fb9eb2
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/go/+/703646
Reviewed-by: Devon H. O'Dell <dhobsd@google.com>
Commit-Queue: Bruno Dal Bo <brunodalbo@google.com>
(cherry picked from commit aec6f21eafe63945bd8341291f1921df0b854d69)
diff --git a/src/runtime/os_fuchsia.go b/src/runtime/os_fuchsia.go
index 048f409..712a1fe 100644
--- a/src/runtime/os_fuchsia.go
+++ b/src/runtime/os_fuchsia.go
@@ -275,17 +275,48 @@
func minit() {
var h uint32
asmcgocall(_cgo_get_thread_self_handle, unsafe.Pointer(&h))
- getg().m.thread = h
+ _g_ := getg()
+ _g_.m.thread = h
+
+ isWorker := _g_.m.p != 0 || _g_.m.nextp != 0
+ threadName := "go-worker"
+ if !isWorker {
+ // There are some known functions that we can compare against,
+ // unfortunately we can't use FuncForPC here because of the write
+ // barriers imposed by the callers.
+ switch funcPC(_g_.m.mstartfn) {
+ case funcPC(sysmon):
+ threadName = "sysmon"
+ case funcPC(watchexceptions):
+ threadName = "watchexceptions"
+ case funcPC(profileLoop):
+ threadName = "profileLoop"
+ case funcPC(templateThread):
+ threadName = "templateThread"
+ default:
+ threadName = "unknown-runtime-thread"
+ }
+ }
+
+ prop := []byte(threadName)
+ if status := vdsoCall_zx_object_set_property(h, propName, unsafe.Pointer(&prop[0]), uint(len(prop))); status != 0 {
+ println("runtime: vdsoCall_zx_object_set_property failed: ", status)
+ exit(2)
+ }
var info zxInfoHandleBasic
var actualSize uint64
var availSize uint64
if status := vdsoCall_zx_object_get_info(h, ZX_INFO_HANDLE_BASIC, unsafe.Pointer(&info), uint(unsafe.Sizeof(info)), unsafe.Pointer(&actualSize), unsafe.Pointer(&availSize)); status != ZX_OK {
println("failed to get the thread koid for tracing", status)
- return
+ } else {
+ _g_.m.threadKoid = info.koid
}
- getg().m.threadKoid = info.koid
- zx_notify_new_thread(h)
+
+ if isWorker {
+ // Don't notifiy users of runtime threads.
+ zx_notify_new_thread(h)
+ }
}
//go:nosplit
@@ -565,6 +596,7 @@
}
// zircon_mktls
+//
//go:nosplit
func zircon_mktls() {
// TODO