[Ryujinx.Horizon] Address dotnet-format issues (#5381)

* dotnet format style --severity info

Some changes were manually reverted.

* dotnet format analyzers --serverity info

Some changes have been minimally adapted.

* Restore a few unused methods and variables

* Silence dotnet format IDE0060 warnings

* Silence dotnet format IDE0052 warnings

* Address dotnet format CA1822 warnings

* Address most dotnet format whitespace warnings

* Apply dotnet format whitespace formatting

A few of them have been manually reverted and the corresponding warning was silenced

* Revert formatting changes for while and for-loops

* Run dotnet format whitespace after rebase

* Run dotnet format style after rebase

* Run dotnet format after rebase and remove unused usings

- analyzers
- style
- whitespace

* Add comments to disabled warnings

* Remove a few unused parameters

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Address IDE0251 warnings

* Silence IDE0060 in .editorconfig

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* First dotnet format pass

* Add trailing commas and fix formatting issues

* Convert if-else chain to switch block

* Address review feedback
This commit is contained in:
TSRBerry 2023-07-01 12:42:10 +02:00 committed by GitHub
parent 801b71a128
commit 02b5c7ea89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
105 changed files with 617 additions and 637 deletions

View file

@ -1,5 +1,4 @@
using Ryujinx.Horizon.Bcat.Ipc; using Ryujinx.Horizon.Bcat.Types;
using Ryujinx.Horizon.Bcat.Types;
using Ryujinx.Horizon.Sdk.Sf.Hipc; using Ryujinx.Horizon.Sdk.Sf.Hipc;
using Ryujinx.Horizon.Sdk.Sm; using Ryujinx.Horizon.Sdk.Sm;
@ -29,10 +28,12 @@ namespace Ryujinx.Horizon.Bcat
_serverManager = new BcatServerManager(allocator, _sm, MaxPortsCount, _bcatManagerOptions, BcatTotalMaxSessionsCount); _serverManager = new BcatServerManager(allocator, _sm, MaxPortsCount, _bcatManagerOptions, BcatTotalMaxSessionsCount);
#pragma warning disable IDE0055 // Disable formatting
_serverManager.RegisterServer((int)BcatPortIndex.Admin, ServiceName.Encode("bcat:a"), BcatMaxSessionsCount); _serverManager.RegisterServer((int)BcatPortIndex.Admin, ServiceName.Encode("bcat:a"), BcatMaxSessionsCount);
_serverManager.RegisterServer((int)BcatPortIndex.Manager, ServiceName.Encode("bcat:m"), BcatMaxSessionsCount); _serverManager.RegisterServer((int)BcatPortIndex.Manager, ServiceName.Encode("bcat:m"), BcatMaxSessionsCount);
_serverManager.RegisterServer((int)BcatPortIndex.User, ServiceName.Encode("bcat:u"), BcatMaxSessionsCount); _serverManager.RegisterServer((int)BcatPortIndex.User, ServiceName.Encode("bcat:u"), BcatMaxSessionsCount);
_serverManager.RegisterServer((int)BcatPortIndex.System, ServiceName.Encode("bcat:s"), BcatMaxSessionsCount); _serverManager.RegisterServer((int)BcatPortIndex.System, ServiceName.Encode("bcat:s"), BcatMaxSessionsCount);
#pragma warning restore IDE0055
} }
public void ServiceRequests() public void ServiceRequests()

View file

@ -1,11 +1,4 @@
using Ryujinx.Horizon.LogManager; namespace Ryujinx.Horizon.Bcat
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ryujinx.Horizon.Bcat
{ {
internal class BcatMain : IService internal class BcatMain : IService
{ {

View file

@ -7,12 +7,7 @@ namespace Ryujinx.Horizon.Bcat.Ipc
{ {
partial class BcatService : IBcatService partial class BcatService : IBcatService
{ {
private readonly BcatServicePermissionLevel _permissionLevel; public BcatService(BcatServicePermissionLevel permissionLevel) { }
public BcatService(BcatServicePermissionLevel permissionLevel)
{
_permissionLevel = permissionLevel;
}
[CmifCommand(10100)] [CmifCommand(10100)]
public Result RequestSyncDeliveryCache(out IDeliveryCacheProgressService deliveryCacheProgressService) public Result RequestSyncDeliveryCache(out IDeliveryCacheProgressService deliveryCacheProgressService)

View file

@ -26,7 +26,7 @@ namespace Ryujinx.Horizon.Bcat.Ipc
} }
[CmifCommand(1)] [CmifCommand(1)]
public Result Read(out int entriesRead, [Buffer(Sdk.Sf.Hipc.HipcBufferFlags.Out | HipcBufferFlags.MapAlias)] Span<DeliveryCacheDirectoryEntry> entriesBuffer) public Result Read(out int entriesRead, [Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias)] Span<DeliveryCacheDirectoryEntry> entriesBuffer)
{ {
return _libHacService.Get.Read(out entriesRead, entriesBuffer).ToHorizonResult(); return _libHacService.Get.Read(out entriesRead, entriesBuffer).ToHorizonResult();
} }

View file

@ -39,7 +39,7 @@ namespace Ryujinx.Horizon.Bcat.Ipc
deliveryCacheProgressImpl = new DeliveryCacheProgressImpl deliveryCacheProgressImpl = new DeliveryCacheProgressImpl
{ {
State = DeliveryCacheProgressImpl.Status.Done, State = DeliveryCacheProgressImpl.Status.Done,
Result = 0 Result = 0,
}; };
Logger.Stub?.PrintStub(LogClass.ServiceBcat); Logger.Stub?.PrintStub(LogClass.ServiceBcat);

View file

@ -8,7 +8,7 @@ namespace Ryujinx.Horizon.Bcat.Ipc.Types
public enum Status public enum Status
{ {
// TODO: determine other values // TODO: determine other values
Done = 9 Done = 9,
} }
public Status State; public Status State;

View file

@ -5,6 +5,6 @@
Admin, Admin,
Manager, Manager,
User, User,
System System,
} }
} }

View file

@ -5,6 +5,6 @@
Admin = -1, Admin = -1,
User = 1, User = 1,
System = 2, System = 2,
Manager = 6 Manager = 6,
} }
} }

View file

