aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Memory/MemoryManagementWindows.cs
diff options
context:
space:
mode:
authorriperiperi <rhy3756547@hotmail.com>2022-07-30 00:16:29 +0200
committerGitHub <noreply@github.com>2022-07-29 19:16:29 -0300
commit14ce9e15672d03cb6fc067316f90d81471398ebc (patch)
tree39befb3c65a2548fe803bf746545de3fd8851ffd /Ryujinx.Memory/MemoryManagementWindows.cs
parent952d013c67a1809fae3b3c7ade9a0757598d9e18 (diff)
Move partial unmap handler to the native signal handler (#3437)1.1.199
* Initial commit with a lot of testing stuff. * Partial Unmap Cleanup Part 1 * Fix some minor issues, hopefully windows tests. * Disable partial unmap tests on macos for now Weird issue. * Goodbye magic number * Add COMPlus_EnableAlternateStackCheck for tests `COMPlus_EnableAlternateStackCheck` is needed for NullReferenceException handling to work on linux after registering the signal handler, due to how dotnet registers its own signal handler. * Address some feedback * Force retry when memory is mapped in memory tracking This case existed before, but returning `false` no longer retries, so it would crash immediately after unprotecting the memory... Now, we return `true` to deliberately retry. This case existed before (was just broken by this change) and I don't really want to look into fixing the issue right now. Technically, this means that on guest code partial unmaps will retry _due to this_ rather than hitting the handler. I don't expect this to cause any issues. This should fix random crashes in Xenoblade Chronicles 2. * Use IsRangeMapped * Suppress MockMemoryManager.UnmapEvent warning This event is not signalled by the mock memory manager. * Remove 4kb mapping
Diffstat (limited to 'Ryujinx.Memory/MemoryManagementWindows.cs')
-rw-r--r--Ryujinx.Memory/MemoryManagementWindows.cs80
1 files changed, 4 insertions, 76 deletions
diff --git a/Ryujinx.Memory/MemoryManagementWindows.cs b/Ryujinx.Memory/MemoryManagementWindows.cs
index 6b4e7fbe..2f89a921 100644
--- a/Ryujinx.Memory/MemoryManagementWindows.cs
+++ b/Ryujinx.Memory/MemoryManagementWindows.cs
@@ -10,23 +10,19 @@ namespace Ryujinx.Memory
public const int PageSize = 0x1000;
private static readonly PlaceholderManager _placeholders = new PlaceholderManager();
- private static readonly PlaceholderManager4KB _placeholders4KB = new PlaceholderManager4KB();
public static IntPtr Allocate(IntPtr size)
{
return AllocateInternal(size, AllocationType.Reserve | AllocationType.Commit);
}
- public static IntPtr Reserve(IntPtr size, bool viewCompatible, bool force4KBMap)
+ public static IntPtr Reserve(IntPtr size, bool viewCompatible)
{
if (viewCompatible)
{
IntPtr baseAddress = AllocateInternal2(size, AllocationType.Reserve | AllocationType.ReservePlaceholder);
- if (!force4KBMap)
- {
- _placeholders.ReserveRange((ulong)baseAddress, (ulong)size);
- }
+ _placeholders.ReserveRange((ulong)baseAddress, (ulong)size);
return baseAddress;
}
@@ -73,49 +69,11 @@ namespace Ryujinx.Memory
_placeholders.MapView(sharedMemory, srcOffset, location, size, owner);
}
- public static void MapView4KB(IntPtr sharedMemory, ulong srcOffset, IntPtr location, IntPtr size)
- {
- _placeholders4KB.UnmapAndMarkRangeAsMapped(location, size);
-
- ulong uaddress = (ulong)location;
- ulong usize = (ulong)size;
- IntPtr endLocation = (IntPtr)(uaddress + usize);
-
- while (location != endLocation)
- {
- WindowsApi.VirtualFree(location, (IntPtr)PageSize, AllocationType.Release | AllocationType.PreservePlaceholder);
-
- var ptr = WindowsApi.MapViewOfFile3(
- sharedMemory,
- WindowsApi.CurrentProcessHandle,
- location,
- srcOffset,
- (IntPtr)PageSize,
- 0x4000,
- MemoryProtection.ReadWrite,
- IntPtr.Zero,
- 0);
-
- if (ptr == IntPtr.Zero)
- {
- throw new WindowsApiException("MapViewOfFile3");
- }
-
- location += PageSize;
- srcOffset += PageSize;
- }
- }
-
public static void UnmapView(IntPtr sharedMemory, IntPtr location, IntPtr size, MemoryBlock owner)
{
_placeholders.UnmapView(sharedMemory, location, size, owner);
}
- public static void UnmapView4KB(IntPtr location, IntPtr size)
- {
- _placeholders4KB.UnmapView(location, size);
- }
-
public static bool Reprotect(IntPtr address, IntPtr size, MemoryPermission permission, bool forView)
{
if (forView)
@@ -128,34 +86,9 @@ namespace Ryujinx.Memory
}
}
- public static bool Reprotect4KB(IntPtr address, IntPtr size, MemoryPermission permission, bool forView)
+ public static bool Free(IntPtr address, IntPtr size)
{
- ulong uaddress = (ulong)address;
- ulong usize = (ulong)size;
- while (usize > 0)
- {
- if (!WindowsApi.VirtualProtect((IntPtr)uaddress, (IntPtr)PageSize, WindowsApi.GetProtection(permission), out _))
- {
- return false;
- }
-
- uaddress += PageSize;
- usize -= PageSize;
- }
-
- return true;
- }
-
- public static bool Free(IntPtr address, IntPtr size, bool force4KBMap)
- {
- if (force4KBMap)
- {
- _placeholders4KB.UnmapRange(address, size);
- }
- else
- {
- _placeholders.UnreserveRange((ulong)address, (ulong)size);
- }
+ _placeholders.UnreserveRange((ulong)address, (ulong)size);
return WindowsApi.VirtualFree(address, IntPtr.Zero, AllocationType.Release);
}
@@ -207,10 +140,5 @@ namespace Ryujinx.Memory
throw new ArgumentException("Invalid address.", nameof(address));
}
}
-
- public static bool RetryFromAccessViolation()
- {
- return _placeholders.RetryFromAccessViolation();
- }
}
} \ No newline at end of file