A
download ceeload.h
Language: C++
Copyright: (c) 2006 Microsoft Corporation. All rights reserved.
LOC: 1120
Project Info
Shared Source Common Language Infrastructure(sscli20)
Server: Shared Source Common Language Infrastructure
Type: filesystem
...sscli20\sscli20\clr\src\vm\
   appdomain.cpp
   appdomain.hpp
   appdomain.inl
   appdomainhelper.cpp
   appdomainhelper.h
   appdomainnative.cpp
   appdomainnative.hpp
   appdomainstack.cpp
   appdomainstack.h
   appdomainstack.inl
   argslot.h
   array.cpp
   array.h
   assembly.cpp
   assembly.hpp
   assemblyname.cpp
   assemblyname.hpp
   assemblynative.cpp
   assemblynative.hpp
   assemblysink.cpp
   assemblysink.h
   assemblyspec.cpp
   assemblyspec.hpp
   binder.cpp
   binder.h
   cachelinealloc.cpp
   cachelinealloc.h
   ceeload.cpp
   ceeload.h
   ceeload.inl
   ceemain.cpp
   ceemain.h
   certificatecache.cpp
   certificatecache.h
   cgensys.h
   class.cpp
   class.h
   class.inl
   classloadlevel.h
   classnames.h
   clrex.cpp
   clrex.h
   clsload.cpp
   clsload.hpp
   clsload.inl
   codeman.cpp
   codeman.h
   codeman.inl
   comarrayhelpers.cpp
   comarrayhelpers.h
   comarrayinfo.cpp
   comarrayinfo.h
   comcallablewrapper.cpp
   comcallablewrapper.h
   comcurrency.cpp
   comcurrency.h
   comdatetime.cpp
   comdatetime.h
   comdecimal.cpp
   comdecimal.h
   comdelegate.cpp
   comdelegate.h
   comdynamic.cpp
   comdynamic.h
   comisolatedstorage.cpp
   comisolatedstorage.h
   commemoryfailpoint.cpp
   commemoryfailpoint.h
   commethodrental.cpp
   commethodrental.h
   commodule.cpp
   commodule.h
   common.cpp
   common.h
   comnumber.cpp
   comnumber.h
   comobject.cpp
   comobject.h
   comreflectioncache.hpp
   comreflectioncommon.cpp
   comreflectioncommon.h
   comstreams.cpp
   comstreams.h
   comstring.cpp
   comstring.h
   comstringbuffer.cpp
   comstringbuffer.h
   comstringcommon.h
   comsynchronizable.cpp
   comsynchronizable.h
   comsystem.cpp
   comsystem.h
   comthreadpool.cpp
   comthreadpool.h
   comutilnative.cpp
   comutilnative.h
   comvarargs.cpp
   comvarargs.h
   comvariant.cpp
   comvariant.h
   comwaithandle.cpp
   comwaithandle.h
   confighelper.cpp
   confighelper.h
   ...inedexecutionregion.cpp
   ...rainedexecutionregion.h
   context.h
   contexts.cpp
   contractimpl.cpp
   contractimpl.h
   corhost.cpp
   crossdomaincalls.cpp
   crossdomaincalls.h
   crst.cpp
   crst.h
   cryptapis.h
   ctxtcall.h
   customattribute.cpp
   customattribute.h
   custommarshalerinfo.cpp
   custommarshalerinfo.h
   dbginterface.h
   debugdebugger.cpp
   debugdebugger.h
   debughelp.cpp
   debuginfostore.cpp
   debuginfostore.h
   decodemd.cpp
   decodemd.h
   delegateinfo.h
   dllimport.cpp
   dllimport.h
   dllimportcallback.cpp
   dllimportcallback.h
   domainfile.cpp
   domainfile.h
   domainfile.inl
   dynamicmethod.cpp
   dynamicmethod.h
   ecall.cpp
   ecall.h
   ecmakey.h
   eecallconv.h
   eeconfig.cpp
   eeconfig.h
   eeconfigfactory.cpp
   eeconfigfactory.h
   eecontract.cpp
   eecontract.h
   eecontract.inl
   eedbginterface.h
   eedbginterfaceimpl.cpp
   eedbginterfaceimpl.h
   eedbginterfaceimpl.inl
   eehash.cpp
   eehash.h
   eemessagebox.cpp
   eemessagebox.h
   eepolicy.cpp
   eepolicy.h
   eeprofinterfaces.h
   eeprofinterfaces.inl
   ...rofinterfacewrapper.inl
   eetwain.cpp
   encee.h
   eventstore.cpp
   eventstore.hpp
   excep.cpp
   excep.h
   exceptmacros.h
   exinfo.cpp
   exinfo.h
   exstate.cpp
   exstate.h
   exstatecommon.h
   fcall.cpp
   fcall.h
   field.cpp
   field.h
   fieldmarshaler.cpp
   fieldmarshaler.h
   fjit_eetwain.cpp
   fjit_eetwain.h
   fptrstubs.cpp
   fptrstubs.h
   frames.cpp
   frames.h
   fusionbind.cpp
   fusioninit.cpp
   fusionsink.cpp
   fusionwrap.cpp
   fusionwrap.h
   gc.h
   gccommon.cpp
   gcdecode.cpp
   gcdesc.h
   gcee.cpp
   gceesvr.cpp
   gceewks.cpp
   gchost.cpp
   gcimpl.h
   gcscan.cpp
   gcscan.h
   gcsmp.cpp
   gcsmppriv.h
   gcsvr.cpp
   gcwks.cpp
   genericdict.cpp
   genericdict.h
   generics.cpp
   generics.h
   genmeth.cpp
   gmheap.cpp
   gmheap.hpp
   gms.h
   h2inc.pl
   handletable.cpp
   handletable.h
   handletable.inl
   handletablecache.cpp
   handletablecore.cpp
   handletablepriv.h
   handletablescan.cpp
   hash.cpp
   hash.h
   hostexecutioncontext.cpp
   hostexecutioncontext.h
   hosting.cpp
   hosting.h
   ibclogger.h
   ildump.h
   ilmarshalers.cpp
   ilmarshalers.h
   ilstubcache.cpp
   ilstubcache.h
   ilstubresolver.cpp
   ilstubresolver.h
   instmethhash.cpp
   instmethhash.h
   interopconverter.cpp
   interopconverter.h
   interoputil.cpp
   interoputil.h
   ...lidoverlappedwrappers.h
   invokeutil.cpp
   invokeutil.h
   jithelpers.cpp
   jitinterface.cpp
   jitinterface.h
   jitinterfacegen.cpp
   list.cpp
   list.h
   listlock.cpp
   listlock.h
   listlock.inl
   makefile.inc
   managedmdimport.cpp
   managedmdimport.hpp
   marshaler.h
   marshalnative.cpp
   marshalnative.h
   mdaassistants.h
   mdaassistantsptr.h
   memberload.cpp
   memberload.h
   message.cpp
   message.h
   metasig.h
   method.cpp
   method.hpp
   method.inl
   methodimpl.cpp
   methodimpl.h
   methoditer.cpp
   methoditer.h
   methodtable.cpp
   methodtable.h
   methodtable.inl
   ml.cpp
   ml.h
   mlcache.cpp
   mlcache.h
   mlgen.cpp
   mlgen.h
   mlinfo.cpp
   mlinfo.h
   mlopdef.h
   mscorlib.h
   mtypes.h
   namespace.h
   nativeoverlapped.cpp
   nativeoverlapped.h
   newcompressedstack.cpp
   newcompressedstack.h
   nsenums.h
   object.cpp
   object.h
   object.inl
   objectclone.cpp
   objectclone.h
   objecthandle.cpp
   objecthandle.h
   objectlist.cpp
   objectlist.h
   olevariant.cpp
   olevariant.h
   pefile.cpp
   pefile.h
   pefile.inl
   peimage.cpp
   peimage.h
   peimage.inl
   peimagelayout.cpp
   peimagelayout.h
   peimagelayout.inl
   pendingload.cpp
   pendingload.h
   precode.cpp
   precode.h
   prestub.cpp
   proftoeeinterfaceimpl.cpp
   proftoeeinterfaceimpl.h
   reflectclasswriter.cpp
   reflectclasswriter.h
   reflectioninvocation.cpp
   reflectioninvocation.h
   remoting.cpp
   remoting.h
   rexcep.h
   runtimeexceptionkind.h
   runtimehandles.cpp
   runtimehandles.h
   rwlock.cpp
   rwlock.h
   safehandle.cpp
   security.h
   security.inl
   securityattributes.cpp
   securityattributes.h
   securityconfig.cpp
   securityconfig.h
   securitydeclarative.cpp
   securitydeclarative.h
   securitydescriptor.cpp
   securitydescriptor.h
   ...descriptorappdomain.cpp
   ...tydescriptorappdomain.h
   ...ydescriptorassembly.cpp
   ...itydescriptorassembly.h
   securityhostprotection.cpp
   securityhostprotection.h
   securityimperative.cpp
   securityimperative.h
   securitymeta.cpp
   securitymeta.h
   securitypolicy.cpp
   securitypolicy.h
   securitystackwalk.cpp
   securitystackwalk.h
   ...transparentassembly.cpp
   ...tytransparentassembly.h
   sigformat.cpp
   sigformat.h
   siginfo.cpp
   siginfo.hpp
   simplerwlock.cpp
   simplerwlock.hpp
   sourceline.cpp
   sourceline.h
   sources.dac
   sources.inc
   specialstatics.h
   spinlock.cpp
   spinlock.h
   stackbuildersink.cpp
   stackbuildersink.h
   stackcompressor.cpp
   stackcompressor.h
   stackingallocator.cpp
   stackingallocator.h
   stackprobe.h
   stackprobe.inl
   stackwalk.cpp
   stackwalk.h
   stackwalktypes.h
   stringliteralmap.cpp
   stringliteralmap.h
   strongname.cpp
   stubgen.h
   stublink.cpp
   stublink.h
   stublink.inl
   stubmgr.cpp
   stubmgr.h
   syncblk.cpp
   syncblk.h
   syncblk.inl
   syncclean.cpp
   syncclean.hpp
   synch.cpp
   synch.h
   ...zationcontextnative.cpp
   ...nizationcontextnative.h
   testhookmgr.cpp
   testhookmgr.h
   thekey.h
   threads.cpp
   threads.h
   threads.inl
   tokeniter.cpp
   tokeniter.hpp
   typectxt.cpp
   typectxt.h
   typedesc.cpp
   typedesc.h
   typedesc.inl
   typehandle.cpp
   typehandle.h
   typehandle.inl
   typehash.cpp
   typehash.h
   typekey.h
   typeparse.cpp
   typeparse.h
   typestring.cpp
   typestring.h
   umthunkhash.cpp
   umthunkhash.h
   util.cpp
   util.hpp
   validator.cpp
   vars.cpp
   vars.hpp
   verifier.cpp
   verifier.hpp
   veropcodes.hpp
   vertable.h
   virtualcallstub.cpp
   virtualcallstub.h
   vmholder.h
   win32threadpool.cpp
   win32threadpool.h
   wrappers.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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
