summaryrefslogtreecommitdiff
path: root/src/vm/vars.cpp
blob: 626ca3c9d3196817d67ef0759f20e66a667bd5ae (plain)
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
// 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.
//
// vars.cpp - Global Var definitions
//



#include "common.h"
#include "vars.hpp"
#include "cordbpriv.h"
#include "eeprofinterfaces.h"
#include "bbsweep.h"

#ifndef DACCESS_COMPILE
//
// Allow use of native images?
//
bool g_fAllowNativeImages = true;

//
// Default install library
//
const WCHAR g_pwBaseLibrary[]     = CoreLibName_IL_W;
const WCHAR g_pwBaseLibraryName[] = CoreLibName_W;
const char g_psBaseLibrary[]      = CoreLibName_IL_A;
const char g_psBaseLibraryName[]  = CoreLibName_A;
const char g_psBaseLibrarySatelliteAssemblyName[]  = CoreLibSatelliteName_A;

#ifdef FEATURE_COMINTEROP
const WCHAR g_pwBaseLibraryTLB[]  = CoreLibName_TLB_W;
const char g_psBaseLibraryTLB[]   = CoreLibName_TLB_A;
#endif  // FEATURE_COMINTEROP

Volatile<LONG>       g_TrapReturningThreads;

HINSTANCE            g_pMSCorEE;
BBSweep              g_BBSweep;

#ifdef _DEBUG
// next two variables are used to enforce an ASSERT in Thread::DbgFindThread
// that does not allow g_TrapReturningThreads to creep up unchecked.
Volatile<LONG>       g_trtChgStamp = 0;
Volatile<LONG>       g_trtChgInFlight = 0;

char *               g_ExceptionFile;   // Source of the last thrown exception (COMPLUSThrow())
DWORD                g_ExceptionLine;   // ... ditto ...
void *               g_ExceptionEIP;    // Managed EIP of the last guy to call JITThrow.
#endif // _DEBUG
void *               g_LastAccessViolationEIP;  // The EIP of the place we last threw an AV.   Used to diagnose stress issues.  

#endif // #ifndef DACCESS_COMPILE
GPTR_IMPL(IdDispenser,       g_pThinLockThreadIdDispenser);

GPTR_IMPL(IdDispenser,       g_pModuleIndexDispenser);

IBCLogger                    g_IBCLogger;

// For [<I1, etc. up to and including [Object
GARY_IMPL(PTR_ArrayTypeDesc, g_pPredefinedArrayTypes, ELEMENT_TYPE_MAX);

GPTR_IMPL(EEConfig, g_pConfig);     // configuration data (from the registry)

GPTR_IMPL(MethodTable,      g_pObjectClass);
GPTR_IMPL(MethodTable,      g_pRuntimeTypeClass);
GPTR_IMPL(MethodTable,      g_pCanonMethodTableClass);  // System.__Canon
GPTR_IMPL(MethodTable,      g_pStringClass);
GPTR_IMPL(MethodTable,      g_pArrayClass);
GPTR_IMPL(MethodTable,      g_pSZArrayHelperClass);
GPTR_IMPL(MethodTable,      g_pNullableClass);
#ifdef FEATURE_SPAN_OF_T
GPTR_IMPL(MethodTable,      g_pByReferenceClass);
#endif
GPTR_IMPL(MethodTable,      g_pExceptionClass);
GPTR_IMPL(MethodTable,      g_pThreadAbortExceptionClass);
GPTR_IMPL(MethodTable,      g_pOutOfMemoryExceptionClass);
GPTR_IMPL(MethodTable,      g_pStackOverflowExceptionClass);
GPTR_IMPL(MethodTable,      g_pExecutionEngineExceptionClass);
GPTR_IMPL(MethodTable,      g_pDelegateClass);
GPTR_IMPL(MethodTable,      g_pMulticastDelegateClass);
GPTR_IMPL(MethodTable,      g_pValueTypeClass);
GPTR_IMPL(MethodTable,      g_pEnumClass);
GPTR_IMPL(MethodTable,      g_pThreadClass);
#ifdef FEATURE_CER
GPTR_IMPL(MethodTable,      g_pCriticalFinalizerObjectClass);
#endif
#ifndef FEATURE_CORECLR
GPTR_IMPL(MethodTable,      g_pAsyncFileStream_AsyncResultClass);
#endif // !FEATURE_CORECLR
GPTR_IMPL(MethodTable,      g_pFreeObjectMethodTable);
GPTR_IMPL(MethodTable,      g_pOverlappedDataClass);

GPTR_IMPL(MethodTable,      g_TypedReferenceMT);

GPTR_IMPL(MethodTable,      g_pByteArrayMT);

#ifdef FEATURE_COMINTEROP
GPTR_IMPL(MethodTable,      g_pBaseCOMObject);
GPTR_IMPL(MethodTable,      g_pBaseRuntimeClass);
#endif

