Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Custom Marshalers in custom-ALC-loaded assemblies results in types loaded from crossing ALCs #21606

Merged
merged 18 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a7dc093
Create repro for dotnet/coreclr#19654
jkoritzinsky Dec 19, 2018
d17832f
Update ICustomMarshaler.csproj
jkoritzinsky Dec 20, 2018
d1a3044
Update ICustomMarshaler.csproj
jkoritzinsky Dec 20, 2018
130f9be
Clean up repro per feedback.
jkoritzinsky Dec 20, 2018
8207f1d
Add test case for different assemblies with the same CustomMarshaler …
jkoritzinsky Dec 20, 2018
f7f49ba
Move EEMarshalingData cache from AppDomain to LoaderAllocator. This f…
jkoritzinsky Dec 21, 2018
c938b8a
Internalize the LoaderHeap* parameter.
jkoritzinsky Dec 21, 2018
7ab2a81
Add the pointer to the requesting assembly to the hashtable key.
jkoritzinsky Dec 21, 2018
a60d1d7
Fix linux-musl build break.
jkoritzinsky Dec 21, 2018
62cf89f
Move Crst out of FEATURE_COMINTEROP block.
jkoritzinsky Dec 21, 2018
0c006a8
Make sure to copy over the assembly pointer to the key that's actuall…
jkoritzinsky Dec 22, 2018
2b0c96f
Add comment for m_invokingAssembly.
jkoritzinsky Jan 2, 2019
2da4af1
Move all usages of EEMarshallingData to hang off the correct loader a…
jkoritzinsky Jan 2, 2019
b37e42c
Change to m_InteropDataCrst since this EEMarshallingData can be used …
jkoritzinsky Jan 3, 2019
fc192a4
Always init m_InteropDataCrst (since it's used by EEMarshallingData a…
jkoritzinsky Jan 3, 2019
9543973
PR Feedback.
jkoritzinsky Jan 14, 2019
c79cae8
Merge branch 'master' of https://github.com/dotnet/coreclr into fixes…
jkoritzinsky Jan 14, 2019
24d32a0
Remove extraneous inlines.
jkoritzinsky Jan 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions src/vm/appdomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,6 @@ BaseDomain::BaseDomain()
m_handleStore = NULL;
#endif

m_pMarshalingData = NULL;

#ifdef FEATURE_COMINTEROP
m_pMngStdInterfacesInfo = NULL;
m_pWinRtBinder = NULL;
Expand Down Expand Up @@ -785,9 +783,6 @@ void BaseDomain::Init()
m_crstAssemblyList.Init(CrstAssemblyList, CrstFlags(
CRST_GC_NOTRIGGER_WHEN_TAKEN | CRST_DEBUGGER_THREAD | CRST_TAKEN_DURING_SHUTDOWN));

// Initialize the EE marshaling data to NULL.
m_pMarshalingData = NULL;

#ifdef FEATURE_COMINTEROP
// Allocate the managed standard interfaces information.
m_pMngStdInterfacesInfo = new MngStdInterfacesInfo();
Expand Down Expand Up @@ -1805,51 +1800,6 @@ OBJECTREF AppDomain::GetMissingObject()

#ifndef DACCESS_COMPILE

EEMarshalingData *BaseDomain::GetMarshalingData()
{
CONTRACT (EEMarshalingData*)
{
THROWS;
GC_TRIGGERS;
MODE_ANY;
INJECT_FAULT(COMPlusThrowOM());
POSTCONDITION(CheckPointer(m_pMarshalingData));
}
CONTRACT_END;

if (!m_pMarshalingData)
{
// Take the lock
CrstHolder holder(&m_InteropDataCrst);

if (!m_pMarshalingData)
{
LoaderHeap* pHeap = GetLoaderAllocator()->GetLowFrequencyHeap();
m_pMarshalingData = new (pHeap) EEMarshalingData(this, pHeap, &m_DomainCrst);
}
}

RETURN m_pMarshalingData;
}

void BaseDomain::DeleteMarshalingData()
{
CONTRACTL
{
NOTHROW;
GC_TRIGGERS;
MODE_ANY;
}
CONTRACTL_END;

// We are in shutdown - no need to take any lock
if (m_pMarshalingData)
{
delete m_pMarshalingData;
m_pMarshalingData = NULL;
}
}

#ifndef CROSSGEN_COMPILE

STRINGREF *BaseDomain::IsStringInterned(STRINGREF *pString)
Expand Down
10 changes: 0 additions & 10 deletions src/vm/appdomain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,14 +1121,6 @@ class BaseDomain
return m_pWinRtBinder;
}
#endif // FEATURE_COMINTEROP

