| 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 | // |
| 20 | bool g_fAllowNativeImages = true; |
| 21 | |
| 22 | // |
| 23 | // Default install library |
| 24 | // |
| 25 | const WCHAR g_pwBaseLibrary[] = CoreLibName_IL_W; |
| 26 | const WCHAR g_pwBaseLibraryName[] = CoreLibName_W; |
| 27 | const char g_psBaseLibrary[] = CoreLibName_IL_A; |
| 28 | const char g_psBaseLibraryName[] = CoreLibName_A; |
| 29 | const char g_psBaseLibrarySatelliteAssemblyName[] = CoreLibSatelliteName_A; |
| 30 | |
| 31 | Volatile<LONG> g_TrapReturningThreads; |
| 32 | |
| 33 | HINSTANCE g_pMSCorEE; |
| 34 | BBSweep 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. |
| 39 | Volatile<LONG> g_trtChgStamp = 0; |
| 40 | Volatile<LONG> g_trtChgInFlight = 0; |
| 41 | |
| 42 | const char * g_ExceptionFile; // Source of the last thrown exception (COMPLUSThrow()) |
| 43 | DWORD g_ExceptionLine; // ... ditto ... |
| 44 | void * g_ExceptionEIP; // Managed EIP of the last guy to call JITThrow. |
| 45 | #endif // _DEBUG |
| 46 | void * g_LastAccessViolationEIP; // The EIP of the place we last threw an AV. Used to diagnose stress issues. |
| 47 | |
| 48 | #endif // #ifndef DACCESS_COMPILE |
| 49 | GPTR_IMPL(IdDispenser, g_pThinLockThreadIdDispenser); |
| 50 | |
| 51 | GPTR_IMPL(IdDispenser, g_pModuleIndexDispenser); |
| 52 | |
| 53 | IBCLogger g_IBCLogger; |
| 54 | |
| 55 | // For [<I1, etc. up to and including [Object |
| 56 | GARY_IMPL(PTR_ArrayTypeDesc, g_pPredefinedArrayTypes, ELEMENT_TYPE_MAX); |
| 57 | |
| 58 | GPTR_IMPL(EEConfig, g_pConfig); // configuration data (from the registry) |
| 59 | |
| 60 | GPTR_IMPL(MethodTable, g_pObjectClass); |
| 61 | GPTR_IMPL(MethodTable, g_pRuntimeTypeClass); |
| 62 | GPTR_IMPL(MethodTable, g_pCanonMethodTableClass); // System.__Canon |
| 63 | GPTR_IMPL(MethodTable, g_pStringClass); |
| 64 | GPTR_IMPL(MethodTable, g_pArrayClass); |
| 65 | GPTR_IMPL(MethodTable, g_pSZArrayHelperClass); |
| 66 | GPTR_IMPL(MethodTable, g_pNullableClass); |
| 67 | GPTR_IMPL(MethodTable, g_pByReferenceClass); |
| 68 | GPTR_IMPL(MethodTable, g_pExceptionClass); |
| 69 | GPTR_IMPL(MethodTable, g_pThreadAbortExceptionClass); |
| 70 | GPTR_IMPL(MethodTable, g_pOutOfMemoryExceptionClass); |
| 71 | GPTR_IMPL(MethodTable, g_pStackOverflowExceptionClass); |
| 72 | GPTR_IMPL(MethodTable, g_pExecutionEngineExceptionClass); |
| 73 | GPTR_IMPL(MethodTable, g_pDelegateClass); |
| 74 | GPTR_IMPL(MethodTable, g_pMulticastDelegateClass); |
| 75 | GPTR_IMPL(MethodTable, g_pValueTypeClass); |
| 76 | GPTR_IMPL(MethodTable, g_pEnumClass); |
| 77 | GPTR_IMPL(MethodTable, g_pThreadClass); |
| 78 | GPTR_IMPL(MethodTable, g_pFreeObjectMethodTable); |
| 79 | GPTR_IMPL(MethodTable, g_pOverlappedDataClass); |
| 80 | |
| 81 | GPTR_IMPL(MethodTable, g_TypedReferenceMT); |
| 82 | |
| 83 | GPTR_IMPL(MethodTable, g_pByteArrayMT); |
| 84 | |
| 85 | #ifdef FEATURE_COMINTEROP |
| 86 | GPTR_IMPL(MethodTable, g_pBaseCOMObject); |
| 87 | GPTR_IMPL(MethodTable, g_pBaseRuntimeClass); |
| 88 | #endif |
| 89 | |
| 90 | #ifdef FEATURE_ICASTABLE |
| 91 | GPTR_IMPL(MethodTable, g_pICastableInterface); |
| 92 | #endif // FEATURE_ICASTABLE |
| 93 | |
| 94 | |
| 95 | GPTR_IMPL(MethodDesc, g_pExecuteBackoutCodeHelperMethod); |
| 96 | |
| 97 | GPTR_IMPL(MethodDesc, g_pObjectFinalizerMD); |
| 98 | |
| 99 | GPTR_IMPL(Thread,g_pFinalizerThread); |
| 100 | GPTR_IMPL(Thread,g_pSuspensionThread); |
| 101 | |
| 102 | // Global SyncBlock cache |
| 103 | GPTR_IMPL(SyncTableEntry,g_pSyncTable); |
| 104 | |
| 105 | #ifdef STRESS_LOG |
| 106 | GPTR_IMPL_INIT(StressLog, g_pStressLog, &StressLog::theLog); |
| 107 | #endif |
| 108 | |
| 109 | #ifdef FEATURE_COMINTEROP |
| 110 | // Global RCW cleanup list |
| 111 | GPTR_IMPL(RCWCleanupList,g_pRCWCleanupList); |
| 112 | #endif // FEATURE_COMINTEROP |
| 113 | |
| 114 | #ifdef FEATURE_INTEROP_DEBUGGING |
| 115 | GVAL_IMPL_INIT(DWORD, g_debuggerWordTLSIndex, TLS_OUT_OF_INDEXES); |
| 116 | #endif |
| 117 | GVAL_IMPL_INIT(DWORD, g_TlsIndex, TLS_OUT_OF_INDEXES); |
| 118 | |
| 119 | #ifndef DACCESS_COMPILE |
| 120 | |
| 121 | // <TODO> @TODO - PROMOTE. </TODO> |
| 122 | OBJECTHANDLE g_pPreallocatedOutOfMemoryException; |
| 123 | OBJECTHANDLE g_pPreallocatedStackOverflowException; |
| 124 | OBJECTHANDLE g_pPreallocatedExecutionEngineException; |
| 125 | OBJECTHANDLE g_pPreallocatedRudeThreadAbortException; |
| 126 | OBJECTHANDLE g_pPreallocatedThreadAbortException; |
| 127 | OBJECTHANDLE g_pPreallocatedSentinelObject; |
| 128 | OBJECTHANDLE g_pPreallocatedBaseException; |
| 129 | |
| 130 | // |
| 131 | // |
| 132 | // Global System Info |
| 133 | // |
| 134 | SYSTEM_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 |
| 139 | SpinConstants 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) |
| 148 | ETW::CEtwTracer * g_pEtwTracer = NULL; |
| 149 | |
| 150 | #endif // #ifndef DACCESS_COMPILE |
| 151 | |
| 152 | // |
| 153 | // Support for the COM+ Debugger. |
| 154 | // |
| 155 | GPTR_IMPL(DebugInterface, g_pDebugInterface); |
| 156 | // A managed debugger may set this flag to high from out of process. |
| 157 | GVAL_IMPL_INIT(DWORD, g_CORDebuggerControlFlags, DBCF_NORMAL_OPERATION); |
| 158 | |
| 159 | #ifdef DEBUGGING_SUPPORTED |
| 160 | GPTR_IMPL(EEDbgInterfaceImpl, g_pEEDbgInterfaceImpl); |
| 161 | #endif // DEBUGGING_SUPPORTED |
| 162 | |
| 163 | #if defined(PROFILING_SUPPORTED_DATA) || defined(PROFILING_SUPPPORTED) |
| 164 | // Profiling support |
| 165 | HINSTANCE g_pDebuggerDll = NULL; |
| 166 | |
| 167 | GVAL_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 |
| 173 | int g_IGCconcurrent = 1; |
| 174 | |
| 175 | int g_IGCHoardVM = 0; |
| 176 | |
| 177 | #ifdef GCTRIMCOMMIT |
| 178 | |
| 179 | int g_IGCTrimCommit = 0; |
| 180 | |
| 181 | #endif |
| 182 | |
| 183 | BOOL g_fEnableETW = FALSE; |
| 184 | |
| 185 | BOOL g_fEnableARM = FALSE; |
| 186 | |
| 187 | // |
| 188 | // Global state variable indicating if the EE is in its init phase. |
| 189 | // |
| 190 | bool 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. |
| 200 | GVAL_IMPL(bool, g_fProcessDetach); |
| 201 | |
| 202 | GVAL_IMPL_INIT(DWORD, g_fEEShutDown, 0); |
| 203 | |
| 204 | #ifndef FEATURE_PAL |
| 205 | GVAL_IMPL(SIZE_T, g_runtimeLoadedBaseAddress); |
| 206 | GVAL_IMPL(SIZE_T, g_runtimeVirtualSize); |
| 207 | #endif // !FEATURE_PAL |
| 208 | |
| 209 | #ifndef DACCESS_COMPILE |
| 210 | |
| 211 | Volatile<LONG> g_fForbidEnterEE = false; |
| 212 | bool g_fManagedAttach = false; |
| 213 | bool g_fNoExceptions = false; |
| 214 | #ifdef FEATURE_COMINTEROP |
| 215 | bool g_fShutDownCOM = false; |
| 216 | #endif //FEATURE_COMINTEROP |
| 217 | |
| 218 | DWORD g_FinalizerWaiterStatus = 0; |
| 219 | |
| 220 | // |
| 221 | // Do we own the lifetime of the process, ie. is it an EXE? |
| 222 | // |
| 223 | bool g_fWeControlLifetime = false; |
| 224 | |
| 225 | #ifdef _DEBUG |
| 226 | // The following should only be used for assertions. (Famous last words). |
| 227 | bool dbg_fDrasticShutdown = false; |
| 228 | #endif |
| 229 | bool g_fInControlC = false; |
| 230 | |
| 231 | // |
| 232 | // |
| 233 | // IJW needs the shim HINSTANCE |
| 234 | // |
| 235 | HINSTANCE g_hInstShim = NULL; |
| 236 | |
| 237 | #endif // #ifndef DACCESS_COMPILE |
| 238 | |
| 239 | #ifdef DACCESS_COMPILE |
| 240 | |
| 241 | void 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 | |
| 257 | void 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 | // |
| 271 | extern "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 | |