github.com/davecheney/badidea@v1.0.0/id_go113.go (about)

     1  // +build go1.13
     2  
     3  package badidea
     4  
     5  import (
     6  	"unsafe"
     7  )
     8  
     9  //go:linkname runtime_getm runtime.getm
    10  func runtime_getm() uintptr
    11  
    12  // from runtime/runtime2.go
    13  
    14  // m duplicates enough of the runtime.m type to find the correct
    15  // offset of m.curg.
    16  type m struct {
    17  	g0      *g     // goroutine with scheduling stack
    18  	morebuf gobuf  // gobuf arg to morestack
    19  	divmod  uint32 // div/mod denominator for arm - known to liblink
    20  
    21  	// Fields not known to debuggers.
    22  	procid     uint64       // for debuggers, but offset not hard-coded
    23  	gsignal    *g           // signal-handling g
    24  	goSigStack gsignalStack // Go-allocated signal handling stack
    25  	sigmask    sigset       // storage for saved signal mask
    26  	tls        [6]uintptr   // thread-local storage (for x86 extern register)
    27  	mstartfn   func()
    28  	curg       *g // current running goroutine
    29  }
    30  
    31  // g provides enough of the runtime.g definition to find the
    32  // correct offset for g.id.
    33  type g struct {
    34  	// Stack parameters.
    35  	// stack describes the actual stack memory: [stack.lo, stack.hi).
    36  	// stackguard0 is the stack pointer compared in the Go stack growth prologue.
    37  	// It is stack.lo+StackGuard normally, but can be StackPreempt to trigger a preemption.
    38  	// stackguard1 is the stack pointer compared in the C stack growth prologue.
    39  	// It is stack.lo+StackGuard on g0 and gsignal stacks.
    40  	// It is ~0 on other goroutine stacks, to trigger a call to morestackc (and crash).
    41  	stack       stack   // offset known to runtime/cgo
    42  	stackguard0 uintptr // offset known to liblink
    43  	stackguard1 uintptr // offset known to liblink
    44  
    45  	_panic       unsafe.Pointer // innermost panic - offset known to liblink
    46  	_defer       unsafe.Pointer // innermost defer
    47  	m            unsafe.Pointer // current m; offset known to arm liblink
    48  	sched        gobuf
    49  	syscallsp    uintptr        // if status==Gsyscall, syscallsp = sched.sp to use during gc
    50  	syscallpc    uintptr        // if status==Gsyscall, syscallpc = sched.pc to use during gc
    51  	stktopsp     uintptr        // expected sp at top of stack, to check in traceback
    52  	param        unsafe.Pointer // passed parameter on wakeup
    53  	atomicstatus uint32
    54  	stackLock    uint32 // sigprof/scang lock; TODO: fold in to atomicstatus
    55  	goid         int64
    56  }
    57  
    58  type sigset uint32
    59  
    60  type guintptr uintptr
    61  
    62  type gobuf struct {
    63  	// The offsets of sp, pc, and g are known to (hard-coded in) libmach.
    64  	//
    65  	// ctxt is unusual with respect to GC: it may be a
    66  	// heap-allocated funcval so write require a write barrier,
    67  	// but gobuf needs to be cleared from assembly. We take
    68  	// advantage of the fact that the only path that uses a
    69  	// non-nil ctxt is morestack. As a result, gogo is the only
    70  	// place where it may not already be nil, so gogo uses an
    71  	// explicit write barrier. Everywhere else that resets the
    72  	// gobuf asserts that ctxt is already nil.
    73  	sp   uintptr
    74  	pc   uintptr
    75  	g    guintptr
    76  	ctxt unsafe.Pointer // this has to be a pointer so that gc scans it
    77  	ret  uint64
    78  	lr   uintptr
    79  	bp   uintptr // for GOEXPERIMENT=framepointer
    80  }
    81  
    82  // Stack describes a Go execution stack.
    83  // The bounds of the stack are exactly [lo, hi),
    84  // with no implicit data structures on either side.
    85  type stack struct {
    86  	lo uintptr
    87  	hi uintptr
    88  }
    89  
    90  // gsignalStack saves the fields of the gsignal stack changed by
    91  // setGsignalStack.
    92  type gsignalStack struct {
    93  	stack       stack
    94  	stackguard0 uintptr
    95  	stackguard1 uintptr
    96  	stktopsp    uintptr
    97  }