// ==++==
//
//   
//    Copyright (c) 2006 Microsoft Corporation.  All rights reserved.
//   
//    The use and distribution terms for this software are contained in the file
//    named license.txt, which can be found in the root of this distribution.
//    By using this software in any fashion, you are agreeing to be bound by the
//    terms of this license.
//   
//    You must not remove this notice, or any other, from this software.
//   
//
// ==--==
// ===========================================================================
// File: CEELOAD.H
//
// CEELOAD.H defines the class use to represent the PE file
// ===========================================================================
#ifndef CEELOAD_H_
#define CEELOAD_H_

#include "common.h"
#include <fusion.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 "pefile.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"


class PELoader;
class Stub;
class MethodDesc;
class FieldDesc;
class Crst;
class AssemblySecurityDescriptor;
class ClassConverter;
class RefClassWriter;
class ReflectionModule;
class EEStringData;
class MethodDescChunk;
class SigTypeContext;
class Assembly;
class BaseDomain;
class AppDomain;
class CompilationDomain;
class DomainModule;
struct DomainLocalModule;
class SystemDomain;
class Module;
class SString;
class Pending;
class MethodTable;
class AppDomain;
class DynamicMethodTable;
struct CerPrepInfo;
class ModuleSecurityDescriptor;

// Used to help clean up interfaces
struct HelpForInterfaceCleanup
{
    void *pData;
    void (*pFunction)(void*);
};

//
// LookupMaps are used to implement RID maps
// It is a linked list of nodes, each handling a successive (and consecutive)
// range of RIDs.
//

typedef DPTR(struct LookupMap) PTR_LookupMap;

struct LookupMap
{
    // This is not actually a pointer to the beginning of the
    // allocated memory, but instead a pointer to &pTable[-MinIndex].
    // Thus, if we know that this LookupMap is the correct one, simply
    // index into it.
    PTR_TADDR           pTable;

    PTR_LookupMap       pNext;

    // Only RIDs less than this value can be present in this node (if they
    // are not handled by an earlier node).
    DWORD               dwMaxIndex;

    // Size of table to allocate for the next node that will be allocated at
    // the end of the list. This number is increased so that successive
    // nodes in the list are of increasingly bigger size
    // These all point to the same block size. Logically this belongs only to
    // the "head" of the list.
    DWORD              *pdwBlockSize;

    DWORD Find(TADDR pointer);

#ifdef DACCESS_COMPILE
    void EnumMemoryRegions(CLRDataEnumMemoryFlags flags,
                           DWORD minIndex,
                           bool enumThis);
    static void ListEnumMemoryRegions(CLRDataEnumMemoryFlags flags,
                                      LookupMap* headMap,
                                      bool enumHead);
#endif // DACCESS_COMPILE

    class Iterator
    {
    public:
        Iterator(LookupMap* map);

        BOOL Next();

        TADDR GetElement();
        DWORD GetIndex();
        LookupMap* GetMap();

    private:
        LookupMap* m_map;
        DWORD m_index;
    };

    enum {
        // flag used to mark back-pointers to the module (see below)
        // MUST NOT CLASH WITH IS_FIELD_MEMBER_REF = 0x00000001
        IS_MODULE_BACKPOINTER         = 0x00000002
    };

};

// TypeDefHandles and MethodDefHandles uniquely identify a TypeDef or
// MethodDef, essentially encoding a Module/Def pair in a
// pointer-sized value, *without* requiring the type or method to be
// loaded.
//
// They are represented by a pointer to the actual entry in the TypeDefToMethodTableMap or
// MethodDefToDescMap for a particular module.
//
// Functions are provided to convert back and forth between Module/Def pairs and DefHandles
//
// For types in ngen'ed modules, the Module is recovered using the
// range-tree For types in non-ngen'ed modules, the Module is
// recovered from the actual entry in the map, if loaded, or from a
// bit-twiddled back-pointer that is stored in the map when the handle
// is first requested but the type or method hasn't yet been loaded.
//
// (Dummy structs enforce strong typing here).
typedef struct TypeDefHandle_STRUCT_* TypeDefHandle;
typedef struct MethodDefHandle_STRUCT_* MethodDefHandle;

//
// 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;
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
    PTR_Stub        pNDirectMLStub;         // will be use if target is NDirect (tag == 0)
    PCCOR_SIGNATURE mdVASig;                // The debugger depends on this being here,
                                            // so please don't move it without changing
                                            // the GetVAInfo debugger routine.
    PTR_Module      pModule;
    VOID Destruct();
};

//
// 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];
};

// This lookup table persists the cctor specific information into the ngen'ed image
// which allows one to run the cctor without touching expensive EEClasses. Note
// that since the persisted info is stored at ngen time as opposed to class layout time,
// in jitted scenarios we would still touch EEClasses. This imples that the variables which store
// this info in the EEClasses are still present even when the prototype is ON.

typedef DPTR(struct ClassCtorInfoEntry) PTR_ClassCtorInfoEntry;
struct ClassCtorInfoEntry
{
    mdToken clTok;
    DWORD firstBoxedStaticOffset;
    DWORD firstBoxedStaticMTIndex;
    WORD numBoxedStatics;
    WORD CCtorSlot;
#ifdef _DEBUG
    PTR_MethodTable mt;
#endif
};



#define MODULE_CTOR_ELEMENTS 256
struct ModuleCtorInfo
{
    DWORD                   numElements;
    DWORD                   numLastAllocated;
    DWORD                   numElementsHot;
    DPTR(PTR_MethodTable)   ppMT;           // size is numElements
    PTR_ClassCtorInfoEntry  cctorInfoHot;   // size is numElementsHot
    PTR_ClassCtorInfoEntry  cctorInfoCold;  // size is numElements-numElementsHot

    PTR_DWORD               hotHashOffsets;  // Indices to the start of each "hash region" in the hot part of the ppMT array. 
    PTR_DWORD               coldHashOffsets; // Indices to the start of each "hash region" in the cold part of the ppMT array. 
    DWORD                   numHotHashes;
    DWORD                   numColdHashes;

    MethodTable **          ppHotGCStaticsMTs;            // hot table
    MethodTable **          ppColdGCStaticsMTs;           // cold table

    DWORD                   numHotGCStaticsMTs;
    DWORD                   numColdGCStaticsMTs;

#ifdef DACCESS_COMPILE
    void EnumMemoryRegions(CLRDataEnumMemoryFlags flags);
#endif

