Esempio n. 1
0
 public DesktopThreadStaticField(DesktopGCHeap heap, IFieldData field, string name)
 {
     _field = field;
     _name  = name;
     _token = field.FieldToken;
     _type  = (BaseDesktopHeapType)heap.GetTypeByMethodTable(field.TypeMethodTable, 0);
 }
Esempio n. 2
0
        internal ulong GetMTForDomain(ClrAppDomain domain, DesktopHeapType type)
        {
            DesktopGCHeap heap = null;
            IList <MethodTableTokenPair> mtList = _runtime.GetMethodTableList(_mapping[domain]);

            bool hasToken = type.MetadataToken != 0 && type.MetadataToken != uint.MaxValue;

            uint token = ~0xff000000 & type.MetadataToken;

            foreach (MethodTableTokenPair pair in mtList)
            {
                if (hasToken)
                {
                    if (pair.Token == token)
                    {
                        return(pair.MethodTable);
                    }
                }
                else
                {
                    if (heap == null)
                    {
                        heap = (DesktopGCHeap)_runtime.Heap;
                    }

                    if (heap.GetTypeByMethodTable(pair.MethodTable, 0) == type)
                    {
                        return(pair.MethodTable);
                    }
                }
            }

            return(0);
        }
Esempio n. 3
0
        public override IEnumerable <ClrType> EnumerateTypes()
        {
            DesktopGCHeap heap = (DesktopGCHeap)_runtime.Heap;
            IList <MethodTableTokenPair> mtList = _runtime.GetMethodTableList(_address);

            if (_typesLoaded)
            {
                foreach (ClrType type in heap.EnumerateTypes())
                {
                    if (type.Module == this)
                    {
                        yield return(type);
                    }
                }
            }
            else
            {
                if (mtList != null)
                {
                    foreach (MethodTableTokenPair pair in mtList)
                    {
                        ulong mt = pair.MethodTable;
                        if (mt != _runtime.ArrayMethodTable)
                        {
                            // prefetch element type, as this also can load types
                            ClrType type = heap.GetTypeByMethodTable(mt, 0, 0);
                            if (type != null)
                            {
                                yield return(type);
                            }
                        }
                    }
                }

                _typesLoaded = true;
            }
        }
