github.com/tencent/goom@v1.0.1/internal/hack/ifunc_18.go (about)

     1  //go:build go1.18 && !go1.21
     2  // +build go1.18,!go1.21
     3  
     4  // Package hack 对 go 系统包的 hack, 包含一些系统结构体的 copy,需要和不同的 go 版本保持同步
     5  package hack
     6  
     7  import (
     8  	"unsafe"
     9  	_ "unsafe" // 匿名引入
    10  )
    11  
    12  // InterceptCallerSkip 拦截器 callerskip
    13  const InterceptCallerSkip = 5
    14  
    15  // Firstmoduledata keep async with runtime.Firstmoduledata
    16  //
    17  //go:linkname Firstmoduledata runtime.firstmoduledata
    18  var Firstmoduledata Moduledata
    19  
    20  // nolint
    21  // Moduledata keep async with runtime.Moduledata
    22  type Moduledata struct {
    23  	pcHeader     *uintptr
    24  	funcnametab  []byte
    25  	cutab        []uint32
    26  	filetab      []byte
    27  	pctab        []byte
    28  	Pclntable    []byte
    29  	Ftab         []Functab
    30  	findfunctab  uintptr
    31  	minpc, maxpc uintptr
    32  
    33  	text, etext           uintptr
    34  	noptrdata, enoptrdata uintptr
    35  	data, edata           uintptr
    36  	bss, ebss             uintptr
    37  	noptrbss, enoptrbss   uintptr
    38  	end, gcdata, gcbss    uintptr
    39  	types, etypes         uintptr
    40  	rodata                uintptr
    41  	gofunc                uintptr // go.func.*
    42  
    43  	textsectmap []textsect
    44  	typelinks   []int32 // offsets from types
    45  	itablinks   []*uintptr
    46  
    47  	ptab []interface{}
    48  
    49  	pluginpath string
    50  	pkghashes  []interface{}
    51  
    52  	modulename   string
    53  	modulehashes []interface{}
    54  
    55  	hasmain uint8 // 1 if module contains the main function, 0 otherwise
    56  
    57  	gcdatamask, gcbssmask Bitvector
    58  
    59  	_ map[typeOff]*interface{} // typemap: offset to *_rtype in previous module
    60  
    61  	_ bool // bad: module failed to load and should be ignored
    62  
    63  	Next *Moduledata
    64  }
    65  
    66  // Functab Functab
    67  type Functab struct {
    68  	Entry   uint32
    69  	Funcoff uint32
    70  }
    71  
    72  // nolint
    73  type textsect struct {
    74  	// nolint
    75  	vaddr    uintptr // prelinked section vaddr
    76  	length   uintptr // section length
    77  	baseaddr uintptr // relocated section address
    78  }
    79  
    80  // Bitvector Bitvector
    81  type Bitvector struct {
    82  	// nolint
    83  	n int32 // # of bits
    84  	// nolint
    85  	bytedata *uint8
    86  }
    87  
    88  // nolint
    89  type typeOff int32 // offset to an *rtype
    90  
    91  // Func convenience struct for modifying the underlying code pointer of a function
    92  // value. The actual struct has other values, but always starts with a code
    93  // pointer.
    94  type Func struct {
    95  	CodePtr uintptr
    96  }
    97  
    98  // Value reflect.Value
    99  type Value struct {
   100  	Typ  *uintptr
   101  	Ptr  unsafe.Pointer
   102  	Flag uintptr
   103  }