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

Commit

Permalink
Change method DestroyContext to PrepareForLoadContextRelease and Rele…
Browse files Browse the repository at this point in the history
…aseManagedAssemblyLoadContext to ReleaseLoadContext
  • Loading branch information
xoofx committed Dec 27, 2016
1 parent df223c1 commit 0cc6d4d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
12 changes: 8 additions & 4 deletions src/binder/clrprivbinderassemblyloadcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::SetupContext(DWORD dwAppDomainId,
return hr;
}

void CLRPrivBinderAssemblyLoadContext::DestroyContext(INT_PTR ptrManagedStrongAssemblyLoadContext)
void CLRPrivBinderAssemblyLoadContext::PrepareForLoadContextRelease(INT_PTR ptrManagedStrongAssemblyLoadContext)
{
CONTRACTL
{
Expand All @@ -287,14 +287,15 @@ void CLRPrivBinderAssemblyLoadContext::DestroyContext(INT_PTR ptrManagedStrongAs
CONTRACTL_END;

// Replace the weak handle with a strong handle
// in order to be able to callback Unloading safely
// in order to be able to callback the managed method AssemblyLoadContext.Unloading safely
OBJECTHANDLE handle = reinterpret_cast<OBJECTHANDLE>(m_ptrManagedAssemblyLoadContext);
OBJECTHANDLE strongHandle = reinterpret_cast<OBJECTHANDLE>(ptrManagedStrongAssemblyLoadContext);
DestroyShortWeakHandle(handle);
m_ptrManagedAssemblyLoadContext = reinterpret_cast<INT_PTR>(strongHandle);

// We cannot delete the binder here as it is used indirectly when comparing assemblies with the same binder
// It will be deleted by the LoaderAllocator once
// It will be deleted when the LoaderAllocator will be deleted
// But we can release the LoaderAllocator as we are no longer using it here
m_pAssemblyLoaderAllocator->Release();
m_pAssemblyLoaderAllocator = NULL;

Expand All @@ -308,9 +309,12 @@ CLRPrivBinderAssemblyLoadContext::CLRPrivBinderAssemblyLoadContext()
m_pTPABinder = NULL;
}

void CLRPrivBinderAssemblyLoadContext::ReleaseManagedAssemblyLoadContext()
void CLRPrivBinderAssemblyLoadContext::ReleaseLoadContext()
{
VERIFY(m_ptrManagedAssemblyLoadContext != NULL);

// This method is called to release the strong handle on the managed AssemblyLoadContext
// once the Unloading event has been fired
OBJECTHANDLE handle = reinterpret_cast<OBJECTHANDLE>(m_ptrManagedAssemblyLoadContext);
DestroyHandle(handle);
m_ptrManagedAssemblyLoadContext = NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/binder/inc/clrprivbinderassemblyloadcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CLRPrivBinderAssemblyLoadContext :
UINT_PTR ptrAssemblyLoadContext,
CLRPrivBinderAssemblyLoadContext **ppBindContext);

void DestroyContext(INT_PTR ptrManagedStrongAssemblyLoadContext);
void PrepareForLoadContextRelease(INT_PTR ptrManagedStrongAssemblyLoadContext);

CLRPrivBinderAssemblyLoadContext();

Expand All @@ -103,7 +103,7 @@ class CLRPrivBinderAssemblyLoadContext :
return m_ptrManagedAssemblyLoadContext;
}

void ReleaseManagedAssemblyLoadContext();
void ReleaseLoadContext();

HRESULT BindUsingPEImage( /* in */ PEImage *pPEImage,
/* in */ BOOL fIsNativeImage,
Expand Down
4 changes: 2 additions & 2 deletions src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public abstract class AssemblyLoadContext

[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
[SuppressUnmanagedCodeSecurity]
private static extern void DestroyAssemblyLoadContext(IntPtr ptrNativeAssemblyLoadContext, IntPtr ptrAssemblyLoadContextStrong);
private static extern void PrepareForAssemblyLoadContextRelease(IntPtr ptrNativeAssemblyLoadContext, IntPtr ptrAssemblyLoadContextStrong);

[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
[SuppressUnmanagedCodeSecurity]
Expand Down Expand Up @@ -278,7 +278,7 @@ private void UnloadInternal()

// The underlying code will transform the original weak handle
// created by InitializeLoadContext to a strong handle
DestroyAssemblyLoadContext(m_pNativeAssemblyLoadContext, thisStrongHandlePtr);
PrepareForAssemblyLoadContextRelease(m_pNativeAssemblyLoadContext, thisStrongHandlePtr);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/vm/assemblynative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2554,7 +2554,7 @@ INT_PTR QCALLTYPE AssemblyNative::InitializeAssemblyLoadContext(INT_PTR ptrManag
}

/*static*/
void QCALLTYPE AssemblyNative::DestroyAssemblyLoadContext(INT_PTR ptrNativeAssemblyLoadContext, INT_PTR ptrManagedStrongAssemblyLoadContext)
void QCALLTYPE AssemblyNative::PrepareForAssemblyLoadContextRelease(INT_PTR ptrNativeAssemblyLoadContext, INT_PTR ptrManagedStrongAssemblyLoadContext)
{
QCALL_CONTRACT;

Expand All @@ -2565,7 +2565,7 @@ void QCALLTYPE AssemblyNative::DestroyAssemblyLoadContext(INT_PTR ptrNativeAssem

{
GCX_COOP();
reinterpret_cast<CLRPrivBinderAssemblyLoadContext *>(ptrNativeAssemblyLoadContext)->DestroyContext(ptrManagedStrongAssemblyLoadContext);
reinterpret_cast<CLRPrivBinderAssemblyLoadContext *>(ptrNativeAssemblyLoadContext)->PrepareForLoadContextRelease(ptrManagedStrongAssemblyLoadContext);
}

END_QCALL;
Expand Down
2 changes: 1 addition & 1 deletion src/vm/assemblynative.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class AssemblyNative
#endif

static INT_PTR QCALLTYPE InitializeAssemblyLoadContext(INT_PTR ptrManagedAssemblyLoadContext, BOOL fRepresentsTPALoadContext, BOOL fIsCollectible);
static void QCALLTYPE DestroyAssemblyLoadContext(INT_PTR ptrNativeAssemblyLoadContext, INT_PTR ptrManagedStrongAssemblyLoadContext);
static void QCALLTYPE PrepareForAssemblyLoadContextRelease(INT_PTR ptrNativeAssemblyLoadContext, INT_PTR ptrManagedStrongAssemblyLoadContext);
static BOOL QCALLTYPE OverrideDefaultAssemblyLoadContextForCurrentDomain(INT_PTR ptrNativeAssemblyLoadContext);
static BOOL QCALLTYPE CanUseAppPathAssemblyLoadContextInCurrentDomain();
static void QCALLTYPE LoadFromPath(INT_PTR ptrNativeAssemblyLoadContext, LPCWSTR pwzILPath, LPCWSTR pwzNIPath, QCall::ObjectHandleOnStack retLoadedAssembly);
Expand Down
2 changes: 1 addition & 1 deletion src/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ FCFuncEnd()
#if defined(FEATURE_HOST_ASSEMBLY_RESOLVER)
FCFuncStart(gAssemblyLoadContextFuncs)
QCFuncElement("InitializeAssemblyLoadContext", AssemblyNative::InitializeAssemblyLoadContext)
QCFuncElement("DestroyAssemblyLoadContext", AssemblyNative::DestroyAssemblyLoadContext)
QCFuncElement("PrepareForAssemblyLoadContextRelease", AssemblyNative::PrepareForAssemblyLoadContextRelease)
QCFuncElement("LoadFromPath", AssemblyNative::LoadFromPath)
QCFuncElement("GetLoadedAssembliesInternal", AssemblyNative::GetLoadedAssembliesInternal)
QCFuncElement("InternalLoadUnmanagedDllFromPath", AssemblyNative::InternalLoadUnmanagedDllFromPath)
Expand Down
3 changes: 1 addition & 2 deletions src/vm/loaderallocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1749,8 +1749,7 @@ void AssemblyLoaderAllocator::OnUnloading()
methodOnUnloading.Call(args);

// Release the managed ALC

m_binderToRelease->ReleaseManagedAssemblyLoadContext();
m_binderToRelease->ReleaseLoadContext();
}
#endif

Expand Down

0 comments on commit 0cc6d4d

Please sign in to comment.