forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathceeload.h
1757 lines (1377 loc) · 57.4 KB
/
ceeload.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// ===========================================================================
// File: CEELOAD.H
//
//
// CEELOAD.H defines the class use to represent the PE file
// ===========================================================================
#ifndef CEELOAD_H_
#define CEELOAD_H_
#include "common.h"
#include "vars.hpp" // for LPCUTF8
#include "hash.h"
#include "clsload.hpp"
#include "cgensys.h"
#include "corsym.h"
#include "typehandle.h"
#include "arraylist.h"
#include "peassembly.h"
#include "typehash.h"
#include "contractimpl.h"
#include "bitmask.h"
#include "instmethhash.h"
#include "eetwain.h" // For EnumGCRefs (we should probably move that somewhere else, but can't
// find anything better (modulo common or vars.hpp)
#include "classloadlevel.h"
#include "precode.h"
#include "ilstubcache.h"
#include "classhash.h"
#include "corcompile.h"
#include <gcinfodecoder.h>
#include "wellknownattributes.h"
#ifdef FEATURE_READYTORUN
#include "readytoruninfo.h"
#endif
#include "ilinstrumentation.h"
#include "codeversion.h"
class MethodDesc;
class FieldDesc;
class Crst;
class RefClassWriter;
class ReflectionModule;
class EEStringData;
class MethodDescChunk;
class SigTypeContext;
class Assembly;
class AppDomain;
class SystemDomain;
class Module;
class SString;
class MethodTable;
class DynamicMethodTable;
class TieredCompilationManager;
class JITInlineTrackingMap;
#ifdef FEATURE_METADATA_UPDATER
class EnCEEClassData;
#endif // FEATURE_METADATA_UPDATER
// Hash table parameter of available classes (name -> module/class) hash
#define AVAILABLE_CLASSES_HASH_BUCKETS 1024
#define AVAILABLE_CLASSES_HASH_BUCKETS_COLLECTIBLE 128
#define PARAMTYPES_HASH_BUCKETS 23
#define PARAMMETHODS_HASH_BUCKETS 11
#define METHOD_STUBS_HASH_BUCKETS 11
#define GUID_TO_TYPE_HASH_BUCKETS 16
typedef DPTR(JITInlineTrackingMap) PTR_JITInlineTrackingMap;
//
// LookupMaps are used to implement RID maps
// It is a linked list of nodes, each handling a successive (and consecutive)
// range of RIDs.
//
// LookupMapBase is non-type safe implementation of the worker methods. LookupMap is type
// safe wrapper around it.
//
typedef DPTR(struct LookupMapBase) PTR_LookupMapBase;
struct DynamicMetadata
{
uint32_t Size;
BYTE Data[0];
friend struct ::cdac_data<DynamicMetadata>;
};
template<>
struct cdac_data<DynamicMetadata>
{
static constexpr size_t Size = offsetof(DynamicMetadata, Size);
static constexpr size_t Data = offsetof(DynamicMetadata, Data);
};
struct LookupMapBase
{
DPTR(LookupMapBase) pNext;
ArrayDPTR(TADDR) pTable;
// Number of elements in this node (only RIDs less than this value can be present in this node)
DWORD dwCount;
// Set of flags that the map supports writing on top of the data value
TADDR supportedFlags;
#ifdef DACCESS_COMPILE
void EnumMemoryRegions(CLRDataEnumMemoryFlags flags,
bool enumThis);
void ListEnumMemoryRegions(CLRDataEnumMemoryFlags flags);
#endif // DACCESS_COMPILE
PTR_TADDR GetIndexPtr(DWORD index)
{
LIMITED_METHOD_DAC_CONTRACT;
_ASSERTE(index < dwCount);
return dac_cast<PTR_TADDR>(pTable) + index;
}
PTR_TADDR GetElementPtr(DWORD rid);
PTR_TADDR GrowMap(ModuleBase * pModule, DWORD rid);
// Get number of RIDs that this table can store
DWORD GetSize();
#ifdef _DEBUG
void DebugGetRidMapOccupancy(DWORD *pdwOccupied, DWORD *pdwSize);
#endif
};
#define NO_MAP_FLAGS ((TADDR)0)
template <typename TYPE>
struct LookupMap : LookupMapBase
{
static TYPE GetValueAt(PTR_TADDR pValue, TADDR* pFlags, TADDR supportedFlags);
#ifndef DACCESS_COMPILE
static void SetValueAt(PTR_TADDR pValue, TYPE value, TADDR flags);
#endif // DACCESS_COMPILE
TYPE GetElement(DWORD rid, TADDR* pFlags);
void SetElement(DWORD rid, TYPE value, TADDR flags);
BOOL TrySetElement(DWORD rid, TYPE value, TADDR flags);
void AddElement(ModuleBase * pModule, DWORD rid, TYPE value, TADDR flags);
void EnsureElementCanBeStored(Module * pModule, DWORD rid);
DWORD Find(TYPE value, TADDR* flags);
public:
//
// Retrieve the value associated with a rid
//
TYPE GetElement(DWORD rid)
{
WRAPPER_NO_CONTRACT;
SUPPORTS_DAC;
return GetElement(rid, NULL);
}
TYPE GetElementAndFlags(DWORD rid, TADDR* pFlags)
{
WRAPPER_NO_CONTRACT;
SUPPORTS_DAC;
_ASSERTE(pFlags != NULL);
return GetElement(rid, pFlags);
}
//
// Stores an association in a map that has been previously grown to
// the required size. Will never throw or fail.
//
void SetElement(DWORD rid, TYPE value)
{
WRAPPER_NO_CONTRACT;
SUPPORTS_DAC;
SetElement(rid, value, 0);
}
void SetElementWithFlags(DWORD rid, TYPE value, TADDR flags)
{
WRAPPER_NO_CONTRACT;
SUPPORTS_DAC;
// Validate flags: that they are in the predefined range and that the range does not collide with value
_ASSERTE((flags & supportedFlags) == flags);
_ASSERTE((dac_cast<TADDR>(value) & supportedFlags) == 0);
SetElement(rid, value, flags);
}
#ifndef DACCESS_COMPILE
void AddFlag(DWORD rid, TADDR flag)
{
WRAPPER_NO_CONTRACT;
_ASSERTE((flag & supportedFlags) == flag);
PTR_TADDR pElement = GetElementPtr(rid);
_ASSERTE(pElement);
if (!pElement)
{
return;
}
TADDR existingFlags;
TYPE existingValue = GetValueAt(pElement, &existingFlags, supportedFlags);
SetValueAt(pElement, existingValue, existingFlags | flag);
}
#endif // DACCESS_COMPILE
//
// Try to store an association in a map. Will never throw or fail.
//
BOOL TrySetElement(DWORD rid, TYPE value)
{
WRAPPER_NO_CONTRACT;
return TrySetElement(rid, value, 0);
}
BOOL TrySetElementWithFlags(DWORD rid, TYPE value, TADDR flags)
{
WRAPPER_NO_CONTRACT;
// Validate flags: that they are in the predefined range and that the range does not collide with value
_ASSERTE((flags & supportedFlags) == flags);
_ASSERTE((dac_cast<TADDR>(value) & supportedFlags) == 0);
return TrySetElement(rid, value, flags);
}
//
// Stores an association in a map. Grows the map as necessary.
//
void AddElement(ModuleBase * pModule, DWORD rid, TYPE value)
{
WRAPPER_NO_CONTRACT;
AddElement(pModule, rid, value, 0);
}
void AddElementWithFlags(ModuleBase * pModule, DWORD rid, TYPE value, TADDR flags)
{
WRAPPER_NO_CONTRACT;
// Validate flags: that they are in the predefined range and that the range does not collide with value
_ASSERTE((flags & supportedFlags) == flags);
_ASSERTE((dac_cast<TADDR>(value) & supportedFlags) == 0);
AddElement(pModule, rid, value, flags);
}
//
// Find the given value in the table and return its RID
//
DWORD Find(TYPE value)
{
WRAPPER_NO_CONTRACT;
return Find(value, NULL);
}
DWORD FindWithFlags(TYPE value, TADDR flags)
{
WRAPPER_NO_CONTRACT;
// Validate flags: that they are in the predefined range and that the range does not collide with value
_ASSERTE((flags & supportedFlags) == flags);
_ASSERTE((dac_cast<TADDR>(value) & supportedFlags) == 0);
return Find(value, &flags);
}
class Iterator
{
public:
Iterator(LookupMap* map);
BOOL Next();
TYPE GetElement()
{
WRAPPER_NO_CONTRACT;
SUPPORTS_DAC;
return GetElement(NULL);
}
TYPE GetElementAndFlags(TADDR* pFlags)
{
WRAPPER_NO_CONTRACT;
SUPPORTS_DAC;
return GetElement(pFlags);
}
private:
TYPE GetElement(TADDR* pFlags);
LookupMap* m_map;
DWORD m_index;
};
};
// Place holder types for RID maps that store cross-module references
class TypeRef { };
typedef DPTR(class TypeRef) PTR_TypeRef;
class MemberRef { };
typedef DPTR(class MemberRef) PTR_MemberRef;
// flag used to mark member ref pointers to field descriptors in the member ref cache
#define IS_FIELD_MEMBER_REF ((TADDR)0x00000002)
//
// VASigCookies are allocated to encapsulate a varargs call signature.
// A reference to the cookie is embedded in the code stream. Cookies
// are shared amongst call sites with identical signatures in the same
// module
//
typedef DPTR(struct VASigCookie) PTR_VASigCookie;
typedef DPTR(PTR_VASigCookie) PTR_PTR_VASigCookie;
struct VASigCookie
{
// The JIT wants knows that the size of the arguments comes first
// so please keep this field first
unsigned sizeOfArgs; // size of argument list
Volatile<PCODE> pNDirectILStub; // will be use if target is NDirect (tag == 0)
PTR_Module pModule;
PTR_Module pLoaderModule;
Signature signature;
Instantiation classInst;
Instantiation methodInst;
};
//
// VASigCookies are allocated in VASigCookieBlocks to amortize
// allocation cost and allow proper bookkeeping.
//
struct VASigCookieBlock
{
enum {
#ifdef _DEBUG
kVASigCookieBlockSize = 2
#else // !_DEBUG
kVASigCookieBlockSize = 20
#endif // !_DEBUG
};
VASigCookieBlock *m_Next;
UINT m_numcookies;
VASigCookie m_cookies[kVASigCookieBlockSize];
};
//
// A Module is the primary unit of code packaging in the runtime. It
// corresponds mostly to an OS executable image, although other kinds
// of modules exist.
//
class UMEntryThunk;
// Hashtable of absolute addresses of IL blobs for dynamics, keyed by token
struct DynamicILBlobEntry
{
mdToken m_methodToken;
TADDR m_il;
};
class DynamicILBlobTraits : public NoRemoveSHashTraits<DefaultSHashTraits<DynamicILBlobEntry> >
{
public:
typedef mdToken key_t;
static key_t GetKey(element_t e)
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
return e.m_methodToken;
}
static BOOL Equals(key_t k1, key_t k2)
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
return k1 == k2;
}
static count_t Hash(key_t k)
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
return (count_t)(size_t)k;
}
static const element_t Null()
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
DynamicILBlobEntry e;
e.m_il = TADDR(0);
e.m_methodToken = 0;
return e;
}
static bool IsNull(const element_t &e)
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
return e.m_methodToken == 0;
}
};
typedef SHash<DynamicILBlobTraits> DynamicILBlobTable;
typedef DPTR(DynamicILBlobTable) PTR_DynamicILBlobTable;
#ifdef FEATURE_READYTORUN
typedef DPTR(class ReadyToRunInfo) PTR_ReadyToRunInfo;
#endif
// A ModuleBase represents the ability to reference code via tokens
// This abstraction exists to allow the R2R manifest metadata to have
// tokens which can be resolved at runtime.
class ModuleBase
{
#ifdef DACCESS_COMPILE
friend class ClrDataAccess;
friend class NativeImageDumper;
#endif
friend class DataImage;
VPTR_BASE_VTABLE_CLASS(ModuleBase)
protected:
// Linear mapping from TypeRef token to TypeHandle *
LookupMap<PTR_TypeRef> m_TypeRefToMethodTableMap;
// Mapping of AssemblyRef token to Module *
LookupMap<PTR_Module> m_ManifestModuleReferencesMap;
// mapping from MemberRef token to MethodDesc*, FieldDesc*
LookupMap<TADDR> m_MemberRefMap;
// For protecting additions to the heap
CrstExplicitInit m_LookupTableCrst;
PTR_LoaderAllocator m_loaderAllocator;
// The vtable needs to match between DAC and non-DAC, but we don't want any use of IsSigInIL in the DAC
virtual BOOL IsSigInILImpl(PCCOR_SIGNATURE signature) { return FALSE; } // ModuleBase doesn't have a PE image to examine
// The vtable needs to match between DAC and non-DAC, but we don't want any use of LoadAssembly in the DAC
virtual Assembly * LoadAssemblyImpl(mdAssemblyRef kAssemblyRef) = 0;
// The vtable needs to match between DAC and non-DAC, but we don't want any use of ThrowTypeLoadException in the DAC
virtual void DECLSPEC_NORETURN ThrowTypeLoadExceptionImpl(IMDInternalImport *pInternalImport,
mdToken token,
UINT resIDWhy)
#ifndef DACCESS_COMPILE
= 0;
#else
;
#endif
public:
ModuleBase() = default;
virtual LPCWSTR GetPathForErrorMessages();
CrstBase *GetLookupTableCrst()
{
LIMITED_METHOD_CONTRACT;
return &m_LookupTableCrst;
}
PTR_LoaderAllocator GetLoaderAllocator()
{
LIMITED_METHOD_DAC_CONTRACT;
return m_loaderAllocator;
}
FORCEINLINE TADDR LookupMemberRef(mdMemberRef token, BOOL *pfIsMethod)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(TypeFromToken(token) == mdtMemberRef);
TADDR flags;
TADDR pResult = m_MemberRefMap.GetElementAndFlags(RidFromToken(token), &flags);
*pfIsMethod = !(flags & IS_FIELD_MEMBER_REF);
return pResult;
}
#ifndef DACCESS_COMPILE
void StoreMemberRef(mdMemberRef token, FieldDesc *value)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(TypeFromToken(token) == mdtMemberRef);
m_MemberRefMap.AddElementWithFlags(this, RidFromToken(token), (TADDR)value, IS_FIELD_MEMBER_REF);
}
void StoreMemberRef(mdMemberRef token, MethodDesc *value)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(TypeFromToken(token) == mdtMemberRef);
m_MemberRefMap.AddElementWithFlags(this, RidFromToken(token), (TADDR)value, 0);
}
#endif // !DACCESS_COMPILE
TypeHandle LookupTypeRef(mdTypeRef token);
virtual IMDInternalImport *GetMDImport() const = 0;
virtual bool IsFullModule() const { return false; }
void StoreTypeRef(mdTypeRef token, TypeHandle value)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(TypeFromToken(token) == mdtTypeRef);
// The TypeRef cache is strictly a lookaside cache. If we get an OOM trying to grow the table,
// we cannot abort the load. (This will cause fatal errors during gc promotion.)
m_TypeRefToMethodTableMap.TrySetElement(RidFromToken(token),
dac_cast<PTR_TypeRef>(value.AsTAddr()));
}
virtual PTR_Module LookupModule(mdToken kFile) { return NULL; }; //wrapper over GetModuleIfLoaded, takes modulerefs as well
virtual Module *GetModuleIfLoaded(mdFile kFile) { return NULL; };
#ifndef DACCESS_COMPILE
virtual Module *LoadModule(mdFile kFile);
#endif
DWORD GetAssemblyRefFlags(mdAssemblyRef tkAssemblyRef);
Assembly *LookupAssemblyRef(mdAssemblyRef token);
// Module/Assembly traversal
virtual Assembly * GetAssemblyIfLoaded(
mdAssemblyRef kAssemblyRef,
IMDInternalImport * pMDImportOverride = NULL,
AssemblyBinder *pBinderForLoadedAssembly = NULL
)
{
LIMITED_METHOD_DAC_CONTRACT;
return NULL;
};
const ReadyToRun_EnclosingTypeMap *m_pEnclosingTypeMap = &ReadyToRun_EnclosingTypeMap::EmptyInstance;
#ifndef DACCESS_COMPILE
// The vtable needs to match between DAC and non-DAC, but we don't want any use of ThrowTypeLoadException in the DAC
void DECLSPEC_NORETURN ThrowTypeLoadException(IMDInternalImport *pInternalImport,
mdToken token,
UINT resIDWhy)
{
ThrowTypeLoadExceptionImpl(pInternalImport, token, resIDWhy);
}
// The vtable needs to match between DAC and non-DAC, but we don't want any use of IsSigInIL in the DAC
BOOL IsSigInIL(PCCOR_SIGNATURE signature) { return IsSigInILImpl(signature); }
Assembly * LoadAssembly(mdAssemblyRef kAssemblyRef)
{
WRAPPER_NO_CONTRACT;
return LoadAssemblyImpl(kAssemblyRef);
}
// Resolving
OBJECTHANDLE ResolveStringRef(DWORD Token, void** ppPinnedString = nullptr);
private:
// string helper
void InitializeStringData(DWORD token, EEStringData *pstrData, CQuickBytes *pqb);
#endif
};
// A code:Module represents a DLL or EXE file loaded from the disk. A module live in a code:Assembly
//
// Some important fields are
// * code:Module.m_pPEAssembly - this points at a code:PEAssembly that understands the layout of a PE assembly. The most
// important part is getting at the code:Module (see file:..\inc\corhdr.h#ManagedHeader) from there
// you can get at the Meta-data and IL)
// * code:Module.m_pAvailableClasses - this is a table that lets you look up the types (the code:EEClass)
// for all the types in the module
//
// See file:..\inc\corhdr.h#ManagedHeader for more on the layout of managed executable files.
class Module : public ModuleBase
{
#ifdef DACCESS_COMPILE
friend class ClrDataAccess;
friend class NativeImageDumper;
#endif
friend class DataImage;
VPTR_VTABLE_CLASS(Module, ModuleBase)
private:
PTR_CUTF8 m_pSimpleName; // Cached simple name for better performance and easier diagnostics
const WCHAR* m_path; // Cached path for easier diagnostics
const WCHAR* m_fileName; // Cached file name for easier diagnostics
PTR_PEAssembly m_pPEAssembly;
PTR_VOID m_baseAddress; // Cached base address for easier diagnostics
enum {
// These are the values set in m_dwTransientFlags.
MODULE_IS_TENURED = 0x00000001, // Set once we know for sure the Module will not be freed until the appdomain itself exits
// unused = 0x00000002,
CLASSES_FREED = 0x00000004,
IS_EDIT_AND_CONTINUE = 0x00000008, // is EnC Enabled for this module
IS_PROFILER_NOTIFIED = 0x00000010,
IS_ETW_NOTIFIED = 0x00000020,
IS_REFLECTION_EMIT = 0x00000040,
//
// Note: The values below must match the ones defined in
// cordbpriv.h for DebuggerAssemblyControlFlags when shifted
// right DEBUGGER_INFO_SHIFT bits.
//
DEBUGGER_USER_OVERRIDE_PRIV = 0x00000400,
DEBUGGER_ALLOW_JIT_OPTS_PRIV= 0x00000800,
DEBUGGER_TRACK_JIT_INFO_PRIV= 0x00001000,
DEBUGGER_ENC_ENABLED_PRIV = 0x00002000, // this is what was attempted to be set. IS_EDIT_AND_CONTINUE is actual result.
DEBUGGER_PDBS_COPIED = 0x00004000,
DEBUGGER_IGNORE_PDBS = 0x00008000,
DEBUGGER_INFO_MASK_PRIV = 0x0000Fc00,
DEBUGGER_INFO_SHIFT_PRIV = 10,
// Used to indicate that this module has had it's IJW fixups properly installed.
IS_IJW_FIXED_UP = 0x00080000,
IS_BEING_UNLOADED = 0x00100000,
};
static_assert_no_msg(DEBUGGER_USER_OVERRIDE_PRIV >> DEBUGGER_INFO_SHIFT_PRIV == DebuggerAssemblyControlFlags::DACF_USER_OVERRIDE);
static_assert_no_msg(DEBUGGER_ALLOW_JIT_OPTS_PRIV >> DEBUGGER_INFO_SHIFT_PRIV == DebuggerAssemblyControlFlags::DACF_ALLOW_JIT_OPTS);
static_assert_no_msg(DEBUGGER_TRACK_JIT_INFO_PRIV >> DEBUGGER_INFO_SHIFT_PRIV == DebuggerAssemblyControlFlags::DACF_OBSOLETE_TRACK_JIT_INFO);
static_assert_no_msg(DEBUGGER_ENC_ENABLED_PRIV >> DEBUGGER_INFO_SHIFT_PRIV == DebuggerAssemblyControlFlags::DACF_ENC_ENABLED);
static_assert_no_msg(DEBUGGER_PDBS_COPIED >> DEBUGGER_INFO_SHIFT_PRIV == DebuggerAssemblyControlFlags::DACF_PDBS_COPIED);
static_assert_no_msg(DEBUGGER_IGNORE_PDBS >> DEBUGGER_INFO_SHIFT_PRIV == DebuggerAssemblyControlFlags::DACF_IGNORE_PDBS);
enum {
// These are the values set in m_dwPersistedFlags.
// unused = 0x00000001,
COMPUTED_GLOBAL_CLASS = 0x00000002,
// unused = 0x00000004,
// unused = 0x00000008,
// This flag applies to assembly, but it is stored so it can be cached in ngen image
COMPUTED_WRAP_EXCEPTIONS = 0x00000010,
WRAP_EXCEPTIONS = 0x00000020,
// unused = 0x00000040,
// unused = 0x00000080,
//If attribute value has been cached before
DEFAULT_DLL_IMPORT_SEARCH_PATHS_IS_CACHED = 0x00000400,
//If module has default dll import search paths attribute
DEFAULT_DLL_IMPORT_SEARCH_PATHS_STATUS = 0x00000800,
//If setting has been cached
RUNTIME_MARSHALLING_ENABLED_IS_CACHED = 0x00008000,
//If runtime marshalling is enabled for this assembly
RUNTIME_MARSHALLING_ENABLED = 0x00010000,
};
Volatile<DWORD> m_dwTransientFlags;
Volatile<DWORD> m_dwPersistedFlags;
// Linked list of VASig cookie blocks: protected by m_pStubListCrst
VASigCookieBlock *m_pVASigCookieBlock;
PTR_Assembly m_pAssembly;
CrstExplicitInit m_Crst;
// Debugging symbols reader interface. This will only be
// initialized if needed, either by the debugging subsystem or for
// an exception.
ISymUnmanagedReader * m_pISymUnmanagedReader;
// The reader lock is used to serialize all creation of symbol readers.
// It does NOT seralize all access to the readers since we freely give
// out references to the reader outside this class. Instead, once a
// reader object is created, it is entirely read-only and so thread-safe.
CrstExplicitInit m_ISymUnmanagedReaderCrst;
// Storage for the in-memory symbol stream if any
// Debugger may retrieve this from out-of-process.
PTR_CGrowableStream m_pIStreamSym;
#define TYPE_DEF_MAP_ALL_FLAGS NO_MAP_FLAGS
#define TYPE_REF_MAP_ALL_FLAGS NO_MAP_FLAGS
// For type ref map, 0x1 cannot be used as a flag: reserved for FIXUP_POINTER_INDIRECTION bit
// For type ref map, 0x2 cannot be used as a flag: reserved for TypeHandle to signify TypeDesc
#define METHOD_DEF_MAP_ALL_FLAGS NO_MAP_FLAGS
#define FIELD_DEF_MAP_ALL_FLAGS NO_MAP_FLAGS
#define MEMBER_REF_MAP_ALL_FLAGS ((TADDR)0x00000003)
// For member ref hash table, 0x1 is reserved for IsHot bit
#define IS_FIELD_MEMBER_REF ((TADDR)0x00000002) // denotes that target is a FieldDesc
#define GENERIC_PARAM_MAP_ALL_FLAGS NO_MAP_FLAGS
#define MANIFEST_MODULE_MAP_ALL_FLAGS NO_MAP_FLAGS
// For manifest module map, 0x1 cannot be used as a flag: reserved for FIXUP_POINTER_INDIRECTION bit
// Linear mapping from TypeDef token to MethodTable *
// For generic types, IsGenericTypeDefinition() is true i.e. instantiation at formals
LookupMap<PTR_MethodTable> m_TypeDefToMethodTableMap;
// Linear mapping from MethodDef token to MethodDesc *
// For generic methods, IsGenericTypeDefinition() is true i.e. instantiation at formals
LookupMap<PTR_MethodDesc> m_MethodDefToDescMap;
// Linear mapping from MethodDef token to ILCodeVersioningState *
// This is used for Code Versioning logic
LookupMap<PTR_ILCodeVersioningState> m_ILCodeVersioningStateMap;
// Linear mapping from FieldDef token to FieldDesc*
LookupMap<PTR_FieldDesc> m_FieldDefToDescMap;
// Linear mapping from GenericParam token to TypeVarTypeDesc*
LookupMap<PTR_TypeVarTypeDesc> m_GenericParamToDescMap;
// IL stub cache with fabricated MethodTable parented by this module.
ILStubCache *m_pILStubCache;
ULONG m_DefaultDllImportSearchPathsAttributeValue;
public:
LookupMap<PTR_MethodTable>::Iterator EnumerateTypeDefs()
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
return LookupMap<PTR_MethodTable>::Iterator(&m_TypeDefToMethodTableMap);
}
// Hash of available types by name
PTR_EEClassHashTable m_pAvailableClasses;
// Hashtable of generic type instances
PTR_EETypeHashTable m_pAvailableParamTypes;
// For protecting additions to m_pInstMethodHashTable
CrstExplicitInit m_InstMethodHashTableCrst;
// Hashtable of instantiated methods and per-instantiation static methods
PTR_InstMethodHashTable m_pInstMethodHashTable;
// This is used by the Debugger. We need to store a dword
// for a count of JMC functions. This is a count, not a pointer.
// We'll pass the address of this field
// off to the jit, which will include it in probes injected for
// debuggable code.
// This means we need the dword at the time a function is jitted.
// The Debugger has its own module structure, but those aren't created
// if a debugger isn't attached.
// We put it here instead of in the debugger's module because:
// 1) we need a module structure that's around even when the debugger
// isn't attached... so we use the EE's module.
// 2) Needs to be here for ngen
DWORD m_dwDebuggerJMCProbeCount;
bool IsFullModule() const final { return true; }
// We can skip the JMC probes if we know that a module has no JMC stuff
// inside. So keep a strict count of all functions inside us.
bool HasAnyJMCFunctions();
void IncJMCFuncCount();
void DecJMCFuncCount();
// Get and set the default JMC status of this module.
bool GetJMCStatus();
void SetJMCStatus(bool fStatus);
// If this is a dynamic module, eagerly serialize the metadata so that it is available for DAC.
// This is a nop for non-dynamic modules.
void UpdateDynamicMetadataIfNeeded();
#ifdef _DEBUG
//
// We call these methods to seal/unseal the
// lists: m_pAvailableClasses and m_pAvailableParamTypes
//
// When they are sealed ClassLoader::PublishType cannot
// add new generic types or methods
//
void SealGenericTypesAndMethods();
void UnsealGenericTypesAndMethods();
#endif
private:
// Set the given bit on m_dwTransientFlags. Return true if we won the race to set the bit.
BOOL SetTransientFlagInterlocked(DWORD dwFlag);
// Cannoically-cased hashtable of the available class names for
// case insensitive lookup. Contains pointers into
// m_pAvailableClasses.
PTR_EEClassHashTable m_pAvailableClassesCaseIns;
public:
BOOL IsCollectible();
#ifdef FEATURE_READYTORUN
private:
PTR_ReadyToRunInfo m_pReadyToRunInfo;
PTR_NativeImage m_pNativeImage;
#endif
#if PROFILING_SUPPORTED_DATA
private:
DWORD m_dwTypeCount;
DWORD m_dwExportedTypeCount;
DWORD m_dwCustomAttributeCount;
#endif // PROFILING_SUPPORTED_DATA
protected:
void DoInit(AllocMemTracker *pamTracker, LPCWSTR szName);
protected:
#ifndef DACCESS_COMPILE
virtual void Initialize(AllocMemTracker *pamTracker, LPCWSTR szName = NULL);
#endif
void AllocateMaps();
#ifdef _DEBUG
void DebugLogRidMapOccupancy();
#endif // _DEBUG
public:
static Module *Create(Assembly *pAssembly, PEAssembly *pPEAssembly, AllocMemTracker *pamTracker);
protected:
Module(Assembly *pAssembly, PEAssembly *file);
public:
#ifndef DACCESS_COMPILE
virtual void Destruct();
#endif
PTR_PEAssembly GetPEAssembly() const { LIMITED_METHOD_DAC_CONTRACT; return m_pPEAssembly; }
void ApplyMetaData();
void FixupVTables();
void FreeClassTables();
#ifdef DACCESS_COMPILE
virtual void EnumMemoryRegions(CLRDataEnumMemoryFlags flags,
bool enumThis);
#endif // DACCESS_COMPILE
ReflectionModule *GetReflectionModule() const
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
_ASSERTE(IsReflectionEmit());
return dac_cast<PTR_ReflectionModule>(this);
}
PTR_Assembly GetAssembly() const;
MethodTable *GetGlobalMethodTable();
bool NeedsGlobalMethodTable();
DomainAssembly *GetDomainAssembly();
void SetDomainAssembly(DomainAssembly *pDomainAssembly);
OBJECTREF GetExposedObject();
OBJECTREF GetExposedObjectIfExists();
ClassLoader *GetClassLoader();
#ifdef FEATURE_CODE_VERSIONING
CodeVersionManager * GetCodeVersionManager();
#endif
BOOL IsReflectionEmit() const { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; return (m_dwTransientFlags & IS_REFLECTION_EMIT) != 0; }
BOOL IsSystem() { WRAPPER_NO_CONTRACT; SUPPORTS_DAC; return m_pPEAssembly->IsSystem(); }
// Returns true iff the debugger can see this module.
BOOL IsVisibleToDebugger();
virtual BOOL IsEditAndContinueCapable() const { return FALSE; }
BOOL IsEditAndContinueEnabled()
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
_ASSERTE((m_dwTransientFlags & IS_EDIT_AND_CONTINUE) == 0 || IsEditAndContinueCapable());
return (m_dwTransientFlags & IS_EDIT_AND_CONTINUE) != 0;
}
#ifdef FEATURE_METADATA_UPDATER
// Holds a table of EnCEEClassData object for classes in this module that have been modified
CUnorderedArray<EnCEEClassData*, 5> m_ClassList;
#endif // FEATURE_METADATA_UPDATER
private:
void EnableEditAndContinue()
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
_ASSERTE(IsEditAndContinueCapable());
LOG((LF_ENC, LL_INFO100, "M:EnableEditAndContinue: this:%p, %s\n", this, GetDebugName()));
m_dwTransientFlags |= IS_EDIT_AND_CONTINUE;
}
public:
BOOL IsTenured()
{
LIMITED_METHOD_CONTRACT;
return m_dwTransientFlags & MODULE_IS_TENURED;
}
#ifndef DACCESS_COMPILE
VOID SetIsTenured()
{
LIMITED_METHOD_CONTRACT;
InterlockedOr((LONG*)&m_dwTransientFlags, MODULE_IS_TENURED);
}
#endif // !DACCESS_COMPILE
#ifndef DACCESS_COMPILE
VOID EnsureActive();
#endif
CHECK CheckActivated();
HRESULT GetCustomAttribute(mdToken parentToken,
WellKnownAttribute attribute,
const void **ppData,
ULONG *pcbData)
{
if (IsReadyToRun())
{
if (!GetReadyToRunInfo()->MayHaveCustomAttribute(attribute, parentToken))
return S_FALSE;
}
return GetMDImport()->GetCustomAttributeByName(parentToken, GetWellKnownAttributeName(attribute), ppData, pcbData);
}
IMDInternalImport *GetMDImport() const final
{
WRAPPER_NO_CONTRACT;
SUPPORTS_DAC;
#ifdef DACCESS_COMPILE
if (IsReflectionEmit())
{
return DacGetMDImport(GetReflectionModule(), true);
}
#endif // DACCESS_COMPILE
return m_pPEAssembly->GetMDImport();
}
#ifndef DACCESS_COMPILE
IMetaDataEmit *GetEmitter()
{
WRAPPER_NO_CONTRACT;
return m_pPEAssembly->GetEmitter();
}
IMetaDataImport2 *GetRWImporter()
{
WRAPPER_NO_CONTRACT;
return m_pPEAssembly->GetRWImporter();
}
HRESULT GetReadablePublicMetaDataInterface(DWORD dwOpenFlags, REFIID riid, LPVOID * ppvInterface);
#endif // !DACCESS_COMPILE
#if defined(FEATURE_READYTORUN)