aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2022-09-14 12:46:37 -0300
committerGitHub <noreply@github.com>2022-09-14 17:46:37 +0200
commit356e480bf55d9a1497fcf54e9395d9b8ab72b815 (patch)
tree8762f0305dfbe613bf1850468fa13560273e0b31
parent8e119a1e9694416289c4c4c7ed38c408c096f9a2 (diff)
Fix partial unmap reprotection on Windows (#3702)
-rw-r--r--Ryujinx.Memory/WindowsShared/PlaceholderManager.cs18
1 files changed, 11 insertions, 7 deletions
diff --git a/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs b/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs
index a17fea5e..3022b661 100644
--- a/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs
+++ b/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs
@@ -73,7 +73,7 @@ namespace Ryujinx.Memory.WindowsShared
lock (_protections)
{
- _protections.Add(new RangeNode<MemoryPermission>(address, size, MemoryPermission.None));
+ _protections.Add(new RangeNode<MemoryPermission>(address, address + size, MemoryPermission.None));
}
}
@@ -132,7 +132,7 @@ namespace Ryujinx.Memory.WindowsShared
try
{
UnmapViewInternal(sharedMemory, location, size, owner, updateProtection: false);
- MapViewInternal(sharedMemory, srcOffset, location, size);
+ MapViewInternal(sharedMemory, srcOffset, location, size, updateProtection: true);
}
finally
{
@@ -147,8 +147,9 @@ namespace Ryujinx.Memory.WindowsShared
/// <param name="srcOffset">Offset in the shared memory to map</param>
/// <param name="location">Address to map the view into</param>
/// <param name="size">Size of the view in bytes</param>
+ /// <param name="updateProtection">Indicates if the memory protections should be updated after the map</param>
/// <exception cref="WindowsApiException">Thrown when the Windows API returns an error mapping the memory</exception>
- private void MapViewInternal(IntPtr sharedMemory, ulong srcOffset, IntPtr location, IntPtr size)
+ private void MapViewInternal(IntPtr sharedMemory, ulong srcOffset, IntPtr location, IntPtr size, bool updateProtection)
{
SplitForMap((ulong)location, (ulong)size, srcOffset);
@@ -168,7 +169,10 @@ namespace Ryujinx.Memory.WindowsShared
throw new WindowsApiException("MapViewOfFile3");
}
- UpdateProtection((ulong)location, (ulong)size, MemoryPermission.ReadAndWrite);
+ if (updateProtection)
+ {
+ UpdateProtection((ulong)location, (ulong)size, MemoryPermission.ReadAndWrite);
+ }
}
/// <summary>
@@ -330,7 +334,7 @@ namespace Ryujinx.Memory.WindowsShared
{
ulong remapSize = startAddress - overlap.Start;
- MapViewInternal(sharedMemory, overlap.Value, (IntPtr)overlap.Start, (IntPtr)remapSize);
+ MapViewInternal(sharedMemory, overlap.Value, (IntPtr)overlap.Start, (IntPtr)remapSize, updateProtection: false);
RestoreRangeProtection(overlap.Start, remapSize);
}
@@ -341,7 +345,7 @@ namespace Ryujinx.Memory.WindowsShared
ulong remapAddress = overlap.Start + overlappedSize;
ulong remapSize = overlap.End - endAddress;
- MapViewInternal(sharedMemory, remapBackingOffset, (IntPtr)remapAddress, (IntPtr)remapSize);
+ MapViewInternal(sharedMemory, remapBackingOffset, (IntPtr)remapAddress, (IntPtr)remapSize, updateProtection: false);
RestoreRangeProtection(remapAddress, remapSize);
}
}
@@ -606,7 +610,7 @@ namespace Ryujinx.Memory.WindowsShared
_protections.Remove(protection);
- if (protection.Value == permission)
+ if (protPermission == permission)
{
if (startAddress > protAddress)
{