mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-03-15 06:10:18 +00:00
Linux support
This commit is contained in:
parent
02718079a0
commit
5834b9aab6
3 changed files with 95 additions and 22 deletions
|
@ -12,8 +12,7 @@ namespace Ryujinx.Memory
|
|||
|
||||
return MemoryManagementWindows.Allocate(sizeNint);
|
||||
}
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.Allocate(size);
|
||||
}
|
||||
|
@ -31,8 +30,7 @@ namespace Ryujinx.Memory
|
|||
|
||||
return MemoryManagementWindows.Reserve(sizeNint, viewCompatible);
|
||||
}
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.Reserve(size);
|
||||
}
|
||||
|
@ -50,8 +48,7 @@ namespace Ryujinx.Memory
|
|||
|
||||
return MemoryManagementWindows.Commit(address, sizeNint);
|
||||
}
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.Commit(address, size);
|
||||
}
|
||||
|
@ -69,8 +66,7 @@ namespace Ryujinx.Memory
|
|||
|
||||
return MemoryManagementWindows.Decommit(address, sizeNint);
|
||||
}
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.Decommit(address, size);
|
||||
}
|
||||
|
@ -88,6 +84,10 @@ namespace Ryujinx.Memory
|
|||
|
||||
MemoryManagementWindows.MapView(sharedMemory, srcOffset, address, sizeNint);
|
||||
}
|
||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
MemoryManagementUnix.Remap(address, (IntPtr)((ulong)sharedMemory + srcOffset), size);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PlatformNotSupportedException();
|
||||
|
@ -102,6 +102,10 @@ namespace Ryujinx.Memory
|
|||
|
||||
MemoryManagementWindows.UnmapView(address, sizeNint);
|
||||
}
|
||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
MemoryManagementUnix.Unmap(address, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PlatformNotSupportedException();
|
||||
|
@ -118,8 +122,7 @@ namespace Ryujinx.Memory
|
|||
|
||||
result = MemoryManagementWindows.Reprotect(address, sizeNint, permission, forView);
|
||||
}
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
result = MemoryManagementUnix.Reprotect(address, size, permission);
|
||||
}
|
||||
|
@ -140,8 +143,7 @@ namespace Ryujinx.Memory
|
|||
{
|
||||
return MemoryManagementWindows.Free(address);
|
||||
}
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.Free(address);
|
||||
}
|
||||
|
@ -159,8 +161,7 @@ namespace Ryujinx.Memory
|
|||
|
||||
return MemoryManagementWindows.CreateSharedMemory(sizeNint, reserve);
|
||||
}
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.CreateSharedMemory(size, reserve);
|
||||
}
|
||||
|
@ -176,8 +177,7 @@ namespace Ryujinx.Memory
|
|||
{
|
||||
MemoryManagementWindows.DestroySharedMemory(handle);
|
||||
}
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
MemoryManagementUnix.DestroySharedMemory(handle);
|
||||
}
|
||||
|
@ -193,8 +193,7 @@ namespace Ryujinx.Memory
|
|||
{
|
||||
return MemoryManagementWindows.MapSharedMemory(handle);
|
||||
}
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.MapSharedMemory(handle);
|
||||
}
|
||||
|
@ -210,8 +209,7 @@ namespace Ryujinx.Memory
|
|||
{
|
||||
MemoryManagementWindows.UnmapSharedMemory(address);
|
||||
}
|
||||
else if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
MemoryManagementUnix.UnmapSharedMemory(address);
|
||||
}
|
||||
|
@ -223,8 +221,7 @@ namespace Ryujinx.Memory
|
|||
|
||||
public static IntPtr Remap(IntPtr target, IntPtr source, ulong size)
|
||||
{
|
||||
if (OperatingSystem.IsLinux() ||
|
||||
OperatingSystem.IsMacOS())
|
||||
if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||
{
|
||||
return MemoryManagementUnix.Remap(target, source, size);
|
||||
}
|
||||
|
|
|
@ -136,6 +136,11 @@ namespace Ryujinx.Memory
|
|||
return false;
|
||||
}
|
||||
|
||||
public static bool Unmap(IntPtr address, ulong size)
|
||||
{
|
||||
return munmap(address, size) == 0;
|
||||
}
|
||||
|
||||
public static IntPtr Remap(IntPtr target, IntPtr source, ulong size)
|
||||
{
|
||||
int flags = 1;
|
||||
|
|
71
Ryujinx.Memory/Range/HostMemoryRange.cs
Normal file
71
Ryujinx.Memory/Range/HostMemoryRange.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
using System;
|
||||
|
||||
namespace Ryujinx.Memory.Range
|
||||
{
|
||||
/// <summary>
|
||||
/// Range of memory composed of an address and size.
|
||||
/// </summary>
|
||||
public struct HostMemoryRange : IEquatable<HostMemoryRange>
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty memory range, with a null address and zero size.
|
||||
/// </summary>
|
||||
public static HostMemoryRange Empty => new HostMemoryRange(0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Start address of the range.
|
||||
/// </summary>
|
||||
public nuint Address { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Size of the range in bytes.
|
||||
/// </summary>
|
||||
public ulong Size { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Address where the range ends (exclusive).
|
||||
/// </summary>
|
||||
public nuint EndAddress => Address + (nuint)Size;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new memory range with the specified address and size.
|
||||
/// </summary>
|
||||
/// <param name="address">Start address</param>
|
||||
/// <param name="size">Size in bytes</param>
|
||||
public HostMemoryRange(nuint address, ulong size)
|
||||
{
|
||||
Address = address;
|
||||
Size = size;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the range overlaps with another.
|
||||
/// </summary>
|
||||
/// <param name="other">The other range to check for overlap</param>
|
||||
/// <returns>True if the ranges overlap, false otherwise</returns>
|
||||
public bool OverlapsWith(HostMemoryRange other)
|
||||
{
|
||||
nuint thisAddress = Address;
|
||||
nuint thisEndAddress = EndAddress;
|
||||
nuint otherAddress = other.Address;
|
||||
nuint otherEndAddress = other.EndAddress;
|
||||
|
||||
return thisAddress < otherEndAddress && otherAddress < thisEndAddress;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is HostMemoryRange other && Equals(other);
|
||||
}
|
||||
|
||||
public bool Equals(HostMemoryRange other)
|
||||
{
|
||||
return Address == other.Address && Size == other.Size;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Address, Size);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue