Пример #1
0
        public long Alloc(long Size)
        {
            long Position = PhysPos;

            Size = AMemoryHelper.PageRoundUp(Size);

            PhysPos += Size;

            if (PhysPos > AMemoryMgr.RamSize || PhysPos < 0)
            {
                throw new VmmOutOfMemoryException(Size);
            }

            return(Position);
        }
Пример #2
0
        public AMemoryMapInfo GetMapInfo(long Position)
        {
            if (!IsValidPosition(Position))
            {
                return(null);
            }

            Position = AMemoryHelper.PageRoundDown(Position);

            PTEntry BaseEntry = GetPTEntry(Position);

            bool IsSameSegment(long Pos)
            {
                if (!IsValidPosition(Pos))
                {
                    return(false);
                }

                PTEntry Entry = GetPTEntry(Pos);

                return(Entry.Map == BaseEntry.Map &&
                       Entry.Perm == BaseEntry.Perm &&
                       Entry.Type == BaseEntry.Type &&
                       Entry.Attr == BaseEntry.Attr);
            }

            long Start = Position;
            long End   = Position + PageSize;

            while (Start > 0 && IsSameSegment(Start - PageSize))
            {
                Start -= PageSize;
            }

            while (End < AddrSize && IsSameSegment(End))
            {
                End += PageSize;
            }

            long Size = End - Start;

            return(new AMemoryMapInfo(
                       Start,
                       Size,
                       BaseEntry.Type,
                       BaseEntry.Attr,
                       BaseEntry.Perm));
        }
Пример #3
0
        public void Reprotect(long Position, long Size, AMemoryPerm Perm)
        {
            Position = AMemoryHelper.PageRoundDown(Position);

            Size = AMemoryHelper.PageRoundUp(Size);

            long PagesCount = Size / PageSize;

            while (PagesCount-- > 0)
            {
                PTEntry Entry = GetPTEntry(Position);

                Entry.Perm = Perm;

                SetPTEntry(Position, Entry);

                Position += PageSize;
            }
        }
Пример #4
0
        public void MapMirror(long Src, long Dst, long Size, int Type)
        {
            Src = AMemoryHelper.PageRoundDown(Src);
            Dst = AMemoryHelper.PageRoundDown(Dst);

            Size = AMemoryHelper.PageRoundUp(Size);

            long PagesCount = Size / PageSize;

            while (PagesCount-- > 0)
            {
                PTEntry Entry = GetPTEntry(Src);

                Entry.Type     = Type;
                Entry.Map      = PTMap.Mirror;
                Entry.Position = Dst;

                SetPTEntry(Src, Entry);

                Src += PageSize;
                Dst += PageSize;
            }
        }
Пример #5
0
        public bool MapPhys(long Src, long Dst, long Size, int Type, AMemoryPerm Perm)
        {
            Src = AMemoryHelper.PageRoundDown(Src);
            Dst = AMemoryHelper.PageRoundDown(Dst);

            Size = AMemoryHelper.PageRoundUp(Size);

            if (Dst < 0 || Dst + Size >= RamSize)
            {
                return(false);
            }

            long PagesCount = Size / PageSize;

            while (PagesCount-- > 0)
            {
                SetPTEntry(Src, new PTEntry(Dst, Type, PTMap.Physical, Perm));

                Src += PageSize;
                Dst += PageSize;
            }

            return(true);
        }