forked from alangpierce/go-forceexport
-
Notifications
You must be signed in to change notification settings - Fork 1
/
go_1_16.go
161 lines (128 loc) · 4.42 KB
/
go_1_16.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//go:build go1.16 && !go1.18
// +build go1.16,!go1.18
package forceexport
import (
"runtime"
"unsafe"
)
type (
functab struct {
entry uintptr
funcoff uintptr
}
newModuleWrapper struct {
pcHeader *pcHeader
funcnametab []byte
cutab []uint32
filetab []byte
pctab []byte
pclntable []byte
ftab []functab
findfunctab uintptr
minpc, maxpc uintptr
text, etext uintptr
noptrdata, enoptrdata uintptr
data, edata uintptr
bss, ebss uintptr
noptrbss, enoptrbss uintptr
end, gcdata, gcbss uintptr
types, etypes uintptr
textsectmap []byte
typelinks []int32 // offsets from types
itablinks []byte
ptab []byte
pluginpath string
pkghashes []byte
modulename string
modulehashes []byte
hasmain uint8 // 1 if module contains the main function, 0 otherwise
gcdatamask, gcbssmask bitvector
typemap map[int32]*byte // offset to *_rtype in previous module
bad bool // module failed to load and should be ignored
next *newModuleWrapper
}
Moduledata struct {
pcHeader *pcHeader
}
// pcHeader holds data used by the pclntab lookups.
pcHeader struct {
magic uint32 // 0xFFFFFFFA
pad1, pad2 uint8 // 0,0
minLC uint8 // min instruction size
ptrSize uint8 // size of a ptr in bytes
nfunc int // number of functions in the module
nfiles uint // number of entries in the file tab.
funcnameOffset uintptr // offset to the funcnametab variable from pcHeader
cuOffset uintptr // offset to the cutab variable from pcHeader
filetabOffset uintptr // offset to the filetab variable from pcHeader
pctabOffset uintptr // offset to the pctab varible from pcHeader
pclnOffset uintptr // offset to the pclntab variable from pcHeader
}
// pcHeader holds data used by the pclntab lookups.
pcHeader1_18 struct {
magic uint32 // 0xFFFFFFF0
pad1, pad2 uint8 // 0,0
minLC uint8 // min instruction size
ptrSize uint8 // size of a ptr in bytes
nfunc int // number of functions in the module
nfiles uint // number of entries in the file tab
textStart uintptr // base for function entry PC offsets in this module, equal to moduledata.text
funcnameOffset uintptr // offset to the funcnametab variable from pcHeader
cuOffset uintptr // offset to the cutab variable from pcHeader
filetabOffset uintptr // offset to the filetab variable from pcHeader
pctabOffset uintptr // offset to the pctab variable from pcHeader
pclnOffset uintptr // offset to the pclntab variable from pcHeader
}
newModuleWrapper1_18 struct {
pcHeader *pcHeader1_18
funcnametab []byte
cutab []uint32
filetab []byte
pctab []byte
pclntable []byte
ftab []functab
findfunctab uintptr
minpc, maxpc uintptr
text, etext uintptr
noptrdata, enoptrdata uintptr
data, edata uintptr
bss, ebss uintptr
noptrbss, enoptrbss uintptr
end, gcdata, gcbss uintptr
types, etypes uintptr
rodata uintptr
gofunc uintptr // go.func.*
textsectmap []byte
typelinks []int32 // offsets from types
itablinks []byte
ptab []byte
pluginpath string
pkghashes []byte
modulename string
modulehashes []byte
hasmain uint8 // 1 if module contains the main function, 0 otherwise
gcdatamask, gcbssmask bitvector
typemap map[int32]*byte // offset to *_rtype in previous module
bad bool // module failed to load and should be ignored
next *newModuleWrapper1_18
}
)
func (me *newModuleWrapper) GetFtab() []functab {
return me.ftab
}
func (me *newModuleWrapper) GetFunc(ftab functab) *runtime.Func {
return (*runtime.Func)(unsafe.Pointer(uintptr(unsafe.Pointer(me.pcHeader)) + uintptr(me.pcHeader.pclnOffset) + ftab.funcoff))
//return (*runtime.Func)(unsafe.Pointer(&(*pcIntable)[ftab.funcoff]))
}
func (me *newModuleWrapper) GetNext() moduleWrapper {
if me.next != nil {
return me.next
}
return nil
}
func getModuleWrapper() moduleWrapper {
new := (*newModuleWrapper)(unsafe.Pointer(&Firstmoduledata))
return new
}
//go:linkname Firstmoduledata runtime.firstmoduledata
var Firstmoduledata Moduledata