public HTransferMem(AMemory Memory, AMemoryPerm Perm, long Position, long Size) { this.Memory = Memory; this.Perm = Perm; this.Position = Position; this.Size = Size; }
public PTEntry(PTMap Map, AMemoryPerm Perm, int Type, int Attr) { this.Map = Map; this.Perm = Perm; this.Type = Type; this.Attr = Attr; }
public AMemoryMapInfo(long Position, long Size, int Type, AMemoryPerm Perm) { this.Position = Position; this.Size = Size; this.Type = Type; this.Perm = Perm; }
public PTEntry(long Position, int Type, PTMap Map, AMemoryPerm Perm) { this.Position = Position; this.Type = Type; this.Map = Map; this.Perm = Perm; }
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); }
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); } }
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); }
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; } }
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]); } }
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; } }
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; } }
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; } }
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); }
public bool HasPermission(long Position, AMemoryPerm Perm) { return(GetPTEntry(Position).Perm.HasFlag(Perm)); }
public void Map(long Position, long Size, int Type, AMemoryPerm Perm) { SetPTEntry(Position, Size, new PTEntry(PTMap.Mapped, Perm, Type, 0)); }
public VmmAccessViolationException(long Position, AMemoryPerm Perm) : base(string.Format(ExMsg, Position, Perm)) { }