From 6dffe0fad4bc8dee0e25ce038639d890b29d56a0 Mon Sep 17 00:00:00 2001
From: Mary <mary@mary.zone>
Date: Wed, 9 Feb 2022 21:18:07 +0100
Subject: [PATCH] misc: Make PID unsigned long instead of long (#3043)

---
 Ryujinx.Graphics.Gpu/GpuContext.cs               | 10 +++++-----
 Ryujinx.Graphics.Gpu/Window.cs                   |  2 +-
 Ryujinx.HLE/HOS/ArmProcessContext.cs             |  4 ++--
 Ryujinx.HLE/HOS/ArmProcessContextFactory.cs      |  2 +-
 Ryujinx.HLE/HOS/Ipc/IpcHandleDesc.cs             |  6 +++---
 Ryujinx.HLE/HOS/Kernel/KernelContext.cs          | 16 ++++++++--------
 Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs   |  4 ++--
 .../HOS/Kernel/Process/IProcessContextFactory.cs |  2 +-
 Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs       |  6 +++---
 .../HOS/Kernel/Process/ProcessContextFactory.cs  |  2 +-
 Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall.cs |  4 ++--
 .../HOS/Kernel/SupervisorCall/Syscall32.cs       | 10 +++++-----
 .../HOS/Kernel/SupervisorCall/Syscall64.cs       |  4 ++--
 Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs      |  2 +-
 .../ILibraryAppletProxy.cs                       |  4 ++--
 .../ISystemAppletProxy.cs                        |  4 ++--
 .../SystemAppletProxy/ISelfController.cs         |  4 ++--
 .../SystemAppletProxy/IWindowController.cs       |  4 ++--
 .../ApplicationProxyService/IApplicationProxy.cs |  4 ++--
 .../Friend/ServiceCreator/IFriendService.cs      |  2 +-
 .../HOS/Services/Ns/Aoc/IAddOnContentManager.cs  | 16 ++++++++--------
 Ryujinx.HLE/HOS/Services/Nv/Host1xContext.cs     |  2 +-
 Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs    |  4 ++--
 .../Services/Nv/NvDrvServices/NvDeviceFile.cs    |  4 ++--
 .../NvHostAsGpu/NvHostAsGpuDeviceFile.cs         |  2 +-
 .../NvHostChannel/NvHostChannelDeviceFile.cs     |  8 ++++----
 .../NvHostChannel/NvHostGpuDeviceFile.cs         |  2 +-
 .../NvHostCtrl/NvHostCtrlDeviceFile.cs           |  2 +-
 .../NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs     |  2 +-
 .../Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs    | 12 ++++++------
 .../Pctl/IParentalControlServiceFactory.cs       |  4 ++--
 .../IParentalControlService.cs                   |  4 ++--
 Ryujinx.HLE/HOS/Services/Pm/IShellInterface.cs   |  2 +-
 Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs      |  2 +-
 .../HOS/Services/Sockets/Bsd/BsdContext.cs       |  6 +++---
 .../Services/Ssl/SslService/ISslConnection.cs    |  4 ++--
 .../HOS/Services/Ssl/SslService/ISslContext.cs   |  5 ++---
 .../HOS/Services/SurfaceFlinger/BufferQueue.cs   |  2 +-
 .../Services/SurfaceFlinger/BufferQueueCore.cs   |  4 ++--
 .../Services/SurfaceFlinger/SurfaceFlinger.cs    |  8 ++++----
 .../SurfaceFlinger/Types/GraphicBuffer.cs        |  4 ++--
 .../IManagerDisplayService.cs                    |  2 +-
 Ryujinx.HLE/HOS/TamperMachine.cs                 |  2 +-
 43 files changed, 99 insertions(+), 100 deletions(-)

diff --git a/Ryujinx.Graphics.Gpu/GpuContext.cs b/Ryujinx.Graphics.Gpu/GpuContext.cs
index 8ea7c91fbb..e6697b3aed 100644
--- a/Ryujinx.Graphics.Gpu/GpuContext.cs
+++ b/Ryujinx.Graphics.Gpu/GpuContext.cs
@@ -77,7 +77,7 @@ namespace Ryujinx.Graphics.Gpu
         /// <summary>
         /// Registry with physical memories that can be used with this GPU context, keyed by owner process ID.
         /// </summary>
-        internal ConcurrentDictionary<long, PhysicalMemory> PhysicalMemoryRegistry { get; }
+        internal ConcurrentDictionary<ulong, PhysicalMemory> PhysicalMemoryRegistry { get; }
 
         /// <summary>
         /// Host hardware capabilities.
@@ -126,7 +126,7 @@ namespace Ryujinx.Graphics.Gpu
 
             DeferredActions = new Queue<Action>();
 
-            PhysicalMemoryRegistry = new ConcurrentDictionary<long, PhysicalMemory>();
+            PhysicalMemoryRegistry = new ConcurrentDictionary<ulong, PhysicalMemory>();
         }
 
         /// <summary>
@@ -144,7 +144,7 @@ namespace Ryujinx.Graphics.Gpu
         /// <param name="pid">ID of the process that owns the memory manager</param>
         /// <returns>The memory manager</returns>
         /// <exception cref="ArgumentException">Thrown when <paramref name="pid"/> is invalid</exception>