//****************************************************************************************
// This method returns marshaling data that the EE uses that is stored on a per app domain
// basis.
EEMarshalingData *GetMarshalingData();

// Deletes marshaling data at shutdown (which contains cached factories that needs to be released)
void DeleteMarshalingData();

#ifdef _DEBUG
BOOL OwnDomainLocalBlockLock()
Expand Down Expand Up @@ -1329,8 +1321,6 @@ class BaseDomain
// The large heap handle table critical section.
CrstExplicitInit m_LargeHeapHandleTableCrst;

EEMarshalingData *m_pMarshalingData;

#ifdef FEATURE_COMINTEROP
// Information regarding the managed standard interfaces.
MngStdInterfacesInfo *m_pMngStdInterfacesInfo;
Expand Down
5 changes: 0 additions & 5 deletions src/vm/ceemain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,11 +1189,6 @@ void InnerCoEEShutDownCOM()
// Release all of the RCWs in all contexts in all caches.
ReleaseRCWsInCaches(NULL);

// Release all marshaling data in all AppDomains
AppDomainIterator i(TRUE);
while (i.Next())
i.GetDomain()->DeleteMarshalingData();

#ifdef FEATURE_APPX
// Cleanup cached factory pointer in SynchronizationContextNative
SynchronizationContextNative::Cleanup();
Expand Down
4 changes: 2 additions & 2 deletions src/vm/cominterfacemarshaler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ void COMInterfaceMarshaler::MarshalToNonRCWType(OBJECTREF *poref)
LPCWSTR pwszRawUri = hsRawUri.GetRawBuffer(&cchRawUri);
gc.refRawURI = StringObject::NewString(pwszRawUri, cchRawUri);

UriMarshalingInfo *pUriMarshalingInfo = GetAppDomain()->GetMarshalingData()->GetUriMarshalingInfo();
UriMarshalingInfo *pUriMarshalingInfo = GetAppDomain()->GetLoaderAllocator()->GetMarshalingData()->GetUriMarshalingInfo();
MethodDesc* pSystemUriCtorMD = pUriMarshalingInfo->GetSystemUriCtorMD();