Esempio n. 4
0
        private static BaseDesktopHeapType GetType(DesktopGCHeap heap, IFieldData data, IntPtr sig, int sigLen, ClrElementType elementType)
        {
            BaseDesktopHeapType result = null;
            ulong mt = data.TypeMethodTable;

            if (mt != 0)
            {
                result = (BaseDesktopHeapType)heap.GetTypeByMethodTable(mt, 0);
            }

            if (result == null)
            {
                if (sig != IntPtr.Zero && sigLen > 0)
                {
                    SigParser sigParser = new SigParser(sig, sigLen);

                    bool res;
                    int  etype = 0;

                    if (res = sigParser.GetCallingConvInfo(out int sigType))
                    {
                        Debug.Assert(sigType == SigParser.IMAGE_CEE_CS_CALLCONV_FIELD);
                    }

                    res = res && sigParser.SkipCustomModifiers();
                    res = res && sigParser.GetElemType(out etype);


                    // Generic instantiation
                    if (etype == 0x15)
                    {
                        res = res && sigParser.GetElemType(out etype);
                    }

                    if (res)
                    {
                        ClrElementType type = (ClrElementType)etype;

                        if (type == ClrElementType.Array)
                        {
                            res = sigParser.PeekElemType(out etype);
                            res = res && sigParser.SkipExactlyOne();

                            int ranks = 0;
                            res = res && sigParser.GetData(out ranks);

                            if (res)
                            {
                                result = heap.GetArrayType((ClrElementType)etype, ranks, null);
                            }
                        }
                        else if (type == ClrElementType.SZArray)
                        {
                            res  = sigParser.PeekElemType(out etype);
                            type = (ClrElementType)etype;

                            if (DesktopRuntimeBase.IsObjectReference(type))
                            {
                                result = (BaseDesktopHeapType)heap.GetBasicType(ClrElementType.SZArray);
                            }
                            else
                            {
                                result = (BaseDesktopHeapType)heap.GetArrayType(type, -1, null);
                            }
                        }
                        else if (type == ClrElementType.Pointer)
                        {
                            // Only deal with single pointers for now and types that have already been constructed
                            res  = sigParser.GetElemType(out etype);
                            type = (ClrElementType)etype;

                            sigParser.GetToken(out int token);
                            BaseDesktopHeapType innerType = (BaseDesktopHeapType)heap.GetGCHeapTypeFromModuleAndToken(data.Module, Convert.ToUInt32(token));

                            if (innerType == null)
                            {
                                innerType = (BaseDesktopHeapType)heap.GetBasicType(type);
                            }

                            result = heap.CreatePointerType(innerType, type, null);
                        }
                        else if (type == ClrElementType.Object || type == ClrElementType.Class)
                        {
                            result = (BaseDesktopHeapType)heap.ObjectType;
                        }
                        else
                        {
                            // struct, then try to get the token
                            int token = 0;
                            if (etype == 0x11 || etype == 0x12)
                            {
                                res = res && sigParser.GetToken(out token);
                            }

                            if (token != 0)
                            {
                                result = (BaseDesktopHeapType)heap.GetGCHeapTypeFromModuleAndToken(data.Module, (uint)token);
                            }

                            if (result == null)
                            {
                                if ((result = (BaseDesktopHeapType)heap.GetBasicType((ClrElementType)etype)) == null)
                                {
                                    result = heap.ErrorType;
                                }
                            }
                        }
                    }
                }

                if (result == null)
                {
                    result = (BaseDesktopHeapType)heap.GetBasicType(elementType);
                }
            }
            else if (elementType != ClrElementType.Class)
            {
                result.ElementType = elementType;
            }

            if (result.IsArray && result.ComponentType == null)
            {
                if (sig != IntPtr.Zero && sigLen > 0)
                {
                    SigParser sigParser = new SigParser(sig, sigLen);

                    bool res;
                    int  etype = 0;

                    if (res = sigParser.GetCallingConvInfo(out int sigType))
                    {
                        Debug.Assert(sigType == SigParser.IMAGE_CEE_CS_CALLCONV_FIELD);
                    }

                    res = res && sigParser.SkipCustomModifiers();
                    res = res && sigParser.GetElemType(out etype);

                    res = res && sigParser.GetElemType(out etype);

                    // Generic instantiation
                    if (etype == 0x15)
                    {
                        res = res && sigParser.GetElemType(out etype);
                    }

                    // If it's a class or struct, then try to get the token
                    int token = 0;
                    if (etype == 0x11 || etype == 0x12)
                    {
                        res = res && sigParser.GetToken(out token);
                    }

                    if (token != 0)
                    {
                        result.ComponentType = heap.GetGCHeapTypeFromModuleAndToken(data.Module, (uint)token);
                    }

                    else if (result.ComponentType == null)
                    {
                        if ((result.ComponentType = heap.GetBasicType((ClrElementType)etype)) == null)
                        {
                            result.ComponentType = heap.ErrorType;
                        }
                    }
                }
            }

            return(result);
        }
Esempio n. 5
0
        public DesktopStaticField(DesktopGCHeap heap, IFieldData field, BaseDesktopHeapType containingType, string name, FieldAttributes attributes, object defaultValue, IntPtr sig, int sigLen)
        {
            _field        = field;
            _name         = name;
            _attributes   = attributes;
            _type         = (BaseDesktopHeapType)heap.GetTypeByMethodTable(field.TypeMethodTable, 0);
            _defaultValue = defaultValue;
            _heap         = heap;
            _token        = field.FieldToken;

            if (_type != null && ElementType != ClrElementType.Class)
            {
                _type.ElementType = ElementType;
            }

            _containingType = containingType;


            if (_type == null)
            {
                if (sig != IntPtr.Zero && sigLen > 0)
                {
                    SigParser sigParser = new SigParser(sig, sigLen);

                    bool res;
                    int  etype = 0;

                    if (res = sigParser.GetCallingConvInfo(out int sigType))
                    {
                        Debug.Assert(sigType == SigParser.IMAGE_CEE_CS_CALLCONV_FIELD);
                    }

                    res = res && sigParser.SkipCustomModifiers();
                    res = res && sigParser.GetElemType(out etype);

                    if (res)
                    {
                        ClrElementType type = (ClrElementType)etype;

                        if (type == ClrElementType.Array)
                        {
                            res = sigParser.PeekElemType(out etype);
                            res = res && sigParser.SkipExactlyOne();

                            int ranks = 0;
                            res = res && sigParser.GetData(out ranks);

                            if (res)
                            {
                                _type = heap.GetArrayType((ClrElementType)etype, ranks, null);
                            }
                        }
                        else if (type == ClrElementType.SZArray)
                        {
                            res  = sigParser.PeekElemType(out etype);
                            type = (ClrElementType)etype;

                            if (DesktopRuntimeBase.IsObjectReference(type))
                            {
                                _type = (BaseDesktopHeapType)heap.GetBasicType(ClrElementType.SZArray);
                            }
                            else
                            {
                                _type = (BaseDesktopHeapType)heap.GetArrayType(type, -1, null);
                            }
                        }
                        else if (type == ClrElementType.Pointer)
                        {
                            // Only deal with single pointers for now and types that have already been constructed
                            res  = sigParser.GetElemType(out etype);
                            type = (ClrElementType)etype;

                            sigParser.GetToken(out int token);
                            BaseDesktopHeapType innerType = (BaseDesktopHeapType)heap.GetGCHeapTypeFromModuleAndToken(field.Module, Convert.ToUInt32(token));

                            if (innerType == null)
                            {
                                innerType = (BaseDesktopHeapType)heap.GetBasicType(type);
                            }

                            _type = heap.CreatePointerType(innerType, type, null);
                        }
                    }
                }
            }

            if (_type == null)
            {
                _typeResolver = new Lazy <ClrType>(() =>
                {
                    ClrType type = (BaseDesktopHeapType)TryBuildType(_heap);

                    if (type == null)
                    {
                        type = (BaseDesktopHeapType)heap.GetBasicType(ElementType);
                    }

                    return(type);
                });
            }
        }