    typedef enum {HOT, COLD} REGION;
    FORCEINLINE DWORD ModuleCtorInfo::GenerateHash(PTR_MethodTable pMT, REGION region)
    {
        DWORD tmp1  = pMT->GetNumMethods();
        DWORD tmp2  = pMT->GetNumVirtuals();
        DWORD tmp3  = pMT->GetNumInterfaces();

        tmp1        = (tmp1 << 7) + (tmp1 << 0); // 10000001
        tmp2        = (tmp2 << 6) + (tmp2 << 1); // 01000010
        tmp3        = (tmp3 << 4) + (tmp3 << 3); // 00011000

        tmp1       ^= (tmp1 >> 4);               // 10001001 0001
        tmp2       ^= (tmp2 >> 4);               // 01000110 0010   
        tmp3       ^= (tmp3 >> 4);               // 00011001 1000

        DWORD hashVal = tmp1 + tmp2 + tmp3;

        if (region == HOT)
            hashVal     &= (numHotHashes - 1);   // numHotHashes is required to be a power of two
        else
            hashVal     &= (numColdHashes - 1);  // numColdHashes is required to be a power of two

        return hashVal;
    };

    MethodTable **      GetGCStaticMTs(DWORD index);

};





#ifdef _MSC_VER
// Disable warning: C4324: 'XXX' : structure was padded due to __declspec(align())
// This will let the compiler automatically pad for us, rather than us maintaining
// it manually.
#pragma warning (push)
#pragma warning (disable:4324)
#endif  // _MSC_VER

class ManagedToUnmanagedVTableThunk;
class ManagedToUnmanagedVTableThunkArray
{
public:
    ManagedToUnmanagedVTableThunkArray() : 
        m_rgbArrayBytes(NULL)
    {
    }
    
    void Create(size_t nElements);
    void Destroy();
    ManagedToUnmanagedVTableThunk* GetElement(size_t index);
    void Fixup(DataImage* image);

private:
    BYTE* m_rgbArrayBytes;
};

//
// 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;
 
struct ModuleEx
{
friend class Module;

private:
    // We disable warning C4324 which will allow the compiler to pad
    // this for us (rather than requiring the padding to be updated
    // manually).

    // This is a workaround to a problem with REL_32 fixups
    DECLSPEC_ALIGN(CODE_SIZE_ALIGN)
    BYTE _pad[CODE_SIZE_ALIGN];

    // This buffer is used to jump to the prestub in preloaded modules
    DECLSPEC_ALIGN(CODE_SIZE_ALIGN)
    BYTE                    m_PrestubJumpStub[BACK_TO_BACK_JUMP_ALLOCATE_SIZE];

#ifdef HAS_FIXUP_PRECODE
    // This buffer is used to jump to the precode fixup thunk in preloaded modules
    DECLSPEC_ALIGN(CODE_SIZE_ALIGN)
    BYTE                    m_PrecodeFixupJumpStub[BACK_TO_BACK_JUMP_ALLOCATE_SIZE];
#endif


    // This buffer is used to jump to vtable fixup stub
    DECLSPEC_ALIGN(CODE_SIZE_ALIGN)
    BYTE                    m_RestoreVTableJumpStub[BACK_TO_BACK_JUMP_ALLOCATE_SIZE];

    // This buffer is used to jump to the ndirect import stub in preloaded modules
    DECLSPEC_ALIGN(CODE_SIZE_ALIGN)
    BYTE                    m_NDirectImportJumpStub[BACK_TO_BACK_JUMP_ALLOCATE_SIZE];

};


class Module
{
#ifdef DACCESS_COMPILE
    friend class ClrDataAccess;
#endif

    friend class ZapMonitor;
    friend struct LookupMap;

    VPTR_BASE_CONCRETE_VTABLE_CLASS(Module)

 public:

#ifdef _DEBUG
    // Force verification even if it's turned off
    BOOL                    m_fForceVerify;

#endif // _DEBUG

private:

#ifdef _DEBUG
    DWORD               m_dwDebugArrayClassSize;
#endif

    PTR_PEFile               m_file;

    MethodDesc              *m_pDllMain;

    enum {
        // These are the values set in m_dwTransientFlags.
        // Note that none of these flags survive a prejit save/restore.

        MODULE_IS_TENURED           = 0x00000004,   // Set once we know for sure the Module will not be freed until the appdomain itself exits
        M_CER_ROOT_TABLE_ON_HEAP    = 0x00000010,   // Set when m_pCerNgenRootTable is allocated from heap (at ngen time)
        // UNUSED                   = 0x00000020,
        CLASSES_FREED               = 0x00000040,
        HAS_PHONY_IL_RVAS           = 0x00000080,
        IS_EDIT_AND_CONTINUE        = 0x00000200,   // is EnC Enabled for this module


        //
        // Note: the order of these must match the order defined in
        // cordbpriv.h for DebuggerAssemblyControlFlags. The three
        // values below should match the values defined in
        // 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             = 0x000080000,
     IS_BEING_UNLOADED        = 0x000100000
    };

    enum {
        // These are the values set in m_dwPersistedFlags.  These will survive
        // a prejit save/restore
        COMPUTED_GLOBAL_CLASS       = 0x00000001,
        COMPILED_DOMAIN_NEUTRAL     = 0x00000002
    };

    enum {
        // flag used to mark member ref pointers to field descriptors in the member ref cache
        IS_FIELD_MEMBER_REF         = 0x00000001,
    };

    DWORD                   m_dwTransientFlags;
    DWORD                   m_dwPersistedFlags;

    // Linked list of VASig cookie blocks: protected by m_pStubListCrst
    VASigCookieBlock        *m_pVASigCookieBlock;

    PTR_Assembly            m_pAssembly;
    mdFile                  m_moduleRef;

    CrstExplicitInit        m_Crst;
    CrstExplicitInit        m_FixupCrst;

    // Debugging symbols reader interface. This will only be
    // initialized if needed, either by the debugging subsystem or for
    // an exception.
    ISymUnmanagedReader     *m_pISymUnmanagedReader;
    Crst                    *m_pISymUnmanagedReaderLock;

    // Active dependencies
    ArrayList               m_activeDependencies;
    BitMask                 m_unconditionalDependencies;
    ULONG                  m_dwNumberOfActivations;
    // Class dependencies
    ArrayList               m_classDependencies;

    // Table of thunks for unmanaged vtables
    ManagedToUnmanagedVTableThunkArray  m_ThunkTable;

    // For protecting additions to the heap
    CrstExplicitInit        m_LookupTableCrst;

    // Linear mapping from TypeDef token to MethodTable *
    // For generic types, IsGenericTypeDefinition() is true i.e. instantiation at formals
    LookupMap               m_TypeDefToMethodTableMap;
    DWORD                   m_dwTypeDefMapBlockSize;

    // Linear mapping from TypeRef token to TypeHandle *
    LookupMap               m_TypeRefToMethodTableMap;
    DWORD                   m_dwTypeRefMapBlockSize;

    // Linear mapping from MethodDef token to MethodDesc *
    // For generic methods, IsGenericTypeDefinition() is true i.e. instantiation at formals
    LookupMap               m_MethodDefToDescMap;
    DWORD                   m_dwMethodDefMapBlockSize;

    // Linear mapping from FieldDef token to FieldDesc*
    LookupMap               m_FieldDefToDescMap;
    DWORD                   m_dwFieldDefMapBlockSize;

    // Linear mapping from MemberRef token to MethodDesc*, FieldDesc*
    LookupMap               m_MemberRefToDescMap;
    DWORD                   m_dwMemberRefMapBlockSize;

    // Mapping from File token to Module *
    LookupMap               m_FileReferencesMap;
    DWORD                   m_dwFileReferencesMapBlockSize;

    // Mapping of AssemblyRef token to Module *
    LookupMap               m_ManifestModuleReferencesMap;
    DWORD                   m_dwManifestModuleReferencesMapBlockSize;

public:
    // 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;

    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;

private:
    // Cannoically-cased hashtable of the available class names for
    // case insensitive lookup.  Contains pointers into
    // m_pAvailableClasses.
    PTR_EEClassHashTable     m_pAvailableClassesCaseIns;

    // Pointer to binder, if we have one
    friend class Binder;
    PTR_Binder               m_pBinder;





    // Module wide static fields information
    ModuleCtorInfo          m_ModuleCtorInfo;

#ifdef PROFILING_SUPPORTED_DATA
    LONG                    m_profilerNotified;
#endif



protected:

    void CreateDomainThunks();

protected:
    void DoInit(AllocMemTracker *pamTracker);

protected:
#ifndef DACCESS_COMPILE
    virtual void Initialize(AllocMemTracker *pamTracker);
#endif