MethodTable *pMTSystemUri = pUriMarshalingInfo->GetSystemUriType().AsMethodTable();
Expand Down Expand Up @@ -787,7 +787,7 @@ void COMInterfaceMarshaler::MarshalToNonRCWType(OBJECTREF *poref)
case WinMDAdapter::RedirectedTypeIndex_System_ComponentModel_PropertyChangedEventArgs:
{
MethodDesc *pMD;
EventArgsMarshalingInfo *pInfo = GetAppDomain()->GetMarshalingData()->GetEventArgsMarshalingInfo();
EventArgsMarshalingInfo *pInfo = GetAppDomain()->GetLoaderAllocator()->GetMarshalingData()->GetEventArgsMarshalingInfo();

if (index == WinMDAdapter::RedirectedTypeIndex_System_Collections_Specialized_NotifyCollectionChangedEventArgs)
pMD = pInfo->GetWinRTNCCEventArgsToSystemNCCEventArgsMD();
Expand Down
14 changes: 10 additions & 4 deletions src/vm/custommarshalerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// Implementation of the custom marshaler info class.
//==========================================================================

CustomMarshalerInfo::CustomMarshalerInfo(BaseDomain *pDomain, TypeHandle hndCustomMarshalerType, TypeHandle hndManagedType, LPCUTF8 strCookie, DWORD cCookieStrBytes)
CustomMarshalerInfo::CustomMarshalerInfo(LoaderAllocator *pLoaderAllocator, TypeHandle hndCustomMarshalerType, TypeHandle hndManagedType, LPCUTF8 strCookie, DWORD cCookieStrBytes)
: m_NativeSize(0)
, m_hndManagedType(hndManagedType)
, m_hndCustomMarshaler(NULL)
Expand All @@ -38,7 +38,7 @@ CustomMarshalerInfo::CustomMarshalerInfo(BaseDomain *pDomain, TypeHandle hndCust
THROWS;
GC_TRIGGERS;
MODE_COOPERATIVE;
PRECONDITION(CheckPointer(pDomain));
PRECONDITION(CheckPointer(pLoaderAllocator));
}
CONTRACTL_END;

Expand Down Expand Up @@ -112,7 +112,7 @@ CustomMarshalerInfo::CustomMarshalerInfo(BaseDomain *pDomain, TypeHandle hndCust
IDS_EE_NOCUSTOMMARSHALER,
GetFullyQualifiedNameForClassW(hndCustomMarshalerType.GetMethodTable()));
}
m_hndCustomMarshaler = pDomain->CreateHandle(CustomMarshalerObj);
m_hndCustomMarshaler = pLoaderAllocator->GetDomain()->CreateHandle(CustomMarshalerObj);

