aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Horizon/Sdk/Sf/Hipc
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Horizon/Sdk/Sf/Hipc')
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferFlags.cs12
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferMode.cs4
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/HipcManager.cs4
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessage.cs122
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessageData.cs8
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMetadata.cs18
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/HipcReceiveListEntry.cs2
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/HipcResult.cs21
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/HipcStaticDescriptor.cs8
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/ManagerOptions.cs16
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/Server.cs20
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/ServerDomainSessionManager.cs2
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs4
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs33
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSession.cs16
-rw-r--r--Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSessionManager.cs41
16 files changed, 168 insertions, 163 deletions
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferFlags.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferFlags.cs
index 594af2c8..269ab4fe 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferFlags.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferFlags.cs
@@ -5,12 +5,12 @@ 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
}
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferMode.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferMode.cs
index 4ef6374b..b1e67253 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferMode.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcBufferMode.cs
@@ -2,9 +2,9 @@
{
enum HipcBufferMode
{
- Normal = 0,
+ Normal = 0,
NonSecure = 1,
- Invalid = 2,
+ Invalid = 2,
NonDevice = 3
}
}
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcManager.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcManager.cs
index ea2ec650..7541e294 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcManager.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcManager.cs
@@ -61,7 +61,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{
clientHandle = 0;
- if (!(_session.ServiceObjectHolder.ServiceObject is DomainServiceObject domain))
+ if (_session.ServiceObjectHolder.ServiceObject is not DomainServiceObject domain)
{
return HipcResult.TargetNotDomain;
}
@@ -112,4 +112,4 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
return Result.Success;
}
}
-}
+} \ No newline at end of file
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessage.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessage.cs
index 3017f404..6500d6cf 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessage.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessage.cs
@@ -10,9 +10,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{
public const int AutoReceiveStatic = byte.MaxValue;
- public HipcMetadata Meta;
+ public HipcMetadata Meta;
public HipcMessageData Data;
- public ulong Pid;
+ public ulong Pid;
public HipcMessage(Span<byte> data)
{
@@ -20,10 +20,10 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
Header header = MemoryMarshal.Cast<byte, Header>(data)[0];
- data = data.Slice(Unsafe.SizeOf<Header>());
+ data = data[Unsafe.SizeOf<Header>()..];
- int receiveStaticsCount = 0;
- ulong pid = 0;
+ int receiveStaticsCount = 0;
+ ulong pid = 0;
if (header.ReceiveStaticMode != 0)
{
@@ -42,46 +42,44 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
if (header.HasSpecialHeader)
{
specialHeader = MemoryMarshal.Cast<byte, SpecialHeader>(data)[0];
-
- data = data.Slice(Unsafe.SizeOf<SpecialHeader>());
+ data = data[Unsafe.SizeOf<SpecialHeader>()..];
if (specialHeader.SendPid)
{
- pid = MemoryMarshal.Cast<byte, ulong>(data)[0];
-
- data = data.Slice(sizeof(ulong));
+ pid = MemoryMarshal.Cast<byte, ulong>(data)[0];
+ data = data[sizeof(ulong)..];
}
}
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()
{
SendStaticsCount = sendStaticCount,
- DataWordsCount = dataWordsCount,
+ DataWordsCount = dataWordsCount,
CopyHandlesCount = copyHandlesCount,
MoveHandlesCount = moveHandlesCount
});
@@ -89,38 +87,37 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
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()
{
- 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.Slice(Unsafe.SizeOf<Header>());
+ destination = destination[Unsafe.SizeOf<Header>()..];
if (hasSpecialHeader)
{
MemoryMarshal.Cast<byte, SpecialHeader>(destination)[0] = new SpecialHeader()
{
- SendPid = meta.SendPid,
+ SendPid = meta.SendPid,
CopyHandlesCount = meta.CopyHandlesCount,
MoveHandlesCount = meta.MoveHandlesCount
};
- destination = destination.Slice(Unsafe.SizeOf<SpecialHeader>());
+ destination = destination[Unsafe.SizeOf<SpecialHeader>()..];
if (meta.SendPid)
{
- destination = destination.Slice(sizeof(ulong));
+ destination = destination[sizeof(ulong)..];
}
}
@@ -133,68 +130,67 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
if (meta.CopyHandlesCount != 0)
{
- copyHandles = MemoryMarshal.Cast<byte, int>(data).Slice(0, meta.CopyHandlesCount);
+ copyHandles = MemoryMarshal.Cast<byte, int>(data)[..meta.CopyHandlesCount];
- data = data.Slice(meta.CopyHandlesCount * sizeof(int));
+ data = data[(meta.CopyHandlesCount * sizeof(int))..];
}
Span<int> moveHandles = Span<int>.Empty;
if (meta.MoveHandlesCount != 0)
{
- moveHandles = MemoryMarshal.Cast<byte, int>(data).Slice(0, meta.MoveHandlesCount);
+ moveHandles = MemoryMarshal.Cast<byte, int>(data)[..meta.MoveHandlesCount];
- data = data.Slice(meta.MoveHandlesCount * sizeof(int));
+ data = data[(meta.MoveHandlesCount * sizeof(int))..];
}
Span<HipcStaticDescriptor> sendStatics = Span<HipcStaticDescriptor>.Empty;
if (meta.SendStaticsCount != 0)
{
- sendStatics = MemoryMarshal.Cast<byte, HipcStaticDescriptor>(data).Slice(0, meta.SendStaticsCount);
+ sendStatics = MemoryMarshal.Cast<byte, HipcStaticDescriptor>(data)[..meta.SendStaticsCount];
- data = data.Slice(meta.SendStaticsCount * Unsafe.SizeOf<HipcStaticDescriptor>());
+ data = data[(meta.SendStaticsCount * Unsafe.SizeOf<HipcStaticDescriptor>())..];
}
Span<HipcBufferDescriptor> sendBuffers = Span<HipcBufferDescriptor>.Empty;
if (meta.SendBuffersCount != 0)
{
- sendBuffers = MemoryMarshal.Cast<byte, HipcBufferDescriptor>(data).Slice(0, meta.SendBuffersCount);
+ sendBuffers = MemoryMarshal.Cast<byte, HipcBufferDescriptor>(data)[..meta.SendBuffersCount];
- data = data.Slice(meta.SendBuffersCount * Unsafe.SizeOf<HipcBufferDescriptor>());
+ data = data[(meta.SendBuffersCount * Unsafe.SizeOf<HipcBufferDescriptor>())..];
}
Span<HipcBufferDescriptor> receiveBuffers = Span<HipcBufferDescriptor>.Empty;
if (meta.ReceiveBuffersCount != 0)
{
- receiveBuffers = MemoryMarshal.Cast<byte, HipcBufferDescriptor>(data).Slice(0, meta.ReceiveBuffersCount);
+ receiveBuffers = MemoryMarshal.Cast<byte, HipcBufferDescriptor>(data)[..meta.ReceiveBuffersCount];
- data = data.Slice(meta.ReceiveBuffersCount * Unsafe.SizeOf<HipcBufferDescriptor>());
+ data = data[(meta.ReceiveBuffersCount * Unsafe.SizeOf<HipcBufferDescriptor>())..];
}
Span<HipcBufferDescriptor> exchangeBuffers = Span<HipcBufferDescriptor>.Empty;
if (meta.ExchangeBuffersCount != 0)
{
- exchangeBuffers = MemoryMarshal.Cast<byte, HipcBufferDescriptor>(data).Slice(0, meta.ExchangeBuffersCount);
+ exchangeBuffers = MemoryMarshal.Cast<byte, HipcBufferDescriptor>(data)[..meta.ExchangeBuffersCount];
- data = data.Slice(meta.ExchangeBuffersCount * Unsafe.SizeOf<HipcBufferDescriptor>());
+ data = data[(meta.ExchangeBuffersCount * Unsafe.SizeOf<HipcBufferDescriptor>())..];
}
Span<uint> dataWords = Span<uint>.Empty;
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).Slice(padding, meta.DataWordsCount - padding);
+ dataWords = MemoryMarshal.Cast<byte, uint>(data)[padding..meta.DataWordsCount];
- data = data.Slice(meta.DataWordsCount * sizeof(uint));
+ data = data[(meta.DataWordsCount * sizeof(uint))..];
}
Span<HipcReceiveListEntry> receiveList = Span<HipcReceiveListEntry>.Empty;
@@ -203,19 +199,19 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{
int receiveListSize = meta.ReceiveStaticsCount == AutoReceiveStatic ? 1 : meta.ReceiveStaticsCount;
- receiveList = MemoryMarshal.Cast<byte, HipcReceiveListEntry>(data).Slice(0, receiveListSize);
+ receiveList = MemoryMarshal.Cast<byte, HipcReceiveListEntry>(data)[..receiveListSize];
}
return new HipcMessageData()
{
- SendStatics = sendStatics,
- SendBuffers = sendBuffers,
- ReceiveBuffers = receiveBuffers,
+ SendStatics = sendStatics,
+ SendBuffers = sendBuffers,
+ ReceiveBuffers = receiveBuffers,
ExchangeBuffers = exchangeBuffers,
- DataWords = dataWords,
- ReceiveList = receiveList,
- CopyHandles = copyHandles,
- MoveHandles = moveHandles
+ DataWords = dataWords,
+ ReceiveList = receiveList,
+ CopyHandles = copyHandles,
+ MoveHandles = moveHandles
};
}
}
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessageData.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessageData.cs
index c83c422c..154b8f07 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessageData.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMessageData.cs
@@ -8,9 +8,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
public Span<HipcBufferDescriptor> SendBuffers;
public Span<HipcBufferDescriptor> ReceiveBuffers;
public Span<HipcBufferDescriptor> ExchangeBuffers;
- public Span<uint> DataWords;
+ public Span<uint> DataWords;
public Span<HipcReceiveListEntry> ReceiveList;
- public Span<int> CopyHandles;
- public Span<int> MoveHandles;
+ public Span<int> CopyHandles;
+ public Span<int> MoveHandles;
}
-}
+} \ No newline at end of file
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMetadata.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMetadata.cs
index fe13137a..10abc400 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMetadata.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcMetadata.cs
@@ -2,15 +2,15 @@
{
struct HipcMetadata
{
- public int Type;
- public int SendStaticsCount;
- public int SendBuffersCount;
- public int ReceiveBuffersCount;
- public int ExchangeBuffersCount;
- public int DataWordsCount;
- public int ReceiveStaticsCount;
+ public int Type;
+ public int SendStaticsCount;
+ public int SendBuffersCount;
+ public int ReceiveBuffersCount;
+ public int ExchangeBuffersCount;
+ public int DataWordsCount;
+ public int ReceiveStaticsCount;
public bool SendPid;
- public int CopyHandlesCount;
- public int MoveHandlesCount;
+ public int CopyHandlesCount;
+ public int MoveHandlesCount;
}
}
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcReceiveListEntry.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcReceiveListEntry.cs
index 94bf0968..56cf16fb 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcReceiveListEntry.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcReceiveListEntry.cs
@@ -8,7 +8,7 @@
public HipcReceiveListEntry(ulong address, ulong size)
{
_addressLow = (uint)address;
- _word1 = (ushort)(address >> 32) | (uint)(size << 16);
+ _word1 = (ushort)(address >> 32) | (uint)(size << 16);
}
}
}
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcResult.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcResult.cs
index ef989a98..3b483be8 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcResult.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcResult.cs
@@ -6,17 +6,14 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{
public const int ModuleId = 11;
- public static Result OutOfSessionMemory => new Result(ModuleId, 102);
- public static Result OutOfSessions => new Result(ModuleId, 131);
- public static Result PointerBufferTooSmall => new Result(ModuleId, 141);
- public static Result OutOfDomains => new Result(ModuleId, 200);
-
- public static Result InvalidRequestSize => new Result(ModuleId, 402);
- public static Result UnknownCommandType => new Result(ModuleId, 403);
-
- public static Result InvalidCmifRequest => new Result(ModuleId, 420);
-
- public static Result TargetNotDomain => new Result(ModuleId, 491);
- public static Result DomainObjectNotFound => new Result(ModuleId, 492);
+ public static Result OutOfSessionMemory => new(ModuleId, 102);
+ public static Result OutOfSessions => new(ModuleId, 131);
+ public static Result PointerBufferTooSmall => new(ModuleId, 141);
+ public static Result OutOfDomains => new(ModuleId, 200);
+ public static Result InvalidRequestSize => new(ModuleId, 402);
+ public static Result UnknownCommandType => new(ModuleId, 403);
+ public static Result InvalidCmifRequest => new(ModuleId, 420);
+ public static Result TargetNotDomain => new(ModuleId, 491);
+ public static Result DomainObjectNotFound => new(ModuleId, 492);
}
}
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcStaticDescriptor.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcStaticDescriptor.cs
index 5cebf47c..103820a6 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcStaticDescriptor.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/HipcStaticDescriptor.cs
@@ -4,9 +4,9 @@
{
private readonly ulong _data;
- public ulong Address => ((((_data >> 2) & 0x70) | ((_data >> 12) & 0xf)) << 32) | (_data >> 32);
- public ushort Size => (ushort)(_data >> 16);
- public int ReceiveIndex => (int)(_data & 0xf);
+ public ulong Address => ((((_data >> 2) & 0x70) | ((_data >> 12) & 0xf)) << 32) | (_data >> 32);
+ public ushort Size => (ushort)(_data >> 16);
+ public int ReceiveIndex => (int)(_data & 0xf);
public HipcStaticDescriptor(ulong address, ushort size, int receiveIndex)
{
@@ -19,4 +19,4 @@
_data = data;
}
}
-}
+} \ No newline at end of file
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/ManagerOptions.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/ManagerOptions.cs
index e087cb22..b99d63c5 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/ManagerOptions.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/ManagerOptions.cs
@@ -2,19 +2,19 @@
{
struct ManagerOptions
{
- public static ManagerOptions Default => new ManagerOptions(0, 0, 0, false);
+ public static ManagerOptions Default => new(0, 0, 0, false);
- public int PointerBufferSize { get; }
- public int MaxDomains { get; }
- public int MaxDomainObjects { get; }
+ public int PointerBufferSize { get; }
+ public int MaxDomains { get; }
+ public int MaxDomainObjects { get; }
public bool CanDeferInvokeRequest { get; }
public ManagerOptions(int pointerBufferSize, int maxDomains, int maxDomainObjects, bool canDeferInvokeRequest)
{
- PointerBufferSize = pointerBufferSize;
- MaxDomains = maxDomains;
- MaxDomainObjects = maxDomainObjects;
+ PointerBufferSize = pointerBufferSize;
+ MaxDomains = maxDomains;
+ MaxDomainObjects = maxDomainObjects;
CanDeferInvokeRequest = canDeferInvokeRequest;
}
}
-}
+} \ No newline at end of file
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/Server.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/Server.cs
index 923f2d52..bbbab898 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/Server.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/Server.cs
@@ -6,22 +6,22 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{
class Server : MultiWaitHolderOfHandle
{
- public int PortIndex { get; }
- public int PortHandle { get; }
- public ServiceName Name { get; }
- public bool Managed { get; }
+ public int PortIndex { get; }
+ public int PortHandle { get; }
+ public ServiceName Name { get; }
+ public bool Managed { get; }
public ServiceObjectHolder StaticObject { get; }
public Server(
- int portIndex,
- int portHandle,
- ServiceName name,
- bool managed,
+ int portIndex,
+ int portHandle,
+ ServiceName name,
+ bool managed,
ServiceObjectHolder staticHoder) : base(portHandle)
{
PortHandle = portHandle;
- Name = name;
- Managed = managed;
+ Name = name;
+ Managed = managed;
if (staticHoder != null)
{
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerDomainSessionManager.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerDomainSessionManager.cs
index d920a659..dda77539 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerDomainSessionManager.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerDomainSessionManager.cs
@@ -15,7 +15,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
protected override Result DispatchManagerRequest(ServerSession session, Span<byte> inMessage, Span<byte> outMessage)
{
- HipcManager hipcManager = new HipcManager(this, session);
+ HipcManager hipcManager = new(this, session);
return DispatchRequest(new ServiceObjectHolder(hipcManager), session, inMessage, outMessage);
}
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs
index 5bb2de25..2ca9ceea 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManager.cs
@@ -80,7 +80,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
return null;
}
- ServerSession session = new ServerSession(sessionIndex, sessionHandle, obj);
+ ServerSession session = new(sessionIndex, sessionHandle, obj);
_sessions.Add(session);
@@ -111,7 +111,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{
lock (_resourceLock)
{
- Server server = new Server(portIndex, portHandle, name, managed, staticHoder);
+ Server server = new(portIndex, portHandle, name, managed, staticHoder);
_servers.Add(server);
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs
index 68cae6bc..9d21290d 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerManagerBase.cs
@@ -26,7 +26,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
private enum UserDataTag
{
- Server = 1,
+ Server = 1,
Session = 2
}
@@ -36,16 +36,17 @@ 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);
+
_notifyEventHolder = new MultiWaitHolderOfEvent(_notifyEvent);
_multiWait.LinkMultiWaitHolder(_notifyEventHolder);
}
@@ -73,6 +74,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
private void RegisterServerImpl(int portIndex, ServiceObjectHolder staticHolder, int portHandle)
{
Server server = AllocateServer(portIndex, portHandle, ServiceName.Invalid, managed: false, staticHolder);
+
RegisterServerImpl(server);
}
@@ -86,6 +88,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
}
Server server = AllocateServer(portIndex, portHandle, name, managed: true, staticHolder);
+
RegisterServerImpl(server);
return Result.Success;
@@ -103,6 +106,11 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
throw new NotSupportedException();
}
+ protected Result AcceptImpl(Server server, IServiceObject obj)
+ {
+ return AcceptSession(server.PortHandle, new ServiceObjectHolder(obj));
+ }
+
public void ServiceRequests()
{
while (WaitAndProcessRequestsImpl());
@@ -175,7 +183,8 @@ 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);
}
@@ -198,15 +207,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
private Result Process(MultiWaitHolder holder)
{
- switch ((UserDataTag)holder.UserData)
+ return (UserDataTag)holder.UserData switch
{
- case UserDataTag.Server:
- return ProcessForServer(holder);
- case UserDataTag.Session:
- return ProcessForSession(holder);
- default:
- throw new NotImplementedException(((UserDataTag)holder.UserData).ToString());
- }
+ UserDataTag.Server => ProcessForServer(holder),
+ UserDataTag.Session => ProcessForSession(holder),
+ _ => throw new NotImplementedException(((UserDataTag)holder.UserData).ToString())
+ };
}
private Result ProcessForServer(MultiWaitHolder holder)
@@ -259,6 +265,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
}
session.HasReceived = true;
+
tlsMessage.Memory.Span.CopyTo(savedMessage.Memory.Span);
}
else
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSession.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSession.cs
index eb98fefd..a1730082 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSession.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSession.cs
@@ -6,18 +6,18 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
class ServerSession : MultiWaitHolderOfHandle
{
public ServiceObjectHolder ServiceObjectHolder { get; set; }
- public PointerAndSize PointerBuffer { get; set; }
- public PointerAndSize SavedMessage { get; set; }
- public int SessionIndex { get; }
- public int SessionHandle { get; }
- public bool IsClosed { get; set; }
- public bool HasReceived { get; set; }
+ public PointerAndSize PointerBuffer { get; set; }
+ public PointerAndSize SavedMessage { get; set; }
+ public int SessionIndex { get; }
+ public int SessionHandle { get; }
+ public bool IsClosed { get; set; }
+ public bool HasReceived { get; set; }
public ServerSession(int index, int handle, ServiceObjectHolder obj) : base(handle)
{
ServiceObjectHolder = obj;
- SessionIndex = index;
- SessionHandle = handle;
+ SessionIndex = index;
+ SessionHandle = handle;
}
}
}
diff --git a/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSessionManager.cs b/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSessionManager.cs
index e85892f2..6d395081 100644
--- a/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSessionManager.cs
+++ b/Ryujinx.Horizon/Sdk/Sf/Hipc/ServerSessionManager.cs
@@ -75,9 +75,10 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
}
session.PointerBuffer = GetSessionPointerBuffer(session);
- session.SavedMessage = GetSessionSavedMessageBuffer(session);
+ session.SavedMessage = GetSessionSavedMessageBuffer(session);
RegisterSessionToWaitList(session);
+
return Result.Success;
}
@@ -109,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();
@@ -141,6 +142,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
protected void CloseSessionImpl(ServerSession session)
{
int sessionHandle = session.Handle;
+
Os.FinalizeMultiWaitHolder(session);
DestroySession(session);
HorizonStatic.Syscall.CloseHandle(sessionHandle).AbortOnFailure();
@@ -156,6 +158,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
if (session.IsClosed || GetCmifCommandType(message) == CommandType.Close)
{
CloseSessionImpl(session);
+
return Result.Success;
}
else
@@ -165,6 +168,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
if (result.IsSuccess)
{
RegisterSessionToWaitList(session);
+
return Result.Success;
}
else if (SfResult.RequestContextChanged(result))
@@ -176,6 +180,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
Logger.Warning?.Print(LogClass.KernelIpc, $"Request processing returned error {result}");
CloseSessionImpl(session);
+
return Result.Success;
}
}
@@ -197,8 +202,8 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
return DispatchManagerRequest(session, inMessage, outMessage);
default:
return HipcResult.UnknownCommandType;
- }
}
+ }
private static int GetInlineContext(CommandType commandType, ReadOnlySpan<byte> inMessage)
{
@@ -231,7 +236,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
{
HipcMessageData messageData = HipcMessage.WriteMessage(message, new HipcMetadata()
{
- Type = (int)CommandType.Invalid,
+ Type = (int)CommandType.Invalid,
ReceiveStaticsCount = HipcMessage.AutoReceiveStatic
});
@@ -271,9 +276,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;
@@ -288,14 +293,14 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
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);
@@ -332,4 +337,4 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
return this;
}
}
-}
+} \ No newline at end of file