1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | // |
6 | // readytorun.h |
7 | // |
8 | |
9 | // |
10 | // Contains definitions for the Ready to Run file format |
11 | // |
12 | |
13 | #ifndef __READYTORUN_H__ |
14 | #define __READYTORUN_H__ |
15 | |
16 | #define READYTORUN_SIGNATURE 0x00525452 // 'RTR' |
17 | |
18 | #define READYTORUN_MAJOR_VERSION 0x0002 |
19 | #define READYTORUN_MINOR_VERSION 0x0002 |
20 | // R2R Version 2.1 adds the READYTORUN_SECTION_INLINING_INFO section |
21 | // R2R Version 2.2 adds the READYTORUN_SECTION_PROFILEDATA_INFO section |
22 | |
23 | struct |
24 | { |
25 | DWORD ; // READYTORUN_SIGNATURE |
26 | USHORT ; // READYTORUN_VERSION_XXX |
27 | USHORT ; |
28 | |
29 | DWORD ; // READYTORUN_FLAG_XXX |
30 | |
31 | DWORD ; |
32 | |
33 | // Array of sections follows. The array entries are sorted by Type |
34 | // READYTORUN_SECTION Sections[]; |
35 | }; |
36 | |
37 | struct READYTORUN_SECTION |
38 | { |
39 | DWORD Type; // READYTORUN_SECTION_XXX |
40 | IMAGE_DATA_DIRECTORY Section; |
41 | }; |
42 | |
43 | enum ReadyToRunFlag |
44 | { |
45 | // Set if the original IL assembly was platform-neutral |
46 | READYTORUN_FLAG_PLATFORM_NEUTRAL_SOURCE = 0x00000001, |
47 | READYTORUN_FLAG_SKIP_TYPE_VALIDATION = 0x00000002, |
48 | }; |
49 | |
50 | enum ReadyToRunSectionType |
51 | { |
52 | READYTORUN_SECTION_COMPILER_IDENTIFIER = 100, |
53 | READYTORUN_SECTION_IMPORT_SECTIONS = 101, |
54 | READYTORUN_SECTION_RUNTIME_FUNCTIONS = 102, |
55 | READYTORUN_SECTION_METHODDEF_ENTRYPOINTS = 103, |
56 | READYTORUN_SECTION_EXCEPTION_INFO = 104, |
57 | READYTORUN_SECTION_DEBUG_INFO = 105, |
58 | READYTORUN_SECTION_DELAYLOAD_METHODCALL_THUNKS = 106, |
59 | // 107 used by an older format of READYTORUN_SECTION_AVAILABLE_TYPES |
60 | READYTORUN_SECTION_AVAILABLE_TYPES = 108, |
61 | READYTORUN_SECTION_INSTANCE_METHOD_ENTRYPOINTS = 109, |
62 | READYTORUN_SECTION_INLINING_INFO = 110, // Added in V2.1 |
63 | READYTORUN_SECTION_PROFILEDATA_INFO = 111 // Added in V2.2 |
64 | |
65 | // If you add a new section consider whether it is a breaking or non-breaking change. |
66 | // Usually it is non-breaking, but if it is preferable to have older runtimes fail |
67 | // to load the image vs. ignoring the new section it could be marked breaking. |
68 | // Increment the READYTORUN_MINOR_VERSION (non-breaking) or READYTORUN_MAJOR_VERSION |
69 | // (breaking) as appropriate. |
70 | }; |
71 | |
72 | // |
73 | // READYTORUN_IMPORT_SECTION describes image range with references to code or runtime data structures |
74 | // |
75 | // There is number of different types of these ranges: eagerly initialized at image load vs. lazily initialized at method entry |
76 | // vs. lazily initialized on first use; handles vs. code pointers, etc. |
77 | // |
78 | struct READYTORUN_IMPORT_SECTION |
79 | { |
80 | IMAGE_DATA_DIRECTORY Section; // Section containing values to be fixed up |
81 | USHORT Flags; // One or more of ReadyToRunImportSectionFlags |
82 | BYTE Type; // One of ReadyToRunImportSectionType |
83 | BYTE EntrySize; |
84 | DWORD Signatures; // RVA of optional signature descriptors |
85 | DWORD AuxiliaryData; // RVA of optional auxiliary data (typically GC info) |
86 | }; |
87 | |
88 | enum ReadyToRunImportSectionType |
89 | { |
90 | READYTORUN_IMPORT_SECTION_TYPE_UNKNOWN = 0, |
91 | }; |
92 | |
93 | enum ReadyToRunImportSectionFlags |
94 | { |
95 | READYTORUN_IMPORT_SECTION_FLAGS_EAGER = 0x0001, |
96 | }; |
97 | |
98 | // |
99 | // Constants for method and field encoding |
100 | // |
101 | |
102 | enum ReadyToRunMethodSigFlags |
103 | { |
104 | READYTORUN_METHOD_SIG_UnboxingStub = 0x01, |
105 | READYTORUN_METHOD_SIG_InstantiatingStub = 0x02, |
106 | READYTORUN_METHOD_SIG_MethodInstantiation = 0x04, |
107 | READYTORUN_METHOD_SIG_SlotInsteadOfToken = 0x08, |
108 | READYTORUN_METHOD_SIG_MemberRefToken = 0x10, |
109 | READYTORUN_METHOD_SIG_Constrained = 0x20, |
110 | READYTORUN_METHOD_SIG_OwnerType = 0x40, |
111 | }; |
112 | |
113 | enum ReadyToRunFieldSigFlags |
114 | { |
115 | READYTORUN_FIELD_SIG_IndexInsteadOfToken = 0x08, |
116 | READYTORUN_FIELD_SIG_MemberRefToken = 0x10, |
117 | READYTORUN_FIELD_SIG_OwnerType = 0x40, |
118 | }; |
119 | |
120 | enum ReadyToRunTypeLayoutFlags |
121 | { |
122 | READYTORUN_LAYOUT_HFA = 0x01, |
123 | READYTORUN_LAYOUT_Alignment = 0x02, |
124 | READYTORUN_LAYOUT_Alignment_Native = 0x04, |
125 | READYTORUN_LAYOUT_GCLayout = 0x08, |
126 | READYTORUN_LAYOUT_GCLayout_Empty = 0x10, |
127 | }; |
128 | |
129 | // |
130 | // Constants for fixup signature encoding |
131 | // |
132 | |
133 | enum ReadyToRunFixupKind |
134 | { |
135 | READYTORUN_FIXUP_ThisObjDictionaryLookup = 0x07, |
136 | READYTORUN_FIXUP_TypeDictionaryLookup = 0x08, |
137 | READYTORUN_FIXUP_MethodDictionaryLookup = 0x09, |
138 | |
139 | READYTORUN_FIXUP_TypeHandle = 0x10, |
140 | READYTORUN_FIXUP_MethodHandle = 0x11, |
141 | READYTORUN_FIXUP_FieldHandle = 0x12, |
142 | |
143 | READYTORUN_FIXUP_MethodEntry = 0x13, /* For calling a method entry point */ |
144 | READYTORUN_FIXUP_MethodEntry_DefToken = 0x14, /* Smaller version of MethodEntry - method is def token */ |
145 | READYTORUN_FIXUP_MethodEntry_RefToken = 0x15, /* Smaller version of MethodEntry - method is ref token */ |
146 | |
147 | READYTORUN_FIXUP_VirtualEntry = 0x16, /* For invoking a virtual method */ |
148 | READYTORUN_FIXUP_VirtualEntry_DefToken = 0x17, /* Smaller version of VirtualEntry - method is def token */ |
149 | READYTORUN_FIXUP_VirtualEntry_RefToken = 0x18, /* Smaller version of VirtualEntry - method is ref token */ |
150 | READYTORUN_FIXUP_VirtualEntry_Slot = 0x19, /* Smaller version of VirtualEntry - type & slot */ |
151 | |
152 | READYTORUN_FIXUP_Helper = 0x1A, /* Helper */ |
153 | READYTORUN_FIXUP_StringHandle = 0x1B, /* String handle */ |
154 | |
155 | READYTORUN_FIXUP_NewObject = 0x1C, /* Dynamically created new helper */ |
156 | READYTORUN_FIXUP_NewArray = 0x1D, |
157 | |
158 | READYTORUN_FIXUP_IsInstanceOf = 0x1E, /* Dynamically created casting helper */ |
159 | READYTORUN_FIXUP_ChkCast = 0x1F, |
160 | |
161 | READYTORUN_FIXUP_FieldAddress = 0x20, /* For accessing a cross-module static fields */ |
162 | READYTORUN_FIXUP_CctorTrigger = 0x21, /* Static constructor trigger */ |
163 | |
164 | READYTORUN_FIXUP_StaticBaseNonGC = 0x22, /* Dynamically created static base helpers */ |
165 | READYTORUN_FIXUP_StaticBaseGC = 0x23, |
166 | READYTORUN_FIXUP_ThreadStaticBaseNonGC = 0x24, |
167 | READYTORUN_FIXUP_ThreadStaticBaseGC = 0x25, |
168 | |
169 | READYTORUN_FIXUP_FieldBaseOffset = 0x26, /* Field base offset */ |
170 | READYTORUN_FIXUP_FieldOffset = 0x27, /* Field offset */ |
171 | |
172 | READYTORUN_FIXUP_TypeDictionary = 0x28, |
173 | READYTORUN_FIXUP_MethodDictionary = 0x29, |
174 | |
175 | READYTORUN_FIXUP_Check_TypeLayout = 0x2A, /* size, alignment, HFA, reference map */ |
176 | READYTORUN_FIXUP_Check_FieldOffset = 0x2B, |
177 | |
178 | READYTORUN_FIXUP_DelegateCtor = 0x2C, /* optimized delegate ctor */ |
179 | READYTORUN_FIXUP_DeclaringTypeHandle = 0x2D, |
180 | }; |
181 | |
182 | // |
183 | // Intrinsics and helpers |
184 | // |
185 | |
186 | enum ReadyToRunHelper |
187 | { |
188 | READYTORUN_HELPER_Invalid = 0x00, |
189 | |
190 | // Not a real helper - handle to current module passed to delay load helpers. |
191 | READYTORUN_HELPER_Module = 0x01, |
192 | READYTORUN_HELPER_GSCookie = 0x02, |
193 | |
194 | // |
195 | // Delay load helpers |
196 | // |
197 | |
198 | // All delay load helpers use custom calling convention: |
199 | // - scratch register - address of indirection cell. 0 = address is inferred from callsite. |
200 | // - stack - section index, module handle |
201 | READYTORUN_HELPER_DelayLoad_MethodCall = 0x08, |
202 | |
203 | READYTORUN_HELPER_DelayLoad_Helper = 0x10, |
204 | READYTORUN_HELPER_DelayLoad_Helper_Obj = 0x11, |
205 | READYTORUN_HELPER_DelayLoad_Helper_ObjObj = 0x12, |
206 | |
207 | // JIT helpers |
208 | |
209 | // Exception handling helpers |
210 | READYTORUN_HELPER_Throw = 0x20, |
211 | READYTORUN_HELPER_Rethrow = 0x21, |
212 | READYTORUN_HELPER_Overflow = 0x22, |
213 | READYTORUN_HELPER_RngChkFail = 0x23, |
214 | READYTORUN_HELPER_FailFast = 0x24, |
215 | READYTORUN_HELPER_ThrowNullRef = 0x25, |
216 | READYTORUN_HELPER_ThrowDivZero = 0x26, |
217 | |
218 | // Write barriers |
219 | READYTORUN_HELPER_WriteBarrier = 0x30, |
220 | READYTORUN_HELPER_CheckedWriteBarrier = 0x31, |
221 | READYTORUN_HELPER_ByRefWriteBarrier = 0x32, |
222 | |
223 | // Array helpers |
224 | READYTORUN_HELPER_Stelem_Ref = 0x38, |
225 | READYTORUN_HELPER_Ldelema_Ref = 0x39, |
226 | |
227 | READYTORUN_HELPER_MemSet = 0x40, |
228 | READYTORUN_HELPER_MemCpy = 0x41, |
229 | |
230 | // Get string handle lazily |
231 | READYTORUN_HELPER_GetString = 0x50, |
232 | |
233 | // Used by /Tuning for Profile optimizations |
234 | READYTORUN_HELPER_LogMethodEnter = 0x51, |
235 | |
236 | // Reflection helpers |
237 | READYTORUN_HELPER_GetRuntimeTypeHandle = 0x54, |
238 | READYTORUN_HELPER_GetRuntimeMethodHandle = 0x55, |
239 | READYTORUN_HELPER_GetRuntimeFieldHandle = 0x56, |
240 | |
241 | READYTORUN_HELPER_Box = 0x58, |
242 | READYTORUN_HELPER_Box_Nullable = 0x59, |
243 | READYTORUN_HELPER_Unbox = 0x5A, |
244 | READYTORUN_HELPER_Unbox_Nullable = 0x5B, |
245 | READYTORUN_HELPER_NewMultiDimArr = 0x5C, |
246 | READYTORUN_HELPER_NewMultiDimArr_NonVarArg = 0x5D, |
247 | |
248 | // Helpers used with generic handle lookup cases |
249 | READYTORUN_HELPER_NewObject = 0x60, |
250 | READYTORUN_HELPER_NewArray = 0x61, |
251 | READYTORUN_HELPER_CheckCastAny = 0x62, |
252 | READYTORUN_HELPER_CheckInstanceAny = 0x63, |
253 | READYTORUN_HELPER_GenericGcStaticBase = 0x64, |
254 | READYTORUN_HELPER_GenericNonGcStaticBase = 0x65, |
255 | READYTORUN_HELPER_GenericGcTlsBase = 0x66, |
256 | READYTORUN_HELPER_GenericNonGcTlsBase = 0x67, |
257 | READYTORUN_HELPER_VirtualFuncPtr = 0x68, |
258 | |
259 | // Long mul/div/shift ops |
260 | READYTORUN_HELPER_LMul = 0xC0, |
261 | READYTORUN_HELPER_LMulOfv = 0xC1, |
262 | READYTORUN_HELPER_ULMulOvf = 0xC2, |
263 | READYTORUN_HELPER_LDiv = 0xC3, |
264 | READYTORUN_HELPER_LMod = 0xC4, |
265 | READYTORUN_HELPER_ULDiv = 0xC5, |
266 | READYTORUN_HELPER_ULMod = 0xC6, |
267 | READYTORUN_HELPER_LLsh = 0xC7, |
268 | READYTORUN_HELPER_LRsh = 0xC8, |
269 | READYTORUN_HELPER_LRsz = 0xC9, |
270 | READYTORUN_HELPER_Lng2Dbl = 0xCA, |
271 | READYTORUN_HELPER_ULng2Dbl = 0xCB, |
272 | |
273 | // 32-bit division helpers |
274 | READYTORUN_HELPER_Div = 0xCC, |
275 | READYTORUN_HELPER_Mod = 0xCD, |
276 | READYTORUN_HELPER_UDiv = 0xCE, |
277 | READYTORUN_HELPER_UMod = 0xCF, |
278 | |
279 | // Floating point conversions |
280 | READYTORUN_HELPER_Dbl2Int = 0xD0, |
281 | READYTORUN_HELPER_Dbl2IntOvf = 0xD1, |
282 | READYTORUN_HELPER_Dbl2Lng = 0xD2, |
283 | READYTORUN_HELPER_Dbl2LngOvf = 0xD3, |
284 | READYTORUN_HELPER_Dbl2UInt = 0xD4, |
285 | READYTORUN_HELPER_Dbl2UIntOvf = 0xD5, |
286 | READYTORUN_HELPER_Dbl2ULng = 0xD6, |
287 | READYTORUN_HELPER_Dbl2ULngOvf = 0xD7, |
288 | |
289 | // Floating point ops |
290 | READYTORUN_HELPER_DblRem = 0xE0, |
291 | READYTORUN_HELPER_FltRem = 0xE1, |
292 | READYTORUN_HELPER_DblRound = 0xE2, |
293 | READYTORUN_HELPER_FltRound = 0xE3, |
294 | |
295 | #ifdef WIN64EXCEPTIONS |
296 | // Personality rountines |
297 | READYTORUN_HELPER_PersonalityRoutine = 0xF0, |
298 | READYTORUN_HELPER_PersonalityRoutineFilterFunclet = 0xF1, |
299 | #endif |
300 | |
301 | // |
302 | // Deprecated/legacy |
303 | // |
304 | |
305 | // JIT32 x86-specific write barriers |
306 | READYTORUN_HELPER_WriteBarrier_EAX = 0x100, |
307 | READYTORUN_HELPER_WriteBarrier_EBX = 0x101, |
308 | READYTORUN_HELPER_WriteBarrier_ECX = 0x102, |
309 | READYTORUN_HELPER_WriteBarrier_ESI = 0x103, |
310 | READYTORUN_HELPER_WriteBarrier_EDI = 0x104, |
311 | READYTORUN_HELPER_WriteBarrier_EBP = 0x105, |
312 | READYTORUN_HELPER_CheckedWriteBarrier_EAX = 0x106, |
313 | READYTORUN_HELPER_CheckedWriteBarrier_EBX = 0x107, |
314 | READYTORUN_HELPER_CheckedWriteBarrier_ECX = 0x108, |
315 | READYTORUN_HELPER_CheckedWriteBarrier_ESI = 0x109, |
316 | READYTORUN_HELPER_CheckedWriteBarrier_EDI = 0x10A, |
317 | READYTORUN_HELPER_CheckedWriteBarrier_EBP = 0x10B, |
318 | |
319 | // JIT32 x86-specific exception handling |
320 | READYTORUN_HELPER_EndCatch = 0x110, |
321 | }; |
322 | |
323 | // |
324 | // Exception info |
325 | // |
326 | |
327 | struct READYTORUN_EXCEPTION_LOOKUP_TABLE_ENTRY |
328 | { |
329 | DWORD MethodStart; |
330 | DWORD ExceptionInfo; |
331 | }; |
332 | |
333 | struct READYTORUN_EXCEPTION_CLAUSE |
334 | { |
335 | CorExceptionFlag Flags; |
336 | DWORD TryStartPC; |
337 | DWORD TryEndPC; |
338 | DWORD HandlerStartPC; |
339 | DWORD HandlerEndPC; |
340 | union { |
341 | mdToken ClassToken; |
342 | DWORD FilterOffset; |
343 | }; |
344 | }; |
345 | |
346 | #endif // __READYTORUN_H__ |
347 | |