diff options
Diffstat (limited to 'src/Ryujinx.HLE/HOS/Kernel/Process')
15 files changed, 212 insertions, 227 deletions
diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityExtensions.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityExtensions.cs index 66d56fe3..dd133ee1 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityExtensions.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityExtensions.cs @@ -19,4 +19,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return (uint)BitOperations.TrailingZeroCount(type.GetFlag()); } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityType.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityType.cs index 51d92316..9812eea0 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityType.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/CapabilityType.cs @@ -2,18 +2,18 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { enum CapabilityType : uint { - CorePriority = (1u << 3) - 1, - SyscallMask = (1u << 4) - 1, - MapRange = (1u << 6) - 1, - MapIoPage = (1u << 7) - 1, - MapRegion = (1u << 10) - 1, + CorePriority = (1u << 3) - 1, + SyscallMask = (1u << 4) - 1, + MapRange = (1u << 6) - 1, + MapIoPage = (1u << 7) - 1, + MapRegion = (1u << 10) - 1, InterruptPair = (1u << 11) - 1, - ProgramType = (1u << 13) - 1, + ProgramType = (1u << 13) - 1, KernelVersion = (1u << 14) - 1, - HandleTable = (1u << 15) - 1, - DebugFlags = (1u << 16) - 1, + HandleTable = (1u << 15) - 1, + DebugFlags = (1u << 16) - 1, - Invalid = 0u, - Padding = ~0u + Invalid = 0u, + Padding = ~0u, } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/HleProcessDebugger.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/HleProcessDebugger.cs index 8fee5c0d..cbfef588 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/HleProcessDebugger.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/HleProcessDebugger.cs @@ -14,7 +14,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { private const int Mod0 = 'M' << 0 | 'O' << 8 | 'D' << 16 | '0' << 24; - private KProcess _owner; + private readonly KProcess _owner; private class Image { @@ -27,12 +27,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public Image(ulong baseAddress, ulong size, ElfSymbol[] symbols) { BaseAddress = baseAddress; - Size = size; - Symbols = symbols; + Size = size; + Symbols = symbols; } } - private List<Image> _images; + private readonly List<Image> _images; private int _loaded; @@ -49,7 +49,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process var context = thread.Context; - StringBuilder trace = new StringBuilder(); + StringBuilder trace = new(); trace.AppendLine($"Process: {_owner.Name}, PID: {_owner.Pid}"); @@ -111,7 +111,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process var context = thread.Context; - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new(); string GetReg(int x) { @@ -145,11 +145,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return sb.ToString(); } - private bool TryGetSubName(Image image, ulong address, out ElfSymbol symbol) + private static bool TryGetSubName(Image image, ulong address, out ElfSymbol symbol) { address -= image.BaseAddress; - int left = 0; + int left = 0; int right = image.Symbols.Length - 1; while (left <= right) @@ -190,9 +190,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public ulong Offset; public ulong SubOffset; - public string ImageDisplay => $"{ImageName}:0x{Offset:x4}"; - public string SubDisplay => SubOffset == 0 ? SubName : $"{SubName}:0x{SubOffset:x4}"; - public string SpDisplay => SubOffset == 0 ? "SP" : $"SP:-0x{SubOffset:x4}"; + public readonly string ImageDisplay => $"{ImageName}:0x{Offset:x4}"; + public readonly string SubDisplay => SubOffset == 0 ? SubName : $"{SubName}:0x{SubOffset:x4}"; + public readonly string SpDisplay => SubOffset == 0 ? "SP" : $"SP:-0x{SubOffset:x4}"; } private bool AnalyzePointer(out PointerInfo info, ulong address, KThread thread) @@ -324,7 +324,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process private void ScanMemoryForTextSegments() { ulong oldAddress = 0; - ulong address = 0; + ulong address = 0; while (address >= oldAddress) { @@ -355,7 +355,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return; } - Dictionary<ElfDynamicTag, ulong> dynamic = new Dictionary<ElfDynamicTag, ulong>(); + Dictionary<ElfDynamicTag, ulong> dynamic = new(); int mod0Magic = memory.Read<int>(mod0Offset + 0x0); @@ -364,12 +364,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return; } - ulong dynamicOffset = memory.Read<uint>(mod0Offset + 0x4) + mod0Offset; - ulong bssStartOffset = memory.Read<uint>(mod0Offset + 0x8) + mod0Offset; - ulong bssEndOffset = memory.Read<uint>(mod0Offset + 0xc) + mod0Offset; + ulong dynamicOffset = memory.Read<uint>(mod0Offset + 0x4) + mod0Offset; + ulong bssStartOffset = memory.Read<uint>(mod0Offset + 0x8) + mod0Offset; + ulong bssEndOffset = memory.Read<uint>(mod0Offset + 0xc) + mod0Offset; ulong ehHdrStartOffset = memory.Read<uint>(mod0Offset + 0x10) + mod0Offset; - ulong ehHdrEndOffset = memory.Read<uint>(mod0Offset + 0x14) + mod0Offset; - ulong modObjOffset = memory.Read<uint>(mod0Offset + 0x18) + mod0Offset; + ulong ehHdrEndOffset = memory.Read<uint>(mod0Offset + 0x14) + mod0Offset; + ulong modObjOffset = memory.Read<uint>(mod0Offset + 0x18) + mod0Offset; bool isAArch32 = memory.Read<ulong>(dynamicOffset) > 0xFFFFFFFF || memory.Read<ulong>(dynamicOffset + 0x10) > 0xFFFFFFFF; @@ -381,14 +381,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Process if (isAArch32) { tagVal = memory.Read<uint>(dynamicOffset + 0); - value = memory.Read<uint>(dynamicOffset + 4); + value = memory.Read<uint>(dynamicOffset + 4); dynamicOffset += 0x8; } else { tagVal = memory.Read<ulong>(dynamicOffset + 0); - value = memory.Read<ulong>(dynamicOffset + 8); + value = memory.Read<ulong>(dynamicOffset + 8); dynamicOffset += 0x10; } @@ -413,7 +413,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process ulong strTblAddr = textOffset + strTab; ulong symTblAddr = textOffset + symTab; - List<ElfSymbol> symbols = new List<ElfSymbol>(); + List<ElfSymbol> symbols = new(); while (symTblAddr < strTblAddr) { @@ -430,7 +430,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process } } - private ElfSymbol GetSymbol64(IVirtualMemoryManager memory, ulong address, ulong strTblAddr) + private static ElfSymbol GetSymbol64(IVirtualMemoryManager memory, ulong address, ulong strTblAddr) { ElfSymbol64 sym = memory.Read<ElfSymbol64>(address); @@ -446,7 +446,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return new ElfSymbol(name, sym.Info, sym.Other, sym.SectionIndex, sym.ValueAddress, sym.Size); } - private ElfSymbol GetSymbol32(IVirtualMemoryManager memory, ulong address, ulong strTblAddr) + private static ElfSymbol GetSymbol32(IVirtualMemoryManager memory, ulong address, ulong strTblAddr) { ElfSymbol32 sym = memory.Read<ElfSymbol32>(address); diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KContextIdManager.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KContextIdManager.cs index 104fe578..32a75132 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KContextIdManager.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KContextIdManager.cs @@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { private const int IdMasksCount = 8; - private int[] _idMasks; + private readonly int[] _idMasks; private int _nextFreeBitHint; @@ -67,17 +67,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Process private bool TestBit(int bit) { - return (_idMasks[_nextFreeBitHint / 32] & (1 << (_nextFreeBitHint & 31))) != 0; + return (_idMasks[bit / 32] & (1 << (bit & 31))) != 0; } private void SetBit(int bit) { - _idMasks[_nextFreeBitHint / 32] |= (1 << (_nextFreeBitHint & 31)); + _idMasks[bit / 32] |= (1 << (bit & 31)); } private void ClearBit(int bit) { - _idMasks[_nextFreeBitHint / 32] &= ~(1 << (_nextFreeBitHint & 31)); + _idMasks[bit / 32] &= ~(1 << (bit & 31)); } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleEntry.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleEntry.cs index b5ca9b5e..c80423b7 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleEntry.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleEntry.cs @@ -8,12 +8,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public int Index { get; private set; } - public ushort HandleId { get; set; } - public KAutoObject Obj { get; set; } + public ushort HandleId { get; set; } + public KAutoObject Obj { get; set; } public KHandleEntry(int index) { Index = index; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleTable.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleTable.cs index 6dd7e5b7..21ea6bb2 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleTable.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KHandleTable.cs @@ -7,11 +7,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { class KHandleTable { - public const int SelfThreadHandle = (0x1ffff << 15) | 0; + public const int SelfThreadHandle = (0x1ffff << 15) | 0; public const int SelfProcessHandle = (0x1ffff << 15) | 1; - private readonly KernelContext _context; - private KHandleEntry[] _table; private KHandleEntry _tableHead; @@ -23,11 +21,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process private ushort _idCounter; - public KHandleTable(KernelContext context) - { - _context = context; - } - public Result Initialize(uint size) { if (size > 1024) @@ -81,7 +74,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process _nextFreeEntry = entry.Next; - entry.Obj = obj; + entry.Obj = obj; entry.HandleId = _idCounter; _activeSlotsCount++; @@ -143,7 +136,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { KHandleEntry entry = _table[index]; - entry.Obj = null; + entry.Obj = null; entry.Next = _nextFreeEntry; _nextFreeEntry = entry; @@ -154,14 +147,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public void SetReservedHandleObj(int handle, KAutoObject obj) { - int index = (handle >> 0) & 0x7fff; + int index = (handle >> 0) & 0x7fff; int handleId = (handle >> 15); lock (_table) { KHandleEntry entry = _table[index]; - entry.Obj = obj; + entry.Obj = obj; entry.HandleId = (ushort)handleId; obj.IncrementReferenceCount(); @@ -177,7 +170,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return false; } - int index = (handle >> 0) & 0x7fff; + int index = (handle >> 0) & 0x7fff; int handleId = (handle >> 15); KAutoObject obj = null; @@ -192,7 +185,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process if ((obj = entry.Obj) != null && entry.HandleId == handleId) { - entry.Obj = null; + entry.Obj = null; entry.Next = _nextFreeEntry; _nextFreeEntry = entry; @@ -214,7 +207,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public T GetObject<T>(int handle) where T : KAutoObject { - int index = (handle >> 0) & 0x7fff; + int index = (handle >> 0) & 0x7fff; int handleId = (handle >> 15); lock (_table) @@ -273,7 +266,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process } entry.Obj.DecrementReferenceCount(); - entry.Obj = null; + entry.Obj = null; entry.Next = _nextFreeEntry; _nextFreeEntry = entry; @@ -282,4 +275,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Process } } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs index c284243a..6008548b 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs @@ -27,8 +27,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public KPageTableBase MemoryManager { get; private set; } - private SortedDictionary<ulong, KTlsPageInfo> _fullTlsPages; - private SortedDictionary<ulong, KTlsPageInfo> _freeTlsPages; + private readonly SortedDictionary<ulong, KTlsPageInfo> _fullTlsPages; + private readonly SortedDictionary<ulong, KTlsPageInfo> _freeTlsPages; public int DefaultCpuCore { get; set; } @@ -66,19 +66,17 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public bool IsApplication { get; private set; } public ulong Pid { get; private set; } - private long _creationTimestamp; private ulong _entrypoint; private ThreadStart _customThreadStart; private ulong _imageSize; private ulong _mainThreadStackSize; private ulong _memoryUsageCapacity; - private int _version; public KHandleTable HandleTable { get; private set; } public ulong UserExceptionContextAddress { get; private set; } - private LinkedList<KThread> _threads; + private readonly LinkedList<KThread> _threads; public bool IsPaused { get; private set; } @@ -107,7 +105,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process PinnedThreads = new KThread[KScheduler.CpuCoresCount]; // TODO: Remove once we no longer need to initialize it externally. - HandleTable = new KHandleTable(context); + HandleTable = new KHandleTable(); _threads = new LinkedList<KThread>(); @@ -347,10 +345,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process State = ProcessState.Created; - _creationTimestamp = PerformanceCounter.ElapsedMilliseconds; - Flags = creationInfo.Flags; - _version = creationInfo.Version; TitleId = creationInfo.TitleId; _entrypoint = creationInfo.CodeAddress; _imageSize = (ulong)creationInfo.CodePagesCount * KPageTableBase.PageSize; @@ -370,8 +365,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process MemoryManager.AliasRegionEnd - MemoryManager.AliasRegionStart; break; - - default: throw new InvalidOperationException($"Invalid MMU flags value 0x{Flags:x2}."); + default: + throw new InvalidOperationException($"Invalid MMU flags value 0x{Flags:x2}."); } GenerateRandomEntropy(); @@ -476,9 +471,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process Result result = Result.Success; - KTlsPageInfo pageInfo; - if (_fullTlsPages.TryGetValue(tlsPageAddr, out pageInfo)) + if (_fullTlsPages.TryGetValue(tlsPageAddr, out KTlsPageInfo pageInfo)) { // TLS page was full, free slot and move to free pages tree. _fullTlsPages.Remove(tlsPageAddr); @@ -525,10 +519,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return result; } +#pragma warning disable CA1822 // Mark member as static private void GenerateRandomEntropy() { // TODO. } +#pragma warning restore CA1822 public Result Start(int mainThreadPriority, ulong stackSize) { @@ -549,7 +545,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process if (_mainThreadStackSize != 0) { - throw new InvalidOperationException("Trying to start a process with a invalid state!"); + throw new InvalidOperationException("Trying to start a process with an invalid state!"); } ulong stackSizeRounded = BitUtils.AlignUp<ulong>(stackSize, KPageTableBase.PageSize); @@ -648,7 +644,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return result; } - HandleTable = new KHandleTable(KernelContext); + HandleTable = new KHandleTable(); result = HandleTable.Initialize(Capabilities.HandleTableSize); @@ -1018,22 +1014,19 @@ namespace Ryujinx.HLE.HOS.Kernel.Process } } - private void SignalExitToDebugTerminated() + private static void SignalExitToDebugTerminated() { // TODO: Debug events. } - private void SignalExitToDebugExited() + private static void SignalExitToDebugExited() { // TODO: Debug events. } private void SignalExit() { - if (ResourceLimit != null) - { - ResourceLimit.Release(LimitableResource.Memory, GetMemoryUsage()); - } + ResourceLimit?.Release(LimitableResource.Memory, GetMemoryUsage()); KernelContext.CriticalSection.Enter(); @@ -1075,7 +1068,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process ProcessCreationFlags.AddressSpace64BitDeprecated => 36, ProcessCreationFlags.AddressSpace32BitWithoutAlias => 32, ProcessCreationFlags.AddressSpace64Bit => 39, - _ => 39 + _ => 39, }; bool for64Bit = flags.HasFlag(ProcessCreationFlags.Is64Bit); @@ -1184,10 +1177,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Process } } - public bool IsExceptionUserThread(KThread thread) + public static bool IsExceptionUserThread(KThread thread) { // TODO return false; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KProcessCapabilities.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KProcessCapabilities.cs index c99e3112..314aadf3 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KProcessCapabilities.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KProcessCapabilities.cs @@ -11,13 +11,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public byte[] SvcAccessMask { get; } public byte[] IrqAccessMask { get; } - public ulong AllowedCpuCoresMask { get; private set; } + public ulong AllowedCpuCoresMask { get; private set; } public ulong AllowedThreadPriosMask { get; private set; } - public uint DebuggingFlags { get; private set; } - public uint HandleTableSize { get; private set; } + public uint DebuggingFlags { get; private set; } + public uint HandleTableSize { get; private set; } public uint KernelReleaseVersion { get; private set; } - public uint ApplicationType { get; private set; } + public uint ApplicationType { get; private set; } public KProcessCapabilities() { @@ -28,10 +28,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public Result InitializeForKernel(ReadOnlySpan<uint> capabilities, KPageTableBase memoryManager) { - AllowedCpuCoresMask = 0xf; + AllowedCpuCoresMask = 0xf; AllowedThreadPriosMask = ulong.MaxValue; - DebuggingFlags &= ~3u; - KernelReleaseVersion = KProcess.KernelVersionPacked; + DebuggingFlags &= ~3u; + KernelReleaseVersion = KProcess.KernelVersionPacked; return Parse(capabilities, memoryManager); } @@ -86,7 +86,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process } long address = ((long)prevCap << 5) & 0xffffff000; - long size = ((long)cap << 5) & 0xfffff000; + long size = ((long)cap << 5) & 0xfffff000; if (((ulong)(address + size - 1) >> 36) != 0) { @@ -101,11 +101,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Process if ((cap >> 31) != 0) { - result = memoryManager.MapNormalMemory(address, size, perm); + result = KPageTableBase.MapNormalMemory(address, size, perm); } else { - result = memoryManager.MapIoMemory(address, size, perm); + result = KPageTableBase.MapIoMemory(address, size, perm); } if (result != Result.Success) @@ -144,168 +144,168 @@ namespace Ryujinx.HLE.HOS.Kernel.Process switch (code) { case CapabilityType.CorePriority: - { - if (AllowedCpuCoresMask != 0 || AllowedThreadPriosMask != 0) { - return KernelResult.InvalidCapability; - } + if (AllowedCpuCoresMask != 0 || AllowedThreadPriosMask != 0) + { + return KernelResult.InvalidCapability; + } - uint lowestCpuCore = (cap >> 16) & 0xff; - uint highestCpuCore = (cap >> 24) & 0xff; + uint lowestCpuCore = (cap >> 16) & 0xff; + uint highestCpuCore = (cap >> 24) & 0xff; - if (lowestCpuCore > highestCpuCore) - { - return KernelResult.InvalidCombination; - } + if (lowestCpuCore > highestCpuCore) + { + return KernelResult.InvalidCombination; + } - uint highestThreadPrio = (cap >> 4) & 0x3f; - uint lowestThreadPrio = (cap >> 10) & 0x3f; + uint highestThreadPrio = (cap >> 4) & 0x3f; + uint lowestThreadPrio = (cap >> 10) & 0x3f; - if (lowestThreadPrio > highestThreadPrio) - { - return KernelResult.InvalidCombination; - } + if (lowestThreadPrio > highestThreadPrio) + { + return KernelResult.InvalidCombination; + } - if (highestCpuCore >= KScheduler.CpuCoresCount) - { - return KernelResult.InvalidCpuCore; - } + if (highestCpuCore >= KScheduler.CpuCoresCount) + { + return KernelResult.InvalidCpuCore; + } - AllowedCpuCoresMask = GetMaskFromMinMax(lowestCpuCore, highestCpuCore); - AllowedThreadPriosMask = GetMaskFromMinMax(lowestThreadPrio, highestThreadPrio); + AllowedCpuCoresMask = GetMaskFromMinMax(lowestCpuCore, highestCpuCore); + AllowedThreadPriosMask = GetMaskFromMinMax(lowestThreadPrio, highestThreadPrio); - break; - } + break; + } case CapabilityType.SyscallMask: - { - int slot = ((int)cap >> 29) & 7; + { + int slot = ((int)cap >> 29) & 7; - int svcSlotMask = 1 << slot; + int svcSlotMask = 1 << slot; - if ((mask1 & svcSlotMask) != 0) - { - return KernelResult.InvalidCombination; - } + if ((mask1 & svcSlotMask) != 0) + { + return KernelResult.InvalidCombination; + } - mask1 |= svcSlotMask; + mask1 |= svcSlotMask; - uint svcMask = (cap >> 5) & 0xffffff; + uint svcMask = (cap >> 5) & 0xffffff; - int baseSvc = slot * 24; + int baseSvc = slot * 24; - for (int index = 0; index < 24; index++) - { - if (((svcMask >> index) & 1) == 0) + for (int index = 0; index < 24; index++) { - continue; - } + if (((svcMask >> index) & 1) == 0) + { + continue; + } - int svcId = baseSvc + index; + int svcId = baseSvc + index; - if (svcId >= KernelConstants.SupervisorCallCount) - { - return KernelResult.MaximumExceeded; + if (svcId >= KernelConstants.SupervisorCallCount) + { + return KernelResult.MaximumExceeded; + } + + SvcAccessMask[svcId / 8] |= (byte)(1 << (svcId & 7)); } - SvcAccessMask[svcId / 8] |= (byte)(1 << (svcId & 7)); + break; } - break; - } - case CapabilityType.MapIoPage: - { - long address = ((long)cap << 4) & 0xffffff000; + { + long address = ((long)cap << 4) & 0xffffff000; - memoryManager.MapIoMemory(address, KPageTableBase.PageSize, KMemoryPermission.ReadAndWrite); + KPageTableBase.MapIoMemory(address, KPageTableBase.PageSize, KMemoryPermission.ReadAndWrite); - break; - } + break; + } case CapabilityType.MapRegion: - { - // TODO: Implement capabilities for MapRegion + { + // TODO: Implement capabilities for MapRegion - break; - } + break; + } case CapabilityType.InterruptPair: - { - // TODO: GIC distributor check. - int irq0 = ((int)cap >> 12) & 0x3ff; - int irq1 = ((int)cap >> 22) & 0x3ff; - - if (irq0 != 0x3ff) { - IrqAccessMask[irq0 / 8] |= (byte)(1 << (irq0 & 7)); - } + // TODO: GIC distributor check. + int irq0 = ((int)cap >> 12) & 0x3ff; + int irq1 = ((int)cap >> 22) & 0x3ff; - if (irq1 != 0x3ff) - { - IrqAccessMask[irq1 / 8] |= (byte)(1 << (irq1 & 7)); - } + if (irq0 != 0x3ff) + { + IrqAccessMask[irq0 / 8] |= (byte)(1 << (irq0 & 7)); + } - break; - } + if (irq1 != 0x3ff) + { + IrqAccessMask[irq1 / 8] |= (byte)(1 << (irq1 & 7)); + } - case CapabilityType.ProgramType: - { - uint applicationType = (cap >> 14); + break; + } - if (applicationType > 7) + case CapabilityType.ProgramType: { - return KernelResult.ReservedValue; - } + uint applicationType = (cap >> 14); + + if (applicationType > 7) + { + return KernelResult.ReservedValue; + } - ApplicationType = applicationType; + ApplicationType = applicationType; - break; - } + break; + } case CapabilityType.KernelVersion: - { - // Note: This check is bugged on kernel too, we are just replicating the bug here. - if ((KernelReleaseVersion >> 17) != 0 || cap < 0x80000) { - return KernelResult.ReservedValue; - } + // Note: This check is bugged on kernel too, we are just replicating the bug here. + if ((KernelReleaseVersion >> 17) != 0 || cap < 0x80000) + { + return KernelResult.ReservedValue; + } - KernelReleaseVersion = cap; + KernelReleaseVersion = cap; - break; - } + break; + } case CapabilityType.HandleTable: - { - uint handleTableSize = cap >> 26; - - if (handleTableSize > 0x3ff) { - return KernelResult.ReservedValue; - } + uint handleTableSize = cap >> 26; + + if (handleTableSize > 0x3ff) + { + return KernelResult.ReservedValue; + } - HandleTableSize = handleTableSize; + HandleTableSize = handleTableSize; - break; - } + break; + } case CapabilityType.DebugFlags: - { - uint debuggingFlags = cap >> 19; - - if (debuggingFlags > 3) { - return KernelResult.ReservedValue; - } + uint debuggingFlags = cap >> 19; - DebuggingFlags &= ~3u; - DebuggingFlags |= debuggingFlags; + if (debuggingFlags > 3) + { + return KernelResult.ReservedValue; + } - break; - } + DebuggingFlags &= ~3u; + DebuggingFlags |= debuggingFlags; - default: return KernelResult.InvalidCapability; + break; + } + default: + return KernelResult.InvalidCapability; } return Result.Success; @@ -325,4 +325,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Process return mask << (int)min; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageInfo.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageInfo.cs index f55e3c10..7fcd87b6 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageInfo.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageInfo.cs @@ -74,4 +74,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Process _isSlotFree[(address - PageVirtualAddress) / TlsEntrySize] = true; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageManager.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageManager.cs index 0fde495c..279fa13e 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageManager.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageManager.cs @@ -7,14 +7,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { private const int TlsEntrySize = 0x200; - private long _pagePosition; + private readonly long _pagePosition; private int _usedSlots; - private bool[] _slots; + private readonly bool[] _slots; public bool IsEmpty => _usedSlots == 0; - public bool IsFull => _usedSlots == _slots.Length; + public bool IsFull => _usedSlots == _slots.Length; public KTlsPageManager(long pagePosition) { @@ -58,4 +58,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Process _usedSlots--; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationFlags.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationFlags.cs index a79978ac..c68190d6 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationFlags.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationFlags.cs @@ -1,8 +1,10 @@ using System; +using System.Diagnostics.CodeAnalysis; namespace Ryujinx.HLE.HOS.Kernel.Process { [Flags] + [SuppressMessage("Design", "CA1069: Enums values should not be duplicated")] enum ProcessCreationFlags { Is64Bit = 1 << 0, @@ -36,6 +38,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process IsApplication | DeprecatedUseSecureMemory | PoolPartitionMask | - OptimizeMemoryAllocation + OptimizeMemoryAllocation, } } diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationInfo.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationInfo.cs index c05bb574..b5e5c29b 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationInfo.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessCreationInfo.cs @@ -34,4 +34,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Process SystemResourcePagesCount = systemResourcePagesCount; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessExecutionContext.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessExecutionContext.cs index 77fcdf33..b8118fbb 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessExecutionContext.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessExecutionContext.cs @@ -7,9 +7,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { public ulong Pc => 0UL; - public ulong CntfrqEl0 { get; set; } - public ulong CntpctEl0 => 0UL; - public long TpidrEl0 { get; set; } public long TpidrroEl0 { get; set; } @@ -43,4 +40,4 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessState.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessState.cs index 5ef3077e..e6c7e33e 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessState.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessState.cs @@ -2,13 +2,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Process { enum ProcessState : byte { - Created = 0, + Created = 0, CreatedAttached = 1, - Started = 2, - Crashed = 3, - Attached = 4, - Exiting = 5, - Exited = 6, - DebugSuspended = 7 + Started = 2, + Crashed = 3, + Attached = 4, + Exiting = 5, + Exited = 6, + DebugSuspended = 7, } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessTamperInfo.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessTamperInfo.cs index 4cf67172..8eafd96c 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessTamperInfo.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/ProcessTamperInfo.cs @@ -13,12 +13,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public ProcessTamperInfo(KProcess process, IEnumerable<string> buildIds, IEnumerable<ulong> codeAddresses, ulong heapAddress, ulong aliasAddress, ulong aslrAddress) { - Process = process; - BuildIds = buildIds; + Process = process; + BuildIds = buildIds; CodeAddresses = codeAddresses; - HeapAddress = heapAddress; - AliasAddress = aliasAddress; - AslrAddress = aslrAddress; + HeapAddress = heapAddress; + AliasAddress = aliasAddress; + AslrAddress = aslrAddress; } } -}
\ No newline at end of file +} |