[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.Sm;
@ -8,7 +7,7 @@ namespace Ryujinx.Horizon.Bcat
internal class BcatIpcServer
{
private const int BcatMaxSessionsCount = 8;
private const int BcatTotalMaxSessionsCount = BcatMaxSessionsCount * 4;
private const int BcatTotalMaxSessionsCount = BcatMaxSessionsCount * 4;
private const int PointerBufferSize = 0x400;
private const int MaxDomains = 64;
@ -29,10 +28,12 @@ namespace Ryujinx.Horizon.Bcat
_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.Manager, ServiceName.Encode("bcat:m"), BcatMaxSessionsCount);
_serverManager.RegisterServer((int)BcatPortIndex.User, ServiceName.Encode("bcat:u"), BcatMaxSessionsCount);
_serverManager.RegisterServer((int)BcatPortIndex.System, ServiceName.Encode("bcat:s"), BcatMaxSessionsCount);
#pragma warning restore IDE0055
}
public void ServiceRequests()

View File

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

View File

@ -17,12 +17,12 @@ namespace Ryujinx.Horizon.Bcat
{
return (BcatPortIndex)portIndex switch
{
BcatPortIndex.Admin => AcceptImpl(server, new ServiceCreator("bcat:a", BcatServicePermissionLevel.Admin)),
BcatPortIndex.Admin => AcceptImpl(server, new ServiceCreator("bcat:a", BcatServicePermissionLevel.Admin)),
BcatPortIndex.Manager => AcceptImpl(server, new ServiceCreator("bcat:m", BcatServicePermissionLevel.Manager)),
BcatPortIndex.User => AcceptImpl(server, new ServiceCreator("bcat:u", BcatServicePermissionLevel.User)),
BcatPortIndex.System => AcceptImpl(server, new ServiceCreator("bcat:s", BcatServicePermissionLevel.System)),
_ => throw new ArgumentOutOfRangeException(nameof(portIndex)),
BcatPortIndex.User => AcceptImpl(server, new ServiceCreator("bcat:u", BcatServicePermissionLevel.User)),
BcatPortIndex.System => AcceptImpl(server, new ServiceCreator("bcat:s", BcatServicePermissionLevel.System)),
_ => throw new ArgumentOutOfRangeException(nameof(portIndex)),
};
}
}
}
}

View File

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

View File

@ -26,7 +26,7 @@ namespace Ryujinx.Horizon.Bcat.Ipc
}
[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();
}

View File

@ -28,7 +28,7 @@ namespace Ryujinx.Horizon.Bcat.Ipc
[CmifCommand(1)]
public Result Read(long offset, out long bytesRead, [Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias)] Span<byte> data)
{
return _libHacService.Get.Read(out bytesRead, offset, data).ToHorizonResult();
return _libHacService.Get.Read(out bytesRead, offset, data).ToHorizonResult();
}
[CmifCommand(2)]

View File

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

View File

@ -8,11 +8,11 @@ namespace Ryujinx.Horizon.Bcat.Ipc.Types
public enum Status
{
// TODO: determine other values
Done = 9
Done = 9,
}
public Status State;
public uint Result;
public uint Result;
// TODO: reverse the rest of the structure
}
}

View File

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

View File

@ -2,9 +2,9 @@
{
enum BcatServicePermissionLevel
{
Admin = -1,
User = 1,
System = 2,
Manager = 6
Admin = -1,
User = 1,
System = 2,
Manager = 6,
}
}
}

View File

@ -9,15 +9,15 @@ namespace Ryujinx.Horizon
{
private const ulong InvalidAddress = ulong.MaxValue;
private struct Range : IComparable<Range>
private readonly struct Range : IComparable<Range>
{
public ulong Offset { get; }
public ulong Size { get; }
public ulong Size { get; }
public Range(ulong offset, ulong size)
{
Offset = offset;
Size = size;
Size = size;
}
public int CompareTo(Range other)
@ -31,7 +31,7 @@ namespace Ryujinx.Horizon
public HeapAllocator()
{
_freeRanges = new List<Range>();
_freeRanges = new List<Range>();
_currentHeapSize = 0;
}
@ -70,8 +70,8 @@ namespace Ryujinx.Horizon
var range = _freeRanges[i];
ulong alignedOffset = BitUtils.AlignUp(range.Offset, alignment);
ulong sizeDelta = alignedOffset - range.Offset;
ulong usableSize = range.Size - sizeDelta;
ulong sizeDelta = alignedOffset - range.Offset;
ulong usableSize = range.Size - sizeDelta;
if (sizeDelta < range.Size && usableSize >= size)
{
@ -82,7 +82,7 @@ namespace Ryujinx.Horizon
InsertFreeRange(range.Offset, sizeDelta);
}
ulong endOffset = range.Offset + range.Size;
ulong endOffset = range.Offset + range.Size;
ulong remainingSize = endOffset - (alignedOffset + size);
if (remainingSize != 0)
{
@ -140,4 +140,4 @@ namespace Ryujinx.Horizon
_freeRanges.Insert(index, range);
}
}
}
}

View File

@ -2,18 +2,18 @@ using LibHac;
namespace Ryujinx.Horizon
{
public struct HorizonOptions
public readonly struct HorizonOptions
{
public bool IgnoreMissingServices { get; }
public bool IgnoreMissingServices { get; }
public bool ThrowOnInvalidCommandIds { get; }
public HorizonClient BcatClient { get; }
public HorizonOptions(bool ignoreMissingServices, HorizonClient bcatClient)
{
IgnoreMissingServices = ignoreMissingServices;
IgnoreMissingServices = ignoreMissingServices;
ThrowOnInvalidCommandIds = true;
BcatClient = bcatClient;
BcatClient = bcatClient;
}
}
}

View File

