diff options
| author | riperiperi <rhy3756547@hotmail.com> | 2022-07-30 00:16:29 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-29 19:16:29 -0300 |
| commit | 14ce9e15672d03cb6fc067316f90d81471398ebc (patch) | |
| tree | 39befb3c65a2548fe803bf746545de3fd8851ffd /Ryujinx.Memory/WindowsShared/PlaceholderManager4KB.cs | |
| parent | 952d013c67a1809fae3b3c7ade9a0757598d9e18 (diff) | |
Move partial unmap handler to the native signal handler (#3437)
* 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/WindowsShared/PlaceholderManager4KB.cs')
| -rw-r--r-- | Ryujinx.Memory/WindowsShared/PlaceholderManager4KB.cs | 170 |
1 files changed, 0 insertions, 170 deletions
diff --git a/Ryujinx.Memory/WindowsShared/PlaceholderManager4KB.cs b/Ryujinx.Memory/WindowsShared/PlaceholderManager4KB.cs deleted file mode 100644 index fc056a2f..00000000 --- a/Ryujinx.Memory/WindowsShared/PlaceholderManager4KB.cs +++ /dev/null @@ -1,170 +0,0 @@ -using System; -using System.Runtime.Versioning; - -namespace Ryujinx.Memory.WindowsShared -{ - /// <summary> - /// Windows 4KB memory placeholder manager. - /// </summary> - [SupportedOSPlatform("windows")] - class PlaceholderManager4KB - { - private const int PageSize = MemoryManagementWindows.PageSize; - - private readonly IntervalTree<ulong, byte> _mappings; - - /// <summary> - /// Creates a new instance of the Windows 4KB memory placeholder manager. - /// </summary> - public PlaceholderManager4KB() - { - _mappings = new IntervalTree<ulong, byte>(); - } - - /// <summary> - /// Unmaps the specified range of memory and marks it as mapped internally. - /// </summary> - /// <remarks> - /// Since this marks the range as mapped, the expectation is that the range will be mapped after calling this method. - /// </remarks> - /// <param name="location">Memory address to unmap and mark as mapped</param> - /// <param name="size">Size of the range in bytes</param> - public void UnmapAndMarkRangeAsMapped(IntPtr location, IntPtr size) - { - ulong startAddress = (ulong)location; - ulong unmapSize = (ulong)size; - ulong endAddress = startAddress + unmapSize; - - var overlaps = Array.Empty<IntervalTreeNode<ulong, byte>>(); - int count = 0; - - lock (_mappings) - { - count = _mappings.Get(startAddress, endAddress, ref overlaps); - } - - for (int index = 0; index < count; index++) - { - var overlap = overlaps[index]; - - // Tree operations might modify the node start/end values, so save a copy before we modify the tree. - ulong overlapStart = overlap.Start; - ulong overlapEnd = overlap.End; - ulong overlapValue = overlap.Value; - - _mappings.Remove(overlap); - - ulong unmapStart = Math.Max(overlapStart, startAddress); - ulong unmapEnd = Math.Min(overlapEnd, endAddress); - - if (overlapStart < startAddress) - { - startAddress = overlapStart; - } - - if (overlapEnd > endAddress) - { - endAddress = overlapEnd; - } - - ulong currentAddress = unmapStart; - while (currentAddress < unmapEnd) - { - WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (IntPtr)currentAddress, 2); - currentAddress += PageSize; - } - } - - _mappings.Add(startAddress, endAddress, 0); - } - - /// <summary> - /// Unmaps views at the specified memory range. - /// </summary> - /// <param name="location">Address of the range</param> - /// <param name="size">Size of the range in bytes</param> - public void UnmapView(IntPtr location, IntPtr size) - { - ulong startAddress = (ulong)location; - ulong unmapSize = (ulong)size; - ulong endAddress = startAddress + unmapSize; - - var overlaps = Array.Empty<IntervalTreeNode<ulong, byte>>(); - int count = 0; - - lock (_mappings) - { - count = _mappings.Get(startAddress, endAddress, ref overlaps); - } - - for (int index = 0; index < count; index++) - { - var overlap = overlaps[index]; - - // Tree operations might modify the node start/end values, so save a copy before we modify the tree. - ulong overlapStart = overlap.Start; - ulong overlapEnd = overlap.End; - - _mappings.Remove(overlap); - - if (overlapStart < startAddress) - { - _mappings.Add(overlapStart, startAddress, 0); - } - - if (overlapEnd > endAddress) - { - _mappings.Add(endAddress, overlapEnd, 0); - } - - ulong unmapStart = Math.Max(overlapStart, startAddress); - ulong unmapEnd = Math.Min(overlapEnd, endAddress); - - ulong currentAddress = unmapStart; - while (currentAddress < unmapEnd) - { - WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (IntPtr)currentAddress, 2); - currentAddress += PageSize; - } - } - } - - /// <summary> - /// Unmaps mapped memory at a given range. - /// </summary> - /// <param name="location">Address of the range</param> - /// <param name="size">Size of the range in bytes</param> - public void UnmapRange(IntPtr location, IntPtr size) - { - ulong startAddress = (ulong)location; - ulong unmapSize = (ulong)size; - ulong endAddress = startAddress + unmapSize; - - var overlaps = Array.Empty<IntervalTreeNode<ulong, byte>>(); - int count = 0; - - lock (_mappings) - { - count = _mappings.Get(startAddress, endAddress, ref overlaps); - } - - for (int index = 0; index < count; index++) - { - var overlap = overlaps[index]; - - // Tree operations might modify the node start/end values, so save a copy before we modify the tree. - ulong unmapStart = Math.Max(overlap.Start, startAddress); - ulong unmapEnd = Math.Min(overlap.End, endAddress); - - _mappings.Remove(overlap); - - ulong currentAddress = unmapStart; - while (currentAddress < unmapEnd) - { - WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (IntPtr)currentAddress, 2); - currentAddress += PageSize; - } - } - } - } -}
\ No newline at end of file |