Esempio n. 6
0
        public DesktopInstanceField(DesktopGCHeap heap, IFieldData data, string name, FieldAttributes attributes, IntPtr sig, int sigLen)
        {
            _name = name;
            _field = data;
            _attributes = attributes;
            _token = data.FieldToken;

            ulong mt = data.TypeMethodTable;
            if (mt != 0)
                _type = (BaseDesktopHeapType)heap.GetTypeByMethodTable(mt, 0);

            if (_type == null)
            {
                if (sig != IntPtr.Zero && sigLen > 0)
                {
                    SigParser sigParser = new SigParser(sig, sigLen);

                    bool res;
                    int sigType, etype = 0;

                    if (res = sigParser.GetCallingConvInfo(out sigType))
                        Debug.Assert(sigType == SigParser.IMAGE_CEE_CS_CALLCONV_FIELD);

                    res = res && sigParser.SkipCustomModifiers();
                    res = res && sigParser.GetElemType(out etype);


                    // Generic instantiation
                    if (etype == 0x15)
                        res = res && sigParser.GetElemType(out etype);

                    if (res)
                    {
                        ClrElementType type = (ClrElementType)etype;

                        if (type == ClrElementType.Array)
                        {
                            res = sigParser.PeekElemType(out etype);
                            res = res && sigParser.SkipExactlyOne();

                            int ranks = 0;
                            res = res && sigParser.GetData(out ranks);

                            if (res)
                                _type = heap.GetArrayType((ClrElementType)etype, ranks, null);
                        }
                        else if (type == ClrElementType.SZArray)
                        {
                            res = sigParser.PeekElemType(out etype);
                            type = (ClrElementType)etype;

                            if (DesktopRuntimeBase.IsObjectReference(type))
                                _type = (BaseDesktopHeapType)heap.GetBasicType(ClrElementType.SZArray);
                            else
                                _type = (BaseDesktopHeapType)heap.GetArrayType(type, -1, null);
                        }
                        else if (type == ClrElementType.Pointer)
                        {
                            // Only deal with single pointers for now and types that have already been constructed
                            res = sigParser.GetElemType(out etype);
                            type = (ClrElementType)etype;

                            int token;
                            sigParser.GetToken(out token);
                            BaseDesktopHeapType innerType = (BaseDesktopHeapType)heap.GetGCHeapTypeFromModuleAndToken(data.Module, Convert.ToUInt32(token));

                            if (innerType == null)
                            {
                                innerType = (BaseDesktopHeapType)heap.GetBasicType(type);
                            }

                            _type = heap.CreatePointerType(innerType, type, null);
                        }
                        else
                        {
                            // If it's a class or struct, then try to get the token
                            int token = 0;
                            if (etype == 0x11 || etype == 0x12)
                                res = res && sigParser.GetToken(out token);

                            if (token != 0)
                                _type = (BaseDesktopHeapType)heap.GetGCHeapTypeFromModuleAndToken(data.Module, (uint)token);

                            if (_type == null)
                                if ((_type = (BaseDesktopHeapType)heap.GetBasicType((ClrElementType)etype)) == null)
                                    _type = heap.ErrorType;
                        }
                    }
                }

                if (_type == null)
                    _type = (BaseDesktopHeapType)heap.GetBasicType(ElementType);
            }
            else if (ElementType != ClrElementType.Class)
            {
                _type.ElementType = ElementType;
            }

            if (_type.IsArray && _type.ComponentType == null)
            {
                if (sig != IntPtr.Zero && sigLen > 0)
                {
                    SigParser sigParser = new SigParser(sig, sigLen);

                    bool res;
                    int sigType, etype = 0;

                    if (res = sigParser.GetCallingConvInfo(out sigType))
                        Debug.Assert(sigType == SigParser.IMAGE_CEE_CS_CALLCONV_FIELD);

                    res = res && sigParser.SkipCustomModifiers();
                    res = res && sigParser.GetElemType(out etype);
                    
                    res = res && sigParser.GetElemType(out etype);

                    // Generic instantiation
                    if (etype == 0x15)
                        res = res && sigParser.GetElemType(out etype);

                    // If it's a class or struct, then try to get the token
                    int token = 0;
                    if (etype == 0x11 || etype == 0x12)
                        res = res && sigParser.GetToken(out token);
                    
                    if (token != 0)
                        _type.ComponentType = heap.GetGCHeapTypeFromModuleAndToken(data.Module, (uint)token);
                    
                    else if (_type.ComponentType == null)
                        if ((_type.ComponentType = heap.GetBasicType((ClrElementType)etype)) == null)
                            _type.ComponentType = heap.ErrorType;
                }
            }
        }
