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