diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/QCallHandles.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/QCallHandles.cs index 29e39d69d3303d..e12808600c45d8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/QCallHandles.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/QCallHandles.cs @@ -75,7 +75,7 @@ internal unsafe ref struct QCallAssembly internal QCallAssembly(ref System.Reflection.RuntimeAssembly assembly) { _ptr = Unsafe.AsPointer(ref assembly); - _assembly = assembly.GetUnderlyingNativeHandle(); + _assembly = assembly?.GetUnderlyingNativeHandle() ?? IntPtr.Zero; } } @@ -88,10 +88,7 @@ internal unsafe ref struct QCallTypeHandle internal QCallTypeHandle(ref System.RuntimeType type) { _ptr = Unsafe.AsPointer(ref type); - if (type != null) - _handle = type.GetUnderlyingNativeHandle(); - else - _handle = IntPtr.Zero; + _handle = type?.GetUnderlyingNativeHandle() ?? IntPtr.Zero; } internal QCallTypeHandle(ref System.RuntimeTypeHandle rth) diff --git a/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs index 138e869ac58a65..b8960fa9757730 100644 --- a/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs @@ -146,7 +146,7 @@ public static Delegate CreateDelegate(Type type, object? firstArgument, MethodIn return null; } - Delegate? d = CreateDelegate_internal(type, firstArgument, method, throwOnBindFailure); + Delegate? d = CreateDelegate_internal(new QCallTypeHandle(ref rtType), firstArgument, method, throwOnBindFailure); if (d != null) { d.original_method_info = method; @@ -180,7 +180,7 @@ public static Delegate CreateDelegate(Type type, object? firstArgument, MethodIn return null; } - return CreateDelegate_internal(type, target, info, throwOnBindFailure); + return CreateDelegate_internal(new QCallTypeHandle(ref rtType), target, info, throwOnBindFailure); } public static Delegate? CreateDelegate(Type type, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type target, string method, bool ignoreCase, bool throwOnBindFailure) @@ -211,7 +211,7 @@ public static Delegate CreateDelegate(Type type, object? firstArgument, MethodIn return null; } - return CreateDelegate_internal(type, null, info, throwOnBindFailure); + return CreateDelegate_internal(new QCallTypeHandle(ref rtType), null, info, throwOnBindFailure); } // GetCandidateMethod is annotated as DynamicallyAccessedMemberTypes.All because it will bind to non-public methods @@ -578,7 +578,7 @@ private static bool InternalEqualTypes(object source, object value) private protected static extern MulticastDelegate AllocDelegateLike_internal(Delegate d); [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static extern Delegate? CreateDelegate_internal(Type type, object? target, MethodInfo info, bool throwOnBindFailure); + private static extern Delegate? CreateDelegate_internal(QCallTypeHandle type, object? target, MethodInfo info, bool throwOnBindFailure); [MethodImplAttribute(MethodImplOptions.InternalCall)] private extern MethodInfo GetVirtualMethod_internal(); diff --git a/src/mono/System.Private.CoreLib/src/System/Enum.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Enum.Mono.cs index 6115ca3d99d8d3..765a2865f60ceb 100644 --- a/src/mono/System.Private.CoreLib/src/System/Enum.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Enum.Mono.cs @@ -9,16 +9,36 @@ namespace System public partial class Enum { [MethodImpl(MethodImplOptions.InternalCall)] - private static extern bool GetEnumValuesAndNames(RuntimeType enumType, out ulong[] values, out string[] names); + private static extern bool GetEnumValuesAndNames(QCallTypeHandle enumType, out ulong[] values, out string[] names); [MethodImpl(MethodImplOptions.InternalCall)] - private static extern object InternalBoxEnum(RuntimeType enumType, long value); + private static extern void InternalBoxEnum(QCallTypeHandle enumType, ObjectHandleOnStack res, long value); [MethodImpl(MethodImplOptions.InternalCall)] - private extern CorElementType InternalGetCorElementType(); + private static extern CorElementType InternalGetCorElementType(QCallTypeHandle enumType); [MethodImpl(MethodImplOptions.InternalCall)] - internal static extern RuntimeType InternalGetUnderlyingType(RuntimeType enumType); + private static extern void InternalGetUnderlyingType(QCallTypeHandle enumType, ObjectHandleOnStack res); + + private static object InternalBoxEnum(RuntimeType enumType, long value) + { + object? res = null; + InternalBoxEnum(new QCallTypeHandle(ref enumType), ObjectHandleOnStack.Create(ref res), value); + return res!; + } + + private CorElementType InternalGetCorElementType() + { + RuntimeType this_type = (RuntimeType)GetType(); + return InternalGetCorElementType(new QCallTypeHandle(ref this_type)); + } + + internal static RuntimeType InternalGetUnderlyingType(RuntimeType enumType) + { + RuntimeType? res = null; + InternalGetUnderlyingType(new QCallTypeHandle(ref enumType), ObjectHandleOnStack.Create(ref res)); + return res!; + } private static EnumInfo GetEnumInfo(RuntimeType enumType, bool getNames = true) { @@ -26,7 +46,7 @@ private static EnumInfo GetEnumInfo(RuntimeType enumType, bool getNames = true) if (entry == null || (getNames && entry.Names == null)) { - if (!GetEnumValuesAndNames(enumType, out ulong[]? values, out string[]? names)) + if (!GetEnumValuesAndNames(new QCallTypeHandle(ref enumType), out ulong[]? values, out string[]? names)) Array.Sort(values, names, Collections.Generic.Comparer.Default); bool hasFlagsAttribute = enumType.IsDefined(typeof(FlagsAttribute), inherit: false); diff --git a/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs index 5cf723dc60aed5..bbb27fb36a1de6 100644 --- a/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs @@ -141,7 +141,7 @@ public static IntPtr AllocateTypeAssociatedMemory(Type type, int size) internal static bool ObjectHasReferences(object obj) { // TODO: Missing intrinsic in interpreter - return RuntimeTypeHandle.HasReferences(obj.GetType() as RuntimeType); + return RuntimeTypeHandle.HasReferences((obj.GetType() as RuntimeType)!); } public static object GetUninitializedObject( diff --git a/src/mono/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs index 5b42f03154612f..14989a5fedb72c 100644 --- a/src/mono/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs @@ -39,13 +39,14 @@ public partial class Marshal public static extern void StructureToPtr(object structure, IntPtr ptr, bool fDeleteOld); [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static extern bool IsPinnableType(Type type); + private static extern bool IsPinnableType(QCallTypeHandle type); internal static bool IsPinnable(object? obj) { if (obj == null || obj is string) return true; - return IsPinnableType(obj.GetType()); + var type = (obj.GetType() as RuntimeType)!; + return IsPinnableType(new QCallTypeHandle(ref type)); //Type type = obj.GetType (); //return !type.IsValueType || RuntimeTypeHandle.HasReferences (type as RuntimeType); } @@ -73,16 +74,30 @@ private static void PtrToStructureHelper(IntPtr ptr, object? structure, bool all } [MethodImpl(MethodImplOptions.InternalCall)] - private static extern Delegate GetDelegateForFunctionPointerInternal(IntPtr ptr, Type t); + private static extern void GetDelegateForFunctionPointerInternal(QCallTypeHandle t, IntPtr ptr, ObjectHandleOnStack res); [MethodImpl(MethodImplOptions.InternalCall)] private static extern IntPtr GetFunctionPointerForDelegateInternal(Delegate d); + private static Delegate GetDelegateForFunctionPointerInternal(IntPtr ptr, Type t) + { + RuntimeType rttype = (RuntimeType)t; + Delegate? res = null; + GetDelegateForFunctionPointerInternal(new QCallTypeHandle(ref rttype), ptr, ObjectHandleOnStack.Create(ref res)); + return res!; + } + [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern void PrelinkInternal(MethodInfo m); [MethodImpl(MethodImplOptions.InternalCall)] - private static extern int SizeOfHelper(Type t, bool throwIfNotMarshalable); + private static extern int SizeOfHelper(QCallTypeHandle t, bool throwIfNotMarshalable); + + private static int SizeOfHelper(Type t, bool throwIfNotMarshalable) + { + RuntimeType rttype = (RuntimeType)t; + return SizeOfHelper(new QCallTypeHandle(ref rttype), throwIfNotMarshalable); + } public static IntPtr GetExceptionPointers() { diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs index 21267d651bc115..289b471450cb66 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs @@ -1285,16 +1285,19 @@ public override GenericParameterAttributes GenericParameterAttributes internal RuntimeType[] GetGenericArgumentsInternal() { - return (RuntimeType[])GetGenericArgumentsInternal(true); + RuntimeType[]? res = null; + var this_type = this; + GetGenericArgumentsInternal(new QCallTypeHandle(ref this_type), ObjectHandleOnStack.Create(ref res), true); + return res!; } public override Type[] GetGenericArguments() { - Type[] types = GetGenericArgumentsInternal(false); - + Type[]? types = null; + var this_type = this; + GetGenericArgumentsInternal(new QCallTypeHandle(ref this_type), ObjectHandleOnStack.Create(ref types), false); if (types == null) types = Type.EmptyTypes; - return types; } @@ -1309,7 +1312,9 @@ public override Type MakeGenericType(Type[] instantiation) if (!IsGenericTypeDefinition) throw new InvalidOperationException(SR.Format(SR.Arg_NotGenericTypeDefinition, this)); - if (GetGenericArguments().Length != instantiation.Length) + RuntimeType[] genericParameters = GetGenericArgumentsInternal(); + + if (genericParameters.Length != instantiation.Length) throw new ArgumentException(SR.Argument_GenericArgsCount, nameof(instantiation)); for (int i = 0; i < instantiation.Length; i++) @@ -1336,11 +1341,10 @@ public override Type MakeGenericType(Type[] instantiation) instantiationRuntimeType[i] = rtInstantiationElem; } - RuntimeType[] genericParameters = GetGenericArgumentsInternal(); - SanityCheckGenericArguments(instantiationRuntimeType, genericParameters); - Type? ret = MakeGenericType(this, instantiationRuntimeType); + Type? ret = null; + MakeGenericType(this, instantiationRuntimeType, ObjectHandleOnStack.Create(ref ret)); if (ret == null) throw new TypeLoadException(); return ret; @@ -1353,7 +1357,8 @@ public override int GenericParameterPosition if (!IsGenericParameter) throw new InvalidOperationException(SR.Arg_NotGenericParameter); - return GetGenericParameterPosition(); + var this_type = this; + return GetGenericParameterPosition(new QCallTypeHandle(ref this_type)); } } @@ -1566,23 +1571,22 @@ internal RuntimeType(object obj) } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private extern MethodInfo GetCorrespondingInflatedMethod(MethodInfo generic); - - [MethodImplAttribute(MethodImplOptions.InternalCall)] - private extern ConstructorInfo GetCorrespondingInflatedConstructor(ConstructorInfo generic); + private static extern MemberInfo GetCorrespondingInflatedMethod(QCallTypeHandle type, MemberInfo generic); internal override MethodInfo GetMethod(MethodInfo fromNoninstanciated) { if (fromNoninstanciated == null) throw new ArgumentNullException(nameof(fromNoninstanciated)); - return GetCorrespondingInflatedMethod(fromNoninstanciated); + var this_type = this; + return (MethodInfo)GetCorrespondingInflatedMethod(new QCallTypeHandle(ref this_type), fromNoninstanciated); } internal override ConstructorInfo GetConstructor(ConstructorInfo fromNoninstanciated) { if (fromNoninstanciated == null) throw new ArgumentNullException(nameof(fromNoninstanciated)); - return GetCorrespondingInflatedConstructor(fromNoninstanciated); + var this_type = this; + return (ConstructorInfo)GetCorrespondingInflatedMethod(new QCallTypeHandle(ref this_type), fromNoninstanciated); } [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2085:UnrecognizedReflectionPattern", @@ -1633,8 +1637,10 @@ internal override FieldInfo GetField(FieldInfo fromNoninstanciated) if (ReferenceEquals(elementType, typeof(TypedReference)) || ReferenceEquals(elementType, typeof(RuntimeArgumentHandle))) throw new NotSupportedException("NotSupported_ContainsStackPtr"); - if (IsValueType) - return CreateInstanceInternal(this); + if (IsValueType) { + var this_type = this; + return CreateInstanceInternal(new QCallTypeHandle(ref this_type)); + } throw new MissingMethodException(SR.Format(SR.Arg_NoDefCTor, this)); } @@ -1874,11 +1880,14 @@ internal override FieldInfo GetField(FieldInfo fromNoninstanciated) } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private extern Type make_array_type(int rank); + private static extern void make_array_type(QCallTypeHandle type, int rank, ObjectHandleOnStack res); public override Type MakeArrayType() { - return make_array_type(0); + Type? type = null; + var base_type = this; + make_array_type(new QCallTypeHandle(ref base_type), 0, ObjectHandleOnStack.Create(ref type)); + return type!; } public override Type MakeArrayType(int rank) @@ -1886,27 +1895,36 @@ public override Type MakeArrayType(int rank) if (rank < 1) throw new IndexOutOfRangeException(); - return make_array_type(rank); + Type? type = null; + var base_type = this; + make_array_type(new QCallTypeHandle(ref base_type), rank, ObjectHandleOnStack.Create(ref type)); + return type!; } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private extern Type make_byref_type(); + private static extern void make_byref_type(QCallTypeHandle type, ObjectHandleOnStack res); public override Type MakeByRefType() { if (IsByRef) throw new TypeLoadException("Can not call MakeByRefType on a ByRef type"); - return make_byref_type(); + Type? type = null; + var base_type = this; + make_byref_type(new QCallTypeHandle(ref base_type), ObjectHandleOnStack.Create(ref type)); + return type!; } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static extern Type MakePointerType(Type type); + private static extern void make_pointer_type(QCallTypeHandle type, ObjectHandleOnStack res); public override Type MakePointerType() { if (IsByRef) throw new TypeLoadException($"Could not load type '{GetType()}' from assembly '{AssemblyQualifiedName}"); - return MakePointerType(this); + Type? type = null; + var base_type = this; + make_pointer_type(new QCallTypeHandle(ref base_type), ObjectHandleOnStack.Create(ref type)); + return type!; } public override StructLayoutAttribute? StructLayoutAttribute @@ -1953,27 +1971,29 @@ internal static object CreateInstanceForAnotherGenericParameter( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type genericType, RuntimeType genericArgument) { - var gt = (RuntimeType)MakeGenericType(genericType, new Type[] { genericArgument }); - RuntimeConstructorInfo? ctor = gt.GetDefaultConstructor(); + RuntimeType? gt = null; + MakeGenericType(genericType, new Type[] { genericArgument }, ObjectHandleOnStack.Create(ref gt)); + RuntimeConstructorInfo? ctor = gt!.GetDefaultConstructor(); // CreateInstanceForAnotherGenericParameter requires type to have a public parameterless constructor so it can be annotated for trimming without preserving private constructors. if (ctor is null || !ctor.IsPublic) - throw new MissingMethodException(SR.Format(SR.Arg_NoDefCTor, gt)); + throw new MissingMethodException(SR.Format(SR.Arg_NoDefCTor, gt!)); return ctor.InvokeCtorWorker(BindingFlags.Default, Span.Empty)!; } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static extern Type MakeGenericType(Type gt, Type[] types); + private static extern void MakeGenericType(Type gt, Type[] types, ObjectHandleOnStack res); [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal extern IntPtr GetMethodsByName_native(IntPtr namePtr, BindingFlags bindingAttr, MemberListType listType); + internal static extern IntPtr GetMethodsByName_native(QCallTypeHandle type, IntPtr namePtr, BindingFlags bindingAttr, MemberListType listType); internal RuntimeMethodInfo[] GetMethodsByName(string? name, BindingFlags bindingAttr, MemberListType listType, RuntimeType reflectedType) { + var this_type = this; var refh = new RuntimeTypeHandle(reflectedType); using (var namePtr = new Mono.SafeStringMarshal(name)) - using (var h = new Mono.SafeGPtrArrayHandle(GetMethodsByName_native(namePtr.Value, bindingAttr, listType))) + using (var h = new Mono.SafeGPtrArrayHandle(GetMethodsByName_native(new QCallTypeHandle(ref this_type), namePtr.Value, bindingAttr, listType))) { int n = h.Length; var a = new RuntimeMethodInfo[n]; @@ -1987,15 +2007,16 @@ internal RuntimeMethodInfo[] GetMethodsByName(string? name, BindingFlags binding } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private extern IntPtr GetPropertiesByName_native(IntPtr name, BindingFlags bindingAttr, MemberListType listType); + private static extern IntPtr GetPropertiesByName_native(QCallTypeHandle type, IntPtr name, BindingFlags bindingAttr, MemberListType listType); [MethodImplAttribute(MethodImplOptions.InternalCall)] - private extern IntPtr GetConstructors_native(BindingFlags bindingAttr); + private static extern IntPtr GetConstructors_native(QCallTypeHandle type, BindingFlags bindingAttr); private RuntimeConstructorInfo[] GetConstructors_internal(BindingFlags bindingAttr, RuntimeType reflectedType) { var refh = new RuntimeTypeHandle(reflectedType); - using (var h = new Mono.SafeGPtrArrayHandle(GetConstructors_native(bindingAttr))) + var this_type = this; + using (var h = new Mono.SafeGPtrArrayHandle(GetConstructors_native(new QCallTypeHandle(ref this_type), bindingAttr))) { int n = h.Length; var a = new RuntimeConstructorInfo[n]; @@ -2011,8 +2032,9 @@ private RuntimeConstructorInfo[] GetConstructors_internal(BindingFlags bindingAt private RuntimePropertyInfo[] GetPropertiesByName(string? name, BindingFlags bindingAttr, MemberListType listType, RuntimeType reflectedType) { var refh = new RuntimeTypeHandle(reflectedType); + var this_type = this; using (var namePtr = new Mono.SafeStringMarshal(name)) - using (var h = new Mono.SafeGPtrArrayHandle(GetPropertiesByName_native(namePtr.Value, bindingAttr, listType))) + using (var h = new Mono.SafeGPtrArrayHandle(GetPropertiesByName_native(new QCallTypeHandle(ref this_type), namePtr.Value, bindingAttr, listType))) { int n = h.Length; var a = new RuntimePropertyInfo[n]; @@ -2043,9 +2065,10 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn throw new ArgumentException("Argument must be an interface.", nameof(ifaceType)); if (IsInterface) throw new ArgumentException("'this' type cannot be an interface itself"); + var this_type = this; res.TargetType = this; res.InterfaceType = ifaceType; - GetInterfaceMapData(this, ifaceType, out res.TargetMethods, out res.InterfaceMethods); + GetInterfaceMapData(new QCallTypeHandle(ref this_type), new QCallTypeHandle(ref ifaceRtType), out res.TargetMethods, out res.InterfaceMethods); if (res.TargetMethods == null) throw new ArgumentException("Interface not found", nameof(ifaceType)); @@ -2053,7 +2076,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static extern void GetInterfaceMapData(Type t, Type iface, out MethodInfo[] targets, out MethodInfo[] methods); + private static extern void GetInterfaceMapData(QCallTypeHandle t, QCallTypeHandle iface, out MethodInfo[] targets, out MethodInfo[] methods); public override Guid GUID { @@ -2067,7 +2090,13 @@ public override Guid GUID } [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal extern void GetPacking(out int packing, out int size); + private static extern void GetPacking(QCallTypeHandle type, out int packing, out int size); + + internal void GetPacking(out int packing, out int size) + { + var this_type = this; + GetPacking(new QCallTypeHandle(ref this_type), out packing, out size); + } public override string ToString() { @@ -2075,19 +2104,35 @@ public override string ToString() } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static extern object CreateInstanceInternal(Type type); + private static extern object CreateInstanceInternal(QCallTypeHandle type); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private static extern void GetDeclaringMethod(QCallTypeHandle type, ObjectHandleOnStack res); - public extern override MethodBase? DeclaringMethod + public override MethodBase? DeclaringMethod { - [MethodImplAttribute(MethodImplOptions.InternalCall)] - get; + get + { + var this_type = this; + MethodBase? res = null; + GetDeclaringMethod(new QCallTypeHandle(ref this_type), ObjectHandleOnStack.Create(ref res)); + return res; + } } [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal extern string getFullName(bool full_name, bool assembly_qualified); + internal static extern void getFullName(QCallTypeHandle type, ObjectHandleOnStack res, bool full_name, bool assembly_qualified); [MethodImplAttribute(MethodImplOptions.InternalCall)] - private extern Type[] GetGenericArgumentsInternal(bool runtimeArray); + private static extern void GetGenericArgumentsInternal(QCallTypeHandle type, ObjectHandleOnStack res, bool runtimeArray); + + internal string getFullName(bool full_name, bool assembly_qualified) + { + var this_type = this; + string? res = null; + getFullName(new QCallTypeHandle(ref this_type), ObjectHandleOnStack.Create(ref res), full_name, assembly_qualified); + return res!; + } private GenericParameterAttributes GetGenericParameterAttributes() { @@ -2095,19 +2140,20 @@ private GenericParameterAttributes GetGenericParameterAttributes() } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private extern int GetGenericParameterPosition(); + private static extern int GetGenericParameterPosition(QCallTypeHandle type); [MethodImplAttribute(MethodImplOptions.InternalCall)] - private extern IntPtr GetEvents_native(IntPtr name, MemberListType listType); + private static extern IntPtr GetEvents_native(QCallTypeHandle type, IntPtr name, MemberListType listType); [MethodImplAttribute(MethodImplOptions.InternalCall)] - private extern IntPtr GetFields_native(IntPtr name, BindingFlags bindingAttr, MemberListType listType); + private static extern IntPtr GetFields_native(QCallTypeHandle type, IntPtr name, BindingFlags bindingAttr, MemberListType listType); private RuntimeFieldInfo[] GetFields_internal(string? name, BindingFlags bindingAttr, MemberListType listType, RuntimeType reflectedType) { var refh = new RuntimeTypeHandle(reflectedType); + var this_type = this; using (var namePtr = new Mono.SafeStringMarshal(name)) - using (var h = new Mono.SafeGPtrArrayHandle(GetFields_native(namePtr.Value, bindingAttr, listType))) + using (var h = new Mono.SafeGPtrArrayHandle(GetFields_native(new QCallTypeHandle(ref this_type), namePtr.Value, bindingAttr, listType))) { int n = h.Length; var a = new RuntimeFieldInfo[n]; @@ -2123,8 +2169,9 @@ private RuntimeFieldInfo[] GetFields_internal(string? name, BindingFlags binding private RuntimeEventInfo[] GetEvents_internal(string? name, MemberListType listType, RuntimeType reflectedType) { var refh = new RuntimeTypeHandle(reflectedType); + var this_type = this; using (var namePtr = new Mono.SafeStringMarshal(name)) - using (var h = new Mono.SafeGPtrArrayHandle(GetEvents_native(namePtr.Value, listType))) + using (var h = new Mono.SafeGPtrArrayHandle(GetEvents_native(new QCallTypeHandle(ref this_type), namePtr.Value, listType))) { int n = h.Length; var a = new RuntimeEventInfo[n]; @@ -2137,20 +2184,29 @@ private RuntimeEventInfo[] GetEvents_internal(string? name, MemberListType listT } } - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] [MethodImplAttribute(MethodImplOptions.InternalCall)] - public extern override Type[] GetInterfaces(); + private static extern void GetInterfaces(QCallTypeHandle type, ObjectHandleOnStack res); + + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] + public override Type[] GetInterfaces() + { + var this_type = this; + Type[]? res = null; + GetInterfaces(new QCallTypeHandle(ref this_type), ObjectHandleOnStack.Create(ref res)); + return res!; + } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private extern IntPtr GetNestedTypes_native(IntPtr name, BindingFlags bindingAttr, MemberListType listType); + private static extern IntPtr GetNestedTypes_native(QCallTypeHandle type, IntPtr name, BindingFlags bindingAttr, MemberListType listType); private RuntimeType[] GetNestedTypes_internal(string? displayName, BindingFlags bindingAttr, MemberListType listType) { string? internalName = null; if (displayName != null) internalName = displayName; + var this_type = this; using (var namePtr = new Mono.SafeStringMarshal(internalName)) - using (var h = new Mono.SafeGPtrArrayHandle(GetNestedTypes_native(namePtr.Value, bindingAttr, listType))) + using (var h = new Mono.SafeGPtrArrayHandle(GetNestedTypes_native(new QCallTypeHandle(ref this_type), namePtr.Value, bindingAttr, listType))) { int n = h.Length; var a = new RuntimeType[n]; @@ -2171,22 +2227,46 @@ public override string? AssemblyQualifiedName } } - public extern override Type? DeclaringType + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private static extern void GetDeclaringType(QCallTypeHandle type, ObjectHandleOnStack res); + + public override Type? DeclaringType { - [MethodImplAttribute(MethodImplOptions.InternalCall)] - get; + get + { + var this_type = this; + Type? res = null; + GetDeclaringType(new QCallTypeHandle(ref this_type), ObjectHandleOnStack.Create(ref res)); + return res; + } } - public extern override string Name + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private static extern void GetName(QCallTypeHandle type, ObjectHandleOnStack res); + + public override string Name { - [MethodImplAttribute(MethodImplOptions.InternalCall)] - get; + get + { + var this_type = this; + string? res = null; + GetName(new QCallTypeHandle(ref this_type), ObjectHandleOnStack.Create(ref res)); + return res!; + } } - public extern override string? Namespace + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private static extern void GetNamespace(QCallTypeHandle type, ObjectHandleOnStack res); + + public override string Namespace { - [MethodImplAttribute(MethodImplOptions.InternalCall)] - get; + get + { + var this_type = this; + string? res = null; + GetNamespace(new QCallTypeHandle(ref this_type), ObjectHandleOnStack.Create(ref res)); + return res!; + } } public override string? FullName diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs index 34f47d66757c04..18bac579db4b37 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs @@ -111,7 +111,12 @@ public override int GetHashCode() } [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern TypeAttributes GetAttributes(RuntimeType type); + internal static extern TypeAttributes GetAttributes(QCallTypeHandle type); + + internal static TypeAttributes GetAttributes(RuntimeType type) + { + return GetAttributes(new QCallTypeHandle(ref type)); + } public ModuleHandle GetModuleHandle() { @@ -125,19 +130,24 @@ public ModuleHandle GetModuleHandle() } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static extern int GetMetadataToken(RuntimeType type); + private static extern int GetMetadataToken(QCallTypeHandle type); internal static int GetToken(RuntimeType type) { - return GetMetadataToken(type); + return GetMetadataToken(new QCallTypeHandle(ref type)); } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static extern Type GetGenericTypeDefinition_impl(RuntimeType type); + private static extern void GetGenericTypeDefinition_impl(QCallTypeHandle type, ObjectHandleOnStack res); internal static Type GetGenericTypeDefinition(RuntimeType type) { - return GetGenericTypeDefinition_impl(type); + Type? res = null; + GetGenericTypeDefinition_impl(new QCallTypeHandle(ref type), ObjectHandleOnStack.Create (ref res)); + if (res == null) + // The icall returns null if TYPE is a gtd + return type; + return res!; } internal static bool IsPrimitive(RuntimeType type) @@ -182,23 +192,43 @@ internal static bool HasElementType(RuntimeType type) } [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern CorElementType GetCorElementType(RuntimeType type); + internal static extern CorElementType GetCorElementType(QCallTypeHandle type); [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern bool HasInstantiation(RuntimeType type); + internal static extern bool HasInstantiation(QCallTypeHandle type); [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern bool IsComObject(RuntimeType type); + internal static extern bool IsComObject(QCallTypeHandle type); [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern bool IsInstanceOfType(RuntimeType type, [NotNullWhen(true)] object? o); + internal static extern bool IsInstanceOfType(QCallTypeHandle type, [NotNullWhen(true)] object? o); + + internal static bool IsInstanceOfType(RuntimeType type, [NotNullWhen(true)] object? o) + { + return IsInstanceOfType(new QCallTypeHandle(ref type), o); + } [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern bool HasReferences(RuntimeType? type); + internal static extern bool HasReferences(QCallTypeHandle type); + + internal static bool HasReferences(RuntimeType type) + { + return HasReferences(new QCallTypeHandle(ref type)); + } + + internal static CorElementType GetCorElementType(RuntimeType type) + { + return GetCorElementType (new QCallTypeHandle(ref type)); + } + + internal static bool HasInstantiation(RuntimeType type) + { + return HasInstantiation (new QCallTypeHandle(ref type)); + } internal static bool IsComObject(RuntimeType type, bool isGenericCOM) { - return isGenericCOM ? false : IsComObject(type); + return isGenericCOM ? false : IsComObject(new QCallTypeHandle(ref type)); } internal static bool IsContextful(RuntimeType type) @@ -218,73 +248,120 @@ internal static bool IsInterface(RuntimeType type) } [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern int GetArrayRank(RuntimeType type); + internal static extern int GetArrayRank(QCallTypeHandle type); [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern RuntimeAssembly GetAssembly(RuntimeType type); + internal static extern void GetAssembly(QCallTypeHandle type, ObjectHandleOnStack res); [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern RuntimeType GetElementType(RuntimeType type); + internal static extern void GetElementType(QCallTypeHandle type, ObjectHandleOnStack res); [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern RuntimeModule GetModule(RuntimeType type); + internal static extern void GetModule(QCallTypeHandle type, ObjectHandleOnStack res); [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern bool IsGenericVariable(RuntimeType type); + internal static extern void GetBaseType(QCallTypeHandle type, ObjectHandleOnStack res); - [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern RuntimeType GetBaseType(RuntimeType type); + internal static int GetArrayRank(RuntimeType type) + { + return GetArrayRank(new QCallTypeHandle (ref type)); + } + + internal static RuntimeAssembly GetAssembly(RuntimeType type) + { + RuntimeAssembly? res = null; + GetAssembly(new QCallTypeHandle(ref type), ObjectHandleOnStack.Create(ref res)); + return res!; + } + + internal static RuntimeModule GetModule(RuntimeType type) + { + RuntimeModule? res = null; + GetModule(new QCallTypeHandle(ref type), ObjectHandleOnStack.Create(ref res)); + return res!; + } + + internal static RuntimeType GetElementType(RuntimeType type) + { + RuntimeType? res = null; + GetElementType(new QCallTypeHandle(ref type), ObjectHandleOnStack.Create(ref res)); + return res!; + } + + internal static RuntimeType GetBaseType(RuntimeType type) + { + RuntimeType? res = null; + GetBaseType(new QCallTypeHandle(ref type), ObjectHandleOnStack.Create(ref res)); + return res!; + } internal static bool CanCastTo(RuntimeType type, RuntimeType target) { - return type_is_assignable_from(target, type); + return type_is_assignable_from(new QCallTypeHandle(ref target), new QCallTypeHandle(ref type)); + } + + internal static bool IsGenericVariable(RuntimeType type) + { + CorElementType corElemType = GetCorElementType(type); + return corElemType == CorElementType.ELEMENT_TYPE_VAR || corElemType == CorElementType.ELEMENT_TYPE_MVAR; } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static extern bool type_is_assignable_from(Type a, Type b); + private static extern bool type_is_assignable_from(QCallTypeHandle a, QCallTypeHandle b); [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern bool IsGenericTypeDefinition(RuntimeType type); + internal static extern bool IsGenericTypeDefinition(QCallTypeHandle type); [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern IntPtr GetGenericParameterInfo(RuntimeType type); + internal static extern IntPtr GetGenericParameterInfo(QCallTypeHandle type); + + internal static bool IsGenericTypeDefinition(RuntimeType type) + { + return IsGenericTypeDefinition(new QCallTypeHandle(ref type)); + } + + internal static IntPtr GetGenericParameterInfo(RuntimeType type) + { + return GetGenericParameterInfo(new QCallTypeHandle(ref type)); + } internal static bool IsSubclassOf(RuntimeType childType, RuntimeType baseType) { - return is_subclass_of(childType._impl.Value, baseType._impl.Value); + return is_subclass_of(new QCallTypeHandle(ref childType), new QCallTypeHandle(ref baseType)); } [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern bool is_subclass_of(IntPtr childType, IntPtr baseType); + internal static extern bool is_subclass_of(QCallTypeHandle childType, QCallTypeHandle baseType); [DynamicDependency("#ctor()", typeof(IsByRefLikeAttribute))] [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern bool IsByRefLike(RuntimeType type); + internal static extern bool IsByRefLike(QCallTypeHandle type); + + internal static bool IsByRefLike(RuntimeType type) + { + return IsByRefLike(new QCallTypeHandle(ref type)); + } internal static bool IsTypeDefinition(RuntimeType type) { - // That's how it has been done on CoreFX but we have no GetCorElementType method implementation - // see https://github.com/dotnet/coreclr/pull/11355 + CorElementType corElemType = GetCorElementType(type); + if (!((corElemType >= CorElementType.ELEMENT_TYPE_VOID && corElemType < CorElementType.ELEMENT_TYPE_PTR) || + corElemType == CorElementType.ELEMENT_TYPE_VALUETYPE || + corElemType == CorElementType.ELEMENT_TYPE_CLASS || + corElemType == CorElementType.ELEMENT_TYPE_TYPEDBYREF || + corElemType == CorElementType.ELEMENT_TYPE_I || + corElemType == CorElementType.ELEMENT_TYPE_U || + corElemType == CorElementType.ELEMENT_TYPE_OBJECT)) + return false; - // CorElementType corElemType = GetCorElementType (type); - // if (!((corElemType >= CorElementType.Void && corElemType < CorElementType.Ptr) || - // corElemType == CorElementType.ValueType || - // corElemType == CorElementType.Class || - // corElemType == CorElementType.TypedByRef || - // corElemType == CorElementType.I || - // corElemType == CorElementType.U || - // corElemType == CorElementType.Object)) - // return false; - // if (HasInstantiation (type) && !IsGenericTypeDefinition (type)) - // return false; - // return true; + if (HasInstantiation(type) && !IsGenericTypeDefinition(type)) + return false; - // It's like a workaround mentioned in https://github.com/dotnet/runtime/issues/20711 - return !type.HasElementType && !type.IsConstructedGenericType && !type.IsGenericParameter; + return true; } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static extern RuntimeType internal_from_name(string name, ref StackCrawlMark stackMark, Assembly? callerAssembly, bool throwOnError, bool ignoreCase); + private static extern void internal_from_name(IntPtr name, ref StackCrawlMark stackMark, ObjectHandleOnStack res, bool throwOnError, bool ignoreCase); [RequiresUnreferencedCode("Types might be removed")] internal static RuntimeType? GetTypeByName(string typeName, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark, @@ -299,9 +376,15 @@ internal static bool IsTypeDefinition(RuntimeType type) else return null; - RuntimeType? t = internal_from_name(typeName, ref stackMark, null, throwOnError, ignoreCase); - if (throwOnError && t == null) - throw new TypeLoadException("Error loading '" + typeName + "'"); + RuntimeType? t = null; + using (var namePtr = new Mono.SafeStringMarshal(typeName)) { + internal_from_name( + namePtr.Value, + ref stackMark, + ObjectHandleOnStack.Create (ref t), throwOnError, ignoreCase); + if (throwOnError && t == null) + throw new TypeLoadException("Error loading '" + typeName + "'"); + } return t; } diff --git a/src/mono/mono/metadata/handle.h b/src/mono/mono/metadata/handle.h index 0e43247971a061..5628d3b1792767 100644 --- a/src/mono/mono/metadata/handle.h +++ b/src/mono/mono/metadata/handle.h @@ -608,6 +608,13 @@ mono_handle_unsafe_field_addr (MonoObjectHandle h, MonoClassField *field) return MONO_HANDLE_SUPPRESS (((gchar *)MONO_HANDLE_RAW (h)) + field->offset); } +/* Matches ObjectHandleOnStack in managed code */ +typedef MonoObject **MonoObjectHandleOnStack; + +#define HANDLE_ON_STACK_SET(handle, obj) do { \ + *(handle) = (MonoObject*)obj; \ + } while (0) + //FIXME this should go somewhere else MonoStringHandle mono_string_new_handle (const char *data, MonoError *error); MonoArrayHandle mono_array_new_handle (MonoClass *eclass, uintptr_t n, MonoError *error); diff --git a/src/mono/mono/metadata/icall-decl.h b/src/mono/mono/metadata/icall-decl.h index 20cbe2723c97cc..d99cf1cee6c329 100644 --- a/src/mono/mono/metadata/icall-decl.h +++ b/src/mono/mono/metadata/icall-decl.h @@ -60,7 +60,6 @@ typedef enum { // This is sorted. // grep ICALL_EXPORT | sort | uniq ICALL_EXPORT MonoAssemblyName* ves_icall_System_Reflection_AssemblyName_GetNativeName (MonoAssembly*); -ICALL_EXPORT MonoBoolean ves_icall_RuntimeTypeHandle_is_subclass_of (MonoType*, MonoType*); ICALL_EXPORT MonoBoolean ves_icall_System_Reflection_AssemblyName_ParseAssemblyName (const char*, MonoAssemblyName*, MonoBoolean*, MonoBoolean* is_token_defined_arg); ICALL_EXPORT MonoBoolean ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_SufficientExecutionStack (void); ICALL_EXPORT MonoBoolean ves_icall_System_Threading_Thread_YieldInternal (void); @@ -190,4 +189,18 @@ ICALL_EXPORT void ves_icall_System_Runtime_Intrinsics_X86_X86Base___cpuidex (int ICALL_EXPORT void ves_icall_AssemblyExtensions_ApplyUpdate (MonoAssembly *assm, gconstpointer dmeta_bytes, int32_t dmeta_len, gconstpointer dil_bytes, int32_t dil_len, gconstpointer dpdb_bytes, int32_t dpdb_len); ICALL_EXPORT gint32 ves_icall_AssemblyExtensions_ApplyUpdateEnabled (gint32 just_component_check); +ICALL_EXPORT guint32 ves_icall_RuntimeTypeHandle_GetCorElementType (MonoQCallTypeHandle type_handle); + +ICALL_EXPORT MonoBoolean ves_icall_RuntimeTypeHandle_HasInstantiation (MonoQCallTypeHandle type_handle); + +ICALL_EXPORT guint32 ves_icall_RuntimeTypeHandle_GetAttributes (MonoQCallTypeHandle type_handle); + +ICALL_EXPORT MonoBoolean ves_icall_RuntimeTypeHandle_IsGenericTypeDefinition (MonoQCallTypeHandle type_handle); + +ICALL_EXPORT gint32 ves_icall_RuntimeType_GetGenericParameterPosition (MonoQCallTypeHandle type_handle); + +ICALL_EXPORT int ves_icall_System_Enum_InternalGetCorElementType (MonoQCallTypeHandle type_handle); + +ICALL_EXPORT MonoBoolean ves_icall_System_Runtime_InteropServices_Marshal_IsPinnableType (MonoQCallTypeHandle type_handle); + #endif // __MONO_METADATA_ICALL_DECL_H__ diff --git a/src/mono/mono/metadata/icall-def-netcore.h b/src/mono/mono/metadata/icall-def-netcore.h index 03d5403df0a835..f16c61677dedaa 100644 --- a/src/mono/mono/metadata/icall-def-netcore.h +++ b/src/mono/mono/metadata/icall-def-netcore.h @@ -38,7 +38,7 @@ NOHANDLES(ICALL(BUFFER_3, "__ZeroMemory", ves_icall_System_Runtime_RuntimeImport ICALL_TYPE(DELEGATE, "System.Delegate", DELEGATE_1) HANDLES(DELEGATE_1, "AllocDelegateLike_internal", ves_icall_System_Delegate_AllocDelegateLike_internal, MonoMulticastDelegate, 1, (MonoDelegate)) -HANDLES(DELEGATE_2, "CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal, MonoObject, 4, (MonoReflectionType, MonoObject, MonoReflectionMethod, MonoBoolean)) +HANDLES(DELEGATE_2, "CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal, MonoObject, 4, (MonoQCallTypeHandle, MonoObject, MonoReflectionMethod, MonoBoolean)) HANDLES(DELEGATE_3, "GetVirtualMethod_internal", ves_icall_System_Delegate_GetVirtualMethod_internal, MonoReflectionMethod, 1, (MonoDelegate)) ICALL_TYPE(DEBUGR, "System.Diagnostics.Debugger", DEBUGR_1) @@ -72,10 +72,10 @@ NOHANDLES(ICALL(NATIVE_RUNTIME_EVENT_SOURCE_8, "LogThreadPoolWorkerThreadWait", NOHANDLES(ICALL(NATIVE_RUNTIME_EVENT_SOURCE_9, "LogThreadPoolWorkingThreadCount", ves_icall_System_Diagnostics_Tracing_NativeRuntimeEventSource_LogThreadPoolWorkingThreadCount)) ICALL_TYPE(ENUM, "System.Enum", ENUM_1) -HANDLES(ENUM_1, "GetEnumValuesAndNames", ves_icall_System_Enum_GetEnumValuesAndNames, MonoBoolean, 3, (MonoReflectionType, MonoArrayOut, MonoArrayOut)) -HANDLES(ENUM_2, "InternalBoxEnum", ves_icall_System_Enum_ToObject, MonoObject, 2, (MonoReflectionType, guint64)) -HANDLES(ENUM_3, "InternalGetCorElementType", ves_icall_System_Enum_InternalGetCorElementType, int, 1, (MonoObject)) -HANDLES(ENUM_4, "InternalGetUnderlyingType", ves_icall_System_Enum_get_underlying_type, MonoReflectionType, 1, (MonoReflectionType)) +HANDLES(ENUM_1, "GetEnumValuesAndNames", ves_icall_System_Enum_GetEnumValuesAndNames, MonoBoolean, 3, (MonoQCallTypeHandle, MonoArrayOut, MonoArrayOut)) +HANDLES(ENUM_2, "InternalBoxEnum", ves_icall_System_Enum_InternalBoxEnum, void, 3, (MonoQCallTypeHandle, MonoObjectHandleOnStack, guint64)) +NOHANDLES(ICALL(ENUM_3, "InternalGetCorElementType", ves_icall_System_Enum_InternalGetCorElementType)) +HANDLES(ENUM_4, "InternalGetUnderlyingType", ves_icall_System_Enum_InternalGetUnderlyingType, void, 2, (MonoQCallTypeHandle, MonoObjectHandleOnStack)) ICALL_TYPE(ENV, "System.Environment", ENV_1) NOHANDLES(ICALL(ENV_1, "Exit", ves_icall_System_Environment_Exit)) @@ -332,16 +332,15 @@ HANDLES(GCH_4, "InternalSet", ves_icall_System_GCHandle_InternalSet, void, 2, (g ICALL_TYPE(MARSHAL, "System.Runtime.InteropServices.Marshal", MARSHAL_4) HANDLES(MARSHAL_4, "DestroyStructure", ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure, void, 2, (gpointer, MonoReflectionType)) -HANDLES(MARSHAL_9, "GetDelegateForFunctionPointerInternal", ves_icall_System_Runtime_InteropServices_Marshal_GetDelegateForFunctionPointerInternal, MonoDelegate, 2, (gpointer, MonoReflectionType)) +HANDLES(MARSHAL_9, "GetDelegateForFunctionPointerInternal", ves_icall_System_Runtime_InteropServices_Marshal_GetDelegateForFunctionPointerInternal, void, 3, (MonoQCallTypeHandle, gpointer, MonoObjectHandleOnStack)) HANDLES(MARSHAL_10, "GetFunctionPointerForDelegateInternal", ves_icall_System_Runtime_InteropServices_Marshal_GetFunctionPointerForDelegateInternal, gpointer, 1, (MonoDelegate)) NOHANDLES(ICALL(MARSHAL_11, "GetLastPInvokeError", ves_icall_System_Runtime_InteropServices_Marshal_GetLastPInvokeError)) -HANDLES(MARSHAL_48a, "IsPinnableType", ves_icall_System_Runtime_InteropServices_Marshal_IsPinnableType, MonoBoolean, 1, (MonoReflectionType)) +NOHANDLES(ICALL(MARSHAL_48a, "IsPinnableType", ves_icall_System_Runtime_InteropServices_Marshal_IsPinnableType)) HANDLES(MARSHAL_12, "OffsetOf", ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf, int, 2, (MonoReflectionType, MonoString)) HANDLES(MARSHAL_13, "PrelinkInternal", ves_icall_System_Runtime_InteropServices_Marshal_Prelink, void, 1, (MonoReflectionMethod)) HANDLES(MARSHAL_20, "PtrToStructureInternal", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructureInternal, void, 3, (gconstpointer, MonoObject, MonoBoolean)) NOHANDLES(ICALL(MARSHAL_29a, "SetLastPInvokeError", ves_icall_System_Runtime_InteropServices_Marshal_SetLastPInvokeError)) -HANDLES(MARSHAL_30, "SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf, guint32, 1, (MonoReflectionType)) -HANDLES(MARSHAL_31, "SizeOfHelper", ves_icall_System_Runtime_InteropServices_Marshal_SizeOfHelper, guint32, 2, (MonoReflectionType, MonoBoolean)) +HANDLES(MARSHAL_31, "SizeOfHelper", ves_icall_System_Runtime_InteropServices_Marshal_SizeOfHelper, guint32, 2, (MonoQCallTypeHandle, MonoBoolean)) HANDLES(MARSHAL_34, "StructureToPtr", ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr, void, 3, (MonoObject, gpointer, MonoBoolean)) ICALL_TYPE(NATIVEL, "System.Runtime.InteropServices.NativeLibrary", NATIVEL_1) @@ -372,51 +371,49 @@ ICALL_TYPE(MHAN, "System.RuntimeMethodHandle", MHAN_1) HANDLES(MHAN_1, "GetFunctionPointer", ves_icall_RuntimeMethodHandle_GetFunctionPointer, gpointer, 1, (MonoMethod_ptr)) ICALL_TYPE(RT, "System.RuntimeType", RT_1) -HANDLES(RT_1, "CreateInstanceInternal", ves_icall_System_Activator_CreateInstanceInternal, MonoObject, 1, (MonoReflectionType)) -HANDLES(RT_2, "GetConstructors_native", ves_icall_RuntimeType_GetConstructors_native, GPtrArray_ptr, 2, (MonoReflectionType, guint32)) -HANDLES(RT_30, "GetCorrespondingInflatedConstructor", ves_icall_RuntimeType_GetCorrespondingInflatedMethod, MonoReflectionMethod, 2, (MonoReflectionType, MonoReflectionMethod)) -HANDLES_REUSE_WRAPPER(RT_31, "GetCorrespondingInflatedMethod", ves_icall_RuntimeType_GetCorrespondingInflatedMethod) -HANDLES(RT_3, "GetEvents_native", ves_icall_RuntimeType_GetEvents_native, GPtrArray_ptr, 3, (MonoReflectionType, char_ptr, guint32)) -HANDLES(RT_5, "GetFields_native", ves_icall_RuntimeType_GetFields_native, GPtrArray_ptr, 4, (MonoReflectionType, char_ptr, guint32, guint32)) -HANDLES(RT_6, "GetGenericArgumentsInternal", ves_icall_RuntimeType_GetGenericArguments, MonoArray, 2, (MonoReflectionType, MonoBoolean)) -HANDLES(RT_9, "GetGenericParameterPosition", ves_icall_RuntimeType_GetGenericParameterPosition, gint32, 1, (MonoReflectionType)) -HANDLES(RT_10, "GetInterfaceMapData", ves_icall_RuntimeType_GetInterfaceMapData, void, 4, (MonoReflectionType, MonoReflectionType, MonoArrayOut, MonoArrayOut)) -HANDLES(RT_11, "GetInterfaces", ves_icall_RuntimeType_GetInterfaces, MonoArray, 1, (MonoReflectionType)) -HANDLES(RT_12, "GetMethodsByName_native", ves_icall_RuntimeType_GetMethodsByName_native, GPtrArray_ptr, 4, (MonoReflectionType, const_char_ptr, guint32, guint32)) -HANDLES(RT_13, "GetNestedTypes_native", ves_icall_RuntimeType_GetNestedTypes_native, GPtrArray_ptr, 4, (MonoReflectionType, char_ptr, guint32, guint32)) -HANDLES(RT_14, "GetPacking", ves_icall_RuntimeType_GetPacking, void, 3, (MonoReflectionType, guint32_ref, guint32_ref)) -HANDLES(RT_15, "GetPropertiesByName_native", ves_icall_RuntimeType_GetPropertiesByName_native, GPtrArray_ptr, 4, (MonoReflectionType, char_ptr, guint32, guint32)) -HANDLES(RT_17, "MakeGenericType", ves_icall_RuntimeType_MakeGenericType, MonoReflectionType, 2, (MonoReflectionType, MonoArray)) -HANDLES(RT_18, "MakePointerType", ves_icall_RuntimeType_MakePointerType, MonoReflectionType, 1, (MonoReflectionType)) -HANDLES(RT_19, "getFullName", ves_icall_System_RuntimeType_getFullName, MonoString, 3, (MonoReflectionType, MonoBoolean, MonoBoolean)) -HANDLES(RT_21, "get_DeclaringMethod", ves_icall_RuntimeType_get_DeclaringMethod, MonoReflectionMethod, 1, (MonoReflectionType)) -HANDLES(RT_22, "get_DeclaringType", ves_icall_RuntimeType_get_DeclaringType, MonoReflectionType, 1, (MonoReflectionType)) -HANDLES(RT_23, "get_Name", ves_icall_RuntimeType_get_Name, MonoString, 1, (MonoReflectionType)) -HANDLES(RT_24, "get_Namespace", ves_icall_RuntimeType_get_Namespace, MonoString, 1, (MonoReflectionType)) -HANDLES(RT_26, "make_array_type", ves_icall_RuntimeType_make_array_type, MonoReflectionType, 2, (MonoReflectionType, int)) -HANDLES(RT_27, "make_byref_type", ves_icall_RuntimeType_make_byref_type, MonoReflectionType, 1, (MonoReflectionType)) +HANDLES(RT_1, "CreateInstanceInternal", ves_icall_System_RuntimeType_CreateInstanceInternal, MonoObject, 1, (MonoQCallTypeHandle)) +HANDLES(RT_2, "GetConstructors_native", ves_icall_RuntimeType_GetConstructors_native, GPtrArray_ptr, 2, (MonoQCallTypeHandle, guint32)) +HANDLES(RT_30, "GetCorrespondingInflatedMethod", ves_icall_RuntimeType_GetCorrespondingInflatedMethod, MonoReflectionMethod, 2, (MonoQCallTypeHandle, MonoReflectionMethod)) +HANDLES(RT_21, "GetDeclaringMethod", ves_icall_RuntimeType_GetDeclaringMethod, void, 2, (MonoQCallTypeHandle, MonoObjectHandleOnStack)) +HANDLES(RT_22, "GetDeclaringType", ves_icall_RuntimeType_GetDeclaringType, void, 2, (MonoQCallTypeHandle, MonoObjectHandleOnStack)) +HANDLES(RT_3, "GetEvents_native", ves_icall_RuntimeType_GetEvents_native, GPtrArray_ptr, 3, (MonoQCallTypeHandle, char_ptr, guint32)) +HANDLES(RT_5, "GetFields_native", ves_icall_RuntimeType_GetFields_native, GPtrArray_ptr, 4, (MonoQCallTypeHandle, char_ptr, guint32, guint32)) +HANDLES(RT_6, "GetGenericArgumentsInternal", ves_icall_RuntimeType_GetGenericArgumentsInternal, void, 3, (MonoQCallTypeHandle, MonoObjectHandleOnStack, MonoBoolean)) +NOHANDLES(ICALL(RT_9, "GetGenericParameterPosition", ves_icall_RuntimeType_GetGenericParameterPosition)) +HANDLES(RT_10, "GetInterfaceMapData", ves_icall_RuntimeType_GetInterfaceMapData, void, 4, (MonoQCallTypeHandle, MonoQCallTypeHandle, MonoArrayOut, MonoArrayOut)) +HANDLES(RT_11, "GetInterfaces", ves_icall_RuntimeType_GetInterfaces, void, 2, (MonoQCallTypeHandle, MonoObjectHandleOnStack)) +HANDLES(RT_12, "GetMethodsByName_native", ves_icall_RuntimeType_GetMethodsByName_native, GPtrArray_ptr, 4, (MonoQCallTypeHandle, const_char_ptr, guint32, guint32)) +HANDLES(RT_23, "GetName", ves_icall_RuntimeType_GetName, void, 2, (MonoQCallTypeHandle, MonoObjectHandleOnStack)) +HANDLES(RT_24, "GetNamespace", ves_icall_RuntimeType_GetNamespace, void, 2, (MonoQCallTypeHandle, MonoObjectHandleOnStack)) +HANDLES(RT_13, "GetNestedTypes_native", ves_icall_RuntimeType_GetNestedTypes_native, GPtrArray_ptr, 4, (MonoQCallTypeHandle, char_ptr, guint32, guint32)) +HANDLES(RT_14, "GetPacking", ves_icall_RuntimeType_GetPacking, void, 3, (MonoQCallTypeHandle, guint32_ref, guint32_ref)) +HANDLES(RT_15, "GetPropertiesByName_native", ves_icall_RuntimeType_GetPropertiesByName_native, GPtrArray_ptr, 4, (MonoQCallTypeHandle, char_ptr, guint32, guint32)) +HANDLES(RT_17, "MakeGenericType", ves_icall_RuntimeType_MakeGenericType, void, 3, (MonoReflectionType, MonoArray, MonoObjectHandleOnStack)) +HANDLES(RT_19, "getFullName", ves_icall_System_RuntimeType_getFullName, void, 4, (MonoQCallTypeHandle, MonoObjectHandleOnStack, MonoBoolean, MonoBoolean)) +HANDLES(RT_26, "make_array_type", ves_icall_RuntimeType_make_array_type, void, 3, (MonoQCallTypeHandle, int, MonoObjectHandleOnStack)) +HANDLES(RT_27, "make_byref_type", ves_icall_RuntimeType_make_byref_type, void, 2, (MonoQCallTypeHandle, MonoObjectHandleOnStack)) +HANDLES(RT_18, "make_pointer_type", ves_icall_RuntimeType_make_pointer_type, void, 2, (MonoQCallTypeHandle, MonoObjectHandleOnStack)) ICALL_TYPE(RTH, "System.RuntimeTypeHandle", RTH_1) -HANDLES(RTH_1, "GetArrayRank", ves_icall_RuntimeTypeHandle_GetArrayRank, gint32, 1, (MonoReflectionType)) -HANDLES(RTH_2, "GetAssembly", ves_icall_RuntimeTypeHandle_GetAssembly, MonoReflectionAssembly, 1, (MonoReflectionType)) -HANDLES(RTH_3, "GetAttributes", ves_icall_RuntimeTypeHandle_GetAttributes, guint32, 1, (MonoReflectionType)) -HANDLES(RTH_4, "GetBaseType", ves_icall_RuntimeTypeHandle_GetBaseType, MonoReflectionType, 1, (MonoReflectionType)) -HANDLES(RTH_4a, "GetCorElementType", ves_icall_RuntimeTypeHandle_GetCorElementType, guint32, 1, (MonoReflectionType)) -HANDLES(RTH_5, "GetElementType", ves_icall_RuntimeTypeHandle_GetElementType, MonoReflectionType, 1, (MonoReflectionType)) -HANDLES(RTH_19, "GetGenericParameterInfo", ves_icall_RuntimeTypeHandle_GetGenericParameterInfo, MonoGenericParamInfo_ptr, 1, (MonoReflectionType)) -HANDLES(RTH_6, "GetGenericTypeDefinition_impl", ves_icall_RuntimeTypeHandle_GetGenericTypeDefinition_impl, MonoReflectionType, 1, (MonoReflectionType)) -HANDLES_REUSE_WRAPPER(RTH_7, "GetMetadataToken", ves_icall_reflection_get_token) -HANDLES(RTH_8, "GetModule", ves_icall_RuntimeTypeHandle_GetModule, MonoReflectionModule, 1, (MonoReflectionType)) -HANDLES(RTH_9, "HasInstantiation", ves_icall_RuntimeTypeHandle_HasInstantiation, MonoBoolean, 1, (MonoReflectionType)) -HANDLES(RTH_20, "HasReferences", ves_icall_RuntimeTypeHandle_HasReferences, MonoBoolean, 1, (MonoReflectionType)) -HANDLES(RTH_21, "IsByRefLike", ves_icall_RuntimeTypeHandle_IsByRefLike, MonoBoolean, 1, (MonoReflectionType)) -HANDLES(RTH_12, "IsComObject", ves_icall_RuntimeTypeHandle_IsComObject, MonoBoolean, 1, (MonoReflectionType)) -HANDLES(RTH_13, "IsGenericTypeDefinition", ves_icall_RuntimeTypeHandle_IsGenericTypeDefinition, MonoBoolean, 1, (MonoReflectionType)) -HANDLES(RTH_14, "IsGenericVariable", ves_icall_RuntimeTypeHandle_IsGenericVariable, MonoBoolean, 1, (MonoReflectionType)) -HANDLES(RTH_15, "IsInstanceOfType", ves_icall_RuntimeTypeHandle_IsInstanceOfType, guint32, 2, (MonoReflectionType, MonoObject)) -HANDLES(RTH_17a, "internal_from_name", ves_icall_System_RuntimeTypeHandle_internal_from_name, MonoReflectionType, 5, (MonoString, MonoStackCrawlMark_ptr, MonoReflectionAssembly, MonoBoolean, MonoBoolean)) -NOHANDLES(ICALL(RTH_17b, "is_subclass_of", ves_icall_RuntimeTypeHandle_is_subclass_of)) -HANDLES(RTH_18, "type_is_assignable_from", ves_icall_RuntimeTypeHandle_type_is_assignable_from, guint32, 2, (MonoReflectionType, MonoReflectionType)) +HANDLES(RTH_1, "GetArrayRank", ves_icall_RuntimeTypeHandle_GetArrayRank, gint32, 1, (MonoQCallTypeHandle)) +HANDLES(RTH_2, "GetAssembly", ves_icall_RuntimeTypeHandle_GetAssembly, void, 2, (MonoQCallTypeHandle, MonoObjectHandleOnStack)) +NOHANDLES(ICALL(RTH_3, "GetAttributes", ves_icall_RuntimeTypeHandle_GetAttributes)) +HANDLES(RTH_4, "GetBaseType", ves_icall_RuntimeTypeHandle_GetBaseType, void, 2, (MonoQCallTypeHandle, MonoObjectHandleOnStack)) +NOHANDLES(ICALL(RTH_4a, "GetCorElementType", ves_icall_RuntimeTypeHandle_GetCorElementType)) +HANDLES(RTH_5, "GetElementType", ves_icall_RuntimeTypeHandle_GetElementType, void, 2, (MonoQCallTypeHandle, MonoObjectHandleOnStack)) +HANDLES(RTH_19, "GetGenericParameterInfo", ves_icall_RuntimeTypeHandle_GetGenericParameterInfo, MonoGenericParamInfo_ptr, 1, (MonoQCallTypeHandle)) +HANDLES(RTH_6, "GetGenericTypeDefinition_impl", ves_icall_RuntimeTypeHandle_GetGenericTypeDefinition_impl, void, 2, (MonoQCallTypeHandle, MonoObjectHandleOnStack)) +HANDLES(RTH_7, "GetMetadataToken", ves_icall_RuntimeTypeHandle_GetMetadataToken, guint32, 1, (MonoQCallTypeHandle)) +HANDLES(RTH_8, "GetModule", ves_icall_RuntimeTypeHandle_GetModule, void, 2, (MonoQCallTypeHandle, MonoObjectHandleOnStack)) +NOHANDLES(ICALL(RTH_9, "HasInstantiation", ves_icall_RuntimeTypeHandle_HasInstantiation)) +HANDLES(RTH_20, "HasReferences", ves_icall_RuntimeTypeHandle_HasReferences, MonoBoolean, 1, (MonoQCallTypeHandle)) +HANDLES(RTH_21, "IsByRefLike", ves_icall_RuntimeTypeHandle_IsByRefLike, MonoBoolean, 1, (MonoQCallTypeHandle)) +HANDLES(RTH_12, "IsComObject", ves_icall_RuntimeTypeHandle_IsComObject, MonoBoolean, 1, (MonoQCallTypeHandle)) +NOHANDLES(ICALL(RTH_13, "IsGenericTypeDefinition", ves_icall_RuntimeTypeHandle_IsGenericTypeDefinition)) +HANDLES(RTH_15, "IsInstanceOfType", ves_icall_RuntimeTypeHandle_IsInstanceOfType, guint32, 2, (MonoQCallTypeHandle, MonoObject)) +HANDLES(RTH_17a, "internal_from_name", ves_icall_System_RuntimeTypeHandle_internal_from_name, void, 5, (char_ptr, MonoStackCrawlMark_ptr, MonoObjectHandleOnStack, MonoBoolean, MonoBoolean)) +HANDLES(RTH_17b, "is_subclass_of", ves_icall_RuntimeTypeHandle_is_subclass_of, MonoBoolean, 2, (MonoQCallTypeHandle, MonoQCallTypeHandle)) +HANDLES(RTH_18, "type_is_assignable_from", ves_icall_RuntimeTypeHandle_type_is_assignable_from, MonoBoolean, 2, (MonoQCallTypeHandle, MonoQCallTypeHandle)) ICALL_TYPE(STRING, "System.String", STRING_1) NOHANDLES(ICALL(STRING_1, ".ctor(System.ReadOnlySpan`1)", ves_icall_System_String_ctor_RedirectToCreateString)) diff --git a/src/mono/mono/metadata/icall-table.h b/src/mono/mono/metadata/icall-table.h index f5d303d392304e..65eb2335cfebbe 100644 --- a/src/mono/mono/metadata/icall-table.h +++ b/src/mono/mono/metadata/icall-table.h @@ -151,6 +151,8 @@ typedef MonoStringHandle MonoStringOutHandle; #define MONO_HANDLE_TYPE_WRAP_MonoProperty_ptr ICALL_HANDLES_WRAP_NONE #define MONO_HANDLE_TYPE_WRAP_size_t ICALL_HANDLES_WRAP_NONE #define MONO_HANDLE_TYPE_WRAP_MonoVTable_ptr ICALL_HANDLES_WRAP_NONE +#define MONO_HANDLE_TYPE_WRAP_MonoQCallTypeHandle ICALL_HANDLES_WRAP_NONE +#define MONO_HANDLE_TYPE_WRAP_MonoQCallAssemblyHandle ICALL_HANDLES_WRAP_NONE #define MONO_HANDLE_TYPE_WRAP_MonoAssemblyName_ref ICALL_HANDLES_WRAP_VALUETYPE_REF #define MONO_HANDLE_TYPE_WRAP_MonoBoolean_ref ICALL_HANDLES_WRAP_VALUETYPE_REF @@ -191,6 +193,7 @@ typedef MonoStringHandle MonoStringOutHandle; #define MONO_HANDLE_TYPE_WRAP_gint32_ptr ICALL_HANDLES_WRAP_NONE #define MONO_HANDLE_TYPE_WRAP_gpointer_ptr ICALL_HANDLES_WRAP_NONE #define MONO_HANDLE_TYPE_WRAP_PROCESS_HANDLE ICALL_HANDLES_WRAP_NONE +#define MONO_HANDLE_TYPE_WRAP_MonoObjectHandleOnStack ICALL_HANDLES_WRAP_NONE // Please keep this sorted (grep ICALL_HANDLES_WRAP_OBJ$ | sort) #define MONO_HANDLE_TYPE_WRAP_MonoAppContext ICALL_HANDLES_WRAP_OBJ diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index 2285778320b9b9..a4fecbec651934 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -1546,7 +1546,7 @@ mono_runtime_get_caller_from_stack_mark (MonoStackCrawlMark *stack_mark) return NULL; } -static MonoReflectionTypeHandle +static MonoReflectionType* type_from_parsed_name (MonoTypeNameParse *info, MonoStackCrawlMark *stack_mark, MonoBoolean ignoreCase, MonoAssembly **caller_assembly, MonoError *error) { MonoMethod *m; @@ -1617,15 +1617,15 @@ type_from_parsed_name (MonoTypeNameParse *info, MonoStackCrawlMark *stack_mark, if (!type) goto fail; - return mono_type_get_object_handle (type, error); + return mono_type_get_object_checked (type, error); fail: - return MONO_HANDLE_NEW (MonoReflectionType, NULL); + return NULL; } -MonoReflectionTypeHandle -ves_icall_System_RuntimeTypeHandle_internal_from_name (MonoStringHandle name, +void +ves_icall_System_RuntimeTypeHandle_internal_from_name (char *name, MonoStackCrawlMark *stack_mark, - MonoReflectionAssemblyHandle callerAssembly, + MonoObjectHandleOnStack res, MonoBoolean throwOnError, MonoBoolean ignoreCase, MonoError *error) @@ -1633,24 +1633,17 @@ ves_icall_System_RuntimeTypeHandle_internal_from_name (MonoStringHandle name, MonoTypeNameParse info; gboolean free_info = FALSE; MonoAssembly *caller_assembly; - MonoReflectionTypeHandle type = MONO_HANDLE_NEW (MonoReflectionType, NULL); - - /* The callerAssembly argument is unused for now */ - - char *str = mono_string_handle_to_utf8 (name, error); - goto_if_nok (error, leave); free_info = TRUE; - if (!mono_reflection_parse_type_checked (str, &info, error)) + if (!mono_reflection_parse_type_checked (name, &info, error)) goto leave; /* mono_reflection_parse_type() mangles the string */ - MONO_HANDLE_ASSIGN (type, type_from_parsed_name (&info, (MonoStackCrawlMark*)stack_mark, ignoreCase, &caller_assembly, error)); - + HANDLE_ON_STACK_SET (res, type_from_parsed_name (&info, (MonoStackCrawlMark*)stack_mark, ignoreCase, &caller_assembly, error)); goto_if_nok (error, leave); - if (MONO_HANDLE_IS_NULL (type)) { + if (!(*res)) { if (throwOnError) { char *tname = info.name_space ? g_strdup_printf ("%s.%s", info.name_space, info.name) : g_strdup (info.name); char *aname; @@ -1668,15 +1661,12 @@ ves_icall_System_RuntimeTypeHandle_internal_from_name (MonoStringHandle name, leave: if (free_info) mono_reflection_free_type_info (&info); - g_free (str); if (!is_ok (error)) { if (!throwOnError) { mono_error_cleanup (error); error_init (error); } - return MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE); - } else - return type; + } } @@ -1735,14 +1725,12 @@ typedef enum { TYPECODE_STRING = 18 } TypeCode; -guint32 -ves_icall_RuntimeTypeHandle_type_is_assignable_from (MonoReflectionTypeHandle ref_type, MonoReflectionTypeHandle ref_c, MonoError *error) +MonoBoolean +ves_icall_RuntimeTypeHandle_type_is_assignable_from (MonoQCallTypeHandle type_handle, MonoQCallTypeHandle c_handle, MonoError *error) { - g_assert (!MONO_HANDLE_IS_NULL (ref_type)); - - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (type); - MonoType *ctype = MONO_HANDLE_GETVAL (ref_c, type); + MonoType *ctype = c_handle.type; MonoClass *klassc = mono_class_from_mono_type_internal (ctype); if (m_type_is_byref (type) ^ m_type_is_byref (ctype)) @@ -1754,13 +1742,14 @@ ves_icall_RuntimeTypeHandle_type_is_assignable_from (MonoReflectionTypeHandle re gboolean result; mono_class_is_assignable_from_checked (klass, klassc, &result, error); - return (guint32)result; + return result; } MonoBoolean -ves_icall_RuntimeTypeHandle_is_subclass_of (MonoType *childType, MonoType *baseType) +ves_icall_RuntimeTypeHandle_is_subclass_of (MonoQCallTypeHandle child_handle, MonoQCallTypeHandle base_handle, MonoError *error) { - ERROR_DECL (error); + MonoType *childType = child_handle.type; + MonoType *baseType = base_handle.type; mono_bool result = FALSE; MonoClass *childClass; MonoClass *baseClass; @@ -1768,21 +1757,15 @@ ves_icall_RuntimeTypeHandle_is_subclass_of (MonoType *childType, MonoType *baseT childClass = mono_class_from_mono_type_internal (childType); baseClass = mono_class_from_mono_type_internal (baseType); - if (G_UNLIKELY (m_type_is_byref (childType))) { - result = !m_type_is_byref (baseType) && baseClass == mono_defaults.object_class; - goto done; - } + if (G_UNLIKELY (m_type_is_byref (childType))) + return !m_type_is_byref (baseType) && baseClass == mono_defaults.object_class; - if (G_UNLIKELY (m_type_is_byref (baseType))) { - result = FALSE; - goto done; - } + if (G_UNLIKELY (m_type_is_byref (baseType))) + return FALSE; - if (childType == baseType) { + if (childType == baseType) /* .NET IsSubclassOf is not reflexive */ - result = FALSE; - goto done; - } + return FALSE; if (G_UNLIKELY (is_generic_parameter (childType))) { /* slow path: walk the type hierarchy looking at base types @@ -1793,28 +1776,23 @@ ves_icall_RuntimeTypeHandle_is_subclass_of (MonoType *childType, MonoType *baseT result = FALSE; while (c != NULL) { - if (c == baseClass) { - result = TRUE; - break; - } - if (!is_generic_parameter (m_class_get_byval_arg (c))) { - result = mono_class_is_subclass_of_internal (c, baseClass, FALSE); - break; - } else + if (c == baseClass) + return TRUE; + if (!is_generic_parameter (m_class_get_byval_arg (c))) + return mono_class_is_subclass_of_internal (c, baseClass, FALSE); + else c = mono_generic_param_get_base_type (c); } + return result; } else { - result = mono_class_is_subclass_of_internal (childClass, baseClass, FALSE); + return mono_class_is_subclass_of_internal (childClass, baseClass, FALSE); } -done: - mono_error_set_pending_exception (error); - return result; } guint32 -ves_icall_RuntimeTypeHandle_IsInstanceOfType (MonoReflectionTypeHandle ref_type, MonoObjectHandle obj, MonoError *error) +ves_icall_RuntimeTypeHandle_IsInstanceOfType (MonoQCallTypeHandle type_handle, MonoObjectHandle obj, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (type); mono_class_init_checked (klass, error); return_val_if_nok (error, FALSE); @@ -1824,9 +1802,9 @@ ves_icall_RuntimeTypeHandle_IsInstanceOfType (MonoReflectionTypeHandle ref_type, } guint32 -ves_icall_RuntimeTypeHandle_GetAttributes (MonoReflectionTypeHandle ref_type, MonoError *error) +ves_icall_RuntimeTypeHandle_GetAttributes (MonoQCallTypeHandle type_handle) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; if (m_type_is_byref (type) || type->type == MONO_TYPE_PTR || type->type == MONO_TYPE_FNPTR) return TYPE_ATTRIBUTE_NOT_PUBLIC; @@ -1835,6 +1813,20 @@ ves_icall_RuntimeTypeHandle_GetAttributes (MonoReflectionTypeHandle ref_type, Mo return mono_class_get_flags (klass); } +guint32 +ves_icall_RuntimeTypeHandle_GetMetadataToken (MonoQCallTypeHandle type_handle, MonoError *error) +{ + MonoType *type = type_handle.type; + + MonoClass *mc = mono_class_from_mono_type_internal (type); + if (!mono_class_init_internal (mc)) { + mono_error_set_for_class_failure (error, mc); + return 0; + } + + return m_class_get_type_token (mc); +} + MonoReflectionMarshalAsAttributeHandle ves_icall_System_Reflection_FieldInfo_get_marshal_info (MonoReflectionFieldHandle field_h, MonoError *error) { @@ -2517,10 +2509,10 @@ get_interfaces_hash (gconstpointer v1) return m_class_get_type_token (k); } -MonoArrayHandle -ves_icall_RuntimeType_GetInterfaces (MonoReflectionTypeHandle ref_type, MonoError *error) +void +ves_icall_RuntimeType_GetInterfaces (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (type); GHashTable *iface_hash = g_hash_table_new (get_interfaces_hash, NULL); @@ -2548,7 +2540,8 @@ ves_icall_RuntimeType_GetInterfaces (MonoReflectionTypeHandle ref_type, MonoErro domain->empty_types = mono_array_new_cached (mono_defaults.runtimetype_class, 0, error); goto_if_nok (error, fail); } - return MONO_HANDLE_NEW (MonoArray, domain->empty_types); + HANDLE_ON_STACK_SET (res, domain->empty_types); + return; } FillIfaceArrayData data; @@ -2563,11 +2556,11 @@ ves_icall_RuntimeType_GetInterfaces (MonoReflectionTypeHandle ref_type, MonoErro goto_if_nok (error, fail); g_hash_table_destroy (iface_hash); - return data.iface_array; + HANDLE_ON_STACK_SET (res, MONO_HANDLE_RAW (data.iface_array)); + return; fail: g_hash_table_destroy (iface_hash); - return NULL_HANDLE_ARRAY; } static gboolean @@ -2649,11 +2642,11 @@ set_interface_map_data_method_object (MonoMethod *method, MonoClass *iclass, int } void -ves_icall_RuntimeType_GetInterfaceMapData (MonoReflectionTypeHandle ref_type, MonoReflectionTypeHandle ref_iface, MonoArrayHandleOut targets, MonoArrayHandleOut methods, MonoError *error) +ves_icall_RuntimeType_GetInterfaceMapData (MonoQCallTypeHandle type_handle, MonoQCallTypeHandle iface_handle, MonoArrayHandleOut targets, MonoArrayHandleOut methods, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (type); - MonoType *iface = MONO_HANDLE_GETVAL (ref_iface, type); + MonoType *iface = iface_handle.type; MonoClass *iclass = mono_class_from_mono_type_internal (iface); mono_class_init_checked (klass, error); @@ -2698,66 +2691,72 @@ ves_icall_RuntimeType_GetInterfaceMapData (MonoReflectionTypeHandle ref_type, Mo } void -ves_icall_RuntimeType_GetPacking (MonoReflectionTypeHandle ref_type, guint32 *packing, guint32 *size, MonoError *error) +ves_icall_RuntimeType_GetPacking (MonoQCallTypeHandle type_handle, guint32 *packing, guint32 *size, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (type); mono_class_init_checked (klass, error); return_if_nok (error); if (image_is_dynamic (m_class_get_image (klass))) { - MonoReflectionTypeBuilderHandle tb = MONO_HANDLE_CAST (MonoReflectionTypeBuilder, ref_type); - *packing = MONO_HANDLE_GETVAL (tb, packing_size); - *size = MONO_HANDLE_GETVAL (tb, class_size); + MonoGCHandle ref_info_handle = mono_class_get_ref_info_handle (klass); + g_assert (ref_info_handle); + MonoReflectionTypeBuilder *tb = (MonoReflectionTypeBuilder*)mono_gchandle_get_target_internal (ref_info_handle); + g_assert (tb); + + *packing = tb->packing_size; + *size = tb->class_size; } else { mono_metadata_packing_from_typedef (m_class_get_image (klass), m_class_get_type_token (klass), packing, size); } } -MonoReflectionTypeHandle -ves_icall_RuntimeTypeHandle_GetElementType (MonoReflectionTypeHandle ref_type, MonoError *error) +void +ves_icall_RuntimeTypeHandle_GetElementType (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; - if (!m_type_is_byref (type) && type->type == MONO_TYPE_SZARRAY) - return mono_type_get_object_handle (m_class_get_byval_arg (type->data.klass), error); + if (!m_type_is_byref (type) && type->type == MONO_TYPE_SZARRAY) { + HANDLE_ON_STACK_SET (res, mono_type_get_object_checked (m_class_get_byval_arg (type->data.klass), error)); + return; + } MonoClass *klass = mono_class_from_mono_type_internal (type); mono_class_init_checked (klass, error); - return_val_if_nok (error, MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE)); + return_if_nok (error); // GetElementType should only return a type for: // Array Pointer PassedByRef if (m_type_is_byref (type)) - return mono_type_get_object_handle (m_class_get_byval_arg (klass), error); + HANDLE_ON_STACK_SET (res, mono_type_get_object_checked (m_class_get_byval_arg (klass), error)); else if (m_class_get_element_class (klass) && MONO_CLASS_IS_ARRAY (klass)) - return mono_type_get_object_handle (m_class_get_byval_arg (m_class_get_element_class (klass)), error); + HANDLE_ON_STACK_SET (res, mono_type_get_object_checked (m_class_get_byval_arg (m_class_get_element_class (klass)), error)); else if (m_class_get_element_class (klass) && type->type == MONO_TYPE_PTR) - return mono_type_get_object_handle (m_class_get_byval_arg (m_class_get_element_class (klass)), error); + HANDLE_ON_STACK_SET (res, mono_type_get_object_checked (m_class_get_byval_arg (m_class_get_element_class (klass)), error)); else - return MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE); + HANDLE_ON_STACK_SET (res, NULL); } -MonoReflectionTypeHandle -ves_icall_RuntimeTypeHandle_GetBaseType (MonoReflectionTypeHandle ref_type, MonoError *error) +void +ves_icall_RuntimeTypeHandle_GetBaseType (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; if (m_type_is_byref (type)) - return MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE); + return; MonoClass *klass = mono_class_from_mono_type_internal (type); if (!m_class_get_parent (klass)) - return MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE); + return; - return mono_type_get_object_handle (m_class_get_byval_arg (m_class_get_parent (klass)), error); + HANDLE_ON_STACK_SET (res, mono_type_get_object_checked (m_class_get_byval_arg (m_class_get_parent (klass)), error)); } guint32 -ves_icall_RuntimeTypeHandle_GetCorElementType (MonoReflectionTypeHandle ref_type, MonoError *error) +ves_icall_RuntimeTypeHandle_GetCorElementType (MonoQCallTypeHandle type_handle) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; if (m_type_is_byref (type)) return MONO_TYPE_BYREF; @@ -2766,9 +2765,9 @@ ves_icall_RuntimeTypeHandle_GetCorElementType (MonoReflectionTypeHandle ref_type } MonoBoolean -ves_icall_RuntimeTypeHandle_HasReferences (MonoReflectionTypeHandle ref_type, MonoError *error) +ves_icall_RuntimeTypeHandle_HasReferences (MonoQCallTypeHandle type_handle, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *klass; klass = mono_class_from_mono_type_internal (type); @@ -2777,9 +2776,10 @@ ves_icall_RuntimeTypeHandle_HasReferences (MonoReflectionTypeHandle ref_type, Mo } MonoBoolean -ves_icall_RuntimeTypeHandle_IsByRefLike (MonoReflectionTypeHandle ref_type, MonoError *error) +ves_icall_RuntimeTypeHandle_IsByRefLike (MonoQCallTypeHandle type_handle, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; + /* .NET Core says byref types are not IsByRefLike */ if (m_type_is_byref (type)) return FALSE; @@ -2788,9 +2788,9 @@ ves_icall_RuntimeTypeHandle_IsByRefLike (MonoReflectionTypeHandle ref_type, Mono } MonoBoolean -ves_icall_RuntimeTypeHandle_IsComObject (MonoReflectionTypeHandle ref_type, MonoError *error) +ves_icall_RuntimeTypeHandle_IsComObject (MonoQCallTypeHandle type_handle, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (type); mono_class_init_checked (klass, error); return_val_if_nok (error, FALSE); @@ -2805,30 +2805,40 @@ ves_icall_reflection_get_token (MonoObjectHandle obj, MonoError *error) return mono_reflection_get_token_checked (obj, error); } -MonoReflectionModuleHandle -ves_icall_RuntimeTypeHandle_GetModule (MonoReflectionTypeHandle type, MonoError *error) +void +ves_icall_RuntimeTypeHandle_GetModule (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res, MonoError *error) { - MonoType *t = MONO_HANDLE_GETVAL (type, type); + MonoType *t = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (t); - return mono_module_get_object_handle (m_class_get_image (klass), error); + + MonoReflectionModuleHandle module; + module = mono_module_get_object_handle (m_class_get_image (klass), error); + return_if_nok (error); + + HANDLE_ON_STACK_SET (res, MONO_HANDLE_RAW (module)); } -MonoReflectionAssemblyHandle -ves_icall_RuntimeTypeHandle_GetAssembly (MonoReflectionTypeHandle type, MonoError *error) +void +ves_icall_RuntimeTypeHandle_GetAssembly (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res, MonoError *error) { - MonoType *t = MONO_HANDLE_GETVAL (type, type); + MonoType *t = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (t); - return mono_assembly_get_object_handle (m_class_get_image (klass)->assembly, error); + + MonoReflectionAssemblyHandle assembly; + assembly = mono_assembly_get_object_handle (m_class_get_image (klass)->assembly, error); + return_if_nok (error); + + HANDLE_ON_STACK_SET (res, MONO_HANDLE_RAW (assembly)); } -MonoReflectionTypeHandle -ves_icall_RuntimeType_get_DeclaringType (MonoReflectionTypeHandle ref_type, MonoError *error) +void +ves_icall_RuntimeType_GetDeclaringType (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *klass; if (m_type_is_byref (type)) - return MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE); + return; if (type->type == MONO_TYPE_VAR) { MonoGenericContainer *param = mono_type_get_generic_param_owner (type); klass = param ? param->owner.klass : NULL; @@ -2840,15 +2850,15 @@ ves_icall_RuntimeType_get_DeclaringType (MonoReflectionTypeHandle ref_type, Mono } if (!klass) - return MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE); + return; - return mono_type_get_object_handle (m_class_get_byval_arg (klass), error); + HANDLE_ON_STACK_SET (res, mono_type_get_object_checked (m_class_get_byval_arg (klass), error)); } -MonoStringHandle -ves_icall_RuntimeType_get_Name (MonoReflectionTypeHandle reftype, MonoError *error) +void +ves_icall_RuntimeType_GetName (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res, MonoError *error) { - MonoType *type = MONO_HANDLE_RAW(reftype)->type; + MonoType *type = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (type); // FIXME: this should be escaped in some scenarios with mono_identifier_escape_type_name_chars // Determining exactly when to do so is fairly difficult, so for now we don't bother to avoid regressions @@ -2856,39 +2866,36 @@ ves_icall_RuntimeType_get_Name (MonoReflectionTypeHandle reftype, MonoError *err if (m_type_is_byref (type)) { char *n = g_strdup_printf ("%s&", klass_name); - MonoStringHandle res = mono_string_new_handle (n, error); + HANDLE_ON_STACK_SET (res, mono_string_new_checked (n, error)); g_free (n); - - return res; } else { - return mono_string_new_handle (klass_name, error); + HANDLE_ON_STACK_SET (res, mono_string_new_checked (klass_name, error)); } } -MonoStringHandle -ves_icall_RuntimeType_get_Namespace (MonoReflectionTypeHandle type, MonoError *error) +void +ves_icall_RuntimeType_GetNamespace (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res, MonoError *error) { - MonoClass *klass = mono_class_from_mono_type_handle (type); + MonoType *type = type_handle.type; + MonoClass *klass = mono_class_from_mono_type_internal (type); MonoClass *klass_nested_in; while ((klass_nested_in = m_class_get_nested_in (klass))) klass = klass_nested_in; if (m_class_get_name_space (klass) [0] == '\0') - return NULL_HANDLE_STRING; + return; char *escaped = mono_identifier_escape_type_name_chars (m_class_get_name_space (klass)); - MonoStringHandle res = mono_string_new_handle (escaped, error); + HANDLE_ON_STACK_SET (res, mono_string_new_checked (escaped, error)); g_free (escaped); - return res; } gint32 -ves_icall_RuntimeTypeHandle_GetArrayRank (MonoReflectionTypeHandle ref_type, MonoError *error) +ves_icall_RuntimeTypeHandle_GetArrayRank (MonoQCallTypeHandle type_handle, MonoError *error) { - error_init (error); - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; if (type->type != MONO_TYPE_ARRAY && type->type != MONO_TYPE_SZARRAY) { mono_error_set_argument (error, "type", "Type must be an array type"); @@ -2920,49 +2927,41 @@ set_type_object_in_array (MonoType *type, MonoArrayHandle dest, int i, MonoError HANDLE_FUNCTION_RETURN_VAL (is_ok (error)); } -MonoArrayHandle -ves_icall_RuntimeType_GetGenericArguments (MonoReflectionTypeHandle ref_type, MonoBoolean runtimeTypeArray, MonoError *error) +void +ves_icall_RuntimeType_GetGenericArgumentsInternal (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res_handle, MonoBoolean runtimeTypeArray, MonoError *error) { - error_init (error); - - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (type); MonoArrayHandle res = MONO_HANDLE_NEW (MonoArray, NULL); if (mono_class_is_gtd (klass)) { MonoGenericContainer *container = mono_class_get_generic_container (klass); MONO_HANDLE_ASSIGN (res, create_type_array (runtimeTypeArray, container->type_argc, error)); - goto_if_nok (error, leave); + return_if_nok (error); for (int i = 0; i < container->type_argc; ++i) { MonoClass *pklass = mono_class_create_generic_parameter (mono_generic_container_get_param (container, i)); if (!set_type_object_in_array (m_class_get_byval_arg (pklass), res, i, error)) - goto leave; + return; } } else if (mono_class_is_ginst (klass)) { MonoGenericInst *inst = mono_class_get_generic_class (klass)->context.class_inst; MONO_HANDLE_ASSIGN (res, create_type_array (runtimeTypeArray, inst->type_argc, error)); - goto_if_nok (error, leave); + return_if_nok (error); for (int i = 0; i < inst->type_argc; ++i) { if (!set_type_object_in_array (inst->type_argv [i], res, i, error)) - goto leave; + return; } } -leave: - return res; + HANDLE_ON_STACK_SET(res_handle, MONO_HANDLE_RAW (res)); } MonoBoolean -ves_icall_RuntimeTypeHandle_IsGenericTypeDefinition (MonoReflectionTypeHandle ref_type, MonoError *error) +ves_icall_RuntimeTypeHandle_IsGenericTypeDefinition (MonoQCallTypeHandle type_handle) { - error_init (error); - - if (!IS_MONOTYPE (MONO_HANDLE_RAW(ref_type))) - return FALSE; - - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; if (m_type_is_byref (type)) return FALSE; @@ -2970,24 +2969,20 @@ ves_icall_RuntimeTypeHandle_IsGenericTypeDefinition (MonoReflectionTypeHandle re return mono_class_is_gtd (klass); } -MonoReflectionTypeHandle -ves_icall_RuntimeTypeHandle_GetGenericTypeDefinition_impl (MonoReflectionTypeHandle ref_type, MonoError *error) +void +ves_icall_RuntimeTypeHandle_GetGenericTypeDefinition_impl (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res, MonoError *error) { - error_init (error); - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); - - MonoReflectionTypeHandle ret = MONO_HANDLE_NEW (MonoReflectionType, NULL); + MonoType *type = type_handle.type; if (m_type_is_byref (type)) - goto leave; + return; MonoClass *klass; klass = mono_class_from_mono_type_internal (type); if (mono_class_is_gtd (klass)) { - /* check this one */ - MONO_HANDLE_ASSIGN (ret, ref_type); - goto leave; + HANDLE_ON_STACK_SET (res, NULL); + return; } if (mono_class_is_ginst (klass)) { MonoClass *generic_class = mono_class_get_generic_class (klass)->container_class; @@ -2997,24 +2992,22 @@ ves_icall_RuntimeTypeHandle_GetGenericTypeDefinition_impl (MonoReflectionTypeHan if (m_class_was_typebuilder (generic_class) && ref_info_handle) { MonoObjectHandle tb = mono_gchandle_get_target_handle (ref_info_handle); g_assert (!MONO_HANDLE_IS_NULL (tb)); - MONO_HANDLE_ASSIGN (ret, tb); + HANDLE_ON_STACK_SET (res, MONO_HANDLE_RAW (tb)); } else { - MONO_HANDLE_ASSIGN (ret, mono_type_get_object_handle (m_class_get_byval_arg (generic_class), error)); + HANDLE_ON_STACK_SET (res, mono_type_get_object_checked (m_class_get_byval_arg (generic_class), error)); } } -leave: - return ret; } -MonoReflectionTypeHandle -ves_icall_RuntimeType_MakeGenericType (MonoReflectionTypeHandle reftype, MonoArrayHandle type_array, MonoError *error) +void +ves_icall_RuntimeType_MakeGenericType (MonoReflectionTypeHandle reftype, MonoArrayHandle type_array, MonoObjectHandleOnStack res, MonoError *error) { error_init (error); g_assert (IS_MONOTYPE_HANDLE (reftype)); MonoType *type = MONO_HANDLE_GETVAL (reftype, type); mono_class_init_checked (mono_class_from_mono_type_internal (type), error); - return_val_if_nok (error, MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE)); + return_if_nok (error); int count = mono_array_handle_length (type_array); MonoType **types = g_new0 (MonoType *, count); @@ -3027,31 +3020,26 @@ ves_icall_RuntimeType_MakeGenericType (MonoReflectionTypeHandle reftype, MonoArr MonoType *geninst = mono_reflection_bind_generic_parameters (reftype, count, types, error); g_free (types); - if (!geninst) { - return MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE); - } + if (!geninst) + return; MonoClass *klass = mono_class_from_mono_type_internal (geninst); /*we might inflate to the GTD*/ if (mono_class_is_ginst (klass) && !mono_verifier_class_is_valid_generic_instantiation (klass)) { mono_error_set_argument (error, "typeArguments", "Invalid generic arguments"); - return MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE); + return; } - return mono_type_get_object_handle (geninst, error); + HANDLE_ON_STACK_SET (res, mono_type_get_object_checked (geninst, error)); } MonoBoolean -ves_icall_RuntimeTypeHandle_HasInstantiation (MonoReflectionTypeHandle ref_type, MonoError *error) +ves_icall_RuntimeTypeHandle_HasInstantiation (MonoQCallTypeHandle type_handle) { - error_init (error); MonoClass *klass; - if (!IS_MONOTYPE (MONO_HANDLE_RAW (ref_type))) - return FALSE; - - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; if (m_type_is_byref (type)) return FALSE; @@ -3060,12 +3048,9 @@ ves_icall_RuntimeTypeHandle_HasInstantiation (MonoReflectionTypeHandle ref_type, } gint32 -ves_icall_RuntimeType_GetGenericParameterPosition (MonoReflectionTypeHandle ref_type, MonoError *error) +ves_icall_RuntimeType_GetGenericParameterPosition (MonoQCallTypeHandle type_handle) { - error_init (error); - if (!IS_MONOTYPE_HANDLE (ref_type)) - return -1; - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; if (is_generic_parameter (type)) return mono_type_get_generic_param_num (type); @@ -3073,27 +3058,18 @@ ves_icall_RuntimeType_GetGenericParameterPosition (MonoReflectionTypeHandle ref_ } MonoGenericParamInfo * -ves_icall_RuntimeTypeHandle_GetGenericParameterInfo (MonoReflectionTypeHandle ref_type, MonoError *error) +ves_icall_RuntimeTypeHandle_GetGenericParameterInfo (MonoQCallTypeHandle type_handle, MonoError *error) { - error_init (error); - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; return mono_generic_param_info (type->data.generic_param); } -MonoBoolean -ves_icall_RuntimeTypeHandle_IsGenericVariable (MonoReflectionTypeHandle ref_type, MonoError *error) -{ - MonoType *type = MONO_HANDLE_GETVAL(ref_type, type); - return is_generic_parameter (type); -} - MonoReflectionMethodHandle -ves_icall_RuntimeType_GetCorrespondingInflatedMethod (MonoReflectionTypeHandle ref_type, - MonoReflectionMethodHandle generic, - MonoError *error) +ves_icall_RuntimeType_GetCorrespondingInflatedMethod (MonoQCallTypeHandle type_handle, + MonoReflectionMethodHandle generic, + MonoError *error) { - error_init (error); - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (type); mono_class_init_checked (klass, error); @@ -3114,27 +3090,23 @@ ves_icall_RuntimeType_GetCorrespondingInflatedMethod (MonoReflectionTypeHandle r return ret; } -MonoReflectionMethodHandle -ves_icall_RuntimeType_get_DeclaringMethod (MonoReflectionTypeHandle ref_type, MonoError *error) +void +ves_icall_RuntimeType_GetDeclaringMethod (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res, MonoError *error) { - error_init (error); - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); - MonoReflectionMethodHandle ret = MONO_HANDLE_NEW (MonoReflectionMethod, NULL); + MonoType *type = type_handle.type; if (m_type_is_byref (type) || (type->type != MONO_TYPE_MVAR && type->type != MONO_TYPE_VAR)) { mono_error_set_invalid_operation (error, "DeclaringMethod can only be used on generic arguments"); - goto leave; + return; } if (type->type == MONO_TYPE_VAR) - goto leave; + return; MonoMethod *method; method = mono_type_get_generic_param_owner (type)->owner.method; g_assert (method); - MONO_HANDLE_ASSIGN (ret, mono_method_get_object_handle (method, method->klass, error)); -leave: - return ret; + HANDLE_ON_STACK_SET (res, mono_method_get_object_checked (method, method->klass, error)); } void @@ -3577,57 +3549,51 @@ write_enum_value (void *mem, int type, guint64 value) return; } -MonoObjectHandle -ves_icall_System_Enum_ToObject (MonoReflectionTypeHandle enumType, guint64 value, MonoError *error) +void +ves_icall_System_Enum_InternalBoxEnum (MonoQCallTypeHandle enum_handle, MonoObjectHandleOnStack res, guint64 value, MonoError *error) { MonoClass *enumc; MonoObjectHandle resultHandle; MonoType *etype; - enumc = mono_class_from_mono_type_internal (MONO_HANDLE_GETVAL (enumType, type)); + enumc = mono_class_from_mono_type_internal (enum_handle.type); mono_class_init_checked (enumc, error); - goto_if_nok (error, return_null); + return_if_nok (error); etype = mono_class_enum_basetype_internal (enumc); resultHandle = mono_object_new_handle (enumc, error); - goto_if_nok (error, return_null); + return_if_nok (error); write_enum_value (mono_handle_unbox_unsafe (resultHandle), etype->type, value); - return resultHandle; - -return_null: - return MONO_HANDLE_NEW (MonoObject, NULL); + HANDLE_ON_STACK_SET (res, MONO_HANDLE_RAW (resultHandle)); } -MonoReflectionTypeHandle -ves_icall_System_Enum_get_underlying_type (MonoReflectionTypeHandle type, MonoError *error) +void +ves_icall_System_Enum_InternalGetUnderlyingType (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res, MonoError *error) { MonoType *etype; MonoClass *klass; - klass = mono_class_from_mono_type_internal (MONO_HANDLE_GETVAL (type, type)); + klass = mono_class_from_mono_type_internal (type_handle.type); mono_class_init_checked (klass, error); - goto_if_nok (error, return_null); + return_if_nok (error); etype = mono_class_enum_basetype_internal (klass); if (!etype) { mono_error_set_argument (error, "enumType", "Type provided must be an Enum."); - goto return_null; + return; } - return mono_type_get_object_handle (etype, error); - -return_null: - return MONO_HANDLE_NEW (MonoReflectionType, NULL); + HANDLE_ON_STACK_SET (res, mono_type_get_object_checked (etype, error)); } int -ves_icall_System_Enum_InternalGetCorElementType (MonoObjectHandle this_handle, MonoError *error) +ves_icall_System_Enum_InternalGetCorElementType (MonoQCallTypeHandle type_handle) { - MonoClass *klass = MONO_HANDLE_GETVAL (this_handle, vtable)->klass; + MonoClass *klass = mono_class_from_mono_type_internal (type_handle.type); return (int)m_class_get_byval_arg (m_class_get_element_class (klass))->type; } @@ -3668,9 +3634,9 @@ get_enum_field (MonoArrayHandle names, MonoArrayHandle values, int base_type, Mo } MonoBoolean -ves_icall_System_Enum_GetEnumValuesAndNames (MonoReflectionTypeHandle type, MonoArrayHandleOut values, MonoArrayHandleOut names, MonoError *error) +ves_icall_System_Enum_GetEnumValuesAndNames (MonoQCallTypeHandle type_handle, MonoArrayHandleOut values, MonoArrayHandleOut names, MonoError *error) { - MonoClass *enumc = mono_class_from_mono_type_internal (MONO_HANDLE_RAW(type)->type); + MonoClass *enumc = mono_class_from_mono_type_internal (type_handle.type); guint j = 0, nvalues; gpointer iter; MonoClassField *field; @@ -3678,7 +3644,6 @@ ves_icall_System_Enum_GetEnumValuesAndNames (MonoReflectionTypeHandle type, Mono guint64 previous_value = 0; gboolean sorted = TRUE; - error_init (error); mono_class_init_checked (enumc, error); return_val_if_nok (error, FALSE); @@ -3733,14 +3698,12 @@ enum { }; GPtrArray* -ves_icall_RuntimeType_GetFields_native (MonoReflectionTypeHandle ref_type, char *utf8_name, guint32 bflags, guint32 mlisttype, MonoError *error) +ves_icall_RuntimeType_GetFields_native (MonoQCallTypeHandle type_handle, char *utf8_name, guint32 bflags, guint32 mlisttype, MonoError *error) { - error_init (error); - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; - if (m_type_is_byref (type)) { + if (m_type_is_byref (type)) return g_ptr_array_new (); - } int (*compare_func) (const char *s1, const char *s2) = NULL; compare_func = ((bflags & BFLAGS_IgnoreCase) || (mlisttype == MLISTTYPE_CaseInsensitive)) ? mono_utf8_strcasecmp : strcmp; @@ -3788,7 +3751,7 @@ ves_icall_RuntimeType_GetFields_native (MonoReflectionTypeHandle ref_type, char continue; if (((mlisttype != MLISTTYPE_All) && (utf8_name != NULL)) && compare_func (mono_field_get_name (field), utf8_name)) - continue; + continue; g_ptr_array_add (ptr_array, field); } @@ -3926,22 +3889,21 @@ mono_class_get_methods_by_name (MonoClass *klass, const char *name, guint32 bfla } GPtrArray* -ves_icall_RuntimeType_GetMethodsByName_native (MonoReflectionTypeHandle ref_type, const char *mname, guint32 bflags, guint32 mlisttype, MonoError *error) +ves_icall_RuntimeType_GetMethodsByName_native (MonoQCallTypeHandle type_handle, const char *mname, guint32 bflags, guint32 mlisttype, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (type); - if (m_type_is_byref (type)) { + if (m_type_is_byref (type)) return g_ptr_array_new (); - } return mono_class_get_methods_by_name (klass, mname, bflags, mlisttype, FALSE, error); } GPtrArray* -ves_icall_RuntimeType_GetConstructors_native (MonoReflectionTypeHandle ref_type, guint32 bflags, MonoError *error) +ves_icall_RuntimeType_GetConstructors_native (MonoQCallTypeHandle type_handle, guint32 bflags, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; if (m_type_is_byref (type)) { return g_ptr_array_new (); } @@ -4055,16 +4017,14 @@ property_accessor_nonpublic (MonoMethod* accessor, gboolean start_klass) } GPtrArray* -ves_icall_RuntimeType_GetPropertiesByName_native (MonoReflectionTypeHandle ref_type, gchar *propname, guint32 bflags, guint32 mlisttype, MonoError *error) +ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handle, gchar *propname, guint32 bflags, guint32 mlisttype, MonoError *error) { // Fetch non-public properties as well because they can hide public properties with the same name in base classes bflags |= BFLAGS_NonPublic; - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; - if (m_type_is_byref (type)) { + if (m_type_is_byref (type)) return g_ptr_array_new (); - } - MonoClass *startklass, *klass; klass = startklass = mono_class_from_mono_type_internal (type); @@ -4142,7 +4102,6 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoReflectionTypeHandle ref_t return res_array; - loader_error: if (properties) g_hash_table_destroy (properties); @@ -4167,13 +4126,12 @@ event_equal (MonoEvent *event1, MonoEvent *event2) } GPtrArray* -ves_icall_RuntimeType_GetEvents_native (MonoReflectionTypeHandle ref_type, char *utf8_name, guint32 mlisttype, MonoError *error) +ves_icall_RuntimeType_GetEvents_native (MonoQCallTypeHandle type_handle, char *utf8_name, guint32 mlisttype, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; - if (m_type_is_byref (type)) { + if (m_type_is_byref (type)) return g_ptr_array_new (); - } int (*compare_func) (const char *s1, const char *s2) = (mlisttype == MLISTTYPE_CaseInsensitive) ? mono_utf8_strcasecmp : strcmp; @@ -4238,13 +4196,12 @@ ves_icall_RuntimeType_GetEvents_native (MonoReflectionTypeHandle ref_type, char } GPtrArray * -ves_icall_RuntimeType_GetNestedTypes_native (MonoReflectionTypeHandle ref_type, char *str, guint32 bflags, guint32 mlisttype, MonoError *error) +ves_icall_RuntimeType_GetNestedTypes_native (MonoQCallTypeHandle type_handle, char *str, guint32 bflags, guint32 mlisttype, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; - if (m_type_is_byref (type)) { + if (m_type_is_byref (type)) return g_ptr_array_new (); - } int (*compare_func) (const char *s1, const char *s2) = ((bflags & BFLAGS_IgnoreCase) || (mlisttype == MLISTTYPE_CaseInsensitive)) ? mono_utf8_strcasecmp : strcmp; @@ -4279,7 +4236,7 @@ ves_icall_RuntimeType_GetNestedTypes_native (MonoReflectionTypeHandle ref_type, continue; if ((mlisttype != MLISTTYPE_All) && (str != NULL) && compare_func (m_class_get_name (nested), str)) - continue; + continue; g_ptr_array_add (res_array, m_class_get_byval_arg (nested)); } @@ -5099,13 +5056,12 @@ ves_icall_System_Reflection_Assembly_GetCallingAssembly (MonoError *error) return mono_assembly_get_object_handle (m_class_get_image (dest->klass)->assembly, error); } -MonoStringHandle -ves_icall_System_RuntimeType_getFullName (MonoReflectionTypeHandle object, MonoBoolean full_name, +void +ves_icall_System_RuntimeType_getFullName (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res, MonoBoolean full_name, MonoBoolean assembly_qualified, MonoError *error) { - MonoType *type = MONO_HANDLE_RAW (object)->type; + MonoType *type = type_handle.type; MonoTypeNameFormat format; - MonoStringHandle res; gchar *name; if (full_name) @@ -5117,17 +5073,15 @@ ves_icall_System_RuntimeType_getFullName (MonoReflectionTypeHandle object, MonoB name = mono_type_get_name_full (type, format); if (!name) - return NULL_HANDLE_STRING; + return; if (full_name && (type->type == MONO_TYPE_VAR || type->type == MONO_TYPE_MVAR)) { g_free (name); - return NULL_HANDLE_STRING; + return; } - res = mono_string_new_handle (name, error); + HANDLE_ON_STACK_SET (res, mono_string_new_checked (name, error)); g_free (name); - - return res; } MonoStringHandle @@ -6058,13 +6012,13 @@ check_for_invalid_byref_or_pointer_type (MonoClass *klass, MonoError *error) return; } -MonoReflectionTypeHandle -ves_icall_RuntimeType_make_array_type (MonoReflectionTypeHandle ref_type, int rank, MonoError *error) +void +ves_icall_RuntimeType_make_array_type (MonoQCallTypeHandle type_handle, int rank, MonoObjectHandleOnStack res, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; check_for_invalid_array_type (type, error); - return_val_if_nok (error, MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE)); + return_if_nok (error); MonoClass *klass = mono_class_from_mono_type_internal (type); MonoClass *aklass; @@ -6075,48 +6029,48 @@ ves_icall_RuntimeType_make_array_type (MonoReflectionTypeHandle ref_type, int ra if (mono_class_has_failure (aklass)) { mono_error_set_for_class_failure (error, aklass); - return MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE); + return; } - return mono_type_get_object_handle (m_class_get_byval_arg (aklass), error); + HANDLE_ON_STACK_SET (res, mono_type_get_object_checked (m_class_get_byval_arg (aklass), error)); } -MonoReflectionTypeHandle -ves_icall_RuntimeType_make_byref_type (MonoReflectionTypeHandle ref_type, MonoError *error) +void +ves_icall_RuntimeType_make_byref_type (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (type); mono_class_init_checked (klass, error); - return_val_if_nok (error, MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE)); + return_if_nok (error); check_for_invalid_byref_or_pointer_type (klass, error); - return_val_if_nok (error, MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE)); + return_if_nok (error); - return mono_type_get_object_handle (m_class_get_this_arg (klass), error); + HANDLE_ON_STACK_SET (res, mono_type_get_object_checked (m_class_get_this_arg (klass), error)); } -MonoReflectionTypeHandle -ves_icall_RuntimeType_MakePointerType (MonoReflectionTypeHandle ref_type, MonoError *error) +void +ves_icall_RuntimeType_make_pointer_type (MonoQCallTypeHandle type_handle, MonoObjectHandleOnStack res, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (type); mono_class_init_checked (klass, error); - return_val_if_nok (error, MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE)); + return_if_nok (error); check_for_invalid_byref_or_pointer_type (klass, error); - return_val_if_nok (error, MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE)); + return_if_nok (error); MonoClass *pklass = mono_class_create_ptr (type); - return mono_type_get_object_handle (m_class_get_byval_arg (pklass), error); + HANDLE_ON_STACK_SET (res, mono_type_get_object_checked (m_class_get_byval_arg (pklass), error)); } MonoObjectHandle -ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionTypeHandle ref_type, MonoObjectHandle target, +ves_icall_System_Delegate_CreateDelegate_internal (MonoQCallTypeHandle type_handle, MonoObjectHandle target, MonoReflectionMethodHandle info, MonoBoolean throwOnBindFailure, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *delegate_class = mono_class_from_mono_type_internal (type); MonoMethod *method = MONO_HANDLE_GETVAL (info, method); MonoMethodSignature *sig = mono_method_signature_internal (method); @@ -6312,9 +6266,9 @@ ves_icall_System_Diagnostics_Debugger_Log (int level, MonoString *volatile* cate /* Only used for value types */ MonoObjectHandle -ves_icall_System_Activator_CreateInstanceInternal (MonoReflectionTypeHandle ref_type, MonoError *error) +ves_icall_System_RuntimeType_CreateInstanceInternal (MonoQCallTypeHandle type_handle, MonoError *error) { - MonoType *type = MONO_HANDLE_GETVAL (ref_type, type); + MonoType *type = type_handle.type; MonoClass *klass = mono_class_from_mono_type_internal (type); (void)klass; diff --git a/src/mono/mono/metadata/loader.c b/src/mono/mono/metadata/loader.c index f31ad254bad36e..7098bb527a4b39 100644 --- a/src/mono/mono/metadata/loader.c +++ b/src/mono/mono/metadata/loader.c @@ -1666,6 +1666,7 @@ stack_walk_adapter (MonoStackFrameInfo *frame, MonoContext *ctx, gpointer data) return FALSE; case FRAME_TYPE_MANAGED: case FRAME_TYPE_INTERP: + case FRAME_TYPE_IL_STATE: g_assert (frame->ji); return d->func (frame->actual_method, frame->native_offset, frame->il_offset, frame->managed, d->user_data); break; diff --git a/src/mono/mono/metadata/marshal.c b/src/mono/mono/metadata/marshal.c index c5b96cec20e73b..498f3ff563f102 100644 --- a/src/mono/mono/metadata/marshal.c +++ b/src/mono/mono/metadata/marshal.c @@ -4981,14 +4981,9 @@ ves_icall_System_Runtime_InteropServices_Marshal_SetLastPInvokeError (guint32 er } guint32 -ves_icall_System_Runtime_InteropServices_Marshal_SizeOf (MonoReflectionTypeHandle rtype, MonoError *error) +ves_icall_System_Runtime_InteropServices_Marshal_SizeOfHelper (MonoQCallTypeHandle type_handle, MonoBoolean throwIfNotMarshalable, MonoError *error) { - if (MONO_HANDLE_IS_NULL (rtype)) { - mono_error_set_argument_null (error, "type", ""); - return 0; - } - - MonoType * const type = MONO_HANDLE_GETVAL (rtype, type); + MonoType * const type = type_handle.type; MonoClass * const klass = mono_class_from_mono_type_internal (type); if (!mono_class_init_checked (klass, error)) return 0; @@ -5008,12 +5003,6 @@ ves_icall_System_Runtime_InteropServices_Marshal_SizeOf (MonoReflectionTypeHandl return (guint32)mono_marshal_type_size (type, NULL, &align, FALSE, m_class_is_unicode (klass)); } -guint32 -ves_icall_System_Runtime_InteropServices_Marshal_SizeOfHelper (MonoReflectionTypeHandle rtype, MonoBoolean throwIfNotMarshalable, MonoError *error) -{ - return ves_icall_System_Runtime_InteropServices_Marshal_SizeOf (rtype, error); -} - void ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr (MonoObjectHandle obj, gpointer dst, MonoBoolean delete_old, MonoError *error) { @@ -5209,14 +5198,14 @@ ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure (gpointer src, mono_struct_delete_old (klass, (char *)src); } -MonoDelegateHandle -ves_icall_System_Runtime_InteropServices_Marshal_GetDelegateForFunctionPointerInternal (void *ftn, MonoReflectionTypeHandle type, MonoError *error) +void +ves_icall_System_Runtime_InteropServices_Marshal_GetDelegateForFunctionPointerInternal (MonoQCallTypeHandle type_handle, void *ftn, MonoObjectHandleOnStack res, MonoError *error) { - MonoClass *klass = mono_type_get_class_internal (MONO_HANDLE_GETVAL (type, type)); + MonoClass *klass = mono_type_get_class_internal (type_handle.type); if (!mono_class_init_checked (klass, error)) - return MONO_HANDLE_CAST (MonoDelegate, NULL_HANDLE); + return; - return mono_ftnptr_to_delegate_impl (klass, ftn, error); + HANDLE_ON_STACK_SET (res, MONO_HANDLE_RAW (mono_ftnptr_to_delegate_impl (klass, ftn, error))); } gpointer @@ -5226,9 +5215,9 @@ ves_icall_System_Runtime_InteropServices_Marshal_GetFunctionPointerForDelegateIn } MonoBoolean -ves_icall_System_Runtime_InteropServices_Marshal_IsPinnableType (MonoReflectionTypeHandle type_h, MonoError *error) +ves_icall_System_Runtime_InteropServices_Marshal_IsPinnableType (MonoQCallTypeHandle type_handle) { - MonoClass *klass = mono_class_from_mono_type_internal (MONO_HANDLE_GETVAL (type_h, type)); + MonoClass *klass = mono_class_from_mono_type_internal (type_handle.type); if (m_class_get_rank (klass)) { MonoClass *eklass = m_class_get_element_class (klass); diff --git a/src/mono/mono/metadata/object-internals.h b/src/mono/mono/metadata/object-internals.h index 425604aeabdbd1..6c6d089ee2122a 100644 --- a/src/mono/mono/metadata/object-internals.h +++ b/src/mono/mono/metadata/object-internals.h @@ -451,6 +451,22 @@ struct _MonoReflectionType { /* Safely access System.Type from native code */ TYPED_HANDLE_DECL (MonoReflectionType); +/* This corresponds to System.Runtime.CompilerServices.QCallTypeHandle */ +struct _MonoQCallTypeHandle { + gpointer _ptr; + MonoType *type; +}; + +typedef struct _MonoQCallTypeHandle MonoQCallTypeHandle; + +/* This corresponds to System.Runtime.CompilerServices.QCallAssembly */ +struct _MonoQCallAssemblyHandle { + gpointer _ptr; + MonoAssembly *assembly; +}; + +typedef struct _MonoQCallAssemblyHandle MonoQCallAssemblyHandle; + typedef struct { MonoObject object; MonoReflectionType *class_to_proxy; diff --git a/src/mono/mono/metadata/object.c b/src/mono/mono/metadata/object.c index fe03fcab2b5ab6..284e15b1ade8e3 100644 --- a/src/mono/mono/metadata/object.c +++ b/src/mono/mono/metadata/object.c @@ -2171,7 +2171,7 @@ mono_class_create_runtime_vtable (MonoClass *klass, MonoError *error) * re-acquire them and check if another thread has created the vtable in the meantime. */ /* Special case System.MonoType to avoid infinite recursion */ - if (klass != mono_defaults.runtimetype_class) { + if (!mono_runtime_get_no_exec () && klass != mono_defaults.runtimetype_class) { MonoReflectionTypeHandle vt_type = mono_type_get_object_handle (m_class_get_byval_arg (klass), error); vt->type = MONO_HANDLE_RAW (vt_type); if (!is_ok (error)) { @@ -2199,7 +2199,7 @@ mono_class_create_runtime_vtable (MonoClass *klass, MonoError *error) mono_memory_barrier (); mono_class_set_runtime_vtable (klass, vt); - if (klass == mono_defaults.runtimetype_class) { + if (!mono_runtime_get_no_exec () && klass == mono_defaults.runtimetype_class) { MonoReflectionTypeHandle vt_type = mono_type_get_object_handle (m_class_get_byval_arg (klass), error); vt->type = MONO_HANDLE_RAW (vt_type); if (!is_ok (error)) { diff --git a/src/mono/mono/mini/interp/interp.c b/src/mono/mono/mini/interp/interp.c index 2cd43b6fffd6a9..e5aef94c5c6ee1 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -1308,7 +1308,8 @@ static MonoFuncV mono_native_to_interp_trampoline = NULL; #endif #ifndef MONO_ARCH_HAVE_INTERP_PINVOKE_TRAMP -static InterpMethodArguments* build_args_from_sig (MonoMethodSignature *sig, InterpFrame *frame) +static InterpMethodArguments* +build_args_from_sig (MonoMethodSignature *sig, InterpFrame *frame) { InterpMethodArguments *margs = g_malloc0 (sizeof (InterpMethodArguments)); @@ -1436,6 +1437,14 @@ static InterpMethodArguments* build_args_from_sig (MonoMethodSignature *sig, Int #if DEBUG_INTERP g_print ("build_args_from_sig: margs->iargs [%d]: %p (vt) (frame @ %d)\n", int_i, margs->iargs [int_i], i); #endif + +#ifdef HOST_WASM + { + /* Scalar vtypes are passed by value */ + if (mini_wasm_is_scalar_vtype (sig->params [i])) + margs->iargs [int_i] = *(gpointer*)margs->iargs [int_i]; + } +#endif int_i++; break; case MONO_TYPE_GENERICINST: { diff --git a/src/mono/mono/mini/mini-wasm.c b/src/mono/mono/mini/mini-wasm.c index baa428336a98bc..67bbdbc94af695 100644 --- a/src/mono/mono/mini/mini-wasm.c +++ b/src/mono/mono/mini/mini-wasm.c @@ -40,44 +40,6 @@ struct CallInfo { ArgInfo args [1]; }; -/* Return whenever TYPE represents a vtype with only one scalar member */ -static gboolean -is_scalar_vtype (MonoType *type) -{ - MonoClass *klass; - MonoClassField *field; - gpointer iter; - - if (!MONO_TYPE_ISSTRUCT (type)) - return FALSE; - klass = mono_class_from_mono_type_internal (type); - mono_class_init_internal (klass); - - int size = mono_class_value_size (klass, NULL); - if (size == 0 || size >= 8) - return FALSE; - - iter = NULL; - int nfields = 0; - field = NULL; - while ((field = mono_class_get_fields_internal (klass, &iter))) { - if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) - continue; - nfields ++; - if (nfields > 1) - return FALSE; - MonoType *t = mini_get_underlying_type (field->type); - if (MONO_TYPE_ISSTRUCT (t)) { - if (!is_scalar_vtype (t)) - return FALSE; - } else if (!((MONO_TYPE_IS_PRIMITIVE (t) || MONO_TYPE_IS_REFERENCE (t)))) { - return FALSE; - } - } - - return TRUE; -} - // WASM ABI: https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md static ArgStorage @@ -117,7 +79,7 @@ get_storage (MonoType *type, gboolean is_return) /* fall through */ case MONO_TYPE_VALUETYPE: case MONO_TYPE_TYPEDBYREF: { - if (is_scalar_vtype (type)) + if (mini_wasm_is_scalar_vtype (type)) return ArgVtypeAsScalar; return is_return ? ArgValuetypeAddrInIReg : ArgValuetypeAddrOnStack; } @@ -829,3 +791,41 @@ mono_wasm_get_debug_level (void) { return mono_wasm_debug_level; } + +/* Return whenever TYPE represents a vtype with only one scalar member */ +gboolean +mini_wasm_is_scalar_vtype (MonoType *type) +{ + MonoClass *klass; + MonoClassField *field; + gpointer iter; + + if (!MONO_TYPE_ISSTRUCT (type)) + return FALSE; + klass = mono_class_from_mono_type_internal (type); + mono_class_init_internal (klass); + + int size = mono_class_value_size (klass, NULL); + if (size == 0 || size >= 8) + return FALSE; + + iter = NULL; + int nfields = 0; + field = NULL; + while ((field = mono_class_get_fields_internal (klass, &iter))) { + if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) + continue; + nfields ++; + if (nfields > 1) + return FALSE; + MonoType *t = mini_get_underlying_type (field->type); + if (MONO_TYPE_ISSTRUCT (t)) { + if (!mini_wasm_is_scalar_vtype (t)) + return FALSE; + } else if (!((MONO_TYPE_IS_PRIMITIVE (t) || MONO_TYPE_IS_REFERENCE (t) || MONO_TYPE_IS_POINTER (t)))) { + return FALSE; + } + } + + return TRUE; +} diff --git a/src/mono/mono/mini/mini-wasm.h b/src/mono/mono/mini/mini-wasm.h index 4dfb04059e17b9..c98f7603828d5a 100644 --- a/src/mono/mono/mini/mini-wasm.h +++ b/src/mono/mono/mini/mini-wasm.h @@ -105,4 +105,7 @@ void mono_wasm_set_timeout (int timeout); int mono_wasm_assembly_already_added (const char *assembly_name); void mono_wasm_print_stack_trace (void); +gboolean +mini_wasm_is_scalar_vtype (MonoType *type); + #endif /* __MONO_MINI_WASM_H__ */