@ -21,24 +21,24 @@ namespace Ryujinx.Horizon
[ThreadStatic]
private static int _threadHandle;
public static HorizonOptions Options => _options;
public static ISyscallApi Syscall => _syscall;
public static IVirtualMemoryManager AddressSpace => _addressSpace;
public static IThreadContext ThreadContext => _threadContext;
public static int CurrentThreadHandle => _threadHandle;
public static HorizonOptions Options => _options;
public static ISyscallApi Syscall => _syscall;
public static IVirtualMemoryManager AddressSpace => _addressSpace;
public static IThreadContext ThreadContext => _threadContext;
public static int CurrentThreadHandle => _threadHandle;
public static void Register(
HorizonOptions options,
ISyscallApi syscallApi,
HorizonOptions options,
ISyscallApi syscallApi,
IVirtualMemoryManager addressSpace,
IThreadContext threadContext,
int threadHandle)
IThreadContext threadContext,
int threadHandle)
{
_options = options;
_syscall = syscallApi;
_addressSpace = addressSpace;
_options = options;
_syscall = syscallApi;
_addressSpace = addressSpace;
_threadContext = threadContext;
_threadHandle = threadHandle;
_threadHandle = threadHandle;
}
}
}

View File

@ -95,74 +95,52 @@ namespace Ryujinx.Horizon.LogManager.Ipc
LogDataChunkKey key = (LogDataChunkKey)type;
if (key == LogDataChunkKey.Start)
switch (key)
{
reader.Skip(size);
continue;
}
else if (key == LogDataChunkKey.Stop)
{
break;
}
else if (key == LogDataChunkKey.Line)
{
if (!reader.TryRead<int>(out _logPacket.Line))
{
case LogDataChunkKey.Start:
reader.Skip(size);
continue;
case LogDataChunkKey.Stop:
break;
case LogDataChunkKey.Line when !reader.TryRead(out _logPacket.Line):
case LogDataChunkKey.DropCount when !reader.TryRead(out _logPacket.DropCount):
case LogDataChunkKey.Time when !reader.TryRead(out _logPacket.Time):
return true;
}
}
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();
if (isHeadPacket && isTailPacket)
{
_logPacket.Message = text;
}
else
{
_logPacket.Message += text;
if (_logPacket.Message.Length >= MessageLengthLimit)
case LogDataChunkKey.Message:
{
isTailPacket = true;
string text = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
if (isHeadPacket && isTailPacket)
{
_logPacket.Message = text;
}
else
{
_logPacket.Message += text;
if (_logPacket.Message.Length >= MessageLengthLimit)
{
isTailPacket = true;
}
}
break;
}
}
}
else if (key == LogDataChunkKey.Filename)
{
_logPacket.Filename = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
}
else if (key == LogDataChunkKey.Function)
{
_logPacket.Function = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
}
else if (key == LogDataChunkKey.Module)
{
_logPacket.Module = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
}
else if (key == LogDataChunkKey.Thread)
{
_logPacket.Thread = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
}
else if (key == LogDataChunkKey.ProgramName)
{
_logPacket.ProgramName = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
case LogDataChunkKey.Filename:
_logPacket.Filename = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
break;
case LogDataChunkKey.Function:
_logPacket.Function = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
break;
case LogDataChunkKey.Module:
_logPacket.Module = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
break;
case LogDataChunkKey.Thread:
_logPacket.Thread = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
break;
case LogDataChunkKey.ProgramName:
_logPacket.ProgramName = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
break;
}
}
@ -177,7 +155,7 @@ namespace Ryujinx.Horizon.LogManager.Ipc
do
{
if (!reader.TryRead<byte>(out encoded))
if (!reader.TryRead(out encoded))
{
return false;
}
@ -190,4 +168,4 @@ namespace Ryujinx.Horizon.LogManager.Ipc
return true;
}
}
}
}

View File

@ -17,4 +17,4 @@ namespace Ryujinx.Horizon.LogManager.Ipc
return Result.Success;
}
}
}
}

View File

@ -9,13 +9,13 @@ namespace Ryujinx.Horizon.LogManager
private const int LogMaxSessionsCount = 42;
private const int PointerBufferSize = 0x400;
private const int MaxDomains = 31;
private const int MaxDomainObjects = 61;
private const int MaxPortsCount = 1;
private const int MaxDomains = 31;
private const int MaxDomainObjects = 61;
private const int MaxPortsCount = 1;
private static readonly ManagerOptions _logManagerOptions = new(PointerBufferSize, MaxDomains, MaxDomainObjects, false);
private SmApi _sm;
private SmApi _sm;
private ServerManager _serverManager;
public void Initialize()
@ -40,4 +40,4 @@ namespace Ryujinx.Horizon.LogManager
_serverManager.Dispose();
}
}
}
}

View File

@ -14,4 +14,4 @@
ipcServer.Shutdown();
}
}
}
}

View File

@ -5,15 +5,15 @@ namespace Ryujinx.Horizon.LogManager.Types
{
struct LogPacket
{
public string Message;
public int Line;
public string Filename;
public string Function;
public string Module;
public string Thread;
public long DropCount;
public long Time;
public string ProgramName;
public string Message;
public int Line;
public string Filename;
public string Function;
public string Module;
public string Thread;
public long DropCount;
public long Time;
public string ProgramName;
public LogSeverity Severity;
public override string ToString()
@ -35,12 +35,12 @@ namespace Ryujinx.Horizon.LogManager.Types
{
builder.AppendLine($" ProgramName: {ProgramName}");
}
if (!string.IsNullOrEmpty(Module))
{
builder.AppendLine($" Module: {Module}");
}
if (!string.IsNullOrEmpty(Thread))
{
builder.AppendLine($" Thread: {Thread}");
@ -69,4 +69,4 @@ namespace Ryujinx.Horizon.LogManager.Types
return builder.ToString();
}
}
}
}

View File