#ifdef FEATURE_ICASTABLE
GPTR_IMPL(MethodTable,      g_pICastableInterface);
#endif // FEATURE_ICASTABLE


#ifdef FEATURE_CER
GPTR_IMPL(MethodDesc,       g_pPrepareConstrainedRegionsMethod);
#endif
GPTR_IMPL(MethodDesc,       g_pExecuteBackoutCodeHelperMethod);

GPTR_IMPL(MethodDesc,       g_pObjectCtorMD);
GPTR_IMPL(MethodDesc,       g_pObjectFinalizerMD);

GPTR_IMPL(Thread,g_pFinalizerThread);
GPTR_IMPL(Thread,g_pSuspensionThread);

// Global SyncBlock cache
GPTR_IMPL(SyncTableEntry,g_pSyncTable);

#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
DWORD g_dwHandles = 0;
#endif // ENABLE_PERF_COUNTERS || FEATURE_EVENT_TRACE

#ifdef STRESS_LOG
GPTR_IMPL_INIT(StressLog, g_pStressLog, &StressLog::theLog);
#endif

#ifdef FEATURE_COMINTEROP
// Global RCW cleanup list
GPTR_IMPL(RCWCleanupList,g_pRCWCleanupList);
#endif // FEATURE_COMINTEROP


#ifndef DACCESS_COMPILE

// <TODO> @TODO Remove eventually - </TODO> determines whether the verifier throws an exception when something fails
bool                g_fVerifierOff;

#ifndef FEATURE_CORECLR
IAssemblyUsageLog   *g_pIAssemblyUsageLogGac;
#endif

// <TODO> @TODO - PROMOTE. </TODO>
OBJECTHANDLE         g_pPreallocatedOutOfMemoryException;
OBJECTHANDLE         g_pPreallocatedStackOverflowException;
OBJECTHANDLE         g_pPreallocatedExecutionEngineException;
OBJECTHANDLE         g_pPreallocatedRudeThreadAbortException;
OBJECTHANDLE         g_pPreallocatedThreadAbortException;
OBJECTHANDLE         g_pPreallocatedSentinelObject;
OBJECTHANDLE         g_pPreallocatedBaseException;

#ifdef FEATURE_CAS_POLICY
CertificateCache *g_pCertificateCache = NULL;
#endif

// 
//
// Global System Info
//
SYSTEM_INFO g_SystemInfo;

// Configurable constants used across our spin locks
// Initialization here is necessary so that we have meaningful values before the runtime is started
// These initial values were selected to match the defaults, but anything reasonable is close enough
SpinConstants g_SpinConstants = { 
    50,        // dwInitialDuration 
    40000,     // dwMaximumDuration - ideally (20000 * max(2, numProc))
    3,         // dwBackoffFactor
    10         // dwRepetitions
};

// support for Event Tracing for Windows (ETW)
ETW::CEtwTracer * g_pEtwTracer = NULL;

#endif // #ifndef DACCESS_COMPILE

#ifdef FEATURE_IPCMAN
// support for IPCManager 
GPTR_IMPL(IPCWriterInterface, g_pIPCManagerInterface);
#endif // FEATURE_IPCMAN

//
// Support for the COM+ Debugger.
//
GPTR_IMPL(DebugInterface,     g_pDebugInterface);
// A managed debugger may set this flag to high from out of process.
GVAL_IMPL_INIT(DWORD,         g_CORDebuggerControlFlags, DBCF_NORMAL_OPERATION);

#ifdef DEBUGGING_SUPPORTED
GPTR_IMPL(EEDbgInterfaceImpl, g_pEEDbgInterfaceImpl);
#endif // DEBUGGING_SUPPORTED

#if defined(PROFILING_SUPPORTED_DATA) || defined(PROFILING_SUPPPORTED)
// Profiling support
HINSTANCE           g_pDebuggerDll = NULL;

GVAL_IMPL(ProfControlBlock, g_profControlBlock);
#endif // defined(PROFILING_SUPPORTED_DATA) || defined(PROFILING_SUPPPORTED)

#ifndef DACCESS_COMPILE

// Global default for Concurrent GC. The default is value is 1
int g_IGCconcurrent = 1;

int g_IGCHoardVM = 0;

#ifdef GCTRIMCOMMIT

int g_IGCTrimCommit = 0;

#endif

BOOL g_fEnableETW = FALSE;

BOOL g_fEnableARM = FALSE;

//
// Global state variable indicating if the EE is in its init phase.
//
bool g_fEEInit = false;

//
// Global state variables indicating which stage of shutdown we are in
//

#endif // #ifndef DACCESS_COMPILE

// See comments at code:EEShutDown for details on how and why this gets set.  Use
// code:IsAtProcessExit to read this.
GVAL_IMPL(bool, g_fProcessDetach);

GVAL_IMPL_INIT(DWORD, g_fEEShutDown, 0);

