diff options
Diffstat (limited to 'src/Ryujinx.Horizon/Sdk/Sf/Hipc')
20 files changed, 196 insertions, 207 deletions
diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Api.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Api.cs index 33c42825..530f81bd 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Api.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Api.cs @@ -41,10 +41,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { return HorizonStatic.Syscall.ReplyAndReceive(out _, handles, 0, -1L); } - else - { - throw new NotImplementedException(); - } + + throw new NotImplementedException(); } public static Result Reply(int sessionHandle, ReadOnlySpan<byte> messageBuffer) @@ -64,10 +62,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { return HorizonStatic.Syscall.ReplyAndReceive(out _, ReadOnlySpan<int>.Empty, sessionHandle, 0); } - else - { - throw new NotImplementedException(); - } + + throw new NotImplementedException(); } public static Result CreateSession(out int serverHandle, out int clientHandle) @@ -82,4 +78,4 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc return result; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Header.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Header.cs index cdb50b57..04abf693 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Header.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Header.cs @@ -10,55 +10,55 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc public CommandType Type { - get => (CommandType)_word0.Extract(0, 16); + readonly get => (CommandType)_word0.Extract(0, 16); set => _word0 = _word0.Insert(0, 16, (uint)value); } public int SendStaticsCount { - get => (int)_word0.Extract(16, 4); + readonly get => (int)_word0.Extract(16, 4); set => _word0 = _word0.Insert(16, 4, (uint)value); } public int SendBuffersCount { - get => (int)_word0.Extract(20, 4); + readonly get => (int)_word0.Extract(20, 4); set => _word0 = _word0.Insert(20, 4, (uint)value); } public int ReceiveBuffersCount { - get => (int)_word0.Extract(24, 4); + readonly get => (int)_word0.Extract(24, 4); set => _word0 = _word0.Insert(24, 4, (uint)value); } public int ExchangeBuffersCount { - get => (int)_word0.Extract(28, 4); + readonly get => (int)_word0.Extract(28, 4); set => _word0 = _word0.Insert(28, 4, (uint)value); } public int DataWordsCount { - get => (int)_word1.Extract(0, 10); + readonly get => (int)_word1.Extract(0, 10); set => _word1 = _word1.Insert(0, 10, (uint)value); } public int ReceiveStaticMode { - get => (int)_word1.Extract(10, 4); + readonly get => (int)_word1.Extract(10, 4); set => _word1 = _word1.Insert(10, 4, (uint)value); } public int ReceiveListOffset { - get => (int)_word1.Extract(20, 11); + readonly get => (int)_word1.Extract(20, 11); set => _word1 = _word1.Insert(20, 11, (uint)value); } public bool HasSpecialHeader { - get => _word1.Extract(31); + readonly get => _word1.Extract(31); set => _word1 = _word1.Insert(31, value); } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferDescriptor.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferDescriptor.cs index 7778d5bc..bef772e6 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferDescriptor.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferDescriptor.cs @@ -1,11 +1,11 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { - struct HipcBufferDescriptor + readonly struct HipcBufferDescriptor { -#pragma warning disable CS0649 - private uint _sizeLow; - private uint _addressLow; - private uint _word2; +#pragma warning disable CS0649 // Field is never assigned to + private readonly uint _sizeLow; + private readonly uint _addressLow; + private readonly uint _word2; #pragma warning restore CS0649 public ulong Address => _addressLow | (((ulong)_word2 << 4) & 0xf00000000UL) | (((ulong)_word2 << 34) & 0x7000000000UL); diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferFlags.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferFlags.cs index 269ab4fe..b1523d61 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferFlags.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferFlags.cs @@ -5,13 +5,13 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc [Flags] enum HipcBufferFlags : byte { - In = 1 << 0, - Out = 1 << 1, - MapAlias = 1 << 2, - Pointer = 1 << 3, - FixedSize = 1 << 4, - AutoSelect = 1 << 5, + In = 1 << 0, + Out = 1 << 1, + MapAlias = 1 << 2, + Pointer = 1 << 3, + FixedSize = 1 << 4, + AutoSelect = 1 << 5, MapTransferAllowsNonSecure = 1 << 6, - MapTransferAllowsNonDevice = 1 << 7 + MapTransferAllowsNonDevice = 1 << 7, } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferMode.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferMode.cs index b1e67253..bc2d5336 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferMode.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferMode.cs @@ -2,9 +2,9 @@ { enum HipcBufferMode { - Normal = 0, + Normal = 0, NonSecure = 1, - Invalid = 2, - NonDevice = 3 + Invalid = 2, + NonDevice = 3, } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcManager.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcManager.cs index 7541e294..f72d8e81 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcManager.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcManager.cs @@ -112,4 +112,4 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc return Result.Success; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessage.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessage.cs index 6500d6cf..82cf6e75 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessage.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessage.cs @@ -10,9 +10,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { public const int AutoReceiveStatic = byte.MaxValue; - public HipcMetadata Meta; + public HipcMetadata Meta; public HipcMessageData Data; - public ulong Pid; + public ulong Pid; public HipcMessage(Span<byte> data) { @@ -22,8 +22,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc data = data[Unsafe.SizeOf<Header>()..]; - int receiveStaticsCount = 0; - ulong pid = 0; + int receiveStaticsCount = 0; + ulong pid = 0; if (header.ReceiveStaticMode != 0) { @@ -42,75 +42,75 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc if (header.HasSpecialHeader) { specialHeader = MemoryMarshal.Cast<byte, SpecialHeader>(data)[0]; - data = data[Unsafe.SizeOf<SpecialHeader>()..]; + data = data[Unsafe.SizeOf<SpecialHeader>()..]; if (specialHeader.SendPid) { - pid = MemoryMarshal.Cast<byte, ulong>(data)[0]; + pid = MemoryMarshal.Cast<byte, ulong>(data)[0]; data = data[sizeof(ulong)..]; } } - Meta = new HipcMetadata() + Meta = new HipcMetadata { - Type = (int)header.Type, - SendStaticsCount = header.SendStaticsCount, - SendBuffersCount = header.SendBuffersCount, - ReceiveBuffersCount = header.ReceiveBuffersCount, + Type = (int)header.Type, + SendStaticsCount = header.SendStaticsCount, + SendBuffersCount = header.SendBuffersCount, + ReceiveBuffersCount = header.ReceiveBuffersCount, ExchangeBuffersCount = header.ExchangeBuffersCount, - DataWordsCount = header.DataWordsCount, - ReceiveStaticsCount = receiveStaticsCount, - SendPid = specialHeader.SendPid, - CopyHandlesCount = specialHeader.CopyHandlesCount, - MoveHandlesCount = specialHeader.MoveHandlesCount + DataWordsCount = header.DataWordsCount, + ReceiveStaticsCount = receiveStaticsCount, + SendPid = specialHeader.SendPid, + CopyHandlesCount = specialHeader.CopyHandlesCount, + MoveHandlesCount = specialHeader.MoveHandlesCount, }; Data = CreateMessageData(Meta, data, initialLength); - Pid = pid; + Pid = pid; } public static HipcMessageData WriteResponse( Span<byte> destination, - int sendStaticCount, - int dataWordsCount, - int copyHandlesCount, - int moveHandlesCount) + int sendStaticCount, + int dataWordsCount, + int copyHandlesCount, + int moveHandlesCount) { - return WriteMessage(destination, new HipcMetadata() + return WriteMessage(destination, new HipcMetadata { SendStaticsCount = sendStaticCount, - DataWordsCount = dataWordsCount, + DataWordsCount = dataWordsCount, CopyHandlesCount = copyHandlesCount, - MoveHandlesCount = moveHandlesCount + MoveHandlesCount = moveHandlesCount, }); } public static HipcMessageData WriteMessage(Span<byte> destination, HipcMetadata meta) { - int initialLength = destination.Length; + int initialLength = destination.Length; bool hasSpecialHeader = meta.SendPid || meta.CopyHandlesCount != 0 || meta.MoveHandlesCount != 0; - MemoryMarshal.Cast<byte, Header>(destination)[0] = new Header() + MemoryMarshal.Cast<byte, Header>(destination)[0] = new Header { - Type = (CommandType)meta.Type, - SendStaticsCount = meta.SendStaticsCount, - SendBuffersCount = meta.SendBuffersCount, - ReceiveBuffersCount = meta.ReceiveBuffersCount, + Type = (CommandType)meta.Type, + SendStaticsCount = meta.SendStaticsCount, + SendBuffersCount = meta.SendBuffersCount, + ReceiveBuffersCount = meta.ReceiveBuffersCount, ExchangeBuffersCount = meta.ExchangeBuffersCount, - DataWordsCount = meta.DataWordsCount, - ReceiveStaticMode = meta.ReceiveStaticsCount != 0 ? (meta.ReceiveStaticsCount != AutoReceiveStatic ? meta.ReceiveStaticsCount + 2 : 2) : 0, - HasSpecialHeader = hasSpecialHeader + DataWordsCount = meta.DataWordsCount, + ReceiveStaticMode = meta.ReceiveStaticsCount != 0 ? (meta.ReceiveStaticsCount != AutoReceiveStatic ? meta.ReceiveStaticsCount + 2 : 2) : 0, + HasSpecialHeader = hasSpecialHeader, }; destination = destination[Unsafe.SizeOf<Header>()..]; if (hasSpecialHeader) { - MemoryMarshal.Cast<byte, SpecialHeader>(destination)[0] = new SpecialHeader() + MemoryMarshal.Cast<byte, SpecialHeader>(destination)[0] = new SpecialHeader { - SendPid = meta.SendPid, + SendPid = meta.SendPid, CopyHandlesCount = meta.CopyHandlesCount, - MoveHandlesCount = meta.MoveHandlesCount + MoveHandlesCount = meta.MoveHandlesCount, }; destination = destination[Unsafe.SizeOf<SpecialHeader>()..]; @@ -184,9 +184,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc if (meta.DataWordsCount != 0) { - int dataOffset = initialLength - data.Length; + int dataOffset = initialLength - data.Length; int dataOffsetAligned = BitUtils.AlignUp(dataOffset, 0x10); - int padding = (dataOffsetAligned - dataOffset) / sizeof(uint); + int padding = (dataOffsetAligned - dataOffset) / sizeof(uint); dataWords = MemoryMarshal.Cast<byte, uint>(data)[padding..meta.DataWordsCount]; @@ -202,16 +202,16 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc receiveList = MemoryMarshal.Cast<byte, HipcReceiveListEntry>(data)[..receiveListSize]; } - return new HipcMessageData() + return new HipcMessageData { - SendStatics = sendStatics, - SendBuffers = sendBuffers, - ReceiveBuffers = receiveBuffers, + SendStatics = sendStatics, + SendBuffers = sendBuffers, + ReceiveBuffers = receiveBuffers, ExchangeBuffers = exchangeBuffers, - DataWords = dataWords, - ReceiveList = receiveList, - CopyHandles = copyHandles, - MoveHandles = moveHandles + DataWords = dataWords, + ReceiveList = receiveList, + CopyHandles = copyHandles, + MoveHandles = moveHandles, }; } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessageData.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessageData.cs index 154b8f07..c83c422c 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessageData.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessageData.cs @@ -8,9 +8,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc public Span<HipcBufferDescriptor> SendBuffers; public Span<HipcBufferDescriptor> ReceiveBuffers; public Span<HipcBufferDescriptor> ExchangeBuffers; - public Span<uint> DataWords; + public Span<uint> DataWords; public Span<HipcReceiveListEntry> ReceiveList; - public Span<int> CopyHandles; - public Span<int> MoveHandles; + public Span<int> CopyHandles; + public Span<int> MoveHandles; } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMetadata.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMetadata.cs index 10abc400..fe13137a 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMetadata.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMetadata.cs @@ -2,15 +2,15 @@ { struct HipcMetadata { - public int Type; - public int SendStaticsCount; - public int SendBuffersCount; - public int ReceiveBuffersCount; - public int ExchangeBuffersCount; - public int DataWordsCount; - public int ReceiveStaticsCount; + public int Type; + public int SendStaticsCount; + public int SendBuffersCount; + public int ReceiveBuffersCount; + public int ExchangeBuffersCount; + public int DataWordsCount; + public int ReceiveStaticsCount; public bool SendPid; - public int CopyHandlesCount; - public int MoveHandlesCount; + public int CopyHandlesCount; + public int MoveHandlesCount; } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcReceiveListEntry.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcReceiveListEntry.cs index 56cf16fb..955428b8 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcReceiveListEntry.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcReceiveListEntry.cs @@ -1,14 +1,16 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { - struct HipcReceiveListEntry + readonly struct HipcReceiveListEntry { - private uint _addressLow; - private uint _word1; +#pragma warning disable IDE0052 // Remove unread private member + private readonly uint _addressLow; + private readonly uint _word1; +#pragma warning restore IDE0052 public HipcReceiveListEntry(ulong address, ulong size) { _addressLow = (uint)address; - _word1 = (ushort)(address >> 32) | (uint)(size << 16); + _word1 = (ushort)(address >> 32) | (uint)(size << 16); } } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcResult.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcResult.cs index 3b483be8..faf5dc41 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcResult.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcResult.cs @@ -6,6 +6,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { public const int ModuleId = 11; +#pragma warning disable IDE0055 // Disable formatting public static Result OutOfSessionMemory => new(ModuleId, 102); public static Result OutOfSessions => new(ModuleId, 131); public static Result PointerBufferTooSmall => new(ModuleId, 141); @@ -15,5 +16,6 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc public static Result InvalidCmifRequest => new(ModuleId, 420); public static Result TargetNotDomain => new(ModuleId, 491); public static Result DomainObjectNotFound => new(ModuleId, 492); + #pragma warning restore IDE0055 } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcStaticDescriptor.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcStaticDescriptor.cs index 103820a6..43e7afb9 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcStaticDescriptor.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcStaticDescriptor.cs @@ -1,12 +1,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { - struct HipcStaticDescriptor + readonly struct HipcStaticDescriptor { private readonly ulong _data; - public ulong Address => ((((_data >> 2) & 0x70) | ((_data >> 12) & 0xf)) << 32) | (_data >> 32); - public ushort Size => (ushort)(_data >> 16); - public int ReceiveIndex => (int)(_data & 0xf); + public ulong Address => ((((_data >> 2) & 0x70) | ((_data >> 12) & 0xf)) << 32) | (_data >> 32); + public ushort Size => (ushort)(_data >> 16); + public int ReceiveIndex => (int)(_data & 0xf); public HipcStaticDescriptor(ulong address, ushort size, int receiveIndex) { @@ -19,4 +19,4 @@ _data = data; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ManagerOptions.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ManagerOptions.cs index b99d63c5..e747490e 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ManagerOptions.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ManagerOptions.cs @@ -1,20 +1,20 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { - struct ManagerOptions + readonly struct ManagerOptions { public static ManagerOptions Default => new(0, 0, 0, false); - public int PointerBufferSize { get; } - public int MaxDomains { get; } - public int MaxDomainObjects { get; } + public int PointerBufferSize { get; } + public int MaxDomains { get; } + public int MaxDomainObjects { get; } public bool CanDeferInvokeRequest { get; } public ManagerOptions(int pointerBufferSize, int maxDomains, int maxDomainObjects, bool canDeferInvokeRequest) { - PointerBufferSize = pointerBufferSize; - MaxDomains = maxDomains; - MaxDomainObjects = maxDomainObjects; + PointerBufferSize = pointerBufferSize; + MaxDomains = maxDomains; + MaxDomainObjects = maxDomainObjects; CanDeferInvokeRequest = canDeferInvokeRequest; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ReceiveResult.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ReceiveResult.cs index 7c380a01..efe99f3f 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ReceiveResult.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ReceiveResult.cs @@ -4,6 +4,6 @@ { Success, Closed, - NeedsRetry + NeedsRetry, } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Server.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Server.cs index bbbab898..923f2d52 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Server.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/Server.cs @@ -6,22 +6,22 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { class Server : MultiWaitHolderOfHandle { - public int PortIndex { get; } - public int PortHandle { get; } - public ServiceName Name { get; } - public bool Managed { get; } + public int PortIndex { get; } + public int PortHandle { get; } + public ServiceName Name { get; } + public bool Managed { get; } public ServiceObjectHolder StaticObject { get; } public Server( - int portIndex, - int portHandle, - ServiceName name, - bool managed, + int portIndex, + int portHandle, + ServiceName name, + bool managed, ServiceObjectHolder staticHoder) : base(portHandle) { PortHandle = portHandle; - Name = name; - Managed = managed; + Name = name; + Managed = managed; if (staticHoder != null) { diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs index 2ca9ceea..9ac2a337 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs @@ -14,8 +14,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc private readonly bool _canDeferInvokeRequest; private readonly int _maxSessions; - private ulong _pointerBuffersBaseAddress; - private ulong _savedMessagesBaseAddress; + private readonly ulong _pointerBuffersBaseAddress; + private readonly ulong _savedMessagesBaseAddress; private readonly object _resourceLock; private readonly ulong[] _sessionAllocationBitmap; @@ -35,7 +35,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc if (options.CanDeferInvokeRequest) { - _savedMessagesBaseAddress = allocator.Allocate((ulong)maxSessions * (ulong)Api.TlsMessageBufferSize); + _savedMessagesBaseAddress = allocator.Allocate((ulong)maxSessions * Api.TlsMessageBufferSize); } } @@ -45,7 +45,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc _servers = new HashSet<Server>(); } - private PointerAndSize GetObjectBySessionIndex(ServerSession session, ulong baseAddress, ulong size) + private static PointerAndSize GetObjectBySessionIndex(ServerSession session, ulong baseAddress, ulong size) { return new PointerAndSize(baseAddress + (ulong)session.SessionIndex * size, size); } @@ -61,7 +61,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc return null; } - for (int i = 0; i <_sessionAllocationBitmap.Length; i++) + for (int i = 0; i < _sessionAllocationBitmap.Length; i++) { ref ulong mask = ref _sessionAllocationBitmap[i]; @@ -145,10 +145,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { return GetObjectBySessionIndex(session, _pointerBuffersBaseAddress, (ulong)_pointerBufferSize); } - else - { - return PointerAndSize.Empty; - } + + return PointerAndSize.Empty; } protected override PointerAndSize GetSessionSavedMessageBuffer(ServerSession session) @@ -157,10 +155,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { return GetObjectBySessionIndex(session, _savedMessagesBaseAddress, Api.TlsMessageBufferSize); } - else - { - return PointerAndSize.Empty; - } + + return PointerAndSize.Empty; } protected virtual void Dispose(bool disposing) diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs index c36cdda2..76407840 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs @@ -10,7 +10,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { private readonly SmApi _sm; - private bool _canDeferInvokeRequest; + private readonly bool _canDeferInvokeRequest; private readonly MultiWait _multiWait; private readonly MultiWait _waitList; @@ -26,8 +26,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc private enum UserDataTag { - Server = 1, - Session = 2 + Server = 1, + Session = 2, } public ServerManagerBase(SmApi sm, ManagerOptions options) : base(options.MaxDomainObjects, options.MaxDomains) @@ -36,13 +36,13 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc _canDeferInvokeRequest = options.CanDeferInvokeRequest; _multiWait = new MultiWait(); - _waitList = new MultiWait(); + _waitList = new MultiWait(); _multiWaitSelectionLock = new object(); - _waitListLock = new object(); + _waitListLock = new object(); _requestStopEvent = new Event(EventClearMode.ManualClear); - _notifyEvent = new Event(EventClearMode.ManualClear); + _notifyEvent = new Event(EventClearMode.ManualClear); _requestStopEventHolder = new MultiWaitHolderOfEvent(_requestStopEvent); _multiWait.LinkMultiWaitHolder(_requestStopEventHolder); @@ -113,7 +113,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc public void ServiceRequests() { - while (WaitAndProcessRequestsImpl()); + while (WaitAndProcessRequestsImpl()) + { + } } public void WaitAndProcessRequests() @@ -183,7 +185,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc protected override void RegisterSessionToWaitList(ServerSession session) { session.HasReceived = false; - session.UserData = UserDataTag.Session; + session.UserData = UserDataTag.Session; RegisterToWaitList(session); } @@ -209,9 +211,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { return (UserDataTag)holder.UserData switch { - UserDataTag.Server => ProcessForServer(holder), + UserDataTag.Server => ProcessForServer(holder), UserDataTag.Session => ProcessForSession(holder), - _ => throw new NotImplementedException(((UserDataTag)holder.UserData).ToString()) + _ => throw new NotImplementedException(((UserDataTag)holder.UserData).ToString()), }; } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSession.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSession.cs index a1730082..eb98fefd 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSession.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSession.cs @@ -6,18 +6,18 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc class ServerSession : MultiWaitHolderOfHandle { public ServiceObjectHolder ServiceObjectHolder { get; set; } - public PointerAndSize PointerBuffer { get; set; } - public PointerAndSize SavedMessage { get; set; } - public int SessionIndex { get; } - public int SessionHandle { get; } - public bool IsClosed { get; set; } - public bool HasReceived { get; set; } + public PointerAndSize PointerBuffer { get; set; } + public PointerAndSize SavedMessage { get; set; } + public int SessionIndex { get; } + public int SessionHandle { get; } + public bool IsClosed { get; set; } + public bool HasReceived { get; set; } public ServerSession(int index, int handle, ServiceObjectHolder obj) : base(handle) { ServiceObjectHolder = obj; - SessionIndex = index; - SessionHandle = handle; + SessionIndex = index; + SessionHandle = handle; } } } diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSessionManager.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSessionManager.cs index 6d395081..bd5a4844 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSessionManager.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSessionManager.cs @@ -75,7 +75,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc } session.PointerBuffer = GetSessionPointerBuffer(session); - session.SavedMessage = GetSessionSavedMessageBuffer(session); + session.SavedMessage = GetSessionSavedMessageBuffer(session); RegisterSessionToWaitList(session); @@ -110,10 +110,10 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc } protected virtual Server AllocateServer( - int portIndex, - int portHandle, - ServiceName name, - bool managed, + int portIndex, + int portHandle, + ServiceName name, + bool managed, ServiceObjectHolder staticHoder) { throw new NotSupportedException(); @@ -161,29 +161,25 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc return Result.Success; } - else + + Result result = ProcessRequestImpl(session, message, message); + + if (result.IsSuccess) { - Result result = ProcessRequestImpl(session, message, message); + RegisterSessionToWaitList(session); - if (result.IsSuccess) - { - RegisterSessionToWaitList(session); + return Result.Success; + } + else if (SfResult.RequestContextChanged(result)) + { + return result; + } - return Result.Success; - } - else if (SfResult.RequestContextChanged(result)) - { - return result; - } - else - { - Logger.Warning?.Print(LogClass.KernelIpc, $"Request processing returned error {result}"); + Logger.Warning?.Print(LogClass.KernelIpc, $"Request processing returned error {result}"); - CloseSessionImpl(session); + CloseSessionImpl(session); - return Result.Success; - } - } + return Result.Success; } private Result ProcessRequestImpl(ServerSession session, Span<byte> inMessage, Span<byte> outMessage) @@ -192,18 +188,13 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc using var _ = new ScopedInlineContextChange(GetInlineContext(commandType, inMessage)); - switch (commandType) + return commandType switch { - case CommandType.Request: - case CommandType.RequestWithContext: - return DispatchRequest(session.ServiceObjectHolder, session, inMessage, outMessage); - case CommandType.Control: - case CommandType.ControlWithContext: - return DispatchManagerRequest(session, inMessage, outMessage); - default: - return HipcResult.UnknownCommandType; + CommandType.Request or CommandType.RequestWithContext => DispatchRequest(session.ServiceObjectHolder, session, inMessage, outMessage), + CommandType.Control or CommandType.ControlWithContext => DispatchManagerRequest(session, inMessage, outMessage), + _ => HipcResult.UnknownCommandType, + }; } - } private static int GetInlineContext(CommandType commandType, ReadOnlySpan<byte> inMessage) { @@ -221,12 +212,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc return 0; } - protected Result ReceiveRequest(ServerSession session, Span<byte> message) + protected static Result ReceiveRequest(ServerSession session, Span<byte> message) { return ReceiveRequestImpl(session, message); } - private Result ReceiveRequestImpl(ServerSession session, Span<byte> message) + private static Result ReceiveRequestImpl(ServerSession session, Span<byte> message) { PointerAndSize pointerBuffer = session.PointerBuffer; @@ -234,19 +225,19 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc { if (pointerBuffer.Address != 0) { - HipcMessageData messageData = HipcMessage.WriteMessage(message, new HipcMetadata() + HipcMessageData messageData = HipcMessage.WriteMessage(message, new HipcMetadata { - Type = (int)CommandType.Invalid, - ReceiveStaticsCount = HipcMessage.AutoReceiveStatic + Type = (int)CommandType.Invalid, + ReceiveStaticsCount = HipcMessage.AutoReceiveStatic, }); messageData.ReceiveList[0] = new HipcReceiveListEntry(pointerBuffer.Address, pointerBuffer.Size); } else { - MemoryMarshal.Cast<byte, Header>(message)[0] = new Header() + MemoryMarshal.Cast<byte, Header>(message)[0] = new Header { - Type = CommandType.Invalid + Type = CommandType.Invalid, }; } @@ -276,9 +267,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc protected virtual Result DispatchRequest( ServiceObjectHolder objectHolder, - ServerSession session, - Span<byte> inMessage, - Span<byte> outMessage) + ServerSession session, + Span<byte> inMessage, + Span<byte> outMessage) { HipcMessage request; @@ -291,16 +282,16 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc return HipcResult.InvalidRequestSize; } - var dispatchCtx = new ServiceDispatchContext() + var dispatchCtx = new ServiceDispatchContext { - ServiceObject = objectHolder.ServiceObject, - Manager = this, - Session = session, - HandlesToClose = new HandlesToClose(), - PointerBuffer = session.PointerBuffer, - InMessageBuffer = inMessage, + ServiceObject = objectHolder.ServiceObject, + Manager = this, + Session = session, + HandlesToClose = new HandlesToClose(), + PointerBuffer = session.PointerBuffer, + InMessageBuffer = inMessage, OutMessageBuffer = outMessage, - Request = request + Request = request, }; ReadOnlySpan<byte> inRawData = MemoryMarshal.Cast<uint, byte>(dispatchCtx.Request.Data.DataWords); @@ -337,4 +328,4 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc return this; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/SpecialHeader.cs b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/SpecialHeader.cs index 8b747626..b6304b7b 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Hipc/SpecialHeader.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Hipc/SpecialHeader.cs @@ -8,19 +8,19 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc public bool SendPid { - get => _word.Extract(0); + readonly get => _word.Extract(0); set => _word = _word.Insert(0, value); } public int CopyHandlesCount { - get => (int)_word.Extract(1, 4); + readonly get => (int)_word.Extract(1, 4); set => _word = _word.Insert(1, 4, (uint)value); } public int MoveHandlesCount { - get => (int)_word.Extract(5, 4); + readonly get => (int)_word.Extract(5, 4); set => _word = _word.Insert(5, 4, (uint)value); } } |