@ -10,6 +10,7 @@ using Ryujinx.Horizon.Sdk.Sf;
using Ryujinx.Horizon.Sdk.Sf.Hipc;
using System;
using System.Text;
using ApplicationId = Ryujinx.Horizon.Sdk.Ncm.ApplicationId;
namespace Ryujinx.Horizon.Prepo.Ipc
{
@ -18,14 +19,14 @@ namespace Ryujinx.Horizon.Prepo.Ipc
enum PlayReportKind
{
Normal,
System
System,
}
private readonly PrepoServicePermissionLevel _permissionLevel;
private ulong _systemSessionId;
private bool _immediateTransmissionEnabled = false;
private bool _userAgreementCheckEnabled = true;
private bool _immediateTransmissionEnabled;
private bool _userAgreementCheckEnabled = true;
public PrepoService(PrepoServicePermissionLevel permissionLevel)
{
@ -107,7 +108,7 @@ namespace Ryujinx.Horizon.Prepo.Ipc
}
[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)
{
@ -118,7 +119,7 @@ namespace Ryujinx.Horizon.Prepo.Ipc
}
[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)
{
@ -164,7 +165,7 @@ namespace Ryujinx.Horizon.Prepo.Ipc
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)
{
@ -191,7 +192,7 @@ namespace Ryujinx.Horizon.Prepo.Ipc
return PrepoResult.InvalidBufferSize;
}
StringBuilder builder = new();
StringBuilder builder = new();
MessagePackObject deserializedReport = MessagePackSerializer.UnpackMessagePackObject(reportBuffer.ToArray());
builder.AppendLine();
@ -222,4 +223,4 @@ namespace Ryujinx.Horizon.Prepo.Ipc
return Result.Success;
}
}
}
}

View File

@ -6,13 +6,13 @@ namespace Ryujinx.Horizon.Prepo
{
class PrepoIpcServer
{
private const int PrepoMaxSessionsCount = 12;
private const int PrepoMaxSessionsCount = 12;
private const int PrepoTotalMaxSessionsCount = PrepoMaxSessionsCount * 6;
private const int PointerBufferSize = 0x80;
private const int MaxDomains = 64;
private const int MaxDomainObjects = 16;
private const int MaxPortsCount = 6;
private const int MaxDomains = 64;
private const int MaxDomainObjects = 16;
private const int MaxPortsCount = 6;
private static readonly ManagerOptions _prepoManagerOptions = new(PointerBufferSize, MaxDomains, MaxDomainObjects, false);
@ -28,12 +28,14 @@ namespace Ryujinx.Horizon.Prepo
_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.Admin2, ServiceName.Encode("prepo:a2"), PrepoMaxSessionsCount); // 6.0.0+
_serverManager.RegisterServer((int)PrepoPortIndex.Manager, ServiceName.Encode("prepo:m"), 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.Debug, ServiceName.Encode("prepo:d"), PrepoMaxSessionsCount); // 1.0.0
#pragma warning restore IDE0055
}
public void ServiceRequests()
@ -46,4 +48,4 @@ namespace Ryujinx.Horizon.Prepo
_serverManager.Dispose();
}
}
}
}

View File

@ -14,4 +14,4 @@
ipcServer.Shutdown();
}
}
}
}

View File

@ -6,10 +6,12 @@ namespace Ryujinx.Horizon.Prepo
{
private const int ModuleId = 129;
#pragma warning disable IDE0055 // Disable formatting
public static Result InvalidArgument => new(ModuleId, 1);
public static Result InvalidState => new(ModuleId, 5);
public static Result InvalidBufferSize => new(ModuleId, 9);
public static Result PermissionDenied => new(ModuleId, 90);
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
{
#pragma warning disable IDE0055 // Disable formatting
PrepoPortIndex.Admin => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Admin)),
PrepoPortIndex.Admin2 => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Admin)),
PrepoPortIndex.Manager => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Manager)),
@ -24,7 +25,8 @@ namespace Ryujinx.Horizon.Prepo
PrepoPortIndex.System => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.System)),
PrepoPortIndex.Debug => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Debug)),
_ => throw new ArgumentOutOfRangeException(nameof(portIndex)),
#pragma warning restore IDE0055
};
}
}
}
}

View File

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

View File

@ -2,10 +2,10 @@
{
enum PrepoServicePermissionLevel
{
Admin = -1,
User = 1,
System = 2,
Admin = -1,
User = 1,
System = 2,
Manager = 6,
Debug = unchecked((int)0x80000006)
Debug = unchecked((int)0x80000006),
}
}
}

View File

@ -17,14 +17,14 @@ namespace Ryujinx.Horizon.Sdk.Account
public Uid(long low, long high)
{
Low = low;
Low = low;
High = high;
}
public Uid(byte[] bytes)
{
High = BitConverter.ToInt64(bytes, 0);
Low = BitConverter.ToInt64(bytes, 8);
Low = BitConverter.ToInt64(bytes, 8);
}
public Uid(string hex)
@ -34,7 +34,7 @@ namespace Ryujinx.Horizon.Sdk.Account
throw new ArgumentException("Invalid Hex value!", nameof(hex));
}
Low = Convert.ToInt64(hex[16..], 16);
Low = Convert.ToInt64(hex[16..], 16);
High = Convert.ToInt64(hex[..16], 16);
}
@ -59,4 +59,4 @@ namespace Ryujinx.Horizon.Sdk.Account
return new UInt128((ulong)High, (ulong)Low);
}
}
}
}

View File

@ -1,4 +1,5 @@
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Ncm;
using Ryujinx.Horizon.Sdk.Sf;
namespace Ryujinx.Horizon.Sdk.Bcat
@ -7,6 +8,6 @@ namespace Ryujinx.Horizon.Sdk.Bcat
{
Result CreateBcatService(out IBcatService 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,
Warn = 2,
Error = 3,
Fatal = 4
Fatal = 4,
}
}
}

View File

@ -9,4 +9,4 @@ namespace Ryujinx.Horizon.Sdk.Lm
Result Log(Span<byte> message);
Result SetDestination(LogDestination destination);
}
}
}

