using System;
namespace Ryujinx.Memory
{
public static class MemoryManagement
public static IntPtr Allocate(ulong size, bool forJit)
if (OperatingSystem.IsWindows())
return MemoryManagementWindows.Allocate((IntPtr)size);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
return MemoryManagementUnix.Allocate(size, forJit);
else
throw new PlatformNotSupportedException();
public static IntPtr Reserve(ulong size, bool forJit, bool viewCompatible)
return MemoryManagementWindows.Reserve((IntPtr)size, viewCompatible);
return MemoryManagementUnix.Reserve(size, forJit);
public static bool Commit(IntPtr address, ulong size, bool forJit)
return MemoryManagementWindows.Commit(address, (IntPtr)size);
return MemoryManagementUnix.Commit(address, size, forJit);
public static bool Decommit(IntPtr address, ulong size)
return MemoryManagementWindows.Decommit(address, (IntPtr)size);
return MemoryManagementUnix.Decommit(address, size);
public static void MapView(IntPtr sharedMemory, ulong srcOffset, IntPtr address, ulong size, MemoryBlock owner)
MemoryManagementWindows.MapView(sharedMemory, srcOffset, address, (IntPtr)size, owner);
MemoryManagementUnix.MapView(sharedMemory, srcOffset, address, size);
public static void UnmapView(IntPtr sharedMemory, IntPtr address, ulong size, MemoryBlock owner)
MemoryManagementWindows.UnmapView(sharedMemory, address, (IntPtr)size, owner);
MemoryManagementUnix.UnmapView(address, size);
public static void Reprotect(IntPtr address, ulong size, MemoryPermission permission, bool forView, bool throwOnFail)
bool result;
result = MemoryManagementWindows.Reprotect(address, (IntPtr)size, permission, forView);
result = MemoryManagementUnix.Reprotect(address, size, permission);
if (!result && throwOnFail)
throw new MemoryProtectionException(permission);
public static bool Free(IntPtr address, ulong size)
return MemoryManagementWindows.Free(address, (IntPtr)size);
return MemoryManagementUnix.Free(address);
public static IntPtr CreateSharedMemory(ulong size, bool reserve)
return MemoryManagementWindows.CreateSharedMemory((IntPtr)size, reserve);
return MemoryManagementUnix.CreateSharedMemory(size, reserve);
public static void DestroySharedMemory(IntPtr handle)
MemoryManagementWindows.DestroySharedMemory(handle);
MemoryManagementUnix.DestroySharedMemory(handle);
public static IntPtr MapSharedMemory(IntPtr handle, ulong size)
return MemoryManagementWindows.MapSharedMemory(handle);
return MemoryManagementUnix.MapSharedMemory(handle, size);
public static void UnmapSharedMemory(IntPtr address, ulong size)
MemoryManagementWindows.UnmapSharedMemory(address);
MemoryManagementUnix.UnmapSharedMemory(address, size);