@ -9,7 +9,7 @@ namespace Ryujinx.Horizon
{ {
private const ulong InvalidAddress = ulong.MaxValue; private const ulong InvalidAddress = ulong.MaxValue;
private struct Range : IComparable<Range> private readonly struct Range : IComparable<Range>
{ {
public ulong Offset { get; } public ulong Offset { get; }
public ulong Size { get; } public ulong Size { get; }

View file

@ -2,7 +2,7 @@ using LibHac;
namespace Ryujinx.Horizon namespace Ryujinx.Horizon
{ {
public struct HorizonOptions public readonly struct HorizonOptions
{ {
public bool IgnoreMissingServices { get; } public bool IgnoreMissingServices { get; }
public bool ThrowOnInvalidCommandIds { get; } public bool ThrowOnInvalidCommandIds { get; }

View file

@ -95,38 +95,18 @@ namespace Ryujinx.Horizon.LogManager.Ipc
LogDataChunkKey key = (LogDataChunkKey)type; LogDataChunkKey key = (LogDataChunkKey)type;
if (key == LogDataChunkKey.Start) switch (key)
{ {
case LogDataChunkKey.Start:
reader.Skip(size); reader.Skip(size);
continue; continue;
} case LogDataChunkKey.Stop:
else if (key == LogDataChunkKey.Stop)
{
break; break;
} case LogDataChunkKey.Line when !reader.TryRead(out _logPacket.Line):
else if (key == LogDataChunkKey.Line) case LogDataChunkKey.DropCount when !reader.TryRead(out _logPacket.DropCount):
{ case LogDataChunkKey.Time when !reader.TryRead(out _logPacket.Time):
if (!reader.TryRead<int>(out _logPacket.Line))
{
return true; return true;
} case LogDataChunkKey.Message:
}
else if (key == LogDataChunkKey.DropCount)
{
if (!reader.TryRead<long>(out _logPacket.DropCount))
{
return true;
}
}
else if (key == LogDataChunkKey.Time)
{
if (!reader.TryRead<long>(out _logPacket.Time))
{
return true;
}
}
else if (key == LogDataChunkKey.Message)
{ {
string text = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); string text = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
@ -143,26 +123,24 @@ namespace Ryujinx.Horizon.LogManager.Ipc
isTailPacket = true; isTailPacket = true;
} }
} }
break;
} }
else if (key == LogDataChunkKey.Filename) case LogDataChunkKey.Filename:
{
_logPacket.Filename = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); _logPacket.Filename = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
} break;
else if (key == LogDataChunkKey.Function) case LogDataChunkKey.Function:
{
_logPacket.Function = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); _logPacket.Function = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
} break;
else if (key == LogDataChunkKey.Module) case LogDataChunkKey.Module:
{
_logPacket.Module = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); _logPacket.Module = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
} break;
else if (key == LogDataChunkKey.Thread) case LogDataChunkKey.Thread:
{
_logPacket.Thread = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); _logPacket.Thread = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
} break;
else if (key == LogDataChunkKey.ProgramName) case LogDataChunkKey.ProgramName:
{
_logPacket.ProgramName = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); _logPacket.ProgramName = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
break;
} }
} }
@ -177,7 +155,7 @@ namespace Ryujinx.Horizon.LogManager.Ipc
do do
{ {
if (!reader.TryRead<byte>(out encoded)) if (!reader.TryRead(out encoded))
{ {
return false; return false;
} }

View file

@ -10,6 +10,7 @@ using Ryujinx.Horizon.Sdk.Sf;
using Ryujinx.Horizon.Sdk.Sf.Hipc; using Ryujinx.Horizon.Sdk.Sf.Hipc;
using System; using System;
using System.Text; using System.Text;
using ApplicationId = Ryujinx.Horizon.Sdk.Ncm.ApplicationId;
namespace Ryujinx.Horizon.Prepo.Ipc namespace Ryujinx.Horizon.Prepo.Ipc
{ {
@ -18,13 +19,13 @@ namespace Ryujinx.Horizon.Prepo.Ipc
enum PlayReportKind enum PlayReportKind
{ {
Normal, Normal,
System System,
} }
private readonly PrepoServicePermissionLevel _permissionLevel; private readonly PrepoServicePermissionLevel _permissionLevel;
private ulong _systemSessionId; private ulong _systemSessionId;
private bool _immediateTransmissionEnabled = false; private bool _immediateTransmissionEnabled;
private bool _userAgreementCheckEnabled = true; private bool _userAgreementCheckEnabled = true;
public PrepoService(PrepoServicePermissionLevel permissionLevel) public PrepoService(PrepoServicePermissionLevel permissionLevel)
@ -107,7 +108,7 @@ namespace Ryujinx.Horizon.Prepo.Ipc
} }
[CmifCommand(20100)] [CmifCommand(20100)]
public Result SaveSystemReport([Buffer(HipcBufferFlags.In | HipcBufferFlags.Pointer)] ReadOnlySpan<byte> gameRoomBuffer, Sdk.Ncm.ApplicationId applicationId, [Buffer(HipcBufferFlags.In | HipcBufferFlags.MapAlias)] ReadOnlySpan<byte> reportBuffer) public Result SaveSystemReport([Buffer(HipcBufferFlags.In | HipcBufferFlags.Pointer)] ReadOnlySpan<byte> gameRoomBuffer, ApplicationId applicationId, [Buffer(HipcBufferFlags.In | HipcBufferFlags.MapAlias)] ReadOnlySpan<byte> reportBuffer)
{ {
if ((_permissionLevel & PrepoServicePermissionLevel.System) != 0) if ((_permissionLevel & PrepoServicePermissionLevel.System) != 0)
{ {
@ -118,7 +119,7 @@ namespace Ryujinx.Horizon.Prepo.Ipc
} }
[CmifCommand(20101)] [CmifCommand(20101)]
public Result SaveSystemReportWithUser(Uid userId, [Buffer(HipcBufferFlags.In | HipcBufferFlags.Pointer)] ReadOnlySpan<byte> gameRoomBuffer, Sdk.Ncm.ApplicationId applicationId, [Buffer(HipcBufferFlags.In | HipcBufferFlags.MapAlias)] ReadOnlySpan<byte> reportBuffer) public Result SaveSystemReportWithUser(Uid userId, [Buffer(HipcBufferFlags.In | HipcBufferFlags.Pointer)] ReadOnlySpan<byte> gameRoomBuffer, ApplicationId applicationId, [Buffer(HipcBufferFlags.In | HipcBufferFlags.MapAlias)] ReadOnlySpan<byte> reportBuffer)
{ {
if ((_permissionLevel & PrepoServicePermissionLevel.System) != 0) if ((_permissionLevel & PrepoServicePermissionLevel.System) != 0)
{ {
@ -164,7 +165,7 @@ namespace Ryujinx.Horizon.Prepo.Ipc
return PrepoResult.PermissionDenied; return PrepoResult.PermissionDenied;
} }
private static Result ProcessPlayReport(PlayReportKind playReportKind, ReadOnlySpan<byte> gameRoomBuffer, ReadOnlySpan<byte> reportBuffer, ulong pid, Uid userId, bool withUserId = false, Sdk.Ncm.ApplicationId applicationId = default) private static Result ProcessPlayReport(PlayReportKind playReportKind, ReadOnlySpan<byte> gameRoomBuffer, ReadOnlySpan<byte> reportBuffer, ulong pid, Uid userId, bool withUserId = false, ApplicationId applicationId = default)
{ {
if (withUserId) if (withUserId)
{ {

View file

@ -28,12 +28,14 @@ namespace Ryujinx.Horizon.Prepo
_serverManager = new PrepoServerManager(allocator, _sm, MaxPortsCount, _prepoManagerOptions, PrepoTotalMaxSessionsCount); _serverManager = new PrepoServerManager(allocator, _sm, MaxPortsCount, _prepoManagerOptions, PrepoTotalMaxSessionsCount);
#pragma warning disable IDE0055 // Disable formatting
_serverManager.RegisterServer((int)PrepoPortIndex.Admin, ServiceName.Encode("prepo:a"), PrepoMaxSessionsCount); // 1.0.0-5.1.0 _serverManager.RegisterServer((int)PrepoPortIndex.Admin, ServiceName.Encode("prepo:a"), PrepoMaxSessionsCount); // 1.0.0-5.1.0
_serverManager.RegisterServer((int)PrepoPortIndex.Admin2, ServiceName.Encode("prepo:a2"), PrepoMaxSessionsCount); // 6.0.0+ _serverManager.RegisterServer((int)PrepoPortIndex.Admin2, ServiceName.Encode("prepo:a2"), PrepoMaxSessionsCount); // 6.0.0+
_serverManager.RegisterServer((int)PrepoPortIndex.Manager, ServiceName.Encode("prepo:m"), PrepoMaxSessionsCount); _serverManager.RegisterServer((int)PrepoPortIndex.Manager, ServiceName.Encode("prepo:m"), PrepoMaxSessionsCount);
_serverManager.RegisterServer((int)PrepoPortIndex.User, ServiceName.Encode("prepo:u"), PrepoMaxSessionsCount); _serverManager.RegisterServer((int)PrepoPortIndex.User, ServiceName.Encode("prepo:u"), PrepoMaxSessionsCount);
_serverManager.RegisterServer((int)PrepoPortIndex.System, ServiceName.Encode("prepo:s"), PrepoMaxSessionsCount); _serverManager.RegisterServer((int)PrepoPortIndex.System, ServiceName.Encode("prepo:s"), PrepoMaxSessionsCount);
_serverManager.RegisterServer((int)PrepoPortIndex.Debug, ServiceName.Encode("prepo:d"), PrepoMaxSessionsCount); // 1.0.0 _serverManager.RegisterServer((int)PrepoPortIndex.Debug, ServiceName.Encode("prepo:d"), PrepoMaxSessionsCount); // 1.0.0
#pragma warning restore IDE0055
} }
public void ServiceRequests() public void ServiceRequests()

View file

@ -6,10 +6,12 @@ namespace Ryujinx.Horizon.Prepo
{ {
private const int ModuleId = 129; private const int ModuleId = 129;
#pragma warning disable IDE0055 // Disable formatting
public static Result InvalidArgument => new(ModuleId, 1); public static Result InvalidArgument => new(ModuleId, 1);
public static Result InvalidState => new(ModuleId, 5); public static Result InvalidState => new(ModuleId, 5);
public static Result InvalidBufferSize => new(ModuleId, 9); public static Result InvalidBufferSize => new(ModuleId, 9);
public static Result PermissionDenied => new(ModuleId, 90); public static Result PermissionDenied => new(ModuleId, 90);
public static Result InvalidPid => new(ModuleId, 101); public static Result InvalidPid => new(ModuleId, 101);
#pragma warning restore IDE0055
} }
} }

View file

@ -17,6 +17,7 @@ namespace Ryujinx.Horizon.Prepo
{ {
return (PrepoPortIndex)portIndex switch return (PrepoPortIndex)portIndex switch
{ {
#pragma warning disable IDE0055 // Disable formatting
PrepoPortIndex.Admin => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Admin)), PrepoPortIndex.Admin => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Admin)),
PrepoPortIndex.Admin2 => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Admin)), PrepoPortIndex.Admin2 => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Admin)),
PrepoPortIndex.Manager => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Manager)), PrepoPortIndex.Manager => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Manager)),
@ -24,6 +25,7 @@ namespace Ryujinx.Horizon.Prepo
PrepoPortIndex.System => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.System)), PrepoPortIndex.System => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.System)),
PrepoPortIndex.Debug => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Debug)), PrepoPortIndex.Debug => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Debug)),
_ => throw new ArgumentOutOfRangeException(nameof(portIndex)), _ => throw new ArgumentOutOfRangeException(nameof(portIndex)),
#pragma warning restore IDE0055
}; };
} }
} }