View File

@ -8,4 +8,4 @@ namespace Ryujinx.Horizon.Sdk.Lm
{
Result OpenLogger(out LmLogger logger, ulong pid);
}
}
}

View File

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

View File

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

View File

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

View File

@ -49,4 +49,4 @@
return $"0x{Id:x}";
}
}
}
}

View File

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

View File

@ -7,9 +7,9 @@ namespace Ryujinx.Horizon.Sdk.OsTypes.Impl
{
class MultiWaitImpl
{
private const int WaitTimedOut = -1;
private const int WaitTimedOut = -1;
private const int WaitCancelled = -2;
private const int WaitInvalid = -3;
private const int WaitInvalid = -3;
private readonly List<MultiWaitHolderBase> _multiWaits;
@ -63,10 +63,7 @@ namespace Ryujinx.Horizon.Sdk.OsTypes.Impl
}
}
if (result == null)
{
result = WaitAnyHandleImpl(infinite, timeout);
}
result ??= WaitAnyHandleImpl(infinite, timeout);
UnlinkHoldersFromObjectsList();
_waitingThreadHandle = 0;
@ -98,7 +95,7 @@ namespace Ryujinx.Horizon.Sdk.OsTypes.Impl
}
else
{
index = WaitSynchronization(objectHandles.Slice(0, count), minTimeout);
index = WaitSynchronization(objectHandles[..count], minTimeout);
DebugUtil.Assert(index != WaitInvalid);
}
@ -200,10 +197,8 @@ namespace Ryujinx.Horizon.Sdk.OsTypes.Impl
{
return WaitCancelled;
}
else
{
result.AbortOnFailure();
}
result.AbortOnFailure();
return index;
}

View File

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

View File

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

View File

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

View File

@ -15,7 +15,7 @@ namespace Ryujinx.Horizon.Sdk.OsTypes
InitiallySignaled = signaled,
ClearMode = clearMode,
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;
public static Result OutOfResource => new Result(ModuleId, 9);
public static Result OutOfResource => new(ModuleId, 9);
}
}

View File

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

View File

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

View File

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

View File

@ -10,15 +10,15 @@ namespace Ryujinx.Horizon.Sdk
public static Result SendRequest(out CmifResponse response, int sessionHandle, uint requestId, bool sendPid, scoped ReadOnlySpan<byte> data)
{
ulong tlsAddress = HorizonStatic.ThreadContext.TlsAddress;
int tlsSize = Api.TlsMessageBufferSize;
int tlsSize = Api.TlsMessageBufferSize;
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,
SendPid = sendPid
SendPid = sendPid,
});
data.CopyTo(request.Data);
@ -36,4 +36,4 @@ namespace Ryujinx.Horizon.Sdk
return CmifMessage.ParseResponse(out response, HorizonStatic.AddressSpace.GetWritableRegion(tlsAddress, tlsSize).Memory.Span, false, 0);
}
}
}
}

View File

@ -3,10 +3,10 @@
struct CmifDomainInHeader
{
public CmifDomainRequestType Type;
public byte ObjectsCount;
public ushort DataSize;
public int ObjectId;
public uint Padding;
public uint Token;
public byte ObjectsCount;
public ushort DataSize;
public int ObjectId;
public uint Padding;
public uint Token;
}
}

View File

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

View File

@ -2,8 +2,8 @@
{
enum CmifDomainRequestType : byte
{
Invalid = 0,
Invalid = 0,
SendMessage = 1,
Close = 2
Close = 2,
}
}

View File

