public bool TryGetGenericVirtualTargetForTypeAndSlot(RuntimeTypeHandle targetHandle, ref RuntimeTypeHandle declaringType, RuntimeTypeHandle[] genericArguments, ref string methodName, ref RuntimeMethodSignature methodSignature, out IntPtr methodPointer, out IntPtr dictionaryPointer, out bool slotUpdated)
        {
            MethodNameAndSignature methodNameAndSignature = new MethodNameAndSignature(methodName, methodSignature);

#if REFLECTION_EXECUTION_TRACE
            ReflectionExecutionLogger.WriteLine("GVM resolution starting for " + GetTypeNameDebug(declaringType) + "." + methodNameAndSignature.Name + "(...)  on a target of type " + GetTypeNameDebug(targetHandle) + " ...");
#endif

            if (RuntimeAugments.IsInterface(declaringType))
            {
                methodPointer = IntPtr.Zero;
                dictionaryPointer = IntPtr.Zero;

                slotUpdated = ResolveInterfaceGenericVirtualMethodSlot(targetHandle, ref declaringType, ref methodNameAndSignature);

                methodName = methodNameAndSignature.Name;
                methodSignature = methodNameAndSignature.Signature;
                return slotUpdated;
            }
            else
            {
                slotUpdated = false;
                return ResolveGenericVirtualMethodTarget(targetHandle, declaringType, genericArguments, methodNameAndSignature, out methodPointer, out dictionaryPointer);
            }
        }
예제 #2
0
        public bool Equals(RuntimeMethodSignature other)
        {
            if (IsNativeLayoutSignature && other.IsNativeLayoutSignature)
            {
                if (NativeLayoutSignature == other.NativeLayoutSignature)
                    return true;
            }
            else if (!IsNativeLayoutSignature && !other.IsNativeLayoutSignature)
            {
                if ((ModuleHandle == other.ModuleHandle) && (Token == other.Token))
                    return true;
            }

            // Walk both signatures to check for equality the slow way
            return RuntimeAugments.TypeLoaderCallbacks.CompareMethodSignatures(this, other);
        }
        public bool CompareMethodSignatures(RuntimeMethodSignature signature1, RuntimeMethodSignature signature2)
        {
            IntPtr nativeLayoutSignature1 = signature1.NativeLayoutSignature;
            IntPtr nativeLayoutSignature2 = signature2.NativeLayoutSignature;

            if ((nativeLayoutSignature1 != IntPtr.Zero) && (nativeLayoutSignature2 != IntPtr.Zero))
            {
                if (nativeLayoutSignature1 == nativeLayoutSignature2)
                    return true;

                NativeReader reader1 = GetNativeLayoutInfoReader(RuntimeAugments.GetModuleFromPointer(nativeLayoutSignature1));
                NativeParser parser1 = new NativeParser(reader1, reader1.AddressToOffset(nativeLayoutSignature1));

                NativeReader reader2 = GetNativeLayoutInfoReader(RuntimeAugments.GetModuleFromPointer(nativeLayoutSignature2));
                NativeParser parser2 = new NativeParser(reader2, reader2.AddressToOffset(nativeLayoutSignature2));

                return CompareMethodSigs(parser1, parser2);
            }
            else if (nativeLayoutSignature1 != IntPtr.Zero)
            {
                int token = signature2.Token;
                MetadataReader metadataReader = ModuleList.Instance.GetMetadataReaderForModule(signature2.ModuleHandle);

                MethodSignatureComparer comparer = new MethodSignatureComparer(metadataReader, token.AsHandle().ToMethodHandle(metadataReader));
                return comparer.IsMatchingNativeLayoutMethodSignature(nativeLayoutSignature1);
            }
            else if (nativeLayoutSignature2 != IntPtr.Zero)
            {
                int token = signature1.Token;
                MetadataReader metadataReader = ModuleList.Instance.GetMetadataReaderForModule(signature1.ModuleHandle);

                MethodSignatureComparer comparer = new MethodSignatureComparer(metadataReader, token.AsHandle().ToMethodHandle(metadataReader));
                return comparer.IsMatchingNativeLayoutMethodSignature(nativeLayoutSignature2);
            }
            else
            {
                // For now, RuntimeMethodSignatures are only used to compare for method signature equality (along with their Name)
                // So we can implement this with the simple equals check
                if (signature1.Token != signature2.Token)
                    return false;

                if (signature1.ModuleHandle != signature2.ModuleHandle)
                    return false;

                return true;
            }
        }
