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// File: CEELOAD.H
6//
7
8//
9// CEELOAD.H defines the class use to represent the PE file
10// ===========================================================================
11
12#ifndef CEELOAD_H_
13#define CEELOAD_H_
14
15#include "common.h"
16#include "vars.hpp" // for LPCUTF8
17#include "hash.h"
18#include "clsload.hpp"
19#include "cgensys.h"
20#include "corsym.h"
21#include "typehandle.h"
22#include "arraylist.h"
23#include "pefile.h"
24#include "typehash.h"
25#include "contractimpl.h"
26#include "bitmask.h"
27#include "instmethhash.h"
28#include "eetwain.h" // For EnumGCRefs (we should probably move that somewhere else, but can't
29 // find anything better (modulo common or vars.hpp)
30#include "classloadlevel.h"
31#include "precode.h"
32#include "corbbtprof.h"
33#include "ilstubcache.h"
34#include "classhash.h"
35
36#ifdef FEATURE_PREJIT
37#include "corcompile.h"
38#include "dataimage.h"
39#include <gcinfodecoder.h>
40#endif // FEATURE_PREJIT
41
42#ifdef FEATURE_COMINTEROP
43#include "winrttypenameconverter.h"
44#endif // FEATURE_COMINTEROP
45
46#ifdef FEATURE_READYTORUN
47#include "readytoruninfo.h"
48#endif
49
50#include "ilinstrumentation.h"
51
52class PELoader;
53class Stub;
54class MethodDesc;
55class FieldDesc;
56class Crst;
57class ClassConverter;
58class RefClassWriter;
59class ReflectionModule;
60class EEStringData;
61class MethodDescChunk;
62class SigTypeContext;
63class Assembly;
64class BaseDomain;
65class AppDomain;
66class CompilationDomain;
67class DomainModule;
68struct DomainLocalModule;
69class SystemDomain;
70class Module;
71class SString;
72class Pending;
73class MethodTable;
74class AppDomain;
75class DynamicMethodTable;
76class CodeVersionManager;
77class CallCounter;
78class TieredCompilationManager;
79#ifdef FEATURE_PREJIT
80class CerNgenRootTable;
81struct MethodContextElement;
82class TypeHandleList;
83class ProfileEmitter;
84class TrackingMap;
85struct MethodInModule;
86class PersistentInlineTrackingMapNGen;
87
88// Hash table parameter of available classes (name -> module/class) hash
89#define AVAILABLE_CLASSES_HASH_BUCKETS 1024
90#define AVAILABLE_CLASSES_HASH_BUCKETS_COLLECTIBLE 128
91#define PARAMTYPES_HASH_BUCKETS 23
92#define PARAMMETHODS_HASH_BUCKETS 11
93#define METHOD_STUBS_HASH_BUCKETS 11
94#define GUID_TO_TYPE_HASH_BUCKETS 16
95
96// The native symbol reader dll name
97#if defined(_AMD64_)
98#define NATIVE_SYMBOL_READER_DLL W("Microsoft.DiaSymReader.Native.amd64.dll")
99#elif defined(_X86_)
100#define NATIVE_SYMBOL_READER_DLL W("Microsoft.DiaSymReader.Native.x86.dll")
101#elif defined(_ARM_)
102#define NATIVE_SYMBOL_READER_DLL W("Microsoft.DiaSymReader.Native.arm.dll")
103#elif defined(_ARM64_)
104// Use diasymreader until the package has an arm64 version - issue #7360
105//#define NATIVE_SYMBOL_READER_DLL W("Microsoft.DiaSymReader.Native.arm64.dll")
106#define NATIVE_SYMBOL_READER_DLL W("diasymreader.dll")
107#endif
108
109typedef DPTR(PersistentInlineTrackingMapNGen) PTR_PersistentInlineTrackingMapNGen;
110
111extern VerboseLevel g_CorCompileVerboseLevel;
112#endif // FEATURE_PREJIT
113
114//
115// LookupMaps are used to implement RID maps
116// It is a linked list of nodes, each handling a successive (and consecutive)
117// range of RIDs.
118//
119// LookupMapBase is non-type safe implementation of the worker methods. LookupMap is type
120// safe wrapper around it.
121//
122
123typedef DPTR(struct LookupMapBase) PTR_LookupMapBase;
124
125#ifdef FEATURE_PREJIT
126
127//
128// LookupMap cold entry compression support
129//
130// A lookup map (the cold section) is notionally an array of pointer values indexed by rid. The pointers are
131// generally to data structures such as MethodTables or MethodDescs. When we compress such a table (at ngen
132// time) we wish to avoid direct pointers, since these would need to be fixed up due to image base
133// relocations. Instead we store RVAs (Relative Virtual Addresses). Unlike regular RVAs our base address is
134// the map address itself (as opposed to the module base). We do this purely out of convenience since
135// LookupMaps don't store the module base address.
136//
137// It turns out that very often the value pointers (and hence the value RVAs) are related to each other:
138// adjacent map entries often point to data structures that were allocated next to or close to each other. The
139// compression algorithm takes advantage of this fact: instead of storing value RVAs we store the deltas
140// between RVAs. So the nth value in the table is composed of the addition of the deltas from the preceding (n
141// - 1) entries. Since the deltas are often small (especially when we take structure alignment into account
142// and realize that we can discard the lower 2 or 3 bits of the delta) we can store them in a compressed
143// manner by discarding the insignificant leading zero bits in each value.
144//
145// So now we imagine our compressed table to be a sequence of entries, each entry being a variably sized delta
146// from the previous entry. As a result we need some means to encode how large each delta in the table is. We
147// could use a fixed size field (a 5-bit length field would be able to encode any length between 1 and 32
148// bits, say). This is troublesome since although most entry values are close in value there are a few
149// (usually a minority) that require much larger deltas (hot/cold data splitting based on profiling can cause
150// this for instance). For most tables this would force us to use a large fixed-size length field for every
151// entry, just to deal with the relatively uncommon worst case (5 bits would be enough, but many entry deltas
152// can be encoded in 2 or 3 bits).
153//
154// Instead we utilize a compromise: we store all delta lengths with a small number of bits
155// (kLookupMapLengthBits below). Instead of encoding the length directly this value indexes a per-map table of
156// possible delta encoding lengths. During ngen we calculate the optimal value for each entry in this encoding
157// length table. The advantage here is that it lets us encode both best case and worst case delta lengths with
158// a fixed size but small field. The disadvantage is that some deltas will be encoded with more bits than they
159// strictly need.
160//
161// This still leaves the problem of runtime lookup performance. Touches to the cold section of a LookupMap
162// aren't all that critical (after all the data is meant to be cold), but looking up the last entry of a map
163// with 22 thousand entries (roughly what the MethodDefToDesc map in mscorlib is sized at at the time of
164// writing) is still likely to so inefficient as to be noticeable. Remember that the issue is that we have to
165// decode all predecessor entries in order to compute the value of a given entry in the table.
166//
167// To address this we introduce an index to each compressed map. The index contains an entry for each
168// kLookupMapIndexStride'th entry in the compressed map. The index entry consists of the RVA of the
169// corresponding table value and the bit offset into the compressed map at which the data for the next entry
170// commences. Thus we can use the index to find a value within kLookupMapIndexStride entries of our target and
171// then proceed to decode only the last few compressed entries to finish the job. This reduces the lookup to a
172// constant time operation once more (given a reasonable value for kLookupMapIndexStride).
173//
174// The main areas in which this algorithm can be tuned are the number of bits used as an index into the
175// encoding lengths table (kLookupMapLengthBits) and the frequency with which entries are bookmarked in the
176// index (kLookupMapIndexStride). The current values have been set based on looking at models of mscorlib,
177// PresentationCore and PresentationFramework built from the actual ridmap data in their ngen images and
178// methodically trying different values in order to maximize compression or balance size versus likely runtime
179// performance. An alternative strategy was considered using direct (non-length prefix) encoding of the
180// deltas with a couple of variantions on probability-based variable length encoding (completely unbalanced
181// tree and completely balanced tree with pessimally encoded worst case escapes). But these were found to
182// yield best case results similar to the above but with more complex processing required at ngen (optimal
183// results for these algorithms are achieved when you have enough resources to build a probability map of your
184// entire data).
185//
186// Note that not all lookup tables are suitable for compression. In fact we compress only TypeDefToMethodTable
187// and MethodDefToDesc tables. For one thing this optimization only brings benefits to larger tables. But more
188// importantly we cannot mutate compressed entries (for obvious reasons). Many of the lookup maps are only
189// partially populated at ngen time or otherwise might be updated at runtime and thus are not candidates.
190//
191// In the threshhold timeframe (predicted to be .Net 4.5.3 at the time of writing), we added profiler support
192// for adding new types to NGEN images. Historically we could always do this for jitted images, but one of the
193// blockers for NGEN were the compressed RID maps. We worked around that by supporting multi-node maps in which
194// the first node is compressed, but all future nodes are uncompressed. The NGENed portion will all land in the
195// compressed node, while the new profiler added data will land in the uncompressed portion. Note this could
196// probably be leveraged for other dynamic scenarios such as a limited form of EnC, but nothing further has
197// been implemented at this time.
198//
199
200// Some useful constants used when compressing tables.
201enum {
202 kLookupMapLengthBits = 2, // Bits used to encode an index into a table of possible value lengths
203 kLookupMapLengthEntries = 1 << kLookupMapLengthBits, // Number of entries in the encoding table above
204 kLookupMapIndexStride = 0x10, // The range of table entries covered by one index entry (power of two for faster hash lookup)
205 kBitsPerRVA = sizeof(DWORD) * 8, // Bits in an (uncompressed) table value RVA (RVAs
206 // currently still 32-bit even on 64-bit platforms)
207#ifdef _WIN64
208 kFlagBits = 3, // Number of bits at the bottom of a value
209 // pointer that may be used for flags
210#else // _WIN64
211 kFlagBits = 2,
212#endif // _WIN64
213
214};
215
216#endif // FEATURE_PREJIT
217
218struct LookupMapBase
219{
220 DPTR(LookupMapBase) pNext;
221
222 ArrayDPTR(TADDR) pTable;
223
224 // Number of elements in this node (only RIDs less than this value can be present in this node)
225 DWORD dwCount;
226
227 // Set of flags that the map supports writing on top of the data value
228 TADDR supportedFlags;
229
230#ifdef FEATURE_PREJIT
231 struct HotItem
232 {
233 DWORD rid;
234 TADDR value;
235 static int __cdecl Cmp(const void* a_, const void* b_);
236 };
237 DWORD dwNumHotItems;
238 ArrayDPTR(HotItem) hotItemList;
239 PTR_TADDR FindHotItemValuePtr(DWORD rid);
240
241 //
242 // Compressed map support
243 //
244 PTR_CBYTE pIndex; // Bookmark for every kLookupMapIndexStride'th entry in the table
245 DWORD cIndexEntryBits; // Number of bits in every index entry
246 DWORD cbTable; // Number of bytes of compressed table data at pTable
247 DWORD cbIndex; // Number of bytes of index data at pIndex
248 BYTE rgEncodingLengths[kLookupMapLengthEntries]; // Table of delta encoding lengths for
249 // compressed values
250
251 // Returns true if this map instance is compressed (this can only happen at runtime when running against
252 // an ngen image). Currently and for the forseeable future only TypeDefToMethodTable and MethodDefToDesc
253 // tables can be compressed.
254 bool MapIsCompressed()
255 {
256 LIMITED_METHOD_DAC_CONTRACT;
257 return pIndex != NULL;
258 }
259
260protected:
261 // Internal routine used to iterate though one entry in the compressed table.
262 INT32 GetNextCompressedEntry(BitStreamReader *pTableStream, INT32 iLastValue);
263
264public:
265 // Public method used to retrieve the full value (non-RVA) of a compressed table entry.
266 TADDR GetValueFromCompressedMap(DWORD rid);
267
268#ifndef DACCESS_COMPILE
269 void CreateHotItemList(DataImage *image, CorProfileData *profileData, int table, BOOL fSkipNullEntries = FALSE);
270 void Save(DataImage *image, DataImage::ItemKind kind, CorProfileData *profileData, int table, BOOL fCopyValues = FALSE);
271 void SaveUncompressedMap(DataImage *image, DataImage::ItemKind kind, BOOL fCopyValues = FALSE);
272 void ConvertSavedMapToUncompressed(DataImage *image, DataImage::ItemKind kind);
273 void Fixup(DataImage *image, BOOL fFixupEntries = TRUE);
274#endif // !DACCESS_COMPILE
275
276#ifdef _DEBUG
277 void CheckConsistentHotItemList();
278#endif
279
280#endif // FEATURE_PREJIT
281
282#ifdef DACCESS_COMPILE
283 void EnumMemoryRegions(CLRDataEnumMemoryFlags flags,
284 bool enumThis);
285 void ListEnumMemoryRegions(CLRDataEnumMemoryFlags flags);
286#endif // DACCESS_COMPILE
287
288 PTR_TADDR GetIndexPtr(DWORD index)
289 {
290 LIMITED_METHOD_DAC_CONTRACT;
291#ifdef FEATURE_PREJIT
292 _ASSERTE(!MapIsCompressed());
293#endif // FEATURE_PREJIT
294 _ASSERTE(index < dwCount);
295 return dac_cast<PTR_TADDR>(pTable) + index;
296 }
297
298 PTR_TADDR GetElementPtr(DWORD rid);
299 PTR_TADDR GrowMap(Module * pModule, DWORD rid);
300
301 // Get number of RIDs that this table can store
302 DWORD GetSize();
303
304#ifdef _DEBUG
305 void DebugGetRidMapOccupancy(DWORD *pdwOccupied, DWORD *pdwSize);
306#endif
307};
308
309#define NO_MAP_FLAGS ((TADDR)0)
310
311template <typename TYPE>
312struct LookupMap : LookupMapBase
313{
314 static TYPE GetValueAt(PTR_TADDR pValue, TADDR* pFlags, TADDR supportedFlags);
315
316#ifndef DACCESS_COMPILE
317 static void SetValueAt(PTR_TADDR pValue, TYPE value, TADDR flags);
318#endif // DACCESS_COMPILE
319
320 TYPE GetElement(DWORD rid, TADDR* pFlags);
321 void SetElement(DWORD rid, TYPE value, TADDR flags);
322 BOOL TrySetElement(DWORD rid, TYPE value, TADDR flags);
323 void AddElement(Module * pModule, DWORD rid, TYPE value, TADDR flags);
324 void EnsureElementCanBeStored(Module * pModule, DWORD rid);
325 DWORD Find(TYPE value, TADDR* flags);
326
327
328public:
329
330 //
331 // Retrieve the value associated with a rid
332 //
333 TYPE GetElement(DWORD rid)
334 {
335 WRAPPER_NO_CONTRACT;
336 SUPPORTS_DAC;
337
338 return GetElement(rid, NULL);
339 }
340
341 TYPE GetElementAndFlags(DWORD rid, TADDR* pFlags)
342 {
343 WRAPPER_NO_CONTRACT;
344 SUPPORTS_DAC;
345
346 _ASSERTE(pFlags != NULL);
347
348 return GetElement(rid, pFlags);
349 }
350
351 //
352 // Stores an association in a map that has been previously grown to
353 // the required size. Will never throw or fail.
354 //
355 void SetElement(DWORD rid, TYPE value)
356 {
357 WRAPPER_NO_CONTRACT;
358 SUPPORTS_DAC;
359
360 SetElement(rid, value, 0);
361 }
362
363 void SetElementWithFlags(DWORD rid, TYPE value, TADDR flags)
364 {
365 WRAPPER_NO_CONTRACT;
366 SUPPORTS_DAC;
367
368 // Validate flags: that they are in the predefined range and that the range does not collide with value
369 _ASSERTE((flags & supportedFlags) == flags);
370 _ASSERTE((dac_cast<TADDR>(value) & supportedFlags) == 0);
371
372 SetElement(rid, value, flags);
373 }
374
375#ifndef DACCESS_COMPILE
376 void AddFlag(DWORD rid, TADDR flag)
377 {
378 WRAPPER_NO_CONTRACT;
379
380 _ASSERTE((flag & supportedFlags) == flag);
381 _ASSERTE(!MapIsCompressed());
382 _ASSERTE(dwNumHotItems == 0);
383
384 PTR_TADDR pElement = GetElementPtr(rid);
385 _ASSERTE(pElement);
386
387 if (!pElement)
388 {
389 return;
390 }
391
392 TADDR existingFlags;
393 TYPE existingValue = GetValueAt(pElement, &existingFlags, supportedFlags);
394 SetValueAt(pElement, existingValue, existingFlags | flag);
395 }
396#endif // DACCESS_COMPILE
397
398 //
399 // Try to store an association in a map. Will never throw or fail.
400 //
401 BOOL TrySetElement(DWORD rid, TYPE value)
402 {
403 WRAPPER_NO_CONTRACT;
404
405 return TrySetElement(rid, value, 0);
406 }
407
408 BOOL TrySetElementWithFlags(DWORD rid, TYPE value, TADDR flags)
409 {
410 WRAPPER_NO_CONTRACT;
411
412 // Validate flags: that they are in the predefined range and that the range does not collide with value
413 _ASSERTE((flags & supportedFlags) == flags);
414 _ASSERTE((dac_cast<TADDR>(value) & supportedFlags) == 0);
415
416 return TrySetElement(rid, value, flags);
417 }
418
419 //
420 // Stores an association in a map. Grows the map as necessary.
421 //
422 void AddElement(Module * pModule, DWORD rid, TYPE value)
423 {
424 WRAPPER_NO_CONTRACT;
425
426 AddElement(pModule, rid, value, 0);
427 }
428
429 void AddElementWithFlags(Module * pModule, DWORD rid, TYPE value, TADDR flags)
430 {
431 WRAPPER_NO_CONTRACT;
432
433 // Validate flags: that they are in the predefined range and that the range does not collide with value
434 _ASSERTE((flags & supportedFlags) == flags);
435 _ASSERTE((dac_cast<TADDR>(value) & supportedFlags) == 0);
436
437 AddElement(pModule, rid, value, flags);
438 }
439
440 //
441 // Find the given value in the table and return its RID
442 //
443 DWORD Find(TYPE value)
444 {
445 WRAPPER_NO_CONTRACT;
446
447 return Find(value, NULL);
448 }
449
450 DWORD FindWithFlags(TYPE value, TADDR flags)
451 {
452 WRAPPER_NO_CONTRACT;
453
454 // Validate flags: that they are in the predefined range and that the range does not collide with value
455 _ASSERTE((flags & supportedFlags) == flags);
456 _ASSERTE((dac_cast<TADDR>(value) & supportedFlags) == 0);
457
458 return Find(value, &flags);
459 }
460
461 class Iterator
462 {
463 public:
464 Iterator(LookupMap* map);
465
466 BOOL Next();
467
468 TYPE GetElement()
469 {
470 WRAPPER_NO_CONTRACT;
471 SUPPORTS_DAC;
472
473 return GetElement(NULL);
474 }
475
476 TYPE GetElementAndFlags(TADDR* pFlags)
477 {
478 WRAPPER_NO_CONTRACT;
479 SUPPORTS_DAC;
480
481 return GetElement(pFlags);
482 }
483
484 private:
485 TYPE GetElement(TADDR* pFlags);
486
487 LookupMap* m_map;
488 DWORD m_index;
489#ifdef FEATURE_PREJIT
490 // Support for iterating compressed maps.
491 INT32 m_currentEntry; // RVA of current entry value
492 BitStreamReader m_tableStream; // Our current context in the compressed bit stream
493#endif // FEATURE_PREJIT
494 };
495};
496
497// Place holder types for RID maps that store cross-module references
498
499class TypeRef { };
500typedef DPTR(class TypeRef) PTR_TypeRef;
501
502class MemberRef { };
503typedef DPTR(class MemberRef) PTR_MemberRef;
504
505
506// flag used to mark member ref pointers to field descriptors in the member ref cache
507#define IS_FIELD_MEMBER_REF ((TADDR)0x00000002)
508
509
510#ifdef FEATURE_PREJIT
511//
512// NGen image layout information that we need to quickly access at runtime
513//
514typedef DPTR(struct NGenLayoutInfo) PTR_NGenLayoutInfo;
515struct NGenLayoutInfo
516{
517 // One range for each hot, unprofiled, cold code sections
518 MemoryRange m_CodeSections[3];
519
520 // Pointer to the RUNTIME_FUNCTION table for hot, unprofiled, and cold code sections.
521 PTR_RUNTIME_FUNCTION m_pRuntimeFunctions[3];
522
523 // Number of RUNTIME_FUNCTIONs for hot, unprofiled, and cold code sections.
524 DWORD m_nRuntimeFunctions[3];
525
526 // A parallel arrays of MethodDesc RVAs for hot and unprofiled methods. Both of the array are parallel for m_pRuntimeFunctions
527 // The first array is for hot methods. The second array is for unprofiled methods.
528 PTR_DWORD m_MethodDescs[2];
529
530 // Lookup table to speed up RUNTIME_FUNCTION lookup.
531 // The first array is for hot methods. The second array is for unprofiled methods.
532 // Number of elements is m_UnwindInfoLookupTableEntryCount + 1.
533 // Last element of the lookup table is a sentinal entry that's good to cover the rest of the code section.
534 // Values are indices into m_pRuntimeFunctions array.
535 PTR_DWORD m_UnwindInfoLookupTable[2];
536
537 // Count of lookup entries in m_UnwindInfoLookupTable
538 DWORD m_UnwindInfoLookupTableEntryCount[2];
539
540 // Map for matching the cold code with hot code. Index is relative position of RUNTIME_FUNCTION within the section.
541 PTR_CORCOMPILE_COLD_METHOD_ENTRY m_ColdCodeMap;
542
543 // One range for each hot, cold, write, hot writeable, and cold writeable precode sections
544 MemoryRange m_Precodes[4];
545
546 MemoryRange m_JumpStubs;
547 MemoryRange m_StubLinkStubs;
548 MemoryRange m_VirtualMethodThunks;
549 MemoryRange m_ExternalMethodThunks;
550 MemoryRange m_ExceptionInfoLookupTable;
551
552 PCODE m_pPrestubJumpStub;
553#ifdef HAS_FIXUP_PRECODE
554 PCODE m_pPrecodeFixupJumpStub;
555#endif
556 PCODE m_pVirtualImportFixupJumpStub;
557 PCODE m_pExternalMethodFixupJumpStub;
558 DWORD m_rvaFilterPersonalityRoutine;
559};
560#endif // FEATURE_PREJIT
561
562
563//
564// VASigCookies are allocated to encapsulate a varargs call signature.
565// A reference to the cookie is embedded in the code stream. Cookies
566// are shared amongst call sites with identical signatures in the same
567// module
568//
569
570typedef DPTR(struct VASigCookie) PTR_VASigCookie;
571typedef DPTR(PTR_VASigCookie) PTR_PTR_VASigCookie;
572struct VASigCookie
573{
574 // The JIT wants knows that the size of the arguments comes first
575 // so please keep this field first
576 unsigned sizeOfArgs; // size of argument list
577 Volatile<PCODE> pNDirectILStub; // will be use if target is NDirect (tag == 0)
578 PTR_Module pModule;
579 Signature signature;
580};
581
582//
583// VASigCookies are allocated in VASigCookieBlocks to amortize
584// allocation cost and allow proper bookkeeping.
585//
586
587struct VASigCookieBlock
588{
589 enum {
590#ifdef _DEBUG
591 kVASigCookieBlockSize = 2
592#else // !_DEBUG
593 kVASigCookieBlockSize = 20
594#endif // !_DEBUG
595 };
596
597 VASigCookieBlock *m_Next;
598 UINT m_numcookies;
599 VASigCookie m_cookies[kVASigCookieBlockSize];
600};
601
602// This lookup table persists the information about boxed statics into the ngen'ed image
603// which allows one to the type static initialization without touching expensive EEClasses. Note
604// that since the persisted info is stored at ngen time as opposed to class layout time,
605// in jitted scenarios we would still touch EEClasses. This imples that the variables which store
606// this info in the EEClasses are still present.
607
608// We used this table to store more data require to run cctors in the past (it explains the name),
609// but we are only using it for boxed statics now. Boxed statics are rare. The complexity may not
610// be worth the gains. We should consider removing this cache and avoid the complexity.
611
612typedef DPTR(struct ClassCtorInfoEntry) PTR_ClassCtorInfoEntry;
613struct ClassCtorInfoEntry
614{
615 DWORD firstBoxedStaticOffset;
616 DWORD firstBoxedStaticMTIndex;
617 WORD numBoxedStatics;
618 WORD hasFixedAddressVTStatics; // This is WORD avoid padding in the datastructure. It is really bool.
619};
620
621#define MODULE_CTOR_ELEMENTS 256
622struct ModuleCtorInfo
623{
624 DWORD numElements;
625 DWORD numLastAllocated;
626 DWORD numElementsHot;
627 DPTR(RelativePointer<PTR_MethodTable>) ppMT; // size is numElements
628 PTR_ClassCtorInfoEntry cctorInfoHot; // size is numElementsHot
629 PTR_ClassCtorInfoEntry cctorInfoCold; // size is numElements-numElementsHot
630
631 PTR_DWORD hotHashOffsets; // Indices to the start of each "hash region" in the hot part of the ppMT array.
632 PTR_DWORD coldHashOffsets; // Indices to the start of each "hash region" in the cold part of the ppMT array.
633 DWORD numHotHashes;
634 DWORD numColdHashes;
635
636 ArrayDPTR(RelativeFixupPointer<PTR_MethodTable>) ppHotGCStaticsMTs; // hot table
637 ArrayDPTR(RelativeFixupPointer<PTR_MethodTable>) ppColdGCStaticsMTs; // cold table
638
639 DWORD numHotGCStaticsMTs;
640 DWORD numColdGCStaticsMTs;
641
642#ifdef DACCESS_COMPILE
643 void EnumMemoryRegions(CLRDataEnumMemoryFlags flags);
644#endif
645
646 typedef enum {HOT, COLD} REGION;
647 FORCEINLINE DWORD GenerateHash(PTR_MethodTable pMT, REGION region)
648 {
649 SUPPORTS_DAC;
650
651 DWORD tmp1 = pMT->GetTypeDefRid();
652 DWORD tmp2 = pMT->GetNumVirtuals();
653 DWORD tmp3 = pMT->GetNumInterfaces();
654
655 tmp1 = (tmp1 << 7) + (tmp1 << 0); // 10000001
656 tmp2 = (tmp2 << 6) + (tmp2 << 1); // 01000010
657 tmp3 = (tmp3 << 4) + (tmp3 << 3); // 00011000
658
659 tmp1 ^= (tmp1 >> 4); // 10001001 0001
660 tmp2 ^= (tmp2 >> 4); // 01000110 0010
661 tmp3 ^= (tmp3 >> 4); // 00011001 1000
662
663 DWORD hashVal = tmp1 + tmp2 + tmp3;
664
665 if (region == HOT)
666 hashVal &= (numHotHashes - 1); // numHotHashes is required to be a power of two
667 else
668 hashVal &= (numColdHashes - 1); // numColdHashes is required to be a power of two
669
670 return hashVal;
671 };
672
673 ArrayDPTR(RelativeFixupPointer<PTR_MethodTable>) GetGCStaticMTs(DWORD index);
674
675 PTR_MethodTable GetMT(DWORD i)
676 {
677 LIMITED_METHOD_DAC_CONTRACT;
678 return ppMT[i].GetValue(dac_cast<TADDR>(ppMT) + i * sizeof(RelativePointer<PTR_MethodTable>));
679 }
680
681#ifdef FEATURE_PREJIT
682
683 void AddElement(MethodTable *pMethodTable);
684 void Save(DataImage *image, CorProfileData *profileData);
685 void Fixup(DataImage *image);
686
687 class ClassCtorInfoEntryArraySort : public CQuickSort<DWORD>
688 {
689 private:
690 DPTR(RelativePointer<PTR_MethodTable>) m_pBase1;
691
692 public:
693 //Constructor
694 ClassCtorInfoEntryArraySort(DWORD *base, DPTR(RelativePointer<PTR_MethodTable>) base1, int count)
695 : CQuickSort<DWORD>(base, count)
696 {
697 WRAPPER_NO_CONTRACT;
698
699 m_pBase1 = base1;
700 }
701
702 //Returns -1,0,or 1 if first's nativeStartOffset is less than, equal to, or greater than second's
703 FORCEINLINE int Compare(DWORD *first, DWORD *second)
704 {
705 LIMITED_METHOD_CONTRACT;
706
707 if (*first < *second)
708 return -1;
709 else if (*first == *second)
710 return 0;
711 else
712 return 1;
713 }
714
715#ifndef DACCESS_COMPILE
716 // Swap is overwriten so that we can sort both the MethodTable pointer
717 // array and the ClassCtorInfoEntry array in parrallel.
718 FORCEINLINE void Swap(SSIZE_T iFirst, SSIZE_T iSecond)
719 {
720 LIMITED_METHOD_CONTRACT;
721
722 DWORD sTemp;
723 PTR_MethodTable sTemp1;
724
725 if (iFirst == iSecond) return;
726
727 sTemp = m_pBase[iFirst];
728 m_pBase[iFirst] = m_pBase[iSecond];
729 m_pBase[iSecond] = sTemp;
730
731 sTemp1 = m_pBase1[iFirst].GetValueMaybeNull();
732 m_pBase1[iFirst].SetValueMaybeNull(m_pBase1[iSecond].GetValueMaybeNull());
733 m_pBase1[iSecond].SetValueMaybeNull(sTemp1);
734 }
735#endif // !DACCESS_COMPILE
736 };
737#endif // FEATURE_PREJIT
738};
739
740
741
742#ifdef FEATURE_PREJIT
743
744// For IBC Profiling we collect signature blobs for instantiated types.
745// For such instantiated types and methods we create our own ibc token
746//
747// For instantiated types, there also may be no corresponding type token
748// or method token for the instantiated types or method in our module.
749// For these cases we create our own ibc token definition that is used
750// to refer to these external types and methods. We have to handle
751// external nested types and namespaces and method signatures.
752//
753// ParamTypeSpec = 4, // Instantiated Type Signature
754// ParamMethodSpec = 5, // Instantiated Method Signature
755// ExternalNamespaceDef = 6, // External Namespace Token Definition
756// ExternalTypeDef = 7, // External Type Token Definition
757// ExternalSignatureDef = 8, // External Signature Definition
758// ExternalMethodDef = 9, // External Method Token Definition
759//
760// typedef DPTR(class ProfilingBlobEntry) PTR_ProfilingBlobEntry;
761class ProfilingBlobEntry
762{
763public:
764 virtual ~ProfilingBlobEntry() { LIMITED_METHOD_CONTRACT; };
765 virtual bool IsEqual(const ProfilingBlobEntry * other) const = 0; // Pure Virtual
766 virtual size_t Hash() const = 0;
767 virtual BlobType kind() const = 0;
768 virtual size_t varSize() const = 0;
769 virtual void newToken() = 0;
770 mdToken token() const { LIMITED_METHOD_CONTRACT; return m_token; }
771
772protected:
773 mdToken m_token;
774};
775
776class TypeSpecBlobEntry : public ProfilingBlobEntry
777{
778public:
779 TypeSpecBlobEntry(DWORD _cbSig, PCCOR_SIGNATURE _pSig);
780
781 virtual ~TypeSpecBlobEntry() { LIMITED_METHOD_CONTRACT; delete [] m_pSig; }
782 virtual BlobType kind() const { LIMITED_METHOD_CONTRACT; return ParamTypeSpec; }
783 virtual size_t varSize() const { LIMITED_METHOD_CONTRACT; return sizeof(COR_SIGNATURE) * m_cbSig; }
784 virtual void newToken() { LIMITED_METHOD_CONTRACT; m_token = ++s_lastTypeSpecToken; }
785 DWORD flags() const { LIMITED_METHOD_CONTRACT; return m_flags; }
786 DWORD cbSig() const { LIMITED_METHOD_CONTRACT; return m_cbSig; }
787 PCCOR_SIGNATURE pSig() const { LIMITED_METHOD_CONTRACT; return m_pSig; }
788 void orFlag(DWORD flag) { LIMITED_METHOD_CONTRACT; m_flags |= flag; }
789 static size_t HashInit() { LIMITED_METHOD_CONTRACT; return 156437; }
790
791 virtual bool IsEqual(const ProfilingBlobEntry * other) const;
792 virtual size_t Hash() const;
793
794 static const TypeSpecBlobEntry * FindOrAdd(PTR_Module pModule,
795 DWORD _cbSig,
796 PCCOR_SIGNATURE _pSig);
797
798private:
799 DWORD m_flags;
800 DWORD m_cbSig;
801 PCCOR_SIGNATURE m_pSig;
802
803 static idTypeSpec s_lastTypeSpecToken;
804};
805
806class MethodSpecBlobEntry : public ProfilingBlobEntry
807{
808public:
809 MethodSpecBlobEntry(DWORD _cbSig, PCCOR_SIGNATURE _pSig);
810
811 virtual ~MethodSpecBlobEntry() { LIMITED_METHOD_CONTRACT; delete [] m_pSig; }
812 virtual BlobType kind() const { LIMITED_METHOD_CONTRACT; return ParamMethodSpec; }
813 virtual size_t varSize() const { LIMITED_METHOD_CONTRACT; return sizeof(COR_SIGNATURE) * m_cbSig; }
814 virtual void newToken() { LIMITED_METHOD_CONTRACT; m_token = ++s_lastMethodSpecToken; }
815 DWORD flags() const { LIMITED_METHOD_CONTRACT; return m_flags; }
816 DWORD cbSig() const { LIMITED_METHOD_CONTRACT; return m_cbSig; }
817 PCCOR_SIGNATURE pSig() const { LIMITED_METHOD_CONTRACT; return m_pSig; }
818 void orFlag(DWORD flag) { LIMITED_METHOD_CONTRACT; m_flags |= flag; }
819 static size_t HashInit() { LIMITED_METHOD_CONTRACT; return 187751; }
820
821 virtual bool IsEqual(const ProfilingBlobEntry * other) const;
822 virtual size_t Hash() const;
823
824 static const MethodSpecBlobEntry * FindOrAdd(PTR_Module pModule,
825 DWORD _cbSig,
826 PCCOR_SIGNATURE _pSig);
827
828private:
829 DWORD m_flags;
830 DWORD m_cbSig;
831 PCCOR_SIGNATURE m_pSig;
832
833 static idTypeSpec s_lastMethodSpecToken;
834};
835
836class ExternalNamespaceBlobEntry : public ProfilingBlobEntry
837{
838public:
839 ExternalNamespaceBlobEntry(LPCSTR _pName);
840
841 virtual ~ExternalNamespaceBlobEntry() { LIMITED_METHOD_CONTRACT; delete [] m_pName; }
842 virtual BlobType kind() const { LIMITED_METHOD_CONTRACT; return ExternalNamespaceDef; }
843 virtual size_t varSize() const { LIMITED_METHOD_CONTRACT; return sizeof(CHAR) * m_cbName; }
844 virtual void newToken() { LIMITED_METHOD_CONTRACT; m_token = ++s_lastExternalNamespaceToken; }
845 DWORD cbName() const { LIMITED_METHOD_CONTRACT; return m_cbName; }
846 LPCSTR pName() const { LIMITED_METHOD_CONTRACT; return m_pName; }
847 static size_t HashInit() { LIMITED_METHOD_CONTRACT; return 225307; }
848
849 virtual bool IsEqual(const ProfilingBlobEntry * other) const;
850 virtual size_t Hash() const;
851
852 static const ExternalNamespaceBlobEntry * FindOrAdd(PTR_Module pModule, LPCSTR _pName);
853
854private:
855 DWORD m_cbName;
856 LPCSTR m_pName;
857
858 static idExternalNamespace s_lastExternalNamespaceToken;
859};
860
861class ExternalTypeBlobEntry : public ProfilingBlobEntry
862{
863public:
864 ExternalTypeBlobEntry(mdToken _assemblyRef, mdToken _nestedClass,
865 mdToken _nameSpace, LPCSTR _pName);
866
867 virtual ~ExternalTypeBlobEntry() { LIMITED_METHOD_CONTRACT; delete [] m_pName; }
868 virtual BlobType kind() const { LIMITED_METHOD_CONTRACT; return ExternalTypeDef; }
869 virtual size_t varSize() const { LIMITED_METHOD_CONTRACT; return sizeof(CHAR) * m_cbName; }
870 virtual void newToken() { LIMITED_METHOD_CONTRACT; m_token = ++s_lastExternalTypeToken; }
871 mdToken assemblyRef() const { LIMITED_METHOD_CONTRACT; return m_assemblyRef; }
872 mdToken nestedClass() const { LIMITED_METHOD_CONTRACT; return m_nestedClass; }
873 mdToken nameSpace() const { LIMITED_METHOD_CONTRACT; return m_nameSpace; }
874 DWORD cbName() const { LIMITED_METHOD_CONTRACT; return m_cbName; }
875 LPCSTR pName() const { LIMITED_METHOD_CONTRACT; return m_pName; }
876 static size_t HashInit() { LIMITED_METHOD_CONTRACT; return 270371; }
877
878 virtual bool IsEqual(const ProfilingBlobEntry * other) const;
879 virtual size_t Hash() const;
880
881 static const ExternalTypeBlobEntry * FindOrAdd(PTR_Module pModule,
882 mdToken _assemblyRef,
883 mdToken _nestedClass,
884 mdToken _nameSpace,
885 LPCSTR _pName);
886
887private:
888 mdToken m_assemblyRef;
889 mdToken m_nestedClass;
890 mdToken m_nameSpace;
891 DWORD m_cbName;
892 LPCSTR m_pName;
893
894 static idExternalType s_lastExternalTypeToken;
895};
896
897class ExternalSignatureBlobEntry : public ProfilingBlobEntry
898{
899public:
900 ExternalSignatureBlobEntry(DWORD _cbSig, PCCOR_SIGNATURE _pSig);
901
902 virtual ~ExternalSignatureBlobEntry() { LIMITED_METHOD_CONTRACT; delete [] m_pSig; }
903 virtual BlobType kind() const { LIMITED_METHOD_CONTRACT; return ExternalSignatureDef; }
904 virtual size_t varSize() const { LIMITED_METHOD_CONTRACT; return sizeof(COR_SIGNATURE) * m_cbSig; }
905 virtual void newToken() { LIMITED_METHOD_CONTRACT; m_token = ++s_lastExternalSignatureToken; }
906 DWORD cbSig() const { LIMITED_METHOD_CONTRACT; return m_cbSig; }
907 PCCOR_SIGNATURE pSig() const { LIMITED_METHOD_CONTRACT; return m_pSig; }
908 static size_t HashInit() { LIMITED_METHOD_CONTRACT; return 324449; }
909
910 virtual bool IsEqual(const ProfilingBlobEntry * other) const;
911 virtual size_t Hash() const;
912
913 static const ExternalSignatureBlobEntry * FindOrAdd(PTR_Module pModule,
914 DWORD _cbSig,
915 PCCOR_SIGNATURE _pSig);
916
917private:
918 DWORD m_cbSig;
919 PCCOR_SIGNATURE m_pSig;
920
921 static idExternalSignature s_lastExternalSignatureToken;
922};
923
924class ExternalMethodBlobEntry : public ProfilingBlobEntry
925{
926public:
927 ExternalMethodBlobEntry(mdToken _nestedClass, mdToken _signature, LPCSTR _pName);
928
929 virtual ~ExternalMethodBlobEntry() { LIMITED_METHOD_CONTRACT; delete [] m_pName; }
930 virtual BlobType kind() const { LIMITED_METHOD_CONTRACT; return ExternalMethodDef; }
931 virtual size_t varSize() const { LIMITED_METHOD_CONTRACT; return sizeof(CHAR) * m_cbName; }
932 virtual void newToken() { LIMITED_METHOD_CONTRACT; m_token = ++s_lastExternalMethodToken; }
933 mdToken nestedClass() const { LIMITED_METHOD_CONTRACT; return m_nestedClass; }
934 mdToken signature() const { LIMITED_METHOD_CONTRACT; return m_signature; }
935 DWORD cbName() const { LIMITED_METHOD_CONTRACT; return m_cbName; }
936 LPCSTR pName() const { LIMITED_METHOD_CONTRACT; return m_pName; }
937 static size_t HashInit() { LIMITED_METHOD_CONTRACT; return 389357; }
938
939 virtual bool IsEqual(const ProfilingBlobEntry * other) const;
940 virtual size_t Hash() const;
941
942 static const ExternalMethodBlobEntry * FindOrAdd(PTR_Module pModule,
943 mdToken _nestedClass,
944 mdToken _signature,
945 LPCSTR _pName);
946
947private:
948 mdToken m_nestedClass;
949 mdToken m_signature;
950 DWORD m_cbName;
951 LPCSTR m_pName;
952
953 static idExternalMethod s_lastExternalMethodToken;
954};
955
956struct IbcNameHandle
957{
958 mdToken tkIbcNameSpace;
959 mdToken tkIbcNestedClass;
960
961 LPCSTR szName;
962 LPCSTR szNamespace;
963 mdToken tkEnclosingClass;
964};
965
966//
967// Hashtable of ProfilingBlobEntry *
968//
969class ProfilingBlobTraits : public NoRemoveSHashTraits<DefaultSHashTraits<ProfilingBlobEntry *> >
970{
971public:
972 typedef ProfilingBlobEntry * key_t;
973
974 static key_t GetKey(element_t e)
975 {
976 LIMITED_METHOD_CONTRACT;
977 return e;
978 }
979 static BOOL Equals(key_t k1, key_t k2)
980 {
981 LIMITED_METHOD_CONTRACT;
982 return k1->IsEqual(k2);
983 }
984 static count_t Hash(key_t k)
985 {
986 LIMITED_METHOD_CONTRACT;
987 return (count_t) k->Hash();
988 }
989 static element_t Null()
990 {
991 LIMITED_METHOD_CONTRACT;
992 return NULL;
993 }
994
995 static bool IsNull(const element_t &e)
996 {
997 LIMITED_METHOD_CONTRACT;
998 return (e == NULL);
999 }
1000};
1001
1002typedef SHash<ProfilingBlobTraits> ProfilingBlobTable;
1003typedef DPTR(ProfilingBlobTable) PTR_ProfilingBlobTable;
1004
1005
1006#define METHODTABLE_RESTORE_REASON() \
1007 RESTORE_REASON_FUNC(CanNotPreRestoreHardBindToParentMethodTable) \
1008 RESTORE_REASON_FUNC(CanNotPreRestoreHardBindToCanonicalMethodTable) \
1009 RESTORE_REASON_FUNC(CrossModuleNonCanonicalMethodTable) \
1010 RESTORE_REASON_FUNC(CanNotHardBindToInstanceMethodTableChain) \
1011 RESTORE_REASON_FUNC(GenericsDictionaryNeedsRestore) \
1012 RESTORE_REASON_FUNC(InterfaceIsGeneric) \
1013 RESTORE_REASON_FUNC(CrossModuleGenericsStatics) \
1014 RESTORE_REASON_FUNC(ComImportStructDependenciesNeedRestore) \
1015 RESTORE_REASON_FUNC(CrossAssembly) \
1016 RESTORE_REASON_FUNC(ArrayElement) \
1017 RESTORE_REASON_FUNC(ProfilingEnabled)
1018
1019#undef RESTORE_REASON_FUNC
1020#define RESTORE_REASON_FUNC(s) s ,
1021typedef enum
1022{
1023
1024 METHODTABLE_RESTORE_REASON()
1025
1026 TotalMethodTables
1027} MethodTableRestoreReason;
1028#undef RESTORE_REASON_FUNC
1029
1030class NgenStats
1031{
1032public:
1033 NgenStats()
1034 {
1035 LIMITED_METHOD_CONTRACT;
1036 memset (MethodTableRestoreNumReasons, 0, sizeof(DWORD)*(TotalMethodTables+1));
1037 }
1038
1039 DWORD MethodTableRestoreNumReasons[TotalMethodTables + 1];
1040};
1041#endif // FEATURE_PREJIT
1042
1043//
1044// A Module is the primary unit of code packaging in the runtime. It
1045// corresponds mostly to an OS executable image, although other kinds
1046// of modules exist.
1047//
1048class UMEntryThunk;
1049
1050// Hashtable of absolute addresses of IL blobs for dynamics, keyed by token
1051
1052 struct DynamicILBlobEntry
1053{
1054 mdToken m_methodToken;
1055 TADDR m_il;
1056};
1057
1058class DynamicILBlobTraits : public NoRemoveSHashTraits<DefaultSHashTraits<DynamicILBlobEntry> >
1059{
1060public:
1061 typedef mdToken key_t;
1062
1063 static key_t GetKey(element_t e)
1064 {
1065 LIMITED_METHOD_CONTRACT;
1066 SUPPORTS_DAC;
1067 return e.m_methodToken;
1068 }
1069 static BOOL Equals(key_t k1, key_t k2)
1070 {
1071 LIMITED_METHOD_CONTRACT;
1072 SUPPORTS_DAC;
1073 return k1 == k2;
1074 }
1075 static count_t Hash(key_t k)
1076 {
1077 LIMITED_METHOD_CONTRACT;
1078 SUPPORTS_DAC;
1079 return (count_t)(size_t)k;
1080 }
1081 static const element_t Null()
1082 {
1083 LIMITED_METHOD_CONTRACT;
1084 SUPPORTS_DAC;
1085 DynamicILBlobEntry e;
1086 e.m_il = TADDR(0);
1087 e.m_methodToken = 0;
1088 return e;
1089 }
1090 static bool IsNull(const element_t &e)
1091 {
1092 LIMITED_METHOD_CONTRACT;
1093 SUPPORTS_DAC;
1094 return e.m_methodToken == 0;
1095 }
1096};
1097
1098typedef SHash<DynamicILBlobTraits> DynamicILBlobTable;
1099typedef DPTR(DynamicILBlobTable) PTR_DynamicILBlobTable;
1100
1101
1102// ESymbolFormat specified the format used by a symbol stream
1103typedef enum
1104{
1105 eSymbolFormatNone, /* symbol format to use not yet determined */
1106 eSymbolFormatPDB, /* PDB format from diasymreader.dll - only safe for trusted scenarios */
1107 eSymbolFormatILDB /* ILDB format from ildbsymbols.dll */
1108}ESymbolFormat;
1109
1110
1111#ifdef FEATURE_COMINTEROP
1112
1113//---------------------------------------------------------------------------------------
1114//
1115// The type of each entry in the Guid to MT hash
1116//
1117typedef DPTR(GUID) PTR_GUID;
1118typedef DPTR(struct GuidToMethodTableEntry) PTR_GuidToMethodTableEntry;
1119struct GuidToMethodTableEntry
1120{
1121 PTR_GUID m_Guid;
1122 PTR_MethodTable m_pMT;
1123};
1124
1125//---------------------------------------------------------------------------------------
1126//
1127// The hash type itself
1128//
1129typedef DPTR(class GuidToMethodTableHashTable) PTR_GuidToMethodTableHashTable;
1130class GuidToMethodTableHashTable : public NgenHashTable<GuidToMethodTableHashTable, GuidToMethodTableEntry, 4>
1131{
1132public:
1133 typedef NgenHashTable<GuidToMethodTableHashTable, GuidToMethodTableEntry, 4> Base_t;
1134 friend class Base_t;
1135
1136#ifndef DACCESS_COMPILE
1137
1138private:
1139 GuidToMethodTableHashTable(Module *pModule, LoaderHeap *pHeap, DWORD cInitialBuckets)
1140 : Base_t(pModule, pHeap, cInitialBuckets)
1141 { LIMITED_METHOD_CONTRACT; }
1142
1143public:
1144 static GuidToMethodTableHashTable* Create(Module* pModule, DWORD cInitialBuckets, AllocMemTracker *pamTracker);
1145
1146 GuidToMethodTableEntry * InsertValue(PTR_GUID pGuid, PTR_MethodTable pMT, BOOL bReplaceIfFound, AllocMemTracker *pamTracker);
1147
1148#endif // !DACCESS_COMPILE
1149
1150public:
1151 typedef Base_t::LookupContext LookupContext;
1152
1153 PTR_MethodTable GetValue(const GUID * pGuid, LookupContext *pContext);
1154 GuidToMethodTableEntry * FindItem(const GUID * pGuid, LookupContext *pContext);
1155
1156private:
1157 BOOL CompareKeys(PTR_GuidToMethodTableEntry pEntry, const GUID * pGuid);
1158 static DWORD Hash(const GUID * pGuid);
1159
1160public:
1161 // An iterator for the table
1162 struct Iterator
1163 {
1164 public:
1165 Iterator() : m_pTable(NULL), m_fIterating(false)
1166 { LIMITED_METHOD_DAC_CONTRACT; }
1167 Iterator(GuidToMethodTableHashTable * pTable) : m_pTable(pTable), m_fIterating(false)
1168 { LIMITED_METHOD_DAC_CONTRACT; }
1169
1170 private:
1171 friend class GuidToMethodTableHashTable;
1172
1173 GuidToMethodTableHashTable * m_pTable;
1174 BaseIterator m_sIterator;
1175 bool m_fIterating;
1176 };
1177
1178 BOOL FindNext(Iterator *it, GuidToMethodTableEntry **ppEntry);
1179 DWORD GetCount();
1180
1181#ifdef DACCESS_COMPILE
1182 // do not save this in mini-/heap-dumps
1183 void EnumMemoryRegions(CLRDataEnumMemoryFlags flags)
1184 { SUPPORTS_DAC; }
1185 void EnumMemoryRegionsForEntry(GuidToMethodTableEntry *pEntry, CLRDataEnumMemoryFlags flags)
1186 { SUPPORTS_DAC; }
1187#endif // DACCESS_COMPILE
1188
1189#if defined(FEATURE_PREJIT) && !defined(DACCESS_COMPILE)
1190
1191public:
1192 void Save(DataImage *pImage, CorProfileData *pProfileData);
1193 void Fixup(DataImage *pImage);
1194
1195private:
1196 // We save all entries
1197 bool ShouldSave(DataImage *pImage, GuidToMethodTableEntry *pEntry)
1198 { LIMITED_METHOD_CONTRACT; return true; }
1199
1200 bool IsHotEntry(GuidToMethodTableEntry *pEntry, CorProfileData *pProfileData)
1201 { LIMITED_METHOD_CONTRACT; return false; }
1202
1203 bool SaveEntry(DataImage *pImage, CorProfileData *pProfileData,
1204 GuidToMethodTableEntry *pOldEntry, GuidToMethodTableEntry *pNewEntry,
1205 EntryMappingTable *pMap);
1206
1207 void FixupEntry(DataImage *pImage, GuidToMethodTableEntry *pEntry, void *pFixupBase, DWORD cbFixupOffset);
1208
1209#endif // FEATURE_PREJIT && !DACCESS_COMPILE
1210
1211};
1212
1213#endif // FEATURE_COMINTEROP
1214
1215
1216//Hash for MemberRef to Desc tables (fieldDesc or MethodDesc)
1217typedef DPTR(struct MemberRefToDescHashEntry) PTR_MemberRefToDescHashEntry;
1218
1219struct MemberRefToDescHashEntry
1220{
1221 TADDR m_value;
1222};
1223
1224typedef DPTR(class MemberRefToDescHashTable) PTR_MemberRefToDescHashTable;
1225
1226#define MEMBERREF_MAP_INITIAL_SIZE 10
1227
1228class MemberRefToDescHashTable: public NgenHashTable<MemberRefToDescHashTable, MemberRefToDescHashEntry, 2>
1229{
1230 friend class NgenHashTable<MemberRefToDescHashTable, MemberRefToDescHashEntry, 2>;
1231#ifndef DACCESS_COMPILE
1232
1233private:
1234 MemberRefToDescHashTable(Module *pModule, LoaderHeap *pHeap, DWORD cInitialBuckets):
1235 NgenHashTable<MemberRefToDescHashTable, MemberRefToDescHashEntry, 2>(pModule, pHeap, cInitialBuckets)
1236 { LIMITED_METHOD_CONTRACT; }
1237
1238public:
1239
1240 static MemberRefToDescHashTable* Create(Module *pModule, DWORD cInitialBuckets, AllocMemTracker *pamTracker);
1241
1242 MemberRefToDescHashEntry* Insert(mdMemberRef token, MethodDesc *value);
1243 MemberRefToDescHashEntry* Insert(mdMemberRef token , FieldDesc *value);
1244#endif //!DACCESS_COMPILE
1245
1246public:
1247 typedef NgenHashTable<MemberRefToDescHashTable, MemberRefToDescHashEntry, 2>::LookupContext LookupContext;
1248
1249 PTR_MemberRef GetValue(mdMemberRef token, BOOL *pfIsMethod);
1250
1251#ifdef DACCESS_COMPILE
1252
1253 void EnumMemoryRegions(CLRDataEnumMemoryFlags flags)
1254 {
1255 WRAPPER_NO_CONTRACT;
1256 BaseEnumMemoryRegions(flags);
1257 }
1258
1259 void EnumMemoryRegionsForEntry(MemberRefToDescHashEntry *pEntry, CLRDataEnumMemoryFlags flags)
1260 { SUPPORTS_DAC; }
1261
1262#endif
1263
1264#if defined(FEATURE_PREJIT) && !defined(DACCESS_COMPILE)
1265
1266 void Fixup(DataImage *pImage)
1267 {
1268 WRAPPER_NO_CONTRACT;
1269 BaseFixup(pImage);
1270 }
1271
1272 void Save(DataImage *pImage, CorProfileData *pProfileData);
1273
1274
1275private:
1276 bool ShouldSave(DataImage *pImage, MemberRefToDescHashEntry *pEntry)
1277 {
1278 return IsHotEntry(pEntry, NULL);
1279 }
1280
1281 bool IsHotEntry(MemberRefToDescHashEntry *pEntry, CorProfileData *pProfileData) // yes according to IBC data
1282 {
1283 LIMITED_METHOD_CONTRACT;
1284
1285 _ASSERTE(pEntry != NULL);
1286 // Low order bit of data field indicates a hot entry.
1287 return (pEntry->m_value & 0x1) != 0;
1288
1289 }
1290
1291
1292 bool SaveEntry(DataImage *pImage, CorProfileData *pProfileData,
1293 MemberRefToDescHashEntry *pOldEntry, MemberRefToDescHashEntry *pNewEntry,
1294 EntryMappingTable *pMap)
1295 {
1296 //The entries are mutable
1297 return FALSE;
1298 }
1299
1300 void FixupEntry(DataImage *pImage, MemberRefToDescHashEntry *pEntry, void *pFixupBase, DWORD cbFixupOffset);
1301
1302#endif
1303};
1304
1305#ifdef FEATURE_READYTORUN
1306typedef DPTR(class ReadyToRunInfo) PTR_ReadyToRunInfo;
1307#endif
1308
1309struct ThreadLocalModule;
1310
1311// A code:Module represents a DLL or EXE file loaded from the disk. It could either be a IL module or a
1312// Native code (NGEN module). A module live in a code:Assembly
1313//
1314// Some important fields are
1315// * code:Module.m_file - this points at a code:PEFile that understands the layout of a PE file. The most
1316// important part is getting at the code:Module (see file:..\inc\corhdr.h#ManagedHeader) from there
1317// you can get at the Meta-data and IL)
1318// * code:Module.m_pAvailableClasses - this is a table that lets you look up the types (the code:EEClass)
1319// for all the types in the module
1320//
1321// See file:..\inc\corhdr.h#ManagedHeader for more on the layout of managed exectuable files.
1322
1323class Module
1324{
1325#ifdef DACCESS_COMPILE
1326 friend class ClrDataAccess;
1327 friend class NativeImageDumper;
1328#endif
1329
1330 friend class DataImage;
1331
1332 VPTR_BASE_CONCRETE_VTABLE_CLASS(Module)
1333
1334private:
1335 PTR_CUTF8 m_pSimpleName; // Cached simple name for better performance and easier diagnostics
1336
1337 PTR_PEFile m_file;
1338
1339 MethodDesc *m_pDllMain;
1340
1341 enum {
1342 // These are the values set in m_dwTransientFlags.
1343 // Note that none of these flags survive a prejit save/restore.
1344
1345 MODULE_IS_TENURED = 0x00000001, // Set once we know for sure the Module will not be freed until the appdomain itself exits
1346 M_CER_ROOT_TABLE_ON_HEAP = 0x00000002, // Set when m_pCerNgenRootTable is allocated from heap (at ngen time)
1347 CLASSES_FREED = 0x00000004,
1348 IS_EDIT_AND_CONTINUE = 0x00000008, // is EnC Enabled for this module
1349
1350 IS_PROFILER_NOTIFIED = 0x00000010,
1351 IS_ETW_NOTIFIED = 0x00000020,
1352
1353 //
1354 // Note: the order of these must match the order defined in
1355 // cordbpriv.h for DebuggerAssemblyControlFlags. The three
1356 // values below should match the values defined in
1357 // DebuggerAssemblyControlFlags when shifted right
1358 // DEBUGGER_INFO_SHIFT bits.
1359 //
1360 DEBUGGER_USER_OVERRIDE_PRIV = 0x00000400,
1361 DEBUGGER_ALLOW_JIT_OPTS_PRIV= 0x00000800,
1362 DEBUGGER_TRACK_JIT_INFO_PRIV= 0x00001000,
1363 DEBUGGER_ENC_ENABLED_PRIV = 0x00002000, // this is what was attempted to be set. IS_EDIT_AND_CONTINUE is actual result.
1364 DEBUGGER_PDBS_COPIED = 0x00004000,
1365 DEBUGGER_IGNORE_PDBS = 0x00008000,
1366 DEBUGGER_INFO_MASK_PRIV = 0x0000Fc00,
1367 DEBUGGER_INFO_SHIFT_PRIV = 10,
1368
1369 // Used to indicate that this module has had it's IJW fixups properly installed.
1370 IS_IJW_FIXED_UP = 0x00080000,
1371 IS_BEING_UNLOADED = 0x00100000,
1372
1373 // Used to indicate that the module is loaded sufficiently for generic candidate instantiations to work
1374 MODULE_READY_FOR_TYPELOAD = 0x00200000,
1375
1376 // Used during NGen only
1377 TYPESPECS_TRIAGED = 0x40000000,
1378 MODULE_SAVED = 0x80000000,
1379 };
1380
1381 enum {
1382 // These are the values set in m_dwPersistedFlags. These will survive
1383 // a prejit save/restore
1384 // unused = 0x00000001,
1385 COMPUTED_GLOBAL_CLASS = 0x00000002,
1386
1387 // This flag applies to assembly, but it is stored so it can be cached in ngen image
1388 COMPUTED_STRING_INTERNING = 0x00000004,
1389 NO_STRING_INTERNING = 0x00000008,
1390
1391 // This flag applies to assembly, but it is stored so it can be cached in ngen image
1392 COMPUTED_WRAP_EXCEPTIONS = 0x00000010,
1393 WRAP_EXCEPTIONS = 0x00000020,
1394
1395 // This flag applies to assembly, but it is stored so it can be cached in ngen image
1396 COMPUTED_RELIABILITY_CONTRACT=0x00000040,
1397
1398 // This flag applies to assembly, but is also stored here so that it can be cached in ngen image
1399 COLLECTIBLE_MODULE = 0x00000080,
1400
1401 // Caches metadata version
1402 COMPUTED_IS_PRE_V4_ASSEMBLY = 0x00000100,
1403 IS_PRE_V4_ASSEMBLY = 0x00000200,
1404
1405 //If attribute value has been cached before
1406 DEFAULT_DLL_IMPORT_SEARCH_PATHS_IS_CACHED = 0x00000400,
1407
1408 //If module has default dll import search paths attribute
1409 DEFAULT_DLL_IMPORT_SEARCH_PATHS_STATUS = 0x00000800,
1410
1411 //If attribute value has been cached before
1412 NEUTRAL_RESOURCES_LANGUAGE_IS_CACHED = 0x00001000,
1413
1414 //If m_MethodDefToPropertyInfoMap has been generated
1415 COMPUTED_METHODDEF_TO_PROPERTYINFO_MAP = 0x00002000,
1416
1417 // Low level system assembly. Used by preferred zap module computation.
1418 LOW_LEVEL_SYSTEM_ASSEMBLY_BY_NAME = 0x00004000,
1419 };
1420
1421 Volatile<DWORD> m_dwTransientFlags;
1422 Volatile<DWORD> m_dwPersistedFlags;
1423
1424 // Linked list of VASig cookie blocks: protected by m_pStubListCrst
1425 VASigCookieBlock *m_pVASigCookieBlock;
1426
1427 PTR_Assembly m_pAssembly;
1428 mdFile m_moduleRef;
1429
1430 CrstExplicitInit m_Crst;
1431 CrstExplicitInit m_FixupCrst;
1432
1433 // Debugging symbols reader interface. This will only be
1434 // initialized if needed, either by the debugging subsystem or for
1435 // an exception.
1436 ISymUnmanagedReader * m_pISymUnmanagedReader;
1437
1438 // The reader lock is used to serialize all creation of symbol readers.
1439 // It does NOT seralize all access to the readers since we freely give
1440 // out references to the reader outside this class. Instead, once a
1441 // reader object is created, it is entirely read-only and so thread-safe.
1442 CrstExplicitInit m_ISymUnmanagedReaderCrst;
1443
1444 // Storage for the in-memory symbol stream if any
1445 // Debugger may retrieve this from out-of-process.
1446 PTR_CGrowableStream m_pIStreamSym;
1447
1448 // Format the above stream is in (if any)
1449 ESymbolFormat m_symbolFormat;
1450
1451 // For protecting additions to the heap
1452 CrstExplicitInit m_LookupTableCrst;
1453
1454 #define TYPE_DEF_MAP_ALL_FLAGS ((TADDR)0x00000001)
1455 #define ZAPPED_TYPE_NEEDS_NO_RESTORE ((TADDR)0x00000001)
1456
1457 #define TYPE_REF_MAP_ALL_FLAGS NO_MAP_FLAGS
1458 // For type ref map, 0x1 cannot be used as a flag: reserved for FIXUP_POINTER_INDIRECTION bit
1459 // For type ref map, 0x2 cannot be used as a flag: reserved for TypeHandle to signify TypeDesc
1460
1461 #define METHOD_DEF_MAP_ALL_FLAGS NO_MAP_FLAGS
1462
1463 #define FIELD_DEF_MAP_ALL_FLAGS NO_MAP_FLAGS
1464
1465 #define MEMBER_REF_MAP_ALL_FLAGS ((TADDR)0x00000003)
1466 // For member ref hash table, 0x1 is reserved for IsHot bit
1467 #define IS_FIELD_MEMBER_REF ((TADDR)0x00000002) // denotes that target is a FieldDesc
1468
1469 #define GENERIC_PARAM_MAP_ALL_FLAGS NO_MAP_FLAGS
1470
1471 #define GENERIC_TYPE_DEF_MAP_ALL_FLAGS ((TADDR)0x00000001)
1472 #define ZAPPED_GENERIC_TYPE_NEEDS_NO_RESTORE ((TADDR)0x00000001)
1473
1474 #define FILE_REF_MAP_ALL_FLAGS NO_MAP_FLAGS
1475 // For file ref map, 0x1 cannot be used as a flag: reserved for FIXUP_POINTER_INDIRECTION bit
1476
1477 #define MANIFEST_MODULE_MAP_ALL_FLAGS NO_MAP_FLAGS
1478 // For manifest module map, 0x1 cannot be used as a flag: reserved for FIXUP_POINTER_INDIRECTION bit
1479
1480 #define PROPERTY_INFO_MAP_ALL_FLAGS NO_MAP_FLAGS
1481
1482 // Linear mapping from TypeDef token to MethodTable *
1483 // For generic types, IsGenericTypeDefinition() is true i.e. instantiation at formals
1484 LookupMap<PTR_MethodTable> m_TypeDefToMethodTableMap;
1485
1486 // Linear mapping from TypeRef token to TypeHandle *
1487 LookupMap<PTR_TypeRef> m_TypeRefToMethodTableMap;
1488
1489 // Linear mapping from MethodDef token to MethodDesc *
1490 // For generic methods, IsGenericTypeDefinition() is true i.e. instantiation at formals
1491 LookupMap<PTR_MethodDesc> m_MethodDefToDescMap;
1492
1493 // Linear mapping from FieldDef token to FieldDesc*
1494 LookupMap<PTR_FieldDesc> m_FieldDefToDescMap;
1495
1496 // mapping from MemberRef token to MethodDesc*, FieldDesc*
1497 PTR_MemberRefToDescHashTable m_pMemberRefToDescHashTable;
1498
1499 // Linear mapping from GenericParam token to TypeVarTypeDesc*
1500 LookupMap<PTR_TypeVarTypeDesc> m_GenericParamToDescMap;
1501
1502 // Linear mapping from TypeDef token to the MethodTable * for its canonical generic instantiation
1503 // If the type is not generic, the entry is guaranteed to be NULL. This means we are paying extra
1504 // space in order to use the LookupMap infrastructure, but what it buys us is IBC support and
1505 // a compressed format for NGen that makes up for it.
1506 LookupMap<PTR_MethodTable> m_GenericTypeDefToCanonMethodTableMap;
1507
1508 // Mapping from File token to Module *
1509 LookupMap<PTR_Module> m_FileReferencesMap;
1510
1511 // Mapping of AssemblyRef token to Module *
1512 LookupMap<PTR_Module> m_ManifestModuleReferencesMap;
1513
1514 // Mapping from MethodDef token to pointer-sized value encoding property information
1515 LookupMap<SIZE_T> m_MethodDefToPropertyInfoMap;
1516
1517 // IL stub cache with fabricated MethodTable parented by this module.
1518 ILStubCache *m_pILStubCache;
1519
1520 ULONG m_DefaultDllImportSearchPathsAttributeValue;
1521
1522 LPCUTF8 m_pszCultureName;
1523 ULONG m_CultureNameLength;
1524 INT16 m_FallbackLocation;
1525
1526#ifdef PROFILING_SUPPORTED_DATA
1527 // a wrapper for the underlying PEFile metadata emitter which validates that the metadata edits being
1528 // made are supported modifications to the type system
1529 VolatilePtr<IMetaDataEmit> m_pValidatedEmitter;
1530#endif
1531
1532public:
1533 LookupMap<PTR_MethodTable>::Iterator EnumerateTypeDefs()
1534 {
1535 LIMITED_METHOD_CONTRACT;
1536 SUPPORTS_DAC;
1537
1538 return LookupMap<PTR_MethodTable>::Iterator(&m_TypeDefToMethodTableMap);
1539 }
1540
1541 // Hash of available types by name
1542 PTR_EEClassHashTable m_pAvailableClasses;
1543
1544 // Hashtable of generic type instances
1545 PTR_EETypeHashTable m_pAvailableParamTypes;
1546
1547 // For protecting additions to m_pInstMethodHashTable
1548 CrstExplicitInit m_InstMethodHashTableCrst;
1549
1550 // Hashtable of instantiated methods and per-instantiation static methods
1551 PTR_InstMethodHashTable m_pInstMethodHashTable;
1552
1553#ifdef FEATURE_PREJIT
1554 // Mapping from tokens to IL marshaling stubs (NGEN only).
1555 PTR_StubMethodHashTable m_pStubMethodHashTable;
1556#endif // FEATURE_PREJIT
1557
1558 // This is used by the Debugger. We need to store a dword
1559 // for a count of JMC functions. This is a count, not a pointer.
1560 // We'll pass the address of this field
1561 // off to the jit, which will include it in probes injected for
1562 // debuggable code.
1563 // This means we need the dword at the time a function is jitted.
1564 // The Debugger has its own module structure, but those aren't created
1565 // if a debugger isn't attached.
1566 // We put it here instead of in the debugger's module because:
1567 // 1) we need a module structure that's around even when the debugger
1568 // isn't attached... so we use the EE's module.
1569 // 2) Needs to be here for ngen
1570 DWORD m_dwDebuggerJMCProbeCount;
1571
1572 // We can skip the JMC probes if we know that a module has no JMC stuff
1573 // inside. So keep a strict count of all functions inside us.
1574 bool HasAnyJMCFunctions();
1575 void IncJMCFuncCount();
1576 void DecJMCFuncCount();
1577
1578 // Get and set the default JMC status of this module.
1579 bool GetJMCStatus();
1580 void SetJMCStatus(bool fStatus);
1581
1582 // If this is a dynamic module, eagerly serialize the metadata so that it is available for DAC.
1583 // This is a nop for non-dynamic modules.
1584 void UpdateDynamicMetadataIfNeeded();
1585
1586#ifdef _DEBUG
1587 //
1588 // We call these methods to seal/unseal the
1589 // lists: m_pAvailableClasses and m_pAvailableParamTypes
1590 //
1591 // When they are sealed ClassLoader::PublishType cannot
1592 // add new generic types or methods
1593 //
1594 void SealGenericTypesAndMethods();
1595 void UnsealGenericTypesAndMethods();
1596#endif
1597
1598private:
1599 // Set the given bit on m_dwTransientFlags. Return true if we won the race to set the bit.
1600 BOOL SetTransientFlagInterlocked(DWORD dwFlag);
1601
1602 // Invoke fusion hooks into host to fetch PDBs
1603 void FetchPdbsFromHost();
1604
1605 // Cannoically-cased hashtable of the available class names for
1606 // case insensitive lookup. Contains pointers into
1607 // m_pAvailableClasses.
1608 PTR_EEClassHashTable m_pAvailableClassesCaseIns;
1609
1610 // Pointer to binder, if we have one
1611 friend class MscorlibBinder;
1612 PTR_MscorlibBinder m_pBinder;
1613
1614public:
1615 BOOL IsCollectible()
1616 {
1617 LIMITED_METHOD_DAC_CONTRACT;
1618 return (m_dwPersistedFlags & COLLECTIBLE_MODULE) != 0;
1619 }
1620
1621#ifdef FEATURE_READYTORUN
1622private:
1623 PTR_ReadyToRunInfo m_pReadyToRunInfo;
1624#endif
1625
1626#ifdef FEATURE_PREJIT
1627
1628private:
1629 PTR_NGenLayoutInfo m_pNGenLayoutInfo;
1630
1631 PTR_ProfilingBlobTable m_pProfilingBlobTable; // While performing IBC instrumenting this hashtable is populated with the External defs
1632 CorProfileData * m_pProfileData; // While ngen-ing with IBC optimizations this contains a link to the IBC data for the assembly
1633
1634 // Profile information
1635 BOOL m_nativeImageProfiling;
1636 CORCOMPILE_METHOD_PROFILE_LIST *m_methodProfileList;
1637
1638#if defined(FEATURE_COMINTEROP)
1639 public:
1640
1641 #ifndef DACCESS_COMPILE
1642 BOOL CanCacheWinRTTypeByGuid(MethodTable *pMT);
1643 void CacheWinRTTypeByGuid(PTR_MethodTable pMT, PTR_GuidInfo pgi = NULL);
1644 #endif // !DACCESS_COMPILE
1645
1646 PTR_MethodTable LookupTypeByGuid(const GUID & guid);
1647 void GetCachedWinRTTypes(SArray<PTR_MethodTable> * pTypes, SArray<GUID> * pGuids);
1648
1649 private:
1650 PTR_GuidToMethodTableHashTable m_pGuidToTypeHash; // A map from GUID to Type, for the "WinRT-interesting" types
1651
1652#endif // defined(FEATURE_COMINTEROP)
1653
1654#endif // FEATURE_PREJIT
1655
1656 // Module wide static fields information
1657 ModuleCtorInfo m_ModuleCtorInfo;
1658
1659#ifdef FEATURE_PREJIT
1660 struct TokenProfileData
1661 {
1662 static TokenProfileData *CreateNoThrow(void);
1663
1664 TokenProfileData()
1665 // We need a critical section that can be entered in both preemptive and cooperative modes.
1666 // Hopefully this restriction can be removed in the future.
1667 : crst(CrstSaveModuleProfileData, CRST_UNSAFE_ANYMODE)
1668 {
1669 WRAPPER_NO_CONTRACT;
1670 }
1671
1672 ~TokenProfileData()
1673 {
1674 WRAPPER_NO_CONTRACT;
1675 }
1676
1677 Crst crst;
1678
1679 struct Formats
1680 {
1681 CQuickArray<CORBBTPROF_TOKEN_INFO> tokenArray;
1682 RidBitmap tokenBitmaps[CORBBTPROF_TOKEN_MAX_NUM_FLAGS];
1683 } m_formats[SectionFormatCount];
1684
1685 } *m_tokenProfileData;
1686
1687 // Stats for prejit log
1688 NgenStats *m_pNgenStats;
1689#endif // FEATURE_PREJIT
1690
1691
1692protected:
1693
1694 void CreateDomainThunks();
1695
1696protected:
1697 void DoInit(AllocMemTracker *pamTracker, LPCWSTR szName);
1698
1699protected:
1700#ifndef DACCESS_COMPILE
1701 virtual void Initialize(AllocMemTracker *pamTracker, LPCWSTR szName = NULL);
1702 void InitializeForProfiling();
1703#ifdef FEATURE_PREJIT
1704 void InitializeNativeImage(AllocMemTracker* pamTracker);
1705#endif
1706#endif
1707
1708 void AllocateMaps();
1709
1710#ifdef _DEBUG
1711 void DebugLogRidMapOccupancy();
1712#endif // _DEBUG
1713
1714 static HRESULT VerifyFile(PEFile *file, BOOL fZap);
1715
1716 public:
1717 static Module *Create(Assembly *pAssembly, mdFile kFile, PEFile *pFile, AllocMemTracker *pamTracker);
1718
1719 protected:
1720 Module(Assembly *pAssembly, mdFile moduleRef, PEFile *file);
1721
1722
1723 public:
1724#ifndef DACCESS_COMPILE
1725 virtual void Destruct();
1726#ifdef FEATURE_PREJIT
1727 void DeleteNativeCodeRanges();
1728#endif
1729#endif
1730
1731 PTR_LoaderAllocator GetLoaderAllocator();
1732
1733 PTR_PEFile GetFile() const { LIMITED_METHOD_DAC_CONTRACT; return m_file; }
1734
1735 static size_t GetFileOffset() { LIMITED_METHOD_CONTRACT; return offsetof(Module, m_file); }
1736
1737 BOOL IsManifest();
1738
1739 void ApplyMetaData();
1740
1741 void FixupVTables();
1742
1743 void FreeClassTables();
1744
1745#ifdef DACCESS_COMPILE
1746 virtual void EnumMemoryRegions(CLRDataEnumMemoryFlags flags,
1747 bool enumThis);
1748#endif // DACCESS_COMPILE
1749
1750 ReflectionModule *GetReflectionModule() const
1751 {
1752 LIMITED_METHOD_CONTRACT;
1753 SUPPORTS_DAC;
1754
1755 _ASSERTE(IsReflection());
1756 return dac_cast<PTR_ReflectionModule>(this);
1757 }
1758
1759 PTR_Assembly GetAssembly() const;
1760
1761 int GetClassLoaderIndex()
1762 {
1763 LIMITED_METHOD_CONTRACT;
1764
1765 return RidFromToken(m_moduleRef);
1766 }
1767
1768 MethodTable *GetGlobalMethodTable();
1769 bool NeedsGlobalMethodTable();
1770
1771 // Only for non-manifest modules
1772 DomainModule *GetDomainModule(AppDomain *pDomain);
1773 DomainModule *FindDomainModule(AppDomain *pDomain);
1774
1775 // This works for manifest modules too
1776 DomainFile *GetDomainFile(AppDomain *pDomain);
1777 DomainFile *FindDomainFile(AppDomain *pDomain);
1778
1779 // Operates on assembly of module
1780 DomainAssembly *GetDomainAssembly(AppDomain *pDomain);
1781 DomainAssembly *FindDomainAssembly(AppDomain *pDomain);
1782
1783 // Versions which rely on the current AppDomain (N/A for DAC builds)
1784#ifndef DACCESS_COMPILE
1785 DomainModule * GetDomainModule() { WRAPPER_NO_CONTRACT; return GetDomainModule(GetAppDomain()); }
1786 DomainFile * GetDomainFile() { WRAPPER_NO_CONTRACT; return GetDomainFile(GetAppDomain()); }
1787 DomainAssembly * GetDomainAssembly() { WRAPPER_NO_CONTRACT; return GetDomainAssembly(GetAppDomain()); }
1788#endif
1789
1790 void SetDomainFile(DomainFile *pDomainFile);
1791
1792 OBJECTREF GetExposedObject();
1793
1794 ClassLoader *GetClassLoader();
1795 PTR_BaseDomain GetDomain();
1796#ifdef FEATURE_CODE_VERSIONING
1797 CodeVersionManager * GetCodeVersionManager();
1798#endif
1799#ifdef FEATURE_TIERED_COMPILATION
1800 CallCounter * GetCallCounter();
1801#endif
1802
1803 mdFile GetModuleRef()
1804 {
1805 LIMITED_METHOD_CONTRACT;
1806
1807 return m_moduleRef;
1808 }
1809
1810
1811 BOOL IsResource() const { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; return GetFile()->IsResource(); }
1812 BOOL IsPEFile() const { WRAPPER_NO_CONTRACT; return !GetFile()->IsDynamic(); }
1813 BOOL IsReflection() const { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; return GetFile()->IsDynamic(); }
1814 BOOL IsIbcOptimized() const { WRAPPER_NO_CONTRACT; return GetFile()->IsIbcOptimized(); }
1815 // Returns true iff the debugger can see this module.
1816 BOOL IsVisibleToDebugger();
1817
1818
1819 BOOL IsEditAndContinueEnabled()
1820 {
1821 LIMITED_METHOD_CONTRACT;
1822 SUPPORTS_DAC;
1823 // We are seeing cases where this flag is set for a module that is not an EditAndContinueModule. This should
1824 // never happen unless the module is EditAndContinueCapable, in which case we would have created an EditAndContinueModule
1825 // not a Module.
1826 //_ASSERTE((m_dwTransientFlags & IS_EDIT_AND_CONTINUE) == 0 || IsEditAndContinueCapable());
1827 return (IsEditAndContinueCapable()) && ((m_dwTransientFlags & IS_EDIT_AND_CONTINUE) != 0);
1828 }
1829
1830 BOOL IsEditAndContinueCapable();
1831
1832 BOOL IsIStream() { LIMITED_METHOD_CONTRACT; return GetFile()->IsIStream(); }
1833
1834 BOOL IsSystem() { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; return m_file->IsSystem(); }
1835
1836 static BOOL IsEditAndContinueCapable(Assembly *pAssembly, PEFile *file);
1837
1838 void EnableEditAndContinue()
1839 {
1840 LIMITED_METHOD_CONTRACT;
1841 SUPPORTS_DAC;
1842 // _ASSERTE(IsEditAndContinueCapable());
1843 LOG((LF_ENC, LL_INFO100, "EnableEditAndContinue: this:0x%x, %s\n", this, GetDebugName()));
1844 m_dwTransientFlags |= IS_EDIT_AND_CONTINUE;
1845 }
1846
1847 void DisableEditAndContinue()
1848 {
1849 LIMITED_METHOD_CONTRACT;
1850 SUPPORTS_DAC;
1851 // don't _ASSERTE(IsEditAndContinueCapable());
1852 LOG((LF_ENC, LL_INFO100, "DisableEditAndContinue: this:0x%x, %s\n", this, GetDebugName()));
1853 m_dwTransientFlags = m_dwTransientFlags.Load() & (~IS_EDIT_AND_CONTINUE);
1854 }
1855
1856 BOOL IsTenured()
1857 {
1858 LIMITED_METHOD_CONTRACT;
1859 return m_dwTransientFlags & MODULE_IS_TENURED;
1860 }
1861
1862#ifndef DACCESS_COMPILE
1863 VOID SetIsTenured()
1864 {
1865 LIMITED_METHOD_CONTRACT;
1866 FastInterlockOr(&m_dwTransientFlags, MODULE_IS_TENURED);
1867 }
1868
1869 // CAUTION: This should only be used as backout code if an assembly is unsuccessfully
1870 // added to the shared domain assembly map.
1871 VOID UnsetIsTenured()
1872 {
1873 LIMITED_METHOD_CONTRACT;
1874 FastInterlockAnd(&m_dwTransientFlags, ~MODULE_IS_TENURED);
1875 }
1876#endif // !DACCESS_COMPILE
1877
1878
1879 // This means the module has been sufficiently fixed up/security checked
1880 // that type loads can occur in domains. This is not sufficient to indicate
1881 // that domain-specific types can be loaded when applied to domain-neutral modules
1882 BOOL IsReadyForTypeLoad()
1883 {
1884 LIMITED_METHOD_CONTRACT;
1885 return m_dwTransientFlags & MODULE_READY_FOR_TYPELOAD;
1886 }
1887
1888#ifndef DACCESS_COMPILE
1889 VOID SetIsReadyForTypeLoad()
1890 {
1891 LIMITED_METHOD_CONTRACT;
1892 FastInterlockOr(&m_dwTransientFlags, MODULE_READY_FOR_TYPELOAD);
1893 }
1894#endif
1895
1896 BOOL IsLowLevelSystemAssemblyByName()
1897 {
1898 LIMITED_METHOD_CONTRACT;
1899 // The flag is set during initialization, so we can skip the memory barrier
1900 return m_dwPersistedFlags.LoadWithoutBarrier() & LOW_LEVEL_SYSTEM_ASSEMBLY_BY_NAME;
1901 }
1902
1903#ifndef DACCESS_COMPILE
1904 VOID EnsureActive();
1905 VOID EnsureAllocated();
1906 VOID EnsureLibraryLoaded();
1907#endif
1908
1909 CHECK CheckActivated();
1910
1911 IMDInternalImport *GetMDImport() const
1912 {
1913 WRAPPER_NO_CONTRACT;
1914 SUPPORTS_DAC;
1915
1916#ifdef DACCESS_COMPILE
1917 if (IsReflection())
1918 {
1919 return DacGetMDImport(GetReflectionModule(), true);
1920 }
1921#endif // DACCESS_COMPILE
1922 return m_file->GetPersistentMDImport();
1923 }
1924
1925#ifndef DACCESS_COMPILE
1926 IMetaDataEmit *GetEmitter()
1927 {
1928 WRAPPER_NO_CONTRACT;
1929
1930 return m_file->GetEmitter();
1931 }
1932
1933#if defined(PROFILING_SUPPORTED) && !defined(CROSSGEN_COMPILE)
1934 IMetaDataEmit *GetValidatedEmitter();
1935#endif
1936
1937 IMetaDataImport2 *GetRWImporter()
1938 {
1939 WRAPPER_NO_CONTRACT;
1940
1941 return m_file->GetRWImporter();
1942 }
1943
1944 IMetaDataAssemblyImport *GetAssemblyImporter()
1945 {
1946 WRAPPER_NO_CONTRACT;
1947
1948 return m_file->GetAssemblyImporter();
1949 }
1950
1951 HRESULT GetReadablePublicMetaDataInterface(DWORD dwOpenFlags, REFIID riid, LPVOID * ppvInterface);
1952#endif // !DACCESS_COMPILE
1953
1954 BOOL IsWindowsRuntimeModule();
1955
1956 BOOL IsInCurrentVersionBubble();
1957
1958 LPCWSTR GetPathForErrorMessages();
1959
1960
1961#ifdef FEATURE_ISYM_READER
1962 // Gets an up-to-date symbol reader for this module, lazily creating it if necessary
1963 // The caller must call Release
1964 ISymUnmanagedReader *GetISymUnmanagedReader(void);
1965 ISymUnmanagedReader *GetISymUnmanagedReaderNoThrow(void);
1966#endif // FEATURE_ISYM_READER
1967
1968 // Save a copy of the provided debugging symbols in the InMemorySymbolStream.
1969 // These are used by code:Module::GetInMemorySymbolStream and code:Module.GetISymUnmanagedReader
1970 // This can only be called during module creation, before anyone may have tried to create a reader.
1971 void SetSymbolBytes(LPCBYTE pSyms, DWORD cbSyms);
1972
1973 // Does the current configuration permit reading of symbols for this module?
1974 // Note that this may require calling into managed code (to resolve security policy).
1975 BOOL IsSymbolReadingEnabled(void);
1976
1977 BOOL IsPersistedObject(void *address);
1978
1979
1980 // Get the in-memory symbol stream for this module, if any.
1981 // If none, this will return null. This is used by modules loaded in-memory (eg. from a byte-array)
1982 // and by dynamic modules. Callers that actually do anything with the return value will almost
1983 // certainly want to check GetInMemorySymbolStreamFormat to know how to interpret the bytes
1984 // in the stream.
1985 PTR_CGrowableStream GetInMemorySymbolStream()
1986 {
1987 LIMITED_METHOD_CONTRACT;
1988 SUPPORTS_DAC;
1989
1990 // Symbol format should be "none" if-and-only-if our stream is null
1991 // If this fails, it may mean somebody is trying to examine this module after
1992 // code:Module::Destruct has been called.
1993 _ASSERTE( (m_symbolFormat == eSymbolFormatNone) == (m_pIStreamSym == NULL) );
1994
1995 return m_pIStreamSym;
1996 }
1997
1998 // Get the format of the in-memory symbol stream for this module, or
1999 // eSymbolFormatNone if no in-memory symbols.
2000 ESymbolFormat GetInMemorySymbolStreamFormat()
2001 {
2002 LIMITED_METHOD_CONTRACT;
2003 SUPPORTS_DAC;
2004
2005 // Symbol format should be "none" if-and-only-if our stream is null
2006 // If this fails, it may mean somebody is trying to examine this module after
2007 // code:Module::Destruct has been called.
2008 _ASSERTE( (m_symbolFormat == eSymbolFormatNone) == (m_pIStreamSym == NULL) );
2009
2010 return m_symbolFormat;
2011 }
2012
2013#ifndef DACCESS_COMPILE
2014 // Set the in-memory stream for debug symbols
2015 // This must only be called when there is no existing stream.
2016 // This takes an AddRef on the supplied stream.
2017 void SetInMemorySymbolStream(CGrowableStream *pStream, ESymbolFormat symbolFormat)
2018 {
2019 LIMITED_METHOD_CONTRACT;
2020
2021 // Must have provided valid stream data
2022 CONSISTENCY_CHECK(pStream != NULL);
2023 CONSISTENCY_CHECK(symbolFormat != eSymbolFormatNone);
2024
2025 // we expect set to only be called once
2026 CONSISTENCY_CHECK(m_pIStreamSym == NULL);
2027 CONSISTENCY_CHECK(m_symbolFormat == eSymbolFormatNone);
2028
2029 m_symbolFormat = symbolFormat;
2030 m_pIStreamSym = pStream;
2031 m_pIStreamSym->AddRef();
2032 }
2033
2034 // Release and clear the in-memory symbol stream if any
2035 void ClearInMemorySymbolStream()
2036 {
2037 LIMITED_METHOD_CONTRACT;
2038 if( m_pIStreamSym != NULL )
2039 {
2040 m_pIStreamSym->Release();
2041 m_pIStreamSym = NULL;
2042 // We could set m_symbolFormat to eSymbolFormatNone to be consistent with not having
2043 // a stream, but no-one should be trying to look at it after destruct time, so it's
2044 // better to leave it inconsistent and get an ASSERT if someone tries to examine the
2045 // module's sybmol stream after the module was destructed.
2046 }
2047 }
2048
2049 // Release the symbol reader if any
2050 // Caller is responsible for aquiring the reader lock if this could occur
2051 // concurrently with other uses of the reader (i.e. not shutdown/unload time)
2052 void ReleaseISymUnmanagedReader(void);
2053
2054 virtual void ReleaseILData();
2055
2056
2057#endif // DACCESS_COMPILE
2058
2059 // IL stub cache
2060 ILStubCache* GetILStubCache();
2061
2062 // Classes
2063 void AddClass(mdTypeDef classdef);
2064 void BuildClassForModule();
2065 PTR_EEClassHashTable GetAvailableClassHash()
2066 {
2067 LIMITED_METHOD_CONTRACT;
2068 SUPPORTS_DAC;
2069 {
2070 // IsResource() may lock when accessing metadata, but this is only in debug,
2071 // for the assert below
2072 CONTRACT_VIOLATION(TakesLockViolation);
2073
2074 _ASSERTE(!IsResource());
2075 }
2076
2077 return m_pAvailableClasses;
2078 }
2079#ifndef DACCESS_COMPILE
2080 void SetAvailableClassHash(EEClassHashTable *pAvailableClasses)
2081 {
2082 LIMITED_METHOD_CONTRACT;
2083 {
2084 // IsResource() may lock when accessing metadata, but this is only in debug,
2085 // for the assert below
2086 CONTRACT_VIOLATION(TakesLockViolation);
2087
2088 _ASSERTE(!IsResource());
2089 }
2090 m_pAvailableClasses = pAvailableClasses;
2091 }
2092#endif // !DACCESS_COMPILE
2093 PTR_EEClassHashTable GetAvailableClassCaseInsHash()
2094 {
2095 LIMITED_METHOD_CONTRACT;
2096 SUPPORTS_DAC;
2097 {
2098 // IsResource() may lock when accessing metadata, but this is only in debug,
2099 // for the assert below
2100 CONTRACT_VIOLATION(TakesLockViolation);
2101
2102 _ASSERTE(!IsResource());
2103 }
2104 return m_pAvailableClassesCaseIns;
2105 }
2106#ifndef DACCESS_COMPILE
2107 void SetAvailableClassCaseInsHash(EEClassHashTable *pAvailableClassesCaseIns)
2108 {
2109 LIMITED_METHOD_CONTRACT;
2110 {
2111 // IsResource() may lock when accessing metadata, but this is only in debug,
2112 // for the assert below
2113 CONTRACT_VIOLATION(TakesLockViolation);
2114
2115 _ASSERTE(!IsResource());
2116 }
2117 m_pAvailableClassesCaseIns = pAvailableClassesCaseIns;
2118 }
2119#endif // !DACCESS_COMPILE
2120
2121 // Constructed types tables
2122 EETypeHashTable *GetAvailableParamTypes()
2123 {
2124 LIMITED_METHOD_CONTRACT;
2125 SUPPORTS_DAC;
2126 {
2127 // IsResource() may lock when accessing metadata, but this is only in debug,
2128 // for the assert below
2129 CONTRACT_VIOLATION(TakesLockViolation);
2130
2131 _ASSERTE(!IsResource());
2132 }
2133 return m_pAvailableParamTypes;
2134 }
2135
2136 InstMethodHashTable *GetInstMethodHashTable()
2137 {
2138 LIMITED_METHOD_CONTRACT;
2139 {
2140 // IsResource() may lock when accessing metadata, but this is only in debug,
2141 // for the assert below
2142 CONTRACT_VIOLATION(TakesLockViolation);
2143
2144 _ASSERTE(!IsResource());
2145 }
2146 return m_pInstMethodHashTable;
2147 }
2148
2149#ifdef FEATURE_PREJIT
2150 // Gets or creates the token -> IL stub MethodDesc hash.
2151 StubMethodHashTable *GetStubMethodHashTable();
2152#endif // FEATURE_PREJIT
2153
2154 // Creates a new Method table for an array. Used to make type handles
2155 // Note that if kind == SZARRAY or ARRAY, we get passed the GENERIC_ARRAY
2156 // needed to create the array. That way we dont need to load classes during
2157 // the class load, which avoids the need for a 'being loaded' list
2158 MethodTable* CreateArrayMethodTable(TypeHandle elemType, CorElementType kind, unsigned rank, class AllocMemTracker *pamTracker);
2159
2160 // This is called from CreateArrayMethodTable
2161 MethodTable* CreateGenericArrayMethodTable(TypeHandle elemType);
2162
2163 // string helper
2164 void InitializeStringData(DWORD token, EEStringData *pstrData, CQuickBytes *pqb);
2165
2166 // Resolving
2167 OBJECTHANDLE ResolveStringRef(DWORD Token, BaseDomain *pDomain, bool bNeedToSyncWithFixups);
2168#ifdef FEATURE_PREJIT
2169 OBJECTHANDLE ResolveStringRefHelper(DWORD token, BaseDomain *pDomain, PTR_CORCOMPILE_IMPORT_SECTION pSection, EEStringData *strData);
2170#endif
2171
2172 CHECK CheckStringRef(RVA rva);
2173
2174 // Module/Assembly traversal
2175 Assembly * GetAssemblyIfLoaded(
2176 mdAssemblyRef kAssemblyRef,
2177 LPCSTR szWinRtNamespace = NULL,
2178 LPCSTR szWinRtClassName = NULL,
2179 IMDInternalImport * pMDImportOverride = NULL,
2180 BOOL fDoNotUtilizeExtraChecks = FALSE,
2181 ICLRPrivBinder *pBindingContextForLoadedAssembly = NULL
2182 );
2183
2184private:
2185 // Helper function used by GetAssemblyIfLoaded. Do not call directly.
2186 Assembly *GetAssemblyIfLoadedFromNativeAssemblyRefWithRefDefMismatch(mdAssemblyRef kAssemblyRef, BOOL *pfDiscoveredAssemblyRefMatchesTargetDefExactly);
2187public:
2188
2189 DomainAssembly * LoadAssembly(
2190 AppDomain * pDomain,
2191 mdAssemblyRef kAssemblyRef,
2192 LPCUTF8 szWinRtTypeNamespace = NULL,
2193 LPCUTF8 szWinRtTypeClassName = NULL);
2194 Module *GetModuleIfLoaded(mdFile kFile, BOOL onlyLoadedInAppDomain, BOOL loadAllowed);
2195 DomainFile *LoadModule(AppDomain *pDomain, mdFile kFile, BOOL loadResources = TRUE, BOOL bindOnly = FALSE);
2196 PTR_Module LookupModule(mdToken kFile, BOOL loadResources = TRUE); //wrapper over GetModuleIfLoaded, takes modulerefs as well
2197 DWORD GetAssemblyRefFlags(mdAssemblyRef tkAssemblyRef);
2198
2199 bool HasBindableIdentity(mdAssemblyRef tkAssemblyRef)
2200 {
2201 WRAPPER_NO_CONTRACT;
2202 return !IsAfContentType_WindowsRuntime(GetAssemblyRefFlags(tkAssemblyRef));
2203 }
2204
2205 // RID maps
2206 TypeHandle LookupTypeDef(mdTypeDef token, ClassLoadLevel *pLoadLevel = NULL)
2207 {
2208 LIMITED_METHOD_DAC_CONTRACT;
2209
2210 BAD_FORMAT_NOTHROW_ASSERT(TypeFromToken(token) == mdtTypeDef);
2211
2212 g_IBCLogger.LogRidMapAccess( MakePair( this, token ) );
2213
2214 TADDR flags;
2215 TypeHandle th = TypeHandle(m_TypeDefToMethodTableMap.GetElementAndFlags(RidFromToken(token), &flags));
2216
2217 if (pLoadLevel && !th.IsNull())
2218 {
2219 if (!IsCompilationProcess() && (flags & ZAPPED_TYPE_NEEDS_NO_RESTORE))
2220 {
2221 // Make sure the flag is consistent with the target data and implies the load level we think it does
2222 _ASSERTE(th.AsMethodTable()->IsPreRestored());
2223 _ASSERTE(th.GetLoadLevel() == CLASS_LOADED);
2224
2225 *pLoadLevel = CLASS_LOADED;
2226 }
2227 else
2228 {
2229 *pLoadLevel = th.GetLoadLevel();
2230 }
2231 }
2232
2233 return th;
2234 }
2235
2236 TypeHandle LookupFullyCanonicalInstantiation(mdTypeDef token, ClassLoadLevel *pLoadLevel = NULL)
2237 {
2238 LIMITED_METHOD_DAC_CONTRACT;
2239
2240 BAD_FORMAT_NOTHROW_ASSERT(TypeFromToken(token) == mdtTypeDef);
2241
2242 g_IBCLogger.LogRidMapAccess( MakePair( this, token ) );
2243
2244 TADDR flags;
2245 TypeHandle th = TypeHandle(m_GenericTypeDefToCanonMethodTableMap.GetElementAndFlags(RidFromToken(token), &flags));
2246
2247 if (pLoadLevel && !th.IsNull())
2248 {
2249 if (!IsCompilationProcess() && (flags & ZAPPED_GENERIC_TYPE_NEEDS_NO_RESTORE))
2250 {
2251 // Make sure the flag is consistent with the target data and implies the load level we think it does
2252 _ASSERTE(th.AsMethodTable()->IsPreRestored());
2253 _ASSERTE(th.GetLoadLevel() == CLASS_LOADED);
2254
2255 *pLoadLevel = CLASS_LOADED;
2256 }
2257 else
2258 {
2259 *pLoadLevel = th.GetLoadLevel();
2260 }
2261 }
2262
2263 return th;
2264 }
2265
2266#ifndef DACCESS_COMPILE
2267 VOID EnsureTypeDefCanBeStored(mdTypeDef token)
2268 {
2269 WRAPPER_NO_CONTRACT; // THROWS/GC_NOTRIGGER/INJECT_FAULT()/MODE_ANY
2270 m_TypeDefToMethodTableMap.EnsureElementCanBeStored(this, RidFromToken(token));
2271 }
2272
2273 void EnsuredStoreTypeDef(mdTypeDef token, TypeHandle value)
2274 {
2275 WRAPPER_NO_CONTRACT; // NOTHROW/GC_NOTRIGGER/FORBID_FAULT/MODE_ANY
2276
2277 _ASSERTE(TypeFromToken(token) == mdtTypeDef);
2278 m_TypeDefToMethodTableMap.SetElement(RidFromToken(token), value.AsMethodTable());
2279 }
2280
2281#endif // !DACCESS_COMPILE
2282
2283 TypeHandle LookupTypeRef(mdTypeRef token);
2284
2285 mdTypeRef LookupTypeRefByMethodTable(MethodTable *pMT);
2286
2287 mdMemberRef LookupMemberRefByMethodDesc(MethodDesc *pMD);
2288
2289#ifndef DACCESS_COMPILE
2290 //
2291 // Increase the size of the TypeRef-to-MethodTable LookupMap to make sure the specified token
2292 // can be stored. Note that nothing is actually added to the LookupMap at this point.
2293 //
2294 // Arguments:
2295 // token - the TypeRef metadata token we need to accommodate
2296 //
2297
2298 void EnsureTypeRefCanBeStored(mdTypeRef token)
2299 {
2300 WRAPPER_NO_CONTRACT; // THROWS/GC_NOTRIGGER/INJECT_FAULT()/MODE_ANY
2301
2302 _ASSERTE(TypeFromToken(token) == mdtTypeRef);
2303 m_TypeRefToMethodTableMap.EnsureElementCanBeStored(this, RidFromToken(token));
2304 }
2305
2306 void StoreTypeRef(mdTypeRef token, TypeHandle value)
2307 {
2308 WRAPPER_NO_CONTRACT;
2309
2310 _ASSERTE(TypeFromToken(token) == mdtTypeRef);
2311
2312 g_IBCLogger.LogRidMapAccess( MakePair( this, token ) );
2313
2314 // The TypeRef cache is strictly a lookaside cache. If we get an OOM trying to grow the table,
2315 // we cannot abort the load. (This will cause fatal errors during gc promotion.)
2316 m_TypeRefToMethodTableMap.TrySetElement(RidFromToken(token),
2317 dac_cast<PTR_TypeRef>(value.AsTAddr()));
2318 }
2319#endif // !DACCESS_COMPILE
2320
2321 MethodDesc *LookupMethodDef(mdMethodDef token);
2322
2323#ifndef DACCESS_COMPILE
2324 void EnsureMethodDefCanBeStored(mdMethodDef token)
2325 {
2326 WRAPPER_NO_CONTRACT; // THROWS/GC_NOTRIGGER/INJECT_FAULT()/MODE_ANY
2327 m_MethodDefToDescMap.EnsureElementCanBeStored(this, RidFromToken(token));
2328 }
2329
2330 void EnsuredStoreMethodDef(mdMethodDef token, MethodDesc *value)
2331 {
2332 WRAPPER_NO_CONTRACT; // NOTHROW/GC_NOTRIGGER/FORBID_FAULT/MODE_ANY
2333
2334 _ASSERTE(TypeFromToken(token) == mdtMethodDef);
2335 m_MethodDefToDescMap.SetElement(RidFromToken(token), value);
2336 }
2337#endif // !DACCESS_COMPILE
2338
2339#ifndef DACCESS_COMPILE
2340 FieldDesc *LookupFieldDef(mdFieldDef token)
2341 {
2342 WRAPPER_NO_CONTRACT;
2343
2344 _ASSERTE(TypeFromToken(token) == mdtFieldDef);
2345 return m_FieldDefToDescMap.GetElement(RidFromToken(token));
2346 }
2347#else // DACCESS_COMPILE
2348 // FieldDesc isn't defined at this point so PTR_FieldDesc can't work.
2349 FieldDesc *LookupFieldDef(mdFieldDef token);
2350#endif // DACCESS_COMPILE
2351
2352#ifndef DACCESS_COMPILE
2353 void EnsureFieldDefCanBeStored(mdFieldDef token)
2354 {
2355 WRAPPER_NO_CONTRACT; // THROWS/GC_NOTRIGGER/INJECT_FAULT()/MODE_ANY
2356 m_FieldDefToDescMap.EnsureElementCanBeStored(this, RidFromToken(token));
2357 }
2358
2359 void EnsuredStoreFieldDef(mdFieldDef token, FieldDesc *value)
2360 {
2361 WRAPPER_NO_CONTRACT; // NOTHROW/GC_NOTRIGGER/FORBID_FAULT/MODE_ANY
2362
2363 _ASSERTE(TypeFromToken(token) == mdtFieldDef);
2364 m_FieldDefToDescMap.SetElement(RidFromToken(token), value);
2365 }
2366#endif // !DACCESS_COMPILE
2367
2368 FORCEINLINE TADDR LookupMemberRef(mdMemberRef token, BOOL *pfIsMethod)
2369 {
2370 WRAPPER_NO_CONTRACT;
2371
2372 _ASSERTE(TypeFromToken(token) == mdtMemberRef);
2373
2374 TADDR pResult = dac_cast<TADDR>(m_pMemberRefToDescHashTable->GetValue(token, pfIsMethod));
2375 g_IBCLogger.LogRidMapAccess( MakePair( this, token ) );
2376 return pResult;
2377 }
2378 MethodDesc *LookupMemberRefAsMethod(mdMemberRef token);
2379#ifndef DACCESS_COMPILE
2380 void StoreMemberRef(mdMemberRef token, FieldDesc *value)
2381 {
2382 WRAPPER_NO_CONTRACT;
2383
2384 _ASSERTE(TypeFromToken(token) == mdtMemberRef);
2385 CrstHolder ch(this->GetLookupTableCrst());
2386 m_pMemberRefToDescHashTable->Insert(token, value);
2387 }
2388 void StoreMemberRef(mdMemberRef token, MethodDesc *value)
2389 {
2390 WRAPPER_NO_CONTRACT;
2391
2392 _ASSERTE(TypeFromToken(token) == mdtMemberRef);
2393 CrstHolder ch(this->GetLookupTableCrst());
2394 m_pMemberRefToDescHashTable->Insert(token, value);
2395 }
2396#endif // !DACCESS_COMPILE
2397
2398 PTR_TypeVarTypeDesc LookupGenericParam(mdGenericParam token)
2399 {
2400 WRAPPER_NO_CONTRACT;
2401
2402 _ASSERTE(TypeFromToken(token) == mdtGenericParam);
2403 return m_GenericParamToDescMap.GetElement(RidFromToken(token));
2404 }
2405#ifndef DACCESS_COMPILE
2406 void StoreGenericParamThrowing(mdGenericParam token, TypeVarTypeDesc *value)
2407 {
2408 WRAPPER_NO_CONTRACT;
2409
2410 _ASSERTE(TypeFromToken(token) == mdtGenericParam);
2411 m_GenericParamToDescMap.AddElement(this, RidFromToken(token), value);
2412 }
2413#endif // !DACCESS_COMPILE
2414
2415 PTR_Module LookupFile(mdFile token)
2416 {
2417 WRAPPER_NO_CONTRACT;
2418 SUPPORTS_DAC;
2419
2420 _ASSERTE(TypeFromToken(token) == mdtFile);
2421 return m_FileReferencesMap.GetElement(RidFromToken(token));
2422 }
2423
2424
2425#ifndef DACCESS_COMPILE
2426 void EnsureFileCanBeStored(mdFile token)
2427 {
2428 WRAPPER_NO_CONTRACT; // THROWS/GC_NOTRIGGER/INJECT_FAULT()/MODE_ANY
2429
2430 _ASSERTE(TypeFromToken(token) == mdtFile);
2431 m_FileReferencesMap.EnsureElementCanBeStored(this, RidFromToken(token));
2432 }
2433
2434 void EnsuredStoreFile(mdFile token, Module *value)
2435 {
2436 WRAPPER_NO_CONTRACT; // NOTHROW/GC_NOTRIGGER/FORBID_FAULT
2437
2438
2439 _ASSERTE(TypeFromToken(token) == mdtFile);
2440 m_FileReferencesMap.SetElement(RidFromToken(token), value);
2441 }
2442
2443
2444 void StoreFileThrowing(mdFile token, Module *value)
2445 {
2446 WRAPPER_NO_CONTRACT;
2447
2448
2449 _ASSERTE(TypeFromToken(token) == mdtFile);
2450 m_FileReferencesMap.AddElement(this, RidFromToken(token), value);
2451 }
2452
2453 BOOL StoreFileNoThrow(mdFile token, Module *value)
2454 {
2455 WRAPPER_NO_CONTRACT;
2456
2457 _ASSERTE(TypeFromToken(token) == mdtFile);
2458 return m_FileReferencesMap.TrySetElement(RidFromToken(token), value);
2459 }
2460
2461 mdAssemblyRef FindManifestModule(Module *value)
2462 {
2463 WRAPPER_NO_CONTRACT;
2464
2465 return m_ManifestModuleReferencesMap.Find(value) | mdtAssembly;
2466 }
2467#endif // !DACCESS_COMPILE
2468
2469 DWORD GetFileMax() { LIMITED_METHOD_DAC_CONTRACT; return m_FileReferencesMap.GetSize(); }
2470
2471 Assembly *LookupAssemblyRef(mdAssemblyRef token);
2472
2473#ifndef DACCESS_COMPILE
2474 //
2475 // Increase the size of the AssemblyRef-to-Module LookupMap to make sure the specified token
2476 // can be stored. Note that nothing is actually added to the LookupMap at this point.
2477 //
2478 // Arguments:
2479 // token - the AssemblyRef metadata token we need to accommodate
2480 //
2481
2482 void EnsureAssemblyRefCanBeStored(mdAssemblyRef token)
2483 {
2484 WRAPPER_NO_CONTRACT; // THROWS/GC_NOTRIGGER/INJECT_FAULT()/MODE_ANY
2485
2486 _ASSERTE(TypeFromToken(token) == mdtAssemblyRef);
2487 m_ManifestModuleReferencesMap.EnsureElementCanBeStored(this, RidFromToken(token));
2488 }
2489
2490 void ForceStoreAssemblyRef(mdAssemblyRef token, Assembly *value);
2491 void StoreAssemblyRef(mdAssemblyRef token, Assembly *value);
2492
2493 mdAssemblyRef FindAssemblyRef(Assembly *targetAssembly);
2494
2495 void CreateAssemblyRefByNameTable(AllocMemTracker *pamTracker);
2496 bool HasReferenceByName(LPCUTF8 pModuleName);
2497
2498#endif // !DACCESS_COMPILE
2499
2500#ifdef FEATURE_PREJIT
2501 void FinalizeLookupMapsPreSave(DataImage *image);
2502#endif
2503
2504 DWORD GetAssemblyRefMax() {LIMITED_METHOD_CONTRACT; return m_ManifestModuleReferencesMap.GetSize(); }
2505
2506 MethodDesc *FindMethodThrowing(mdToken pMethod);
2507 MethodDesc *FindMethod(mdToken pMethod);
2508
2509 void PopulatePropertyInfoMap();
2510 HRESULT GetPropertyInfoForMethodDef(mdMethodDef md, mdProperty *ppd, LPCSTR *pName, ULONG *pSemantic);
2511
2512 #define NUM_PROPERTY_SET_HASHES 4
2513#ifdef FEATURE_PREJIT
2514 void PrecomputeMatchingProperties(DataImage *image);
2515#endif
2516 BOOL MightContainMatchingProperty(mdProperty tkProperty, ULONG nameHash);
2517
2518private:
2519 ArrayDPTR(BYTE) m_propertyNameSet;
2520 DWORD m_nPropertyNameSet;
2521
2522public:
2523
2524 // Debugger stuff
2525 BOOL NotifyDebuggerLoad(AppDomain *pDomain, DomainFile * pDomainFile, int level, BOOL attaching);
2526 void NotifyDebuggerUnload(AppDomain *pDomain);
2527
2528 void SetDebuggerInfoBits(DebuggerAssemblyControlFlags newBits);
2529
2530 DebuggerAssemblyControlFlags GetDebuggerInfoBits(void)
2531 {
2532 LIMITED_METHOD_CONTRACT;
2533 SUPPORTS_DAC;
2534
2535 return (DebuggerAssemblyControlFlags)((m_dwTransientFlags &
2536 DEBUGGER_INFO_MASK_PRIV) >>
2537 DEBUGGER_INFO_SHIFT_PRIV);
2538 }
2539
2540#ifdef PROFILING_SUPPORTED
2541 BOOL IsProfilerNotified() {LIMITED_METHOD_CONTRACT; return (m_dwTransientFlags & IS_PROFILER_NOTIFIED) != 0; }
2542 void NotifyProfilerLoadFinished(HRESULT hr);
2543#endif // PROFILING_SUPPORTED
2544
2545 BOOL HasInlineTrackingMap();
2546 COUNT_T GetInliners(PTR_Module inlineeOwnerMod, mdMethodDef inlineeTkn, COUNT_T inlinersSize, MethodInModule inliners[], BOOL *incompleteData);
2547
2548public:
2549 void NotifyEtwLoadFinished(HRESULT hr);
2550
2551 // Enregisters a VASig.
2552 VASigCookie *GetVASigCookie(Signature vaSignature);
2553
2554 // DLL entry point
2555 MethodDesc *GetDllEntryPoint()
2556 {
2557 LIMITED_METHOD_CONTRACT;
2558 return m_pDllMain;
2559 }
2560 void SetDllEntryPoint(MethodDesc *pMD)
2561 {
2562 LIMITED_METHOD_CONTRACT;
2563 m_pDllMain = pMD;
2564 }
2565
2566 // This data is only valid for NGEN'd modules, and for modules we're creating at NGEN time.
2567 ModuleCtorInfo* GetZapModuleCtorInfo()
2568 {
2569 LIMITED_METHOD_DAC_CONTRACT;
2570
2571 return &m_ModuleCtorInfo;
2572 }
2573
2574 private:
2575
2576
2577 public:
2578#ifndef DACCESS_COMPILE
2579 BOOL Equals(Module *pModule) { WRAPPER_NO_CONTRACT; return m_file->Equals(pModule->m_file); }
2580 BOOL Equals(PEFile *pFile) { WRAPPER_NO_CONTRACT; return m_file->Equals(pFile); }
2581#endif // !DACCESS_COMPILE
2582
2583 LPCUTF8 GetSimpleName()
2584 {
2585 WRAPPER_NO_CONTRACT;
2586 _ASSERTE(m_pSimpleName != NULL);
2587 return m_pSimpleName;
2588 }
2589
2590 HRESULT GetScopeName(LPCUTF8 * pszName) { WRAPPER_NO_CONTRACT; return m_file->GetScopeName(pszName); }
2591 const SString &GetPath() { WRAPPER_NO_CONTRACT; return m_file->GetPath(); }
2592
2593#ifdef LOGGING
2594 LPCWSTR GetDebugName() { WRAPPER_NO_CONTRACT; return m_file->GetDebugName(); }
2595#endif
2596
2597#ifdef FEATURE_PREJIT
2598 BOOL HasNativeImage()
2599 {
2600 WRAPPER_NO_CONTRACT;
2601 SUPPORTS_DAC;
2602 return m_file->HasNativeImage();
2603 }
2604
2605 PEImageLayout *GetNativeImage()
2606 {
2607 CONTRACT(PEImageLayout *)
2608 {
2609 PRECONDITION(m_file->HasNativeImage());
2610 POSTCONDITION(CheckPointer(RETVAL));
2611 NOTHROW;
2612 GC_NOTRIGGER;
2613 SUPPORTS_DAC;
2614 CANNOT_TAKE_LOCK;
2615 SO_TOLERANT;
2616 }
2617 CONTRACT_END;
2618
2619 _ASSERTE(!IsCollectible());
2620 RETURN m_file->GetLoadedNative();
2621 }
2622#else
2623 BOOL HasNativeImage()
2624 {
2625 LIMITED_METHOD_CONTRACT;
2626 return FALSE;
2627 }
2628
2629 PEImageLayout * GetNativeImage()
2630 {
2631 // Should never get here
2632 PRECONDITION(HasNativeImage());
2633 return NULL;
2634 }
2635#endif // FEATURE_PREJIT
2636
2637
2638 BOOL HasNativeOrReadyToRunImage();
2639 PEImageLayout * GetNativeOrReadyToRunImage();
2640 PTR_CORCOMPILE_IMPORT_SECTION GetImportSections(COUNT_T *pCount);
2641 PTR_CORCOMPILE_IMPORT_SECTION GetImportSectionFromIndex(COUNT_T index);
2642 PTR_CORCOMPILE_IMPORT_SECTION GetImportSectionForRVA(RVA rva);
2643
2644 // These are overridden by reflection modules
2645 virtual TADDR GetIL(RVA il);
2646
2647 virtual PTR_VOID GetRvaField(RVA field, BOOL fZapped);
2648 CHECK CheckRvaField(RVA field);
2649 CHECK CheckRvaField(RVA field, COUNT_T size);
2650
2651 const void *GetInternalPInvokeTarget(RVA target)
2652 { WRAPPER_NO_CONTRACT; return m_file->GetInternalPInvokeTarget(target); }
2653
2654 BOOL HasTls();
2655 BOOL IsRvaFieldTls(DWORD field);
2656 UINT32 GetFieldTlsOffset(DWORD field);
2657 UINT32 GetTlsIndex();
2658
2659 BOOL IsSigInIL(PCCOR_SIGNATURE signature);
2660
2661 mdToken GetEntryPointToken();
2662
2663 BYTE *GetProfilerBase();
2664
2665
2666 // Active transition path management
2667 //
2668 // This list keeps track of module which we have active transition
2669 // paths to. An active transition path is where we move from
2670 // active execution in one module to another module without
2671 // involving triggering the file loader to ensure that the
2672 // destination module is active. We must explicitly list these
2673 // relationships so the the loader can ensure that the activation
2674 // constraints are a priori satisfied.
2675 //
2676 // Conditional vs. Unconditional describes how we deal with
2677 // activation failure of a dependency. In the unconditional case,
2678 // we propagate the activation failure to the depending module.
2679 // In the conditional case, we activate a "trigger" in the active
2680 // transition path which will cause the path to fail in particular
2681 // app domains where the destination module failed to activate.
2682 // (This trigger in the path typically has a perf cost even in the
2683 // nonfailing case.)
2684 //
2685 // In either case we must try to perform the activation eagerly -
2686 // even in the conditional case we have to know whether to turn on
2687 // the trigger or not before we let the active transition path
2688 // execute.
2689
2690 void AddActiveDependency(Module *pModule, BOOL unconditional);
2691
2692 // Turn triggers from this module into runtime checks
2693 void EnableModuleFailureTriggers(Module *pModule, AppDomain *pDomain);
2694
2695#ifdef FEATURE_PREJIT
2696 BOOL IsZappedCode(PCODE code);
2697 BOOL IsZappedPrecode(PCODE code);
2698
2699 CORCOMPILE_DEBUG_ENTRY GetMethodDebugInfoOffset(MethodDesc *pMD);
2700 PTR_BYTE GetNativeDebugInfo(MethodDesc * pMD);
2701
2702 // The methods below must be called when loading back an ngen'ed image for any fields that
2703 // might be an encoded token (rather than a hard pointer) and/or need a restore operation
2704 //
2705 static void RestoreMethodTablePointerRaw(PTR_MethodTable * ppMT,
2706 Module *pContainingModule = NULL,
2707 ClassLoadLevel level = CLASS_LOADED);
2708 static void RestoreTypeHandlePointerRaw(TypeHandle *pHandle,
2709 Module *pContainingModule = NULL,
2710 ClassLoadLevel level = CLASS_LOADED);
2711 static void RestoreMethodDescPointerRaw(PTR_MethodDesc * ppMD,
2712 Module *pContainingModule = NULL,
2713 ClassLoadLevel level = CLASS_LOADED);
2714
2715 static void RestoreMethodTablePointer(FixupPointer<PTR_MethodTable> * ppMT,
2716 Module *pContainingModule = NULL,
2717 ClassLoadLevel level = CLASS_LOADED);
2718 static void RestoreTypeHandlePointer(FixupPointer<TypeHandle> *pHandle,
2719 Module *pContainingModule = NULL,
2720 ClassLoadLevel level = CLASS_LOADED);
2721 static void RestoreMethodDescPointer(FixupPointer<PTR_MethodDesc> * ppMD,
2722 Module *pContainingModule = NULL,
2723 ClassLoadLevel level = CLASS_LOADED);
2724
2725 static void RestoreMethodTablePointer(RelativeFixupPointer<PTR_MethodTable> * ppMT,
2726 Module *pContainingModule = NULL,
2727 ClassLoadLevel level = CLASS_LOADED);
2728 static void RestoreTypeHandlePointer(RelativeFixupPointer<TypeHandle> *pHandle,
2729 Module *pContainingModule = NULL,
2730 ClassLoadLevel level = CLASS_LOADED);
2731 static void RestoreMethodDescPointer(RelativeFixupPointer<PTR_MethodDesc> * ppMD,
2732 Module *pContainingModule = NULL,
2733 ClassLoadLevel level = CLASS_LOADED);
2734 static void RestoreFieldDescPointer(RelativeFixupPointer<PTR_FieldDesc> * ppFD);
2735
2736 static void RestoreModulePointer(RelativeFixupPointer<PTR_Module> * ppModule, Module *pContainingModule);
2737
2738 static PTR_Module RestoreModulePointerIfLoaded(DPTR(RelativeFixupPointer<PTR_Module>) ppModule, Module *pContainingModule);
2739
2740 PCCOR_SIGNATURE GetEncodedSig(RVA fixupRva, Module **ppDefiningModule);
2741 PCCOR_SIGNATURE GetEncodedSigIfLoaded(RVA fixupRva, Module **ppDefiningModule);
2742
2743 BYTE *GetNativeFixupBlobData(RVA fixup);
2744
2745 IMDInternalImport *GetNativeAssemblyImport(BOOL loadAllowed = TRUE);
2746
2747 BOOL FixupNativeEntry(CORCOMPILE_IMPORT_SECTION * pSection, SIZE_T fixupIndex, SIZE_T *fixup);
2748
2749 //this split exists to support new CLR Dump functionality in DAC. The
2750 //template removes any indirections.
2751 BOOL FixupDelayList(TADDR pFixupList);
2752
2753 template<typename Ptr, typename FixupNativeEntryCallback>
2754 BOOL FixupDelayListAux(TADDR pFixupList,
2755 Ptr pThis, FixupNativeEntryCallback pfnCB,
2756 PTR_CORCOMPILE_IMPORT_SECTION pImportSections, COUNT_T nImportSections,
2757 PEDecoder * pNativeImage);
2758 void RunEagerFixups();
2759
2760 IMDInternalImport *GetNativeFixupImport();
2761 Module *GetModuleFromIndex(DWORD ix);
2762 Module *GetModuleFromIndexIfLoaded(DWORD ix);
2763
2764 // This is to rebuild stub dispatch maps to module-local values.
2765 void UpdateStubDispatchTypeTable(DataImage *image);
2766
2767 void SetProfileData(CorProfileData * profileData);
2768 CorProfileData *GetProfileData();
2769
2770 mdTypeDef LookupIbcTypeToken( Module * pExternalModule, mdToken ibcToken, SString* optionalFullNameOut = NULL);
2771 mdMethodDef LookupIbcMethodToken(TypeHandle enclosingType, mdToken ibcToken, SString* optionalFullNameOut = NULL);
2772
2773 TypeHandle LoadIBCTypeHelper(DataImage *image, CORBBTPROF_BLOB_PARAM_SIG_ENTRY *pBlobSigEntry);
2774 MethodDesc * LoadIBCMethodHelper(DataImage *image, CORBBTPROF_BLOB_PARAM_SIG_ENTRY *pBlobSigEntry);
2775
2776
2777 void ExpandAll(DataImage *image);
2778 // profileData may be different than the profileData passed in to
2779 // ExpandAll() depending on more information that may now be available
2780 // (after all the methods have been compiled)
2781
2782 void Save(DataImage *image);
2783 void Arrange(DataImage *image);
2784 void PlaceType(DataImage *image, TypeHandle th, DWORD profilingFlags);
2785 void PlaceMethod(DataImage *image, MethodDesc *pMD, DWORD profilingFlags);
2786 void Fixup(DataImage *image);
2787
2788 bool AreAllClassesFullyLoaded();
2789
2790 // Precompute type-specific auxiliary information saved into NGen image
2791 void PrepareTypesForSave(DataImage *image);
2792
2793 static void SaveMethodTable(DataImage *image,
2794 MethodTable *pMT,
2795 DWORD profilingFlags);
2796
2797 static void SaveTypeHandle(DataImage *image,
2798 TypeHandle t,
2799 DWORD profilingFlags);
2800
2801private:
2802 static BOOL CanEagerBindTo(Module *targetModule, Module *pPreferredZapModule, void *address);
2803public:
2804
2805 static PTR_Module ComputePreferredZapModule(Module * pDefinitionModule, // the module that declares the generic type or method
2806 Instantiation classInst, // the type arguments to the type (if any)
2807 Instantiation methodInst = Instantiation()); // the type arguments to the method (if any)
2808
2809 static PTR_Module ComputePreferredZapModuleHelper(Module * pDefinitionModule,
2810 Instantiation classInst,
2811 Instantiation methodInst);
2812
2813 static PTR_Module ComputePreferredZapModule(TypeKey * pKey);
2814
2815 // Return true if types or methods of this instantiation are *always* precompiled and saved
2816 // in the preferred zap module
2817 // At present, only true for <__Canon,...,__Canon> instantiation
2818 static BOOL IsAlwaysSavedInPreferredZapModule(Instantiation classInst,
2819 Instantiation methodInst = Instantiation());
2820
2821 static PTR_Module GetPreferredZapModuleForTypeHandle(TypeHandle t);
2822 static PTR_Module GetPreferredZapModuleForMethodTable(MethodTable * pMT);
2823 static PTR_Module GetPreferredZapModuleForMethodDesc(const MethodDesc * pMD);
2824 static PTR_Module GetPreferredZapModuleForFieldDesc(FieldDesc * pFD);
2825 static PTR_Module GetPreferredZapModuleForTypeDesc(PTR_TypeDesc pTD);
2826
2827 void PrepopulateDictionaries(DataImage *image, BOOL nonExpansive);
2828
2829
2830 void LoadTokenTables();
2831 void LoadHelperTable();
2832
2833 PTR_NGenLayoutInfo GetNGenLayoutInfo()
2834 {
2835 LIMITED_METHOD_DAC_CONTRACT;
2836 return m_pNGenLayoutInfo;
2837 }
2838
2839 PCODE GetPrestubJumpStub()
2840 {
2841 LIMITED_METHOD_DAC_CONTRACT;
2842
2843 if (!m_pNGenLayoutInfo)
2844 return NULL;
2845
2846 return m_pNGenLayoutInfo->m_pPrestubJumpStub;
2847 }
2848
2849#ifdef HAS_FIXUP_PRECODE
2850 PCODE GetPrecodeFixupJumpStub()
2851 {
2852 LIMITED_METHOD_DAC_CONTRACT;
2853
2854 if (!m_pNGenLayoutInfo)
2855 return NULL;
2856
2857 return m_pNGenLayoutInfo->m_pPrecodeFixupJumpStub;
2858 }
2859#endif
2860
2861 BOOL IsVirtualImportThunk(PCODE code)
2862 {
2863 LIMITED_METHOD_DAC_CONTRACT;
2864
2865 if (!m_pNGenLayoutInfo)
2866 return FALSE;
2867
2868 return m_pNGenLayoutInfo->m_VirtualMethodThunks.IsInRange(code);
2869 }
2870
2871 ICorJitInfo::ProfileBuffer * AllocateProfileBuffer(mdToken _token, DWORD _size, DWORD _ILSize);
2872 HANDLE OpenMethodProfileDataLogFile(GUID mvid);
2873 static void ProfileDataAllocateTokenLists(ProfileEmitter * pEmitter, TokenProfileData* pTokenProfileData);
2874 HRESULT WriteMethodProfileDataLogFile(bool cleanup);
2875 static void WriteAllModuleProfileData(bool cleanup);
2876 void SetMethodProfileList(CORCOMPILE_METHOD_PROFILE_LIST * value)
2877 {
2878 m_methodProfileList = value;
2879 }
2880
2881 void CreateProfilingData();
2882 void DeleteProfilingData();
2883
2884 PTR_ProfilingBlobTable GetProfilingBlobTable();
2885
2886 void LogTokenAccess(mdToken token, SectionFormat format, ULONG flagNum);
2887 void LogTokenAccess(mdToken token, ULONG flagNum);
2888
2889 BOOL AreTypeSpecsTriaged()
2890 {
2891 return m_dwTransientFlags & TYPESPECS_TRIAGED;
2892 }
2893
2894 void SetTypeSpecsTriaged()
2895 {
2896 FastInterlockOr(&m_dwTransientFlags, TYPESPECS_TRIAGED);
2897 }
2898
2899 BOOL IsModuleSaved()
2900 {
2901 return m_dwTransientFlags & MODULE_SAVED;
2902 }
2903
2904 void SetIsModuleSaved()
2905 {
2906 FastInterlockOr(&m_dwTransientFlags, MODULE_SAVED);
2907 }
2908
2909#endif // FEATURE_PREJIT
2910
2911 BOOL IsReadyToRun()
2912 {
2913 LIMITED_METHOD_DAC_CONTRACT;
2914
2915#ifdef FEATURE_READYTORUN
2916 return m_pReadyToRunInfo != NULL;
2917#else
2918 return FALSE;
2919#endif
2920 }
2921
2922#ifdef FEATURE_READYTORUN
2923 PTR_ReadyToRunInfo GetReadyToRunInfo()
2924 {
2925 LIMITED_METHOD_DAC_CONTRACT;
2926 return m_pReadyToRunInfo;
2927 }
2928#endif
2929
2930#ifdef _DEBUG
2931 //Similar to the ExpandAll we use for NGen, this forces jitting of all methods in a module. This is
2932 //used for debug purposes though.
2933 void ExpandAll();
2934#endif
2935
2936 BOOL IsIJWFixedUp() { return m_dwTransientFlags & IS_IJW_FIXED_UP; }
2937 void SetIsIJWFixedUp();
2938
2939 BOOL IsBeingUnloaded() { return m_dwTransientFlags & IS_BEING_UNLOADED; }
2940 void SetBeingUnloaded();
2941 void StartUnload();
2942
2943
2944public:
2945 idTypeSpec LogInstantiatedType(TypeHandle typeHnd, ULONG flagNum);
2946 idMethodSpec LogInstantiatedMethod(const MethodDesc * md, ULONG flagNum);
2947
2948 static DWORD EncodeModuleHelper(void* pModuleContext, Module *pReferencedModule);
2949 static void TokenDefinitionHelper(void* pModuleContext, Module *pReferencedModule, DWORD index, mdToken* token);
2950
2951public:
2952 MethodTable* MapZapType(UINT32 typeID);
2953
2954 void SetDynamicIL(mdToken token, TADDR blobAddress, BOOL fTemporaryOverride);
2955 TADDR GetDynamicIL(mdToken token, BOOL fAllowTemporary);
2956
2957 // store and retrieve the instrumented IL offset mapping for a particular method
2958#if !defined(DACCESS_COMPILE)
2959 void SetInstrumentedILOffsetMapping(mdMethodDef token, InstrumentedILOffsetMapping mapping);
2960#endif // !DACCESS_COMPILE
2961 InstrumentedILOffsetMapping GetInstrumentedILOffsetMapping(mdMethodDef token);
2962
2963public:
2964 // This helper returns to offsets for the slots/bytes/handles. They return the offset in bytes from the beggining
2965 // of the 1st GC pointer in the statics block for the module.
2966 void GetOffsetsForRegularStaticData(
2967 mdTypeDef cl,
2968 BOOL bDynamic,
2969 DWORD dwGCStaticHandles,
2970 DWORD dwNonGCStaticBytes,
2971 DWORD * pOutStaticHandleOffset,
2972 DWORD * pOutNonGCStaticOffset);
2973
2974 void GetOffsetsForThreadStaticData(
2975 mdTypeDef cl,
2976 BOOL bDynamic,
2977 DWORD dwGCStaticHandles,
2978 DWORD dwNonGCStaticBytes,
2979 DWORD * pOutStaticHandleOffset,
2980 DWORD * pOutNonGCStaticOffset);
2981
2982
2983 BOOL IsStaticStoragePrepared(mdTypeDef tkType);
2984
2985 DWORD GetNumGCThreadStaticHandles()
2986 {
2987 return m_dwMaxGCThreadStaticHandles;;
2988 }
2989
2990 CrstBase* GetFixupCrst()
2991 {
2992 return &m_FixupCrst;
2993 }
2994
2995 void AllocateRegularStaticHandles(AppDomain* pDomainMT);
2996
2997 void FreeModuleIndex();
2998
2999 DWORD GetDomainLocalModuleSize()
3000 {
3001 return m_dwRegularStaticsBlockSize;
3002 }
3003
3004 DWORD GetThreadLocalModuleSize()
3005 {
3006 return m_dwThreadStaticsBlockSize;
3007 }
3008
3009 DWORD AllocateDynamicEntry(MethodTable *pMT);
3010
3011 // We need this for the jitted shared case,
3012 inline MethodTable* GetDynamicClassMT(DWORD dynamicClassID);
3013
3014 static BOOL IsEncodedModuleIndex(SIZE_T ModuleID)
3015 {
3016 LIMITED_METHOD_DAC_CONTRACT;
3017
3018 // We should never see encoded module index in CoreCLR
3019 _ASSERTE((ModuleID&1)==0);
3020 return FALSE;
3021 }
3022
3023 static SIZE_T IndexToID(ModuleIndex index)
3024 {
3025 LIMITED_METHOD_CONTRACT
3026
3027 return (index.m_dwIndex << 1) | 1;
3028 }
3029
3030 static ModuleIndex IDToIndex(SIZE_T ModuleID)
3031 {
3032 LIMITED_METHOD_CONTRACT
3033 SUPPORTS_DAC;
3034
3035 _ASSERTE(IsEncodedModuleIndex(ModuleID));
3036 ModuleIndex index(ModuleID >> 1);
3037
3038 return index;
3039 }
3040
3041 static ModuleIndex AllocateModuleIndex();
3042 static void FreeModuleIndex(ModuleIndex index);
3043
3044 ModuleIndex GetModuleIndex()
3045 {
3046 LIMITED_METHOD_DAC_CONTRACT;
3047 return m_ModuleIndex;
3048 }
3049
3050 SIZE_T GetModuleID()
3051 {
3052 LIMITED_METHOD_DAC_CONTRACT;
3053 return dac_cast<TADDR>(m_ModuleID);
3054 }
3055
3056 SIZE_T * GetAddrModuleID()
3057 {
3058 LIMITED_METHOD_CONTRACT;
3059 return (SIZE_T*) &m_ModuleID;
3060 }
3061
3062 static SIZE_T GetOffsetOfModuleID()
3063 {
3064 LIMITED_METHOD_CONTRACT;
3065 return offsetof(Module, m_ModuleID);
3066 }
3067
3068 PTR_DomainLocalModule GetDomainLocalModule(AppDomain *pDomain);
3069
3070#ifndef DACCESS_COMPILE
3071 PTR_DomainLocalModule GetDomainLocalModule() { WRAPPER_NO_CONTRACT; return GetDomainLocalModule(NULL); };
3072#endif
3073
3074#ifdef FEATURE_PREJIT
3075 NgenStats *GetNgenStats()
3076 {
3077 LIMITED_METHOD_CONTRACT;
3078 return m_pNgenStats;
3079 }
3080#endif // FEATURE_PREJIT
3081
3082 // LoaderHeap for storing IJW thunks
3083 PTR_LoaderHeap m_pThunkHeap;
3084
3085 // Self-initializing accessor for IJW thunk heap
3086 LoaderHeap *GetThunkHeap();
3087 // Self-initializing accessor for domain-independent IJW thunk heap
3088 LoaderHeap *GetDllThunkHeap();
3089
3090 void EnumRegularStaticGCRefs (AppDomain* pAppDomain, promote_func* fn, ScanContext* sc);
3091
3092protected:
3093
3094 void BuildStaticsOffsets (AllocMemTracker *pamTracker);
3095 void AllocateStatics (AllocMemTracker *pamTracker);
3096
3097 // ModuleID is quite ugly. We should try to switch to using ModuleIndex instead
3098 // where appropriate, and we should clean up code that uses ModuleID
3099 PTR_DomainLocalModule m_ModuleID; // MultiDomain case: tagged (low bit 1) ModuleIndex
3100 // SingleDomain case: pointer to domain local module
3101
3102 ModuleIndex m_ModuleIndex;
3103
3104 // reusing the statics area of a method table to store
3105 // these for the non domain neutral case, but they're now unified
3106 // it so that we don't have different code paths for this.
3107 PTR_DWORD m_pRegularStaticOffsets; // Offset of statics in each class
3108 PTR_DWORD m_pThreadStaticOffsets; // Offset of ThreadStatics in each class
3109
3110 // All types with RID <= this value have static storage allocated within the module by AllocateStatics
3111 // If AllocateStatics hasn't run yet, the value is 0
3112 RID m_maxTypeRidStaticsAllocated;
3113
3114 // @NICE: see if we can remove these fields
3115 DWORD m_dwMaxGCRegularStaticHandles; // Max number of handles we can have.
3116 DWORD m_dwMaxGCThreadStaticHandles;
3117
3118 // Size of the precomputed statics block. This includes class init bytes, gc handles and non gc statics
3119 DWORD m_dwRegularStaticsBlockSize;
3120 DWORD m_dwThreadStaticsBlockSize;
3121
3122 // For 'dynamic' statics (Reflection and generics)
3123 SIZE_T m_cDynamicEntries; // Number of used entries in DynamicStaticsInfo table
3124 SIZE_T m_maxDynamicEntries; // Size of table itself, including unused entries
3125
3126 // Info we need for dynamic statics that we can store per-module (ie, no need for it to be duplicated
3127 // per appdomain)
3128 struct DynamicStaticsInfo
3129 {
3130 MethodTable* pEnclosingMT; // Enclosing type; necessarily in this loader module
3131 };
3132 DynamicStaticsInfo* m_pDynamicStaticsInfo; // Table with entry for each dynamic ID
3133
3134
3135public:
3136 //-----------------------------------------------------------------------------------------
3137 // If true, strings only need to be interned at a per module basis, instead of at a
3138 // per appdomain basis, which is the default. Use the module accessor so you don't need
3139 // to touch the metadata in the ngen case
3140 //-----------------------------------------------------------------------------------------
3141 BOOL IsNoStringInterning();
3142
3143 //-----------------------------------------------------------------------------------------
3144 // Returns a BOOL to indicate if we have computed whether compiler has instructed us to
3145 // wrap the non-CLS compliant exceptions or not.
3146 //-----------------------------------------------------------------------------------------
3147 BOOL IsRuntimeWrapExceptionsStatusComputed();
3148
3149 //-----------------------------------------------------------------------------------------
3150 // If true, any non-CLSCompliant exceptions (i.e. ones which derive from something other
3151 // than System.Exception) are wrapped in a RuntimeWrappedException instance. In other
3152 // words, they become compliant
3153 //-----------------------------------------------------------------------------------------
3154 BOOL IsRuntimeWrapExceptions();
3155
3156 BOOL HasDefaultDllImportSearchPathsAttribute();
3157
3158 BOOL IsDefaultDllImportSearchPathsAttributeCached()
3159 {
3160 LIMITED_METHOD_CONTRACT;
3161 return (m_dwPersistedFlags & DEFAULT_DLL_IMPORT_SEARCH_PATHS_IS_CACHED) != 0;
3162 }
3163
3164 ULONG DefaultDllImportSearchPathsAttributeCachedValue()
3165 {
3166 LIMITED_METHOD_CONTRACT;
3167 return m_DefaultDllImportSearchPathsAttributeValue & 0xFFFFFFFD;
3168 }
3169
3170 BOOL DllImportSearchAssemblyDirectory()
3171 {
3172 LIMITED_METHOD_CONTRACT;
3173 return (m_DefaultDllImportSearchPathsAttributeValue & 0x2) != 0;
3174 }
3175
3176 //-----------------------------------------------------------------------------------------
3177 // True iff metadata version string is 1.* or 2.*.
3178 // @TODO (post-Dev10): All places that need this information should call this function
3179 // instead of parsing the version themselves.
3180 //-----------------------------------------------------------------------------------------
3181 BOOL IsPreV4Assembly();
3182
3183
3184 //-----------------------------------------------------------------------------------------
3185 // Parse/Return NeutralResourcesLanguageAttribute if it exists (updates Module member variables at ngen time)
3186 //-----------------------------------------------------------------------------------------
3187 BOOL GetNeutralResourcesLanguage(LPCUTF8 * cultureName, ULONG * cultureNameLength, INT16 * fallbackLocation, BOOL cacheAttribute);
3188
3189protected:
3190
3191
3192 // initialize Crst controlling the Dynamic IL hashtables
3193 void InitializeDynamicILCrst();
3194
3195public:
3196
3197 CrstBase *GetLookupTableCrst()
3198 {
3199 LIMITED_METHOD_CONTRACT;
3200 return &m_LookupTableCrst;
3201 }
3202
3203private:
3204
3205 // This struct stores the data used by the managed debugging infrastructure. If it turns out that
3206 // the debugger is increasing the size of the Module class by too much, we can consider allocating
3207 // this struct lazily on demand.
3208 struct DebuggerSpecificData
3209 {
3210 // Mutex protecting update access to the DynamicILBlobTable and TemporaryILBlobTable
3211 PTR_Crst m_pDynamicILCrst;
3212
3213 // maps tokens for EnC/dynamics/reflection emit to their corresponding IL blobs
3214 // this map *always* overrides the Metadata RVA
3215 PTR_DynamicILBlobTable m_pDynamicILBlobTable;
3216
3217 // maps tokens for to their corresponding overriden IL blobs
3218 // this map conditionally overrides the Metadata RVA and the DynamicILBlobTable
3219 PTR_DynamicILBlobTable m_pTemporaryILBlobTable;
3220
3221 // hash table storing any profiler-provided instrumented IL offset mapping
3222 PTR_ILOffsetMappingTable m_pILOffsetMappingTable;
3223
3224 // Strict count of # of methods in this module that are JMC-enabled.
3225 LONG m_cTotalJMCFuncs;
3226
3227 // The default JMC status for methods in this module.
3228 // Individual methods can be overridden.
3229 bool m_fDefaultJMCStatus;
3230 };
3231
3232 DebuggerSpecificData m_debuggerSpecificData;
3233
3234 // This is a compressed read only copy of m_inlineTrackingMap, which is being saved to NGEN image.
3235 PTR_PersistentInlineTrackingMapNGen m_pPersistentInlineTrackingMapNGen;
3236
3237
3238 LPCSTR *m_AssemblyRefByNameTable; // array that maps mdAssemblyRef tokens into their simple name
3239 DWORD m_AssemblyRefByNameCount; // array size
3240
3241#if defined(FEATURE_PREJIT)
3242 // a.dll calls a method in b.dll and that method call a method in c.dll. When ngening
3243 // a.dll it is possible then method in b.dll can be inlined. When that happens a.ni.dll stores
3244 // an added native metadata which has information about assemblyRef to c.dll
3245 // Now due to facades, this scenario is very common. This led to lots of calls to
3246 // binder to get the module corresponding to assemblyRef in native metadata.
3247 // Adding a lookup map to cache assembly ptr so that AssemblySpec::LoadAssembly()
3248 // is not called for each fixup
3249
3250 PTR_Assembly *m_NativeMetadataAssemblyRefMap;
3251#endif // defined(FEATURE_PREJIT)
3252
3253public:
3254#if !defined(DACCESS_COMPILE) && defined(FEATURE_PREJIT)
3255 PTR_Assembly GetNativeMetadataAssemblyRefFromCache(DWORD rid)
3256 {
3257 PTR_Assembly * NativeMetadataAssemblyRefMap = VolatileLoadWithoutBarrier(&m_NativeMetadataAssemblyRefMap);
3258
3259 if (NativeMetadataAssemblyRefMap == NULL)
3260 return NULL;
3261
3262 _ASSERTE(rid <= GetNativeAssemblyImport()->GetCountWithTokenKind(mdtAssemblyRef));
3263 return NativeMetadataAssemblyRefMap[rid - 1];
3264 }
3265
3266 void SetNativeMetadataAssemblyRefInCache(DWORD rid, PTR_Assembly pAssembly);
3267#endif // !defined(DACCESS_COMPILE) && defined(FEATURE_PREJIT)
3268};
3269
3270//
3271// A ReflectionModule is a module created by reflection
3272//
3273
3274class ReflectionModule : public Module
3275{
3276 VPTR_VTABLE_CLASS(ReflectionModule, Module)
3277
3278 public:
3279 HCEESECTION m_sdataSection;
3280
3281 protected:
3282 ICeeGen * m_pCeeFileGen;
3283private:
3284 Assembly *m_pCreatingAssembly;
3285 ISymUnmanagedWriter *m_pISymUnmanagedWriter;
3286 RefClassWriter *m_pInMemoryWriter;
3287
3288
3289 // Simple Critical Section used for basic leaf-lock operatons.
3290 CrstExplicitInit m_CrstLeafLock;
3291
3292 // Buffer of Metadata storage for dynamic modules. May be NULL. This provides a reasonable way for
3293 // the debugger to get metadata of dynamic modules from out of process.
3294 // A dynamic module will eagerly serialize its metadata to this buffer.
3295 PTR_SBuffer m_pDynamicMetadata;
3296
3297 // If true, does not eagerly serialize metadata in code:ReflectionModule.CaptureModuleMetaDataToMemory.
3298 // This is used to allow bulk emitting types without re-emitting the metadata between each type.
3299 bool m_fSuppressMetadataCapture;
3300
3301 // If true, then only other transient modules can depend on this module.
3302 bool m_fIsTransient;
3303
3304#if !defined DACCESS_COMPILE && !defined CROSSGEN_COMPILE
3305 // Returns true iff metadata capturing is suppressed
3306 bool IsMetadataCaptureSuppressed();
3307
3308 // Toggle whether CaptureModuleMetaDataToMemory should do antyhing. This can be an important perf win to
3309 // allow batching up metadata capture. Use SuppressMetadataCaptureHolder to ensure they're balanced.
3310 // These are not nestable.
3311 void SuppressMetadataCapture();
3312 void ResumeMetadataCapture();
3313
3314 // Glue functions for holders.
3315 static void SuppressCaptureWrapper(ReflectionModule * pModule)
3316 {
3317 pModule->SuppressMetadataCapture();
3318 }
3319 static void ResumeCaptureWrapper(ReflectionModule * pModule)
3320 {
3321 pModule->ResumeMetadataCapture();
3322 }
3323
3324 ReflectionModule(Assembly *pAssembly, mdFile token, PEFile *pFile);
3325#endif // !DACCESS_COMPILE && !CROSSGEN_COMPILE
3326
3327public:
3328
3329#ifdef DACCESS_COMPILE
3330 // Accessor to expose m_pDynamicMetadata to debugger.
3331 PTR_SBuffer GetDynamicMetadataBuffer() const;
3332#endif
3333
3334#if !defined DACCESS_COMPILE && !defined CROSSGEN_COMPILE
3335 static ReflectionModule *Create(Assembly *pAssembly, PEFile *pFile, AllocMemTracker *pamTracker, LPCWSTR szName, BOOL fIsTransient);
3336 void Initialize(AllocMemTracker *pamTracker, LPCWSTR szName);
3337 void Destruct();
3338
3339 void ReleaseILData();
3340#endif // !DACCESS_COMPILE && !CROSSGEN_COMPILE
3341
3342 // Overides functions to access sections
3343 virtual TADDR GetIL(RVA target);
3344 virtual PTR_VOID GetRvaField(RVA rva, BOOL fZapped);
3345
3346 Assembly* GetCreatingAssembly( void )
3347 {
3348 LIMITED_METHOD_CONTRACT;
3349
3350 return m_pCreatingAssembly;
3351 }
3352
3353 void SetCreatingAssembly( Assembly* assembly )
3354 {
3355 LIMITED_METHOD_CONTRACT;
3356
3357 m_pCreatingAssembly = assembly;
3358 }
3359
3360 ICeeGen *GetCeeGen() {LIMITED_METHOD_CONTRACT; return m_pCeeFileGen; }
3361
3362 RefClassWriter *GetClassWriter()
3363 {
3364 LIMITED_METHOD_CONTRACT;
3365
3366 return m_pInMemoryWriter;
3367 }
3368
3369 ISymUnmanagedWriter *GetISymUnmanagedWriter()
3370 {
3371 LIMITED_METHOD_CONTRACT;
3372 return m_pISymUnmanagedWriter;
3373 }
3374
3375 // Note: we now use the same writer instance for the life of a module,
3376 // so there should no longer be any need for the extra indirection.
3377 ISymUnmanagedWriter **GetISymUnmanagedWriterAddr()
3378 {
3379 LIMITED_METHOD_CONTRACT;
3380
3381 // We must have setup the writer before trying to get
3382 // the address for it. Any calls to this before a
3383 // SetISymUnmanagedWriter are very incorrect.
3384 _ASSERTE(m_pISymUnmanagedWriter != NULL);
3385
3386 return &m_pISymUnmanagedWriter;
3387 }
3388
3389 bool IsTransient()
3390 {
3391 LIMITED_METHOD_CONTRACT;
3392
3393 return m_fIsTransient;
3394 }
3395
3396 void SetIsTransient(bool fIsTransient)
3397 {
3398 LIMITED_METHOD_CONTRACT;
3399
3400 m_fIsTransient = fIsTransient;
3401 }
3402
3403#ifndef DACCESS_COMPILE
3404#ifndef CROSSGEN_COMPILE
3405
3406 typedef Wrapper<
3407 ReflectionModule*,
3408 ReflectionModule::SuppressCaptureWrapper,
3409 ReflectionModule::ResumeCaptureWrapper> SuppressMetadataCaptureHolder;
3410#endif // !CROSSGEN_COMPILE
3411
3412 HRESULT SetISymUnmanagedWriter(ISymUnmanagedWriter *pWriter)
3413 {
3414 CONTRACTL
3415 {
3416 NOTHROW;
3417 GC_NOTRIGGER;
3418 INJECT_FAULT(return E_OUTOFMEMORY;);
3419 }
3420 CONTRACTL_END
3421
3422
3423 // Setting to NULL when we've never set a writer before should
3424 // do nothing.
3425 if ((pWriter == NULL) && (m_pISymUnmanagedWriter == NULL))
3426 return S_OK;
3427
3428 if (m_pISymUnmanagedWriter != NULL)
3429 {
3430 // We shouldn't be trying to replace an existing writer anymore
3431 _ASSERTE( pWriter == NULL );
3432
3433 m_pISymUnmanagedWriter->Release();
3434 }
3435
3436 m_pISymUnmanagedWriter = pWriter;
3437 return S_OK;
3438 }
3439#endif // !DACCESS_COMPILE
3440
3441 // Eagerly serialize the metadata to a buffer that the debugger can retrieve.
3442 void CaptureModuleMetaDataToMemory();
3443};
3444
3445// Module holders
3446FORCEINLINE void VoidModuleDestruct(Module *pModule)
3447{
3448#ifndef DACCESS_COMPILE
3449 if (g_fEEStarted)
3450 pModule->Destruct();
3451#endif
3452}
3453
3454typedef Wrapper<Module*, DoNothing, VoidModuleDestruct, 0> ModuleHolder;
3455
3456
3457
3458FORCEINLINE void VoidReflectionModuleDestruct(ReflectionModule *pModule)
3459{
3460#ifndef DACCESS_COMPILE
3461 pModule->Destruct();
3462#endif
3463}
3464
3465typedef Wrapper<ReflectionModule*, DoNothing, VoidReflectionModuleDestruct, 0> ReflectionModuleHolder;
3466
3467
3468
3469//----------------------------------------------------------------------
3470// VASigCookieEx (used to create a fake VASigCookie for unmanaged->managed
3471// calls to vararg functions. These fakes are distinguished from the
3472// real thing by having a null mdVASig.
3473//----------------------------------------------------------------------
3474struct VASigCookieEx : public VASigCookie
3475{
3476 const BYTE *m_pArgs; // pointer to first unfixed unmanaged arg
3477};
3478
3479#endif // !CEELOAD_H_
3480