    void AllocateMaps();

    // RID maps
    LookupMap *IncMapSize(LookupMap *pMap, DWORD rid);
    void AddToRidMap(LookupMap *pMap, DWORD rid, TADDR pDatum);
#ifndef DACCESS_COMPILE
    BOOL TryAddToRidMap(LookupMap *pMap, DWORD rid, TADDR pDatum);
    void SetInRidMap(LookupMap *pMap, DWORD rid, TADDR pDatum);
#endif // !DACCESS_COMPILE
    TADDR GetFromRidMap(LookupMap *pMap, DWORD rid);
    DWORD GetRidFromMapAddress(LookupMap *pMap, TADDR* addr);
    TADDR* RidToDefHandle(LookupMap *pMap, DWORD rid);

#ifdef _DEBUG
    void DebugGetRidMapOccupancy(LookupMap *pMap,
                                 DWORD *pdwOccupied, DWORD *pdwSize);
    void DebugLogRidMapOccupancy();
#endif // _DEBUG

    static HRESULT VerifyFile(PEFile *file, BOOL fZap);

 public:
    static Module *Create(Assembly *pAssembly, mdFile kFile, PEFile *pFile, AllocMemTracker *pamTracker);

 protected:
    Module(Assembly *pAssembly, mdFile moduleRef, PEFile *file);


 public:
#ifndef DACCESS_COMPILE
    virtual void Destruct();
#endif

    PTR_PEFile GetFile() { LEAF_CONTRACT; return m_file; }
    static size_t GetFileOffset() { LEAF_CONTRACT; return offsetof(Module, m_file); }

    BOOL IsManifest();


    void FreeClassTables();

#ifdef DACCESS_COMPILE
    virtual void EnumMemoryRegions(CLRDataEnumMemoryFlags flags,
                                   bool enumThis);
#endif // DACCESS_COMPILE

    ReflectionModule *GetReflectionModule()
    {
        LEAF_CONTRACT;

        _ASSERTE(IsReflection());
        return PTR_ReflectionModule(PTR_HOST_TO_TADDR(this));
    }

    Assembly* GetAssembly() const;

    int GetClassLoaderIndex()
    {
        LEAF_CONTRACT;

        return RidFromToken(m_moduleRef);
    }

    MethodTable *GetGlobalMethodTable();
    bool         NeedsGlobalMethodTable();

    // Only for non-manifest modules
    DomainModule *GetDomainModule(AppDomain *pDomain = NULL);
    DomainModule *FindDomainModule(AppDomain *pDomain);

    // This works for manifest modules too
    DomainFile *GetDomainFile(AppDomain *pDomain = NULL);
    DomainFile *FindDomainFile(AppDomain *pDomain);

    // Operates on assembly of module
    DomainAssembly *GetDomainAssembly(AppDomain *pDomain = NULL);
    DomainAssembly *FindDomainAssembly(AppDomain *pDomain);

    void SetDomainFile(DomainFile *pDomainFile);

    BOOL IsCompiledDomainNeutral() 
    { 
        LEAF_CONTRACT; 
        return (m_dwPersistedFlags & COMPILED_DOMAIN_NEUTRAL) != 0;
    }

    void SetCompiledDomainNeutral() 
    { 
        LEAF_CONTRACT; 
        m_dwPersistedFlags |= COMPILED_DOMAIN_NEUTRAL;
    }

    OBJECTREF GetExposedObject();

    ClassLoader *GetClassLoader();
    BaseDomain* GetDomain();
    AssemblySecurityDescriptor* GetSecurityDescriptor();

    mdFile GetModuleRef()
    {
        LEAF_CONTRACT;

        return m_moduleRef;
    }


    BOOL IsResource() { WRAPPER_CONTRACT; return GetFile()->IsResource(); }
    BOOL IsPEFile() { WRAPPER_CONTRACT; return !GetFile()->IsDynamic(); }
    BOOL IsReflection() { WRAPPER_CONTRACT; return GetFile()->IsDynamic(); }

    BOOL IsEditAndContinueEnabled() 
    { 
        LEAF_CONTRACT; 
        return (IsEditAndContinueCapable()) && ((m_dwTransientFlags & IS_EDIT_AND_CONTINUE) != 0); 
    }

    BOOL IsEditAndContinueCapable(); 
    
    BOOL IsIStream() { LEAF_CONTRACT; return GetFile()->IsIStream(); }

    BOOL IsSystem() { WRAPPER_CONTRACT; return m_file->IsSystem(); }

    static BOOL IsEditAndContinueCapable(PEFile *file) 
    { 
        WRAPPER_CONTRACT; 
        // Some modules are never EnC-capable
        return ! (file->IsSystem() || file->IsResource() || file->HasNativeImage() || file->IsDynamic());
    }

    void EnableEditAndContinue()
    {
        LEAF_CONTRACT;
        LOG((LF_ENC, LL_INFO100, "EnableEditAndContinue: this:0x%x, %s\n", this, GetDebugName()));
        m_dwTransientFlags |= IS_EDIT_AND_CONTINUE;
    }

    void DisableEditAndContinue()
    {
        LEAF_CONTRACT;
        LOG((LF_ENC, LL_INFO100, "DisableEditAndContinue: this:0x%x, %s\n", this, GetDebugName()));
        m_dwTransientFlags &= ~IS_EDIT_AND_CONTINUE;
    }

    // Does pDependentModule depend on "this"?
    BOOL IsDependencyOf(Module * pDependentModule)
    {
        WRAPPER_CONTRACT;
        // This is a watered-down implementation
        // Everything depends on mscorlib.dll and on self
        return (IsSystem() || this == pDependentModule);
    }


    BOOL IsTenured()
    {
        LEAF_CONTRACT;
        return m_dwTransientFlags & MODULE_IS_TENURED;
    }

#ifndef DACCESS_COMPILE
    VOID SetIsTenured()
    {
        LEAF_CONTRACT;
        FastInterlockOr(&m_dwTransientFlags, MODULE_IS_TENURED);
    }

    // CAUTION: This should only be used as backout code if an assembly is unsuccessfully
    //          added to the shared domain assembly map.
    VOID UnsetIsTenured()
    {
        LEAF_CONTRACT;
        FastInterlockAnd(&m_dwTransientFlags, ~MODULE_IS_TENURED);
    }
#endif // !DACCESS_COMPILE

    BOOL IsIntrospectionOnly();
    VOID EnsureActive();
    VOID EnsureAllocated();    
    VOID EnsureLibraryLoaded();
    CHECK CheckActivated();
    ULONG GetNumberOfActivations();
    ULONG IncrementNumberOfActivations();

    IMDInternalImport *GetMDImport() const
    {
        WRAPPER_CONTRACT;

        return m_file->GetPersistentMDImport();
    }

#ifndef DACCESS_COMPILE
    IMetaDataEmit *GetEmitter()
    {
        WRAPPER_CONTRACT;

        return m_file->GetEmitter();
    }

    IMetaDataImport *GetRWImporter()
    {
        WRAPPER_CONTRACT;

        return m_file->GetRWImporter();
    }

    IMetaDataAssemblyImport *GetAssemblyImporter()
    {
        WRAPPER_CONTRACT;

        return m_file->GetAssemblyImporter();
    }

    IMetaDataImport2 *GetRWImporter2()
    {
        WRAPPER_CONTRACT;

        return m_file->GetRWImporter2();
    }

#endif // !DACCESS_COMPILE


    void GetPathForErrorMessages(SString & result);


    ISymUnmanagedReader *GetISymUnmanagedReader(void);
    ISymUnmanagedReader *GetISymUnmanagedReaderNoThrow(void);
    HRESULT SetSymbolBytes(BYTE *pSyms, DWORD cbSyms);

    // Does the current configuration permit reading of symbols for this module?
    // Note that this may require calling into managed code (to resolve security policy).
    BOOL IsSymbolReadingEnabled(void);

    BOOL IsPersistedObject(void *address);


    // This is used by the debugger, in case the symbols aren't
    // available in an on-disk .pdb file (reflection emit,
    // Assembly.Load(byte[],byte[]), etc.
    CGrowableStream *m_pIStreamSym;
    CGrowableStream *GetInMemorySymbolStream()
    {
        LEAF_CONTRACT;

        return m_pIStreamSym;
    }

    void SetInMemorySymbolStream(CGrowableStream *pStream)
    {
        LEAF_CONTRACT;

        m_pIStreamSym = pStream;
    }

#ifndef DACCESS_COMPILE
    static HRESULT TrackIUnknownForDelete(IUnknown *pUnk,
                                          IUnknown ***pppUnk,
                                          HelpForInterfaceCleanup *pCleanHelp=NULL);
#endif // !DACCESS_COMPILE
    static void ReleaseAllIUnknowns(void);
    static void ReleaseIUnknown(IUnknown *pUnk);
    static void ReleaseIUnknown(IUnknown **pUnk);
    void ReleaseISymUnmanagedReader(void);
#ifndef DACCESS_COMPILE
    virtual void ReleaseILData();
#endif

