protected virtual void Dispose(bool disposing) { if (Ram != IntPtr.Zero) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { AMemoryWin32.Free(Ram); } else { Marshal.FreeHGlobal(Ram); } Ram = IntPtr.Zero; } }
public AMemory() { Manager = new AMemoryMgr(); Monitors = new Dictionary <int, ArmMonitor>(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Ram = AMemoryWin32.Allocate((IntPtr)AMemoryMgr.RamSize + AMemoryMgr.PageSize); } else { Ram = Marshal.AllocHGlobal((IntPtr)AMemoryMgr.RamSize + AMemoryMgr.PageSize); } RamPtr = (byte *)Ram; }
public long GetHostPageSize() { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return(AMemoryMgr.PageSize); } IntPtr MemAddress = new IntPtr(RamPtr); IntPtr MemSize = new IntPtr(AMemoryMgr.RamSize); long PageSize = AMemoryWin32.IsRegionModified(MemAddress, MemSize, Reset: false); if (PageSize < 1) { throw new InvalidOperationException(); } return(PageSize); }
public (bool[], long) IsRegionModified(long Position, long Size) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return(null, 0); } long EndPos = Position + Size; if ((ulong)EndPos < (ulong)Position) { return(null, 0); } if ((ulong)EndPos > AMemoryMgr.RamSize) { return(null, 0); } IntPtr MemAddress = new IntPtr(RamPtr + Position); IntPtr MemSize = new IntPtr(Size); int HostPageMask = HostPageSize - 1; Position &= ~HostPageMask; Size = EndPos - Position; IntPtr[] Addresses = new IntPtr[(Size + HostPageMask) / HostPageSize]; AMemoryWin32.IsRegionModified(MemAddress, MemSize, Addresses, out int Count); bool[] Modified = new bool[Addresses.Length]; for (int Index = 0; Index < Count; Index++) { long VA = Addresses[Index].ToInt64() - Ram.ToInt64(); Modified[(VA - Position) / HostPageSize] = true; } return(Modified, Count); }
public bool IsRegionModified(long Position, long Size) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return(true); } long EndPos = Position + Size; if ((ulong)EndPos < (ulong)Position) { return(false); } if ((ulong)EndPos > AMemoryMgr.RamSize) { return(false); } IntPtr MemAddress = new IntPtr(RamPtr + Position); IntPtr MemSize = new IntPtr(Size); return(AMemoryWin32.IsRegionModified(MemAddress, MemSize, Reset: true) != 0); }