public FixupCellMetadataResolver(NativeFormatMetadataUnit metadataUnit, NativeLayoutInfoLoadContext loadContext) { _metadataUnit = metadataUnit; _methodContext = null; _typeContext = null; _loadContextFromNativeLayout = loadContext; }
// TODO // bool _hasModifiers; public NativeFormatSignatureParser(NativeFormatMetadataUnit metadataUnit, Handle signatureHandle, MetadataReader metadataReader) { _metadataUnit = metadataUnit; _signatureHandle = signatureHandle; _metadataReader = metadataReader; // _hasModifiers = false; }
public FixupCellMetadataResolver(NativeFormatMetadataUnit metadataUnit, MethodDesc methodContext) { _metadataUnit = metadataUnit; _methodContext = methodContext; _typeContext = methodContext.OwningType; _loadContextFromNativeLayout = null; }
/// <summary> /// Attempt a virtual dispatch on a given instanceType based on the method found via a metadata token /// </summary> private static bool TryDispatchMethodOnTarget_Inner(NativeFormatModuleInfo module, int metadataToken, RuntimeTypeHandle targetInstanceType, out IntPtr methodAddress) { #if SUPPORTS_NATIVE_METADATA_TYPE_LOADING TypeSystemContext context = TypeSystemContextFactory.Create(); NativeFormatMetadataUnit metadataUnit = context.ResolveMetadataUnit(module); MethodDesc targetMethod = metadataUnit.GetMethod(metadataToken.AsHandle(), null); TypeDesc instanceType = context.ResolveRuntimeTypeHandle(targetInstanceType); MethodDesc realTargetMethod = targetMethod; // For non-interface methods we support the target method not being the exact target. (This allows // a canonical method to be passed in and work for any generic type instantiation.) if (!targetMethod.OwningType.IsInterface) { realTargetMethod = instanceType.FindMethodOnTypeWithMatchingTypicalMethod(targetMethod); } bool success = LazyVTableResolver.TryDispatchMethodOnTarget(instanceType, realTargetMethod, out methodAddress); TypeSystemContextFactory.Recycle(context); return(success); #else methodAddress = IntPtr.Zero; return(false); #endif }
internal NativeFormatType(NativeFormatMetadataUnit metadataUnit, TypeDefinitionHandle handle) { _handle = handle; _metadataUnit = metadataUnit; _typeDefinition = metadataUnit.MetadataReader.GetTypeDefinition(handle); _module = metadataUnit.GetModuleFromNamespaceDefinition(_typeDefinition.NamespaceDefinition); _baseType = this; // Not yet initialized flag #if DEBUG // Initialize name eagerly in debug builds for convenience this.ToString(); #endif }
public override ModuleDesc ResolveAssembly(System.Reflection.AssemblyName name, bool throwErrorIfNotFound) { #if SUPPORTS_NATIVE_METADATA_TYPE_LOADING AssemblyBindResult bindResult; Exception failureException; if (!AssemblyBinderImplementation.Instance.Bind(name, out bindResult, out failureException)) { if (throwErrorIfNotFound) { throw failureException; } return(null); } var moduleList = Internal.Runtime.TypeLoader.ModuleList.Instance; IntPtr primaryModuleHandle = moduleList.GetModuleForMetadataReader(bindResult.Reader); NativeFormatMetadataUnit metadataUnit = ResolveMetadataUnit(primaryModuleHandle); return(metadataUnit.GetModule(bindResult.ScopeDefinitionHandle)); #else return(null); #endif }
public override ModuleDesc ResolveAssembly(System.Reflection.AssemblyName name, bool throwErrorIfNotFound) { #if SUPPORTS_NATIVE_METADATA_TYPE_LOADING AssemblyBindResult bindResult; Exception failureException; if (!AssemblyBinderImplementation.Instance.Bind(name, out bindResult, out failureException)) { if (throwErrorIfNotFound) { throw failureException; } return(null); } var moduleList = Internal.Runtime.TypeLoader.ModuleList.Instance; if (bindResult.Reader != null) { NativeFormatModuleInfo primaryModule = moduleList.GetModuleInfoForMetadataReader(bindResult.Reader); NativeFormatMetadataUnit metadataUnit = ResolveMetadataUnit(primaryModule); return(metadataUnit.GetModule(bindResult.ScopeDefinitionHandle)); } #if ECMA_METADATA_SUPPORT else if (bindResult.EcmaMetadataReader != null) { EcmaModuleInfo ecmaModule = moduleList.GetModuleInfoForMetadataReader(bindResult.EcmaMetadataReader); return(ResolveEcmaModule(ecmaModule)); } #endif else { // Should not be possible to reach here throw new Exception(); } #else return(null); #endif }
internal TypeDesc GetTypeDescFromQHandle(QTypeDefinition qTypeDefinition) { #if ECMA_METADATA_SUPPORT if (qTypeDefinition.IsNativeFormatMetadataBased) #endif { MetadataReader nativeFormatMetadataReader = qTypeDefinition.NativeFormatReader; TypeDefinitionHandle typeDefinitionHandle = qTypeDefinition.NativeFormatHandle; NativeFormatModuleInfo module = ModuleList.Instance.GetModuleInfoForMetadataReader(nativeFormatMetadataReader); NativeFormatMetadataUnit metadataUnit = ResolveMetadataUnit(module); NativeFormatType nativeFormatType = (NativeFormatType)metadataUnit.GetType(typeDefinitionHandle); return(nativeFormatType); } #if ECMA_METADATA_SUPPORT else if (qTypeDefinition.IsEcmaFormatMetadataBased) { EcmaModuleInfo module = ModuleList.Instance.GetModuleInfoForMetadataReader(qTypeDefinition.EcmaFormatReader); Ecma.EcmaModule ecmaModule = ResolveEcmaModule(module); Ecma.EcmaType ecmaType = (Ecma.EcmaType)ecmaModule.GetType(qTypeDefinition.EcmaFormatHandle); return(ecmaType); } #endif return(null); }
/// <summary> /// Build an array of GenericDictionaryCell from a NativeParser stream that has the appropriate metadata /// Return null if there are no cells to describe /// </summary> internal unsafe static GenericDictionaryCell[] BuildDictionaryFromMetadataTokensAndContext(TypeBuilder typeBuilder, NativeParser parser, NativeFormatMetadataUnit nativeMetadataUnit, FixupCellMetadataResolver resolver) { uint parserStartOffset = parser.Offset; uint count = parser.GetSequenceCount(); // An empty dictionary isn't interesting if (count == 0) return null; Debug.Assert(count > 0); TypeLoaderLogger.WriteLine("Parsing dictionary layout @ " + parserStartOffset.LowLevelToString() + " (" + count.LowLevelToString() + " entries)"); GenericDictionaryCell[] dictionary = new GenericDictionaryCell[count]; for (uint i = 0; i < count; i++) { MetadataFixupKind fixupKind = (MetadataFixupKind)parser.GetUInt8(); Internal.Metadata.NativeFormat.Handle token = parser.GetUnsigned().AsHandle(); Internal.Metadata.NativeFormat.Handle token2 = new Internal.Metadata.NativeFormat.Handle(); switch (fixupKind) { case MetadataFixupKind.GenericConstrainedMethod: case MetadataFixupKind.NonGenericConstrainedMethod: case MetadataFixupKind.NonGenericDirectConstrainedMethod: token2 = parser.GetUnsigned().AsHandle(); break; } GenericDictionaryCell cell = CreateCellFromFixupKindAndToken(fixupKind, resolver, token, token2); cell.Prepare(typeBuilder); dictionary[i] = cell; } return dictionary; }
internal NativeFormatGenericParameter(NativeFormatMetadataUnit metadataUnit, GenericParameterHandle handle) { _metadataUnit = metadataUnit; _handle = handle; }
public TypeDesc ResolveRuntimeTypeHandle(RuntimeTypeHandle rtth) { TypeDesc returnedType; if (_runtimeTypeHandleResolutionCache.TryGetValue(rtth, out returnedType)) { return(returnedType); } if (rtth.Equals(CanonType.RuntimeTypeHandle)) { returnedType = CanonType; } else if (rtth.Equals(UniversalCanonType.RuntimeTypeHandle)) { returnedType = UniversalCanonType; } else if (RuntimeAugments.IsGenericTypeDefinition(rtth)) { #if SUPPORTS_NATIVE_METADATA_TYPE_LOADING MetadataReader metadataReader; TypeDefinitionHandle typeDefinitionHandle; if (TypeLoaderEnvironment.Instance.TryGetMetadataForNamedType(rtth, out metadataReader, out typeDefinitionHandle)) { IntPtr moduleHandle = ModuleList.Instance.GetModuleForMetadataReader(metadataReader); NativeFormatMetadataUnit metadataUnit = ResolveMetadataUnit(moduleHandle); NativeFormatType nativeFormatType = (NativeFormatType)metadataUnit.GetType(typeDefinitionHandle); returnedType = nativeFormatType; } if (returnedType == null) #endif { unsafe { TypeDesc[] genericParameters = new TypeDesc[rtth.ToEETypePtr()->GenericArgumentCount]; for (int i = 0; i < genericParameters.Length; i++) { genericParameters[i] = GetSignatureVariable(i, false); } returnedType = new NoMetadataType(this, rtth, null, new Instantiation(genericParameters), rtth.GetHashCode()); } } } else if (RuntimeAugments.IsGenericType(rtth)) { RuntimeTypeHandle typeDefRuntimeTypeHandle; RuntimeTypeHandle[] genericArgRuntimeTypeHandles; typeDefRuntimeTypeHandle = RuntimeAugments.GetGenericInstantiation(rtth, out genericArgRuntimeTypeHandles); DefType typeDef = (DefType)ResolveRuntimeTypeHandle(typeDefRuntimeTypeHandle); Instantiation genericArgs = ResolveRuntimeTypeHandles(genericArgRuntimeTypeHandles); returnedType = ResolveGenericInstantiation(typeDef, genericArgs); } else if (RuntimeAugments.IsArrayType(rtth)) { RuntimeTypeHandle elementTypeHandle = RuntimeAugments.GetRelatedParameterTypeHandle(rtth); TypeDesc elementType = ResolveRuntimeTypeHandle(elementTypeHandle); unsafe { if (rtth.ToEETypePtr()->IsSzArray) { returnedType = GetArrayType(elementType); } else { returnedType = GetArrayType(elementType, rtth.ToEETypePtr()->ArrayRank); } } } else if (RuntimeAugments.IsUnmanagedPointerType(rtth)) { RuntimeTypeHandle targetTypeHandle = RuntimeAugments.GetRelatedParameterTypeHandle(rtth); TypeDesc targetType = ResolveRuntimeTypeHandle(targetTypeHandle); returnedType = GetPointerType(targetType); } else { #if SUPPORTS_NATIVE_METADATA_TYPE_LOADING MetadataReader metadataReader; TypeDefinitionHandle typeDefinitionHandle; if (TypeLoaderEnvironment.Instance.TryGetMetadataForNamedType(rtth, out metadataReader, out typeDefinitionHandle)) { IntPtr moduleHandle = ModuleList.Instance.GetModuleForMetadataReader(metadataReader); NativeFormatMetadataUnit metadataUnit = ResolveMetadataUnit(moduleHandle); returnedType = metadataUnit.GetType(typeDefinitionHandle); } else #endif { returnedType = new NoMetadataType(this, rtth, null, Instantiation.Empty, rtth.GetHashCode()); } } // We either retrieved an existing DefType that is already registered with the runtime // or one that is not associated with an EEType yet. If it's not associated, associate it. if (returnedType.RuntimeTypeHandle.IsNull()) { TypeBuilderState state = returnedType.GetTypeBuilderStateIfExist(); bool skipStoringRuntimeTypeHandle = false; // If we've already attempted to lookup and failed to retrieve this type handle, we // may have already decided to create a new one. In that case, do not attempt to abort // that creation process as it may have already begun the process of type creation if (state != null && state.AttemptedAndFailedToRetrieveTypeHandle) { skipStoringRuntimeTypeHandle = true; } if (!skipStoringRuntimeTypeHandle) { returnedType.SetRuntimeTypeHandleUnsafe(rtth); } } _runtimeTypeHandleResolutionCache.Add(rtth, returnedType); return(returnedType.WithDebugName()); }