From 0a75b73fa43ddadf561ddeb0f923c6f3811c025b Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Wed, 28 Jun 2023 18:34:00 +0200 Subject: [PATCH] [Ryujinx.Memory] Address dotnet-format issues (#5386) * dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Silence dotnet format IDE0059 warnings * Address or silence dotnet format IDE1006 warnings * Address dotnet format CA1816 warnings * Address or silence dotnet format CA1069 warnings * Address remaining dotnet format analyzer warnings * Address review comments * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Format if-blocks correctly * Another rebase, another dotnet format run * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Add comments to disabled warnings * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * Address review feedback * Assign Decommit to ReplacePlaceholder * Run final dotnet format pass * Organize imports again * Add trailing commas * Add missing newline --- src/Ryujinx.Memory/AddressSpaceManager.cs | 8 ++++---- src/Ryujinx.Memory/MemoryAllocationFlags.cs | 2 +- src/Ryujinx.Memory/MemoryBlock.cs | 6 +++--- src/Ryujinx.Memory/MemoryManagement.cs | 2 +- src/Ryujinx.Memory/MemoryManagementUnix.cs | 14 +++++++------- src/Ryujinx.Memory/MemoryManagementWindows.cs | 2 +- src/Ryujinx.Memory/MemoryManagerUnixHelper.cs | 8 ++++---- src/Ryujinx.Memory/MemoryMapFlags.cs | 2 +- src/Ryujinx.Memory/MemoryNotContiguousException.cs | 2 +- src/Ryujinx.Memory/MemoryPermission.cs | 2 +- src/Ryujinx.Memory/Range/HostMemoryRange.cs | 14 ++++++++++++-- src/Ryujinx.Memory/Range/IRange.cs | 2 +- src/Ryujinx.Memory/Range/MemoryRange.cs | 2 +- src/Ryujinx.Memory/Range/MultiRange.cs | 12 +++++++++++- src/Ryujinx.Memory/Range/RangeList.cs | 8 ++++---- src/Ryujinx.Memory/Tracking/MemoryTracking.cs | 8 ++++---- src/Ryujinx.Memory/Tracking/MultiRegionHandle.cs | 11 +++++++---- src/Ryujinx.Memory/Tracking/RegionHandle.cs | 14 +++++++++----- .../Tracking/SmartMultiRegionHandle.cs | 4 +++- src/Ryujinx.Memory/Tracking/VirtualRegion.cs | 9 ++++++--- src/Ryujinx.Memory/WindowsShared/MappingTree.cs | 2 +- .../WindowsShared/PlaceholderManager.cs | 12 ++++++------ src/Ryujinx.Memory/WindowsShared/WindowsApi.cs | 8 ++++---- .../WindowsShared/WindowsApiException.cs | 2 +- src/Ryujinx.Memory/WindowsShared/WindowsFlags.cs | 8 ++++---- 25 files changed, 98 insertions(+), 66 deletions(-) diff --git a/src/Ryujinx.Memory/AddressSpaceManager.cs b/src/Ryujinx.Memory/AddressSpaceManager.cs index ac89fca6d..65b4d48f2 100644 --- a/src/Ryujinx.Memory/AddressSpaceManager.cs +++ b/src/Ryujinx.Memory/AddressSpaceManager.cs @@ -136,7 +136,7 @@ namespace Ryujinx.Memory { size = Math.Min(data.Length, PageSize - (int)(va & PageMask)); - data.Slice(0, size).CopyTo(GetHostSpanContiguous(va, size)); + data[..size].CopyTo(GetHostSpanContiguous(va, size)); offset += size; } @@ -215,7 +215,7 @@ namespace Ryujinx.Memory /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - private int GetPagesCount(ulong va, uint size, out ulong startVa) + private static int GetPagesCount(ulong va, uint size, out ulong startVa) { // WARNING: Always check if ulong does not overflow during the operations. startVa = va & ~(ulong)PageMask; @@ -224,7 +224,7 @@ namespace Ryujinx.Memory return (int)(vaSpan / PageSize); } - private void ThrowMemoryNotContiguous() => throw new MemoryNotContiguousException(); + private static void ThrowMemoryNotContiguous() => throw new MemoryNotContiguousException(); [MethodImpl(MethodImplOptions.AggressiveInlining)] private bool IsContiguousAndMapped(ulong va, int size) => IsContiguous(va, size) && IsMapped(va); @@ -361,7 +361,7 @@ namespace Ryujinx.Memory { size = Math.Min(data.Length, PageSize - (int)(va & PageMask)); - GetHostSpanContiguous(va, size).CopyTo(data.Slice(0, size)); + GetHostSpanContiguous(va, size).CopyTo(data[..size]); offset += size; } diff --git a/src/Ryujinx.Memory/MemoryAllocationFlags.cs b/src/Ryujinx.Memory/MemoryAllocationFlags.cs index 6f0ef1aa9..e5fa9360d 100644 --- a/src/Ryujinx.Memory/MemoryAllocationFlags.cs +++ b/src/Ryujinx.Memory/MemoryAllocationFlags.cs @@ -47,6 +47,6 @@ namespace Ryujinx.Memory /// Indicates that the memory will be used to store JIT generated code. /// On some platforms, this requires special flags to be passed that will allow the memory to be executable. /// - Jit = 1 << 5 + Jit = 1 << 5, } } diff --git a/src/Ryujinx.Memory/MemoryBlock.cs b/src/Ryujinx.Memory/MemoryBlock.cs index e7fc47516..7d8d7cf05 100644 --- a/src/Ryujinx.Memory/MemoryBlock.cs +++ b/src/Ryujinx.Memory/MemoryBlock.cs @@ -364,9 +364,9 @@ namespace Ryujinx.Memory /// Native pointer /// Offset to add /// Native pointer with the added offset - private IntPtr PtrAddr(IntPtr pointer, ulong offset) + private static IntPtr PtrAddr(IntPtr pointer, ulong offset) { - return (IntPtr)(pointer.ToInt64() + (long)offset); + return new IntPtr(pointer.ToInt64() + (long)offset); } /// @@ -439,4 +439,4 @@ namespace Ryujinx.Memory private static void ThrowInvalidMemoryRegionException() => throw new InvalidMemoryRegionException(); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/MemoryManagement.cs b/src/Ryujinx.Memory/MemoryManagement.cs index 7acf8345f..3415ba40e 100644 --- a/src/Ryujinx.Memory/MemoryManagement.cs +++ b/src/Ryujinx.Memory/MemoryManagement.cs @@ -203,4 +203,4 @@ namespace Ryujinx.Memory } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/MemoryManagementUnix.cs b/src/Ryujinx.Memory/MemoryManagementUnix.cs index 4314c3928..9827b59be 100644 --- a/src/Ryujinx.Memory/MemoryManagementUnix.cs +++ b/src/Ryujinx.Memory/MemoryManagementUnix.cs @@ -50,7 +50,7 @@ namespace Ryujinx.Memory } } - IntPtr ptr = mmap(IntPtr.Zero, size, prot, flags, -1, 0); + IntPtr ptr = Mmap(IntPtr.Zero, size, prot, flags, -1, 0); if (ptr == MAP_FAILED) { @@ -115,7 +115,7 @@ namespace Ryujinx.Memory MemoryPermission.ReadAndExecute => MmapProts.PROT_READ | MmapProts.PROT_EXEC, MemoryPermission.ReadWriteExecute => MmapProts.PROT_READ | MmapProts.PROT_WRITE | MmapProts.PROT_EXEC, MemoryPermission.Execute => MmapProts.PROT_EXEC, - _ => throw new MemoryProtectionException(permission) + _ => throw new MemoryProtectionException(permission), }; } @@ -185,12 +185,12 @@ namespace Ryujinx.Memory public static void DestroySharedMemory(IntPtr handle) { - close((int)handle); + close(handle.ToInt32()); } public static IntPtr MapSharedMemory(IntPtr handle, ulong size) { - return mmap(IntPtr.Zero, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE, MmapFlags.MAP_SHARED, (int)handle, 0); + return Mmap(IntPtr.Zero, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE, MmapFlags.MAP_SHARED, handle.ToInt32(), 0); } public static void UnmapSharedMemory(IntPtr address, ulong size) @@ -200,12 +200,12 @@ namespace Ryujinx.Memory public static void MapView(IntPtr sharedMemory, ulong srcOffset, IntPtr location, ulong size) { - mmap(location, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE, MmapFlags.MAP_FIXED | MmapFlags.MAP_SHARED, (int)sharedMemory, (long)srcOffset); + Mmap(location, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE, MmapFlags.MAP_FIXED | MmapFlags.MAP_SHARED, sharedMemory.ToInt32(), (long)srcOffset); } public static void UnmapView(IntPtr location, ulong size) { - mmap(location, size, MmapProts.PROT_NONE, MmapFlags.MAP_FIXED | MmapFlags.MAP_PRIVATE | MmapFlags.MAP_ANONYMOUS | MmapFlags.MAP_NORESERVE, -1, 0); + Mmap(location, size, MmapProts.PROT_NONE, MmapFlags.MAP_FIXED | MmapFlags.MAP_PRIVATE | MmapFlags.MAP_ANONYMOUS | MmapFlags.MAP_NORESERVE, -1, 0); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/MemoryManagementWindows.cs b/src/Ryujinx.Memory/MemoryManagementWindows.cs index aaed5a637..b5be5b3cf 100644 --- a/src/Ryujinx.Memory/MemoryManagementWindows.cs +++ b/src/Ryujinx.Memory/MemoryManagementWindows.cs @@ -148,4 +148,4 @@ namespace Ryujinx.Memory } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs b/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs index a7b207ab0..6f36a6d56 100644 --- a/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs +++ b/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs @@ -14,7 +14,7 @@ namespace Ryujinx.Memory PROT_NONE = 0, PROT_READ = 1, PROT_WRITE = 2, - PROT_EXEC = 4 + PROT_EXEC = 4, } [Flags] @@ -26,7 +26,7 @@ namespace Ryujinx.Memory MAP_NORESERVE = 8, MAP_FIXED = 16, MAP_UNLOCKED = 32, - MAP_JIT_DARWIN = 0x800 + MAP_JIT_DARWIN = 0x800, } [Flags] @@ -164,9 +164,9 @@ namespace Ryujinx.Memory return result; } - public static IntPtr mmap(IntPtr address, ulong length, MmapProts prot, MmapFlags flags, int fd, long offset) + public static IntPtr Mmap(IntPtr address, ulong length, MmapProts prot, MmapFlags flags, int fd, long offset) { return Internal_mmap(address, length, prot, MmapFlagsToSystemFlags(flags), fd, offset); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/MemoryMapFlags.cs b/src/Ryujinx.Memory/MemoryMapFlags.cs index b4c74c8c9..5c023cc12 100644 --- a/src/Ryujinx.Memory/MemoryMapFlags.cs +++ b/src/Ryujinx.Memory/MemoryMapFlags.cs @@ -18,6 +18,6 @@ namespace Ryujinx.Memory /// and allocate its own private storage for the mapping. /// This allows some mappings that would otherwise fail due to host platform restrictions to succeed. /// - Private = 1 << 0 + Private = 1 << 0, } } diff --git a/src/Ryujinx.Memory/MemoryNotContiguousException.cs b/src/Ryujinx.Memory/MemoryNotContiguousException.cs index 3106955b8..3468adb99 100644 --- a/src/Ryujinx.Memory/MemoryNotContiguousException.cs +++ b/src/Ryujinx.Memory/MemoryNotContiguousException.cs @@ -16,4 +16,4 @@ namespace Ryujinx.Memory { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/MemoryPermission.cs b/src/Ryujinx.Memory/MemoryPermission.cs index 8c3e33cf7..6e71d7b8c 100644 --- a/src/Ryujinx.Memory/MemoryPermission.cs +++ b/src/Ryujinx.Memory/MemoryPermission.cs @@ -46,6 +46,6 @@ namespace Ryujinx.Memory /// /// Indicates an invalid protection. /// - Invalid = 255 + Invalid = 255, } } diff --git a/src/Ryujinx.Memory/Range/HostMemoryRange.cs b/src/Ryujinx.Memory/Range/HostMemoryRange.cs index 79c649d85..a4abebb54 100644 --- a/src/Ryujinx.Memory/Range/HostMemoryRange.cs +++ b/src/Ryujinx.Memory/Range/HostMemoryRange.cs @@ -5,12 +5,12 @@ namespace Ryujinx.Memory.Range /// /// Range of memory composed of an address and size. /// - public struct HostMemoryRange : IEquatable + public readonly struct HostMemoryRange : IEquatable { /// /// An empty memory range, with a null address and zero size. /// - public static HostMemoryRange Empty => new HostMemoryRange(0, 0); + public static HostMemoryRange Empty => new(0, 0); /// /// Start address of the range. @@ -67,5 +67,15 @@ namespace Ryujinx.Memory.Range { return HashCode.Combine(Address, Size); } + + public static bool operator ==(HostMemoryRange left, HostMemoryRange right) + { + return left.Equals(right); + } + + public static bool operator !=(HostMemoryRange left, HostMemoryRange right) + { + return !(left == right); + } } } diff --git a/src/Ryujinx.Memory/Range/IRange.cs b/src/Ryujinx.Memory/Range/IRange.cs index 1685396d1..c85e21d1d 100644 --- a/src/Ryujinx.Memory/Range/IRange.cs +++ b/src/Ryujinx.Memory/Range/IRange.cs @@ -28,4 +28,4 @@ namespace Ryujinx.Memory.Range /// True if overlapping, false otherwise bool OverlapsWith(ulong address, ulong size); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/Range/MemoryRange.cs b/src/Ryujinx.Memory/Range/MemoryRange.cs index c7ee6db22..7e7b84b51 100644 --- a/src/Ryujinx.Memory/Range/MemoryRange.cs +++ b/src/Ryujinx.Memory/Range/MemoryRange.cs @@ -8,7 +8,7 @@ /// /// An empty memory range, with a null address and zero size. /// - public static MemoryRange Empty => new MemoryRange(0UL, 0); + public static MemoryRange Empty => new(0UL, 0); /// /// Start address of the range. diff --git a/src/Ryujinx.Memory/Range/MultiRange.cs b/src/Ryujinx.Memory/Range/MultiRange.cs index 42ef24be6..7011e528e 100644 --- a/src/Ryujinx.Memory/Range/MultiRange.cs +++ b/src/Ryujinx.Memory/Range/MultiRange.cs @@ -310,7 +310,7 @@ namespace Ryujinx.Memory.Range return _singleRange.GetHashCode(); } - HashCode hash = new HashCode(); + HashCode hash = new(); foreach (MemoryRange range in _ranges) { @@ -328,5 +328,15 @@ namespace Ryujinx.Memory.Range { return HasSingleRange ? _singleRange.ToString() : string.Join(", ", _ranges); } + + public static bool operator ==(MultiRange left, MultiRange right) + { + return left.Equals(right); + } + + public static bool operator !=(MultiRange left, MultiRange right) + { + return !(left == right); + } } } diff --git a/src/Ryujinx.Memory/Range/RangeList.cs b/src/Ryujinx.Memory/Range/RangeList.cs index 469195973..72cef1de0 100644 --- a/src/Ryujinx.Memory/Range/RangeList.cs +++ b/src/Ryujinx.Memory/Range/RangeList.cs @@ -238,7 +238,7 @@ namespace Ryujinx.Memory.Range if (index < 0) { - return default(T); + return default; } return _items[index].Value; @@ -398,7 +398,7 @@ namespace Ryujinx.Memory.Range /// List index of the item, or complement index of nearest item with lower value on the list private int BinarySearch(ulong address) { - int left = 0; + int left = 0; int right = Count - 1; while (left <= right) @@ -435,7 +435,7 @@ namespace Ryujinx.Memory.Range /// List index of the item, or complement index of nearest item with lower value on the list private int BinarySearch(ulong address, ulong endAddress) { - int left = 0; + int left = 0; int right = Count - 1; while (left <= right) @@ -480,4 +480,4 @@ namespace Ryujinx.Memory.Range } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/Tracking/MemoryTracking.cs b/src/Ryujinx.Memory/Tracking/MemoryTracking.cs index bf1e0ad34..ab9d98932 100644 --- a/src/Ryujinx.Memory/Tracking/MemoryTracking.cs +++ b/src/Ryujinx.Memory/Tracking/MemoryTracking.cs @@ -21,7 +21,7 @@ namespace Ryujinx.Memory.Tracking /// This lock must be obtained when traversing or updating the region-handle hierarchy. /// It is not required when reading dirty flags. /// - internal object TrackingLock = new object(); + internal object TrackingLock = new(); /// /// Create a new tracking structure for the given "physical" memory block, @@ -114,7 +114,7 @@ namespace Ryujinx.Memory.Tracking /// A list of virtual regions within the given range internal List GetVirtualRegionsForHandle(ulong va, ulong size) { - List result = new List(); + List result = new(); _virtualRegions.GetOrAddRegions(result, va, size, (va, size) => new VirtualRegion(this, va, size)); return result; @@ -172,7 +172,7 @@ namespace Ryujinx.Memory.Tracking lock (TrackingLock) { bool mapped = _memoryManager.IsRangeMapped(address, size); - RegionHandle handle = new RegionHandle(this, paAddress, paSize, address, size, id, mapped); + RegionHandle handle = new(this, paAddress, paSize, address, size, id, mapped); return handle; } @@ -194,7 +194,7 @@ namespace Ryujinx.Memory.Tracking lock (TrackingLock) { bool mapped = _memoryManager.IsRangeMapped(address, size); - RegionHandle handle = new RegionHandle(this, paAddress, paSize, address, size, bitmap, bit, id, mapped); + RegionHandle handle = new(this, paAddress, paSize, address, size, bitmap, bit, id, mapped); return handle; } diff --git a/src/Ryujinx.Memory/Tracking/MultiRegionHandle.cs b/src/Ryujinx.Memory/Tracking/MultiRegionHandle.cs index 68fc5e759..5d3f20f4f 100644 --- a/src/Ryujinx.Memory/Tracking/MultiRegionHandle.cs +++ b/src/Ryujinx.Memory/Tracking/MultiRegionHandle.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using System.Threading; @@ -21,11 +22,11 @@ namespace Ryujinx.Memory.Tracking private readonly ulong Granularity; private readonly ulong Size; - private ConcurrentBitmap _dirtyBitmap; + private readonly ConcurrentBitmap _dirtyBitmap; private int _sequenceNumber; - private BitMap _sequenceNumberBitmap; - private BitMap _dirtyCheckedBitmap; + private readonly BitMap _sequenceNumberBitmap; + private readonly BitMap _dirtyCheckedBitmap; private int _uncheckedHandles; public bool Dirty { get; private set; } = true; @@ -54,7 +55,7 @@ namespace Ryujinx.Memory.Tracking // It is assumed that the provided handles do not overlap, in order, are on page boundaries, // and don't extend past the requested range. - foreach (RegionHandle handle in handles) + foreach (RegionHandle handle in handles.Cast()) { int startIndex = (int)((handle.RealAddress - address) / granularity); @@ -406,6 +407,8 @@ namespace Ryujinx.Memory.Tracking public void Dispose() { + GC.SuppressFinalize(this); + foreach (var handle in _handles) { handle.Dispose(); diff --git a/src/Ryujinx.Memory/Tracking/RegionHandle.cs b/src/Ryujinx.Memory/Tracking/RegionHandle.cs index 777944888..d36207cad 100644 --- a/src/Ryujinx.Memory/Tracking/RegionHandle.cs +++ b/src/Ryujinx.Memory/Tracking/RegionHandle.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection.Metadata; using System.Threading; namespace Ryujinx.Memory.Tracking @@ -50,7 +49,7 @@ namespace Ryujinx.Memory.Tracking internal IMultiRegionHandle Parent { get; set; } - private event Action _onDirty; + private event Action OnDirty; private readonly object _preActionLock = new(); private RegionSignal _preAction; // Action to perform before a read or write. This will block the memory access. @@ -269,7 +268,7 @@ namespace Ryujinx.Memory.Tracking Dirty = true; if (!oldDirty) { - _onDirty?.Invoke(); + OnDirty?.Invoke(); } Parent?.SignalWrite(); } @@ -311,7 +310,10 @@ namespace Ryujinx.Memory.Tracking /// True if this reprotect is the result of consecutive dirty checks public void Reprotect(bool asDirty, bool consecutiveCheck = false) { - if (_volatile) return; + if (_volatile) + { + return; + } Dirty = asDirty; @@ -403,7 +405,7 @@ namespace Ryujinx.Memory.Tracking /// Action to call on dirty public void RegisterDirtyEvent(Action action) { - _onDirty += action; + OnDirty += action; } /// @@ -461,6 +463,8 @@ namespace Ryujinx.Memory.Tracking { ObjectDisposedException.ThrowIf(_disposed, this); + GC.SuppressFinalize(this); + _disposed = true; lock (_tracking.TrackingLock) diff --git a/src/Ryujinx.Memory/Tracking/SmartMultiRegionHandle.cs b/src/Ryujinx.Memory/Tracking/SmartMultiRegionHandle.cs index 4acddefaf..bab00377d 100644 --- a/src/Ryujinx.Memory/Tracking/SmartMultiRegionHandle.cs +++ b/src/Ryujinx.Memory/Tracking/SmartMultiRegionHandle.cs @@ -17,7 +17,7 @@ namespace Ryujinx.Memory.Tracking private readonly ulong _address; private readonly ulong _granularity; private readonly ulong _size; - private MemoryTracking _tracking; + private readonly MemoryTracking _tracking; private readonly int _id; public bool Dirty { get; private set; } = true; @@ -271,6 +271,8 @@ namespace Ryujinx.Memory.Tracking public void Dispose() { + GC.SuppressFinalize(this); + foreach (var handle in _handles) { handle?.Dispose(); diff --git a/src/Ryujinx.Memory/Tracking/VirtualRegion.cs b/src/Ryujinx.Memory/Tracking/VirtualRegion.cs index 9651426b3..e595196c7 100644 --- a/src/Ryujinx.Memory/Tracking/VirtualRegion.cs +++ b/src/Ryujinx.Memory/Tracking/VirtualRegion.cs @@ -8,7 +8,7 @@ namespace Ryujinx.Memory.Tracking /// class VirtualRegion : AbstractRegion { - public List Handles = new List(); + public List Handles = new(); private readonly MemoryTracking _tracking; private MemoryPermission _lastPermission; @@ -86,7 +86,10 @@ namespace Ryujinx.Memory.Tracking foreach (var handle in Handles) { result &= handle.RequiredPermission; - if (result == 0) return result; + if (result == 0) + { + return result; + } } return result; } @@ -128,7 +131,7 @@ namespace Ryujinx.Memory.Tracking public override INonOverlappingRange Split(ulong splitAddress) { - VirtualRegion newRegion = new VirtualRegion(_tracking, splitAddress, EndAddress - splitAddress, _lastPermission); + VirtualRegion newRegion = new(_tracking, splitAddress, EndAddress - splitAddress, _lastPermission); Size = splitAddress - Address; // The new region inherits all of our parents. diff --git a/src/Ryujinx.Memory/WindowsShared/MappingTree.cs b/src/Ryujinx.Memory/WindowsShared/MappingTree.cs index 97758c2b1..9ca84b56b 100644 --- a/src/Ryujinx.Memory/WindowsShared/MappingTree.cs +++ b/src/Ryujinx.Memory/WindowsShared/MappingTree.cs @@ -84,4 +84,4 @@ namespace Ryujinx.Memory.WindowsShared } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs b/src/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs index 3022b6616..b68a076c4 100644 --- a/src/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs +++ b/src/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs @@ -31,9 +31,11 @@ namespace Ryujinx.Memory.WindowsShared _partialUnmapStatePtr = PartialUnmapState.GlobalState; - _partialUnmapTrimThread = new Thread(TrimThreadLocalMapLoop); - _partialUnmapTrimThread.Name = "CPU.PartialUnmapTrimThread"; - _partialUnmapTrimThread.IsBackground = true; + _partialUnmapTrimThread = new Thread(TrimThreadLocalMapLoop) + { + Name = "CPU.PartialUnmapTrimThread", + IsBackground = true, + }; _partialUnmapTrimThread.Start(); } @@ -704,8 +706,6 @@ namespace Ryujinx.Memory.WindowsShared count = _protections.GetNodes(address, endAddress, ref overlaps); } - ulong startAddress = address; - for (int index = 0; index < count; index++) { var protection = overlaps[index]; @@ -733,4 +733,4 @@ namespace Ryujinx.Memory.WindowsShared } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs b/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs index c554e3205..82903c05f 100644 --- a/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs +++ b/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs @@ -7,8 +7,8 @@ namespace Ryujinx.Memory.WindowsShared [SupportedOSPlatform("windows")] static partial class WindowsApi { - public static readonly IntPtr InvalidHandleValue = new IntPtr(-1); - public static readonly IntPtr CurrentProcessHandle = new IntPtr(-1); + public static readonly IntPtr InvalidHandleValue = new(-1); + public static readonly IntPtr CurrentProcessHandle = new(-1); [LibraryImport("kernel32.dll", SetLastError = true)] public static partial IntPtr VirtualAlloc( @@ -96,8 +96,8 @@ namespace Ryujinx.Memory.WindowsShared MemoryPermission.ReadAndExecute => MemoryProtection.ExecuteRead, MemoryPermission.ReadWriteExecute => MemoryProtection.ExecuteReadWrite, MemoryPermission.Execute => MemoryProtection.Execute, - _ => throw new MemoryProtectionException(permission) + _ => throw new MemoryProtectionException(permission), }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/WindowsShared/WindowsApiException.cs b/src/Ryujinx.Memory/WindowsShared/WindowsApiException.cs index 330c1842a..308006aba 100644 --- a/src/Ryujinx.Memory/WindowsShared/WindowsApiException.cs +++ b/src/Ryujinx.Memory/WindowsShared/WindowsApiException.cs @@ -23,4 +23,4 @@ namespace Ryujinx.Memory.WindowsShared return $"{functionName} returned error code 0x{WindowsApi.GetLastError():X}."; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/WindowsShared/WindowsFlags.cs b/src/Ryujinx.Memory/WindowsShared/WindowsFlags.cs index ca69cfe93..7dd4215ee 100644 --- a/src/Ryujinx.Memory/WindowsShared/WindowsFlags.cs +++ b/src/Ryujinx.Memory/WindowsShared/WindowsFlags.cs @@ -10,14 +10,14 @@ namespace Ryujinx.Memory.WindowsShared Commit = 0x1000, Reserve = 0x2000, Decommit = 0x4000, - ReplacePlaceholder = 0x4000, + ReplacePlaceholder = Decommit, Release = 0x8000, ReservePlaceholder = 0x40000, Reset = 0x80000, Physical = 0x400000, TopDown = 0x100000, WriteWatch = 0x200000, - LargePages = 0x20000000 + LargePages = 0x20000000, } [Flags] @@ -33,7 +33,7 @@ namespace Ryujinx.Memory.WindowsShared ExecuteWriteCopy = 0x80, GuardModifierflag = 0x100, NoCacheModifierflag = 0x200, - WriteCombineModifierflag = 0x400 + WriteCombineModifierflag = 0x400, } [Flags] @@ -47,6 +47,6 @@ namespace Ryujinx.Memory.WindowsShared SectionCommit = 0x8000000, SectionImage = 0x1000000, SectionNoCache = 0x10000000, - SectionReserve = 0x4000000 + SectionReserve = 0x4000000, } }