View file

@ -7,6 +7,6 @@
Manager, Manager,
User, User,
System, System,
Debug Debug,
} }
} }

View file

@ -6,6 +6,6 @@
User = 1, User = 1,
System = 2, System = 2,
Manager = 6, Manager = 6,
Debug = unchecked((int)0x80000006) Debug = unchecked((int)0x80000006),
} }
} }

View file

@ -1,4 +1,5 @@
using Ryujinx.Horizon.Common; using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Ncm;
using Ryujinx.Horizon.Sdk.Sf; using Ryujinx.Horizon.Sdk.Sf;
namespace Ryujinx.Horizon.Sdk.Bcat namespace Ryujinx.Horizon.Sdk.Bcat
@ -7,6 +8,6 @@ namespace Ryujinx.Horizon.Sdk.Bcat
{ {
Result CreateBcatService(out IBcatService service, ulong pid); Result CreateBcatService(out IBcatService service, ulong pid);
Result CreateDeliveryCacheStorageService(out IDeliveryCacheStorageService service, ulong pid); Result CreateDeliveryCacheStorageService(out IDeliveryCacheStorageService service, ulong pid);
Result CreateDeliveryCacheStorageServiceWithApplicationId(out IDeliveryCacheStorageService service, Ncm.ApplicationId applicationId); Result CreateDeliveryCacheStorageServiceWithApplicationId(out IDeliveryCacheStorageService service, ApplicationId applicationId);
} }
} }

View file

@ -6,6 +6,6 @@ namespace Ryujinx.Horizon.Sdk.Diag
Info = 1, Info = 1,
Warn = 2, Warn = 2,
Error = 3, Error = 3,
Fatal = 4 Fatal = 4,
} }
} }

View file

@ -14,6 +14,6 @@ namespace Ryujinx.Horizon.Sdk.Lm
Time = 9, Time = 9,
ProgramName = 10, ProgramName = 10,
Count Count,
} }
} }

View file

@ -9,6 +9,6 @@ namespace Ryujinx.Horizon.Sdk.Lm
Uart = 1 << 1, Uart = 1 << 1,
UartIfSleep = 1 << 2, UartIfSleep = 1 << 2,
All = 0xffff All = 0xffff,
} }
} }

View file

@ -7,6 +7,6 @@ namespace Ryujinx.Horizon.Sdk.Lm
{ {
IsHead = 1 << 0, IsHead = 1 << 0,
IsTail = 1 << 1, IsTail = 1 << 1,
IsLittleEndian = 1 << 2 IsLittleEndian = 1 << 2,
} }
} }

View file

@ -3,6 +3,6 @@
enum EventClearMode enum EventClearMode
{ {
ManualClear, ManualClear,
AutoClear AutoClear,
} }
} }

View file

@ -63,10 +63,7 @@ namespace Ryujinx.Horizon.Sdk.OsTypes.Impl
} }
} }
if (result == null) result ??= WaitAnyHandleImpl(infinite, timeout);
{
result = WaitAnyHandleImpl(infinite, timeout);
}
UnlinkHoldersFromObjectsList(); UnlinkHoldersFromObjectsList();
_waitingThreadHandle = 0; _waitingThreadHandle = 0;
@ -98,7 +95,7 @@ namespace Ryujinx.Horizon.Sdk.OsTypes.Impl
} }
else else
{ {
index = WaitSynchronization(objectHandles.Slice(0, count), minTimeout); index = WaitSynchronization(objectHandles[..count], minTimeout);
DebugUtil.Assert(index != WaitInvalid); DebugUtil.Assert(index != WaitInvalid);
} }
@ -200,10 +197,8 @@ namespace Ryujinx.Horizon.Sdk.OsTypes.Impl
{ {
return WaitCancelled; return WaitCancelled;
} }
else
{
result.AbortOnFailure(); result.AbortOnFailure();
}
return index; return index;
} }

View file

@ -3,6 +3,6 @@ namespace Ryujinx.Horizon.Sdk.OsTypes
enum InitializationState : byte enum InitializationState : byte
{ {
NotInitialized, NotInitialized,
Initialized Initialized,
} }
} }

View file

@ -4,7 +4,7 @@ namespace Ryujinx.Horizon.Sdk.OsTypes
{ {
class MultiWaitHolderOfEvent : MultiWaitHolder class MultiWaitHolderOfEvent : MultiWaitHolder
{ {
private Event _event; private readonly Event _event;
private LinkedListNode<MultiWaitHolderBase> _node; private LinkedListNode<MultiWaitHolderBase> _node;
public override TriBool Signaled public override TriBool Signaled

View file

@ -2,7 +2,7 @@
{ {
class MultiWaitHolderOfHandle : MultiWaitHolder class MultiWaitHolderOfHandle : MultiWaitHolder
{ {
private int _handle; private readonly int _handle;
public override int Handle => _handle; public override int Handle => _handle;

View file

@ -15,7 +15,7 @@ namespace Ryujinx.Horizon.Sdk.OsTypes
InitiallySignaled = signaled, InitiallySignaled = signaled,
ClearMode = clearMode, ClearMode = clearMode,
State = InitializationState.Initialized, State = InitializationState.Initialized,
Lock = new object() Lock = new object(),
}; };
} }

View file

@ -6,6 +6,6 @@ namespace Ryujinx.Horizon.Sdk.OsTypes
{ {
private const int ModuleId = 3; private const int ModuleId = 3;
public static Result OutOfResource => new Result(ModuleId, 9); public static Result OutOfResource => new(ModuleId, 9);
} }
} }

View file

@ -6,12 +6,12 @@
{ {
NotInitialized, NotInitialized,
InitializedAsEvent, InitializedAsEvent,
InitializedAsInterProcess InitializedAsInterProcess,
} }
public InterProcessEventType InterProcessEvent; public InterProcessEventType InterProcessEvent;
public InitializationState State; public InitializationState State;
public bool NotInitialized => State == InitializationState.NotInitialized; public readonly bool NotInitialized => State == InitializationState.NotInitialized;
} }
} }

View file

@ -4,6 +4,6 @@
{ {
False, False,
True, True,
Undefined Undefined,
} }
} }

View file

