gcc/libgo/go/runtime/os_gccgo.go
Ian Lance Taylor c43137e800 runtime: add precise stack scan support
This CL adds support of precise stack scan using stack maps to
    the runtime. The stack maps are generated by the compiler (if
    supported). Each safepoint is associated with a (real or dummy)
    landing pad, and its "type info" in the exception table is a
    pointer to the stack map. When a stack is scanned, the stack map
    is found by the stack unwinding code by inspecting the exception
    table (LSDA).
    
    For precise stack scan we need to unwind the stack. There are
    three cases:
    
    - If a goroutine is scanning its own stack, it can unwind the
      stack and scan the frames.
    
    - If a goroutine is scanning another, stopped, goroutine, it
      cannot directly unwind the target stack. We handle this by
      switching (runtime.gogo) to the target g, letting it unwind
      and scan the stack, and switch back.
    
    - If we are scanning a goroutine that is blocked in a syscall,
      we send a signal to the target goroutine's thread, and let the
      signal handler unwind and scan the stack. Extra care is needed
      as this races with enter/exit syscall.
    
    Currently this is only implemented on linux.
    
    Reviewed-on: https://go-review.googlesource.com/c/140518

From-SVN: r266832
2018-12-05 23:09:51 +00:00

54 lines
1.2 KiB
Go

// 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"
)
// For C code to call:
//go:linkname minit runtime.minit
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) {
mp.gsignal = malg(true, true, &mp.gsignalstack, &mp.gsignalstacksize)
mp.gsignal.m = mp
}
// minit is called to initialize a new m (including the bootstrap m).
// Called on the new thread, cannot allocate memory.
func minit() {
minitSignals()
// FIXME: only works on linux for now.
getg().m.procid = uint64(gettid())
}
// Called from dropm to undo the effect of an minit.
//go:nosplit
//go:nowritebarrierrec
func unminit() {
unminitSignals()
}
var urandom_dev = []byte("/dev/urandom\x00")
func getRandomData(r []byte) {
if startupRandomData != nil {
n := copy(r, startupRandomData)
extendRandom(r, n)
return
}
fd := open(&urandom_dev[0], 0 /* O_RDONLY */, 0)
n := read(fd, unsafe.Pointer(&r[0]), int32(len(r)))
closefd(fd)
extendRandom(r, int(n))
}