Esempio n. 7
0
        public DesktopInstanceField(DesktopGCHeap heap, IFieldData data, string name, FieldAttributes attributes, IntPtr sig, int sigLen)
        {
            _name = name;
            _field = data;
            _attributes = attributes;

            ulong mt = data.TypeMethodTable;
            if (mt != 0)
                _type = (BaseDesktopHeapType)heap.GetTypeByMethodTable(mt, 0);

            if (_type == null)
            {
                if (sig != IntPtr.Zero && sigLen > 0)
                {
                    SigParser sigParser = new SigParser(sig, sigLen);

                    bool res;
                    int sigType, etype = 0;

                    if (res = sigParser.GetCallingConvInfo(out sigType))
                        Debug.Assert(sigType == SigParser.IMAGE_CEE_CS_CALLCONV_FIELD);

                    res = res && sigParser.SkipCustomModifiers();
                    res = res && sigParser.GetElemType(out etype);


                    // Generic instantiation
                    if (etype == 0x15)
                        res = res && sigParser.GetElemType(out etype);

                    if (res)
                    {
                        ClrElementType type = (ClrElementType)etype;

                        if (type == ClrElementType.Array)
                        {
                            res = sigParser.PeekElemType(out etype);
                            res = res && sigParser.SkipExactlyOne();

                            int ranks = 0;
                            res = res && sigParser.GetData(out ranks);

                            if (res)
                                _type = heap.GetArrayType((ClrElementType)etype, ranks, null);
                        }
                        else if (type == ClrElementType.SZArray)
                        {
                            res = sigParser.PeekElemType(out etype);
                            type = (ClrElementType)etype;

                            if (DesktopRuntimeBase.IsObjectReference(type))
                                _type = (BaseDesktopHeapType)heap.GetBasicType(ClrElementType.SZArray);
                            else
                                _type = (BaseDesktopHeapType)heap.GetArrayType(type, -1, null);
                        }
                        else if (type == ClrElementType.Pointer)
                        {
                            // Only deal with single pointers for now and types that have already been constructed
                            res = sigParser.GetElemType(out etype);
                            type = (ClrElementType)etype;

                            int token;
                            sigParser.GetToken(out token);
                            BaseDesktopHeapType innerType = (BaseDesktopHeapType)heap.GetGCHeapTypeFromModuleAndToken(data.Module, Convert.ToUInt32(token));

                            if (innerType == null)
                            {
                                innerType = (BaseDesktopHeapType)heap.GetBasicType(type);
                            }

                            _type = heap.CreatePointerType(innerType, type, null);
                        }
                        else
                        {
                            // If it's a class or struct, then try to get the token
                            int token = 0;
                            if (etype == 0x11 || etype == 0x12)
                                res = res && sigParser.GetToken(out token);

                            if (token != 0)
                                _type = (BaseDesktopHeapType)heap.GetGCHeapTypeFromModuleAndToken(data.Module, (uint)token);

                            if (_type == null)
                                if ((_type = (BaseDesktopHeapType)heap.GetBasicType((ClrElementType)etype)) == null)
                                    _type = heap.ErrorType;
                        }
                    }
                }

                if (_type == null)
                    _type = (BaseDesktopHeapType)heap.GetBasicType(ElementType);
            }
            else if (ElementType != ClrElementType.Class)
            {
                _type.ElementType = ElementType;
            }

            if (_type.IsArray && _type.ComponentType == null)
            {
                if (sig != IntPtr.Zero && sigLen > 0)
                {
                    SigParser sigParser = new SigParser(sig, sigLen);

                    bool res;
                    int sigType, etype = 0;

                    if (res = sigParser.GetCallingConvInfo(out sigType))
                        Debug.Assert(sigType == SigParser.IMAGE_CEE_CS_CALLCONV_FIELD);

                    res = res && sigParser.SkipCustomModifiers();
                    res = res && sigParser.GetElemType(out etype);
                    
                    res = res && sigParser.GetElemType(out etype);

                    // Generic instantiation
                    if (etype == 0x15)
                        res = res && sigParser.GetElemType(out etype);

                    // If it's a class or struct, then try to get the token
                    int token = 0;
                    if (etype == 0x11 || etype == 0x12)
                        res = res && sigParser.GetToken(out token);
                    
                    if (token != 0)
                        _type.ComponentType = heap.GetGCHeapTypeFromModuleAndToken(data.Module, (uint)token);
                    
                    else if (_type.ComponentType == null)
                        if ((_type.ComponentType = heap.GetBasicType((ClrElementType)etype)) == null)
                            _type.ComponentType = heap.ErrorType;
                }
            }
        }
