diff --git a/src/coreclr/System.Private.CoreLib/src/System/Environment.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Environment.CoreCLR.cs index 4b4fb747ca049d..8e4b9a58a0f038 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Environment.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Environment.CoreCLR.cs @@ -104,6 +104,20 @@ private static unsafe string[] InitializeCommandLineArgs(char* exePath, int argc return mainMethodArgs; } + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void InitializeCommandLineArgs(char* exePath, int argc, char** argv, string[]* pResult, Exception* pException) + { + try + { + *pResult = InitializeCommandLineArgs(exePath, argc, argv); + } + catch (Exception ex) + { + *pException = ex; + } + } + [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Environment_GetProcessorCount")] internal static partial int GetProcessorCount(); diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs index ab666d209b3abb..ad32d438c5121f 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs @@ -146,27 +146,49 @@ private static ProcessorArchitecture CalculateProcArch(PortableExecutableKinds p return ProcessorArchitecture.None; } + [UnmanagedCallersOnly] [RequiresUnsafe] - private static unsafe void ParseAsAssemblySpec(char* pAssemblyName, void* pAssemblySpec) + private static unsafe void ParseAsAssemblySpec(char* pAssemblyName, void* pAssemblySpec, Exception* pException) { - AssemblyNameParser.AssemblyNameParts parts = AssemblyNameParser.Parse(MemoryMarshal.CreateReadOnlySpanFromNullTerminated(pAssemblyName)); - - fixed (char* pName = parts._name) - fixed (char* pCultureName = parts._cultureName) - fixed (byte* pPublicKeyOrToken = parts._publicKeyOrToken) + try { - NativeAssemblyNameParts nameParts = default; + AssemblyNameParser.AssemblyNameParts parts = AssemblyNameParser.Parse(MemoryMarshal.CreateReadOnlySpanFromNullTerminated(pAssemblyName)); + + fixed (char* pName = parts._name) + fixed (char* pCultureName = parts._cultureName) + fixed (byte* pPublicKeyOrToken = parts._publicKeyOrToken) + { + NativeAssemblyNameParts nameParts = default; + + nameParts._flags = parts._flags; + nameParts._pName = pName; + nameParts._pCultureName = pCultureName; - nameParts._flags = parts._flags; - nameParts._pName = pName; - nameParts._pCultureName = pCultureName; + nameParts._pPublicKeyOrToken = pPublicKeyOrToken; + nameParts._cbPublicKeyOrToken = (parts._publicKeyOrToken != null) ? parts._publicKeyOrToken.Length : 0; - nameParts._pPublicKeyOrToken = pPublicKeyOrToken; - nameParts._cbPublicKeyOrToken = (parts._publicKeyOrToken != null) ? parts._publicKeyOrToken.Length : 0; + nameParts.SetVersion(parts._version, defaultValue: ushort.MaxValue); - nameParts.SetVersion(parts._version, defaultValue: ushort.MaxValue); + InitializeAssemblySpec(&nameParts, pAssemblySpec); + } + } + catch (Exception ex) + { + *pException = ex; + } + } - InitializeAssemblySpec(&nameParts, pAssemblySpec); + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void CreateAssemblyName(AssemblyName* pResult, NativeAssemblyNameParts* pParts, Exception* pException) + { + try + { + *pResult = new AssemblyName(pParts); + } + catch (Exception ex) + { + *pException = ex; } } diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/TypeNameResolver.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/TypeNameResolver.CoreCLR.cs index 118254da701297..02d99767439b05 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/TypeNameResolver.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/TypeNameResolver.CoreCLR.cs @@ -130,13 +130,19 @@ internal static RuntimeType GetTypeReferencedByCustomAttribute(string typeName, return type; } - // Used by VM + [UnmanagedCallersOnly] [RequiresUnsafe] - internal static unsafe RuntimeType? GetTypeHelper(char* pTypeName, RuntimeAssembly? requestingAssembly, - bool throwOnError, bool requireAssemblyQualifiedName, IntPtr unsafeAccessorMethod) + private static unsafe void GetTypeHelper(char* pTypeName, RuntimeAssembly* pRequestingAssembly, bool throwOnError, bool requireAssemblyQualifiedName, IntPtr unsafeAccessorMethod, RuntimeType* pResult, Exception* pException) { - ReadOnlySpan typeName = MemoryMarshal.CreateReadOnlySpanFromNullTerminated(pTypeName); - return GetTypeHelper(typeName, requestingAssembly, throwOnError, requireAssemblyQualifiedName, unsafeAccessorMethod); + try + { + ReadOnlySpan typeName = MemoryMarshal.CreateReadOnlySpanFromNullTerminated(pTypeName); + *pResult = GetTypeHelper(typeName, *pRequestingAssembly, throwOnError, requireAssemblyQualifiedName, unsafeAccessorMethod); + } + catch (Exception ex) + { + *pException = ex; + } } internal static RuntimeType? GetTypeHelper(ReadOnlySpan typeName, RuntimeAssembly? requestingAssembly, diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.CoreCLR.cs index cde042607e20d8..9fb2717ff094cf 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.CoreCLR.cs @@ -68,6 +68,21 @@ internal static int CallICustomQueryInterface(ManagedObjectWrapperHolder holder, return -1; // See TryInvokeICustomQueryInterfaceResult } + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe int CallICustomQueryInterface(ManagedObjectWrapperHolder* pHolder, Guid* pIid, IntPtr* ppObject, Exception* pException) + { + try + { + return CallICustomQueryInterface(*pHolder, ref *pIid, out *ppObject); + } + catch (Exception ex) + { + *pException = ex; + return default; + } + } + internal static IntPtr GetOrCreateComInterfaceForObjectWithGlobalMarshallingInstance(object obj) { if (s_globalInstanceForMarshalling == null) @@ -87,6 +102,20 @@ internal static IntPtr GetOrCreateComInterfaceForObjectWithGlobalMarshallingInst } } + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void GetOrCreateComInterfaceForObjectWithGlobalMarshallingInstance(object* pObj, IntPtr* pResult, Exception* pException) + { + try + { + *pResult = GetOrCreateComInterfaceForObjectWithGlobalMarshallingInstance(*pObj); + } + catch (Exception ex) + { + *pException = ex; + } + } + internal static object? GetOrCreateObjectForComInstanceWithGlobalMarshallingInstance(IntPtr comObject, CreateObjectFlags flags) { if (s_globalInstanceForMarshalling == null) @@ -106,6 +135,20 @@ internal static IntPtr GetOrCreateComInterfaceForObjectWithGlobalMarshallingInst } } + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void GetOrCreateObjectForComInstanceWithGlobalMarshallingInstance(IntPtr comObject, int flags, object* pResult, Exception* pException) + { + try + { + *pResult = GetOrCreateObjectForComInstanceWithGlobalMarshallingInstance(comObject, (CreateObjectFlags)flags); + } + catch (Exception ex) + { + *pException = ex; + } + } + [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ComWrappers_GetIReferenceTrackerTargetVftbl")] [SuppressGCTransition] private static partial IntPtr GetDefaultIReferenceTrackerTargetVftbl(); diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumeratorToEnumVariantMarshaler.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumeratorToEnumVariantMarshaler.cs index 05d1d8108042e5..dfef80658e0b61 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumeratorToEnumVariantMarshaler.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumeratorToEnumVariantMarshaler.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections; +using System.Diagnostics.CodeAnalysis; using System.Runtime.Versioning; using ComTypes = System.Runtime.InteropServices.ComTypes; @@ -47,8 +48,19 @@ public IntPtr MarshalManagedToNative(object ManagedObj) return Marshal.GetComInterfaceForObject(nativeView); } - internal static object InternalMarshalNativeToManaged(IntPtr pNativeData) - => GetInstance(null).MarshalNativeToManaged(pNativeData); + [System.Runtime.InteropServices.UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void InternalMarshalNativeToManaged(IntPtr pNativeData, object* pResult, Exception* pException) + { + try + { + *pResult = GetInstance(null).MarshalNativeToManaged(pNativeData); + } + catch (Exception ex) + { + *pException = ex; + } + } public object MarshalNativeToManaged(IntPtr pNativeData) { diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/DynamicInterfaceCastableHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/DynamicInterfaceCastableHelpers.cs index 260534b1ce799a..613767c1c6c9b5 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/DynamicInterfaceCastableHelpers.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/DynamicInterfaceCastableHelpers.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Runtime.InteropServices { @@ -22,6 +23,20 @@ internal static bool IsInterfaceImplemented(IDynamicInterfaceCastable castable, return isImplemented; } + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void IsInterfaceImplemented(IDynamicInterfaceCastable* pCastable, RuntimeType* pInterfaceType, bool throwIfNotImplemented, bool* pResult, Exception* pException) + { + try + { + *pResult = IsInterfaceImplemented(*pCastable, *pInterfaceType, throwIfNotImplemented); + } + catch (Exception ex) + { + *pException = ex; + } + } + [StackTraceHidden] internal static RuntimeType? GetInterfaceImplementation(IDynamicInterfaceCastable castable, RuntimeType interfaceType) { @@ -41,5 +56,19 @@ internal static bool IsInterfaceImplemented(IDynamicInterfaceCastable castable, return implType; } + + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void GetInterfaceImplementation(IDynamicInterfaceCastable* pCastable, RuntimeType* pInterfaceType, RuntimeType* pResult, Exception* pException) + { + try + { + *pResult = GetInterfaceImplementation(*pCastable, *pInterfaceType); + } + catch (Exception ex) + { + *pException = ex; + } + } } } diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.CoreCLR.cs index 75d0bf2c2c5b63..ee7c61c672120a 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.CoreCLR.cs @@ -3,6 +3,7 @@ using System.Reflection; using System.Runtime.CompilerServices; +using System.Diagnostics.CodeAnalysis; namespace System.Runtime.InteropServices { @@ -24,5 +25,20 @@ internal static IntPtr LoadLibraryByName(string libraryName, Assembly assembly, internal static partial IntPtr LoadByName(string libraryName, QCallAssembly callingAssembly, [MarshalAs(UnmanagedType.Bool)] bool hasDllImportSearchPathFlag, uint dllImportSearchPathFlag, [MarshalAs(UnmanagedType.Bool)] bool throwOnError); + + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe IntPtr LoadLibraryCallbackStub(char* pLibraryName, Assembly* pAssembly, bool hasDllImportSearchPathFlags, uint dllImportSearchPathFlags, Exception* pException) + { + try + { + return LoadLibraryCallbackStub(new string(pLibraryName), *pAssembly, hasDllImportSearchPathFlags, dllImportSearchPathFlags); + } + catch (Exception ex) + { + *pException = ex; + return default; + } + } } } diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs index 5334448667167e..867f42389cbd4b 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs @@ -110,18 +110,38 @@ internal Assembly LoadFromInMemoryModule(IntPtr moduleHandle) // This method is invoked by the VM when using the host-provided assembly load context // implementation. - private static IntPtr ResolveUnmanagedDll(string unmanagedDllName, IntPtr gchAssemblyLoadContext) + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe IntPtr ResolveUnmanagedDll(char* pUnmanagedDllName, IntPtr gchAssemblyLoadContext, Exception* pException) { - AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchAssemblyLoadContext).Target)!; - return context.LoadUnmanagedDll(unmanagedDllName); + try + { + AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchAssemblyLoadContext).Target)!; + return context.LoadUnmanagedDll(new string(pUnmanagedDllName)); + } + catch (Exception ex) + { + *pException = ex; + return default; + } } // This method is invoked by the VM to resolve a native library using the ResolvingUnmanagedDll event // after trying all other means of resolution. - private static IntPtr ResolveUnmanagedDllUsingEvent(string unmanagedDllName, Assembly assembly, IntPtr gchAssemblyLoadContext) + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe IntPtr ResolveUnmanagedDllUsingEvent(char* pUnmanagedDllName, Assembly* pAssembly, IntPtr gchAssemblyLoadContext, Exception* pException) { - AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchAssemblyLoadContext).Target)!; - return context.GetResolvedUnmanagedDll(assembly, unmanagedDllName); + try + { + AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchAssemblyLoadContext).Target)!; + return context.GetResolvedUnmanagedDll(*pAssembly, new string(pUnmanagedDllName)); + } + catch (Exception ex) + { + *pException = ex; + return default; + } } [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "AssemblyNative_GetLoadContextForAssembly")] @@ -182,30 +202,57 @@ public void StartProfileOptimization(string? profile) /// /// Called by the runtime to start an assembly load activity for tracing /// - private static void StartAssemblyLoad(ref Guid activityId, ref Guid relatedActivityId) + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void StartAssemblyLoad(Guid* activityId, Guid* relatedActivityId, Exception* pException) { - // Make sure ActivityTracker is enabled - ActivityTracker.Instance.Enable(); + try + { + // Make sure ActivityTracker is enabled + ActivityTracker.Instance.Enable(); - // Don't use trace to TPL event source in ActivityTracker - that event source is a singleton and its instantiation may have triggered the load. - ActivityTracker.Instance.OnStart(NativeRuntimeEventSource.Log.Name, AssemblyLoadName, 0, ref activityId, ref relatedActivityId, EventActivityOptions.Recursive, useTplSource: false); + // Don't use trace to TPL event source in ActivityTracker - that event source is a singleton and its instantiation may have triggered the load. + ActivityTracker.Instance.OnStart(NativeRuntimeEventSource.Log.Name, AssemblyLoadName, 0, ref *activityId, ref *relatedActivityId, EventActivityOptions.Recursive, useTplSource: false); + } + catch (Exception ex) + { + *pException = ex; + } } /// /// Called by the runtime to stop an assembly load activity for tracing /// - private static void StopAssemblyLoad(ref Guid activityId) + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void StopAssemblyLoad(Guid* activityId, Exception* pException) { - // Don't use trace to TPL event source in ActivityTracker - that event source is a singleton and its instantiation may have triggered the load. - ActivityTracker.Instance.OnStop(NativeRuntimeEventSource.Log.Name, AssemblyLoadName, 0, ref activityId, useTplSource: false); + try + { + // Don't use trace to TPL event source in ActivityTracker - that event source is a singleton and its instantiation may have triggered the load. + ActivityTracker.Instance.OnStop(NativeRuntimeEventSource.Log.Name, AssemblyLoadName, 0, ref *activityId, useTplSource: false); + } + catch (Exception ex) + { + *pException = ex; + } } /// /// Called by the runtime to make sure the default ALC is initialized /// - private static void InitializeDefaultContext() + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void InitializeDefaultContext(Exception* pException) { - _ = Default; + try + { + _ = Default; + } + catch (Exception ex) + { + *pException = ex; + } } } } diff --git a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs index 042a34158eaa9b..673390f94d9cb9 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs @@ -319,6 +319,21 @@ internal static unsafe IntPtr ConvertToNative(string strManaged, IntPtr pNativeB } } + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe IntPtr ConvertToNative(string* pStr, Exception* pException) + { + try + { + return ConvertToNative(*pStr, IntPtr.Zero); + } + catch (Exception ex) + { + *pException = ex; + return default; + } + } + internal static unsafe string? ConvertToManaged(IntPtr bstr) { if (IntPtr.Zero == bstr) @@ -362,6 +377,19 @@ internal static unsafe IntPtr ConvertToNative(string strManaged, IntPtr pNativeB } } + [UnmanagedCallersOnly] + private static unsafe void ConvertToManaged(IntPtr bstr, string* pResult, Exception* pException) + { + try + { + *pResult = ConvertToManaged(bstr); + } + catch (Exception ex) + { + *pException = ex; + } + } + internal static void ClearNative(IntPtr pNative) { Marshal.FreeBSTR(pNative); diff --git a/src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs index dc0bab6e328107..2aba01144ce94a 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs @@ -124,7 +124,7 @@ private void StartCallback() // When this thread is about to exit, inform any subsystems that need to know. // For external threads that have been attached to the runtime, we'll call this // after the thread has been detached as it won't come through this path. - OnThreadExiting(); + OnThreadExited(); } // Max iterations to be done in SpinWait without switching GC modes. @@ -569,7 +569,7 @@ WaitSubsystem.ThreadWaitInfo AllocateWaitInfo() } #endif - private void OnThreadExiting() + private void OnThreadExited() { // Consider this managed thread as dead. // The unmanaged thread is still alive, but will die soon, after cleaning up some state. @@ -585,6 +585,20 @@ private void OnThreadExiting() #endif } + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void OnThreadExited(Thread* pThread, Exception* pException) + { + try + { + pThread->OnThreadExited(); + } + catch (Exception ex) + { + *pException = ex; + } + } + [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ThreadNative_ReentrantWaitAny")] [RequiresUnsafe] internal static unsafe partial int ReentrantWaitAny([MarshalAs(UnmanagedType.Bool)] bool alertable, int timeout, int count, IntPtr* handles); diff --git a/src/coreclr/System.Private.CoreLib/src/System/__ComObject.cs b/src/coreclr/System.Private.CoreLib/src/System/__ComObject.cs index 5ef7080d53b1bf..a8c640551faf0e 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/__ComObject.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/__ComObject.cs @@ -109,6 +109,20 @@ internal void ReleaseAllData() } } + [UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void ReleaseAllData(__ComObject* pComObject, Exception* pException) + { + try + { + pComObject->ReleaseAllData(); + } + catch (Exception ex) + { + *pException = ex; + } + } + /// /// Called from within the EE and is used to handle calls on methods of event interfaces. /// @@ -128,6 +142,7 @@ internal object GetEventProvider( [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2062:Value passed to parameter cannot be statically determined", Justification = "The runtime passes a RuntimeType describing the COM event provider. The dynamic constructor access requirements are enforced by runtime callsite semantics.")] [UnmanagedCallersOnly] + [RequiresUnsafe] private static unsafe void GetEventProvider(__ComObject* pComObject, RuntimeType* pProviderType, object* pResult, Exception* pException) { try diff --git a/src/coreclr/binder/activitytracker.cpp b/src/coreclr/binder/activitytracker.cpp index b7287d3afa9180..f3b59e5056016e 100644 --- a/src/coreclr/binder/activitytracker.cpp +++ b/src/coreclr/binder/activitytracker.cpp @@ -20,12 +20,8 @@ void ActivityTracker::Start(/*out*/ GUID *activityId, /*out*/ GUID *relatedActiv OVERRIDE_TYPE_LOAD_LEVEL_LIMIT(CLASS_LOADED); - PREPARE_NONVIRTUAL_CALLSITE(METHOD__ASSEMBLYLOADCONTEXT__START_ASSEMBLY_LOAD); - DECLARE_ARGHOLDER_ARRAY(args, 2); - args[ARGNUM_0] = PTR_TO_ARGHOLDER(activityId); - args[ARGNUM_1] = PTR_TO_ARGHOLDER(relatedActivityId); - - CALL_MANAGED_METHOD_NORET(args) + UnmanagedCallersOnlyCaller startAssemblyLoad(METHOD__ASSEMBLYLOADCONTEXT__START_ASSEMBLY_LOAD); + startAssemblyLoad.InvokeThrowing(activityId, relatedActivityId); } void ActivityTracker::Stop(/*out*/ GUID *activityId) @@ -34,9 +30,6 @@ void ActivityTracker::Stop(/*out*/ GUID *activityId) OVERRIDE_TYPE_LOAD_LEVEL_LIMIT(CLASS_LOADED); - PREPARE_NONVIRTUAL_CALLSITE(METHOD__ASSEMBLYLOADCONTEXT__STOP_ASSEMBLY_LOAD); - DECLARE_ARGHOLDER_ARRAY(args, 1); - args[ARGNUM_0] = PTR_TO_ARGHOLDER(activityId); - - CALL_MANAGED_METHOD_NORET(args) + UnmanagedCallersOnlyCaller stopAssemblyLoad(METHOD__ASSEMBLYLOADCONTEXT__STOP_ASSEMBLY_LOAD); + stopAssemblyLoad.InvokeThrowing(activityId); } diff --git a/src/coreclr/binder/defaultassemblybinder.cpp b/src/coreclr/binder/defaultassemblybinder.cpp index 9900da40a7d263..730618d0a43dfa 100644 --- a/src/coreclr/binder/defaultassemblybinder.cpp +++ b/src/coreclr/binder/defaultassemblybinder.cpp @@ -73,9 +73,8 @@ HRESULT DefaultAssemblyBinder::BindUsingAssemblyName(BINDER_SPACE::AssemblyName { // Make sure the managed default ALC is initialized. GCX_COOP(); - PREPARE_NONVIRTUAL_CALLSITE(METHOD__ASSEMBLYLOADCONTEXT__INITIALIZE_DEFAULT_CONTEXT); - DECLARE_ARGHOLDER_ARRAY(args, 0); - CALL_MANAGED_METHOD_NORET(args) + UnmanagedCallersOnlyCaller initializeDefaultContext(METHOD__ASSEMBLYLOADCONTEXT__INITIALIZE_DEFAULT_CONTEXT); + initializeDefaultContext.InvokeThrowing(); pAssemblyLoadContext = GetAssemblyLoadContext(); _ASSERTE(pAssemblyLoadContext != (INT_PTR)NULL); diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index 4b519cb48aa8e9..5ffe69065668b3 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -4093,9 +4093,6 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pAssemblyLoadContextToBindWith bool fResolvedAssembly = false; BinderTracing::ResolutionAttemptedOperation tracer{pAssemblyName, 0 /*binderID*/, pAssemblyLoadContextToBindWithin, hr}; - // Allocate an AssemblyName managed object - _gcRefs.oRefAssemblyName = (ASSEMBLYNAMEREF) AllocateObject(CoreLibBinder::GetClass(CLASS__ASSEMBLY_NAME)); - // Initialize the AssemblyName object AssemblySpec::InitializeAssemblyNameRef(pAssemblyName, &_gcRefs.oRefAssemblyName); diff --git a/src/coreclr/vm/assemblynative.cpp b/src/coreclr/vm/assemblynative.cpp index 383918fcc91965..ce938e9549ff38 100644 --- a/src/coreclr/vm/assemblynative.cpp +++ b/src/coreclr/vm/assemblynative.cpp @@ -1062,7 +1062,7 @@ extern "C" void QCALLTYPE AssemblyNative_GetReferencedAssemblies(QCall::Assembly AssemblySpec spec; spec.InitializeSpec(mdAssemblyRef, pImport); - gc.pObj = (ASSEMBLYNAMEREF) AllocateObject(pAsmNameClass); + gc.pObj = NULL; spec.AssemblyNameInit(&gc.pObj); gc.ItemArray->SetAt(i, (OBJECTREF) gc.pObj); diff --git a/src/coreclr/vm/assemblyspec.cpp b/src/coreclr/vm/assemblyspec.cpp index 4650b95691e0f2..eec10de149a933 100644 --- a/src/coreclr/vm/assemblyspec.cpp +++ b/src/coreclr/vm/assemblyspec.cpp @@ -246,11 +246,8 @@ void AssemblySpec::AssemblyNameInit(ASSEMBLYNAMEREF* pAsmName) OVERRIDE_TYPE_LOAD_LEVEL_LIMIT(CLASS_LOADED); - PREPARE_NONVIRTUAL_CALLSITE(METHOD__ASSEMBLY_NAME__CTOR); - DECLARE_ARGHOLDER_ARRAY(args, 2); - args[ARGNUM_0] = OBJECTREF_TO_ARGHOLDER(*pAsmName); - args[ARGNUM_1] = PTR_TO_ARGHOLDER(&nameParts); - CALL_MANAGED_METHOD_NORET(args); + UnmanagedCallersOnlyCaller createAssemblyName(METHOD__ASSEMBLY_NAME__CREATE_ASSEMBLY_SPEC); + createAssemblyName.InvokeThrowing(pAsmName, &nameParts); } /* static */ diff --git a/src/coreclr/vm/comsynchronizable.cpp b/src/coreclr/vm/comsynchronizable.cpp index 6a99fa6cee2a95..64b4a288db7964 100644 --- a/src/coreclr/vm/comsynchronizable.cpp +++ b/src/coreclr/vm/comsynchronizable.cpp @@ -130,11 +130,15 @@ static void KickOffThread_Worker(LPVOID ptr) } CONTRACTL_END; + OBJECTREF exposedObj = GetThread()->GetExposedObjectRaw(); + GCPROTECT_BEGIN(exposedObj); + PREPARE_NONVIRTUAL_CALLSITE(METHOD__THREAD__START_CALLBACK); DECLARE_ARGHOLDER_ARRAY(args, 1); - args[ARGNUM_0] = OBJECTREF_TO_ARGHOLDER(GetThread()->GetExposedObjectRaw()); - + args[ARGNUM_0] = OBJECTREF_TO_ARGHOLDER(exposedObj); CALL_MANAGED_METHOD_NORET(args); + + GCPROTECT_END(); } // When an exposed thread is started by Win32, this is where it starts. diff --git a/src/coreclr/vm/coreassemblyspec.cpp b/src/coreclr/vm/coreassemblyspec.cpp index 58a5d1ab56789a..8e98f6729088e3 100644 --- a/src/coreclr/vm/coreassemblyspec.cpp +++ b/src/coreclr/vm/coreassemblyspec.cpp @@ -159,11 +159,8 @@ void BaseAssemblySpec::Init(SString& assemblyDisplayName) OVERRIDE_TYPE_LOAD_LEVEL_LIMIT(CLASS_LOADED); - PREPARE_NONVIRTUAL_CALLSITE(METHOD__ASSEMBLY_NAME__PARSE_AS_ASSEMBLYSPEC); - DECLARE_ARGHOLDER_ARRAY(args, 2); - args[ARGNUM_0] = PTR_TO_ARGHOLDER(pAssemblyDisplayName); - args[ARGNUM_1] = PTR_TO_ARGHOLDER(this); - CALL_MANAGED_METHOD_NORET(args); + UnmanagedCallersOnlyCaller parseAsAssemblySpec(METHOD__ASSEMBLY_NAME__PARSE_AS_ASSEMBLYSPEC); + parseAsAssemblySpec.InvokeThrowing(pAssemblyDisplayName, (void*)this); } extern "C" void QCALLTYPE AssemblyName_InitializeAssemblySpec(NativeAssemblyNameParts* pAssemblyNameParts, BaseAssemblySpec* pAssemblySpec) diff --git a/src/coreclr/vm/corelib.h b/src/coreclr/vm/corelib.h index 3d58d3bf98c82d..da160cf5412f26 100644 --- a/src/coreclr/vm/corelib.h +++ b/src/coreclr/vm/corelib.h @@ -117,8 +117,8 @@ DEFINE_FIELD(ARRAY_WITH_OFFSET, M_OFFSET, m_offset) DEFINE_FIELD(ARRAY_WITH_OFFSET, M_COUNT, m_count) DEFINE_CLASS(ASSEMBLY_NAME, Reflection, AssemblyName) -DEFINE_METHOD(ASSEMBLY_NAME, CTOR, .ctor, IM_PtrNativeAssemblyNameParts) -DEFINE_METHOD(ASSEMBLY_NAME, PARSE_AS_ASSEMBLYSPEC, ParseAsAssemblySpec, SM_PtrCharPtrVoid) +DEFINE_METHOD(ASSEMBLY_NAME, CREATE_ASSEMBLY_SPEC, CreateAssemblyName, SM_PtrAssemblyName_PtrNativeAssemblyNameParts_PtrException_RetVoid) +DEFINE_METHOD(ASSEMBLY_NAME, PARSE_AS_ASSEMBLYSPEC, ParseAsAssemblySpec, SM_PtrChar_PtrVoid_PtrException_RetVoid) DEFINE_CLASS(NATIVE_ASSEMBLY_NAME_PARTS, Reflection, NativeAssemblyNameParts) // ASSEMBLYBASE is System.ReflectionAssembly while ASSEMBLY is System.Reflection.RuntimeAssembly @@ -178,7 +178,7 @@ BEGIN_ILLINK_FEATURE_SWITCH(System.Runtime.InteropServices.BuiltInComInterop.IsS DEFINE_CLASS_U(System, __ComObject, ComObject) DEFINE_FIELD_U(m_ObjectToDataMap, ComObject, m_ObjectToDataMap) DEFINE_CLASS(COM_OBJECT, System, __ComObject) -DEFINE_METHOD(COM_OBJECT, RELEASE_ALL_DATA, ReleaseAllData, IM_RetVoid) +DEFINE_METHOD(COM_OBJECT, RELEASE_ALL_DATA, ReleaseAllData, SM_PtrComObject_PtrException_RetVoid) DEFINE_METHOD(COM_OBJECT, GET_EVENT_PROVIDER, GetEventProvider, SM_PtrComObject_PtrClass_PtrObj_PtrException_RetVoid) #ifdef FOR_ILLINK DEFINE_METHOD(COM_OBJECT, CTOR, .ctor, IM_RetVoid) @@ -278,7 +278,7 @@ DEFINE_CLASS(ENUM, System, Enum) DEFINE_CLASS(ENVIRONMENT, System, Environment) DEFINE_METHOD(ENVIRONMENT, GET_RESOURCE_STRING, GetResourceString, SM_PtrChar_PtrStr_PtrException_RetVoid) -DEFINE_METHOD(ENVIRONMENT, INITIALIZE_COMMAND_LINE_ARGS, InitializeCommandLineArgs, SM_PtrChar_Int_PtrPtrChar_RetArrStr) +DEFINE_METHOD(ENVIRONMENT, INITIALIZE_COMMAND_LINE_ARGS, InitializeCommandLineArgs, SM_PtrChar_Int_PtrPtrChar_PtrArrStr_PtrException_RetVoid) DEFINE_CLASS(EVENT, Reflection, RuntimeEventInfo) @@ -350,7 +350,7 @@ DEFINE_FIELD(RT_TYPE_HANDLE, M_TYPE, m_type) DEFINE_METHOD(TYPED_REFERENCE, GETREFANY, GetRefAny, NoSig) DEFINE_CLASS(TYPE_NAME_RESOLVER, Reflection, TypeNameResolver) -DEFINE_METHOD(TYPE_NAME_RESOLVER, GET_TYPE_HELPER, GetTypeHelper, SM_Type_CharPtr_RuntimeAssembly_Bool_Bool_IntPtr_RetRuntimeType) +DEFINE_METHOD(TYPE_NAME_RESOLVER, GET_TYPE_HELPER, GetTypeHelper, SM_PtrChar_PtrAssembly_CLR_BOOL_CLR_BOOL_IntPtr_PtrClass_PtrException_RetVoid) DEFINE_CLASS_U(Reflection, RtFieldInfo, NoClass) DEFINE_FIELD_U(m_fieldHandle, ReflectFieldObject, m_pFD) @@ -402,8 +402,8 @@ DEFINE_CLASS(ICUSTOMADAPTER, Interop, ICustomAdapter) DEFINE_CLASS(IDYNAMICINTERFACECASTABLE, Interop, IDynamicInterfaceCastable) DEFINE_CLASS(DYNAMICINTERFACECASTABLEHELPERS, Interop, DynamicInterfaceCastableHelpers) -DEFINE_METHOD(DYNAMICINTERFACECASTABLEHELPERS, IS_INTERFACE_IMPLEMENTED, IsInterfaceImplemented, SM_IDynamicInterfaceCastable_RuntimeType_Bool_RetBool) -DEFINE_METHOD(DYNAMICINTERFACECASTABLEHELPERS, GET_INTERFACE_IMPLEMENTATION, GetInterfaceImplementation, SM_IDynamicInterfaceCastable_RuntimeType_RetRtType) +DEFINE_METHOD(DYNAMICINTERFACECASTABLEHELPERS, IS_INTERFACE_IMPLEMENTED, IsInterfaceImplemented, SM_PtrIDynamicInterfaceCastable_PtrClass_CLR_BOOL_PtrCLR_BOOL_PtrException_RetVoid) +DEFINE_METHOD(DYNAMICINTERFACECASTABLEHELPERS, GET_INTERFACE_IMPLEMENTATION, GetInterfaceImplementation, SM_PtrIDynamicInterfaceCastable_PtrClass_PtrClass_PtrException_RetVoid) BEGIN_ILLINK_FEATURE_SWITCH(System.Runtime.InteropServices.BuiltInComInterop.IsSupported, true, true) #ifdef FEATURE_COMINTEROP @@ -412,7 +412,7 @@ DEFINE_METHOD(ICUSTOM_QUERYINTERFACE, GET_INTERFACE, GetInterface, DEFINE_CLASS(CUSTOMQUERYINTERFACERESULT, Interop, CustomQueryInterfaceResult) DEFINE_CLASS(ENUMERATORTOENUMVARIANTMARSHALER, CustomMarshalers, EnumeratorToEnumVariantMarshaler) -DEFINE_METHOD(ENUMERATORTOENUMVARIANTMARSHALER, INTERNALMARSHALNATIVETOMANAGED, InternalMarshalNativeToManaged, SM_IntPtr_RetObj) +DEFINE_METHOD(ENUMERATORTOENUMVARIANTMARSHALER, INTERNALMARSHALNATIVETOMANAGED, InternalMarshalNativeToManaged, SM_IntPtr_PtrObj_PtrException_RetVoid) #endif //FEATURE_COMINTEROP END_ILLINK_FEATURE_SWITCH() @@ -421,9 +421,9 @@ DEFINE_CLASS(COMWRAPPERS, Interop, ComWrappers) DEFINE_CLASS(CREATEOBJECTFLAGS, Interop, CreateObjectFlags) DEFINE_CLASS(MANAGED_OBJECT_WRAPPER_HOLDER,Interop, ComWrappers+ManagedObjectWrapperHolder) DEFINE_CLASS(NATIVE_OBJECT_WRAPPER, Interop, ComWrappers+NativeObjectWrapper) // cDAC depends on the exact namespace and name -DEFINE_METHOD(COMWRAPPERS, CALL_ICUSTOMQUERYINTERFACE, CallICustomQueryInterface, SM_ManagedObjectWrapperHolder_RefGuid_RefIntPtr_RetInt) -DEFINE_METHOD(COMWRAPPERS, GET_OR_CREATE_COM_INTERFACE_FOR_OBJECT_WITH_GLOBAL_MARSHALLING_INSTANCE, GetOrCreateComInterfaceForObjectWithGlobalMarshallingInstance, SM_Obj_RetIntPtr) -DEFINE_METHOD(COMWRAPPERS, GET_OR_CREATE_OBJECT_FOR_COM_INSTANCE_WITH_GLOBAL_MARSHALLING_INSTANCE, GetOrCreateObjectForComInstanceWithGlobalMarshallingInstance, SM_IntPtr_CreateObjectFlags_RetObj) +DEFINE_METHOD(COMWRAPPERS, CALL_ICUSTOMQUERYINTERFACE, CallICustomQueryInterface, SM_PtrManagedObjectWrapperHolder_PtrGuid_PtrIntPtr_PtrException_RetInt) +DEFINE_METHOD(COMWRAPPERS, GET_OR_CREATE_COM_INTERFACE_FOR_OBJECT_WITH_GLOBAL_MARSHALLING_INSTANCE, GetOrCreateComInterfaceForObjectWithGlobalMarshallingInstance, SM_PtrObj_PtrIntPtr_PtrException_RetVoid) +DEFINE_METHOD(COMWRAPPERS, GET_OR_CREATE_OBJECT_FOR_COM_INSTANCE_WITH_GLOBAL_MARSHALLING_INSTANCE, GetOrCreateObjectForComInstanceWithGlobalMarshallingInstance, SM_IntPtr_Int_PtrObj_PtrException_RetVoid) DEFINE_FIELD(COMWRAPPERS, NAITVE_OBJECT_WRAPPER_TABLE, s_nativeObjectWrapperTable) DEFINE_FIELD(COMWRAPPERS, ALL_MANAGED_OBJECT_WRAPPER_TABLE, s_allManagedObjectWrapperTable) @@ -494,7 +494,7 @@ DEFINE_METHOD(MARSHAL, DESTROY_STRUCTURE, DestroySt DEFINE_METHOD(MARSHAL, SIZEOF_TYPE, SizeOf, SM_Type_RetInt) DEFINE_CLASS(NATIVELIBRARY, Interop, NativeLibrary) -DEFINE_METHOD(NATIVELIBRARY, LOADLIBRARYCALLBACKSTUB, LoadLibraryCallbackStub, SM_Str_AssemblyBase_Bool_UInt_RetIntPtr) +DEFINE_METHOD(NATIVELIBRARY, LOADLIBRARYCALLBACKSTUB, LoadLibraryCallbackStub, SM_PtrChar_PtrAssemblyBase_CLR_BOOL_UInt_PtrException_RetIntPtr) DEFINE_CLASS(VECTOR64T, Intrinsics, Vector64`1) DEFINE_CLASS(VECTOR128T, Intrinsics, Vector128`1) @@ -629,7 +629,7 @@ DEFINE_FIELD(LOCK, OWNING_THREAD_ID, _owningThreadId) DEFINE_FIELD(LOCK, STATE, _state) DEFINE_FIELD(LOCK, RECURSION_COUNT, _recursionCount) DEFINE_METHOD(LOCK, CTOR, .ctor, IM_RetVoid) -DEFINE_METHOD(LOCK, INITIALIZE_FOR_MONITOR, InitializeForMonitor, NoSig) +DEFINE_METHOD(LOCK, INITIALIZE_FOR_MONITOR, InitializeForMonitor, SM_PtrLock_Int_UInt_PtrException_RetVoid) DEFINE_CLASS(CONDITION, Threading, Condition) DEFINE_FIELD(CONDITION, WAITERS_HEAD, _waitersHead) @@ -970,15 +970,15 @@ DEFINE_CLASS(DIRECTONTHREADLOCALDATA, Threading, Thread+DirectOnThreadLocalData) DEFINE_CLASS(THREAD, Threading, Thread) DEFINE_METHOD(THREAD, START_CALLBACK, StartCallback, IM_RetVoid) DEFINE_METHOD(THREAD, POLLGC, PollGC, NoSig) -DEFINE_METHOD(THREAD, ON_THREAD_EXITING, OnThreadExiting, IM_RetVoid) +DEFINE_METHOD(THREAD, ON_THREAD_EXITING, OnThreadExited, SM_PtrThread_PtrException_RetVoid) #ifdef FOR_ILLINK DEFINE_METHOD(THREAD, CTOR, .ctor, IM_RetVoid) #endif // FOR_ILLINK #ifdef FEATURE_OBJCMARSHAL DEFINE_CLASS(AUTORELEASEPOOL, Threading, AutoreleasePool) -DEFINE_METHOD(AUTORELEASEPOOL, CREATEAUTORELEASEPOOL, CreateAutoreleasePool, SM_RetVoid) -DEFINE_METHOD(AUTORELEASEPOOL, DRAINAUTORELEASEPOOL, DrainAutoreleasePool, SM_RetVoid) +DEFINE_METHOD(AUTORELEASEPOOL, CREATEAUTORELEASEPOOL, CreateAutoreleasePool, SM_PtrException_RetVoid) +DEFINE_METHOD(AUTORELEASEPOOL, DRAINAUTORELEASEPOOL, DrainAutoreleasePool, SM_PtrException_RetVoid) #endif // FEATURE_OBJCMARSHAL DEFINE_CLASS(TYPE, System, Type) @@ -1002,8 +1002,8 @@ DEFINE_FIELD_U(_state, AssemblyLoadContextBaseObject, _stat DEFINE_FIELD_U(_isCollectible, AssemblyLoadContextBaseObject, _isCollectible) DEFINE_CLASS(ASSEMBLYLOADCONTEXT, Loader, AssemblyLoadContext) DEFINE_METHOD(ASSEMBLYLOADCONTEXT, RESOLVE, Resolve, SM_IntPtr_PtrAssemblyName_PtrAssemblyBase_PtrException_RetVoid) -DEFINE_METHOD(ASSEMBLYLOADCONTEXT, RESOLVEUNMANAGEDDLL, ResolveUnmanagedDll, SM_Str_IntPtr_RetIntPtr) -DEFINE_METHOD(ASSEMBLYLOADCONTEXT, RESOLVEUNMANAGEDDLLUSINGEVENT, ResolveUnmanagedDllUsingEvent, SM_Str_AssemblyBase_IntPtr_RetIntPtr) +DEFINE_METHOD(ASSEMBLYLOADCONTEXT, RESOLVEUNMANAGEDDLL, ResolveUnmanagedDll, SM_PtrChar_IntPtr_PtrException_RetIntPtr) +DEFINE_METHOD(ASSEMBLYLOADCONTEXT, RESOLVEUNMANAGEDDLLUSINGEVENT, ResolveUnmanagedDllUsingEvent, SM_PtrChar_PtrAssemblyBase_IntPtr_PtrException_RetIntPtr) DEFINE_METHOD(ASSEMBLYLOADCONTEXT, RESOLVEUSINGEVENT, ResolveUsingEvent, SM_IntPtr_PtrAssemblyName_PtrAssemblyBase_PtrException_RetVoid) DEFINE_METHOD(ASSEMBLYLOADCONTEXT, RESOLVESATELLITEASSEMBLY, ResolveSatelliteAssembly, SM_IntPtr_PtrAssemblyName_PtrAssemblyBase_PtrException_RetVoid) DEFINE_FIELD(ASSEMBLYLOADCONTEXT, ASSEMBLY_LOAD, AssemblyLoad) @@ -1011,9 +1011,9 @@ DEFINE_METHOD(ASSEMBLYLOADCONTEXT, ON_ASSEMBLY_LOAD, OnAssemblyLoad, DEFINE_METHOD(ASSEMBLYLOADCONTEXT, ON_RESOURCE_RESOLVE, OnResourceResolve, SM_PtrAssembly_PtrByte_PtrAssembly_PtrException_RetVoid) DEFINE_METHOD(ASSEMBLYLOADCONTEXT, ON_TYPE_RESOLVE, OnTypeResolve, SM_PtrAssembly_PtrByte_PtrAssembly_PtrException_RetVoid) DEFINE_METHOD(ASSEMBLYLOADCONTEXT, ON_ASSEMBLY_RESOLVE, OnAssemblyResolve, SM_PtrAssembly_PtrChar_PtrAssembly_PtrException_RetVoid) -DEFINE_METHOD(ASSEMBLYLOADCONTEXT, START_ASSEMBLY_LOAD, StartAssemblyLoad, SM_RefGuid_RefGuid_RetVoid) -DEFINE_METHOD(ASSEMBLYLOADCONTEXT, STOP_ASSEMBLY_LOAD, StopAssemblyLoad, SM_RefGuid_RetVoid) -DEFINE_METHOD(ASSEMBLYLOADCONTEXT, INITIALIZE_DEFAULT_CONTEXT, InitializeDefaultContext, SM_RetVoid) +DEFINE_METHOD(ASSEMBLYLOADCONTEXT, START_ASSEMBLY_LOAD, StartAssemblyLoad, SM_PtrGuid_PtrGuid_PtrException_RetVoid) +DEFINE_METHOD(ASSEMBLYLOADCONTEXT, STOP_ASSEMBLY_LOAD, StopAssemblyLoad, SM_PtrGuid_PtrException_RetVoid) +DEFINE_METHOD(ASSEMBLYLOADCONTEXT, INITIALIZE_DEFAULT_CONTEXT, InitializeDefaultContext, SM_PtrException_RetVoid) DEFINE_CLASS(VALUE_TYPE, System, ValueType) DEFINE_METHOD(VALUE_TYPE, GET_HASH_CODE, GetHashCode, IM_RetInt) @@ -1095,6 +1095,8 @@ DEFINE_METHOD(FIXEDWSTRMARSHALER, CONVERT_TO_MANAGED, ConvertToManaged, DEFINE_CLASS(BSTRMARSHALER, StubHelpers, BSTRMarshaler) DEFINE_METHOD(BSTRMARSHALER, CONVERT_TO_NATIVE, ConvertToNative, SM_Str_IntPtr_RetIntPtr) DEFINE_METHOD(BSTRMARSHALER, CONVERT_TO_MANAGED, ConvertToManaged, SM_IntPtr_RetStr) +DEFINE_METHOD(BSTRMARSHALER, CONVERT_TO_NATIVE_UCO, ConvertToNative, SM_PtrStr_PtrException_RetIntPtr) +DEFINE_METHOD(BSTRMARSHALER, CONVERT_TO_MANAGED_UCO, ConvertToManaged, SM_IntPtr_PtrStr_PtrException_RetVoid) DEFINE_METHOD(BSTRMARSHALER, CLEAR_NATIVE, ClearNative, SM_IntPtr_RetVoid) DEFINE_CLASS(ANSIBSTRMARSHALER, StubHelpers, AnsiBSTRMarshaler) diff --git a/src/coreclr/vm/corhost.cpp b/src/coreclr/vm/corhost.cpp index cf6ce72115a701..8a6eb65cede3ff 100644 --- a/src/coreclr/vm/corhost.cpp +++ b/src/coreclr/vm/corhost.cpp @@ -244,13 +244,11 @@ static PTRARRAYREF SetCommandLineArgs(PCWSTR pwzAssemblyPath, int argc, PCWSTR* PCWSTR exePath = Bundle::AppIsBundle() ? static_cast(Bundle::AppBundle->Path()) : pwzAssemblyPath; - PTRARRAYREF result; - PREPARE_NONVIRTUAL_CALLSITE(METHOD__ENVIRONMENT__INITIALIZE_COMMAND_LINE_ARGS); - DECLARE_ARGHOLDER_ARRAY(args, 3); - args[ARGNUM_0] = PTR_TO_ARGHOLDER(exePath); - args[ARGNUM_1] = DWORD_TO_ARGHOLDER(argc); - args[ARGNUM_2] = PTR_TO_ARGHOLDER(argv); - CALL_MANAGED_METHOD_RETREF(result, PTRARRAYREF, args); + PTRARRAYREF result = NULL; + GCPROTECT_BEGIN(result); + UnmanagedCallersOnlyCaller initializeCommandLineArgs(METHOD__ENVIRONMENT__INITIALIZE_COMMAND_LINE_ARGS); + initializeCommandLineArgs.InvokeThrowing(exePath, argc, argv, &result); + GCPROTECT_END(); return result; } diff --git a/src/coreclr/vm/dynamicinterfacecastable.cpp b/src/coreclr/vm/dynamicinterfacecastable.cpp index bf2bf5af00d015..b29797a2b81271 100644 --- a/src/coreclr/vm/dynamicinterfacecastable.cpp +++ b/src/coreclr/vm/dynamicinterfacecastable.cpp @@ -18,18 +18,18 @@ namespace POSTCONDITION(!throwIfNotImplemented || RETVAL); } CONTRACT_END; - PREPARE_NONVIRTUAL_CALLSITE(METHOD__DYNAMICINTERFACECASTABLEHELPERS__IS_INTERFACE_IMPLEMENTED); - - OBJECTREF managedType = interfaceTypeHandle.GetManagedClassObject(); // GC triggers - - DECLARE_ARGHOLDER_ARRAY(args, 3); - args[ARGNUM_0] = OBJECTREF_TO_ARGHOLDER(*objPROTECTED); - args[ARGNUM_1] = OBJECTREF_TO_ARGHOLDER(managedType); - args[ARGNUM_2] = BOOL_TO_ARGHOLDER(throwIfNotImplemented); - - BOOL isImplemented; - CALL_MANAGED_METHOD(isImplemented, CLR_BOOL, args); - INDEBUG(managedType = NULL); // managedType wasn't protected during the call + struct + { + OBJECTREF managedType; + } gc; + gc.managedType = NULL; + CLR_BOOL isImplemented = FALSE; + GCPROTECT_BEGIN(gc); + gc.managedType = interfaceTypeHandle.GetManagedClassObject(); // GC triggers + + UnmanagedCallersOnlyCaller isInterfaceImplemented(METHOD__DYNAMICINTERFACECASTABLEHELPERS__IS_INTERFACE_IMPLEMENTED); + isInterfaceImplemented.InvokeThrowing(objPROTECTED, &gc.managedType, CLR_BOOL_ARG(throwIfNotImplemented), &isImplemented); + GCPROTECT_END(); RETURN isImplemented; } @@ -45,19 +45,21 @@ namespace POSTCONDITION(RETVAL != NULL); } CONTRACT_END; - PREPARE_NONVIRTUAL_CALLSITE(METHOD__DYNAMICINTERFACECASTABLEHELPERS__GET_INTERFACE_IMPLEMENTATION); - - OBJECTREF managedType = interfaceTypeHandle.GetManagedClassObject(); // GC triggers - - DECLARE_ARGHOLDER_ARRAY(args, 2); - args[ARGNUM_0] = OBJECTREF_TO_ARGHOLDER(*objPROTECTED); - args[ARGNUM_1] = OBJECTREF_TO_ARGHOLDER(managedType); - - OBJECTREF implTypeRef; - CALL_MANAGED_METHOD_RETREF(implTypeRef, OBJECTREF, args); - INDEBUG(managedType = NULL); // managedType wasn't protected during the call - - RETURN implTypeRef; + struct + { + OBJECTREF managedType; + OBJECTREF result; + } gc; + gc.managedType = NULL; + gc.result = NULL; + GCPROTECT_BEGIN(gc); + gc.managedType = interfaceTypeHandle.GetManagedClassObject(); // GC triggers + + UnmanagedCallersOnlyCaller getInterfaceImplementation(METHOD__DYNAMICINTERFACECASTABLEHELPERS__GET_INTERFACE_IMPLEMENTATION); + getInterfaceImplementation.InvokeThrowing(objPROTECTED, &gc.managedType, &gc.result); + GCPROTECT_END(); + + RETURN gc.result; } } diff --git a/src/coreclr/vm/interoplibinterface_comwrappers.cpp b/src/coreclr/vm/interoplibinterface_comwrappers.cpp index 7b984171ff6715..857e4cd77bc18e 100644 --- a/src/coreclr/vm/interoplibinterface_comwrappers.cpp +++ b/src/coreclr/vm/interoplibinterface_comwrappers.cpp @@ -22,32 +22,6 @@ using CreateObjectFlags = InteropLib::Com::CreateObjectFlags; namespace { - int CallICustomQueryInterface( - _In_ OBJECTREF* implPROTECTED, - _In_ REFGUID iid, - _Outptr_result_maybenull_ void** ppObject) - { - CONTRACTL - { - THROWS; - MODE_COOPERATIVE; - PRECONDITION(implPROTECTED != NULL); - PRECONDITION(ppObject != NULL); - } - CONTRACTL_END; - - int result; - - PREPARE_NONVIRTUAL_CALLSITE(METHOD__COMWRAPPERS__CALL_ICUSTOMQUERYINTERFACE); - DECLARE_ARGHOLDER_ARRAY(args, 3); - args[ARGNUM_0] = OBJECTREF_TO_ARGHOLDER(*implPROTECTED); - args[ARGNUM_1] = PTR_TO_ARGHOLDER(&iid); - args[ARGNUM_2] = PTR_TO_ARGHOLDER(ppObject); - CALL_MANAGED_METHOD(result, int, args); - - return result; - } - BOOL g_isGlobalPeggingOn = TRUE; } @@ -95,14 +69,12 @@ bool GlobalComWrappersForMarshalling::TryGetOrCreateComInterfaceForObject( } CONTRACTL_END; - void* wrapper; + void* wrapper = nullptr; GCPROTECT_BEGIN(instance); - PREPARE_NONVIRTUAL_CALLSITE(METHOD__COMWRAPPERS__GET_OR_CREATE_COM_INTERFACE_FOR_OBJECT_WITH_GLOBAL_MARSHALLING_INSTANCE); - DECLARE_ARGHOLDER_ARRAY(args, 1); - args[ARGNUM_0] = OBJECTREF_TO_ARGHOLDER(instance); - CALL_MANAGED_METHOD(wrapper, void*, args); + UnmanagedCallersOnlyCaller getOrCreateComInterface(METHOD__COMWRAPPERS__GET_OR_CREATE_COM_INTERFACE_FOR_OBJECT_WITH_GLOBAL_MARSHALLING_INSTANCE); + getOrCreateComInterface.InvokeThrowing(&instance, &wrapper); GCPROTECT_END(); @@ -131,11 +103,8 @@ bool GlobalComWrappersForMarshalling::TryGetOrCreateObjectForComInstance( OBJECTREF obj = NULL; GCPROTECT_BEGIN(obj); - PREPARE_NONVIRTUAL_CALLSITE(METHOD__COMWRAPPERS__GET_OR_CREATE_OBJECT_FOR_COM_INSTANCE_WITH_GLOBAL_MARSHALLING_INSTANCE); - DECLARE_ARGHOLDER_ARRAY(args, 2); - args[ARGNUM_0] = PTR_TO_ARGHOLDER(externalComObject); - args[ARGNUM_1] = DWORD_TO_ARGHOLDER(flags); - CALL_MANAGED_METHOD_RETREF(obj, OBJECTREF, args); + UnmanagedCallersOnlyCaller getOrCreateObjectForComInstance(METHOD__COMWRAPPERS__GET_OR_CREATE_OBJECT_FOR_COM_INSTANCE_WITH_GLOBAL_MARSHALLING_INSTANCE); + getOrCreateObjectForComInstance.InvokeThrowing(externalComObject, flags, &obj); GCPROTECT_END(); @@ -378,7 +347,8 @@ namespace InteropLibImports ::OBJECTHANDLE objectHandle = static_cast<::OBJECTHANDLE>(handle); gc.objRef = ObjectFromHandle(objectHandle); - result = (TryInvokeICustomQueryInterfaceResult)CallICustomQueryInterface(&gc.objRef, iid, obj); + UnmanagedCallersOnlyCaller callICustomQueryInterface(METHOD__COMWRAPPERS__CALL_ICUSTOMQUERYINTERFACE); + result = (TryInvokeICustomQueryInterfaceResult)callICustomQueryInterface.InvokeThrowing_Ret(&gc.objRef, &iid, obj); GCPROTECT_END(); } diff --git a/src/coreclr/vm/interoputil.cpp b/src/coreclr/vm/interoputil.cpp index 204cca19abf0bc..3bd9c9ad7531b4 100644 --- a/src/coreclr/vm/interoputil.cpp +++ b/src/coreclr/vm/interoputil.cpp @@ -2984,12 +2984,11 @@ static OBJECTREF ConvertEnumVariantToMngEnum(IEnumVARIANT* pNativeEnum) } CONTRACTL_END; - OBJECTREF retObjRef; - - PREPARE_NONVIRTUAL_CALLSITE(METHOD__ENUMERATORTOENUMVARIANTMARSHALER__INTERNALMARSHALNATIVETOMANAGED); - DECLARE_ARGHOLDER_ARRAY(args, 1); - args[ARGNUM_0] = PTR_TO_ARGHOLDER(pNativeEnum); - CALL_MANAGED_METHOD_RETREF(retObjRef, OBJECTREF, args); + OBJECTREF retObjRef = NULL; + GCPROTECT_BEGIN(retObjRef); + UnmanagedCallersOnlyCaller internalMarshalNativeToManaged(METHOD__ENUMERATORTOENUMVARIANTMARSHALER__INTERNALMARSHALNATIVETOMANAGED); + internalMarshalNativeToManaged.InvokeThrowing((INT_PTR)pNativeEnum, &retObjRef); + GCPROTECT_END(); return retObjRef; } diff --git a/src/coreclr/vm/metasig.h b/src/coreclr/vm/metasig.h index 0ff156f0883adc..7e4c1e101c073b 100644 --- a/src/coreclr/vm/metasig.h +++ b/src/coreclr/vm/metasig.h @@ -446,6 +446,32 @@ DEFINE_METASIG_T(SM(PtrException_PtrException_RetVoid, P(C(EXCEPTION)) P(C(EXCEP DEFINE_METASIG_T(SM(PtrChar_PtrException_PtrObj_PtrException_RetVoid, P(u) P(C(EXCEPTION)) P(j) P(C(EXCEPTION)), v)) DEFINE_METASIG_T(SM(PtrChar_PtrStr_PtrException_RetVoid, P(u) P(s) P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(PtrGuid_PtrException_RetVoid, P(g(GUID)) P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(PtrGuid_PtrGuid_PtrException_RetVoid, P(g(GUID)) P(g(GUID)) P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(PtrLock_Int_UInt_PtrException_RetVoid, P(C(LOCK)) i K P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(PtrThread_PtrException_RetVoid, P(C(THREAD)) P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(PtrChar_PtrVoid_PtrException_RetVoid, P(u) P(v) P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(PtrAssemblyName_PtrNativeAssemblyNameParts_PtrException_RetVoid, P(C(ASSEMBLY_NAME)) P(g(NATIVE_ASSEMBLY_NAME_PARTS)) P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(PtrChar_Int_PtrPtrChar_PtrArrStr_PtrException_RetVoid, P(u) i P(P(u)) P(a(s)) P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(PtrIDynamicInterfaceCastable_PtrClass_CLR_BOOL_PtrCLR_BOOL_PtrException_RetVoid, P(C(IDYNAMICINTERFACECASTABLE)) P(C(CLASS)) F P(F) P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(PtrIDynamicInterfaceCastable_PtrClass_PtrClass_PtrException_RetVoid, P(C(IDYNAMICINTERFACECASTABLE)) P(C(CLASS)) P(C(CLASS)) P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(PtrChar_PtrAssembly_CLR_BOOL_CLR_BOOL_IntPtr_PtrClass_PtrException_RetVoid, P(u) P(C(ASSEMBLY)) F F I P(C(CLASS)) P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(IntPtr_PtrStr_PtrException_RetVoid, I P(s) P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(PtrStr_IntPtr_PtrException_RetIntPtr, P(s) I P(C(EXCEPTION)), I)) +DEFINE_METASIG_T(SM(PtrStr_PtrException_RetIntPtr, P(s) P(C(EXCEPTION)), I)) +DEFINE_METASIG_T(SM(IntPtr_PtrObj_PtrException_RetVoid, I P(j) P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(PtrObj_PtrIntPtr_PtrException_RetVoid, P(j) P(I) P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(IntPtr_Int_PtrObj_PtrException_RetVoid, I i P(j) P(C(EXCEPTION)), v)) +DEFINE_METASIG_T(SM(PtrChar_IntPtr_PtrException_RetIntPtr, P(u) I P(C(EXCEPTION)), I)) +DEFINE_METASIG_T(SM(PtrChar_PtrAssemblyBase_CLR_BOOL_UInt_PtrException_RetIntPtr, P(u) P(C(ASSEMBLYBASE)) F K P(C(EXCEPTION)), I)) +DEFINE_METASIG_T(SM(PtrChar_PtrAssemblyBase_IntPtr_PtrException_RetIntPtr, P(u) P(C(ASSEMBLYBASE)) I P(C(EXCEPTION)), I)) +#ifdef FEATURE_COMINTEROP +DEFINE_METASIG_T(SM(PtrComObject_PtrException_RetVoid, P(C(COM_OBJECT)) P(C(EXCEPTION)), v)) +#endif // FEATURE_COMINTEROP +#ifdef FEATURE_COMWRAPPERS +DEFINE_METASIG_T(SM(PtrManagedObjectWrapperHolder_PtrGuid_PtrIntPtr_PtrException_RetInt, P(C(MANAGED_OBJECT_WRAPPER_HOLDER)) P(g(GUID)) P(I) P(C(EXCEPTION)), i)) +#endif // FEATURE_COMWRAPPERS + // fields - e.g.: // DEFINE_METASIG(Fld(PtrVoid, P(v))) diff --git a/src/coreclr/vm/nativelibrary.cpp b/src/coreclr/vm/nativelibrary.cpp index c8ee99667a45b7..aec8848b951991 100644 --- a/src/coreclr/vm/nativelibrary.cpp +++ b/src/coreclr/vm/nativelibrary.cpp @@ -267,7 +267,6 @@ namespace } #endif // !TARGET_UNIX - NATIVE_LIBRARY_HANDLE hmod = NULL; PEAssembly *pManifestFile = pAssembly->GetPEAssembly(); PTR_AssemblyBinder pBinder = pManifestFile->GetAssemblyBinder(); @@ -286,26 +285,12 @@ namespace GCX_COOP(); - STRINGREF pUnmanagedDllName; - pUnmanagedDllName = StringObject::NewString(wszLibName); - - GCPROTECT_BEGIN(pUnmanagedDllName); - // Get the pointer to the managed assembly load context INT_PTR ptrAssemblyLoadContext = pCurrentBinder->GetAssemblyLoadContext(); - // Prepare to invoke System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDll method. - PREPARE_NONVIRTUAL_CALLSITE(METHOD__ASSEMBLYLOADCONTEXT__RESOLVEUNMANAGEDDLL); - DECLARE_ARGHOLDER_ARRAY(args, 2); - args[ARGNUM_0] = STRINGREF_TO_ARGHOLDER(pUnmanagedDllName); - args[ARGNUM_1] = PTR_TO_ARGHOLDER(ptrAssemblyLoadContext); - - // Make the call - CALL_MANAGED_METHOD(hmod, NATIVE_LIBRARY_HANDLE, args); - - GCPROTECT_END(); - - return hmod; + // Invoke System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDll method. + UnmanagedCallersOnlyCaller resolveUnmanagedDll(METHOD__ASSEMBLYLOADCONTEXT__RESOLVEUNMANAGEDDLL); + return (NATIVE_LIBRARY_HANDLE)resolveUnmanagedDll.InvokeThrowing_Ret(wszLibName, ptrAssemblyLoadContext); } // Return the AssemblyLoadContext for an assembly @@ -331,28 +316,18 @@ namespace GCX_COOP(); - struct { - STRINGREF DllName; - OBJECTREF AssemblyRef; - } gc = { NULL, NULL }; + OBJECTREF assemblyRef = NULL; - GCPROTECT_BEGIN(gc); + GCPROTECT_BEGIN(assemblyRef); - gc.DllName = StringObject::NewString(wszLibName); - gc.AssemblyRef = pAssembly->GetExposedObject(); + assemblyRef = pAssembly->GetExposedObject(); - // Prepare to invoke System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDllUsingEvent method + // Invoke System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDllUsingEvent method // While ResolveUnmanagedDllUsingEvent() could compute the AssemblyLoadContext using the AssemblyRef // argument, it will involve another pInvoke to the runtime. So AssemblyLoadContext is passed in // as an additional argument. - PREPARE_NONVIRTUAL_CALLSITE(METHOD__ASSEMBLYLOADCONTEXT__RESOLVEUNMANAGEDDLLUSINGEVENT); - DECLARE_ARGHOLDER_ARRAY(args, 3); - args[ARGNUM_0] = STRINGREF_TO_ARGHOLDER(gc.DllName); - args[ARGNUM_1] = OBJECTREF_TO_ARGHOLDER(gc.AssemblyRef); - args[ARGNUM_2] = PTR_TO_ARGHOLDER(ptrAssemblyLoadContext); - - // Make the call - CALL_MANAGED_METHOD(hmod, NATIVE_LIBRARY_HANDLE, args); + UnmanagedCallersOnlyCaller resolveUnmanagedDllUsingEvent(METHOD__ASSEMBLYLOADCONTEXT__RESOLVEUNMANAGEDDLLUSINGEVENT); + hmod = (NATIVE_LIBRARY_HANDLE)resolveUnmanagedDllUsingEvent.InvokeThrowing_Ret(wszLibName, &assemblyRef, ptrAssemblyLoadContext); GCPROTECT_END(); @@ -380,25 +355,14 @@ namespace GCX_COOP(); - struct { - STRINGREF libNameRef; - OBJECTREF assemblyRef; - } gc = { NULL, NULL }; - - GCPROTECT_BEGIN(gc); + OBJECTREF assemblyRef = NULL; - gc.libNameRef = StringObject::NewString(wszLibName); - gc.assemblyRef = pAssembly->GetExposedObject(); + GCPROTECT_BEGIN(assemblyRef); - PREPARE_NONVIRTUAL_CALLSITE(METHOD__NATIVELIBRARY__LOADLIBRARYCALLBACKSTUB); - DECLARE_ARGHOLDER_ARRAY(args, 4); - args[ARGNUM_0] = STRINGREF_TO_ARGHOLDER(gc.libNameRef); - args[ARGNUM_1] = OBJECTREF_TO_ARGHOLDER(gc.assemblyRef); - args[ARGNUM_2] = BOOL_TO_ARGHOLDER(hasDllImportSearchPathFlags); - args[ARGNUM_3] = DWORD_TO_ARGHOLDER(dllImportSearchPathFlags); + assemblyRef = pAssembly->GetExposedObject(); - // Make the call - CALL_MANAGED_METHOD(handle, NATIVE_LIBRARY_HANDLE, args); + UnmanagedCallersOnlyCaller loadLibraryCallbackStub(METHOD__NATIVELIBRARY__LOADLIBRARYCALLBACKSTUB); + handle = (NATIVE_LIBRARY_HANDLE)loadLibraryCallbackStub.InvokeThrowing_Ret(wszLibName, &assemblyRef, CLR_BOOL_ARG(hasDllImportSearchPathFlags), dllImportSearchPathFlags); GCPROTECT_END(); return handle; diff --git a/src/coreclr/vm/olevariant.cpp b/src/coreclr/vm/olevariant.cpp index 24a00ce910e887..ccb340fa7acdde 100644 --- a/src/coreclr/vm/olevariant.cpp +++ b/src/coreclr/vm/olevariant.cpp @@ -4197,10 +4197,8 @@ void OleVariant::ConvertBSTRToString(BSTR bstr, STRINGREF *pStringObj) if (bstr == NULL) return; - PREPARE_NONVIRTUAL_CALLSITE(METHOD__BSTRMARSHALER__CONVERT_TO_MANAGED); - DECLARE_ARGHOLDER_ARRAY(args, 1); - args[ARGNUM_0] = PTR_TO_ARGHOLDER(bstr); - CALL_MANAGED_METHOD_RETREF(*pStringObj, STRINGREF, args); + UnmanagedCallersOnlyCaller convertToManaged(METHOD__BSTRMARSHALER__CONVERT_TO_MANAGED_UCO); + convertToManaged.InvokeThrowing((INT_PTR)bstr, pStringObj); } BSTR OleVariant::ConvertStringToBSTR(STRINGREF *pStringObj) @@ -4217,20 +4215,13 @@ BSTR OleVariant::ConvertStringToBSTR(STRINGREF *pStringObj) } CONTRACT_END; - // Initiatilize the return BSTR value to null. - BSTR bstr = NULL; - if (*pStringObj == NULL) { RETURN NULL; } - PREPARE_NONVIRTUAL_CALLSITE(METHOD__BSTRMARSHALER__CONVERT_TO_NATIVE); - DECLARE_ARGHOLDER_ARRAY(args, 2); - args[ARGNUM_0] = STRINGREF_TO_ARGHOLDER(*pStringObj); - args[ARGNUM_1] = PTR_TO_ARGHOLDER(nullptr); - CALL_MANAGED_METHOD(bstr, BSTR, args); - RETURN bstr; + UnmanagedCallersOnlyCaller convertToNative(METHOD__BSTRMARSHALER__CONVERT_TO_NATIVE_UCO); + RETURN (BSTR)convertToNative.InvokeThrowing_Ret(pStringObj); } extern "C" void QCALLTYPE Variant_ConvertValueTypeToRecord(QCall::ObjectHandleOnStack obj, VARIANT * pOle) diff --git a/src/coreclr/vm/runtimecallablewrapper.cpp b/src/coreclr/vm/runtimecallablewrapper.cpp index db58879480b80a..91ed63aa8ce4fc 100644 --- a/src/coreclr/vm/runtimecallablewrapper.cpp +++ b/src/coreclr/vm/runtimecallablewrapper.cpp @@ -2520,14 +2520,10 @@ void ComObject::ReleaseAllData(OBJECTREF oref) } CONTRACTL_END; - GCPROTECT_BEGIN(oref) + GCPROTECT_BEGIN(oref); { - PREPARE_NONVIRTUAL_CALLSITE(METHOD__COM_OBJECT__RELEASE_ALL_DATA); - - DECLARE_ARGHOLDER_ARRAY(ReleaseAllDataArgs, 1); - ReleaseAllDataArgs[ARGNUM_0] = OBJECTREF_TO_ARGHOLDER(oref); - - CALL_MANAGED_METHOD_NORET(ReleaseAllDataArgs); + UnmanagedCallersOnlyCaller releaseAllData(METHOD__COM_OBJECT__RELEASE_ALL_DATA); + releaseAllData.InvokeThrowing(&oref); } GCPROTECT_END(); } diff --git a/src/coreclr/vm/syncblk.cpp b/src/coreclr/vm/syncblk.cpp index c210092c685fdb..bffd9d2d69c318 100644 --- a/src/coreclr/vm/syncblk.cpp +++ b/src/coreclr/vm/syncblk.cpp @@ -1782,16 +1782,15 @@ bool SyncBlock::TryUpgradeThinLockToFullLock(OBJECTHANDLE lockHandle) DWORD lockThreadId = thinLock & SBLK_MASK_LOCK_THREADID; DWORD recursionLevel = (thinLock & SBLK_MASK_LOCK_RECLEVEL) >> SBLK_RECLEVEL_SHIFT; _ASSERTE(lockThreadId != 0); - PREPARE_NONVIRTUAL_CALLSITE(METHOD__LOCK__INITIALIZE_FOR_MONITOR); // We have thin-lock info that needs to be transferred to the lock object. OBJECTREF lockObj = ObjectFromHandle(lockHandle); + GCPROTECT_BEGIN(lockObj); + + UnmanagedCallersOnlyCaller initializeForMonitor(METHOD__LOCK__INITIALIZE_FOR_MONITOR); + initializeForMonitor.InvokeThrowing(&lockObj, (int32_t)lockThreadId, (uint32_t)recursionLevel); - DECLARE_ARGHOLDER_ARRAY(args, 3); - args[ARGNUM_0] = OBJECTREF_TO_ARGHOLDER(lockObj); - args[ARGNUM_1] = DWORD_TO_ARGHOLDER(lockThreadId); - args[ARGNUM_2] = DWORD_TO_ARGHOLDER(recursionLevel); - CALL_MANAGED_METHOD_NORET(args); + GCPROTECT_END(); } VolatileStore(&m_Lock, lockHandle); diff --git a/src/coreclr/vm/threads.cpp b/src/coreclr/vm/threads.cpp index e51ca6c5bd8667..f0cf759e010cbf 100644 --- a/src/coreclr/vm/threads.cpp +++ b/src/coreclr/vm/threads.cpp @@ -1811,9 +1811,8 @@ void Thread::InitializationForManagedThreadInNative(_In_ Thread* pThread) #ifdef FEATURE_OBJCMARSHAL { GCX_COOP_THREAD_EXISTS(pThread); - PREPARE_NONVIRTUAL_CALLSITE(METHOD__AUTORELEASEPOOL__CREATEAUTORELEASEPOOL); - DECLARE_ARGHOLDER_ARRAY(args, 0); - CALL_MANAGED_METHOD_NORET(args); + UnmanagedCallersOnlyCaller createAutoreleasePool(METHOD__AUTORELEASEPOOL__CREATEAUTORELEASEPOOL); + createAutoreleasePool.InvokeThrowing(); } #endif // FEATURE_OBJCMARSHAL } @@ -1832,9 +1831,8 @@ void Thread::CleanUpForManagedThreadInNative(_In_ Thread* pThread) #ifdef FEATURE_OBJCMARSHAL { GCX_COOP_THREAD_EXISTS(pThread); - PREPARE_NONVIRTUAL_CALLSITE(METHOD__AUTORELEASEPOOL__DRAINAUTORELEASEPOOL); - DECLARE_ARGHOLDER_ARRAY(args, 0); - CALL_MANAGED_METHOD_NORET(args); + UnmanagedCallersOnlyCaller drainAutoreleasePool(METHOD__AUTORELEASEPOOL__DRAINAUTORELEASEPOOL); + drainAutoreleasePool.InvokeThrowing(); } #endif // FEATURE_OBJCMARSHAL } @@ -2466,10 +2464,11 @@ void Thread::CleanupDetachedThreads() // Instead, run that clean up here when the Thread is detached, // which is definitely after the thread has exited. PTR_Thread pThread = (PTR_Thread)iter.GetElement(); - PREPARE_NONVIRTUAL_CALLSITE(METHOD__THREAD__ON_THREAD_EXITING); - DECLARE_ARGHOLDER_ARRAY(args, 1); - args[ARGNUM_0] = OBJECTREF_TO_ARGHOLDER(pThread->GetExposedObject()); - CALL_MANAGED_METHOD_NORET(args); + OBJECTREF exposedObj = pThread->GetExposedObject(); + GCPROTECT_BEGIN(exposedObj); + UnmanagedCallersOnlyCaller onThreadExiting(METHOD__THREAD__ON_THREAD_EXITING); + onThreadExiting.InvokeThrowing(&exposedObj); + GCPROTECT_END(); pThread->DecExternalCount(FALSE); } diff --git a/src/coreclr/vm/typeparse.cpp b/src/coreclr/vm/typeparse.cpp index ae3fdf778f76a2..06ab120b1f7def 100644 --- a/src/coreclr/vm/typeparse.cpp +++ b/src/coreclr/vm/typeparse.cpp @@ -21,30 +21,28 @@ static TypeHandle GetTypeHelper(LPCWSTR szTypeName, Assembly* pRequestingAssembl GCX_COOP(); - OBJECTREF objRequestingAssembly = NULL; - GCPROTECT_BEGIN(objRequestingAssembly); + struct { + OBJECTREF objRequestingAssembly; + OBJECTREF objType; + } gc; + gc.objRequestingAssembly = NULL; + gc.objType = NULL; + + GCPROTECT_BEGIN(gc); if (pRequestingAssembly != NULL) { - objRequestingAssembly = pRequestingAssembly->GetExposedObject(); + gc.objRequestingAssembly = pRequestingAssembly->GetExposedObject(); } OVERRIDE_TYPE_LOAD_LEVEL_LIMIT(CLASS_LOADED); - PREPARE_NONVIRTUAL_CALLSITE(METHOD__TYPE_NAME_RESOLVER__GET_TYPE_HELPER); - DECLARE_ARGHOLDER_ARRAY(args, 5); - args[ARGNUM_0] = PTR_TO_ARGHOLDER(szTypeName); - args[ARGNUM_1] = OBJECTREF_TO_ARGHOLDER(objRequestingAssembly); - args[ARGNUM_2] = BOOL_TO_ARGHOLDER(bThrowIfNotFound); - args[ARGNUM_3] = BOOL_TO_ARGHOLDER(bRequireAssemblyQualifiedName); - args[ARGNUM_4] = PTR_TO_ARGHOLDER(unsafeAccessorMethod); - - REFLECTCLASSBASEREF objType = NULL; - CALL_MANAGED_METHOD_RETREF(objType, REFLECTCLASSBASEREF, args); + UnmanagedCallersOnlyCaller getTypeHelper(METHOD__TYPE_NAME_RESOLVER__GET_TYPE_HELPER); + getTypeHelper.InvokeThrowing(szTypeName, &gc.objRequestingAssembly, CLR_BOOL_ARG(bThrowIfNotFound), CLR_BOOL_ARG(bRequireAssemblyQualifiedName), (INT_PTR)unsafeAccessorMethod, &gc.objType); - if (objType != NULL) + if (gc.objType != NULL) { - type = objType->GetType(); + type = ((REFLECTCLASSBASEREF)gc.objType)->GetType(); } GCPROTECT_END(); diff --git a/src/coreclr/vm/wasm/callhelpers-reverse.cpp b/src/coreclr/vm/wasm/callhelpers-reverse.cpp index d4458712808143..a0d7b7d45a1dc2 100644 --- a/src/coreclr/vm/wasm/callhelpers-reverse.cpp +++ b/src/coreclr/vm/wasm/callhelpers-reverse.cpp @@ -232,6 +232,35 @@ static void Call_System_Private_CoreLib_System_StubHelpers_MngdRefCustomMarshale ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_StubHelpers_MngdRefCustomMarshaler_ConvertContentsToNative_I32_I32_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_StubHelpers_MngdRefCustomMarshaler_ConvertContentsToNative_I32_I32_I32_I32_RetVoid); } +static MethodDesc* MD_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToManaged_I32_I32_I32_RetVoid = nullptr; +static void Call_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToManaged_I32_I32_I32_RetVoid(void * arg0, void * arg1, void * arg2) +{ + int64_t args[3] = { (int64_t)arg0, (int64_t)arg1, (int64_t)arg2 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToManaged_I32_I32_I32_RetVoid) + { + LookupUnmanagedCallersOnlyMethodByName("System.StubHelpers.BSTRMarshaler, System.Private.CoreLib", "ConvertToManaged", &MD_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToManaged_I32_I32_I32_RetVoid); + } + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToManaged_I32_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToManaged_I32_I32_I32_RetVoid); +} + +static MethodDesc* MD_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToNative_I32_I32_RetI32 = nullptr; +static void * Call_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToNative_I32_I32_RetI32(void * arg0, void * arg1) +{ + int64_t args[2] = { (int64_t)arg0, (int64_t)arg1 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToNative_I32_I32_RetI32) + { + LookupUnmanagedCallersOnlyMethodByName("System.StubHelpers.BSTRMarshaler, System.Private.CoreLib", "ConvertToNative", &MD_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToNative_I32_I32_RetI32); + } + + void * result; + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToNative_I32_I32_RetI32, (int8_t*)args, sizeof(args), (int8_t*)&result, (PCODE)&Call_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToNative_I32_I32_RetI32); + return result; +} + static MethodDesc* MD_System_Private_CoreLib_System_Reflection_LoaderAllocator_Create_I32_I32_RetVoid = nullptr; static void Call_System_Private_CoreLib_System_Reflection_LoaderAllocator_Create_I32_I32_RetVoid(void * arg0, void * arg1) { @@ -245,6 +274,19 @@ static void Call_System_Private_CoreLib_System_Reflection_LoaderAllocator_Create ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Reflection_LoaderAllocator_Create_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Reflection_LoaderAllocator_Create_I32_I32_RetVoid); } +static MethodDesc* MD_System_Private_CoreLib_System_Reflection_AssemblyName_CreateAssemblyName_I32_I32_I32_RetVoid = nullptr; +static void Call_System_Private_CoreLib_System_Reflection_AssemblyName_CreateAssemblyName_I32_I32_I32_RetVoid(void * arg0, void * arg1, void * arg2) +{ + int64_t args[3] = { (int64_t)arg0, (int64_t)arg1, (int64_t)arg2 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_Reflection_AssemblyName_CreateAssemblyName_I32_I32_I32_RetVoid) + { + LookupUnmanagedCallersOnlyMethodByName("System.Reflection.AssemblyName, System.Private.CoreLib", "CreateAssemblyName", &MD_System_Private_CoreLib_System_Reflection_AssemblyName_CreateAssemblyName_I32_I32_I32_RetVoid); + } + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Reflection_AssemblyName_CreateAssemblyName_I32_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Reflection_AssemblyName_CreateAssemblyName_I32_I32_I32_RetVoid); +} + static MethodDesc* MD_System_Private_CoreLib_System_Exception_CreateRuntimeWrappedException_I32_I32_I32_RetVoid = nullptr; static void Call_System_Private_CoreLib_System_Exception_CreateRuntimeWrappedException_I32_I32_I32_RetVoid(void * arg0, void * arg1, void * arg2) { @@ -368,6 +410,19 @@ static int32_t Call_System_Private_CoreLib_Internal_Runtime_InteropServices_Comp return result; } +static MethodDesc* MD_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_GetInterfaceImplementation_I32_I32_I32_I32_RetVoid = nullptr; +static void Call_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_GetInterfaceImplementation_I32_I32_I32_I32_RetVoid(void * arg0, void * arg1, void * arg2, void * arg3) +{ + int64_t args[4] = { (int64_t)arg0, (int64_t)arg1, (int64_t)arg2, (int64_t)arg3 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_GetInterfaceImplementation_I32_I32_I32_I32_RetVoid) + { + LookupUnmanagedCallersOnlyMethodByName("System.Runtime.InteropServices.DynamicInterfaceCastableHelpers, System.Private.CoreLib", "GetInterfaceImplementation", &MD_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_GetInterfaceImplementation_I32_I32_I32_I32_RetVoid); + } + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_GetInterfaceImplementation_I32_I32_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_GetInterfaceImplementation_I32_I32_I32_I32_RetVoid); +} + static MethodDesc* MD_System_Private_CoreLib_System_Resolver_GetJitContext_I32_I32_I32_I32_RetVoid = nullptr; static void Call_System_Private_CoreLib_System_Resolver_GetJitContext_I32_I32_I32_I32_RetVoid(void * arg0, void * arg1, void * arg2, void * arg3) { @@ -438,6 +493,45 @@ static void Call_System_Private_CoreLib_System_Resolver_GetStringLiteral_I32_I32 ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Resolver_GetStringLiteral_I32_I32_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Resolver_GetStringLiteral_I32_I32_I32_I32_RetVoid); } +static MethodDesc* MD_System_Private_CoreLib_System_Reflection_TypeNameResolver_GetTypeHelper_I32_I32_I32_I32_I32_I32_I32_RetVoid = nullptr; +static void Call_System_Private_CoreLib_System_Reflection_TypeNameResolver_GetTypeHelper_I32_I32_I32_I32_I32_I32_I32_RetVoid(void * arg0, void * arg1, int32_t arg2, int32_t arg3, void * arg4, void * arg5, void * arg6) +{ + int64_t args[7] = { (int64_t)arg0, (int64_t)arg1, (int64_t)arg2, (int64_t)arg3, (int64_t)arg4, (int64_t)arg5, (int64_t)arg6 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_Reflection_TypeNameResolver_GetTypeHelper_I32_I32_I32_I32_I32_I32_I32_RetVoid) + { + LookupUnmanagedCallersOnlyMethodByName("System.Reflection.TypeNameResolver, System.Private.CoreLib", "GetTypeHelper", &MD_System_Private_CoreLib_System_Reflection_TypeNameResolver_GetTypeHelper_I32_I32_I32_I32_I32_I32_I32_RetVoid); + } + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Reflection_TypeNameResolver_GetTypeHelper_I32_I32_I32_I32_I32_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Reflection_TypeNameResolver_GetTypeHelper_I32_I32_I32_I32_I32_I32_I32_RetVoid); +} + +static MethodDesc* MD_System_Private_CoreLib_System_Environment_InitializeCommandLineArgs_I32_I32_I32_I32_I32_RetVoid = nullptr; +static void Call_System_Private_CoreLib_System_Environment_InitializeCommandLineArgs_I32_I32_I32_I32_I32_RetVoid(void * arg0, int32_t arg1, void * arg2, void * arg3, void * arg4) +{ + int64_t args[5] = { (int64_t)arg0, (int64_t)arg1, (int64_t)arg2, (int64_t)arg3, (int64_t)arg4 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_Environment_InitializeCommandLineArgs_I32_I32_I32_I32_I32_RetVoid) + { + LookupUnmanagedCallersOnlyMethodByName("System.Environment, System.Private.CoreLib", "InitializeCommandLineArgs", &MD_System_Private_CoreLib_System_Environment_InitializeCommandLineArgs_I32_I32_I32_I32_I32_RetVoid); + } + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Environment_InitializeCommandLineArgs_I32_I32_I32_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Environment_InitializeCommandLineArgs_I32_I32_I32_I32_I32_RetVoid); +} + +static MethodDesc* MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_InitializeDefaultContext_I32_RetVoid = nullptr; +static void Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_InitializeDefaultContext_I32_RetVoid(void * arg0) +{ + int64_t args[1] = { (int64_t)arg0 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_InitializeDefaultContext_I32_RetVoid) + { + LookupUnmanagedCallersOnlyMethodByName("System.Runtime.Loader.AssemblyLoadContext, System.Private.CoreLib", "InitializeDefaultContext", &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_InitializeDefaultContext_I32_RetVoid); + } + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_InitializeDefaultContext_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_InitializeDefaultContext_I32_RetVoid); +} + static MethodDesc* MD_System_Private_CoreLib_System_Diagnostics_Tracing_EventSource_InitializeDefaultEventSources_I32_RetVoid = nullptr; static void Call_System_Private_CoreLib_System_Diagnostics_Tracing_EventSource_InitializeDefaultEventSources_I32_RetVoid(void * arg0) { @@ -451,6 +545,19 @@ static void Call_System_Private_CoreLib_System_Diagnostics_Tracing_EventSource_I ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Diagnostics_Tracing_EventSource_InitializeDefaultEventSources_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Diagnostics_Tracing_EventSource_InitializeDefaultEventSources_I32_RetVoid); } +static MethodDesc* MD_System_Private_CoreLib_System_Threading_Lock_InitializeForMonitor_I32_I32_I32_I32_RetVoid = nullptr; +static void Call_System_Private_CoreLib_System_Threading_Lock_InitializeForMonitor_I32_I32_I32_I32_RetVoid(void * arg0, int32_t arg1, uint32_t arg2, void * arg3) +{ + int64_t args[4] = { (int64_t)arg0, (int64_t)arg1, (int64_t)arg2, (int64_t)arg3 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_Threading_Lock_InitializeForMonitor_I32_I32_I32_I32_RetVoid) + { + LookupUnmanagedCallersOnlyMethodByName("System.Threading.Lock, System.Private.CoreLib", "InitializeForMonitor", &MD_System_Private_CoreLib_System_Threading_Lock_InitializeForMonitor_I32_I32_I32_I32_RetVoid); + } + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Threading_Lock_InitializeForMonitor_I32_I32_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Threading_Lock_InitializeForMonitor_I32_I32_I32_I32_RetVoid); +} + static MethodDesc* MD_System_Private_CoreLib_System_Exception_InternalPreserveStackTrace_I32_I32_RetVoid = nullptr; static void Call_System_Private_CoreLib_System_Exception_InternalPreserveStackTrace_I32_I32_RetVoid(void * arg0, void * arg1) { @@ -464,6 +571,19 @@ static void Call_System_Private_CoreLib_System_Exception_InternalPreserveStackTr ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Exception_InternalPreserveStackTrace_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Exception_InternalPreserveStackTrace_I32_I32_RetVoid); } +static MethodDesc* MD_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_IsInterfaceImplemented_I32_I32_I32_I32_I32_RetVoid = nullptr; +static void Call_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_IsInterfaceImplemented_I32_I32_I32_I32_I32_RetVoid(void * arg0, void * arg1, int32_t arg2, void * arg3, void * arg4) +{ + int64_t args[5] = { (int64_t)arg0, (int64_t)arg1, (int64_t)arg2, (int64_t)arg3, (int64_t)arg4 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_IsInterfaceImplemented_I32_I32_I32_I32_I32_RetVoid) + { + LookupUnmanagedCallersOnlyMethodByName("System.Runtime.InteropServices.DynamicInterfaceCastableHelpers, System.Private.CoreLib", "IsInterfaceImplemented", &MD_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_IsInterfaceImplemented_I32_I32_I32_I32_I32_RetVoid); + } + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_IsInterfaceImplemented_I32_I32_I32_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_IsInterfaceImplemented_I32_I32_I32_I32_I32_RetVoid); +} + static MethodDesc* MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssembly_I32_I32_I32_RetI32 = nullptr; static int32_t Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssembly_I32_I32_I32_RetI32(void * arg0, void * arg1, void * arg2) { @@ -512,6 +632,22 @@ static int32_t Call_System_Private_CoreLib_Internal_Runtime_InteropServices_Comp return result; } +static MethodDesc* MD_System_Private_CoreLib_System_Runtime_InteropServices_NativeLibrary_LoadLibraryCallbackStub_I32_I32_I32_I32_I32_RetI32 = nullptr; +static void * Call_System_Private_CoreLib_System_Runtime_InteropServices_NativeLibrary_LoadLibraryCallbackStub_I32_I32_I32_I32_I32_RetI32(void * arg0, void * arg1, int32_t arg2, uint32_t arg3, void * arg4) +{ + int64_t args[5] = { (int64_t)arg0, (int64_t)arg1, (int64_t)arg2, (int64_t)arg3, (int64_t)arg4 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_Runtime_InteropServices_NativeLibrary_LoadLibraryCallbackStub_I32_I32_I32_I32_I32_RetI32) + { + LookupUnmanagedCallersOnlyMethodByName("System.Runtime.InteropServices.NativeLibrary, System.Private.CoreLib", "LoadLibraryCallbackStub", &MD_System_Private_CoreLib_System_Runtime_InteropServices_NativeLibrary_LoadLibraryCallbackStub_I32_I32_I32_I32_I32_RetI32); + } + + void * result; + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Runtime_InteropServices_NativeLibrary_LoadLibraryCallbackStub_I32_I32_I32_I32_I32_RetI32, (int8_t*)args, sizeof(args), (int8_t*)&result, (PCODE)&Call_System_Private_CoreLib_System_Runtime_InteropServices_NativeLibrary_LoadLibraryCallbackStub_I32_I32_I32_I32_I32_RetI32); + return result; +} + static MethodDesc* MD_System_Private_CoreLib_System_StartupHookProvider_ManagedStartup_I32_I32_RetVoid = nullptr; static void Call_System_Private_CoreLib_System_StartupHookProvider_ManagedStartup_I32_I32_RetVoid(void * arg0, void * arg1) { @@ -654,6 +790,19 @@ static void Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContex ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_OnResourceResolve_I32_I32_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_OnResourceResolve_I32_I32_I32_I32_RetVoid); } +static MethodDesc* MD_System_Private_CoreLib_System_Threading_Thread_OnThreadExiting_I32_I32_RetVoid = nullptr; +static void Call_System_Private_CoreLib_System_Threading_Thread_OnThreadExiting_I32_I32_RetVoid(void * arg0, void * arg1) +{ + int64_t args[2] = { (int64_t)arg0, (int64_t)arg1 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_Threading_Thread_OnThreadExiting_I32_I32_RetVoid) + { + LookupUnmanagedCallersOnlyMethodByName("System.Threading.Thread, System.Private.CoreLib", "OnThreadExiting", &MD_System_Private_CoreLib_System_Threading_Thread_OnThreadExiting_I32_I32_RetVoid); + } + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Threading_Thread_OnThreadExiting_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Threading_Thread_OnThreadExiting_I32_I32_RetVoid); +} + static MethodDesc* MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_OnTypeResolve_I32_I32_I32_I32_RetVoid = nullptr; static void Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_OnTypeResolve_I32_I32_I32_I32_RetVoid(void * arg0, void * arg1, void * arg2, void * arg3) { @@ -680,6 +829,19 @@ static void Call_System_Private_CoreLib_System_AppContext_OnUnhandledException_I ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_AppContext_OnUnhandledException_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_AppContext_OnUnhandledException_I32_I32_RetVoid); } +static MethodDesc* MD_System_Private_CoreLib_System_Reflection_AssemblyName_ParseAsAssemblySpec_I32_I32_I32_RetVoid = nullptr; +static void Call_System_Private_CoreLib_System_Reflection_AssemblyName_ParseAsAssemblySpec_I32_I32_I32_RetVoid(void * arg0, void * arg1, void * arg2) +{ + int64_t args[3] = { (int64_t)arg0, (int64_t)arg1, (int64_t)arg2 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_Reflection_AssemblyName_ParseAsAssemblySpec_I32_I32_I32_RetVoid) + { + LookupUnmanagedCallersOnlyMethodByName("System.Reflection.AssemblyName, System.Private.CoreLib", "ParseAsAssemblySpec", &MD_System_Private_CoreLib_System_Reflection_AssemblyName_ParseAsAssemblySpec_I32_I32_I32_RetVoid); + } + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Reflection_AssemblyName_ParseAsAssemblySpec_I32_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Reflection_AssemblyName_ParseAsAssemblySpec_I32_I32_I32_RetVoid); +} + static MethodDesc* MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_RegisterClassForTypeInternal_I32_RetI32 = nullptr; static int32_t Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_RegisterClassForTypeInternal_I32_RetI32(void * arg0) { @@ -766,6 +928,38 @@ static void Call_System_Private_CoreLib_System_Resolver_ResolveToken_I32_I32_I32 ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Resolver_ResolveToken_I32_I32_I32_I32_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Resolver_ResolveToken_I32_I32_I32_I32_I32_I32_RetVoid); } +static MethodDesc* MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDll_I32_I32_I32_RetI32 = nullptr; +static void * Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDll_I32_I32_I32_RetI32(void * arg0, void * arg1, void * arg2) +{ + int64_t args[3] = { (int64_t)arg0, (int64_t)arg1, (int64_t)arg2 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDll_I32_I32_I32_RetI32) + { + LookupUnmanagedCallersOnlyMethodByName("System.Runtime.Loader.AssemblyLoadContext, System.Private.CoreLib", "ResolveUnmanagedDll", &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDll_I32_I32_I32_RetI32); + } + + void * result; + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDll_I32_I32_I32_RetI32, (int8_t*)args, sizeof(args), (int8_t*)&result, (PCODE)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDll_I32_I32_I32_RetI32); + return result; +} + +static MethodDesc* MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDllUsingEvent_I32_I32_I32_I32_RetI32 = nullptr; +static void * Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDllUsingEvent_I32_I32_I32_I32_RetI32(void * arg0, void * arg1, void * arg2, void * arg3) +{ + int64_t args[4] = { (int64_t)arg0, (int64_t)arg1, (int64_t)arg2, (int64_t)arg3 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDllUsingEvent_I32_I32_I32_I32_RetI32) + { + LookupUnmanagedCallersOnlyMethodByName("System.Runtime.Loader.AssemblyLoadContext, System.Private.CoreLib", "ResolveUnmanagedDllUsingEvent", &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDllUsingEvent_I32_I32_I32_I32_RetI32); + } + + void * result; + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDllUsingEvent_I32_I32_I32_I32_RetI32, (int8_t*)args, sizeof(args), (int8_t*)&result, (PCODE)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDllUsingEvent_I32_I32_I32_I32_RetI32); + return result; +} + static MethodDesc* MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUsingEvent_I32_I32_I32_I32_RetVoid = nullptr; static void Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUsingEvent_I32_I32_I32_I32_RetVoid(void * arg0, void * arg1, void * arg2, void * arg3) { @@ -792,6 +986,32 @@ static void Call_System_Private_CoreLib_System_AppContext_Setup_I32_I32_I32_I32_ ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_AppContext_Setup_I32_I32_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_AppContext_Setup_I32_I32_I32_I32_RetVoid); } +static MethodDesc* MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StartAssemblyLoad_I32_I32_I32_RetVoid = nullptr; +static void Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StartAssemblyLoad_I32_I32_I32_RetVoid(void * arg0, void * arg1, void * arg2) +{ + int64_t args[3] = { (int64_t)arg0, (int64_t)arg1, (int64_t)arg2 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StartAssemblyLoad_I32_I32_I32_RetVoid) + { + LookupUnmanagedCallersOnlyMethodByName("System.Runtime.Loader.AssemblyLoadContext, System.Private.CoreLib", "StartAssemblyLoad", &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StartAssemblyLoad_I32_I32_I32_RetVoid); + } + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StartAssemblyLoad_I32_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StartAssemblyLoad_I32_I32_I32_RetVoid); +} + +static MethodDesc* MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StopAssemblyLoad_I32_I32_RetVoid = nullptr; +static void Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StopAssemblyLoad_I32_I32_RetVoid(void * arg0, void * arg1) +{ + int64_t args[2] = { (int64_t)arg0, (int64_t)arg1 }; + + // Lazy lookup of MethodDesc for the function export scenario. + if (!MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StopAssemblyLoad_I32_I32_RetVoid) + { + LookupUnmanagedCallersOnlyMethodByName("System.Runtime.Loader.AssemblyLoadContext, System.Private.CoreLib", "StopAssemblyLoad", &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StopAssemblyLoad_I32_I32_RetVoid); + } + ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StopAssemblyLoad_I32_I32_RetVoid, (int8_t*)args, sizeof(args), nullptr, (PCODE)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StopAssemblyLoad_I32_I32_RetVoid); +} + static MethodDesc* MD_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler_Void_RetVoid = nullptr; static void Call_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler_Void_RetVoid() { @@ -841,7 +1061,10 @@ const ReverseThunkMapEntry g_ReverseThunks[] = { 3378852959, "ConfigCallback#5:System.Private.CoreLib:System:GC", { &MD_System_Private_CoreLib_System_GC_ConfigCallback_I32_I32_I32_I32_I64_RetVoid, (void*)&Call_System_Private_CoreLib_System_GC_ConfigCallback_I32_I32_I32_I32_I64_RetVoid } }, { 823296796, "ConvertContentsToManaged#4:System.Private.CoreLib:System.StubHelpers:MngdRefCustomMarshaler", { &MD_System_Private_CoreLib_System_StubHelpers_MngdRefCustomMarshaler_ConvertContentsToManaged_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_StubHelpers_MngdRefCustomMarshaler_ConvertContentsToManaged_I32_I32_I32_I32_RetVoid } }, { 3788988216, "ConvertContentsToNative#4:System.Private.CoreLib:System.StubHelpers:MngdRefCustomMarshaler", { &MD_System_Private_CoreLib_System_StubHelpers_MngdRefCustomMarshaler_ConvertContentsToNative_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_StubHelpers_MngdRefCustomMarshaler_ConvertContentsToNative_I32_I32_I32_I32_RetVoid } }, + { 4090197812, "ConvertToManaged#3:System.Private.CoreLib:System.StubHelpers:BSTRMarshaler", { &MD_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToManaged_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToManaged_I32_I32_I32_RetVoid } }, + { 1901425681, "ConvertToNative#2:System.Private.CoreLib:System.StubHelpers:BSTRMarshaler", { &MD_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToNative_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_System_StubHelpers_BSTRMarshaler_ConvertToNative_I32_I32_RetI32 } }, { 1243134822, "Create#2:System.Private.CoreLib:System.Reflection:LoaderAllocator", { &MD_System_Private_CoreLib_System_Reflection_LoaderAllocator_Create_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Reflection_LoaderAllocator_Create_I32_I32_RetVoid } }, + { 1570902419, "CreateAssemblyName#3:System.Private.CoreLib:System.Reflection:AssemblyName", { &MD_System_Private_CoreLib_System_Reflection_AssemblyName_CreateAssemblyName_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Reflection_AssemblyName_CreateAssemblyName_I32_I32_I32_RetVoid } }, { 3054399043, "CreateRuntimeWrappedException#3:System.Private.CoreLib:System:Exception", { &MD_System_Private_CoreLib_System_Exception_CreateRuntimeWrappedException_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Exception_CreateRuntimeWrappedException_I32_I32_I32_RetVoid } }, { 271519467, "CreateTargetInvocationException#3:System.Private.CoreLib:System:Exception", { &MD_System_Private_CoreLib_System_Exception_CreateTargetInvocationException_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Exception_CreateTargetInvocationException_I32_I32_I32_RetVoid } }, { 3064803797, "CreateTypeInitializationException#4:System.Private.CoreLib:System:Exception", { &MD_System_Private_CoreLib_System_Exception_CreateTypeInitializationException_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Exception_CreateTypeInitializationException_I32_I32_I32_I32_RetVoid } }, @@ -851,16 +1074,23 @@ const ReverseThunkMapEntry g_ReverseThunks[] = { 3084636701, "GetCustomMarshalerInstance#5:System.Private.CoreLib:System.StubHelpers:MngdRefCustomMarshaler", { &MD_System_Private_CoreLib_System_StubHelpers_MngdRefCustomMarshaler_GetCustomMarshalerInstance_I32_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_StubHelpers_MngdRefCustomMarshaler_GetCustomMarshalerInstance_I32_I32_I32_I32_I32_RetVoid } }, { 1641343147, "GetEHInfo#5:System.Private.CoreLib:System:Resolver", { &MD_System_Private_CoreLib_System_Resolver_GetEHInfo_I32_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Resolver_GetEHInfo_I32_I32_I32_I32_I32_RetVoid } }, { 993231473, "GetFunctionPointer#6:System.Private.CoreLib:Internal.Runtime.InteropServices:ComponentActivator", { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_GetFunctionPointer_I32_I32_I32_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_GetFunctionPointer_I32_I32_I32_I32_I32_I32_RetI32 } }, + { 3098497371, "GetInterfaceImplementation#4:System.Private.CoreLib:System.Runtime.InteropServices:DynamicInterfaceCastableHelpers", { &MD_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_GetInterfaceImplementation_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_GetInterfaceImplementation_I32_I32_I32_I32_RetVoid } }, { 4101188193, "GetJitContext#4:System.Private.CoreLib:System:Resolver", { &MD_System_Private_CoreLib_System_Resolver_GetJitContext_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Resolver_GetJitContext_I32_I32_I32_I32_RetVoid } }, { 2512220404, "GetLocalsSignature#3:System.Private.CoreLib:System:Resolver", { &MD_System_Private_CoreLib_System_Resolver_GetLocalsSignature_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Resolver_GetLocalsSignature_I32_I32_I32_RetVoid } }, { 1081971317, "GetManagedStackTrace#1:System.Runtime.InteropServices.JavaScript:System.Runtime.InteropServices.JavaScript:JavaScriptExports", { &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace_I32_RetVoid, (void*)&Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace_I32_RetVoid } }, { 1275372322, "GetResourceString#3:System.Private.CoreLib:System:Environment", { &MD_System_Private_CoreLib_System_Environment_GetResourceString_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Environment_GetResourceString_I32_I32_I32_RetVoid } }, { 831291767, "GetStringLiteral#4:System.Private.CoreLib:System:Resolver", { &MD_System_Private_CoreLib_System_Resolver_GetStringLiteral_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Resolver_GetStringLiteral_I32_I32_I32_I32_RetVoid } }, + { 3370125186, "GetTypeHelper#7:System.Private.CoreLib:System.Reflection:TypeNameResolver", { &MD_System_Private_CoreLib_System_Reflection_TypeNameResolver_GetTypeHelper_I32_I32_I32_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Reflection_TypeNameResolver_GetTypeHelper_I32_I32_I32_I32_I32_I32_I32_RetVoid } }, + { 3481461579, "InitializeCommandLineArgs#5:System.Private.CoreLib:System:Environment", { &MD_System_Private_CoreLib_System_Environment_InitializeCommandLineArgs_I32_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Environment_InitializeCommandLineArgs_I32_I32_I32_I32_I32_RetVoid } }, + { 1351540042, "InitializeDefaultContext#1:System.Private.CoreLib:System.Runtime.Loader:AssemblyLoadContext", { &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_InitializeDefaultContext_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_InitializeDefaultContext_I32_RetVoid } }, { 513042204, "InitializeDefaultEventSources#1:System.Private.CoreLib:System.Diagnostics.Tracing:EventSource", { &MD_System_Private_CoreLib_System_Diagnostics_Tracing_EventSource_InitializeDefaultEventSources_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Diagnostics_Tracing_EventSource_InitializeDefaultEventSources_I32_RetVoid } }, + { 266659693, "InitializeForMonitor#4:System.Private.CoreLib:System.Threading:Lock", { &MD_System_Private_CoreLib_System_Threading_Lock_InitializeForMonitor_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Threading_Lock_InitializeForMonitor_I32_I32_I32_I32_RetVoid } }, { 288803216, "InternalPreserveStackTrace#2:System.Private.CoreLib:System:Exception", { &MD_System_Private_CoreLib_System_Exception_InternalPreserveStackTrace_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Exception_InternalPreserveStackTrace_I32_I32_RetVoid } }, + { 3290644746, "IsInterfaceImplemented#5:System.Private.CoreLib:System.Runtime.InteropServices:DynamicInterfaceCastableHelpers", { &MD_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_IsInterfaceImplemented_I32_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Runtime_InteropServices_DynamicInterfaceCastableHelpers_IsInterfaceImplemented_I32_I32_I32_I32_I32_RetVoid } }, { 3422156547, "LoadAssembly#3:System.Private.CoreLib:Internal.Runtime.InteropServices:ComponentActivator", { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssembly_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssembly_I32_I32_I32_RetI32 } }, { 542185314, "LoadAssemblyAndGetFunctionPointer#6:System.Private.CoreLib:Internal.Runtime.InteropServices:ComponentActivator", { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssemblyAndGetFunctionPointer_I32_I32_I32_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssemblyAndGetFunctionPointer_I32_I32_I32_I32_I32_I32_RetI32 } }, { 3765950975, "LoadAssemblyBytes#6:System.Private.CoreLib:Internal.Runtime.InteropServices:ComponentActivator", { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssemblyBytes_I32_I32_I32_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssemblyBytes_I32_I32_I32_I32_I32_I32_RetI32 } }, + { 1086681967, "LoadLibraryCallbackStub#5:System.Private.CoreLib:System.Runtime.InteropServices:NativeLibrary", { &MD_System_Private_CoreLib_System_Runtime_InteropServices_NativeLibrary_LoadLibraryCallbackStub_I32_I32_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_System_Runtime_InteropServices_NativeLibrary_LoadLibraryCallbackStub_I32_I32_I32_I32_I32_RetI32 } }, { 705270488, "ManagedStartup#2:System.Private.CoreLib:System:StartupHookProvider", { &MD_System_Private_CoreLib_System_StartupHookProvider_ManagedStartup_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_StartupHookProvider_ManagedStartup_I32_I32_RetVoid } }, { 343912841, "NewExternalTypeEntry#2:System.Private.CoreLib:System.Runtime.InteropServices:TypeMapLazyDictionary", { &MD_System_Private_CoreLib_System_Runtime_InteropServices_TypeMapLazyDictionary_NewExternalTypeEntry_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_System_Runtime_InteropServices_TypeMapLazyDictionary_NewExternalTypeEntry_I32_I32_RetI32 } }, { 3515006989, "NewPrecachedExternalTypeMap#1:System.Private.CoreLib:System.Runtime.InteropServices:TypeMapLazyDictionary", { &MD_System_Private_CoreLib_System_Runtime_InteropServices_TypeMapLazyDictionary_NewPrecachedExternalTypeMap_I32_RetI32, (void*)&Call_System_Private_CoreLib_System_Runtime_InteropServices_TypeMapLazyDictionary_NewPrecachedExternalTypeMap_I32_RetI32 } }, @@ -871,16 +1101,22 @@ const ReverseThunkMapEntry g_ReverseThunks[] = { 3308959471, "OnFirstChanceException#2:System.Private.CoreLib:System:AppContext", { &MD_System_Private_CoreLib_System_AppContext_OnFirstChanceException_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_AppContext_OnFirstChanceException_I32_I32_RetVoid } }, { 3570701864, "OnProcessExit#1:System.Private.CoreLib:System:AppContext", { &MD_System_Private_CoreLib_System_AppContext_OnProcessExit_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_AppContext_OnProcessExit_I32_RetVoid } }, { 2158495436, "OnResourceResolve#4:System.Private.CoreLib:System.Runtime.Loader:AssemblyLoadContext", { &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_OnResourceResolve_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_OnResourceResolve_I32_I32_I32_I32_RetVoid } }, + { 771783454, "OnThreadExiting#2:System.Private.CoreLib:System.Threading:Thread", { &MD_System_Private_CoreLib_System_Threading_Thread_OnThreadExiting_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Threading_Thread_OnThreadExiting_I32_I32_RetVoid } }, { 3572430398, "OnTypeResolve#4:System.Private.CoreLib:System.Runtime.Loader:AssemblyLoadContext", { &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_OnTypeResolve_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_OnTypeResolve_I32_I32_I32_I32_RetVoid } }, { 4206970338, "OnUnhandledException#2:System.Private.CoreLib:System:AppContext", { &MD_System_Private_CoreLib_System_AppContext_OnUnhandledException_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_AppContext_OnUnhandledException_I32_I32_RetVoid } }, + { 1873201650, "ParseAsAssemblySpec#3:System.Private.CoreLib:System.Reflection:AssemblyName", { &MD_System_Private_CoreLib_System_Reflection_AssemblyName_ParseAsAssemblySpec_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Reflection_AssemblyName_ParseAsAssemblySpec_I32_I32_I32_RetVoid } }, { 4239234100, "RegisterClassForTypeInternal#1:System.Private.CoreLib:Internal.Runtime.InteropServices:ComActivator", { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_RegisterClassForTypeInternal_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_RegisterClassForTypeInternal_I32_RetI32 } }, { 1403522766, "ReleaseJSOwnedObjectByGCHandle#1:System.Runtime.InteropServices.JavaScript:System.Runtime.InteropServices.JavaScript:JavaScriptExports", { &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_ReleaseJSOwnedObjectByGCHandle_I32_RetVoid, (void*)&Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_ReleaseJSOwnedObjectByGCHandle_I32_RetVoid } }, { 225437511, "Resolve#4:System.Private.CoreLib:System.Runtime.Loader:AssemblyLoadContext", { &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_Resolve_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_Resolve_I32_I32_I32_I32_RetVoid } }, { 260403842, "ResolveSatelliteAssembly#4:System.Private.CoreLib:System.Runtime.Loader:AssemblyLoadContext", { &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveSatelliteAssembly_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveSatelliteAssembly_I32_I32_I32_I32_RetVoid } }, { 426514126, "ResolveSignature#5:System.Private.CoreLib:System:Resolver", { &MD_System_Private_CoreLib_System_Resolver_ResolveSignature_I32_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Resolver_ResolveSignature_I32_I32_I32_I32_I32_RetVoid } }, { 2988924914, "ResolveToken#6:System.Private.CoreLib:System:Resolver", { &MD_System_Private_CoreLib_System_Resolver_ResolveToken_I32_I32_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Resolver_ResolveToken_I32_I32_I32_I32_I32_I32_RetVoid } }, + { 2195947930, "ResolveUnmanagedDll#3:System.Private.CoreLib:System.Runtime.Loader:AssemblyLoadContext", { &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDll_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDll_I32_I32_I32_RetI32 } }, + { 2050198231, "ResolveUnmanagedDllUsingEvent#4:System.Private.CoreLib:System.Runtime.Loader:AssemblyLoadContext", { &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDllUsingEvent_I32_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUnmanagedDllUsingEvent_I32_I32_I32_I32_RetI32 } }, { 2533042349, "ResolveUsingEvent#4:System.Private.CoreLib:System.Runtime.Loader:AssemblyLoadContext", { &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUsingEvent_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_ResolveUsingEvent_I32_I32_I32_I32_RetVoid } }, { 1963568864, "Setup#4:System.Private.CoreLib:System:AppContext", { &MD_System_Private_CoreLib_System_AppContext_Setup_I32_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_AppContext_Setup_I32_I32_I32_I32_RetVoid } }, + { 1343309100, "StartAssemblyLoad#3:System.Private.CoreLib:System.Runtime.Loader:AssemblyLoadContext", { &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StartAssemblyLoad_I32_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StartAssemblyLoad_I32_I32_I32_RetVoid } }, + { 3495913109, "StopAssemblyLoad#2:System.Private.CoreLib:System.Runtime.Loader:AssemblyLoadContext", { &MD_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StopAssemblyLoad_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Runtime_Loader_AssemblyLoadContext_StopAssemblyLoad_I32_I32_RetVoid } }, { 167179540, "TimerHandler#0:System.Private.CoreLib:System.Threading:TimerQueue", { &MD_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler_Void_RetVoid, (void*)&Call_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler_Void_RetVoid } }, { 2150642223, "UnregisterClassForTypeInternal#1:System.Private.CoreLib:Internal.Runtime.InteropServices:ComActivator", { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_UnregisterClassForTypeInternal_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_UnregisterClassForTypeInternal_I32_RetI32 } } }; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/AutoreleasePool.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/AutoreleasePool.cs index 59cabf533971c4..ea3e899db2b6e5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/AutoreleasePool.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/AutoreleasePool.cs @@ -51,5 +51,35 @@ internal static void DrainAutoreleasePool() s_AutoreleasePoolInstance = IntPtr.Zero; } } + +#if CORECLR + [System.Runtime.InteropServices.UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void CreateAutoreleasePool(Exception* pException) + { + try + { + CreateAutoreleasePool(); + } + catch (Exception ex) + { + *pException = ex; + } + } + + [System.Runtime.InteropServices.UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void DrainAutoreleasePool(Exception* pException) + { + try + { + DrainAutoreleasePool(); + } + catch (Exception ex) + { + *pException = ex; + } + } +#endif } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs index b27d337e23fabb..2efdad100f59c8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; using System.Runtime.CompilerServices; @@ -876,6 +877,22 @@ internal void InitializeForMonitor(int managedThreadId, uint recursionCount) Debug.Assert(!new State(this).UseTrivialWaits); } +#if CORECLR + [System.Runtime.InteropServices.UnmanagedCallersOnly] + [RequiresUnsafe] + private static unsafe void InitializeForMonitor(Lock* pLock, int managedThreadId, uint recursionCount, Exception* pException) + { + try + { + pLock->InitializeForMonitor(managedThreadId, recursionCount); + } + catch (Exception ex) + { + *pException = ex; + } + } +#endif + private static short DetermineMaxSpinCount() { if (IsSingleProcessor)