| 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 | // common.h - precompiled headers include for the COM+ Execution Engine |
| 6 | // |
| 7 | |
| 8 | #ifndef _common_h_ |
| 9 | #define _common_h_ |
| 10 | |
| 11 | #if defined(_MSC_VER) && defined(_X86_) && !defined(FPO_ON) |
| 12 | #pragma optimize("y", on) // Small critical routines, don't put in EBP frame |
| 13 | #define FPO_ON 1 |
| 14 | #define COMMON_TURNED_FPO_ON 1 |
| 15 | #endif |
| 16 | |
| 17 | #if STRONGNAME_IN_VM |
| 18 | |
| 19 | #define USE_COM_CONTEXT_DEF |
| 20 | |
| 21 | #ifdef _DEBUG |
| 22 | #define DEBUG_REGDISPLAY |
| 23 | #endif |
| 24 | |
| 25 | #ifdef _MSC_VER |
| 26 | |
| 27 | // These don't seem useful, so turning them off is no big deal |
| 28 | #pragma warning(disable:4244) // loss of data int -> char .. |
| 29 | |
| 30 | #ifndef DEBUG |
| 31 | #pragma warning(disable:4189) // local variable initialized but not used |
| 32 | #pragma warning(disable:4505) // unreferenced local function has been removed |
| 33 | #pragma warning(disable:4313) // 'format specifier' in format string conflicts with argument %d of type 'type' |
| 34 | #endif // !DEBUG |
| 35 | |
| 36 | |
| 37 | #endif // _MSC_VER |
| 38 | |
| 39 | #endif // STRONGNAME_IN_VM |
| 40 | |
| 41 | #define _CRT_DEPENDENCY_ //this code depends on the crt file functions |
| 42 | |
| 43 | |
| 44 | #include <stdint.h> |
| 45 | #include <winwrap.h> |
| 46 | |
| 47 | #include <windows.h> |
| 48 | #include <wincrypt.h> |
| 49 | #include <winnt.h> |
| 50 | #include <crosscomp.h> |
| 51 | #include <clrnt.h> |
| 52 | #include <stdlib.h> |
| 53 | #include <wchar.h> |
| 54 | #include <objbase.h> |
| 55 | #include <stddef.h> |
| 56 | #include <float.h> |
| 57 | #include <math.h> |
| 58 | #include <time.h> |
| 59 | #include <limits.h> |
| 60 | |
| 61 | #include <olectl.h> |
| 62 | |
| 63 | #ifdef _MSC_VER |
| 64 | //non inline intrinsics are faster |
| 65 | #pragma function(memcpy,memcmp,strcmp,strcpy,strlen,strcat) |
| 66 | #endif // _MSC_VER |
| 67 | |
| 68 | // make all the unsafe redefinitions available |
| 69 | #include "unsafe.h" |
| 70 | |
| 71 | //----------------------------------------------------------------------------------------------------------- |
| 72 | |
| 73 | #include "lazycow.h" |
| 74 | |
| 75 | #include "strongname.h" |
| 76 | #include "stdmacros.h" |
| 77 | |
| 78 | #define POISONC ((UINT_PTR)((sizeof(int *) == 4)?0xCCCCCCCCL:I64(0xCCCCCCCCCCCCCCCC))) |
| 79 | |
| 80 | #include "ndpversion.h" |
| 81 | #include "switches.h" |
| 82 | #include "holder.h" |
| 83 | |
| 84 | #if STRONGNAME_IN_VM |
| 85 | #include "classnames.h" |
| 86 | #include "util.hpp" |
| 87 | #endif // STRONGNAME_IN_VM |
| 88 | |
| 89 | #include "corpriv.h" |
| 90 | |
| 91 | #include <daccess.h> |
| 92 | |
| 93 | #if STRONGNAME_IN_VM |
| 94 | |
| 95 | typedef VPTR(class LoaderAllocator) PTR_LoaderAllocator; |
| 96 | typedef VPTR(class AppDomain) PTR_AppDomain; |
| 97 | typedef VPTR(class AppDomainBaseObject) PTR_AppDomainBaseObject; |
| 98 | typedef DPTR(class ArrayBase) PTR_ArrayBase; |
| 99 | typedef DPTR(class ArrayTypeDesc) PTR_ArrayTypeDesc; |
| 100 | typedef DPTR(class Assembly) PTR_Assembly; |
| 101 | typedef DPTR(class AssemblyBaseObject) PTR_AssemblyBaseObject; |
| 102 | typedef DPTR(class AssemblyNameBaseObject) PTR_AssemblyNameBaseObject; |
| 103 | typedef VPTR(class BaseDomain) PTR_BaseDomain; |
| 104 | typedef DPTR(class MscorlibBinder) PTR_MscorlibBinder; |
| 105 | typedef DPTR(class ClassLoader) PTR_ClassLoader; |
| 106 | typedef DPTR(class ComCallMethodDesc) PTR_ComCallMethodDesc; |
| 107 | typedef VPTR(class CompilationDomain) PTR_CompilationDomain; |
| 108 | typedef DPTR(class ComPlusCallMethodDesc) PTR_ComPlusCallMethodDesc; |
| 109 | typedef VPTR(class DebugInterface) PTR_DebugInterface; |
| 110 | typedef DPTR(class Dictionary) PTR_Dictionary; |
| 111 | typedef VPTR(class DomainAssembly) PTR_DomainAssembly; |
| 112 | typedef VPTR(class DomainFile) PTR_DomainFile; |
| 113 | typedef VPTR(class DomainModule) PTR_DomainModule; |
| 114 | typedef DPTR(struct FailedAssembly) PTR_FailedAssembly; |
| 115 | typedef VPTR(class EditAndContinueModule) PTR_EditAndContinueModule; |
| 116 | typedef DPTR(class EEClass) PTR_EEClass; |
| 117 | typedef DPTR(class DelegateEEClass) PTR_DelegateEEClass; |
| 118 | typedef DPTR(struct DomainLocalModule) PTR_DomainLocalModule; |
| 119 | typedef VPTR(class EECodeManager) PTR_EECodeManager; |
| 120 | typedef DPTR(class EEConfig) PTR_EEConfig; |
| 121 | typedef VPTR(class EEDbgInterfaceImpl) PTR_EEDbgInterfaceImpl; |
| 122 | typedef VPTR(class DebugInfoManager) PTR_DebugInfoManager; |
| 123 | typedef DPTR(class FieldDesc) PTR_FieldDesc; |
| 124 | typedef VPTR(class Frame) PTR_Frame; |
| 125 | typedef VPTR(class ICodeManager) PTR_ICodeManager; |
| 126 | typedef VPTR(class IJitManager) PTR_IJitManager; |
| 127 | typedef DPTR(class InstMethodHashTable) PTR_InstMethodHashTable; |
| 128 | typedef DPTR(class MetaSig) PTR_MetaSig; |
| 129 | typedef DPTR(class MethodDesc) PTR_MethodDesc; |
| 130 | typedef DPTR(class MethodDescChunk) PTR_MethodDescChunk; |
| 131 | typedef DPTR(class MethodImpl) PTR_MethodImpl; |
| 132 | typedef DPTR(class MethodTable) PTR_MethodTable; |
| 133 | typedef VPTR(class Module) PTR_Module; |
| 134 | typedef DPTR(class NDirectMethodDesc) PTR_NDirectMethodDesc; |
| 135 | typedef VPTR(class Thread) PTR_Thread; |
| 136 | typedef DPTR(class Object) PTR_Object; |
| 137 | typedef DPTR(PTR_Object) PTR_PTR_Object; |
| 138 | typedef DPTR(class ObjHeader) ; |
| 139 | typedef DPTR(class Precode) PTR_Precode; |
| 140 | typedef VPTR(class ReflectionModule) PTR_ReflectionModule; |
| 141 | typedef DPTR(class ReflectClassBaseObject) PTR_ReflectClassBaseObject; |
| 142 | typedef DPTR(class ReflectModuleBaseObject) PTR_ReflectModuleBaseObject; |
| 143 | typedef DPTR(class ReflectMethodObject) PTR_ReflectMethodObject; |
| 144 | typedef DPTR(class ReflectFieldObject) PTR_ReflectFieldObject; |
| 145 | typedef DPTR(class ReJitManager) PTR_ReJitManager; |
| 146 | typedef DPTR(struct ReJitInfo) PTR_ReJitInfo; |
| 147 | typedef DPTR(struct SharedReJitInfo) PTR_SharedReJitInfo; |
| 148 | typedef DPTR(class StringObject) PTR_StringObject; |
| 149 | typedef DPTR(class TypeHandle) PTR_TypeHandle; |
| 150 | #ifdef STUB_DISPATCH |
| 151 | typedef VPTR(class VirtualCallStubManager) PTR_VirtualCallStubManager; |
| 152 | typedef VPTR(class VirtualCallStubManagerManager) PTR_VirtualCallStubManagerManager; |
| 153 | #endif |
| 154 | typedef VPTR(class IGCHeap) PTR_IGCHeap; |
| 155 | |
| 156 | // |
| 157 | // _UNCHECKED_OBJECTREF is for code that can't deal with DEBUG OBJECTREFs |
| 158 | // |
| 159 | typedef PTR_Object _UNCHECKED_OBJECTREF; |
| 160 | typedef DPTR(PTR_Object) PTR_UNCHECKED_OBJECTREF; |
| 161 | |
| 162 | #ifdef USE_CHECKED_OBJECTREFS |
| 163 | class OBJECTREF; |
| 164 | #else |
| 165 | typedef PTR_Object OBJECTREF; |
| 166 | #endif |
| 167 | typedef DPTR(OBJECTREF) PTR_OBJECTREF; |
| 168 | typedef DPTR(PTR_OBJECTREF) PTR_PTR_OBJECTREF; |
| 169 | |
| 170 | |
| 171 | EXTERN_C Thread* STDCALL GetThread(); |
| 172 | |
| 173 | // This is a mechanism by which macros can make the Thread pointer available to inner scopes |
| 174 | // that is robust to code changes. If the outer Thread no longer is available for some reason |
| 175 | // (e.g. code refactoring), this GET_THREAD() macro will fall back to calling GetThread(). |
| 176 | const bool CURRENT_THREAD_AVAILABLE = false; |
| 177 | Thread * const CURRENT_THREAD = NULL; |
| 178 | #define GET_THREAD() (CURRENT_THREAD_AVAILABLE ? CURRENT_THREAD : GetThread()) |
| 179 | |
| 180 | #define MAKE_CURRENT_THREAD_AVAILABLE() \ |
| 181 | Thread * __pThread = GET_THREAD(); \ |
| 182 | MAKE_CURRENT_THREAD_AVAILABLE_EX(__pThread) |
| 183 | |
| 184 | #define MAKE_CURRENT_THREAD_AVAILABLE_EX(__pThread) \ |
| 185 | Thread * CURRENT_THREAD = __pThread; \ |
| 186 | const bool CURRENT_THREAD_AVAILABLE = true; \ |
| 187 | (void)CURRENT_THREAD_AVAILABLE; /* silence "local variable initialized but not used" warning */ \ |
| 188 | |
| 189 | #ifndef DACCESS_COMPILE |
| 190 | EXTERN_C AppDomain* STDCALL GetAppDomain(); |
| 191 | #endif //!DACCESS_COMPILE |
| 192 | |
| 193 | inline void RetailBreak() |
| 194 | { |
| 195 | #if defined(_TARGET_X86_) |
| 196 | __asm int 3 |
| 197 | #else |
| 198 | DebugBreak(); |
| 199 | #endif |
| 200 | } |
| 201 | |
| 202 | extern BOOL isMemoryReadable(const TADDR start, unsigned len); |
| 203 | |
| 204 | #ifndef memcpyUnsafe_f |
| 205 | #define memcpyUnsafe_f |
| 206 | |
| 207 | // use this when you want to memcpy something that contains GC refs |
| 208 | inline void* memcpyUnsafe(void *dest, const void *src, size_t len) |
| 209 | { |
| 210 | WRAPPER_NO_CONTRACT; |
| 211 | return memcpy(dest, src, len); |
| 212 | } |
| 213 | |
| 214 | #endif // !memcpyUnsafe_f |
| 215 | |
| 216 | // |
| 217 | // By default logging, and debug GC are enabled under debug |
| 218 | // |
| 219 | // These can be enabled in non-debug by removing the #ifdef _DEBUG |
| 220 | // allowing one to log/check_gc a free build. |
| 221 | // |
| 222 | #if defined(_DEBUG) && !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) |
| 223 | |
| 224 | //If memcpy has been defined to PAL_memcpy, we undefine it so that this case |
| 225 | //can be covered by the if !defined(memcpy) block below |
| 226 | #ifdef FEATURE_PAL |
| 227 | #if IS_REDEFINED_IN_PAL(memcpy) |
| 228 | #undef memcpy |
| 229 | #endif //IS_REDEFINED_IN_PAL |
| 230 | #endif //FEATURE_PAL |
| 231 | |
| 232 | // You should be using CopyValueClass if you are doing an memcpy |
| 233 | // in the CG heap. |
| 234 | #if !defined(memcpy) |
| 235 | inline void* memcpyNoGCRefs(void * dest, const void * src, size_t len) { |
| 236 | WRAPPER_NO_CONTRACT; |
| 237 | |
| 238 | #ifndef FEATURE_PAL |
| 239 | return memcpy(dest, src, len); |
| 240 | #else //FEATURE_PAL |
| 241 | return PAL_memcpy(dest, src, len); |
| 242 | #endif //FEATURE_PAL |
| 243 | |
| 244 | } |
| 245 | extern "C" void * __cdecl GCSafeMemCpy(void *, const void *, size_t); |
| 246 | #define memcpy(dest, src, len) GCSafeMemCpy(dest, src, len) |
| 247 | #endif // !defined(memcpy) |
| 248 | #else // !_DEBUG && !DACCESS_COMPILE && !CROSSGEN_COMPILE |
| 249 | inline void* memcpyNoGCRefs(void * dest, const void * src, size_t len) { |
| 250 | WRAPPER_NO_CONTRACT; |
| 251 | return memcpy(dest, src, len); |
| 252 | } |
| 253 | #endif // !_DEBUG && !DACCESS_COMPILE && !CROSSGEN_COMPILE |
| 254 | |
| 255 | namespace Loader |
| 256 | { |
| 257 | typedef enum |
| 258 | { |
| 259 | Load, //should load |
| 260 | DontLoad, //should not load |
| 261 | SafeLookup //take no locks, no allocations |
| 262 | } LoadFlag; |
| 263 | } |
| 264 | |
| 265 | #endif // STRONGNAME_IN_VM |
| 266 | |
| 267 | // src/inc |
| 268 | #include "utilcode.h" |
| 269 | #include "log.h" |
| 270 | #include "loaderheap.h" |
| 271 | |
| 272 | #if STRONGNAME_IN_VM |
| 273 | |
| 274 | // src/vm |
| 275 | #include "gcenv.interlocked.h" |
| 276 | #include "gcenv.interlocked.inl" |
| 277 | |
| 278 | #include "util.hpp" |
| 279 | #include "ibclogger.h" |
| 280 | #include "eepolicy.h" |
| 281 | |
| 282 | #include "vars.hpp" |
| 283 | #include "crst.h" |
| 284 | #include "argslot.h" |
| 285 | #include "stublink.h" |
| 286 | #include "cgensys.h" |
| 287 | #include "ceemain.h" |
| 288 | #include "hash.h" |
| 289 | #include "eecontract.h" |
| 290 | #include "pedecoder.h" |
| 291 | #include "sstring.h" |
| 292 | #include "slist.h" |
| 293 | |
| 294 | #include "eeconfig.h" |
| 295 | |
| 296 | #include "spinlock.h" |
| 297 | #include "cgensys.h" |
| 298 | #include "declsec.h" |
| 299 | |
| 300 | #ifdef FEATURE_COMINTEROP |
| 301 | #include "stdinterfaces.h" |
| 302 | #endif |
| 303 | |
| 304 | #include "typehandle.h" |
| 305 | #include "perfcounters.h" |
| 306 | #include "methodtable.h" |
| 307 | #include "typectxt.h" |
| 308 | |
| 309 | #include "eehash.h" |
| 310 | |
| 311 | #include "vars.hpp" |
| 312 | #include "eventstore.hpp" |
| 313 | |
| 314 | #include "synch.h" |
| 315 | #include "regdisp.h" |
| 316 | #include "stackframe.h" |
| 317 | #include "gms.h" |
| 318 | #include "stackprobe.h" |
| 319 | #include "fcall.h" |
| 320 | #include "syncblk.h" |
| 321 | #include "gcdesc.h" |
| 322 | #include "specialstatics.h" |
| 323 | #include "object.h" // <NICE> We should not really need to put this so early... </NICE> |
| 324 | #include "gchelpers.h" |
| 325 | #include "pefile.h" |
| 326 | #include "clrex.h" |
| 327 | #include "clsload.hpp" // <NICE> We should not really need to put this so early... </NICE> |
| 328 | #include "siginfo.hpp" |
| 329 | #include "binder.h" |
| 330 | #include "jitinterface.h" // <NICE> We should not really need to put this so early... </NICE> |
| 331 | #include "ceeload.h" |
| 332 | #include "memberload.h" |
| 333 | #include "genericdict.h" |
| 334 | #include "class.h" |
| 335 | #include "codeman.h" |
| 336 | #include "threads.h" |
| 337 | #include "clrex.inl" |
| 338 | #include "loaderallocator.hpp" |
| 339 | #include "appdomain.hpp" |
| 340 | #include "assembly.hpp" |
| 341 | #include "pefile.inl" |
| 342 | #include "excep.h" |
| 343 | #include "method.hpp" |
| 344 | #include "frames.h" |
| 345 | |
| 346 | #include "stackwalk.h" |
| 347 | #include "stackingallocator.h" |
| 348 | #include "interoputil.h" |
| 349 | #include "wrappers.h" |
| 350 | #include "dynamicmethod.h" |
| 351 | |
| 352 | |
| 353 | HRESULT EnsureRtlFunctions(); |
| 354 | HINSTANCE GetModuleInst(); |
| 355 | |
| 356 | |
| 357 | #if defined(_DEBUG) |
| 358 | |
| 359 | // This catches CANNOTTHROW macros that occur outside the scope of a CONTRACT. |
| 360 | // Note that it's important for m_CannotThrowLineNums to be NULL. |
| 361 | struct DummyGlobalContract |
| 362 | { |
| 363 | int *m_CannotThrowLineNums; //= NULL; |
| 364 | LPVOID *m_CannotThrowRecords; //= NULL; |
| 365 | }; |
| 366 | |
| 367 | extern DummyGlobalContract ___contract; |
| 368 | |
| 369 | #endif // defined(_DEBUG) |
| 370 | |
| 371 | |
| 372 | // All files get to see all of these .inl files to make sure all files |
| 373 | // get the benefit of inlining. |
| 374 | #include "ceeload.inl" |
| 375 | #include "typedesc.inl" |
| 376 | #include "class.inl" |
| 377 | #include "methodtable.inl" |
| 378 | #include "typehandle.inl" |
| 379 | #include "object.inl" |
| 380 | #include "ceeload.inl" |
| 381 | #include "clsload.inl" |
| 382 | #include "domainfile.inl" |
| 383 | #include "clsload.inl" |
| 384 | #include "method.inl" |
| 385 | #include "stackprobe.inl" |
| 386 | #include "syncblk.inl" |
| 387 | #include "threads.inl" |
| 388 | #include "eehash.inl" |
| 389 | |
| 390 | #endif // STRONGNAME_IN_VM |
| 391 | |
| 392 | #include "pedecoder.h" |
| 393 | |
| 394 | #if defined(COMMON_TURNED_FPO_ON) |
| 395 | #pragma optimize("", on) // Go back to command line default optimizations |
| 396 | #undef COMMON_TURNED_FPO_ON |
| 397 | #undef FPO_ON |
| 398 | #endif |
| 399 | |
| 400 | #endif // !_common_h_ |
| 401 | |