From: Gaurav Khanna Date: Fri, 28 Apr 2017 23:06:54 +0000 (-0700) Subject: Correctly enumerate loaded assemblies in AppDomain (dotnet/coreclr#11294) X-Git-Tag: submit/tizen/20210909.063632~11030^2~7072 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bbc039fe1ee9ba3476504dfe6053411bd9573009;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Correctly enumerate loaded assemblies in AppDomain (dotnet/coreclr#11294) * Correctly enumerate loaded assemblies in AppDomain * Remove unrequired attribute Commit migrated from https://github.com/dotnet/coreclr/commit/b38113c80d04c39890207d149bf0359a86711d62 --- diff --git a/src/coreclr/src/mscorlib/src/System/AppDomain.cs b/src/coreclr/src/mscorlib/src/System/AppDomain.cs index 7d2f2ce..02a473c 100644 --- a/src/coreclr/src/mscorlib/src/System/AppDomain.cs +++ b/src/coreclr/src/mscorlib/src/System/AppDomain.cs @@ -646,6 +646,14 @@ namespace System return StringBuilderCache.GetStringAndRelease(sb); } + [MethodImpl(MethodImplOptions.InternalCall)] + private extern Assembly[] nGetAssemblies(bool forIntrospection); + + internal Assembly[] GetAssemblies(bool forIntrospection) + { + return nGetAssemblies(forIntrospection); + } + // this is true when we've removed the handles etc so really can't do anything [MethodImplAttribute(MethodImplOptions.InternalCall)] internal extern bool IsUnloadingForcedFinalize(); diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs b/src/coreclr/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs index de8137f..a7bf871 100644 --- a/src/coreclr/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs +++ b/src/coreclr/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs @@ -71,15 +71,9 @@ namespace System.Runtime.Loader [SuppressUnmanagedCodeSecurity] private static extern void LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, string ilPath, string niPath, ObjectHandleOnStack retAssembly); - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - private static extern void GetLoadedAssembliesInternal(ObjectHandleOnStack assemblies); - public static Assembly[] GetLoadedAssemblies() { - Assembly[] assemblies = null; - GetLoadedAssembliesInternal(JitHelpers.GetObjectHandleOnStack(ref assemblies)); - return assemblies; + return AppDomain.CurrentDomain.GetAssemblies(false); } // These are helpers that can be used by AssemblyLoadContext derivations. diff --git a/src/coreclr/src/vm/assemblynative.cpp b/src/coreclr/src/vm/assemblynative.cpp index b9079ec..702c255 100644 --- a/src/coreclr/src/vm/assemblynative.cpp +++ b/src/coreclr/src/vm/assemblynative.cpp @@ -536,42 +536,6 @@ Assembly* AssemblyNative::LoadFromPEImage(ICLRPrivBinder* pBinderContext, PEImag RETURN pLoadedAssembly; } -/* static */ -void QCALLTYPE AssemblyNative::GetLoadedAssembliesInternal(QCall::ObjectHandleOnStack assemblies) -{ - QCALL_CONTRACT; - - BEGIN_QCALL; - - MethodTable * pAssemblyClass = MscorlibBinder::GetClass(CLASS__ASSEMBLY); - - PTR_AppDomain pCurDomain = GetAppDomain(); - - SetSHash assemblySet; - pCurDomain->GetCacheAssemblyList(assemblySet); - size_t nArrayElems = assemblySet.GetCount(); - PTRARRAYREF AsmArray = NULL; - - GCX_COOP(); - - GCPROTECT_BEGIN(AsmArray); - AsmArray = (PTRARRAYREF) AllocateObjectArray( (DWORD)nArrayElems, pAssemblyClass); - for(auto it = assemblySet.Begin(); it != assemblySet.End(); it++) - { - PTR_DomainAssembly assem = *it; - OBJECTREF o = (OBJECTREF)assem->GetExposedAssemblyObject(); - _ASSERTE(o != NULL); - _ASSERTE(nArrayElems > 0); - AsmArray->SetAt(--nArrayElems, o); - } - - assemblies.Set(AsmArray); - - GCPROTECT_END(); - - END_QCALL; -} - /* static */ void QCALLTYPE AssemblyNative::LoadFromPath(INT_PTR ptrNativeAssemblyLoadContext, LPCWSTR pwzILPath, LPCWSTR pwzNIPath, QCall::ObjectHandleOnStack retLoadedAssembly) { diff --git a/src/coreclr/src/vm/assemblynative.hpp b/src/coreclr/src/vm/assemblynative.hpp index ece8100..514589f 100644 --- a/src/coreclr/src/vm/assemblynative.hpp +++ b/src/coreclr/src/vm/assemblynative.hpp @@ -208,7 +208,6 @@ public: 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); - static void QCALLTYPE GetLoadedAssembliesInternal(QCall::ObjectHandleOnStack assemblies); static INT_PTR QCALLTYPE InternalLoadUnmanagedDllFromPath(LPCWSTR unmanagedLibraryPath); static void QCALLTYPE LoadFromStream(INT_PTR ptrNativeAssemblyLoadContext, INT_PTR ptrAssemblyArray, INT32 cbAssemblyArrayLength, INT_PTR ptrSymbolArray, INT32 cbSymbolArrayLength, QCall::ObjectHandleOnStack retLoadedAssembly); static Assembly* LoadFromPEImage(ICLRPrivBinder* pBinderContext, PEImage *pILImage, PEImage *pNIImage); diff --git a/src/coreclr/src/vm/ecalllist.h b/src/coreclr/src/vm/ecalllist.h index 5c3e5f8..f2784d1 100644 --- a/src/coreclr/src/vm/ecalllist.h +++ b/src/coreclr/src/vm/ecalllist.h @@ -519,6 +519,7 @@ FCFuncStart(gAppDomainFuncs) #if FEATURE_COMINTEROP FCFuncElement("nSetDisableInterfaceCache", AppDomainNative::SetDisableInterfaceCache) #endif // FEATURE_COMINTEROP + FCFuncElement("nGetAssemblies", AppDomainNative::GetAssemblies) FCFuncElement("nCreateContext", AppDomainNative::CreateContext) FCFuncElement("GetId", AppDomainNative::GetId) FCFuncElement("GetOrInternString", AppDomainNative::GetOrInternString) @@ -617,7 +618,6 @@ FCFuncEnd() FCFuncStart(gAssemblyLoadContextFuncs) QCFuncElement("InitializeAssemblyLoadContext", AssemblyNative::InitializeAssemblyLoadContext) QCFuncElement("LoadFromPath", AssemblyNative::LoadFromPath) - QCFuncElement("GetLoadedAssembliesInternal", AssemblyNative::GetLoadedAssembliesInternal) QCFuncElement("InternalLoadUnmanagedDllFromPath", AssemblyNative::InternalLoadUnmanagedDllFromPath) QCFuncElement("CanUseAppPathAssemblyLoadContextInCurrentDomain", AssemblyNative::CanUseAppPathAssemblyLoadContextInCurrentDomain) QCFuncElement("LoadFromStream", AssemblyNative::LoadFromStream)