@ -8,7 +8,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
{
static class CmifMessage
{
public const uint CmifInHeaderMagic = 0x49434653; // SFCI
public const uint CmifInHeaderMagic = 0x49434653; // SFCI
public const uint CmifOutHeaderMagic = 0x4f434653; // SFCO
public static CmifRequest CreateRequest(Span<byte> output, CmifRequestFormat format)
@ -21,10 +21,10 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
}
totalSize += Unsafe.SizeOf<CmifInHeader>() + format.DataSize;
totalSize = (totalSize + 1) & ~1;
totalSize = (totalSize + 1) & ~1;
int outPointerSizeTableOffset = totalSize;
int outPointerSizeTableSize = format.OutAutoBuffersCount + format.OutPointersCount;
int outPointerSizeTableSize = format.OutAutoBuffersCount + format.OutPointersCount;
totalSize += sizeof(ushort) * outPointerSizeTableSize;
@ -32,19 +32,19 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
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,
SendStaticsCount = format.InAutoBuffersCount + format.InPointersCount,
SendBuffersCount = format.InAutoBuffersCount + format.InBuffersCount,
ReceiveBuffersCount = format.OutAutoBuffersCount + format.OutBuffersCount,
Type = format.Context != 0 ? (int)CommandType.RequestWithContext : (int)CommandType.Request,
SendStaticsCount = format.InAutoBuffersCount + format.InPointersCount,
SendBuffersCount = format.InAutoBuffersCount + format.InBuffersCount,
ReceiveBuffersCount = format.OutAutoBuffersCount + format.OutBuffersCount,
ExchangeBuffersCount = format.InOutBuffersCount,
DataWordsCount = rawDataSizeInWords,
ReceiveStaticsCount = outPointerSizeTableSize + format.OutFixedPointersCount,
SendPid = format.SendPid,
CopyHandlesCount = format.HandlesCount,
MoveHandlesCount = 0
})
DataWordsCount = rawDataSizeInWords,
ReceiveStaticsCount = outPointerSizeTableSize + format.OutFixedPointersCount,
SendPid = format.SendPid,
CopyHandlesCount = format.HandlesCount,
MoveHandlesCount = 0,
}),
};
Span<uint> data = request.Hipc.DataWords;
@ -55,14 +55,14 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
int payloadSize = Unsafe.SizeOf<CmifInHeader>() + format.DataSize;
domainHeader = new CmifDomainInHeader()
domainHeader = new CmifDomainInHeader
{
Type = CmifDomainRequestType.SendMessage,
Type = CmifDomainRequestType.SendMessage,
ObjectsCount = (byte)format.ObjectsCount,
DataSize = (ushort)payloadSize,
ObjectId = format.ObjectId,
Padding = 0,
Token = format.Context
DataSize = (ushort)payloadSize,
ObjectId = format.ObjectId,
Padding = 0,
Token = format.Context,
};
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];
header = new CmifInHeader()
header = new CmifInHeader
{
Magic = CmifInHeaderMagic,
Version = format.Context != 0 ? 1u : 0u,
Magic = CmifInHeaderMagic,
Version = format.Context != 0 ? 1u : 0u,
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>()..];
@ -86,7 +86,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
Span<byte> outPointerTable = MemoryMarshal.Cast<uint, byte>(request.Hipc.DataWords)[(outPointerSizeTableOffset - paddingSizeBefore)..];
request.OutPointerSizes = MemoryMarshal.Cast<byte, ushort>(outPointerTable);
request.OutPointerSizes = MemoryMarshal.Cast<byte, ushort>(outPointerTable);
request.ServerPointerSize = format.ServerPointerSize;
return request;
@ -96,12 +96,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
{
HipcMessage responseMessage = new(input);
Span<byte> data = MemoryMarshal.Cast<uint, byte>(responseMessage.Data.DataWords);
Span<byte> data = MemoryMarshal.Cast<uint, byte>(responseMessage.Data.DataWords);
Span<uint> objects = Span<uint>.Empty;
if (isDomain)
{
data = data[Unsafe.SizeOf<CmifDomainOutHeader>()..];
data = data[Unsafe.SizeOf<CmifDomainOutHeader>()..];
objects = MemoryMarshal.Cast<byte, uint>(data[(Unsafe.SizeOf<CmifOutHeader>() + size)..]);
}
@ -121,15 +121,15 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
return header.Result;
}
response = new CmifResponse()
response = new CmifResponse
{
Data = data[Unsafe.SizeOf<CmifOutHeader>()..],
Objects = objects,
Data = data[Unsafe.SizeOf<CmifOutHeader>()..],
Objects = objects,
CopyHandles = responseMessage.Data.CopyHandles,
MoveHandles = responseMessage.Data.MoveHandles
MoveHandles = responseMessage.Data.MoveHandles,
};
return Result.Success;
}
}
}
}

View File

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

View File

@ -6,9 +6,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
ref struct CmifRequest
{
public HipcMessageData Hipc;
public Span<byte> Data;
public Span<ushort> OutPointerSizes;
public Span<uint> Objects;
public int ServerPointerSize;
public Span<byte> Data;
public Span<ushort> OutPointerSizes;
public Span<uint> Objects;
public int ServerPointerSize;
}
}

View File

@ -2,22 +2,22 @@
{
struct CmifRequestFormat
{
#pragma warning disable CS0649
public int ObjectId;
#pragma warning disable CS0649 // Field is never assigned to
public int ObjectId;
public uint RequestId;
public uint Context;
public int DataSize;
public int ServerPointerSize;
public int InAutoBuffersCount;
public int OutAutoBuffersCount;
public int InBuffersCount;
public int OutBuffersCount;
public int InOutBuffersCount;
public int InPointersCount;
public int OutPointersCount;
public int OutFixedPointersCount;
public int ObjectsCount;
public int HandlesCount;
public int DataSize;
public int ServerPointerSize;
public int InAutoBuffersCount;
public int OutAutoBuffersCount;
public int InBuffersCount;
public int OutBuffersCount;
public int InOutBuffersCount;
public int InPointersCount;
public int OutPointersCount;
public int OutFixedPointersCount;
public int ObjectsCount;
public int HandlesCount;
public bool SendPid;
#pragma warning restore CS0649
}

View File

@ -6,7 +6,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
{
public ReadOnlySpan<byte> Data;
public ReadOnlySpan<uint> Objects;
public ReadOnlySpan<int> CopyHandles;
public ReadOnlySpan<int> MoveHandles;
public ReadOnlySpan<int> CopyHandles;
public ReadOnlySpan<int> MoveHandles;
}
}

View File