예제 #4
0
 public abstract bool TryGetGenericVirtualTargetForTypeAndSlot(RuntimeTypeHandle targetHandle, ref RuntimeTypeHandle declaringType, RuntimeTypeHandle[] genericArguments, ref string methodName, ref RuntimeMethodSignature methodSignature, out IntPtr methodPointer, out IntPtr dictionaryPointer, out bool slotUpdated);
예제 #5
0
 public abstract bool CompareMethodSignatures(RuntimeMethodSignature signature1, RuntimeMethodSignature signature2);
예제 #6
0
 public static unsafe IntPtr MakeThunk(ThunkKind thunkKind, IntPtr targetPointer, RuntimeMethodSignature methodSignature, IntPtr instantiatingArg, RuntimeTypeHandle[] typeArgs, RuntimeTypeHandle[] methodArgs)
 {
     int callConversionInfo = CallConversionInfo.RegisterCallConversionInfo(thunkKind, targetPointer, methodSignature, instantiatingArg, typeArgs, methodArgs);
     return FindExistingOrAllocateThunk(callConversionInfo);
 }
        internal bool MethodSignatureHasVarsNeedingCallingConventionConverter(TypeSystemContext context, RuntimeMethodSignature methodSig)
        {
            if (methodSig.IsNativeLayoutSignature)
                return MethodSignatureHasVarsNeedingCallingConventionConverter_NativeLayout(context, methodSig.NativeLayoutSignature);
            else
            {
#if SUPPORTS_NATIVE_METADATA_TYPE_LOADING
                MetadataReader metadataReader = ModuleList.Instance.GetMetadataReaderForModule(methodSig.ModuleHandle);
                var methodHandle = methodSig.Token.AsHandle().ToMethodHandle(metadataReader);
                var metadataUnit = ((TypeLoaderTypeSystemContext)context).ResolveMetadataUnit(methodSig.ModuleHandle);
                var parser = new Internal.TypeSystem.NativeFormat.NativeFormatSignatureParser(metadataUnit, metadataReader.GetMethod(methodHandle).Signature, metadataReader);
                var signature = parser.ParseMethodSignature();

                return MethodSignatureHasVarsNeedingCallingConventionConverter_MethodSignature(signature);
#else
                Environment.FailFast("Cannot parse signature");
                return false;
#endif
            }
        }
        internal bool GetCallingConverterDataFromMethodSignature(TypeSystemContext context, RuntimeMethodSignature methodSig, NativeLayoutInfoLoadContext nativeLayoutContext, out bool hasThis, out TypeDesc[] parameters, out bool[] parametersWithGenericDependentLayout)
        {
            if (methodSig.IsNativeLayoutSignature)
                return GetCallingConverterDataFromMethodSignature_NativeLayout(context, methodSig.NativeLayoutSignature, nativeLayoutContext, out hasThis, out parameters, out parametersWithGenericDependentLayout);
            else
            {
#if SUPPORTS_NATIVE_METADATA_TYPE_LOADING
                MetadataReader metadataReader = ModuleList.Instance.GetMetadataReaderForModule(methodSig.ModuleHandle);
                var methodHandle = methodSig.Token.AsHandle().ToMethodHandle(metadataReader);
                var metadataUnit = ((TypeLoaderTypeSystemContext)context).ResolveMetadataUnit(methodSig.ModuleHandle);
                var parser = new Internal.TypeSystem.NativeFormat.NativeFormatSignatureParser(metadataUnit, metadataReader.GetMethod(methodHandle).Signature, metadataReader);
                var signature = parser.ParseMethodSignature();

                return GetCallingConverterDataFromMethodSignature_MethodSignature(signature, nativeLayoutContext, out hasThis, out parameters, out parametersWithGenericDependentLayout);
#else
                parametersWithGenericDependentLayout = null;
                hasThis = false;
                parameters = null;
                return false;
#endif
            }
        }
        internal bool IsStaticMethodSignature(RuntimeMethodSignature methodSig)
        {
            if (methodSig.IsNativeLayoutSignature)
            {
                IntPtr moduleHandle = RuntimeAugments.GetModuleFromPointer(methodSig.NativeLayoutSignature);
                NativeReader reader = GetNativeLayoutInfoReader(moduleHandle);
                NativeParser parser = new NativeParser(reader, reader.AddressToOffset(methodSig.NativeLayoutSignature));

                MethodCallingConvention callingConvention = (MethodCallingConvention)parser.GetUnsigned();
                return callingConvention.HasFlag(MethodCallingConvention.Static);
            }
            else
            {
                var metadataReader = ModuleList.Instance.GetMetadataReaderForModule(methodSig.ModuleHandle);
                var methodHandle = methodSig.Token.AsHandle().ToMethodHandle(metadataReader);

                var method = methodHandle.GetMethod(metadataReader);
                return (method.Flags & MethodAttributes.Static) != 0;
            }
        }