Esempio n. 8
0
 public DesktopThreadStaticField(DesktopGCHeap heap, IFieldData field, string name)
 {
     _field = field;
     _name = name;
     _type = (BaseDesktopHeapType)heap.GetTypeByMethodTable(field.TypeMethodTable, 0);
 }
Esempio n. 9
0
        public DesktopStaticField(DesktopGCHeap heap, IFieldData field, BaseDesktopHeapType containingType, string name, FieldAttributes attributes, object defaultValue, IntPtr sig, int sigLen)
        {
            _field = field;
            _name = name;
            _attributes = attributes;
            _type = (BaseDesktopHeapType)heap.GetTypeByMethodTable(field.TypeMethodTable, 0);
            _defaultValue = defaultValue;
            _heap = heap;

            if (_type != null && ElementType != ClrElementType.Class)
                _type.ElementType = ElementType;

            _containingType = containingType;


            if (_type == null)
            {
                if (sig != IntPtr.Zero && sigLen > 0)
                {
                    SigParser sigParser = new SigParser(sig, sigLen);

                    bool res;
                    int sigType, etype = 0;

                    if (res = sigParser.GetCallingConvInfo(out sigType))
                        Debug.Assert(sigType == SigParser.IMAGE_CEE_CS_CALLCONV_FIELD);

                    res = res && sigParser.SkipCustomModifiers();
                    res = res && sigParser.GetElemType(out etype);

                    if (res)
                    {
                        ClrElementType type = (ClrElementType)etype;

                        if (type == ClrElementType.Array)
                        {
                            res = sigParser.PeekElemType(out etype);
                            res = res && sigParser.SkipExactlyOne();

                            int ranks = 0;
                            res = res && sigParser.GetData(out ranks);

                            if (res)
                                _type = heap.GetArrayType((ClrElementType)etype, ranks, null);
                        }
                        else if (type == ClrElementType.SZArray)
                        {
                            res = sigParser.PeekElemType(out etype);
                            type = (ClrElementType)etype;

                            if (DesktopRuntimeBase.IsObjectReference(type))
                                _type = (BaseDesktopHeapType)heap.GetBasicType(ClrElementType.SZArray);
                            else
                                _type = (BaseDesktopHeapType)heap.GetArrayType(type, -1, null);
                        }
                        else if (type == ClrElementType.Pointer)
                        {
                            // Only deal with single pointers for now and types that have already been constructed
                            res = sigParser.GetElemType(out etype);
                            type = (ClrElementType)etype;

                            int token;
                            sigParser.GetToken(out token);
                            BaseDesktopHeapType innerType = (BaseDesktopHeapType)heap.GetGCHeapTypeFromModuleAndToken(field.Module, Convert.ToUInt32(token));

                            if (innerType == null)
                            {
                                innerType = (BaseDesktopHeapType)heap.GetBasicType(type);
                            }

                            _type = heap.CreatePointerType(innerType, type, null);
                        }
                    }
                }

                if (_type == null)
                    _type = (BaseDesktopHeapType)TryBuildType(_heap);

                if (_type == null)
                    _type = (BaseDesktopHeapType)heap.GetBasicType(ElementType);
            }
        }