// Retrieve the size of the native data.
if (m_bDataIsByValue)
Expand Down Expand Up @@ -367,6 +367,7 @@ EEHashEntry_t * EECMHelperHashtableHelper::AllocateEntry(EECMHelperHashtableKey
cbEntry += S_SIZE_T(pKey->GetMarshalerTypeNameByteCount());
cbEntry += S_SIZE_T(pKey->GetCookieStringByteCount());
cbEntry += S_SIZE_T(pKey->GetMarshalerInstantiation().GetNumArgs()) * S_SIZE_T(sizeof(LPVOID));
cbEntry += S_SIZE_T(sizeof(LPVOID)); // For EECMHelperHashtableKey::m_invokingAssembly

if (cbEntry.IsOverflow())
return NULL;
Expand All @@ -387,6 +388,7 @@ EEHashEntry_t * EECMHelperHashtableHelper::AllocateEntry(EECMHelperHashtableKey
memcpy((void*)pEntryKey->m_strCookie, pKey->GetCookieString(), pKey->GetCookieStringByteCount());
memcpy((void*)pEntryKey->m_Instantiation.GetRawArgs(), pKey->GetMarshalerInstantiation().GetRawArgs(),
pEntryKey->m_Instantiation.GetNumArgs() * sizeof(LPVOID));
pEntryKey->m_invokingAssembly = pKey->GetInvokingAssembly();
}
else
{
Expand All @@ -401,6 +403,7 @@ EEHashEntry_t * EECMHelperHashtableHelper::AllocateEntry(EECMHelperHashtableKey
pEntryKey->m_cCookieStrBytes = pKey->GetCookieStringByteCount();
pEntryKey->m_strCookie = pKey->GetCookieString();
pEntryKey->m_Instantiation = Instantiation(pKey->GetMarshalerInstantiation());
pEntryKey->m_invokingAssembly = pKey->GetInvokingAssembly();
}

return pEntry;
Expand Down Expand Up @@ -458,6 +461,9 @@ BOOL EECMHelperHashtableHelper::CompareKeys(EEHashEntry_t *pEntry, EECMHelperHas
return FALSE;
}

if (pEntryKey->GetInvokingAssembly() != pKey->GetInvokingAssembly())
return FALSE;

return TRUE;
}

Expand Down Expand Up @@ -628,7 +634,7 @@ CustomMarshalerInfo *SharedCustomMarshalerHelper::GetCustomMarshalerInfo()
CONTRACTL_END;

// Retrieve the marshalling data for the current app domain.
EEMarshalingData *pMarshalingData = GetThread()->GetDomain()->GetMarshalingData();
EEMarshalingData *pMarshalingData = GetThread()->GetDomain()->GetLoaderAllocator()->GetMarshalingData();

// Retrieve the custom marshaling information for the current shared custom
// marshaling helper.
Expand Down
22 changes: 15 additions & 7 deletions src/vm/custommarshalerinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CustomMarshalerInfo
{
public:
// Constructor and destructor.
CustomMarshalerInfo(BaseDomain* pDomain, TypeHandle hndCustomMarshalerType, TypeHandle hndManagedType, LPCUTF8 strCookie, DWORD cCookieStrBytes);
CustomMarshalerInfo(LoaderAllocator* pLoaderAllocator, TypeHandle hndCustomMarshalerType, TypeHandle hndManagedType, LPCUTF8 strCookie, DWORD cCookieStrBytes);
~CustomMarshalerInfo();

// CustomMarshalerInfo's are always allocated on the loader heap so we need to redefine
Expand Down Expand Up @@ -114,51 +114,59 @@ class CustomMarshalerInfo

typedef SList<CustomMarshalerInfo, true> CMINFOLIST;

class Assembly;

class EECMHelperHashtableKey
{
public:
EECMHelperHashtableKey(DWORD cMarshalerTypeNameBytes, LPCSTR strMarshalerTypeName, DWORD cCookieStrBytes, LPCSTR strCookie, Instantiation instantiation)
EECMHelperHashtableKey(DWORD cMarshalerTypeNameBytes, LPCSTR strMarshalerTypeName, DWORD cCookieStrBytes, LPCSTR strCookie, Instantiation instantiation, Assembly* invokingAssembly)
: m_cMarshalerTypeNameBytes(cMarshalerTypeNameBytes)
, m_strMarshalerTypeName(strMarshalerTypeName)
, m_cCookieStrBytes(cCookieStrBytes)
, m_strCookie(strCookie)
, m_Instantiation(instantiation)
, m_invokingAssembly(invokingAssembly)
{
LIMITED_METHOD_CONTRACT;
}

inline DWORD GetMarshalerTypeNameByteCount() const
DWORD GetMarshalerTypeNameByteCount() const
{
LIMITED_METHOD_CONTRACT;
return m_cMarshalerTypeNameBytes;
}
inline LPCSTR GetMarshalerTypeName() const
LPCSTR GetMarshalerTypeName() const
{
LIMITED_METHOD_CONTRACT;
return m_strMarshalerTypeName;
}
inline LPCSTR GetCookieString() const
LPCSTR GetCookieString() const
{
LIMITED_METHOD_CONTRACT;
return m_strCookie;
}
inline ULONG GetCookieStringByteCount() const
ULONG GetCookieStringByteCount() const
{
LIMITED_METHOD_CONTRACT;
return m_cCookieStrBytes;
}
inline Instantiation GetMarshalerInstantiation() const
Instantiation GetMarshalerInstantiation() const
{
LIMITED_METHOD_CONTRACT;
return m_Instantiation;
}
Assembly* GetInvokingAssembly() const
{
LIMITED_METHOD_CONTRACT;
return m_invokingAssembly;
}

DWORD m_cMarshalerTypeNameBytes;
LPCSTR m_strMarshalerTypeName;
DWORD m_cCookieStrBytes;
LPCSTR m_strCookie;
Instantiation m_Instantiation;
Assembly* m_invokingAssembly;
};


Expand Down
2 changes: 1 addition & 1 deletion src/vm/dispparammarshaler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void DispParamOleColorMarshaler::MarshalNativeToManaged(VARIANT *pSrcVar, OBJECT

// Box the System.Drawing.Color value class and give back the boxed object.
TypeHandle hndColorType =
GetThread()->GetDomain()->GetMarshalingData()->GetOleColorMarshalingInfo()->GetColorType();
GetThread()->GetDomain()->GetLoaderAllocator()->GetMarshalingData()->GetOleColorMarshalingInfo()->GetColorType();

*pDestObj = hndColorType.GetMethodTable()->Box(&MngColor);
}
Expand Down
Loading