aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure/Memory/MemoryManagementUnix.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ARMeilleure/Memory/MemoryManagementUnix.cs')
-rw-r--r--ARMeilleure/Memory/MemoryManagementUnix.cs23
1 files changed, 23 insertions, 0 deletions
diff --git a/ARMeilleure/Memory/MemoryManagementUnix.cs b/ARMeilleure/Memory/MemoryManagementUnix.cs
index 3331fb42..e9b29608 100644
--- a/ARMeilleure/Memory/MemoryManagementUnix.cs
+++ b/ARMeilleure/Memory/MemoryManagementUnix.cs
@@ -30,6 +30,11 @@ namespace ARMeilleure.Memory
return ptr;
}
+ public static bool Commit(IntPtr address, ulong size)
+ {
+ return Syscall.mprotect(address, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE) == 0;
+ }
+
public static bool Reprotect(IntPtr address, ulong size, Memory.MemoryProtection protection)
{
MmapProts prot = GetProtection(protection);
@@ -37,6 +42,24 @@ namespace ARMeilleure.Memory
return Syscall.mprotect(address, size, prot) == 0;
}
+ public static IntPtr Reserve(ulong size)
+ {
+ ulong pageSize = (ulong)Syscall.sysconf(SysconfName._SC_PAGESIZE);
+
+ const MmapProts prot = MmapProts.PROT_NONE;
+
+ const MmapFlags flags = MmapFlags.MAP_PRIVATE | MmapFlags.MAP_ANONYMOUS;
+
+ IntPtr ptr = Syscall.mmap(IntPtr.Zero, size + pageSize, prot, flags, -1, 0);
+
+ if (ptr == IntPtr.Zero)
+ {
+ throw new OutOfMemoryException();
+ }
+
+ return ptr;
+ }
+
private static MmapProts GetProtection(Memory.MemoryProtection protection)
{
switch (protection)