@ -2,13 +2,13 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
{
enum CommandType
{
Invalid = 0,
LegacyRequest = 1,
Close = 2,
LegacyControl = 3,
Request = 4,
Control = 5,
Invalid = 0,
LegacyRequest = 1,
Close = 2,
LegacyControl = 3,
Request = 4,
Control = 5,
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);
}
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>())
{

View File

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

View File

@ -17,7 +17,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
public int this[int index]
{
get
readonly get
{
return index switch
{
@ -29,22 +29,39 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
5 => _handle5,
6 => _handle6,
7 => _handle7,
_ => throw new IndexOutOfRangeException()
_ => throw new IndexOutOfRangeException(),
};
}
set
{
switch (index)
{
case 0: _handle0 = value; break;
case 1: _handle1 = value; break;
case 2: _handle2 = value; 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();
case 0:
_handle0 = value;
break;
case 1:
_handle1 = value;
break;
case 2:
_handle2 = value;
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
{
struct PointerAndSize
readonly struct PointerAndSize
{
public static PointerAndSize Empty => new(0UL, 0UL);
@ -11,7 +11,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
public PointerAndSize(ulong address, ulong size)
{
Address = address;
Size = size;
Size = size;
}
}
}

View File

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

View File

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

View File

@ -1,30 +1,30 @@
namespace Ryujinx.Horizon.Sdk.Sf.Cmif
{
struct ServerMessageRuntimeMetadata
readonly struct ServerMessageRuntimeMetadata
{
public ushort InDataSize { get; }
public ushort OutDataSize { get; }
public byte InHeadersSize { get; }
public byte OutHeadersSize { get; }
public byte InObjectsCount { get; }
public byte OutObjectsCount { get; }
public ushort InDataSize { get; }
public ushort OutDataSize { get; }
public byte InHeadersSize { get; }
public byte OutHeadersSize { get; }
public byte InObjectsCount { get; }
public byte OutObjectsCount { get; }
public int UnfixedOutPointerSizeOffset => InDataSize + InHeadersSize + 0x10;
public ServerMessageRuntimeMetadata(
ushort inDataSize,
ushort outDataSize,
byte inHeadersSize,
byte outHeadersSize,
byte inObjectsCount,
byte outObjectsCount)
byte inHeadersSize,
byte outHeadersSize,
byte inObjectsCount,
byte outObjectsCount)
{
InDataSize = inDataSize;
OutDataSize = outDataSize;
InHeadersSize = inHeadersSize;
OutHeadersSize = outHeadersSize;
InObjectsCount = inObjectsCount;
InDataSize = inDataSize;
OutDataSize = outDataSize;
InHeadersSize = inHeadersSize;
OutHeadersSize = outHeadersSize;
InObjectsCount = inObjectsCount;
OutObjectsCount = outObjectsCount;
}
}
}
}

View File

@ -5,14 +5,14 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
{
ref struct ServiceDispatchContext
{
public IServiceObject ServiceObject;
public ServerSessionManager Manager;
public ServerSession Session;
public IServiceObject ServiceObject;
public ServerSessionManager Manager;
public ServerSession Session;
public ServerMessageProcessor Processor;
public HandlesToClose HandlesToClose;
public PointerAndSize PointerBuffer;
public ReadOnlySpan<byte> InMessageBuffer;
public Span<byte> OutMessageBuffer;
public HipcMessage Request;
public HandlesToClose HandlesToClose;
public PointerAndSize PointerBuffer;
public ReadOnlySpan<byte> InMessageBuffer;
public Span<byte> OutMessageBuffer;
public HipcMessage Request;
}
}
}

View File

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

View File

@ -12,7 +12,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
public ServiceDispatchTable(string objectName, IReadOnlyDictionary<int, CommandHandler> entries)
{
_objectName = objectName;
_entries = entries;
_entries = entries;
}
public override Result ProcessMessage(ref ServiceDispatchContext context, ReadOnlySpan<byte> inRawData)
@ -30,4 +30,4 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
return new ServiceDispatchTable(instance.GetType().Name, instance.GetCommandHandlers());
}
}
}
}

View File

@ -14,7 +14,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
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>())
{
@ -44,7 +44,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
// If ignore missing services is enabled, just pretend that everything is fine.
PrepareForStubReply(ref context, out Span<byte> 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");
@ -80,7 +80,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
return commandResult;
}
outHeader[0] = new CmifOutHeader() { Magic = CmifMessage.CmifOutHeaderMagic, Result = commandResult };
outHeader[0] = new CmifOutHeader { Magic = CmifMessage.CmifOutHeaderMagic, Result = commandResult };
return Result.Success;
}
@ -91,4 +91,4 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
outRawData = MemoryMarshal.Cast<uint, byte>(response.DataWords);
}
}
}
}

View File

@ -15,42 +15,42 @@ namespace Ryujinx.Horizon.Sdk.Sf
OutCopyHandle,
OutMoveHandle,
OutObject,
ProcessId
ProcessId,
}
struct CommandArg
readonly struct CommandArg
{
public CommandArgType Type { get; }
public HipcBufferFlags BufferFlags { get; }
public ushort BufferFixedSize { get; }
public int ArgSize { get; }
public int ArgAlignment { get; }
public CommandArgType Type { get; }
public HipcBufferFlags BufferFlags { get; }
public ushort BufferFixedSize { get; }
public int ArgSize { get; }
public int ArgAlignment { get; }
public CommandArg(CommandArgType type)
{
Type = type;
BufferFlags = default;
Type = type;
BufferFlags = default;
BufferFixedSize = 0;
ArgSize = 0;
ArgAlignment = 0;
ArgSize = 0;
ArgAlignment = 0;
}
public CommandArg(CommandArgType type, int argSize, int argAlignment)
{
Type = type;
BufferFlags = default;
Type = type;
BufferFlags = default;
BufferFixedSize = 0;
ArgSize = argSize;
ArgAlignment = argAlignment;
ArgSize = argSize;
ArgAlignment = argAlignment;
}
public CommandArg(HipcBufferFlags flags, ushort fixedSize = 0)
{
Type = CommandArgType.Buffer;
BufferFlags = flags;
Type = CommandArgType.Buffer;
BufferFlags = flags;
BufferFixedSize = fixedSize;
ArgSize = 0;
ArgAlignment = 0;
ArgSize = 0;
ArgAlignment = 0;
}
}
}
}

View File

@ -6,8 +6,8 @@ namespace Ryujinx.Horizon.Sdk.Sf
[AttributeUsage(AttributeTargets.Parameter)]
class BufferAttribute : Attribute
{
public HipcBufferFlags Flags { get; }
public ushort FixedSize { get; }
public HipcBufferFlags Flags { get; }
public ushort FixedSize { get; }
public BufferAttribute(HipcBufferFlags flags)
{
@ -16,7 +16,7 @@ namespace Ryujinx.Horizon.Sdk.Sf
public BufferAttribute(HipcBufferFlags flags, ushort fixedSize)
{
Flags = flags | HipcBufferFlags.FixedSize;
Flags = flags | HipcBufferFlags.FixedSize;
FixedSize = fixedSize;
}
}
@ -35,4 +35,4 @@ namespace Ryujinx.Horizon.Sdk.Sf
class MoveHandleAttribute : Attribute
{
}
}
}

View File

