github.com/Rookout/GoSDK@v0.1.48/pkg/services/instrumentation/module/module1.16.go (about) 1 //go:build go1.16 && !go1.18 2 // +build go1.16,!go1.18 3 4 package module 5 6 import ( 7 "unsafe" 8 ) 9 10 11 12 type funcFlag uint8 13 14 //go:linkname functab runtime.functab 15 type functab struct { 16 entry uintptr 17 funcoff uintptr 18 } 19 20 //go:linkname textsect runtime.textsect 21 type textsect struct { 22 vaddr uintptr 23 length uintptr 24 baseaddr uintptr 25 } 26 27 type _func struct { 28 entry uintptr 29 nameoff int32 30 31 args int32 32 deferreturn uint32 33 34 pcsp uint32 35 pcfile uint32 36 pcln uint32 37 npcdata uint32 38 cuOffset uint32 39 funcID FuncID 40 _ [2]byte 41 nfuncdata uint8 42 } 43 44 type pcHeader struct { 45 magic uint32 46 pad1, pad2 uint8 47 minLC uint8 48 ptrSize uint8 49 nfunc int 50 nfiles uint 51 funcnameOffset uintptr 52 cuOffset uintptr 53 filetabOffset uintptr 54 pctabOffset uintptr 55 pclnOffset uintptr 56 } 57 58 //go:linkname moduledata runtime.moduledata 59 type moduledata struct { 60 pcHeader *pcHeader 61 funcnametab []byte 62 cutab []uint32 63 filetab []byte 64 pctab []byte 65 66 pclntable []byte 67 ftab []functab 68 findfunctab uintptr 69 minpc, maxpc uintptr 70 71 text, etext uintptr 72 noptrdata, enoptrdata uintptr 73 data, edata uintptr 74 bss, ebss uintptr 75 noptrbss, enoptrbss uintptr 76 end, gcdata, gcbss uintptr 77 types, etypes uintptr 78 79 textsectmap []textsect 80 typelinks []int32 81 itablinks []*itab 82 83 ptab []ptabEntry 84 85 pluginpath string 86 pkghashes []modulehash 87 88 modulename string 89 modulehashes []modulehash 90 91 hasmain uint8 92 93 gcdatamask, gcbssmask bitvector 94 95 typemap map[TypeOff]uintptr 96 97 bad bool 98 99 next *moduledata 100 } 101 102 func getPCTab(m *moduledata) []byte { 103 return m.pctab 104 } 105 106 func (f *FuncInfo) getEntry() uintptr { 107 return f.entry 108 } 109 110 111 func findFuncOffsetInModule(pc uintptr, datap *moduledata) (uintptr, bool) { 112 if datap == nil { 113 return 0, false 114 } 115 const nsub = uintptr(len(findfuncbucket{}.subbuckets)) 116 117 x := pc - datap.minpc 118 b := x / pcbucketsize 119 i := x % pcbucketsize / (pcbucketsize / nsub) 120 121 //goland:noinspection GoVetUnsafePointer 122 ffb := (*findfuncbucket)(add(unsafe.Pointer(datap.findfunctab), b*unsafe.Sizeof(findfuncbucket{}))) 123 idx := ffb.idx + uint32(ffb.subbuckets[i]) 124 125 126 127 128 129 if idx >= uint32(len(datap.ftab)) { 130 idx = uint32(len(datap.ftab) - 1) 131 } 132 if pc < datap.ftab[idx].entry { 133 134 135 136 for datap.ftab[idx].entry > pc && idx > 0 { 137 idx-- 138 } 139 if idx == 0 { 140 141 println("findfunc: bad findfunctab entry idx") 142 } 143 } else { 144 145 for datap.ftab[idx+1].entry <= pc { 146 idx++ 147 } 148 } 149 funcoff := datap.ftab[idx].funcoff 150 if funcoff == ^uintptr(0) { 151 152 153 154 155 return 0, false 156 } 157 return funcoff, true 158 } 159 160 func (md *moduledata) GetTypeMap() map[TypeOff]uintptr { 161 return md.typemap 162 }