Esempio n. 1
0
 public HTransferMem(AMemory Memory, AMemoryPerm Perm, long Position, long Size)
 {
     this.Memory   = Memory;
     this.Perm     = Perm;
     this.Position = Position;
     this.Size     = Size;
 }
Esempio n. 2
0
 public PTEntry(PTMap Map, AMemoryPerm Perm, int Type, int Attr)
 {
     this.Map  = Map;
     this.Perm = Perm;
     this.Type = Type;
     this.Attr = Attr;
 }
Esempio n. 3
0
 public AMemoryMapInfo(long Position, long Size, int Type, AMemoryPerm Perm)
 {
     this.Position = Position;
     this.Size     = Size;
     this.Type     = Type;
     this.Perm     = Perm;
 }
Esempio n. 4
0
 public PTEntry(long Position, int Type, PTMap Map, AMemoryPerm Perm)
 {
     this.Position = Position;
     this.Type     = Type;
     this.Map      = Map;
     this.Perm     = Perm;
 }
Esempio n. 5
0
        public long GetPhys(long Position, AMemoryPerm Perm)
        {
            if (!HasPTEntry(Position))
            {
                if (Position < 0x08000000)
                {
                    Console.WriteLine($"HACK: Ignoring bad access at {Position:x16}");

                    return(0);
                }

                throw new VmmPageFaultException(Position);
            }

            PTEntry Entry = GetPTEntry(Position);

            long AbsPos = Entry.Position + (Position & PageMask);

            if (Entry.Map == PTMap.Mirror)
            {
                return(GetPhys(AbsPos, Perm));
            }

            if (Entry.Map == PTMap.Unmapped)
            {
                throw new VmmPageFaultException(Position);
            }

            return(AbsPos);
        }
Esempio n. 6
0
        private void EnsureAccessIsValid(long Position, AMemoryPerm Perm)
        {
            if (!Manager.IsMapped(Position))
            {
                throw new VmmPageFaultException(Position);
            }

            if (!Manager.HasPermission(Position, Perm))
            {
                throw new VmmAccessViolationException(Position, Perm);
            }
        }
Esempio n. 7
0
        private void WriteData(
            long Position,
            byte[]      Data,
            MemoryType Type,
            AMemoryPerm Perm)
        {
            Memory.Manager.Map(Position, Data.Length, (int)Type, AMemoryPerm.Write);

            AMemoryHelper.WriteBytes(Memory, Position, Data);

            Memory.Manager.Reprotect(Position, Data.Length, Perm);
        }
Esempio n. 8
0
        private void EnsureRangeIsValid(long Position, long Size, AMemoryPerm Perm)
        {
            long EndPos = Position + Size;

            Position &= ~AMemoryMgr.PageMask;

            while ((ulong)Position < (ulong)EndPos)
            {
                EnsureAccessIsValid(Position, Perm);

                Position += AMemoryMgr.PageSize;
            }
        }
Esempio n. 9
0
        private void WriteData(
            long Position,
            IList <byte> Data,
            MemoryType Type,
            AMemoryPerm Perm)
        {
            Memory.Manager.MapPhys(Position, Data.Count, (int)Type, Perm);

            for (int Index = 0; Index < Data.Count; Index++)
            {
                Memory.WriteByte(Position + Index, Data[Index]);
            }
        }
Esempio n. 10
0
        public void MapPhys(long Position, long Size, int Type, AMemoryPerm Perm)
        {
            while (Size > 0)
            {
                if (!IsMapped(Position))
                {
                    SetPTEntry(Position, new PTEntry(PTMap.Mapped, Perm, Type, 0));
                }

                long CPgSize = PageSize - (Position & PageMask);

                Position += CPgSize;
                Size     -= CPgSize;
            }
        }
Esempio n. 11
0
        public void MapPhys(long Position, long Size, int Type, AMemoryPerm Perm)
        {
            while (Size > 0)
            {
                if (!HasPTEntry(Position))
                {
                    long PhysPos = Allocator.Alloc(PageSize);

                    SetPTEntry(Position, new PTEntry(PhysPos, Type, PTMap.Physical, Perm));
                }

                long CPgSize = PageSize - (Position & PageMask);

                Position += CPgSize;
                Size     -= CPgSize;
            }
        }
Esempio n. 12
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;
            }
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
 public bool HasPermission(long Position, AMemoryPerm Perm)
 {
     return(GetPTEntry(Position).Perm.HasFlag(Perm));
 }
Esempio n. 15
0
 public void Map(long Position, long Size, int Type, AMemoryPerm Perm)
 {
     SetPTEntry(Position, Size, new PTEntry(PTMap.Mapped, Perm, Type, 0));
 }
Esempio n. 16
0
 public VmmAccessViolationException(long Position, AMemoryPerm Perm) : base(string.Format(ExMsg, Position, Perm))
 {
 }