@ -9,20 +9,20 @@ namespace Ryujinx.Horizon.Sdk.Sf
class CommandHandler
{
public delegate Result MethodInvoke(
ref ServiceDispatchContext context,
HipcCommandProcessor processor,
ref ServiceDispatchContext context,
HipcCommandProcessor processor,
ServerMessageRuntimeMetadata runtimeMetadata,
ReadOnlySpan<byte> inRawData,
ref Span<CmifOutHeader> outHeader);
ReadOnlySpan<byte> inRawData,
ref Span<CmifOutHeader> outHeader);
private readonly MethodInvoke _invoke;
private readonly MethodInvoke _invoke;
private readonly HipcCommandProcessor _processor;
public string MethodName => _invoke.Method.Name;
public CommandHandler(MethodInvoke invoke, params CommandArg[] args)
{
_invoke = invoke;
_invoke = invoke;
_processor = new HipcCommandProcessor(args);
}
@ -37,16 +37,16 @@ namespace Ryujinx.Horizon.Sdk.Sf
context.Processor.SetImplementationProcessor(_processor);
}
var runtimeMetadata = context.Processor.GetRuntimeMetadata();
Result result = context.Processor.PrepareForProcess(ref context, runtimeMetadata);
var runtimeMetadata = context.Processor.GetRuntimeMetadata();
Result result = context.Processor.PrepareForProcess(ref context, runtimeMetadata);
return result.IsFailure ? result : _invoke(ref context, _processor, runtimeMetadata, inRawData, ref outHeader);
}
public static void GetCmifOutHeaderPointer(ref Span<CmifOutHeader> outHeader, ref Span<byte> outRawData)
{
outHeader = MemoryMarshal.Cast<byte, CmifOutHeader>(outRawData)[..1];
outHeader = MemoryMarshal.Cast<byte, CmifOutHeader>(outRawData)[..1];
outRawData = outRawData[Unsafe.SizeOf<CmifOutHeader>()..];
}
}
}
}

View File

@ -66,4 +66,4 @@ namespace Ryujinx.Horizon.Sdk.Sf
response.MoveHandles[index] = value;
}
}
}
}

View File

@ -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;
}
}
}
}

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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,
}
}

View File

@ -2,9 +2,9 @@
{
enum HipcBufferMode
{
Normal = 0,
Normal = 0,
NonSecure = 1,
Invalid = 2,
NonDevice = 3
Invalid = 2,
NonDevice = 3,
}
}

View File

@ -112,4 +112,4 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
return Result.Success;
}
}
}
}

View File

@ -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,
};
}
}

View File

@ -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;
}
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}
}

View File

@ -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
}
}

View File

@ -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;
}
}
}
}

View File

@ -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;
}
}
}
}

View File

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

View File

@ -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)
{

View File

@ -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)

View File

@ -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()),
};
}

View File

@ -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;
}
}
}

View File

@ -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;
}
else
{
Logger.Warning?.Print(LogClass.KernelIpc, $"Request processing returned error {result}");
CloseSessionImpl(session);
return Result.Success;
}
return Result.Success;
}
else if (SfResult.RequestContextChanged(result))
{
return result;
}
Logger.Warning?.Print(LogClass.KernelIpc, $"Request processing returned error {result}");
CloseSessionImpl(session);
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;
}
}
}
}

View File

@ -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);
}
}

View File

@ -134,9 +134,9 @@ namespace Ryujinx.Horizon.Sdk.Sf
ulong pointerBufferTail = context.PointerBuffer.Address;
ulong pointerBufferHead = pointerBufferTail + context.PointerBuffer.Size;
int sendMapAliasIndex = 0;
int recvMapAliasIndex = 0;
int sendPointerIndex = 0;
int sendMapAliasIndex = 0;
int recvMapAliasIndex = 0;
int sendPointerIndex = 0;
int unfixedRecvPointerIndex = 0;
for (int i = 0; i < _args.Length; i++)
@ -186,8 +186,8 @@ namespace Ryujinx.Horizon.Sdk.Sf
if (flags.HasFlag(HipcBufferFlags.In))
{
var descriptor = context.Request.Data.SendStatics[sendPointerIndex++];
ulong address = descriptor.Address;
ulong size = descriptor.Size;
ulong address = descriptor.Address;
ulong size = descriptor.Size;
_bufferRanges[i] = new PointerAndSize(address, size);
@ -206,14 +206,14 @@ namespace Ryujinx.Horizon.Sdk.Sf
}
else
{
var data = MemoryMarshal.Cast<uint, byte>(context.Request.Data.DataWords);
var data = MemoryMarshal.Cast<uint, byte>(context.Request.Data.DataWords);
var recvPointerSizes = MemoryMarshal.Cast<byte, ushort>(data[runtimeMetadata.UnfixedOutPointerSizeOffset..]);
size = recvPointerSizes[unfixedRecvPointerIndex++];
}
pointerBufferHead = BitUtils.AlignDown(pointerBufferHead - size, 0x10UL);
_bufferRanges[i] = new PointerAndSize(pointerBufferHead, size);
_bufferRanges[i] = new PointerAndSize(pointerBufferHead, size);
}
}
}
@ -305,13 +305,13 @@ namespace Ryujinx.Horizon.Sdk.Sf
{
ref var meta = ref context.Request.Meta;
bool requestValid = true;
requestValid &= meta.SendPid == _hasInProcessIdHolder;
requestValid &= meta.SendStaticsCount == _inPointerBuffersCount;
requestValid &= meta.SendBuffersCount == _inMapAliasBuffersCount;
requestValid &= meta.ReceiveBuffersCount == _outMapAliasBuffersCount;
requestValid &= meta.SendPid == _hasInProcessIdHolder;
requestValid &= meta.SendStaticsCount == _inPointerBuffersCount;
requestValid &= meta.SendBuffersCount == _inMapAliasBuffersCount;
requestValid &= meta.ReceiveBuffersCount == _outMapAliasBuffersCount;
requestValid &= meta.ExchangeBuffersCount == 0;
requestValid &= meta.CopyHandlesCount == _inCopyHandlesCount;
requestValid &= meta.MoveHandlesCount == _inMoveHandlesCount;
requestValid &= meta.CopyHandlesCount == _inCopyHandlesCount;
requestValid &= meta.MoveHandlesCount == _inMoveHandlesCount;
int rawSizeInBytes = meta.DataWordsCount * sizeof(uint);
int commandRawSize = BitUtils.AlignUp(runtimeMetadata.UnfixedOutPointerSizeOffset + (OutUnfixedSizePointerBuffersCount * sizeof(ushort)), sizeof(uint));
@ -345,7 +345,7 @@ namespace Ryujinx.Horizon.Sdk.Sf
continue;
}
int index = inObjectIndex++;
int index = inObjectIndex++;
var inObject = inObjects[index];
objects[index] = inObject?.ServiceObject;
@ -386,7 +386,9 @@ namespace Ryujinx.Horizon.Sdk.Sf
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)
#pragma warning restore CA1822
{
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)
{
@ -425,4 +427,4 @@ namespace Ryujinx.Horizon.Sdk.Sf
response.MoveHandles[index] = clientHandle;
}
}
}
}