    static void ReleaseMemoryForTracking();

    void FusionCopyPDBs(LPCWSTR moduleName);

    // This function will return PDB stream if exist.
    HRESULT GetHostPdbStream(IStream **ppStream);
    HRESULT ClearHostPdbStream(void);

    // Classes
    void AddClass(mdTypeDef classdef);
    void BuildClassForModule();
    EEClassHashTable *GetAvailableClassHash()
    {
        LEAF_CONTRACT;
        _ASSERTE(!IsResource());
        return m_pAvailableClasses;
    }
#ifndef DACCESS_COMPILE
    void SetAvailableClassHash(EEClassHashTable *pAvailableClasses)
    {
        LEAF_CONTRACT;
        _ASSERTE(!IsResource());
        m_pAvailableClasses = pAvailableClasses;
    }
#endif // !DACCESS_COMPILE
    EEClassHashTable *GetAvailableClassCaseInsHash()
    {
        LEAF_CONTRACT;
        _ASSERTE(!IsResource());
        return m_pAvailableClassesCaseIns;
    }
#ifndef DACCESS_COMPILE
    void SetAvailableClassCaseInsHash(EEClassHashTable *pAvailableClassesCaseIns)
    {
        LEAF_CONTRACT;
        _ASSERTE(!IsResource());
        m_pAvailableClassesCaseIns = pAvailableClassesCaseIns;
    }
#endif // !DACCESS_COMPILE

    // Constructed types tables
    EETypeHashTable *GetAvailableParamTypes()
    {
        LEAF_CONTRACT;
        _ASSERTE(!IsResource());
        return m_pAvailableParamTypes;
    }

    InstMethodHashTable *GetInstMethodHashTable()
    {
        LEAF_CONTRACT;
        _ASSERTE(!IsResource());
        return m_pInstMethodHashTable;
    }

    // Creates a new Method table for an array.  Used to make type handles
    // Note that if kind == SZARRAY or ARRAY, we get passed the GENERIC_ARRAY
    // needed to create the array.  That way we dont need to load classes during
    // the class load, which avoids the need for a 'being loaded' list
    MethodTable* CreateArrayMethodTable(TypeHandle elemType, CorElementType kind, unsigned rank, class AllocMemTracker *pamTracker);

    // This is called from CreateArrayMethodTable
    MethodTable* CreateGenericArrayMethodTable(TypeHandle elemType);

    // Generate a short sig for an array accessor
    VOID GenerateArrayAccessorCallSig(DWORD   dwRank,
                                      DWORD   dwFuncType, // Load, store, or <init>
                                      PCCOR_SIGNATURE *ppSig, // Generated signature
                                      DWORD * pcSig,      // Generated signature size
                                      class AllocMemTracker *pamTracker
    );

    // string helper
    void InitializeStringData(DWORD token, EEStringData *pstrData, CQuickBytes *pqb);

    // Resolving
    OBJECTHANDLE ResolveStringRef(DWORD Token, BaseDomain *pDomain, bool bNeedToSyncWithFixups);
    
    CHECK CheckStringRef(RVA rva);

    // Module/Assembly traversal
    Assembly *GetAssemblyIfLoaded(mdAssemblyRef kAssemblyRef);
    DomainAssembly *LoadAssembly(AppDomain *pDomain, mdAssemblyRef kAssemblyRef);
    Module *GetModuleIfLoaded(mdFile kFile, BOOL loadResources = TRUE);
    DomainFile *LoadModule(AppDomain *pDomain, mdFile kFile, BOOL loadResources = TRUE, BOOL bindOnly = FALSE);
#ifndef DACCESS_COMPILE
    Module *LookupModule(mdToken kFile, BOOL loadResources = TRUE); //wrapper over GetModuleIfLoaded, takes modulerefs as well
#endif

    // RID maps
    TypeHandle LookupTypeDef(mdTypeDef token, ClassLoadLevel level = CLASS_LOAD_UNRESTOREDTYPEKEY)
    {
        WRAPPER_CONTRACT;

        BAD_FORMAT_NOTHROW_ASSERT(TypeFromToken(token) == mdtTypeDef);

        g_IBCLogger.LogRidMapAccess( MakePair( this, token ) );
        PTR_MethodTable pMT = PTR_MethodTable(GetFromRidMap(&m_TypeDefToMethodTableMap, RidFromToken(token)));
        if (pMT == NULL || pMT->GetLoadLevel() < level)
            return TypeHandle();
        else
            return (TypeHandle)pMT;
    }


#ifndef DACCESS_COMPILE
    VOID EnsureTypeDefCanBeStored(mdTypeDef token)
    {
        WRAPPER_CONTRACT; // THROWS/GC_NOTRIGGER/INJECT_FAULT()/MODE_ANY
        if (!IncMapSize(&m_TypeDefToMethodTableMap, RidFromToken(token)))
        {
            COMPlusThrowOM();
        }
    }

    void EnsuredStoreTypeDef(mdTypeDef token, TypeHandle value)
    {
        WRAPPER_CONTRACT; // NOTHROW/GC_NOTRIGGER/FORBID_FAULT/MODE_ANY

        _ASSERTE(TypeFromToken(token) == mdtTypeDef);
        SetInRidMap(&m_TypeDefToMethodTableMap,
                    RidFromToken(token),
                    value.AsTAddr());
    }

#endif // !DACCESS_COMPILE

    DWORD GetTypeDefMax() { LEAF_CONTRACT; return m_TypeDefToMethodTableMap.dwMaxIndex; }

    TypeHandle LookupTypeRef(mdTypeRef token, ClassLoadLevel level = CLASS_LOAD_UNRESTOREDTYPEKEY);

#ifndef DACCESS_COMPILE
    void StoreTypeRef(mdTypeRef token, TypeHandle value)
    {
        WRAPPER_CONTRACT;

        _ASSERTE(TypeFromToken(token) == mdtTypeRef);

        g_IBCLogger.LogRidMapAccess( MakePair( this, token ) );

        // 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.)
        TryAddToRidMap(&m_TypeRefToMethodTableMap,
                    RidFromToken(token),
                    value.AsTAddr());
    }
#endif // !DACCESS_COMPILE

    // Turn a type or method def into a handle
    TypeDefHandle TypeDefToTypeDefHandle(mdTypeDef typeDef);
    MethodDefHandle MethodDefToMethodDefHandle(mdMethodDef methodDef);

    // Determine the module that this type/method def handle belongs to
    static Module* GetModuleForTypeDefHandle(TypeDefHandle handle);
    static Module* GetModuleForMethodDefHandle(MethodDefHandle handle);

    // Convert type or method def handles to defs
    mdTypeDef GetTypeDefForTypeDefHandle(TypeDefHandle handle);
    mdMethodDef GetMethodDefForMethodDefHandle(MethodDefHandle handle);

    DWORD GetTypeRefMax() { return m_TypeRefToMethodTableMap.dwMaxIndex; }

    MethodDesc *LookupMethodDef(mdMethodDef token);

#ifndef DACCESS_COMPILE
    void EnsureMethodDefCanBeStored(mdMethodDef token)
    {
        WRAPPER_CONTRACT; // THROWS/GC_NOTRIGGER/INJECT_FAULT()/MODE_ANY
        if (!IncMapSize(&m_MethodDefToDescMap, RidFromToken(token)))
        {
            COMPlusThrowOM();
        }
    }

    void EnsuredStoreMethodDef(mdMethodDef token, MethodDesc *value)
    {
        WRAPPER_CONTRACT; // NOTHROW/GC_NOTRIGGER/FORBID_FAULT/MODE_ANY

        _ASSERTE(TypeFromToken(token) == mdtMethodDef);
        SetInRidMap(&m_MethodDefToDescMap,
                    RidFromToken(token),
                    PTR_HOST_TO_TADDR(value));
    }

    mdMethodDef FindMethodDef(MethodDesc *value)
    {
        WRAPPER_CONTRACT;

        return m_MethodDefToDescMap.Find(PTR_HOST_TO_TADDR(value)) |
            mdtMethodDef;
    }
#endif // !DACCESS_COMPILE

