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
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// EEConfig.CPP
//
//
// Fetched configuration data from the registry (should we Jit, run GC checks ...)
//
//
#include "common.h"
#ifdef FEATURE_COMINTEROP
#include <appxutil.h>
#endif
#include "eeconfig.h"
#include "method.hpp"
#include "eventtrace.h"
#include "eehash.h"
#include "eemessagebox.h"
#include "corhost.h"
#include "regex_util.h"
#include "clr/fs/path.h"
#include "configuration.h"
using namespace clr;
#define DEFAULT_ZAP_SET W("")
#define DEFAULT_APP_DOMAIN_LEAKS 0
#ifdef STRESS_HEAP
// Global counter to disable GCStress. This is needed so we can inhibit
// GC stres collections without resetting the global GCStressLevel, which
// is relied on by the EH code and the JIT code (for handling patched
// managed code, and GC stress exception) after GC stress is dynamically
// turned off.
Volatile<DWORD> GCStressPolicy::InhibitHolder::s_nGcStressDisabled = 0;
#endif // STRESS_HEAP
ConfigSource::ConfigSource()
{
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
FORBID_FAULT;
} CONTRACTL_END;
m_pNext = this;
m_pPrev = this;
}// ConfigSource::ConfigSource
ConfigSource::~ConfigSource()
{
CONTRACTL {
NOTHROW;
FORBID_FAULT;
GC_NOTRIGGER;
MODE_ANY;
} CONTRACTL_END;
for(ConfigStringHashtable::Iterator iter = m_Table.Begin(), end = m_Table.End(); iter != end; iter++)
{
ConfigStringKeyValuePair * pair = *(iter);
delete[] pair->key;
delete[] pair->value;
delete pair;
}
}// ConfigSource::~ConfigSource
ConfigStringHashtable * ConfigSource::Table()
{
LIMITED_METHOD_CONTRACT;
return &(m_Table);
}// ConfigSource::Table
void ConfigSource::Add(ConfigSource* prev)
{
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(CheckPointer(prev));
PRECONDITION(CheckPointer(prev->m_pNext));
} CONTRACTL_END;
m_pPrev = prev;
m_pNext = prev->m_pNext;
m_pNext->m_pPrev = this;
prev->m_pNext = this;
}// ConfigSource::Add
/**************************************************************/
// Poor mans narrow
LPUTF8 NarrowWideChar(__inout_z LPWSTR str)
{
CONTRACT (LPUTF8)
{
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(CheckPointer(str, NULL_OK));
POSTCONDITION(CheckPointer(RETVAL, NULL_OK));
} CONTRACT_END;
if (str != 0) {
LPWSTR fromPtr = str;
LPUTF8 toPtr = (LPUTF8) str;
LPUTF8 result = toPtr;
while(*fromPtr != 0)
*toPtr++ = (char) *fromPtr++;
*toPtr = 0;
RETURN result;
}
RETURN NULL;
}
extern void UpdateGCSettingFromHost ();
HRESULT EEConfig::Setup()
{
STANDARD_VM_CONTRACT;
ETWOnStartup (EEConfigSetup_V1,EEConfigSetupEnd_V1);
// This 'new' uses EEConfig's overloaded new, which uses a static memory buffer and will
// not fail
EEConfig *pConfig = new EEConfig();
HRESULT hr = pConfig->Init();
if (FAILED(hr))
return hr;
EEConfig *pConfigOld = NULL;
pConfigOld = InterlockedCompareExchangeT(&g_pConfig, pConfig, NULL);
_ASSERTE(pConfigOld == NULL && "EEConfig::Setup called multiple times!");
UpdateGCSettingFromHost();
return S_OK;
}
/**************************************************************/
// For in-place constructor
BYTE g_EEConfigMemory[sizeof(EEConfig)];
void *EEConfig::operator new(size_t size)
{
CONTRACT(void*) {
FORBID_FAULT;
GC_NOTRIGGER;
NOTHROW;
MODE_ANY;
POSTCONDITION(CheckPointer(RETVAL));
} CONTRACT_END;
RETURN g_EEConfigMemory;
}
/**************************************************************/
HRESULT EEConfig::Init()
{
STANDARD_VM_CONTRACT;
fInited = false;
#ifdef VERIFY_HEAP
iGCHeapVerify = 0; // Heap Verification OFF by default
#endif
#if defined(STRESS_HEAP) || defined(_DEBUG)
iGCStress = 0;
#endif
#ifdef STRESS_HEAP
iGCStressMix = 0;
iGCStressStep = 1;
#endif
fGCBreakOnOOM = false;
iGCgen0size = 0;
iGCSegmentSize = 0;
iGCconcurrent = 0;
#ifdef _DEBUG
iGCLatencyMode = -1;
#endif //_DEBUG
iGCForceCompact = 0;
iGCHoardVM = 0;
iGCLOHCompactionMode = 0;
iGCHeapCount = 0;
iGCNoAffinitize = 0;
#ifdef GCTRIMCOMMIT
iGCTrimCommit = 0;
#endif
m_fFreepZapSet = false;
dwSpinInitialDuration = 0x32;
dwSpinBackoffFactor = 0x3;
dwSpinLimitProcCap = 0xFFFFFFFF;
dwSpinLimitProcFactor = 0x4E20;
dwSpinLimitConstant = 0x0;
dwSpinRetryCount = 0xA;
iJitOptimizeType = OPT_DEFAULT;
fJitFramed = false;
fJitAlignLoops = false;
fAddRejitNops = false;
fJitMinOpts = false;
fPInvokeRestoreEsp = (DWORD)-1;
fLegacyNullReferenceExceptionPolicy = false;
fLegacyUnhandledExceptionPolicy = false;
fLegacyApartmentInitPolicy = false;
fLegacyComHierarchyVisibility = false;
fLegacyComVTableLayout = false;
fLegacyVirtualMethodCallVerification = false;
fNewComVTableLayout = false;
#ifdef FEATURE_CORRUPTING_EXCEPTIONS
// By default, there is not pre-V4 CSE policy
fLegacyCorruptedStateExceptionsPolicy = false;
#endif // FEATURE_CORRUPTING_EXCEPTIONS
fNgenBindOptimizeNonGac = false;
fStressLog = false;
fCacheBindingFailures = true;
fDisableCommitThreadStack = false;
fProbeForStackOverflow = true;
INDEBUG(fStressLog = true;)
fVerifyAllOnLoad = false;
#ifdef _DEBUG
fExpandAllOnLoad = false;
fDebuggable = false;
fStressOn = false;
apiThreadStressCount = 0;
pPrestubHalt = 0;
pPrestubGC = 0;
pszBreakOnClassLoad = 0;
pszBreakOnClassBuild = 0;
pszBreakOnMethodName = 0;
pszDumpOnClassLoad = 0;
pszBreakOnInteropStubSetup = 0;
pszBreakOnComToClrNativeInfoInit = 0;
pszBreakOnStructMarshalSetup = 0;
fJitVerificationDisable= false;
fVerifierOff = false;
fDoAllowUntrustedCallerChecks = true;
#ifdef ENABLE_STARTUP_DELAY
iStartupDelayMS = 0;
#endif
iPerfNumAllocsThreshold = 0;
iPerfAllocsSizeThreshold = 0;
pPerfTypesToLog = NULL;
iFastGCStress = 0;
iInjectFatalError = 0;
fSaveThreadInfo = FALSE;
dwSaveThreadInfoMask = (DWORD)-1;
#ifdef TEST_DATA_CONSISTENCY
// indicates whether to run the self test to determine that we are detecting when a lock is held by the
// LS in DAC builds. Initialized via the environment variable TestDataConsistency
fTestDataConsistency = false;
#endif
// In Thread::SuspendThread(), default the timeout to 2 seconds. If the suspension
// takes longer, assert (but keep trying).
m_SuspendThreadDeadlockTimeoutMs = 2000;
// For now, give our suspension attempts 40 seconds to succeed before trapping to
// the debugger. Note that we should probably lower this when the JIT is run in
// preemtive mode, as we really should not be starving the GC for 10's of seconds
m_SuspendDeadlockTimeout = 40000;
#endif // _DEBUG
#ifdef FEATURE_COMINTEROP
bLogCCWRefCountChange = false;
pszLogCCWRefCountChange = NULL;
#endif // FEATURE_COMINTEROP
#ifdef _DEBUG
m_fAssertOnBadImageFormat = false;
m_fAssertOnFailFast = true;
fSuppressChecks = false;
fConditionalContracts = false;
fEnableFullDebug = false;
#endif
#ifdef FEATURE_DOUBLE_ALIGNMENT_HINT
DoubleArrayToLargeObjectHeapThreshold = 1000;
#endif
iRequireZaps = REQUIRE_ZAPS_NONE;
// new loader behavior switches
m_fDeveloperInstallation = false;
pZapSet = DEFAULT_ZAP_SET;
#ifdef FEATURE_LOADER_OPTIMIZATION
dwSharePolicy = AppDomain::SHARE_POLICY_UNSPECIFIED;
#endif
#if defined(_TARGET_X86_) || defined(_TARGET_AMD64_)
dwDisableStackwalkCache = 0;
#else // _TARGET_X86_
dwDisableStackwalkCache = 1;
#endif // _TARGET_X86_
fUseNewCrossDomainRemoting = 1;
szZapBBInstr = NULL;
szZapBBInstrDir = NULL;
fAppDomainUnload = true;
dwADURetryCount=1000;
#ifdef _DEBUG
fAppDomainLeaks = DEFAULT_APP_DOMAIN_LEAKS;
// interop logging
m_pTraceIUnknown = NULL;
m_TraceWrapper = 0;
#endif
iNgenHardBind = NGEN_HARD_BIND_DEFAULT;
#ifdef _DEBUG
dwNgenForceFailureMask = 0;
dwNgenForceFailureCount = 0;
dwNgenForceFailureKind = 0;
#endif
iGCPollType = GCPOLL_TYPE_DEFAULT;
#ifdef _DEBUG
fGenerateStubForHost = FALSE;
fShouldInjectFault = 0;
testThreadAbort = 0;
testADUnload = 0;
#endif
#ifdef FEATURE_COMINTEROP
m_fComInsteadOfManagedRemoting = false;
#endif
m_fInteropValidatePinnedObjects = false;
m_fInteropLogArguments = false;
#if defined(_DEBUG) && defined(STUBLINKER_GENERATES_UNWIND_INFO)
fStubLinkerUnwindInfoVerificationOn = FALSE;
#endif
#if defined(_DEBUG) && defined(WIN64EXCEPTIONS)
fSuppressLockViolationsOnReentryFromOS = false;
#endif
#if defined(_DEBUG) && defined(_TARGET_AMD64_)
// For determining if we should force generation of long jump dispatch stubs.
m_cGenerateLongJumpDispatchStubRatio = (size_t)(-1);
m_cDispatchStubsGenerated = 0;
#endif
#if defined(_DEBUG)
bDiagnosticSuspend = false;
#endif
#if defined(FEATURE_TIERED_COMPILATION)
fTieredCompilation = false;
#endif
// After initialization, register the code:#GetConfigValueCallback method with code:CLRConfig to let
// CLRConfig access config files. This is needed because CLRConfig lives outside the VM and can't
// statically link to EEConfig.
CLRConfig::RegisterGetConfigValueCallback(&GetConfigValueCallback);
return S_OK;
}
#ifdef _DEBUG
static int DumpConfigTable(ConfigStringHashtable* table, __in_z LPCSTR label, int count)
{
LIMITED_METHOD_CONTRACT;
LOG((LF_ALWAYS, LL_ALWAYS, label, count++));
LOG((LF_ALWAYS, LL_ALWAYS, "*********************************\n", count++));
for(ConfigStringHashtable::Iterator iter = table->Begin(), end = table->End(); iter != end; iter++)
{
ConfigStringKeyValuePair * pair = *(iter);
LPCWSTR keyString = pair->key;
LPCWSTR data = pair->value;
LOG((LF_ALWAYS, LL_ALWAYS, "%S = %S\n", keyString, data));
}
LOG((LF_ALWAYS, LL_ALWAYS, "\n"));
return count;
}
#endif
/**************************************************************/
HRESULT EEConfig::Cleanup()
{
CONTRACTL {
FORBID_FAULT;
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
} CONTRACTL_END;
#ifdef _DEBUG
if (g_pConfig) {
// TODO: Do we even need this? CLRConfig::GetConfigValue has FORBID_FAULT in its contract.
FAULT_NOT_FATAL(); // If GetConfigValue fails the alloc, that's ok.
DWORD setting = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_DumpConfiguration);
if (setting != 0)
{
ConfigList::ConfigIter iter(&m_Configuration);
int count = 0;
for(ConfigStringHashtable* table = iter.Next();table; table = iter.Next())
{
count = DumpConfigTable(table, "\nSystem Configuration Table: %d\n", count);
}
ConfigList::ConfigIter iter2(&m_Configuration);
count = 0;
for (ConfigStringHashtable* table = iter2.Previous();table; table = iter2.Previous())
{
count = DumpConfigTable(table, "\nApplication Configuration Table: %d\n", count);
}
}
}
#endif
if (m_fFreepZapSet)
delete[] pZapSet;
delete[] szZapBBInstr;
if (pRequireZapsList)
delete pRequireZapsList;
if (pRequireZapsExcludeList)
delete pRequireZapsExcludeList;
if (pReadyToRunExcludeList)
delete pReadyToRunExcludeList;
#ifdef _DEBUG
if (pForbidZapsList)
delete pForbidZapsList;
if (pForbidZapsExcludeList)
delete pForbidZapsExcludeList;
#endif
#ifdef FEATURE_COMINTEROP
if (pszLogCCWRefCountChange)
delete [] pszLogCCWRefCountChange;
#endif // FEATURE_COMINTEROP
#ifdef _DEBUG
if (pPrestubHalt)
{
DestroyMethList(pPrestubHalt);
pPrestubHalt = NULL;
}
if (pPrestubGC)
{
DestroyMethList(pPrestubGC);
pPrestubGC = NULL;
}
if (pSkipGCCoverageList)
{
delete pSkipGCCoverageList;
pSkipGCCoverageList = NULL;
}
delete [] pszBreakOnClassLoad;
delete [] pszBreakOnClassBuild;
delete [] pszBreakOnInstantiation;
delete [] pszBreakOnMethodName;
delete [] pszDumpOnClassLoad;
delete [] pszBreakOnInteropStubSetup;
delete [] pszBreakOnComToClrNativeInfoInit;
delete [] pszBreakOnStructMarshalSetup;
delete [] pszGcCoverageOnMethod;
#endif
#ifdef _DEBUG
if (pPerfTypesToLog)
{
DestroyTypeList(pPerfTypesToLog);
pPerfTypesToLog = NULL;
}
#endif
return S_OK;
}
//
// NOTE: This function is deprecated; use the CLRConfig class instead.
// To use the CLRConfig class, add an entry in file:../inc/CLRConfigValues.h.
//
HRESULT EEConfig::GetConfigString_DontUse_(__in_z LPCWSTR name, __deref_out_z LPWSTR *outVal, BOOL fPrependCOMPLUS, ConfigSearch direction)
{
CONTRACT(HRESULT) {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
INJECT_FAULT (CONTRACT_RETURN E_OUTOFMEMORY);
PRECONDITION(CheckPointer(name));
POSTCONDITION(CheckPointer(outVal, NULL_OK));
} CONTRACT_END;
LPWSTR pvalue = REGUTIL::GetConfigString_DontUse_(name, fPrependCOMPLUS);
if(pvalue == NULL && g_pConfig != NULL)
{
LPCWSTR pResult;
if(SUCCEEDED(g_pConfig->GetConfiguration_DontUse_(name, direction, &pResult)) && pResult != NULL)
{
size_t len = wcslen(pResult) + 1;
pvalue = new (nothrow) WCHAR[len];
if (pvalue == NULL)
{
RETURN E_OUTOFMEMORY;
}
wcscpy_s(pvalue,len,pResult);
}
}
*outVal = pvalue;
RETURN S_OK;
}
//
// NOTE: This function is deprecated; use the CLRConfig class instead.
// To use the CLRConfig class, add an entry in file:../inc/CLRConfigValues.h.
//
DWORD EEConfig::GetConfigDWORD_DontUse_(__in_z LPCWSTR name, DWORD defValue, DWORD level, BOOL fPrependCOMPLUS, ConfigSearch direction)
{
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(CheckPointer(name));
} CONTRACTL_END;
// <TODO>@TODO: After everyone has moved off registry, key remove the following line in golden</TODO>
DWORD result = REGUTIL::GetConfigDWORD_DontUse_(name, defValue, (REGUTIL::CORConfigLevel)level, fPrependCOMPLUS);
if(result == defValue && g_pConfig != NULL)
{
LPCWSTR pvalue;
if(SUCCEEDED(g_pConfig->GetConfiguration_DontUse_(name, direction, &pvalue)) && pvalue != NULL)
{
WCHAR *end;
errno = 0;
result = wcstoul(pvalue, &end, 0);
// errno is ERANGE if the number is out of range, and end is set to pvalue if
// no valid conversion exists.
if (errno == ERANGE || end == pvalue)
{
result = defValue;
}
}
}
return result;
}
//
// NOTE: This function is deprecated; use the CLRConfig class instead.
// To use the CLRConfig class, add an entry in file:../inc/CLRConfigValues.h.
//
// Note for PAL: right now PAL does not have a _wcstoui64 API, so I am temporarily reading in all numbers as
// a 32-bit number. When we have the _wcstoui64 API on MAC we will use that instead of wcstoul.
ULONGLONG EEConfig::GetConfigULONGLONG_DontUse_(__in_z LPCWSTR name, ULONGLONG defValue, DWORD level, BOOL fPrependCOMPLUS, ConfigSearch direction)
{
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(CheckPointer(name));
} CONTRACTL_END;
// <TODO>@TODO: After everyone has moved off registry, key remove the following line in golden</TODO>
ULONGLONG result = REGUTIL::GetConfigULONGLONG_DontUse_(name, defValue, (REGUTIL::CORConfigLevel)level, fPrependCOMPLUS);
if(result == defValue && g_pConfig != NULL)
{
LPCWSTR pvalue;
if(SUCCEEDED(g_pConfig->GetConfiguration_DontUse_(name, direction, &pvalue)) && pvalue != NULL)
{
WCHAR *end;
errno = 0;
result = _wcstoui64(pvalue, &end, 0);
// errno is ERANGE if the number is out of range, and end is set to pvalue if
// no valid conversion exists.
if (errno == ERANGE || end == pvalue)
{
result = defValue;
}
}
}
return result;
}
//
// NOTE: This function is deprecated; use the CLRConfig class instead.
// To use the CLRConfig class, add an entry in file:../inc/CLRConfigValues.h.
//
// This is very similar to GetConfigDWORD, except that it favors the settings in config files over those in the
// registry. This is the Shim's policy with configuration flags, and there are a few flags in EEConfig that adhere
// to this policy.
//
DWORD EEConfig::GetConfigDWORDFavoringConfigFile_DontUse_(__in_z LPCWSTR name,
DWORD defValue,
DWORD level,
BOOL fPrependCOMPLUS,
ConfigSearch direction)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(CheckPointer(name));
} CONTRACTL_END;
DWORD result = defValue;
if (g_pConfig != NULL)
{
LPCWSTR pvalue;
if (SUCCEEDED(g_pConfig->GetConfiguration_DontUse_(name, direction, &pvalue)) && pvalue != NULL)
{
WCHAR *end = NULL;
errno = 0;
result = wcstoul(pvalue, &end, 0);
// errno is ERANGE if the number is out of range, and end is set to pvalue if
// no valid conversion exists.
if (errno == ERANGE || end == pvalue)
{
result = defValue;
}
}
else
{
result = REGUTIL::GetConfigDWORD_DontUse_(name, defValue, (REGUTIL::CORConfigLevel)level, fPrependCOMPLUS);
}
}
return result;
}
//
// NOTE: This function is deprecated; use the CLRConfig class instead.
// To use the CLRConfig class, add an entry in file:../inc/CLRConfigValues.h.
//
DWORD EEConfig::GetConfigDWORDInternal_DontUse_(__in_z LPCWSTR name, DWORD defValue, DWORD level, BOOL fPrependCOMPLUS, ConfigSearch direction)
{
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(CheckPointer(name));
} CONTRACTL_END;
// <TODO>@TODO: After everyone has moved off registry, key remove the following line in golden</TODO>
DWORD result = REGUTIL::GetConfigDWORD_DontUse_(name, defValue, (REGUTIL::CORConfigLevel)level, fPrependCOMPLUS);
if(result == defValue)
{
LPCWSTR pvalue;
if(SUCCEEDED(GetConfiguration_DontUse_(name, direction, &pvalue)) && pvalue != NULL)
{
WCHAR *end = NULL;
errno = 0;
result = wcstoul(pvalue, &end, 0);
// errno is ERANGE if the number is out of range, and end is set to pvalue if
// no valid conversion exists.
if (errno == ERANGE || end == pvalue)
{
result = defValue;
}
}
}
return result;
}
/**************************************************************/
HRESULT EEConfig::sync()
{
CONTRACTL {
THROWS;
GC_NOTRIGGER;
MODE_ANY;
INJECT_FAULT (return E_OUTOFMEMORY);
} CONTRACTL_END;
ETWOnStartup (EEConfigSync_V1, EEConfigSyncEnd_V1);
HRESULT hr = S_OK;
// Note the global variable is not updated directly by the GetRegKey function
// so we only update it once (to avoid reentrancy windows)
#ifdef _DEBUG
iFastGCStress = GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_FastGCStress, iFastGCStress);
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_GcCoverage, (LPWSTR*)&pszGcCoverageOnMethod));
pszGcCoverageOnMethod = NarrowWideChar((LPWSTR)pszGcCoverageOnMethod);
iGCLatencyMode = GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_GCLatencyMode, iGCLatencyMode);
#endif
if (CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_ARMEnabled))
{
g_fEnableARM = TRUE;
}
bool gcConcurrentWasForced = false;
// The CLRConfig value for UNSUPPORTED_gcConcurrent defaults to -1, and treats any
// positive value as 'forcing' concurrent GC to be on. Because the standard logic
// for mapping a DWORD CLRConfig to a boolean configuration treats -1 as true (just
// like any other nonzero value), we will explicitly check the DWORD later if this
// check returns false.
gcConcurrentWasForced = Configuration::GetKnobBooleanValue(W("System.GC.Concurrent"), false);
int gcConcurrentConfigVal = 0;
if (!gcConcurrentWasForced)
{
gcConcurrentConfigVal = CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_gcConcurrent);
gcConcurrentWasForced = (gcConcurrentConfigVal > 0);
}
if (gcConcurrentWasForced || (gcConcurrentConfigVal == -1 && g_IGCconcurrent))
iGCconcurrent = TRUE;
// Disable concurrent GC during ngen for the rare case a GC gets triggered, causing problems
if (IsCompilationProcess())
iGCconcurrent = FALSE;
#ifdef _DEBUG
fAppDomainLeaks = GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_AppDomainAgilityChecked, DEFAULT_APP_DOMAIN_LEAKS) == 1;
#endif
#if defined(STRESS_HEAP) || defined(_DEBUG)
iGCStress = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_GCStress);
#endif
#ifdef STRESS_HEAP
BOOL bGCStressAndHeapVerifyAllowed = true;
iGCStressMix = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_GCStressMix);
iGCStressStep = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_GCStressStep);
// For GC stress mix mode ensure reasonable defaults
if (iGCStressMix != 0)
{
if (iGCStress == 0)
iGCStress |= int(GCSTRESS_ALLOC) | int(GCSTRESS_TRANSITION);
if (iGCStressStep == 0 || iGCStressStep == 1)
iGCStressStep = 0x10;
}
if (iGCStress)
{
LPWSTR pszGCStressExe = NULL;
#ifdef _DEBUG
// If GCStress is turned on, then perform AppDomain agility checks in debug builds
fAppDomainLeaks = 1;
#endif
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_RestrictedGCStressExe, &pszGCStressExe));
if (pszGCStressExe != NULL)
{
if (*pszGCStressExe != W('\0'))
{
bGCStressAndHeapVerifyAllowed = false;
PathString wszFileName;
if (WszGetModuleFileName(NULL, wszFileName) != 0)
{
// just keep the name
LPCWSTR pwszName = wcsrchr(wszFileName, W('\\'));
pwszName = (pwszName == NULL) ? wszFileName.GetUnicode() : (pwszName + 1);
if (SString::_wcsicmp(pwszName,pszGCStressExe) == 0)
{
bGCStressAndHeapVerifyAllowed = true;
}
}
}
delete [] pszGCStressExe;
}
if (bGCStressAndHeapVerifyAllowed)
{
if (gcConcurrentWasForced)
{
#ifdef _DEBUG
iFastGCStress = 0;
#endif
iGCStress |= int(GCSTRESS_ALLOC) | int(GCSTRESS_TRANSITION);
}
else
{
// If GCStress was enabled, and
// If GcConcurrent was NOT explicitly specified in the environment, and
// If GSCtressMix was NOT specified
// Then let's turn off concurrent GC since it make objects move less
if (iGCStressMix == 0)
{
iGCconcurrent =
g_IGCconcurrent = 0;
}
}
}
else
{
iGCStress = 0;
iGCStressMix = 0;
iGCStressStep = 1;
}
}
#ifdef VERIFY_HEAP
if (bGCStressAndHeapVerifyAllowed)
{
iGCHeapVerify = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_HeapVerify, iGCHeapVerify);
}
#endif
#endif //STRESS_HEAP
#ifdef _WIN64
if (!iGCSegmentSize) iGCSegmentSize = GetConfigULONGLONG_DontUse_(CLRConfig::UNSUPPORTED_GCSegmentSize, iGCSegmentSize);
if (!iGCgen0size) iGCgen0size = GetConfigULONGLONG_DontUse_(CLRConfig::UNSUPPORTED_GCgen0size, iGCgen0size);
#else
if (!iGCSegmentSize) iGCSegmentSize = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_GCSegmentSize, iGCSegmentSize);
if (!iGCgen0size) iGCgen0size = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_GCgen0size, iGCgen0size);
#endif //_WIN64
if (g_IGCHoardVM)
iGCHoardVM = g_IGCHoardVM;
else
iGCHoardVM = CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_GCRetainVM);
if (!iGCLOHCompactionMode) iGCLOHCompactionMode = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_GCLOHCompact, iGCLOHCompactionMode);
#ifdef GCTRIMCOMMIT
if (g_IGCTrimCommit)
iGCTrimCommit = g_IGCTrimCommit;
else
iGCTrimCommit = GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_gcTrimCommitOnLowMemory, iGCTrimCommit);
#endif
#ifdef FEATURE_CONSERVATIVE_GC
iGCConservative = (CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_gcConservative) != 0);
#endif // FEATURE_CONSERVATIVE_GC
#ifdef _WIN64
iGCAllowVeryLargeObjects = (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_gcAllowVeryLargeObjects) != 0);
#endif
fGCBreakOnOOM = (GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_GCBreakOnOOM, fGCBreakOnOOM) != 0);
#ifdef TRACE_GC
iGCtraceStart = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_GCtraceStart, iGCtraceStart);
iGCtraceEnd = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_GCtraceEnd, iGCtraceEnd);
iGCtraceFac = GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_GCtraceFacility, iGCtraceFac);
iGCprnLvl = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_GCprnLvl, iGCprnLvl);
#endif
#ifdef _DEBUG
iInjectFatalError = GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_InjectFatalError, iInjectFatalError);
fSaveThreadInfo = (GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_SaveThreadInfo, fSaveThreadInfo) != 0);
dwSaveThreadInfoMask = GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_SaveThreadInfoMask, dwSaveThreadInfoMask);
{
LPWSTR wszSkipGCCoverageList = NULL;
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_SkipGCCoverage, &wszSkipGCCoverageList));
EX_TRY
{
if (wszSkipGCCoverageList)
pSkipGCCoverageList = new AssemblyNamesList(wszSkipGCCoverageList);
}
EX_CATCH_HRESULT(hr);
IfFailRet(hr);
}
#endif
iGCForceCompact = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_gcForceCompact, iGCForceCompact);
iGCNoAffinitize = Configuration::GetKnobBooleanValue(W("System.GC.NoAffinitize"),
CLRConfig::UNSUPPORTED_GCNoAffinitize);
iGCHeapCount = Configuration::GetKnobDWORDValue(W("System.GC.HeapCount"), CLRConfig::UNSUPPORTED_GCHeapCount);
fStressLog = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_StressLog, fStressLog) != 0;
fForceEnc = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_ForceEnc, fForceEnc) != 0;
iRequireZaps = RequireZapsType(GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_ZapRequire, iRequireZaps));
if (IsCompilationProcess() || iRequireZaps >= REQUIRE_ZAPS_COUNT)
iRequireZaps = REQUIRE_ZAPS_NONE;
if (iRequireZaps != REQUIRE_ZAPS_NONE)
{
{
NewArrayHolder<WCHAR> wszZapRequireList;
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_ZapRequireList, &wszZapRequireList));
if (wszZapRequireList)
pRequireZapsList = new AssemblyNamesList(wszZapRequireList);
}
{
NewArrayHolder<WCHAR> wszZapRequireExcludeList;
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_ZapRequireExcludeList, &wszZapRequireExcludeList));
if (wszZapRequireExcludeList)
pRequireZapsExcludeList = new AssemblyNamesList(wszZapRequireExcludeList);
}
}
pReadyToRunExcludeList = NULL;
#if defined(FEATURE_READYTORUN)
if (ReadyToRunInfo::IsReadyToRunEnabled())
{
NewArrayHolder<WCHAR> wszReadyToRunExcludeList;
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_ReadyToRunExcludeList, &wszReadyToRunExcludeList));
if (wszReadyToRunExcludeList)
pReadyToRunExcludeList = new AssemblyNamesList(wszReadyToRunExcludeList);
}
#endif // defined(FEATURE_READYTORUN)
#ifdef _DEBUG
iForbidZaps = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_NgenBind_ZapForbid) != 0;
if (iForbidZaps != 0)
{
{
NewArrayHolder<WCHAR> wszZapForbidList;
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_NgenBind_ZapForbidList, &wszZapForbidList));
if (wszZapForbidList)
pForbidZapsList = new AssemblyNamesList(wszZapForbidList);
}
{
NewArrayHolder<WCHAR> wszZapForbidExcludeList;
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_NgenBind_ZapForbidExcludeList, &wszZapForbidExcludeList));
if (wszZapForbidExcludeList)
pForbidZapsExcludeList = new AssemblyNamesList(wszZapForbidExcludeList);
}
}
#endif
#ifdef FEATURE_LOADER_OPTIMIZATION
dwSharePolicy = GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_LoaderOptimization, dwSharePolicy);
#endif
#ifdef FEATURE_DOUBLE_ALIGNMENT_HINT
DoubleArrayToLargeObjectHeapThreshold = GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_DoubleArrayToLargeObjectHeap, DoubleArrayToLargeObjectHeapThreshold);
#endif
#ifdef FEATURE_PREJIT
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_ZapBBInstr, (LPWSTR*)&szZapBBInstr));
if (szZapBBInstr)
{
szZapBBInstr = NarrowWideChar((LPWSTR)szZapBBInstr);
// If szZapBBInstr only contains white space, then there's nothing to instrument (this
// is the case with some test cases, and it's easier to fix all of them here).
LPWSTR pStr = (LPWSTR) szZapBBInstr;
while (*pStr == W(' ')) pStr++;
if (*pStr == 0)
szZapBBInstr = NULL;
}
if (szZapBBInstr != NULL)
{
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_ZapBBInstrDir, &szZapBBInstrDir));
g_IBCLogger.EnableAllInstr();
}
else
g_IBCLogger.DisableAllInstr();
#endif
dwDisableStackwalkCache = GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_DisableStackwalkCache, dwDisableStackwalkCache);
#ifdef _DEBUG
IfFailRet (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_BreakOnClassLoad, (LPWSTR*) &pszBreakOnClassLoad));
pszBreakOnClassLoad = NarrowWideChar((LPWSTR)pszBreakOnClassLoad);
#endif
dwSpinInitialDuration = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_SpinInitialDuration);
dwSpinBackoffFactor = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_SpinBackoffFactor);
dwSpinLimitProcCap = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_SpinLimitProcCap);
dwSpinLimitProcFactor = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_SpinLimitProcFactor);
dwSpinLimitConstant = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_SpinLimitConstant);
dwSpinRetryCount = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_SpinRetryCount);
fJitFramed = (GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_JitFramed, fJitFramed) != 0);
fJitAlignLoops = (GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_JitAlignLoops, fJitAlignLoops) != 0);
fJitMinOpts = (GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_JITMinOpts, fJitMinOpts) == 1);
iJitOptimizeType = GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_JitOptimizeType, iJitOptimizeType);
if (iJitOptimizeType > OPT_RANDOM) iJitOptimizeType = OPT_DEFAULT;
#ifdef FEATURE_REJIT
fAddRejitNops = (GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_AddRejitNops, fAddRejitNops) != 0);
#endif
#ifdef _TARGET_X86_
fPInvokeRestoreEsp = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_Jit_NetFx40PInvokeStackResilience);
#endif
#ifdef _DEBUG
fDebuggable = (GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_JitDebuggable, fDebuggable) != 0);
fStressOn = (GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_StressOn, fStressOn) != 0);
apiThreadStressCount = GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_APIThreadStress, apiThreadStressCount);
LPWSTR wszPreStubStuff = NULL;
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_PrestubHalt, &wszPreStubStuff));
IfFailRet(ParseMethList(wszPreStubStuff, &pPrestubHalt));
LPWSTR wszInvokeStuff = NULL;
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_InvokeHalt, &wszInvokeStuff));
IfFailRet(ParseMethList(wszInvokeStuff, &pInvokeHalt));
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_PrestubGC, &wszPreStubStuff));
IfFailRet(ParseMethList(wszPreStubStuff, &pPrestubGC));
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_BreakOnClassBuild, (LPWSTR*)&pszBreakOnClassBuild));
pszBreakOnClassBuild = NarrowWideChar((LPWSTR)pszBreakOnClassBuild);
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_BreakOnInstantiation, (LPWSTR*)&pszBreakOnInstantiation));
pszBreakOnInstantiation = NarrowWideChar((LPWSTR)pszBreakOnInstantiation);
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_BreakOnMethodName, (LPWSTR*)&pszBreakOnMethodName));
pszBreakOnMethodName = NarrowWideChar((LPWSTR)pszBreakOnMethodName);
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_DumpOnClassLoad, (LPWSTR*)&pszDumpOnClassLoad));
pszDumpOnClassLoad = NarrowWideChar((LPWSTR)pszDumpOnClassLoad);
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_BreakOnInteropStubSetup, (LPWSTR*)&pszBreakOnInteropStubSetup));
pszBreakOnInteropStubSetup = NarrowWideChar((LPWSTR)pszBreakOnInteropStubSetup);
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_BreakOnComToClrNativeInfoInit, (LPWSTR*)&pszBreakOnComToClrNativeInfoInit));
pszBreakOnComToClrNativeInfoInit = NarrowWideChar((LPWSTR)pszBreakOnComToClrNativeInfoInit);
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_BreakOnStructMarshalSetup, (LPWSTR*)&pszBreakOnStructMarshalSetup));
pszBreakOnStructMarshalSetup = NarrowWideChar((LPWSTR)pszBreakOnStructMarshalSetup);
m_fAssertOnBadImageFormat = (GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_AssertOnBadImageFormat, m_fAssertOnBadImageFormat) != 0);
m_fAssertOnFailFast = (GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_AssertOnFailFast, m_fAssertOnFailFast) != 0);
fSuppressChecks = (GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_SuppressChecks, fSuppressChecks) != 0);
CHECK::SetAssertEnforcement(!fSuppressChecks);
fConditionalContracts = (GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_ConditionalContracts, fConditionalContracts) != 0);
#ifdef ENABLE_CONTRACTS_IMPL
Contract::SetUnconditionalContractEnforcement(!fConditionalContracts);
#endif
fEnableFullDebug = (GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_EnableFullDebug, fEnableFullDebug) != 0);
fVerifierOff = (GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_VerifierOff, fVerifierOff) != 0);
fJitVerificationDisable = (GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_JitVerificationDisable, fJitVerificationDisable) != 0);
iExposeExceptionsInCOM = GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_ExposeExceptionsInCOM, iExposeExceptionsInCOM);
#endif
#ifdef FEATURE_COMINTEROP
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_LogCCWRefCountChange, (LPWSTR*)&pszLogCCWRefCountChange));
pszLogCCWRefCountChange = NarrowWideChar((LPWSTR)pszLogCCWRefCountChange);
if (pszLogCCWRefCountChange != NULL)
bLogCCWRefCountChange = true;
fEnableRCWCleanupOnSTAShutdown = (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_EnableRCWCleanupOnSTAShutdown) != 0);
#endif // FEATURE_COMINTEROP
//Eager verification of all assemblies.
fVerifyAllOnLoad = (GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_VerifyAllOnLoad, fVerifyAllOnLoad) != 0);
#ifdef _DEBUG
fExpandAllOnLoad = (GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_ExpandAllOnLoad, fExpandAllOnLoad) != 0);
#endif //_DEBUG
#ifdef AD_NO_UNLOAD
fAppDomainUnload = (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_AppDomainNoUnload) == 0);
#endif
dwADURetryCount=GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_ADURetryCount, dwADURetryCount);
if (dwADURetryCount==(DWORD)-1)
{
_ASSERTE(!"Reserved value");
dwADURetryCount=(DWORD)-2;
}
#ifdef ENABLE_STARTUP_DELAY
{
//I want this string in decimal
WCHAR * end;
WCHAR * str;
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_StartupDelayMS, &str));
if( str )
{
errno = 0;
iStartupDelayMS = wcstoul(str, &end, 10);
if (errno == ERANGE || end == str)
iStartupDelayMS = 0;
}
}
#endif
#ifdef _DEBUG
#ifdef TEST_DATA_CONSISTENCY
fTestDataConsistency = (CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_TestDataConsistency) !=0);
#endif
fDoAllowUntrustedCallerChecks =
(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_SupressAllowUntrustedCallerChecks) != 1);
m_SuspendThreadDeadlockTimeoutMs = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_SuspendThreadDeadlockTimeoutMs);
m_SuspendDeadlockTimeout = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_SuspendDeadlockTimeout);
#endif // _DEBUG
fInited = true;
#ifdef _DEBUG
m_pTraceIUnknown = (IUnknown*)(DWORD_PTR)(GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_TraceIUnknown, (DWORD)(DWORD_PTR)(m_pTraceIUnknown))); // <TODO> WIN64 - conversion from DWORD to IUnknown* of greater size</TODO>
m_TraceWrapper = GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_TraceWrap, m_TraceWrapper);
// can't have both
if (m_pTraceIUnknown != 0)
{
m_TraceWrapper = 0;
}
else
if (m_TraceWrapper != 0)
{
m_pTraceIUnknown = (IUnknown*)-1;
}
#endif
#ifdef _DEBUG
LPWSTR wszPerfTypes = NULL;
IfFailRet(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_PerfTypesToLog, &wszPerfTypes));
IfFailRet(ParseTypeList(wszPerfTypes, &pPerfTypesToLog));
iPerfNumAllocsThreshold = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_PerfNumAllocsThreshold);
iPerfAllocsSizeThreshold = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_PerfAllocsSizeThreshold);
fGenerateStubForHost = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_GenerateStubForHost);
fShouldInjectFault = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_InjectFault);
testThreadAbort = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_HostTestThreadAbort);
testADUnload = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_HostTestADUnload);
#endif //_DEBUG
#ifdef FEATURE_COMINTEROP
m_fComInsteadOfManagedRemoting = (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_ComInsteadOfManagedRemoting) != 0);
#endif // FEATURE_COMINTEROP
m_fInteropValidatePinnedObjects = (CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_InteropValidatePinnedObjects) != 0);
m_fInteropLogArguments = (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_InteropLogArguments) != 0);
#ifdef FEATURE_PREJIT
#ifdef _DEBUG
dwNgenForceFailureMask = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_NgenForceFailureMask);
dwNgenForceFailureCount = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_NgenForceFailureCount);
dwNgenForceFailureKind = CLRConfig::GetConfigValue(CLRConfig::INTERNAL_NgenForceFailureKind);
#endif
#endif // FEATURE_PREJIT
DWORD iGCPollTypeOverride = GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_GCPollType, iGCPollType);
#ifndef FEATURE_HIJACK
// Platforms that do not support hijacking MUST support GC polling.
// Reject attempts by the user to configure the GC polling type as
// GCPOLL_TYPE_HIJACK.
_ASSERTE(EEConfig::GCPOLL_TYPE_HIJACK != iGCPollTypeOverride);
if (EEConfig::GCPOLL_TYPE_HIJACK == iGCPollTypeOverride)
iGCPollTypeOverride = EEConfig::GCPOLL_TYPE_DEFAULT;
#endif
_ASSERTE(iGCPollTypeOverride < GCPOLL_TYPE_COUNT);
if (iGCPollTypeOverride < GCPOLL_TYPE_COUNT)
iGCPollType = GCPollType(iGCPollTypeOverride);
#if defined(_DEBUG) && defined(WIN64EXCEPTIONS)
fSuppressLockViolationsOnReentryFromOS = (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_SuppressLockViolationsOnReentryFromOS) != 0);
#endif
#if defined(_DEBUG) && defined(STUBLINKER_GENERATES_UNWIND_INFO)
fStubLinkerUnwindInfoVerificationOn = (GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_StubLinkerUnwindInfoVerificationOn, fStubLinkerUnwindInfoVerificationOn) != 0);
#endif
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_UseMethodDataCache) != 0) {
MethodTable::AllowMethodDataCaching();
}
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_UseParentMethodData) != 0) {
MethodTable::AllowParentMethodDataCopy();
}
#if defined(_DEBUG) && defined(_TARGET_AMD64_)
m_cGenerateLongJumpDispatchStubRatio = GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_GenerateLongJumpDispatchStubRatio,
static_cast<DWORD>(m_cGenerateLongJumpDispatchStubRatio));
#endif
#if defined(_DEBUG)
bDiagnosticSuspend = (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_DiagnosticSuspend) != 0);
#endif
dwSleepOnExit = CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_SleepOnExit);
#if defined(FEATURE_TIERED_COMPILATION)
fTieredCompilation = CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_TieredCompilation) != 0;
#endif
return hr;
}
//
// #GetConfigValueCallback
// Provides a way for code:CLRConfig to access configuration file values.
//
// static
HRESULT EEConfig::GetConfigValueCallback(__in_z LPCWSTR pKey, __deref_out_opt LPCWSTR* pValue, BOOL systemOnly, BOOL applicationFirst)
{
CONTRACT (HRESULT) {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
SO_TOLERANT;
PRECONDITION(CheckPointer(pValue));
PRECONDITION(CheckPointer(pKey));
} CONTRACT_END;
// Ensure that both options aren't set.
_ASSERTE(!(systemOnly && applicationFirst));
if(g_pConfig != NULL)
{
ConfigSearch direction = CONFIG_SYSTEM;
if(systemOnly)
{
direction = CONFIG_SYSTEMONLY;
}
else if(applicationFirst)
{
direction = CONFIG_APPLICATION;
}
RETURN g_pConfig->GetConfiguration_DontUse_(pKey, direction, pValue);
}
else
{
RETURN E_FAIL;
}
}
HRESULT EEConfig::GetConfiguration_DontUse_(__in_z LPCWSTR pKey, ConfigSearch direction, __deref_out_opt LPCWSTR* pValue)
{
CONTRACT (HRESULT) {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
SO_TOLERANT; // TODO: Verify this does not do anything that would make it so_intolerant
PRECONDITION(CheckPointer(pValue));
PRECONDITION(CheckPointer(pKey));
} CONTRACT_END;
Thread *pThread = GetThread();
ConfigStringKeyValuePair * pair = NULL;
*pValue = NULL;
ConfigList::ConfigIter iter(&m_Configuration);
switch(direction) {
case CONFIG_SYSTEMONLY:
{
// for things that only admin should be able to set
ConfigStringHashtable* table = iter.Next();
if(table != NULL)
{
BEGIN_SO_INTOLERANT_CODE_NOTHROW(pThread, RETURN E_FAIL;)
pair = table->Lookup(pKey);
END_SO_INTOLERANT_CODE
if(pair != NULL)
{
*pValue = pair->value;
RETURN S_OK;
}
}
RETURN E_FAIL;
}
case CONFIG_SYSTEM:
{
for(ConfigStringHashtable* table = iter.Next();
table != NULL;
table = iter.Next())
{
BEGIN_SO_INTOLERANT_CODE_NOTHROW(pThread, RETURN E_FAIL;)
pair = table->Lookup(pKey);
END_SO_INTOLERANT_CODE
if(pair != NULL)
{
*pValue = pair->value;
RETURN S_OK;
}
}
RETURN E_FAIL;
}
case CONFIG_APPLICATION: {
for(ConfigStringHashtable* table = iter.Previous();
table != NULL;
table = iter.Previous())
{
BEGIN_SO_INTOLERANT_CODE_NOTHROW(pThread, RETURN E_FAIL;)
pair = table->Lookup(pKey);
END_SO_INTOLERANT_CODE
if(pair != NULL)
{
*pValue = pair->value;
RETURN S_OK;
}
}
RETURN E_FAIL;
}
default:
RETURN E_FAIL;
}
}
bool EEConfig::RequireZap(LPCUTF8 assemblyName) const
{
LIMITED_METHOD_CONTRACT;
if (iRequireZaps == REQUIRE_ZAPS_NONE)
return false;
if (pRequireZapsExcludeList != NULL && pRequireZapsExcludeList->IsInList(assemblyName))
return false;
if (pRequireZapsList == NULL || pRequireZapsList->IsInList(assemblyName))
return true;
return false;
}
#ifdef _DEBUG
bool EEConfig::ForbidZap(LPCUTF8 assemblyName) const
{
LIMITED_METHOD_CONTRACT;
if (iForbidZaps == 0)
return false;
if (pForbidZapsExcludeList != NULL && pForbidZapsExcludeList->IsInList(assemblyName))
return false;
if (pForbidZapsList == NULL || pForbidZapsList->IsInList(assemblyName))
return true;
return false;
}
#endif
bool EEConfig::ExcludeReadyToRun(LPCUTF8 assemblyName) const
{
LIMITED_METHOD_CONTRACT;
if (pReadyToRunExcludeList != NULL && pReadyToRunExcludeList->IsInList(assemblyName))
return true;
return false;
}
/**************************************************************/
#ifdef _DEBUG
/**************************************************************/
// Ownership of the string buffer passes to ParseMethList
/* static */
HRESULT EEConfig::ParseMethList(__in_z LPWSTR str, MethodNamesList** out) {
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
INJECT_FAULT(return E_OUTOFMEMORY);
PRECONDITION(CheckPointer(str, NULL_OK));
PRECONDITION(CheckPointer(out));
} CONTRACTL_END;
HRESULT hr = S_OK;
*out = NULL;
// we are now done with the string passed in
if (str == NULL)
{
return S_OK;
}
EX_TRY
{
*out = new MethodNamesList(str);
} EX_CATCH_HRESULT(hr);
delete [] str;
return hr;
}
/**************************************************************/
/* static */
void EEConfig::DestroyMethList(MethodNamesList* list) {
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(CheckPointer(list));
} CONTRACTL_END;
if (list == 0)
return;
delete list;
}
/**************************************************************/
/* static */
bool EEConfig::IsInMethList(MethodNamesList* list, MethodDesc* pMD)
{
CONTRACTL {
THROWS;
GC_TRIGGERS;
MODE_ANY;
PRECONDITION(CheckPointer(list, NULL_OK));
PRECONDITION(CheckPointer(pMD));
} CONTRACTL_END;
if (list == 0)
return(false);
else
{
DefineFullyQualifiedNameForClass();
LPCUTF8 name = pMD->GetName();
if (name == NULL)
{
return false;
}
LPCUTF8 className = GetFullyQualifiedNameForClass(pMD->GetMethodTable());
if (className == NULL)
{
return false;
}
PCCOR_SIGNATURE sig = pMD->GetSig();
return list->IsInList(name, className, sig);
}
}
// Ownership of the string buffer passes to ParseTypeList
/* static */
HRESULT EEConfig::ParseTypeList(__in_z LPWSTR str, TypeNamesList** out)
{
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(CheckPointer(out));
PRECONDITION(CheckPointer(str, NULL_OK));
INJECT_FAULT(return E_OUTOFMEMORY);
} CONTRACTL_END;
HRESULT hr = S_OK;
*out = NULL;
if (str == NULL)
return S_OK;
NewHolder<TypeNamesList> newTypeNameList(new (nothrow) TypeNamesList());
if (newTypeNameList != NULL)
IfFailRet(newTypeNameList->Init(str));
delete [] str;
newTypeNameList.SuppressRelease();
*out = newTypeNameList;
return (*out != NULL)?S_OK:E_OUTOFMEMORY;
}
void EEConfig::DestroyTypeList(TypeNamesList* list) {
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(CheckPointer(list));
} CONTRACTL_END;
if (list == 0)
return;
delete list;
}
TypeNamesList::TypeNamesList()
{
LIMITED_METHOD_CONTRACT;
}
bool EEConfig::RegexOrExactMatch(LPCUTF8 regex, LPCUTF8 input)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
if (regex == NULL || input == NULL)
return false;
if (*regex == '/')
{
// Debug only, so we can live with it.
CONTRACT_VIOLATION(ThrowsViolation);
regex::STRRegEx::GroupingContainer groups;
if (regex::STRRegEx::Match("^/(.*)/(i?)$", regex, groups))
{
regex::STRRegEx::MatchFlags flags = regex::STRRegEx::DefaultMatchFlags;
if (groups[2].Length() != 0)
flags = (regex::STRRegEx::MatchFlags)(flags | regex::STRRegEx::MF_CASE_INSENSITIVE);
return regex::STRRegEx::Matches(groups[1].Begin(), groups[1].End(),
input, input + strlen(input), flags);
}
}
return strcmp(regex, input) == 0;
}
HRESULT TypeNamesList::Init(__in_z LPCWSTR str)
{
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(CheckPointer(str));
INJECT_FAULT(return E_OUTOFMEMORY);
} CONTRACTL_END;
pNames = NULL;
LPCWSTR currentType = str;
int length = 0;
bool typeFound = false;
for (; *str != '\0'; str++)
{
switch(*str)
{
case ' ':
{
if (!typeFound)
break;
NewHolder<TypeName> tn(new (nothrow) TypeName());
if (tn == NULL)
return E_OUTOFMEMORY;
tn->typeName = new (nothrow) char[length + 1];
if (tn->typeName == NULL)
return E_OUTOFMEMORY;
tn.SuppressRelease();
MAKE_UTF8PTR_FROMWIDE_NOTHROW(temp, currentType);
if (temp == NULL)
return E_OUTOFMEMORY;
memcpy(tn->typeName, temp, length * sizeof(char));
tn->typeName[length] = '\0';
tn->next = pNames;
pNames = tn;
typeFound = false;
length = 0;
break;
}
default:
if (!typeFound)
currentType = str;
typeFound = true;
length++;
break;
}
}
if (typeFound)
{
NewHolder<TypeName> tn(new (nothrow) TypeName());
if (tn == NULL)
return E_OUTOFMEMORY;
tn->typeName = new (nothrow) char[length + 1];
if (tn->typeName == NULL)
return E_OUTOFMEMORY;
tn.SuppressRelease();
MAKE_UTF8PTR_FROMWIDE_NOTHROW(temp, currentType);
if (temp == NULL)
return E_OUTOFMEMORY;
memcpy(tn->typeName, temp, length * sizeof(char));
tn->typeName[length] = '\0';
tn->next = pNames;
pNames = tn;
}
return S_OK;
}
TypeNamesList::~TypeNamesList()
{
CONTRACTL {
NOTHROW;
FORBID_FAULT;
GC_NOTRIGGER;
MODE_ANY;
} CONTRACTL_END;
while (pNames)
{
delete [] pNames->typeName;
TypeName *tmp = pNames;
pNames = pNames->next;
delete tmp;
}
}
bool TypeNamesList::IsInList(LPCUTF8 typeName)
{
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
CANNOT_TAKE_LOCK;
PRECONDITION(CheckPointer(typeName));
} CONTRACTL_END;
TypeName *tnTemp = pNames;
while (tnTemp)
{
if (strstr(typeName, tnTemp->typeName) != typeName)
tnTemp = tnTemp->next;
else
return true;
}
return false;
}
#endif // _DEBUG
#ifdef FEATURE_COMINTEROP
void EEConfig::SetLogCCWRefCountChangeEnabled(bool newVal)
{
LIMITED_METHOD_CONTRACT;
// logically we want pszLogCCWRefCountChange != NULL to force bLogCCWRefCountChange to be true
bLogCCWRefCountChange = (newVal || pszLogCCWRefCountChange != NULL);
}
bool EEConfig::ShouldLogCCWRefCountChange(LPCUTF8 pszClassName, LPCUTF8 pszNamespace) const
{
CONTRACTL {
NOTHROW;
GC_NOTRIGGER;
} CONTRACTL_END
if (pszLogCCWRefCountChange == NULL)
return false;
// check simple class name
if (strcmp(pszLogCCWRefCountChange, "*") == 0 ||
strcmp(pszLogCCWRefCountChange, pszClassName) == 0)
return true;
// check namespace DOT class name
LPCUTF8 dot = strrchr(pszLogCCWRefCountChange, '.');
if (dot != NULL)
{
if (strncmp(pszLogCCWRefCountChange, pszNamespace, dot - pszLogCCWRefCountChange) == 0 &&
strcmp(dot + 1, pszClassName) == 0)
return true;
}
return false;
}
#endif // FEATURE_COMINTEROP
|