aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Memory/Tracking/MemoryTracking.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/Tracking/MemoryTracking.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/Tracking/MemoryTracking.cs')
-rw-r--r--Ryujinx.Memory/Tracking/MemoryTracking.cs30
1 files changed, 4 insertions, 26 deletions
diff --git a/Ryujinx.Memory/Tracking/MemoryTracking.cs b/Ryujinx.Memory/Tracking/MemoryTracking.cs
index c5abb576..ec75e3d0 100644
--- a/Ryujinx.Memory/Tracking/MemoryTracking.cs
+++ b/Ryujinx.Memory/Tracking/MemoryTracking.cs
@@ -190,30 +190,6 @@ namespace Ryujinx.Memory.Tracking
/// <summary>
/// Signal that a virtual memory event happened at the given location.
- /// This is similar VirtualMemoryEvent, but on Windows, it might also return true after a partial unmap.
- /// This should only be called from the exception handler.
- /// </summary>
- /// <param name="address">Virtual address accessed</param>
- /// <param name="size">Size of the region affected in bytes</param>
- /// <param name="write">Whether the region was written to or read</param>
- /// <param name="precise">True if the access is precise, false otherwise</param>
- /// <returns>True if the event triggered any tracking regions, false otherwise</returns>
- public bool VirtualMemoryEventEh(ulong address, ulong size, bool write, bool precise = false)
- {
- // Windows has a limitation, it can't do partial unmaps.
- // For this reason, we need to unmap the whole range and then remap the sub-ranges.
- // When this happens, we might have caused a undesirable access violation from the time that the range was unmapped.
- // In this case, try again as the memory might be mapped now.
- if (OperatingSystem.IsWindows() && MemoryManagementWindows.RetryFromAccessViolation())
- {
- return true;
- }
-
- return VirtualMemoryEvent(address, size, write, precise);
- }
-
- /// <summary>
- /// Signal that a virtual memory event happened at the given location.
/// This can be flagged as a precise event, which will avoid reprotection and call special handlers if possible.
/// A precise event has an exact address and size, rather than triggering on page granularity.
/// </summary>
@@ -237,10 +213,12 @@ namespace Ryujinx.Memory.Tracking
if (count == 0 && !precise)
{
- if (_memoryManager.IsMapped(address))
+ if (_memoryManager.IsRangeMapped(address, size))
{
+ // TODO: There is currently the possibility that a page can be protected after its virtual region is removed.
+ // This code handles that case when it happens, but it would be better to find out how this happens.
_memoryManager.TrackingReprotect(address & ~(ulong)(_pageSize - 1), (ulong)_pageSize, MemoryPermission.ReadAndWrite);
- return false; // We can't handle this - it's probably a real invalid access.
+ return true; // This memory _should_ be mapped, so we need to try again.
}
else
{