#ifndef FEATURE_PAL
GVAL_IMPL(SIZE_T, g_runtimeLoadedBaseAddress);
GVAL_IMPL(SIZE_T, g_runtimeVirtualSize);
#endif // !FEATURE_PAL

#ifndef DACCESS_COMPILE

Volatile<LONG> g_fForbidEnterEE = false;
bool g_fFinalizerRunOnShutDown = false;
bool g_fManagedAttach = false;
bool g_fNoExceptions = false;
#ifdef FEATURE_COMINTEROP
bool g_fShutDownCOM = false;
#endif //FEATURE_COMINTEROP

DWORD g_FinalizerWaiterStatus = 0;

const WCHAR g_pwzClickOnceEnv_FullName[] = W("__COR_COMMAND_LINE_APP_FULL_NAME__");
const WCHAR g_pwzClickOnceEnv_Manifest[] = W("__COR_COMMAND_LINE_MANIFEST__");
const WCHAR g_pwzClickOnceEnv_Parameter[] = W("__COR_COMMAND_LINE_PARAMETER__");

#ifdef FEATURE_LOADER_OPTIMIZATION
DWORD g_dwGlobalSharePolicy = AppDomain::SHARE_POLICY_UNSPECIFIED;
#endif

//
// Do we own the lifetime of the process, ie. is it an EXE?
//
bool g_fWeControlLifetime = false;

#ifdef _DEBUG
// The following should only be used for assertions.  (Famous last words).
bool dbg_fDrasticShutdown = false;
#endif
bool g_fInControlC = false;

//
// Cached command line file provided by the host.
//
LPWSTR g_pCachedCommandLine = NULL;
LPWSTR g_pCachedModuleFileName = 0;

// host configuration file. If set, it is added to every AppDomain (fusion context)
LPCWSTR  g_pszHostConfigFile = NULL;
SIZE_T  g_dwHostConfigFile = 0;

// AppDomainManager assembly and type names provided as environment variables.
LPWSTR g_wszAppDomainManagerAsm = NULL;
LPWSTR g_wszAppDomainManagerType = NULL;
bool g_fDomainManagerInitialized = false;

//
// IJW needs the shim HINSTANCE
//
HINSTANCE g_hInstShim = NULL;

char g_Version[] = VER_PRODUCTVERSION_STR;

#endif // #ifndef DACCESS_COMPILE

#ifdef DACCESS_COMPILE

void OBJECTHANDLE_EnumMemoryRegions(OBJECTHANDLE handle)
{
    SUPPORTS_DAC;
    PTR_TADDR ref = PTR_TADDR(handle);
    if (ref.IsValid())
    {
        ref.EnumMem();
        
        PTR_Object obj = PTR_Object(*ref);
        if (obj.IsValid())
        {
            obj->EnumMemoryRegions();
        }
    }
}

void OBJECTREF_EnumMemoryRegions(OBJECTREF ref)
{
    if (ref.IsValid())
    {
        ref->EnumMemoryRegions();
    }
}

#endif // #ifdef DACCESS_COMPILE

#ifndef DACCESS_COMPILE
//
// We need the following to be the compiler's notion of volatile.
//
extern "C" RAW_KEYWORD(volatile) const GSCookie s_gsCookie = 0;

#else
__GlobalVal< GSCookie > s_gsCookie(&g_dacGlobals.dac__s_gsCookie);
#endif //!DACCESS_COMPILE

BOOL IsCompilationProcess()
{
    LIMITED_METHOD_DAC_CONTRACT;
#if defined(FEATURE_NATIVE_IMAGE_GENERATION) && !defined(DACCESS_COMPILE)
    return g_pCEECompileInfo != NULL;
#else
    return FALSE;
#endif
}

//==============================================================================

enum NingenState
{
    kNotInitialized = 0,
    kNingenEnabled = 1,
    kNingenDisabled = 2,
};

extern int g_ningenState;
int g_ningenState = kNotInitialized;

// Removes all execution of managed or third-party code in the ngen compilation process.
BOOL NingenEnabled()
{
    LIMITED_METHOD_CONTRACT;

#ifdef CROSSGEN_COMPILE
    // Always enable ningen for cross-compile
    return TRUE;
#else // CROSSGEN_COMPILE

#ifdef FEATURE_NATIVE_IMAGE_GENERATION
    // Note that ningen is enabled by default to get byte-to-byte identical NGen images between native compile and cross-compile
    if (g_ningenState == kNotInitialized)
    {
        // This code must be idempotent as we don't have a lock to prevent a race to initialize g_ningenState.
        g_ningenState = (IsCompilationProcess() && (0 != CLRConfig::GetConfigValue(CLRConfig::INTERNAL_Ningen))) ? kNingenEnabled : kNingenDisabled;
    }

    return g_ningenState == kNingenEnabled;
#else
    return FALSE;
#endif

#endif // CROSSGEN_COMPILE
}