2 // Copyright (c) Microsoft. All rights reserved.
3 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
8 // Definitions of a Com+ Object
11 // See code:EEStartup#TableOfContents for overview
20 #include "specialstatics.h"
24 extern "C" void __fastcall ZeroMemoryInGCHeap(void*, size_t);
26 void ErectWriteBarrierForMT(MethodTable **dst, MethodTable *ref);
30 * COM+ Internal Object Model
33 * Object - This is the common base part to all COM+ objects
34 * | it contains the MethodTable pointer and the
35 * | sync block index, which is at a negative offset
37 * +-- code:StringObject - String objects are specialized objects for string
38 * | storage/retrieval for higher performance
40 * +-- code:StringBufferObject - StringBuffer instance layout.
42 * +-- BaseObjectWithCachedData - Object Plus one object field for caching.
44 * | +- ReflectClassBaseObject - The base object for the RuntimeType class
45 * | +- ReflectMethodObject - The base object for the RuntimeMethodInfo class
46 * | +- ReflectFieldObject - The base object for the RtFieldInfo class
48 * +-- code:ArrayBase - Base portion of all arrays
50 * | +- I1Array - Base type arrays
54 * | +- PtrArray - Array of OBJECTREFs, different than base arrays because of pObjectClass
56 * +-- code:AppDomainBaseObject - The base object for the class AppDomain
58 * +-- code:AssemblyBaseObject - The base object for the class Assembly
60 * +-- code:ContextBaseObject - base object for class Context
63 * PLEASE NOTE THE FOLLOWING WHEN ADDING A NEW OBJECT TYPE:
65 * The size of the object in the heap must be able to be computed
66 * very, very quickly for GC purposes. Restrictions on the layout
67 * of the object guarantee this is possible.
69 * Any object that inherits from Object must be able to
70 * compute its complete size by using the first 4 bytes of
71 * the object following the Object part and constants
72 * reachable from the MethodTable...
74 * The formula used for this calculation is:
75 * MT->GetBaseSize() + ((OBJECTTYPEREF->GetSizeField() * MT->GetComponentSize())
77 * So for Object, since this is of fixed size, the ComponentSize is 0, which makes the right side
78 * of the equation above equal to 0 no matter what the value of GetSizeField(), so the size is just the base size.
83 // @TODO: #define COW 0x04
84 // @TODO: MOO, MOO - no, not bovine, really Copy On Write bit for StringBuffer, requires 8 byte align MT
85 // @TODL: which we don't have yet</TODO>
95 class WaitHandleNative;
98 #if CHECK_APP_DOMAIN_LEAKS
102 class SetAppDomainAgilePendingTable
106 SetAppDomainAgilePendingTable ();
107 ~SetAppDomainAgilePendingTable ();
109 void PushReference (Object *pObject)
111 STATIC_CONTRACT_THROWS;
112 STATIC_CONTRACT_GC_NOTRIGGER;
115 entry.pObject = pObject;
120 void PushParent (Object *pObject)
122 STATIC_CONTRACT_THROWS;
123 STATIC_CONTRACT_GC_NOTRIGGER;
126 entry.pObject = (Object*)((size_t)pObject | 1);
131 Object *GetPendingObject (bool *pfReturnedToParent)
133 STATIC_CONTRACT_THROWS;
134 STATIC_CONTRACT_GC_NOTRIGGER;
136 if (!m_Stack.Count())
139 PendingEntry *pPending = m_Stack.Pop();
141 *pfReturnedToParent = pPending->fMarked != 0;
142 return (Object*)((size_t)pPending->pObject & ~1);
151 // Indicates whether the current thread set BIT_SBLK_AGILE_IN_PROGRESS
152 // on the object. Entries without this flag set are unexplored
157 CStackArray<PendingEntry> m_Stack;
160 #endif //CHECK_APP_DOMAIN_LEAKS
164 // The generational GC requires that every object be at least 12 bytes
167 #define MIN_OBJECT_SIZE (2*sizeof(BYTE*) + sizeof(ObjHeader))
169 #define PTRALIGNCONST (DATA_ALIGNMENT-1)
172 #define PtrAlign(size) \
173 ((size + PTRALIGNCONST) & (~PTRALIGNCONST))
176 // code:Object is the respesentation of an managed object on the GC heap.
178 // See code:#ObjectModel for some important subclasses of code:Object
180 // The only fields mandated by all objects are
182 // * a pointer to the code:MethodTable at offset 0
183 // * a poiner to a code:ObjHeader at a negative offset. This is often zero. It holds information that
184 // any addition information that we might need to attach to arbitrary objects.
189 PTR_MethodTable m_pMethTab;
192 Object() { LIMITED_METHOD_CONTRACT; };
193 ~Object() { LIMITED_METHOD_CONTRACT; };
196 MethodTable *RawGetMethodTable() const
201 #ifndef DACCESS_COMPILE
202 void RawSetMethodTable(MethodTable *pMT)
204 LIMITED_METHOD_CONTRACT;
208 VOID SetMethodTable(MethodTable *pMT)
210 LIMITED_METHOD_CONTRACT;
214 VOID SetMethodTableForLargeObject(MethodTable *pMT)
216 // This function must be used if the allocation occurs on the large object heap, and the method table might be a collectible type
218 ErectWriteBarrierForMT(&m_pMethTab, pMT);
221 #endif //!DACCESS_COMPILE
223 // An object might be a proxy of some sort, with a thunking VTable. If so, we can
224 // advance to the true method table or class.
225 BOOL IsTransparentProxy()
227 #ifdef FEATURE_REMOTING
229 return( GetMethodTable()->IsTransparentProxy() );
231 LIMITED_METHOD_CONTRACT;
236 #define MARKED_BIT 0x1
238 PTR_MethodTable GetMethodTable() const
240 LIMITED_METHOD_DAC_CONTRACT;
242 #ifndef DACCESS_COMPILE
243 // We should always use GetGCSafeMethodTable() if we're running during a GC.
244 // If the mark bit is set then we're running during a GC
245 _ASSERTE((dac_cast<TADDR>(m_pMethTab) & MARKED_BIT) == 0);
248 #else //DACCESS_COMPILE
250 //@dbgtodo dharvey Make this a type which supports bitwise and operations
252 return PTR_MethodTable((dac_cast<TADDR>(m_pMethTab)) & (~MARKED_BIT));
253 #endif //DACCESS_COMPILE
256 DPTR(PTR_MethodTable) GetMethodTablePtr() const
258 LIMITED_METHOD_CONTRACT;
259 return dac_cast<DPTR(PTR_MethodTable)>(PTR_HOST_MEMBER_TADDR(Object, this, m_pMethTab));
262 MethodTable *GetTrueMethodTable();
264 TypeHandle GetTypeHandle();
265 TypeHandle GetTrueTypeHandle();
267 // Methods used to determine if an object supports a given interface.
268 static BOOL SupportsInterface(OBJECTREF pObj, MethodTable *pInterfaceMT);
270 inline DWORD GetNumComponents();
271 inline SIZE_T GetSize();
273 CGCDesc* GetSlotMap()
276 return( CGCDesc::GetCGCDescFromMT(GetMethodTable()));
279 // Sync Block & Synchronization services
281 // Access the ObjHeader which is at a negative offset on the object (because of
283 PTR_ObjHeader GetHeader()
285 LIMITED_METHOD_DAC_CONTRACT;
286 return dac_cast<PTR_ObjHeader>(this) - 1;
289 // Get the current address of the object (works for debug refs, too.)
290 PTR_BYTE GetAddress()
292 LIMITED_METHOD_DAC_CONTRACT;
293 return dac_cast<PTR_BYTE>(this);
297 // TRUE if the header has a real SyncBlockIndex (i.e. it has an entry in the
298 // SyncTable, though it doesn't necessarily have an entry in the SyncBlockCache)
299 BOOL HasEmptySyncBlockInfo()
302 return GetHeader()->HasEmptySyncBlockInfo();
306 // retrieve or allocate a sync block for this object
307 SyncBlock *GetSyncBlock()
310 return GetHeader()->GetSyncBlock();
313 DWORD GetSyncBlockIndex()
316 return GetHeader()->GetSyncBlockIndex();
320 ADIndex GetAppDomainIndex();
322 // Get app domain of object, or NULL if it is agile
323 AppDomain *GetAppDomain();
325 #ifndef DACCESS_COMPILE
326 // Set app domain of object to current domain.
327 void SetAppDomain() { WRAPPER_NO_CONTRACT; SetAppDomain(::GetAppDomain()); }
330 // Set app domain of object to given domain - it can only be set once
331 void SetAppDomain(AppDomain *pDomain);
335 #ifndef DACCESS_COMPILE
336 // For SO-tolerance contract violation purposes, define these DEBUG_ versions to identify
337 // the codepaths to SetAppDomain that are called only from DEBUG code.
338 void DEBUG_SetAppDomain()
343 DEBUG_SetAppDomain(::GetAppDomain());
346 #endif //!DACCESS_COMPILE
348 void DEBUG_SetAppDomain(AppDomain *pDomain);
351 #if CHECK_APP_DOMAIN_LEAKS
353 // Mark object as app domain agile
354 BOOL SetAppDomainAgile(BOOL raiseAssert=TRUE, SetAppDomainAgilePendingTable *pTable = NULL);
355 BOOL TrySetAppDomainAgile(BOOL raiseAssert=TRUE);
357 // Mark sync block as app domain agile
358 void SetSyncBlockAppDomainAgile();
360 // Check if object is app domain agile
361 BOOL IsAppDomainAgile();
363 // Check if object is app domain agile
364 BOOL IsAppDomainAgileRaw()
368 SyncBlock *psb = PassiveGetSyncBlock();
370 return (psb && psb->IsAppDomainAgile());
373 BOOL Object::IsCheckedForAppDomainAgile()
377 SyncBlock *psb = PassiveGetSyncBlock();
378 return (psb && psb->IsCheckedForAppDomainAgile());
381 void Object::SetIsCheckedForAppDomainAgile()
385 SyncBlock *psb = PassiveGetSyncBlock();
387 psb->SetIsCheckedForAppDomainAgile();
390 // Check object to see if it is usable in the current domain
391 BOOL CheckAppDomain() { WRAPPER_NO_CONTRACT; return CheckAppDomain(::GetAppDomain()); }
393 //Check object to see if it is usable in the given domain
394 BOOL CheckAppDomain(AppDomain *pDomain);
396 // Check if the object's type is app domain agile
397 BOOL IsTypeAppDomainAgile();
399 // Check if the object's type is conditionally app domain agile
400 BOOL IsTypeCheckAppDomainAgile();
402 // Check if the object's type is naturally app domain agile
403 BOOL IsTypeTypesafeAppDomainAgile();
405 // Check if the object's type is possibly app domain agile
406 BOOL IsTypeNeverAppDomainAgile();
408 // Validate object & fields to see that it's usable from the current app domain
409 BOOL ValidateAppDomain() { WRAPPER_NO_CONTRACT; return ValidateAppDomain(::GetAppDomain()); }
411 // Validate object & fields to see that it's usable from any app domain
412 BOOL ValidateAppDomainAgile() { WRAPPER_NO_CONTRACT; return ValidateAppDomain(NULL); }
414 // Validate object & fields to see that it's usable from the given app domain (or null for agile)
415 BOOL ValidateAppDomain(AppDomain *pAppDomain);
417 // Validate fields to see that they are usable from the object's app domain
418 // (or from any domain if the object is agile)
419 BOOL ValidateAppDomainFields() { WRAPPER_NO_CONTRACT; return ValidateAppDomainFields(GetAppDomain()); }
421 // Validate fields to see that they are usable from the given app domain (or null for agile)
422 BOOL ValidateAppDomainFields(AppDomain *pAppDomain);
424 // Validate a value type's fields to see that it's usable from the current app domain
425 static BOOL ValidateValueTypeAppDomain(MethodTable *pMT, void *base, BOOL raiseAssert = TRUE)
426 { WRAPPER_NO_CONTRACT; return ValidateValueTypeAppDomain(pMT, base, ::GetAppDomain(), raiseAssert); }
428 // Validate a value type's fields to see that it's usable from any app domain
429 static BOOL ValidateValueTypeAppDomainAgile(MethodTable *pMT, void *base, BOOL raiseAssert = TRUE)
430 { WRAPPER_NO_CONTRACT; return ValidateValueTypeAppDomain(pMT, base, NULL, raiseAssert); }
432 // Validate a value type's fields to see that it's usable from the given app domain (or null for agile)
433 static BOOL ValidateValueTypeAppDomain(MethodTable *pMT, void *base, AppDomain *pAppDomain, BOOL raiseAssert = TRUE);
435 // Call when we are assigning this object to a dangerous field
436 // in an object in a given app domain (or agile if null)
437 BOOL AssignAppDomain(AppDomain *pAppDomain, BOOL raiseAssert = TRUE);
438 BOOL TryAssignAppDomain(AppDomain *pAppDomain, BOOL raiseAssert = TRUE);
440 // Call when we are assigning to a dangerous value type field
441 // in an object in a given app domain (or agile if null)
442 static BOOL AssignValueTypeAppDomain(MethodTable *pMT, void *base, AppDomain *pAppDomain, BOOL raiseAssert = TRUE);
444 #endif // CHECK_APP_DOMAIN_LEAKS
446 // DO NOT ADD ANY ASSERTS TO THIS METHOD.
447 // DO NOT USE THIS METHOD.
448 // Yes folks, for better or worse the debugger pokes supposed object addresses
449 // to try to see if objects are valid, possibly firing an AccessViolation or worse,
450 // and then catches the AV and reports a failure to the debug client. This makes
451 // the debugger slightly more robust should any corrupted object references appear
452 // in a session. Thus it is "correct" behaviour for this to AV when used with
453 // an invalid object pointer, and incorrect behaviour for it to
455 BOOL ValidateObjectWithPossibleAV();
457 // Validate an object ref out of the Promote routine in the GC
458 void ValidatePromote(ScanContext *sc, DWORD flags);
460 // Validate an object ref out of the VerifyHeap routine in the GC
461 void ValidateHeap(Object *from, BOOL bDeep=TRUE);
463 PTR_SyncBlock PassiveGetSyncBlock()
465 LIMITED_METHOD_DAC_CONTRACT;
466 return GetHeader()->PassiveGetSyncBlock();
469 static DWORD ComputeHashCode();
471 #ifndef DACCESS_COMPILE
472 INT32 GetHashCodeEx();
473 #endif // #ifndef DACCESS_COMPILE
476 #ifndef DACCESS_COMPILE
478 void EnterObjMonitor()
481 GetHeader()->EnterObjMonitor();
484 BOOL TryEnterObjMonitor(INT32 timeOut = 0)
487 return GetHeader()->TryEnterObjMonitor(timeOut);
490 FORCEINLINE AwareLock::EnterHelperResult EnterObjMonitorHelper(Thread* pCurThread)
493 return GetHeader()->EnterObjMonitorHelper(pCurThread);
496 FORCEINLINE AwareLock::EnterHelperResult EnterObjMonitorHelperSpin(Thread* pCurThread)
499 return GetHeader()->EnterObjMonitorHelperSpin(pCurThread);
502 BOOL LeaveObjMonitor()
505 return GetHeader()->LeaveObjMonitor();
508 // should be called only from unwind code; used in the
509 // case where EnterObjMonitor failed to allocate the
511 BOOL LeaveObjMonitorAtException()
514 return GetHeader()->LeaveObjMonitorAtException();
517 FORCEINLINE AwareLock::LeaveHelperAction LeaveObjMonitorHelper(Thread* pCurThread)
520 return GetHeader()->LeaveObjMonitorHelper(pCurThread);
523 // Returns TRUE if the lock is owned and FALSE otherwise
524 // threadId is set to the ID (Thread::GetThreadId()) of the thread which owns the lock
525 // acquisitionCount is set to the number of times the lock needs to be released before
527 BOOL GetThreadOwningMonitorLock(DWORD *pThreadId, DWORD *pAcquisitionCount)
531 return GetHeader()->GetThreadOwningMonitorLock(pThreadId, pAcquisitionCount);
534 #endif // #ifndef DACCESS_COMPILE
536 BOOL Wait(INT32 timeOut, BOOL exitContext)
539 return GetHeader()->Wait(timeOut, exitContext);
545 GetHeader()->Pulse();
551 GetHeader()->PulseAll();
554 PTR_VOID UnBox(); // if it is a value class, get the pointer to the first field
556 PTR_BYTE GetData(void)
558 LIMITED_METHOD_CONTRACT;
560 return dac_cast<PTR_BYTE>(this) + sizeof(Object);
563 static UINT GetOffsetOfFirstField()
565 LIMITED_METHOD_CONTRACT;
566 return sizeof(Object);
569 DWORD GetOffset32(DWORD dwOffset)
572 return * PTR_DWORD(GetData() + dwOffset);
575 USHORT GetOffset16(DWORD dwOffset)
578 return * PTR_USHORT(GetData() + dwOffset);
581 BYTE GetOffset8(DWORD dwOffset)
584 return * PTR_BYTE(GetData() + dwOffset);
587 __int64 GetOffset64(DWORD dwOffset)
590 return (__int64) * PTR_ULONG64(GetData() + dwOffset);
593 void *GetPtrOffset(DWORD dwOffset)
596 return (void *)(TADDR)*PTR_TADDR(GetData() + dwOffset);
599 #ifndef DACCESS_COMPILE
601 void SetOffsetObjectRef(DWORD dwOffset, size_t dwValue);
603 void SetOffsetPtr(DWORD dwOffset, LPVOID value)
606 *(LPVOID *) &GetData()[dwOffset] = value;
609 void SetOffset32(DWORD dwOffset, DWORD dwValue)
612 *(DWORD *) &GetData()[dwOffset] = dwValue;
615 void SetOffset16(DWORD dwOffset, DWORD dwValue)
618 *(USHORT *) &GetData()[dwOffset] = (USHORT) dwValue;
621 void SetOffset8(DWORD dwOffset, DWORD dwValue)
624 *(BYTE *) &GetData()[dwOffset] = (BYTE) dwValue;
627 void SetOffset64(DWORD dwOffset, __int64 qwValue)
630 *(__int64 *) &GetData()[dwOffset] = qwValue;
633 #endif // #ifndef DACCESS_COMPILE
635 VOID Validate(BOOL bDeep = TRUE, BOOL bVerifyNextHeader = TRUE, BOOL bVerifySyncBlock = TRUE);
637 PTR_MethodTable GetGCSafeMethodTable() const
639 LIMITED_METHOD_CONTRACT;
642 // lose GC marking bit and the pinning bit
643 // A method table pointer should always be aligned. During GC we set the least
644 // significant bit for marked objects and we set the second to least significant
645 // bit for pinned objects. So if we want the actual MT pointer during a GC
646 // we must zero out the lowest 2 bits.
647 return dac_cast<PTR_MethodTable>((dac_cast<TADDR>(m_pMethTab)) & ~((UINT_PTR)3));
650 // There are some cases where it is unsafe to get the type handle during a GC.
651 // This occurs when the type has already been unloaded as part of an in-progress appdomain shutdown.
652 TypeHandle GetGCSafeTypeHandleIfPossible() const;
654 inline TypeHandle GetGCSafeTypeHandle() const;
656 #ifdef DACCESS_COMPILE
657 void EnumMemoryRegions(void);
661 VOID ValidateInner(BOOL bDeep, BOOL bVerifyNextHeader, BOOL bVerifySyncBlock);
663 #if CHECK_APP_DOMAIN_LEAKS
664 friend class ObjHeader;
665 BOOL SetFieldsAgile(BOOL raiseAssert = TRUE, SetAppDomainAgilePendingTable *pTable = NULL);
666 static BOOL SetClassFieldsAgile(MethodTable *pMT, void *base, BOOL baseIsVT, BOOL raiseAssert = TRUE, SetAppDomainAgilePendingTable *pTable = NULL);
667 static BOOL ValidateClassFields(MethodTable *pMT, void *base, BOOL baseIsVT, AppDomain *pAppDomain, BOOL raiseAssert = TRUE);
668 BOOL SetAppDomainAgileWorker(BOOL raiseAssert, SetAppDomainAgilePendingTable *pTable);
669 BOOL ShouldCheckAppDomainAgile(BOOL raiseAssert, BOOL *pfResult);
675 * Object ref setting routines. You must use these to do
676 * proper write barrier support, as well as app domain
679 * Note that the AppDomain parameter is the app domain affinity
680 * of the object containing the field or value class. It should
681 * be NULL if the containing object is app domain agile. Note that
682 * you typically get this value by calling obj->GetAppDomain() on
683 * the containing object.
686 // SetObjectReference sets an OBJECTREF field
688 void SetObjectReferenceUnchecked(OBJECTREF *dst,OBJECTREF ref);
691 void EnableStressHeapHelper();
694 //Used to clear the object reference
695 inline void ClearObjectReference(OBJECTREF* dst)
697 LIMITED_METHOD_CONTRACT;
698 *(void**)(dst) = NULL;
701 // CopyValueClass sets a value class field
703 void STDCALL CopyValueClassUnchecked(void* dest, void* src, MethodTable *pMT);
705 inline void InitValueClass(void *dest, MethodTable *pMT)
708 ZeroMemoryInGCHeap(dest, pMT->GetNumInstanceFieldBytes());
711 #if CHECK_APP_DOMAIN_LEAKS
713 void SetObjectReferenceChecked(OBJECTREF *dst,OBJECTREF ref, AppDomain *pAppDomain);
714 void CopyValueClassChecked(void* dest, void* src, MethodTable *pMT, AppDomain *pAppDomain);
716 #define SetObjectReference(_d,_r,_a) SetObjectReferenceChecked(_d, _r, _a)
717 #define CopyValueClass(_d,_s,_m,_a) CopyValueClassChecked(_d,_s,_m,_a)
721 #define SetObjectReference(_d,_r,_a) SetObjectReferenceUnchecked(_d, _r)
722 #define CopyValueClass(_d,_s,_m,_a) CopyValueClassUnchecked(_d,_s,_m)
726 #include <pshpack4.h>
729 // There are two basic kinds of array layouts in COM+
730 // ELEMENT_TYPE_ARRAY - a multidimensional array with lower bounds on the dims
731 // ELMENNT_TYPE_SZARRAY - A zero based single dimensional array
733 // In addition the layout of an array in memory is also affected by
734 // whether the method table is shared (eg in the case of arrays of object refs)
735 // or not. In the shared case, the array has to hold the type handle of
738 // ArrayBase encapuslates all of these details. In theory you should never
739 // have to peek inside this abstraction
741 class ArrayBase : public Object
744 friend class CObjectHeader;
746 friend OBJECTREF AllocateArrayEx(TypeHandle arrayClass, INT32 *pArgs, DWORD dwNumArgs, BOOL bAllocateInLargeHeap DEBUG_ARG(BOOL bDontSetAppDomain));
747 friend OBJECTREF FastAllocatePrimitiveArray(MethodTable* arrayType, DWORD cElements, BOOL bAllocateInLargeHeap);
748 friend class JIT_TrialAlloc;
749 friend class CheckAsmOffsets;
750 friend struct _DacGlobals;
753 // This MUST be the first field, so that it directly follows Object. This is because
754 // Object::GetSize() looks at m_NumComponents even though it may not be an array (the
755 // values is shifted out if not an array, so it's ok).
756 DWORD m_NumComponents;
761 SVAL_DECL(INT32, s_arrayBoundsZero); // = 0
763 // What comes after this conceputally is:
764 // TypeHandle elementType; Only present if the method table is shared among many types (arrays of pointers)
765 // INT32 bounds[rank]; The bounds are only present for Multidimensional arrays
766 // INT32 lowerBounds[rank]; Valid indexes are lowerBounds[i] <= index[i] < lowerBounds[i] + bounds[i]
769 // Gets the unique type handle for this array object.
770 // This will call the loader in don't-load mode - the allocator
771 // always makes sure that the particular ArrayTypeDesc for this array
772 // type is available before allocating any instances of this array type.
773 inline TypeHandle GetTypeHandle() const;
775 inline static TypeHandle GetTypeHandle(MethodTable * pMT);
777 // Get the element type for the array, this works whether the the element
778 // type is stored in the array or not
779 inline TypeHandle GetArrayElementTypeHandle() const;
781 // Get the CorElementType for the elements in the array. Avoids creating a TypeHandle
782 inline CorElementType GetArrayElementType() const;
784 inline unsigned GetRank() const;
786 // Total element count for the array
787 inline DWORD GetNumComponents() const;
789 // Get pointer to elements, handles any number of dimensions
790 PTR_BYTE GetDataPtr(BOOL inGC = FALSE) const {
791 LIMITED_METHOD_CONTRACT;
794 #ifndef DACCESS_COMPILE
795 EnableStressHeapHelper();
798 return dac_cast<PTR_BYTE>(this) +
799 GetDataPtrOffset(inGC ? GetGCSafeMethodTable() : GetMethodTable());
802 // The component size is actually 16-bit WORD, but this method is returning SIZE_T to ensure
803 // that SIZE_T is used everywhere for object size computation. It is necessary to support
804 // objects bigger than 2GB.
805 SIZE_T GetComponentSize() const {
808 #if CHECK_APP_DOMAIN_LEAKS
809 pMT = GetGCSafeMethodTable();
811 pMT = GetMethodTable();
812 #endif //CHECK_APP_DOMAIN_LEAKS
813 _ASSERTE(pMT->HasComponentSize());
814 return pMT->RawGetComponentSize();
817 // Note that this can be a multidimensional array of rank 1
818 // (for example if we had a 1-D array with lower bounds
819 BOOL IsMultiDimArray() const {
822 return(GetMethodTable()->IsMultiDimArray());
825 // Get pointer to the begining of the bounds (counts for each dim)
826 // Works for any array type
827 PTR_INT32 GetBoundsPtr() const {
829 MethodTable * pMT = GetMethodTable();
830 if (pMT->IsMultiDimArray())
832 return dac_cast<PTR_INT32>(
833 dac_cast<TADDR>(this) + sizeof(*this));
837 return dac_cast<PTR_INT32>(PTR_HOST_MEMBER_TADDR(ArrayBase, this,
842 // Works for any array type
843 PTR_INT32 GetLowerBoundsPtr() const {
845 if (IsMultiDimArray())
847 // Lower bounds info is after total bounds info
848 // and total bounds info has rank elements
849 return GetBoundsPtr() + GetRank();
852 return dac_cast<PTR_INT32>(GVAL_ADDR(s_arrayBoundsZero));
855 static unsigned GetOffsetOfNumComponents() {
856 LIMITED_METHOD_CONTRACT;
857 return offsetof(ArrayBase, m_NumComponents);
860 inline static unsigned GetDataPtrOffset(MethodTable* pMT);
862 inline static unsigned GetBoundsOffset(MethodTable* pMT);
863 inline static unsigned GetLowerBoundsOffset(MethodTable* pMT);
867 // Template used to build all the non-object
868 // arrays of a single dimension
871 template < class KIND >
872 class Array : public ArrayBase
876 typedef DPTR(KIND) PTR_KIND;
877 typedef DPTR(const KIND) PTR_CKIND;
881 PTR_KIND GetDirectPointerToNonObjectElements()
886 return PTR_KIND(GetDataPtr()); // This also handles arrays of dim 1 with lower bounds present
890 PTR_CKIND GetDirectConstPointerToNonObjectElements() const
894 return PTR_CKIND(GetDataPtr()); // This also handles arrays of dim 1 with lower bounds present
899 // Warning: Use PtrArray only for single dimensional arrays, not multidim arrays.
900 class PtrArray : public ArrayBase
903 friend class ClrDataAccess;
904 friend OBJECTREF AllocateArrayEx(TypeHandle arrayClass, INT32 *pArgs, DWORD dwNumArgs, BOOL bAllocateInLargeHeap);
905 friend class JIT_TrialAlloc;
906 friend class CheckAsmOffsets;
909 TypeHandle GetArrayElementTypeHandle()
911 LIMITED_METHOD_CONTRACT;
912 return GetMethodTable()->GetApproxArrayElementTypeHandle();
915 static SIZE_T GetDataOffset()
917 LIMITED_METHOD_CONTRACT;
918 return offsetof(PtrArray, m_Array);
921 void SetAt(SIZE_T i, OBJECTREF ref)
931 _ASSERTE(i < GetNumComponents());
932 SetObjectReference(m_Array + i, ref, GetAppDomain());
935 void ClearAt(SIZE_T i)
938 _ASSERTE(i < GetNumComponents());
939 ClearObjectReference(m_Array + i);
942 OBJECTREF GetAt(SIZE_T i)
944 LIMITED_METHOD_CONTRACT;
946 _ASSERTE(i < GetNumComponents());
948 // DAC doesn't know the true size of this array
949 // the compiler thinks it is size 1, but really it is size N hanging off the structure
950 #ifndef DACCESS_COMPILE
953 TADDR arrayTargetAddress = dac_cast<TADDR>(this) + offsetof(PtrArray, m_Array);
954 __ArrayDPtr<OBJECTREF> targetArray = dac_cast< __ArrayDPtr<OBJECTREF> >(arrayTargetAddress);
955 return targetArray[i];
959 friend class StubLinkerCPU;
960 #ifdef FEATURE_ARRAYSTUB_AS_IL
961 friend class ArrayOpLinker;
964 OBJECTREF m_Array[1];
967 /* a TypedByRef is a structure that is used to implement VB's BYREF variants.
968 it is basically a tuple of an address of some data along with a TypeHandle
969 that indicates the type of the address */
978 typedef DPTR(TypedByRef) PTR_TypedByRef;
980 typedef Array<I1> I1Array;
981 typedef Array<I2> I2Array;
982 typedef Array<I4> I4Array;
983 typedef Array<I8> I8Array;
984 typedef Array<R4> R4Array;
985 typedef Array<R8> R8Array;
986 typedef Array<U1> U1Array;
987 typedef Array<U1> BOOLArray;
988 typedef Array<U2> U2Array;
989 typedef Array<WCHAR> CHARArray;
990 typedef Array<U4> U4Array;
991 typedef Array<U8> U8Array;
992 typedef PtrArray PTRArray;
994 typedef DPTR(I1Array) PTR_I1Array;
995 typedef DPTR(I2Array) PTR_I2Array;
996 typedef DPTR(I4Array) PTR_I4Array;
997 typedef DPTR(I8Array) PTR_I8Array;
998 typedef DPTR(R4Array) PTR_R4Array;
999 typedef DPTR(R8Array) PTR_R8Array;
1000 typedef DPTR(U1Array) PTR_U1Array;
1001 typedef DPTR(BOOLArray) PTR_BOOLArray;
1002 typedef DPTR(U2Array) PTR_U2Array;
1003 typedef DPTR(CHARArray) PTR_CHARArray;
1004 typedef DPTR(U4Array) PTR_U4Array;
1005 typedef DPTR(U8Array) PTR_U8Array;
1006 typedef DPTR(PTRArray) PTR_PTRArray;
1010 #ifdef USE_CHECKED_OBJECTREFS
1011 typedef REF<ArrayBase> BASEARRAYREF;
1012 typedef REF<I1Array> I1ARRAYREF;
1013 typedef REF<I2Array> I2ARRAYREF;
1014 typedef REF<I4Array> I4ARRAYREF;
1015 typedef REF<I8Array> I8ARRAYREF;
1016 typedef REF<R4Array> R4ARRAYREF;
1017 typedef REF<R8Array> R8ARRAYREF;
1018 typedef REF<U1Array> U1ARRAYREF;
1019 typedef REF<BOOLArray> BOOLARRAYREF;
1020 typedef REF<U2Array> U2ARRAYREF;
1021 typedef REF<U4Array> U4ARRAYREF;
1022 typedef REF<U8Array> U8ARRAYREF;
1023 typedef REF<CHARArray> CHARARRAYREF;
1024 typedef REF<PTRArray> PTRARRAYREF; // Warning: Use PtrArray only for single dimensional arrays, not multidim arrays.
1025 typedef REF<StringObject> STRINGREF;
1027 #else // USE_CHECKED_OBJECTREFS
1029 typedef PTR_ArrayBase BASEARRAYREF;
1030 typedef PTR_I1Array I1ARRAYREF;
1031 typedef PTR_I2Array I2ARRAYREF;
1032 typedef PTR_I4Array I4ARRAYREF;
1033 typedef PTR_I8Array I8ARRAYREF;
1034 typedef PTR_R4Array R4ARRAYREF;
1035 typedef PTR_R8Array R8ARRAYREF;
1036 typedef PTR_U1Array U1ARRAYREF;
1037 typedef PTR_BOOLArray BOOLARRAYREF;
1038 typedef PTR_U2Array U2ARRAYREF;
1039 typedef PTR_U4Array U4ARRAYREF;
1040 typedef PTR_U8Array U8ARRAYREF;
1041 typedef PTR_CHARArray CHARARRAYREF;
1042 typedef PTR_PTRArray PTRARRAYREF; // Warning: Use PtrArray only for single dimensional arrays, not multidim arrays.
1043 typedef PTR_StringObject STRINGREF;
1045 #endif // USE_CHECKED_OBJECTREFS
1048 #include <poppack.h>
1054 * Special String implementation for performance.
1056 * m_ArrayLength - Length of buffer (m_Characters) in number of WCHARs
1057 * m_StringLength - Length of string in number of WCHARs, may be smaller
1058 * than the m_ArrayLength implying that there is extra
1059 * space at the end. The high two bits of this field are used
1060 * to indicate if the String has characters higher than 0x7F
1061 * m_Characters - The string buffer
1067 * The high bit state can be one of three value:
1068 * STRING_STATE_HIGH_CHARS: We've examined the string and determined that it definitely has values greater than 0x80
1069 * STRING_STATE_FAST_OPS: We've examined the string and determined that it definitely has no chars greater than 0x80
1070 * STRING_STATE_UNDETERMINED: We've never examined this string.
1071 * We've also reserved another bit for future use.
1074 #define STRING_STATE_UNDETERMINED 0x00000000
1075 #define STRING_STATE_HIGH_CHARS 0x40000000
1076 #define STRING_STATE_FAST_OPS 0x80000000
1077 #define STRING_STATE_SPECIAL_SORT 0xC0000000
1080 #pragma warning(disable : 4200) // disable zero-sized array warning
1082 class StringObject : public Object
1084 #ifdef DACCESS_COMPILE
1085 friend class ClrDataAccess;
1087 friend class GCHeap;
1088 friend class JIT_TrialAlloc;
1089 friend class CheckAsmOffsets;
1090 friend class COMString;
1093 DWORD m_StringLength;
1094 WCHAR m_Characters[0];
1095 // GC will see a StringObject like this:
1096 // DWORD m_StringLength
1097 // WCHAR m_Characters[0]
1098 // DWORD m_OptionalPadding (this is an optional field and will appear based on need)
1101 VOID SetStringLength(DWORD len) { LIMITED_METHOD_CONTRACT; _ASSERTE(len >= 0); m_StringLength = len; }
1104 StringObject() {LIMITED_METHOD_CONTRACT; }
1105 ~StringObject() {LIMITED_METHOD_CONTRACT; }
1108 static SIZE_T GetSize(DWORD stringLength);
1110 DWORD GetStringLength() { LIMITED_METHOD_DAC_CONTRACT; return( m_StringLength );}
1111 WCHAR* GetBuffer() { LIMITED_METHOD_CONTRACT; _ASSERTE(this != nullptr); return (WCHAR*)( dac_cast<TADDR>(this) + offsetof(StringObject, m_Characters) ); }
1112 WCHAR* GetBuffer(DWORD *pdwSize) { LIMITED_METHOD_CONTRACT; _ASSERTE((this != nullptr) && pdwSize); *pdwSize = GetStringLength(); return GetBuffer(); }
1113 WCHAR* GetBufferNullable() { LIMITED_METHOD_CONTRACT; return( (this == nullptr) ? nullptr : (WCHAR*)( dac_cast<TADDR>(this) + offsetof(StringObject, m_Characters) ) ); }
1115 DWORD GetHighCharState() {
1116 WRAPPER_NO_CONTRACT;
1117 DWORD ret = GetHeader()->GetBits() & (BIT_SBLK_STRING_HIGH_CHAR_MASK);
1121 VOID SetHighCharState(DWORD value) {
1122 WRAPPER_NO_CONTRACT;
1123 _ASSERTE(value==STRING_STATE_HIGH_CHARS || value==STRING_STATE_FAST_OPS
1124 || value==STRING_STATE_UNDETERMINED || value==STRING_STATE_SPECIAL_SORT);
1126 // you need to clear the present state before going to a new state, but we'll allow multiple threads to set it to the same thing.
1127 _ASSERTE((GetHighCharState() == STRING_STATE_UNDETERMINED) || (GetHighCharState()==value));
1129 static_assert_no_msg(BIT_SBLK_STRING_HAS_NO_HIGH_CHARS == STRING_STATE_FAST_OPS &&
1130 STRING_STATE_HIGH_CHARS == BIT_SBLK_STRING_HIGH_CHARS_KNOWN &&
1131 STRING_STATE_SPECIAL_SORT == BIT_SBLK_STRING_HAS_SPECIAL_SORT);
1133 GetHeader()->SetBit(value);
1136 static UINT GetBufferOffset()
1138 LIMITED_METHOD_DAC_CONTRACT;
1139 return (UINT)(offsetof(StringObject, m_Characters));
1141 static UINT GetStringLengthOffset()
1143 LIMITED_METHOD_CONTRACT;
1144 return (UINT)(offsetof(StringObject, m_StringLength));
1146 VOID GetSString(SString &result)
1148 WRAPPER_NO_CONTRACT;
1149 result.Set(GetBuffer(), GetStringLength());
1151 //========================================================================
1152 // Creates a System.String object. All the functions that take a length
1153 // or a count of bytes will add the null terminator after length
1154 // characters. So this means that if you have a string that has 5
1155 // characters and the null terminator you should pass in 5 and NOT 6.
1156 //========================================================================
1157 static STRINGREF NewString(int length);
1158 static STRINGREF NewString(int length, BOOL bHasTrailByte);
1159 static STRINGREF NewString(const WCHAR *pwsz);
1160 static STRINGREF NewString(const WCHAR *pwsz, int length);
1161 static STRINGREF NewString(LPCUTF8 psz);
1162 static STRINGREF NewString(LPCUTF8 psz, int cBytes);
1164 static STRINGREF GetEmptyString();
1165 static STRINGREF* GetEmptyStringRefPtr();
1167 static STRINGREF* InitEmptyStringRefPtr();
1169 static STRINGREF __stdcall StringInitCharHelper(LPCSTR pszSource, int length);
1170 DWORD InternalCheckHighChars();
1172 BOOL HasTrailByte();
1173 BOOL GetTrailByte(BYTE *bTrailByte);
1174 BOOL SetTrailByte(BYTE bTrailByte);
1175 static BOOL CaseInsensitiveCompHelper(__in_ecount(aLength) WCHAR * strA, __in_z INT8 * strB, int aLength, int bLength, int *result);
1178 //has to use raw object to avoid recursive validation
1179 BOOL ValidateHighChars ();
1180 #endif //VERIFY_HEAP
1182 /*=================RefInterpretGetStringValuesDangerousForGC======================
1183 **N.B.: This perfoms no range checking and relies on the caller to have done this.
1184 **Args: (IN)ref -- the String to be interpretted.
1185 ** (OUT)chars -- a pointer to the characters in the buffer.
1186 ** (OUT)length -- a pointer to the length of the buffer.
1189 ==============================================================================*/
1190 // !!!! If you use this function, you have to be careful because chars is a pointer
1191 // !!!! to the data buffer of ref. If GC happens after this call, you need to make
1192 // !!!! sure that you have a pin handle on ref, or use GCPROTECT_BEGINPINNING on ref.
1193 void RefInterpretGetStringValuesDangerousForGC(__deref_out_ecount(*length + 1) WCHAR **chars, int *length) {
1194 WRAPPER_NO_CONTRACT;
1196 _ASSERTE(GetGCSafeMethodTable() == g_pStringClass);
1197 *length = GetStringLength();
1198 *chars = GetBuffer();
1200 EnableStressHeapHelper();
1206 static INT32 FastCompareStringHelper(DWORD* strAChars, INT32 countA, DWORD* strBChars, INT32 countB);
1208 static STRINGREF* EmptyStringRefPtr;
1211 //The first two macros are essentially the same. I just define both because
1212 //having both can make the code more readable.
1213 #define IS_FAST_SORT(state) (((state) == STRING_STATE_FAST_OPS))
1214 #define IS_SLOW_SORT(state) (((state) != STRING_STATE_FAST_OPS))
1216 //This macro should be used to determine things like indexing, casing, and encoding.
1217 #define IS_FAST_OPS_EXCEPT_SORT(state) (((state)==STRING_STATE_SPECIAL_SORT) || ((state)==STRING_STATE_FAST_OPS))
1218 #define IS_ASCII(state) (((state)==STRING_STATE_SPECIAL_SORT) || ((state)==STRING_STATE_FAST_OPS))
1219 #define IS_FAST_CASING(state) IS_ASCII(state)
1220 #define IS_FAST_INDEX(state) IS_ASCII(state)
1221 #define IS_STRING_STATE_UNDETERMINED(state) ((state)==STRING_STATE_UNDETERMINED)
1222 #define HAS_HIGH_CHARS(state) ((state)==STRING_STATE_HIGH_CHARS)
1224 /*================================GetEmptyString================================
1225 **Get a reference to the empty string. If we haven't already gotten one, we
1226 **query the String class for a pointer to the empty string that we know was
1227 **created at startup.
1230 **Returns: A STRINGREF to the EmptyString
1232 ==============================================================================*/
1233 inline STRINGREF StringObject::GetEmptyString() {
1240 STRINGREF* refptr = EmptyStringRefPtr;
1242 //If we've never gotten a reference to the EmptyString, we need to go get one.
1244 refptr = InitEmptyStringRefPtr();
1246 //We've already have a reference to the EmptyString, so we can just return it.
1250 inline STRINGREF* StringObject::GetEmptyStringRefPtr() {
1257 STRINGREF* refptr = EmptyStringRefPtr;
1259 //If we've never gotten a reference to the EmptyString, we need to go get one.
1261 refptr = InitEmptyStringRefPtr();
1263 //We've already have a reference to the EmptyString, so we can just return it.
1267 // This is used to account for the remoting cache on RuntimeType,
1268 // RuntimeMethodInfo, and RtFieldInfo.
1269 class BaseObjectWithCachedData : public Object
1271 #ifdef FEATURE_REMOTING
1273 OBJECTREF m_CachedData;
1274 #endif //FEATURE_REMOTING
1278 // This is the Class version of the Reflection object.
1279 // A Class has adddition information.
1280 // For a ReflectClassBaseObject the m_pData is a pointer to a FieldDesc array that
1281 // contains all of the final static primitives if its defined.
1282 // m_cnt = the number of elements defined in the m_pData FieldDesc array. -1 means
1283 // this hasn't yet been defined.
1284 class ReflectClassBaseObject : public BaseObjectWithCachedData
1286 friend class MscorlibBinder;
1289 OBJECTREF m_keepalive;
1291 TypeHandle m_typeHandle;
1293 UINT32 m_invocationFlags;
1308 MethodTable *pMT = GetMethodTable();
1309 while (pMT != g_pRuntimeTypeClass && pMT != NULL)
1311 pMT = pMT->GetParentMethodTable();
1313 _ASSERTE(pMT == g_pRuntimeTypeClass);
1318 void SetType(TypeHandle type) {
1328 INDEBUG(TypeCheck());
1329 m_typeHandle = type;
1332 void SetKeepAlive(OBJECTREF keepalive)
1343 INDEBUG(TypeCheck());
1344 SetObjectReference(&m_keepalive, keepalive, GetAppDomain());
1347 TypeHandle GetType() {
1357 INDEBUG(TypeCheck());
1358 return m_typeHandle;
1364 // This is the Method version of the Reflection object.
1365 // A Method has adddition information.
1366 // m_pMD - A pointer to the actual MethodDesc of the method.
1367 // m_object - a field that has a reference type in it. Used only for RuntimeMethodInfoStub to keep the real type alive.
1368 // This structure matches the structure up to the m_pMD for several different managed types.
1369 // (RuntimeConstructorInfo, RuntimeMethodInfo, and RuntimeMethodInfoStub). These types are unrelated in the type
1370 // system except that they all implement a particular interface. It is important that that interface is not attached to any
1371 // type that does not sufficiently match this data structure.
1372 class ReflectMethodObject : public BaseObjectWithCachedData
1374 friend class MscorlibBinder;
1388 void SetMethod(MethodDesc *pMethod) {
1389 LIMITED_METHOD_CONTRACT;
1393 // This must only be called on instances of ReflectMethodObject that are actually RuntimeMethodInfoStub
1394 void SetKeepAlive(OBJECTREF keepalive)
1396 WRAPPER_NO_CONTRACT;
1397 SetObjectReference(&m_object, keepalive, GetAppDomain());
1400 MethodDesc *GetMethod() {
1401 LIMITED_METHOD_CONTRACT;
1407 // This is the Field version of the Reflection object.
1408 // A Method has adddition information.
1409 // m_pFD - A pointer to the actual MethodDesc of the method.
1410 // m_object - a field that has a reference type in it. Used only for RuntimeFieldInfoStub to keep the real type alive.
1411 // This structure matches the structure up to the m_pFD for several different managed types.
1412 // (RtFieldInfo and RuntimeFieldInfoStub). These types are unrelated in the type
1413 // system except that they all implement a particular interface. It is important that that interface is not attached to any
1414 // type that does not sufficiently match this data structure.
1415 class ReflectFieldObject : public BaseObjectWithCachedData
1417 friend class MscorlibBinder;
1428 void SetField(FieldDesc *pField) {
1429 LIMITED_METHOD_CONTRACT;
1433 // This must only be called on instances of ReflectFieldObject that are actually RuntimeFieldInfoStub
1434 void SetKeepAlive(OBJECTREF keepalive)
1436 WRAPPER_NO_CONTRACT;
1437 SetObjectReference(&m_object, keepalive, GetAppDomain());
1440 FieldDesc *GetField() {
1441 LIMITED_METHOD_CONTRACT;
1446 // ReflectModuleBaseObject
1447 // This class is the base class for managed Module.
1448 // This class will connect the Object back to the underlying VM representation
1449 // m_ReflectClass -- This is the real Class that was used for reflection
1450 // This class was used to get at this object
1451 // m_pData -- this is a generic pointer which usually points CorModule
1453 class ReflectModuleBaseObject : public Object
1455 friend class MscorlibBinder;
1459 // Modifying the order or fields of this object may require other changes to the
1460 // classlib class definition of this object.
1461 OBJECTREF m_runtimeType;
1462 OBJECTREF m_runtimeAssembly;
1463 void* m_ReflectClass; // Pointer to the ReflectClass structure
1464 Module* m_pData; // Pointer to the Module
1465 void* m_pGlobals; // Global values....
1466 void* m_pGlobalsFlds; // Global Fields....
1469 ReflectModuleBaseObject() {LIMITED_METHOD_CONTRACT;}
1470 ~ReflectModuleBaseObject() {LIMITED_METHOD_CONTRACT;}
1473 void SetModule(Module* p) {
1474 LIMITED_METHOD_CONTRACT;
1477 Module* GetModule() {
1478 LIMITED_METHOD_CONTRACT;
1481 void SetAssembly(OBJECTREF assembly)
1483 WRAPPER_NO_CONTRACT;
1484 SetObjectReference(&m_runtimeAssembly, assembly, GetAppDomain());
1488 NOINLINE ReflectModuleBaseObject* GetRuntimeModuleHelper(LPVOID __me, Module *pModule, OBJECTREF keepAlive);
1489 #define FC_RETURN_MODULE_OBJECT(pModule, refKeepAlive) FC_INNER_RETURN(ReflectModuleBaseObject*, GetRuntimeModuleHelper(__me, pModule, refKeepAlive))
1493 #ifdef USE_CHECKED_OBJECTREFS
1494 typedef REF<SafeHandle> SAFEHANDLE;
1495 typedef REF<SafeHandle> SAFEHANDLEREF;
1496 #else // USE_CHECKED_OBJECTREFS
1497 typedef SafeHandle * SAFEHANDLE;
1498 typedef SafeHandle * SAFEHANDLEREF;
1499 #endif // USE_CHECKED_OBJECTREFS
1501 class PermissionListSetObject: public Object
1503 friend class MscorlibBinder;
1506 OBJECTREF _firstPermSetTriple;
1507 OBJECTREF _permSetTriples;
1508 #ifdef FEATURE_COMPRESSEDSTACK
1509 OBJECTREF _zoneList;
1510 OBJECTREF _originList;
1511 #endif // FEATURE_COMPRESSEDSTACK
1516 LIMITED_METHOD_CONTRACT;
1517 return (_firstPermSetTriple == NULL &&
1518 _permSetTriples == NULL
1519 #ifdef FEATURE_COMPRESSEDSTACK
1520 && _zoneList == NULL &&
1522 #endif // FEATURE_COMPRESSEDSTACK
1527 #ifdef USE_CHECKED_OBJECTREFS
1528 typedef REF<PermissionListSetObject> PERMISSIONLISTSETREF;
1530 typedef PermissionListSetObject* PERMISSIONLISTSETREF;
1532 #ifdef FEATURE_COMPRESSEDSTACK
1533 class CompressedStackObject: public Object
1535 friend class MscorlibBinder;
1538 // These field are also defined in the managed representation. (CompressedStack.cs)If you
1539 // add or change these field you must also change the managed code so that
1540 // it matches these. This is necessary so that the object is the proper
1542 PERMISSIONLISTSETREF m_pls;
1543 SAFEHANDLEREF m_compressedStackHandle;
1546 void* GetUnmanagedCompressedStack();
1549 LIMITED_METHOD_CONTRACT;
1550 return (m_pls == NULL || m_pls->IsEmpty());
1554 #ifdef USE_CHECKED_OBJECTREFS
1555 typedef REF<CompressedStackObject> COMPRESSEDSTACKREF;
1557 typedef CompressedStackObject* COMPRESSEDSTACKREF;
1559 #endif // #ifdef FEATURE_COMPRESSEDSTACK
1561 #if defined(FEATURE_IMPERSONATION) || defined(FEATURE_COMPRESSEDSTACK)
1562 class SecurityContextObject: public Object
1564 friend class MscorlibBinder;
1568 // These field are also defined in the managed representation. (SecurityContext.cs)If you
1569 // add or change these field you must also change the managed code so that
1570 // it matches these. This is necessary so that the object is the proper
1573 OBJECTREF _executionContext;
1574 #ifdef FEATURE_IMPERSONATION
1575 OBJECTREF _windowsIdentity;
1576 #endif // FEATURE_IMPERSONATION
1577 #ifdef FEATURE_COMPRESSEDSTACK
1578 COMPRESSEDSTACKREF _compressedStack;
1579 #endif // FEATURE_COMPRESSEDSTACK
1581 CLR_BOOL _isNewCapture;
1583 #ifdef FEATURE_COMPRESSEDSTACK
1584 COMPRESSEDSTACKREF GetCompressedStack()
1586 LIMITED_METHOD_CONTRACT;
1587 return _compressedStack;
1589 #endif // #ifdef FEATURE_COMPRESSEDSTACK
1592 #ifdef USE_CHECKED_OBJECTREFS
1593 typedef REF<SecurityContextObject> SECURITYCONTEXTREF;
1595 typedef SecurityContextObject* SECURITYCONTEXTREF;
1597 #endif // #if defined(FEATURE_IMPERSONATION) || defined(FEATURE_COMPRESSEDSTACK)
1599 #ifdef FEATURE_SYNCHRONIZATIONCONTEXT_WAIT
1600 #define SYNCCTXPROPS_REQUIRESWAITNOTIFICATION 0x1 // Keep in sync with SynchronizationContext.cs SynchronizationContextFlags
1601 class ThreadBaseObject;
1602 class SynchronizationContextObject: public Object
1604 friend class MscorlibBinder;
1606 // These field are also defined in the managed representation. (SecurityContext.cs)If you
1607 // add or change these field you must also change the managed code so that
1608 // it matches these. This is necessary so that the object is the proper
1612 BOOL IsWaitNotificationRequired()
1614 LIMITED_METHOD_CONTRACT;
1615 if ((_props & SYNCCTXPROPS_REQUIRESWAITNOTIFICATION) != 0)
1620 #endif // FEATURE_SYNCHRONIZATIONCONTEXT_WAIT
1622 #ifdef FEATURE_REMOTING
1623 class CallContextRemotingDataObject : public Object
1626 // These field are also defined in the managed representation. (SecurityContext.cs)If you
1627 // add or change these field you must also change the managed code so that
1628 // it matches these. This is necessary so that the object is the proper
1630 OBJECTREF _logicalCallID;
1632 OBJECTREF GetLogicalCallID()
1634 LIMITED_METHOD_CONTRACT;
1635 return _logicalCallID;
1639 class CallContextSecurityDataObject : public Object
1642 // These field are also defined in the managed representation. (SecurityContext.cs)If you
1643 // add or change these field you must also change the managed code so that
1644 // it matches these. This is necessary so that the object is the proper
1646 OBJECTREF _principal;
1648 OBJECTREF GetPrincipal()
1650 LIMITED_METHOD_CONTRACT;
1654 void SetPrincipal(OBJECTREF ref)
1656 WRAPPER_NO_CONTRACT;
1657 SetObjectReferenceUnchecked(&_principal, ref);
1661 #ifdef USE_CHECKED_OBJECTREFS
1662 typedef REF<CallContextSecurityDataObject> CCSECURITYDATAREF;
1663 typedef REF<CallContextRemotingDataObject> CCREMOTINGDATAREF;
1665 typedef CallContextSecurityDataObject* CCSECURITYDATAREF;
1666 typedef CallContextRemotingDataObject* CCREMOTINGDATAREF;
1669 class LogicalCallContextObject : public Object
1671 friend class MscorlibBinder;
1673 // These field are also defined in the managed representation. (CallContext.cs) If you
1674 // add or change these field you must also change the managed code so that
1675 // it matches these. This is necessary so that the object is the proper
1678 OBJECTREF m_Datastore;
1679 CCREMOTINGDATAREF m_RemotingData;
1680 CCSECURITYDATAREF m_SecurityData;
1681 OBJECTREF m_HostContext;
1682 OBJECTREF _sendHeaders;
1683 OBJECTREF _recvHeaders;
1684 CLR_BOOL m_IsCorrelationMgr;
1687 CCSECURITYDATAREF GetSecurityData()
1689 LIMITED_METHOD_CONTRACT;
1690 return m_SecurityData;
1693 // This is an unmanaged equivalent of System.Runtime.Remoting.Messaging.LogicalCallContext.HasInfo
1694 BOOL ContainsDataForSerialization()
1704 return (ContainsNonSecurityDataForSerialization() ||
1705 (m_SecurityData != NULL && m_SecurityData->GetPrincipal() != NULL));
1708 BOOL ContainsNonSecurityDataForSerialization()
1710 LIMITED_METHOD_CONTRACT;
1712 // m_Datastore may contain 0 items even if it's non-NULL in which case it does
1713 // not really contain any useful data for serialization and this function could
1714 // return FALSE. However we don't waste time trying to detect this case - it will
1715 // be reset to NULL the first time a call is made due to how LogicalCallContext's
1716 // ISerializable implementation works.
1717 return (m_Datastore != NULL ||
1718 (m_RemotingData != NULL && m_RemotingData->GetLogicalCallID() != NULL) ||
1719 m_HostContext != NULL);
1723 #ifdef USE_CHECKED_OBJECTREFS
1724 typedef REF<LogicalCallContextObject> LOGICALCALLCONTEXTREF;
1726 typedef LogicalCallContextObject* LOGICALCALLCONTEXTREF;
1729 #endif // FEATURE_REMOTING
1731 #ifndef FEATURE_CORECLR
1732 class ExecutionContextObject : public Object
1734 friend class MscorlibBinder;
1736 // These fields are also defined in the managed representation. (ExecutionContext.cs) If you
1737 // add or change these fields you must also change the managed code so that
1738 // it matches these. This is necessary so that the object is the proper
1741 #ifdef FEATURE_CAS_POLICY
1742 OBJECTREF _hostExecutionContext;
1743 #endif // FEATURE_CAS_POLICY
1744 OBJECTREF _syncContext;
1745 OBJECTREF _syncContextNoFlow;
1746 #if defined(FEATURE_IMPERSONATION) || defined(FEATURE_COMPRESSEDSTACK)
1747 SECURITYCONTEXTREF _securityContext;
1748 #endif // #if defined(FEATURE_IMPERSONATION) || defined(FEATURE_COMPRESSEDSTACK)
1749 #ifdef FEATURE_REMOTING
1750 LOGICALCALLCONTEXTREF _logicalCallContext;
1751 OBJECTREF _illogicalCallContext;
1752 #endif // #ifdef FEATURE_REMOTING
1754 OBJECTREF _localValues;
1755 OBJECTREF _localChangeNotifications;
1758 OBJECTREF GetSynchronizationContext()
1760 LIMITED_METHOD_CONTRACT;
1761 return _syncContext;
1763 #if defined(FEATURE_IMPERSONATION) || defined(FEATURE_COMPRESSEDSTACK)
1764 SECURITYCONTEXTREF GetSecurityContext()
1766 LIMITED_METHOD_CONTRACT;
1767 return _securityContext;
1769 #endif // #if defined(FEATURE_IMPERSONATION) || defined(FEATURE_COMPRESSEDSTACK)
1770 #ifdef FEATURE_REMOTING
1771 LOGICALCALLCONTEXTREF GetLogicalCallContext()
1773 LIMITED_METHOD_CONTRACT;
1774 return _logicalCallContext;
1776 void SetLogicalCallContext(LOGICALCALLCONTEXTREF ref)
1778 WRAPPER_NO_CONTRACT;
1779 SetObjectReferenceUnchecked((OBJECTREF*)&_logicalCallContext, (OBJECTREF)ref);
1781 OBJECTREF GetIllogicalCallContext()
1783 LIMITED_METHOD_CONTRACT;
1784 return _illogicalCallContext;
1786 void SetIllogicalCallContext(OBJECTREF ref)
1788 WRAPPER_NO_CONTRACT;
1789 SetObjectReferenceUnchecked((OBJECTREF*)&_illogicalCallContext, ref);
1791 #endif //#ifdef FEATURE_REMOTING
1792 #ifdef FEATURE_COMPRESSEDSTACK
1793 COMPRESSEDSTACKREF GetCompressedStack()
1795 WRAPPER_NO_CONTRACT;
1796 if (_securityContext != NULL)
1797 return _securityContext->GetCompressedStack();
1800 #endif // #ifdef FEATURE_COMPRESSEDSTACK
1803 #endif //FEATURE_CORECLR
1807 typedef DPTR(class CultureInfoBaseObject) PTR_CultureInfoBaseObject;
1809 #ifdef USE_CHECKED_OBJECTREFS
1810 #ifdef FEATURE_SYNCHRONIZATIONCONTEXT_WAIT
1811 typedef REF<SynchronizationContextObject> SYNCHRONIZATIONCONTEXTREF;
1812 #endif // FEATURE_SYNCHRONIZATIONCONTEXT_WAIT
1813 typedef REF<ExecutionContextObject> EXECUTIONCONTEXTREF;
1814 typedef REF<CultureInfoBaseObject> CULTUREINFOBASEREF;
1815 typedef REF<ArrayBase> ARRAYBASEREF;
1818 #ifdef FEATURE_SYNCHRONIZATIONCONTEXT_WAIT
1819 typedef SynchronizationContextObject* SYNCHRONIZATIONCONTEXTREF;
1820 #endif // FEATURE_SYNCHRONIZATIONCONTEXT_WAIT
1821 #ifndef FEATURE_CORECLR
1822 typedef ExecutionContextObject* EXECUTIONCONTEXTREF;
1824 typedef CultureInfoBaseObject* CULTUREINFOBASEREF;
1825 typedef PTR_ArrayBase ARRAYBASEREF;
1828 // Note that the name must always be "" or "en-US". Other cases and nulls
1829 // aren't allowed (we already checked.)
1830 __inline bool IsCultureEnglishOrInvariant(LPCWSTR localeName)
1832 LIMITED_METHOD_CONTRACT;
1833 if (localeName != NULL &&
1834 (localeName[0] == W('\0') ||
1835 wcscmp(localeName, W("en-US")) == 0))
1842 class CultureInfoBaseObject : public Object
1844 friend class MscorlibBinder;
1847 OBJECTREF compareInfo;
1849 #ifndef FEATURE_CORECLR
1850 OBJECTREF regionInfo;
1851 #endif // !FEATURE_CORECLR
1853 OBJECTREF dateTimeInfo;
1855 OBJECTREF m_cultureData;
1856 #ifndef FEATURE_CORECLR
1857 OBJECTREF m_consoleFallbackCulture;
1858 #endif // !FEATURE_CORECLR
1859 STRINGREF m_name; // "real" name - en-US, de-DE_phoneb or fj-FJ
1860 STRINGREF m_nonSortName; // name w/o sort info (de-DE for de-DE_phoneb)
1861 STRINGREF m_sortName; // Sort only name (de-DE_phoneb, en-us for fj-fj (w/us sort)
1862 CULTUREINFOBASEREF m_parent;
1863 #if !FEATURE_CORECLR
1864 INT32 iDataItem; // NEVER USED, DO NOT USE THIS! (Serialized in Whidbey/Everett)
1865 INT32 iCultureID; // NEVER USED, DO NOT USE THIS! (Serialized in Whidbey/Everett)
1866 #endif // !FEATURE_CORECLR
1867 #ifdef FEATURE_LEAK_CULTURE_INFO
1868 INT32 m_createdDomainID;
1869 #endif // FEATURE_LEAK_CULTURE_INFO
1870 CLR_BOOL m_isReadOnly;
1871 CLR_BOOL m_isInherited;
1872 #ifdef FEATURE_LEAK_CULTURE_INFO
1873 CLR_BOOL m_isSafeCrossDomain;
1874 #endif // FEATURE_LEAK_CULTURE_INFO
1875 #ifndef FEATURE_COREFX_GLOBALIZATION
1876 CLR_BOOL m_useUserOverride;
1880 CULTUREINFOBASEREF GetParent()
1882 LIMITED_METHOD_CONTRACT;
1889 LIMITED_METHOD_CONTRACT;
1893 #ifdef FEATURE_LEAK_CULTURE_INFO
1894 BOOL IsSafeCrossDomain()
1896 return m_isSafeCrossDomain;
1897 }// IsSafeCrossDomain
1899 ADID GetCreatedDomainID()
1901 return ADID(m_createdDomainID);
1902 }// GetCreatedDomain
1903 #endif // FEATURE_LEAK_CULTURE_INFO
1905 }; // class CultureInfoBaseObject
1908 #ifndef FEATURE_COREFX_GLOBALIZATION
1909 typedef DPTR(class CultureDataBaseObject) PTR_CultureDataBaseObject;
1910 class CultureDataBaseObject : public Object
1913 // offsets are for Silverlight
1914 /* 0x000 */ STRINGREF sRealName ; // Name you passed in (ie: en-US, en, or de-DE_phoneb)
1915 /* 0x008 */ STRINGREF sWindowsName ; // Name OS thinks the object is (ie: de-DE_phoneb, or en-US (even if en was passed in))
1916 /* 0x010 */ STRINGREF sName ; // locale name (ie: en-us, NO sort info, but could be neutral)
1917 /* 0x012 */ STRINGREF sParent ; // Parent name (which may be a custom locale/culture)
1918 /* 0x020 */ STRINGREF sLocalizedDisplayName ; // Localized pretty name for this locale
1919 /* 0x028 */ STRINGREF sEnglishDisplayName ; // English pretty name for this locale
1920 /* 0x030 */ STRINGREF sNativeDisplayName ; // Native pretty name for this locale
1921 /* 0x038 */ STRINGREF sSpecificCulture ; // The culture name to be used in CultureInfo.CreateSpecificCulture(), en-US form if neutral, sort name if sort
1922 /* 0x040 */ STRINGREF sISO639Language ; // ISO 639 Language Name
1923 /* 0x048 */ STRINGREF sLocalizedLanguage ; // Localized name for this language
1924 /* 0x050 */ STRINGREF sEnglishLanguage ; // English name for this language
1925 /* 0x058 */ STRINGREF sNativeLanguage ; // Native name of this language
1926 /* 0x060 */ STRINGREF sRegionName ; // (RegionInfo)
1927 /* 0x068 */ STRINGREF sLocalizedCountry ; // localized country name
1928 /* 0x070 */ STRINGREF sEnglishCountry ; // english country name (RegionInfo)
1929 /* 0x078 */ STRINGREF sNativeCountry ; // native country name
1930 /* 0x080 */ STRINGREF sISO3166CountryName ; // (RegionInfo), ie: US
1931 /* 0x088 */ STRINGREF sPositiveSign ; // (user can override) positive sign
1932 /* 0x090 */ STRINGREF sNegativeSign ; // (user can override) negative sign
1934 /* 0x098 */ PTRARRAYREF saNativeDigits ; // (user can override) native characters for digits 0-9
1935 /* 0x0a0 */ I4ARRAYREF waGrouping ; // (user can override) grouping of digits
1937 /* 0x0a8 */ STRINGREF sDecimalSeparator ; // (user can override) decimal separator
1938 /* 0x0b0 */ STRINGREF sThousandSeparator ; // (user can override) thousands separator
1939 /* 0x0b8 */ STRINGREF sNaN ; // Not a Number
1940 /* 0x0c0 */ STRINGREF sPositiveInfinity ; // + Infinity
1941 /* 0x0c8 */ STRINGREF sNegativeInfinity ; // - Infinity
1942 /* 0x0d0 */ STRINGREF sPercent ; // Percent (%) symbol
1943 /* 0x0d8 */ STRINGREF sPerMille ; // PerMille (U+2030) symbol
1944 /* 0x0e0 */ STRINGREF sCurrency ; // (user can override) local monetary symbol
1945 /* 0x0e8 */ STRINGREF sIntlMonetarySymbol ; // international monetary symbol (RegionInfo)
1946 /* 0x0f0 */ STRINGREF sEnglishCurrency ; // English name for this currency
1947 /* 0x0f8 */ STRINGREF sNativeCurrency ; // Native name for this currency
1949 /* 0x100 */ I4ARRAYREF waMonetaryGrouping ; // (user can override) monetary grouping of digits
1951 /* 0x108 */ STRINGREF sMonetaryDecimal ; // (user can override) monetary decimal separator
1952 /* 0x110 */ STRINGREF sMonetaryThousand ; // (user can override) monetary thousands separator
1953 /* 0x118 */ STRINGREF sListSeparator ; // (user can override) list separator
1954 /* 0x120 */ STRINGREF sAM1159 ; // (user can override) AM designator
1955 /* 0x128 */ STRINGREF sPM2359 ; // (user can override) PM designator
1956 STRINGREF sTimeSeparator ; // Time Separator
1958 /* 0x130 */ PTRARRAYREF saLongTimes ; // (user can override) time format
1959 /* 0x138 */ PTRARRAYREF saShortTimes ; // short time format
1960 /* 0x140 */ PTRARRAYREF saDurationFormats ; // time duration format
1962 /* 0x148 */ I4ARRAYREF waCalendars ; // all available calendar type(s). The first one is the default calendar
1964 /* 0x150 */ PTRARRAYREF calendars ; // Store for specific calendar data
1966 /* 0x158 */ STRINGREF sTextInfo ; // Text info name to use for custom
1967 /* 0x160 */ STRINGREF sCompareInfo ; // Compare info name (including sorting key) to use if custom
1968 /* 0x168 */ STRINGREF sScripts ; // Typical Scripts for this locale (latn;cyrl; etc)
1970 #if !defined(FEATURE_CORECLR)
1971 // desktop only fields - these are ordered correctly
1972 /* ????? */ STRINGREF sAbbrevLang ; // abbreviated language name (Windows Language Name) ex: ENU
1973 /* ????? */ STRINGREF sAbbrevCountry ; // abbreviated country name (RegionInfo) (Windows Region Name) ex: USA
1974 /* ????? */ STRINGREF sISO639Language2 ; // 3 char ISO 639 lang name 2 ex: eng
1975 /* ????? */ STRINGREF sISO3166CountryName2 ; // 3 char ISO 639 country name 2 2(RegionInfo) ex: USA (ISO)
1976 /* ????? */ STRINGREF sConsoleFallbackName ; // The culture name for the console fallback UI culture
1977 /* ????? */ STRINGREF sKeyboardsToInstall ; // Keyboard installation string.
1978 /* ????? */ STRINGREF fontSignature ; // Font signature (16 WORDS)
1981 // Unused for now: /* ????? */ INT32 iCountry ; // (user can override) country code (RegionInfo)
1982 /* 0x170 */ INT32 iGeoId ; // GeoId
1983 /* 0x174 */ INT32 iDigitSubstitution ; // (user can override) Digit substitution 0=context, 1=none/arabic, 2=Native/national (2 seems to be unused)
1984 /* 0x178 */ INT32 iLeadingZeros ; // (user can override) leading zeros 0 = no leading zeros, 1 = leading zeros
1985 /* 0x17c */ INT32 iDigits ; // (user can override) number of fractional digits
1986 /* 0x180 */ INT32 iNegativeNumber ; // (user can override) negative number format
1987 /* 0x184 */ INT32 iNegativePercent ; // Negative Percent (0-3)
1988 /* 0x188 */ INT32 iPositivePercent ; // Positive Percent (0-11)
1989 /* 0x18c */ INT32 iCurrencyDigits ; // (user can override) # local monetary fractional digits
1990 /* 0x190 */ INT32 iCurrency ; // (user can override) positive currency format
1991 /* 0x194 */ INT32 iNegativeCurrency ; // (user can override) negative currency format
1992 /* 0x198 */ INT32 iMeasure ; // (user can override) system of measurement 0=metric, 1=US (RegionInfo)
1993 // Unused for now /* ????? */ INT32 iPaperSize ; // default paper size (RegionInfo)
1994 /* 0x19c */ INT32 iFirstDayOfWeek ; // (user can override) first day of week (gregorian really)
1995 /* 0x1a0 */ INT32 iFirstWeekOfYear ; // (user can override) first week of year (gregorian really)
1997 /* ????? */ INT32 iReadingLayout; // Reading Layout Data (0-3)
1998 #if !defined(FEATURE_CORECLR)
1999 // desktop only fields - these are ordered correctly
2000 /* ????? */ INT32 iDefaultAnsiCodePage ; // default ansi code page ID (ACP)
2001 /* ????? */ INT32 iDefaultOemCodePage ; // default oem code page ID (OCP or OEM)
2002 /* ????? */ INT32 iDefaultMacCodePage ; // default macintosh code page
2003 /* ????? */ INT32 iDefaultEbcdicCodePage ; // default EBCDIC code page
2004 /* ????? */ INT32 iLanguage ; // locale ID (0409) - NO sort information
2005 /* ????? */ INT32 iInputLanguageHandle ; // input language handle
2007 /* 0x1a4 */ CLR_BOOL bUseOverrides ; // use user overrides?
2008 /* 0x1a5 */ CLR_BOOL bNeutral ; // Flags for the culture (ie: neutral or not right now)
2009 #if !defined(FEATURE_CORECLR)
2010 /* ????? */ CLR_BOOL bWin32Installed ; // Flags indicate if the culture is Win32 installed
2011 /* ????? */ CLR_BOOL bFramework ; // Flags for indicate if the culture is one of Whidbey cultures
2014 }; // class CultureDataBaseObject
2018 typedef DPTR(class CalendarDataBaseObject) PTR_CalendarDataBaseObject;
2019 class CalendarDataBaseObject : public Object
2022 /* 0x000 */ STRINGREF sNativeName ; // Calendar Name for the locale
2026 /* 0x008 */ PTRARRAYREF saShortDates ; // Short Data format, default first
2027 /* 0x010 */ PTRARRAYREF saYearMonths ; // Year/Month Data format, default first
2028 /* 0x018 */ PTRARRAYREF saLongDates ; // Long Data format, default first
2029 /* 0x020 */ STRINGREF sMonthDay ; // Month/Day format
2031 // Calendar Parts Names
2032 /* 0x028 */ PTRARRAYREF saEraNames ; // Names of Eras
2033 /* 0x030 */ PTRARRAYREF saAbbrevEraNames ; // Abbreviated Era Names
2034 /* 0x038 */ PTRARRAYREF saAbbrevEnglishEraNames ; // Abbreviated Era Names in English
2035 /* 0x040 */ PTRARRAYREF saDayNames ; // Day Names, null to use locale data, starts on Sunday
2036 /* 0x048 */ PTRARRAYREF saAbbrevDayNames ; // Abbrev Day Names, null to use locale data, starts on Sunday
2037 /* 0x050 */ PTRARRAYREF saSuperShortDayNames ; // Super short Day of week names
2038 /* 0x058 */ PTRARRAYREF saMonthNames ; // Month Names (13)
2039 /* 0x060 */ PTRARRAYREF saAbbrevMonthNames ; // Abbrev Month Names (13)
2040 /* 0x068 */ PTRARRAYREF saMonthGenitiveNames ; // Genitive Month Names (13)
2041 /* 0x070 */ PTRARRAYREF saAbbrevMonthGenitiveNames ; // Genitive Abbrev Month Names (13)
2042 /* 0x078 */ PTRARRAYREF saLeapYearMonthNames ; // Multiple strings for the month names in a leap year.
2044 // Integers at end to make marshaller happier
2045 /* 0x080 */ INT32 iTwoDigitYearMax ; // Max 2 digit year (for Y2K bug data entry)
2046 /* 0x084 */ INT32 iCurrentEra ; // current era # (usually 1)
2049 /* 0x088 */ CLR_BOOL bUseUserOverrides ; // True if we want user overrides.
2050 }; // class CalendarDataBaseObject
2054 typedef DPTR(class ThreadBaseObject) PTR_ThreadBaseObject;
2055 class ThreadBaseObject : public Object
2057 friend class ClrDataAccess;
2058 friend class ThreadNative;
2059 friend class MscorlibBinder;
2060 friend class Object;
2064 // These field are also defined in the managed representation. If you
2065 // add or change these field you must also change the managed code so that
2066 // it matches these. This is necessary so that the object is the proper
2067 // size. The order here must match that order which the loader will choose
2068 // when laying out the managed class. Note that the layouts are checked
2069 // at run time, not compile time.
2070 #ifdef FEATURE_REMOTING
2071 OBJECTREF m_ExposedContext;
2073 #ifndef FEATURE_CORECLR
2074 EXECUTIONCONTEXTREF m_ExecutionContext;
2077 OBJECTREF m_Delegate;
2078 #ifdef FEATURE_LEAK_CULTURE_INFO
2079 CULTUREINFOBASEREF m_CurrentUserCulture;
2080 CULTUREINFOBASEREF m_CurrentUICulture;
2082 #ifdef IO_CANCELLATION_ENABLED
2083 OBJECTREF m_CancellationSignals;
2085 OBJECTREF m_ThreadStartArg;
2087 // The next field (m_InternalThread) is declared as IntPtr in the managed
2088 // definition of Thread. The loader will sort it next.
2090 // m_InternalThread is always valid -- unless the thread has finalized and been
2091 // resurrected. (The thread stopped running before it was finalized).
2092 Thread *m_InternalThread;
2095 //We need to cache the thread id in managed code for perf reasons.
2096 INT32 m_ManagedThreadId;
2098 CLR_BOOL m_ExecutionContextBelongsToCurrentScope;
2100 CLR_BOOL m_ForbidExecutionContextMutation;
2104 // the ctor and dtor can do no useful work.
2105 ThreadBaseObject() {LIMITED_METHOD_CONTRACT;};
2106 ~ThreadBaseObject() {LIMITED_METHOD_CONTRACT;};
2109 Thread *GetInternal()
2111 LIMITED_METHOD_CONTRACT;
2112 return m_InternalThread;
2115 void SetInternal(Thread *it);
2116 void ClearInternal();
2118 INT32 GetManagedThreadId()
2120 LIMITED_METHOD_CONTRACT;
2121 return m_ManagedThreadId;
2124 void SetManagedThreadId(INT32 id)
2126 LIMITED_METHOD_CONTRACT;
2127 m_ManagedThreadId = id;
2130 OBJECTREF GetThreadStartArg() { LIMITED_METHOD_CONTRACT; return m_ThreadStartArg; }
2131 void SetThreadStartArg(OBJECTREF newThreadStartArg)
2133 WRAPPER_NO_CONTRACT;
2135 _ASSERTE(newThreadStartArg == NULL);
2136 // Note: this is an unchecked assignment. We are cleaning out the ThreadStartArg field when
2137 // a thread starts so that ADU does not cause problems
2138 SetObjectReferenceUnchecked( (OBJECTREF *)&m_ThreadStartArg, newThreadStartArg);
2142 OBJECTREF GetDelegate() { LIMITED_METHOD_CONTRACT; return m_Delegate; }
2143 void SetDelegate(OBJECTREF delegate);
2145 #ifndef FEATURE_LEAK_CULTURE_INFO
2146 CULTUREINFOBASEREF GetCurrentUserCulture();
2147 CULTUREINFOBASEREF GetCurrentUICulture();
2148 OBJECTREF GetManagedThreadCulture(BOOL bUICulture);
2149 void ResetManagedThreadCulture(BOOL bUICulture);
2150 void ResetCurrentUserCulture();
2151 void ResetCurrentUICulture();
2154 #ifdef FEATURE_REMOTING
2155 // These expose the remoting context (System\Remoting\Context)
2156 OBJECTREF GetExposedContext() { LIMITED_METHOD_CONTRACT; return m_ExposedContext; }
2157 OBJECTREF SetExposedContext(OBJECTREF newContext)
2159 WRAPPER_NO_CONTRACT;
2161 OBJECTREF oldContext = m_ExposedContext;
2163 // Note: this is a very dangerous unchecked assignment. We are taking
2164 // responsibilty here for cleaning out the ExposedContext field when
2165 // an app domain is unloaded.
2166 SetObjectReferenceUnchecked( (OBJECTREF *)&m_ExposedContext, newContext );
2172 #ifdef FEATURE_LEAK_CULTURE_INFO
2173 CULTUREINFOBASEREF GetCurrentUserCulture()
2175 LIMITED_METHOD_CONTRACT;
2176 return m_CurrentUserCulture;
2179 void ResetCurrentUserCulture()
2181 WRAPPER_NO_CONTRACT;
2182 ClearObjectReference((OBJECTREF *)&m_CurrentUserCulture);
2185 CULTUREINFOBASEREF GetCurrentUICulture()
2187 LIMITED_METHOD_CONTRACT;
2188 return m_CurrentUICulture;
2191 void ResetCurrentUICulture()
2193 WRAPPER_NO_CONTRACT;
2194 ClearObjectReference((OBJECTREF *)&m_CurrentUICulture);
2196 #endif // FEATURE_LEAK_CULTURE_INFO
2198 #ifndef FEATURE_CORECLR
2199 OBJECTREF GetSynchronizationContext()
2201 LIMITED_METHOD_CONTRACT;
2202 if (m_ExecutionContext != NULL)
2203 return m_ExecutionContext->GetSynchronizationContext();
2206 OBJECTREF GetExecutionContext()
2208 LIMITED_METHOD_CONTRACT;
2209 return (OBJECTREF)m_ExecutionContext;
2211 void SetExecutionContext(OBJECTREF ref)
2213 LIMITED_METHOD_CONTRACT;
2214 SetObjectReferenceUnchecked((OBJECTREF*)&m_ExecutionContext, ref);
2216 #endif //!FEATURE_CORECLR
2217 #ifdef FEATURE_COMPRESSEDSTACK
2218 COMPRESSEDSTACKREF GetCompressedStack()
2220 WRAPPER_NO_CONTRACT;
2221 if (m_ExecutionContext != NULL)
2222 return m_ExecutionContext->GetCompressedStack();
2225 #endif // #ifdef FEATURE_COMPRESSEDSTACK
2226 // SetDelegate is our "constructor" for the pathway where the exposed object is
2227 // created first. InitExisting is our "constructor" for the pathway where an
2228 // existing physical thread is later exposed.
2229 void InitExisting();
2233 LIMITED_METHOD_CONTRACT;
2234 ResetCurrentUserCulture();
2235 ResetCurrentUICulture();
2240 LIMITED_METHOD_CONTRACT;
2244 void SetPriority(INT32 priority)
2246 LIMITED_METHOD_CONTRACT;
2247 m_Priority = priority;
2250 INT32 GetPriority() const
2252 LIMITED_METHOD_CONTRACT;
2257 // MarshalByRefObjectBaseObject
2258 // This class is the base class for MarshalByRefObject
2260 class MarshalByRefObjectBaseObject : public Object
2262 #ifdef FEATURE_REMOTING
2263 friend class MscorlibBinder;
2266 static int GetOffsetOfServerIdentity() { LIMITED_METHOD_CONTRACT; return offsetof(MarshalByRefObjectBaseObject, m_ServerIdentity); }
2270 // Modifying the order or fields of this object may require other changes to the
2271 // classlib class definition of this object.
2272 OBJECTREF m_ServerIdentity;
2275 MarshalByRefObjectBaseObject() {LIMITED_METHOD_CONTRACT;}
2276 ~MarshalByRefObjectBaseObject() {LIMITED_METHOD_CONTRACT;}
2281 // ContextBaseObject
2282 // This class is the base class for Contexts
2284 class ContextBaseObject : public Object
2286 friend class Context;
2287 friend class MscorlibBinder;
2291 // Modifying the order or fields of this object may require other changes to the
2292 // classlib class definition of this object.
2294 OBJECTREF m_ctxProps; // array of name-value pairs of properties
2295 OBJECTREF m_dphCtx; // dynamic property holder
2296 OBJECTREF m_localDataStore; // context local store
2297 OBJECTREF m_serverContextChain; // server context sink chain
2298 OBJECTREF m_clientContextChain; // client context sink chain
2299 OBJECTREF m_exposedAppDomain; //appDomain ??
2300 PTRARRAYREF m_ctxStatics; // holder for context relative statics
2302 Context* m_internalContext; // Pointer to the VM context
2306 INT32 _numCtxProps; // current count of properties
2308 INT32 _ctxStaticsCurrentBucket;
2309 INT32 _ctxStaticsFreeIndex;
2312 ContextBaseObject() { LIMITED_METHOD_CONTRACT; }
2313 ~ContextBaseObject() { LIMITED_METHOD_CONTRACT; }
2317 void SetInternalContext(Context* pCtx)
2319 LIMITED_METHOD_CONTRACT;
2320 // either transitioning from NULL to non-NULL or vice versa.
2321 // But not setting NULL to NULL or non-NULL to non-NULL.
2322 _ASSERTE((m_internalContext == NULL) != (pCtx == NULL));
2323 m_internalContext = pCtx;
2326 Context* GetInternalContext()
2328 LIMITED_METHOD_CONTRACT;
2329 return m_internalContext;
2332 OBJECTREF GetExposedDomain() { return m_exposedAppDomain; }
2333 OBJECTREF SetExposedDomain(OBJECTREF newDomain)
2335 LIMITED_METHOD_CONTRACT;
2336 OBJECTREF oldDomain = m_exposedAppDomain;
2337 SetObjectReference( (OBJECTREF *)&m_exposedAppDomain, newDomain, GetAppDomain() );
2341 PTRARRAYREF GetContextStaticsHolder()
2343 LIMITED_METHOD_CONTRACT;
2345 // The code that needs this should have faulted it in by now!
2346 _ASSERTE(m_ctxStatics != NULL);
2348 return m_ctxStatics;
2352 typedef DPTR(ContextBaseObject) PTR_ContextBaseObject;
2354 // AppDomainBaseObject
2355 // This class is the base class for application domains
2357 class AppDomainBaseObject : public MarshalByRefObjectBaseObject
2359 friend class AppDomain;
2360 friend class MscorlibBinder;
2364 // Modifying the order or fields of this object may require other changes to the
2365 // classlib class definition of this object.
2366 OBJECTREF m_pDomainManager; // AppDomainManager for host settings.
2367 OBJECTREF m_LocalStore;
2368 OBJECTREF m_FusionTable;
2369 OBJECTREF m_pSecurityIdentity; // Evidence associated with this domain
2370 OBJECTREF m_pPolicies; // Array of context policies associated with this domain
2371 OBJECTREF m_pAssemblyEventHandler; // Delegate for 'loading assembly' event
2372 OBJECTREF m_pTypeEventHandler; // Delegate for 'resolve type' event
2373 OBJECTREF m_pResourceEventHandler; // Delegate for 'resolve resource' event
2374 OBJECTREF m_pAsmResolveEventHandler; // Delegate for 'resolve assembly' event
2375 #ifdef FEATURE_REFLECTION_ONLY_LOAD
2376 OBJECTREF m_pReflectionAsmResolveEventHandler; //Delegate for 'reflection resolve assembly' event
2378 #ifdef FEATURE_REMOTING
2379 OBJECTREF m_pDefaultContext; // Default managed context for this AD.
2381 #ifdef FEATURE_CLICKONCE
2382 OBJECTREF m_pActivationContext; // ClickOnce ActivationContext.
2383 OBJECTREF m_pApplicationIdentity; // App ApplicationIdentity.
2385 OBJECTREF m_pApplicationTrust; // App ApplicationTrust.
2386 #ifdef FEATURE_IMPERSONATION
2387 OBJECTREF m_pDefaultPrincipal; // Lazily computed default principle object used by threads
2388 #endif // FEATURE_IMPERSONATION
2389 #ifdef FEATURE_REMOTING
2390 OBJECTREF m_pURITable; // Identity table for remoting
2392 OBJECTREF m_pProcessExitEventHandler; // Delegate for 'process exit' event. Only used in Default appdomain.
2393 OBJECTREF m_pDomainUnloadEventHandler; // Delegate for 'about to unload domain' event
2394 OBJECTREF m_pUnhandledExceptionEventHandler; // Delegate for 'unhandled exception' event
2395 #ifdef FEATURE_APTCA
2396 OBJECTREF m_aptcaVisibleAssemblies; // array of conditional APTCA assembly names that should be APTCA visible
2399 OBJECTREF m_compatFlags;
2401 #ifdef FEATURE_EXCEPTION_NOTIFICATIONS
2402 OBJECTREF m_pFirstChanceExceptionHandler; // Delegate for 'FirstChance Exception' event
2403 #endif // FEATURE_EXCEPTION_NOTIFICATIONS
2405 AppDomain* m_pDomain; // Pointer to the BaseDomain Structure
2406 #ifdef FEATURE_CAS_POLICY
2407 INT32 m_iPrincipalPolicy; // Type of principal to create by default
2409 CLR_BOOL m_bHasSetPolicy; // SetDomainPolicy has been called for this domain
2410 CLR_BOOL m_bIsFastFullTrustDomain; // We know for sure that this is a homogeneous full trust domain.
2411 CLR_BOOL m_compatFlagsInitialized;
2414 AppDomainBaseObject() { LIMITED_METHOD_CONTRACT; }
2415 ~AppDomainBaseObject() { LIMITED_METHOD_CONTRACT; }
2419 void SetDomain(AppDomain* p)
2421 LIMITED_METHOD_CONTRACT;
2424 AppDomain* GetDomain()
2426 LIMITED_METHOD_CONTRACT;
2430 OBJECTREF GetSecurityIdentity()
2432 LIMITED_METHOD_CONTRACT;
2433 return m_pSecurityIdentity;
2436 OBJECTREF GetAppDomainManager()
2438 LIMITED_METHOD_CONTRACT;
2439 return m_pDomainManager;
2442 OBJECTREF GetApplicationTrust()
2444 LIMITED_METHOD_CONTRACT;
2445 return m_pApplicationTrust;
2448 BOOL GetIsFastFullTrustDomain()
2450 LIMITED_METHOD_CONTRACT;
2451 return !!m_bIsFastFullTrustDomain;
2454 #ifdef FEATURE_APTCA
2455 OBJECTREF GetPartialTrustVisibleAssemblies()
2457 LIMITED_METHOD_CONTRACT
2458 return m_aptcaVisibleAssemblies;
2460 #endif // FEATURE_APTCA
2462 // Ref needs to be a PTRARRAYREF
2463 void SetPolicies(OBJECTREF ref)
2465 WRAPPER_NO_CONTRACT;
2466 SetObjectReference(&m_pPolicies, ref, m_pDomain );
2468 #ifdef FEATURE_REMOTING
2469 void SetDefaultContext(OBJECTREF ref)
2471 WRAPPER_NO_CONTRACT;
2472 SetObjectReference(&m_pDefaultContext,ref,m_pDomain);
2477 LIMITED_METHOD_CONTRACT;
2478 return m_bHasSetPolicy;
2481 #ifdef FEATURE_CLICKONCE
2482 BOOL HasActivationContext()
2484 LIMITED_METHOD_CONTRACT;
2485 return m_pActivationContext != NULL;
2487 #endif // FEATURE_CLICKONCE
2489 #ifdef FEATURE_EXCEPTION_NOTIFICATIONS
2490 // Returns the reference to the delegate of the first chance exception notification handler
2491 OBJECTREF GetFirstChanceExceptionNotificationHandler()
2493 LIMITED_METHOD_CONTRACT;
2495 return m_pFirstChanceExceptionHandler;
2497 #endif // FEATURE_EXCEPTION_NOTIFICATIONS
2500 #ifndef FEATURE_CORECLR
2501 // The managed definition of AppDomainSortingSetupInfo is in BCL\System\Globalization\AppDomainSortingSetupInfo.cs
2502 class AppDomainSortingSetupInfoObject : public Object
2504 friend class MscorlibBinder;
2507 INT_PTR m_pfnIsNLSDefinedString;
2508 INT_PTR m_pfnCompareStringEx;
2509 INT_PTR m_pfnLCMapStringEx;
2510 INT_PTR m_pfnFindNLSStringEx;
2511 INT_PTR m_pfnCompareStringOrdinal;
2512 INT_PTR m_pfnGetNLSVersionEx;
2513 INT_PTR m_pfnFindStringOrdinal;
2514 CLR_BOOL m_useV2LegacySorting;
2515 CLR_BOOL m_useV4LegacySorting;
2518 AppDomainSortingSetupInfoObject() { LIMITED_METHOD_CONTRACT; }
2519 ~AppDomainSortingSetupInfoObject() { LIMITED_METHOD_CONTRACT; }
2522 CLR_BOOL UseV2LegacySorting() { LIMITED_METHOD_CONTRACT; return m_useV2LegacySorting; }
2523 CLR_BOOL UseV4LegacySorting() { LIMITED_METHOD_CONTRACT; return m_useV4LegacySorting; }
2525 INT_PTR GetPFNIsNLSDefinedString() { LIMITED_METHOD_CONTRACT; return m_pfnIsNLSDefinedString; }
2526 INT_PTR GetPFNCompareStringEx() { LIMITED_METHOD_CONTRACT; return m_pfnCompareStringEx; }
2527 INT_PTR GetPFNLCMapStringEx() { LIMITED_METHOD_CONTRACT; return m_pfnLCMapStringEx; }
2528 INT_PTR GetPFNFindNLSStringEx() { LIMITED_METHOD_CONTRACT; return m_pfnFindNLSStringEx; }
2529 INT_PTR GetPFNCompareStringOrdinal() { LIMITED_METHOD_CONTRACT; return m_pfnCompareStringOrdinal; }
2530 INT_PTR GetPFNGetNLSVersionEx() { LIMITED_METHOD_CONTRACT; return m_pfnGetNLSVersionEx; }
2531 INT_PTR GetPFNFindStringOrdinal() { LIMITED_METHOD_CONTRACT; return m_pfnFindStringOrdinal; }
2533 typedef DPTR(AppDomainSortingSetupInfoObject) PTR_AppDomainSortingSetupInfoObject;
2534 #ifdef USE_CHECKED_OBJECTREFS
2535 typedef REF<AppDomainSortingSetupInfoObject> APPDOMAINSORTINGSETUPINFOREF;
2537 typedef AppDomainSortingSetupInfoObject* APPDOMAINSORTINGSETUPINFOREF;
2538 #endif // USE_CHECKED_OBJECTREFS
2539 #endif // FEATURE_CORECLR
2541 // The managed definition of AppDomainSetup is in BCL\System\AppDomainSetup.cs
2542 class AppDomainSetupObject : public Object
2544 friend class MscorlibBinder;
2547 PTRARRAYREF m_Entries;
2548 STRINGREF m_AppBase;
2549 OBJECTREF m_AppDomainInitializer;
2550 PTRARRAYREF m_AppDomainInitializerArguments;
2551 #ifdef FEATURE_CLICKONCE
2552 OBJECTREF m_ActivationArguments;
2553 #endif // FEATURE_CLICKONCE
2554 STRINGREF m_ApplicationTrust;
2555 I1ARRAYREF m_ConfigurationBytes;
2556 STRINGREF m_AppDomainManagerAssembly;
2557 STRINGREF m_AppDomainManagerType;
2559 PTRARRAYREF m_AptcaVisibleAssemblies;
2561 OBJECTREF m_CompatFlags;
2562 STRINGREF m_TargetFrameworkName;
2563 #ifndef FEATURE_CORECLR
2564 APPDOMAINSORTINGSETUPINFOREF m_AppDomainSortingSetupInfo;
2565 #endif // FEATURE_CORECLR
2566 INT32 m_LoaderOptimization;
2567 #ifdef FEATURE_COMINTEROP
2568 CLR_BOOL m_DisableInterfaceCache;
2569 #endif // FEATURE_COMINTEROP
2570 CLR_BOOL m_CheckedForTargetFrameworkName;
2571 #ifdef FEATURE_RANDOMIZED_STRING_HASHING
2572 CLR_BOOL m_UseRandomizedStringHashing;
2577 AppDomainSetupObject() { LIMITED_METHOD_CONTRACT; }
2578 ~AppDomainSetupObject() { LIMITED_METHOD_CONTRACT; }
2581 #ifndef FEATURE_CORECLR
2582 APPDOMAINSORTINGSETUPINFOREF GetAppDomainSortingSetupInfo() { LIMITED_METHOD_CONTRACT; return m_AppDomainSortingSetupInfo; }
2583 #endif // FEATURE_CORECLR
2584 #ifdef FEATURE_RANDOMIZED_STRING_HASHING
2585 BOOL UseRandomizedStringHashing() { LIMITED_METHOD_CONTRACT; return (BOOL) m_UseRandomizedStringHashing; }
2586 #endif // FEATURE_RANDOMIZED_STRING_HASHING
2588 typedef DPTR(AppDomainSetupObject) PTR_AppDomainSetupObject;
2589 #ifdef USE_CHECKED_OBJECTREFS
2590 typedef REF<AppDomainSetupObject> APPDOMAINSETUPREF;
2592 typedef AppDomainSetupObject* APPDOMAINSETUPREF;
2595 // AssemblyBaseObject
2596 // This class is the base class for assemblies
2598 class AssemblyBaseObject : public Object
2600 friend class Assembly;
2601 friend class MscorlibBinder;
2605 // Modifying the order or fields of this object may require other changes to the
2606 // classlib class definition of this object.
2607 OBJECTREF m_pModuleEventHandler; // Delegate for 'resolve module' event
2608 STRINGREF m_fullname; // Slot for storing assemblies fullname
2609 OBJECTREF m_pSyncRoot; // Pointer to loader allocator to keep collectible types alive, and to serve as the syncroot for assembly building in ref.emit
2610 DomainAssembly* m_pAssembly; // Pointer to the Assembly Structure
2616 AssemblyBaseObject() { LIMITED_METHOD_CONTRACT; }
2617 ~AssemblyBaseObject() { LIMITED_METHOD_CONTRACT; }
2621 void SetAssembly(DomainAssembly* p)
2623 LIMITED_METHOD_CONTRACT;
2627 DomainAssembly* GetDomainAssembly()
2629 LIMITED_METHOD_CONTRACT;
2633 Assembly* GetAssembly();
2635 void SetSyncRoot(OBJECTREF pSyncRoot)
2637 WRAPPER_NO_CONTRACT;
2638 SetObjectReferenceUnchecked(&m_pSyncRoot, pSyncRoot);
2641 NOINLINE AssemblyBaseObject* GetRuntimeAssemblyHelper(LPVOID __me, DomainAssembly *pAssembly, OBJECTREF keepAlive);
2642 #define FC_RETURN_ASSEMBLY_OBJECT(pAssembly, refKeepAlive) FC_INNER_RETURN(AssemblyBaseObject*, GetRuntimeAssemblyHelper(__me, pAssembly, refKeepAlive))
2644 // AssemblyNameBaseObject
2645 // This class is the base class for assembly names
2647 class AssemblyNameBaseObject : public Object
2649 friend class AssemblyNative;
2650 friend class AppDomainNative;
2651 friend class MscorlibBinder;
2655 // Modifying the order or fields of this object may require other changes to the
2656 // classlib class definition of this object.
2658 OBJECTREF m_pSimpleName;
2659 U1ARRAYREF m_pPublicKey;
2660 U1ARRAYREF m_pPublicKeyToken;
2661 OBJECTREF m_pCultureInfo;
2662 OBJECTREF m_pCodeBase;
2663 OBJECTREF m_pVersion;
2664 OBJECTREF m_StrongNameKeyPair;
2665 #ifdef FEATURE_SERIALIZATION
2668 U1ARRAYREF m_HashForControl;
2669 DWORD m_HashAlgorithm;
2670 DWORD m_HashAlgorithmForControl;
2671 DWORD m_VersionCompatibility;
2675 AssemblyNameBaseObject() { LIMITED_METHOD_CONTRACT; }
2676 ~AssemblyNameBaseObject() { LIMITED_METHOD_CONTRACT; }
2679 OBJECTREF GetSimpleName() { LIMITED_METHOD_CONTRACT; return m_pSimpleName; }
2680 U1ARRAYREF GetPublicKey() { LIMITED_METHOD_CONTRACT; return m_pPublicKey; }
2681 U1ARRAYREF GetPublicKeyToken() { LIMITED_METHOD_CONTRACT; return m_pPublicKeyToken; }
2682 OBJECTREF GetStrongNameKeyPair() { LIMITED_METHOD_CONTRACT; return m_StrongNameKeyPair; }
2683 OBJECTREF GetCultureInfo() { LIMITED_METHOD_CONTRACT; return m_pCultureInfo; }
2684 OBJECTREF GetAssemblyCodeBase() { LIMITED_METHOD_CONTRACT; return m_pCodeBase; }
2685 OBJECTREF GetVersion() { LIMITED_METHOD_CONTRACT; return m_pVersion; }
2686 DWORD GetAssemblyHashAlgorithm() { LIMITED_METHOD_CONTRACT; return m_HashAlgorithm; }
2687 DWORD GetFlags() { LIMITED_METHOD_CONTRACT; return m_Flags; }
2688 U1ARRAYREF GetHashForControl() { LIMITED_METHOD_CONTRACT; return m_HashForControl;}
2689 DWORD GetHashAlgorithmForControl() { LIMITED_METHOD_CONTRACT; return m_HashAlgorithmForControl; }
2692 // VersionBaseObject
2693 // This class is the base class for versions
2695 class VersionBaseObject : public Object
2697 friend class MscorlibBinder;
2701 // Modifying the order or fields of this object may require other changes to the
2702 // classlib class definition of this object.
2709 VersionBaseObject() {LIMITED_METHOD_CONTRACT;}
2710 ~VersionBaseObject() {LIMITED_METHOD_CONTRACT;}
2713 int GetMajor() { LIMITED_METHOD_CONTRACT; return m_Major; }
2714 int GetMinor() { LIMITED_METHOD_CONTRACT; return m_Minor; }
2715 int GetBuild() { LIMITED_METHOD_CONTRACT; return m_Build; }
2716 int GetRevision() { LIMITED_METHOD_CONTRACT; return m_Revision; }
2719 // FrameSecurityDescriptorBaseObject
2720 // This class is the base class for the frame security descriptor
2723 class FrameSecurityDescriptorBaseObject : public Object
2725 friend class MscorlibBinder;
2729 // Modifying the order or fields of this object may require other changes to the
2730 // classlib class definition of this object.
2732 OBJECTREF m_assertions; // imperative
2733 OBJECTREF m_denials; // imperative
2734 OBJECTREF m_restriction; // imperative
2735 OBJECTREF m_DeclarativeAssertions;
2736 OBJECTREF m_DeclarativeDenials;
2737 OBJECTREF m_DeclarativeRestrictions;
2739 SAFEHANDLEREF m_callerToken; // the thread token (or process token if there was no thread token) when a call to Impersonate was made ("previous" token)
2740 SAFEHANDLEREF m_impToken; // the thread token after a call to Impersonate is made (the "current" impersonation)
2741 #endif // !FEATURE_PAL
2742 CLR_BOOL m_assertFT;
2743 CLR_BOOL m_assertAllPossible;
2744 CLR_BOOL m_declSecComputed;
2749 FrameSecurityDescriptorBaseObject() {LIMITED_METHOD_CONTRACT;}
2750 ~FrameSecurityDescriptorBaseObject() {LIMITED_METHOD_CONTRACT;}
2754 INT32 GetOverridesCount()
2756 LIMITED_METHOD_CONTRACT;
2758 if (m_restriction != NULL)
2760 if (m_denials != NULL)
2762 if (m_DeclarativeDenials != NULL)
2764 if (m_DeclarativeRestrictions != NULL)
2769 INT32 GetAssertCount()
2771 LIMITED_METHOD_CONTRACT;
2773 if (m_assertions != NULL || m_DeclarativeAssertions != NULL || HasAssertAllPossible())
2780 LIMITED_METHOD_CONTRACT;
2784 BOOL IsDeclSecComputed()
2786 LIMITED_METHOD_CONTRACT;
2787 return m_declSecComputed;
2790 BOOL HasAssertAllPossible()
2792 LIMITED_METHOD_CONTRACT;
2793 return m_assertAllPossible;
2796 OBJECTREF GetImperativeAssertions()
2798 LIMITED_METHOD_CONTRACT;
2799 return m_assertions;
2801 OBJECTREF GetDeclarativeAssertions()
2803 LIMITED_METHOD_CONTRACT;
2804 return m_DeclarativeAssertions;
2806 OBJECTREF GetImperativeDenials()
2808 LIMITED_METHOD_CONTRACT;
2811 OBJECTREF GetDeclarativeDenials()
2813 LIMITED_METHOD_CONTRACT;
2814 return m_DeclarativeDenials;
2816 OBJECTREF GetImperativeRestrictions()
2818 LIMITED_METHOD_CONTRACT;
2819 return m_restriction;
2821 OBJECTREF GetDeclarativeRestrictions()
2823 LIMITED_METHOD_CONTRACT;
2824 return m_DeclarativeRestrictions;
2826 void SetImperativeAssertions(OBJECTREF assertRef)
2828 LIMITED_METHOD_CONTRACT;
2829 SetObjectReference(&m_assertions, assertRef, this->GetAppDomain());
2831 void SetDeclarativeAssertions(OBJECTREF assertRef)
2833 LIMITED_METHOD_CONTRACT;
2834 SetObjectReference(&m_DeclarativeAssertions, assertRef, this->GetAppDomain());
2836 void SetImperativeDenials(OBJECTREF denialRef)
2838 LIMITED_METHOD_CONTRACT;
2839 SetObjectReference(&m_denials, denialRef, this->GetAppDomain());
2842 void SetDeclarativeDenials(OBJECTREF denialRef)
2844 LIMITED_METHOD_CONTRACT;
2845 SetObjectReference(&m_DeclarativeDenials, denialRef, this->GetAppDomain());
2848 void SetImperativeRestrictions(OBJECTREF restrictRef)
2850 LIMITED_METHOD_CONTRACT;
2851 SetObjectReference(&m_restriction, restrictRef, this->GetAppDomain());
2854 void SetDeclarativeRestrictions(OBJECTREF restrictRef)
2856 LIMITED_METHOD_CONTRACT;
2857 SetObjectReference(&m_DeclarativeRestrictions, restrictRef, this->GetAppDomain());
2859 void SetAssertAllPossible(BOOL assertAllPossible)
2861 LIMITED_METHOD_CONTRACT;
2862 m_assertAllPossible = !!assertAllPossible;
2865 void SetAssertFT(BOOL assertFT)
2867 LIMITED_METHOD_CONTRACT;
2868 m_assertFT = !!assertFT;
2870 void SetDeclSecComputed(BOOL declSec)
2872 LIMITED_METHOD_CONTRACT;
2873 m_declSecComputed = !!declSec;
2875 LPVOID GetCallerToken();
2876 LPVOID GetImpersonationToken();
2879 #ifdef FEATURE_COMPRESSEDSTACK
2880 class FrameSecurityDescriptorWithResolverBaseObject : public FrameSecurityDescriptorBaseObject
2883 OBJECTREF m_resolver;
2886 void SetDynamicMethodResolver(OBJECTREF resolver)
2888 LIMITED_METHOD_CONTRACT;
2889 SetObjectReference(&m_resolver, resolver, this->GetAppDomain());
2892 #endif // FEATURE_COMPRESSEDSTACK
2894 class WeakReferenceObject : public Object
2897 Volatile<OBJECTHANDLE> m_Handle;
2900 #ifdef USE_CHECKED_OBJECTREFS
2902 typedef REF<ReflectModuleBaseObject> REFLECTMODULEBASEREF;
2904 typedef REF<ReflectClassBaseObject> REFLECTCLASSBASEREF;
2906 typedef REF<ReflectMethodObject> REFLECTMETHODREF;
2908 typedef REF<ReflectFieldObject> REFLECTFIELDREF;
2910 typedef REF<ThreadBaseObject> THREADBASEREF;
2912 typedef REF<AppDomainBaseObject> APPDOMAINREF;
2914 typedef REF<MarshalByRefObjectBaseObject> MARSHALBYREFOBJECTBASEREF;
2916 typedef REF<ContextBaseObject> CONTEXTBASEREF;
2918 typedef REF<AssemblyBaseObject> ASSEMBLYREF;
2920 typedef REF<AssemblyNameBaseObject> ASSEMBLYNAMEREF;
2922 typedef REF<VersionBaseObject> VERSIONREF;
2924 typedef REF<FrameSecurityDescriptorBaseObject> FRAMESECDESCREF;
2926 #ifdef FEATURE_COMPRESSEDSTACK
2927 typedef REF<FrameSecurityDescriptorWithResolverBaseObject> FRAMESECDESWITHRESOLVERCREF;
2928 #endif // FEATURE_COMPRESSEDSTACK
2930 typedef REF<WeakReferenceObject> WEAKREFERENCEREF;
2932 inline ARG_SLOT ObjToArgSlot(OBJECTREF objRef)
2934 LIMITED_METHOD_CONTRACT;
2936 v = OBJECTREFToObject(objRef);
2937 return (ARG_SLOT)(SIZE_T)v;
2940 inline OBJECTREF ArgSlotToObj(ARG_SLOT i)
2942 LIMITED_METHOD_CONTRACT;
2944 v = (LPVOID)(SIZE_T)i;
2945 return ObjectToOBJECTREF ((Object*)v);
2948 inline ARG_SLOT StringToArgSlot(STRINGREF sr)
2950 LIMITED_METHOD_CONTRACT;
2952 v = OBJECTREFToObject(sr);
2953 return (ARG_SLOT)(SIZE_T)v;
2956 inline STRINGREF ArgSlotToString(ARG_SLOT s)
2958 LIMITED_METHOD_CONTRACT;
2960 v = (LPVOID)(SIZE_T)s;
2961 return ObjectToSTRINGREF ((StringObject*)v);
2964 #else // USE_CHECKED_OBJECTREFS
2966 typedef PTR_ReflectModuleBaseObject REFLECTMODULEBASEREF;
2967 typedef PTR_ReflectClassBaseObject REFLECTCLASSBASEREF;
2968 typedef PTR_ReflectMethodObject REFLECTMETHODREF;
2969 typedef PTR_ReflectFieldObject REFLECTFIELDREF;
2970 typedef PTR_ThreadBaseObject THREADBASEREF;
2971 typedef PTR_AppDomainBaseObject APPDOMAINREF;
2972 typedef PTR_AssemblyBaseObject ASSEMBLYREF;
2973 typedef PTR_AssemblyNameBaseObject ASSEMBLYNAMEREF;
2974 typedef PTR_ContextBaseObject CONTEXTBASEREF;
2976 #ifndef DACCESS_COMPILE
2977 typedef MarshalByRefObjectBaseObject* MARSHALBYREFOBJECTBASEREF;
2978 typedef VersionBaseObject* VERSIONREF;
2979 typedef FrameSecurityDescriptorBaseObject* FRAMESECDESCREF;
2981 #ifdef FEATURE_COMPRESSEDSTACK
2982 typedef FrameSecurityDescriptorWithResolverBaseObject* FRAMESECDESWITHRESOLVERCREF;
2983 #endif // FEATURE_COMPRESSEDSTACK
2985 typedef WeakReferenceObject* WEAKREFERENCEREF;
2986 #endif // #ifndef DACCESS_COMPILE
2988 #define ObjToArgSlot(objref) ((ARG_SLOT)(SIZE_T)(objref))
2989 #define ArgSlotToObj(s) ((OBJECTREF)(SIZE_T)(s))
2991 #define StringToArgSlot(objref) ((ARG_SLOT)(SIZE_T)(objref))
2992 #define ArgSlotToString(s) ((STRINGREF)(SIZE_T)(s))
2994 #endif //USE_CHECKED_OBJECTREFS
2996 #define PtrToArgSlot(ptr) ((ARG_SLOT)(SIZE_T)(ptr))
2997 #define ArgSlotToPtr(s) ((LPVOID)(SIZE_T)(s))
2999 #define BoolToArgSlot(b) ((ARG_SLOT)(CLR_BOOL)(!!(b)))
3000 #define ArgSlotToBool(s) ((BOOL)(s))
3002 STRINGREF AllocateString(SString sstr);
3003 CHARARRAYREF AllocateCharArray(DWORD dwArrayLength);
3006 class TransparentProxyObject : public Object
3008 friend class MscorlibBinder;
3009 friend class CheckAsmOffsets;
3012 MethodTable * GetMethodTableBeingProxied()
3014 LIMITED_METHOD_CONTRACT;
3017 void SetMethodTableBeingProxied(MethodTable * pMT)
3019 LIMITED_METHOD_CONTRACT;
3023 MethodTable * GetInterfaceMethodTable()
3025 LIMITED_METHOD_CONTRACT;
3026 return _pInterfaceMT;
3028 void SetInterfaceMethodTable(MethodTable * pInterfaceMT)
3030 LIMITED_METHOD_CONTRACT;
3031 _pInterfaceMT = pInterfaceMT;
3036 LIMITED_METHOD_CONTRACT;
3039 void SetStub(void * pStub)
3041 LIMITED_METHOD_CONTRACT;
3045 OBJECTREF GetStubData()
3047 LIMITED_METHOD_CONTRACT;
3050 void SetStubData(OBJECTREF stubData)
3052 LIMITED_METHOD_CONTRACT;
3053 SetObjectReference(&_stubData, stubData, GetAppDomain());
3056 OBJECTREF GetRealProxy()
3058 LIMITED_METHOD_CONTRACT;
3061 void SetRealProxy(OBJECTREF realProxy)
3063 LIMITED_METHOD_CONTRACT;
3064 SetObjectReference(&_rp, realProxy, GetAppDomain());
3067 static int GetOffsetOfRP() { LIMITED_METHOD_CONTRACT; return offsetof(TransparentProxyObject, _rp); }
3070 TransparentProxyObject()
3071 {LIMITED_METHOD_CONTRACT;}; // don't instantiate this class directly
3072 ~TransparentProxyObject(){LIMITED_METHOD_CONTRACT;};
3076 OBJECTREF _stubData;
3078 MethodTable* _pInterfaceMT;
3082 #ifdef USE_CHECKED_OBJECTREFS
3083 typedef REF<TransparentProxyObject> TRANSPARENTPROXYREF;
3085 typedef TransparentProxyObject* TRANSPARENTPROXYREF;
3089 class RealProxyObject : public Object
3091 friend class MscorlibBinder;
3096 LIMITED_METHOD_CONTRACT;
3099 VOID SetOptFlags(DWORD flags)
3101 LIMITED_METHOD_CONTRACT;
3107 LIMITED_METHOD_CONTRACT;
3111 TRANSPARENTPROXYREF GetTransparentProxy()
3113 LIMITED_METHOD_CONTRACT;
3114 return (TRANSPARENTPROXYREF&)_tp;
3116 void SetTransparentProxy(TRANSPARENTPROXYREF tp)
3118 LIMITED_METHOD_CONTRACT;
3119 SetObjectReference(&_tp, (OBJECTREF)tp, GetAppDomain());
3122 static int GetOffsetOfIdentity() { LIMITED_METHOD_CONTRACT; return offsetof(RealProxyObject, _identity); }
3123 static int GetOffsetOfServerObject() { LIMITED_METHOD_CONTRACT; return offsetof(RealProxyObject, _serverObject); }
3124 static int GetOffsetOfServerIdentity() { LIMITED_METHOD_CONTRACT; return offsetof(RealProxyObject, _srvIdentity); }
3129 LIMITED_METHOD_CONTRACT;
3130 }; // don't instantiate this class directly
3131 ~RealProxyObject(){ LIMITED_METHOD_CONTRACT; };
3135 OBJECTREF _identity;
3136 OBJECTREF _serverObject;
3140 OBJECTHANDLE _srvIdentity;
3143 #ifdef USE_CHECKED_OBJECTREFS
3144 typedef REF<RealProxyObject> REALPROXYREF;
3146 typedef RealProxyObject* REALPROXYREF;
3150 #ifndef CLR_STANDALONE_BINDER
3151 #ifdef FEATURE_COMINTEROP
3153 //-------------------------------------------------------------
3154 // class ComObject, Exposed class __ComObject
3157 //-------------------------------------------------------------
3158 class ComObject : public MarshalByRefObjectBaseObject
3160 friend class MscorlibBinder;
3165 {LIMITED_METHOD_CONTRACT;}; // don't instantiate this class directly
3166 ~ComObject(){LIMITED_METHOD_CONTRACT;};
3169 OBJECTREF m_ObjectToDataMap;
3171 //--------------------------------------------------------------------
3172 // SupportsInterface
3173 static BOOL SupportsInterface(OBJECTREF oref, MethodTable* pIntfTable);
3175 //--------------------------------------------------------------------
3176 // SupportsInterface
3177 static void ThrowInvalidCastException(OBJECTREF *pObj, MethodTable* pCastToMT);
3179 //-----------------------------------------------------------------
3181 static IUnknown* GetComIPFromRCW(OBJECTREF *pObj, MethodTable* pIntfTable);
3183 //-----------------------------------------------------------------
3184 // GetComIPFromRCWThrowing
3185 static IUnknown* GetComIPFromRCWThrowing(OBJECTREF *pObj, MethodTable* pIntfTable);
3187 //-----------------------------------------------------------
3188 // create an empty ComObjectRef
3189 static OBJECTREF CreateComObjectRef(MethodTable* pMT);
3191 //-----------------------------------------------------------
3192 // Release all the data associated with the __ComObject.
3193 static void ReleaseAllData(OBJECTREF oref);
3195 //-----------------------------------------------------------
3196 // Redirection for ToString
3197 static FCDECL1(MethodDesc *, GetRedirectedToStringMD, Object *pThisUNSAFE);
3198 static FCDECL2(StringObject *, RedirectToString, Object *pThisUNSAFE, MethodDesc *pToStringMD);
3200 //-----------------------------------------------------------
3201 // Redirection for GetHashCode
3202 static FCDECL1(MethodDesc *, GetRedirectedGetHashCodeMD, Object *pThisUNSAFE);
3203 static FCDECL2(int, RedirectGetHashCode, Object *pThisUNSAFE, MethodDesc *pGetHashCodeMD);
3205 //-----------------------------------------------------------
3206 // Redirection for Equals
3207 static FCDECL1(MethodDesc *, GetRedirectedEqualsMD, Object *pThisUNSAFE);
3208 static FCDECL3(FC_BOOL_RET, RedirectEquals, Object *pThisUNSAFE, Object *pOtherUNSAFE, MethodDesc *pEqualsMD);
3211 #ifdef USE_CHECKED_OBJECTREFS
3212 typedef REF<ComObject> COMOBJECTREF;
3214 typedef ComObject* COMOBJECTREF;
3218 //-------------------------------------------------------------
3219 // class UnknownWrapper, Exposed class UnknownWrapper
3222 //-------------------------------------------------------------
3223 class UnknownWrapper : public Object
3227 UnknownWrapper(UnknownWrapper &wrap) {LIMITED_METHOD_CONTRACT}; // dissalow copy construction.
3228 UnknownWrapper() {LIMITED_METHOD_CONTRACT;}; // don't instantiate this class directly
3229 ~UnknownWrapper() {LIMITED_METHOD_CONTRACT;};
3231 OBJECTREF m_WrappedObject;
3234 OBJECTREF GetWrappedObject()
3236 LIMITED_METHOD_CONTRACT;
3237 return m_WrappedObject;
3240 void SetWrappedObject(OBJECTREF pWrappedObject)
3242 LIMITED_METHOD_CONTRACT;
3243 m_WrappedObject = pWrappedObject;
3247 #ifdef USE_CHECKED_OBJECTREFS
3248 typedef REF<UnknownWrapper> UNKNOWNWRAPPEROBJECTREF;
3250 typedef UnknownWrapper* UNKNOWNWRAPPEROBJECTREF;
3254 //-------------------------------------------------------------
3255 // class DispatchWrapper, Exposed class DispatchWrapper
3258 //-------------------------------------------------------------
3259 class DispatchWrapper : public Object
3263 DispatchWrapper(DispatchWrapper &wrap) {LIMITED_METHOD_CONTRACT}; // dissalow copy construction.
3264 DispatchWrapper() {LIMITED_METHOD_CONTRACT;}; // don't instantiate this class directly
3265 ~DispatchWrapper() {LIMITED_METHOD_CONTRACT;};
3267 OBJECTREF m_WrappedObject;
3270 OBJECTREF GetWrappedObject()
3272 LIMITED_METHOD_CONTRACT;
3273 return m_WrappedObject;
3276 void SetWrappedObject(OBJECTREF pWrappedObject)
3278 LIMITED_METHOD_CONTRACT;
3279 m_WrappedObject = pWrappedObject;
3283 #ifdef USE_CHECKED_OBJECTREFS
3284 typedef REF<DispatchWrapper> DISPATCHWRAPPEROBJECTREF;
3286 typedef DispatchWrapper* DISPATCHWRAPPEROBJECTREF;
3290 //-------------------------------------------------------------
3291 // class VariantWrapper, Exposed class VARIANTWRAPPEROBJECTREF
3294 //-------------------------------------------------------------
3295 class VariantWrapper : public Object
3299 VariantWrapper(VariantWrapper &wrap) {LIMITED_METHOD_CONTRACT}; // dissalow copy construction.
3300 VariantWrapper() {LIMITED_METHOD_CONTRACT}; // don't instantiate this class directly
3301 ~VariantWrapper() {LIMITED_METHOD_CONTRACT};
3303 OBJECTREF m_WrappedObject;
3306 OBJECTREF GetWrappedObject()
3308 LIMITED_METHOD_CONTRACT;
3309 return m_WrappedObject;
3312 void SetWrappedObject(OBJECTREF pWrappedObject)
3314 LIMITED_METHOD_CONTRACT;
3315 m_WrappedObject = pWrappedObject;
3319 #ifdef USE_CHECKED_OBJECTREFS
3320 typedef REF<VariantWrapper> VARIANTWRAPPEROBJECTREF;
3322 typedef VariantWrapper* VARIANTWRAPPEROBJECTREF;
3326 //-------------------------------------------------------------
3327 // class ErrorWrapper, Exposed class ErrorWrapper
3330 //-------------------------------------------------------------
3331 class ErrorWrapper : public Object
3335 ErrorWrapper(ErrorWrapper &wrap) {LIMITED_METHOD_CONTRACT}; // dissalow copy construction.
3336 ErrorWrapper() {LIMITED_METHOD_CONTRACT;}; // don't instantiate this class directly
3337 ~ErrorWrapper() {LIMITED_METHOD_CONTRACT;};
3342 INT32 GetErrorCode()
3344 LIMITED_METHOD_CONTRACT;
3348 void SetErrorCode(int ErrorCode)
3350 LIMITED_METHOD_CONTRACT;
3351 m_ErrorCode = ErrorCode;
3355 #ifdef USE_CHECKED_OBJECTREFS
3356 typedef REF<ErrorWrapper> ERRORWRAPPEROBJECTREF;
3358 typedef ErrorWrapper* ERRORWRAPPEROBJECTREF;
3362 //-------------------------------------------------------------
3363 // class CurrencyWrapper, Exposed class CurrencyWrapper
3366 //-------------------------------------------------------------
3368 // Keep this in sync with code:MethodTableBuilder.CheckForSystemTypes where
3369 // alignment requirement of the managed System.Decimal structure is computed.
3370 #if !defined(ALIGN_ACCESS) && !defined(FEATURE_64BIT_ALIGNMENT)
3371 #include <pshpack4.h>
3372 #endif // !ALIGN_ACCESS && !FEATURE_64BIT_ALIGNMENT
3374 class CurrencyWrapper : public Object
3378 CurrencyWrapper(CurrencyWrapper &wrap) {LIMITED_METHOD_CONTRACT}; // dissalow copy construction.
3379 CurrencyWrapper() {LIMITED_METHOD_CONTRACT;}; // don't instantiate this class directly
3380 ~CurrencyWrapper() {LIMITED_METHOD_CONTRACT;};
3382 DECIMAL m_WrappedObject;
3385 DECIMAL GetWrappedObject()
3387 LIMITED_METHOD_CONTRACT;
3388 return m_WrappedObject;
3391 void SetWrappedObject(DECIMAL WrappedObj)
3393 LIMITED_METHOD_CONTRACT;
3394 m_WrappedObject = WrappedObj;
3398 #if !defined(ALIGN_ACCESS) && !defined(FEATURE_64BIT_ALIGNMENT)
3399 #include <poppack.h>
3400 #endif // !ALIGN_ACCESS && !FEATURE_64BIT_ALIGNMENT
3402 #ifdef USE_CHECKED_OBJECTREFS
3403 typedef REF<CurrencyWrapper> CURRENCYWRAPPEROBJECTREF;
3405 typedef CurrencyWrapper* CURRENCYWRAPPEROBJECTREF;
3408 //-------------------------------------------------------------
3409 // class BStrWrapper, Exposed class BSTRWRAPPEROBJECTREF
3412 //-------------------------------------------------------------
3413 class BStrWrapper : public Object
3417 BStrWrapper(BStrWrapper &wrap) {LIMITED_METHOD_CONTRACT}; // dissalow copy construction.
3418 BStrWrapper() {LIMITED_METHOD_CONTRACT}; // don't instantiate this class directly
3419 ~BStrWrapper() {LIMITED_METHOD_CONTRACT};
3421 STRINGREF m_WrappedObject;
3424 STRINGREF GetWrappedObject()
3426 LIMITED_METHOD_CONTRACT;
3427 return m_WrappedObject;
3430 void SetWrappedObject(STRINGREF pWrappedObject)
3432 LIMITED_METHOD_CONTRACT;
3433 m_WrappedObject = pWrappedObject;
3437 #ifdef USE_CHECKED_OBJECTREFS
3438 typedef REF<BStrWrapper> BSTRWRAPPEROBJECTREF;
3440 typedef BStrWrapper* BSTRWRAPPEROBJECTREF;
3443 #endif // FEATURE_COMINTEROP
3444 #endif // CLR_STANDALONE_BINDER
3446 class StringBufferObject;
3447 #ifdef USE_CHECKED_OBJECTREFS
3448 typedef REF<StringBufferObject> STRINGBUFFERREF;
3449 #else // USE_CHECKED_OBJECTREFS
3450 typedef StringBufferObject * STRINGBUFFERREF;
3451 #endif // USE_CHECKED_OBJECTREFS
3454 // StringBufferObject
3456 // Note that the "copy on write" bit is buried within the implementation
3457 // of the object in order to make the implementation smaller.
3461 class StringBufferObject : public Object
3463 friend class MscorlibBinder;
3466 CHARARRAYREF m_ChunkChars;
3467 StringBufferObject *m_ChunkPrevious;
3468 UINT32 m_ChunkLength;
3469 UINT32 m_ChunkOffset;
3470 INT32 m_MaxCapacity;
3474 LIMITED_METHOD_CONTRACT;
3475 return (WCHAR *)m_ChunkChars->GetDirectPointerToNonObjectElements();
3478 // This function assumes that requiredLength will be less
3479 // than the max capacity of the StringBufferObject
3480 DWORD GetAllocationLength(DWORD dwRequiredLength)
3482 LIMITED_METHOD_CONTRACT;
3483 _ASSERTE((INT32)dwRequiredLength <= m_MaxCapacity);
3484 DWORD dwCurrentLength = GetArrayLength();
3486 // round the current length to the nearest multiple of 2
3487 // that is >= the required length
3488 if(dwCurrentLength < dwRequiredLength)
3490 dwCurrentLength = (dwRequiredLength + 1) & ~1;
3492 return dwCurrentLength;
3496 StringBufferObject() { LIMITED_METHOD_CONTRACT; };
3497 ~StringBufferObject() { LIMITED_METHOD_CONTRACT; };
3500 INT32 GetMaxCapacity()
3502 return m_MaxCapacity;
3505 DWORD GetArrayLength()
3507 LIMITED_METHOD_CONTRACT;
3508 _ASSERTE(m_ChunkChars);
3509 return m_ChunkOffset + m_ChunkChars->GetNumComponents();
3512 // Given an ANSI string, use it to replace the StringBufferObject's internal buffer
3513 VOID ReplaceBufferWithAnsi(CHARARRAYREF *newArrayRef, __in CHAR *newChars, DWORD dwNewCapacity)
3515 #ifndef DACCESS_COMPILE
3516 SetObjectReference((OBJECTREF *)&m_ChunkChars, (OBJECTREF)(*newArrayRef), GetAppDomain());
3517 #endif //!DACCESS_COMPILE
3518 WCHAR *thisChars = GetBuffer();
3519 // NOTE: This call to MultiByte also writes out the null terminator
3520 // which is currently part of the String representation.
3521 INT32 ncWritten = MultiByteToWideChar(CP_ACP,
3530 // Normally, we'd throw an exception if the string couldn't be converted.
3531 // In this particular case, we paper over it instead. The reason is
3532 // that most likely reason a P/Invoke-called api returned a
3533 // poison string is that the api failed for some reason, and hence
3534 // exercised its right to leave the buffer in a poison state.
3535 // Because P/Invoke cannot discover if an api failed, it cannot
3536 // know to ignore the buffer on the out marshaling path.
3537 // Because normal P/Invoke procedure is for the caller to check error
3538 // codes manually, we don't want to throw an exception on him.
3539 // We certainly don't want to randomly throw or not throw based on the
3540 // nondeterministic contents of a buffer passed to a failing api.
3541 *thisChars = W('\0');
3546 m_ChunkLength = ncWritten-1;
3547 m_ChunkPrevious = NULL;
3550 // Given a Unicode string, use it to replace the StringBufferObject's internal buffer
3551 VOID ReplaceBuffer(CHARARRAYREF *newArrayRef, __in_ecount(dwNewCapacity) WCHAR *newChars, DWORD dwNewCapacity)
3561 #ifndef DACCESS_COMPILE
3562 SetObjectReference((OBJECTREF *)&m_ChunkChars, (OBJECTREF)(*newArrayRef), GetAppDomain());
3563 #endif //!DACCESS_COMPILE
3564 WCHAR *thisChars = GetBuffer();
3565 memcpyNoGCRefs(thisChars, newChars, sizeof(WCHAR)*dwNewCapacity);
3566 thisChars[dwNewCapacity] = W('\0');
3567 m_ChunkLength = dwNewCapacity;
3568 m_ChunkPrevious = NULL;
3572 static void ReplaceBuffer(STRINGBUFFERREF *thisRef, __in_ecount(newLength) WCHAR *newBuffer, INT32 newLength);
3573 static void ReplaceBufferAnsi(STRINGBUFFERREF *thisRef, __in_ecount(newCapacity) CHAR *newBuffer, INT32 newCapacity);
3574 static INT32 LocalIndexOfString(__in_ecount(strLength) WCHAR *base, __in_ecount(patternLength) WCHAR *search, int strLength, int patternLength, int startPos);
3577 class SafeHandle : public Object
3579 friend class MscorlibBinder;
3583 // Modifying the order or fields of this object may require
3584 // other changes to the classlib class definition of this
3585 // object or special handling when loading this system class.
3587 STRINGREF m_debugStackTrace; // Where we allocated this SafeHandle
3589 Volatile<LPVOID> m_handle;
3590 Volatile<INT32> m_state; // Combined ref count and closed/disposed state (for atomicity)
3591 Volatile<CLR_BOOL> m_ownsHandle;
3592 Volatile<CLR_BOOL> m_fullyInitialized; // Did constructor finish?
3594 // Describe the bits in the m_state field above.
3597 SH_State_Closed = 0x00000001,
3598 SH_State_Disposed = 0x00000002,
3599 SH_State_RefCount = 0xfffffffc,
3600 SH_RefCountOne = 4, // Amount to increment state field to yield a ref count increment of 1
3603 static WORD s_IsInvalidHandleMethodSlot;
3604 static WORD s_ReleaseHandleMethodSlot;
3606 static void RunReleaseMethod(SafeHandle* psh);
3607 BOOL IsFullyInitialized() const { LIMITED_METHOD_CONTRACT; return m_fullyInitialized; }
3612 // To use the SafeHandle from native, look at the SafeHandleHolder, which
3613 // will do the AddRef & Release for you.
3614 LPVOID GetHandle() const {
3615 LIMITED_METHOD_CONTRACT;
3616 _ASSERTE(((unsigned int) m_state) >= SH_RefCountOne);
3620 BOOL OwnsHandle() const
3622 LIMITED_METHOD_CONTRACT;
3623 return m_ownsHandle;
3626 static size_t GetHandleOffset() { LIMITED_METHOD_CONTRACT; return offsetof(SafeHandle, m_handle); }
3629 void Release(bool fDispose = false);
3631 void SetHandle(LPVOID handle);
3633 static FCDECL1(void, DisposeNative, SafeHandle* refThisUNSAFE);
3634 static FCDECL1(void, Finalize, SafeHandle* refThisUNSAFE);
3635 static FCDECL1(void, SetHandleAsInvalid, SafeHandle* refThisUNSAFE);
3636 static FCDECL2(void, DangerousAddRef, SafeHandle* refThisUNSAFE, CLR_BOOL *pfSuccess);
3637 static FCDECL1(void, DangerousRelease, SafeHandle* refThisUNSAFE);
3640 // SAFEHANDLEREF defined above because CompressedStackObject needs it
3642 void AcquireSafeHandle(SAFEHANDLEREF* s);
3643 void ReleaseSafeHandle(SAFEHANDLEREF* s);
3645 typedef Holder<SAFEHANDLEREF*, AcquireSafeHandle, ReleaseSafeHandle> SafeHandleHolder;
3647 class CriticalHandle : public Object
3649 friend class MscorlibBinder;
3653 // Modifying the order or fields of this object may require
3654 // other changes to the classlib class definition of this
3655 // object or special handling when loading this system class.
3657 STRINGREF m_debugStackTrace; // Where we allocated this CriticalHandle
3659 Volatile<LPVOID> m_handle;
3660 Volatile<CLR_BOOL> m_isClosed;
3663 LPVOID GetHandle() const { LIMITED_METHOD_CONTRACT; return m_handle; }
3664 static size_t GetHandleOffset() { LIMITED_METHOD_CONTRACT; return offsetof(CriticalHandle, m_handle); }
3666 void SetHandle(LPVOID handle) { LIMITED_METHOD_CONTRACT; m_handle = handle; }
3668 static FCDECL1(void, FireCustomerDebugProbe, CriticalHandle* refThisUNSAFE);
3672 class ReflectClassBaseObject;
3674 class SafeBuffer : SafeHandle
3680 static FCDECL1(UINT, SizeOfType, ReflectClassBaseObject* typeUNSAFE);
3681 static FCDECL1(UINT, AlignedSizeOfType, ReflectClassBaseObject* typeUNSAFE);
3682 static FCDECL3(void, PtrToStructure, BYTE* ptr, FC_TypedByRef structure, UINT32 sizeofT);
3683 static FCDECL3(void, StructureToPtr, FC_TypedByRef structure, BYTE* ptr, UINT32 sizeofT);
3686 #ifdef USE_CHECKED_OBJECTREFS
3687 typedef REF<CriticalHandle> CRITICALHANDLE;
3688 typedef REF<CriticalHandle> CRITICALHANDLEREF;
3689 #else // USE_CHECKED_OBJECTREFS
3690 typedef CriticalHandle * CRITICALHANDLE;
3691 typedef CriticalHandle * CRITICALHANDLEREF;
3692 #endif // USE_CHECKED_OBJECTREFS
3695 // Base class for WaitHandle
3696 class WaitHandleBase :public MarshalByRefObjectBaseObject
3698 friend class WaitHandleNative;
3699 friend class MscorlibBinder;
3702 __inline LPVOID GetWaitHandle() {LIMITED_METHOD_CONTRACT; return m_handle;}
3703 __inline SAFEHANDLEREF GetSafeHandle() {LIMITED_METHOD_CONTRACT; return m_safeHandle;}
3706 SAFEHANDLEREF m_safeHandle;
3708 CLR_BOOL m_hasThreadAffinity;
3711 #ifdef USE_CHECKED_OBJECTREFS
3712 typedef REF<WaitHandleBase> WAITHANDLEREF;
3713 #else // USE_CHECKED_OBJECTREFS
3714 typedef WaitHandleBase* WAITHANDLEREF;
3715 #endif // USE_CHECKED_OBJECTREFS
3717 // This class corresponds to FileStreamAsyncResult on the managed side.
3718 class AsyncResultBase :public Object
3720 friend class MscorlibBinder;
3723 WAITHANDLEREF GetWaitHandle() { LIMITED_METHOD_CONTRACT; return _waitHandle;}
3724 void SetErrorCode(int errcode) { LIMITED_METHOD_CONTRACT; _errorCode = errcode;}
3725 void SetNumBytes(int numBytes) { LIMITED_METHOD_CONTRACT; _numBytes = numBytes;}
3726 void SetIsComplete() { LIMITED_METHOD_CONTRACT; _isComplete = TRUE; }
3727 void SetCompletedAsynchronously() { LIMITED_METHOD_CONTRACT; _completedSynchronously = FALSE; }
3730 // If you modify the order of these fields, make sure to update the definition in
3731 // BCL for this object.
3733 OBJECTREF _userCallback;
3734 OBJECTREF _userStateObject;
3736 WAITHANDLEREF _waitHandle;
3737 SAFEHANDLEREF _fileHandle; // For cancellation.
3738 LPOVERLAPPED _overlapped;
3739 int _EndXxxCalled; // Whether we've called EndXxx already.
3740 int _numBytes; // number of bytes read OR written
3742 int _numBufferedBytes;
3744 CLR_BOOL _isWrite; // Whether this is a read or a write
3745 CLR_BOOL _isComplete;
3746 CLR_BOOL _completedSynchronously; // Which thread called callback
3749 #ifdef USE_CHECKED_OBJECTREFS
3750 typedef REF<AsyncResultBase> ASYNCRESULTREF;
3751 #else // USE_CHECKED_OBJECTREFS
3752 typedef AsyncResultBase* ASYNCRESULTREF;
3753 #endif // USE_CHECKED_OBJECTREFS
3755 // This class corresponds to System.MulticastDelegate on the managed side.
3756 class DelegateObject : public Object
3758 friend class CheckAsmOffsets;
3759 friend class MscorlibBinder;
3762 BOOL IsWrapperDelegate() { LIMITED_METHOD_CONTRACT; return _methodPtrAux == NULL; }
3764 OBJECTREF GetTarget() { LIMITED_METHOD_CONTRACT; return _target; }
3765 void SetTarget(OBJECTREF target) { WRAPPER_NO_CONTRACT; SetObjectReference(&_target, target, GetAppDomain()); }
3766 static int GetOffsetOfTarget() { LIMITED_METHOD_CONTRACT; return offsetof(DelegateObject, _target); }
3768 PCODE GetMethodPtr() { LIMITED_METHOD_CONTRACT; return _methodPtr; }
3769 void SetMethodPtr(PCODE methodPtr) { LIMITED_METHOD_CONTRACT; _methodPtr = methodPtr; }
3770 static int GetOffsetOfMethodPtr() { LIMITED_METHOD_CONTRACT; return offsetof(DelegateObject, _methodPtr); }
3772 PCODE GetMethodPtrAux() { LIMITED_METHOD_CONTRACT; return _methodPtrAux; }
3773 void SetMethodPtrAux(PCODE methodPtrAux) { LIMITED_METHOD_CONTRACT; _methodPtrAux = methodPtrAux; }
3774 static int GetOffsetOfMethodPtrAux() { LIMITED_METHOD_CONTRACT; return offsetof(DelegateObject, _methodPtrAux); }
3776 OBJECTREF GetInvocationList() { LIMITED_METHOD_CONTRACT; return _invocationList; }
3777 void SetInvocationList(OBJECTREF invocationList) { WRAPPER_NO_CONTRACT; SetObjectReference(&_invocationList, invocationList, GetAppDomain()); }
3778 static int GetOffsetOfInvocationList() { LIMITED_METHOD_CONTRACT; return offsetof(DelegateObject, _invocationList); }
3780 INT_PTR GetInvocationCount() { LIMITED_METHOD_CONTRACT; return _invocationCount; }
3781 void SetInvocationCount(INT_PTR invocationCount) { LIMITED_METHOD_CONTRACT; _invocationCount = invocationCount; }
3782 static int GetOffsetOfInvocationCount() { LIMITED_METHOD_CONTRACT; return offsetof(DelegateObject, _invocationCount); }
3784 void SetMethodBase(OBJECTREF newMethodBase) { LIMITED_METHOD_CONTRACT; SetObjectReference((OBJECTREF*)&_methodBase, newMethodBase, GetAppDomain()); }
3787 // If you modify the order of these fields, make sure to update the definition in
3788 // BCL for this object.
3792 OBJECTREF _methodBase;
3794 PCODE _methodPtrAux;
3795 // System.MulticastDelegate
3796 OBJECTREF _invocationList;
3797 INT_PTR _invocationCount;
3800 #ifdef USE_CHECKED_OBJECTREFS
3801 typedef REF<DelegateObject> DELEGATEREF;
3802 #else // USE_CHECKED_OBJECTREFS
3803 typedef DelegateObject* DELEGATEREF;
3804 #endif // USE_CHECKED_OBJECTREFS
3806 // This class corresponds to PermissionSet on the managed side.
3807 class PermissionSetObject : public Object
3809 friend class MscorlibBinder;
3812 BOOL AllPermissionsDecoded()
3814 LIMITED_METHOD_CONTRACT;
3815 return _allPermissionsDecoded == TRUE;
3820 LIMITED_METHOD_CONTRACT;
3821 return _ContainsCas == TRUE;
3824 BOOL ContainsNonCas()
3826 LIMITED_METHOD_CONTRACT;
3827 return _ContainsNonCas == TRUE;
3830 BOOL CheckedForNonCas()
3832 LIMITED_METHOD_CONTRACT;
3833 return _CheckedForNonCas == TRUE;
3836 BOOL IsUnrestricted()
3838 LIMITED_METHOD_CONTRACT;
3839 return _Unrestricted == TRUE;
3842 OBJECTREF GetTokenBasedSet()
3844 LIMITED_METHOD_CONTRACT;
3850 // If you modify the order of these fields, make sure to update the definition in
3851 // BCL for this object.
3853 // Order of the fields is important as it mirrors the layout of PermissionSet
3854 // to access the fields directly from unmanaged code given an OBJECTREF.
3855 // Please keep them in sync when you make changes to the fields.
3857 STRINGREF _serializedPermissionSet;
3858 OBJECTREF _permSetSaved;
3859 OBJECTREF _unrestrictedPermSet;
3860 OBJECTREF _normalPermSet;
3861 CLR_BOOL _Unrestricted;
3862 CLR_BOOL _allPermissionsDecoded;
3863 CLR_BOOL _ignoreTypeLoadFailures;
3864 CLR_BOOL _CheckedForNonCas;
3865 CLR_BOOL _ContainsCas;
3866 CLR_BOOL _ContainsNonCas;
3868 #ifdef FEATURE_CAS_POLICY
3869 CLR_BOOL _canUnrestrictedOverride;
3870 #endif // FEATURE_CAS_POLICY
3873 #ifdef USE_CHECKED_OBJECTREFS
3874 typedef REF<PermissionSetObject> PERMISSIONSETREF;
3875 #else // USE_CHECKED_OBJECTREFS
3876 typedef PermissionSetObject* PERMISSIONSETREF;
3877 #endif // USE_CHECKED_OBJECTREFS
3879 // This class corresponds to TokenBasedSet on the managed side.
3880 class TokenBasedSetObject : public Object
3883 INT32 GetNumElements () {
3884 LIMITED_METHOD_CONTRACT;
3888 OBJECTREF GetPermSet () {
3889 LIMITED_METHOD_CONTRACT;
3894 // If you modify the order of these fields, make sure
3895 // to update the definition in BCL for this object.
3905 #ifdef USE_CHECKED_OBJECTREFS
3906 typedef REF<TokenBasedSetObject> TOKENBASEDSETREF;
3907 #else // USE_CHECKED_OBJECTREFS
3908 typedef TokenBasedSetObject* TOKENBASEDSETREF;
3909 #endif // USE_CHECKED_OBJECTREFS
3911 // This class corresponds to PolicyStatement on the managed side.
3912 class PolicyStatementObject : public Object
3914 friend class MscorlibBinder;
3916 PERMISSIONSETREF _permSet;
3917 #ifdef FEATURE_CAS_POLICY
3918 OBJECTREF _dependentEvidence;
3919 #endif // FEATURE_CAS_POLICY
3923 PERMISSIONSETREF GetPermissionSet()
3925 LIMITED_METHOD_CONTRACT;
3929 #ifdef USE_CHECKED_OBJECTREFS
3930 typedef REF<PolicyStatementObject> POLICYSTATEMENTREF;
3931 #else // USE_CHECKED_OBJECTREFS
3932 typedef PolicyStatementObject* POLICYSTATEMENTREF;
3933 #endif // USE_CHECKED_OBJECTREFS
3935 // This class corresponds to ApplicationTrust on the managed side.
3936 class ApplicationTrustObject : public Object
3938 friend class MscorlibBinder;
3940 #ifdef FEATURE_CLICKONCE
3942 OBJECTREF _extraInfo;
3943 OBJECTREF _elExtraInfo;
3944 #endif // FEATURE_CLICKONCE
3945 POLICYSTATEMENTREF _psDefaultGrant;
3946 OBJECTREF _fullTrustAssemblies;
3947 DWORD _grantSetSpecialFlags;
3948 #ifdef FEATURE_CLICKONCE
3949 CLR_BOOL _appTrustedToRun;
3951 #endif // FEATURE_CLICKONCE
3954 POLICYSTATEMENTREF GetPolicyStatement()
3956 LIMITED_METHOD_CONTRACT;
3957 return _psDefaultGrant;
3960 // The grant set special flags are mapped in the BCL for the DefaultGrantSet of the ApplicationTrust.
3961 // Since ApplicationTrust provides a reference to its DefaultGrantSet rather than a copy, the flags may
3962 // not be in sync if user code can ever get a hold of the ApplicationTrust object. Therefore, these
3963 // flags should only be used in code paths where we are sure that only trusted code can ever get a
3964 // reference to the ApplicationTrust (such as the ApplicationTrust created when setting up a homogenous
3966 DWORD GetGrantSetSpecialFlags()
3968 LIMITED_METHOD_CONTRACT;
3969 return _grantSetSpecialFlags;
3972 #ifdef USE_CHECKED_OBJECTREFS
3973 typedef REF<ApplicationTrustObject> APPLICATIONTRUSTREF;
3974 #else // USE_CHECKED_OBJECTREFS
3975 typedef ApplicationTrustObject* APPLICATIONTRUSTREF;
3976 #endif // USE_CHECKED_OBJECTREFS
3978 // This class corresponds to SecurityPermission on the managed side.
3979 class SecurityPermissionObject : public Object
3983 LIMITED_METHOD_CONTRACT;
3988 // If you modify the order of these fields, make sure
3989 // to update the definition in BCL for this object.
3993 #ifdef USE_CHECKED_OBJECTREFS
3994 typedef REF<SecurityPermissionObject> SECURITYPERMISSIONREF;
3995 #else // USE_CHECKED_OBJECTREFS
3996 typedef SecurityPermissionObject* SECURITYPERMISSIONREF;
3997 #endif // USE_CHECKED_OBJECTREFS
3999 // This class corresponds to ReflectionPermission on the managed side.
4000 class ReflectionPermissionObject : public Object
4004 LIMITED_METHOD_CONTRACT;
4012 #ifdef USE_CHECKED_OBJECTREFS
4013 typedef REF<ReflectionPermissionObject> REFLECTIONPERMISSIONREF;
4014 #else // USE_CHECKED_OBJECTREFS
4015 typedef ReflectionPermissionObject* REFLECTIONPERMISSIONREF;
4016 #endif // USE_CHECKED_OBJECTREFS
4018 struct StackTraceElement;
4019 class ClrDataAccess;
4022 typedef DPTR(StackTraceElement) PTR_StackTraceElement;
4024 class StackTraceArray
4032 typedef DPTR(ArrayHeader) PTR_ArrayHeader;
4036 : m_array(static_cast<I1Array *>(NULL))
4038 WRAPPER_NO_CONTRACT;
4041 StackTraceArray(I1ARRAYREF array)
4044 LIMITED_METHOD_CONTRACT;
4047 void Swap(StackTraceArray & rhs)
4058 I1ARRAYREF t = m_array;
4059 m_array = rhs.m_array;
4065 WRAPPER_NO_CONTRACT;
4072 StackTraceElement const & operator[](size_t index) const;
4073 StackTraceElement & operator[](size_t index);
4075 void Append(StackTraceElement const * begin, StackTraceElement const * end);
4076 void AppendSkipLast(StackTraceElement const * begin, StackTraceElement const * end);
4078 I1ARRAYREF Get() const
4080 LIMITED_METHOD_DAC_CONTRACT;
4084 // Deep copies the array
4085 void CopyFrom(StackTraceArray const & src);
4088 StackTraceArray(StackTraceArray const & rhs);
4090 StackTraceArray & operator=(StackTraceArray const & rhs)
4092 WRAPPER_NO_CONTRACT;
4093 StackTraceArray copy(rhs);
4098 void Grow(size_t size);
4099 void EnsureThreadAffinity();
4100 void CheckState() const;
4102 size_t Capacity() const
4104 WRAPPER_NO_CONTRACT;
4107 return m_array->GetNumComponents();
4110 size_t GetSize() const
4112 WRAPPER_NO_CONTRACT;
4113 return GetHeader()->m_size;
4116 void SetSize(size_t size)
4118 WRAPPER_NO_CONTRACT;
4119 GetHeader()->m_size = size;
4122 Thread * GetObjectThread() const
4124 WRAPPER_NO_CONTRACT;
4125 return GetHeader()->m_thread;
4129 void SetObjectThread()
4131 WRAPPER_NO_CONTRACT;
4132 GetHeader()->m_thread = GetThread();
4136 StackTraceElement const * GetData() const
4138 WRAPPER_NO_CONTRACT;
4140 return dac_cast<PTR_StackTraceElement>(GetRaw() + sizeof(ArrayHeader));
4143 PTR_StackTraceElement GetData()
4145 WRAPPER_NO_CONTRACT;
4147 return dac_cast<PTR_StackTraceElement>(GetRaw() + sizeof(ArrayHeader));
4150 I1 const * GetRaw() const
4152 WRAPPER_NO_CONTRACT;
4155 return const_cast<I1ARRAYREF &>(m_array)->GetDirectPointerToNonObjectElements();
4160 WRAPPER_NO_CONTRACT;
4164 return dac_cast<PTR_I1>(m_array->GetDirectPointerToNonObjectElements());
4167 ArrayHeader const * GetHeader() const
4169 WRAPPER_NO_CONTRACT;
4171 return dac_cast<PTR_ArrayHeader>(GetRaw());
4174 PTR_ArrayHeader GetHeader()
4176 WRAPPER_NO_CONTRACT;
4178 return dac_cast<PTR_ArrayHeader>(GetRaw());
4181 void SetArray(I1ARRAYREF const & arr)
4183 LIMITED_METHOD_CONTRACT;
4188 // put only things here that can be protected with GCPROTECT
4192 #ifdef FEATURE_COLLECTIBLE_TYPES
4194 class LoaderAllocatorScoutObject : public Object
4196 friend class MscorlibBinder;
4197 friend class LoaderAllocatorObject;
4200 LoaderAllocator * m_nativeLoaderAllocator;
4203 #ifdef USE_CHECKED_OBJECTREFS
4204 typedef REF<LoaderAllocatorScoutObject> LOADERALLOCATORSCOUTREF;
4205 #else // USE_CHECKED_OBJECTREFS
4206 typedef LoaderAllocatorScoutObject* LOADERALLOCATORSCOUTREF;
4207 #endif // USE_CHECKED_OBJECTREFS
4209 class LoaderAllocatorObject : public Object
4211 friend class MscorlibBinder;
4214 PTRARRAYREF GetHandleTable()
4216 LIMITED_METHOD_DAC_CONTRACT;
4217 return (PTRARRAYREF)m_pSlots;
4220 void SetHandleTable(PTRARRAYREF handleTable)
4222 LIMITED_METHOD_CONTRACT;
4223 SetObjectReferenceUnchecked(&m_pSlots, (OBJECTREF)handleTable);
4226 INT32 GetSlotsUsed()
4228 LIMITED_METHOD_CONTRACT;
4232 void SetSlotsUsed(INT32 newSlotsUsed)
4234 LIMITED_METHOD_CONTRACT;
4235 m_slotsUsed = newSlotsUsed;
4238 void SetNativeLoaderAllocator(LoaderAllocator * pLoaderAllocator)
4240 LIMITED_METHOD_CONTRACT;
4241 m_pLoaderAllocatorScout->m_nativeLoaderAllocator = pLoaderAllocator;
4245 // If you modify the order of these fields, make sure to update the definition in
4246 // BCL for this object.
4248 LOADERALLOCATORSCOUTREF m_pLoaderAllocatorScout;
4251 OBJECTREF m_methodInstantiationsTable;
4254 #ifdef USE_CHECKED_OBJECTREFS
4255 typedef REF<LoaderAllocatorObject> LOADERALLOCATORREF;
4256 #else // USE_CHECKED_OBJECTREFS
4257 typedef DPTR(LoaderAllocatorObject) PTR_LoaderAllocatorObject;
4258 typedef PTR_LoaderAllocatorObject LOADERALLOCATORREF;
4259 #endif // USE_CHECKED_OBJECTREFS
4261 #endif // FEATURE_COLLECTIBLE_TYPES
4263 #if !defined(DACCESS_COMPILE) && !defined(CLR_STANDALONE_BINDER)
4264 // Define the lock used to access stacktrace from an exception object
4265 EXTERN_C SpinLock g_StackTraceArrayLock;
4266 #endif // !defined(DACCESS_COMPILE) && !defined(CLR_STANDALONE_BINDER)
4268 // This class corresponds to Exception on the managed side.
4269 typedef DPTR(class ExceptionObject) PTR_ExceptionObject;
4270 #include "pshpack4.h"
4271 class ExceptionObject : public Object
4273 friend class MscorlibBinder;
4276 void SetHResult(HRESULT hr)
4278 LIMITED_METHOD_CONTRACT;
4282 HRESULT GetHResult()
4284 LIMITED_METHOD_CONTRACT;
4288 void SetXCode(DWORD code)
4290 LIMITED_METHOD_CONTRACT;
4296 LIMITED_METHOD_CONTRACT;
4300 void SetXPtrs(void* xptrs)
4302 LIMITED_METHOD_CONTRACT;
4308 LIMITED_METHOD_CONTRACT;
4312 void SetStackTrace(StackTraceArray const & stackTrace, PTRARRAYREF dynamicMethodArray);
4313 void SetNullStackTrace();
4315 void GetStackTrace(StackTraceArray & stackTrace, PTRARRAYREF * outDynamicMethodArray = NULL) const;
4317 #ifdef DACCESS_COMPILE
4318 I1ARRAYREF GetStackTraceArrayObject() const
4320 LIMITED_METHOD_DAC_CONTRACT;
4323 #endif // DACCESS_COMPILE
4325 void SetInnerException(OBJECTREF innerException)
4327 WRAPPER_NO_CONTRACT;
4328 SetObjectReference((OBJECTREF*)&_innerException, (OBJECTREF)innerException, GetAppDomain());
4331 OBJECTREF GetInnerException()
4333 LIMITED_METHOD_DAC_CONTRACT;
4334 return _innerException;
4337 // Returns the innermost exception object - equivalent of the
4338 // managed System.Exception.GetBaseException method.
4339 OBJECTREF GetBaseException()
4341 LIMITED_METHOD_CONTRACT;
4343 // Loop and get the innermost exception object
4344 OBJECTREF oInnerMostException = NULL;
4345 OBJECTREF oCurrent = NULL;
4347 oCurrent = _innerException;
4348 while(oCurrent != NULL)
4350 oInnerMostException = oCurrent;
4351 oCurrent = ((ExceptionObject*)(Object *)OBJECTREFToObject(oCurrent))->GetInnerException();
4354 // return the innermost exception
4355 return oInnerMostException;
4358 void SetMessage(STRINGREF message)
4360 WRAPPER_NO_CONTRACT;
4361 SetObjectReference((OBJECTREF*)&_message, (OBJECTREF)message, GetAppDomain());
4364 STRINGREF GetMessage()
4366 LIMITED_METHOD_DAC_CONTRACT;
4370 void SetStackTraceString(STRINGREF stackTraceString)
4372 WRAPPER_NO_CONTRACT;
4373 SetObjectReference((OBJECTREF*)&_stackTraceString, (OBJECTREF)stackTraceString, GetAppDomain());
4376 STRINGREF GetStackTraceString()
4378 LIMITED_METHOD_DAC_CONTRACT;
4379 return _stackTraceString;
4382 STRINGREF GetRemoteStackTraceString()
4384 LIMITED_METHOD_DAC_CONTRACT;
4385 return _remoteStackTraceString;
4388 void SetHelpURL(STRINGREF helpURL)
4390 WRAPPER_NO_CONTRACT;
4391 SetObjectReference((OBJECTREF*)&_helpURL, (OBJECTREF)helpURL, GetAppDomain());
4394 void SetSource(STRINGREF source)
4396 WRAPPER_NO_CONTRACT;
4397 SetObjectReference((OBJECTREF*)&_source, (OBJECTREF)source, GetAppDomain());
4400 void ClearStackTraceForThrow()
4402 WRAPPER_NO_CONTRACT;
4403 SetObjectReferenceUnchecked((OBJECTREF*)&_remoteStackTraceString, NULL);
4404 SetObjectReferenceUnchecked((OBJECTREF*)&_stackTrace, NULL);
4405 SetObjectReferenceUnchecked((OBJECTREF*)&_stackTraceString, NULL);
4408 void ClearStackTracePreservingRemoteStackTrace()
4410 WRAPPER_NO_CONTRACT;
4411 SetObjectReferenceUnchecked((OBJECTREF*)&_stackTrace, NULL);
4412 SetObjectReferenceUnchecked((OBJECTREF*)&_stackTraceString, NULL);
4415 // This method will set the reference to the array
4416 // containing the watson bucket information (in byte[] form).
4417 void SetWatsonBucketReference(OBJECTREF oWatsonBucketArray)
4419 WRAPPER_NO_CONTRACT;
4420 SetObjectReference((OBJECTREF*)&_watsonBuckets, (OBJECTREF)oWatsonBucketArray, GetAppDomain());
4423 // This method will return the reference to the array
4424 // containing the watson buckets
4425 U1ARRAYREF GetWatsonBucketReference()
4427 LIMITED_METHOD_CONTRACT;
4428 return _watsonBuckets;
4431 // This method will return a BOOL to indicate if the
4432 // watson buckets are present or not.
4433 BOOL AreWatsonBucketsPresent()
4435 LIMITED_METHOD_CONTRACT;
4436 return (_watsonBuckets != NULL)?TRUE:FALSE;
4439 // This method will save the IP to be used for watson bucketing.
4440 void SetIPForWatsonBuckets(UINT_PTR ip)
4442 LIMITED_METHOD_CONTRACT;
4444 _ipForWatsonBuckets = ip;
4447 // This method will return a BOOL to indicate if Watson bucketing IP
4448 // is present (or not).
4449 BOOL IsIPForWatsonBucketsPresent()
4451 LIMITED_METHOD_CONTRACT;
4453 return (_ipForWatsonBuckets != NULL);
4456 // This method returns the IP for Watson Buckets.
4457 UINT_PTR GetIPForWatsonBuckets()
4459 LIMITED_METHOD_CONTRACT;
4461 return _ipForWatsonBuckets;
4465 // If you modify the order of these fields, make sure to update the definition in
4466 // BCL for this object.
4468 STRINGREF _className; //Needed for serialization.
4469 OBJECTREF _exceptionMethod; //Needed for serialization.
4470 STRINGREF _exceptionMethodString; //Needed for serialization.
4473 OBJECTREF _innerException;
4475 I1ARRAYREF _stackTrace;
4476 U1ARRAYREF _watsonBuckets;
4477 STRINGREF _stackTraceString; //Needed for serialization.
4478 STRINGREF _remoteStackTraceString;
4479 PTRARRAYREF _dynamicMethods;
4480 STRINGREF _source; // Mainly used by VB.
4481 #ifdef FEATURE_SERIALIZATION
4482 OBJECTREF _safeSerializationManager;
4483 #endif // FEATURE_SERIALIZATION
4484 IN_WIN64(void* _xptrs;)
4485 IN_WIN64(UINT_PTR _ipForWatsonBuckets;) // Contains the IP of exception for watson bucketing
4486 INT32 _remoteStackIndex;
4488 IN_WIN32(void* _xptrs;)
4490 IN_WIN32(UINT_PTR _ipForWatsonBuckets;) // Contains the IP of exception for watson bucketing
4493 // Defined in Contracts.cs
4494 enum ContractFailureKind
4496 CONTRACT_FAILURE_PRECONDITION = 0,
4497 CONTRACT_FAILURE_POSTCONDITION,
4498 CONTRACT_FAILURE_POSTCONDITION_ON_EXCEPTION,
4499 CONTRACT_FAILURE_INVARIANT,
4500 CONTRACT_FAILURE_ASSERT,
4501 CONTRACT_FAILURE_ASSUME,
4504 typedef DPTR(class ContractExceptionObject) PTR_ContractExceptionObject;
4505 class ContractExceptionObject : public ExceptionObject
4507 friend class MscorlibBinder;
4510 ContractFailureKind GetContractFailureKind()
4512 LIMITED_METHOD_CONTRACT;
4514 return static_cast<ContractFailureKind>(_Kind);
4518 // keep these in sync with ndp/clr/src/bcl/system/diagnostics/contracts/contractsbcl.cs
4519 IN_WIN64(INT32 _Kind;)
4520 STRINGREF _UserMessage;
4521 STRINGREF _Condition;
4522 IN_WIN32(INT32 _Kind;)
4524 #include "poppack.h"
4526 #ifdef USE_CHECKED_OBJECTREFS
4527 typedef REF<ContractExceptionObject> CONTRACTEXCEPTIONREF;
4528 #else // USE_CHECKED_OBJECTREFS
4529 typedef PTR_ContractExceptionObject CONTRACTEXCEPTIONREF;
4530 #endif // USE_CHECKED_OBJECTREFS
4532 class NumberFormatInfo: public Object
4535 // C++ data members // Corresponding data member in NumberFormatInfo.cs
4536 // Also update mscorlib.h when you add/remove fields
4538 I4ARRAYREF cNumberGroup; // numberGroupSize
4539 I4ARRAYREF cCurrencyGroup; // currencyGroupSize
4540 I4ARRAYREF cPercentGroup; // percentGroupSize
4542 STRINGREF sPositive; // positiveSign
4543 STRINGREF sNegative; // negativeSign
4544 STRINGREF sNumberDecimal; // numberDecimalSeparator
4545 STRINGREF sNumberGroup; // numberGroupSeparator
4546 STRINGREF sCurrencyGroup; // currencyDecimalSeparator
4547 STRINGREF sCurrencyDecimal; // currencyGroupSeparator
4548 STRINGREF sCurrency; // currencySymbol
4549 #ifndef FEATURE_COREFX_GLOBALIZATION
4550 STRINGREF sAnsiCurrency; // ansiCurrencySymbol
4552 STRINGREF sNaN; // nanSymbol
4553 STRINGREF sPositiveInfinity; // positiveInfinitySymbol
4554 STRINGREF sNegativeInfinity; // negativeInfinitySymbol
4555 STRINGREF sPercentDecimal; // percentDecimalSeparator
4556 STRINGREF sPercentGroup; // percentGroupSeparator
4557 STRINGREF sPercent; // percentSymbol
4558 STRINGREF sPerMille; // perMilleSymbol
4560 PTRARRAYREF sNativeDigits; // nativeDigits (a string array)
4562 #ifndef FEATURE_COREFX_GLOBALIZATION
4563 INT32 iDataItem; // Index into the CultureInfo Table. Only used from managed code.
4565 INT32 cNumberDecimals; // numberDecimalDigits
4566 INT32 cCurrencyDecimals; // currencyDecimalDigits
4567 INT32 cPosCurrencyFormat; // positiveCurrencyFormat
4568 INT32 cNegCurrencyFormat; // negativeCurrencyFormat
4569 INT32 cNegativeNumberFormat; // negativeNumberFormat
4570 INT32 cPositivePercentFormat; // positivePercentFormat
4571 INT32 cNegativePercentFormat; // negativePercentFormat
4572 INT32 cPercentDecimals; // percentDecimalDigits
4573 #ifndef FEATURE_CORECLR
4574 INT32 iDigitSubstitution; // digitSubstitution
4577 CLR_BOOL bIsReadOnly; // Is this NumberFormatInfo ReadOnly?
4578 #ifndef FEATURE_COREFX_GLOBALIZATION
4579 CLR_BOOL bUseUserOverride; // Flag to use user override. Only used from managed code.
4581 CLR_BOOL bIsInvariant; // Is this the NumberFormatInfo for the Invariant Culture?
4582 #ifndef FEATURE_CORECLR
4583 CLR_BOOL bvalidForParseAsNumber; // NEVER USED, DO NOT USE THIS! (Serialized in Whidbey/Everett)
4584 CLR_BOOL bvalidForParseAsCurrency; // NEVER USED, DO NOT USE THIS! (Serialized in Whidbey/Everett)
4585 #endif // !FEATURE_CORECLR
4588 typedef NumberFormatInfo * NUMFMTREF;
4590 //===============================================================================
4592 // #NullableArchitecture
4594 // In a nutshell it is counterintuitive to have a boxed Nullable<T>, since a boxed
4595 // object already has a representation for null (the null pointer), and having
4596 // multiple representations for the 'not present' value just causes grief. Thus the
4597 // feature is build make Nullable<T> box to a boxed<T> (not boxed<Nullable<T>).
4599 // We want to do this in a way that does not impact the perf of the runtime in the
4600 // non-nullable case.
4602 // To do this we need to
4603 // * Modify the boxing helper code:JIT_Box (we don't need a special one because
4604 // the JIT inlines the common case, so this only gets call in uncommon cases)
4605 // * Make a new helper for the Unbox case (see code:JIT_Unbox_Nullable)
4606 // * Plumb the JIT to ask for what kind of Boxing helper is needed
4607 // (see code:CEEInfo.getBoxHelper, code:CEEInfo.getUnBoxHelper
4608 // * change all the places in the CLR where we box or unbox by hand, and force
4609 // them to use code:MethodTable.Box, and code:MethodTable.Unbox which in
4610 // turn call code:Nullable.Box and code:Nullable.UnBox, most of these
4611 // are in reflection, and remoting (passing and returning value types).
4613 // #NullableVerification
4615 // Sadly, the IL Verifier also needs to know about this change. Basically the 'box'
4616 // instruction returns a boxed(T) (not a boxed(Nullable<T>)) for the purposes of
4617 // verfication. The JIT finds out what box returns by calling back to the EE with
4618 // the code:CEEInfo.getTypeForBox API.
4620 // #NullableDebugging
4622 // Sadly, because the debugger also does its own boxing 'by hand' for expression
4623 // evaluation inside visual studio, it measn that debuggers also need to be aware
4624 // of the fact that Nullable<T> boxes to a boxed<T>. It is the responcibility of
4625 // debuggers to follow this convention (which is why this is sad).
4628 //===============================================================================
4629 // Nullable represents the managed generic value type Nullable<T>
4631 // The runtime has special logic for this value class. When it is boxed
4632 // it becomes either null or a boxed T. Similarly a boxed T can be unboxed
4633 // either as a T (as normal), or as a Nullable<T>
4635 // See code:Nullable#NullableArchitecture for more.
4638 Nullable(); // This is purposefully undefined. Do not make instances
4641 static void CheckFieldOffsets(TypeHandle nullableType);
4642 static BOOL IsNullableType(TypeHandle nullableType);
4643 static BOOL IsNullableForType(TypeHandle nullableType, MethodTable* paramMT);
4644 static BOOL IsNullableForTypeNoGC(TypeHandle nullableType, MethodTable* paramMT);
4646 static OBJECTREF Box(void* src, MethodTable* nullable);
4647 static BOOL UnBox(void* dest, OBJECTREF boxedVal, MethodTable* destMT);
4648 static BOOL UnBoxNoGC(void* dest, OBJECTREF boxedVal, MethodTable* destMT);
4649 static void UnBoxNoCheck(void* dest, OBJECTREF boxedVal, MethodTable* destMT);
4650 static OBJECTREF BoxedNullableNull(TypeHandle nullableType) { return 0; }
4652 // if 'Obj' is a true boxed nullable, return the form we want (either null or a boxed T)
4653 static OBJECTREF NormalizeBox(OBJECTREF obj);
4655 static inline CLR_BOOL HasValue(void *src, MethodTable *nullableMT)
4657 Nullable *nullable = (Nullable *)src;
4658 return *(nullable->HasValueAddr(nullableMT));
4661 static inline void *Value(void *src, MethodTable *nullableMT)
4663 Nullable *nullable = (Nullable *)src;
4664 return nullable->ValueAddr(nullableMT);
4668 static BOOL IsNullableForTypeHelper(MethodTable* nullableMT, MethodTable* paramMT);
4669 static BOOL IsNullableForTypeHelperNoGC(MethodTable* nullableMT, MethodTable* paramMT);
4671 CLR_BOOL* HasValueAddr(MethodTable* nullableMT);
4672 void* ValueAddr(MethodTable* nullableMT);
4675 #ifdef USE_CHECKED_OBJECTREFS
4676 typedef REF<ExceptionObject> EXCEPTIONREF;
4677 #else // USE_CHECKED_OBJECTREFS
4678 typedef PTR_ExceptionObject EXCEPTIONREF;
4679 #endif // USE_CHECKED_OBJECTREFS
4681 #endif // _OBJECT_H_