    DWORD GetMethodDefMax() { return m_MethodDefToDescMap.dwMaxIndex; }

#ifndef DACCESS_COMPILE
    FieldDesc *LookupFieldDef(mdFieldDef token)
    {
        WRAPPER_CONTRACT;

        _ASSERTE(TypeFromToken(token) == mdtFieldDef);
        return PTR_FieldDesc(GetFromRidMap(&m_FieldDefToDescMap,
                                           RidFromToken(token)));
    }
#else
    FieldDesc *LookupFieldDef(mdFieldDef token);
#endif // DACCESS_COMPILE

#ifndef DACCESS_COMPILE
    void EnsureFieldDefCanBeStored(mdFieldDef token)
    {
        WRAPPER_CONTRACT; // THROWS/GC_NOTRIGGER/INJECT_FAULT()/MODE_ANY
        if (!IncMapSize(&m_FieldDefToDescMap, RidFromToken(token)))
        {
            COMPlusThrowOM();
        }
    }

    void EnsuredStoreFieldDef(mdFieldDef token, FieldDesc *value)
    {
        WRAPPER_CONTRACT; // NOTHROW/GC_NOTRIGGER/FORBID_FAULT/MODE_ANY

        _ASSERTE(TypeFromToken(token) == mdtFieldDef);
        SetInRidMap(&m_FieldDefToDescMap,
                    RidFromToken(token),
                    PTR_HOST_TO_TADDR(value));
    }

    mdFieldDef FindFieldDef(FieldDesc *value)
    {
        WRAPPER_CONTRACT;

        return m_FieldDefToDescMap.Find(PTR_HOST_TO_TADDR(value)) |
            mdtFieldDef;
    }
#endif // !DACCESS_COMPILE

    DWORD GetFieldDefMax() { LEAF_CONTRACT; return m_FieldDefToDescMap.dwMaxIndex; }

    void *LookupMemberRef(mdMemberRef token, BOOL *pfIsMethod)
    {
        WRAPPER_CONTRACT;

        _ASSERTE(TypeFromToken(token) == mdtMemberRef);
        TADDR pResult = GetFromRidMap(&m_MemberRefToDescMap,
                                      RidFromToken(token));
        g_IBCLogger.LogRidMapAccess( MakePair( this, token ) );
        *pfIsMethod = (pResult & IS_FIELD_MEMBER_REF) == 0;
        return (void*)(pResult & ~(TADDR)IS_FIELD_MEMBER_REF);
    }
    MethodDesc *LookupMemberRefAsMethod(mdMemberRef token);
#ifndef DACCESS_COMPILE
    void StoreMemberRef(mdMemberRef token, FieldDesc *value)
    {
        WRAPPER_CONTRACT;

        _ASSERTE(TypeFromToken(token) == mdtMemberRef);
        TryAddToRidMap(&m_MemberRefToDescMap,
                           RidFromToken(token),
                           (PTR_HOST_TO_TADDR(value) | IS_FIELD_MEMBER_REF));
    }
    void StoreMemberRef(mdMemberRef token, MethodDesc *value)
    {
        WRAPPER_CONTRACT;

        _ASSERTE(TypeFromToken(token) == mdtMemberRef);
        TryAddToRidMap(&m_MemberRefToDescMap,
                           RidFromToken(token),
                           PTR_HOST_TO_TADDR(value));
    }
    mdMemberRef FindMemberRef(MethodDesc *value)
    {
        WRAPPER_CONTRACT;

        return m_MemberRefToDescMap.Find(PTR_HOST_TO_TADDR(value)) | mdtMemberRef;
    }
    mdMemberRef FindMemberRef(FieldDesc *value)
    {
        WRAPPER_CONTRACT;

        return m_MemberRefToDescMap.Find(PTR_HOST_TO_TADDR(value)) | mdtMemberRef;
    }
#endif // !DACCESS_COMPILE
    DWORD GetMemberRefMax() { LEAF_CONTRACT; return m_MemberRefToDescMap.dwMaxIndex; }

    Module *LookupFile(mdFile token)
    {
        WRAPPER_CONTRACT;

        _ASSERTE(TypeFromToken(token) == mdtFile);
        return PTR_Module(GetFromRidMap(&m_FileReferencesMap,
                                        RidFromToken(token)));
    }


#ifndef DACCESS_COMPILE
    void EnsureFileCanBeStored(mdFile token)
    {
        WRAPPER_CONTRACT; // THROWS/GC_NOTRIGGER/INJECT_FAULT()/MODE_ANY

        _ASSERTE(TypeFromToken(token) == mdtFile);
        if (!IncMapSize(&m_FileReferencesMap, RidFromToken(token)))
        {
            COMPlusThrowOM();
        }
    }

    void EnsuredStoreFile(mdFile token, Module *value)
    {
        WRAPPER_CONTRACT; // NOTHROW/GC_NOTRIGGER/FORBID_FAULT


        _ASSERTE(TypeFromToken(token) == mdtFile);
        SetInRidMap(&m_FileReferencesMap,
                    RidFromToken(token),
                    PTR_HOST_TO_TADDR(value));
    }


    void StoreFileThrowing(mdFile token, Module *value)
    {
        WRAPPER_CONTRACT;


        _ASSERTE(TypeFromToken(token) == mdtFile);
        AddToRidMap(&m_FileReferencesMap,
                    RidFromToken(token),
                    PTR_HOST_TO_TADDR(value));
    }

    BOOL StoreFileNoThrow(mdFile token, Module *value)
    {
        WRAPPER_CONTRACT;

        _ASSERTE(TypeFromToken(token) == mdtFile);
        return TryAddToRidMap(&m_FileReferencesMap,
                              RidFromToken(token),
                              PTR_HOST_TO_TADDR(value));
    }

    mdFile FindFile(Module *value)
    {
        WRAPPER_CONTRACT;

        return m_FileReferencesMap.Find(PTR_HOST_TO_TADDR(value)) | mdtFile;
    }
#endif // !DACCESS_COMPILE

    DWORD GetFileMax() {LEAF_CONTRACT;  return m_FileReferencesMap.dwMaxIndex; }

    Assembly *LookupAssemblyRef(mdAssemblyRef token);

#ifndef DACCESS_COMPILE
    void ForceStoreAssemblyRef(mdAssemblyRef token, Assembly *value);
    void StoreAssemblyRef(mdAssemblyRef token, Assembly *value);
    mdAssemblyRef FindAssemblyRef(Assembly *value);
#endif // !DACCESS_COMPILE

    DWORD GetAssemblyRefMax() {LEAF_CONTRACT;  return m_ManifestModuleReferencesMap.dwMaxIndex; }

    MethodDesc *FindMethodThrowing(mdToken pMethod);
    MethodDesc *FindMethod(mdToken pMethod);

#ifdef DEBUGGING_SUPPORTED
    // Debugger stuff
    BOOL NotifyDebuggerLoad(AppDomain *pDomain, int level, BOOL attaching);
    void NotifyDebuggerUnload(AppDomain *pDomain);

    DebuggerAssemblyControlFlags GetDebuggerInfoBits(void)
    {
        LEAF_CONTRACT;

        return (DebuggerAssemblyControlFlags)((m_dwTransientFlags &
                                               DEBUGGER_INFO_MASK_PRIV) >>
                                              DEBUGGER_INFO_SHIFT_PRIV);
    }

    void SetDebuggerInfoBits(DebuggerAssemblyControlFlags newBits);
#endif // DEBUGGING_SUPPORTED

#ifdef PROFILING_SUPPORTED
    BOOL IsProfilerNotified() {LEAF_CONTRACT;  return m_profilerNotified; }
    void NotifyProfilerLoadFinished(HRESULT hr);
#endif // PROFILING_SUPPORTED

    // Get any cached ITypeLib* for the module.
    ITypeLib *GetTypeLib();
    // Cache the ITypeLib*, if one is not already cached.
    void SetTypeLib(ITypeLib *pITLB);
    ITypeLib *GetTypeLibTCE();
    void SetTypeLibTCE(ITypeLib *pITLB);

    // Enregisters a VASig. Returns NULL for failure (out of memory.)
    VASigCookie *GetVASigCookie(PCCOR_SIGNATURE pVASig);

    // DLL entry point
    MethodDesc *GetDllEntryPoint()
    {
        LEAF_CONTRACT;
        return m_pDllMain;
    }
    void SetDllEntryPoint(MethodDesc *pMD)
    {
        LEAF_CONTRACT;
        m_pDllMain = pMD;
    }

    BOOL CanExecuteCode();


    // This data is only valid for NGEN'd modules, and for modules we're creating at NGEN time.
    ModuleCtorInfo* GetZapModuleCtorInfo()
    {
        LEAF_CONTRACT;
        
        return &m_ModuleCtorInfo;
    }

 private:


 public:
    ULONG HashIdentity() { WRAPPER_CONTRACT; return m_file->HashIdentity(); }
#ifndef DACCESS_COMPILE
    BOOL Equals(Module *pModule) { WRAPPER_CONTRACT; return m_file->Equals(pModule->m_file); }
    BOOL Equals(PEFile *pFile) { WRAPPER_CONTRACT; return m_file->Equals(pFile); }
#endif // !DACCESS_COMPILE

