From f5d14ffea2bcfeebfd20006d4369c0a3acee75b3 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sun, 7 Jul 2024 17:25:17 -0700 Subject: [PATCH] Add asserts --- src/coreclr/vm/appdomain.cpp | 40 +++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index f8436aca04d5b..decf569b90d3a 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -3965,7 +3965,7 @@ Assembly* AppDomain::RaiseTypeResolveEventThrowing(Assembly* pAssembly, LPCSTR s GCX_COOP(); struct { - OBJECTREF AssemblyRef; + ASSEMBLYREF AssemblyRef; STRINGREF str; } gc; gc.AssemblyRef = NULL; @@ -3974,7 +3974,7 @@ Assembly* AppDomain::RaiseTypeResolveEventThrowing(Assembly* pAssembly, LPCSTR s GCPROTECT_BEGIN(gc); if (pAssembly != NULL) - gc.AssemblyRef = pAssembly->GetExposedObject(); + gc.AssemblyRef = (ASSEMBLYREF)pAssembly->GetExposedObject(); MethodDescCallSite onTypeResolve(METHOD__ASSEMBLYLOADCONTEXT__ON_TYPE_RESOLVE); @@ -3984,14 +3984,16 @@ Assembly* AppDomain::RaiseTypeResolveEventThrowing(Assembly* pAssembly, LPCSTR s ObjToArgSlot(gc.AssemblyRef), ObjToArgSlot(gc.str) }; - ASSEMBLYREF ResultingAssemblyRef = (ASSEMBLYREF) onTypeResolve.Call_RetOBJECTREF(args); + gc.AssemblyRef = (ASSEMBLYREF) onTypeResolve.Call_RetOBJECTREF(args); - if (ResultingAssemblyRef != NULL) + if (gc.AssemblyRef != NULL) { - pResolvedAssembly = ResultingAssemblyRef->GetAssembly(); + _ASSERTE(CoreLibBinder::IsClass(gc.AssemblyRef->GetMethodTable(), CLASS__ASSEMBLY)); + + pResolvedAssembly = gc.AssemblyRef->GetAssembly(); if (pResultingAssemblyRef) - *pResultingAssemblyRef = ResultingAssemblyRef; + *pResultingAssemblyRef = gc.AssemblyRef; else { if (pResolvedAssembly->IsCollectible()) @@ -4023,7 +4025,7 @@ Assembly* AppDomain::RaiseResourceResolveEvent(Assembly* pAssembly, LPCSTR szNam GCX_COOP(); struct { - OBJECTREF AssemblyRef; + ASSEMBLYREF AssemblyRef; STRINGREF str; } gc; gc.AssemblyRef = NULL; @@ -4032,7 +4034,7 @@ Assembly* AppDomain::RaiseResourceResolveEvent(Assembly* pAssembly, LPCSTR szNam GCPROTECT_BEGIN(gc); if (pAssembly != NULL) - gc.AssemblyRef=pAssembly->GetExposedObject(); + gc.AssemblyRef=(ASSEMBLYREF)pAssembly->GetExposedObject(); MethodDescCallSite onResourceResolve(METHOD__ASSEMBLYLOADCONTEXT__ON_RESOURCE_RESOLVE); gc.str = StringObject::NewString(szName); @@ -4041,10 +4043,12 @@ Assembly* AppDomain::RaiseResourceResolveEvent(Assembly* pAssembly, LPCSTR szNam ObjToArgSlot(gc.AssemblyRef), ObjToArgSlot(gc.str) }; - ASSEMBLYREF ResultingAssemblyRef = (ASSEMBLYREF) onResourceResolve.Call_RetOBJECTREF(args); - if (ResultingAssemblyRef != NULL) + gc.AssemblyRef = (ASSEMBLYREF) onResourceResolve.Call_RetOBJECTREF(args); + if (gc.AssemblyRef != NULL) { - pResolvedAssembly = ResultingAssemblyRef->GetAssembly(); + _ASSERTE(CoreLibBinder::IsClass(gc.AssemblyRef->GetMethodTable(), CLASS__ASSEMBLY)); + + pResolvedAssembly = gc.AssemblyRef->GetAssembly(); if (pResolvedAssembly->IsCollectible()) { COMPlusThrow(kNotSupportedException, W("NotSupported_CollectibleAssemblyResolve")); @@ -4085,7 +4089,7 @@ AppDomain::RaiseAssemblyResolveEvent( Assembly* pAssembly = NULL; struct { - OBJECTREF AssemblyRef; + ASSEMBLYREF AssemblyRef; STRINGREF str; } gc; gc.AssemblyRef = NULL; @@ -4095,7 +4099,7 @@ AppDomain::RaiseAssemblyResolveEvent( { if (pSpec->GetParentAssembly() != NULL) { - gc.AssemblyRef=pSpec->GetParentAssembly()->GetExposedObject(); + gc.AssemblyRef=(ASSEMBLYREF)pSpec->GetParentAssembly()->GetExposedObject(); } MethodDescCallSite onAssemblyResolve(METHOD__ASSEMBLYLOADCONTEXT__ON_ASSEMBLY_RESOLVE); @@ -4106,11 +4110,13 @@ AppDomain::RaiseAssemblyResolveEvent( ObjToArgSlot(gc.str) }; - ASSEMBLYREF ResultingAssemblyRef = (ASSEMBLYREF) onAssemblyResolve.Call_RetOBJECTREF(args); + gc.AssemblyRef = (ASSEMBLYREF) onAssemblyResolve.Call_RetOBJECTREF(args); - if (ResultingAssemblyRef != NULL) + if (gc.AssemblyRef != NULL) { - pAssembly = ResultingAssemblyRef->GetAssembly(); + _ASSERTE(CoreLibBinder::IsClass(gc.AssemblyRef->GetMethodTable(), CLASS__ASSEMBLY)); + + pAssembly = gc.AssemblyRef->GetAssembly(); if (pAssembly->IsCollectible()) { COMPlusThrow(kNotSupportedException, W("NotSupported_CollectibleAssemblyResolve")); @@ -4543,6 +4549,8 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToB // If we are here, assembly was successfully resolved via Load or Resolving events. _ASSERTE(_gcRefs.oRefLoadedAssembly != NULL); + _ASSERTE(CoreLibBinder::IsClass(_gcRefs.oRefLoadedAssembly->GetMethodTable(), CLASS__ASSEMBLY)); + // We were able to get the assembly loaded. Now, get its name since the host could have // performed the resolution using an assembly with different name. DomainAssembly *pDomainAssembly = _gcRefs.oRefLoadedAssembly->GetDomainAssembly();