Exemplo n.º 1
0
        public void SetHeapSize(int Size, int Type)
        {
            //TODO: Return error when theres no enough space to allocate heap.
            Size = (int)AMemoryHelper.PageRoundUp(Size);

            long Position = HeapAddr;

            if ((ulong)Size < (ulong)HeapSize)
            {
                //Try to free now free area if size is smaller than old size.
                Position += Size;

                while ((ulong)Size < (ulong)HeapSize)
                {
                    Allocator.Free(GetPhys(Position, AMemoryPerm.None));

                    Position += PageSize;
                }
            }
            else
            {
                //Allocate extra needed size.
                Position += HeapSize;
                Size     -= HeapSize;

                MapPhys(Position, Size, Type, AMemoryPerm.RW);
            }

            HeapSize = Size;
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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);
        }