From c393cdf8e3775bc95850e4d8c8e4c446b286d3b4 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 15 Aug 2018 15:59:51 -0300 Subject: More flexible memory manager (#307) * Keep track mapped buffers with fixed offsets * Started rewriting the memory manager * Initial support for MapPhysicalMemory and UnmapPhysicalMemory, other tweaks * MapPhysicalMemory/UnmapPhysicalMemory support, other tweaks * Rebased * Optimize the map/unmap physical memory svcs * Integrate shared font support * Fix address space reserve alignment * Some fixes related to gpu memory mapping * Some cleanup * Only try uploading const buffers that are really used * Check if memory region is contiguous * Rebased * Add missing count increment on IsRegionModified * Check for reads/writes outside of the address space, optimize translation with a tail call --- ChocolArm64/Memory/AMemoryHelper.cs | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) (limited to 'ChocolArm64/Memory/AMemoryHelper.cs') diff --git a/ChocolArm64/Memory/AMemoryHelper.cs b/ChocolArm64/Memory/AMemoryHelper.cs index 0a23a2f8..ea877834 100644 --- a/ChocolArm64/Memory/AMemoryHelper.cs +++ b/ChocolArm64/Memory/AMemoryHelper.cs @@ -26,12 +26,9 @@ namespace ChocolArm64.Memory { long Size = Marshal.SizeOf(); - if ((ulong)(Position + Size) > AMemoryMgr.AddrSize) - { - throw new ArgumentOutOfRangeException(nameof(Position)); - } + Memory.EnsureRangeIsValid(Position, Size); - IntPtr Ptr = new IntPtr((byte*)Memory.Ram + Position); + IntPtr Ptr = (IntPtr)Memory.Translate(Position); return Marshal.PtrToStructure(Ptr); } @@ -40,12 +37,9 @@ namespace ChocolArm64.Memory { long Size = Marshal.SizeOf(); - if ((ulong)(Position + Size) > AMemoryMgr.AddrSize) - { - throw new ArgumentOutOfRangeException(nameof(Position)); - } + Memory.EnsureRangeIsValid(Position, Size); - IntPtr Ptr = new IntPtr((byte*)Memory.Ram + Position); + IntPtr Ptr = (IntPtr)Memory.TranslateWrite(Position); Marshal.StructureToPtr(Value, Ptr, false); } @@ -69,15 +63,5 @@ namespace ChocolArm64.Memory return Encoding.ASCII.GetString(MS.ToArray()); } } - - public static long PageRoundUp(long Value) - { - return (Value + AMemoryMgr.PageMask) & ~AMemoryMgr.PageMask; - } - - public static long PageRoundDown(long Value) - { - return Value & ~AMemoryMgr.PageMask; - } } } \ No newline at end of file -- cgit v1.2.3