    LPCUTF8 GetSimpleName()  { WRAPPER_CONTRACT; return m_file->GetSimpleName(); }
    const SString &GetPath() { WRAPPER_CONTRACT; return m_file->GetPath(); }

#ifdef LOGGING
    LPCWSTR GetDebugName() { WRAPPER_CONTRACT; return m_file->GetDebugName(); }
#endif

    BOOL IsILOnly() { WRAPPER_CONTRACT; return m_file->IsILOnly(); }
    BOOL HasNativeImage() { WRAPPER_CONTRACT; return m_file->HasNativeImage(); }
    
    PEImageLayout *GetNativeImage()
    {
        CONTRACT(PEImageLayout *)
        {
            PRECONDITION(m_file->HasNativeImage());
            POSTCONDITION(CheckPointer(RETVAL));
            NOTHROW;
            GC_NOTRIGGER;
        }
        CONTRACT_END;

        RETURN m_file->GetLoadedNative();
    }

    // These are overridden by reflection modules
    virtual const void *GetIL(RVA il);
    virtual void *GetRvaField(RVA field);

    CHECK CheckIL(RVA il, COUNT_T size);
    CHECK CheckIL(RVA il);
    CHECK CheckRvaField(RVA field);
    CHECK CheckRvaField(RVA field, COUNT_T size);

    BYTE *GetPhonyILBase();
    RVA GetPhonyILRva(BYTE *il);

    const void *GetInternalPInvokeTarget(RVA target)
    { WRAPPER_CONTRACT; return m_file->GetInternalPInvokeTarget(target); }

    BOOL HasTls();
    BOOL IsRvaFieldTls(DWORD field);
    UINT32 GetFieldTlsOffset(DWORD field);
    UINT32 GetTlsIndex();

    PCCOR_SIGNATURE GetSignature(RVA signature);
    RVA GetSignatureRva(PCCOR_SIGNATURE signature);
    CHECK CheckSignatureRva(RVA signature);
    CHECK CheckSignature(PCCOR_SIGNATURE signature);

    mdToken GetEntryPointToken();

    BYTE *GetProfilerBase();


    // Active transition path management
    // 
    // This list keeps track of module which we have active transition
    // paths to.  An active transition path is where we move from
    // active execution in one module to another module without
    // involving triggering the file loader to ensure that the
    // destination module is active.  We must explicitly list these
    // relationships so the the loader can ensure that the activation
    // constraints are a priori satisfied.
    //
    // Conditional vs. Unconditional describes how we deal with
    // activation failure of a dependency.  In the unconditional case,
    // we propagate the activation failure to the depending module.
    // In the conditional case, we activate a "trigger" in the active
    // transition path which will cause the path to fail in particular
    // app domains where the destination module failed to activate.
    // (This trigger in the path typically has a perf cost even in the
    // nonfailing case.)
    //
    // In either case we must try to perform the activation eagerly -
    // even in the conditional case we have to know whether to turn on
    // the trigger or not before we let the active transition path
    // execute.

    BOOL AddActiveDependency(Module *pModule, BOOL unconditional);

    // Active dependency iterator
    class DependencyIterator
    {
      protected:
        ArrayList::Iterator m_i;
        COUNT_T             m_index;
        BitMask             *m_unconditionalFlags;

        friend class Module;

        DependencyIterator(ArrayList *list, BitMask *unconditionalFlags)
          : m_index((COUNT_T)-1),
            m_unconditionalFlags(unconditionalFlags)
        {
            m_i = list->Iterate();
        }

      public:
        Module *GetDependency()
        {
            return (Module *) m_i.GetElement();
        }

        BOOL Next()
        {
            while (m_i.Next())
            {
                ++m_index;

                // When iterating all dependencies, we do not restore any tokens
                // as we want to be lazy.
                if (!CORCOMPILE_IS_TOKEN_TAGGED(m_i.GetElement()))
                    return TRUE;
            }
            return FALSE;
        }
        BOOL IsUnconditional()
        {
            if (m_unconditionalFlags == NULL)
                return TRUE;
            else
                return m_unconditionalFlags->TestBit(m_index);
        }
    };

    DependencyIterator IterateActiveDependencies()
    {
        return DependencyIterator(&m_activeDependencies, &m_unconditionalDependencies);
    }

    BOOL HasActiveDependency(Module *pModule);
    BOOL HasUnconditionalActiveDependency(Module *pModule);

    // Class dependencies are rolled up inheritence dependencies of individual
    // classes in the module.  The list is shared across all classes to save space.
    // Each class has a BitMask indicating which entries in the shared dependencies list 
    // apply to it.

    BOOL AddClassDependency(Module *pModule, BitMask *classMask);

    class DependencySetIterator : public DependencyIterator
    {
      protected:
        BitMask           *m_mask;

        friend class Module;
        DependencySetIterator(ArrayList *list, BitMask *mask)
          : DependencyIterator(list, NULL),
            m_mask(mask)
        {
        }

      public:
        BOOL Next()
        {
            while (m_i.Next())
            {
                COUNT_T index = ++m_index;

                if (m_mask->TestBit(index))
                {
                    // When asking for specific dependencies, we will go ahead
                    // and restore them.

                    
                    return TRUE;
                }
            }
            return FALSE;
        }
    };

    DependencySetIterator IterateClassDependencies(BitMask *classMask)
    {
        return DependencySetIterator(&m_classDependencies, classMask);
    }

    // Turn triggers from this module into runtime checks
    void EnableModuleFailureTriggers(Module *pModule, AppDomain *pDomain);


    BOOL IsBeingUnloaded() { return m_dwTransientFlags & IS_BEING_UNLOADED; }
    void   SetBeingUnloaded();
    void   StartUnload();
    

public:
    void LogInstantiatedType(TypeHandle typeHnd, ULONG flagNum);
    void LogInstantiatedMethod( MethodDesc * md );

private:
    // First entry contains the size of the table.
    PTR_SIZE_T   m_rgDispatchTypeTable;

    SIZE_T GetDispatchTypeTableEntryCount()
    {
        if (m_rgDispatchTypeTable != NULL)
            return m_rgDispatchTypeTable[0];
        else
            return 0;
    }

public:
    UINT32 MapZapTypeID(UINT32 typeID);

public:
    // This helper returns to offsets for the slots/bytes/handles. They return the offset in bytes from the beggining
    // of the 1st GC pointer in the statics block for the module.
    void        GetOffsetsForStaticData(
                    mdTypeDef cl,
                    BOOL bDynamic,
                    DWORD dwGCStaticHandles,
                    DWORD dwNonGCStaticBytes,
                    DWORD * pOutStaticHandleOffset,
                    DWORD * pOutNonGCStaticOffset);
public:

    CrstBase*           GetFixupCrst()
    {
        return &m_FixupCrst;
    }

    void                AllocateStaticHandles(AppDomain* pDomainMT);

    DWORD               GetStaticsAndClassInitBlockSize()
    {
        return m_dwStaticsBlockSize;
    }

    DWORD               AllocateDynamicEntry(MethodTable *pMT);

    // We need this for the jitted shared case,
    inline MethodTable* GetDynamicClassMT(DWORD dynamicClassID)
    {
        LEAF_CONTRACT;
        _ASSERTE(m_cDynamicEntries > dynamicClassID);
        return m_pDynamicStaticsInfo[dynamicClassID].pEnclosingMT;
    }

    SIZE_T               GetModuleID()
    {
        LEAF_CONTRACT;
        return PTR_TO_TADDR(m_pDomainLocalModule);
    }

    SIZE_T *             GetAddrModuleID()
    {
        LEAF_CONTRACT;
        return (SIZE_T*) &m_pDomainLocalModule;
    }

    PTR_DomainLocalModule   GetDomainLocalModule(AppDomain *pDomain = NULL);


    BOOL IsFCallMapActive()
    {
        return FALSE;
    }

protected:
    void            BuildStaticsOffsets     ();
    void            AllocateStatics         (AllocMemTracker *pamTracker);

public:
    void            EnumStaticGCRefs        (AppDomain* pAppDomain, GCEnumCallback  pCallback, LPVOID hCallBack);

protected:    

    // Will return underlying type if it's an enum
    //             ELEMENT_TYPE_VALUETYPE if it is a non enum
    //             ELEMENT_TYPE_END if it doesn't know (we may not want to load other assemblies)
    CorElementType  ParseMetadataForStaticsIsTypeDefEnum(mdToken tk, const SigTypeContext* pContext);
    CorElementType  ParseMetadataForStaticsIsValueTypeEnum(mdToken tk, const SigTypeContext* pContext);
    void            ParseMetadataForStatics(DWORD* pdwNumTypes, DWORD* pdwNonGCStaticBytes, DWORD* pdwGCStaticHandles);

