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.hpp
6//
7// Global variables
8//
9
10
11#ifndef _VARS_HPP
12#define _VARS_HPP
13
14// This will need ifdefs for non-x86 processors (ia64 is pointer to 128bit instructions)!
15#define SLOT PBYTE
16typedef DPTR(SLOT) PTR_SLOT;
17
18typedef LPVOID DictionaryEntry;
19
20/* Define the implementation dependent size types */
21
22#ifndef _INTPTR_T_DEFINED
23#ifdef _WIN64
24typedef __int64 intptr_t;
25#else
26typedef int intptr_t;
27#endif
28#define _INTPTR_T_DEFINED
29#endif
30
31#ifndef _UINTPTR_T_DEFINED
32#ifdef _WIN64
33typedef unsigned __int64 uintptr_t;
34#else
35typedef unsigned int uintptr_t;
36#endif
37#define _UINTPTR_T_DEFINED
38#endif
39
40#ifndef _PTRDIFF_T_DEFINED
41#ifdef _WIN64
42typedef __int64 ptrdiff_t;
43#else
44typedef int ptrdiff_t;
45#endif
46#define _PTRDIFF_T_DEFINED
47#endif
48
49
50#ifndef _SIZE_T_DEFINED
51#ifdef _WIN64
52typedef unsigned __int64 size_t;
53#else
54typedef unsigned int size_t;
55#endif
56#define _SIZE_T_DEFINED
57#endif
58
59
60#ifndef _WCHAR_T_DEFINED
61typedef unsigned short wchar_t;
62#define _WCHAR_T_DEFINED
63#endif
64
65#include "util.hpp"
66#include <corpriv.h>
67#include <cordbpriv.h>
68
69
70#include "eeprofinterfaces.h"
71#include "eehash.h"
72
73#include "profilepriv.h"
74
75#include "gcinterface.h"
76
77class ClassLoader;
78class LoaderHeap;
79class IGCHeap;
80class Object;
81class StringObject;
82class ArrayClass;
83class MethodTable;
84class MethodDesc;
85class SyncBlockCache;
86class SyncTableEntry;
87class ThreadStore;
88namespace ETW { class CEtwTracer; };
89class DebugInterface;
90class DebugInfoManager;
91class EEDbgInterfaceImpl;
92class EECodeManager;
93class Crst;
94#ifdef FEATURE_COMINTEROP
95class RCWCleanupList;
96#endif // FEATURE_COMINTEROP
97class BBSweep;
98
99//
100// loader handles are opaque types that track object pointers that have a lifetime
101// that matches that of a loader allocator
102//
103struct LOADERHANDLE__
104{
105 void* unused;
106};
107typedef TADDR LOADERHANDLE;
108
109
110#ifdef DACCESS_COMPILE
111void OBJECTHANDLE_EnumMemoryRegions(OBJECTHANDLE handle);
112void OBJECTREF_EnumMemoryRegions(OBJECTREF ref);
113#endif
114
115
116#ifdef USE_CHECKED_OBJECTREFS
117
118
119//=========================================================================
120// In the retail build, OBJECTREF is typedef'd to "Object*".
121// In the debug build, we use operator overloading to detect
122// common programming mistakes that create GC holes. The critical
123// rules are:
124//
125// 1. Your thread must have disabled preemptive GC before
126// reading or writing any OBJECTREF. When preemptive GC is enabled,
127// another other thread can suspend you at any time and
128// move or discard objects.
129// 2. You must guard your OBJECTREF's using a root pointer across
130// any code that might trigger a GC.
131//
132// Each of the overloads validate that:
133//
134// 1. Preemptive GC is currently disabled
135// 2. The object looks consistent (checked by comparing the
136// object's methodtable pointer with that of the class.)
137//
138// Limitations:
139// - Can't say
140//
141// if (or) {}
142//
143// must say
144//
145// if (or != NULL) {}
146//
147//
148//=========================================================================
149class OBJECTREF {
150 private:
151 // Holds the real object pointer.
152 // The union gives us better debugger pretty printing
153 union {
154 Object *m_asObj;
155 class StringObject* m_asString;
156 class ArrayBase* m_asArray;
157 class PtrArray* m_asPtrArray;
158 class DelegateObject* m_asDelegate;
159
160 class ReflectClassBaseObject* m_asReflectClass;
161 class ExecutionContextObject* m_asExecutionContext;
162 class AppDomainBaseObject* m_asAppDomainBase;
163 class PermissionSetObject* m_asPermissionSetObject;
164 };
165
166 public:
167 //-------------------------------------------------------------
168 // Default constructor, for non-initializing declarations:
169 //
170 // OBJECTREF or;
171 //-------------------------------------------------------------
172 OBJECTREF();
173
174 //-------------------------------------------------------------
175 // Copy constructor, for passing OBJECTREF's as function arguments.
176 //-------------------------------------------------------------
177 OBJECTREF(const OBJECTREF & objref);
178
179 //-------------------------------------------------------------
180 // To allow NULL to be used as an OBJECTREF.
181 //-------------------------------------------------------------
182 OBJECTREF(TADDR nul);
183
184 //-------------------------------------------------------------
185 // Test against NULL.
186 //-------------------------------------------------------------
187 int operator!() const;
188
189 //-------------------------------------------------------------
190 // Compare two OBJECTREF's.
191 //-------------------------------------------------------------
192 int operator==(const OBJECTREF &objref) const;
193
194 //-------------------------------------------------------------
195 // Compare two OBJECTREF's.
196 //-------------------------------------------------------------
197 int operator!=(const OBJECTREF &objref) const;
198
199 //-------------------------------------------------------------
200 // Forward method calls.
201 //-------------------------------------------------------------
202 Object* operator->();
203 const Object* operator->() const;
204
205 //-------------------------------------------------------------
206 // Assignment. We don't validate the destination so as not
207 // to break the sequence:
208 //
209 // OBJECTREF or;
210 // or = ...;
211 //-------------------------------------------------------------
212 OBJECTREF& operator=(const OBJECTREF &objref);
213 OBJECTREF& operator=(TADDR nul);
214
215 // allow explict casts
216 explicit OBJECTREF(Object *pObject);
217
218 void Validate(BOOL bDeep = TRUE, BOOL bVerifyNextHeader = TRUE, BOOL bVerifySyncBlock = TRUE);
219
220};
221
222//-------------------------------------------------------------
223// template class REF for different types of REF class to be used
224// in the debug mode
225// Template type should be a class that extends Object
226//-------------------------------------------------------------
227
228
229
230template <class T>
231class REF : public OBJECTREF
232{
233 public:
234
235 //-------------------------------------------------------------
236 // Default constructor, for non-initializing declarations:
237 //
238 // OBJECTREF or;
239 //-------------------------------------------------------------
240 REF() :OBJECTREF ()
241 {
242 LIMITED_METHOD_CONTRACT;
243 // no op
244 }
245
246 //-------------------------------------------------------------
247 // Copy constructor, for passing OBJECTREF's as function arguments.
248 //-------------------------------------------------------------
249 explicit REF(const OBJECTREF& objref) : OBJECTREF(objref)
250 {
251 LIMITED_METHOD_CONTRACT;
252 //no op
253 }
254
255
256 //-------------------------------------------------------------
257 // To allow NULL to be used as an OBJECTREF.
258 //-------------------------------------------------------------
259 REF(TADDR nul) : OBJECTREF (nul)
260 {
261 LIMITED_METHOD_CONTRACT;
262 // no op
263 }
264
265 explicit REF(T* pObject) : OBJECTREF(pObject)
266 {
267 LIMITED_METHOD_CONTRACT;
268 // no op
269 }
270
271 //-------------------------------------------------------------
272 // Forward method calls.
273 //-------------------------------------------------------------
274 T* operator->()
275 {
276 // What kind of statement can we make about member methods on Object
277 // except that we need to be in COOPERATIVE when touching them?
278 STATIC_CONTRACT_MODE_COOPERATIVE;
279 return (T *)OBJECTREF::operator->();
280 }
281
282 const T* operator->() const
283 {
284 // What kind of statement can we make about member methods on Object
285 // except that we need to be in COOPERATIVE when touching them?
286 STATIC_CONTRACT_MODE_COOPERATIVE;
287 return (const T *)OBJECTREF::operator->();
288 }
289
290 //-------------------------------------------------------------
291 // Assignment. We don't validate the destination so as not
292 // to break the sequence:
293 //
294 // OBJECTREF or;
295 // or = ...;
296 //-------------------------------------------------------------
297 REF<T> &operator=(OBJECTREF &objref)
298 {
299 STATIC_CONTRACT_NOTHROW;
300 STATIC_CONTRACT_GC_NOTRIGGER;
301 STATIC_CONTRACT_CANNOT_TAKE_LOCK;
302 STATIC_CONTRACT_MODE_COOPERATIVE;
303 return (REF<T>&)OBJECTREF::operator=(objref);
304 }
305
306};
307
308// the while (0) syntax below is to force a trailing semicolon on users of the macro
309#define VALIDATEOBJECTREF(objref) do {if ((objref) != NULL) (objref).Validate();} while (0)
310#define VALIDATEOBJECT(obj) do {if ((obj) != NULL) (obj)->Validate();} while (0)
311
312#define ObjectToOBJECTREF(obj) (OBJECTREF(obj))
313#define OBJECTREFToObject(objref) ((objref).operator-> ())
314#define ObjectToSTRINGREF(obj) (STRINGREF(obj))
315#define STRINGREFToObject(objref) (*( (StringObject**) &(objref) ))
316
317#else // _DEBUG_IMPL
318
319#define VALIDATEOBJECTREF(objref)
320#define VALIDATEOBJECT(obj)
321
322#define ObjectToOBJECTREF(obj) ((PTR_Object) (obj))
323#define OBJECTREFToObject(objref) ((PTR_Object) (objref))
324#define ObjectToSTRINGREF(obj) ((PTR_StringObject) (obj))
325#define STRINGREFToObject(objref) ((PTR_StringObject) (objref))
326
327#endif // _DEBUG_IMPL
328
329
330// <TODO> Get rid of these! Don't use them any more!</TODO>
331#define MAX_CLASSNAME_LENGTH 1024
332#define MAX_NAMESPACE_LENGTH 1024
333
334class EEConfig;
335class ClassLoaderList;
336class Module;
337class ArrayTypeDesc;
338
339#define EXTERN extern
340
341// For [<I1, etc. up to and including [Object
342GARY_DECL(PTR_ArrayTypeDesc, g_pPredefinedArrayTypes, ELEMENT_TYPE_MAX);
343
344extern "C" Volatile<LONG> g_TrapReturningThreads;
345
346EXTERN HINSTANCE g_pMSCorEE;
347EXTERN BBSweep g_BBSweep;
348EXTERN IBCLogger g_IBCLogger;
349
350#ifdef _DEBUG
351// next two variables are used to enforce an ASSERT in Thread::DbgFindThread
352// that does not allow g_TrapReturningThreads to creep up unchecked.
353EXTERN Volatile<LONG> g_trtChgStamp;
354EXTERN Volatile<LONG> g_trtChgInFlight;
355EXTERN const char * g_ExceptionFile;
356EXTERN DWORD g_ExceptionLine;
357EXTERN void * g_ExceptionEIP;
358#endif
359EXTERN void * g_LastAccessViolationEIP;
360
361GPTR_DECL(EEConfig, g_pConfig); // configuration data (from the registry)
362GPTR_DECL(MethodTable, g_pObjectClass);
363GPTR_DECL(MethodTable, g_pRuntimeTypeClass);
364GPTR_DECL(MethodTable, g_pCanonMethodTableClass); // System.__Canon
365GPTR_DECL(MethodTable, g_pStringClass);
366GPTR_DECL(MethodTable, g_pArrayClass);
367GPTR_DECL(MethodTable, g_pSZArrayHelperClass);
368GPTR_DECL(MethodTable, g_pNullableClass);
369GPTR_DECL(MethodTable, g_pByReferenceClass);
370GPTR_DECL(MethodTable, g_pExceptionClass);
371GPTR_DECL(MethodTable, g_pThreadAbortExceptionClass);
372GPTR_DECL(MethodTable, g_pOutOfMemoryExceptionClass);
373GPTR_DECL(MethodTable, g_pStackOverflowExceptionClass);
374GPTR_DECL(MethodTable, g_pExecutionEngineExceptionClass);
375GPTR_DECL(MethodTable, g_pThreadAbortExceptionClass);
376GPTR_DECL(MethodTable, g_pDelegateClass);
377GPTR_DECL(MethodTable, g_pMulticastDelegateClass);
378GPTR_DECL(MethodTable, g_pFreeObjectMethodTable);
379GPTR_DECL(MethodTable, g_pValueTypeClass);
380GPTR_DECL(MethodTable, g_pEnumClass);
381GPTR_DECL(MethodTable, g_pThreadClass);
382GPTR_DECL(MethodTable, g_pOverlappedDataClass);
383
384GPTR_DECL(MethodTable, g_TypedReferenceMT);
385
386GPTR_DECL(MethodTable, g_pByteArrayMT);
387
388#ifdef FEATURE_COMINTEROP
389GPTR_DECL(MethodTable, g_pBaseCOMObject);
390GPTR_DECL(MethodTable, g_pBaseRuntimeClass);
391#endif
392
393#ifdef FEATURE_ICASTABLE
394GPTR_DECL(MethodTable, g_pICastableInterface);
395#endif // FEATURE_ICASTABLE
396
397GPTR_DECL(MethodDesc, g_pExecuteBackoutCodeHelperMethod);
398
399GPTR_DECL(MethodDesc, g_pObjectFinalizerMD);
400
401#ifdef FEATURE_INTEROP_DEBUGGING
402GVAL_DECL(DWORD, g_debuggerWordTLSIndex);
403#endif
404GVAL_DECL(DWORD, g_TlsIndex);
405
406// Global System Information
407extern SYSTEM_INFO g_SystemInfo;
408
409// <TODO>@TODO - PROMOTE.</TODO>
410// <TODO>@TODO - I'd like to make these private members of CLRException some day.</TODO>
411EXTERN OBJECTHANDLE g_pPreallocatedOutOfMemoryException;
412EXTERN OBJECTHANDLE g_pPreallocatedStackOverflowException;
413EXTERN OBJECTHANDLE g_pPreallocatedExecutionEngineException;
414EXTERN OBJECTHANDLE g_pPreallocatedRudeThreadAbortException;
415
416// We may not be able to create a normal thread abort exception if OOM or StackOverFlow.
417// When this happens, we will use our pre-allocated thread abort exception.
418EXTERN OBJECTHANDLE g_pPreallocatedThreadAbortException;
419
420// we use this as a dummy object to indicate free space in the handle tables -- this object is never visible to the world
421EXTERN OBJECTHANDLE g_pPreallocatedSentinelObject;
422
423// We use this object to return a preallocated System.Exception instance when we have nothing
424// better to return.
425EXTERN OBJECTHANDLE g_pPreallocatedBaseException;
426
427GPTR_DECL(Thread,g_pFinalizerThread);
428GPTR_DECL(Thread,g_pSuspensionThread);
429
430// Global SyncBlock cache
431typedef DPTR(SyncTableEntry) PTR_SyncTableEntry;
432GPTR_DECL(SyncTableEntry, g_pSyncTable);
433
434#ifdef FEATURE_COMINTEROP
435// Global RCW cleanup list
436typedef DPTR(RCWCleanupList) PTR_RCWCleanupList;
437GPTR_DECL(RCWCleanupList,g_pRCWCleanupList);
438#endif // FEATURE_COMINTEROP
439
440// support for Event Tracing for Windows (ETW)
441EXTERN ETW::CEtwTracer* g_pEtwTracer;
442
443#ifdef STRESS_LOG
444class StressLog;
445typedef DPTR(StressLog) PTR_StressLog;
446GPTR_DECL(StressLog, g_pStressLog);
447#endif
448
449
450//
451// Support for the COM+ Debugger.
452//
453GPTR_DECL(DebugInterface, g_pDebugInterface);
454GVAL_DECL(DWORD, g_CORDebuggerControlFlags);
455#ifdef DEBUGGING_SUPPORTED
456GPTR_DECL(EEDbgInterfaceImpl, g_pEEDbgInterfaceImpl);
457#endif // DEBUGGING_SUPPORTED
458
459#ifdef PROFILING_SUPPORTED
460EXTERN HINSTANCE g_pDebuggerDll;
461#endif
462
463// Global default for Concurrent GC. The default is on (value 1)
464EXTERN int g_IGCconcurrent;
465extern int g_IGCHoardVM;
466
467#ifdef GCTRIMCOMMIT
468extern int g_IGCTrimCommit;
469#endif
470
471extern BOOL g_fEnableETW;
472extern BOOL g_fEnableARM;
473
474// Returns a BOOL to indicate if the runtime is active or not
475BOOL IsRuntimeActive();
476
477//
478// Can we run managed code?
479//
480struct LoaderLockCheck
481{
482 enum kind
483 {
484 ForMDA,
485 ForCorrectness,
486 None,
487 };
488};
489BOOL CanRunManagedCode(LoaderLockCheck::kind checkKind, HINSTANCE hInst = 0);
490inline BOOL CanRunManagedCode(HINSTANCE hInst = 0)
491{
492 return CanRunManagedCode(LoaderLockCheck::ForMDA, hInst);
493}
494
495//
496// Global state variable indicating if the EE is in its init phase.
497//
498EXTERN bool g_fEEInit;
499
500//
501// Global state variable indicating if the EE has been started up.
502//
503EXTERN Volatile<BOOL> g_fEEStarted;
504
505#ifdef FEATURE_COMINTEROP
506//
507// Global state variable indicating if COM has been started up.
508//
509EXTERN BOOL g_fComStarted;
510#endif
511
512
513//
514// Global state variables indicating which stage of shutdown we are in
515//
516GVAL_DECL(DWORD, g_fEEShutDown);
517EXTERN DWORD g_fFastExitProcess;
518EXTERN BOOL g_fFatalErrorOccurredOnGCThread;
519#ifndef DACCESS_COMPILE
520EXTERN BOOL g_fSuspendOnShutdown;
521EXTERN BOOL g_fSuspendFinalizerOnShutdown;
522#endif // DACCESS_COMPILE
523EXTERN Volatile<LONG> g_fForbidEnterEE;
524GVAL_DECL(bool, g_fProcessDetach);
525EXTERN bool g_fManagedAttach;
526EXTERN bool g_fNoExceptions;
527#ifdef FEATURE_COMINTEROP
528EXTERN bool g_fShutDownCOM;
529#endif // FEATURE_COMINTEROP
530
531// Indicates whether we're executing shut down as a result of DllMain
532// (DLL_PROCESS_DETACH). See comments at code:EEShutDown for details.
533inline BOOL IsAtProcessExit()
534{
535 SUPPORTS_DAC;
536 return g_fProcessDetach;
537}
538
539enum FWStatus
540{
541 FWS_WaitInterrupt = 0x00000001,
542};
543
544EXTERN DWORD g_FinalizerWaiterStatus;
545extern ULONGLONG g_ObjFinalizeStartTime;
546extern Volatile<BOOL> g_FinalizerIsRunning;
547extern Volatile<ULONG> g_FinalizerLoopCount;
548
549#if defined(FEATURE_PAL) && defined(FEATURE_EVENT_TRACE)
550extern Volatile<BOOL> g_TriggerHeapDump;
551#endif // FEATURE_PAL
552
553extern LONG GetProcessedExitProcessEventCount();
554
555#ifndef DACCESS_COMPILE
556//
557// Allow use of native images?
558//
559extern bool g_fAllowNativeImages;
560
561//
562// Default install library
563//
564EXTERN const WCHAR g_pwBaseLibrary[];
565EXTERN const WCHAR g_pwBaseLibraryName[];
566EXTERN const char g_psBaseLibrary[];
567EXTERN const char g_psBaseLibraryName[];
568EXTERN const char g_psBaseLibrarySatelliteAssemblyName[];
569
570#endif // DACCESS_COMPILE
571
572//
573// Do we own the lifetime of the process, ie. is it an EXE?
574//
575EXTERN bool g_fWeControlLifetime;
576
577#ifdef _DEBUG
578// The following should only be used for assertions. (Famous last words).
579EXTERN bool dbg_fDrasticShutdown;
580#endif
581EXTERN bool g_fInControlC;
582
583// There is a global table of prime numbers that's available for e.g. hashing
584extern const DWORD g_rgPrimes[71];
585
586//
587// Macros to check debugger and profiler settings.
588//
589inline bool CORDebuggerPendingAttach()
590{
591 LIMITED_METHOD_CONTRACT;
592 SUPPORTS_DAC;
593 // If we're in rude shutdown, then pretend the debugger is detached.
594 // We want shutdown to be as simple as possible, so this avoids
595 // us trying to do elaborate operations while exiting.
596 return (g_CORDebuggerControlFlags & DBCF_PENDING_ATTACH) && !IsAtProcessExit();
597}
598
599inline bool CORDebuggerAttached()
600{
601 LIMITED_METHOD_CONTRACT;
602 SUPPORTS_DAC;
603 // If we're in rude shutdown, then pretend the debugger is detached.
604 // We want shutdown to be as simple as possible, so this avoids
605 // us trying to do elaborate operations while exiting.
606 return (g_CORDebuggerControlFlags & DBCF_ATTACHED) && !IsAtProcessExit();
607}
608
609#define CORDebuggerAllowJITOpts(dwDebuggerBits) \
610 (((dwDebuggerBits) & DACF_ALLOW_JIT_OPTS) \
611 || \
612 ((g_CORDebuggerControlFlags & DBCF_ALLOW_JIT_OPT) && \
613 !((dwDebuggerBits) & DACF_USER_OVERRIDE)))
614
615#define CORDebuggerEnCMode(dwDebuggerBits) \
616 ((dwDebuggerBits) & DACF_ENC_ENABLED)
617
618#define CORDebuggerTraceCall() \
619 (CORDebuggerAttached() && GetThread()->IsTraceCall())
620
621
622
623//
624// Define stuff for precedence between profiling and debugging
625// flags that can both be set.
626//
627
628#if defined(PROFILING_SUPPORTED) || defined(PROFILING_SUPPORTED_DATA)
629
630#ifdef DEBUGGING_SUPPORTED
631
632#define CORDisableJITOptimizations(dwDebuggerBits) \
633 (CORProfilerDisableOptimizations() || \
634 !CORDebuggerAllowJITOpts(dwDebuggerBits))
635
636#else // !DEBUGGING_SUPPORTED
637
638#define CORDisableJITOptimizations(dwDebuggerBits) \
639 CORProfilerDisableOptimizations()
640
641#endif// DEBUGGING_SUPPORTED
642
643#else // !defined(PROFILING_SUPPORTED) && !defined(PROFILING_SUPPORTED_DATA)
644
645#ifdef DEBUGGING_SUPPORTED
646
647#define CORDisableJITOptimizations(dwDebuggerBits) \
648 !CORDebuggerAllowJITOpts(dwDebuggerBits)
649
650#else // DEBUGGING_SUPPORTED
651
652#define CORDisableJITOptimizations(dwDebuggerBits) FALSE
653
654#endif// DEBUGGING_SUPPORTED
655
656#endif// defined(PROFILING_SUPPORTED) || defined(PROFILING_SUPPORTED_DATA)
657
658
659
660
661//
662// IJW needs the shim HINSTANCE
663//
664EXTERN HINSTANCE g_hInstShim;
665
666#ifndef FEATURE_PAL
667GVAL_DECL(SIZE_T, g_runtimeLoadedBaseAddress);
668GVAL_DECL(SIZE_T, g_runtimeVirtualSize);
669#endif // !FEATURE_PAL
670
671
672#ifndef MAXULONG
673#define MAXULONG 0xffffffff
674#endif
675
676#ifndef MAXULONGLONG
677#define MAXULONGLONG UI64(0xffffffffffffffff)
678#endif
679
680// #ADID_vs_ADIndex
681// code:ADID is an ID for an appdomain that is sparse and remains unique within the process for the lifetime of the process.
682// Remoting and (I believe) the thread pool use the former as a way of referring to appdomains outside of their normal lifetime safely.
683// Interop also uses ADID to handle issues involving unloaded domains.
684//
685// code:ADIndex is an ID for an appdomain that's dense and may be reused once the appdomain is unloaded.
686// This is useful for fast array based lookup from a number to an appdomain property.
687struct ADIndex
688{
689 DWORD m_dwIndex;
690 ADIndex ()
691 : m_dwIndex(0)
692 {}
693 explicit ADIndex (DWORD id)
694 : m_dwIndex(id)
695 {
696 SUPPORTS_DAC;
697 }
698 BOOL operator==(const ADIndex& ad) const
699 {
700 return m_dwIndex == ad.m_dwIndex;
701 }
702 BOOL operator!=(const ADIndex& ad) const
703 {
704 return m_dwIndex != ad.m_dwIndex;
705 }
706};
707
708// An ADID is a number that represents an appdomain. They are allcoated with code:SystemDomain::GetNewAppDomainId
709// ADIDs are NOT reused today, so they are unique even after the appdomain dies.
710//
711// see also code:BaseDomain::m_dwId
712// see also code:ADIndex
713// see also code:ADIndex#ADID_vs_ADIndex
714struct ADID
715{
716 DWORD m_dwId;
717 ADID ()
718 : m_dwId(0)
719 {LIMITED_METHOD_CONTRACT;}
720 explicit ADID (DWORD id)
721 : m_dwId(id)
722 {LIMITED_METHOD_CONTRACT;}
723 BOOL operator==(const ADID& ad) const
724 {
725 LIMITED_METHOD_DAC_CONTRACT;
726 return m_dwId == ad.m_dwId;
727 }
728 BOOL operator!=(const ADID& ad) const
729 {
730 LIMITED_METHOD_CONTRACT;
731 return m_dwId != ad.m_dwId;
732 }
733};
734
735struct TPIndex
736{
737 DWORD m_dwIndex;
738 TPIndex ()
739 : m_dwIndex(0)
740 {}
741 explicit TPIndex (DWORD id)
742 : m_dwIndex(id)
743 {}
744 BOOL operator==(const TPIndex& tpindex) const
745 {
746 return m_dwIndex == tpindex.m_dwIndex;
747 }
748 BOOL operator!=(const TPIndex& tpindex) const
749 {
750 return m_dwIndex != tpindex.m_dwIndex;
751 }
752};
753
754// Every Module is assigned a ModuleIndex, regardless of whether the Module is domain
755// neutral or domain specific. When a domain specific Module is unloaded, its ModuleIndex
756// can be reused.
757
758// ModuleIndexes are not the same as ModuleIDs. The main purpose of a ModuleIndex is
759// to have a compact way to refer to any Module (domain neutral or domain specific).
760// The main purpose of a ModuleID is to facilitate looking up the DomainLocalModule
761// that corresponds to a given Module in a given AppDomain.
762
763struct ModuleIndex
764{
765 SIZE_T m_dwIndex;
766 ModuleIndex ()
767 : m_dwIndex(0)
768 {}
769 explicit ModuleIndex (SIZE_T id)
770 : m_dwIndex(id)
771 { LIMITED_METHOD_DAC_CONTRACT; }
772 BOOL operator==(const ModuleIndex& ad) const
773 {
774 return m_dwIndex == ad.m_dwIndex;
775 }
776 BOOL operator!=(const ModuleIndex& ad) const
777 {
778 return m_dwIndex != ad.m_dwIndex;
779 }
780};
781
782//-----------------------------------------------------------------------------
783// GSCookies (guard-stack cookies) for detecting buffer overruns
784//-----------------------------------------------------------------------------
785
786typedef DPTR(GSCookie) PTR_GSCookie;
787
788#ifndef DACCESS_COMPILE
789// const is so that it gets placed in the .text section (which is read-only)
790// volatile is so that accesses to it do not get optimized away because of the const
791//
792
793extern "C" RAW_KEYWORD(volatile) const GSCookie s_gsCookie;
794
795inline
796GSCookie * GetProcessGSCookiePtr() { return const_cast<GSCookie *>(&s_gsCookie); }
797
798#else
799
800extern __GlobalVal< GSCookie > s_gsCookie;
801
802inline
803PTR_GSCookie GetProcessGSCookiePtr() { return PTR_GSCookie(&s_gsCookie); }
804
805#endif //!DACCESS_COMPILE
806
807inline
808GSCookie GetProcessGSCookie() { return *(RAW_KEYWORD(volatile) GSCookie *)(&s_gsCookie); }
809
810class CEECompileInfo;
811extern CEECompileInfo *g_pCEECompileInfo;
812
813#ifdef FEATURE_READYTORUN_COMPILER
814extern bool g_fReadyToRunCompilation;
815#endif
816
817// Returns true if this is NGen compilation process.
818// This is a superset of CompilationDomain::IsCompilationDomain() as there is more
819// than one AppDomain in ngen (the DefaultDomain)
820inline BOOL IsCompilationProcess()
821{
822#ifdef CROSSGEN_COMPILE
823 return TRUE;
824#else
825 return FALSE;
826#endif
827}
828
829// Flag for cross-platform ngen: Removes all execution of managed or third-party code in the ngen compilation process.
830inline BOOL NingenEnabled()
831{
832#ifdef CROSSGEN_COMPILE
833 return TRUE;
834#else
835 return FALSE;
836#endif
837}
838
839// Passed to JitManager APIs to determine whether to avoid calling into the host.
840// The profiling API stackwalking uses this to ensure to avoid re-entering the host
841// (particularly SQL) from a hijacked thread.
842enum HostCallPreference
843{
844 AllowHostCalls,
845 NoHostCalls,
846};
847
848#endif /* _VARS_HPP */
849