1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4//
5// vars.cpp - Global Var definitions
6//
7
8
9
10#include "common.h"
11#include "vars.hpp"
12#include "cordbpriv.h"
13#include "eeprofinterfaces.h"
14#include "bbsweep.h"
15
16#ifndef DACCESS_COMPILE
17//
18// Allow use of native images?
19//
20bool g_fAllowNativeImages = true;
21
22//
23// Default install library
24//
25const WCHAR g_pwBaseLibrary[] = CoreLibName_IL_W;
26const WCHAR g_pwBaseLibraryName[] = CoreLibName_W;
27const char g_psBaseLibrary[] = CoreLibName_IL_A;
28const char g_psBaseLibraryName[] = CoreLibName_A;
29const char g_psBaseLibrarySatelliteAssemblyName[] = CoreLibSatelliteName_A;
30
31Volatile<LONG> g_TrapReturningThreads;
32
33HINSTANCE g_pMSCorEE;
34BBSweep g_BBSweep;
35
36#ifdef _DEBUG
37// next two variables are used to enforce an ASSERT in Thread::DbgFindThread
38// that does not allow g_TrapReturningThreads to creep up unchecked.
39Volatile<LONG> g_trtChgStamp = 0;
40Volatile<LONG> g_trtChgInFlight = 0;
41
42const char * g_ExceptionFile; // Source of the last thrown exception (COMPLUSThrow())
43DWORD g_ExceptionLine; // ... ditto ...
44void * g_ExceptionEIP; // Managed EIP of the last guy to call JITThrow.
45#endif // _DEBUG
46void * g_LastAccessViolationEIP; // The EIP of the place we last threw an AV. Used to diagnose stress issues.
47
48#endif // #ifndef DACCESS_COMPILE
49GPTR_IMPL(IdDispenser, g_pThinLockThreadIdDispenser);
50
51GPTR_IMPL(IdDispenser, g_pModuleIndexDispenser);
52
53IBCLogger g_IBCLogger;
54
55// For [<I1, etc. up to and including [Object
56GARY_IMPL(PTR_ArrayTypeDesc, g_pPredefinedArrayTypes, ELEMENT_TYPE_MAX);
57
58GPTR_IMPL(EEConfig, g_pConfig); // configuration data (from the registry)
59
60GPTR_IMPL(MethodTable, g_pObjectClass);
61GPTR_IMPL(MethodTable, g_pRuntimeTypeClass);
62GPTR_IMPL(MethodTable, g_pCanonMethodTableClass); // System.__Canon
63GPTR_IMPL(MethodTable, g_pStringClass);
64GPTR_IMPL(MethodTable, g_pArrayClass);
65GPTR_IMPL(MethodTable, g_pSZArrayHelperClass);
66GPTR_IMPL(MethodTable, g_pNullableClass);
67GPTR_IMPL(MethodTable, g_pByReferenceClass);
68GPTR_IMPL(MethodTable, g_pExceptionClass);
69GPTR_IMPL(MethodTable, g_pThreadAbortExceptionClass);
70GPTR_IMPL(MethodTable, g_pOutOfMemoryExceptionClass);
71GPTR_IMPL(MethodTable, g_pStackOverflowExceptionClass);
72GPTR_IMPL(MethodTable, g_pExecutionEngineExceptionClass);
73GPTR_IMPL(MethodTable, g_pDelegateClass);
74GPTR_IMPL(MethodTable, g_pMulticastDelegateClass);
75GPTR_IMPL(MethodTable, g_pValueTypeClass);
76GPTR_IMPL(MethodTable, g_pEnumClass);
77GPTR_IMPL(MethodTable, g_pThreadClass);
78GPTR_IMPL(MethodTable, g_pFreeObjectMethodTable);
79GPTR_IMPL(MethodTable, g_pOverlappedDataClass);
80
81GPTR_IMPL(MethodTable, g_TypedReferenceMT);
82
83GPTR_IMPL(MethodTable, g_pByteArrayMT);
84
85#ifdef FEATURE_COMINTEROP
86GPTR_IMPL(MethodTable, g_pBaseCOMObject);
87GPTR_IMPL(MethodTable, g_pBaseRuntimeClass);
88#endif
89
90#ifdef FEATURE_ICASTABLE
91GPTR_IMPL(MethodTable, g_pICastableInterface);
92#endif // FEATURE_ICASTABLE
93
94
95GPTR_IMPL(MethodDesc, g_pExecuteBackoutCodeHelperMethod);
96
97GPTR_IMPL(MethodDesc, g_pObjectFinalizerMD);
98
99GPTR_IMPL(Thread,g_pFinalizerThread);
100GPTR_IMPL(Thread,g_pSuspensionThread);
101
102// Global SyncBlock cache
103GPTR_IMPL(SyncTableEntry,g_pSyncTable);
104
105#ifdef STRESS_LOG
106GPTR_IMPL_INIT(StressLog, g_pStressLog, &StressLog::theLog);
107#endif
108
109#ifdef FEATURE_COMINTEROP
110// Global RCW cleanup list
111GPTR_IMPL(RCWCleanupList,g_pRCWCleanupList);
112#endif // FEATURE_COMINTEROP
113
114#ifdef FEATURE_INTEROP_DEBUGGING
115GVAL_IMPL_INIT(DWORD, g_debuggerWordTLSIndex, TLS_OUT_OF_INDEXES);
116#endif
117GVAL_IMPL_INIT(DWORD, g_TlsIndex, TLS_OUT_OF_INDEXES);
118
119#ifndef DACCESS_COMPILE
120
121// <TODO> @TODO - PROMOTE. </TODO>
122OBJECTHANDLE g_pPreallocatedOutOfMemoryException;
123OBJECTHANDLE g_pPreallocatedStackOverflowException;
124OBJECTHANDLE g_pPreallocatedExecutionEngineException;
125OBJECTHANDLE g_pPreallocatedRudeThreadAbortException;
126OBJECTHANDLE g_pPreallocatedThreadAbortException;
127OBJECTHANDLE g_pPreallocatedSentinelObject;
128OBJECTHANDLE g_pPreallocatedBaseException;
129
130//
131//
132// Global System Info
133//
134SYSTEM_INFO g_SystemInfo;
135
136// Configurable constants used across our spin locks
137// Initialization here is necessary so that we have meaningful values before the runtime is started
138// These initial values were selected to match the defaults, but anything reasonable is close enough
139SpinConstants g_SpinConstants = {
140 50, // dwInitialDuration
141 40000, // dwMaximumDuration - ideally (20000 * max(2, numProc))
142 3, // dwBackoffFactor
143 10, // dwRepetitions
144 0 // dwMonitorSpinCount
145};
146
147// support for Event Tracing for Windows (ETW)
148ETW::CEtwTracer * g_pEtwTracer = NULL;
149
150#endif // #ifndef DACCESS_COMPILE
151
152//
153// Support for the COM+ Debugger.
154//
155GPTR_IMPL(DebugInterface, g_pDebugInterface);
156// A managed debugger may set this flag to high from out of process.
157GVAL_IMPL_INIT(DWORD, g_CORDebuggerControlFlags, DBCF_NORMAL_OPERATION);
158
159#ifdef DEBUGGING_SUPPORTED
160GPTR_IMPL(EEDbgInterfaceImpl, g_pEEDbgInterfaceImpl);
161#endif // DEBUGGING_SUPPORTED
162
163#if defined(PROFILING_SUPPORTED_DATA) || defined(PROFILING_SUPPPORTED)
164// Profiling support
165HINSTANCE g_pDebuggerDll = NULL;
166
167GVAL_IMPL(ProfControlBlock, g_profControlBlock);
168#endif // defined(PROFILING_SUPPORTED_DATA) || defined(PROFILING_SUPPPORTED)
169
170#ifndef DACCESS_COMPILE
171
172// Global default for Concurrent GC. The default is value is 1
173int g_IGCconcurrent = 1;
174
175int g_IGCHoardVM = 0;
176
177#ifdef GCTRIMCOMMIT
178
179int g_IGCTrimCommit = 0;
180
181#endif
182
183BOOL g_fEnableETW = FALSE;
184
185BOOL g_fEnableARM = FALSE;
186
187//
188// Global state variable indicating if the EE is in its init phase.
189//
190bool g_fEEInit = false;
191
192//
193// Global state variables indicating which stage of shutdown we are in
194//
195
196#endif // #ifndef DACCESS_COMPILE
197
198// See comments at code:EEShutDown for details on how and why this gets set. Use
199// code:IsAtProcessExit to read this.
200GVAL_IMPL(bool, g_fProcessDetach);
201
202GVAL_IMPL_INIT(DWORD, g_fEEShutDown, 0);
203
204#ifndef FEATURE_PAL
205GVAL_IMPL(SIZE_T, g_runtimeLoadedBaseAddress);
206GVAL_IMPL(SIZE_T, g_runtimeVirtualSize);
207#endif // !FEATURE_PAL
208
209#ifndef DACCESS_COMPILE
210
211Volatile<LONG> g_fForbidEnterEE = false;
212bool g_fManagedAttach = false;
213bool g_fNoExceptions = false;
214#ifdef FEATURE_COMINTEROP
215bool g_fShutDownCOM = false;
216#endif //FEATURE_COMINTEROP
217
218DWORD g_FinalizerWaiterStatus = 0;
219
220//
221// Do we own the lifetime of the process, ie. is it an EXE?
222//
223bool g_fWeControlLifetime = false;
224
225#ifdef _DEBUG
226// The following should only be used for assertions. (Famous last words).
227bool dbg_fDrasticShutdown = false;
228#endif
229bool g_fInControlC = false;
230
231//
232//
233// IJW needs the shim HINSTANCE
234//
235HINSTANCE g_hInstShim = NULL;
236
237#endif // #ifndef DACCESS_COMPILE
238
239#ifdef DACCESS_COMPILE
240
241void OBJECTHANDLE_EnumMemoryRegions(OBJECTHANDLE handle)
242{
243 SUPPORTS_DAC;
244 PTR_TADDR ref = PTR_TADDR(handle);
245 if (ref.IsValid())
246 {
247 ref.EnumMem();
248
249 PTR_Object obj = PTR_Object(*ref);
250 if (obj.IsValid())
251 {
252 obj->EnumMemoryRegions();
253 }
254 }
255}
256
257void OBJECTREF_EnumMemoryRegions(OBJECTREF ref)
258{
259 if (ref.IsValid())
260 {
261 ref->EnumMemoryRegions();
262 }
263}
264
265#endif // #ifdef DACCESS_COMPILE
266
267#ifndef DACCESS_COMPILE
268//
269// We need the following to be the compiler's notion of volatile.
270//
271extern "C" RAW_KEYWORD(volatile) const GSCookie s_gsCookie = 0;
272
273#else
274__GlobalVal< GSCookie > s_gsCookie(&g_dacGlobals.dac__s_gsCookie);
275#endif //!DACCESS_COMPILE
276
277//==============================================================================
278
279