From dfb4854d19d850e808c15701a9c5ef13a9464a22 Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Sat, 26 Oct 2024 08:46:41 -0500 Subject: [PATCH] misc: Replace references to IntPtr/UIntPtr with nint/nuint + code cleanups. --- .../CodeGen/Arm64/HardwareCapabilities.cs | 4 +- src/ARMeilleure/CodeGen/CompiledFunction.cs | 2 +- .../RegisterAllocators/LiveInterval.cs | 2 +- .../CodeGen/RegisterAllocators/LiveRange.cs | 2 +- src/ARMeilleure/Common/AddressTable.cs | 16 ++-- src/ARMeilleure/Common/ArenaAllocator.cs | 14 +-- src/ARMeilleure/Common/EntryTable.cs | 8 +- src/ARMeilleure/Common/NativeAllocator.cs | 4 +- .../IntrusiveList.cs | 2 +- .../MemoryOperand.cs | 2 +- .../IntermediateRepresentation/Operation.cs | 2 +- src/ARMeilleure/Memory/IJitMemoryBlock.cs | 2 +- src/ARMeilleure/Memory/IMemoryManager.cs | 2 +- src/ARMeilleure/Memory/ReservedRegion.cs | 2 +- src/ARMeilleure/Native/JitSupportDarwin.cs | 2 +- .../Signal/NativeSignalHandlerGenerator.cs | 6 +- src/ARMeilleure/Signal/TestMethods.cs | 4 +- .../Signal/WindowsPartialUnmapHandler.cs | 44 ++++----- src/ARMeilleure/State/ExecutionContext.cs | 2 +- src/ARMeilleure/State/NativeContext.cs | 2 +- .../Translation/ArmEmitterContext.cs | 2 +- src/ARMeilleure/Translation/Cache/JitCache.cs | 12 +-- .../Translation/Cache/JitCacheInvalidation.cs | 2 +- .../Translation/Cache/JitUnwindWindows.cs | 8 +- src/ARMeilleure/Translation/DelegateInfo.cs | 4 +- src/ARMeilleure/Translation/Delegates.cs | 8 +- .../Translation/DispatcherFunction.cs | 4 +- src/ARMeilleure/Translation/EmitterContext.cs | 2 +- src/ARMeilleure/Translation/GuestFunction.cs | 2 +- src/ARMeilleure/Translation/PTC/Ptc.cs | 22 ++--- .../Translation/TranslatedFunction.cs | 4 +- src/ARMeilleure/Translation/Translator.cs | 2 +- .../Translation/TranslatorStubs.cs | 12 +-- .../Translation/TranslatorTestMethods.cs | 2 +- .../SDL2HardwareDeviceDriver.cs | 6 +- .../SDL2HardwareDeviceSession.cs | 4 +- .../Native/SoundIo.cs | 96 +++++++++---------- .../Native/SoundIoContext.cs | 18 ++-- .../Native/SoundIoDeviceContext.cs | 10 +- .../Native/SoundIoOutStreamContext.cs | 22 ++--- .../Renderer/Dsp/Command/CommandList.cs | 4 +- .../Renderer/Dsp/Command/CompressorCommand.cs | 4 +- .../Renderer/Dsp/Command/DelayCommand.cs | 10 +- .../Dsp/Command/LimiterCommandVersion1.cs | 4 +- .../Dsp/Command/LimiterCommandVersion2.cs | 4 +- .../Renderer/Dsp/Command/Reverb3dCommand.cs | 14 +-- .../Renderer/Dsp/Command/ReverbCommand.cs | 14 +-- .../Renderer/Server/MemoryPool/AddressInfo.cs | 2 +- .../Server/MemoryPool/MemoryPoolState.cs | 2 +- .../Renderer/Server/Mix/MixState.cs | 6 +- .../GraphicsDriver/NVThreadedOptimization.cs | 24 ++--- src/Ryujinx.Common/Memory/ArrayPtr.cs | 12 +-- .../Memory/PartialUnmaps/PartialUnmapState.cs | 12 +-- src/Ryujinx.Common/Memory/Ptr.cs | 8 +- .../SystemInterop/ForceDpiAware.cs | 14 +-- .../SystemInterop/GdiPlusHelper.cs | 22 ++--- src/Ryujinx.Cpu/AppleHv/HvApi.cs | 4 +- .../AppleHv/HvExecutionContextVcpu.cs | 6 +- src/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs | 4 +- src/Ryujinx.Cpu/AppleHv/HvVcpuPool.cs | 2 +- src/Ryujinx.Cpu/AppleHv/HvVm.cs | 2 +- .../Jit/HostTracked/AddressSpacePartition.cs | 4 +- .../AddressSpacePartitionAllocator.cs | 4 +- .../AddressSpacePartitionMultiAllocation.cs | 4 +- .../HostTracked/AddressSpacePartitioned.cs | 4 +- .../Jit/HostTracked/NativePageTable.cs | 12 +-- src/Ryujinx.Cpu/Jit/JitMemoryBlock.cs | 2 +- src/Ryujinx.Cpu/Jit/MemoryManager.cs | 4 +- .../Jit/MemoryManagerHostMapped.cs | 2 +- .../Jit/MemoryManagerHostTracked.cs | 4 +- src/Ryujinx.Cpu/LightningJit/AarchCompiler.cs | 2 +- .../LightningJit/Arm32/A32Compiler.cs | 2 +- .../Arm32/Target/Arm64/Compiler.cs | 10 +- .../Arm32/Target/Arm64/InstEmitFlow.cs | 2 +- .../Arm32/Target/Arm64/InstEmitSystem.cs | 12 +-- .../LightningJit/Arm64/A64Compiler.cs | 2 +- .../Arm64/Target/Arm64/Compiler.cs | 10 +- .../Arm64/Target/Arm64/InstEmitSystem.cs | 16 ++-- .../LightningJit/Cache/JitCache.cs | 12 +-- .../Cache/JitCacheInvalidation.cs | 2 +- .../LightningJit/Cache/JitSupportDarwin.cs | 4 +- .../LightningJit/Cache/NoWxCache.cs | 24 ++--- .../LightningJit/CodeGen/Arm64/StackWalker.cs | 4 +- src/Ryujinx.Cpu/LightningJit/IStackWalker.cs | 2 +- .../LightningJit/NativeInterface.cs | 2 +- .../LightningJit/State/ExecutionContext.cs | 2 +- .../LightningJit/State/NativeContext.cs | 2 +- .../LightningJit/TranslatedFunction.cs | 4 +- src/Ryujinx.Cpu/LightningJit/Translator.cs | 4 +- .../LightningJit/TranslatorStubs.cs | 22 ++--- src/Ryujinx.Cpu/MemoryEhMeilleure.cs | 2 +- src/Ryujinx.Cpu/Signal/NativeSignalHandler.cs | 14 +-- .../Signal/UnixSignalHandlerRegistration.cs | 10 +- .../WindowsSignalHandlerRegistration.cs | 8 +- src/Ryujinx.Graphics.Device/DeviceState.cs | 10 +- .../Engine/Threed/StateUpdateTracker.cs | 2 +- .../FFmpegContext.cs | 2 +- .../Native/AVCodec.cs | 12 +-- .../Native/AVCodec501.cs | 10 +- .../Native/AVCodecContext.cs | 56 +++++------ .../Native/AVFrame.cs | 6 +- .../Native/FFCodec.cs | 12 +-- .../Native/FFCodecLegacy.cs | 16 ++-- .../Native/FFmpegApi.cs | 6 +- src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs | 6 +- .../Common/MemoryAllocator.cs | 14 +-- .../Types/Surface.cs | 10 +- src/Ryujinx.Graphics.OpenGL/Buffer.cs | 28 +++--- src/Ryujinx.Graphics.OpenGL/Debugger.cs | 8 +- .../Helper/GLXHelper.cs | 8 +- .../Helper/WGLHelper.cs | 2 +- .../Image/TextureBuffer.cs | 2 +- .../Image/TextureCopy.cs | 2 +- .../Image/TextureView.cs | 28 +++--- .../PersistentBuffers.cs | 22 ++--- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 32 +++---- src/Ryujinx.Graphics.OpenGL/Program.cs | 2 +- .../Queries/BufferedQuery.cs | 6 +- src/Ryujinx.Graphics.OpenGL/Sync.cs | 10 +- src/Ryujinx.Graphics.OpenGL/VertexArray.cs | 8 +- src/Ryujinx.Graphics.Video/Plane.cs | 2 +- src/Ryujinx.Graphics.Vulkan/BufferHolder.cs | 12 +-- .../HostMemoryAllocator.cs | 8 +- .../MemoryAllocation.cs | 6 +- .../MemoryAllocatorBlockList.cs | 20 ++-- .../MoltenVK/MVKConfiguration.cs | 2 +- .../MoltenVK/MVKInitialization.cs | 10 +- src/Ryujinx.Graphics.Vulkan/NativeArray.cs | 2 +- .../Queries/BufferedQuery.cs | 2 +- src/Ryujinx.Graphics.Vulkan/Shader.cs | 2 +- .../VulkanDebugMessenger.cs | 2 +- .../VulkanInitialization.cs | 6 +- src/Ryujinx.Graphics.Vulkan/VulkanInstance.cs | 6 +- .../VulkanPhysicalDevice.cs | 4 +- src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs | 2 +- .../HOS/Services/Sockets/Bsd/ISocket.cs | 2 +- .../Sockets/Bsd/Impl/ManagedSocket.cs | 2 +- .../OpenGL/OpenGLWindow.cs | 22 ++--- .../Vulkan/VulkanWindow.cs | 12 +-- src/Ryujinx.Headless.SDL2/WindowBase.cs | 10 +- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 10 +- src/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs | 4 +- src/Ryujinx.Input.SDL2/SDL2Keyboard.cs | 2 +- src/Ryujinx.Memory/MemoryBlock.cs | 36 +++---- src/Ryujinx.Memory/MemoryManagement.cs | 42 ++++---- src/Ryujinx.Memory/MemoryManagementUnix.cs | 44 ++++----- src/Ryujinx.Memory/MemoryManagementWindows.cs | 52 +++++----- src/Ryujinx.Memory/MemoryManagerUnixHelper.cs | 24 ++--- .../WindowsShared/PlaceholderManager.cs | 48 +++++----- .../WindowsShared/WindowsApi.cs | 56 +++++------ src/Ryujinx.Tests/Memory/MockMemoryManager.cs | 2 +- src/Ryujinx.Tests/Memory/PartialUnmaps.cs | 4 +- .../App/ApplicationLibrary.cs | 21 ++-- src/Ryujinx.UI.Common/Helper/ConsoleHelper.cs | 8 +- .../Helper/FileAssociationHelper.cs | 4 +- src/Ryujinx.UI.Common/Helper/ObjectiveC.cs | 44 ++++----- src/Ryujinx.UI.Common/Helper/OpenHelper.cs | 12 +-- .../SystemInfo/MacOSSystemInfo.cs | 12 +-- src/Ryujinx/App.axaml.cs | 4 +- src/Ryujinx/AppHost.cs | 4 +- src/Ryujinx/Modules/Updater/Updater.cs | 4 +- src/Ryujinx/Program.cs | 10 +- src/Ryujinx/UI/Helpers/Win32NativeInterop.cs | 52 +++++----- src/Ryujinx/UI/Renderer/EmbeddedWindow.cs | 24 ++--- .../UI/Renderer/OpenTKBindingsContext.cs | 6 +- src/Ryujinx/UI/Renderer/RendererHost.axaml.cs | 2 +- .../UI/Views/Main/MainMenuBarView.axaml.cs | 30 +++--- .../UI/Views/Main/MainStatusBarView.axaml.cs | 3 +- .../Views/Settings/SettingsSystemView.axaml | 1 + src/Ryujinx/UI/Windows/CheatWindow.axaml.cs | 2 - src/Ryujinx/UI/Windows/MainWindow.axaml.cs | 33 ++++--- src/Ryujinx/UI/Windows/StyleableWindow.cs | 8 +- 172 files changed, 902 insertions(+), 914 deletions(-) diff --git a/src/ARMeilleure/CodeGen/Arm64/HardwareCapabilities.cs b/src/ARMeilleure/CodeGen/Arm64/HardwareCapabilities.cs index 86afc2b4d..639e4476b 100644 --- a/src/ARMeilleure/CodeGen/Arm64/HardwareCapabilities.cs +++ b/src/ARMeilleure/CodeGen/Arm64/HardwareCapabilities.cs @@ -127,13 +127,13 @@ namespace ARMeilleure.CodeGen.Arm64 #region macOS [LibraryImport("libSystem.dylib", SetLastError = true)] - private static unsafe partial int sysctlbyname([MarshalAs(UnmanagedType.LPStr)] string name, out int oldValue, ref ulong oldSize, IntPtr newValue, ulong newValueSize); + private static unsafe partial int sysctlbyname([MarshalAs(UnmanagedType.LPStr)] string name, out int oldValue, ref ulong oldSize, nint newValue, ulong newValueSize); [SupportedOSPlatform("macos")] private static bool CheckSysctlName(string name) { ulong size = sizeof(int); - if (sysctlbyname(name, out int val, ref size, IntPtr.Zero, 0) == 0 && size == sizeof(int)) + if (sysctlbyname(name, out int val, ref size, nint.Zero, 0) == 0 && size == sizeof(int)) { return val != 0; } diff --git a/src/ARMeilleure/CodeGen/CompiledFunction.cs b/src/ARMeilleure/CodeGen/CompiledFunction.cs index 3844cbfc9..8ea7ff532 100644 --- a/src/ARMeilleure/CodeGen/CompiledFunction.cs +++ b/src/ARMeilleure/CodeGen/CompiledFunction.cs @@ -58,7 +58,7 @@ namespace ARMeilleure.CodeGen /// Type of delegate /// Pointer to the function code in memory /// A delegate of type pointing to the mapped function - public T MapWithPointer(out IntPtr codePointer) + public T MapWithPointer(out nint codePointer) { codePointer = JitCache.Map(this); diff --git a/src/ARMeilleure/CodeGen/RegisterAllocators/LiveInterval.cs b/src/ARMeilleure/CodeGen/RegisterAllocators/LiveInterval.cs index cfe1bc7ca..3a16186d2 100644 --- a/src/ARMeilleure/CodeGen/RegisterAllocators/LiveInterval.cs +++ b/src/ARMeilleure/CodeGen/RegisterAllocators/LiveInterval.cs @@ -387,7 +387,7 @@ namespace ARMeilleure.CodeGen.RegisterAllocators public override int GetHashCode() { - return HashCode.Combine((IntPtr)_data); + return HashCode.Combine((nint)_data); } public override string ToString() diff --git a/src/ARMeilleure/CodeGen/RegisterAllocators/LiveRange.cs b/src/ARMeilleure/CodeGen/RegisterAllocators/LiveRange.cs index 412d597e8..dcd573a9d 100644 --- a/src/ARMeilleure/CodeGen/RegisterAllocators/LiveRange.cs +++ b/src/ARMeilleure/CodeGen/RegisterAllocators/LiveRange.cs @@ -63,7 +63,7 @@ namespace ARMeilleure.CodeGen.RegisterAllocators public override int GetHashCode() { - return HashCode.Combine((IntPtr)_data); + return HashCode.Combine((nint)_data); } public override string ToString() diff --git a/src/ARMeilleure/Common/AddressTable.cs b/src/ARMeilleure/Common/AddressTable.cs index fcab3a202..a3ffaf470 100644 --- a/src/ARMeilleure/Common/AddressTable.cs +++ b/src/ARMeilleure/Common/AddressTable.cs @@ -55,7 +55,7 @@ namespace ARMeilleure.Common private bool _disposed; private TEntry** _table; - private readonly List _pages; + private readonly List _pages; /// /// Gets the bits used by the of the instance. @@ -76,7 +76,7 @@ namespace ARMeilleure.Common /// Gets the base address of the . /// /// instance was disposed - public IntPtr Base + public nint Base { get { @@ -84,7 +84,7 @@ namespace ARMeilleure.Common lock (_pages) { - return (IntPtr)GetRootPage(); + return (nint)GetRootPage(); } } } @@ -104,7 +104,7 @@ namespace ARMeilleure.Common throw new ArgumentException("Table must be at least 2 levels deep.", nameof(levels)); } - _pages = new List(capacity: 16); + _pages = new List(capacity: 16); Levels = levels; Mask = 0; @@ -168,7 +168,7 @@ namespace ARMeilleure.Common nextPage = i == Levels.Length - 2 ? (TEntry*)Allocate(1 << nextLevel.Length, Fill, leaf: true) : - (TEntry*)Allocate(1 << nextLevel.Length, IntPtr.Zero, leaf: false); + (TEntry*)Allocate(1 << nextLevel.Length, nint.Zero, leaf: false); } page = (TEntry**)nextPage; @@ -185,7 +185,7 @@ namespace ARMeilleure.Common { if (_table == null) { - _table = (TEntry**)Allocate(1 << Levels[0].Length, fill: IntPtr.Zero, leaf: false); + _table = (TEntry**)Allocate(1 << Levels[0].Length, fill: nint.Zero, leaf: false); } return _table; @@ -199,10 +199,10 @@ namespace ARMeilleure.Common /// Fill value /// if leaf; otherwise /// Allocated block - private IntPtr Allocate(int length, T fill, bool leaf) where T : unmanaged + private nint Allocate(int length, T fill, bool leaf) where T : unmanaged { var size = sizeof(T) * length; - var page = (IntPtr)NativeAllocator.Instance.Allocate((uint)size); + var page = (nint)NativeAllocator.Instance.Allocate((uint)size); var span = new Span((void*)page, length); span.Fill(fill); diff --git a/src/ARMeilleure/Common/ArenaAllocator.cs b/src/ARMeilleure/Common/ArenaAllocator.cs index ce8e33913..f9dbcbb20 100644 --- a/src/ARMeilleure/Common/ArenaAllocator.cs +++ b/src/ARMeilleure/Common/ArenaAllocator.cs @@ -20,7 +20,7 @@ namespace ARMeilleure.Common private List _pages; private readonly ulong _pageSize; private readonly uint _pageCount; - private readonly List _extras; + private readonly List _extras; public ArenaAllocator(uint pageSize, uint pageCount) { @@ -31,11 +31,11 @@ namespace ARMeilleure.Common _pageIndex = -1; _page = null; - _pages = new List(); + _pages = []; _pageSize = pageSize; _pageCount = pageCount; - _extras = new List(); + _extras = []; } public Span AllocateSpan(ulong count) where T : unmanaged @@ -64,7 +64,7 @@ namespace ARMeilleure.Common { void* extra = NativeAllocator.Instance.Allocate(size); - _extras.Add((IntPtr)extra); + _extras.Add((nint)extra); return extra; } @@ -84,7 +84,7 @@ namespace ARMeilleure.Common { _page = new PageInfo { - Pointer = (byte*)NativeAllocator.Instance.Allocate(_pageSize), + Pointer = (byte*)NativeAllocator.Instance.Allocate(_pageSize) }; _pages.Add(_page); @@ -114,7 +114,7 @@ namespace ARMeilleure.Common } // Free extra blocks that are not page-sized - foreach (IntPtr ptr in _extras) + foreach (nint ptr in _extras) { NativeAllocator.Instance.Free((void*)ptr); } @@ -173,7 +173,7 @@ namespace ARMeilleure.Common NativeAllocator.Instance.Free(info.Pointer); } - foreach (IntPtr ptr in _extras) + foreach (nint ptr in _extras) { NativeAllocator.Instance.Free((void*)ptr); } diff --git a/src/ARMeilleure/Common/EntryTable.cs b/src/ARMeilleure/Common/EntryTable.cs index 625e3f73f..e49a0989e 100644 --- a/src/ARMeilleure/Common/EntryTable.cs +++ b/src/ARMeilleure/Common/EntryTable.cs @@ -15,7 +15,7 @@ namespace ARMeilleure.Common private int _freeHint; private readonly int _pageCapacity; // Number of entries per page. private readonly int _pageLogCapacity; - private readonly Dictionary _pages; + private readonly Dictionary _pages; private readonly BitMap _allocated; /// @@ -41,7 +41,7 @@ namespace ARMeilleure.Common } _allocated = new BitMap(NativeAllocator.Instance); - _pages = new Dictionary(); + _pages = new Dictionary(); _pageLogCapacity = BitOperations.Log2((uint)(pageSize / sizeof(TEntry))); _pageCapacity = 1 << _pageLogCapacity; } @@ -138,9 +138,9 @@ namespace ARMeilleure.Common { var pageIndex = (int)((uint)(index & ~(_pageCapacity - 1)) >> _pageLogCapacity); - if (!_pages.TryGetValue(pageIndex, out IntPtr page)) + if (!_pages.TryGetValue(pageIndex, out nint page)) { - page = (IntPtr)NativeAllocator.Instance.Allocate((uint)sizeof(TEntry) * (uint)_pageCapacity); + page = (nint)NativeAllocator.Instance.Allocate((uint)sizeof(TEntry) * (uint)_pageCapacity); _pages.Add(pageIndex, page); } diff --git a/src/ARMeilleure/Common/NativeAllocator.cs b/src/ARMeilleure/Common/NativeAllocator.cs index 93c48adda..ca5d3a850 100644 --- a/src/ARMeilleure/Common/NativeAllocator.cs +++ b/src/ARMeilleure/Common/NativeAllocator.cs @@ -9,7 +9,7 @@ namespace ARMeilleure.Common public override void* Allocate(ulong size) { - void* result = (void*)Marshal.AllocHGlobal((IntPtr)size); + void* result = (void*)Marshal.AllocHGlobal((nint)size); if (result == null) { @@ -21,7 +21,7 @@ namespace ARMeilleure.Common public override void Free(void* block) { - Marshal.FreeHGlobal((IntPtr)block); + Marshal.FreeHGlobal((nint)block); } } } diff --git a/src/ARMeilleure/IntermediateRepresentation/IntrusiveList.cs b/src/ARMeilleure/IntermediateRepresentation/IntrusiveList.cs index 8d300075d..642e5aa90 100644 --- a/src/ARMeilleure/IntermediateRepresentation/IntrusiveList.cs +++ b/src/ARMeilleure/IntermediateRepresentation/IntrusiveList.cs @@ -32,7 +32,7 @@ namespace ARMeilleure.IntermediateRepresentation /// is not pointer sized. public IntrusiveList() { - if (Unsafe.SizeOf() != IntPtr.Size) + if (Unsafe.SizeOf() != nint.Size) { throw new ArgumentException("T must be a reference type or a pointer sized struct."); } diff --git a/src/ARMeilleure/IntermediateRepresentation/MemoryOperand.cs b/src/ARMeilleure/IntermediateRepresentation/MemoryOperand.cs index 9b3df8ca4..45695396f 100644 --- a/src/ARMeilleure/IntermediateRepresentation/MemoryOperand.cs +++ b/src/ARMeilleure/IntermediateRepresentation/MemoryOperand.cs @@ -24,7 +24,7 @@ namespace ARMeilleure.IntermediateRepresentation { Debug.Assert(operand.Kind == OperandKind.Memory); - _data = (Data*)Unsafe.As(ref operand); + _data = (Data*)Unsafe.As(ref operand); } public Operand BaseAddress diff --git a/src/ARMeilleure/IntermediateRepresentation/Operation.cs b/src/ARMeilleure/IntermediateRepresentation/Operation.cs index bc3a71b31..b0dc173af 100644 --- a/src/ARMeilleure/IntermediateRepresentation/Operation.cs +++ b/src/ARMeilleure/IntermediateRepresentation/Operation.cs @@ -228,7 +228,7 @@ namespace ARMeilleure.IntermediateRepresentation public readonly override int GetHashCode() { - return HashCode.Combine((IntPtr)_data); + return HashCode.Combine((nint)_data); } public static bool operator ==(Operation a, Operation b) diff --git a/src/ARMeilleure/Memory/IJitMemoryBlock.cs b/src/ARMeilleure/Memory/IJitMemoryBlock.cs index c103fe8d1..59710d1ce 100644 --- a/src/ARMeilleure/Memory/IJitMemoryBlock.cs +++ b/src/ARMeilleure/Memory/IJitMemoryBlock.cs @@ -4,7 +4,7 @@ namespace ARMeilleure.Memory { public interface IJitMemoryBlock : IDisposable { - IntPtr Pointer { get; } + nint Pointer { get; } void Commit(ulong offset, ulong size); diff --git a/src/ARMeilleure/Memory/IMemoryManager.cs b/src/ARMeilleure/Memory/IMemoryManager.cs index 46d442655..84d82caf7 100644 --- a/src/ARMeilleure/Memory/IMemoryManager.cs +++ b/src/ARMeilleure/Memory/IMemoryManager.cs @@ -6,7 +6,7 @@ namespace ARMeilleure.Memory { int AddressSpaceBits { get; } - IntPtr PageTablePointer { get; } + nint PageTablePointer { get; } MemoryManagerType Type { get; } diff --git a/src/ARMeilleure/Memory/ReservedRegion.cs b/src/ARMeilleure/Memory/ReservedRegion.cs index 3870d4c84..a3ebd610d 100644 --- a/src/ARMeilleure/Memory/ReservedRegion.cs +++ b/src/ARMeilleure/Memory/ReservedRegion.cs @@ -8,7 +8,7 @@ namespace ARMeilleure.Memory public IJitMemoryBlock Block { get; } - public IntPtr Pointer => Block.Pointer; + public nint Pointer => Block.Pointer; private readonly ulong _maxSize; private readonly ulong _sizeGranularity; diff --git a/src/ARMeilleure/Native/JitSupportDarwin.cs b/src/ARMeilleure/Native/JitSupportDarwin.cs index 339460397..39df3878f 100644 --- a/src/ARMeilleure/Native/JitSupportDarwin.cs +++ b/src/ARMeilleure/Native/JitSupportDarwin.cs @@ -8,6 +8,6 @@ namespace ARMeilleure.Native static partial class JitSupportDarwin { [LibraryImport("libarmeilleure-jitsupport", EntryPoint = "armeilleure_jit_memcpy")] - public static partial void Copy(IntPtr dst, IntPtr src, ulong n); + public static partial void Copy(nint dst, nint src, ulong n); } } diff --git a/src/ARMeilleure/Signal/NativeSignalHandlerGenerator.cs b/src/ARMeilleure/Signal/NativeSignalHandlerGenerator.cs index 2ec5bc1b3..1b3689e3f 100644 --- a/src/ARMeilleure/Signal/NativeSignalHandlerGenerator.cs +++ b/src/ARMeilleure/Signal/NativeSignalHandlerGenerator.cs @@ -21,7 +21,7 @@ namespace ARMeilleure.Signal private const uint EXCEPTION_ACCESS_VIOLATION = 0xc0000005; - private static Operand EmitGenericRegionCheck(EmitterContext context, IntPtr signalStructPtr, Operand faultAddress, Operand isWrite, int rangeStructSize) + private static Operand EmitGenericRegionCheck(EmitterContext context, nint signalStructPtr, Operand faultAddress, Operand isWrite, int rangeStructSize) { Operand inRegionLocal = context.AllocateLocal(OperandType.I32); context.Copy(inRegionLocal, Const(0)); @@ -155,7 +155,7 @@ namespace ARMeilleure.Signal throw new PlatformNotSupportedException(); } - public static byte[] GenerateUnixSignalHandler(IntPtr signalStructPtr, int rangeStructSize) + public static byte[] GenerateUnixSignalHandler(nint signalStructPtr, int rangeStructSize) { EmitterContext context = new(); @@ -203,7 +203,7 @@ namespace ARMeilleure.Signal return Compiler.Compile(cfg, argTypes, OperandType.None, CompilerOptions.HighCq, RuntimeInformation.ProcessArchitecture).Code; } - public static byte[] GenerateWindowsSignalHandler(IntPtr signalStructPtr, int rangeStructSize) + public static byte[] GenerateWindowsSignalHandler(nint signalStructPtr, int rangeStructSize) { EmitterContext context = new(); diff --git a/src/ARMeilleure/Signal/TestMethods.cs b/src/ARMeilleure/Signal/TestMethods.cs index 0a8b3f5ff..9d11ab183 100644 --- a/src/ARMeilleure/Signal/TestMethods.cs +++ b/src/ARMeilleure/Signal/TestMethods.cs @@ -16,7 +16,7 @@ namespace ARMeilleure.Signal { public delegate bool DebugPartialUnmap(); public delegate int DebugThreadLocalMapGetOrReserve(int threadId, int initialState); - public delegate void DebugNativeWriteLoop(IntPtr nativeWriteLoopPtr, IntPtr writePtr); + public delegate void DebugNativeWriteLoop(nint nativeWriteLoopPtr, nint writePtr); public static DebugPartialUnmap GenerateDebugPartialUnmap() { @@ -35,7 +35,7 @@ namespace ARMeilleure.Signal return Compiler.Compile(cfg, argTypes, OperandType.I32, CompilerOptions.HighCq, RuntimeInformation.ProcessArchitecture).Map(); } - public static DebugThreadLocalMapGetOrReserve GenerateDebugThreadLocalMapGetOrReserve(IntPtr structPtr) + public static DebugThreadLocalMapGetOrReserve GenerateDebugThreadLocalMapGetOrReserve(nint structPtr) { EmitterContext context = new(); diff --git a/src/ARMeilleure/Signal/WindowsPartialUnmapHandler.cs b/src/ARMeilleure/Signal/WindowsPartialUnmapHandler.cs index 3bf6a4498..7aa3e4788 100644 --- a/src/ARMeilleure/Signal/WindowsPartialUnmapHandler.cs +++ b/src/ARMeilleure/Signal/WindowsPartialUnmapHandler.cs @@ -13,18 +13,18 @@ namespace ARMeilleure.Signal internal static partial class WindowsPartialUnmapHandler { [LibraryImport("kernel32.dll", SetLastError = true, EntryPoint = "LoadLibraryA")] - private static partial IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName); + private static partial nint LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName); [LibraryImport("kernel32.dll", SetLastError = true)] - private static partial IntPtr GetProcAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] string procName); + private static partial nint GetProcAddress(nint hModule, [MarshalAs(UnmanagedType.LPStr)] string procName); - private static IntPtr _getCurrentThreadIdPtr; + private static nint _getCurrentThreadIdPtr; - public static IntPtr GetCurrentThreadIdFunc() + public static nint GetCurrentThreadIdFunc() { - if (_getCurrentThreadIdPtr == IntPtr.Zero) + if (_getCurrentThreadIdPtr == nint.Zero) { - IntPtr handle = LoadLibrary("kernel32.dll"); + nint handle = LoadLibrary("kernel32.dll"); _getCurrentThreadIdPtr = GetProcAddress(handle, "GetCurrentThreadId"); } @@ -34,13 +34,13 @@ namespace ARMeilleure.Signal public static Operand EmitRetryFromAccessViolation(EmitterContext context) { - IntPtr partialRemapStatePtr = PartialUnmapState.GlobalState; - IntPtr localCountsPtr = IntPtr.Add(partialRemapStatePtr, PartialUnmapState.LocalCountsOffset); + nint partialRemapStatePtr = PartialUnmapState.GlobalState; + nint localCountsPtr = nint.Add(partialRemapStatePtr, PartialUnmapState.LocalCountsOffset); // Get the lock first. - EmitNativeReaderLockAcquire(context, IntPtr.Add(partialRemapStatePtr, PartialUnmapState.PartialUnmapLockOffset)); + EmitNativeReaderLockAcquire(context, nint.Add(partialRemapStatePtr, PartialUnmapState.PartialUnmapLockOffset)); - IntPtr getCurrentThreadId = GetCurrentThreadIdFunc(); + nint getCurrentThreadId = GetCurrentThreadIdFunc(); Operand threadId = context.Call(Const((ulong)getCurrentThreadId), OperandType.I32); Operand threadIndex = EmitThreadLocalMapIntGetOrReserve(context, localCountsPtr, threadId, Const(0)); @@ -58,7 +58,7 @@ namespace ARMeilleure.Signal Operand threadLocalPartialUnmapsPtr = EmitThreadLocalMapIntGetValuePtr(context, localCountsPtr, threadIndex); Operand threadLocalPartialUnmaps = context.Load(OperandType.I32, threadLocalPartialUnmapsPtr); - Operand partialUnmapsCount = context.Load(OperandType.I32, Const((ulong)IntPtr.Add(partialRemapStatePtr, PartialUnmapState.PartialUnmapsCountOffset))); + Operand partialUnmapsCount = context.Load(OperandType.I32, Const((ulong)nint.Add(partialRemapStatePtr, PartialUnmapState.PartialUnmapsCountOffset))); context.Copy(retry, context.ICompareNotEqual(threadLocalPartialUnmaps, partialUnmapsCount)); @@ -79,14 +79,14 @@ namespace ARMeilleure.Signal context.MarkLabel(endLabel); // Finally, release the lock and return the retry value. - EmitNativeReaderLockRelease(context, IntPtr.Add(partialRemapStatePtr, PartialUnmapState.PartialUnmapLockOffset)); + EmitNativeReaderLockRelease(context, nint.Add(partialRemapStatePtr, PartialUnmapState.PartialUnmapLockOffset)); return retry; } - public static Operand EmitThreadLocalMapIntGetOrReserve(EmitterContext context, IntPtr threadLocalMapPtr, Operand threadId, Operand initialState) + public static Operand EmitThreadLocalMapIntGetOrReserve(EmitterContext context, nint threadLocalMapPtr, Operand threadId, Operand initialState) { - Operand idsPtr = Const((ulong)IntPtr.Add(threadLocalMapPtr, ThreadLocalMap.ThreadIdsOffset)); + Operand idsPtr = Const((ulong)nint.Add(threadLocalMapPtr, ThreadLocalMap.ThreadIdsOffset)); Operand i = context.AllocateLocal(OperandType.I32); @@ -130,7 +130,7 @@ namespace ARMeilleure.Signal // If it was 0, then we need to initialize the struct entry and return i. context.BranchIfFalse(idNot0Label, context.ICompareEqual(existingId2, Const(0))); - Operand structsPtr = Const((ulong)IntPtr.Add(threadLocalMapPtr, ThreadLocalMap.StructsOffset)); + Operand structsPtr = Const((ulong)nint.Add(threadLocalMapPtr, ThreadLocalMap.StructsOffset)); Operand structPtr = context.Add(structsPtr, context.SignExtend32(OperandType.I64, offset2)); context.Store(structPtr, initialState); @@ -149,10 +149,10 @@ namespace ARMeilleure.Signal return context.Copy(i); } - private static Operand EmitThreadLocalMapIntGetValuePtr(EmitterContext context, IntPtr threadLocalMapPtr, Operand index) + private static Operand EmitThreadLocalMapIntGetValuePtr(EmitterContext context, nint threadLocalMapPtr, Operand index) { Operand offset = context.Multiply(index, Const(sizeof(int))); - Operand structsPtr = Const((ulong)IntPtr.Add(threadLocalMapPtr, ThreadLocalMap.StructsOffset)); + Operand structsPtr = Const((ulong)nint.Add(threadLocalMapPtr, ThreadLocalMap.StructsOffset)); return context.Add(structsPtr, context.SignExtend32(OperandType.I64, offset)); } @@ -170,9 +170,9 @@ namespace ARMeilleure.Signal context.BranchIfFalse(loop, context.ICompareEqual(initial, replaced)); } - private static void EmitNativeReaderLockAcquire(EmitterContext context, IntPtr nativeReaderLockPtr) + private static void EmitNativeReaderLockAcquire(EmitterContext context, nint nativeReaderLockPtr) { - Operand writeLockPtr = Const((ulong)IntPtr.Add(nativeReaderLockPtr, NativeReaderWriterLock.WriteLockOffset)); + Operand writeLockPtr = Const((ulong)nint.Add(nativeReaderLockPtr, NativeReaderWriterLock.WriteLockOffset)); // Spin until we can acquire the write lock. Operand spinLabel = Label(); @@ -182,16 +182,16 @@ namespace ARMeilleure.Signal context.BranchIfTrue(spinLabel, context.CompareAndSwap(writeLockPtr, Const(0), Const(1))); // Increment reader count. - EmitAtomicAddI32(context, Const((ulong)IntPtr.Add(nativeReaderLockPtr, NativeReaderWriterLock.ReaderCountOffset)), Const(1)); + EmitAtomicAddI32(context, Const((ulong)nint.Add(nativeReaderLockPtr, NativeReaderWriterLock.ReaderCountOffset)), Const(1)); // Release write lock. context.CompareAndSwap(writeLockPtr, Const(1), Const(0)); } - private static void EmitNativeReaderLockRelease(EmitterContext context, IntPtr nativeReaderLockPtr) + private static void EmitNativeReaderLockRelease(EmitterContext context, nint nativeReaderLockPtr) { // Decrement reader count. - EmitAtomicAddI32(context, Const((ulong)IntPtr.Add(nativeReaderLockPtr, NativeReaderWriterLock.ReaderCountOffset)), Const(-1)); + EmitAtomicAddI32(context, Const((ulong)nint.Add(nativeReaderLockPtr, NativeReaderWriterLock.ReaderCountOffset)), Const(-1)); } } } diff --git a/src/ARMeilleure/State/ExecutionContext.cs b/src/ARMeilleure/State/ExecutionContext.cs index ce10a591c..314b06b13 100644 --- a/src/ARMeilleure/State/ExecutionContext.cs +++ b/src/ARMeilleure/State/ExecutionContext.cs @@ -9,7 +9,7 @@ namespace ARMeilleure.State private readonly NativeContext _nativeContext; - internal IntPtr NativeContextPtr => _nativeContext.BasePtr; + internal nint NativeContextPtr => _nativeContext.BasePtr; private bool _interrupted; diff --git a/src/ARMeilleure/State/NativeContext.cs b/src/ARMeilleure/State/NativeContext.cs index 5403042ea..628efde41 100644 --- a/src/ARMeilleure/State/NativeContext.cs +++ b/src/ARMeilleure/State/NativeContext.cs @@ -27,7 +27,7 @@ namespace ARMeilleure.State private readonly IJitMemoryBlock _block; - public IntPtr BasePtr => _block.Pointer; + public nint BasePtr => _block.Pointer; public NativeContext(IJitMemoryAllocator allocator) { diff --git a/src/ARMeilleure/Translation/ArmEmitterContext.cs b/src/ARMeilleure/Translation/ArmEmitterContext.cs index e24074739..5d79171a2 100644 --- a/src/ARMeilleure/Translation/ArmEmitterContext.cs +++ b/src/ARMeilleure/Translation/ArmEmitterContext.cs @@ -92,7 +92,7 @@ namespace ARMeilleure.Translation else { int index = Delegates.GetDelegateIndex(info); - IntPtr funcPtr = Delegates.GetDelegateFuncPtrByIndex(index); + nint funcPtr = Delegates.GetDelegateFuncPtrByIndex(index); OperandType returnType = GetOperandType(info.ReturnType); diff --git a/src/ARMeilleure/Translation/Cache/JitCache.cs b/src/ARMeilleure/Translation/Cache/JitCache.cs index e2b5e2d10..cf13cd6cb 100644 --- a/src/ARMeilleure/Translation/Cache/JitCache.cs +++ b/src/ARMeilleure/Translation/Cache/JitCache.cs @@ -31,7 +31,7 @@ namespace ARMeilleure.Translation.Cache [SupportedOSPlatform("windows")] [LibraryImport("kernel32.dll", SetLastError = true)] - public static partial IntPtr FlushInstructionCache(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize); + public static partial nint FlushInstructionCache(nint hProcess, nint lpAddress, nuint dwSize); public static void Initialize(IJitMemoryAllocator allocator) { @@ -65,7 +65,7 @@ namespace ARMeilleure.Translation.Cache } } - public static IntPtr Map(CompiledFunction func) + public static nint Map(CompiledFunction func) { byte[] code = func.Code; @@ -75,7 +75,7 @@ namespace ARMeilleure.Translation.Cache int funcOffset = Allocate(code.Length); - IntPtr funcPtr = _jitRegion.Pointer + funcOffset; + nint funcPtr = _jitRegion.Pointer + funcOffset; if (OperatingSystem.IsMacOS() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64) { @@ -83,7 +83,7 @@ namespace ARMeilleure.Translation.Cache { fixed (byte* codePtr = code) { - JitSupportDarwin.Copy(funcPtr, (IntPtr)codePtr, (ulong)code.Length); + JitSupportDarwin.Copy(funcPtr, (nint)codePtr, (ulong)code.Length); } } } @@ -95,7 +95,7 @@ namespace ARMeilleure.Translation.Cache if (OperatingSystem.IsWindows() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64) { - FlushInstructionCache(Process.GetCurrentProcess().Handle, funcPtr, (UIntPtr)code.Length); + FlushInstructionCache(Process.GetCurrentProcess().Handle, funcPtr, (nuint)code.Length); } else { @@ -109,7 +109,7 @@ namespace ARMeilleure.Translation.Cache } } - public static void Unmap(IntPtr pointer) + public static void Unmap(nint pointer) { lock (_lock) { diff --git a/src/ARMeilleure/Translation/Cache/JitCacheInvalidation.cs b/src/ARMeilleure/Translation/Cache/JitCacheInvalidation.cs index 3aa2e19f1..6f9c22b4a 100644 --- a/src/ARMeilleure/Translation/Cache/JitCacheInvalidation.cs +++ b/src/ARMeilleure/Translation/Cache/JitCacheInvalidation.cs @@ -68,7 +68,7 @@ namespace ARMeilleure.Translation.Cache } } - public void Invalidate(IntPtr basePointer, ulong size) + public void Invalidate(nint basePointer, ulong size) { if (_needsInvalidation) { diff --git a/src/ARMeilleure/Translation/Cache/JitUnwindWindows.cs b/src/ARMeilleure/Translation/Cache/JitUnwindWindows.cs index 3957a7559..642794188 100644 --- a/src/ARMeilleure/Translation/Cache/JitUnwindWindows.cs +++ b/src/ARMeilleure/Translation/Cache/JitUnwindWindows.cs @@ -40,7 +40,7 @@ namespace ARMeilleure.Translation.Cache PushMachframe = 10, } - private unsafe delegate RuntimeFunction* GetRuntimeFunctionCallback(ulong controlPc, IntPtr context); + private unsafe delegate RuntimeFunction* GetRuntimeFunctionCallback(ulong controlPc, nint context); [LibraryImport("kernel32.dll")] [return: MarshalAs(UnmanagedType.Bool)] @@ -49,7 +49,7 @@ namespace ARMeilleure.Translation.Cache ulong baseAddress, uint length, GetRuntimeFunctionCallback callback, - IntPtr context, + nint context, [MarshalAs(UnmanagedType.LPWStr)] string outOfProcessCallbackDll); private static GetRuntimeFunctionCallback _getRuntimeFunctionCallback; @@ -60,7 +60,7 @@ namespace ARMeilleure.Translation.Cache private unsafe static UnwindInfo* _unwindInfo; - public static void InstallFunctionTableHandler(IntPtr codeCachePointer, uint codeCacheLength, IntPtr workBufferPtr) + public static void InstallFunctionTableHandler(nint codeCachePointer, uint codeCacheLength, nint workBufferPtr) { ulong codeCachePtr = (ulong)codeCachePointer.ToInt64(); @@ -91,7 +91,7 @@ namespace ARMeilleure.Translation.Cache } } - private static unsafe RuntimeFunction* FunctionTableHandler(ulong controlPc, IntPtr context) + private static unsafe RuntimeFunction* FunctionTableHandler(ulong controlPc, nint context) { int offset = (int)((long)controlPc - context.ToInt64()); diff --git a/src/ARMeilleure/Translation/DelegateInfo.cs b/src/ARMeilleure/Translation/DelegateInfo.cs index 706625437..d3b535de1 100644 --- a/src/ARMeilleure/Translation/DelegateInfo.cs +++ b/src/ARMeilleure/Translation/DelegateInfo.cs @@ -8,9 +8,9 @@ namespace ARMeilleure.Translation private readonly Delegate _dlg; // Ensure that this delegate will not be garbage collected. #pragma warning restore IDE0052 - public IntPtr FuncPtr { get; } + public nint FuncPtr { get; } - public DelegateInfo(Delegate dlg, IntPtr funcPtr) + public DelegateInfo(Delegate dlg, nint funcPtr) { _dlg = dlg; FuncPtr = funcPtr; diff --git a/src/ARMeilleure/Translation/Delegates.cs b/src/ARMeilleure/Translation/Delegates.cs index 66412b8e6..d8c1cfd58 100644 --- a/src/ARMeilleure/Translation/Delegates.cs +++ b/src/ARMeilleure/Translation/Delegates.cs @@ -9,7 +9,7 @@ namespace ARMeilleure.Translation { static class Delegates { - public static bool TryGetDelegateFuncPtrByIndex(int index, out IntPtr funcPtr) + public static bool TryGetDelegateFuncPtrByIndex(int index, out nint funcPtr) { if (index >= 0 && index < _delegates.Count) { @@ -25,7 +25,7 @@ namespace ARMeilleure.Translation } } - public static IntPtr GetDelegateFuncPtrByIndex(int index) + public static nint GetDelegateFuncPtrByIndex(int index) { if (index < 0 || index >= _delegates.Count) { @@ -35,7 +35,7 @@ namespace ARMeilleure.Translation return _delegates.Values[index].FuncPtr; // O(1). } - public static IntPtr GetDelegateFuncPtr(MethodInfo info) + public static nint GetDelegateFuncPtr(MethodInfo info) { ArgumentNullException.ThrowIfNull(info); @@ -65,7 +65,7 @@ namespace ARMeilleure.Translation return index; } - private static void SetDelegateInfo(Delegate dlg, IntPtr funcPtr) + private static void SetDelegateInfo(Delegate dlg, nint funcPtr) { string key = GetKey(dlg.Method); diff --git a/src/ARMeilleure/Translation/DispatcherFunction.cs b/src/ARMeilleure/Translation/DispatcherFunction.cs index 649fa0f50..f8b9dc31e 100644 --- a/src/ARMeilleure/Translation/DispatcherFunction.cs +++ b/src/ARMeilleure/Translation/DispatcherFunction.cs @@ -2,6 +2,6 @@ using System; namespace ARMeilleure.Translation { - delegate void DispatcherFunction(IntPtr nativeContext, ulong startAddress); - delegate ulong WrapperFunction(IntPtr nativeContext, ulong startAddress); + delegate void DispatcherFunction(nint nativeContext, ulong startAddress); + delegate ulong WrapperFunction(nint nativeContext, ulong startAddress); } diff --git a/src/ARMeilleure/Translation/EmitterContext.cs b/src/ARMeilleure/Translation/EmitterContext.cs index 88bfe1335..e2d860f82 100644 --- a/src/ARMeilleure/Translation/EmitterContext.cs +++ b/src/ARMeilleure/Translation/EmitterContext.cs @@ -97,7 +97,7 @@ namespace ARMeilleure.Translation public virtual Operand Call(MethodInfo info, params Operand[] callArgs) { - IntPtr funcPtr = Delegates.GetDelegateFuncPtr(info); + nint funcPtr = Delegates.GetDelegateFuncPtr(info); OperandType returnType = GetOperandType(info.ReturnType); diff --git a/src/ARMeilleure/Translation/GuestFunction.cs b/src/ARMeilleure/Translation/GuestFunction.cs index 6414d6bd0..5c7c733f9 100644 --- a/src/ARMeilleure/Translation/GuestFunction.cs +++ b/src/ARMeilleure/Translation/GuestFunction.cs @@ -2,5 +2,5 @@ using System; namespace ARMeilleure.Translation { - delegate ulong GuestFunction(IntPtr nativeContextPtr); + delegate ulong GuestFunction(nint nativeContextPtr); } diff --git a/src/ARMeilleure/Translation/PTC/Ptc.cs b/src/ARMeilleure/Translation/PTC/Ptc.cs index fa178eace..2fecbc3d9 100644 --- a/src/ARMeilleure/Translation/PTC/Ptc.cs +++ b/src/ARMeilleure/Translation/PTC/Ptc.cs @@ -268,11 +268,11 @@ namespace ARMeilleure.Translation.PTC return false; } - IntPtr intPtr = IntPtr.Zero; + nint intPtr = nint.Zero; try { - intPtr = Marshal.AllocHGlobal(new IntPtr(outerHeader.UncompressedStreamSize)); + intPtr = Marshal.AllocHGlobal(new nint(outerHeader.UncompressedStreamSize)); using UnmanagedMemoryStream stream = new((byte*)intPtr.ToPointer(), outerHeader.UncompressedStreamSize, outerHeader.UncompressedStreamSize, FileAccess.ReadWrite); try @@ -373,7 +373,7 @@ namespace ARMeilleure.Translation.PTC } finally { - if (intPtr != IntPtr.Zero) + if (intPtr != nint.Zero) { Marshal.FreeHGlobal(intPtr); } @@ -455,11 +455,11 @@ namespace ARMeilleure.Translation.PTC outerHeader.SetHeaderHash(); - IntPtr intPtr = IntPtr.Zero; + nint intPtr = nint.Zero; try { - intPtr = Marshal.AllocHGlobal(new IntPtr(outerHeader.UncompressedStreamSize)); + intPtr = Marshal.AllocHGlobal(new nint(outerHeader.UncompressedStreamSize)); using UnmanagedMemoryStream stream = new((byte*)intPtr.ToPointer(), outerHeader.UncompressedStreamSize, outerHeader.UncompressedStreamSize, FileAccess.ReadWrite); stream.Seek((long)Unsafe.SizeOf(), SeekOrigin.Begin); @@ -513,7 +513,7 @@ namespace ARMeilleure.Translation.PTC } finally { - if (intPtr != IntPtr.Zero) + if (intPtr != nint.Zero) { Marshal.FreeHGlobal(intPtr); } @@ -664,7 +664,7 @@ namespace ARMeilleure.Translation.PTC foreach (RelocEntry relocEntry in relocEntries) { - IntPtr? imm = null; + nint? imm = null; Symbol symbol = relocEntry.Symbol; if (symbol.Type == SymbolType.FunctionTable) @@ -675,7 +675,7 @@ namespace ARMeilleure.Translation.PTC { unsafe { - imm = (IntPtr)Unsafe.AsPointer(ref translator.FunctionTable.GetValue(guestAddress)); + imm = (nint)Unsafe.AsPointer(ref translator.FunctionTable.GetValue(guestAddress)); } } } @@ -683,7 +683,7 @@ namespace ARMeilleure.Translation.PTC { int index = (int)symbol.Value; - if (Delegates.TryGetDelegateFuncPtrByIndex(index, out IntPtr funcPtr)) + if (Delegates.TryGetDelegateFuncPtrByIndex(index, out nint funcPtr)) { imm = funcPtr; } @@ -698,7 +698,7 @@ namespace ARMeilleure.Translation.PTC unsafe { - imm = (IntPtr)Unsafe.AsPointer(ref callCounter.Value); + imm = (nint)Unsafe.AsPointer(ref callCounter.Value); } } else if (symbol == DispatchStubSymbol) @@ -744,7 +744,7 @@ namespace ARMeilleure.Translation.PTC bool highCq) { var cFunc = new CompiledFunction(code, unwindInfo, RelocInfo.Empty); - var gFunc = cFunc.MapWithPointer(out IntPtr gFuncPointer); + var gFunc = cFunc.MapWithPointer(out nint gFuncPointer); return new TranslatedFunction(gFunc, gFuncPointer, callCounter, guestSize, highCq); } diff --git a/src/ARMeilleure/Translation/TranslatedFunction.cs b/src/ARMeilleure/Translation/TranslatedFunction.cs index 1446c254a..3d7ae9ffe 100644 --- a/src/ARMeilleure/Translation/TranslatedFunction.cs +++ b/src/ARMeilleure/Translation/TranslatedFunction.cs @@ -7,12 +7,12 @@ namespace ARMeilleure.Translation { private readonly GuestFunction _func; // Ensure that this delegate will not be garbage collected. - public IntPtr FuncPointer { get; } + public nint FuncPointer { get; } public Counter CallCounter { get; } public ulong GuestSize { get; } public bool HighCq { get; } - public TranslatedFunction(GuestFunction func, IntPtr funcPointer, Counter callCounter, ulong guestSize, bool highCq) + public TranslatedFunction(GuestFunction func, nint funcPointer, Counter callCounter, ulong guestSize, bool highCq) { _func = func; FuncPointer = funcPointer; diff --git a/src/ARMeilleure/Translation/Translator.cs b/src/ARMeilleure/Translation/Translator.cs index 014b12035..24fbd7621 100644 --- a/src/ARMeilleure/Translation/Translator.cs +++ b/src/ARMeilleure/Translation/Translator.cs @@ -298,7 +298,7 @@ namespace ARMeilleure.Translation _ptc.WriteCompiledFunction(address, funcSize, hash, highCq, compiledFunc); } - GuestFunction func = compiledFunc.MapWithPointer(out IntPtr funcPointer); + GuestFunction func = compiledFunc.MapWithPointer(out nint funcPointer); Allocators.ResetAll(); diff --git a/src/ARMeilleure/Translation/TranslatorStubs.cs b/src/ARMeilleure/Translation/TranslatorStubs.cs index d80823a8b..364cca13c 100644 --- a/src/ARMeilleure/Translation/TranslatorStubs.cs +++ b/src/ARMeilleure/Translation/TranslatorStubs.cs @@ -15,12 +15,12 @@ namespace ARMeilleure.Translation /// class TranslatorStubs : IDisposable { - private readonly Lazy _slowDispatchStub; + private readonly Lazy _slowDispatchStub; private bool _disposed; private readonly AddressTable _functionTable; - private readonly Lazy _dispatchStub; + private readonly Lazy _dispatchStub; private readonly Lazy _dispatchLoop; private readonly Lazy _contextWrapper; @@ -28,7 +28,7 @@ namespace ARMeilleure.Translation /// Gets the dispatch stub. /// /// instance was disposed - public IntPtr DispatchStub + public nint DispatchStub { get { @@ -42,7 +42,7 @@ namespace ARMeilleure.Translation /// Gets the slow dispatch stub. /// /// instance was disposed - public IntPtr SlowDispatchStub + public nint SlowDispatchStub { get { @@ -140,7 +140,7 @@ namespace ARMeilleure.Translation /// Generates a . /// /// Generated - private IntPtr GenerateDispatchStub() + private nint GenerateDispatchStub() { var context = new EmitterContext(); @@ -198,7 +198,7 @@ namespace ARMeilleure.Translation /// Generates a . /// /// Generated - private IntPtr GenerateSlowDispatchStub() + private nint GenerateSlowDispatchStub() { var context = new EmitterContext(); diff --git a/src/ARMeilleure/Translation/TranslatorTestMethods.cs b/src/ARMeilleure/Translation/TranslatorTestMethods.cs index 8cc7a3cf8..186780daa 100644 --- a/src/ARMeilleure/Translation/TranslatorTestMethods.cs +++ b/src/ARMeilleure/Translation/TranslatorTestMethods.cs @@ -9,7 +9,7 @@ namespace ARMeilleure.Translation { public static class TranslatorTestMethods { - public delegate int FpFlagsPInvokeTest(IntPtr managedMethod); + public delegate int FpFlagsPInvokeTest(nint managedMethod); private static bool SetPlatformFtz(EmitterContext context, bool ftz) { diff --git a/src/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceDriver.cs b/src/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceDriver.cs index e39bfe549..acd1582ec 100644 --- a/src/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceDriver.cs +++ b/src/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceDriver.cs @@ -26,7 +26,7 @@ namespace Ryujinx.Audio.Backends.SDL2 // NOTE: We use a DllImport here because of marshaling issue for spec. #pragma warning disable SYSLIB1054 [DllImport("SDL2")] - private static extern int SDL_GetDefaultAudioInfo(IntPtr name, out SDL_AudioSpec spec, int isCapture); + private static extern int SDL_GetDefaultAudioInfo(nint name, out SDL_AudioSpec spec, int isCapture); #pragma warning restore SYSLIB1054 public SDL2HardwareDeviceDriver() @@ -37,7 +37,7 @@ namespace Ryujinx.Audio.Backends.SDL2 SDL2Driver.Instance.Initialize(); - int res = SDL_GetDefaultAudioInfo(IntPtr.Zero, out var spec, 0); + int res = SDL_GetDefaultAudioInfo(nint.Zero, out var spec, 0); if (res != 0) { @@ -136,7 +136,7 @@ namespace Ryujinx.Audio.Backends.SDL2 desired.callback = callback; - uint device = SDL_OpenAudioDevice(IntPtr.Zero, 0, ref desired, out SDL_AudioSpec got, 0); + uint device = SDL_OpenAudioDevice(nint.Zero, 0, ref desired, out SDL_AudioSpec got, 0); if (device == 0) { diff --git a/src/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceSession.cs b/src/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceSession.cs index 4eb75a578..51cd43c55 100644 --- a/src/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceSession.cs +++ b/src/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceSession.cs @@ -72,7 +72,7 @@ namespace Ryujinx.Audio.Backends.SDL2 } } - private unsafe void Update(IntPtr userdata, IntPtr stream, int streamLength) + private unsafe void Update(nint userdata, nint stream, int streamLength) { Span streamSpan = new((void*)stream, streamLength); @@ -97,7 +97,7 @@ namespace Ryujinx.Audio.Backends.SDL2 fixed (byte* p = samples) { - IntPtr pStreamSrc = (IntPtr)p; + nint pStreamSrc = (nint)p; // Zero the dest buffer streamSpan.Clear(); diff --git a/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIo.cs b/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIo.cs index 7fdb1fc04..9decd79fc 100644 --- a/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIo.cs +++ b/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIo.cs @@ -10,41 +10,41 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native private const string LibraryName = "libsoundio"; [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnDeviceChangeNativeDelegate(IntPtr ctx); + public delegate void OnDeviceChangeNativeDelegate(nint ctx); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnBackendDisconnectedDelegate(IntPtr ctx, SoundIoError err); + public delegate void OnBackendDisconnectedDelegate(nint ctx, SoundIoError err); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnEventsSignalDelegate(IntPtr ctx); + public delegate void OnEventsSignalDelegate(nint ctx); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void EmitRtPrioWarningDelegate(); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void JackCallbackDelegate(IntPtr msg); + public delegate void JackCallbackDelegate(nint msg); [StructLayout(LayoutKind.Sequential)] public struct SoundIoStruct { - public IntPtr UserData; - public IntPtr OnDeviceChange; - public IntPtr OnBackendDisconnected; - public IntPtr OnEventsSignal; + public nint UserData; + public nint OnDeviceChange; + public nint OnBackendDisconnected; + public nint OnEventsSignal; public SoundIoBackend CurrentBackend; - public IntPtr ApplicationName; - public IntPtr EmitRtPrioWarning; - public IntPtr JackInfoCallback; - public IntPtr JackErrorCallback; + public nint ApplicationName; + public nint EmitRtPrioWarning; + public nint JackInfoCallback; + public nint JackErrorCallback; } public struct SoundIoChannelLayout { - public IntPtr Name; + public nint Name; public int ChannelCount; public Array24 Channels; - public static IntPtr GetDefault(int channelCount) + public static nint GetDefault(int channelCount) { return soundio_channel_layout_get_default(channelCount); } @@ -63,17 +63,17 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native public struct SoundIoDevice { - public IntPtr SoundIo; - public IntPtr Id; - public IntPtr Name; + public nint SoundIo; + public nint Id; + public nint Name; public SoundIoDeviceAim Aim; - public IntPtr Layouts; + public nint Layouts; public int LayoutCount; public SoundIoChannelLayout CurrentLayout; - public IntPtr Formats; + public nint Formats; public int FormatCount; public SoundIoFormat CurrentFormat; - public IntPtr SampleRates; + public nint SampleRates; public int SampleRateCount; public int SampleRateCurrent; public double SoftwareLatencyMin; @@ -86,17 +86,17 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native public struct SoundIoOutStream { - public IntPtr Device; + public nint Device; public SoundIoFormat Format; public int SampleRate; public SoundIoChannelLayout Layout; public double SoftwareLatency; public float Volume; - public IntPtr UserData; - public IntPtr WriteCallback; - public IntPtr UnderflowCallback; - public IntPtr ErrorCallback; - public IntPtr Name; + public nint UserData; + public nint WriteCallback; + public nint UnderflowCallback; + public nint ErrorCallback; + public nint Name; public bool NonTerminalHint; public int BytesPerFrame; public int BytesPerSample; @@ -105,74 +105,74 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native public struct SoundIoChannelArea { - public IntPtr Pointer; + public nint Pointer; public int Step; } [LibraryImport(LibraryName)] - internal static partial IntPtr soundio_create(); + internal static partial nint soundio_create(); [LibraryImport(LibraryName)] - internal static partial SoundIoError soundio_connect(IntPtr ctx); + internal static partial SoundIoError soundio_connect(nint ctx); [LibraryImport(LibraryName)] - internal static partial void soundio_disconnect(IntPtr ctx); + internal static partial void soundio_disconnect(nint ctx); [LibraryImport(LibraryName)] - internal static partial void soundio_flush_events(IntPtr ctx); + internal static partial void soundio_flush_events(nint ctx); [LibraryImport(LibraryName)] - internal static partial int soundio_output_device_count(IntPtr ctx); + internal static partial int soundio_output_device_count(nint ctx); [LibraryImport(LibraryName)] - internal static partial int soundio_default_output_device_index(IntPtr ctx); + internal static partial int soundio_default_output_device_index(nint ctx); [LibraryImport(LibraryName)] - internal static partial IntPtr soundio_get_output_device(IntPtr ctx, int index); + internal static partial nint soundio_get_output_device(nint ctx, int index); [LibraryImport(LibraryName)] [return: MarshalAs(UnmanagedType.Bool)] - internal static partial bool soundio_device_supports_format(IntPtr devCtx, SoundIoFormat format); + internal static partial bool soundio_device_supports_format(nint devCtx, SoundIoFormat format); [LibraryImport(LibraryName)] [return: MarshalAs(UnmanagedType.Bool)] - internal static partial bool soundio_device_supports_layout(IntPtr devCtx, IntPtr layout); + internal static partial bool soundio_device_supports_layout(nint devCtx, nint layout); [LibraryImport(LibraryName)] [return: MarshalAs(UnmanagedType.Bool)] - internal static partial bool soundio_device_supports_sample_rate(IntPtr devCtx, int sampleRate); + internal static partial bool soundio_device_supports_sample_rate(nint devCtx, int sampleRate); [LibraryImport(LibraryName)] - internal static partial IntPtr soundio_outstream_create(IntPtr devCtx); + internal static partial nint soundio_outstream_create(nint devCtx); [LibraryImport(LibraryName)] - internal static partial SoundIoError soundio_outstream_open(IntPtr outStreamCtx); + internal static partial SoundIoError soundio_outstream_open(nint outStreamCtx); [LibraryImport(LibraryName)] - internal static partial SoundIoError soundio_outstream_start(IntPtr outStreamCtx); + internal static partial SoundIoError soundio_outstream_start(nint outStreamCtx); [LibraryImport(LibraryName)] - internal static partial SoundIoError soundio_outstream_begin_write(IntPtr outStreamCtx, IntPtr areas, IntPtr frameCount); + internal static partial SoundIoError soundio_outstream_begin_write(nint outStreamCtx, nint areas, nint frameCount); [LibraryImport(LibraryName)] - internal static partial SoundIoError soundio_outstream_end_write(IntPtr outStreamCtx); + internal static partial SoundIoError soundio_outstream_end_write(nint outStreamCtx); [LibraryImport(LibraryName)] - internal static partial SoundIoError soundio_outstream_pause(IntPtr devCtx, [MarshalAs(UnmanagedType.Bool)] bool pause); + internal static partial SoundIoError soundio_outstream_pause(nint devCtx, [MarshalAs(UnmanagedType.Bool)] bool pause); [LibraryImport(LibraryName)] - internal static partial SoundIoError soundio_outstream_set_volume(IntPtr devCtx, double volume); + internal static partial SoundIoError soundio_outstream_set_volume(nint devCtx, double volume); [LibraryImport(LibraryName)] - internal static partial void soundio_outstream_destroy(IntPtr streamCtx); + internal static partial void soundio_outstream_destroy(nint streamCtx); [LibraryImport(LibraryName)] - internal static partial void soundio_destroy(IntPtr ctx); + internal static partial void soundio_destroy(nint ctx); [LibraryImport(LibraryName)] - internal static partial IntPtr soundio_channel_layout_get_default(int channelCount); + internal static partial nint soundio_channel_layout_get_default(int channelCount); [LibraryImport(LibraryName)] - internal static partial IntPtr soundio_strerror(SoundIoError err); + internal static partial nint soundio_strerror(SoundIoError err); } } diff --git a/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoContext.cs b/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoContext.cs index f2e91fcd7..a881e8ffe 100644 --- a/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoContext.cs +++ b/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoContext.cs @@ -8,13 +8,13 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native { public class SoundIoContext : IDisposable { - private IntPtr _context; + private nint _context; private Action _onBackendDisconnect; private OnBackendDisconnectedDelegate _onBackendDisconnectNative; - public IntPtr Context => _context; + public nint Context => _context; - internal SoundIoContext(IntPtr context) + internal SoundIoContext(nint context) { _context = context; _onBackendDisconnect = null; @@ -60,9 +60,9 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native public SoundIoDeviceContext GetOutputDevice(int index) { - IntPtr deviceContext = soundio_get_output_device(_context, index); + nint deviceContext = soundio_get_output_device(_context, index); - if (deviceContext == IntPtr.Zero) + if (deviceContext == nint.Zero) { return null; } @@ -72,9 +72,9 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native public static SoundIoContext Create() { - IntPtr context = soundio_create(); + nint context = soundio_create(); - if (context == IntPtr.Zero) + if (context == nint.Zero) { return null; } @@ -84,9 +84,9 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native protected virtual void Dispose(bool disposing) { - IntPtr currentContext = Interlocked.Exchange(ref _context, IntPtr.Zero); + nint currentContext = Interlocked.Exchange(ref _context, nint.Zero); - if (currentContext != IntPtr.Zero) + if (currentContext != nint.Zero) { soundio_destroy(currentContext); } diff --git a/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoDeviceContext.cs b/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoDeviceContext.cs index 7923e9b17..efea52b35 100644 --- a/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoDeviceContext.cs +++ b/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoDeviceContext.cs @@ -7,11 +7,11 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native { public class SoundIoDeviceContext { - private readonly IntPtr _context; + private readonly nint _context; - public IntPtr Context => _context; + public nint Context => _context; - internal SoundIoDeviceContext(IntPtr context) + internal SoundIoDeviceContext(nint context) { _context = context; } @@ -36,9 +36,9 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native public SoundIoOutStreamContext CreateOutStream() { - IntPtr context = soundio_outstream_create(_context); + nint context = soundio_outstream_create(_context); - if (context == IntPtr.Zero) + if (context == nint.Zero) { return null; } diff --git a/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoOutStreamContext.cs b/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoOutStreamContext.cs index 4148ea0dd..b1823a074 100644 --- a/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoOutStreamContext.cs +++ b/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoOutStreamContext.cs @@ -8,19 +8,19 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native public class SoundIoOutStreamContext : IDisposable { [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private unsafe delegate void WriteCallbackDelegate(IntPtr ctx, int frameCountMin, int frameCountMax); + private unsafe delegate void WriteCallbackDelegate(nint ctx, int frameCountMin, int frameCountMax); - private IntPtr _context; - private IntPtr _nameStored; + private nint _context; + private nint _nameStored; private Action _writeCallback; private WriteCallbackDelegate _writeCallbackNative; - public IntPtr Context => _context; + public nint Context => _context; - internal SoundIoOutStreamContext(IntPtr context) + internal SoundIoOutStreamContext(nint context) { _context = context; - _nameStored = IntPtr.Zero; + _nameStored = nint.Zero; _writeCallback = null; _writeCallbackNative = null; } @@ -40,7 +40,7 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native { var context = GetOutContext(); - if (_nameStored != IntPtr.Zero && context.Name == _nameStored) + if (_nameStored != nint.Zero && context.Name == _nameStored) { Marshal.FreeHGlobal(_nameStored); } @@ -124,14 +124,14 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native public Span BeginWrite(ref int frameCount) { - IntPtr arenas = default; + nint arenas = default; int nativeFrameCount = frameCount; unsafe { var frameCountPtr = &nativeFrameCount; var arenasPtr = &arenas; - CheckError(soundio_outstream_begin_write(_context, (IntPtr)arenasPtr, (IntPtr)frameCountPtr)); + CheckError(soundio_outstream_begin_write(_context, (nint)arenasPtr, (nint)frameCountPtr)); frameCount = *frameCountPtr; @@ -143,10 +143,10 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native protected virtual void Dispose(bool disposing) { - if (_context != IntPtr.Zero) + if (_context != nint.Zero) { soundio_outstream_destroy(_context); - _context = IntPtr.Zero; + _context = nint.Zero; } } diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/CommandList.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/CommandList.cs index 3fe106ddf..ba19330b6 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/CommandList.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/CommandList.cs @@ -64,11 +64,11 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public unsafe IntPtr GetBufferPointer(int index) + public unsafe nint GetBufferPointer(int index) { if (index >= 0 && index < _buffersEntryCount) { - return (IntPtr)((float*)_buffersMemoryHandle.Pointer + index * _sampleCount); + return (nint)((float*)_buffersMemoryHandle.Pointer + index * _sampleCount); } throw new ArgumentOutOfRangeException(nameof(index), index, null); diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/CompressorCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/CompressorCommand.cs index 33f61e6a5..c6c0956a6 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/CompressorCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/CompressorCommand.cs @@ -82,8 +82,8 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command statistics.Reset(_parameter.ChannelCount); } - Span inputBuffers = stackalloc IntPtr[_parameter.ChannelCount]; - Span outputBuffers = stackalloc IntPtr[_parameter.ChannelCount]; + Span inputBuffers = stackalloc nint[_parameter.ChannelCount]; + Span outputBuffers = stackalloc nint[_parameter.ChannelCount]; Span channelInput = stackalloc float[_parameter.ChannelCount]; ExponentialMovingAverage inputMovingAverage = state.InputMovingAverage; float unknown4 = state.Unknown4; diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/DelayCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/DelayCommand.cs index 6fa3777f4..21cf69504 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/DelayCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/DelayCommand.cs @@ -77,7 +77,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - private unsafe void ProcessDelayStereo(ref DelayState state, Span outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) + private unsafe void ProcessDelayStereo(ref DelayState state, Span outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { const ushort ChannelCount = 2; @@ -114,7 +114,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - private unsafe void ProcessDelayQuadraphonic(ref DelayState state, Span outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) + private unsafe void ProcessDelayQuadraphonic(ref DelayState state, Span outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { const ushort ChannelCount = 4; @@ -160,7 +160,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - private unsafe void ProcessDelaySurround(ref DelayState state, Span outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) + private unsafe void ProcessDelaySurround(ref DelayState state, Span outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { const ushort ChannelCount = 6; @@ -219,8 +219,8 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command if (IsEffectEnabled && Parameter.IsChannelCountValid()) { - Span inputBuffers = stackalloc IntPtr[Parameter.ChannelCount]; - Span outputBuffers = stackalloc IntPtr[Parameter.ChannelCount]; + Span inputBuffers = stackalloc nint[Parameter.ChannelCount]; + Span outputBuffers = stackalloc nint[Parameter.ChannelCount]; for (int i = 0; i < Parameter.ChannelCount; i++) { diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion1.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion1.cs index 06e932199..4e7f67e78 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion1.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion1.cs @@ -70,8 +70,8 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command if (IsEffectEnabled && _parameter.IsChannelCountValid()) { - Span inputBuffers = stackalloc IntPtr[_parameter.ChannelCount]; - Span outputBuffers = stackalloc IntPtr[_parameter.ChannelCount]; + Span inputBuffers = stackalloc nint[_parameter.ChannelCount]; + Span outputBuffers = stackalloc nint[_parameter.ChannelCount]; for (int i = 0; i < _parameter.ChannelCount; i++) { diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs index ed0538c06..b0032c5b7 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs @@ -88,8 +88,8 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command statistics.Reset(); } - Span inputBuffers = stackalloc IntPtr[_parameter.ChannelCount]; - Span outputBuffers = stackalloc IntPtr[_parameter.ChannelCount]; + Span inputBuffers = stackalloc nint[_parameter.ChannelCount]; + Span outputBuffers = stackalloc nint[_parameter.ChannelCount]; for (int i = 0; i < _parameter.ChannelCount; i++) { diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/Reverb3dCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/Reverb3dCommand.cs index 8cdd4843b..58023ac9d 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/Reverb3dCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/Reverb3dCommand.cs @@ -71,30 +71,30 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void ProcessReverb3dMono(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) + private void ProcessReverb3dMono(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { ProcessReverb3dGeneric(ref state, outputBuffers, inputBuffers, sampleCount, _outputEarlyIndicesTableMono, _targetEarlyDelayLineIndicesTableMono, _targetOutputFeedbackIndicesTableMono); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void ProcessReverb3dStereo(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) + private void ProcessReverb3dStereo(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { ProcessReverb3dGeneric(ref state, outputBuffers, inputBuffers, sampleCount, _outputEarlyIndicesTableStereo, _targetEarlyDelayLineIndicesTableStereo, _targetOutputFeedbackIndicesTableStereo); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void ProcessReverb3dQuadraphonic(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) + private void ProcessReverb3dQuadraphonic(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { ProcessReverb3dGeneric(ref state, outputBuffers, inputBuffers, sampleCount, _outputEarlyIndicesTableQuadraphonic, _targetEarlyDelayLineIndicesTableQuadraphonic, _targetOutputFeedbackIndicesTableQuadraphonic); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void ProcessReverb3dSurround(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) + private void ProcessReverb3dSurround(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { ProcessReverb3dGeneric(ref state, outputBuffers, inputBuffers, sampleCount, _outputEarlyIndicesTableSurround, _targetEarlyDelayLineIndicesTableSurround, _targetOutputFeedbackIndicesTableSurround); } - private unsafe void ProcessReverb3dGeneric(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount, ReadOnlySpan outputEarlyIndicesTable, ReadOnlySpan targetEarlyDelayLineIndicesTable, ReadOnlySpan targetOutputFeedbackIndicesTable) + private unsafe void ProcessReverb3dGeneric(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount, ReadOnlySpan outputEarlyIndicesTable, ReadOnlySpan targetEarlyDelayLineIndicesTable, ReadOnlySpan targetOutputFeedbackIndicesTable) { const int DelayLineSampleIndexOffset = 1; @@ -193,8 +193,8 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command if (IsEffectEnabled && Parameter.IsChannelCountValid()) { - Span inputBuffers = stackalloc IntPtr[Parameter.ChannelCount]; - Span outputBuffers = stackalloc IntPtr[Parameter.ChannelCount]; + Span inputBuffers = stackalloc nint[Parameter.ChannelCount]; + Span outputBuffers = stackalloc nint[Parameter.ChannelCount]; for (int i = 0; i < Parameter.ChannelCount; i++) { diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/ReverbCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/ReverbCommand.cs index 874eb8e8b..204570cec 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/ReverbCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/ReverbCommand.cs @@ -77,7 +77,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void ProcessReverbMono(ref ReverbState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) + private void ProcessReverbMono(ref ReverbState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { ProcessReverbGeneric( ref state, @@ -91,7 +91,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void ProcessReverbStereo(ref ReverbState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) + private void ProcessReverbStereo(ref ReverbState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { ProcessReverbGeneric( ref state, @@ -105,7 +105,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void ProcessReverbQuadraphonic(ref ReverbState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) + private void ProcessReverbQuadraphonic(ref ReverbState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { ProcessReverbGeneric( ref state, @@ -119,7 +119,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void ProcessReverbSurround(ref ReverbState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) + private void ProcessReverbSurround(ref ReverbState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { ProcessReverbGeneric( ref state, @@ -132,7 +132,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command _outputIndicesTableSurround); } - private unsafe void ProcessReverbGeneric(ref ReverbState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount, ReadOnlySpan outputEarlyIndicesTable, ReadOnlySpan targetEarlyDelayLineIndicesTable, ReadOnlySpan targetOutputFeedbackIndicesTable, ReadOnlySpan outputIndicesTable) + private unsafe void ProcessReverbGeneric(ref ReverbState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount, ReadOnlySpan outputEarlyIndicesTable, ReadOnlySpan targetEarlyDelayLineIndicesTable, ReadOnlySpan targetOutputFeedbackIndicesTable, ReadOnlySpan outputIndicesTable) { bool isSurround = Parameter.ChannelCount == 6; @@ -223,8 +223,8 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command if (IsEffectEnabled && Parameter.IsChannelCountValid()) { - Span inputBuffers = stackalloc IntPtr[Parameter.ChannelCount]; - Span outputBuffers = stackalloc IntPtr[Parameter.ChannelCount]; + Span inputBuffers = stackalloc nint[Parameter.ChannelCount]; + Span outputBuffers = stackalloc nint[Parameter.ChannelCount]; for (int i = 0; i < Parameter.ChannelCount; i++) { diff --git a/src/Ryujinx.Audio/Renderer/Server/MemoryPool/AddressInfo.cs b/src/Ryujinx.Audio/Renderer/Server/MemoryPool/AddressInfo.cs index a7ec4cf51..3337e44b0 100644 --- a/src/Ryujinx.Audio/Renderer/Server/MemoryPool/AddressInfo.cs +++ b/src/Ryujinx.Audio/Renderer/Server/MemoryPool/AddressInfo.cs @@ -29,7 +29,7 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool private readonly unsafe ref MemoryPoolState MemoryPoolState => ref *_memoryPools; - public readonly unsafe bool HasMemoryPoolState => (IntPtr)_memoryPools != IntPtr.Zero; + public readonly unsafe bool HasMemoryPoolState => (nint)_memoryPools != nint.Zero; /// /// Create an new empty . diff --git a/src/Ryujinx.Audio/Renderer/Server/MemoryPool/MemoryPoolState.cs b/src/Ryujinx.Audio/Renderer/Server/MemoryPool/MemoryPoolState.cs index 91bd5dbf5..d0133622a 100644 --- a/src/Ryujinx.Audio/Renderer/Server/MemoryPool/MemoryPoolState.cs +++ b/src/Ryujinx.Audio/Renderer/Server/MemoryPool/MemoryPoolState.cs @@ -55,7 +55,7 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool [MarshalAs(UnmanagedType.I1)] public bool IsUsed; - public static unsafe MemoryPoolState* Null => (MemoryPoolState*)IntPtr.Zero.ToPointer(); + public static unsafe MemoryPoolState* Null => (MemoryPoolState*)nint.Zero.ToPointer(); /// /// Create a new with the given . diff --git a/src/Ryujinx.Audio/Renderer/Server/Mix/MixState.cs b/src/Ryujinx.Audio/Renderer/Server/Mix/MixState.cs index 5ba58ea5b..34b3ed4bd 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Mix/MixState.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Mix/MixState.cs @@ -65,7 +65,7 @@ namespace Ryujinx.Audio.Renderer.Server.Mix /// /// The effect processing order storage. /// - private readonly IntPtr _effectProcessingOrderArrayPointer; + private readonly nint _effectProcessingOrderArrayPointer; /// /// The max element count that can be found in the effect processing order storage. @@ -123,7 +123,7 @@ namespace Ryujinx.Audio.Renderer.Server.Mix { get { - if (_effectProcessingOrderArrayPointer == IntPtr.Zero) + if (_effectProcessingOrderArrayPointer == nint.Zero) { return Span.Empty; } @@ -153,7 +153,7 @@ namespace Ryujinx.Audio.Renderer.Server.Mix unsafe { // SAFETY: safe as effectProcessingOrderArray comes from the work buffer memory that is pinned. - _effectProcessingOrderArrayPointer = (IntPtr)Unsafe.AsPointer(ref MemoryMarshal.GetReference(effectProcessingOrderArray.Span)); + _effectProcessingOrderArrayPointer = (nint)Unsafe.AsPointer(ref MemoryMarshal.GetReference(effectProcessingOrderArray.Span)); } EffectProcessingOrderArrayMaxCount = (uint)effectProcessingOrderArray.Length; diff --git a/src/Ryujinx.Common/GraphicsDriver/NVThreadedOptimization.cs b/src/Ryujinx.Common/GraphicsDriver/NVThreadedOptimization.cs index a8036ed90..c1e9e8fbb 100644 --- a/src/Ryujinx.Common/GraphicsDriver/NVThreadedOptimization.cs +++ b/src/Ryujinx.Common/GraphicsDriver/NVThreadedOptimization.cs @@ -21,33 +21,33 @@ namespace Ryujinx.Common.GraphicsDriver private const uint NvAPI_DRS_DestroySession_ID = 0x0DAD9CFF8; [LibraryImport("nvapi64")] - private static partial IntPtr nvapi_QueryInterface(uint id); + private static partial nint nvapi_QueryInterface(uint id); private delegate int NvAPI_InitializeDelegate(); private static NvAPI_InitializeDelegate NvAPI_Initialize; - private delegate int NvAPI_DRS_CreateSessionDelegate(out IntPtr handle); + private delegate int NvAPI_DRS_CreateSessionDelegate(out nint handle); private static NvAPI_DRS_CreateSessionDelegate NvAPI_DRS_CreateSession; - private delegate int NvAPI_DRS_LoadSettingsDelegate(IntPtr handle); + private delegate int NvAPI_DRS_LoadSettingsDelegate(nint handle); private static NvAPI_DRS_LoadSettingsDelegate NvAPI_DRS_LoadSettings; - private delegate int NvAPI_DRS_FindProfileByNameDelegate(IntPtr handle, NvapiUnicodeString profileName, out IntPtr profileHandle); + private delegate int NvAPI_DRS_FindProfileByNameDelegate(nint handle, NvapiUnicodeString profileName, out nint profileHandle); private static NvAPI_DRS_FindProfileByNameDelegate NvAPI_DRS_FindProfileByName; - private delegate int NvAPI_DRS_CreateProfileDelegate(IntPtr handle, ref NvdrsProfile profileInfo, out IntPtr profileHandle); + private delegate int NvAPI_DRS_CreateProfileDelegate(nint handle, ref NvdrsProfile profileInfo, out nint profileHandle); private static NvAPI_DRS_CreateProfileDelegate NvAPI_DRS_CreateProfile; - private delegate int NvAPI_DRS_CreateApplicationDelegate(IntPtr handle, IntPtr profileHandle, ref NvdrsApplicationV4 app); + private delegate int NvAPI_DRS_CreateApplicationDelegate(nint handle, nint profileHandle, ref NvdrsApplicationV4 app); private static NvAPI_DRS_CreateApplicationDelegate NvAPI_DRS_CreateApplication; - private delegate int NvAPI_DRS_SetSettingDelegate(IntPtr handle, IntPtr profileHandle, ref NvdrsSetting setting); + private delegate int NvAPI_DRS_SetSettingDelegate(nint handle, nint profileHandle, ref NvdrsSetting setting); private static NvAPI_DRS_SetSettingDelegate NvAPI_DRS_SetSetting; - private delegate int NvAPI_DRS_SaveSettingsDelegate(IntPtr handle); + private delegate int NvAPI_DRS_SaveSettingsDelegate(nint handle); private static NvAPI_DRS_SaveSettingsDelegate NvAPI_DRS_SaveSettings; - private delegate int NvAPI_DRS_DestroySessionDelegate(IntPtr handle); + private delegate int NvAPI_DRS_DestroySessionDelegate(nint handle); private static NvAPI_DRS_DestroySessionDelegate NvAPI_DRS_DestroySession; private static bool _initialized; @@ -94,7 +94,7 @@ namespace Ryujinx.Common.GraphicsDriver Check(NvAPI_Initialize()); - Check(NvAPI_DRS_CreateSession(out IntPtr handle)); + Check(NvAPI_DRS_CreateSession(out nint handle)); Check(NvAPI_DRS_LoadSettings(handle)); @@ -148,9 +148,9 @@ namespace Ryujinx.Common.GraphicsDriver private static T NvAPI_Delegate(uint id) where T : class { - IntPtr ptr = nvapi_QueryInterface(id); + nint ptr = nvapi_QueryInterface(id); - if (ptr != IntPtr.Zero) + if (ptr != nint.Zero) { return Marshal.GetDelegateForFunctionPointer(ptr); } diff --git a/src/Ryujinx.Common/Memory/ArrayPtr.cs b/src/Ryujinx.Common/Memory/ArrayPtr.cs index 7487a1ff5..a54bdb3f6 100644 --- a/src/Ryujinx.Common/Memory/ArrayPtr.cs +++ b/src/Ryujinx.Common/Memory/ArrayPtr.cs @@ -11,17 +11,17 @@ namespace Ryujinx.Common.Memory /// Array element type public unsafe struct ArrayPtr : IEquatable>, IArray where T : unmanaged { - private IntPtr _ptr; + private nint _ptr; /// /// Null pointer. /// - public static ArrayPtr Null => new() { _ptr = IntPtr.Zero }; + public static ArrayPtr Null => new() { _ptr = nint.Zero }; /// /// True if the pointer is null, false otherwise. /// - public readonly bool IsNull => _ptr == IntPtr.Zero; + public readonly bool IsNull => _ptr == nint.Zero; /// /// Number of elements on the array. @@ -50,7 +50,7 @@ namespace Ryujinx.Common.Memory /// Number of elements on the array public ArrayPtr(ref T value, int length) { - _ptr = (IntPtr)Unsafe.AsPointer(ref value); + _ptr = (nint)Unsafe.AsPointer(ref value); Length = length; } @@ -61,7 +61,7 @@ namespace Ryujinx.Common.Memory /// Number of elements on the array public ArrayPtr(T* ptr, int length) { - _ptr = (IntPtr)ptr; + _ptr = (nint)ptr; Length = length; } @@ -70,7 +70,7 @@ namespace Ryujinx.Common.Memory /// /// Array base pointer /// Number of elements on the array - public ArrayPtr(IntPtr ptr, int length) + public ArrayPtr(nint ptr, int length) { _ptr = ptr; Length = length; diff --git a/src/Ryujinx.Common/Memory/PartialUnmaps/PartialUnmapState.cs b/src/Ryujinx.Common/Memory/PartialUnmaps/PartialUnmapState.cs index 93fef5c3b..60fdd7af6 100644 --- a/src/Ryujinx.Common/Memory/PartialUnmaps/PartialUnmapState.cs +++ b/src/Ryujinx.Common/Memory/PartialUnmaps/PartialUnmapState.cs @@ -21,7 +21,7 @@ namespace Ryujinx.Common.Memory.PartialUnmaps public readonly static int PartialUnmapsCountOffset; public readonly static int LocalCountsOffset; - public readonly static IntPtr GlobalState; + public readonly static nint GlobalState; [SupportedOSPlatform("windows")] [LibraryImport("kernel32.dll")] @@ -29,17 +29,17 @@ namespace Ryujinx.Common.Memory.PartialUnmaps [SupportedOSPlatform("windows")] [LibraryImport("kernel32.dll", SetLastError = true)] - private static partial IntPtr OpenThread(int dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, uint dwThreadId); + private static partial nint OpenThread(int dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, uint dwThreadId); [SupportedOSPlatform("windows")] [LibraryImport("kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - private static partial bool CloseHandle(IntPtr hObject); + private static partial bool CloseHandle(nint hObject); [SupportedOSPlatform("windows")] [LibraryImport("kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - private static partial bool GetExitCodeThread(IntPtr hThread, out uint lpExitCode); + private static partial bool GetExitCodeThread(nint hThread, out uint lpExitCode); /// /// Creates a global static PartialUnmapState and populates the field offsets. @@ -137,9 +137,9 @@ namespace Ryujinx.Common.Memory.PartialUnmaps if (id != 0) { - IntPtr handle = OpenThread(ThreadQueryInformation, false, (uint)id); + nint handle = OpenThread(ThreadQueryInformation, false, (uint)id); - if (handle == IntPtr.Zero) + if (handle == nint.Zero) { Interlocked.CompareExchange(ref ids[i], 0, id); } diff --git a/src/Ryujinx.Common/Memory/Ptr.cs b/src/Ryujinx.Common/Memory/Ptr.cs index d01748c16..3a8c1e1b6 100644 --- a/src/Ryujinx.Common/Memory/Ptr.cs +++ b/src/Ryujinx.Common/Memory/Ptr.cs @@ -10,17 +10,17 @@ namespace Ryujinx.Common.Memory /// Type of the unmanaged resource public unsafe struct Ptr : IEquatable> where T : unmanaged { - private IntPtr _ptr; + private nint _ptr; /// /// Null pointer. /// - public static Ptr Null => new() { _ptr = IntPtr.Zero }; + public static Ptr Null => new() { _ptr = nint.Zero }; /// /// True if the pointer is null, false otherwise. /// - public readonly bool IsNull => _ptr == IntPtr.Zero; + public readonly bool IsNull => _ptr == nint.Zero; /// /// Gets a reference to the value. @@ -37,7 +37,7 @@ namespace Ryujinx.Common.Memory /// Reference to the unmanaged resource public Ptr(ref T value) { - _ptr = (IntPtr)Unsafe.AsPointer(ref value); + _ptr = (nint)Unsafe.AsPointer(ref value); } public readonly override bool Equals(object obj) diff --git a/src/Ryujinx.Common/SystemInterop/ForceDpiAware.cs b/src/Ryujinx.Common/SystemInterop/ForceDpiAware.cs index b8e1df7d2..330638171 100644 --- a/src/Ryujinx.Common/SystemInterop/ForceDpiAware.cs +++ b/src/Ryujinx.Common/SystemInterop/ForceDpiAware.cs @@ -14,19 +14,19 @@ namespace Ryujinx.Common.SystemInterop private const string X11LibraryName = "libX11.so.6"; [LibraryImport(X11LibraryName)] - private static partial IntPtr XOpenDisplay([MarshalAs(UnmanagedType.LPStr)] string display); + private static partial nint XOpenDisplay([MarshalAs(UnmanagedType.LPStr)] string display); [LibraryImport(X11LibraryName)] - private static partial IntPtr XGetDefault(IntPtr display, [MarshalAs(UnmanagedType.LPStr)] string program, [MarshalAs(UnmanagedType.LPStr)] string option); + private static partial nint XGetDefault(nint display, [MarshalAs(UnmanagedType.LPStr)] string program, [MarshalAs(UnmanagedType.LPStr)] string option); [LibraryImport(X11LibraryName)] - private static partial int XDisplayWidth(IntPtr display, int screenNumber); + private static partial int XDisplayWidth(nint display, int screenNumber); [LibraryImport(X11LibraryName)] - private static partial int XDisplayWidthMM(IntPtr display, int screenNumber); + private static partial int XDisplayWidthMM(nint display, int screenNumber); [LibraryImport(X11LibraryName)] - private static partial int XCloseDisplay(IntPtr display); + private static partial int XCloseDisplay(nint display); private const double StandardDpiScale = 96.0; private const double MaxScaleFactor = 1.25; @@ -51,7 +51,7 @@ namespace Ryujinx.Common.SystemInterop { if (OperatingSystem.IsWindows()) { - userDpiScale = GdiPlusHelper.GetDpiX(IntPtr.Zero); + userDpiScale = GdiPlusHelper.GetDpiX(nint.Zero); } else if (OperatingSystem.IsLinux()) { @@ -59,7 +59,7 @@ namespace Ryujinx.Common.SystemInterop if (xdgSessionType == null || xdgSessionType == "x11") { - IntPtr display = XOpenDisplay(null); + nint display = XOpenDisplay(null); string dpiString = Marshal.PtrToStringAnsi(XGetDefault(display, "Xft", "dpi")); if (dpiString == null || !double.TryParse(dpiString, NumberStyles.Any, CultureInfo.InvariantCulture, out userDpiScale)) { diff --git a/src/Ryujinx.Common/SystemInterop/GdiPlusHelper.cs b/src/Ryujinx.Common/SystemInterop/GdiPlusHelper.cs index 7e8e9f2a5..c00598c98 100644 --- a/src/Ryujinx.Common/SystemInterop/GdiPlusHelper.cs +++ b/src/Ryujinx.Common/SystemInterop/GdiPlusHelper.cs @@ -9,7 +9,7 @@ namespace Ryujinx.Common.SystemInterop { private const string LibraryName = "gdiplus.dll"; - private static readonly IntPtr _initToken; + private static readonly nint _initToken; static GdiPlusHelper() { @@ -29,7 +29,7 @@ namespace Ryujinx.Common.SystemInterop public int GdiplusVersion; #pragma warning disable CS0649 // Field is never assigned to - public IntPtr DebugEventCallback; + public nint DebugEventCallback; public int SuppressBackgroundThread; public int SuppressExternalCodecs; public int StartupParameters; @@ -39,7 +39,7 @@ namespace Ryujinx.Common.SystemInterop { // We assume Windows 8 and upper GdiplusVersion = 2, - DebugEventCallback = IntPtr.Zero, + DebugEventCallback = nint.Zero, SuppressBackgroundThread = 0, SuppressExternalCodecs = 0, StartupParameters = 0, @@ -48,25 +48,25 @@ namespace Ryujinx.Common.SystemInterop private struct StartupOutput { - public IntPtr NotificationHook; - public IntPtr NotificationUnhook; + public nint NotificationHook; + public nint NotificationUnhook; } [LibraryImport(LibraryName)] - private static partial int GdiplusStartup(out IntPtr token, in StartupInputEx input, out StartupOutput output); + private static partial int GdiplusStartup(out nint token, in StartupInputEx input, out StartupOutput output); [LibraryImport(LibraryName)] - private static partial int GdipCreateFromHWND(IntPtr hwnd, out IntPtr graphics); + private static partial int GdipCreateFromHWND(nint hwnd, out nint graphics); [LibraryImport(LibraryName)] - private static partial int GdipDeleteGraphics(IntPtr graphics); + private static partial int GdipDeleteGraphics(nint graphics); [LibraryImport(LibraryName)] - private static partial int GdipGetDpiX(IntPtr graphics, out float dpi); + private static partial int GdipGetDpiX(nint graphics, out float dpi); - public static float GetDpiX(IntPtr hwnd) + public static float GetDpiX(nint hwnd) { - CheckStatus(GdipCreateFromHWND(hwnd, out IntPtr graphicsHandle)); + CheckStatus(GdipCreateFromHWND(hwnd, out nint graphicsHandle)); CheckStatus(GdipGetDpiX(graphicsHandle, out float result)); CheckStatus(GdipDeleteGraphics(graphicsHandle)); diff --git a/src/Ryujinx.Cpu/AppleHv/HvApi.cs b/src/Ryujinx.Cpu/AppleHv/HvApi.cs index e6e08111f..864f6b063 100644 --- a/src/Ryujinx.Cpu/AppleHv/HvApi.cs +++ b/src/Ryujinx.Cpu/AppleHv/HvApi.cs @@ -273,7 +273,7 @@ namespace Ryujinx.Cpu.AppleHv public static partial HvResult hv_vm_get_max_vcpu_count(out uint max_vcpu_count); [LibraryImport(LibraryName, SetLastError = true)] - public static partial HvResult hv_vm_create(IntPtr config); + public static partial HvResult hv_vm_create(nint config); [LibraryImport(LibraryName, SetLastError = true)] public static partial HvResult hv_vm_destroy(); @@ -288,7 +288,7 @@ namespace Ryujinx.Cpu.AppleHv public static partial HvResult hv_vm_protect(ulong ipa, ulong size, HvMemoryFlags flags); [LibraryImport(LibraryName, SetLastError = true)] - public unsafe static partial HvResult hv_vcpu_create(out ulong vcpu, ref HvVcpuExit* exit, IntPtr config); + public unsafe static partial HvResult hv_vcpu_create(out ulong vcpu, ref HvVcpuExit* exit, nint config); [LibraryImport(LibraryName, SetLastError = true)] public unsafe static partial HvResult hv_vcpu_destroy(ulong vcpu); diff --git a/src/Ryujinx.Cpu/AppleHv/HvExecutionContextVcpu.cs b/src/Ryujinx.Cpu/AppleHv/HvExecutionContextVcpu.cs index bb232940d..9d459d062 100644 --- a/src/Ryujinx.Cpu/AppleHv/HvExecutionContextVcpu.cs +++ b/src/Ryujinx.Cpu/AppleHv/HvExecutionContextVcpu.cs @@ -10,9 +10,9 @@ namespace Ryujinx.Cpu.AppleHv class HvExecutionContextVcpu : IHvExecutionContext { private static readonly MemoryBlock _setSimdFpRegFuncMem; - private delegate HvResult SetSimdFpReg(ulong vcpu, HvSimdFPReg reg, in V128 value, IntPtr funcPtr); + private delegate HvResult SetSimdFpReg(ulong vcpu, HvSimdFPReg reg, in V128 value, nint funcPtr); private static readonly SetSimdFpReg _setSimdFpReg; - private static readonly IntPtr _setSimdFpRegNativePtr; + private static readonly nint _setSimdFpRegNativePtr; static HvExecutionContextVcpu() { @@ -25,7 +25,7 @@ namespace Ryujinx.Cpu.AppleHv _setSimdFpReg = Marshal.GetDelegateForFunctionPointer(_setSimdFpRegFuncMem.Pointer); - if (NativeLibrary.TryLoad(HvApi.LibraryName, out IntPtr hvLibHandle)) + if (NativeLibrary.TryLoad(HvApi.LibraryName, out nint hvLibHandle)) { _setSimdFpRegNativePtr = NativeLibrary.GetExport(hvLibHandle, nameof(HvApi.hv_vcpu_set_simd_fp_reg)); } diff --git a/src/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs b/src/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs index abdddb31c..bb56a4344 100644 --- a/src/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs +++ b/src/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs @@ -32,7 +32,7 @@ namespace Ryujinx.Cpu.AppleHv public int AddressSpaceBits { get; } - public IntPtr PageTablePointer => IntPtr.Zero; + public nint PageTablePointer => nint.Zero; public MemoryManagerType Type => MemoryManagerType.SoftwarePageTable; @@ -244,7 +244,7 @@ namespace Ryujinx.Cpu.AppleHv for (int i = 0; i < regions.Length; i++) { var guestRegion = guestRegions[i]; - IntPtr pointer = _backingMemory.GetPointer(guestRegion.Address, guestRegion.Size); + nint pointer = _backingMemory.GetPointer(guestRegion.Address, guestRegion.Size); regions[i] = new HostMemoryRange((nuint)(ulong)pointer, guestRegion.Size); } diff --git a/src/Ryujinx.Cpu/AppleHv/HvVcpuPool.cs b/src/Ryujinx.Cpu/AppleHv/HvVcpuPool.cs index 2edcd7e4e..af124fc7a 100644 --- a/src/Ryujinx.Cpu/AppleHv/HvVcpuPool.cs +++ b/src/Ryujinx.Cpu/AppleHv/HvVcpuPool.cs @@ -72,7 +72,7 @@ namespace Ryujinx.Cpu.AppleHv // Create VCPU. HvVcpuExit* exitInfo = null; - HvApi.hv_vcpu_create(out ulong vcpuHandle, ref exitInfo, IntPtr.Zero).ThrowOnError(); + HvApi.hv_vcpu_create(out ulong vcpuHandle, ref exitInfo, nint.Zero).ThrowOnError(); // Enable FP and SIMD instructions. HvApi.hv_vcpu_set_sys_reg(vcpuHandle, HvSysReg.CPACR_EL1, 0b11 << 20).ThrowOnError(); diff --git a/src/Ryujinx.Cpu/AppleHv/HvVm.cs b/src/Ryujinx.Cpu/AppleHv/HvVm.cs index c4f107532..a12bbea9b 100644 --- a/src/Ryujinx.Cpu/AppleHv/HvVm.cs +++ b/src/Ryujinx.Cpu/AppleHv/HvVm.cs @@ -22,7 +22,7 @@ namespace Ryujinx.Cpu.AppleHv { if (++_addressSpaces == 1) { - HvApi.hv_vm_create(IntPtr.Zero).ThrowOnError(); + HvApi.hv_vm_create(nint.Zero).ThrowOnError(); _ipaAllocator = ipaAllocator = new HvIpaAllocator(); } else diff --git a/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartition.cs b/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartition.cs index 224c5edc3..f9743a0a1 100644 --- a/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartition.cs +++ b/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartition.cs @@ -307,7 +307,7 @@ namespace Ryujinx.Cpu.Jit.HostTracked ulong size, MemoryPermission protection, AddressSpacePartitioned addressSpace, - Action updatePtCallback) + Action updatePtCallback) { if (_baseMemory.LazyInitMirrorForProtection(addressSpace, Address, Size, protection)) { @@ -317,7 +317,7 @@ namespace Ryujinx.Cpu.Jit.HostTracked updatePtCallback(va, _baseMemory.GetPointerForProtection(va - Address, size, protection), size); } - public IntPtr GetPointer(ulong va, ulong size) + public nint GetPointer(ulong va, ulong size) { Debug.Assert(va >= Address); Debug.Assert(va + size <= EndAddress); diff --git a/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartitionAllocator.cs b/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartitionAllocator.cs index 44dedb640..a49e0179d 100644 --- a/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartitionAllocator.cs +++ b/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartitionAllocator.cs @@ -11,7 +11,7 @@ namespace Ryujinx.Cpu.Jit.HostTracked private readonly AddressSpacePartitionAllocator _owner; private readonly PrivateMemoryAllocatorImpl.Allocation _allocation; - public IntPtr Pointer => (IntPtr)((ulong)_allocation.Block.Memory.Pointer + _allocation.Offset); + public nint Pointer => (nint)((ulong)_allocation.Block.Memory.Pointer + _allocation.Offset); public bool IsValid => _owner != null; @@ -43,7 +43,7 @@ namespace Ryujinx.Cpu.Jit.HostTracked _allocation.Block.Memory.Reprotect(_allocation.Offset + offset, size, permission, throwOnFail); } - public IntPtr GetPointer(ulong offset, ulong size) + public nint GetPointer(ulong offset, ulong size) { return _allocation.Block.Memory.GetPointer(_allocation.Offset + offset, size); } diff --git a/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartitionMultiAllocation.cs b/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartitionMultiAllocation.cs index 3b065583f..db1f3ea4b 100644 --- a/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartitionMultiAllocation.cs +++ b/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartitionMultiAllocation.cs @@ -47,7 +47,7 @@ namespace Ryujinx.Cpu.Jit.HostTracked _baseMemory.Reprotect(offset, size, permission, throwOnFail); } - public IntPtr GetPointer(ulong offset, ulong size) + public nint GetPointer(ulong offset, ulong size) { return _baseMemory.GetPointer(offset, size); } @@ -68,7 +68,7 @@ namespace Ryujinx.Cpu.Jit.HostTracked return false; } - public IntPtr GetPointerForProtection(ulong offset, ulong size, MemoryPermission permission) + public nint GetPointerForProtection(ulong offset, ulong size, MemoryPermission permission) { AddressSpacePartitionAllocation allocation = permission switch { diff --git a/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartitioned.cs b/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartitioned.cs index 2cf2c248b..e3cb75f64 100644 --- a/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartitioned.cs +++ b/src/Ryujinx.Cpu/Jit/HostTracked/AddressSpacePartitioned.cs @@ -15,7 +15,7 @@ namespace Ryujinx.Cpu.Jit.HostTracked private readonly MemoryBlock _backingMemory; private readonly List _partitions; private readonly AddressSpacePartitionAllocator _asAllocator; - private readonly Action _updatePtCallback; + private readonly Action _updatePtCallback; private readonly bool _useProtectionMirrors; public AddressSpacePartitioned(MemoryTracking tracking, MemoryBlock backingMemory, NativePageTable nativePageTable, bool useProtectionMirrors) @@ -212,7 +212,7 @@ namespace Ryujinx.Cpu.Jit.HostTracked } } - public IntPtr GetPointer(ulong va, ulong size) + public nint GetPointer(ulong va, ulong size) { AddressSpacePartition partition = FindPartition(va); diff --git a/src/Ryujinx.Cpu/Jit/HostTracked/NativePageTable.cs b/src/Ryujinx.Cpu/Jit/HostTracked/NativePageTable.cs index e3174e3fc..aa663d7d9 100644 --- a/src/Ryujinx.Cpu/Jit/HostTracked/NativePageTable.cs +++ b/src/Ryujinx.Cpu/Jit/HostTracked/NativePageTable.cs @@ -30,7 +30,7 @@ namespace Ryujinx.Cpu.Jit.HostTracked private bool _disposed; - public IntPtr PageTablePointer => _nativePageTable.Pointer; + public nint PageTablePointer => _nativePageTable.Pointer; public NativePageTable(ulong asSize) { @@ -83,7 +83,7 @@ namespace Ryujinx.Cpu.Jit.HostTracked public void Unmap(ulong va, ulong size) { - IntPtr guardPagePtr = GetGuardPagePointer(); + nint guardPagePtr = GetGuardPagePointer(); while (size != 0) { @@ -104,7 +104,7 @@ namespace Ryujinx.Cpu.Jit.HostTracked return pte + (va & PageMask); } - public void Update(ulong va, IntPtr ptr, ulong size) + public void Update(ulong va, nint ptr, ulong size) { ulong remainingSize = size; @@ -148,7 +148,7 @@ namespace Ryujinx.Cpu.Jit.HostTracked Debug.Assert(pageSpan.Length == _entriesPerPtPage); - IntPtr guardPagePtr = GetGuardPagePointer(); + nint guardPagePtr = GetGuardPagePointer(); for (int i = 0; i < pageSpan.Length; i++) { @@ -160,12 +160,12 @@ namespace Ryujinx.Cpu.Jit.HostTracked } } - private IntPtr GetGuardPagePointer() + private nint GetGuardPagePointer() { return _nativePageTable.GetPointer(_nativePageTable.Size - _hostPageSize, _hostPageSize); } - private static ulong GetPte(ulong va, IntPtr ptr) + private static ulong GetPte(ulong va, nint ptr) { Debug.Assert((va & PageMask) == 0); diff --git a/src/Ryujinx.Cpu/Jit/JitMemoryBlock.cs b/src/Ryujinx.Cpu/Jit/JitMemoryBlock.cs index bd07d349c..0311db565 100644 --- a/src/Ryujinx.Cpu/Jit/JitMemoryBlock.cs +++ b/src/Ryujinx.Cpu/Jit/JitMemoryBlock.cs @@ -8,7 +8,7 @@ namespace Ryujinx.Cpu.Jit { private readonly MemoryBlock _impl; - public IntPtr Pointer => _impl.Pointer; + public nint Pointer => _impl.Pointer; public JitMemoryBlock(ulong size, MemoryAllocationFlags flags) { diff --git a/src/Ryujinx.Cpu/Jit/MemoryManager.cs b/src/Ryujinx.Cpu/Jit/MemoryManager.cs index 6f594ec2f..049e508d0 100644 --- a/src/Ryujinx.Cpu/Jit/MemoryManager.cs +++ b/src/Ryujinx.Cpu/Jit/MemoryManager.cs @@ -39,7 +39,7 @@ namespace Ryujinx.Cpu.Jit /// /// Page table base pointer. /// - public IntPtr PageTablePointer => _pageTable.Pointer; + public nint PageTablePointer => _pageTable.Pointer; public MemoryManagerType Type => MemoryManagerType.SoftwarePageTable; @@ -264,7 +264,7 @@ namespace Ryujinx.Cpu.Jit for (int i = 0; i < regions.Length; i++) { var guestRegion = guestRegions[i]; - IntPtr pointer = _backingMemory.GetPointer(guestRegion.Address, guestRegion.Size); + nint pointer = _backingMemory.GetPointer(guestRegion.Address, guestRegion.Size); regions[i] = new HostMemoryRange((nuint)(ulong)pointer, guestRegion.Size); } diff --git a/src/Ryujinx.Cpu/Jit/MemoryManagerHostMapped.cs b/src/Ryujinx.Cpu/Jit/MemoryManagerHostMapped.cs index 4639ab913..0fe8b344f 100644 --- a/src/Ryujinx.Cpu/Jit/MemoryManagerHostMapped.cs +++ b/src/Ryujinx.Cpu/Jit/MemoryManagerHostMapped.cs @@ -31,7 +31,7 @@ namespace Ryujinx.Cpu.Jit public int AddressSpaceBits { get; } - public IntPtr PageTablePointer => _addressSpace.Base.Pointer; + public nint PageTablePointer => _addressSpace.Base.Pointer; public MemoryManagerType Type => _unsafeMode ? MemoryManagerType.HostMappedUnsafe : MemoryManagerType.HostMapped; diff --git a/src/Ryujinx.Cpu/Jit/MemoryManagerHostTracked.cs b/src/Ryujinx.Cpu/Jit/MemoryManagerHostTracked.cs index 95200a7dc..4dab212a7 100644 --- a/src/Ryujinx.Cpu/Jit/MemoryManagerHostTracked.cs +++ b/src/Ryujinx.Cpu/Jit/MemoryManagerHostTracked.cs @@ -37,7 +37,7 @@ namespace Ryujinx.Cpu.Jit /// public bool UsesPrivateAllocations => true; - public IntPtr PageTablePointer => _nativePageTable.PageTablePointer; + public nint PageTablePointer => _nativePageTable.PageTablePointer; public MemoryManagerType Type => _unsafeMode ? MemoryManagerType.HostTrackedUnsafe : MemoryManagerType.HostTracked; @@ -452,7 +452,7 @@ namespace Ryujinx.Cpu.Jit { (MemoryBlock memory, ulong rangeOffset, ulong rangeSize) = GetMemoryOffsetAndSize(va, endVa - va); - regions.Add(new((UIntPtr)memory.GetPointer(rangeOffset, rangeSize), rangeSize)); + regions.Add(new((nuint)memory.GetPointer(rangeOffset, rangeSize), rangeSize)); va += rangeSize; } diff --git a/src/Ryujinx.Cpu/LightningJit/AarchCompiler.cs b/src/Ryujinx.Cpu/LightningJit/AarchCompiler.cs index ee4fc439f..89e1499c0 100644 --- a/src/Ryujinx.Cpu/LightningJit/AarchCompiler.cs +++ b/src/Ryujinx.Cpu/LightningJit/AarchCompiler.cs @@ -15,7 +15,7 @@ namespace Ryujinx.Cpu.LightningJit IMemoryManager memoryManager, ulong address, AddressTable funcTable, - IntPtr dispatchStubPtr, + nint dispatchStubPtr, ExecutionMode executionMode, Architecture targetArch) { diff --git a/src/Ryujinx.Cpu/LightningJit/Arm32/A32Compiler.cs b/src/Ryujinx.Cpu/LightningJit/Arm32/A32Compiler.cs index 7f6024d47..0fe42b923 100644 --- a/src/Ryujinx.Cpu/LightningJit/Arm32/A32Compiler.cs +++ b/src/Ryujinx.Cpu/LightningJit/Arm32/A32Compiler.cs @@ -13,7 +13,7 @@ namespace Ryujinx.Cpu.LightningJit.Arm32 IMemoryManager memoryManager, ulong address, AddressTable funcTable, - IntPtr dispatchStubPtr, + nint dispatchStubPtr, bool isThumb, Architecture targetArch) { diff --git a/src/Ryujinx.Cpu/LightningJit/Arm32/Target/Arm64/Compiler.cs b/src/Ryujinx.Cpu/LightningJit/Arm32/Target/Arm64/Compiler.cs index a668b5777..0d56f28c9 100644 --- a/src/Ryujinx.Cpu/LightningJit/Arm32/Target/Arm64/Compiler.cs +++ b/src/Ryujinx.Cpu/LightningJit/Arm32/Target/Arm64/Compiler.cs @@ -24,10 +24,10 @@ namespace Ryujinx.Cpu.LightningJit.Arm32.Target.Arm64 public readonly MemoryManagerType MemoryManagerType; public readonly TailMerger TailMerger; public readonly AddressTable FuncTable; - public readonly IntPtr DispatchStubPointer; + public readonly nint DispatchStubPointer; private readonly RegisterSaveRestore _registerSaveRestore; - private readonly IntPtr _pageTablePointer; + private readonly nint _pageTablePointer; public Context( CodeWriter writer, @@ -36,8 +36,8 @@ namespace Ryujinx.Cpu.LightningJit.Arm32.Target.Arm64 TailMerger tailMerger, AddressTable funcTable, RegisterSaveRestore registerSaveRestore, - IntPtr dispatchStubPointer, - IntPtr pageTablePointer) + nint dispatchStubPointer, + nint pageTablePointer) { Writer = writer; RegisterAllocator = registerAllocator; @@ -226,7 +226,7 @@ namespace Ryujinx.Cpu.LightningJit.Arm32.Target.Arm64 } } - public static CompiledFunction Compile(CpuPreset cpuPreset, IMemoryManager memoryManager, ulong address, AddressTable funcTable, IntPtr dispatchStubPtr, bool isThumb) + public static CompiledFunction Compile(CpuPreset cpuPreset, IMemoryManager memoryManager, ulong address, AddressTable funcTable, nint dispatchStubPtr, bool isThumb) { MultiBlock multiBlock = Decoder.DecodeMulti(cpuPreset, memoryManager, address, isThumb); diff --git a/src/Ryujinx.Cpu/LightningJit/Arm32/Target/Arm64/InstEmitFlow.cs b/src/Ryujinx.Cpu/LightningJit/Arm32/Target/Arm64/InstEmitFlow.cs index 3b1ff5a2a..7f5e4835c 100644 --- a/src/Ryujinx.Cpu/LightningJit/Arm32/Target/Arm64/InstEmitFlow.cs +++ b/src/Ryujinx.Cpu/LightningJit/Arm32/Target/Arm64/InstEmitFlow.cs @@ -133,7 +133,7 @@ namespace Ryujinx.Cpu.LightningJit.Arm32.Target.Arm64 TailMerger tailMerger, Action writeEpilogue, AddressTable funcTable, - IntPtr funcPtr, + nint funcPtr, int spillBaseOffset, uint nextAddress, Operand guestAddress, diff --git a/src/Ryujinx.Cpu/LightningJit/Arm32/Target/Arm64/InstEmitSystem.cs b/src/Ryujinx.Cpu/LightningJit/Arm32/Target/Arm64/InstEmitSystem.cs index 07f9f86a8..4d97a2264 100644 --- a/src/Ryujinx.Cpu/LightningJit/Arm32/Target/Arm64/InstEmitSystem.cs +++ b/src/Ryujinx.Cpu/LightningJit/Arm32/Target/Arm64/InstEmitSystem.cs @@ -324,27 +324,27 @@ namespace Ryujinx.Cpu.LightningJit.Arm32.Target.Arm64 Udf(context, encoding, 0); } - private static IntPtr GetBkptHandlerPtr() + private static nint GetBkptHandlerPtr() { return Marshal.GetFunctionPointerForDelegate(NativeInterface.Break); } - private static IntPtr GetSvcHandlerPtr() + private static nint GetSvcHandlerPtr() { return Marshal.GetFunctionPointerForDelegate(NativeInterface.SupervisorCall); } - private static IntPtr GetUdfHandlerPtr() + private static nint GetUdfHandlerPtr() { return Marshal.GetFunctionPointerForDelegate(NativeInterface.Undefined); } - private static IntPtr GetCntpctEl0Ptr() + private static nint GetCntpctEl0Ptr() { return Marshal.GetFunctionPointerForDelegate(NativeInterface.GetCntpctEl0); } - private static IntPtr CheckSynchronizationPtr() + private static nint CheckSynchronizationPtr() { return Marshal.GetFunctionPointerForDelegate(NativeInterface.CheckSynchronization); } @@ -474,7 +474,7 @@ namespace Ryujinx.Cpu.LightningJit.Arm32.Target.Arm64 private static void WriteCall( ref Assembler asm, RegisterAllocator regAlloc, - IntPtr funcPtr, + nint funcPtr, bool skipContext, int spillBaseOffset, int? resultRegister, diff --git a/src/Ryujinx.Cpu/LightningJit/Arm64/A64Compiler.cs b/src/Ryujinx.Cpu/LightningJit/Arm64/A64Compiler.cs index b46ae3b0c..44de4cd0d 100644 --- a/src/Ryujinx.Cpu/LightningJit/Arm64/A64Compiler.cs +++ b/src/Ryujinx.Cpu/LightningJit/Arm64/A64Compiler.cs @@ -13,7 +13,7 @@ namespace Ryujinx.Cpu.LightningJit.Arm64 IMemoryManager memoryManager, ulong address, AddressTable funcTable, - IntPtr dispatchStubPtr, + nint dispatchStubPtr, Architecture targetArch) { if (targetArch == Architecture.Arm64) diff --git a/src/Ryujinx.Cpu/LightningJit/Arm64/Target/Arm64/Compiler.cs b/src/Ryujinx.Cpu/LightningJit/Arm64/Target/Arm64/Compiler.cs index 7a6d761e8..4a3c507df 100644 --- a/src/Ryujinx.Cpu/LightningJit/Arm64/Target/Arm64/Compiler.cs +++ b/src/Ryujinx.Cpu/LightningJit/Arm64/Target/Arm64/Compiler.cs @@ -20,11 +20,11 @@ namespace Ryujinx.Cpu.LightningJit.Arm64.Target.Arm64 public readonly RegisterAllocator RegisterAllocator; public readonly TailMerger TailMerger; public readonly AddressTable FuncTable; - public readonly IntPtr DispatchStubPointer; + public readonly nint DispatchStubPointer; private readonly MultiBlock _multiBlock; private readonly RegisterSaveRestore _registerSaveRestore; - private readonly IntPtr _pageTablePointer; + private readonly nint _pageTablePointer; public Context( CodeWriter writer, @@ -33,8 +33,8 @@ namespace Ryujinx.Cpu.LightningJit.Arm64.Target.Arm64 RegisterSaveRestore registerSaveRestore, MultiBlock multiBlock, AddressTable funcTable, - IntPtr dispatchStubPointer, - IntPtr pageTablePointer) + nint dispatchStubPointer, + nint pageTablePointer) { Writer = writer; RegisterAllocator = registerAllocator; @@ -304,7 +304,7 @@ namespace Ryujinx.Cpu.LightningJit.Arm64.Target.Arm64 } } - public static CompiledFunction Compile(CpuPreset cpuPreset, IMemoryManager memoryManager, ulong address, AddressTable funcTable, IntPtr dispatchStubPtr) + public static CompiledFunction Compile(CpuPreset cpuPreset, IMemoryManager memoryManager, ulong address, AddressTable funcTable, nint dispatchStubPtr) { MultiBlock multiBlock = Decoder.DecodeMulti(cpuPreset, memoryManager, address); diff --git a/src/Ryujinx.Cpu/LightningJit/Arm64/Target/Arm64/InstEmitSystem.cs b/src/Ryujinx.Cpu/LightningJit/Arm64/Target/Arm64/InstEmitSystem.cs index 82cb29d73..1eeeb746e 100644 --- a/src/Ryujinx.Cpu/LightningJit/Arm64/Target/Arm64/InstEmitSystem.cs +++ b/src/Ryujinx.Cpu/LightningJit/Arm64/Target/Arm64/InstEmitSystem.cs @@ -144,27 +144,27 @@ namespace Ryujinx.Cpu.LightningJit.Arm64.Target.Arm64 return name == InstName.Svc; } - private static IntPtr GetBrkHandlerPtr() + private static nint GetBrkHandlerPtr() { return Marshal.GetFunctionPointerForDelegate(NativeInterface.Break); } - private static IntPtr GetSvcHandlerPtr() + private static nint GetSvcHandlerPtr() { return Marshal.GetFunctionPointerForDelegate(NativeInterface.SupervisorCall); } - private static IntPtr GetUdfHandlerPtr() + private static nint GetUdfHandlerPtr() { return Marshal.GetFunctionPointerForDelegate(NativeInterface.Undefined); } - private static IntPtr GetCntpctEl0Ptr() + private static nint GetCntpctEl0Ptr() { return Marshal.GetFunctionPointerForDelegate(NativeInterface.GetCntpctEl0); } - private static IntPtr CheckSynchronizationPtr() + private static nint CheckSynchronizationPtr() { return Marshal.GetFunctionPointerForDelegate(NativeInterface.CheckSynchronization); } @@ -215,7 +215,7 @@ namespace Ryujinx.Cpu.LightningJit.Arm64.Target.Arm64 TailMerger tailMerger, Action writeEpilogue, AddressTable funcTable, - IntPtr dispatchStubPtr, + nint dispatchStubPtr, InstName name, ulong pc, uint encoding, @@ -298,7 +298,7 @@ namespace Ryujinx.Cpu.LightningJit.Arm64.Target.Arm64 TailMerger tailMerger, Action writeEpilogue, AddressTable funcTable, - IntPtr funcPtr, + nint funcPtr, int spillBaseOffset, ulong pc, Operand guestAddress, @@ -369,7 +369,7 @@ namespace Ryujinx.Cpu.LightningJit.Arm64.Target.Arm64 private static void WriteCall( ref Assembler asm, RegisterAllocator regAlloc, - IntPtr funcPtr, + nint funcPtr, int spillBaseOffset, int? resultRegister, params ulong[] callArgs) diff --git a/src/Ryujinx.Cpu/LightningJit/Cache/JitCache.cs b/src/Ryujinx.Cpu/LightningJit/Cache/JitCache.cs index 6f1191ca5..ac1274bf6 100644 --- a/src/Ryujinx.Cpu/LightningJit/Cache/JitCache.cs +++ b/src/Ryujinx.Cpu/LightningJit/Cache/JitCache.cs @@ -28,7 +28,7 @@ namespace Ryujinx.Cpu.LightningJit.Cache [SupportedOSPlatform("windows")] [LibraryImport("kernel32.dll", SetLastError = true)] - public static partial IntPtr FlushInstructionCache(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize); + public static partial nint FlushInstructionCache(nint hProcess, nint lpAddress, nuint dwSize); public static void Initialize(IJitMemoryAllocator allocator) { @@ -57,7 +57,7 @@ namespace Ryujinx.Cpu.LightningJit.Cache } } - public unsafe static IntPtr Map(ReadOnlySpan code) + public unsafe static nint Map(ReadOnlySpan code) { lock (_lock) { @@ -65,7 +65,7 @@ namespace Ryujinx.Cpu.LightningJit.Cache int funcOffset = Allocate(code.Length); - IntPtr funcPtr = _jitRegion.Pointer + funcOffset; + nint funcPtr = _jitRegion.Pointer + funcOffset; if (OperatingSystem.IsMacOS() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64) { @@ -73,7 +73,7 @@ namespace Ryujinx.Cpu.LightningJit.Cache { fixed (byte* codePtr = code) { - JitSupportDarwin.Copy(funcPtr, (IntPtr)codePtr, (ulong)code.Length); + JitSupportDarwin.Copy(funcPtr, (nint)codePtr, (ulong)code.Length); } } } @@ -85,7 +85,7 @@ namespace Ryujinx.Cpu.LightningJit.Cache if (OperatingSystem.IsWindows() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64) { - FlushInstructionCache(Process.GetCurrentProcess().Handle, funcPtr, (UIntPtr)code.Length); + FlushInstructionCache(Process.GetCurrentProcess().Handle, funcPtr, (nuint)code.Length); } else { @@ -99,7 +99,7 @@ namespace Ryujinx.Cpu.LightningJit.Cache } } - public static void Unmap(IntPtr pointer) + public static void Unmap(nint pointer) { lock (_lock) { diff --git a/src/Ryujinx.Cpu/LightningJit/Cache/JitCacheInvalidation.cs b/src/Ryujinx.Cpu/LightningJit/Cache/JitCacheInvalidation.cs index cd5f3ede4..d0a5e4ac8 100644 --- a/src/Ryujinx.Cpu/LightningJit/Cache/JitCacheInvalidation.cs +++ b/src/Ryujinx.Cpu/LightningJit/Cache/JitCacheInvalidation.cs @@ -68,7 +68,7 @@ namespace Ryujinx.Cpu.LightningJit.Cache } } - public void Invalidate(IntPtr basePointer, ulong size) + public void Invalidate(nint basePointer, ulong size) { if (_needsInvalidation) { diff --git a/src/Ryujinx.Cpu/LightningJit/Cache/JitSupportDarwin.cs b/src/Ryujinx.Cpu/LightningJit/Cache/JitSupportDarwin.cs index 06c81045d..ed02a9c28 100644 --- a/src/Ryujinx.Cpu/LightningJit/Cache/JitSupportDarwin.cs +++ b/src/Ryujinx.Cpu/LightningJit/Cache/JitSupportDarwin.cs @@ -8,9 +8,9 @@ namespace Ryujinx.Cpu.LightningJit.Cache static partial class JitSupportDarwin { [LibraryImport("libarmeilleure-jitsupport", EntryPoint = "armeilleure_jit_memcpy")] - public static partial void Copy(IntPtr dst, IntPtr src, ulong n); + public static partial void Copy(nint dst, nint src, ulong n); [LibraryImport("libc", EntryPoint = "sys_icache_invalidate", SetLastError = true)] - public static partial void SysIcacheInvalidate(IntPtr start, IntPtr len); + public static partial void SysIcacheInvalidate(nint start, nint len); } } diff --git a/src/Ryujinx.Cpu/LightningJit/Cache/NoWxCache.cs b/src/Ryujinx.Cpu/LightningJit/Cache/NoWxCache.cs index a71074995..3cf279ae3 100644 --- a/src/Ryujinx.Cpu/LightningJit/Cache/NoWxCache.cs +++ b/src/Ryujinx.Cpu/LightningJit/Cache/NoWxCache.cs @@ -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 code, ulong guestAddress, ulong guestSize) + public unsafe nint Map(nint framePointer, ReadOnlySpan 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 code) + public unsafe nint MapPageAligned(ReadOnlySpan 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((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 code, ulong guestAddress) + private unsafe nint AddThreadLocalFunction(ReadOnlySpan 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((void*)funcPtr, code.Length)); (_threadLocalCache ??= new()).Add(guestAddress, new(funcOffset, code.Length, funcPtr)); diff --git a/src/Ryujinx.Cpu/LightningJit/CodeGen/Arm64/StackWalker.cs b/src/Ryujinx.Cpu/LightningJit/CodeGen/Arm64/StackWalker.cs index 3b01e674b..3ce7c4f9c 100644 --- a/src/Ryujinx.Cpu/LightningJit/CodeGen/Arm64/StackWalker.cs +++ b/src/Ryujinx.Cpu/LightningJit/CodeGen/Arm64/StackWalker.cs @@ -6,13 +6,13 @@ namespace Ryujinx.Cpu.LightningJit.CodeGen.Arm64 { class StackWalker : IStackWalker { - public IEnumerable GetCallStack(IntPtr framePointer, IntPtr codeRegionStart, int codeRegionSize, IntPtr codeRegion2Start, int codeRegion2Size) + public IEnumerable GetCallStack(nint framePointer, nint codeRegionStart, int codeRegionSize, nint codeRegion2Start, int codeRegion2Size) { List functionPointers = new(); while (true) { - IntPtr functionPointer = Marshal.ReadIntPtr(framePointer, IntPtr.Size); + nint functionPointer = Marshal.ReadIntPtr(framePointer, nint.Size); if ((functionPointer < codeRegionStart || functionPointer >= codeRegionStart + codeRegionSize) && (functionPointer < codeRegion2Start || functionPointer >= codeRegion2Start + codeRegion2Size)) diff --git a/src/Ryujinx.Cpu/LightningJit/IStackWalker.cs b/src/Ryujinx.Cpu/LightningJit/IStackWalker.cs index 2fddef659..375c09d26 100644 --- a/src/Ryujinx.Cpu/LightningJit/IStackWalker.cs +++ b/src/Ryujinx.Cpu/LightningJit/IStackWalker.cs @@ -5,6 +5,6 @@ namespace Ryujinx.Cpu.LightningJit { interface IStackWalker { - IEnumerable GetCallStack(IntPtr framePointer, IntPtr codeRegionStart, int codeRegionSize, IntPtr codeRegion2Start, int codeRegion2Size); + IEnumerable GetCallStack(nint framePointer, nint codeRegionStart, int codeRegionSize, nint codeRegion2Start, int codeRegion2Size); } } diff --git a/src/Ryujinx.Cpu/LightningJit/NativeInterface.cs b/src/Ryujinx.Cpu/LightningJit/NativeInterface.cs index da3ad9832..5f243c0ee 100644 --- a/src/Ryujinx.Cpu/LightningJit/NativeInterface.cs +++ b/src/Ryujinx.Cpu/LightningJit/NativeInterface.cs @@ -61,7 +61,7 @@ namespace Ryujinx.Cpu.LightningJit return GetContext().CntpctEl0; } - public static ulong GetFunctionAddress(IntPtr framePointer, ulong address) + public static ulong GetFunctionAddress(nint framePointer, ulong address) { return (ulong)Context.Translator.GetOrTranslatePointer(framePointer, address, GetContext().ExecutionMode); } diff --git a/src/Ryujinx.Cpu/LightningJit/State/ExecutionContext.cs b/src/Ryujinx.Cpu/LightningJit/State/ExecutionContext.cs index facb9142f..a366dcca6 100644 --- a/src/Ryujinx.Cpu/LightningJit/State/ExecutionContext.cs +++ b/src/Ryujinx.Cpu/LightningJit/State/ExecutionContext.cs @@ -10,7 +10,7 @@ namespace Ryujinx.Cpu.LightningJit.State private readonly NativeContext _nativeContext; - internal IntPtr NativeContextPtr => _nativeContext.BasePtr; + internal nint NativeContextPtr => _nativeContext.BasePtr; private bool _interrupted; private readonly ICounter _counter; diff --git a/src/Ryujinx.Cpu/LightningJit/State/NativeContext.cs b/src/Ryujinx.Cpu/LightningJit/State/NativeContext.cs index fdb8793de..9895c78c2 100644 --- a/src/Ryujinx.Cpu/LightningJit/State/NativeContext.cs +++ b/src/Ryujinx.Cpu/LightningJit/State/NativeContext.cs @@ -25,7 +25,7 @@ namespace Ryujinx.Cpu.LightningJit.State private readonly IJitMemoryBlock _block; - public IntPtr BasePtr => _block.Pointer; + public nint BasePtr => _block.Pointer; public NativeContext(IJitMemoryAllocator allocator) { diff --git a/src/Ryujinx.Cpu/LightningJit/TranslatedFunction.cs b/src/Ryujinx.Cpu/LightningJit/TranslatedFunction.cs index a4e2c7b93..df0f52b8c 100644 --- a/src/Ryujinx.Cpu/LightningJit/TranslatedFunction.cs +++ b/src/Ryujinx.Cpu/LightningJit/TranslatedFunction.cs @@ -4,10 +4,10 @@ namespace Ryujinx.Cpu.LightningJit { class TranslatedFunction { - public IntPtr FuncPointer { get; } + public nint FuncPointer { get; } public ulong GuestSize { get; } - public TranslatedFunction(IntPtr funcPointer, ulong guestSize) + public TranslatedFunction(nint funcPointer, ulong guestSize) { FuncPointer = funcPointer; GuestSize = guestSize; diff --git a/src/Ryujinx.Cpu/LightningJit/Translator.cs b/src/Ryujinx.Cpu/LightningJit/Translator.cs index d62410253..b4710e34e 100644 --- a/src/Ryujinx.Cpu/LightningJit/Translator.cs +++ b/src/Ryujinx.Cpu/LightningJit/Translator.cs @@ -98,7 +98,7 @@ namespace Ryujinx.Cpu.LightningJit _noWxCache?.ClearEntireThreadLocalCache(); } - internal IntPtr GetOrTranslatePointer(IntPtr framePointer, ulong address, ExecutionMode mode) + internal nint GetOrTranslatePointer(nint framePointer, ulong address, ExecutionMode mode) { if (_noWxCache != null) { @@ -141,7 +141,7 @@ namespace Ryujinx.Cpu.LightningJit private TranslatedFunction Translate(ulong address, ExecutionMode mode) { CompiledFunction func = Compile(address, mode); - IntPtr funcPointer = JitCache.Map(func.Code); + nint funcPointer = JitCache.Map(func.Code); return new TranslatedFunction(funcPointer, (ulong)func.GuestCodeLength); } diff --git a/src/Ryujinx.Cpu/LightningJit/TranslatorStubs.cs b/src/Ryujinx.Cpu/LightningJit/TranslatorStubs.cs index 914712bb1..e88414d5e 100644 --- a/src/Ryujinx.Cpu/LightningJit/TranslatorStubs.cs +++ b/src/Ryujinx.Cpu/LightningJit/TranslatorStubs.cs @@ -10,31 +10,31 @@ using System.Runtime.InteropServices; namespace Ryujinx.Cpu.LightningJit { - delegate void DispatcherFunction(IntPtr nativeContext, ulong startAddress); + delegate void DispatcherFunction(nint nativeContext, ulong startAddress); /// /// Represents a stub manager. /// class TranslatorStubs : IDisposable { - private delegate ulong GetFunctionAddressDelegate(IntPtr framePointer, ulong address); + private delegate ulong GetFunctionAddressDelegate(nint framePointer, ulong address); - private readonly Lazy _slowDispatchStub; + private readonly Lazy _slowDispatchStub; private bool _disposed; private readonly AddressTable _functionTable; private readonly NoWxCache _noWxCache; private readonly GetFunctionAddressDelegate _getFunctionAddressRef; - private readonly IntPtr _getFunctionAddress; - private readonly Lazy _dispatchStub; + private readonly nint _getFunctionAddress; + private readonly Lazy _dispatchStub; private readonly Lazy _dispatchLoop; /// /// Gets the dispatch stub. /// /// instance was disposed - public IntPtr DispatchStub + public nint DispatchStub { get { @@ -48,7 +48,7 @@ namespace Ryujinx.Cpu.LightningJit /// Gets the slow dispatch stub. /// /// instance was disposed - public IntPtr SlowDispatchStub + public nint SlowDispatchStub { get { @@ -138,7 +138,7 @@ namespace Ryujinx.Cpu.LightningJit /// Generates a . /// /// Generated - private IntPtr GenerateDispatchStub() + private nint GenerateDispatchStub() { List branchToFallbackOffsets = new(); @@ -226,7 +226,7 @@ namespace Ryujinx.Cpu.LightningJit /// Generates a . /// /// Generated - private IntPtr GenerateSlowDispatchStub() + private nint GenerateSlowDispatchStub() { CodeWriter writer = new(); @@ -350,12 +350,12 @@ namespace Ryujinx.Cpu.LightningJit throw new PlatformNotSupportedException(); } - IntPtr pointer = Map(writer.AsByteSpan()); + nint pointer = Map(writer.AsByteSpan()); return Marshal.GetDelegateForFunctionPointer(pointer); } - private IntPtr Map(ReadOnlySpan code) + private nint Map(ReadOnlySpan code) { if (_noWxCache != null) { diff --git a/src/Ryujinx.Cpu/MemoryEhMeilleure.cs b/src/Ryujinx.Cpu/MemoryEhMeilleure.cs index 379ace941..e9a3ac4aa 100644 --- a/src/Ryujinx.Cpu/MemoryEhMeilleure.cs +++ b/src/Ryujinx.Cpu/MemoryEhMeilleure.cs @@ -46,7 +46,7 @@ namespace Ryujinx.Cpu _mirrorAddress = (ulong)addressSpaceMirror.Pointer; ulong endAddressMirror = _mirrorAddress + addressSpace.Size; - bool addedMirror = NativeSignalHandler.AddTrackedRegion((nuint)_mirrorAddress, (nuint)endAddressMirror, IntPtr.Zero); + bool addedMirror = NativeSignalHandler.AddTrackedRegion((nuint)_mirrorAddress, (nuint)endAddressMirror, nint.Zero); if (!addedMirror) { diff --git a/src/Ryujinx.Cpu/Signal/NativeSignalHandler.cs b/src/Ryujinx.Cpu/Signal/NativeSignalHandler.cs index 93e608329..2985f1c21 100644 --- a/src/Ryujinx.Cpu/Signal/NativeSignalHandler.cs +++ b/src/Ryujinx.Cpu/Signal/NativeSignalHandler.cs @@ -14,7 +14,7 @@ namespace Ryujinx.Cpu.Signal public int IsActive; public nuint RangeAddress; public nuint RangeEndAddress; - public IntPtr ActionPointer; + public nint ActionPointer; } [InlineArray(NativeSignalHandlerGenerator.MaxTrackedRanges)] @@ -54,8 +54,8 @@ namespace Ryujinx.Cpu.Signal static class NativeSignalHandler { - private static readonly IntPtr _handlerConfig; - private static IntPtr _signalHandlerPtr; + private static readonly nint _handlerConfig; + private static nint _signalHandlerPtr; private static MemoryBlock _codeBlock; @@ -70,7 +70,7 @@ namespace Ryujinx.Cpu.Signal config = new SignalHandlerConfig(); } - public static void InitializeSignalHandler(Func customSignalHandlerFactory = null) + public static void InitializeSignalHandler(Func customSignalHandlerFactory = null) { if (_initialized) { @@ -111,7 +111,7 @@ namespace Ryujinx.Cpu.Signal if (customSignalHandlerFactory != null) { - _signalHandlerPtr = customSignalHandlerFactory(IntPtr.Zero, _signalHandlerPtr); + _signalHandlerPtr = customSignalHandlerFactory(nint.Zero, _signalHandlerPtr); } WindowsSignalHandlerRegistration.RegisterExceptionHandler(_signalHandlerPtr); @@ -121,7 +121,7 @@ namespace Ryujinx.Cpu.Signal } } - private static IntPtr MapCode(ReadOnlySpan code) + private static nint MapCode(ReadOnlySpan code) { Debug.Assert(_codeBlock == null); @@ -139,7 +139,7 @@ namespace Ryujinx.Cpu.Signal return ref Unsafe.AsRef((void*)_handlerConfig); } - public static bool AddTrackedRegion(nuint address, nuint endAddress, IntPtr action) + public static bool AddTrackedRegion(nuint address, nuint endAddress, nint action) { Span ranges = GetConfigRef().Ranges; diff --git a/src/Ryujinx.Cpu/Signal/UnixSignalHandlerRegistration.cs b/src/Ryujinx.Cpu/Signal/UnixSignalHandlerRegistration.cs index e88a6c0f6..d40e7cdc9 100644 --- a/src/Ryujinx.Cpu/Signal/UnixSignalHandlerRegistration.cs +++ b/src/Ryujinx.Cpu/Signal/UnixSignalHandlerRegistration.cs @@ -14,10 +14,10 @@ namespace Ryujinx.Cpu.Signal [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct SigAction { - public IntPtr sa_handler; + public nint sa_handler; public SigSet sa_mask; public int sa_flags; - public IntPtr sa_restorer; + public nint sa_restorer; } private const int SIGSEGV = 11; @@ -28,14 +28,14 @@ namespace Ryujinx.Cpu.Signal private static partial int sigaction(int signum, ref SigAction sigAction, out SigAction oldAction); [LibraryImport("libc", SetLastError = true)] - private static partial int sigaction(int signum, IntPtr sigAction, out SigAction oldAction); + private static partial int sigaction(int signum, nint sigAction, out SigAction oldAction); [LibraryImport("libc", SetLastError = true)] private static partial int sigemptyset(ref SigSet set); public static SigAction GetSegfaultExceptionHandler() { - int result = sigaction(SIGSEGV, IntPtr.Zero, out SigAction old); + int result = sigaction(SIGSEGV, nint.Zero, out SigAction old); if (result != 0) { @@ -45,7 +45,7 @@ namespace Ryujinx.Cpu.Signal return old; } - public static SigAction RegisterExceptionHandler(IntPtr action) + public static SigAction RegisterExceptionHandler(nint action) { SigAction sig = new() { diff --git a/src/Ryujinx.Cpu/Signal/WindowsSignalHandlerRegistration.cs b/src/Ryujinx.Cpu/Signal/WindowsSignalHandlerRegistration.cs index 1fbce0f72..7ac15b816 100644 --- a/src/Ryujinx.Cpu/Signal/WindowsSignalHandlerRegistration.cs +++ b/src/Ryujinx.Cpu/Signal/WindowsSignalHandlerRegistration.cs @@ -6,17 +6,17 @@ namespace Ryujinx.Cpu.Signal static partial class WindowsSignalHandlerRegistration { [LibraryImport("kernel32.dll")] - private static partial IntPtr AddVectoredExceptionHandler(uint first, IntPtr handler); + private static partial nint AddVectoredExceptionHandler(uint first, nint handler); [LibraryImport("kernel32.dll")] - private static partial ulong RemoveVectoredExceptionHandler(IntPtr handle); + private static partial ulong RemoveVectoredExceptionHandler(nint handle); - public static IntPtr RegisterExceptionHandler(IntPtr action) + public static nint RegisterExceptionHandler(nint action) { return AddVectoredExceptionHandler(1, action); } - public static bool RemoveExceptionHandler(IntPtr handle) + public static bool RemoveExceptionHandler(nint handle) { return RemoveVectoredExceptionHandler(handle) != 0; } diff --git a/src/Ryujinx.Graphics.Device/DeviceState.cs b/src/Ryujinx.Graphics.Device/DeviceState.cs index 54178a414..0dd4f5904 100644 --- a/src/Ryujinx.Graphics.Device/DeviceState.cs +++ b/src/Ryujinx.Graphics.Device/DeviceState.cs @@ -81,7 +81,7 @@ namespace Ryujinx.Graphics.Device { uint alignedOffset = index * RegisterSize; - var readCallback = Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(_readCallbacks), (IntPtr)index); + var readCallback = Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(_readCallbacks), (nint)index); if (readCallback != null) { return readCallback(); @@ -106,7 +106,7 @@ namespace Ryujinx.Graphics.Device GetRefIntAlignedUncheck(index) = data; - Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(_writeCallbacks), (IntPtr)index)?.Invoke(data); + Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(_writeCallbacks), (nint)index)?.Invoke(data); } } @@ -123,7 +123,7 @@ namespace Ryujinx.Graphics.Device changed = storage != data; storage = data; - Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(_writeCallbacks), (IntPtr)index)?.Invoke(data); + Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(_writeCallbacks), (nint)index)?.Invoke(data); } else { @@ -153,13 +153,13 @@ namespace Ryujinx.Graphics.Device [MethodImpl(MethodImplOptions.AggressiveInlining)] private ref T GetRefUnchecked(uint offset) where T : unmanaged { - return ref Unsafe.As(ref Unsafe.AddByteOffset(ref State, (IntPtr)offset)); + return ref Unsafe.As(ref Unsafe.AddByteOffset(ref State, (nint)offset)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private ref int GetRefIntAlignedUncheck(ulong index) { - return ref Unsafe.Add(ref Unsafe.As(ref State), (IntPtr)index); + return ref Unsafe.Add(ref Unsafe.As(ref State), (nint)index); } } } diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdateTracker.cs b/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdateTracker.cs index effcb7bbb..ea9fc9e31 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdateTracker.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdateTracker.cs @@ -109,7 +109,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed if (index < BlockSize) { - int groupIndex = Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(_registerToGroupMapping), (IntPtr)index); + int groupIndex = Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(_registerToGroupMapping), (nint)index); if (groupIndex != 0) { groupIndex--; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/FFmpegContext.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/FFmpegContext.cs index 33f227edb..5c9e3989b 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/FFmpegContext.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/FFmpegContext.cs @@ -91,7 +91,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg FFmpegApi.av_log_format_line(ptr, level, format, vl, lineBuffer, lineSize, &printPrefix); - string line = Marshal.PtrToStringAnsi((IntPtr)lineBuffer).Trim(); + string line = Marshal.PtrToStringAnsi((nint)lineBuffer).Trim(); switch (level) { diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec.cs index 0267000c8..b5ef710b1 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec.cs @@ -12,15 +12,15 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native public int Capabilities; public byte MaxLowRes; public unsafe AVRational* SupportedFramerates; - public IntPtr PixFmts; - public IntPtr SupportedSamplerates; - public IntPtr SampleFmts; + public nint PixFmts; + public nint SupportedSamplerates; + public nint SampleFmts; // Deprecated public unsafe ulong* ChannelLayouts; - public unsafe IntPtr PrivClass; - public IntPtr Profiles; + public unsafe nint PrivClass; + public nint Profiles; public unsafe byte* WrapperName; - public IntPtr ChLayouts; + public nint ChLayouts; #pragma warning restore CS0649 } } diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec501.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec501.cs index 9084f4024..d745e9f04 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec501.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec501.cs @@ -12,13 +12,13 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native public int Capabilities; public byte MaxLowRes; public unsafe AVRational* SupportedFramerates; - public IntPtr PixFmts; - public IntPtr SupportedSamplerates; - public IntPtr SampleFmts; + public nint PixFmts; + public nint SupportedSamplerates; + public nint SampleFmts; // Deprecated public unsafe ulong* ChannelLayouts; - public unsafe IntPtr PrivClass; - public IntPtr Profiles; + public unsafe nint PrivClass; + public nint Profiles; public unsafe byte* WrapperName; #pragma warning restore CS0649 } diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodecContext.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodecContext.cs index c743ab33e..1de0a13e4 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodecContext.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodecContext.cs @@ -6,22 +6,22 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native struct AVCodecContext { #pragma warning disable CS0649 // Field is never assigned to - public unsafe IntPtr AvClass; + public unsafe nint AvClass; public int LogLevelOffset; public int CodecType; public unsafe AVCodec* Codec; public AVCodecID CodecId; public uint CodecTag; - public IntPtr PrivData; - public IntPtr Internal; - public IntPtr Opaque; + public nint PrivData; + public nint Internal; + public nint Opaque; public long BitRate; public int BitRateTolerance; public int GlobalQuality; public int CompressionLevel; public int Flags; public int Flags2; - public IntPtr ExtraData; + public nint ExtraData; public int ExtraDataSize; public AVRational TimeBase; public int TicksPerFrame; @@ -32,8 +32,8 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native public int CodedHeight; public int GopSize; public int PixFmt; - public IntPtr DrawHorizBand; - public IntPtr GetFormat; + public nint DrawHorizBand; + public nint GetFormat; public int MaxBFrames; public float BQuantFactor; public float BQuantOffset; @@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native public float PMasking; public float DarkMasking; public int SliceCount; - public IntPtr SliceOffset; + public nint SliceOffset; public AVRational SampleAspectRatio; public int MeCmp; public int MeSubCmp; @@ -60,8 +60,8 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native public int MeRange; public int SliceFlags; public int MbDecision; - public IntPtr IntraMatrix; - public IntPtr InterMatrix; + public nint IntraMatrix; + public nint InterMatrix; public int IntraDcPrecision; public int SkipTop; public int SkipBottom; @@ -89,7 +89,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native public ulong RequestChannelLayout; public int AudioServiceType; public int RequestSampleFmt; - public IntPtr GetBuffer2; + public nint GetBuffer2; public float QCompress; public float QBlur; public int QMin; @@ -97,23 +97,23 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native public int MaxQdiff; public int RcBufferSize; public int RcOverrideCount; - public IntPtr RcOverride; + public nint RcOverride; public long RcMaxRate; public long RcMinRate; public float RcMax_available_vbv_use; public float RcMin_vbv_overflow_use; public int RcInitialBufferOccupancy; public int Trellis; - public IntPtr StatsOut; - public IntPtr StatsIn; + public nint StatsOut; + public nint StatsIn; public int WorkaroundBugs; public int StrictStdCompliance; public int ErrorConcealment; public int Debug; public int ErrRecognition; public long ReorderedOpaque; - public IntPtr HwAccel; - public IntPtr HwAccelContext; + public nint HwAccel; + public nint HwAccelContext; public Array8 Error; public int DctAlgo; public int IdctAlgo; @@ -124,48 +124,48 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native public int ThreadType; public int ActiveThreadType; public int ThreadSafeCallbacks; - public IntPtr Execute; - public IntPtr Execute2; + public nint Execute; + public nint Execute2; public int NsseWeight; public int Profile; public int Level; public int SkipLoopFilter; public int SkipIdct; public int SkipFrame; - public IntPtr SubtitleHeader; + public nint SubtitleHeader; public int SubtitleHeaderSize; public int InitialPadding; public AVRational Framerate; public int SwPixFmt; public AVRational PktTimebase; - public IntPtr CodecDescriptor; + public nint CodecDescriptor; public long PtsCorrectionNumFaultyPts; public long PtsCorrectionNumFaultyDts; public long PtsCorrectionLastPts; public long PtsCorrectionLastDts; - public IntPtr SubCharenc; + public nint SubCharenc; public int SubCharencMode; public int SkipAlpha; public int SeekPreroll; public int DebugMv; - public IntPtr ChromaIntraMatrix; - public IntPtr DumpSeparator; - public IntPtr CodecWhitelist; + public nint ChromaIntraMatrix; + public nint DumpSeparator; + public nint CodecWhitelist; public uint Properties; - public IntPtr CodedSideData; + public nint CodedSideData; public int NbCodedSideData; - public IntPtr HwFramesCtx; + public nint HwFramesCtx; public int SubTextFormat; public int TrailingPadding; public long MaxPixels; - public IntPtr HwDeviceCtx; + public nint HwDeviceCtx; public int HwAccelFlags; public int applyCropping; public int ExtraHwFrames; public int DiscardDamagedPercentage; public long MaxSamples; public int ExportSideData; - public IntPtr GetEncodeBuffer; + public nint GetEncodeBuffer; #pragma warning restore CS0649 } } diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVFrame.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVFrame.cs index a1eb7a090..97c30c718 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVFrame.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVFrame.cs @@ -6,9 +6,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native struct AVFrame { #pragma warning disable CS0649 // Field is never assigned to - public Array8 Data; + public Array8 Data; public Array8 LineSize; - public IntPtr ExtendedData; + public nint ExtendedData; public int Width; public int Height; public int NumSamples; @@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native public int CodedPictureNumber; public int DisplayPictureNumber; public int Quality; - public IntPtr Opaque; + public nint Opaque; public int RepeatPicture; public int InterlacedFrame; public int TopFieldFirst; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodec.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodec.cs index ceb8a3b01..95926298c 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodec.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodec.cs @@ -8,12 +8,12 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native public T Base; public int CapsInternalOrCbType; public int PrivDataSize; - public IntPtr UpdateThreadContext; - public IntPtr UpdateThreadContextForUser; - public IntPtr Defaults; - public IntPtr InitStaticData; - public IntPtr Init; - public IntPtr CodecCallback; + public nint UpdateThreadContext; + public nint UpdateThreadContextForUser; + public nint Defaults; + public nint InitStaticData; + public nint Init; + public nint CodecCallback; #pragma warning restore CS0649 // NOTE: There is more after, but the layout kind of changed a bit and we don't need more than this. This is safe as we only manipulate this behind a reference. diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodecLegacy.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodecLegacy.cs index 03eba311c..873d2518a 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodecLegacy.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodecLegacy.cs @@ -8,14 +8,14 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native public T Base; public uint CapsInternalOrCbType; public int PrivDataSize; - public IntPtr UpdateThreadContext; - public IntPtr UpdateThreadContextForUser; - public IntPtr Defaults; - public IntPtr InitStaticData; - public IntPtr Init; - public IntPtr EncodeSub; - public IntPtr Encode2; - public IntPtr Decode; + public nint UpdateThreadContext; + public nint UpdateThreadContextForUser; + public nint Defaults; + public nint InitStaticData; + public nint Init; + public nint EncodeSub; + public nint Encode2; + public nint Decode; #pragma warning restore CS0649 // NOTE: There is more after, but the layout kind of changed a bit and we don't need more than this. This is safe as we only manipulate this behind a reference. diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFmpegApi.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFmpegApi.cs index 5167ff9fe..7b0c2a8ad 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFmpegApi.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFmpegApi.cs @@ -37,9 +37,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native } - private static bool TryLoadWhitelistedLibrary(string libraryName, Assembly assembly, DllImportSearchPath? searchPath, out IntPtr handle) + private static bool TryLoadWhitelistedLibrary(string libraryName, Assembly assembly, DllImportSearchPath? searchPath, out nint handle) { - handle = IntPtr.Zero; + handle = nint.Zero; if (_librariesWhitelist.TryGetValue(libraryName, out var value)) { @@ -71,7 +71,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native return handle; } - return IntPtr.Zero; + return nint.Zero; }); } diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs index 65fb7b4ad..c13cfe1aa 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs @@ -11,9 +11,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg public int RequestedWidth { get; } public int RequestedHeight { get; } - public Plane YPlane => new((IntPtr)Frame->Data[0], Stride * Height); - public Plane UPlane => new((IntPtr)Frame->Data[1], UvStride * UvHeight); - public Plane VPlane => new((IntPtr)Frame->Data[2], UvStride * UvHeight); + public Plane YPlane => new((nint)Frame->Data[0], Stride * Height); + public Plane UPlane => new((nint)Frame->Data[1], UvStride * UvHeight); + public Plane VPlane => new((nint)Frame->Data[2], UvStride * UvHeight); public FrameField Field => Frame->InterlacedFrame != 0 ? FrameField.Interlaced : FrameField.Progressive; diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/Common/MemoryAllocator.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/Common/MemoryAllocator.cs index c75cfeb0f..18ed172f8 100644 --- a/src/Ryujinx.Graphics.Nvdec.Vp9/Common/MemoryAllocator.cs +++ b/src/Ryujinx.Graphics.Nvdec.Vp9/Common/MemoryAllocator.cs @@ -11,7 +11,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Common private struct PoolItem { - public IntPtr Pointer; + public nint Pointer; public int Length; public bool InUse; } @@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Common { int lengthInBytes = Unsafe.SizeOf() * length; - IntPtr ptr = IntPtr.Zero; + nint ptr = nint.Zero; for (int i = 0; i < PoolEntries; i++) { @@ -36,7 +36,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Common } } - if (ptr == IntPtr.Zero) + if (ptr == nint.Zero) { ptr = Marshal.AllocHGlobal(lengthInBytes); @@ -47,7 +47,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Common if (!item.InUse) { item.InUse = true; - if (item.Pointer != IntPtr.Zero) + if (item.Pointer != nint.Zero) { Marshal.FreeHGlobal(item.Pointer); } @@ -63,7 +63,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Common public unsafe void Free(ArrayPtr arr) where T : unmanaged { - IntPtr ptr = (IntPtr)arr.ToPointer(); + nint ptr = (nint)arr.ToPointer(); for (int i = 0; i < PoolEntries; i++) { @@ -83,10 +83,10 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Common { ref PoolItem item = ref _pool[i]; - if (item.Pointer != IntPtr.Zero) + if (item.Pointer != nint.Zero) { Marshal.FreeHGlobal(item.Pointer); - item.Pointer = IntPtr.Zero; + item.Pointer = nint.Zero; } } } diff --git a/src/Ryujinx.Graphics.Nvdec.Vp9/Types/Surface.cs b/src/Ryujinx.Graphics.Nvdec.Vp9/Types/Surface.cs index 372b1d2b4..d9bda185b 100644 --- a/src/Ryujinx.Graphics.Nvdec.Vp9/Types/Surface.cs +++ b/src/Ryujinx.Graphics.Nvdec.Vp9/Types/Surface.cs @@ -11,9 +11,9 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Types public ArrayPtr UBuffer; public ArrayPtr VBuffer; - public readonly unsafe Plane YPlane => new((IntPtr)YBuffer.ToPointer(), YBuffer.Length); - public readonly unsafe Plane UPlane => new((IntPtr)UBuffer.ToPointer(), UBuffer.Length); - public readonly unsafe Plane VPlane => new((IntPtr)VBuffer.ToPointer(), VBuffer.Length); + public readonly unsafe Plane YPlane => new((nint)YBuffer.ToPointer(), YBuffer.Length); + public readonly unsafe Plane UPlane => new((nint)UBuffer.ToPointer(), UBuffer.Length); + public readonly unsafe Plane VPlane => new((nint)VBuffer.ToPointer(), VBuffer.Length); public readonly FrameField Field => FrameField.Progressive; @@ -30,7 +30,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Types public bool HighBd { get; } - private readonly IntPtr _pointer; + private readonly nint _pointer; public Surface(int width, int height) { @@ -53,7 +53,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Types int frameSize = (HighBd ? 2 : 1) * (yplaneSize + 2 * uvplaneSize); - IntPtr pointer = Marshal.AllocHGlobal(frameSize); + nint pointer = Marshal.AllocHGlobal(frameSize); _pointer = pointer; Width = width; Height = height; diff --git a/src/Ryujinx.Graphics.OpenGL/Buffer.cs b/src/Ryujinx.Graphics.OpenGL/Buffer.cs index 2a5143101..33ca25174 100644 --- a/src/Ryujinx.Graphics.OpenGL/Buffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Buffer.cs @@ -19,11 +19,11 @@ namespace Ryujinx.Graphics.OpenGL GL.ClearBufferSubData( BufferTarget.CopyWriteBuffer, PixelInternalFormat.Rgba8ui, - (IntPtr)offset, - (IntPtr)size, + (nint)offset, + (nint)size, PixelFormat.RgbaInteger, PixelType.UnsignedByte, - (IntPtr)valueArr); + (nint)valueArr); } } @@ -37,7 +37,7 @@ namespace Ryujinx.Graphics.OpenGL int handle = GL.GenBuffer(); GL.BindBuffer(BufferTarget.CopyWriteBuffer, handle); - GL.BufferData(BufferTarget.CopyWriteBuffer, size, IntPtr.Zero, BufferUsageHint.DynamicDraw); + GL.BufferData(BufferTarget.CopyWriteBuffer, size, nint.Zero, BufferUsageHint.DynamicDraw); return Handle.FromInt32(handle); } @@ -47,7 +47,7 @@ namespace Ryujinx.Graphics.OpenGL int handle = GL.GenBuffer(); GL.BindBuffer(BufferTarget.CopyWriteBuffer, handle); - GL.BufferStorage(BufferTarget.CopyWriteBuffer, size, IntPtr.Zero, + GL.BufferStorage(BufferTarget.CopyWriteBuffer, size, nint.Zero, BufferStorageFlags.MapPersistentBit | BufferStorageFlags.MapCoherentBit | BufferStorageFlags.ClientStorageBit | @@ -64,9 +64,9 @@ namespace Ryujinx.Graphics.OpenGL GL.CopyBufferSubData( BufferTarget.CopyReadBuffer, BufferTarget.CopyWriteBuffer, - (IntPtr)srcOffset, - (IntPtr)dstOffset, - (IntPtr)size); + (nint)srcOffset, + (nint)dstOffset, + (nint)size); } public static unsafe PinnedSpan GetData(OpenGLRenderer renderer, BufferHandle buffer, int offset, int size) @@ -74,9 +74,9 @@ namespace Ryujinx.Graphics.OpenGL // Data in the persistent buffer and host array is guaranteed to be available // until the next time the host thread requests data. - if (renderer.PersistentBuffers.TryGet(buffer, out IntPtr ptr)) + if (renderer.PersistentBuffers.TryGet(buffer, out nint ptr)) { - return new PinnedSpan(IntPtr.Add(ptr, offset).ToPointer(), size); + return new PinnedSpan(nint.Add(ptr, offset).ToPointer(), size); } else if (HwCapabilities.UsePersistentBufferForFlush) { @@ -84,11 +84,11 @@ namespace Ryujinx.Graphics.OpenGL } else { - IntPtr target = renderer.PersistentBuffers.Default.GetHostArray(size); + nint target = renderer.PersistentBuffers.Default.GetHostArray(size); GL.BindBuffer(BufferTarget.CopyReadBuffer, buffer.ToInt32()); - GL.GetBufferSubData(BufferTarget.CopyReadBuffer, (IntPtr)offset, size, target); + GL.GetBufferSubData(BufferTarget.CopyReadBuffer, (nint)offset, size, target); return new PinnedSpan(target.ToPointer(), size); } @@ -97,7 +97,7 @@ namespace Ryujinx.Graphics.OpenGL public static void Resize(BufferHandle handle, int size) { GL.BindBuffer(BufferTarget.CopyWriteBuffer, handle.ToInt32()); - GL.BufferData(BufferTarget.CopyWriteBuffer, size, IntPtr.Zero, BufferUsageHint.StreamCopy); + GL.BufferData(BufferTarget.CopyWriteBuffer, size, nint.Zero, BufferUsageHint.StreamCopy); } public static void SetData(BufferHandle buffer, int offset, ReadOnlySpan data) @@ -108,7 +108,7 @@ namespace Ryujinx.Graphics.OpenGL { fixed (byte* ptr = data) { - GL.BufferSubData(BufferTarget.CopyWriteBuffer, (IntPtr)offset, data.Length, (IntPtr)ptr); + GL.BufferSubData(BufferTarget.CopyWriteBuffer, (nint)offset, data.Length, (nint)ptr); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Debugger.cs b/src/Ryujinx.Graphics.OpenGL/Debugger.cs index 7606bdbfd..c700b3b7c 100644 --- a/src/Ryujinx.Graphics.OpenGL/Debugger.cs +++ b/src/Ryujinx.Graphics.OpenGL/Debugger.cs @@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.OpenGL if (logLevel == GraphicsDebugLevel.None) { GL.Disable(EnableCap.DebugOutputSynchronous); - GL.DebugMessageCallback(null, IntPtr.Zero); + GL.DebugMessageCallback(null, nint.Zero); return; } @@ -45,7 +45,7 @@ namespace Ryujinx.Graphics.OpenGL _counter = 0; _debugCallback = GLDebugHandler; - GL.DebugMessageCallback(_debugCallback, IntPtr.Zero); + GL.DebugMessageCallback(_debugCallback, nint.Zero); Logger.Warning?.Print(LogClass.Gpu, "OpenGL Debugging is enabled. Performance will be negatively impacted."); } @@ -56,8 +56,8 @@ namespace Ryujinx.Graphics.OpenGL int id, DebugSeverity severity, int length, - IntPtr message, - IntPtr userParam) + nint message, + nint userParam) { string msg = Marshal.PtrToStringUTF8(message).Replace('\n', ' '); diff --git a/src/Ryujinx.Graphics.OpenGL/Helper/GLXHelper.cs b/src/Ryujinx.Graphics.OpenGL/Helper/GLXHelper.cs index ce2b20f7d..b722bbf04 100644 --- a/src/Ryujinx.Graphics.OpenGL/Helper/GLXHelper.cs +++ b/src/Ryujinx.Graphics.OpenGL/Helper/GLXHelper.cs @@ -15,14 +15,14 @@ namespace Ryujinx.Graphics.OpenGL.Helper { if (name != LibraryName) { - return IntPtr.Zero; + return nint.Zero; } - if (!NativeLibrary.TryLoad("libGL.so.1", assembly, path, out IntPtr result)) + if (!NativeLibrary.TryLoad("libGL.so.1", assembly, path, out nint result)) { if (!NativeLibrary.TryLoad("libGL.so", assembly, path, out result)) { - return IntPtr.Zero; + return nint.Zero; } } @@ -31,6 +31,6 @@ namespace Ryujinx.Graphics.OpenGL.Helper } [LibraryImport(LibraryName, EntryPoint = "glXGetCurrentContext")] - public static partial IntPtr GetCurrentContext(); + public static partial nint GetCurrentContext(); } } diff --git a/src/Ryujinx.Graphics.OpenGL/Helper/WGLHelper.cs b/src/Ryujinx.Graphics.OpenGL/Helper/WGLHelper.cs index be12ff999..7072bbd9f 100644 --- a/src/Ryujinx.Graphics.OpenGL/Helper/WGLHelper.cs +++ b/src/Ryujinx.Graphics.OpenGL/Helper/WGLHelper.cs @@ -10,6 +10,6 @@ namespace Ryujinx.Graphics.OpenGL.Helper private const string LibraryName = "OPENGL32.DLL"; [LibraryImport(LibraryName, EntryPoint = "wglGetCurrentContext")] - public static partial IntPtr GetCurrentContext(); + public static partial nint GetCurrentContext(); } } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs index 22f4c04cd..8e728a2bb 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs @@ -97,7 +97,7 @@ namespace Ryujinx.Graphics.OpenGL.Image SizedInternalFormat format = (SizedInternalFormat)FormatTable.GetFormatInfo(Info.Format).PixelInternalFormat; - GL.TexBufferRange(TextureBufferTarget.TextureBuffer, format, _buffer.ToInt32(), (IntPtr)buffer.Offset, buffer.Size); + GL.TexBufferRange(TextureBufferTarget.TextureBuffer, format, _buffer.ToInt32(), (nint)buffer.Offset, buffer.Size); } public void Dispose() diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs index 89bd5e4ff..e08da7013 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs @@ -464,7 +464,7 @@ namespace Ryujinx.Graphics.OpenGL.Image _copyPboSize = requiredSize; GL.BindBuffer(BufferTarget.PixelPackBuffer, _copyPboHandle); - GL.BufferData(BufferTarget.PixelPackBuffer, requiredSize, IntPtr.Zero, BufferUsageHint.DynamicCopy); + GL.BufferData(BufferTarget.PixelPackBuffer, requiredSize, nint.Zero, BufferUsageHint.DynamicCopy); } } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs index b0859c49e..a89dd5131 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs @@ -282,7 +282,7 @@ namespace Ryujinx.Graphics.OpenGL.Image } else { - IntPtr target = _renderer.PersistentBuffers.Default.GetHostArray(size); + nint target = _renderer.PersistentBuffers.Default.GetHostArray(size); WriteTo(target); @@ -307,7 +307,7 @@ namespace Ryujinx.Graphics.OpenGL.Image } else { - IntPtr target = _renderer.PersistentBuffers.Default.GetHostArray(size); + nint target = _renderer.PersistentBuffers.Default.GetHostArray(size); int offset = WriteTo2D(target, layer, level); @@ -339,15 +339,15 @@ namespace Ryujinx.Graphics.OpenGL.Image public void WriteToPbo(int offset, bool forceBgra) { - WriteTo(IntPtr.Zero + offset, forceBgra); + WriteTo(nint.Zero + offset, forceBgra); } public int WriteToPbo2D(int offset, int layer, int level) { - return WriteTo2D(IntPtr.Zero + offset, layer, level); + return WriteTo2D(nint.Zero + offset, layer, level); } - private int WriteTo2D(IntPtr data, int layer, int level) + private int WriteTo2D(nint data, int layer, int level) { TextureTarget target = Target.Convert(); @@ -390,7 +390,7 @@ namespace Ryujinx.Graphics.OpenGL.Image return 0; } - private void WriteTo(IntPtr data, bool forceBgra = false) + private void WriteTo(nint data, bool forceBgra = false) { TextureTarget target = Target.Convert(); @@ -457,7 +457,7 @@ namespace Ryujinx.Graphics.OpenGL.Image var dataSpan = data.Span; fixed (byte* ptr = dataSpan) { - ReadFrom((IntPtr)ptr, dataSpan.Length); + ReadFrom((nint)ptr, dataSpan.Length); } } } @@ -474,7 +474,7 @@ namespace Ryujinx.Graphics.OpenGL.Image int width = Math.Max(Info.Width >> level, 1); int height = Math.Max(Info.Height >> level, 1); - ReadFrom2D((IntPtr)ptr, layer, level, 0, 0, width, height); + ReadFrom2D((nint)ptr, layer, level, 0, 0, width, height); } } } @@ -492,7 +492,7 @@ namespace Ryujinx.Graphics.OpenGL.Image fixed (byte* ptr = data.Span) { ReadFrom2D( - (IntPtr)ptr, + (nint)ptr, layer, level, region.X, @@ -507,15 +507,15 @@ namespace Ryujinx.Graphics.OpenGL.Image public void ReadFromPbo(int offset, int size) { - ReadFrom(IntPtr.Zero + offset, size); + ReadFrom(nint.Zero + offset, size); } public void ReadFromPbo2D(int offset, int layer, int level, int width, int height) { - ReadFrom2D(IntPtr.Zero + offset, layer, level, 0, 0, width, height); + ReadFrom2D(nint.Zero + offset, layer, level, 0, 0, width, height); } - private void ReadFrom2D(IntPtr data, int layer, int level, int x, int y, int width, int height) + private void ReadFrom2D(nint data, int layer, int level, int x, int y, int width, int height) { int mipSize = Info.GetMipSize2D(level); @@ -535,7 +535,7 @@ namespace Ryujinx.Graphics.OpenGL.Image return data; } - private void ReadFrom2D(IntPtr data, int layer, int level, int x, int y, int width, int height, int mipSize) + private void ReadFrom2D(nint data, int layer, int level, int x, int y, int width, int height, int mipSize) { TextureTarget target = Target.Convert(); @@ -694,7 +694,7 @@ namespace Ryujinx.Graphics.OpenGL.Image } } - private void ReadFrom(IntPtr data, int size) + private void ReadFrom(nint data, int size) { TextureTarget target = Target.Convert(); int baseLevel = 0; diff --git a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs index ebfe3ad64..28ebe88a5 100644 --- a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs +++ b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs @@ -14,7 +14,7 @@ namespace Ryujinx.Graphics.OpenGL private readonly PersistentBuffer _main = new(); private readonly PersistentBuffer _background = new(); - private readonly Dictionary _maps = new(); + private readonly Dictionary _maps = new(); public PersistentBuffer Default => BackgroundContextWorker.InBackground ? _background : _main; @@ -27,7 +27,7 @@ namespace Ryujinx.Graphics.OpenGL public void Map(BufferHandle handle, int size) { GL.BindBuffer(BufferTarget.CopyWriteBuffer, handle.ToInt32()); - IntPtr ptr = GL.MapBufferRange(BufferTarget.CopyWriteBuffer, IntPtr.Zero, size, BufferAccessMask.MapReadBit | BufferAccessMask.MapPersistentBit); + nint ptr = GL.MapBufferRange(BufferTarget.CopyWriteBuffer, nint.Zero, size, BufferAccessMask.MapReadBit | BufferAccessMask.MapPersistentBit); _maps[handle] = ptr; } @@ -43,7 +43,7 @@ namespace Ryujinx.Graphics.OpenGL } } - public bool TryGet(BufferHandle handle, out IntPtr ptr) + public bool TryGet(BufferHandle handle, out nint ptr) { return _maps.TryGetValue(handle, out ptr); } @@ -51,12 +51,12 @@ namespace Ryujinx.Graphics.OpenGL class PersistentBuffer : IDisposable { - private IntPtr _bufferMap; + private nint _bufferMap; private int _copyBufferHandle; private int _copyBufferSize; private byte[] _data; - private IntPtr _dataMap; + private nint _dataMap; private void EnsureBuffer(int requiredSize) { @@ -73,19 +73,19 @@ namespace Ryujinx.Graphics.OpenGL _copyBufferSize = requiredSize; GL.BindBuffer(BufferTarget.CopyWriteBuffer, _copyBufferHandle); - GL.BufferStorage(BufferTarget.CopyWriteBuffer, requiredSize, IntPtr.Zero, BufferStorageFlags.MapReadBit | BufferStorageFlags.MapPersistentBit); + GL.BufferStorage(BufferTarget.CopyWriteBuffer, requiredSize, nint.Zero, BufferStorageFlags.MapReadBit | BufferStorageFlags.MapPersistentBit); - _bufferMap = GL.MapBufferRange(BufferTarget.CopyWriteBuffer, IntPtr.Zero, requiredSize, BufferAccessMask.MapReadBit | BufferAccessMask.MapPersistentBit); + _bufferMap = GL.MapBufferRange(BufferTarget.CopyWriteBuffer, nint.Zero, requiredSize, BufferAccessMask.MapReadBit | BufferAccessMask.MapPersistentBit); } } - public unsafe IntPtr GetHostArray(int requiredSize) + public unsafe nint GetHostArray(int requiredSize) { if (_data == null || _data.Length < requiredSize) { _data = GC.AllocateUninitializedArray(requiredSize, true); - _dataMap = (IntPtr)Unsafe.AsPointer(ref MemoryMarshal.GetArrayDataReference(_data)); + _dataMap = (nint)Unsafe.AsPointer(ref MemoryMarshal.GetArrayDataReference(_data)); } return _dataMap; @@ -95,7 +95,7 @@ namespace Ryujinx.Graphics.OpenGL { GL.MemoryBarrier(MemoryBarrierFlags.ClientMappedBufferBarrierBit); - IntPtr sync = GL.FenceSync(SyncCondition.SyncGpuCommandsComplete, WaitSyncFlags.None); + nint sync = GL.FenceSync(SyncCondition.SyncGpuCommandsComplete, WaitSyncFlags.None); WaitSyncStatus syncResult = GL.ClientWaitSync(sync, ClientWaitSyncFlags.SyncFlushCommandsBit, 1000000000); if (syncResult == WaitSyncStatus.TimeoutExpired) @@ -143,7 +143,7 @@ namespace Ryujinx.Graphics.OpenGL GL.BindBuffer(BufferTarget.CopyReadBuffer, buffer.ToInt32()); GL.BindBuffer(BufferTarget.CopyWriteBuffer, _copyBufferHandle); - GL.CopyBufferSubData(BufferTarget.CopyReadBuffer, BufferTarget.CopyWriteBuffer, (IntPtr)offset, IntPtr.Zero, size); + GL.CopyBufferSubData(BufferTarget.CopyReadBuffer, BufferTarget.CopyWriteBuffer, (nint)offset, nint.Zero, size); GL.BindBuffer(BufferTarget.CopyWriteBuffer, 0); diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index 27aacac15..096e2e5eb 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -23,7 +23,7 @@ namespace Ryujinx.Graphics.OpenGL private VertexArray _vertexArray; private Framebuffer _framebuffer; - private IntPtr _indexBaseOffset; + private nint _indexBaseOffset; private DrawElementsType _elementsType; @@ -358,7 +358,7 @@ namespace Ryujinx.Graphics.OpenGL break; } - IntPtr indexBaseOffset = _indexBaseOffset + firstIndex * indexElemSize; + nint indexBaseOffset = _indexBaseOffset + firstIndex * indexElemSize; if (_primitiveType == PrimitiveType.Quads && !HwCapabilities.SupportsQuads) { @@ -396,7 +396,7 @@ namespace Ryujinx.Graphics.OpenGL private void DrawQuadsIndexedImpl( int indexCount, int instanceCount, - IntPtr indexBaseOffset, + nint indexBaseOffset, int indexElemSize, int firstVertex, int firstInstance) @@ -447,7 +447,7 @@ namespace Ryujinx.Graphics.OpenGL } else { - IntPtr[] indices = new IntPtr[quadsCount]; + nint[] indices = new nint[quadsCount]; int[] counts = new int[quadsCount]; @@ -475,7 +475,7 @@ namespace Ryujinx.Graphics.OpenGL private void DrawQuadStripIndexedImpl( int indexCount, int instanceCount, - IntPtr indexBaseOffset, + nint indexBaseOffset, int indexElemSize, int firstVertex, int firstInstance) @@ -483,7 +483,7 @@ namespace Ryujinx.Graphics.OpenGL // TODO: Instanced rendering. int quadsCount = (indexCount - 2) / 2; - IntPtr[] indices = new IntPtr[quadsCount]; + nint[] indices = new nint[quadsCount]; int[] counts = new int[quadsCount]; @@ -516,7 +516,7 @@ namespace Ryujinx.Graphics.OpenGL private void DrawIndexedImpl( int indexCount, int instanceCount, - IntPtr indexBaseOffset, + nint indexBaseOffset, int firstVertex, int firstInstance) { @@ -589,7 +589,7 @@ namespace Ryujinx.Graphics.OpenGL GL.BindBuffer((BufferTarget)All.DrawIndirectBuffer, indirectBuffer.Handle.ToInt32()); - GL.DrawElementsIndirect(_primitiveType, _elementsType, (IntPtr)indirectBuffer.Offset); + GL.DrawElementsIndirect(_primitiveType, _elementsType, (nint)indirectBuffer.Offset); _vertexArray.RestoreIndexBuffer(); @@ -614,8 +614,8 @@ namespace Ryujinx.Graphics.OpenGL GL.MultiDrawElementsIndirectCount( _primitiveType, (All)_elementsType, - (IntPtr)indirectBuffer.Offset, - (IntPtr)parameterBuffer.Offset, + (nint)indirectBuffer.Offset, + (nint)parameterBuffer.Offset, maxDrawCount, stride); @@ -636,7 +636,7 @@ namespace Ryujinx.Graphics.OpenGL GL.BindBuffer((BufferTarget)All.DrawIndirectBuffer, indirectBuffer.Handle.ToInt32()); - GL.DrawArraysIndirect(_primitiveType, (IntPtr)indirectBuffer.Offset); + GL.DrawArraysIndirect(_primitiveType, (nint)indirectBuffer.Offset); PostDraw(); } @@ -656,8 +656,8 @@ namespace Ryujinx.Graphics.OpenGL GL.MultiDrawArraysIndirectCount( _primitiveType, - (IntPtr)indirectBuffer.Offset, - (IntPtr)parameterBuffer.Offset, + (nint)indirectBuffer.Offset, + (nint)parameterBuffer.Offset, maxDrawCount, stride); @@ -972,7 +972,7 @@ namespace Ryujinx.Graphics.OpenGL { _elementsType = type.Convert(); - _indexBaseOffset = (IntPtr)buffer.Offset; + _indexBaseOffset = (nint)buffer.Offset; EnsureVertexArray(); @@ -1450,11 +1450,11 @@ namespace Ryujinx.Graphics.OpenGL if (buffer.Handle == BufferHandle.Null) { - GL.BindBufferRange(target, assignment.Binding, 0, IntPtr.Zero, 0); + GL.BindBufferRange(target, assignment.Binding, 0, nint.Zero, 0); continue; } - GL.BindBufferRange(target, assignment.Binding, buffer.Handle.ToInt32(), (IntPtr)buffer.Offset, buffer.Size); + GL.BindBufferRange(target, assignment.Binding, buffer.Handle.ToInt32(), (nint)buffer.Offset, buffer.Size); } } diff --git a/src/Ryujinx.Graphics.OpenGL/Program.cs b/src/Ryujinx.Graphics.OpenGL/Program.cs index 19de06f8f..608a03451 100644 --- a/src/Ryujinx.Graphics.OpenGL/Program.cs +++ b/src/Ryujinx.Graphics.OpenGL/Program.cs @@ -86,7 +86,7 @@ namespace Ryujinx.Graphics.OpenGL { fixed (byte* ptr = code) { - GL.ProgramBinary(Handle, binaryFormat, (IntPtr)ptr, code.Length - 4); + GL.ProgramBinary(Handle, binaryFormat, (nint)ptr, code.Length - 4); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs index 0a85970d7..a5acd8dce 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs @@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries public int Query { get; } private readonly int _buffer; - private readonly IntPtr _bufferMap; + private readonly nint _bufferMap; private readonly QueryTarget _type; public BufferedQuery(QueryTarget type) @@ -29,9 +29,9 @@ namespace Ryujinx.Graphics.OpenGL.Queries unsafe { long defaultValue = DefaultValue; - GL.BufferStorage(BufferTarget.QueryBuffer, sizeof(long), (IntPtr)(&defaultValue), BufferStorageFlags.MapReadBit | BufferStorageFlags.MapWriteBit | BufferStorageFlags.MapPersistentBit); + GL.BufferStorage(BufferTarget.QueryBuffer, sizeof(long), (nint)(&defaultValue), BufferStorageFlags.MapReadBit | BufferStorageFlags.MapWriteBit | BufferStorageFlags.MapPersistentBit); } - _bufferMap = GL.MapBufferRange(BufferTarget.QueryBuffer, IntPtr.Zero, sizeof(long), BufferAccessMask.MapReadBit | BufferAccessMask.MapWriteBit | BufferAccessMask.MapPersistentBit); + _bufferMap = GL.MapBufferRange(BufferTarget.QueryBuffer, nint.Zero, sizeof(long), BufferAccessMask.MapReadBit | BufferAccessMask.MapWriteBit | BufferAccessMask.MapPersistentBit); } public void Reset() diff --git a/src/Ryujinx.Graphics.OpenGL/Sync.cs b/src/Ryujinx.Graphics.OpenGL/Sync.cs index eba1638a3..e8f7ebc00 100644 --- a/src/Ryujinx.Graphics.OpenGL/Sync.cs +++ b/src/Ryujinx.Graphics.OpenGL/Sync.cs @@ -11,7 +11,7 @@ namespace Ryujinx.Graphics.OpenGL private class SyncHandle { public ulong ID; - public IntPtr Handle; + public nint Handle; } private ulong _firstHandle = 0; @@ -50,7 +50,7 @@ namespace Ryujinx.Graphics.OpenGL { lock (handle) { - if (handle.Handle == IntPtr.Zero) + if (handle.Handle == nint.Zero) { continue; } @@ -96,7 +96,7 @@ namespace Ryujinx.Graphics.OpenGL { lock (result) { - if (result.Handle == IntPtr.Zero) + if (result.Handle == nint.Zero) { return; } @@ -140,7 +140,7 @@ namespace Ryujinx.Graphics.OpenGL _firstHandle = first.ID + 1; _handles.RemoveAt(0); GL.DeleteSync(first.Handle); - first.Handle = IntPtr.Zero; + first.Handle = nint.Zero; } } } @@ -161,7 +161,7 @@ namespace Ryujinx.Graphics.OpenGL lock (handle) { GL.DeleteSync(handle.Handle); - handle.Handle = IntPtr.Zero; + handle.Handle = nint.Zero; } } diff --git a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs index 32211e783..2db84421f 100644 --- a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs @@ -56,7 +56,7 @@ namespace Ryujinx.Graphics.OpenGL minVertexCount = vertexCount; } - GL.BindVertexBuffer(bindingIndex, vb.Buffer.Handle.ToInt32(), (IntPtr)vb.Buffer.Offset, vb.Stride); + GL.BindVertexBuffer(bindingIndex, vb.Buffer.Handle.ToInt32(), (nint)vb.Buffer.Offset, vb.Stride); GL.VertexBindingDivisor(bindingIndex, vb.Divisor); _vertexBuffersInUse |= 1u << bindingIndex; } @@ -64,7 +64,7 @@ namespace Ryujinx.Graphics.OpenGL { if ((_vertexBuffersInUse & (1u << bindingIndex)) != 0) { - GL.BindVertexBuffer(bindingIndex, 0, IntPtr.Zero, 0); + GL.BindVertexBuffer(bindingIndex, 0, nint.Zero, 0); _vertexBuffersInUse &= ~(1u << bindingIndex); } } @@ -188,7 +188,7 @@ namespace Ryujinx.Graphics.OpenGL Buffer.Copy(vb.Buffer.Handle, tempVertexBuffer, vb.Buffer.Offset, currentTempVbOffset, vb.Buffer.Size); Buffer.Clear(tempVertexBuffer, currentTempVbOffset + vb.Buffer.Size, requiredSize - vb.Buffer.Size, 0); - GL.BindVertexBuffer(vbIndex, tempVertexBuffer.ToInt32(), (IntPtr)currentTempVbOffset, vb.Stride); + GL.BindVertexBuffer(vbIndex, tempVertexBuffer.ToInt32(), (nint)currentTempVbOffset, vb.Stride); currentTempVbOffset += requiredSize; _vertexBuffersLimited |= 1u << vbIndex; @@ -234,7 +234,7 @@ namespace Ryujinx.Graphics.OpenGL ref var vb = ref _vertexBuffers[vbIndex]; - GL.BindVertexBuffer(vbIndex, vb.Buffer.Handle.ToInt32(), (IntPtr)vb.Buffer.Offset, vb.Stride); + GL.BindVertexBuffer(vbIndex, vb.Buffer.Handle.ToInt32(), (nint)vb.Buffer.Offset, vb.Stride); buffersLimited &= ~(1u << vbIndex); } diff --git a/src/Ryujinx.Graphics.Video/Plane.cs b/src/Ryujinx.Graphics.Video/Plane.cs index b895cad90..4e4e65b32 100644 --- a/src/Ryujinx.Graphics.Video/Plane.cs +++ b/src/Ryujinx.Graphics.Video/Plane.cs @@ -2,5 +2,5 @@ using System; namespace Ryujinx.Graphics.Video { - public readonly record struct Plane(IntPtr Pointer, int Length); + public readonly record struct Plane(nint Pointer, int Length); } diff --git a/src/Ryujinx.Graphics.Vulkan/BufferHolder.cs b/src/Ryujinx.Graphics.Vulkan/BufferHolder.cs index e840fdc02..6dce6abb5 100644 --- a/src/Ryujinx.Graphics.Vulkan/BufferHolder.cs +++ b/src/Ryujinx.Graphics.Vulkan/BufferHolder.cs @@ -40,7 +40,7 @@ namespace Ryujinx.Graphics.Vulkan public int Size { get; } - private readonly IntPtr _map; + private readonly nint _map; private readonly MultiFenceHolder _waitable; @@ -370,7 +370,7 @@ namespace Ryujinx.Graphics.Vulkan return Unsafe.As(ref handle); } - public IntPtr Map(int offset, int mappingSize) + public nint Map(int offset, int mappingSize) { return _map; } @@ -435,7 +435,7 @@ namespace Ryujinx.Graphics.Vulkan Span result; - if (_map != IntPtr.Zero) + if (_map != nint.Zero) { result = GetDataStorage(offset, size); @@ -470,7 +470,7 @@ namespace Ryujinx.Graphics.Vulkan { int mappingSize = Math.Min(size, Size - offset); - if (_map != IntPtr.Zero) + if (_map != nint.Zero) { return new Span((void*)(_map + offset), mappingSize); } @@ -515,7 +515,7 @@ namespace Ryujinx.Graphics.Vulkan bool allowMirror = _useMirrors && allowCbsWait && cbs != null && _activeType <= BufferAllocationType.HostMapped; - if (_map != IntPtr.Zero) + if (_map != nint.Zero) { // If persistently mapped, set the data directly if the buffer is not currently in use. bool isRented = _buffer.HasRentedCommandBufferDependency(_gd.CommandBufferPool); @@ -630,7 +630,7 @@ namespace Ryujinx.Graphics.Vulkan return; } - if (_map != IntPtr.Zero) + if (_map != nint.Zero) { data[..dataSize].CopyTo(new Span((void*)(_map + offset), dataSize)); } diff --git a/src/Ryujinx.Graphics.Vulkan/HostMemoryAllocator.cs b/src/Ryujinx.Graphics.Vulkan/HostMemoryAllocator.cs index ff1565246..77c5f95c9 100644 --- a/src/Ryujinx.Graphics.Vulkan/HostMemoryAllocator.cs +++ b/src/Ryujinx.Graphics.Vulkan/HostMemoryAllocator.cs @@ -13,13 +13,13 @@ namespace Ryujinx.Graphics.Vulkan private readonly struct HostMemoryAllocation { public readonly Auto Allocation; - public readonly IntPtr Pointer; + public readonly nint Pointer; public readonly ulong Size; public ulong Start => (ulong)Pointer; public ulong End => (ulong)Pointer + Size; - public HostMemoryAllocation(Auto allocation, IntPtr pointer, ulong size) + public HostMemoryAllocation(Auto allocation, nint pointer, ulong size) { Allocation = allocation; Pointer = pointer; @@ -50,7 +50,7 @@ namespace Ryujinx.Graphics.Vulkan public unsafe bool TryImport( MemoryRequirements requirements, MemoryPropertyFlags flags, - IntPtr pointer, + nint pointer, ulong size) { lock (_lock) @@ -139,7 +139,7 @@ namespace Ryujinx.Graphics.Vulkan return true; } - public (Auto, ulong) GetExistingAllocation(IntPtr pointer, ulong size) + public (Auto, ulong) GetExistingAllocation(nint pointer, ulong size) { lock (_lock) { diff --git a/src/Ryujinx.Graphics.Vulkan/MemoryAllocation.cs b/src/Ryujinx.Graphics.Vulkan/MemoryAllocation.cs index 3f134e289..d0d0ac1e7 100644 --- a/src/Ryujinx.Graphics.Vulkan/MemoryAllocation.cs +++ b/src/Ryujinx.Graphics.Vulkan/MemoryAllocation.cs @@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Vulkan private readonly HostMemoryAllocator _hostMemory; public DeviceMemory Memory { get; } - public IntPtr HostPointer { get; } + public nint HostPointer { get; } public ulong Offset { get; } public ulong Size { get; } @@ -18,7 +18,7 @@ namespace Ryujinx.Graphics.Vulkan MemoryAllocatorBlockList owner, MemoryAllocatorBlockList.Block block, DeviceMemory memory, - IntPtr hostPointer, + nint hostPointer, ulong offset, ulong size) { @@ -33,7 +33,7 @@ namespace Ryujinx.Graphics.Vulkan public MemoryAllocation( HostMemoryAllocator hostMemory, DeviceMemory memory, - IntPtr hostPointer, + nint hostPointer, ulong offset, ulong size) { diff --git a/src/Ryujinx.Graphics.Vulkan/MemoryAllocatorBlockList.cs b/src/Ryujinx.Graphics.Vulkan/MemoryAllocatorBlockList.cs index 3d42ed7e2..4a0cb2a74 100644 --- a/src/Ryujinx.Graphics.Vulkan/MemoryAllocatorBlockList.cs +++ b/src/Ryujinx.Graphics.Vulkan/MemoryAllocatorBlockList.cs @@ -14,9 +14,9 @@ namespace Ryujinx.Graphics.Vulkan public class Block : IComparable { public DeviceMemory Memory { get; private set; } - public IntPtr HostPointer { get; private set; } + public nint HostPointer { get; private set; } public ulong Size { get; } - public bool Mapped => HostPointer != IntPtr.Zero; + public bool Mapped => HostPointer != nint.Zero; private readonly struct Range : IComparable { @@ -37,7 +37,7 @@ namespace Ryujinx.Graphics.Vulkan private readonly List _freeRanges; - public Block(DeviceMemory memory, IntPtr hostPointer, ulong size) + public Block(DeviceMemory memory, nint hostPointer, ulong size) { Memory = memory; HostPointer = hostPointer; @@ -146,7 +146,7 @@ namespace Ryujinx.Graphics.Vulkan if (Mapped) { api.UnmapMemory(device, Memory); - HostPointer = IntPtr.Zero; + HostPointer = nint.Zero; } if (Memory.Handle != 0) @@ -222,13 +222,13 @@ namespace Ryujinx.Graphics.Vulkan _api.AllocateMemory(_device, in memoryAllocateInfo, null, out var deviceMemory).ThrowOnError(); - IntPtr hostPointer = IntPtr.Zero; + nint hostPointer = nint.Zero; if (map) { void* pointer = null; _api.MapMemory(_device, deviceMemory, 0, blockAlignedSize, 0, ref pointer).ThrowOnError(); - hostPointer = (IntPtr)pointer; + hostPointer = (nint)pointer; } var newBlock = new Block(deviceMemory, hostPointer, blockAlignedSize); @@ -241,14 +241,14 @@ namespace Ryujinx.Graphics.Vulkan return new MemoryAllocation(this, newBlock, deviceMemory, GetHostPointer(newBlock, newBlockOffset), newBlockOffset, size); } - private static IntPtr GetHostPointer(Block block, ulong offset) + private static nint GetHostPointer(Block block, ulong offset) { - if (block.HostPointer == IntPtr.Zero) + if (block.HostPointer == nint.Zero) { - return IntPtr.Zero; + return nint.Zero; } - return (IntPtr)((nuint)block.HostPointer + offset); + return (nint)((nuint)block.HostPointer + offset); } public void Free(Block block, ulong offset, ulong size) diff --git a/src/Ryujinx.Graphics.Vulkan/MoltenVK/MVKConfiguration.cs b/src/Ryujinx.Graphics.Vulkan/MoltenVK/MVKConfiguration.cs index bdf606e82..271999375 100644 --- a/src/Ryujinx.Graphics.Vulkan/MoltenVK/MVKConfiguration.cs +++ b/src/Ryujinx.Graphics.Vulkan/MoltenVK/MVKConfiguration.cs @@ -90,7 +90,7 @@ namespace Ryujinx.Graphics.Vulkan.MoltenVK public Bool32 SemaphoreUseMTLFence; public MVKVkSemaphoreSupportStyle SemaphoreSupportStyle; public MVKConfigAutoGPUCaptureScope AutoGPUCaptureScope; - public IntPtr AutoGPUCaptureOutputFilepath; + public nint AutoGPUCaptureOutputFilepath; public Bool32 Texture1DAs2D; public Bool32 PreallocateDescriptors; public Bool32 UseCommandPooling; diff --git a/src/Ryujinx.Graphics.Vulkan/MoltenVK/MVKInitialization.cs b/src/Ryujinx.Graphics.Vulkan/MoltenVK/MVKInitialization.cs index 930d6b525..086c4e1df 100644 --- a/src/Ryujinx.Graphics.Vulkan/MoltenVK/MVKInitialization.cs +++ b/src/Ryujinx.Graphics.Vulkan/MoltenVK/MVKInitialization.cs @@ -12,16 +12,16 @@ namespace Ryujinx.Graphics.Vulkan.MoltenVK private const string VulkanLib = "libvulkan.dylib"; [LibraryImport("libMoltenVK.dylib")] - private static partial Result vkGetMoltenVKConfigurationMVK(IntPtr unusedInstance, out MVKConfiguration config, in IntPtr configSize); + private static partial Result vkGetMoltenVKConfigurationMVK(nint unusedInstance, out MVKConfiguration config, in nint configSize); [LibraryImport("libMoltenVK.dylib")] - private static partial Result vkSetMoltenVKConfigurationMVK(IntPtr unusedInstance, in MVKConfiguration config, in IntPtr configSize); + private static partial Result vkSetMoltenVKConfigurationMVK(nint unusedInstance, in MVKConfiguration config, in nint configSize); public static void Initialize() { - var configSize = (IntPtr)Marshal.SizeOf(); + var configSize = (nint)Marshal.SizeOf(); - vkGetMoltenVKConfigurationMVK(IntPtr.Zero, out MVKConfiguration config, configSize); + vkGetMoltenVKConfigurationMVK(nint.Zero, out MVKConfiguration config, configSize); config.UseMetalArgumentBuffers = true; @@ -30,7 +30,7 @@ namespace Ryujinx.Graphics.Vulkan.MoltenVK config.ResumeLostDevice = true; - vkSetMoltenVKConfigurationMVK(IntPtr.Zero, config, configSize); + vkSetMoltenVKConfigurationMVK(nint.Zero, config, configSize); } private static string[] Resolver(string path) diff --git a/src/Ryujinx.Graphics.Vulkan/NativeArray.cs b/src/Ryujinx.Graphics.Vulkan/NativeArray.cs index 7678b63c8..33377962b 100644 --- a/src/Ryujinx.Graphics.Vulkan/NativeArray.cs +++ b/src/Ryujinx.Graphics.Vulkan/NativeArray.cs @@ -40,7 +40,7 @@ namespace Ryujinx.Graphics.Vulkan { if (Pointer != null) { - Marshal.FreeHGlobal((IntPtr)Pointer); + Marshal.FreeHGlobal((nint)Pointer); Pointer = null; } } diff --git a/src/Ryujinx.Graphics.Vulkan/Queries/BufferedQuery.cs b/src/Ryujinx.Graphics.Vulkan/Queries/BufferedQuery.cs index c9a546648..5d48a6622 100644 --- a/src/Ryujinx.Graphics.Vulkan/Queries/BufferedQuery.cs +++ b/src/Ryujinx.Graphics.Vulkan/Queries/BufferedQuery.cs @@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.Vulkan.Queries private QueryPool _queryPool; private readonly BufferHolder _buffer; - private readonly IntPtr _bufferMap; + private readonly nint _bufferMap; private readonly CounterType _type; private readonly bool _result32Bit; private readonly bool _isSupported; diff --git a/src/Ryujinx.Graphics.Vulkan/Shader.cs b/src/Ryujinx.Graphics.Vulkan/Shader.cs index 1c8caffd9..f23b78f51 100644 --- a/src/Ryujinx.Graphics.Vulkan/Shader.cs +++ b/src/Ryujinx.Graphics.Vulkan/Shader.cs @@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.Vulkan // Take this lock when using them. private static readonly object _shaderOptionsLock = new(); - private static readonly IntPtr _ptrMainEntryPointName = Marshal.StringToHGlobalAnsi("main"); + private static readonly nint _ptrMainEntryPointName = Marshal.StringToHGlobalAnsi("main"); private readonly Vk _api; private readonly Device _device; diff --git a/src/Ryujinx.Graphics.Vulkan/VulkanDebugMessenger.cs b/src/Ryujinx.Graphics.Vulkan/VulkanDebugMessenger.cs index 496a90fbe..6dfcd8b6e 100644 --- a/src/Ryujinx.Graphics.Vulkan/VulkanDebugMessenger.cs +++ b/src/Ryujinx.Graphics.Vulkan/VulkanDebugMessenger.cs @@ -95,7 +95,7 @@ namespace Ryujinx.Graphics.Vulkan DebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData) { - var msg = Marshal.PtrToStringAnsi((IntPtr)pCallbackData->PMessage); + var msg = Marshal.PtrToStringAnsi((nint)pCallbackData->PMessage); if (messageSeverity.HasFlag(DebugUtilsMessageSeverityFlagsEXT.ErrorBitExt)) { diff --git a/src/Ryujinx.Graphics.Vulkan/VulkanInitialization.cs b/src/Ryujinx.Graphics.Vulkan/VulkanInitialization.cs index 2c327fdb7..352f271cc 100644 --- a/src/Ryujinx.Graphics.Vulkan/VulkanInitialization.cs +++ b/src/Ryujinx.Graphics.Vulkan/VulkanInitialization.cs @@ -94,8 +94,8 @@ namespace Ryujinx.Graphics.Vulkan ApiVersion = _maximumVulkanVersion, }; - IntPtr* ppEnabledExtensions = stackalloc IntPtr[enabledExtensions.Length]; - IntPtr* ppEnabledLayers = stackalloc IntPtr[enabledLayers.Count]; + nint* ppEnabledExtensions = stackalloc nint[enabledExtensions.Length]; + nint* ppEnabledLayers = stackalloc nint[enabledLayers.Count]; for (int i = 0; i < enabledExtensions.Length; i++) { @@ -587,7 +587,7 @@ namespace Ryujinx.Graphics.Vulkan var enabledExtensions = _requiredExtensions.Union(_desirableExtensions.Intersect(physicalDevice.DeviceExtensions)).ToArray(); - IntPtr* ppEnabledExtensions = stackalloc IntPtr[enabledExtensions.Length]; + nint* ppEnabledExtensions = stackalloc nint[enabledExtensions.Length]; for (int i = 0; i < enabledExtensions.Length; i++) { diff --git a/src/Ryujinx.Graphics.Vulkan/VulkanInstance.cs b/src/Ryujinx.Graphics.Vulkan/VulkanInstance.cs index 843d34125..69b75925e 100644 --- a/src/Ryujinx.Graphics.Vulkan/VulkanInstance.cs +++ b/src/Ryujinx.Graphics.Vulkan/VulkanInstance.cs @@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Vulkan _api = api; Instance = instance; - if (api.GetInstanceProcAddr(instance, "vkEnumerateInstanceVersion") == IntPtr.Zero) + if (api.GetInstanceProcAddr(instance, "vkEnumerateInstanceVersion") == nint.Zero) { InstanceVersion = Vk.Version10; } @@ -94,7 +94,7 @@ namespace Ryujinx.Graphics.Vulkan unsafe { - return extensionProperties.Select(x => Marshal.PtrToStringAnsi((IntPtr)x.ExtensionName)).ToImmutableHashSet(); + return extensionProperties.Select(x => Marshal.PtrToStringAnsi((nint)x.ExtensionName)).ToImmutableHashSet(); } } @@ -110,7 +110,7 @@ namespace Ryujinx.Graphics.Vulkan unsafe { - return layerProperties.Select(x => Marshal.PtrToStringAnsi((IntPtr)x.LayerName)).ToImmutableHashSet(); + return layerProperties.Select(x => Marshal.PtrToStringAnsi((nint)x.LayerName)).ToImmutableHashSet(); } } diff --git a/src/Ryujinx.Graphics.Vulkan/VulkanPhysicalDevice.cs b/src/Ryujinx.Graphics.Vulkan/VulkanPhysicalDevice.cs index 3bee1e9d8..b3f8fd756 100644 --- a/src/Ryujinx.Graphics.Vulkan/VulkanPhysicalDevice.cs +++ b/src/Ryujinx.Graphics.Vulkan/VulkanPhysicalDevice.cs @@ -31,7 +31,7 @@ namespace Ryujinx.Graphics.Vulkan unsafe { - DeviceName = Marshal.PtrToStringAnsi((IntPtr)physicalDeviceProperties.DeviceName); + DeviceName = Marshal.PtrToStringAnsi((nint)physicalDeviceProperties.DeviceName); } uint propertiesCount = 0; @@ -50,7 +50,7 @@ namespace Ryujinx.Graphics.Vulkan unsafe { - DeviceExtensions = extensionProperties.Select(x => Marshal.PtrToStringAnsi((IntPtr)x.ExtensionName)).ToImmutableHashSet(); + DeviceExtensions = extensionProperties.Select(x => Marshal.PtrToStringAnsi((nint)x.ExtensionName)).ToImmutableHashSet(); } } diff --git a/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs b/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs index a40b20f14..af2cfa17f 100644 --- a/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs +++ b/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs @@ -365,7 +365,7 @@ namespace Ryujinx.Graphics.Vulkan fixed (byte* deviceName = properties.DeviceName) { - GpuRenderer = Marshal.PtrToStringAnsi((IntPtr)deviceName); + GpuRenderer = Marshal.PtrToStringAnsi((nint)deviceName); } GpuVersion = $"Vulkan v{ParseStandardVulkanVersion(properties.ApiVersion)}, Driver v{ParseDriverVersion(ref properties)}"; diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/ISocket.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/ISocket.cs index fe2f8477f..cf32daf3b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/ISocket.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/ISocket.cs @@ -16,7 +16,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd ProtocolType ProtocolType { get; } - IntPtr Handle { get; } + nint Handle { get; } LinuxError Receive(out int receiveSize, Span buffer, BsdSocketFlags flags); diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs index c42b7201b..c9b811cf5 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs @@ -21,7 +21,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl public bool Blocking { get => Socket.Blocking; set => Socket.Blocking = value; } - public IntPtr Handle => Socket.Handle; + public nint Handle => Socket.Handle; public IPEndPoint RemoteEndPoint => Socket.RemoteEndPoint as IPEndPoint; diff --git a/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs b/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs index 7ea6e1481..ce52f84d9 100644 --- a/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs +++ b/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs @@ -40,7 +40,7 @@ namespace Ryujinx.Headless.SDL2.OpenGL private class OpenToolkitBindingsContext : IBindingsContext { - public IntPtr GetProcAddress(string procName) + public nint GetProcAddress(string procName) { return SDL_GL_GetProcAddress(procName); } @@ -48,11 +48,11 @@ namespace Ryujinx.Headless.SDL2.OpenGL private class SDL2OpenGLContext : IOpenGLContext { - private readonly IntPtr _context; - private readonly IntPtr _window; + private readonly nint _context; + private readonly nint _window; private readonly bool _shouldDisposeWindow; - public SDL2OpenGLContext(IntPtr context, IntPtr window, bool shouldDisposeWindow = true) + public SDL2OpenGLContext(nint context, nint window, bool shouldDisposeWindow = true) { _context = context; _window = window; @@ -65,14 +65,14 @@ namespace Ryujinx.Headless.SDL2.OpenGL // Ensure we share our contexts. SetupOpenGLAttributes(true, GraphicsDebugLevel.None); - IntPtr windowHandle = SDL_CreateWindow("Ryujinx background context window", 0, 0, 1, 1, SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL_WindowFlags.SDL_WINDOW_HIDDEN); - IntPtr context = SDL_GL_CreateContext(windowHandle); + nint windowHandle = SDL_CreateWindow("Ryujinx background context window", 0, 0, 1, 1, SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL_WindowFlags.SDL_WINDOW_HIDDEN); + nint context = SDL_GL_CreateContext(windowHandle); GL.LoadBindings(new OpenToolkitBindingsContext()); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 0)); - CheckResult(SDL_GL_MakeCurrent(windowHandle, IntPtr.Zero)); + CheckResult(SDL_GL_MakeCurrent(windowHandle, nint.Zero)); return new SDL2OpenGLContext(context, windowHandle); } @@ -96,7 +96,7 @@ namespace Ryujinx.Headless.SDL2.OpenGL } } - public bool HasContext() => SDL_GL_GetCurrentContext() != IntPtr.Zero; + public bool HasContext() => SDL_GL_GetCurrentContext() != nint.Zero; public void Dispose() { @@ -129,10 +129,10 @@ namespace Ryujinx.Headless.SDL2.OpenGL { // Ensure to not share this context with other contexts before this point. SetupOpenGLAttributes(false, _glLogLevel); - IntPtr context = SDL_GL_CreateContext(WindowHandle); + nint context = SDL_GL_CreateContext(WindowHandle); CheckResult(SDL_GL_SetSwapInterval(1)); - if (context == IntPtr.Zero) + if (context == nint.Zero) { string errorMessage = $"SDL_GL_CreateContext failed with error \"{SDL_GetError()}\""; @@ -190,7 +190,7 @@ namespace Ryujinx.Headless.SDL2.OpenGL Device.DisposeGpu(); // Unbind context and destroy everything - CheckResult(SDL_GL_MakeCurrent(WindowHandle, IntPtr.Zero)); + CheckResult(SDL_GL_MakeCurrent(WindowHandle, nint.Zero)); _openGLContext.Dispose(); } diff --git a/src/Ryujinx.Headless.SDL2/Vulkan/VulkanWindow.cs b/src/Ryujinx.Headless.SDL2/Vulkan/VulkanWindow.cs index e5572c936..fb73ca335 100644 --- a/src/Ryujinx.Headless.SDL2/Vulkan/VulkanWindow.cs +++ b/src/Ryujinx.Headless.SDL2/Vulkan/VulkanWindow.cs @@ -46,7 +46,7 @@ namespace Ryujinx.Headless.SDL2.Vulkan action(); } - public IntPtr CreateWindowSurface(IntPtr instance) + public nint CreateWindowSurface(nint instance) { ulong surfaceHandle = 0; @@ -71,19 +71,19 @@ namespace Ryujinx.Headless.SDL2.Vulkan CreateSurface(); } - return (IntPtr)surfaceHandle; + return (nint)surfaceHandle; } public unsafe string[] GetRequiredInstanceExtensions() { - if (SDL_Vulkan_GetInstanceExtensions(WindowHandle, out uint extensionsCount, IntPtr.Zero) == SDL_bool.SDL_TRUE) + if (SDL_Vulkan_GetInstanceExtensions(WindowHandle, out uint extensionsCount, nint.Zero) == SDL_bool.SDL_TRUE) { - IntPtr[] rawExtensions = new IntPtr[(int)extensionsCount]; + nint[] rawExtensions = new nint[(int)extensionsCount]; string[] extensions = new string[(int)extensionsCount]; - fixed (IntPtr* rawExtensionsPtr = rawExtensions) + fixed (nint* rawExtensionsPtr = rawExtensions) { - if (SDL_Vulkan_GetInstanceExtensions(WindowHandle, out extensionsCount, (IntPtr)rawExtensionsPtr) == SDL_bool.SDL_TRUE) + if (SDL_Vulkan_GetInstanceExtensions(WindowHandle, out extensionsCount, (nint)rawExtensionsPtr) == SDL_bool.SDL_TRUE) { for (int i = 0; i < extensions.Length; i++) { diff --git a/src/Ryujinx.Headless.SDL2/WindowBase.cs b/src/Ryujinx.Headless.SDL2/WindowBase.cs index 039ef10e8..4addf62b5 100644 --- a/src/Ryujinx.Headless.SDL2/WindowBase.cs +++ b/src/Ryujinx.Headless.SDL2/WindowBase.cs @@ -38,7 +38,7 @@ namespace Ryujinx.Headless.SDL2 [LibraryImport("SDL2")] // TODO: Remove this as soon as SDL2-CS was updated to expose this method publicly - private static partial IntPtr SDL_LoadBMP_RW(IntPtr src, int freesrc); + private static partial nint SDL_LoadBMP_RW(nint src, int freesrc); public static void QueueMainThreadAction(Action action) { @@ -52,7 +52,7 @@ namespace Ryujinx.Headless.SDL2 public event EventHandler StatusUpdatedEvent; - protected IntPtr WindowHandle { get; set; } + protected nint WindowHandle { get; set; } public IHostUITheme HostUITheme { get; } public int Width { get; private set; } @@ -148,8 +148,8 @@ namespace Ryujinx.Headless.SDL2 { fixed (byte* iconPtr = iconBytes) { - IntPtr rwOpsStruct = SDL_RWFromConstMem((IntPtr)iconPtr, iconBytes.Length); - IntPtr iconHandle = SDL_LoadBMP_RW(rwOpsStruct, 1); + nint rwOpsStruct = SDL_RWFromConstMem((nint)iconPtr, iconBytes.Length); + nint iconHandle = SDL_LoadBMP_RW(rwOpsStruct, 1); SDL_SetWindowIcon(WindowHandle, iconHandle); SDL_FreeSurface(iconHandle); @@ -187,7 +187,7 @@ namespace Ryujinx.Headless.SDL2 WindowHandle = SDL_CreateWindow($"Ryujinx {Program.Version}{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}", SDL_WINDOWPOS_CENTERED_DISPLAY(DisplayId), SDL_WINDOWPOS_CENTERED_DISPLAY(DisplayId), Width, Height, DefaultFlags | FullscreenFlag | GetWindowFlags()); - if (WindowHandle == IntPtr.Zero) + if (WindowHandle == nint.Zero) { string errorMessage = $"SDL_CreateWindow failed with error \"{SDL_GetError()}\""; diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 475855fd5..af6f4c625 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -71,11 +71,11 @@ namespace Ryujinx.Input.SDL2 public GamepadFeaturesFlag Features { get; } - private IntPtr _gamepadHandle; + private nint _gamepadHandle; private float _triggerThreshold; - public SDL2Gamepad(IntPtr gamepadHandle, string driverId) + public SDL2Gamepad(nint gamepadHandle, string driverId) { _gamepadHandle = gamepadHandle; _buttonsUserMapping = new List(20); @@ -127,11 +127,11 @@ namespace Ryujinx.Input.SDL2 protected virtual void Dispose(bool disposing) { - if (disposing && _gamepadHandle != IntPtr.Zero) + if (disposing && _gamepadHandle != nint.Zero) { SDL_GameControllerClose(_gamepadHandle); - _gamepadHandle = IntPtr.Zero; + _gamepadHandle = nint.Zero; } } @@ -187,7 +187,7 @@ namespace Ryujinx.Input.SDL2 { float* values = stackalloc float[ElementCount]; - int result = SDL_GameControllerGetSensorData(_gamepadHandle, sensorType, (IntPtr)values, ElementCount); + int result = SDL_GameControllerGetSensorData(_gamepadHandle, sensorType, (nint)values, ElementCount); if (result != 0) return Vector3.Zero; diff --git a/src/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs b/src/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs index 012d72d7c..5bb3c10c4 100644 --- a/src/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs +++ b/src/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs @@ -160,9 +160,9 @@ namespace Ryujinx.Input.SDL2 return null; } - IntPtr gamepadHandle = SDL_GameControllerOpen(joystickIndex); + nint gamepadHandle = SDL_GameControllerOpen(joystickIndex); - if (gamepadHandle == IntPtr.Zero) + if (gamepadHandle == nint.Zero) { return null; } diff --git a/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs b/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs index 08eacc4ee..a0dd8ab95 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs @@ -225,7 +225,7 @@ namespace Ryujinx.Input.SDL2 unsafe { - IntPtr statePtr = SDL_GetKeyboardState(out int numKeys); + nint statePtr = SDL_GetKeyboardState(out int numKeys); rawKeyboardState = new ReadOnlySpan((byte*)statePtr, numKeys); } diff --git a/src/Ryujinx.Memory/MemoryBlock.cs b/src/Ryujinx.Memory/MemoryBlock.cs index 59ee269bb..c2ba51f82 100644 --- a/src/Ryujinx.Memory/MemoryBlock.cs +++ b/src/Ryujinx.Memory/MemoryBlock.cs @@ -13,13 +13,13 @@ namespace Ryujinx.Memory private readonly bool _isMirror; private readonly bool _viewCompatible; private readonly bool _forJit; - private IntPtr _sharedMemory; - private IntPtr _pointer; + private nint _sharedMemory; + private nint _pointer; /// /// Pointer to the memory block data. /// - public IntPtr Pointer => _pointer; + public nint Pointer => _pointer; /// /// Size of the memory block. @@ -68,7 +68,7 @@ namespace Ryujinx.Memory /// Shared memory to use as backing storage for this block /// Throw when there's an error while mapping the shared memory /// Throw when the current platform is not supported - private MemoryBlock(ulong size, IntPtr sharedMemory) + private MemoryBlock(ulong size, nint sharedMemory) { _pointer = MemoryManagement.MapSharedMemory(sharedMemory, size); Size = size; @@ -86,7 +86,7 @@ namespace Ryujinx.Memory /// Throw when the current platform is not supported public MemoryBlock CreateMirror() { - if (_sharedMemory == IntPtr.Zero) + if (_sharedMemory == nint.Zero) { throw new NotSupportedException("Mirroring is not supported on the memory block because the Mirrorable flag was not set."); } @@ -134,7 +134,7 @@ namespace Ryujinx.Memory /// Throw when either or are out of range public void MapView(MemoryBlock srcBlock, ulong srcOffset, ulong dstOffset, ulong size) { - if (srcBlock._sharedMemory == IntPtr.Zero) + if (srcBlock._sharedMemory == nint.Zero) { throw new ArgumentException("The source memory block is not mirrorable, and thus cannot be mapped on the current block."); } @@ -273,9 +273,9 @@ namespace Ryujinx.Memory [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe ref T GetRef(ulong offset) where T : unmanaged { - IntPtr ptr = _pointer; + nint ptr = _pointer; - ObjectDisposedException.ThrowIf(ptr == IntPtr.Zero, this); + ObjectDisposedException.ThrowIf(ptr == nint.Zero, this); int size = Unsafe.SizeOf(); @@ -298,14 +298,14 @@ namespace Ryujinx.Memory /// Throw when the memory block has already been disposed /// Throw when either or are out of range [MethodImpl(MethodImplOptions.AggressiveInlining)] - public IntPtr GetPointer(ulong offset, ulong size) => GetPointerInternal(offset, size); + public nint GetPointer(ulong offset, ulong size) => GetPointerInternal(offset, size); [MethodImpl(MethodImplOptions.AggressiveInlining)] - private IntPtr GetPointerInternal(ulong offset, ulong size) + private nint GetPointerInternal(ulong offset, ulong size) { - IntPtr ptr = _pointer; + nint ptr = _pointer; - ObjectDisposedException.ThrowIf(ptr == IntPtr.Zero, this); + ObjectDisposedException.ThrowIf(ptr == nint.Zero, this); ulong endOffset = offset + size; @@ -364,9 +364,9 @@ namespace Ryujinx.Memory /// Native pointer /// Offset to add /// Native pointer with the added offset - private static IntPtr PtrAddr(IntPtr pointer, ulong offset) + private static nint PtrAddr(nint pointer, ulong offset) { - return new IntPtr(pointer.ToInt64() + (long)offset); + return new nint(pointer.ToInt64() + (long)offset); } /// @@ -386,10 +386,10 @@ namespace Ryujinx.Memory private void FreeMemory() { - IntPtr ptr = Interlocked.Exchange(ref _pointer, IntPtr.Zero); + nint ptr = Interlocked.Exchange(ref _pointer, nint.Zero); // If pointer is null, the memory was already freed or never allocated. - if (ptr != IntPtr.Zero) + if (ptr != nint.Zero) { if (_usesSharedMemory) { @@ -403,9 +403,9 @@ namespace Ryujinx.Memory if (!_isMirror) { - IntPtr sharedMemory = Interlocked.Exchange(ref _sharedMemory, IntPtr.Zero); + nint sharedMemory = Interlocked.Exchange(ref _sharedMemory, nint.Zero); - if (sharedMemory != IntPtr.Zero) + if (sharedMemory != nint.Zero) { MemoryManagement.DestroySharedMemory(sharedMemory); } diff --git a/src/Ryujinx.Memory/MemoryManagement.cs b/src/Ryujinx.Memory/MemoryManagement.cs index 860d3f368..276cc2a4c 100644 --- a/src/Ryujinx.Memory/MemoryManagement.cs +++ b/src/Ryujinx.Memory/MemoryManagement.cs @@ -4,11 +4,11 @@ namespace Ryujinx.Memory { public static class MemoryManagement { - public static IntPtr Allocate(ulong size, bool forJit) + public static nint Allocate(ulong size, bool forJit) { if (OperatingSystem.IsWindows()) { - return MemoryManagementWindows.Allocate((IntPtr)size); + return MemoryManagementWindows.Allocate((nint)size); } else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { @@ -20,11 +20,11 @@ namespace Ryujinx.Memory } } - public static IntPtr Reserve(ulong size, bool forJit, bool viewCompatible) + public static nint Reserve(ulong size, bool forJit, bool viewCompatible) { if (OperatingSystem.IsWindows()) { - return MemoryManagementWindows.Reserve((IntPtr)size, viewCompatible); + return MemoryManagementWindows.Reserve((nint)size, viewCompatible); } else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { @@ -36,11 +36,11 @@ namespace Ryujinx.Memory } } - public static void Commit(IntPtr address, ulong size, bool forJit) + public static void Commit(nint address, ulong size, bool forJit) { if (OperatingSystem.IsWindows()) { - MemoryManagementWindows.Commit(address, (IntPtr)size); + MemoryManagementWindows.Commit(address, (nint)size); } else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { @@ -52,11 +52,11 @@ namespace Ryujinx.Memory } } - public static void Decommit(IntPtr address, ulong size) + public static void Decommit(nint address, ulong size) { if (OperatingSystem.IsWindows()) { - MemoryManagementWindows.Decommit(address, (IntPtr)size); + MemoryManagementWindows.Decommit(address, (nint)size); } else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { @@ -68,11 +68,11 @@ namespace Ryujinx.Memory } } - public static void MapView(IntPtr sharedMemory, ulong srcOffset, IntPtr address, ulong size, MemoryBlock owner) + public static void MapView(nint sharedMemory, ulong srcOffset, nint address, ulong size, MemoryBlock owner) { if (OperatingSystem.IsWindows()) { - MemoryManagementWindows.MapView(sharedMemory, srcOffset, address, (IntPtr)size, owner); + MemoryManagementWindows.MapView(sharedMemory, srcOffset, address, (nint)size, owner); } else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { @@ -84,11 +84,11 @@ namespace Ryujinx.Memory } } - public static void UnmapView(IntPtr sharedMemory, IntPtr address, ulong size, MemoryBlock owner) + public static void UnmapView(nint sharedMemory, nint address, ulong size, MemoryBlock owner) { if (OperatingSystem.IsWindows()) { - MemoryManagementWindows.UnmapView(sharedMemory, address, (IntPtr)size, owner); + MemoryManagementWindows.UnmapView(sharedMemory, address, (nint)size, owner); } else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { @@ -100,13 +100,13 @@ namespace Ryujinx.Memory } } - public static void Reprotect(IntPtr address, ulong size, MemoryPermission permission, bool forView, bool throwOnFail) + public static void Reprotect(nint address, ulong size, MemoryPermission permission, bool forView, bool throwOnFail) { bool result; if (OperatingSystem.IsWindows()) { - result = MemoryManagementWindows.Reprotect(address, (IntPtr)size, permission, forView); + result = MemoryManagementWindows.Reprotect(address, (nint)size, permission, forView); } else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { @@ -123,11 +123,11 @@ namespace Ryujinx.Memory } } - public static bool Free(IntPtr address, ulong size) + public static bool Free(nint address, ulong size) { if (OperatingSystem.IsWindows()) { - return MemoryManagementWindows.Free(address, (IntPtr)size); + return MemoryManagementWindows.Free(address, (nint)size); } else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { @@ -139,11 +139,11 @@ namespace Ryujinx.Memory } } - public static IntPtr CreateSharedMemory(ulong size, bool reserve) + public static nint CreateSharedMemory(ulong size, bool reserve) { if (OperatingSystem.IsWindows()) { - return MemoryManagementWindows.CreateSharedMemory((IntPtr)size, reserve); + return MemoryManagementWindows.CreateSharedMemory((nint)size, reserve); } else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { @@ -155,7 +155,7 @@ namespace Ryujinx.Memory } } - public static void DestroySharedMemory(IntPtr handle) + public static void DestroySharedMemory(nint handle) { if (OperatingSystem.IsWindows()) { @@ -171,7 +171,7 @@ namespace Ryujinx.Memory } } - public static IntPtr MapSharedMemory(IntPtr handle, ulong size) + public static nint MapSharedMemory(nint handle, ulong size) { if (OperatingSystem.IsWindows()) { @@ -187,7 +187,7 @@ namespace Ryujinx.Memory } } - public static void UnmapSharedMemory(IntPtr address, ulong size) + public static void UnmapSharedMemory(nint address, ulong size) { if (OperatingSystem.IsWindows()) { diff --git a/src/Ryujinx.Memory/MemoryManagementUnix.cs b/src/Ryujinx.Memory/MemoryManagementUnix.cs index e132dbbb8..76a63a466 100644 --- a/src/Ryujinx.Memory/MemoryManagementUnix.cs +++ b/src/Ryujinx.Memory/MemoryManagementUnix.cs @@ -10,19 +10,19 @@ namespace Ryujinx.Memory [SupportedOSPlatform("macos")] static class MemoryManagementUnix { - private static readonly ConcurrentDictionary _allocations = new(); + private static readonly ConcurrentDictionary _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); } diff --git a/src/Ryujinx.Memory/MemoryManagementWindows.cs b/src/Ryujinx.Memory/MemoryManagementWindows.cs index 742ef6c96..468355dd0 100644 --- a/src/Ryujinx.Memory/MemoryManagementWindows.cs +++ b/src/Ryujinx.Memory/MemoryManagementWindows.cs @@ -12,16 +12,16 @@ namespace Ryujinx.Memory private static readonly PlaceholderManager _placeholders = new(); - public static IntPtr Allocate(IntPtr size) + public static nint Allocate(nint size) { return AllocateInternal(size, AllocationType.Reserve | AllocationType.Commit); } - public static IntPtr Reserve(IntPtr size, bool viewCompatible) + public static nint Reserve(nint size, bool viewCompatible) { if (viewCompatible) { - IntPtr baseAddress = AllocateInternal2(size, AllocationType.Reserve | AllocationType.ReservePlaceholder); + nint baseAddress = AllocateInternal2(size, AllocationType.Reserve | AllocationType.ReservePlaceholder); _placeholders.ReserveRange((ulong)baseAddress, (ulong)size); @@ -31,11 +31,11 @@ namespace Ryujinx.Memory return AllocateInternal(size, AllocationType.Reserve); } - private static IntPtr AllocateInternal(IntPtr size, AllocationType flags = 0) + private static nint AllocateInternal(nint size, AllocationType flags = 0) { - IntPtr ptr = WindowsApi.VirtualAlloc(IntPtr.Zero, size, flags, MemoryProtection.ReadWrite); + nint ptr = WindowsApi.VirtualAlloc(nint.Zero, size, flags, MemoryProtection.ReadWrite); - if (ptr == IntPtr.Zero) + if (ptr == nint.Zero) { throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } @@ -43,11 +43,11 @@ namespace Ryujinx.Memory return ptr; } - private static IntPtr AllocateInternal2(IntPtr size, AllocationType flags = 0) + private static nint AllocateInternal2(nint size, AllocationType flags = 0) { - IntPtr ptr = WindowsApi.VirtualAlloc2(WindowsApi.CurrentProcessHandle, IntPtr.Zero, size, flags, MemoryProtection.NoAccess, IntPtr.Zero, 0); + nint ptr = WindowsApi.VirtualAlloc2(WindowsApi.CurrentProcessHandle, nint.Zero, size, flags, MemoryProtection.NoAccess, nint.Zero, 0); - if (ptr == IntPtr.Zero) + if (ptr == nint.Zero) { throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } @@ -55,15 +55,15 @@ namespace Ryujinx.Memory return ptr; } - public static void Commit(IntPtr location, IntPtr size) + public static void Commit(nint location, nint size) { - if (WindowsApi.VirtualAlloc(location, size, AllocationType.Commit, MemoryProtection.ReadWrite) == IntPtr.Zero) + if (WindowsApi.VirtualAlloc(location, size, AllocationType.Commit, MemoryProtection.ReadWrite) == nint.Zero) { throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } } - public static void Decommit(IntPtr location, IntPtr size) + public static void Decommit(nint location, nint size) { if (!WindowsApi.VirtualFree(location, size, AllocationType.Decommit)) { @@ -71,17 +71,17 @@ namespace Ryujinx.Memory } } - public static void MapView(IntPtr sharedMemory, ulong srcOffset, IntPtr location, IntPtr size, MemoryBlock owner) + public static void MapView(nint sharedMemory, ulong srcOffset, nint location, nint size, MemoryBlock owner) { _placeholders.MapView(sharedMemory, srcOffset, location, size, owner); } - public static void UnmapView(IntPtr sharedMemory, IntPtr location, IntPtr size, MemoryBlock owner) + public static void UnmapView(nint sharedMemory, nint location, nint size, MemoryBlock owner) { _placeholders.UnmapView(sharedMemory, location, size, owner); } - public static bool Reprotect(IntPtr address, IntPtr size, MemoryPermission permission, bool forView) + public static bool Reprotect(nint address, nint size, MemoryPermission permission, bool forView) { if (forView) { @@ -93,26 +93,26 @@ namespace Ryujinx.Memory } } - public static bool Free(IntPtr address, IntPtr size) + public static bool Free(nint address, nint size) { _placeholders.UnreserveRange((ulong)address, (ulong)size); - return WindowsApi.VirtualFree(address, IntPtr.Zero, AllocationType.Release); + return WindowsApi.VirtualFree(address, nint.Zero, AllocationType.Release); } - public static IntPtr CreateSharedMemory(IntPtr size, bool reserve) + public static nint CreateSharedMemory(nint size, bool reserve) { var prot = reserve ? FileMapProtection.SectionReserve : FileMapProtection.SectionCommit; - IntPtr handle = WindowsApi.CreateFileMapping( + nint handle = WindowsApi.CreateFileMapping( WindowsApi.InvalidHandleValue, - IntPtr.Zero, + nint.Zero, FileMapProtection.PageReadWrite | prot, (uint)(size.ToInt64() >> 32), (uint)size.ToInt64(), null); - if (handle == IntPtr.Zero) + if (handle == nint.Zero) { throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } @@ -120,7 +120,7 @@ namespace Ryujinx.Memory return handle; } - public static void DestroySharedMemory(IntPtr handle) + public static void DestroySharedMemory(nint handle) { if (!WindowsApi.CloseHandle(handle)) { @@ -128,11 +128,11 @@ namespace Ryujinx.Memory } } - public static IntPtr MapSharedMemory(IntPtr handle) + public static nint MapSharedMemory(nint handle) { - IntPtr ptr = WindowsApi.MapViewOfFile(handle, 4 | 2, 0, 0, IntPtr.Zero); + nint ptr = WindowsApi.MapViewOfFile(handle, 4 | 2, 0, 0, nint.Zero); - if (ptr == IntPtr.Zero) + if (ptr == nint.Zero) { throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } @@ -140,7 +140,7 @@ namespace Ryujinx.Memory return ptr; } - public static void UnmapSharedMemory(IntPtr address) + public static void UnmapSharedMemory(nint address) { if (!WindowsApi.UnmapViewOfFile(address)) { diff --git a/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs b/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs index 43888c85b..e5a0b7a4d 100644 --- a/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs +++ b/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs @@ -44,7 +44,7 @@ namespace Ryujinx.Memory O_SYNC = 256, } - public const IntPtr MAP_FAILED = -1; + public const nint MAP_FAILED = -1; private const int MAP_ANONYMOUS_LINUX_GENERIC = 0x20; private const int MAP_NORESERVE_LINUX_GENERIC = 0x4000; @@ -57,37 +57,37 @@ namespace Ryujinx.Memory public const int MADV_REMOVE = 9; [LibraryImport("libc", EntryPoint = "mmap", SetLastError = true)] - private static partial IntPtr Internal_mmap(IntPtr address, ulong length, MmapProts prot, int flags, int fd, long offset); + private static partial nint Internal_mmap(nint address, ulong length, MmapProts prot, int flags, int fd, long offset); [LibraryImport("libc", SetLastError = true)] - public static partial int mprotect(IntPtr address, ulong length, MmapProts prot); + public static partial int mprotect(nint address, ulong length, MmapProts prot); [LibraryImport("libc", SetLastError = true)] - public static partial int munmap(IntPtr address, ulong length); + public static partial int munmap(nint address, ulong length); [LibraryImport("libc", SetLastError = true)] - public static partial IntPtr mremap(IntPtr old_address, ulong old_size, ulong new_size, int flags, IntPtr new_address); + public static partial nint mremap(nint old_address, ulong old_size, ulong new_size, int flags, nint new_address); [LibraryImport("libc", SetLastError = true)] - public static partial int madvise(IntPtr address, ulong size, int advice); + public static partial int madvise(nint address, ulong size, int advice); [LibraryImport("libc", SetLastError = true)] - public static partial int mkstemp(IntPtr template); + public static partial int mkstemp(nint template); [LibraryImport("libc", SetLastError = true)] - public static partial int unlink(IntPtr pathname); + public static partial int unlink(nint pathname); [LibraryImport("libc", SetLastError = true)] - public static partial int ftruncate(int fildes, IntPtr length); + public static partial int ftruncate(int fildes, nint length); [LibraryImport("libc", SetLastError = true)] public static partial int close(int fd); [LibraryImport("libc", SetLastError = true)] - public static partial int shm_open(IntPtr name, int oflag, uint mode); + public static partial int shm_open(nint name, int oflag, uint mode); [LibraryImport("libc", SetLastError = true)] - public static partial int shm_unlink(IntPtr name); + public static partial int shm_unlink(nint name); private static int MmapFlagsToSystemFlags(MmapFlags flags) { @@ -164,7 +164,7 @@ namespace Ryujinx.Memory return result; } - public static IntPtr Mmap(IntPtr address, ulong length, MmapProts prot, MmapFlags flags, int fd, long offset) + public static nint Mmap(nint address, ulong length, MmapProts prot, MmapFlags flags, int fd, long offset) { return Internal_mmap(address, length, prot, MmapFlagsToSystemFlags(flags), fd, offset); } diff --git a/src/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs b/src/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs index b68a076c4..2a294bba9 100644 --- a/src/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs +++ b/src/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs @@ -18,7 +18,7 @@ namespace Ryujinx.Memory.WindowsShared private readonly MappingTree _mappings; private readonly MappingTree _protections; - private readonly IntPtr _partialUnmapStatePtr; + private readonly nint _partialUnmapStatePtr; private readonly Thread _partialUnmapTrimThread; /// @@ -100,7 +100,7 @@ namespace Ryujinx.Memory.WindowsShared if (IsMapped(node.Value)) { - if (!WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (IntPtr)node.Start, 2)) + if (!WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (nint)node.Start, 2)) { throw new WindowsApiException("UnmapViewOfFile2"); } @@ -126,7 +126,7 @@ namespace Ryujinx.Memory.WindowsShared /// Address to map the view into /// Size of the view in bytes /// Memory block that owns the mapping - public void MapView(IntPtr sharedMemory, ulong srcOffset, IntPtr location, IntPtr size, MemoryBlock owner) + public void MapView(nint sharedMemory, ulong srcOffset, nint location, nint size, MemoryBlock owner) { ref var partialUnmapLock = ref GetPartialUnmapState().PartialUnmapLock; partialUnmapLock.AcquireReaderLock(); @@ -151,7 +151,7 @@ namespace Ryujinx.Memory.WindowsShared /// Size of the view in bytes /// Indicates if the memory protections should be updated after the map /// Thrown when the Windows API returns an error mapping the memory - private void MapViewInternal(IntPtr sharedMemory, ulong srcOffset, IntPtr location, IntPtr size, bool updateProtection) + private void MapViewInternal(nint sharedMemory, ulong srcOffset, nint location, nint size, bool updateProtection) { SplitForMap((ulong)location, (ulong)size, srcOffset); @@ -163,10 +163,10 @@ namespace Ryujinx.Memory.WindowsShared size, 0x4000, MemoryProtection.ReadWrite, - IntPtr.Zero, + nint.Zero, 0); - if (ptr == IntPtr.Zero) + if (ptr == nint.Zero) { throw new WindowsApiException("MapViewOfFile3"); } @@ -210,8 +210,8 @@ namespace Ryujinx.Memory.WindowsShared if (overlapStartsBefore && overlapEndsAfter) { CheckFreeResult(WindowsApi.VirtualFree( - (IntPtr)address, - (IntPtr)size, + (nint)address, + (nint)size, AllocationType.Release | AllocationType.PreservePlaceholder)); _mappings.Add(new RangeNode(overlapStart, address, overlapValue)); @@ -222,8 +222,8 @@ namespace Ryujinx.Memory.WindowsShared ulong overlappedSize = overlapEnd - address; CheckFreeResult(WindowsApi.VirtualFree( - (IntPtr)address, - (IntPtr)overlappedSize, + (nint)address, + (nint)overlappedSize, AllocationType.Release | AllocationType.PreservePlaceholder)); _mappings.Add(new RangeNode(overlapStart, address, overlapValue)); @@ -233,8 +233,8 @@ namespace Ryujinx.Memory.WindowsShared ulong overlappedSize = endAddress - overlapStart; CheckFreeResult(WindowsApi.VirtualFree( - (IntPtr)overlapStart, - (IntPtr)overlappedSize, + (nint)overlapStart, + (nint)overlappedSize, AllocationType.Release | AllocationType.PreservePlaceholder)); _mappings.Add(new RangeNode(endAddress, overlapEnd, AddBackingOffset(overlapValue, overlappedSize))); @@ -255,7 +255,7 @@ namespace Ryujinx.Memory.WindowsShared /// Address to unmap /// Size of the region to unmap in bytes /// Memory block that owns the mapping - public void UnmapView(IntPtr sharedMemory, IntPtr location, IntPtr size, MemoryBlock owner) + public void UnmapView(nint sharedMemory, nint location, nint size, MemoryBlock owner) { ref var partialUnmapLock = ref GetPartialUnmapState().PartialUnmapLock; partialUnmapLock.AcquireReaderLock(); @@ -283,7 +283,7 @@ namespace Ryujinx.Memory.WindowsShared /// Memory block that owns the mapping /// Indicates if the memory protections should be updated after the unmap /// Thrown when the Windows API returns an error unmapping or remapping the memory - private void UnmapViewInternal(IntPtr sharedMemory, IntPtr location, IntPtr size, MemoryBlock owner, bool updateProtection) + private void UnmapViewInternal(nint sharedMemory, nint location, nint size, MemoryBlock owner, bool updateProtection) { ulong startAddress = (ulong)location; ulong unmapSize = (ulong)size; @@ -327,7 +327,7 @@ namespace Ryujinx.Memory.WindowsShared { partialUnmapState.PartialUnmapsCount++; - if (!WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (IntPtr)overlap.Start, 2)) + if (!WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (nint)overlap.Start, 2)) { throw new WindowsApiException("UnmapViewOfFile2"); } @@ -336,7 +336,7 @@ namespace Ryujinx.Memory.WindowsShared { ulong remapSize = startAddress - overlap.Start; - MapViewInternal(sharedMemory, overlap.Value, (IntPtr)overlap.Start, (IntPtr)remapSize, updateProtection: false); + MapViewInternal(sharedMemory, overlap.Value, (nint)overlap.Start, (nint)remapSize, updateProtection: false); RestoreRangeProtection(overlap.Start, remapSize); } @@ -347,7 +347,7 @@ namespace Ryujinx.Memory.WindowsShared ulong remapAddress = overlap.Start + overlappedSize; ulong remapSize = overlap.End - endAddress; - MapViewInternal(sharedMemory, remapBackingOffset, (IntPtr)remapAddress, (IntPtr)remapSize, updateProtection: false); + MapViewInternal(sharedMemory, remapBackingOffset, (nint)remapAddress, (nint)remapSize, updateProtection: false); RestoreRangeProtection(remapAddress, remapSize); } } @@ -356,7 +356,7 @@ namespace Ryujinx.Memory.WindowsShared partialUnmapLock.DowngradeFromWriterLock(); } } - else if (!WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (IntPtr)overlap.Start, 2)) + else if (!WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (nint)overlap.Start, 2)) { throw new WindowsApiException("UnmapViewOfFile2"); } @@ -441,8 +441,8 @@ namespace Ryujinx.Memory.WindowsShared size = endAddress - address; CheckFreeResult(WindowsApi.VirtualFree( - (IntPtr)address, - (IntPtr)size, + (nint)address, + (nint)size, AllocationType.Release | AllocationType.CoalescePlaceholders)); } } @@ -454,7 +454,7 @@ namespace Ryujinx.Memory.WindowsShared /// Size of the region to reprotect in bytes /// New permissions /// True if the reprotection was successful, false otherwise - public bool ReprotectView(IntPtr address, IntPtr size, MemoryPermission permission) + public bool ReprotectView(nint address, nint size, MemoryPermission permission) { ref var partialUnmapLock = ref GetPartialUnmapState().PartialUnmapLock; partialUnmapLock.AcquireReaderLock(); @@ -478,7 +478,7 @@ namespace Ryujinx.Memory.WindowsShared /// Throw an exception instead of returning an error if the operation fails /// True if the reprotection was successful or if is true, false otherwise /// If is true, it is thrown when the Windows API returns an error reprotecting the memory - private bool ReprotectViewInternal(IntPtr address, IntPtr size, MemoryPermission permission, bool throwOnError) + private bool ReprotectViewInternal(nint address, nint size, MemoryPermission permission, bool throwOnError) { ulong reprotectAddress = (ulong)address; ulong reprotectSize = (ulong)size; @@ -514,7 +514,7 @@ namespace Ryujinx.Memory.WindowsShared mappedSize -= delta; } - if (!WindowsApi.VirtualProtect((IntPtr)mappedAddress, (IntPtr)mappedSize, WindowsApi.GetProtection(permission), out _)) + if (!WindowsApi.VirtualProtect((nint)mappedAddress, (nint)mappedSize, WindowsApi.GetProtection(permission), out _)) { if (throwOnError) { @@ -729,7 +729,7 @@ namespace Ryujinx.Memory.WindowsShared protEndAddress = endAddress; } - ReprotectViewInternal((IntPtr)protAddress, (IntPtr)(protEndAddress - protAddress), protection.Value, true); + ReprotectViewInternal((nint)protAddress, (nint)(protEndAddress - protAddress), protection.Value, true); } } } diff --git a/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs b/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs index 82903c05f..0d002dada 100644 --- a/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs +++ b/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs @@ -7,42 +7,42 @@ namespace Ryujinx.Memory.WindowsShared [SupportedOSPlatform("windows")] static partial class WindowsApi { - public static readonly IntPtr InvalidHandleValue = new(-1); - public static readonly IntPtr CurrentProcessHandle = new(-1); + public static readonly nint InvalidHandleValue = new(-1); + public static readonly nint CurrentProcessHandle = new(-1); [LibraryImport("kernel32.dll", SetLastError = true)] - public static partial IntPtr VirtualAlloc( - IntPtr lpAddress, - IntPtr dwSize, + public static partial nint VirtualAlloc( + nint lpAddress, + nint dwSize, AllocationType flAllocationType, MemoryProtection flProtect); [LibraryImport("KernelBase.dll", SetLastError = true)] - public static partial IntPtr VirtualAlloc2( - IntPtr process, - IntPtr lpAddress, - IntPtr dwSize, + public static partial nint VirtualAlloc2( + nint process, + nint lpAddress, + nint dwSize, AllocationType flAllocationType, MemoryProtection flProtect, - IntPtr extendedParameters, + nint extendedParameters, ulong parameterCount); [LibraryImport("kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static partial bool VirtualProtect( - IntPtr lpAddress, - IntPtr dwSize, + nint lpAddress, + nint dwSize, MemoryProtection flNewProtect, out MemoryProtection lpflOldProtect); [LibraryImport("kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - public static partial bool VirtualFree(IntPtr lpAddress, IntPtr dwSize, AllocationType dwFreeType); + public static partial bool VirtualFree(nint lpAddress, nint dwSize, AllocationType dwFreeType); [LibraryImport("kernel32.dll", SetLastError = true, EntryPoint = "CreateFileMappingW")] - public static partial IntPtr CreateFileMapping( - IntPtr hFile, - IntPtr lpFileMappingAttributes, + public static partial nint CreateFileMapping( + nint hFile, + nint lpFileMappingAttributes, FileMapProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, @@ -50,35 +50,35 @@ namespace Ryujinx.Memory.WindowsShared [LibraryImport("kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - public static partial bool CloseHandle(IntPtr hObject); + public static partial bool CloseHandle(nint hObject); [LibraryImport("kernel32.dll", SetLastError = true)] - public static partial IntPtr MapViewOfFile( - IntPtr hFileMappingObject, + public static partial nint MapViewOfFile( + nint hFileMappingObject, uint dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow, - IntPtr dwNumberOfBytesToMap); + nint dwNumberOfBytesToMap); [LibraryImport("KernelBase.dll", SetLastError = true)] - public static partial IntPtr MapViewOfFile3( - IntPtr hFileMappingObject, - IntPtr process, - IntPtr baseAddress, + public static partial nint MapViewOfFile3( + nint hFileMappingObject, + nint process, + nint baseAddress, ulong offset, - IntPtr dwNumberOfBytesToMap, + nint dwNumberOfBytesToMap, ulong allocationType, MemoryProtection dwDesiredAccess, - IntPtr extendedParameters, + nint extendedParameters, ulong parameterCount); [LibraryImport("kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - public static partial bool UnmapViewOfFile(IntPtr lpBaseAddress); + public static partial bool UnmapViewOfFile(nint lpBaseAddress); [LibraryImport("KernelBase.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - public static partial bool UnmapViewOfFile2(IntPtr process, IntPtr lpBaseAddress, ulong unmapFlags); + public static partial bool UnmapViewOfFile2(nint process, nint lpBaseAddress, ulong unmapFlags); [LibraryImport("kernel32.dll")] public static partial uint GetLastError(); diff --git a/src/Ryujinx.Tests/Memory/MockMemoryManager.cs b/src/Ryujinx.Tests/Memory/MockMemoryManager.cs index 20c318de6..207d28f50 100644 --- a/src/Ryujinx.Tests/Memory/MockMemoryManager.cs +++ b/src/Ryujinx.Tests/Memory/MockMemoryManager.cs @@ -7,7 +7,7 @@ namespace Ryujinx.Tests.Memory { public int AddressSpaceBits => throw new NotImplementedException(); - public IntPtr PageTablePointer => throw new NotImplementedException(); + public nint PageTablePointer => throw new NotImplementedException(); public MemoryManagerType Type => MemoryManagerType.HostMappedUnsafe; diff --git a/src/Ryujinx.Tests/Memory/PartialUnmaps.cs b/src/Ryujinx.Tests/Memory/PartialUnmaps.cs index ace68e5c2..6d2ad8fb0 100644 --- a/src/Ryujinx.Tests/Memory/PartialUnmaps.cs +++ b/src/Ryujinx.Tests/Memory/PartialUnmaps.cs @@ -237,7 +237,7 @@ namespace Ryujinx.Tests.Memory mainMemory.MapView(backing, 0, 0, vaSize); var writeFunc = TestMethods.GenerateDebugNativeWriteLoop(); - IntPtr writePtr = mainMemory.GetPointer(vaSize - 0x1000, 4); + nint writePtr = mainMemory.GetPointer(vaSize - 0x1000, 4); Thread testThread = new(() => { @@ -330,7 +330,7 @@ namespace Ryujinx.Tests.Memory fixed (void* localMap = &state.LocalCounts) { - var getOrReserve = TestMethods.GenerateDebugThreadLocalMapGetOrReserve((IntPtr)localMap); + var getOrReserve = TestMethods.GenerateDebugThreadLocalMapGetOrReserve((nint)localMap); for (int i = 0; i < ThreadLocalMap.MapSize; i++) { diff --git a/src/Ryujinx.UI.Common/App/ApplicationLibrary.cs b/src/Ryujinx.UI.Common/App/ApplicationLibrary.cs index ff8d9b141..5d407390a 100644 --- a/src/Ryujinx.UI.Common/App/ApplicationLibrary.cs +++ b/src/Ryujinx.UI.Common/App/ApplicationLibrary.cs @@ -677,19 +677,18 @@ namespace Ryujinx.UI.App.Common EnumerationOptions options = new() { RecurseSubdirectories = true, - IgnoreInaccessible = false, + IgnoreInaccessible = false }; - IEnumerable files = Directory.EnumerateFiles(appDir, "*", options).Where(file => - { - return - (Path.GetExtension(file).ToLower() is ".nsp" && ConfigurationState.Instance.UI.ShownFileTypes.NSP.Value) || - (Path.GetExtension(file).ToLower() is ".pfs0" && ConfigurationState.Instance.UI.ShownFileTypes.PFS0.Value) || - (Path.GetExtension(file).ToLower() is ".xci" && ConfigurationState.Instance.UI.ShownFileTypes.XCI.Value) || - (Path.GetExtension(file).ToLower() is ".nca" && ConfigurationState.Instance.UI.ShownFileTypes.NCA.Value) || - (Path.GetExtension(file).ToLower() is ".nro" && ConfigurationState.Instance.UI.ShownFileTypes.NRO.Value) || - (Path.GetExtension(file).ToLower() is ".nso" && ConfigurationState.Instance.UI.ShownFileTypes.NSO.Value); - }); + IEnumerable files = Directory.EnumerateFiles(appDir, "*", options) + .Where(file => + (Path.GetExtension(file).ToLower() is ".nsp" && ConfigurationState.Instance.UI.ShownFileTypes.NSP) || + (Path.GetExtension(file).ToLower() is ".pfs0" && ConfigurationState.Instance.UI.ShownFileTypes.PFS0) || + (Path.GetExtension(file).ToLower() is ".xci" && ConfigurationState.Instance.UI.ShownFileTypes.XCI) || + (Path.GetExtension(file).ToLower() is ".nca" && ConfigurationState.Instance.UI.ShownFileTypes.NCA) || + (Path.GetExtension(file).ToLower() is ".nro" && ConfigurationState.Instance.UI.ShownFileTypes.NRO) || + (Path.GetExtension(file).ToLower() is ".nso" && ConfigurationState.Instance.UI.ShownFileTypes.NSO) + ); foreach (string app in files) { diff --git a/src/Ryujinx.UI.Common/Helper/ConsoleHelper.cs b/src/Ryujinx.UI.Common/Helper/ConsoleHelper.cs index 208ff5c9d..623952b37 100644 --- a/src/Ryujinx.UI.Common/Helper/ConsoleHelper.cs +++ b/src/Ryujinx.UI.Common/Helper/ConsoleHelper.cs @@ -27,9 +27,9 @@ namespace Ryujinx.UI.Common.Helper const int SW_HIDE = 0; const int SW_SHOW = 5; - IntPtr hWnd = GetConsoleWindow(); + nint hWnd = GetConsoleWindow(); - if (hWnd == IntPtr.Zero) + if (hWnd == nint.Zero) { Logger.Warning?.Print(LogClass.Application, "Attempted to show/hide console window but console window does not exist"); return; @@ -40,11 +40,11 @@ namespace Ryujinx.UI.Common.Helper [SupportedOSPlatform("windows")] [LibraryImport("kernel32")] - private static partial IntPtr GetConsoleWindow(); + private static partial nint GetConsoleWindow(); [SupportedOSPlatform("windows")] [LibraryImport("user32")] [return: MarshalAs(UnmanagedType.Bool)] - private static partial bool ShowWindow(IntPtr hWnd, int nCmdShow); + private static partial bool ShowWindow(nint hWnd, int nCmdShow); } } diff --git a/src/Ryujinx.UI.Common/Helper/FileAssociationHelper.cs b/src/Ryujinx.UI.Common/Helper/FileAssociationHelper.cs index a1ab356a7..b7631f48a 100644 --- a/src/Ryujinx.UI.Common/Helper/FileAssociationHelper.cs +++ b/src/Ryujinx.UI.Common/Helper/FileAssociationHelper.cs @@ -20,7 +20,7 @@ namespace Ryujinx.UI.Common.Helper private const int SHCNF_FLUSH = 0x1000; [LibraryImport("shell32.dll", SetLastError = true)] - public static partial void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2); + public static partial void SHChangeNotify(uint wEventId, uint uFlags, nint dwItem1, nint dwItem2); public static bool IsTypeAssociationSupported => (OperatingSystem.IsLinux() || OperatingSystem.IsWindows()) && !ReleaseInformation.IsFlatHubBuild; @@ -143,7 +143,7 @@ namespace Ryujinx.UI.Common.Helper } // Notify Explorer the file association has been changed. - SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, IntPtr.Zero, IntPtr.Zero); + SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, nint.Zero, nint.Zero); return registered; } diff --git a/src/Ryujinx.UI.Common/Helper/ObjectiveC.cs b/src/Ryujinx.UI.Common/Helper/ObjectiveC.cs index 6aba377a3..f8f972098 100644 --- a/src/Ryujinx.UI.Common/Helper/ObjectiveC.cs +++ b/src/Ryujinx.UI.Common/Helper/ObjectiveC.cs @@ -10,44 +10,44 @@ namespace Ryujinx.UI.Common.Helper private const string ObjCRuntime = "/usr/lib/libobjc.A.dylib"; [LibraryImport(ObjCRuntime, StringMarshalling = StringMarshalling.Utf8)] - private static partial IntPtr sel_getUid(string name); + private static partial nint sel_getUid(string name); [LibraryImport(ObjCRuntime, StringMarshalling = StringMarshalling.Utf8)] - private static partial IntPtr objc_getClass(string name); + private static partial nint objc_getClass(string name); [LibraryImport(ObjCRuntime)] - private static partial void objc_msgSend(IntPtr receiver, Selector selector); + private static partial void objc_msgSend(nint receiver, Selector selector); [LibraryImport(ObjCRuntime)] - private static partial void objc_msgSend(IntPtr receiver, Selector selector, byte value); + private static partial void objc_msgSend(nint receiver, Selector selector, byte value); [LibraryImport(ObjCRuntime)] - private static partial void objc_msgSend(IntPtr receiver, Selector selector, IntPtr value); + private static partial void objc_msgSend(nint receiver, Selector selector, nint value); [LibraryImport(ObjCRuntime)] - private static partial void objc_msgSend(IntPtr receiver, Selector selector, NSRect point); + private static partial void objc_msgSend(nint receiver, Selector selector, NSRect point); [LibraryImport(ObjCRuntime)] - private static partial void objc_msgSend(IntPtr receiver, Selector selector, double value); + private static partial void objc_msgSend(nint receiver, Selector selector, double value); [LibraryImport(ObjCRuntime, EntryPoint = "objc_msgSend")] - private static partial IntPtr IntPtr_objc_msgSend(IntPtr receiver, Selector selector); + private static partial nint nint_objc_msgSend(nint receiver, Selector selector); [LibraryImport(ObjCRuntime, EntryPoint = "objc_msgSend")] - private static partial IntPtr IntPtr_objc_msgSend(IntPtr receiver, Selector selector, IntPtr param); + private static partial nint nint_objc_msgSend(nint receiver, Selector selector, nint param); [LibraryImport(ObjCRuntime, EntryPoint = "objc_msgSend", StringMarshalling = StringMarshalling.Utf8)] - private static partial IntPtr IntPtr_objc_msgSend(IntPtr receiver, Selector selector, string param); + private static partial nint nint_objc_msgSend(nint receiver, Selector selector, string param); [LibraryImport(ObjCRuntime, EntryPoint = "objc_msgSend")] [return: MarshalAs(UnmanagedType.Bool)] - private static partial bool bool_objc_msgSend(IntPtr receiver, Selector selector, IntPtr param); + private static partial bool bool_objc_msgSend(nint receiver, Selector selector, nint param); public readonly struct Object { - public readonly IntPtr ObjPtr; + public readonly nint ObjPtr; - private Object(IntPtr pointer) + private Object(nint pointer) { ObjPtr = pointer; } @@ -84,22 +84,22 @@ namespace Ryujinx.UI.Common.Helper public Object GetFromMessage(Selector selector) { - return new Object(IntPtr_objc_msgSend(ObjPtr, selector)); + return new Object(nint_objc_msgSend(ObjPtr, selector)); } public Object GetFromMessage(Selector selector, Object obj) { - return new Object(IntPtr_objc_msgSend(ObjPtr, selector, obj.ObjPtr)); + return new Object(nint_objc_msgSend(ObjPtr, selector, obj.ObjPtr)); } public Object GetFromMessage(Selector selector, NSString nsString) { - return new Object(IntPtr_objc_msgSend(ObjPtr, selector, nsString.StrPtr)); + return new Object(nint_objc_msgSend(ObjPtr, selector, nsString.StrPtr)); } public Object GetFromMessage(Selector selector, string param) { - return new Object(IntPtr_objc_msgSend(ObjPtr, selector, param)); + return new Object(nint_objc_msgSend(ObjPtr, selector, param)); } public bool GetBoolFromMessage(Selector selector, Object obj) @@ -110,7 +110,7 @@ namespace Ryujinx.UI.Common.Helper public readonly struct Selector { - public readonly IntPtr SelPtr; + public readonly nint SelPtr; private Selector(string name) { @@ -122,15 +122,15 @@ namespace Ryujinx.UI.Common.Helper public readonly struct NSString { - public readonly IntPtr StrPtr; + public readonly nint StrPtr; public NSString(string aString) { - IntPtr nsString = objc_getClass("NSString"); - StrPtr = IntPtr_objc_msgSend(nsString, "stringWithUTF8String:", aString); + nint nsString = objc_getClass("NSString"); + StrPtr = nint_objc_msgSend(nsString, "stringWithUTF8String:", aString); } - public static implicit operator IntPtr(NSString nsString) => nsString.StrPtr; + public static implicit operator nint(NSString nsString) => nsString.StrPtr; } public readonly struct NSPoint diff --git a/src/Ryujinx.UI.Common/Helper/OpenHelper.cs b/src/Ryujinx.UI.Common/Helper/OpenHelper.cs index af6170afe..8b0e1f1fd 100644 --- a/src/Ryujinx.UI.Common/Helper/OpenHelper.cs +++ b/src/Ryujinx.UI.Common/Helper/OpenHelper.cs @@ -9,13 +9,13 @@ namespace Ryujinx.UI.Common.Helper public static partial class OpenHelper { [LibraryImport("shell32.dll", SetLastError = true)] - private static partial int SHOpenFolderAndSelectItems(IntPtr pidlFolder, uint cidl, IntPtr apidl, uint dwFlags); + private static partial int SHOpenFolderAndSelectItems(nint pidlFolder, uint cidl, nint apidl, uint dwFlags); [LibraryImport("shell32.dll", SetLastError = true)] - private static partial void ILFree(IntPtr pidlList); + private static partial void ILFree(nint pidlList); [LibraryImport("shell32.dll", SetLastError = true)] - private static partial IntPtr ILCreateFromPathW([MarshalAs(UnmanagedType.LPWStr)] string pszPath); + private static partial nint ILCreateFromPathW([MarshalAs(UnmanagedType.LPWStr)] string pszPath); public static void OpenFolder(string path) { @@ -40,12 +40,12 @@ namespace Ryujinx.UI.Common.Helper { if (OperatingSystem.IsWindows()) { - IntPtr pidlList = ILCreateFromPathW(path); - if (pidlList != IntPtr.Zero) + nint pidlList = ILCreateFromPathW(path); + if (pidlList != nint.Zero) { try { - Marshal.ThrowExceptionForHR(SHOpenFolderAndSelectItems(pidlList, 0, IntPtr.Zero, 0)); + Marshal.ThrowExceptionForHR(SHOpenFolderAndSelectItems(pidlList, 0, nint.Zero, 0)); } finally { diff --git a/src/Ryujinx.UI.Common/SystemInfo/MacOSSystemInfo.cs b/src/Ryujinx.UI.Common/SystemInfo/MacOSSystemInfo.cs index 36deaf35f..894c3cadc 100644 --- a/src/Ryujinx.UI.Common/SystemInfo/MacOSSystemInfo.cs +++ b/src/Ryujinx.UI.Common/SystemInfo/MacOSSystemInfo.cs @@ -68,11 +68,11 @@ namespace Ryujinx.UI.Common.SystemInfo private const string SystemLibraryName = "libSystem.dylib"; [LibraryImport(SystemLibraryName, SetLastError = true)] - private static partial int sysctlbyname([MarshalAs(UnmanagedType.LPStr)] string name, IntPtr oldValue, ref ulong oldSize, IntPtr newValue, ulong newValueSize); + private static partial int sysctlbyname([MarshalAs(UnmanagedType.LPStr)] string name, nint oldValue, ref ulong oldSize, nint newValue, ulong newValueSize); - private static int SysctlByName(string name, IntPtr oldValue, ref ulong oldSize) + private static int SysctlByName(string name, nint oldValue, ref ulong oldSize) { - if (sysctlbyname(name, oldValue, ref oldSize, IntPtr.Zero, 0) == -1) + if (sysctlbyname(name, oldValue, ref oldSize, nint.Zero, 0) == -1) { int err = Marshal.GetLastWin32Error(); @@ -90,7 +90,7 @@ namespace Ryujinx.UI.Common.SystemInfo { ulong oldValueSize = (ulong)Unsafe.SizeOf(); - return SysctlByName(name, (IntPtr)Unsafe.AsPointer(ref oldValue), ref oldValueSize); + return SysctlByName(name, (nint)Unsafe.AsPointer(ref oldValue), ref oldValueSize); } } @@ -100,7 +100,7 @@ namespace Ryujinx.UI.Common.SystemInfo ulong strSize = 0; - int res = SysctlByName(name, IntPtr.Zero, ref strSize); + int res = SysctlByName(name, nint.Zero, ref strSize); if (res == 0) { @@ -110,7 +110,7 @@ namespace Ryujinx.UI.Common.SystemInfo { fixed (byte* rawDataPtr = rawData) { - res = SysctlByName(name, (IntPtr)rawDataPtr, ref strSize); + res = SysctlByName(name, (nint)rawDataPtr, ref strSize); } if (res == 0) diff --git a/src/Ryujinx/App.axaml.cs b/src/Ryujinx/App.axaml.cs index 522cf2bcb..295ac1503 100644 --- a/src/Ryujinx/App.axaml.cs +++ b/src/Ryujinx/App.axaml.cs @@ -106,13 +106,11 @@ namespace Ryujinx.Ava baseStyle = ConfigurationState.Instance.UI.BaseStyle; } - ThemeVariant systemTheme = DetectSystemTheme(); - ThemeManager.OnThemeChanged(); RequestedThemeVariant = baseStyle switch { - "Auto" => systemTheme, + "Auto" => DetectSystemTheme(), "Light" => ThemeVariant.Light, "Dark" => ThemeVariant.Dark, _ => ThemeVariant.Default, diff --git a/src/Ryujinx/AppHost.cs b/src/Ryujinx/AppHost.cs index 9c9898a87..e2cede1c4 100644 --- a/src/Ryujinx/AppHost.cs +++ b/src/Ryujinx/AppHost.cs @@ -68,8 +68,8 @@ namespace Ryujinx.Ava private const float VolumeDelta = 0.05f; private static readonly Cursor _invisibleCursor = new(StandardCursorType.None); - private readonly IntPtr _invisibleCursorWin; - private readonly IntPtr _defaultCursorWin; + private readonly nint _invisibleCursorWin; + private readonly nint _defaultCursorWin; private readonly long _ticksPerFrame; private readonly Stopwatch _chrono; diff --git a/src/Ryujinx/Modules/Updater/Updater.cs b/src/Ryujinx/Modules/Updater/Updater.cs index b87751b4e..ce826aef9 100644 --- a/src/Ryujinx/Modules/Updater/Updater.cs +++ b/src/Ryujinx/Modules/Updater/Updater.cs @@ -762,10 +762,8 @@ namespace Ryujinx.Modules } } - public static void CleanupUpdate() - { + public static void CleanupUpdate() => Directory.GetFiles(_homeDir, "*.ryuold", SearchOption.AllDirectories) .ForEach(File.Delete); - } } } diff --git a/src/Ryujinx/Program.cs b/src/Ryujinx/Program.cs index 47b37c9fa..1f016052a 100644 --- a/src/Ryujinx/Program.cs +++ b/src/Ryujinx/Program.cs @@ -39,7 +39,7 @@ namespace Ryujinx.Ava public static bool UseHardwareAcceleration { get; private set; } [LibraryImport("user32.dll", SetLastError = true)] - public static partial int MessageBoxA(IntPtr hWnd, [MarshalAs(UnmanagedType.LPStr)] string text, [MarshalAs(UnmanagedType.LPStr)] string caption, uint type); + public static partial int MessageBoxA(nint hWnd, [MarshalAs(UnmanagedType.LPStr)] string text, [MarshalAs(UnmanagedType.LPStr)] string caption, uint type); private const uint MbIconwarning = 0x30; @@ -49,7 +49,7 @@ namespace Ryujinx.Ava if (OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17134)) { - _ = MessageBoxA(IntPtr.Zero, "You are running an outdated version of Windows.\n\nRyujinx supports Windows 10 version 1803 and newer.\n", $"Ryujinx {Version}", MbIconwarning); + _ = MessageBoxA(nint.Zero, "You are running an outdated version of Windows.\n\nRyujinx supports Windows 10 version 1803 and newer.\n", $"Ryujinx {Version}", MbIconwarning); } PreviewerDetached = true; @@ -75,14 +75,14 @@ namespace Ryujinx.Ava EnableInputFocusProxy = Environment.GetEnvironmentVariable("XDG_CURRENT_DESKTOP") == "gamescope", RenderingMode = UseHardwareAcceleration ? [X11RenderingMode.Glx, X11RenderingMode.Software] - : [X11RenderingMode.Software], + : [X11RenderingMode.Software] }) .With(new Win32PlatformOptions { WinUICompositionBackdropCornerRadius = 8.0f, RenderingMode = UseHardwareAcceleration ? [Win32RenderingMode.AngleEgl, Win32RenderingMode.Software] - : [Win32RenderingMode.Software], + : [Win32RenderingMode.Software] }); private static void Initialize(string[] args) @@ -232,7 +232,7 @@ namespace Ryujinx.Ava Logger.Notice.Print(LogClass.Application, $"Logs Enabled: { (enabledLogLevels.Length is 0 - ? "" + ? "" : enabledLogLevels.JoinToString(", ")) }"); diff --git a/src/Ryujinx/UI/Helpers/Win32NativeInterop.cs b/src/Ryujinx/UI/Helpers/Win32NativeInterop.cs index 01478cb3d..48f98f44a 100644 --- a/src/Ryujinx/UI/Helpers/Win32NativeInterop.cs +++ b/src/Ryujinx/UI/Helpers/Win32NativeInterop.cs @@ -35,23 +35,23 @@ namespace Ryujinx.Ava.UI.Helpers } [UnmanagedFunctionPointer(CallingConvention.Winapi)] - internal delegate IntPtr WindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam); + internal delegate nint WindowProc(nint hWnd, WindowsMessages msg, nint wParam, nint lParam); [StructLayout(LayoutKind.Sequential)] public struct WndClassEx { public int cbSize; public ClassStyles style; - public IntPtr lpfnWndProc; // not WndProc + public nint lpfnWndProc; // not WndProc public int cbClsExtra; public int cbWndExtra; - public IntPtr hInstance; - public IntPtr hIcon; - public IntPtr hCursor; - public IntPtr hbrBackground; - public IntPtr lpszMenuName; - public IntPtr lpszClassName; - public IntPtr hIconSm; + public nint hInstance; + public nint hIcon; + public nint hCursor; + public nint hbrBackground; + public nint lpszMenuName; + public nint lpszClassName; + public nint hIconSm; public WndClassEx() { @@ -59,43 +59,43 @@ namespace Ryujinx.Ava.UI.Helpers } } - public static IntPtr CreateEmptyCursor() + public static nint CreateEmptyCursor() { - return CreateCursor(IntPtr.Zero, 0, 0, 1, 1, new byte[] { 0xFF }, new byte[] { 0x00 }); + return CreateCursor(nint.Zero, 0, 0, 1, 1, [0xFF], [0x00]); } - public static IntPtr CreateArrowCursor() + public static nint CreateArrowCursor() { - return LoadCursor(IntPtr.Zero, (IntPtr)Cursors.IdcArrow); + return LoadCursor(nint.Zero, (nint)Cursors.IdcArrow); } [LibraryImport("user32.dll")] - public static partial IntPtr SetCursor(IntPtr handle); + public static partial nint SetCursor(nint handle); [LibraryImport("user32.dll")] - public static partial IntPtr CreateCursor(IntPtr hInst, int xHotSpot, int yHotSpot, int nWidth, int nHeight, [In] byte[] pvAndPlane, [In] byte[] pvXorPlane); + public static partial nint CreateCursor(nint hInst, int xHotSpot, int yHotSpot, int nWidth, int nHeight, [In] byte[] pvAndPlane, [In] byte[] pvXorPlane); [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "RegisterClassExW")] public static partial ushort RegisterClassEx(ref WndClassEx param); [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "UnregisterClassW")] - public static partial short UnregisterClass([MarshalAs(UnmanagedType.LPWStr)] string lpClassName, IntPtr instance); + public static partial short UnregisterClass([MarshalAs(UnmanagedType.LPWStr)] string lpClassName, nint instance); [LibraryImport("user32.dll", EntryPoint = "DefWindowProcW")] - public static partial IntPtr DefWindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam); + public static partial nint DefWindowProc(nint hWnd, WindowsMessages msg, nint wParam, nint lParam); [LibraryImport("kernel32.dll", EntryPoint = "GetModuleHandleA")] - public static partial IntPtr GetModuleHandle([MarshalAs(UnmanagedType.LPStr)] string lpModuleName); + public static partial nint GetModuleHandle([MarshalAs(UnmanagedType.LPStr)] string lpModuleName); [LibraryImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - public static partial bool DestroyWindow(IntPtr hwnd); + public static partial bool DestroyWindow(nint hwnd); [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "LoadCursorA")] - public static partial IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName); + public static partial nint LoadCursor(nint hInstance, nint lpCursorName); [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "CreateWindowExW")] - public static partial IntPtr CreateWindowEx( + public static partial nint CreateWindowEx( uint dwExStyle, [MarshalAs(UnmanagedType.LPWStr)] string lpClassName, [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName, @@ -104,12 +104,12 @@ namespace Ryujinx.Ava.UI.Helpers int y, int nWidth, int nHeight, - IntPtr hWndParent, - IntPtr hMenu, - IntPtr hInstance, - IntPtr lpParam); + nint hWndParent, + nint hMenu, + nint hInstance, + nint lpParam); [LibraryImport("user32.dll", SetLastError = true)] - public static partial IntPtr SetWindowLongPtrW(IntPtr hWnd, int nIndex, IntPtr value); + public static partial nint SetWindowLongPtrW(nint hWnd, int nIndex, nint value); } } diff --git a/src/Ryujinx/UI/Renderer/EmbeddedWindow.cs b/src/Ryujinx/UI/Renderer/EmbeddedWindow.cs index 0930e7795..ea5a8dbdd 100644 --- a/src/Ryujinx/UI/Renderer/EmbeddedWindow.cs +++ b/src/Ryujinx/UI/Renderer/EmbeddedWindow.cs @@ -25,15 +25,15 @@ namespace Ryujinx.Ava.UI.Renderer protected GLXWindow X11Window { get; set; } - protected IntPtr WindowHandle { get; set; } - protected IntPtr X11Display { get; set; } - protected IntPtr NsView { get; set; } - protected IntPtr MetalLayer { get; set; } + protected nint WindowHandle { get; set; } + protected nint X11Display { get; set; } + protected nint NsView { get; set; } + protected nint MetalLayer { get; set; } public delegate void UpdateBoundsCallbackDelegate(Rect rect); private UpdateBoundsCallbackDelegate _updateBoundsCallback; - public event EventHandler WindowCreated; + public event EventHandler WindowCreated; public event EventHandler BoundsChanged; public EmbeddedWindow() @@ -49,10 +49,10 @@ namespace Ryujinx.Ava.UI.Renderer protected virtual void OnWindowDestroying() { - WindowHandle = IntPtr.Zero; - X11Display = IntPtr.Zero; - NsView = IntPtr.Zero; - MetalLayer = IntPtr.Zero; + WindowHandle = nint.Zero; + X11Display = nint.Zero; + NsView = nint.Zero; + MetalLayer = nint.Zero; } private void OnNativeEmbeddedWindowCreated(object sender, EventArgs e) @@ -139,7 +139,7 @@ namespace Ryujinx.Ava.UI.Renderer { _className = "NativeWindow-" + Guid.NewGuid(); - _wndProcDelegate = delegate (IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam) + _wndProcDelegate = delegate (nint hWnd, WindowsMessages msg, nint wParam, nint lParam) { switch (msg) { @@ -162,7 +162,7 @@ namespace Ryujinx.Ava.UI.Renderer RegisterClassEx(ref wndClassEx); - WindowHandle = CreateWindowEx(0, _className, "NativeWindow", WindowStyles.WsChild, 0, 0, 640, 480, control.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); + WindowHandle = CreateWindowEx(0, _className, "NativeWindow", WindowStyles.WsChild, 0, 0, 640, 480, control.Handle, nint.Zero, nint.Zero, nint.Zero); SetWindowLongPtrW(control.Handle, GWLP_WNDPROC, wndClassEx.lpfnWndProc); @@ -195,7 +195,7 @@ namespace Ryujinx.Ava.UI.Renderer metalLayer.SendMessage("setContentsScale:", Program.DesktopScaleFactor); }; - IntPtr nsView = child.ObjPtr; + nint nsView = child.ObjPtr; MetalLayer = metalLayer.ObjPtr; NsView = nsView; diff --git a/src/Ryujinx/UI/Renderer/OpenTKBindingsContext.cs b/src/Ryujinx/UI/Renderer/OpenTKBindingsContext.cs index 85e8585fc..2e5dff733 100644 --- a/src/Ryujinx/UI/Renderer/OpenTKBindingsContext.cs +++ b/src/Ryujinx/UI/Renderer/OpenTKBindingsContext.cs @@ -5,14 +5,14 @@ namespace Ryujinx.Ava.UI.Renderer { internal class OpenTKBindingsContext : IBindingsContext { - private readonly Func _getProcAddress; + private readonly Func _getProcAddress; - public OpenTKBindingsContext(Func getProcAddress) + public OpenTKBindingsContext(Func getProcAddress) { _getProcAddress = getProcAddress; } - public IntPtr GetProcAddress(string procName) + public nint GetProcAddress(string procName) { return _getProcAddress(procName); } diff --git a/src/Ryujinx/UI/Renderer/RendererHost.axaml.cs b/src/Ryujinx/UI/Renderer/RendererHost.axaml.cs index d055d9ea4..4bf10d0d7 100644 --- a/src/Ryujinx/UI/Renderer/RendererHost.axaml.cs +++ b/src/Ryujinx/UI/Renderer/RendererHost.axaml.cs @@ -60,7 +60,7 @@ namespace Ryujinx.Ava.UI.Renderer BoundsChanged?.Invoke(sender, e); } - private void CurrentWindow_WindowCreated(object sender, IntPtr e) + private void CurrentWindow_WindowCreated(object sender, nint e) { WindowCreated?.Invoke(this, EventArgs.Empty); } diff --git a/src/Ryujinx/UI/Views/Main/MainMenuBarView.axaml.cs b/src/Ryujinx/UI/Views/Main/MainMenuBarView.axaml.cs index fad7a08f7..edb05282d 100644 --- a/src/Ryujinx/UI/Views/Main/MainMenuBarView.axaml.cs +++ b/src/Ryujinx/UI/Views/Main/MainMenuBarView.axaml.cs @@ -36,23 +36,17 @@ namespace Ryujinx.Ava.UI.Views.Main ChangeLanguageMenuItem.ItemsSource = GenerateLanguageMenuItems(); } - private CheckBox[] GenerateToggleFileTypeItems() - { - List checkBoxes = new(); - - foreach (var item in Enum.GetValues(typeof(FileTypes))) - { - string fileName = Enum.GetName(typeof(FileTypes), item); - checkBoxes.Add(new CheckBox - { - Content = $".{fileName}", - IsChecked = ((FileTypes)item).GetConfigValue(ConfigurationState.Instance.UI.ShownFileTypes), - Command = MiniCommand.Create(() => Window.ToggleFileType(fileName)), - }); - } - - return checkBoxes.ToArray(); - } + private CheckBox[] GenerateToggleFileTypeItems() => + Enum.GetValues() + .Select(it => (FileName: Enum.GetName(it)!, FileType: it)) + .Select(it => + new CheckBox + { + Content = $".{it.FileName}", + IsChecked = it.FileType.GetConfigValue(ConfigurationState.Instance.UI.ShownFileTypes), + Command = MiniCommand.Create(() => Window.ToggleFileType(it.FileName)) + } + ).ToArray(); private static MenuItem[] GenerateLanguageMenuItems() { @@ -80,7 +74,7 @@ namespace Ryujinx.Ava.UI.Views.Main { Padding = new Thickness(10, 0, 0, 0), Header = " " + languageName, - Command = MiniCommand.Create(() => MainWindowViewModel.ChangeLanguage(languageCode)), + Command = MiniCommand.Create(() => MainWindowViewModel.ChangeLanguage(languageCode)) }; menuItems.Add(menuItem); diff --git a/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs b/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs index 372bcf20b..068dee350 100644 --- a/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs +++ b/src/Ryujinx/UI/Views/Main/MainStatusBarView.axaml.cs @@ -5,6 +5,7 @@ using Avalonia.Interactivity; using Avalonia.Threading; using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.UI.Windows; +using Ryujinx.Common; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.UI.Common.Configuration; @@ -46,7 +47,7 @@ namespace Ryujinx.Ava.UI.Views.Main private void DockedStatus_PointerReleased(object sender, PointerReleasedEventArgs e) { - ConfigurationState.Instance.System.EnableDockedMode.Value = !ConfigurationState.Instance.System.EnableDockedMode.Value; + ConfigurationState.Instance.System.EnableDockedMode.Toggle(); } private void AspectRatioStatus_OnClick(object sender, RoutedEventArgs e) diff --git a/src/Ryujinx/UI/Views/Settings/SettingsSystemView.axaml b/src/Ryujinx/UI/Views/Settings/SettingsSystemView.axaml index 8b01aae8e..96dd9fe39 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsSystemView.axaml +++ b/src/Ryujinx/UI/Views/Settings/SettingsSystemView.axaml @@ -201,6 +201,7 @@ Text="{locale:Locale SettingsTabSystemHacks}" /> + ViewModel.AppHost.AppExit += (_, _) => { ViewModel.AppHost = null; @@ -599,18 +600,16 @@ namespace Ryujinx.Ava.UI.Windows public void ToggleFileType(string fileType) { - _ = fileType switch + switch (fileType) { -#pragma warning disable IDE0055 // Disable formatting - "NSP" => ConfigurationState.Instance.UI.ShownFileTypes.NSP.Value = !ConfigurationState.Instance.UI.ShownFileTypes.NSP, - "PFS0" => ConfigurationState.Instance.UI.ShownFileTypes.PFS0.Value = !ConfigurationState.Instance.UI.ShownFileTypes.PFS0, - "XCI" => ConfigurationState.Instance.UI.ShownFileTypes.XCI.Value = !ConfigurationState.Instance.UI.ShownFileTypes.XCI, - "NCA" => ConfigurationState.Instance.UI.ShownFileTypes.NCA.Value = !ConfigurationState.Instance.UI.ShownFileTypes.NCA, - "NRO" => ConfigurationState.Instance.UI.ShownFileTypes.NRO.Value = !ConfigurationState.Instance.UI.ShownFileTypes.NRO, - "NSO" => ConfigurationState.Instance.UI.ShownFileTypes.NSO.Value = !ConfigurationState.Instance.UI.ShownFileTypes.NSO, - _ => throw new ArgumentOutOfRangeException(fileType), -#pragma warning restore IDE0055 - }; + case "NSP": ConfigurationState.Instance.UI.ShownFileTypes.NSP.Toggle(); break; + case "PFS0": ConfigurationState.Instance.UI.ShownFileTypes.PFS0.Toggle(); break; + case "XCI": ConfigurationState.Instance.UI.ShownFileTypes.XCI.Toggle(); break; + case "NCA": ConfigurationState.Instance.UI.ShownFileTypes.NCA.Toggle(); break; + case "NRO": ConfigurationState.Instance.UI.ShownFileTypes.NRO.Toggle(); break; + case "NSO": ConfigurationState.Instance.UI.ShownFileTypes.NSO.Toggle(); break; + default: throw new ArgumentOutOfRangeException(fileType); + } ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath); LoadApplications(); diff --git a/src/Ryujinx/UI/Windows/StyleableWindow.cs b/src/Ryujinx/UI/Windows/StyleableWindow.cs index 653df7833..493214ee2 100644 --- a/src/Ryujinx/UI/Windows/StyleableWindow.cs +++ b/src/Ryujinx/UI/Windows/StyleableWindow.cs @@ -8,9 +8,9 @@ using Ryujinx.Ava.UI.ViewModels; namespace Ryujinx.Ava.UI.Windows { - public class StyleableAppWindow : AppWindow + public abstract class StyleableAppWindow : AppWindow { - public StyleableAppWindow() + protected StyleableAppWindow() { WindowStartupLocation = WindowStartupLocation.CenterOwner; TransparencyLevelHint = [WindowTransparencyLevel.None]; @@ -34,9 +34,9 @@ namespace Ryujinx.Ava.UI.Windows } } - public class StyleableWindow : Window + public abstract class StyleableWindow : Window { - public StyleableWindow() + protected StyleableWindow() { WindowStartupLocation = WindowStartupLocation.CenterOwner; TransparencyLevelHint = [WindowTransparencyLevel.None];