diff options
Diffstat (limited to 'Ryujinx.Memory/Tracking/MemoryTracking.cs')
-rw-r--r-- | Ryujinx.Memory/Tracking/MemoryTracking.cs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Ryujinx.Memory/Tracking/MemoryTracking.cs b/Ryujinx.Memory/Tracking/MemoryTracking.cs index 425552f8..70951e8c 100644 --- a/Ryujinx.Memory/Tracking/MemoryTracking.cs +++ b/Ryujinx.Memory/Tracking/MemoryTracking.cs @@ -9,7 +9,7 @@ namespace Ryujinx.Memory.Tracking public class MemoryTracking { private readonly IVirtualMemoryManager _memoryManager; - private readonly MemoryBlock _block; + private readonly InvalidAccessHandler _invalidAccessHandler; // Only use these from within the lock. private readonly NonOverlappingRangeList<VirtualRegion> _virtualRegions; @@ -25,8 +25,6 @@ namespace Ryujinx.Memory.Tracking /// </summary> internal object TrackingLock = new object(); - public bool EnablePhysicalProtection { get; set; } - /// <summary> /// Create a new tracking structure for the given "physical" memory block, /// with a given "virtual" memory manager that will provide mappings and virtual memory protection. @@ -34,11 +32,11 @@ namespace Ryujinx.Memory.Tracking /// <param name="memoryManager">Virtual memory manager</param> /// <param name="block">Physical memory block</param> /// <param name="pageSize">Page size of the virtual memory space</param> - public MemoryTracking(IVirtualMemoryManager memoryManager, MemoryBlock block, int pageSize) + public MemoryTracking(IVirtualMemoryManager memoryManager, int pageSize, InvalidAccessHandler invalidAccessHandler = null) { _memoryManager = memoryManager; - _block = block; _pageSize = pageSize; + _invalidAccessHandler = invalidAccessHandler; _virtualRegions = new NonOverlappingRangeList<VirtualRegion>(); } @@ -56,9 +54,8 @@ namespace Ryujinx.Memory.Tracking /// Should be called after the mapping is complete. /// </summary> /// <param name="va">Virtual memory address</param> - /// <param name="pa">Physical memory address</param> /// <param name="size">Size to be mapped</param> - public void Map(ulong va, ulong pa, ulong size) + public void Map(ulong va, ulong size) { // A mapping may mean we need to re-evaluate each VirtualRegion's affected area. // Find all handles that overlap with the range, we need to recalculate their physical regions @@ -208,6 +205,15 @@ namespace Ryujinx.Memory.Tracking if (count == 0) { + if (!_memoryManager.IsMapped(address)) + { + _invalidAccessHandler?.Invoke(address); + + // We can't continue - it's impossible to remove protection from the page. + // Even if the access handler wants us to continue, we wouldn't be able to. + throw new InvalidMemoryRegionException(); + } + _memoryManager.TrackingReprotect(address & ~(ulong)(_pageSize - 1), (ulong)_pageSize, MemoryPermission.ReadAndWrite); return false; // We can't handle this - it's probably a real invalid access. } |