-        public MemoryManager CreateMemoryManager(long pid)
+        public MemoryManager CreateMemoryManager(ulong pid)
         {
             if (!PhysicalMemoryRegistry.TryGetValue(pid, out var physicalMemory))
             {
@@ -160,7 +160,7 @@ namespace Ryujinx.Graphics.Gpu
         /// <param name="pid">ID of the process that owns <paramref name="cpuMemory"/></param>
         /// <param name="cpuMemory">Virtual memory owned by the process</param>
         /// <exception cref="ArgumentException">Thrown if <paramref name="pid"/> was already registered</exception>
-        public void RegisterProcess(long pid, Cpu.IVirtualMemoryManagerTracked cpuMemory)
+        public void RegisterProcess(ulong pid, Cpu.IVirtualMemoryManagerTracked cpuMemory)
         {
             var physicalMemory = new PhysicalMemory(this, cpuMemory);
             if (!PhysicalMemoryRegistry.TryAdd(pid, physicalMemory))
@@ -175,7 +175,7 @@ namespace Ryujinx.Graphics.Gpu
         /// Unregisters a process, indicating that its memory will no longer be used, and that caches can be freed.
         /// </summary>
         /// <param name="pid">ID of the process</param>
-        public void UnregisterProcess(long pid)
+        public void UnregisterProcess(ulong pid)
         {
             if (PhysicalMemoryRegistry.TryRemove(pid, out var physicalMemory))
             {
diff --git a/Ryujinx.Graphics.Gpu/Window.cs b/Ryujinx.Graphics.Gpu/Window.cs
index 9a4dfb9acd..17da1ffa1c 100644
--- a/Ryujinx.Graphics.Gpu/Window.cs
+++ b/Ryujinx.Graphics.Gpu/Window.cs
@@ -122,7 +122,7 @@ namespace Ryujinx.Graphics.Gpu
         /// <param name="userObj">User defined object passed to the release callback</param>
         /// <exception cref="ArgumentException">Thrown when <paramref name="pid"/> is invalid</exception>
         public void EnqueueFrameThreadSafe(
-            long                       pid,
+            ulong                      pid,
             ulong                      address,
             int                        width,
             int                        height,
diff --git a/Ryujinx.HLE/HOS/ArmProcessContext.cs b/Ryujinx.HLE/HOS/ArmProcessContext.cs
index 89ce0eb348..e76ee15570 100644
--- a/Ryujinx.HLE/HOS/ArmProcessContext.cs
+++ b/Ryujinx.HLE/HOS/ArmProcessContext.cs
@@ -9,14 +9,14 @@ namespace Ryujinx.HLE.HOS
 {
     class ArmProcessContext<T> : IProcessContext where T : class, IVirtualMemoryManagerTracked, IMemoryManager
     {
-        private readonly long _pid;
+        private readonly ulong _pid;
         private readonly GpuContext _gpuContext;
         private readonly CpuContext _cpuContext;
         private T _memoryManager;
 
         public IVirtualMemoryManager AddressSpace => _memoryManager;
 
-        public ArmProcessContext(long pid, GpuContext gpuContext, T memoryManager, bool for64Bit)
+        public ArmProcessContext(ulong pid, GpuContext gpuContext, T memoryManager, bool for64Bit)
         {
             if (memoryManager is IRefCounted rc)
             {
diff --git a/Ryujinx.HLE/HOS/ArmProcessContextFactory.cs b/Ryujinx.HLE/HOS/ArmProcessContextFactory.cs
index 50dbd84354..2556b2cc8e 100644
--- a/Ryujinx.HLE/HOS/ArmProcessContextFactory.cs
+++ b/Ryujinx.HLE/HOS/ArmProcessContextFactory.cs
@@ -17,7 +17,7 @@ namespace Ryujinx.HLE.HOS
             _gpu = gpu;
         }
 
-        public IProcessContext Create(KernelContext context, long pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit)
+        public IProcessContext Create(KernelContext context, ulong pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit)
         {
             MemoryManagerMode mode = context.Device.Configuration.MemoryManagerMode;
 
diff --git a/Ryujinx.HLE/HOS/Ipc/IpcHandleDesc.cs b/Ryujinx.HLE/HOS/Ipc/IpcHandleDesc.cs
index 5b1d5788f6..439590e0c5 100644
--- a/Ryujinx.HLE/HOS/Ipc/IpcHandleDesc.cs
+++ b/Ryujinx.HLE/HOS/Ipc/IpcHandleDesc.cs
@@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Ipc
     {
         public bool HasPId { get; private set; }
 
-        public long PId { get; private set; }
+        public ulong PId { get; private set; }
 
         public int[] ToCopy { get; private set; }
         public int[] ToMove { get; private set; }
@@ -21,7 +21,7 @@ namespace Ryujinx.HLE.HOS.Ipc
             ToCopy = new int[(word >> 1) & 0xf];
             ToMove = new int[(word >> 5) & 0xf];
 
-            PId = HasPId ? reader.ReadInt64() : 0;
+            PId = HasPId ? reader.ReadUInt64() : 0;
 
             for (int index = 0; index < ToCopy.Length; index++)
             {
@@ -40,7 +40,7 @@ namespace Ryujinx.HLE.HOS.Ipc
             ToMove = move ?? throw new ArgumentNullException(nameof(move));
         }
 
-        public IpcHandleDesc(int[] copy, int[] move, long pId) : this(copy, move)
+        public IpcHandleDesc(int[] copy, int[] move, ulong pId) : this(copy, move)
         {
             PId = pId;
 
diff --git a/Ryujinx.HLE/HOS/Kernel/KernelContext.cs b/Ryujinx.HLE/HOS/Kernel/KernelContext.cs
index 4f18faca68..4b8e4d1598 100644
--- a/Ryujinx.HLE/HOS/Kernel/KernelContext.cs
+++ b/Ryujinx.HLE/HOS/Kernel/KernelContext.cs
@@ -42,14 +42,14 @@ namespace Ryujinx.HLE.HOS.Kernel
         public KSynchronization Synchronization { get; }
         public KContextIdManager ContextIdManager { get; }
 
-        public ConcurrentDictionary<long, KProcess> Processes { get; }
+        public ConcurrentDictionary<ulong, KProcess> Processes { get; }
         public ConcurrentDictionary<string, KAutoObject> AutoObjectNames { get; }
 
         public bool ThreadReselectionRequested { get; set; }
 
-        private long _kipId;
-        private long _processId;
-        private long _threadUid;
+        private ulong _kipId;
+        private ulong _processId;
+        private ulong _threadUid;
 
         public KernelContext(
             Switch device,
@@ -98,7 +98,7 @@ namespace Ryujinx.HLE.HOS.Kernel
 
             KernelInitialized = true;
 
-            Processes = new ConcurrentDictionary<long, KProcess>();
+            Processes = new ConcurrentDictionary<ulong, KProcess>();
             AutoObjectNames = new ConcurrentDictionary<string, KAutoObject>();
 
             _kipId = KernelConstants.InitialKipId;
@@ -115,17 +115,17 @@ namespace Ryujinx.HLE.HOS.Kernel
             new Thread(PreemptionThreadStart) { Name = "HLE.PreemptionThread" }.Start();
         }
 
-        public long NewThreadUid()
+        public ulong NewThreadUid()
         {
             return Interlocked.Increment(ref _threadUid) - 1;
         }
 
-        public long NewKipId()
+        public ulong NewKipId()
         {
             return Interlocked.Increment(ref _kipId) - 1;
         }
 
-        public long NewProcessId()
+        public ulong NewProcessId()
         {
             return Interlocked.Increment(ref _processId) - 1;
         }
diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs
index 61c883d807..4e51684277 100644
--- a/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Memory/KSharedMemory.cs
@@ -8,7 +8,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
     {
         private readonly SharedMemoryStorage _storage;
 
-        private readonly long _ownerPid;
+        private readonly ulong _ownerPid;
 
         private readonly KMemoryPermission _ownerPermission;
         private readonly KMemoryPermission _userPermission;
@@ -16,7 +16,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
         public KSharedMemory(
             KernelContext context,
             SharedMemoryStorage storage,
-            long ownerPid,
+            ulong ownerPid,
             KMemoryPermission ownerPermission,
             KMemoryPermission userPermission) : base(context)
         {
diff --git a/Ryujinx.HLE/HOS/Kernel/Process/IProcessContextFactory.cs b/Ryujinx.HLE/HOS/Kernel/Process/IProcessContextFactory.cs
index 10df43a82c..0a24a52403 100644
--- a/Ryujinx.HLE/HOS/Kernel/Process/IProcessContextFactory.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Process/IProcessContextFactory.cs
@@ -4,6 +4,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
 {
     interface IProcessContextFactory
     {
-        IProcessContext Create(KernelContext context, long pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit);
+        IProcessContext Create(KernelContext context, ulong pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit);
     }
 }
diff --git a/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs b/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs
index 20b3a49732..83316b0fac 100644
--- a/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs
@@ -62,7 +62,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
 
         public ulong TitleId { get; private set; }
         public bool IsApplication { get; private set; }
-        public long Pid { get; private set; }
+        public ulong Pid { get; private set; }
 
         private long _creationTimestamp;
         private ulong _entrypoint;
@@ -131,7 +131,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
 
             Pid = KernelContext.NewKipId();
 
-            if (Pid == 0 || (ulong)Pid >= KernelConstants.InitialProcessId)
+            if (Pid == 0 || Pid >= KernelConstants.InitialProcessId)
             {
                 throw new InvalidOperationException($"Invalid KIP Id {Pid}.");
             }
@@ -239,7 +239,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
 
             Pid = KernelContext.NewProcessId();
 
-            if (Pid == -1 || (ulong)Pid < KernelConstants.InitialProcessId)
+            if (Pid == ulong.MaxValue || Pid < KernelConstants.InitialProcessId)
             {
                 throw new InvalidOperationException($"Invalid Process Id {Pid}.");
             }
diff --git a/Ryujinx.HLE/HOS/Kernel/Process/ProcessContextFactory.cs b/Ryujinx.HLE/HOS/Kernel/Process/ProcessContextFactory.cs
index ff250e88b8..d81f1d0ac0 100644
--- a/Ryujinx.HLE/HOS/Kernel/Process/ProcessContextFactory.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Process/ProcessContextFactory.cs
@@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
 {
     class ProcessContextFactory : IProcessContextFactory
     {
-        public IProcessContext Create(KernelContext context, long pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit)
+        public IProcessContext Create(KernelContext context, ulong pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit)
         {
             return new ProcessContext(new AddressSpaceManager(addressSpaceSize));
         }
diff --git a/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall.cs b/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall.cs
index c022d6e29d..3c6e2586da 100644
--- a/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall.cs
+++ b/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall.cs
@@ -24,7 +24,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
 
         // Process
 
-        public KernelResult GetProcessId(out long pid, int handle)
+        public KernelResult GetProcessId(out ulong pid, int handle)
         {
             KProcess currentProcess = KernelStatic.GetCurrentProcess();
 
@@ -2280,7 +2280,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
             return KernelStatic.GetCurrentThread().CurrentCore;
         }
 
-        public KernelResult GetThreadId(out long threadUid, int handle)
+        public KernelResult GetThreadId(out ulong threadUid, int handle)
         {
             KProcess process = KernelStatic.GetCurrentProcess();
 
diff --git a/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall32.cs b/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall32.cs
index f1b5b0e56a..bf4eee7978 100644
--- a/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall32.cs
+++ b/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall32.cs
@@ -235,12 +235,12 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
             resultHigh = (uint)(result >> 32);
         }
 
-        public KernelResult GetProcessId32([R(1)] int handle, [R(1)] out int pidLow, [R(2)] out int pidHigh)
+        public KernelResult GetProcessId32([R(1)] int handle, [R(1)] out uint pidLow, [R(2)] out uint pidHigh)
         {
-            KernelResult result = _syscall.GetProcessId(out long pid, handle);
+            KernelResult result = _syscall.GetProcessId(out ulong pid, handle);
 
-            pidLow = (int)(pid & uint.MaxValue);
-            pidHigh = (int)(pid >> 32);
+            pidLow = (uint)(pid & uint.MaxValue);
+            pidHigh = (uint)(pid >> 32);
 
             return result;
         }
@@ -413,7 +413,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
 
         public KernelResult GetThreadId32([R(1)] int handle, [R(1)] out uint threadUidLow, [R(2)] out uint threadUidHigh)
         {
-            long threadUid;
+            ulong threadUid;
 
             KernelResult result = _syscall.GetThreadId(out threadUid, handle);
 
diff --git a/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall64.cs b/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall64.cs
index fcb2a702f1..2af736d8af 100644
--- a/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall64.cs
+++ b/Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall64.cs
@@ -232,7 +232,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
             return _syscall.GetSystemTick();
         }
 
-        public KernelResult GetProcessId64([R(1)] int handle, [R(1)] out long pid)
+        public KernelResult GetProcessId64([R(1)] int handle, [R(1)] out ulong pid)
         {
             return _syscall.GetProcessId(out pid, handle);
         }
@@ -345,7 +345,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
             return _syscall.GetCurrentProcessorNumber();
         }
 
-        public KernelResult GetThreadId64([R(1)] int handle, [R(1)] out long threadUid)
+        public KernelResult GetThreadId64([R(1)] int handle, [R(1)] out ulong threadUid)
         {
             return _syscall.GetThreadId(out threadUid, handle);
         }
diff --git a/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs b/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs
index 16744c4372..60f5e1a87c 100644
--- a/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs
@@ -30,7 +30,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
         public int DynamicPriority { get; set; }
         public ulong AffinityMask { get; set; }
 
-        public long ThreadUid { get; private set; }
+        public ulong ThreadUid { get; private set; }
 
         private long _totalTimeRunning;
 
diff --git a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ILibraryAppletProxy.cs b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ILibraryAppletProxy.cs
index b85a39e5cf..08b8fc7ea3 100644
--- a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ILibraryAppletProxy.cs
+++ b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ILibraryAppletProxy.cs
@@ -5,9 +5,9 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService
 {
     class ILibraryAppletProxy : IpcService
     {
-        private readonly long _pid;
+        private readonly ulong _pid;
 
-        public ILibraryAppletProxy(long pid)
+        public ILibraryAppletProxy(ulong pid)
         {
             _pid = pid;
         }
diff --git a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ISystemAppletProxy.cs b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ISystemAppletProxy.cs
index 4c94f9b6e6..61a7a46d3d 100644
--- a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ISystemAppletProxy.cs
+++ b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/ISystemAppletProxy.cs
@@ -4,9 +4,9 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService
 {
     class ISystemAppletProxy : IpcService
     {
-        private readonly long _pid;
+        private readonly ulong _pid;
 
-        public ISystemAppletProxy(long pid)
+        public ISystemAppletProxy(ulong pid)
         {
             _pid = pid;
         }
diff --git a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ISelfController.cs b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ISelfController.cs
index 51b204f0f9..2af80f6ef5 100644
--- a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ISelfController.cs
+++ b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/ISelfController.cs
@@ -8,7 +8,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
 {
     class ISelfController : IpcService
     {
-        private readonly long _pid;
+        private readonly ulong _pid;
 
         private KEvent _libraryAppletLaunchableEvent;
         private int    _libraryAppletLaunchableEventHandle;
@@ -35,7 +35,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
         private uint _screenShotImageOrientation = 0;
         private uint _idleTimeDetectionExtension = 0;
 
-        public ISelfController(ServiceCtx context, long pid)
+        public ISelfController(ServiceCtx context, ulong pid)
         {
             _libraryAppletLaunchableEvent = new KEvent(context.Device.System.KernelContext);
             _pid = pid;
diff --git a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IWindowController.cs b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IWindowController.cs
index a97b01b410..7cb557ae00 100644
--- a/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IWindowController.cs
+++ b/Ryujinx.HLE/HOS/Services/Am/AppletAE/AllSystemAppletProxiesService/SystemAppletProxy/IWindowController.cs
@@ -4,9 +4,9 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
 {
     class IWindowController : IpcService
     {
-        private readonly long _pid;
+        private readonly ulong _pid;
 
-        public IWindowController(long pid)
+        public IWindowController(ulong pid)
         {
             _pid = pid;
         }
diff --git a/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/IApplicationProxy.cs b/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/IApplicationProxy.cs
index 44477922d3..bb85c1db45 100644
--- a/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/IApplicationProxy.cs
+++ b/Ryujinx.HLE/HOS/Services/Am/AppletOE/ApplicationProxyService/IApplicationProxy.cs
@@ -5,9 +5,9 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService
 {
     class IApplicationProxy : IpcService
     {
-        private readonly long _pid;
+        private readonly ulong _pid;
 
-        public IApplicationProxy(long pid)
+        public IApplicationProxy(ulong pid)
         {
             _pid = pid;
         }
diff --git a/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs b/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs
index 7a98b0e13c..e417ffd5de 100644
--- a/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs
+++ b/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs
@@ -318,7 +318,7 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator
 
             // Pid placeholder
             context.RequestData.ReadInt64();
-            long pid = context.Request.HandleDesc.PId;
+            ulong pid = context.Request.HandleDesc.PId;
 
             ulong playHistoryRegistrationKeyPosition = context.Request.PtrBuff[0].Position;
             ulong PlayHistoryRegistrationKeySize     = context.Request.PtrBuff[0].Size;
diff --git a/Ryujinx.HLE/HOS/Services/Ns/Aoc/IAddOnContentManager.cs b/Ryujinx.HLE/HOS/Services/Ns/Aoc/IAddOnContentManager.cs
index 18e371da5a..53866a6b38 100644
--- a/Ryujinx.HLE/HOS/Services/Ns/Aoc/IAddOnContentManager.cs
+++ b/Ryujinx.HLE/HOS/Services/Ns/Aoc/IAddOnContentManager.cs
@@ -44,7 +44,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
         // CountAddOnContent(pid) -> u32
         public ResultCode CountAddOnContent(ServiceCtx context)
         {
-            long pid = context.Request.HandleDesc.PId;
+            ulong pid = context.Request.HandleDesc.PId;
 
             // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
 
@@ -55,7 +55,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
         // ListAddOnContent(u32 start_index, u32 buffer_size, pid) -> (u32 count, buffer<u32>)
         public ResultCode ListAddOnContent(ServiceCtx context)
         {
-            long pid = context.Request.HandleDesc.PId;
+            ulong pid = context.Request.HandleDesc.PId;
 
             // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
 
@@ -75,7 +75,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
         // GetAddOnContentBaseId(pid) -> u64
         public ResultCode GetAddOnContentBaseId(ServiceCtx context)
         {
-            long pid = context.Request.HandleDesc.PId;
+            ulong pid = context.Request.HandleDesc.PId;
 
             // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
 
@@ -95,7 +95,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
         // PrepareAddOnContent(u32 index, pid)
         public ResultCode PrepareAddOnContent(ServiceCtx context)
         {
-            long pid = context.Request.HandleDesc.PId;
+            ulong pid = context.Request.HandleDesc.PId;
 
             // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
 
@@ -123,7 +123,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
         // GetAddOnContentListChangedEventWithProcessId(pid) -> handle<copy>
         public ResultCode GetAddOnContentListChangedEventWithProcessId(ServiceCtx context)
         {
-            long pid = context.Request.HandleDesc.PId;
+            ulong pid = context.Request.HandleDesc.PId;
 
             // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
 
@@ -142,7 +142,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
         // NotifyMountAddOnContent(pid, u64 title_id)
         public ResultCode NotifyMountAddOnContent(ServiceCtx context)
         {
-            long pid = context.Request.HandleDesc.PId;
+            ulong pid = context.Request.HandleDesc.PId;
 
             // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
 
@@ -160,7 +160,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
         // NotifyUnmountAddOnContent(pid, u64 title_id)
         public ResultCode NotifyUnmountAddOnContent(ServiceCtx context)
         {
-            long pid = context.Request.HandleDesc.PId;
+            ulong pid = context.Request.HandleDesc.PId;
 
             // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
 
@@ -175,7 +175,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
         // CheckAddOnContentMountStatus(pid)
         public ResultCode CheckAddOnContentMountStatus(ServiceCtx context)
         {
-            long pid = context.Request.HandleDesc.PId;
+            ulong pid = context.Request.HandleDesc.PId;
 
             // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
             //       Then it does some internal checks and returns InvalidBufferSize if they fail.
diff --git a/Ryujinx.HLE/HOS/Services/Nv/Host1xContext.cs b/Ryujinx.HLE/HOS/Services/Nv/Host1xContext.cs
index 14f3389b85..bb609fa4a2 100644
--- a/Ryujinx.HLE/HOS/Services/Nv/Host1xContext.cs
+++ b/Ryujinx.HLE/HOS/Services/Nv/Host1xContext.cs
@@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv
         public NvMemoryAllocator MemoryAllocator { get; }
         public Host1xDevice Host1x { get;}
 
-        public Host1xContext(GpuContext gpu, long pid)
+        public Host1xContext(GpuContext gpu, ulong pid)
         {
             MemoryAllocator = new NvMemoryAllocator();
             Host1x = new Host1xDevice(gpu.Synchronization);
diff --git a/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs b/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs
index b70f6cb79b..9a1842268c 100644
--- a/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs
+++ b/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs
@@ -40,7 +40,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv
         public static IdDictionary DeviceFileIdRegistry = new IdDictionary();
 
         private IVirtualMemoryManager _clientMemory;
-        private long _owner;
+        private ulong _owner;
 
         private bool _transferMemInitialized = false;
 
@@ -53,7 +53,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv
         {
             if (_deviceFileRegistry.TryGetValue(path, out Type deviceFileClass))
             {
-                ConstructorInfo constructor = deviceFileClass.GetConstructor(new Type[] { typeof(ServiceCtx), typeof(IVirtualMemoryManager), typeof(long) });
+                ConstructorInfo constructor = deviceFileClass.GetConstructor(new Type[] { typeof(ServiceCtx), typeof(IVirtualMemoryManager), typeof(ulong) });
 
                 NvDeviceFile deviceFile = (NvDeviceFile)constructor.Invoke(new object[] { context, _clientMemory, _owner });
 
diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvDeviceFile.cs
index f143f6d1c3..0ecbab3ff0 100644
--- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvDeviceFile.cs
+++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvDeviceFile.cs
@@ -11,11 +11,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices
     abstract class NvDeviceFile
     {
         public readonly ServiceCtx Context;
-        public readonly long       Owner;
+        public readonly ulong      Owner;
 
         public string Path;
 
-        public NvDeviceFile(ServiceCtx context, long owner)
+        public NvDeviceFile(ServiceCtx context, ulong owner)
         {
             Context = context;
             Owner   = owner;
diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs
index 49c768b4e1..ac5761d694 100644
--- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs
+++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs
@@ -41,7 +41,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
         private readonly AddressSpaceContext _asContext;
         private readonly NvMemoryAllocator _memoryAllocator;
 
-        public NvHostAsGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, owner)
+        public NvHostAsGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner)
         {
             _asContext = new AddressSpaceContext(context.Device.Gpu.CreateMemoryManager(owner));
             _memoryAllocator = new NvMemoryAllocator();
diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs
index edf554382c..f0c968eb36 100644
--- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs
+++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostChannelDeviceFile.cs
@@ -15,7 +15,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
 {
     class NvHostChannelDeviceFile : NvDeviceFile
     {
-        private static readonly ConcurrentDictionary<long, Host1xContext> _host1xContextRegistry = new();
+        private static readonly ConcurrentDictionary<ulong, Host1xContext> _host1xContextRegistry = new();
 
         private const uint MaxModuleSyncpoint = 16;
 
@@ -45,7 +45,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
 
         private NvFence _channelSyncpoint;
 
-        public NvHostChannelDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, owner)
+        public NvHostChannelDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner)
         {
             _device        = context.Device;
             _memory        = memory;
@@ -556,9 +556,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
             _channelSyncpoint.Id = 0;
         }
 
-        private static Host1xContext GetHost1XContext(GpuContext gpu, long pid)
+        private static Host1xContext GetHost1XContext(GpuContext gpu, ulong pid)
         {
-            return _host1xContextRegistry.GetOrAdd(pid, (long key) => new Host1xContext(gpu, key));
+            return _host1xContextRegistry.GetOrAdd(pid, (ulong key) => new Host1xContext(gpu, key));
         }
 
         public static void Destroy()
diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs
index 46c19c6ebb..5bc3e3bd34 100644
--- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs
+++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostChannel/NvHostGpuDeviceFile.cs
@@ -16,7 +16,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
         private int _smExceptionBptPauseReportEventHandle;
         private int _errorNotifierEventHandle;
 
-        public NvHostGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, memory, owner)
+        public NvHostGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, memory, owner)
         {
             _smExceptionBptIntReportEvent   = CreateEvent(context, out _smExceptionBptIntReportEventHandle);
             _smExceptionBptPauseReportEvent = CreateEvent(context, out _smExceptionBptPauseReportEventHandle);
diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs
index f9a2e03dfa..2149e26676 100644
--- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs
+++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrl/NvHostCtrlDeviceFile.cs
@@ -20,7 +20,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
         private Switch        _device;
         private NvHostEvent[] _events;
 
-        public NvHostCtrlDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, owner)
+        public NvHostCtrlDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner)
         {
             if (NxSettings.Settings.TryGetValue("nv!rmos_set_production_mode", out object productionModeSetting))
             {
diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs
index 840d95b93a..f1a6570b08 100644
--- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs
+++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostCtrlGpu/NvHostCtrlGpuDeviceFile.cs
@@ -16,7 +16,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu
         private KEvent _errorEvent;
         private KEvent _unknownEvent;
 
-        public NvHostCtrlGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, owner)
+        public NvHostCtrlGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner)
         {
             _errorEvent   = new KEvent(context.Device.System.KernelContext);
             _unknownEvent = new KEvent(context.Device.System.KernelContext);
diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs
index 7f6f6068fb..68e6100680 100644
--- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs
+++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs
@@ -11,9 +11,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
     {
         private const int FlagNotFreedYet = 1;
 
-        private static ConcurrentDictionary<long, IdDictionary> _maps = new ConcurrentDictionary<long, IdDictionary>();
+        private static ConcurrentDictionary<ulong, IdDictionary> _maps = new ConcurrentDictionary<ulong, IdDictionary>();
 
-        public NvMapDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, owner)
+        public NvMapDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner)
         {
             IdDictionary dict = _maps.GetOrAdd(Owner, (key) => new IdDictionary());
 
@@ -237,7 +237,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
             return dict.Add(map);
         }
 
-        private static bool DeleteMapWithHandle(long pid, int handle)
+        private static bool DeleteMapWithHandle(ulong pid, int handle)
         {
             if (_maps.TryGetValue(pid, out IdDictionary dict))
             {
@@ -247,12 +247,12 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
             return false;
         }
 
-        public static void IncrementMapRefCount(long pid, int handle)
+        public static void IncrementMapRefCount(ulong pid, int handle)
         {
             GetMapFromHandle(pid, handle)?.IncrementRefCount();
         }
 
-        public static bool DecrementMapRefCount(long pid, int handle)
+        public static bool DecrementMapRefCount(ulong pid, int handle)
         {
             NvMapHandle map = GetMapFromHandle(pid, handle);
 
@@ -275,7 +275,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
             }
         }
 
-        public static NvMapHandle GetMapFromHandle(long pid, int handle)
+        public static NvMapHandle GetMapFromHandle(ulong pid, int handle)
         {
             if (_maps.TryGetValue(pid, out IdDictionary dict))
             {
diff --git a/Ryujinx.HLE/HOS/Services/Pctl/IParentalControlServiceFactory.cs b/Ryujinx.HLE/HOS/Services/Pctl/IParentalControlServiceFactory.cs
index a84e13b54c..f5be0cb423 100644
--- a/Ryujinx.HLE/HOS/Services/Pctl/IParentalControlServiceFactory.cs
+++ b/Ryujinx.HLE/HOS/Services/Pctl/IParentalControlServiceFactory.cs
@@ -19,7 +19,7 @@ namespace Ryujinx.HLE.HOS.Services.Pctl
         // CreateService(u64, pid) -> object<nn::pctl::detail::ipc::IParentalControlService>
         public ResultCode CreateService(ServiceCtx context)
         {
-            long pid = context.Request.HandleDesc.PId;
+            ulong pid = context.Request.HandleDesc.PId;
 
             MakeObject(context, new IParentalControlService(context, pid, true, _permissionFlag));
 
@@ -30,7 +30,7 @@ namespace Ryujinx.HLE.HOS.Services.Pctl
         // CreateServiceWithoutInitialize(u64, pid) -> object<nn::pctl::detail::ipc::IParentalControlService>
         public ResultCode CreateServiceWithoutInitialize(ServiceCtx context)
         {
-            long pid = context.Request.HandleDesc.PId;
+            ulong pid = context.Request.HandleDesc.PId;
 
             MakeObject(context, new IParentalControlService(context, pid, false, _permissionFlag));
 
diff --git a/Ryujinx.HLE/HOS/Services/Pctl/ParentalControlServiceFactory/IParentalControlService.cs b/Ryujinx.HLE/HOS/Services/Pctl/ParentalControlServiceFactory/IParentalControlService.cs
index 173b3223dc..15b998f2a7 100644
--- a/Ryujinx.HLE/HOS/Services/Pctl/ParentalControlServiceFactory/IParentalControlService.cs
+++ b/Ryujinx.HLE/HOS/Services/Pctl/ParentalControlServiceFactory/IParentalControlService.cs
@@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory
 {
     class IParentalControlService : IpcService
     {
-        private long                     _pid;
+        private ulong                    _pid;
         private int                      _permissionFlag;
         private ulong                    _titleId;
         private ParentalControlFlagValue _parentalControlFlag;
@@ -19,7 +19,7 @@ namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory
         private bool _stereoVisionRestrictionConfigurable = true;
         private bool _stereoVisionRestriction             = false;
 
-        public IParentalControlService(ServiceCtx context, long pid, bool withInitialize, int permissionFlag)
+        public IParentalControlService(ServiceCtx context, ulong pid, bool withInitialize, int permissionFlag)
         {
             _pid            = pid;
             _permissionFlag = permissionFlag;
diff --git a/Ryujinx.HLE/HOS/Services/Pm/IShellInterface.cs b/Ryujinx.HLE/HOS/Services/Pm/IShellInterface.cs
index 7bb7c8ed21..e59b02d818 100644
--- a/Ryujinx.HLE/HOS/Services/Pm/IShellInterface.cs
+++ b/Ryujinx.HLE/HOS/Services/Pm/IShellInterface.cs
@@ -11,7 +11,7 @@
         {
             // FIXME: This is wrong but needed to make hb loader works
             // TODO: Change this when we will have a way to process via a PM like interface.
-            long pid = context.Process.Pid;
+            ulong pid = context.Process.Pid;
 
             context.ResponseData.Write(pid);
 
diff --git a/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs b/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs
index e93971fcb0..713ef6cc1a 100644
--- a/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs
+++ b/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs
@@ -418,7 +418,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro
             return (ResultCode)result;
         }
 
-        private ResultCode IsInitialized(long pid)
+        private ResultCode IsInitialized(ulong pid)
         {
             if (_owner != null && _owner.Pid == pid)
             {
diff --git a/Ryujinx.HLE/HOS/Services/Sockets/Bsd/BsdContext.cs b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/BsdContext.cs
index 071c131766..cd78af78bf 100644
--- a/Ryujinx.HLE/HOS/Services/Sockets/Bsd/BsdContext.cs
+++ b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/BsdContext.cs
@@ -5,7 +5,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
 {
     class BsdContext
     {
-        private static ConcurrentDictionary<long, BsdContext> _registry = new ConcurrentDictionary<long, BsdContext>();
+        private static ConcurrentDictionary<ulong, BsdContext> _registry = new ConcurrentDictionary<ulong, BsdContext>();
 
         private readonly object _lock = new object();
 
@@ -123,7 +123,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
             return LinuxError.SUCCESS;
         }
 
-        public static BsdContext GetOrRegister(long processId)
+        public static BsdContext GetOrRegister(ulong processId)
         {
             BsdContext context = GetContext(processId);
 
@@ -137,7 +137,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
             return context;
         }
 
-        public static BsdContext GetContext(long processId)
+        public static BsdContext GetContext(ulong processId)
         {
             if (!_registry.TryGetValue(processId, out BsdContext processContext))
             {
diff --git a/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnection.cs b/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnection.cs
index fba22f45db..96ae84be7b 100644
--- a/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnection.cs
+++ b/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnection.cs
@@ -23,11 +23,11 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService
 
         private ISslConnectionBase _connection;
         private BsdContext _bsdContext;
-        private readonly long _processId;
+        private readonly ulong _processId;
 
         private byte[] _nextAplnProto;
 
-        public ISslConnection(long processId, SslVersion sslVersion)
+        public ISslConnection(ulong processId, SslVersion sslVersion)
         {
             _processId = processId;
             _sslVersion = sslVersion;
diff --git a/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslContext.cs b/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslContext.cs
index 0b8cb463ab..93b9b423ef 100644
--- a/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslContext.cs
+++ b/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslContext.cs
@@ -1,5 +1,4 @@
 using Ryujinx.Common.Logging;
-using Ryujinx.HLE.HOS.Services.Sockets.Bsd;
 using Ryujinx.HLE.HOS.Services.Ssl.Types;
 using System.Text;
 
@@ -9,12 +8,12 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService
     {
         private uint _connectionCount;
 
-        private readonly long _processId;
+        private readonly ulong _processId;
         private readonly SslVersion _sslVersion;
         private ulong _serverCertificateId;
         private ulong _clientCertificateId;
 
-        public ISslContext(long processId, SslVersion sslVersion)
+        public ISslContext(ulong processId, SslVersion sslVersion)
         {
             _processId = processId;
             _sslVersion = sslVersion;
diff --git a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueue.cs b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueue.cs
index 2a9a606446..422414dee0 100644
--- a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueue.cs
+++ b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueue.cs
@@ -2,7 +2,7 @@
 {
     static class BufferQueue
     {
-        public static BufferQueueCore CreateBufferQueue(Switch device, long pid, out BufferQueueProducer producer, out BufferQueueConsumer consumer)
+        public static BufferQueueCore CreateBufferQueue(Switch device, ulong pid, out BufferQueueProducer producer, out BufferQueueConsumer consumer)
         {
             BufferQueueCore core = new BufferQueueCore(device, pid);
 
diff --git a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueCore.cs b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueCore.cs
index b8fc71f386..3c93139361 100644
--- a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueCore.cs
+++ b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/BufferQueueCore.cs
@@ -40,7 +40,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
         private KEvent _waitBufferFreeEvent;
         private KEvent _frameAvailableEvent;
 
-        public long Owner { get; }
+        public ulong Owner { get; }
 
         public bool Active { get; private set; }
 
@@ -48,7 +48,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
 
         public event Action BufferQueued;
 
-        public BufferQueueCore(Switch device, long pid)
+        public BufferQueueCore(Switch device, ulong pid)
         {
             Slots                    = new BufferSlotArray();
             IsAbandoned              = false;
diff --git a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/SurfaceFlinger.cs b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/SurfaceFlinger.cs
index c45c4b9da7..be2e15bd3c 100644
--- a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/SurfaceFlinger.cs
+++ b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/SurfaceFlinger.cs
@@ -44,7 +44,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
             public IGraphicBufferProducer Producer;
             public BufferItemConsumer     Consumer;
             public BufferQueueCore        Core;
-            public long                   Owner;
+            public ulong                  Owner;
         }
 
         private class TextureCallbackInformation
@@ -92,7 +92,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
             }
         }
 
-        public IGraphicBufferProducer OpenLayer(long pid, long layerId)
+        public IGraphicBufferProducer OpenLayer(ulong pid, long layerId)
         {
             bool needCreate;
 
@@ -109,7 +109,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
             return GetProducerByLayerId(layerId);
         }
 
-        public IGraphicBufferProducer CreateLayer(long pid, out long layerId)
+        public IGraphicBufferProducer CreateLayer(ulong pid, out long layerId)
         {
             layerId = 1;
 
@@ -129,7 +129,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
             return GetProducerByLayerId(layerId);
         }
 
-        private void CreateLayerFromId(long pid, long layerId)
+        private void CreateLayerFromId(ulong pid, long layerId)
         {
             lock (Lock)
             {
diff --git a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/GraphicBuffer.cs b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/GraphicBuffer.cs
index d86ff21e85..bd76922616 100644
--- a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/GraphicBuffer.cs
+++ b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Types/GraphicBuffer.cs
@@ -42,7 +42,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
             Buffer = parcel.ReadUnmanagedType<NvGraphicBuffer>();
         }
 
-        public void IncrementNvMapHandleRefCount(long pid)
+        public void IncrementNvMapHandleRefCount(ulong pid)
         {
             NvMapDeviceFile.IncrementMapRefCount(pid, Buffer.NvMapId);
 
@@ -52,7 +52,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
             }
         }
 
-        public void DecrementNvMapHandleRefCount(long pid)
+        public void DecrementNvMapHandleRefCount(ulong pid)
         {
             NvMapDeviceFile.DecrementMapRefCount(pid, Buffer.NvMapId);
 
diff --git a/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/IManagerDisplayService.cs b/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/IManagerDisplayService.cs
index fdab0f1b71..096c7a30e9 100644
--- a/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/IManagerDisplayService.cs
+++ b/Ryujinx.HLE/HOS/Services/Vi/RootService/ApplicationDisplayService/IManagerDisplayService.cs
@@ -33,7 +33,7 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService.ApplicationDisplayService
             long displayId            = context.RequestData.ReadInt64();
             long appletResourceUserId = context.RequestData.ReadInt64();
 
-            long pid = context.Device.System.AppletState.AppletResourceUserIds.GetData<long>((int)appletResourceUserId);
+            ulong pid = context.Device.System.AppletState.AppletResourceUserIds.GetData<ulong>((int)appletResourceUserId);
 
             context.Device.System.SurfaceFlinger.CreateLayer(pid, out long layerId);
             context.Device.System.SurfaceFlinger.SetRenderLayer(layerId);
diff --git a/Ryujinx.HLE/HOS/TamperMachine.cs b/Ryujinx.HLE/HOS/TamperMachine.cs
index 016f326f1b..c6f8bf9735 100644
--- a/Ryujinx.HLE/HOS/TamperMachine.cs
+++ b/Ryujinx.HLE/HOS/TamperMachine.cs
@@ -54,7 +54,7 @@ namespace Ryujinx.HLE.HOS
             Activate();
         }
 
-        private bool CanInstallOnPid(long pid)
+        private bool CanInstallOnPid(ulong pid)
         {
             // Do not allow tampering of kernel processes.
             if (pid < KernelConstants.InitialProcessId)