View File

@ -12,15 +12,15 @@ namespace Ryujinx.Horizon.Sdk.Sf
{
int argsCount = args.Length;
int[] sizes = new int[argsCount];
int[] sizes = new int[argsCount];
int[] aligns = new int[argsCount];
int[] map = new int[argsCount];
int[] map = new int[argsCount];
for (int i = 0; i < argsCount; i++)
{
sizes[i] = args[i].ArgSize;
sizes[i] = args[i].ArgSize;
aligns[i] = args[i].ArgAlignment;
map[i] = i;
map[i] = i;
}
for (int i = 1; i < argsCount; i++)
@ -35,9 +35,9 @@ namespace Ryujinx.Horizon.Sdk.Sf
foreach (int i in map)
{
offset = BitUtils.AlignUp(offset, aligns[i]);
offset = BitUtils.AlignUp(offset, aligns[i]);
offsets[i] = offset;
offset += sizes[i];
offset += sizes[i];
}
offsets[argsCount] = offset;
@ -46,4 +46,4 @@ namespace Ryujinx.Horizon.Sdk.Sf
return offsets;
}
}
}
}

View File

@ -6,6 +6,7 @@ namespace Ryujinx.Horizon.Sdk.Sf
{
public const int ModuleId = 10;
#pragma warning disable IDE0055 // Disable formatting
public static Result NotSupported => new(ModuleId, 1);
public static Result InvalidHeaderSize => new(ModuleId, 202);
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 Invalidated(Result result) => result.InRange(801, 809);
public static bool RequestDeferred(Result result) => result.InRange(811, 819);
#pragma warning restore IDE0055
}
}
}

View File

@ -5,4 +5,4 @@ namespace Ryujinx.Horizon.Sdk.Sm
interface IManagerService : IServiceObject
{
}
}
}

View File

@ -10,4 +10,4 @@ namespace Ryujinx.Horizon.Sdk.Sm
Result RegisterService(out int handle, ServiceName name, int maxSessions, bool isLight);
Result UnregisterService(ServiceName name);
}
}
}

View File

@ -4,13 +4,13 @@ using System.Runtime.InteropServices;
namespace Ryujinx.Horizon.Sdk.Sm
{
[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 int Length => sizeof(ulong);
public const int Length = sizeof(ulong);
public ulong Packed { get; }

View File

@ -110,4 +110,4 @@ namespace Ryujinx.Horizon.Sdk.Sm
return ServiceUtil.SendRequest(out _, _portHandle, 4, sendPid: true, data);
}
}
}
}

View File

@ -4,17 +4,17 @@ using System;
namespace Ryujinx.Horizon
{
public struct ServiceEntry
public readonly struct ServiceEntry
{
private readonly Action<ServiceTable> _entrypoint;
private readonly ServiceTable _serviceTable;
private readonly HorizonOptions _options;
private readonly ServiceTable _serviceTable;
private readonly HorizonOptions _options;
internal ServiceEntry(Action<ServiceTable> entrypoint, ServiceTable serviceTable, HorizonOptions options)
{
_entrypoint = entrypoint;
_entrypoint = entrypoint;
_serviceTable = serviceTable;
_options = options;
_options = options;
}
public void Start(ISyscallApi syscallApi, IVirtualMemoryManager addressSpace, IThreadContext threadContext)
@ -24,4 +24,4 @@ namespace Ryujinx.Horizon
_entrypoint(_serviceTable);
}
}
}
}

View File

@ -57,4 +57,4 @@ namespace Ryujinx.Horizon
Dispose(true);
}
}
}
}

View File

@ -5,16 +5,16 @@ namespace Ryujinx.Horizon.Sm.Impl
struct ServiceInfo
{
public ServiceName Name;
public ulong OwnerProcessId;
public int PortHandle;
public ulong OwnerProcessId;
public int PortHandle;
public void Free()
{
HorizonStatic.Syscall.CloseHandle(PortHandle);
Name = ServiceName.Invalid;
Name = ServiceName.Invalid;
OwnerProcessId = 0L;
PortHandle = 0;
PortHandle = 0;
}
}
}
}

View File

@ -40,7 +40,7 @@ namespace Ryujinx.Horizon.Sm.Impl
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);
}
@ -96,8 +96,8 @@ namespace Ryujinx.Horizon.Sm.Impl
return result;
}
freeService.PortHandle = clientPort;
freeService.Name = name;
freeService.PortHandle = clientPort;
freeService.Name = name;
freeService.OwnerProcessId = processId;
return Result.Success;
@ -140,7 +140,7 @@ namespace Ryujinx.Horizon.Sm.Impl
int nameLength = 1;
for (; nameLength < name.Length; nameLength++)
for (; nameLength < ServiceName.Length; nameLength++)
{
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)
{
@ -182,4 +182,4 @@ namespace Ryujinx.Horizon.Sm.Impl
return -1;
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More