See merge request ryubing/ryujinx!234
This commit is contained in:
LotP
2025-12-06 17:19:19 -06:00
committed by GreemDev
parent fd7554425a
commit c3155fcadb
37 changed files with 563 additions and 677 deletions

View File

@@ -5,7 +5,7 @@ namespace Ryujinx.Memory.Tracking
/// <summary>
/// A region of memory.
/// </summary>
abstract class AbstractRegion : INonOverlappingRange
abstract class AbstractRegion<T> : INonOverlappingRange<T> where T : class, INonOverlappingRange<T>
{
/// <summary>
/// Base address.
@@ -21,6 +21,9 @@ namespace Ryujinx.Memory.Tracking
/// End address.
/// </summary>
public ulong EndAddress => Address + Size;
public T Next { get; set; }
public T Previous { get; set; }
/// <summary>
/// Create a new region.
@@ -37,11 +40,11 @@ namespace Ryujinx.Memory.Tracking
/// Check if this range overlaps with another.
/// </summary>
/// <param name="address">Base address</param>
/// <param name="size">Size of the range</param>
/// <param name="endAddress">End address</param>
/// <returns>True if overlapping, false otherwise</returns>
public bool OverlapsWith(ulong address, ulong size)
public bool OverlapsWith(ulong address, ulong endAddress)
{
return Address < address + size && address < EndAddress;
return Address < endAddress && address < EndAddress;
}
/// <summary>
@@ -68,6 +71,6 @@ namespace Ryujinx.Memory.Tracking
/// </summary>
/// <param name="splitAddress">Address to split the region around</param>
/// <returns>The second part of the split region, with start address at the given split.</returns>
public abstract INonOverlappingRange Split(ulong splitAddress);
public abstract INonOverlappingRange<T> Split(ulong splitAddress);
}
}

View File

@@ -81,10 +81,10 @@ namespace Ryujinx.Memory.Tracking
{
NonOverlappingRangeList<VirtualRegion> regions = type == 0 ? _virtualRegions : _guestVirtualRegions;
regions.Lock.EnterReadLock();
Span<RangeItem<VirtualRegion>> overlaps = regions.FindOverlapsAsSpan(va, size);
ReadOnlySpan<VirtualRegion> overlaps = regions.FindOverlapsAsSpan(va, size);
for (int i = 0; i < overlaps.Length; i++)
{
VirtualRegion region = overlaps[i].Value;
VirtualRegion region = overlaps[i];
// If the region has been fully remapped, signal that it has been mapped again.
bool remapped = _memoryManager.IsRangeMapped(region.Address, region.Size);
@@ -117,11 +117,11 @@ namespace Ryujinx.Memory.Tracking
{
NonOverlappingRangeList<VirtualRegion> regions = type == 0 ? _virtualRegions : _guestVirtualRegions;
regions.Lock.EnterReadLock();
Span<RangeItem<VirtualRegion>> overlaps = regions.FindOverlapsAsSpan(va, size);
ReadOnlySpan<VirtualRegion> overlaps = regions.FindOverlapsAsSpan(va, size);
for (int i = 0; i < overlaps.Length; i++)
{
overlaps[i].Value.SignalMappingChanged(false);
overlaps[i].SignalMappingChanged(false);
}
regions.Lock.ExitReadLock();
}
@@ -301,7 +301,7 @@ namespace Ryujinx.Memory.Tracking
// We use the non-span method here because keeping the lock will cause a deadlock.
regions.Lock.EnterReadLock();
RangeItem<VirtualRegion>[] overlaps = regions.FindOverlapsAsArray(address, size, out int length);
VirtualRegion[] overlaps = regions.FindOverlapsAsArray(address, size, out int length);
regions.Lock.ExitReadLock();
if (length == 0 && !precise)
@@ -327,7 +327,7 @@ namespace Ryujinx.Memory.Tracking
for (int i = 0; i < length; i++)
{
VirtualRegion region = overlaps[i].Value;
VirtualRegion region = overlaps[i];
if (precise)
{
@@ -341,7 +341,7 @@ namespace Ryujinx.Memory.Tracking
if (length != 0)
{
ArrayPool<RangeItem<VirtualRegion>>.Shared.Return(overlaps);
ArrayPool<VirtualRegion>.Shared.Return(overlaps);
}
}
}

View File

@@ -6,7 +6,7 @@ namespace Ryujinx.Memory.Tracking
/// <summary>
/// A region of virtual memory.
/// </summary>
class VirtualRegion : AbstractRegion
class VirtualRegion : AbstractRegion<VirtualRegion>
{
public List<RegionHandle> Handles = [];
@@ -137,7 +137,7 @@ namespace Ryujinx.Memory.Tracking
}
}
public override INonOverlappingRange Split(ulong splitAddress)
public override INonOverlappingRange<VirtualRegion> Split(ulong splitAddress)
{
VirtualRegion newRegion = new(_tracking, splitAddress, EndAddress - splitAddress, Guest, _lastPermission);
Size = splitAddress - Address;