@ -2,6 +2,7 @@
using Ryujinx.Horizon.Sdk.Account; using Ryujinx.Horizon.Sdk.Account;
using Ryujinx.Horizon.Sdk.Sf; using Ryujinx.Horizon.Sdk.Sf;
using System; using System;
using ApplicationId = Ryujinx.Horizon.Sdk.Ncm.ApplicationId;
namespace Ryujinx.Horizon.Sdk.Prepo namespace Ryujinx.Horizon.Sdk.Prepo
{ {
@ -12,8 +13,8 @@ namespace Ryujinx.Horizon.Sdk.Prepo
Result RequestImmediateTransmission(); Result RequestImmediateTransmission();
Result GetTransmissionStatus(out int status); Result GetTransmissionStatus(out int status);
Result GetSystemSessionId(out ulong systemSessionId); Result GetSystemSessionId(out ulong systemSessionId);
Result SaveSystemReport(ReadOnlySpan<byte> gameRoomBuffer, Ncm.ApplicationId applicationId, ReadOnlySpan<byte> reportBuffer); Result SaveSystemReport(ReadOnlySpan<byte> gameRoomBuffer, ApplicationId applicationId, ReadOnlySpan<byte> reportBuffer);
Result SaveSystemReportWithUser(Uid userId, ReadOnlySpan<byte> gameRoomBuffer, Ncm.ApplicationId applicationId, ReadOnlySpan<byte> reportBuffer); Result SaveSystemReportWithUser(Uid userId, ReadOnlySpan<byte> gameRoomBuffer, ApplicationId applicationId, ReadOnlySpan<byte> reportBuffer);
Result IsUserAgreementCheckEnabled(out bool enabled); Result IsUserAgreementCheckEnabled(out bool enabled);
Result SetUserAgreementCheckEnabled(bool enabled); Result SetUserAgreementCheckEnabled(bool enabled);
} }

View file

