Esempio n. 1
0
        internal RuntimeType(RuntimeTypeHandle handle)
        {
            this.handle = handle;
            typeStruct = (MetadataTypeStruct*)((uint**)&handle)[0];

            assemblyQualifiedName = Mosa.Runtime.Internal.InitializeMetadataString(typeStruct->Name);    // TODO
            name = Mosa.Runtime.Internal.InitializeMetadataString(typeStruct->Name);                 // TODO
            @namespace = Mosa.Runtime.Internal.InitializeMetadataString(typeStruct->Name);               // TODO
            fullname = Mosa.Runtime.Internal.InitializeMetadataString(typeStruct->Name);

            typeCode = (TypeCode)(typeStruct->Attributes >> 24);
            attributes = (TypeAttributes)(typeStruct->Attributes & 0x00FFFFFF);

            // Declaring Type
            if (typeStruct->DeclaringType != null)
            {
                RuntimeTypeHandle declaringHandle = new RuntimeTypeHandle();
                ((uint**)&declaringHandle)[0] = (uint*)typeStruct->DeclaringType;
                declaringTypeHandle = declaringHandle;
            }

            // Element Type
            if ((*typeStruct).ElementType != null)
            {
                RuntimeTypeHandle elementHandle = new RuntimeTypeHandle();
                ((uint**)&elementHandle)[0] = (uint*)typeStruct->ElementType;
                elementTypeHandle = elementHandle;
            }
        }
Esempio n. 2
0
        public static void *IsInstanceOfInterfaceType(int interfaceSlot, void *obj)
        {
            MetadataTypeStruct *objTypeDefinition = (MetadataTypeStruct *)((uint *)obj)[0];

            if (objTypeDefinition == null)
            {
                return(null);
            }

            uint *bitmap = objTypeDefinition->Bitmap;

            if (bitmap == null)
            {
                return(null);
            }

            int  index  = interfaceSlot / 32;
            int  bit    = interfaceSlot % 32;
            uint value  = bitmap[index];
            uint result = value & (uint)(1 << bit);

            if (result == 0)
            {
                return(null);
            }

            return(obj);
        }
Esempio n. 3
0
        internal RuntimeType(RuntimeTypeHandle handle)
        {
            this.handle     = handle;
            this.typeStruct = (MetadataTypeStruct *)((uint **)&handle)[0];

            this.assemblyQualifiedName = x86Runtime.InitializeMetadataString(this.typeStruct->Name);            // TODO
            this.name       = x86Runtime.InitializeMetadataString(this.typeStruct->Name);                       // TODO
            this.@namespace = x86Runtime.InitializeMetadataString(this.typeStruct->Name);                       // TODO
            this.fullname   = x86Runtime.InitializeMetadataString(this.typeStruct->Name);

            this.typeCode   = (TypeCode)(this.typeStruct->Attributes >> 24);
            this.attributes = (TypeAttributes)(this.typeStruct->Attributes & 0x00FFFFFF);

            // Declaring Type
            if (this.typeStruct->DeclaringType != null)
            {
                RuntimeTypeHandle declaringHandle = new RuntimeTypeHandle();
                ((uint **)&declaringHandle)[0] = (uint *)this.typeStruct->DeclaringType;
                this.declaringTypeHandle       = declaringHandle;
            }

            // Element Type
            if ((*this.typeStruct).ElementType != null)
            {
                RuntimeTypeHandle elementHandle = new RuntimeTypeHandle();
                ((uint **)&elementHandle)[0] = (uint *)this.typeStruct->ElementType;
                this.elementTypeHandle       = elementHandle;
            }
        }
Esempio n. 4
0
 internal RuntimeType(RuntimeTypeHandle handle)
 {
     this.handle = handle;
     this.typeStruct = (MetadataTypeStruct*)((uint**)&handle)[0];
     this.assemblyQualifiedName = x86Runtime.InitializeMetadataString((*this.typeStruct).Name);
     this.name = x86Runtime.InitializeMetadataString((*this.typeStruct).Name);
     this.@namespace = x86Runtime.InitializeMetadataString((*this.typeStruct).Name);
     this.fullname = x86Runtime.InitializeMetadataString((*this.typeStruct).Name);
 }