예제 #10
0
 public override bool TryGetGenericVirtualTargetForTypeAndSlot(RuntimeTypeHandle targetHandle, ref RuntimeTypeHandle declaringType, RuntimeTypeHandle[] genericArguments, ref string methodName, ref RuntimeMethodSignature methodSignature, out IntPtr methodPointer, out IntPtr dictionaryPointer, out bool slotUpdated)
 {
     return TypeLoaderEnvironment.Instance.TryGetGenericVirtualTargetForTypeAndSlot(targetHandle, ref declaringType, genericArguments, ref methodName, ref methodSignature, out methodPointer, out dictionaryPointer, out slotUpdated);
 }
예제 #11
0
 public override bool CompareMethodSignatures(RuntimeMethodSignature signature1, RuntimeMethodSignature signature2)
 {
     return TypeLoaderEnvironment.Instance.CompareMethodSignatures(signature1, signature2);
 }
 public unsafe bool TryGetRuntimeMethodHandleForComponents(RuntimeTypeHandle declaringTypeHandle, IntPtr methodName, RuntimeMethodSignature methodSignature, RuntimeTypeHandle[] genericMethodArgs, out RuntimeMethodHandle handle)
 {
     handle = default(RuntimeMethodHandle);
     fixed (RuntimeMethodHandle* pRMH = &handle)
     {
         IntPtr rmhAsPointer = TryGetRuntimeMethodHandleForComponents(declaringTypeHandle, methodName, methodSignature, genericMethodArgs);
         *((IntPtr*)pRMH) = rmhAsPointer;
         return rmhAsPointer != IntPtr.Zero;
     }
 }
        /// <summary>
        /// Create a runtime method handle from name, signature and generic arguments. If the methodSignature 
        /// is constructed from a metadata token, the methodName should be IntPtr.Zero, as it already encodes the method
        /// name.
        /// </summary>
        internal unsafe IntPtr TryGetRuntimeMethodHandleForComponents(RuntimeTypeHandle declaringTypeHandle, IntPtr methodName, RuntimeMethodSignature methodSignature, RuntimeTypeHandle[] genericMethodArgs)
        {
            int sizeToAllocate = sizeof(DynamicMethodHandleInfo);
            // Use checked arithmetics to ensure there aren't any overflows/truncations
            sizeToAllocate = checked(sizeToAllocate + (genericMethodArgs.Length > 0 ? sizeof(IntPtr) * (genericMethodArgs.Length - 1) : 0));
            IntPtr runtimeMethodHandleValue = MemoryHelpers.AllocateMemory(sizeToAllocate);

            DynamicMethodHandleInfo* methodData = (DynamicMethodHandleInfo*)runtimeMethodHandleValue.ToPointer();
            methodData->DeclaringType = *(IntPtr*)&declaringTypeHandle;
            methodData->MethodName = methodName;
            methodData->MethodSignature = methodSignature;
            methodData->NumGenericArgs = genericMethodArgs.Length;
            IntPtr* genericArgPtr = &(methodData->GenericArgsArray);
            for (int i = 0; i < genericMethodArgs.Length; i++)
            {
                RuntimeTypeHandle currentArg = genericMethodArgs[i];
                genericArgPtr[i] = *(IntPtr*)&currentArg;
            }

            // Special flag in the handle value to indicate it was dynamically allocated, and doesn't point into the InvokeMap blob
            return runtimeMethodHandleValue + 1;
        }
예제 #14
0
        /// <summary>
        /// Fast equality check
        /// </summary>
        public bool StructuralEquals(RuntimeMethodSignature other)
        {
            if (_ptrField != other._ptrField)
                return false;

            if (_intField != other._intField)
                return false;

            if (_isNativeLayoutSignature != other._isNativeLayoutSignature)
                return false;

            return true;
        }
예제 #15
0
 public MethodNameAndSignature(string name, RuntimeMethodSignature signature)
 {
     Name = name;
     Signature = signature;
 }