@ -14,11 +14,11 @@ namespace Ryujinx.Horizon.Sdk
using (var tlsRegion = HorizonStatic.AddressSpace.GetWritableRegion(tlsAddress, tlsSize)) using (var tlsRegion = HorizonStatic.AddressSpace.GetWritableRegion(tlsAddress, tlsSize))
{ {
CmifRequest request = CmifMessage.CreateRequest(tlsRegion.Memory.Span, new CmifRequestFormat() CmifRequest request = CmifMessage.CreateRequest(tlsRegion.Memory.Span, new CmifRequestFormat
{ {
DataSize = data.Length, DataSize = data.Length,
RequestId = requestId, RequestId = requestId,
SendPid = sendPid SendPid = sendPid,
}); });
data.CopyTo(request.Data); data.CopyTo(request.Data);

View file

@ -2,7 +2,7 @@
{ {
struct CmifDomainOutHeader struct CmifDomainOutHeader
{ {
#pragma warning disable CS0649 #pragma warning disable CS0649 // Field is never assigned to
public uint ObjectsCount; public uint ObjectsCount;
public uint Padding; public uint Padding;
public uint Padding2; public uint Padding2;

View file

@ -4,6 +4,6 @@
{ {
Invalid = 0, Invalid = 0,
SendMessage = 1, SendMessage = 1,
Close = 2 Close = 2,
} }
} }

View file

@ -32,7 +32,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
CmifRequest request = new() CmifRequest request = new()
{ {
Hipc = HipcMessage.WriteMessage(output, new HipcMetadata() Hipc = HipcMessage.WriteMessage(output, new HipcMetadata
{ {
Type = format.Context != 0 ? (int)CommandType.RequestWithContext : (int)CommandType.Request, Type = format.Context != 0 ? (int)CommandType.RequestWithContext : (int)CommandType.Request,
SendStaticsCount = format.InAutoBuffersCount + format.InPointersCount, SendStaticsCount = format.InAutoBuffersCount + format.InPointersCount,
@ -43,8 +43,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
ReceiveStaticsCount = outPointerSizeTableSize + format.OutFixedPointersCount, ReceiveStaticsCount = outPointerSizeTableSize + format.OutFixedPointersCount,
SendPid = format.SendPid, SendPid = format.SendPid,
CopyHandlesCount = format.HandlesCount, CopyHandlesCount = format.HandlesCount,
MoveHandlesCount = 0 MoveHandlesCount = 0,
}) }),
}; };
Span<uint> data = request.Hipc.DataWords; Span<uint> data = request.Hipc.DataWords;
@ -55,14 +55,14 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
int payloadSize = Unsafe.SizeOf<CmifInHeader>() + format.DataSize; int payloadSize = Unsafe.SizeOf<CmifInHeader>() + format.DataSize;
domainHeader = new CmifDomainInHeader() domainHeader = new CmifDomainInHeader
{ {
Type = CmifDomainRequestType.SendMessage, Type = CmifDomainRequestType.SendMessage,
ObjectsCount = (byte)format.ObjectsCount, ObjectsCount = (byte)format.ObjectsCount,
DataSize = (ushort)payloadSize, DataSize = (ushort)payloadSize,
ObjectId = format.ObjectId, ObjectId = format.ObjectId,
Padding = 0, Padding = 0,
Token = format.Context Token = format.Context,
}; };
data = data[(Unsafe.SizeOf<CmifDomainInHeader>() / sizeof(uint))..]; data = data[(Unsafe.SizeOf<CmifDomainInHeader>() / sizeof(uint))..];
@ -72,12 +72,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
ref CmifInHeader header = ref MemoryMarshal.Cast<uint, CmifInHeader>(data)[0]; ref CmifInHeader header = ref MemoryMarshal.Cast<uint, CmifInHeader>(data)[0];
header = new CmifInHeader() header = new CmifInHeader
{ {
Magic = CmifInHeaderMagic, Magic = CmifInHeaderMagic,
Version = format.Context != 0 ? 1u : 0u, Version = format.Context != 0 ? 1u : 0u,
CommandId = format.RequestId, CommandId = format.RequestId,
Token = format.ObjectId != 0 ? 0u : format.Context Token = format.ObjectId != 0 ? 0u : format.Context,
}; };
request.Data = MemoryMarshal.Cast<uint, byte>(data)[Unsafe.SizeOf<CmifInHeader>()..]; request.Data = MemoryMarshal.Cast<uint, byte>(data)[Unsafe.SizeOf<CmifInHeader>()..];
@ -121,12 +121,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
return header.Result; return header.Result;
} }
response = new CmifResponse() response = new CmifResponse
{ {
Data = data[Unsafe.SizeOf<CmifOutHeader>()..], Data = data[Unsafe.SizeOf<CmifOutHeader>()..],
Objects = objects, Objects = objects,
CopyHandles = responseMessage.Data.CopyHandles, CopyHandles = responseMessage.Data.CopyHandles,
MoveHandles = responseMessage.Data.MoveHandles MoveHandles = responseMessage.Data.MoveHandles,
}; };
return Result.Success; return Result.Success;

View file

@ -4,7 +4,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
{ {
struct CmifOutHeader struct CmifOutHeader
{ {
#pragma warning disable CS0649 #pragma warning disable CS0649 // Field is never assigned to
public uint Magic; public uint Magic;
public uint Version; public uint Version;
public Result Result; public Result Result;

View file

@ -2,7 +2,7 @@
{ {
struct CmifRequestFormat struct CmifRequestFormat
{ {
#pragma warning disable CS0649 #pragma warning disable CS0649 // Field is never assigned to
public int ObjectId; public int ObjectId;
public uint RequestId; public uint RequestId;
public uint Context; public uint Context;

View file

@ -9,6 +9,6 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
Request = 4, Request = 4,
Control = 5, Control = 5,
RequestWithContext = 6, RequestWithContext = 6,
ControlWithContext = 7 ControlWithContext = 7,
} }
} }

View file

@ -12,7 +12,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
return ProcessMessageImpl(ref context, ((DomainServiceObject)context.ServiceObject).GetServerDomain(), inRawData); return ProcessMessageImpl(ref context, ((DomainServiceObject)context.ServiceObject).GetServerDomain(), inRawData);
} }
private Result ProcessMessageImpl(ref ServiceDispatchContext context, ServerDomainBase domain, ReadOnlySpan<byte> inRawData) private static Result ProcessMessageImpl(ref ServiceDispatchContext context, ServerDomainBase domain, ReadOnlySpan<byte> inRawData)
{ {
if (inRawData.Length < Unsafe.SizeOf<CmifDomainInHeader>()) if (inRawData.Length < Unsafe.SizeOf<CmifDomainInHeader>())
{ {

View file

@ -19,7 +19,6 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
private int InObjectsCount => _inObjectIds.Length; private int InObjectsCount => _inObjectIds.Length;
private int OutObjectsCount => _implMetadata.OutObjectsCount; private int OutObjectsCount => _implMetadata.OutObjectsCount;
private int ImplOutHeadersSize => _implMetadata.OutHeadersSize;
private int ImplOutDataTotalSize => _implMetadata.OutDataSize + _implMetadata.OutHeadersSize; private int ImplOutDataTotalSize => _implMetadata.OutDataSize + _implMetadata.OutHeadersSize;
public DomainServiceObjectProcessor(ServerDomainBase domain, int[] inObjectIds) public DomainServiceObjectProcessor(ServerDomainBase domain, int[] inObjectIds)

View file

@ -17,7 +17,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
public int this[int index] public int this[int index]
{ {
get readonly get
{ {
return index switch return index switch
{ {
@ -29,22 +29,39 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
5 => _handle5, 5 => _handle5,
6 => _handle6, 6 => _handle6,
7 => _handle7, 7 => _handle7,
_ => throw new IndexOutOfRangeException() _ => throw new IndexOutOfRangeException(),
}; };
} }
set set
{ {
switch (index) switch (index)
{ {
case 0: _handle0 = value; break; case 0:
case 1: _handle1 = value; break; _handle0 = value;
case 2: _handle2 = value; break; break;
case 3: _handle3 = value; break; case 1:
case 4: _handle4 = value; break; _handle1 = value;
case 5: _handle5 = value; break; break;
case 6: _handle6 = value; break; case 2:
case 7: _handle7 = value; break; _handle2 = value;
default: throw new IndexOutOfRangeException(); break;
case 3:
_handle3 = value;
break;
case 4:
_handle4 = value;
break;
case 5:
_handle5 = value;
break;
case 6:
_handle6 = value;
break;
case 7:
_handle7 = value;
break;
default:
throw new IndexOutOfRangeException();
} }
} }
} }

View file

@ -1,6 +1,6 @@
namespace Ryujinx.Horizon.Sdk.Sf.Cmif namespace Ryujinx.Horizon.Sdk.Sf.Cmif
{ {
struct PointerAndSize readonly struct PointerAndSize
{ {
public static PointerAndSize Empty => new(0UL, 0UL); public static PointerAndSize Empty => new(0UL, 0UL);

View file

@ -2,7 +2,7 @@ using System;
namespace Ryujinx.Horizon.Sdk.Sf.Cmif namespace Ryujinx.Horizon.Sdk.Sf.Cmif
{ {
struct ScopedInlineContextChange : IDisposable readonly struct ScopedInlineContextChange : IDisposable
{ {
private readonly int _previousContext; private readonly int _previousContext;

View file

@ -211,7 +211,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
private readonly EntryManager _entryManager; private readonly EntryManager _entryManager;
private readonly object _entryOwnerLock; private readonly object _entryOwnerLock;
private readonly HashSet<Domain> _domains; private readonly HashSet<Domain> _domains;
private int _maxDomains; private readonly int _maxDomains;
public ServerDomainManager(int entryCount, int maxDomains) public ServerDomainManager(int entryCount, int maxDomains)
{ {

View file

@ -1,6 +1,6 @@
namespace Ryujinx.Horizon.Sdk.Sf.Cmif namespace Ryujinx.Horizon.Sdk.Sf.Cmif
{ {
struct ServerMessageRuntimeMetadata readonly struct ServerMessageRuntimeMetadata
{ {
public ushort InDataSize { get; } public ushort InDataSize { get; }
public ushort OutDataSize { get; } public ushort OutDataSize { get; }

View file

@ -1,6 +1,6 @@
namespace Ryujinx.Horizon.Sdk.Sf.Cmif namespace Ryujinx.Horizon.Sdk.Sf.Cmif
{ {
struct ServiceDispatchMeta readonly struct ServiceDispatchMeta
{ {
public ServiceDispatchTableBase DispatchTable { get; } public ServiceDispatchTableBase DispatchTable { get; }

View file

@ -14,7 +14,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
public abstract Result ProcessMessage(ref ServiceDispatchContext context, ReadOnlySpan<byte> inRawData); public abstract Result ProcessMessage(ref ServiceDispatchContext context, ReadOnlySpan<byte> inRawData);
protected Result ProcessMessageImpl(ref ServiceDispatchContext context, ReadOnlySpan<byte> inRawData, IReadOnlyDictionary<int, CommandHandler> entries, string objectName) protected static Result ProcessMessageImpl(ref ServiceDispatchContext context, ReadOnlySpan<byte> inRawData, IReadOnlyDictionary<int, CommandHandler> entries, string objectName)
{ {
if (inRawData.Length < Unsafe.SizeOf<CmifInHeader>()) if (inRawData.Length < Unsafe.SizeOf<CmifInHeader>())
{ {
@ -44,7 +44,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
// If ignore missing services is enabled, just pretend that everything is fine. // If ignore missing services is enabled, just pretend that everything is fine.
PrepareForStubReply(ref context, out Span<byte> outRawData); PrepareForStubReply(ref context, out Span<byte> outRawData);
CommandHandler.GetCmifOutHeaderPointer(ref outHeader, ref outRawData); CommandHandler.GetCmifOutHeaderPointer(ref outHeader, ref outRawData);
outHeader[0] = new CmifOutHeader() { Magic = CmifMessage.CmifOutHeaderMagic, Result = Result.Success }; outHeader[0] = new CmifOutHeader { Magic = CmifMessage.CmifOutHeaderMagic, Result = Result.Success };
Logger.Warning?.Print(LogClass.Service, $"Missing service {objectName} (command ID: {commandId}) ignored"); Logger.Warning?.Print(LogClass.Service, $"Missing service {objectName} (command ID: {commandId}) ignored");
@ -80,7 +80,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
return commandResult; return commandResult;
} }
outHeader[0] = new CmifOutHeader() { Magic = CmifMessage.CmifOutHeaderMagic, Result = commandResult }; outHeader[0] = new CmifOutHeader { Magic = CmifMessage.CmifOutHeaderMagic, Result = commandResult };
return Result.Success; return Result.Success;
} }

View file

@ -15,10 +15,10 @@ namespace Ryujinx.Horizon.Sdk.Sf
OutCopyHandle, OutCopyHandle,
OutMoveHandle, OutMoveHandle,
OutObject, OutObject,
ProcessId ProcessId,
} }
struct CommandArg readonly struct CommandArg
{ {
public CommandArgType Type { get; } public CommandArgType Type { get; }
public HipcBufferFlags BufferFlags { get; } public HipcBufferFlags BufferFlags { get; }

View file

@ -41,11 +41,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{ {
return HorizonStatic.Syscall.ReplyAndReceive(out _, handles, 0, -1L); return HorizonStatic.Syscall.ReplyAndReceive(out _, handles, 0, -1L);
} }
else
{
throw new NotImplementedException(); throw new NotImplementedException();
} }
}
public static Result Reply(int sessionHandle, ReadOnlySpan<byte> messageBuffer) public static Result Reply(int sessionHandle, ReadOnlySpan<byte> messageBuffer)
{ {
@ -64,11 +62,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{ {
return HorizonStatic.Syscall.ReplyAndReceive(out _, ReadOnlySpan<int>.Empty, sessionHandle, 0); 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) public static Result CreateSession(out int serverHandle, out int clientHandle)
{ {

View file

@ -10,55 +10,55 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
public CommandType Type public CommandType Type
{ {
get => (CommandType)_word0.Extract(0, 16); readonly get => (CommandType)_word0.Extract(0, 16);
set => _word0 = _word0.Insert(0, 16, (uint)value); set => _word0 = _word0.Insert(0, 16, (uint)value);
} }
public int SendStaticsCount public int SendStaticsCount
{ {
get => (int)_word0.Extract(16, 4); readonly get => (int)_word0.Extract(16, 4);
set => _word0 = _word0.Insert(16, 4, (uint)value); set => _word0 = _word0.Insert(16, 4, (uint)value);
} }
public int SendBuffersCount public int SendBuffersCount
{ {
get => (int)_word0.Extract(20, 4); readonly get => (int)_word0.Extract(20, 4);
set => _word0 = _word0.Insert(20, 4, (uint)value); set => _word0 = _word0.Insert(20, 4, (uint)value);
} }
public int ReceiveBuffersCount public int ReceiveBuffersCount
{ {
get => (int)_word0.Extract(24, 4); readonly get => (int)_word0.Extract(24, 4);
set => _word0 = _word0.Insert(24, 4, (uint)value); set => _word0 = _word0.Insert(24, 4, (uint)value);
} }
public int ExchangeBuffersCount public int ExchangeBuffersCount
{ {
get => (int)_word0.Extract(28, 4); readonly get => (int)_word0.Extract(28, 4);
set => _word0 = _word0.Insert(28, 4, (uint)value); set => _word0 = _word0.Insert(28, 4, (uint)value);
} }
public int DataWordsCount public int DataWordsCount
{ {
get => (int)_word1.Extract(0, 10); readonly get => (int)_word1.Extract(0, 10);
set => _word1 = _word1.Insert(0, 10, (uint)value); set => _word1 = _word1.Insert(0, 10, (uint)value);
} }
public int ReceiveStaticMode public int ReceiveStaticMode
{ {
get => (int)_word1.Extract(10, 4); readonly get => (int)_word1.Extract(10, 4);
set => _word1 = _word1.Insert(10, 4, (uint)value); set => _word1 = _word1.Insert(10, 4, (uint)value);
} }
public int ReceiveListOffset public int ReceiveListOffset
{ {
get => (int)_word1.Extract(20, 11); readonly get => (int)_word1.Extract(20, 11);
set => _word1 = _word1.Insert(20, 11, (uint)value); set => _word1 = _word1.Insert(20, 11, (uint)value);
} }
public bool HasSpecialHeader public bool HasSpecialHeader
{ {
get => _word1.Extract(31); readonly get => _word1.Extract(31);
set => _word1 = _word1.Insert(31, value); set => _word1 = _word1.Insert(31, value);
} }
} }

View file

@ -1,11 +1,11 @@
namespace Ryujinx.Horizon.Sdk.Sf.Hipc namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{ {
struct HipcBufferDescriptor readonly struct HipcBufferDescriptor
{ {
#pragma warning disable CS0649 #pragma warning disable CS0649 // Field is never assigned to
private uint _sizeLow; private readonly uint _sizeLow;
private uint _addressLow; private readonly uint _addressLow;
private uint _word2; private readonly uint _word2;
#pragma warning restore CS0649 #pragma warning restore CS0649
public ulong Address => _addressLow | (((ulong)_word2 << 4) & 0xf00000000UL) | (((ulong)_word2 << 34) & 0x7000000000UL); public ulong Address => _addressLow | (((ulong)_word2 << 4) & 0xf00000000UL) | (((ulong)_word2 << 34) & 0x7000000000UL);

View file

@ -12,6 +12,6 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
FixedSize = 1 << 4, FixedSize = 1 << 4,
AutoSelect = 1 << 5, AutoSelect = 1 << 5,
MapTransferAllowsNonSecure = 1 << 6, MapTransferAllowsNonSecure = 1 << 6,
MapTransferAllowsNonDevice = 1 << 7 MapTransferAllowsNonDevice = 1 << 7,
} }
} }

View file

@ -5,6 +5,6 @@
Normal = 0, Normal = 0,
NonSecure = 1, NonSecure = 1,
Invalid = 2, Invalid = 2,
NonDevice = 3 NonDevice = 3,
} }
} }

View file

@ -51,7 +51,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
} }
} }
Meta = new HipcMetadata() Meta = new HipcMetadata
{ {
Type = (int)header.Type, Type = (int)header.Type,
SendStaticsCount = header.SendStaticsCount, SendStaticsCount = header.SendStaticsCount,
@ -62,7 +62,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
ReceiveStaticsCount = receiveStaticsCount, ReceiveStaticsCount = receiveStaticsCount,
SendPid = specialHeader.SendPid, SendPid = specialHeader.SendPid,
CopyHandlesCount = specialHeader.CopyHandlesCount, CopyHandlesCount = specialHeader.CopyHandlesCount,
MoveHandlesCount = specialHeader.MoveHandlesCount MoveHandlesCount = specialHeader.MoveHandlesCount,
}; };
Data = CreateMessageData(Meta, data, initialLength); Data = CreateMessageData(Meta, data, initialLength);
@ -76,12 +76,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
int copyHandlesCount, int copyHandlesCount,
int moveHandlesCount) int moveHandlesCount)
{ {
return WriteMessage(destination, new HipcMetadata() return WriteMessage(destination, new HipcMetadata
{ {
SendStaticsCount = sendStaticCount, SendStaticsCount = sendStaticCount,
DataWordsCount = dataWordsCount, DataWordsCount = dataWordsCount,
CopyHandlesCount = copyHandlesCount, CopyHandlesCount = copyHandlesCount,
MoveHandlesCount = moveHandlesCount MoveHandlesCount = moveHandlesCount,
}); });
} }
@ -90,7 +90,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
int initialLength = destination.Length; int initialLength = destination.Length;
bool hasSpecialHeader = meta.SendPid || meta.CopyHandlesCount != 0 || meta.MoveHandlesCount != 0; 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, Type = (CommandType)meta.Type,
SendStaticsCount = meta.SendStaticsCount, SendStaticsCount = meta.SendStaticsCount,
@ -99,18 +99,18 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
ExchangeBuffersCount = meta.ExchangeBuffersCount, ExchangeBuffersCount = meta.ExchangeBuffersCount,
DataWordsCount = meta.DataWordsCount, DataWordsCount = meta.DataWordsCount,
ReceiveStaticMode = meta.ReceiveStaticsCount != 0 ? (meta.ReceiveStaticsCount != AutoReceiveStatic ? meta.ReceiveStaticsCount + 2 : 2) : 0, ReceiveStaticMode = meta.ReceiveStaticsCount != 0 ? (meta.ReceiveStaticsCount != AutoReceiveStatic ? meta.ReceiveStaticsCount + 2 : 2) : 0,
HasSpecialHeader = hasSpecialHeader HasSpecialHeader = hasSpecialHeader,
}; };
destination = destination[Unsafe.SizeOf<Header>()..]; destination = destination[Unsafe.SizeOf<Header>()..];
if (hasSpecialHeader) 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, CopyHandlesCount = meta.CopyHandlesCount,
MoveHandlesCount = meta.MoveHandlesCount MoveHandlesCount = meta.MoveHandlesCount,
}; };
destination = destination[Unsafe.SizeOf<SpecialHeader>()..]; destination = destination[Unsafe.SizeOf<SpecialHeader>()..];
@ -202,7 +202,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
receiveList = MemoryMarshal.Cast<byte, HipcReceiveListEntry>(data)[..receiveListSize]; receiveList = MemoryMarshal.Cast<byte, HipcReceiveListEntry>(data)[..receiveListSize];
} }
return new HipcMessageData() return new HipcMessageData
{ {
SendStatics = sendStatics, SendStatics = sendStatics,
SendBuffers = sendBuffers, SendBuffers = sendBuffers,
@ -211,7 +211,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
DataWords = dataWords, DataWords = dataWords,
ReceiveList = receiveList, ReceiveList = receiveList,
CopyHandles = copyHandles, CopyHandles = copyHandles,
MoveHandles = moveHandles MoveHandles = moveHandles,
}; };
} }
} }

View file

@ -1,9 +1,11 @@
namespace Ryujinx.Horizon.Sdk.Sf.Hipc namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{ {
struct HipcReceiveListEntry readonly struct HipcReceiveListEntry
{ {
private uint _addressLow; #pragma warning disable IDE0052 // Remove unread private member
private uint _word1; private readonly uint _addressLow;
private readonly uint _word1;
#pragma warning restore IDE0052
public HipcReceiveListEntry(ulong address, ulong size) public HipcReceiveListEntry(ulong address, ulong size)
{ {

View file

@ -6,6 +6,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{ {
public const int ModuleId = 11; public const int ModuleId = 11;
#pragma warning disable IDE0055 // Disable formatting
public static Result OutOfSessionMemory => new(ModuleId, 102); public static Result OutOfSessionMemory => new(ModuleId, 102);
public static Result OutOfSessions => new(ModuleId, 131); public static Result OutOfSessions => new(ModuleId, 131);
public static Result PointerBufferTooSmall => new(ModuleId, 141); 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 InvalidCmifRequest => new(ModuleId, 420);
public static Result TargetNotDomain => new(ModuleId, 491); public static Result TargetNotDomain => new(ModuleId, 491);
public static Result DomainObjectNotFound => new(ModuleId, 492); public static Result DomainObjectNotFound => new(ModuleId, 492);
#pragma warning restore IDE0055
} }
} }

View file

@ -1,6 +1,6 @@
namespace Ryujinx.Horizon.Sdk.Sf.Hipc namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{ {
struct HipcStaticDescriptor readonly struct HipcStaticDescriptor
{ {
private readonly ulong _data; private readonly ulong _data;

View file

@ -1,6 +1,6 @@
namespace Ryujinx.Horizon.Sdk.Sf.Hipc namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{ {
struct ManagerOptions readonly struct ManagerOptions
{ {
public static ManagerOptions Default => new(0, 0, 0, false); public static ManagerOptions Default => new(0, 0, 0, false);

View file

@ -4,6 +4,6 @@
{ {
Success, Success,
Closed, Closed,
NeedsRetry NeedsRetry,
} }
} }

View file

@ -14,8 +14,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
private readonly bool _canDeferInvokeRequest; private readonly bool _canDeferInvokeRequest;
private readonly int _maxSessions; private readonly int _maxSessions;
private ulong _pointerBuffersBaseAddress; private readonly ulong _pointerBuffersBaseAddress;
private ulong _savedMessagesBaseAddress; private readonly ulong _savedMessagesBaseAddress;
private readonly object _resourceLock; private readonly object _resourceLock;
private readonly ulong[] _sessionAllocationBitmap; private readonly ulong[] _sessionAllocationBitmap;
@ -35,7 +35,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
if (options.CanDeferInvokeRequest) 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>(); _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); return new PointerAndSize(baseAddress + (ulong)session.SessionIndex * size, size);
} }
@ -145,11 +145,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{ {
return GetObjectBySessionIndex(session, _pointerBuffersBaseAddress, (ulong)_pointerBufferSize); return GetObjectBySessionIndex(session, _pointerBuffersBaseAddress, (ulong)_pointerBufferSize);
} }
else
{
return PointerAndSize.Empty; return PointerAndSize.Empty;
} }
}
protected override PointerAndSize GetSessionSavedMessageBuffer(ServerSession session) protected override PointerAndSize GetSessionSavedMessageBuffer(ServerSession session)
{ {
@ -157,11 +155,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{ {
return GetObjectBySessionIndex(session, _savedMessagesBaseAddress, Api.TlsMessageBufferSize); return GetObjectBySessionIndex(session, _savedMessagesBaseAddress, Api.TlsMessageBufferSize);
} }
else
{
return PointerAndSize.Empty; return PointerAndSize.Empty;
} }
}
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {

View file

@ -10,7 +10,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{ {
private readonly SmApi _sm; private readonly SmApi _sm;
private bool _canDeferInvokeRequest; private readonly bool _canDeferInvokeRequest;
private readonly MultiWait _multiWait; private readonly MultiWait _multiWait;
private readonly MultiWait _waitList; private readonly MultiWait _waitList;
@ -27,7 +27,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
private enum UserDataTag private enum UserDataTag
{ {
Server = 1, Server = 1,
Session = 2 Session = 2,
} }
public ServerManagerBase(SmApi sm, ManagerOptions options) : base(options.MaxDomainObjects, options.MaxDomains) public ServerManagerBase(SmApi sm, ManagerOptions options) : base(options.MaxDomainObjects, options.MaxDomains)
@ -113,7 +113,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
public void ServiceRequests() public void ServiceRequests()
{ {
while (WaitAndProcessRequestsImpl()); while (WaitAndProcessRequestsImpl())
{
}
} }
public void WaitAndProcessRequests() public void WaitAndProcessRequests()
@ -211,7 +213,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{ {
UserDataTag.Server => ProcessForServer(holder), UserDataTag.Server => ProcessForServer(holder),
UserDataTag.Session => ProcessForSession(holder), UserDataTag.Session => ProcessForSession(holder),
_ => throw new NotImplementedException(((UserDataTag)holder.UserData).ToString()) _ => throw new NotImplementedException(((UserDataTag)holder.UserData).ToString()),
}; };
} }

View file

@ -161,8 +161,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
return Result.Success; return Result.Success;
} }
else
{
Result result = ProcessRequestImpl(session, message, message); Result result = ProcessRequestImpl(session, message, message);
if (result.IsSuccess) if (result.IsSuccess)
@ -175,16 +174,13 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{ {
return 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) private Result ProcessRequestImpl(ServerSession session, Span<byte> inMessage, Span<byte> outMessage)
{ {
@ -192,17 +188,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
using var _ = new ScopedInlineContextChange(GetInlineContext(commandType, inMessage)); using var _ = new ScopedInlineContextChange(GetInlineContext(commandType, inMessage));
switch (commandType) return commandType switch
{ {
case CommandType.Request: CommandType.Request or CommandType.RequestWithContext => DispatchRequest(session.ServiceObjectHolder, session, inMessage, outMessage),
case CommandType.RequestWithContext: CommandType.Control or CommandType.ControlWithContext => DispatchManagerRequest(session, inMessage, outMessage),
return DispatchRequest(session.ServiceObjectHolder, session, inMessage, outMessage); _ => HipcResult.UnknownCommandType,
case CommandType.Control: };
case CommandType.ControlWithContext:
return DispatchManagerRequest(session, inMessage, outMessage);
default:
return HipcResult.UnknownCommandType;
}
} }
private static int GetInlineContext(CommandType commandType, ReadOnlySpan<byte> inMessage) private static int GetInlineContext(CommandType commandType, ReadOnlySpan<byte> inMessage)
@ -221,12 +212,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
return 0; return 0;
} }
protected Result ReceiveRequest(ServerSession session, Span<byte> message) protected static Result ReceiveRequest(ServerSession session, Span<byte> message)
{ {
return ReceiveRequestImpl(session, 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; PointerAndSize pointerBuffer = session.PointerBuffer;
@ -234,19 +225,19 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{ {
if (pointerBuffer.Address != 0) if (pointerBuffer.Address != 0)
{ {
HipcMessageData messageData = HipcMessage.WriteMessage(message, new HipcMetadata() HipcMessageData messageData = HipcMessage.WriteMessage(message, new HipcMetadata
{ {
Type = (int)CommandType.Invalid, Type = (int)CommandType.Invalid,
ReceiveStaticsCount = HipcMessage.AutoReceiveStatic ReceiveStaticsCount = HipcMessage.AutoReceiveStatic,
}); });
messageData.ReceiveList[0] = new HipcReceiveListEntry(pointerBuffer.Address, pointerBuffer.Size); messageData.ReceiveList[0] = new HipcReceiveListEntry(pointerBuffer.Address, pointerBuffer.Size);
} }
else else
{ {
MemoryMarshal.Cast<byte, Header>(message)[0] = new Header() MemoryMarshal.Cast<byte, Header>(message)[0] = new Header
{ {
Type = CommandType.Invalid Type = CommandType.Invalid,
}; };
} }
@ -291,7 +282,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
return HipcResult.InvalidRequestSize; return HipcResult.InvalidRequestSize;
} }
var dispatchCtx = new ServiceDispatchContext() var dispatchCtx = new ServiceDispatchContext
{ {
ServiceObject = objectHolder.ServiceObject, ServiceObject = objectHolder.ServiceObject,
Manager = this, Manager = this,
@ -300,7 +291,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
PointerBuffer = session.PointerBuffer, PointerBuffer = session.PointerBuffer,
InMessageBuffer = inMessage, InMessageBuffer = inMessage,
OutMessageBuffer = outMessage, OutMessageBuffer = outMessage,
Request = request Request = request,
}; };
ReadOnlySpan<byte> inRawData = MemoryMarshal.Cast<uint, byte>(dispatchCtx.Request.Data.DataWords); ReadOnlySpan<byte> inRawData = MemoryMarshal.Cast<uint, byte>(dispatchCtx.Request.Data.DataWords);

View file

@ -8,19 +8,19 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
public bool SendPid public bool SendPid
{ {
get => _word.Extract(0); readonly get => _word.Extract(0);
set => _word = _word.Insert(0, value); set => _word = _word.Insert(0, value);
} }
public int CopyHandlesCount public int CopyHandlesCount
{ {
get => (int)_word.Extract(1, 4); readonly get => (int)_word.Extract(1, 4);
set => _word = _word.Insert(1, 4, (uint)value); set => _word = _word.Insert(1, 4, (uint)value);
} }
public int MoveHandlesCount public int MoveHandlesCount
{ {
get => (int)_word.Extract(5, 4); readonly get => (int)_word.Extract(5, 4);
set => _word = _word.Insert(5, 4, (uint)value); set => _word = _word.Insert(5, 4, (uint)value);
} }
} }

View file

@ -386,7 +386,9 @@ namespace Ryujinx.Horizon.Sdk.Sf
outRawData = MemoryMarshal.Cast<uint, byte>(response.DataWords); outRawData = MemoryMarshal.Cast<uint, byte>(response.DataWords);
} }
#pragma warning disable CA1822 // Mark member as static
public void SetOutObjects(ref ServiceDispatchContext context, HipcMessageData response, Span<IServiceObject> objects) public void SetOutObjects(ref ServiceDispatchContext context, HipcMessageData response, Span<IServiceObject> objects)
#pragma warning restore CA1822
{ {
if (objects.Length == 0) if (objects.Length == 0)
{ {
@ -411,7 +413,7 @@ namespace Ryujinx.Horizon.Sdk.Sf
} }
} }
private void SetOutObjectImpl(int index, HipcMessageData response, ServerSessionManager manager, ServiceObjectHolder obj) private static void SetOutObjectImpl(int index, HipcMessageData response, ServerSessionManager manager, ServiceObjectHolder obj)
{ {
if (obj == null) if (obj == null)
{ {

View file

@ -6,6 +6,7 @@ namespace Ryujinx.Horizon.Sdk.Sf
{ {
public const int ModuleId = 10; public const int ModuleId = 10;
#pragma warning disable IDE0055 // Disable formatting
public static Result NotSupported => new(ModuleId, 1); public static Result NotSupported => new(ModuleId, 1);
public static Result InvalidHeaderSize => new(ModuleId, 202); public static Result InvalidHeaderSize => new(ModuleId, 202);
public static Result InvalidInHeader => new(ModuleId, 211); public static Result InvalidInHeader => new(ModuleId, 211);
@ -23,5 +24,6 @@ namespace Ryujinx.Horizon.Sdk.Sf
public static bool RequestContextChanged(Result result) => result.InRange(800, 899); public static bool RequestContextChanged(Result result) => result.InRange(800, 899);
public static bool Invalidated(Result result) => result.InRange(801, 809); public static bool Invalidated(Result result) => result.InRange(801, 809);
public static bool RequestDeferred(Result result) => result.InRange(811, 819); public static bool RequestDeferred(Result result) => result.InRange(811, 819);
#pragma warning restore IDE0055
} }
} }

View file

@ -4,13 +4,13 @@ using System.Runtime.InteropServices;
namespace Ryujinx.Horizon.Sdk.Sm namespace Ryujinx.Horizon.Sdk.Sm
{ {
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ServiceName readonly struct ServiceName
{ {
public static ServiceName Invalid { get; } = new ServiceName(0); public static ServiceName Invalid { get; } = new(0);
public bool IsValid => Packed != 0; public bool IsValid => Packed != 0;
public int Length => sizeof(ulong); public const int Length = sizeof(ulong);
public ulong Packed { get; } public ulong Packed { get; }

View file

@ -4,7 +4,7 @@ using System;
namespace Ryujinx.Horizon namespace Ryujinx.Horizon
{ {
public struct ServiceEntry public readonly struct ServiceEntry
{ {
private readonly Action<ServiceTable> _entrypoint; private readonly Action<ServiceTable> _entrypoint;
private readonly ServiceTable _serviceTable; private readonly ServiceTable _serviceTable;

View file

@ -40,7 +40,7 @@ namespace Ryujinx.Horizon.Sm.Impl
return result == KernelResult.SessionCountExceeded ? SmResult.OutOfSessions : result; return result == KernelResult.SessionCountExceeded ? SmResult.OutOfSessions : result;
} }
private Result GetServiceImpl(out int handle, ref ServiceInfo serviceInfo) private static Result GetServiceImpl(out int handle, ref ServiceInfo serviceInfo)
{ {
return HorizonStatic.Syscall.ConnectToPort(out handle, serviceInfo.PortHandle); return HorizonStatic.Syscall.ConnectToPort(out handle, serviceInfo.PortHandle);
} }
@ -140,7 +140,7 @@ namespace Ryujinx.Horizon.Sm.Impl
int nameLength = 1; int nameLength = 1;
for (; nameLength < name.Length; nameLength++) for (; nameLength < ServiceName.Length; nameLength++)
{ {
if (name[nameLength] == 0) if (name[nameLength] == 0)
{ {
@ -148,7 +148,7 @@ namespace Ryujinx.Horizon.Sm.Impl
} }
} }
while (nameLength < name.Length) while (nameLength < ServiceName.Length)
{ {
if (name[nameLength++] != 0) if (name[nameLength++] != 0)
{ {

View file

@ -1,6 +1,4 @@
using Ryujinx.Horizon.Prepo; using Ryujinx.Horizon.Sdk.Sf.Hipc;
using Ryujinx.Horizon.Prepo.Types;
using Ryujinx.Horizon.Sdk.Sf.Hipc;
using Ryujinx.Horizon.Sdk.Sm; using Ryujinx.Horizon.Sdk.Sm;
using Ryujinx.Horizon.Sm.Impl; using Ryujinx.Horizon.Sm.Impl;
using Ryujinx.Horizon.Sm.Types; using Ryujinx.Horizon.Sm.Types;

View file

@ -6,6 +6,7 @@ namespace Ryujinx.Horizon.Sm
{ {
private const int ModuleId = 21; private const int ModuleId = 21;
#pragma warning disable IDE0055 // Disable formatting
public static Result OutOfProcess => new(ModuleId, 1); public static Result OutOfProcess => new(ModuleId, 1);
public static Result InvalidClient => new(ModuleId, 2); public static Result InvalidClient => new(ModuleId, 2);
public static Result OutOfSessions => new(ModuleId, 3); public static Result OutOfSessions => new(ModuleId, 3);
@ -15,5 +16,6 @@ namespace Ryujinx.Horizon.Sm
public static Result NotRegistered => new(ModuleId, 7); public static Result NotRegistered => new(ModuleId, 7);
public static Result NotAllowed => new(ModuleId, 8); public static Result NotAllowed => new(ModuleId, 8);
public static Result TooLargeAccessControl => new(ModuleId, 9); public static Result TooLargeAccessControl => new(ModuleId, 9);
#pragma warning restore IDE0055
} }
} }

View file

@ -3,6 +3,6 @@
enum SmPortIndex enum SmPortIndex
{ {
User, User,
Manager Manager,
} }
} }