    PTR_DomainLocalModule   m_pDomainLocalModule;       // MultiDomain case: tagged (low bit 1) DLS index
                                                        // SingleDomain case: domain local module

    // reusing the statics area of a method table to store
    // these for the non domain neutral case, but they're now unified
    // it so that we don't have different code paths for this.
    PTR_DWORD               m_pStaticOffsets;               // Offset of statics in each class

    // @NICE: see if we can remove these fields
    DWORD                   m_dwMaxGCStaticHandles;         // Max number of handles we can have.

    // Size of the precomputed statics block. This includes class init bytes, gc handles and non gc statics
    DWORD                   m_dwStaticsBlockSize;


    // For 'dynamic' statics (Reflection and generics)
protected:
    SIZE_T                  m_cDynamicEntries;              // Number of used entries in DynamicStaticsInfo table
    SIZE_T                  m_maxDynamicEntries;            // Size of table itself, including unused entries

    // Info we need for dynamic statics that we can store per-module (ie, no need for it to be duplicated
    // per appdomain)
    struct DynamicStaticsInfo
    {
        MethodTable*        pEnclosingMT;                   // Enclosing type; necessarily in this loader module
    };
    DynamicStaticsInfo*     m_pDynamicStaticsInfo;          // Table with entry for each dynamic ID

public:
    BOOL                    IsNoStringInterning();



protected:
    void                    GenerateAllCompilationRelaxationFlags();
    DWORD                   m_dwCompilationRelaxationFlags; // We cache these so that we don't have
                                                            // to pull in a custom attribute;



#ifndef DACCESS_COMPILE
public:

    // Support for getting and creating information about Constrained Execution Regions rooted in this module.

    // Access to CerPrepInfo, the structure used to track CERs prepared at runtime (as opposed to ngen time). GetCerPrepInfo will
    // return the structure associated with the given method desc if it exists or NULL otherwise. CreateCerPrepInfo will get the
    // structure if it exists or allocate and return a new struct otherwise. Creation of CerPrepInfo structures is automatically
    // synchronized by the CerCrst (lazily allocated as needed).
    CerPrepInfo *GetCerPrepInfo(MethodDesc *pMD);
    CerPrepInfo *CreateCerPrepInfo(MethodDesc *pMD);


    Crst *GetCerCrst()
    {
        LEAF_CONTRACT;
        return m_pCerCrst;
    }

    BOOL GetRVAOverrideForMethod(MethodDesc* pMD, DWORD* pdwOverride);
    void SetRVAOverrideForMethod(MethodDesc* pMD, DWORD dwOverride);
#endif // !DACCESS_COMPILE

private:
    EEPtrHashTable       *m_pCerPrepInfo;       // Root methods prepared for Constrained Execution Regions
    Crst                 *m_pCerCrst;           // Mutex protecting update access to both of the above hashes

    EEPtrHashTable       *m_pRVAOverrides;      // Overriden 
    Crst                 *m_pRVAOverridesCrst;  // Mutex protecting update access to both of the above hashes

public:
    // Support for per-module remoting thunks used to dispatch interface calls on transparent proxies in some edge cases.

    EEPtrHashTable       *m_pRemotingInterfaceThunks;       // Hash map of method descs to stub entry points
    Crst                 *m_pRemotingInterfaceThunksCrst;   // Mutex protecting access to the above         

    ModuleSecurityDescriptor* m_pModuleSecurityDescriptor;
    
};



#ifdef _MSC_VER
#pragma warning (pop)
#endif


//
// A ReflectionModule is a module created by reflection
//

// {F5398690-98FE-11d2-9C56-00A0C9B7CC45}
extern "C" const GUID IID_ICorReflectionModule;

class ReflectionModule : public Module
{
    VPTR_VTABLE_CLASS(ReflectionModule, Module)

 public:
    HCEESECTION m_sdataSection;
 protected:
    ICeeGen *m_pCeeFileGen;
private:
    Assembly             *m_pCreatingAssembly;
    ISymUnmanagedWriter **m_ppISymUnmanagedWriter;
    RefClassWriter       *m_pInMemoryWriter;

    ReflectionModule(Assembly *pAssembly, mdFile token, PEFile *pFile);

public:

    static ReflectionModule *Create(Assembly *pAssembly, PEFile *pFile, AllocMemTracker *pamTracker);

    void Initialize(AllocMemTracker *pamTracker);

    void Destruct();
#ifndef DACCESS_COMPILE    
    void ReleaseILData();
#endif

    // Overides functions to access sections
    virtual const void *GetIL(RVA target);
    virtual void *GetRvaField(RVA rva);

    Assembly* GetCreatingAssembly( void )
    {
        LEAF_CONTRACT;

        return m_pCreatingAssembly;
    }

    void SetCreatingAssembly( Assembly* assembly )
    {
        LEAF_CONTRACT;

        m_pCreatingAssembly = assembly;
    }

    ICeeGen *GetCeeGen() {LEAF_CONTRACT;  return m_pCeeFileGen; }

    RefClassWriter *GetClassWriter()
    {
        LEAF_CONTRACT;

        return m_pInMemoryWriter;
    }

    ISymUnmanagedWriter *GetISymUnmanagedWriter()
    {
        LEAF_CONTRACT;

        // If we haven't set up room for a writer, then we certinally
        // haven't set one, so just return NULL.
        if (m_ppISymUnmanagedWriter == NULL)
            return NULL;
        else
            return *m_ppISymUnmanagedWriter;
    }

    ISymUnmanagedWriter **GetISymUnmanagedWriterAddr()
    {
        LEAF_CONTRACT;

        // We must have setup room for the writer before trying to get
        // the address for it. Any calls to this before a
        // SetISymUnmanagedWriter are very incorrect.
        _ASSERTE(m_ppISymUnmanagedWriter != NULL);

        return m_ppISymUnmanagedWriter;
    }

#ifndef DACCESS_COMPILE
    HRESULT SetISymUnmanagedWriter(ISymUnmanagedWriter *pWriter, HelpForInterfaceCleanup* hlp=NULL)
    {
        CONTRACTL
        {
            NOTHROW;
            GC_NOTRIGGER;
            INJECT_FAULT(return E_OUTOFMEMORY;);
        }
        CONTRACTL_END


        // Setting to NULL when we've never set a writer before should
        // do nothing.
        if ((pWriter == NULL) && (m_ppISymUnmanagedWriter == NULL))
            return S_OK;

        // Make room for the writer if necessary.
        if (m_ppISymUnmanagedWriter == NULL)
        {

            return Module::TrackIUnknownForDelete(
                                   (IUnknown*)pWriter,
                                   (IUnknown***)&m_ppISymUnmanagedWriter,
                                   hlp);
        }
        else
        {
            if (*m_ppISymUnmanagedWriter)
                ((IUnknown*)(*m_ppISymUnmanagedWriter))->Release();
            *m_ppISymUnmanagedWriter = pWriter;
            return S_OK;
        }
    }
#endif // !DACCESS_COMPILE
};


// Module holders
FORCEINLINE void VoidModuleDestruct(Module *pModule)
{
#ifndef DACCESS_COMPILE
    if (g_fEEStarted)
        pModule->Destruct();
#endif
}

#if defined (_MSC_VER) && _MSC_VER <= 1300
template void DoNothing(Module *);
template BOOL CompareDefault(Module*,Module*);
#endif // defined (_MSC_VER) && _MSC_VER <= 1300
typedef Wrapper<Module*, DoNothing, VoidModuleDestruct, 0> ModuleHolder;



FORCEINLINE void VoidReflectionModuleDestruct(ReflectionModule *pModule)
{
#ifndef DACCESS_COMPILE
    pModule->Destruct();
#endif
}

#if defined (_MSC_VER) && _MSC_VER <= 1300
template void DoNothing(ReflectionModule *);
template BOOL CompareDefault(ReflectionModule*,ReflectionModule*);
#endif // defined (_MSC_VER) && _MSC_VER <= 1300
typedef Wrapper<ReflectionModule*, DoNothing, VoidReflectionModuleDestruct, 0> ReflectionModuleHolder;



//----------------------------------------------------------------------
// VASigCookieEx (used to create a fake VASigCookie for unmanaged->managed
// calls to vararg functions. These fakes are distinguished from the
// real thing by having a null mdVASig.
//----------------------------------------------------------------------
struct VASigCookieEx : public VASigCookie
{
    const BYTE *m_pArgs;        // pointer to first unfixed unmanaged arg
};

#endif // !CEELOAD_H_



About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us