if(fValid)
{
// Get the appdomain
- ADIndex appDomainIndex = HndGetHandleADIndex(objectHandle);
+ IGCHandleManager *mgr = GCHandleUtilities::GetGCHandleManager();
+ ADIndex appDomainIndex = ADIndex(reinterpret_cast<DWORD>(mgr->GetHandleContext(objectHandle)));
pAppDomain = SystemDomain::GetAppDomainAtIndex(appDomainIndex);
_ASSERTE(pAppDomain != NULL);
#include "gcenv.h"
#include "gchandletableimpl.h"
#include "objecthandle.h"
+#include "handletablepriv.h"
GCHandleStore* g_gcGlobalHandleStore;
return _underlyingBucket.Contains(handle);
}
-OBJECTHANDLE GCHandleStore::CreateHandleOfType(Object* object, int type)
+OBJECTHANDLE GCHandleStore::CreateHandleOfType(Object* object, HandleType type)
{
HHANDLETABLE handletable = _underlyingBucket.pTable[GetCurrentThreadHomeHeapNumber()];
return ::HndCreateHandle(handletable, type, ObjectToOBJECTREF(object));
}
-OBJECTHANDLE GCHandleStore::CreateHandleOfType(Object* object, int type, int heapToAffinitizeTo)
+OBJECTHANDLE GCHandleStore::CreateHandleOfType(Object* object, HandleType type, int heapToAffinitizeTo)
{
HHANDLETABLE handletable = _underlyingBucket.pTable[heapToAffinitizeTo];
return ::HndCreateHandle(handletable, type, ObjectToOBJECTREF(object));
}
-OBJECTHANDLE GCHandleStore::CreateHandleWithExtraInfo(Object* object, int type, void* pExtraInfo)
+OBJECTHANDLE GCHandleStore::CreateHandleWithExtraInfo(Object* object, HandleType type, void* pExtraInfo)
{
HHANDLETABLE handletable = _underlyingBucket.pTable[GetCurrentThreadHomeHeapNumber()];
return ::HndCreateHandle(handletable, type, ObjectToOBJECTREF(object), reinterpret_cast<uintptr_t>(pExtraInfo));
return (void*)((uintptr_t)::HndGetHandleTableADIndex(::HndGetHandleTable(handle)).m_dwIndex);
}
-OBJECTHANDLE GCHandleManager::CreateGlobalHandleOfType(Object* object, int type)
+OBJECTHANDLE GCHandleManager::CreateGlobalHandleOfType(Object* object, HandleType type)
{
return ::HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], type, ObjectToOBJECTREF(object));
}
return ::HndCreateHandle(HndGetHandleTable(handle), HNDTYPE_DEFAULT, ::HndFetchHandle(handle));
}
-void GCHandleManager::DestroyHandleOfType(OBJECTHANDLE handle, int type)
+void GCHandleManager::DestroyHandleOfType(OBJECTHANDLE handle, HandleType type)
{
::HndDestroyHandle(::HndGetHandleTable(handle), type, handle);
}
::HndDestroyHandleOfUnknownType(::HndGetHandleTable(handle), handle);
}
+void GCHandleManager::SetExtraInfoForHandle(OBJECTHANDLE handle, HandleType type, void* pExtraInfo)
+{
+ ::HndSetHandleExtraInfo(handle, type, (uintptr_t)pExtraInfo);
+}
+
void* GCHandleManager::GetExtraInfoFromHandle(OBJECTHANDLE handle)
{
return (void*)::HndGetHandleExtraInfo(handle);
{
return (Object*)::HndInterlockedCompareExchangeHandle(handle, ObjectToOBJECTREF(object), ObjectToOBJECTREF(comparandObject));
}
+
+HandleType GCHandleManager::HandleFetchType(OBJECTHANDLE handle)
+{
+ uint32_t type = ::HandleFetchType(handle);
+ assert(type >= HNDTYPE_WEAK_SHORT && type <= HNDTYPE_WEAK_WINRT);
+ return static_cast<HandleType>(type);
+}
+
virtual bool ContainsHandle(OBJECTHANDLE handle);
- virtual OBJECTHANDLE CreateHandleOfType(Object* object, int type);
+ virtual OBJECTHANDLE CreateHandleOfType(Object* object, HandleType type);
- virtual OBJECTHANDLE CreateHandleOfType(Object* object, int type, int heapToAffinitizeTo);
+ virtual OBJECTHANDLE CreateHandleOfType(Object* object, HandleType type, int heapToAffinitizeTo);
- virtual OBJECTHANDLE CreateHandleWithExtraInfo(Object* object, int type, void* pExtraInfo);
+ virtual OBJECTHANDLE CreateHandleWithExtraInfo(Object* object, HandleType type, void* pExtraInfo);
virtual OBJECTHANDLE CreateDependentHandle(Object* primary, Object* secondary);
virtual void DestroyHandleStore(IGCHandleStore* store);
- virtual OBJECTHANDLE CreateGlobalHandleOfType(Object* object, int type);
+ virtual OBJECTHANDLE CreateGlobalHandleOfType(Object* object, HandleType type);
virtual OBJECTHANDLE CreateDuplicateHandle(OBJECTHANDLE handle);
- virtual void DestroyHandleOfType(OBJECTHANDLE handle, int type);
+ virtual void DestroyHandleOfType(OBJECTHANDLE handle, HandleType type);
virtual void DestroyHandleOfUnknownType(OBJECTHANDLE handle);
+ virtual void SetExtraInfoForHandle(OBJECTHANDLE handle, HandleType type, void* pExtraInfo);
+
virtual void* GetExtraInfoFromHandle(OBJECTHANDLE handle);
virtual void StoreObjectInHandle(OBJECTHANDLE handle, Object* object);
virtual Object* GetDependentHandleSecondary(OBJECTHANDLE handle);
virtual Object* InterlockedCompareExchangeObjectInHandle(OBJECTHANDLE handle, Object* object, Object* comparandObject);
+
+ virtual HandleType HandleFetchType(OBJECTHANDLE handle);
};
#endif // GCHANDLETABLE_H_
virtual bool ContainsHandle(OBJECTHANDLE handle) = 0;
- virtual OBJECTHANDLE CreateHandleOfType(Object* object, int type) = 0;
+ virtual OBJECTHANDLE CreateHandleOfType(Object* object, HandleType type) = 0;
- virtual OBJECTHANDLE CreateHandleOfType(Object* object, int type, int heapToAffinitizeTo) = 0;
+ virtual OBJECTHANDLE CreateHandleOfType(Object* object, HandleType type, int heapToAffinitizeTo) = 0;
- virtual OBJECTHANDLE CreateHandleWithExtraInfo(Object* object, int type, void* pExtraInfo) = 0;
+ virtual OBJECTHANDLE CreateHandleWithExtraInfo(Object* object, HandleType type, void* pExtraInfo) = 0;
virtual OBJECTHANDLE CreateDependentHandle(Object* primary, Object* secondary) = 0;
virtual void DestroyHandleStore(IGCHandleStore* store) = 0;
- virtual OBJECTHANDLE CreateGlobalHandleOfType(Object* object, int type) = 0;
+ virtual OBJECTHANDLE CreateGlobalHandleOfType(Object* object, HandleType type) = 0;
virtual OBJECTHANDLE CreateDuplicateHandle(OBJECTHANDLE handle) = 0;
- virtual void DestroyHandleOfType(OBJECTHANDLE handle, int type) = 0;
+ virtual void DestroyHandleOfType(OBJECTHANDLE handle, HandleType type) = 0;
virtual void DestroyHandleOfUnknownType(OBJECTHANDLE handle) = 0;
+ virtual void SetExtraInfoForHandle(OBJECTHANDLE handle, HandleType type, void* pExtraInfo) = 0;
+
virtual void* GetExtraInfoFromHandle(OBJECTHANDLE handle) = 0;
virtual void StoreObjectInHandle(OBJECTHANDLE handle, Object* object) = 0;
virtual Object* GetDependentHandleSecondary(OBJECTHANDLE handle) = 0;
virtual Object* InterlockedCompareExchangeObjectInHandle(OBJECTHANDLE handle, Object* object, Object* comparandObject) = 0;
+
+ virtual HandleType HandleFetchType(OBJECTHANDLE handle) = 0;
};
// IGCHeap is the interface that the VM will use when interacting with the GC.
# Needed due to the cmunged files being in the binary folders, the set(CMAKE_INCLUDE_CURRENT_DIR ON) is not enough
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR})
-
-include_directories(${CLR_DIR}/src/gc)
-
include_directories(${ARCH_SOURCES_DIR})
add_definitions(-DUNICODE)
pNewCtxEntry = pEntry->m_pCtxEntry;
pEntry->m_pCtxEntry = pTemp;
- HndAssignHandle(pEntry->m_ohFactoryObject, *refFactory);
+ IGCHandleManager *mgr = GCHandleUtilities::GetGCHandleManager();
+ mgr->StoreObjectInHandle(pEntry->m_ohFactoryObject, OBJECTREFToObject(*refFactory));
}
}
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
-#ifdef _DEBUG
-#include "handletablepriv.h"
-#endif
-
-
-
void AppDomain::Init()
{
CONTRACTL
// Handles
#if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
- OBJECTHANDLE CreateTypedHandle(OBJECTREF object, int type)
+ OBJECTHANDLE CreateTypedHandle(OBJECTREF object, HandleType type)
{
WRAPPER_NO_CONTRACT;
FieldDesc *pHelperField = MscorlibBinder::GetField(FIELD__ENC_HELPER__OBJECT_REFERENCE);
// store the empty boxed object into the helper object
- OBJECTREF pHelperObj = GetDependentHandleSecondary(pEntry->m_FieldData);
+ IGCHandleManager *mgr = GCHandleUtilities::GetGCHandleManager();
+ OBJECTREF pHelperObj = ObjectToOBJECTREF(mgr->GetDependentHandleSecondary(pEntry->m_FieldData));
OBJECTREF *pHelperRef = (OBJECTREF *)pHelperField->GetAddress( pHelperObj->GetAddress() );
SetObjectReference( pHelperRef, obj, pDomain );
// we found a matching entry in the list of EnCAddedFields
// Get the EnC helper object (see the detailed description in Allocate above)
- OBJECTREF pHelper = GetDependentHandleSecondary(pEntry->m_FieldData);
+ IGCHandleManager *mgr = GCHandleUtilities::GetGCHandleManager();
+ OBJECTREF pHelper = ObjectToOBJECTREF(mgr->GetDependentHandleSecondary(pEntry->m_FieldData));
_ASSERTE(pHelper != NULL);
FieldDesc *pHelperFieldDesc = NULL;
// we found a matching entry in the list of EnCAddedFields
// Get the EnC helper object (see the detailed description in Allocate above)
- OBJECTREF pHelper = GetDependentHandleSecondary(pEntry->m_FieldData);
+ IGCHandleManager *mgr = GCHandleUtilities::GetGCHandleManager();
+ OBJECTREF pHelper = ObjectToOBJECTREF(mgr->GetDependentHandleSecondary(pEntry->m_FieldData));
_ASSERTE(pHelper != NULL);
FieldDesc * pHelperField = NULL;
#undef Sleep
#endif // Sleep
-#include "env/gcenv.os.h"
+#include "../gc/env/gcenv.os.h"
#define MAX_PTR ((uint8_t*)(~(ptrdiff_t)0))
_ASSERTE("Attempt to access destroyed handle." && *(_UNCHECKED_OBJECTREF*)handle != DEBUG_DestroyedHandleValue);
#endif
- ADIndex appDomainIndex = HndGetHandleADIndex(handle);
+ IGCHandleManager *mgr = GCHandleUtilities::GetGCHandleManager();
+ ADIndex appDomainIndex = ADIndex(reinterpret_cast<DWORD>(mgr->GetHandleContext(handle)));
AppDomain *unloadingDomain = SystemDomain::AppDomainBeingUnloaded();
if (unloadingDomain && unloadingDomain->GetIndex() == appDomainIndex && unloadingDomain->NoAccessToHandleTable())
ValidateObjectAndAppDomain(objRef, appDomainIndex);
#endif // _DEBUG_IMPL
-}
\ No newline at end of file
+}
#include "fcall.h"
#include "dllimportcallback.h"
#include "comdelegate.h"
-#include "handletablepriv.h"
#include "mdaassistants.h"
#include "typestring.h"
#include "appdomain.inl"
OBJECTHANDLE hnd = 0;
HELPER_METHOD_FRAME_BEGIN_RET_NOPOLL();
-
+
// If it is a pinned handle, check the object type.
if (type == HNDTYPE_PINNED)
GCHandleValidatePinnedObject(objRef);
+ assert(type >= HNDTYPE_WEAK_SHORT && type <= HNDTYPE_WEAK_WINRT);
// Create the handle.
- hnd = GetAppDomain()->CreateTypedHandle(objRef, type);
+ hnd = GetAppDomain()->CreateTypedHandle(objRef, static_cast<HandleType>(type));
HELPER_METHOD_FRAME_END_POLL();
return (LPVOID) hnd;
{
FCALL_CONTRACT;
- return HandleFetchType(handle);
+ return GCHandleUtilities::GetGCHandleManager()->HandleFetchType(handle);
}
FCIMPLEND
{
OBJECTHANDLE depHnd = m_depHndList[i];
- HndAssignHandle(depHnd, NULL);
- SetDependentHandleSecondary(depHnd, NULL);
+ IGCHandleManager *mgr = GCHandleUtilities::GetGCHandleManager();
+ mgr->StoreObjectInHandle(depHnd, NULL);
+ mgr->SetDependentHandleSecondary(depHnd, NULL);
LOG((LF_INTEROP, LL_INFO1000, "\t[RCWRefCache 0x%p] DependentHandle 0x%p cleared @ index %d\n", this, depHnd, (ULONG) i));
}
// Yes, there is a valid DependentHandle entry on the list, use that
OBJECTHANDLE depHnd = (OBJECTHANDLE) m_depHndList[m_dwDepHndListFreeIndex];
- HndAssignHandle(depHnd, pRCW->GetExposedObject());
- SetDependentHandleSecondary(depHnd, pCCW->GetObjectRef());
+ IGCHandleManager *mgr = GCHandleUtilities::GetGCHandleManager();
+ mgr->StoreObjectInHandle(depHnd, OBJECTREFToObject(pRCW->GetExposedObject()));
+ mgr->SetDependentHandleSecondary(depHnd, OBJECTREFToObject(pCCW->GetObjectRef()));
STRESS_LOG3(
LF_INTEROP, LL_INFO1000,
GCX_COOP();
TypeHandle th = TypeHandle::FromPtr(pTypeHandle);
- objHandle = th.GetDomain()->CreateTypedHandle(NULL, handleType);
+ assert(handleType >= HNDTYPE_WEAK_SHORT && handleType <= HNDTYPE_WEAK_WINRT);
+ objHandle = th.GetDomain()->CreateTypedHandle(NULL, static_cast<HandleType>(handleType));
th.GetLoaderAllocator()->RegisterHandleForCleanup(objHandle);
END_QCALL;
#include "common.h"
+#include "gchandleutilities.h"
#include "weakreferencenative.h"
-#include "handletablepriv.h"
#include "typestring.h"
#include "typeparse.h"
}
else if(IsWinRTWeakReferenceHandle(handle.RawHandle))
{
- _ASSERTE(HandleFetchType(handle.Handle) == HNDTYPE_WEAK_WINRT);
+ _ASSERTE(GCHandleUtilities::GetGCHandleManager()->HandleFetchType(handle.Handle) == HNDTYPE_WEAK_WINRT);
// Retrieve the associated IWeakReference* for this weak reference. Add a reference to it while we release
// the spin lock so that another thread doesn't release it out from underneath us.
// it's always set to NULL here and there's nothing for it to release.
_ASSERTE(pWinRTWeakReference.IsNull());
CONTRACT_VIOLATION(GCViolation);
- pWinRTWeakReference = reinterpret_cast<IWeakReference*>(HndGetHandleExtraInfo(handle.Handle));
+ IGCHandleManager *mgr = GCHandleUtilities::GetGCHandleManager();
+ pWinRTWeakReference = reinterpret_cast<IWeakReference*>(mgr->GetExtraInfoFromHandle(handle.Handle));
if (!pWinRTWeakReference.IsNull())
{
pWinRTWeakReference->AddRef();
handleToDestroy = GetHandleValue(handle);
// Cache the old handle value
- UINT handleType = HandleFetchType(handleToDestroy);
+ HandleType handleType = GCHandleUtilities::GetGCHandleManager()->HandleFetchType(handleToDestroy);
#ifdef FEATURE_COMINTEROP
_ASSERTE(handleType == HNDTYPE_WEAK_LONG || handleType == HNDTYPE_WEAK_SHORT || handleType == HNDTYPE_WEAK_WINRT);
isWeakWinRTHandle = handleType == HNDTYPE_WEAK_WINRT;
// and update it with the new weak reference pointer. If the incoming object is not an RCW that can
// use IWeakReference, then pTargetWeakReference will be null. Therefore, no matter what the incoming
// object type is, we can unconditionally store pTargetWeakReference to the object handle's extra data.
- IWeakReference* pExistingWeakReference = reinterpret_cast<IWeakReference*>(HndGetHandleExtraInfo(handle.Handle));
- HndSetHandleExtraInfo(handle.Handle, HNDTYPE_WEAK_WINRT, reinterpret_cast<LPARAM>(pTargetWeakReference.GetValue()));
+ IGCHandleManager *mgr = GCHandleUtilities::GetGCHandleManager();
+ IWeakReference* pExistingWeakReference = reinterpret_cast<IWeakReference*>(mgr->GetExtraInfoFromHandle(handle.Handle));
+ mgr->SetExtraInfoForHandle(handle.Handle, HNDTYPE_WEAK_WINRT, reinterpret_cast<void*>(pTargetWeakReference.GetValue()));
StoreObjectInHandle(handle.Handle, target);
if (pExistingWeakReference != nullptr)
}
else
{
- trackResurrection = HandleFetchType(GetHandleValue(handle)) == HNDTYPE_WEAK_LONG;
+ trackResurrection = GCHandleUtilities::GetGCHandleManager()->HandleFetchType(GetHandleValue(handle)) == HNDTYPE_WEAK_LONG;
}
ReleaseWeakHandleSpinLock(pThis, handle);
}
else
{
- trackResurrection = HandleFetchType(GetHandleValue(handle)) == HNDTYPE_WEAK_LONG;
+ trackResurrection = GCHandleUtilities::GetGCHandleManager()->HandleFetchType(GetHandleValue(handle)) == HNDTYPE_WEAK_LONG;
}
ReleaseWeakHandleSpinLock(pThis, handle);