From a325ae393b5a4ee710ef6eeeb4253517156e63c1 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 9 Sep 2024 15:01:50 -0700 Subject: [PATCH 1/2] Remove FCThrowRes from FCallIsDynamic --- .../src/System/Reflection/RuntimeAssembly.cs | 12 ++++++++++-- src/coreclr/vm/assemblynative.cpp | 16 ++++++++-------- src/coreclr/vm/assemblynative.hpp | 6 +----- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index 1ebaa04f8f681..c66b432642716 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@ -584,9 +584,17 @@ private CultureInfo GetLocale() } [MethodImpl(MethodImplOptions.InternalCall)] - private static extern bool FCallIsDynamic(RuntimeAssembly assembly); + private static extern bool FCallIsDynamic(IntPtr assembly); - public override bool IsDynamic => FCallIsDynamic(this); + public override bool IsDynamic + { + get + { + bool isDynamic = FCallIsDynamic(GetUnderlyingNativeHandle()); + GC.KeepAlive(this); // We directly pass the native handle above - make sure this object stays alive for the call + return isDynamic; + } + } [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "AssemblyNative_GetSimpleName")] private static partial void GetSimpleName(QCallAssembly assembly, StringHandleOnStack retSimpleName); diff --git a/src/coreclr/vm/assemblynative.cpp b/src/coreclr/vm/assemblynative.cpp index 02ba71a51c323..cb9cc53cc12d0 100644 --- a/src/coreclr/vm/assemblynative.cpp +++ b/src/coreclr/vm/assemblynative.cpp @@ -513,16 +513,16 @@ extern "C" void QCALLTYPE AssemblyNative_GetForwardedType(QCall::AssemblyHandle END_QCALL; } -FCIMPL1(FC_BOOL_RET, AssemblyNative::IsDynamic, AssemblyBaseObject* pAssemblyUNSAFE) +FCIMPL1(FC_BOOL_RET, AssemblyNative::IsDynamic, Assembly* pAssembly) { - FCALL_CONTRACT; - - ASSEMBLYREF refAssembly = (ASSEMBLYREF)ObjectToOBJECTREF(pAssemblyUNSAFE); - - if (refAssembly == NULL) - FCThrowRes(kArgumentNullException, W("Arg_InvalidHandle")); + CONTRACTL + { + FCALL_CHECK; + PRECONDITION(CheckPointer(pAssembly)); + } + CONTRACTL_END; - FC_RETURN_BOOL(refAssembly->GetAssembly()->GetPEAssembly()->IsReflectionEmit()); + FC_RETURN_BOOL(pAssembly->GetPEAssembly()->IsReflectionEmit()); } FCIMPLEND diff --git a/src/coreclr/vm/assemblynative.hpp b/src/coreclr/vm/assemblynative.hpp index 80ae3da8c2bd5..2e2715e69d76a 100644 --- a/src/coreclr/vm/assemblynative.hpp +++ b/src/coreclr/vm/assemblynative.hpp @@ -19,10 +19,6 @@ class CustomAssemblyBinder; class AssemblyNative { - friend class Assembly; - friend class BaseDomain; - friend class DomainAssembly; - public: static Assembly* LoadFromPEImage(AssemblyBinder* pBinder, PEImage *pImage, bool excludeAppPaths = false); @@ -35,7 +31,7 @@ class AssemblyNative // static - FCDECL1(FC_BOOL_RET, IsDynamic, AssemblyBaseObject * pAssemblyUNSAFE); + FCDECL1(FC_BOOL_RET, IsDynamic, Assembly* pAssembly); }; extern "C" uint32_t QCALLTYPE AssemblyNative_GetAssemblyCount(); From ec790a927e847b53453012f198aa7c4a2131d05b Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 9 Sep 2024 15:51:53 -0700 Subject: [PATCH 2/2] Rename FCallIsDynamic -> GetIsDynamic --- .../src/System/Reflection/RuntimeAssembly.cs | 4 ++-- src/coreclr/vm/assemblynative.cpp | 2 +- src/coreclr/vm/assemblynative.hpp | 2 +- src/coreclr/vm/ecalllist.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index c66b432642716..95bcf0652648a 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@ -584,13 +584,13 @@ private CultureInfo GetLocale() } [MethodImpl(MethodImplOptions.InternalCall)] - private static extern bool FCallIsDynamic(IntPtr assembly); + private static extern bool GetIsDynamic(IntPtr assembly); public override bool IsDynamic { get { - bool isDynamic = FCallIsDynamic(GetUnderlyingNativeHandle()); + bool isDynamic = GetIsDynamic(GetUnderlyingNativeHandle()); GC.KeepAlive(this); // We directly pass the native handle above - make sure this object stays alive for the call return isDynamic; } diff --git a/src/coreclr/vm/assemblynative.cpp b/src/coreclr/vm/assemblynative.cpp index cb9cc53cc12d0..cad3829428c15 100644 --- a/src/coreclr/vm/assemblynative.cpp +++ b/src/coreclr/vm/assemblynative.cpp @@ -513,7 +513,7 @@ extern "C" void QCALLTYPE AssemblyNative_GetForwardedType(QCall::AssemblyHandle END_QCALL; } -FCIMPL1(FC_BOOL_RET, AssemblyNative::IsDynamic, Assembly* pAssembly) +FCIMPL1(FC_BOOL_RET, AssemblyNative::GetIsDynamic, Assembly* pAssembly) { CONTRACTL { diff --git a/src/coreclr/vm/assemblynative.hpp b/src/coreclr/vm/assemblynative.hpp index 2e2715e69d76a..1ff73a406c70a 100644 --- a/src/coreclr/vm/assemblynative.hpp +++ b/src/coreclr/vm/assemblynative.hpp @@ -31,7 +31,7 @@ class AssemblyNative // static - FCDECL1(FC_BOOL_RET, IsDynamic, Assembly* pAssembly); + FCDECL1(FC_BOOL_RET, GetIsDynamic, Assembly* pAssembly); }; extern "C" uint32_t QCALLTYPE AssemblyNative_GetAssemblyCount(); diff --git a/src/coreclr/vm/ecalllist.h b/src/coreclr/vm/ecalllist.h index 48edcc4d04672..35bfdb14e00b4 100644 --- a/src/coreclr/vm/ecalllist.h +++ b/src/coreclr/vm/ecalllist.h @@ -222,7 +222,7 @@ FCFuncStart(gCOMModuleHandleFuncs) FCFuncEnd() FCFuncStart(gRuntimeAssemblyFuncs) - FCFuncElement("FCallIsDynamic", AssemblyNative::IsDynamic) + FCFuncElement("GetIsDynamic", AssemblyNative::GetIsDynamic) FCFuncElement("GetManifestModule", AssemblyHandle::GetManifestModule) FCFuncElement("GetToken", AssemblyHandle::GetToken) FCFuncEnd()