forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadytoruninfo.h
375 lines (294 loc) · 14.5 KB
/
readytoruninfo.h
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// ===========================================================================
// File: ReadyToRunInfo.h
//
//
// Runtime support for Ready to Run
// ===========================================================================
#ifndef _READYTORUNINFO_H_
#define _READYTORUNINFO_H_
#include "nativeformatreader.h"
#include "inlinetracking.h"
#include "wellknownattributes.h"
#include "nativeimage.h"
typedef DPTR(struct READYTORUN_SECTION) PTR_READYTORUN_SECTION;
class NativeImage;
class PrepareCodeConfig;
typedef DPTR(class ReadyToRunCoreInfo) PTR_ReadyToRunCoreInfo;
class ReadyToRunCoreInfo
{
private:
PTR_PEImageLayout m_pLayout;
PTR_READYTORUN_CORE_HEADER m_pCoreHeader;
Volatile<bool> m_fForbidLoadILBodyFixups;
public:
ReadyToRunCoreInfo();
ReadyToRunCoreInfo(PEImageLayout * pLayout, READYTORUN_CORE_HEADER * pCoreHeader);
PTR_PEImageLayout GetLayout() const { return m_pLayout; }
IMAGE_DATA_DIRECTORY * FindSection(ReadyToRunSectionType type) const;
void ForbidProcessMoreILBodyFixups() { m_fForbidLoadILBodyFixups = true; }
bool IsForbidProcessMoreILBodyFixups() { return m_fForbidLoadILBodyFixups; }
PTR_PEImageLayout GetImage() const
{
LIMITED_METHOD_CONTRACT;
return m_pLayout;
}
};
typedef DPTR(class ReadyToRunInfo) PTR_ReadyToRunInfo;
typedef DPTR(class ReadyToRunCoreInfo) PTR_ReadyToRunCoreInfo;
class ReadyToRun_EnclosingTypeMap
{
private:
uint16_t TypeCount = 0;
ReadyToRun_EnclosingTypeMap() = default;
public:
ReadyToRun_EnclosingTypeMap& operator=(const ReadyToRun_EnclosingTypeMap& other) = delete;
ReadyToRun_EnclosingTypeMap(const ReadyToRun_EnclosingTypeMap& other) = delete;
const static ReadyToRun_EnclosingTypeMap EmptyInstance;
mdTypeDef GetEnclosingType(mdTypeDef input, IMDInternalImport* pImport) const;
HRESULT GetEnclosingTypeNoThrow(mdTypeDef input, mdTypeDef *pEnclosingType, IMDInternalImport* pImport) const;
};
class ReadyToRun_TypeGenericInfoMap
{
private:
uint32_t TypeCount = 0;
ReadyToRunTypeGenericInfo GetTypeGenericInfo(mdTypeDef input, bool *foundResult) const;
ReadyToRun_TypeGenericInfoMap() = default;
public:
ReadyToRun_TypeGenericInfoMap& operator=(const ReadyToRun_TypeGenericInfoMap& other) = delete;
ReadyToRun_TypeGenericInfoMap(const ReadyToRun_TypeGenericInfoMap& other) = delete;
const static ReadyToRun_TypeGenericInfoMap EmptyInstance;
HRESULT IsGenericNoThrow(mdTypeDef input, bool *pIsGeneric, IMDInternalImport* pImport) const;
HRESULT GetGenericArgumentCountNoThrow(mdTypeDef input, uint32_t *pCount, IMDInternalImport* pImport) const;
bool IsGeneric(mdTypeDef input, IMDInternalImport* pImport) const;
uint32_t GetGenericArgumentCount(mdTypeDef input, IMDInternalImport* pImport) const;
bool HasVariance(mdTypeDef input, bool *foundResult) const;
bool HasConstraints(mdTypeDef input, bool *foundResult) const;
};
class ReadyToRun_MethodIsGenericMap
{
uint32_t MethodCount = 0;
ReadyToRun_MethodIsGenericMap() = default;
public:
ReadyToRun_MethodIsGenericMap& operator=(const ReadyToRun_MethodIsGenericMap& other) = delete;
ReadyToRun_MethodIsGenericMap(const ReadyToRun_MethodIsGenericMap& other) = delete;
const static ReadyToRun_MethodIsGenericMap EmptyInstance;
bool IsGeneric(mdMethodDef input, bool *foundResult) const;
};
class ReadyToRunInfo
{
friend class ReadyToRunJitManager;
// HotColdMappingLookupTable::LookupMappingForMethod searches m_pHotColdMap, and thus needs access.
friend class HotColdMappingLookupTable;
PTR_Module m_pModule;
PTR_ModuleBase m_pNativeManifestModule;
PTR_READYTORUN_HEADER m_pHeader;
bool m_isComponentAssembly;
PTR_NativeImage m_pNativeImage;
PTR_ReadyToRunInfo m_pCompositeInfo;
ReadyToRunCoreInfo m_component;
PTR_ReadyToRunCoreInfo m_pComposite;
PTR_RUNTIME_FUNCTION m_pRuntimeFunctions;
DWORD m_nRuntimeFunctions;
PTR_ULONG m_pHotColdMap;
DWORD m_nHotColdMap;
PTR_IMAGE_DATA_DIRECTORY m_pSectionDelayLoadMethodCallThunks;
PTR_READYTORUN_IMPORT_SECTION m_pImportSections;
DWORD m_nImportSections;
bool m_readyToRunCodeDisabled;
NativeFormat::NativeReader m_nativeReader;
NativeFormat::NativeArray m_methodDefEntryPoints;
NativeFormat::NativeHashtable m_instMethodEntryPoints;
NativeFormat::NativeHashtable m_availableTypesHashtable;
NativeFormat::NativeHashtable m_pgoInstrumentationDataHashtable;
NativeFormat::NativeHashtable m_pMetaDataHashtable;
NativeFormat::NativeCuckooFilter m_attributesPresence;
Crst m_Crst;
PtrHashMap m_entryPointToMethodDescMap;
PTR_PersistentInlineTrackingMapR2R m_pPersistentInlineTrackingMap;
PTR_PersistentInlineTrackingMapR2R m_pCrossModulePersistentInlineTrackingMap;
PTR_ReadyToRunInfo m_pNextR2RForUnrelatedCode;
public:
ReadyToRunInfo(Module * pModule, LoaderAllocator* pLoaderAllocator, PEImageLayout * pLayout, READYTORUN_HEADER * pHeader, NativeImage * pNativeImage, AllocMemTracker *pamTracker);
static PTR_ReadyToRunInfo ComputeAlternateGenericLocationForR2RCode(MethodDesc *pMethod);
static PTR_ReadyToRunInfo GetUnrelatedR2RModules();
PTR_ReadyToRunInfo GetNextUnrelatedR2RModule() { LIMITED_METHOD_CONTRACT; return dac_cast<PTR_ReadyToRunInfo>(dac_cast<TADDR>(m_pNextR2RForUnrelatedCode) & ~0x1); }
void RegisterUnrelatedR2RModule();
static PTR_ReadyToRunInfo Initialize(Module * pModule, AllocMemTracker *pamTracker);
bool IsComponentAssembly() const { return m_isComponentAssembly; }
static bool IsNativeImageSharedBy(PTR_Module pModule1, PTR_Module pModule2);
PTR_ModuleBase GetNativeManifestModule() const { return m_pNativeManifestModule; }
PTR_READYTORUN_HEADER GetReadyToRunHeader() const { return m_pHeader; }
PTR_IMAGE_DATA_DIRECTORY GetDelayMethodCallThunksSection() const { return m_pSectionDelayLoadMethodCallThunks; }
PTR_NativeImage GetNativeImage() const { return m_pNativeImage; }
PTR_PEImageLayout GetImage() const { return m_pComposite->GetImage(); }
IMAGE_DATA_DIRECTORY * FindSection(ReadyToRunSectionType type) const { return m_pComposite->FindSection(type); }
PCODE GetEntryPoint(MethodDesc * pMD, PrepareCodeConfig* pConfig, BOOL fFixups);
PTR_MethodDesc GetMethodDescForEntryPoint(PCODE entryPoint);
bool GetPgoInstrumentationData(MethodDesc * pMD, BYTE** pAllocatedMemory, ICorJitInfo::PgoInstrumentationSchema**ppSchema, UINT *pcSchema, BYTE** pInstrumentationData);
BOOL HasHashtableOfTypes();
BOOL TryLookupTypeTokenFromName(const NameHandle *pName, mdToken * pFoundTypeToken);
BOOL SkipTypeValidation()
{
LIMITED_METHOD_CONTRACT;
return m_pHeader->CoreHeader.Flags & READYTORUN_FLAG_SKIP_TYPE_VALIDATION;
}
BOOL IsPartial()
{
LIMITED_METHOD_CONTRACT;
return m_pHeader->CoreHeader.Flags & READYTORUN_FLAG_PARTIAL;
}
void DisableAllR2RCode()
{
LIMITED_METHOD_CONTRACT;
m_readyToRunCodeDisabled = true;
}
bool ReadyToRunCodeDisabled()
{
LIMITED_METHOD_CONTRACT;
return m_readyToRunCodeDisabled;
}
void ForbidProcessMoreILBodyFixups() { m_pComposite->ForbidProcessMoreILBodyFixups(); }
bool IsForbidProcessMoreILBodyFixups() { return m_pComposite->IsForbidProcessMoreILBodyFixups(); }
BOOL HasNonShareablePInvokeStubs()
{
LIMITED_METHOD_CONTRACT;
return m_pHeader->CoreHeader.Flags & READYTORUN_FLAG_NONSHARED_PINVOKE_STUBS;
}
bool MultiModuleVersionBubble()
{
LIMITED_METHOD_CONTRACT;
return m_pHeader->CoreHeader.Flags & READYTORUN_FLAG_MULTIMODULE_VERSION_BUBBLE;
}
PTR_READYTORUN_IMPORT_SECTION GetImportSections(COUNT_T * pCount)
{
LIMITED_METHOD_CONTRACT;
*pCount = m_nImportSections;
return m_pImportSections;
}
PTR_READYTORUN_IMPORT_SECTION GetImportSectionFromIndex(COUNT_T index)
{
LIMITED_METHOD_CONTRACT;
_ASSERTE(index < m_nImportSections);
return m_pImportSections + index;
}
PTR_READYTORUN_IMPORT_SECTION GetImportSectionForRVA(RVA rva)
{
LIMITED_METHOD_CONTRACT;
PTR_READYTORUN_IMPORT_SECTION pEnd = m_pImportSections + m_nImportSections;
for (PTR_READYTORUN_IMPORT_SECTION pSection = m_pImportSections; pSection < pEnd; pSection++)
{
if (rva >= VAL32(pSection->Section.VirtualAddress) && rva < VAL32(pSection->Section.VirtualAddress) + VAL32(pSection->Section.Size))
return pSection;
}
return NULL;
}
PTR_BYTE GetDebugInfo(PTR_RUNTIME_FUNCTION pRuntimeFunction);
class MethodIterator
{
ReadyToRunInfo * m_pInfo;
int m_methodDefIndex;
NativeFormat::NativeHashtable::AllEntriesEnumerator m_genericEnum;
NativeFormat::NativeParser m_genericParser;
uint m_genericCurrentOffset;
RID m_genericCurrentRid;
PCCOR_SIGNATURE m_genericCurrentSig;
void ParseGenericMethodSignatureAndRid(uint *offset, RID *rid);
public:
MethodIterator(ReadyToRunInfo * pInfo) :
m_pInfo(pInfo),
m_methodDefIndex(-1),
m_genericEnum(),
m_genericParser(),
m_genericCurrentOffset(-1),
m_genericCurrentRid(-1),
m_genericCurrentSig(NULL)
{
NativeFormat::PTR_NativeHashtable pHash = NULL;
if (!pInfo->m_instMethodEntryPoints.IsNull())
{
pHash = NativeFormat::PTR_NativeHashtable(&pInfo->m_instMethodEntryPoints);
}
m_genericEnum = NativeFormat::NativeHashtable::AllEntriesEnumerator(pHash);
}
BOOL Next();
MethodDesc * GetMethodDesc();
MethodDesc * GetMethodDesc_NoRestore();
PCODE GetMethodStartAddress();
};
static DWORD GetFieldBaseOffset(MethodTable * pMT);
PTR_PersistentInlineTrackingMapR2R GetInlineTrackingMap()
{
return m_pPersistentInlineTrackingMap;
}
bool HasReadyToRunInlineTrackingMap()
{
return (m_pPersistentInlineTrackingMap != NULL || m_pCrossModulePersistentInlineTrackingMap != NULL);
}
COUNT_T GetInliners(PTR_Module inlineeOwnerMod, mdMethodDef inlineeTkn, COUNT_T inlinersSize, MethodInModule *inliners, BOOL *incompleteData)
{
COUNT_T inlinersCount = 0;
if (m_pPersistentInlineTrackingMap != NULL)
{
COUNT_T newInliners = m_pPersistentInlineTrackingMap->GetInliners(inlineeOwnerMod, inlineeTkn, inlinersSize, inliners, incompleteData);
if (newInliners < inlinersSize)
{
inlinersSize -= newInliners;
inliners += newInliners;
}
inlinersCount += newInliners;
}
if (m_pCrossModulePersistentInlineTrackingMap != NULL)
{
COUNT_T newInliners = m_pCrossModulePersistentInlineTrackingMap->GetInliners(inlineeOwnerMod, inlineeTkn, inlinersSize, inliners, incompleteData);
if (newInliners < inlinersSize)
{
inlinersSize -= newInliners;
inliners += newInliners;
}
inlinersCount += newInliners;
}
return inlinersCount;
}
bool MayHaveCustomAttribute(WellKnownAttribute attribute, mdToken token);
void DisableCustomAttributeFilter();
BOOL IsImageVersionAtLeast(int majorVersion, int minorVersion);
private:
BOOL GetTypeNameFromToken(IMDInternalImport * pImport, mdToken mdType, LPCUTF8 * ppszName, LPCUTF8 * ppszNameSpace);
BOOL GetEnclosingToken(IMDInternalImport * pImport, ModuleBase *pModule1, mdToken mdType, mdToken * pEnclosingToken);
BOOL CompareTypeNameOfTokens(mdToken mdToken1, IMDInternalImport * pImport1, ModuleBase *pModule1, mdToken mdToken2, IMDInternalImport * pImport2, ModuleBase *pModule2);
PTR_MethodDesc GetMethodDescForEntryPointInNativeImage(PCODE entryPoint);
void SetMethodDescForEntryPointInNativeImage(PCODE entryPoint, PTR_MethodDesc methodDesc);
PTR_ReadyToRunCoreInfo GetComponentInfo() { return dac_cast<PTR_ReadyToRunCoreInfo>(&m_component); }
friend struct ::cdac_data<ReadyToRunInfo>;
};
template<>
struct cdac_data<ReadyToRunInfo>
{
static constexpr size_t CompositeInfo = offsetof(ReadyToRunInfo, m_pCompositeInfo);
static constexpr size_t NumRuntimeFunctions = offsetof(ReadyToRunInfo, m_nRuntimeFunctions);
static constexpr size_t RuntimeFunctions = offsetof(ReadyToRunInfo, m_pRuntimeFunctions);
static constexpr size_t NumHotColdMap = offsetof(ReadyToRunInfo, m_nHotColdMap);
static constexpr size_t HotColdMap = offsetof(ReadyToRunInfo, m_pHotColdMap);
static constexpr size_t DelayLoadMethodCallThunks = offsetof(ReadyToRunInfo, m_pSectionDelayLoadMethodCallThunks);
static constexpr size_t EntryPointToMethodDescMap = offsetof(ReadyToRunInfo, m_entryPointToMethodDescMap);
};
class DynamicHelpers
{
private:
static void EmitHelperWithArg(BYTE*& pCode, size_t rxOffset, LoaderAllocator * pAllocator, TADDR arg, PCODE target);
static PCODE GetDictionaryLookupHelper(CorInfoHelpFunc jitHelper);
public:
static PCODE CreateHelper(LoaderAllocator * pAllocator, TADDR arg, PCODE target);
static PCODE CreateHelperWithArg(LoaderAllocator * pAllocator, TADDR arg, PCODE target);
static PCODE CreateHelper(LoaderAllocator * pAllocator, TADDR arg, TADDR arg2, PCODE target);
static PCODE CreateHelperArgMove(LoaderAllocator * pAllocator, TADDR arg, PCODE target);
static PCODE CreateReturn(LoaderAllocator * pAllocator);
static PCODE CreateReturnConst(LoaderAllocator * pAllocator, TADDR arg);
static PCODE CreateReturnIndirConst(LoaderAllocator * pAllocator, TADDR arg, INT8 offset);
static PCODE CreateHelperWithTwoArgs(LoaderAllocator * pAllocator, TADDR arg, PCODE target);
static PCODE CreateHelperWithTwoArgs(LoaderAllocator * pAllocator, TADDR arg, TADDR arg2, PCODE target);
static PCODE CreateDictionaryLookupHelper(LoaderAllocator * pAllocator, CORINFO_RUNTIME_LOOKUP * pLookup, DWORD dictionaryIndexAndSlot, Module * pModule);
};
#endif // _READYTORUNINFO_H_