aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Ryujinx.Memory.Tests/Tests.cs26
-rw-r--r--Ryujinx.Memory/MemoryManagementUnix.cs2
2 files changed, 27 insertions, 1 deletions
diff --git a/Ryujinx.Memory.Tests/Tests.cs b/Ryujinx.Memory.Tests/Tests.cs
index 45d00e51..c5a7842e 100644
--- a/Ryujinx.Memory.Tests/Tests.cs
+++ b/Ryujinx.Memory.Tests/Tests.cs
@@ -92,5 +92,31 @@ namespace Ryujinx.Memory.Tests
}
}
}
+
+ [Test]
+ public void Test_AliasMapLeak()
+ {
+ if (OperatingSystem.IsMacOS())
+ {
+ // Memory aliasing tests fail on CI at the moment.
+ return;
+ }
+
+ ulong pageSize = 4096;
+ ulong size = 100000 * pageSize; // The mappings limit on Linux is usually around 65K, so let's make sure we are above that.
+
+ using MemoryBlock backing = new MemoryBlock(pageSize, MemoryAllocationFlags.Mirrorable);
+ using MemoryBlock toAlias = new MemoryBlock(size, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible);
+
+ for (ulong offset = 0; offset < size; offset += pageSize)
+ {
+ toAlias.MapView(backing, 0, offset, pageSize);
+
+ toAlias.Write(offset, 0xbadc0de);
+ Assert.AreEqual(0xbadc0de, backing.Read<int>(0));
+
+ toAlias.UnmapView(backing, offset, pageSize);
+ }
+ }
}
} \ No newline at end of file
diff --git a/Ryujinx.Memory/MemoryManagementUnix.cs b/Ryujinx.Memory/MemoryManagementUnix.cs
index db7539f0..df3fcea9 100644
--- a/Ryujinx.Memory/MemoryManagementUnix.cs
+++ b/Ryujinx.Memory/MemoryManagementUnix.cs
@@ -177,7 +177,7 @@ namespace Ryujinx.Memory
public static void UnmapView(IntPtr location, ulong size)
{
- mmap(location, size, MmapProts.PROT_NONE, MmapFlags.MAP_FIXED, -1, 0);
+ mmap(location, size, MmapProts.PROT_NONE, MmapFlags.MAP_FIXED | MmapFlags.MAP_PRIVATE | MmapFlags.MAP_ANONYMOUS | MmapFlags.MAP_NORESERVE, -1, 0);
}
}
} \ No newline at end of file