mirror of
https://github.com/Ryubing/Ryujinx.git
synced 2025-03-10 09:04:23 +00:00
misc: chore: Use explicit types in Memory project
This commit is contained in:
parent
ac401034d7
commit
fe661dc750
@ -109,7 +109,7 @@ namespace Ryujinx.Memory
|
||||
yield break;
|
||||
}
|
||||
|
||||
foreach (var hostRegion in GetHostRegionsImpl(va, size))
|
||||
foreach (HostMemoryRange hostRegion in GetHostRegionsImpl(va, size))
|
||||
{
|
||||
yield return hostRegion;
|
||||
}
|
||||
@ -123,7 +123,7 @@ namespace Ryujinx.Memory
|
||||
yield break;
|
||||
}
|
||||
|
||||
var hostRegions = GetHostRegionsImpl(va, size);
|
||||
IEnumerable<HostMemoryRange> hostRegions = GetHostRegionsImpl(va, size);
|
||||
if (hostRegions == null)
|
||||
{
|
||||
yield break;
|
||||
@ -132,7 +132,7 @@ namespace Ryujinx.Memory
|
||||
ulong backingStart = (ulong)_backingMemory.Pointer;
|
||||
ulong backingEnd = backingStart + _backingMemory.Size;
|
||||
|
||||
foreach (var hostRegion in hostRegions)
|
||||
foreach (HostMemoryRange hostRegion in hostRegions)
|
||||
{
|
||||
if (hostRegion.Address >= backingStart && hostRegion.Address < backingEnd)
|
||||
{
|
||||
|
@ -14,7 +14,7 @@ namespace Ryujinx.Memory
|
||||
|
||||
public BytesReadOnlySequenceSegment Append(Memory<byte> memory)
|
||||
{
|
||||
var nextSegment = new BytesReadOnlySequenceSegment(memory)
|
||||
BytesReadOnlySequenceSegment nextSegment = new BytesReadOnlySequenceSegment(memory)
|
||||
{
|
||||
RunningIndex = RunningIndex + Memory.Length
|
||||
};
|
||||
@ -34,8 +34,8 @@ namespace Ryujinx.Memory
|
||||
/// <returns>True if the segments are contiguous, otherwise false</returns>
|
||||
public unsafe bool IsContiguousWith(Memory<byte> other, out nuint contiguousStart, out int contiguousSize)
|
||||
{
|
||||
if (MemoryMarshal.TryGetMemoryManager<byte, NativeMemoryManager<byte>>(Memory, out var thisMemoryManager) &&
|
||||
MemoryMarshal.TryGetMemoryManager<byte, NativeMemoryManager<byte>>(other, out var otherMemoryManager) &&
|
||||
if (MemoryMarshal.TryGetMemoryManager<byte, NativeMemoryManager<byte>>(Memory, out NativeMemoryManager<byte> thisMemoryManager) &&
|
||||
MemoryMarshal.TryGetMemoryManager<byte, NativeMemoryManager<byte>>(other, out NativeMemoryManager<byte> otherMemoryManager) &&
|
||||
thisMemoryManager.Pointer + thisMemoryManager.Length == otherMemoryManager.Pointer)
|
||||
{
|
||||
contiguousStart = (nuint)thisMemoryManager.Pointer;
|
||||
|
@ -118,7 +118,7 @@ namespace Ryujinx.Memory
|
||||
{
|
||||
int copySize = (int)Math.Min(MaxChunkSize, size - subOffset);
|
||||
|
||||
using var writableRegion = GetWritableRegion(va + subOffset, copySize);
|
||||
using WritableRegion writableRegion = GetWritableRegion(va + subOffset, copySize);
|
||||
|
||||
writableRegion.Memory.Span.Fill(value);
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ namespace Ryujinx.Memory
|
||||
|
||||
public static nint CreateSharedMemory(nint size, bool reserve)
|
||||
{
|
||||
var prot = reserve ? FileMapProtection.SectionReserve : FileMapProtection.SectionCommit;
|
||||
FileMapProtection prot = reserve ? FileMapProtection.SectionReserve : FileMapProtection.SectionCommit;
|
||||
|
||||
nint handle = WindowsApi.CreateFileMapping(
|
||||
WindowsApi.InvalidHandleValue,
|
||||
|
@ -73,7 +73,7 @@ namespace Ryujinx.Memory.Range
|
||||
}
|
||||
else
|
||||
{
|
||||
var ranges = new List<MemoryRange>();
|
||||
List<MemoryRange> ranges = [];
|
||||
|
||||
foreach (MemoryRange range in _ranges)
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ namespace Ryujinx.Memory.Range
|
||||
|
||||
for (int i = 0; i < range.Count; i++)
|
||||
{
|
||||
var subrange = range.GetSubRange(i);
|
||||
MemoryRange subrange = range.GetSubRange(i);
|
||||
|
||||
if (MemoryRange.IsInvalid(ref subrange))
|
||||
{
|
||||
@ -54,7 +54,7 @@ namespace Ryujinx.Memory.Range
|
||||
|
||||
for (int i = 0; i < range.Count; i++)
|
||||
{
|
||||
var subrange = range.GetSubRange(i);
|
||||
MemoryRange subrange = range.GetSubRange(i);
|
||||
|
||||
if (MemoryRange.IsInvalid(ref subrange))
|
||||
{
|
||||
@ -97,7 +97,7 @@ namespace Ryujinx.Memory.Range
|
||||
|
||||
for (int i = 0; i < range.Count; i++)
|
||||
{
|
||||
var subrange = range.GetSubRange(i);
|
||||
MemoryRange subrange = range.GetSubRange(i);
|
||||
|
||||
if (MemoryRange.IsInvalid(ref subrange))
|
||||
{
|
||||
@ -172,8 +172,8 @@ namespace Ryujinx.Memory.Range
|
||||
|
||||
private List<T> GetList()
|
||||
{
|
||||
var items = _items.AsList();
|
||||
var result = new List<T>();
|
||||
List<RangeNode<ulong, T>> items = _items.AsList();
|
||||
List<T> result = new List<T>();
|
||||
|
||||
foreach (RangeNode<ulong, T> item in items)
|
||||
{
|
||||
|
@ -26,7 +26,7 @@ namespace Ryujinx.Memory.Range
|
||||
// For instance, while a virtual mapping could cover 0-2 in physical space, the space 0-1 may have already been reserved...
|
||||
// So we need to return both the split 0-1 and 1-2 ranges.
|
||||
|
||||
var results = new T[1];
|
||||
T[] results = new T[1];
|
||||
int count = FindOverlapsNonOverlapping(address, size, ref results);
|
||||
|
||||
if (count == 0)
|
||||
|
@ -76,7 +76,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
|
||||
lock (TrackingLock)
|
||||
{
|
||||
ref var overlaps = ref ThreadStaticArray<VirtualRegion>.Get();
|
||||
ref VirtualRegion[] overlaps = ref ThreadStaticArray<VirtualRegion>.Get();
|
||||
|
||||
for (int type = 0; type < 2; type++)
|
||||
{
|
||||
@ -114,7 +114,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
|
||||
lock (TrackingLock)
|
||||
{
|
||||
ref var overlaps = ref ThreadStaticArray<VirtualRegion>.Get();
|
||||
ref VirtualRegion[] overlaps = ref ThreadStaticArray<VirtualRegion>.Get();
|
||||
|
||||
for (int type = 0; type < 2; type++)
|
||||
{
|
||||
@ -228,7 +228,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
/// <returns>The memory tracking handle</returns>
|
||||
public RegionHandle BeginTracking(ulong address, ulong size, int id, RegionFlags flags = RegionFlags.None)
|
||||
{
|
||||
var (paAddress, paSize) = PageAlign(address, size);
|
||||
(ulong paAddress, ulong paSize) = PageAlign(address, size);
|
||||
|
||||
lock (TrackingLock)
|
||||
{
|
||||
@ -251,7 +251,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
/// <returns>The memory tracking handle</returns>
|
||||
internal RegionHandle BeginTrackingBitmap(ulong address, ulong size, ConcurrentBitmap bitmap, int bit, int id, RegionFlags flags = RegionFlags.None)
|
||||
{
|
||||
var (paAddress, paSize) = PageAlign(address, size);
|
||||
(ulong paAddress, ulong paSize) = PageAlign(address, size);
|
||||
|
||||
lock (TrackingLock)
|
||||
{
|
||||
@ -296,7 +296,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
|
||||
lock (TrackingLock)
|
||||
{
|
||||
ref var overlaps = ref ThreadStaticArray<VirtualRegion>.Get();
|
||||
ref VirtualRegion[] overlaps = ref ThreadStaticArray<VirtualRegion>.Get();
|
||||
|
||||
NonOverlappingRangeList<VirtualRegion> regions = guest ? _guestVirtualRegions : _virtualRegions;
|
||||
|
||||
|
@ -320,7 +320,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
|
||||
if (startHandle == lastHandle)
|
||||
{
|
||||
var handle = _handles[startHandle];
|
||||
RegionHandle handle = _handles[startHandle];
|
||||
if (_sequenceNumberBitmap.Set(startHandle))
|
||||
{
|
||||
_uncheckedHandles--;
|
||||
@ -410,7 +410,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
foreach (var handle in _handles)
|
||||
foreach (RegionHandle handle in _handles)
|
||||
{
|
||||
handle.Dispose();
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
_allRegions.AddRange(_regions);
|
||||
_allRegions.AddRange(_guestRegions);
|
||||
|
||||
foreach (var region in _allRegions)
|
||||
foreach (VirtualRegion region in _allRegions)
|
||||
{
|
||||
region.Handles.Add(this);
|
||||
}
|
||||
@ -217,8 +217,8 @@ namespace Ryujinx.Memory.Tracking
|
||||
{
|
||||
// Assumes the tracking lock is held, so nothing else can signal right now.
|
||||
|
||||
var oldBitmap = Bitmap;
|
||||
var oldBit = DirtyBit;
|
||||
ConcurrentBitmap oldBitmap = Bitmap;
|
||||
int oldBit = DirtyBit;
|
||||
|
||||
bitmap.Set(bit, Dirty);
|
||||
|
||||
|
@ -45,7 +45,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
|
||||
public void ForceDirty(ulong address, ulong size)
|
||||
{
|
||||
foreach (var handle in _handles)
|
||||
foreach (RegionHandle handle in _handles)
|
||||
{
|
||||
if (handle != null && handle.OverlapsWith(address, size))
|
||||
{
|
||||
@ -56,7 +56,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
|
||||
public void RegisterAction(RegionSignal action)
|
||||
{
|
||||
foreach (var handle in _handles)
|
||||
foreach (RegionHandle handle in _handles)
|
||||
{
|
||||
if (handle != null)
|
||||
{
|
||||
@ -67,7 +67,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
|
||||
public void RegisterPreciseAction(PreciseRegionSignal action)
|
||||
{
|
||||
foreach (var handle in _handles)
|
||||
foreach (RegionHandle handle in _handles)
|
||||
{
|
||||
if (handle != null)
|
||||
{
|
||||
@ -273,7 +273,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
foreach (var handle in _handles)
|
||||
foreach (RegionHandle handle in _handles)
|
||||
{
|
||||
handle?.Dispose();
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
|
||||
MemoryPermission result = MemoryPermission.ReadAndWrite;
|
||||
|
||||
foreach (var handle in Handles)
|
||||
foreach (RegionHandle handle in Handles)
|
||||
{
|
||||
result &= handle.RequiredPermission;
|
||||
if (result == 0)
|
||||
@ -143,7 +143,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
|
||||
// The new region inherits all of our parents.
|
||||
newRegion.Handles = new List<RegionHandle>(Handles);
|
||||
foreach (var parent in Handles)
|
||||
foreach (RegionHandle parent in Handles)
|
||||
{
|
||||
parent.AddChild(newRegion);
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ namespace Ryujinx.Memory
|
||||
|
||||
nuint pa = TranslateVirtualAddressChecked(va);
|
||||
|
||||
var target = GetPhysicalAddressSpan(pa, data.Length);
|
||||
Span<byte> target = GetPhysicalAddressSpan(pa, data.Length);
|
||||
|
||||
bool changed = !data.SequenceEqual(target);
|
||||
|
||||
|
@ -128,7 +128,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
/// <param name="owner">Memory block that owns the mapping</param>
|
||||
public void MapView(nint sharedMemory, ulong srcOffset, nint location, nint size, MemoryBlock owner)
|
||||
{
|
||||
ref var partialUnmapLock = ref GetPartialUnmapState().PartialUnmapLock;
|
||||
ref NativeReaderWriterLock partialUnmapLock = ref GetPartialUnmapState().PartialUnmapLock;
|
||||
partialUnmapLock.AcquireReaderLock();
|
||||
|
||||
try
|
||||
@ -155,7 +155,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
{
|
||||
SplitForMap((ulong)location, (ulong)size, srcOffset);
|
||||
|
||||
var ptr = WindowsApi.MapViewOfFile3(
|
||||
IntPtr ptr = WindowsApi.MapViewOfFile3(
|
||||
sharedMemory,
|
||||
WindowsApi.CurrentProcessHandle,
|
||||
location,
|
||||
@ -187,7 +187,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
{
|
||||
ulong endAddress = address + size;
|
||||
|
||||
var overlaps = new RangeNode<ulong>[InitialOverlapsSize];
|
||||
RangeNode<ulong>[] overlaps = new RangeNode<ulong>[InitialOverlapsSize];
|
||||
|
||||
lock (_mappings)
|
||||
{
|
||||
@ -196,7 +196,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
Debug.Assert(count == 1);
|
||||
Debug.Assert(!IsMapped(overlaps[0].Value));
|
||||
|
||||
var overlap = overlaps[0];
|
||||
RangeNode<ulong> overlap = overlaps[0];
|
||||
|
||||
ulong overlapStart = overlap.Start;
|
||||
ulong overlapEnd = overlap.End;
|
||||
@ -257,7 +257,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
/// <param name="owner">Memory block that owns the mapping</param>
|
||||
public void UnmapView(nint sharedMemory, nint location, nint size, MemoryBlock owner)
|
||||
{
|
||||
ref var partialUnmapLock = ref GetPartialUnmapState().PartialUnmapLock;
|
||||
ref NativeReaderWriterLock partialUnmapLock = ref GetPartialUnmapState().PartialUnmapLock;
|
||||
partialUnmapLock.AcquireReaderLock();
|
||||
|
||||
try
|
||||
@ -289,7 +289,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
ulong unmapSize = (ulong)size;
|
||||
ulong endAddress = startAddress + unmapSize;
|
||||
|
||||
var overlaps = new RangeNode<ulong>[InitialOverlapsSize];
|
||||
RangeNode<ulong>[] overlaps = new RangeNode<ulong>[InitialOverlapsSize];
|
||||
int count;
|
||||
|
||||
lock (_mappings)
|
||||
@ -299,7 +299,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
|
||||
for (int index = 0; index < count; index++)
|
||||
{
|
||||
var overlap = overlaps[index];
|
||||
RangeNode<ulong> overlap = overlaps[index];
|
||||
|
||||
if (IsMapped(overlap.Value))
|
||||
{
|
||||
@ -319,8 +319,8 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
// This is necessary because Windows does not support partial view unmaps.
|
||||
// That is, you can only fully unmap a view that was previously mapped, you can't just unmap a chunck of it.
|
||||
|
||||
ref var partialUnmapState = ref GetPartialUnmapState();
|
||||
ref var partialUnmapLock = ref partialUnmapState.PartialUnmapLock;
|
||||
ref PartialUnmapState partialUnmapState = ref GetPartialUnmapState();
|
||||
ref NativeReaderWriterLock partialUnmapLock = ref partialUnmapState.PartialUnmapLock;
|
||||
partialUnmapLock.UpgradeToWriterLock();
|
||||
|
||||
try
|
||||
@ -400,7 +400,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
for (; node != null; node = successor)
|
||||
{
|
||||
successor = node.Successor;
|
||||
var overlap = node;
|
||||
RangeNode<ulong> overlap = node;
|
||||
|
||||
if (!IsMapped(overlap.Value))
|
||||
{
|
||||
@ -456,7 +456,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
/// <returns>True if the reprotection was successful, false otherwise</returns>
|
||||
public bool ReprotectView(nint address, nint size, MemoryPermission permission)
|
||||
{
|
||||
ref var partialUnmapLock = ref GetPartialUnmapState().PartialUnmapLock;
|
||||
ref NativeReaderWriterLock partialUnmapLock = ref GetPartialUnmapState().PartialUnmapLock;
|
||||
partialUnmapLock.AcquireReaderLock();
|
||||
|
||||
try
|
||||
@ -494,7 +494,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
for (; node != null; node = successorNode)
|
||||
{
|
||||
successorNode = node.Successor;
|
||||
var overlap = node;
|
||||
RangeNode<ulong> overlap = node;
|
||||
|
||||
ulong mappedAddress = overlap.Start;
|
||||
ulong mappedSize = overlap.End - overlap.Start;
|
||||
@ -604,7 +604,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
for (; node != null; node = successorNode)
|
||||
{
|
||||
successorNode = node.Successor;
|
||||
var protection = node;
|
||||
RangeNode<MemoryPermission> protection = node;
|
||||
|
||||
ulong protAddress = protection.Start;
|
||||
ulong protEndAddress = protection.End;
|
||||
@ -664,7 +664,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
for (; node != null; node = successorNode)
|
||||
{
|
||||
successorNode = node.Successor;
|
||||
var protection = node;
|
||||
RangeNode<MemoryPermission> protection = node;
|
||||
|
||||
ulong protAddress = protection.Start;
|
||||
ulong protEndAddress = protection.End;
|
||||
@ -698,7 +698,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
private void RestoreRangeProtection(ulong address, ulong size)
|
||||
{
|
||||
ulong endAddress = address + size;
|
||||
var overlaps = new RangeNode<MemoryPermission>[InitialOverlapsSize];
|
||||
RangeNode<MemoryPermission>[] overlaps = new RangeNode<MemoryPermission>[InitialOverlapsSize];
|
||||
int count;
|
||||
|
||||
lock (_protections)
|
||||
@ -708,7 +708,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||
|
||||
for (int index = 0; index < count; index++)
|
||||
{
|
||||
var protection = overlaps[index];
|
||||
RangeNode<MemoryPermission> protection = overlaps[index];
|
||||
|
||||
// If protection is R/W we don't need to reprotect as views are initially mapped as R/W.
|
||||
if (protection.Value == MemoryPermission.ReadAndWrite)
|
||||
|
Loading…
x
Reference in New Issue
Block a user