mirror of
https://github.com/Ryubing/Ryujinx.git
synced 2026-01-02 05:21:18 -05:00
misc: Replace references to IntPtr/UIntPtr with nint/nuint + code cleanups.
This commit is contained in:
@@ -10,19 +10,19 @@ namespace Ryujinx.Memory
|
||||
[SupportedOSPlatform("macos")]
|
||||
static class MemoryManagementUnix
|
||||
{
|
||||
private static readonly ConcurrentDictionary<IntPtr, ulong> _allocations = new();
|
||||
private static readonly ConcurrentDictionary<nint, ulong> _allocations = new();
|
||||
|
||||
public static IntPtr Allocate(ulong size, bool forJit)
|
||||
public static nint Allocate(ulong size, bool forJit)
|
||||
{
|
||||
return AllocateInternal(size, MmapProts.PROT_READ | MmapProts.PROT_WRITE, forJit);
|
||||
}
|
||||
|
||||
public static IntPtr Reserve(ulong size, bool forJit)
|
||||
public static nint Reserve(ulong size, bool forJit)
|
||||
{
|
||||
return AllocateInternal(size, MmapProts.PROT_NONE, forJit);
|
||||
}
|
||||
|
||||
private static IntPtr AllocateInternal(ulong size, MmapProts prot, bool forJit, bool shared = false)
|
||||
private static nint AllocateInternal(ulong size, MmapProts prot, bool forJit, bool shared = false)
|
||||
{
|
||||
MmapFlags flags = MmapFlags.MAP_ANONYMOUS;
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Ryujinx.Memory
|
||||
}
|
||||
}
|
||||
|
||||
IntPtr ptr = Mmap(IntPtr.Zero, size, prot, flags, -1, 0);
|
||||
nint ptr = Mmap(nint.Zero, size, prot, flags, -1, 0);
|
||||
|
||||
if (ptr == MAP_FAILED)
|
||||
{
|
||||
@@ -66,7 +66,7 @@ namespace Ryujinx.Memory
|
||||
return ptr;
|
||||
}
|
||||
|
||||
public static void Commit(IntPtr address, ulong size, bool forJit)
|
||||
public static void Commit(nint address, ulong size, bool forJit)
|
||||
{
|
||||
MmapProts prot = MmapProts.PROT_READ | MmapProts.PROT_WRITE;
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Ryujinx.Memory
|
||||
}
|
||||
}
|
||||
|
||||
public static void Decommit(IntPtr address, ulong size)
|
||||
public static void Decommit(nint address, ulong size)
|
||||
{
|
||||
// Must be writable for madvise to work properly.
|
||||
if (mprotect(address, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE) != 0)
|
||||
@@ -100,7 +100,7 @@ namespace Ryujinx.Memory
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Reprotect(IntPtr address, ulong size, MemoryPermission permission)
|
||||
public static bool Reprotect(nint address, ulong size, MemoryPermission permission)
|
||||
{
|
||||
return mprotect(address, size, GetProtection(permission)) == 0;
|
||||
}
|
||||
@@ -119,7 +119,7 @@ namespace Ryujinx.Memory
|
||||
};
|
||||
}
|
||||
|
||||
public static bool Free(IntPtr address)
|
||||
public static bool Free(nint address)
|
||||
{
|
||||
if (_allocations.TryRemove(address, out ulong size))
|
||||
{
|
||||
@@ -129,12 +129,12 @@ namespace Ryujinx.Memory
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool Unmap(IntPtr address, ulong size)
|
||||
public static bool Unmap(nint address, ulong size)
|
||||
{
|
||||
return munmap(address, size) == 0;
|
||||
}
|
||||
|
||||
public unsafe static IntPtr CreateSharedMemory(ulong size, bool reserve)
|
||||
public unsafe static nint CreateSharedMemory(ulong size, bool reserve)
|
||||
{
|
||||
int fd;
|
||||
|
||||
@@ -144,13 +144,13 @@ namespace Ryujinx.Memory
|
||||
|
||||
fixed (byte* pMemName = memName)
|
||||
{
|
||||
fd = shm_open((IntPtr)pMemName, 0x2 | 0x200 | 0x800 | 0x400, 384); // O_RDWR | O_CREAT | O_EXCL | O_TRUNC, 0600
|
||||
fd = shm_open((nint)pMemName, 0x2 | 0x200 | 0x800 | 0x400, 384); // O_RDWR | O_CREAT | O_EXCL | O_TRUNC, 0600
|
||||
if (fd == -1)
|
||||
{
|
||||
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
|
||||
}
|
||||
|
||||
if (shm_unlink((IntPtr)pMemName) != 0)
|
||||
if (shm_unlink((nint)pMemName) != 0)
|
||||
{
|
||||
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
|
||||
}
|
||||
@@ -162,20 +162,20 @@ namespace Ryujinx.Memory
|
||||
|
||||
fixed (byte* pFileName = fileName)
|
||||
{
|
||||
fd = mkstemp((IntPtr)pFileName);
|
||||
fd = mkstemp((nint)pFileName);
|
||||
if (fd == -1)
|
||||
{
|
||||
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
|
||||
}
|
||||
|
||||
if (unlink((IntPtr)pFileName) != 0)
|
||||
if (unlink((nint)pFileName) != 0)
|
||||
{
|
||||
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ftruncate(fd, (IntPtr)size) != 0)
|
||||
if (ftruncate(fd, (nint)size) != 0)
|
||||
{
|
||||
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
|
||||
}
|
||||
@@ -183,27 +183,27 @@ namespace Ryujinx.Memory
|
||||
return fd;
|
||||
}
|
||||
|
||||
public static void DestroySharedMemory(IntPtr handle)
|
||||
public static void DestroySharedMemory(nint handle)
|
||||
{
|
||||
close(handle.ToInt32());
|
||||
}
|
||||
|
||||
public static IntPtr MapSharedMemory(IntPtr handle, ulong size)
|
||||
public static nint MapSharedMemory(nint handle, ulong size)
|
||||
{
|
||||
return Mmap(IntPtr.Zero, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE, MmapFlags.MAP_SHARED, handle.ToInt32(), 0);
|
||||
return Mmap(nint.Zero, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE, MmapFlags.MAP_SHARED, handle.ToInt32(), 0);
|
||||
}
|
||||
|
||||
public static void UnmapSharedMemory(IntPtr address, ulong size)
|
||||
public static void UnmapSharedMemory(nint address, ulong size)
|
||||
{
|
||||
munmap(address, size);
|
||||
}
|
||||
|
||||
public static void MapView(IntPtr sharedMemory, ulong srcOffset, IntPtr location, ulong size)
|
||||
public static void MapView(nint sharedMemory, ulong srcOffset, nint location, ulong size)
|
||||
{
|
||||
Mmap(location, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE, MmapFlags.MAP_FIXED | MmapFlags.MAP_SHARED, sharedMemory.ToInt32(), (long)srcOffset);
|
||||
}
|
||||
|
||||
public static void UnmapView(IntPtr location, ulong size)
|
||||
public static void UnmapView(nint location, ulong size)
|
||||
{
|
||||
Mmap(location, size, MmapProts.PROT_NONE, MmapFlags.MAP_FIXED | MmapFlags.MAP_PRIVATE | MmapFlags.MAP_ANONYMOUS | MmapFlags.MAP_NORESERVE, -1, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user