Structural and Memory Safety Improvements, Analyzer Cleanup (ryubing/ryujinx!47)

See merge request ryubing/ryujinx!47
This commit is contained in:
MrKev
2025-06-11 17:58:27 -05:00
committed by LotP
parent d03ae9c164
commit ea027d65a7
309 changed files with 1018 additions and 1247 deletions

View File

@@ -4,9 +4,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
class KLightClientSession : KAutoObject
{
#pragma warning disable IDE0052 // Remove unread private member
private readonly KLightSession _parent;
#pragma warning restore IDE0052
public KLightClientSession(KernelContext context, KLightSession parent) : base(context)
{

View File

@@ -4,9 +4,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
class KLightServerSession : KAutoObject
{
#pragma warning disable IDE0052 // Remove unread private member
private readonly KLightSession _parent;
#pragma warning restore IDE0052
public KLightServerSession(KernelContext context, KLightSession parent) : base(context)
{

View File

@@ -8,9 +8,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
public KServerPort ServerPort { get; }
public KClientPort ClientPort { get; }
#pragma warning disable IDE0052 // Remove unread private member
private readonly string _name;
#pragma warning restore IDE0052
private readonly ChannelState _state;

View File

@@ -86,11 +86,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
private static readonly int[] _memoryBlockPageShifts = [12, 16, 21, 22, 25, 29, 30];
#pragma warning disable IDE0052 // Remove unread private member
private readonly ulong _heapAddress;
private readonly ulong _heapSize;
private ulong _usedSize;
#pragma warning restore IDE0052
private readonly int _blocksCount;
private readonly Block[] _blocks;

View File

@@ -1,5 +1,4 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace Ryujinx.HLE.HOS.Kernel.Process
{

View File

@@ -1,7 +1,9 @@
using Ryujinx.HLE.HOS.Kernel.Memory;
using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
{
[StructLayout(LayoutKind.Sequential, Pack = 4)]
struct MemoryInfo
{
public ulong Address;
@@ -11,9 +13,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
public KMemoryPermission Permission;
public int IpcRefCount;
public int DeviceRefCount;
#pragma warning disable CS0414, IDE0052 // Remove unread private member
private readonly int _padding;
#pragma warning restore CS0414, IDE0052
public MemoryInfo(
ulong address,

View File

@@ -184,7 +184,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x5f)]
public Result FlushProcessDataCache(int processHandle, ulong address, ulong size)
public static Result FlushProcessDataCache(int processHandle, ulong address, ulong size)
{
// FIXME: This needs to be implemented as ARMv7 doesn't have any way to do cache maintenance operations on EL0.
// As we don't support (and don't actually need) to flush the cache, this is stubbed.
@@ -263,7 +263,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x22)]
public Result SendSyncRequestWithUserBuffer(
public static Result SendSyncRequestWithUserBuffer(
[PointerSized] ulong messagePtr,
[PointerSized] ulong messageSize,
int handle)
@@ -901,7 +901,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(2)]
public Result SetMemoryPermission([PointerSized] ulong address, [PointerSized] ulong size, KMemoryPermission permission)
public static Result SetMemoryPermission([PointerSized] ulong address, [PointerSized] ulong size, KMemoryPermission permission)
{
if (!PageAligned(address))
{
@@ -934,7 +934,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(3)]
public Result SetMemoryAttribute(
public static Result SetMemoryAttribute(
[PointerSized] ulong address,
[PointerSized] ulong size,
MemoryAttribute attributeMask,
@@ -983,7 +983,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(4)]
public Result MapMemory([PointerSized] ulong dst, [PointerSized] ulong src, [PointerSized] ulong size)
public static Result MapMemory([PointerSized] ulong dst, [PointerSized] ulong src, [PointerSized] ulong size)
{
if (!PageAligned(src | dst))
{
@@ -1020,7 +1020,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(5)]
public Result UnmapMemory([PointerSized] ulong dst, [PointerSized] ulong src, [PointerSized] ulong size)
public static Result UnmapMemory([PointerSized] ulong dst, [PointerSized] ulong src, [PointerSized] ulong size)
{
if (!PageAligned(src | dst))
{
@@ -1057,7 +1057,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(6)]
public Result QueryMemory([PointerSized] ulong infoPtr, [PointerSized] out ulong pageInfo, [PointerSized] ulong address)
public static Result QueryMemory([PointerSized] ulong infoPtr, [PointerSized] out ulong pageInfo, [PointerSized] ulong address)
{
Result result = QueryMemory(out MemoryInfo info, out pageInfo, address);
@@ -1092,7 +1092,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x13)]
public Result MapSharedMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size, KMemoryPermission permission)
public static Result MapSharedMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size, KMemoryPermission permission)
{
if (!PageAligned(address))
{
@@ -1139,7 +1139,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x14)]
public Result UnmapSharedMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size)
public static Result UnmapSharedMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size)
{
if (!PageAligned(address))
{
@@ -1244,7 +1244,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x51)]
public Result MapTransferMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size, KMemoryPermission permission)
public static Result MapTransferMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size, KMemoryPermission permission)
{
if (!PageAligned(address))
{
@@ -1291,7 +1291,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x52)]
public Result UnmapTransferMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size)
public static Result UnmapTransferMemory(int handle, [PointerSized] ulong address, [PointerSized] ulong size)
{
if (!PageAligned(address))
{
@@ -1332,7 +1332,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x2c)]
public Result MapPhysicalMemory([PointerSized] ulong address, [PointerSized] ulong size)
public static Result MapPhysicalMemory([PointerSized] ulong address, [PointerSized] ulong size)
{
if (!PageAligned(address))
{
@@ -1368,7 +1368,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x2d)]
public Result UnmapPhysicalMemory([PointerSized] ulong address, [PointerSized] ulong size)
public static Result UnmapPhysicalMemory([PointerSized] ulong address, [PointerSized] ulong size)
{
if (!PageAligned(address))
{
@@ -1445,7 +1445,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x4c)]
public Result ControlCodeMemory(
public static Result ControlCodeMemory(
int handle,
CodeMemoryOperation op,
ulong address,
@@ -1524,7 +1524,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x73)]
public Result SetProcessMemoryPermission(
public static Result SetProcessMemoryPermission(
int handle,
ulong src,
ulong size,
@@ -1566,7 +1566,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x74)]
public Result MapProcessMemory(
public static Result MapProcessMemory(
[PointerSized] ulong dst,
int handle,
ulong src,
@@ -1623,7 +1623,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x75)]
public Result UnmapProcessMemory(
public static Result UnmapProcessMemory(
[PointerSized] ulong dst,
int handle,
ulong src,
@@ -1669,7 +1669,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x77)]
public Result MapProcessCodeMemory(int handle, ulong dst, ulong src, ulong size)
public static Result MapProcessCodeMemory(int handle, ulong dst, ulong src, ulong size)
{
if (!PageAligned(dst) || !PageAligned(src))
{
@@ -1707,7 +1707,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x78)]
public Result UnmapProcessCodeMemory(int handle, ulong dst, ulong src, ulong size)
public static Result UnmapProcessCodeMemory(int handle, ulong dst, ulong src, ulong size)
{
if (!PageAligned(dst) || !PageAligned(src))
{
@@ -1752,7 +1752,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
// System
[Svc(0x7b)]
public Result TerminateProcess(int handle)
public static Result TerminateProcess(int handle)
{
KProcess process = KernelStatic.GetCurrentProcess();
@@ -1782,7 +1782,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(7)]
public void ExitProcess()
public static void ExitProcess()
{
KernelStatic.GetCurrentProcess().TerminateCurrentProcess();
}
@@ -1878,7 +1878,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x26)]
public void Break(ulong reason)
public static void Break(ulong reason)
{
KThread currentThread = KernelStatic.GetCurrentThread();
@@ -1905,7 +1905,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x27)]
public void OutputDebugString([PointerSized] ulong strPtr, [PointerSized] ulong size)
public static void OutputDebugString([PointerSized] ulong strPtr, [PointerSized] ulong size)
{
KProcess process = KernelStatic.GetCurrentProcess();
@@ -2371,7 +2371,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x30)]
public Result GetResourceLimitLimitValue(out long limitValue, int handle, LimitableResource resource)
public static Result GetResourceLimitLimitValue(out long limitValue, int handle, LimitableResource resource)
{
limitValue = 0;
@@ -2393,7 +2393,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x31)]
public Result GetResourceLimitCurrentValue(out long limitValue, int handle, LimitableResource resource)
public static Result GetResourceLimitCurrentValue(out long limitValue, int handle, LimitableResource resource)
{
limitValue = 0;
@@ -2415,7 +2415,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x37)]
public Result GetResourceLimitPeakValue(out long peak, int handle, LimitableResource resource)
public static Result GetResourceLimitPeakValue(out long peak, int handle, LimitableResource resource)
{
peak = 0;
@@ -2447,7 +2447,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x7e)]
public Result SetResourceLimitLimitValue(int handle, LimitableResource resource, long limitValue)
public static Result SetResourceLimitLimitValue(int handle, LimitableResource resource, long limitValue)
{
if (resource >= LimitableResource.Count)
{
@@ -2542,7 +2542,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(9)]
public Result StartThread(int handle)
public static Result StartThread(int handle)
{
KProcess process = KernelStatic.GetCurrentProcess();
@@ -2570,7 +2570,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0xa)]
public void ExitThread()
public static void ExitThread()
{
KThread currentThread = KernelStatic.GetCurrentThread();
@@ -2602,7 +2602,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0xc)]
public Result GetThreadPriority(out int priority, int handle)
public static Result GetThreadPriority(out int priority, int handle)
{
KProcess process = KernelStatic.GetCurrentProcess();
@@ -2623,7 +2623,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0xd)]
public Result SetThreadPriority(int handle, int priority)
public static Result SetThreadPriority(int handle, int priority)
{
// TODO: NPDM check.
@@ -2642,7 +2642,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0xe)]
public Result GetThreadCoreMask(out int preferredCore, out ulong affinityMask, int handle)
public static Result GetThreadCoreMask(out int preferredCore, out ulong affinityMask, int handle)
{
KProcess process = KernelStatic.GetCurrentProcess();
@@ -2665,7 +2665,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0xf)]
public Result SetThreadCoreMask(int handle, int preferredCore, ulong affinityMask)
public static Result SetThreadCoreMask(int handle, int preferredCore, ulong affinityMask)
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
@@ -2714,13 +2714,13 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x10)]
public int GetCurrentProcessorNumber()
public static int GetCurrentProcessorNumber()
{
return KernelStatic.GetCurrentThread().CurrentCore;
}
[Svc(0x25)]
public Result GetThreadId(out ulong threadUid, int handle)
public static Result GetThreadId(out ulong threadUid, int handle)
{
KProcess process = KernelStatic.GetCurrentProcess();
@@ -2741,7 +2741,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x32)]
public Result SetThreadActivity(int handle, bool pause)
public static Result SetThreadActivity(int handle, bool pause)
{
KProcess process = KernelStatic.GetCurrentProcess();
@@ -2766,7 +2766,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x33)]
public Result GetThreadContext3([PointerSized] ulong address, int handle)
public static Result GetThreadContext3([PointerSized] ulong address, int handle)
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
KThread currentThread = KernelStatic.GetCurrentThread();
@@ -2931,7 +2931,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x1a)]
public Result ArbitrateLock(int ownerHandle, [PointerSized] ulong mutexAddress, int requesterHandle)
public static Result ArbitrateLock(int ownerHandle, [PointerSized] ulong mutexAddress, int requesterHandle)
{
if (IsPointingInsideKernel(mutexAddress))
{
@@ -2949,7 +2949,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x1b)]
public Result ArbitrateUnlock([PointerSized] ulong mutexAddress)
public static Result ArbitrateUnlock([PointerSized] ulong mutexAddress)
{
if (IsPointingInsideKernel(mutexAddress))
{
@@ -2967,7 +2967,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x1c)]
public Result WaitProcessWideKeyAtomic(
public static Result WaitProcessWideKeyAtomic(
[PointerSized] ulong mutexAddress,
[PointerSized] ulong condVarAddress,
int handle,
@@ -2998,7 +2998,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x1d)]
public Result SignalProcessWideKey([PointerSized] ulong address, int count)
public static Result SignalProcessWideKey([PointerSized] ulong address, int count)
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
@@ -3008,7 +3008,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x34)]
public Result WaitForAddress([PointerSized] ulong address, ArbitrationType type, int value, long timeout)
public static Result WaitForAddress([PointerSized] ulong address, ArbitrationType type, int value, long timeout)
{
if (IsPointingInsideKernel(address))
{
@@ -3040,7 +3040,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x35)]
public Result SignalToAddress([PointerSized] ulong address, SignalType type, int value, int count)
public static Result SignalToAddress([PointerSized] ulong address, SignalType type, int value, int count)
{
if (IsPointingInsideKernel(address))
{
@@ -3067,7 +3067,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
}
[Svc(0x36)]
public Result SynchronizePreemptionState()
public static Result SynchronizePreemptionState()
{
KernelStatic.GetCurrentThread().SynchronizePreemptionState();

View File

@@ -1,8 +1,10 @@
using ARMeilleure.State;
using Ryujinx.Common.Memory;
using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ThreadContext
{
public Array29<ulong> Registers;
@@ -11,9 +13,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
public ulong Sp;
public ulong Pc;
public uint Pstate;
#pragma warning disable CS0169, IDE0051 // Remove unused private member
private readonly uint _padding;
#pragma warning restore CS0169, IDE0051
public Array32<V128> FpuRegisters;
public uint Fpcr;
public uint Fpsr;