代码拉取完成,页面将自动刷新
package routine
import (
"fmt"
"reflect"
"unsafe"
)
var (
offsetGoid uintptr
offsetPaniconfault uintptr
offsetGopc uintptr
offsetLabels uintptr
)
func init() {
gt := getgt()
offsetGoid = offset(gt, "goid")
offsetPaniconfault = offset(gt, "paniconfault")
offsetGopc = offset(gt, "gopc")
offsetLabels = offset(gt, "labels")
}
type g struct {
goid int64
paniconfault *bool
gopc *uintptr
labels *unsafe.Pointer
}
//go:norace
func (gp g) getPanicOnFault() bool {
return *gp.paniconfault
}
//go:norace
func (gp g) setPanicOnFault(new bool) (old bool) {
old = *gp.paniconfault
*gp.paniconfault = new
return old
}
//go:norace
func (gp g) getLabels() unsafe.Pointer {
return *gp.labels
}
//go:norace
func (gp g) setLabels(labels unsafe.Pointer) {
*gp.labels = labels
}
// getg returns current coroutine struct.
func getg() g {
gp := getgp()
if gp == nil {
panic("Failed to get gp from runtime natively.")
}
return g{
goid: *(*int64)(add(gp, offsetGoid)),
paniconfault: (*bool)(add(gp, offsetPaniconfault)),
gopc: (*uintptr)(add(gp, offsetGopc)),
labels: (*unsafe.Pointer)(add(gp, offsetLabels)),
}
}
// offset returns the offset of the specified field.
func offset(t reflect.Type, f string) uintptr {
field, found := t.FieldByName(f)
if found {
return field.Offset
}
panic(fmt.Sprintf("No such field '%v' of struct '%v.%v'.", f, t.PkgPath(), t.Name()))
}
// add pointer addition operation.
func add(p unsafe.Pointer, x uintptr) unsafe.Pointer {
return unsafe.Pointer(uintptr(p) + x)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。