aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgdk <gab.dark.100@gmail.com>2022-06-23 13:59:43 -0300
committerMary-nyan <thog@protonmail.com>2022-09-10 16:23:49 +0200
commit93dd6d525a8c4072ba704e0bb126a980ef4b479a (patch)
treebe682dadac86bb86d8c680cd3cf816bf41330212
parent96d4ad952c60e99c1d814ad7680106a5eabcb0d8 (diff)
Fix potential issue with partial unmap
We must also do the unmap operation with the RWLock, otherwise faults on the unmapped region will cause crashes and the whole thing becomes pointless
-rw-r--r--Ryujinx.Memory/WindowsShared/PlaceholderManager.cs28
1 files changed, 12 insertions, 16 deletions
diff --git a/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs b/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs
index f1752229..b08a91e0 100644
--- a/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs
+++ b/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs
@@ -293,18 +293,14 @@ namespace Ryujinx.Memory.WindowsShared
if (IsMapped(overlap.Value))
{
- ulong overlapStart = overlap.Start;
- ulong overlapEnd = overlap.End;
- ulong overlapValue = overlap.Value;
-
lock (_mappings)
{
_mappings.Remove(overlap);
- _mappings.Add(new RangeNode<ulong>(overlapStart, overlapEnd, ulong.MaxValue));
+ _mappings.Add(new RangeNode<ulong>(overlap.Start, overlap.End, ulong.MaxValue));
}
- bool overlapStartsBefore = overlapStart < startAddress;
- bool overlapEndsAfter = overlapEnd > endAddress;
+ bool overlapStartsBefore = overlap.Start < startAddress;
+ bool overlapEndsAfter = overlap.End > endAddress;
if (overlapStartsBefore || overlapEndsAfter)
{
@@ -321,25 +317,25 @@ namespace Ryujinx.Memory.WindowsShared
{
partialUnmapState.PartialUnmapsCount++;
- if (!WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (IntPtr)overlapStart, 2))
+ if (!WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (IntPtr)overlap.Start, 2))
{
throw new WindowsApiException("UnmapViewOfFile2");
}
if (overlapStartsBefore)
{
- ulong remapSize = startAddress - overlapStart;
+ ulong remapSize = startAddress - overlap.Start;
- MapViewInternal(sharedMemory, overlapValue, (IntPtr)overlapStart, (IntPtr)remapSize);
- RestoreRangeProtection(overlapStart, remapSize);
+ MapViewInternal(sharedMemory, overlap.Value, (IntPtr)overlap.Start, (IntPtr)remapSize);
+ RestoreRangeProtection(overlap.Start, remapSize);
}
if (overlapEndsAfter)
{
- ulong overlappedSize = endAddress - overlapStart;
- ulong remapBackingOffset = overlapValue + overlappedSize;
- ulong remapAddress = overlapStart + overlappedSize;
- ulong remapSize = overlapEnd - endAddress;
+ ulong overlappedSize = endAddress - overlap.Start;
+ ulong remapBackingOffset = overlap.Value + overlappedSize;
+ ulong remapAddress = overlap.Start + overlappedSize;
+ ulong remapSize = overlap.End - endAddress;
MapViewInternal(sharedMemory, remapBackingOffset, (IntPtr)remapAddress, (IntPtr)remapSize);
RestoreRangeProtection(remapAddress, remapSize);
@@ -350,7 +346,7 @@ namespace Ryujinx.Memory.WindowsShared
partialUnmapLock.DowngradeFromWriterLock();
}
}
- else if (!WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (IntPtr)overlapStart, 2))
+ else if (!WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (IntPtr)overlap.Start, 2))
{
throw new WindowsApiException("UnmapViewOfFile2");
}