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