misc: Replace references to IntPtr/UIntPtr with nint/nuint + code cleanups.

This commit is contained in:
Evan Husted
2024-10-26 08:46:41 -05:00
parent a09d314817
commit dfb4854d19
172 changed files with 902 additions and 914 deletions

View File

@@ -23,7 +23,7 @@ namespace Ryujinx.Cpu.LightningJit.Cache
private readonly CacheMemoryAllocator _cacheAllocator;
public CacheMemoryAllocator Allocator => _cacheAllocator;
public IntPtr Pointer => _region.Block.Pointer;
public nint Pointer => _region.Block.Pointer;
public MemoryCache(IJitMemoryAllocator allocator, ulong size)
{
@@ -110,10 +110,10 @@ namespace Ryujinx.Cpu.LightningJit.Cache
{
public readonly int Offset;
public readonly int Size;
public readonly IntPtr FuncPtr;
public readonly nint FuncPtr;
private int _useCount;
public ThreadLocalCacheEntry(int offset, int size, IntPtr funcPtr)
public ThreadLocalCacheEntry(int offset, int size, nint funcPtr)
{
Offset = offset;
Size = size;
@@ -140,9 +140,9 @@ namespace Ryujinx.Cpu.LightningJit.Cache
_lock = new();
}
public unsafe IntPtr Map(IntPtr framePointer, ReadOnlySpan<byte> code, ulong guestAddress, ulong guestSize)
public unsafe nint Map(nint framePointer, ReadOnlySpan<byte> code, ulong guestAddress, ulong guestSize)
{
if (TryGetThreadLocalFunction(guestAddress, out IntPtr funcPtr))
if (TryGetThreadLocalFunction(guestAddress, out nint funcPtr))
{
return funcPtr;
}
@@ -167,7 +167,7 @@ namespace Ryujinx.Cpu.LightningJit.Cache
}
}
public unsafe IntPtr MapPageAligned(ReadOnlySpan<byte> code)
public unsafe nint MapPageAligned(ReadOnlySpan<byte> code)
{
lock (_lock)
{
@@ -179,7 +179,7 @@ namespace Ryujinx.Cpu.LightningJit.Cache
Debug.Assert((funcOffset & ((int)MemoryBlock.GetPageSize() - 1)) == 0);
IntPtr funcPtr = _sharedCache.Pointer + funcOffset;
nint funcPtr = _sharedCache.Pointer + funcOffset;
code.CopyTo(new Span<byte>((void*)funcPtr, code.Length));
_sharedCache.ReprotectAsRx(funcOffset, sizeAligned);
@@ -188,7 +188,7 @@ namespace Ryujinx.Cpu.LightningJit.Cache
}
}
private bool TryGetThreadLocalFunction(ulong guestAddress, out IntPtr funcPtr)
private bool TryGetThreadLocalFunction(ulong guestAddress, out nint funcPtr)
{
if ((_threadLocalCache ??= new()).TryGetValue(guestAddress, out var entry))
{
@@ -209,12 +209,12 @@ namespace Ryujinx.Cpu.LightningJit.Cache
return true;
}
funcPtr = IntPtr.Zero;
funcPtr = nint.Zero;
return false;
}
private void ClearThreadLocalCache(IntPtr framePointer)
private void ClearThreadLocalCache(nint framePointer)
{
// Try to delete functions that are already on the shared cache
// and no longer being executed.
@@ -296,14 +296,14 @@ namespace Ryujinx.Cpu.LightningJit.Cache
_threadLocalCache = null;
}
private unsafe IntPtr AddThreadLocalFunction(ReadOnlySpan<byte> code, ulong guestAddress)
private unsafe nint AddThreadLocalFunction(ReadOnlySpan<byte> code, ulong guestAddress)
{
int alignedSize = BitUtils.AlignUp(code.Length, (int)MemoryBlock.GetPageSize());
int funcOffset = _localCache.Allocate(alignedSize);
Debug.Assert((funcOffset & (int)(MemoryBlock.GetPageSize() - 1)) == 0);
IntPtr funcPtr = _localCache.Pointer + funcOffset;
nint funcPtr = _localCache.Pointer + funcOffset;
code.CopyTo(new Span<byte>((void*)funcPtr, code.Length));
(_threadLocalCache ??= new()).Add(guestAddress, new(funcOffset, code.Length, funcPtr));