Esempio n. 5
0
        public static bool IsTypeInInheritanceChain(MetadataTypeStruct *typeDefinition, MetadataTypeStruct *chain)
        {
            while (chain != null)
            {
                if (chain == typeDefinition)
                {
                    return(true);
                }

                chain = chain->ParentType;
            }

            return(false);
        }
        public RuntimeCustomAttributeData(MetadataCAStruct *customAttributeTable)
        {
            RuntimeTypeHandle typeHandle = new RuntimeTypeHandle();

            ((uint **)&typeHandle)[0] = (uint *)customAttributeTable->AttributeType;
            base.attributeType        = Type.GetTypeFromHandle(typeHandle);

            // Get the metadata pointer for the enum type
            typeHandle  = typeof(System.Enum).TypeHandle;
            EnumTypePtr = (MetadataTypeStruct *)((uint **)&typeHandle)[0];

            // Create temporary lists to hold the arguments
            var typedArgs = new LinkedList <CustomAttributeTypedArgument>();
            var namedArgs = new LinkedList <CustomAttributeNamedArgument>();

            for (uint i = 0; i < customAttributeTable->NumberOfArguments; i++)
            {
                // Get the argument metadata pointer
                var argument = MetadataCAStruct.GetCAArgumentAddress(customAttributeTable, i);

                // Get the argument name (if any)
                string name = null;
                if (argument->Name != null)
                {
                    name = x86Runtime.InitializeMetadataString(argument->Name);
                }

                // Get the argument type
                RuntimeTypeHandle argTypeHandle = new RuntimeTypeHandle();
                ((uint **)&argTypeHandle)[0] = (uint *)argument->ArgumentType;
                var argType = Type.GetTypeFromHandle(argTypeHandle);

                // Get the argument value
                var value = ResolveArgumentValue(argument, argType);

                // If the argument has a name then its a NamedArgument, otherwise its a TypedArgument
                if (name == null)
                {
                    typedArgs.AddLast(CreateTypedArgumentStruct(argType, value));
                }
                else
                {
                    namedArgs.AddLast(CreateNamedArgumentStruct(name, argType, value, argument->IsField));
                }
            }

            // Generate arrays from the argument lists
            this.ctorArgs  = typedArgs.ToArray();
            this.namedArgs = namedArgs.ToArray();
        }
        public RuntimeCustomAttributeData(MetadataCAStruct* customAttributeTable)
        {
            RuntimeTypeHandle typeHandle = new RuntimeTypeHandle();
            ((uint**)&typeHandle)[0] = (uint*)customAttributeTable->AttributeType;
            base.attributeType = Type.GetTypeFromHandle(typeHandle);

            // Get the metadata pointer for the enum type
            typeHandle = typeof(System.Enum).TypeHandle;
            EnumTypePtr = (MetadataTypeStruct*)((uint**)&typeHandle)[0];

            // Create temporary lists to hold the arguments
            var typedArgs = new LinkedList<CustomAttributeTypedArgument>();
            var namedArgs = new LinkedList<CustomAttributeNamedArgument>();

            for (uint i = 0; i < customAttributeTable->NumberOfArguments; i++)
            {
                // Get the argument metadata pointer
                var argument = MetadataCAStruct.GetCAArgumentAddress(customAttributeTable, i);

                // Get the argument name (if any)
                string name = null;
                if (argument->Name != null)
                {
                    name = x86Runtime.InitializeMetadataString(argument->Name);
                }

                // Get the argument type
                RuntimeTypeHandle argTypeHandle = new RuntimeTypeHandle();
                ((uint**)&argTypeHandle)[0] = (uint*)argument->ArgumentType;
                var argType = Type.GetTypeFromHandle(argTypeHandle);

                // Get the argument value
                var value = ResolveArgumentValue(argument, argType);

                // If the argument has a name then its a NamedArgument, otherwise its a TypedArgument
                if (name == null)
                {
                    typedArgs.AddLast(CreateTypedArgumentStruct(argType, value));
                }
                else
                {
                    namedArgs.AddLast(CreateNamedArgumentStruct(name, argType, value, argument->IsField));
                }
            }

            // Generate arrays from the argument lists
            this.ctorArgs = typedArgs.ToArray();
            this.namedArgs = namedArgs.ToArray();
        }
Esempio n. 8
0
        public static void *IsInstanceOfType(RuntimeTypeHandle handle, void *obj)
        {
            if (obj == null)
            {
                return(null);
            }

            MetadataTypeStruct *typeDefinition = (MetadataTypeStruct *)((uint **)&handle)[0];

            MetadataTypeStruct *objTypeDefinition = (MetadataTypeStruct *)((uint *)obj)[0];

            if (IsTypeInInheritanceChain(typeDefinition, objTypeDefinition))
            {
                return((void *)obj);
            }

            return(null);
        }
        public RuntimeTypeInfo(RuntimeType type, Assembly assembly)
        {
            var handle = type.TypeHandle;

            this.asType   = type;
            this.assembly = assembly;

            //this.handle = handle;
            this.typeStruct = (MetadataTypeStruct *)((uint **)&handle)[0];

            this.assemblyQualifiedName = x86Runtime.InitializeMetadataString(this.typeStruct->Name);            // TODO
            this.name       = x86Runtime.InitializeMetadataString(this.typeStruct->Name);                       // TODO
            this.@namespace = x86Runtime.InitializeMetadataString(this.typeStruct->Name);                       // TODO
            this.fullname   = x86Runtime.InitializeMetadataString(this.typeStruct->Name);

            this.typeCode   = (TypeCode)(this.typeStruct->Attributes >> 24);
            this.attributes = (TypeAttributes)(this.typeStruct->Attributes & 0x00FFFFFF);

            // Base Type
            if (this.typeStruct->ParentType != null)
            {
                RuntimeTypeHandle parentHandle = new RuntimeTypeHandle();
                ((uint **)&parentHandle)[0] = (uint *)this.typeStruct->ParentType;
                this.baseType = Type.GetTypeFromHandle(parentHandle);
            }

            // Declaring Type
            if (this.typeStruct->DeclaringType != null)
            {
                RuntimeTypeHandle declaringHandle = new RuntimeTypeHandle();
                ((uint **)&declaringHandle)[0] = (uint *)this.typeStruct->DeclaringType;
                this.declaringType             = Type.GetTypeFromHandle(declaringHandle);
            }

            // Element Type
            if (this.typeStruct->ElementType != null)
            {
                RuntimeTypeHandle elementHandle = new RuntimeTypeHandle();
                ((uint **)&elementHandle)[0] = (uint *)this.typeStruct->ElementType;
                this.elementType             = Type.GetTypeFromHandle(elementHandle);
            }
        }
