forked from MeloNX/MeloNX
memory: Add Android support
This commit is contained in:
parent
c27a12df2c
commit
0b14eb3a61
@ -426,7 +426,7 @@ namespace Ryujinx.Memory
|
|||||||
return OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17134);
|
return OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17134);
|
||||||
}
|
}
|
||||||
|
|
||||||
return OperatingSystem.IsLinux() || OperatingSystem.IsMacOS();
|
return OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsAndroid();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -10,7 +10,7 @@ namespace Ryujinx.Memory
|
|||||||
{
|
{
|
||||||
return MemoryManagementWindows.Allocate((IntPtr)size);
|
return MemoryManagementWindows.Allocate((IntPtr)size);
|
||||||
}
|
}
|
||||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
return MemoryManagementUnix.Allocate(size, forJit);
|
return MemoryManagementUnix.Allocate(size, forJit);
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ namespace Ryujinx.Memory
|
|||||||
{
|
{
|
||||||
return MemoryManagementWindows.Reserve((IntPtr)size, viewCompatible);
|
return MemoryManagementWindows.Reserve((IntPtr)size, viewCompatible);
|
||||||
}
|
}
|
||||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
return MemoryManagementUnix.Reserve(size, forJit);
|
return MemoryManagementUnix.Reserve(size, forJit);
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ namespace Ryujinx.Memory
|
|||||||
{
|
{
|
||||||
MemoryManagementWindows.Commit(address, (IntPtr)size);
|
MemoryManagementWindows.Commit(address, (IntPtr)size);
|
||||||
}
|
}
|
||||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
MemoryManagementUnix.Commit(address, size, forJit);
|
MemoryManagementUnix.Commit(address, size, forJit);
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ namespace Ryujinx.Memory
|
|||||||
{
|
{
|
||||||
MemoryManagementWindows.Decommit(address, (IntPtr)size);
|
MemoryManagementWindows.Decommit(address, (IntPtr)size);
|
||||||
}
|
}
|
||||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
MemoryManagementUnix.Decommit(address, size);
|
MemoryManagementUnix.Decommit(address, size);
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ namespace Ryujinx.Memory
|
|||||||
{
|
{
|
||||||
MemoryManagementWindows.MapView(sharedMemory, srcOffset, address, (IntPtr)size, owner);
|
MemoryManagementWindows.MapView(sharedMemory, srcOffset, address, (IntPtr)size, owner);
|
||||||
}
|
}
|
||||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
MemoryManagementUnix.MapView(sharedMemory, srcOffset, address, size);
|
MemoryManagementUnix.MapView(sharedMemory, srcOffset, address, size);
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ namespace Ryujinx.Memory
|
|||||||
{
|
{
|
||||||
MemoryManagementWindows.UnmapView(sharedMemory, address, (IntPtr)size, owner);
|
MemoryManagementWindows.UnmapView(sharedMemory, address, (IntPtr)size, owner);
|
||||||
}
|
}
|
||||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
MemoryManagementUnix.UnmapView(address, size);
|
MemoryManagementUnix.UnmapView(address, size);
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ namespace Ryujinx.Memory
|
|||||||
{
|
{
|
||||||
result = MemoryManagementWindows.Reprotect(address, (IntPtr)size, permission, forView);
|
result = MemoryManagementWindows.Reprotect(address, (IntPtr)size, permission, forView);
|
||||||
}
|
}
|
||||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
result = MemoryManagementUnix.Reprotect(address, size, permission);
|
result = MemoryManagementUnix.Reprotect(address, size, permission);
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ namespace Ryujinx.Memory
|
|||||||
{
|
{
|
||||||
return MemoryManagementWindows.Free(address, (IntPtr)size);
|
return MemoryManagementWindows.Free(address, (IntPtr)size);
|
||||||
}
|
}
|
||||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
return MemoryManagementUnix.Free(address);
|
return MemoryManagementUnix.Free(address);
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ namespace Ryujinx.Memory
|
|||||||
{
|
{
|
||||||
return MemoryManagementWindows.CreateSharedMemory((IntPtr)size, reserve);
|
return MemoryManagementWindows.CreateSharedMemory((IntPtr)size, reserve);
|
||||||
}
|
}
|
||||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
return MemoryManagementUnix.CreateSharedMemory(size, reserve);
|
return MemoryManagementUnix.CreateSharedMemory(size, reserve);
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ namespace Ryujinx.Memory
|
|||||||
{
|
{
|
||||||
MemoryManagementWindows.DestroySharedMemory(handle);
|
MemoryManagementWindows.DestroySharedMemory(handle);
|
||||||
}
|
}
|
||||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
MemoryManagementUnix.DestroySharedMemory(handle);
|
MemoryManagementUnix.DestroySharedMemory(handle);
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ namespace Ryujinx.Memory
|
|||||||
{
|
{
|
||||||
return MemoryManagementWindows.MapSharedMemory(handle);
|
return MemoryManagementWindows.MapSharedMemory(handle);
|
||||||
}
|
}
|
||||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
return MemoryManagementUnix.MapSharedMemory(handle, size);
|
return MemoryManagementUnix.MapSharedMemory(handle, size);
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ namespace Ryujinx.Memory
|
|||||||
{
|
{
|
||||||
MemoryManagementWindows.UnmapSharedMemory(address);
|
MemoryManagementWindows.UnmapSharedMemory(address);
|
||||||
}
|
}
|
||||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
MemoryManagementUnix.UnmapSharedMemory(address, size);
|
MemoryManagementUnix.UnmapSharedMemory(address, size);
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ namespace Ryujinx.Memory
|
|||||||
{
|
{
|
||||||
[SupportedOSPlatform("linux")]
|
[SupportedOSPlatform("linux")]
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
|
[SupportedOSPlatform("android")]
|
||||||
static class MemoryManagementUnix
|
static class MemoryManagementUnix
|
||||||
{
|
{
|
||||||
private static readonly ConcurrentDictionary<IntPtr, ulong> _allocations = new();
|
private static readonly ConcurrentDictionary<IntPtr, ulong> _allocations = new();
|
||||||
@ -156,6 +157,22 @@ namespace Ryujinx.Memory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (OperatingSystem.IsAndroid())
|
||||||
|
{
|
||||||
|
byte[] memName = Encoding.ASCII.GetBytes("Ryujinx-XXXXXX");
|
||||||
|
|
||||||
|
fixed (byte* pMemName = memName)
|
||||||
|
{
|
||||||
|
fd = ASharedMemory_create((IntPtr)pMemName, (nuint)size);
|
||||||
|
if (fd <= 0)
|
||||||
|
{
|
||||||
|
throw new OutOfMemoryException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ASharedMemory_create handle ftruncate for us.
|
||||||
|
return (IntPtr)fd;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
byte[] fileName = "/dev/shm/Ryujinx-XXXXXX"u8.ToArray();
|
byte[] fileName = "/dev/shm/Ryujinx-XXXXXX"u8.ToArray();
|
||||||
|
@ -89,6 +89,9 @@ namespace Ryujinx.Memory
|
|||||||
[LibraryImport("libc", SetLastError = true)]
|
[LibraryImport("libc", SetLastError = true)]
|
||||||
public static partial int shm_unlink(IntPtr name);
|
public static partial int shm_unlink(IntPtr name);
|
||||||
|
|
||||||
|
[DllImport("android")]
|
||||||
|
internal static extern int ASharedMemory_create(IntPtr name, nuint size);
|
||||||
|
|
||||||
private static int MmapFlagsToSystemFlags(MmapFlags flags)
|
private static int MmapFlagsToSystemFlags(MmapFlags flags)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
@ -110,7 +113,7 @@ namespace Ryujinx.Memory
|
|||||||
|
|
||||||
if (flags.HasFlag(MmapFlags.MAP_ANONYMOUS))
|
if (flags.HasFlag(MmapFlags.MAP_ANONYMOUS))
|
||||||
{
|
{
|
||||||
if (OperatingSystem.IsLinux())
|
if (OperatingSystem.IsLinux() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
result |= MAP_ANONYMOUS_LINUX_GENERIC;
|
result |= MAP_ANONYMOUS_LINUX_GENERIC;
|
||||||
}
|
}
|
||||||
@ -126,7 +129,7 @@ namespace Ryujinx.Memory
|
|||||||
|
|
||||||
if (flags.HasFlag(MmapFlags.MAP_NORESERVE))
|
if (flags.HasFlag(MmapFlags.MAP_NORESERVE))
|
||||||
{
|
{
|
||||||
if (OperatingSystem.IsLinux())
|
if (OperatingSystem.IsLinux() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
result |= MAP_NORESERVE_LINUX_GENERIC;
|
result |= MAP_NORESERVE_LINUX_GENERIC;
|
||||||
}
|
}
|
||||||
@ -142,7 +145,7 @@ namespace Ryujinx.Memory
|
|||||||
|
|
||||||
if (flags.HasFlag(MmapFlags.MAP_UNLOCKED))
|
if (flags.HasFlag(MmapFlags.MAP_UNLOCKED))
|
||||||
{
|
{
|
||||||
if (OperatingSystem.IsLinux())
|
if (OperatingSystem.IsLinux() || OperatingSystem.IsAndroid())
|
||||||
{
|
{
|
||||||
result |= MAP_UNLOCKED_LINUX_GENERIC;
|
result |= MAP_UNLOCKED_LINUX_GENERIC;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user