Skip to content

Commit

Permalink
Add asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Jul 13, 2024
1 parent 46338d5 commit f5d14ff
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/coreclr/vm/appdomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3965,7 +3965,7 @@ Assembly* AppDomain::RaiseTypeResolveEventThrowing(Assembly* pAssembly, LPCSTR s
GCX_COOP();

struct {
OBJECTREF AssemblyRef;
ASSEMBLYREF AssemblyRef;
STRINGREF str;
} gc;
gc.AssemblyRef = NULL;
Expand All @@ -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);

Expand All @@ -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())
Expand Down Expand Up @@ -4023,7 +4025,7 @@ Assembly* AppDomain::RaiseResourceResolveEvent(Assembly* pAssembly, LPCSTR szNam
GCX_COOP();

struct {
OBJECTREF AssemblyRef;
ASSEMBLYREF AssemblyRef;
STRINGREF str;
} gc;
gc.AssemblyRef = NULL;
Expand All @@ -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);
Expand All @@ -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"));
Expand Down Expand Up @@ -4085,7 +4089,7 @@ AppDomain::RaiseAssemblyResolveEvent(
Assembly* pAssembly = NULL;

struct {
OBJECTREF AssemblyRef;
ASSEMBLYREF AssemblyRef;
STRINGREF str;
} gc;
gc.AssemblyRef = NULL;
Expand All @@ -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);
Expand All @@ -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"));
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f5d14ff

Please sign in to comment.