Esempio n. 10
0
        public RuntimeTypeInfo(RuntimeType type, Assembly assembly)
        {
            var handle = type.TypeHandle;
            this.asType = type;
            this.assembly = assembly;

            //this.handle = handle;
            this.typeStruct = (MetadataTypeStruct*)((uint**)&handle)[0];

            this.assemblyQualifiedName = x86Runtime.InitializeMetadataString(this.typeStruct->Name);    // TODO
            this.name = x86Runtime.InitializeMetadataString(this.typeStruct->Name);                 // TODO
            this.@namespace = x86Runtime.InitializeMetadataString(this.typeStruct->Name);               // TODO
            this.fullname = x86Runtime.InitializeMetadataString(this.typeStruct->Name);

            this.typeCode = (TypeCode)(this.typeStruct->Attributes >> 24);
            this.attributes = (TypeAttributes)(this.typeStruct->Attributes & 0x00FFFFFF);

            // Base Type
            if (this.typeStruct->ParentType != null)
            {
                RuntimeTypeHandle parentHandle = new RuntimeTypeHandle();
                ((uint**)&parentHandle)[0] = (uint*)this.typeStruct->ParentType;
                this.baseType = Type.GetTypeFromHandle(parentHandle);
            }

            // Declaring Type
            if (this.typeStruct->DeclaringType != null)
            {
                RuntimeTypeHandle declaringHandle = new RuntimeTypeHandle();
                ((uint**)&declaringHandle)[0] = (uint*)this.typeStruct->DeclaringType;
                this.declaringType = Type.GetTypeFromHandle(declaringHandle);
            }

            // Element Type
            if (this.typeStruct->ElementType != null)
            {
                RuntimeTypeHandle elementHandle = new RuntimeTypeHandle();
                ((uint**)&elementHandle)[0] = (uint*)this.typeStruct->ElementType;
                this.elementType = Type.GetTypeFromHandle(elementHandle);
            }
        }
Esempio n. 11
0
        public static MetadataPRDefinitionStruct *GetProtectedRegionEntryByAddress(uint address, MetadataTypeStruct *exceptionType, MetadataMethodStruct *methodDef)
        {
            var protectedRegionTable = methodDef->ProtectedRegionTable;

            if (protectedRegionTable == null)
            {
                return(null);
            }

            uint method = (uint)methodDef->Method;

            if (method == 0)
            {
                return(null);
            }

            uint offset  = address - method;
            int  entries = protectedRegionTable->NumberOfRegions;

            int entry = 0;
            MetadataPRDefinitionStruct *protectedRegionDef = null;
            uint currentStart = uint.MinValue;
            uint currentEnd   = uint.MaxValue;

            while (entry < entries)
            {
                var prDef = MetadataPRTableStruct.GetProtecteRegionDefinitionAddress(protectedRegionTable, (uint)entry);

                uint start = prDef->StartOffset;
                uint end   = prDef->EndOffset;

                if ((offset >= start) && (offset < end) && (start >= currentStart) && (end < currentEnd))
                {
                    var handlerType = prDef->HandlerType;

                    // If the handler is a Finally clause, accept without testing
                    if (handlerType == ExceptionHandlerType.Finally)
                    {
                        protectedRegionDef = prDef;
                        currentStart       = start;
                        currentEnd         = end;
                        entry++;
                        continue;
                    }

                    var exType = prDef->ExceptionType;

                    // If the handler is a Exception clause, accept if the exception Type
                    // is in the is within the inhertiance chain of the exception object
                    if (handlerType == ExceptionHandlerType.Exception && IsTypeInInheritanceChain(exType, exceptionType))
                    {
                        protectedRegionDef = prDef;
                        currentStart       = start;
                        currentEnd         = end;
                        entry++;
                        continue;
                    }
                }

                entry++;
            }

            return(protectedRegionDef);
        }
 public static MetadataMethodStruct *GetMethodDefinitionAddress(MetadataTypeStruct *data, uint slot)
 {
     return((MetadataMethodStruct *)*((uint *)data + MetadataTypeStruct.MethodsOffset + slot));
 }