2019-01-18 23:26:39 +01:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Process;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2023-01-04 23:15:45 +01:00
|
|
|
using Ryujinx.Horizon.Common;
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Ipc
|
|
|
|
{
|
|
|
|
class KClientSession : KSynchronizationObject
|
|
|
|
{
|
|
|
|
public KProcess CreatorProcess { get; }
|
|
|
|
|
|
|
|
private KSession _parent;
|
|
|
|
|
|
|
|
public ChannelState State { get; set; }
|
|
|
|
|
2020-07-17 06:19:07 +02:00
|
|
|
public KClientPort ParentPort { get; }
|
|
|
|
|
|
|
|
public KClientSession(KernelContext context, KSession parent, KClientPort parentPort) : base(context)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
2020-07-17 06:19:07 +02:00
|
|
|
_parent = parent;
|
|
|
|
ParentPort = parentPort;
|
|
|
|
|
|
|
|
parentPort?.IncrementReferenceCount();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
State = ChannelState.Open;
|
|
|
|
|
2020-12-09 23:20:05 +01:00
|
|
|
CreatorProcess = KernelStatic.GetCurrentProcess();
|
2019-01-18 23:26:39 +01:00
|
|
|
CreatorProcess.IncrementReferenceCount();
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
public Result SendSyncRequest(ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
2020-12-09 23:20:05 +01:00
|
|
|
KThread currentThread = KernelStatic.GetCurrentThread();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
KSessionRequest request = new KSessionRequest(currentThread, customCmdBuffAddr, customCmdBuffSize);
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Enter();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
currentThread.SignaledObj = null;
|
2023-01-04 23:15:45 +01:00
|
|
|
currentThread.ObjSyncResult = Result.Success;
|
2019-01-18 23:26:39 +01:00
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
Result result = _parent.ServerSession.EnqueueRequest(request);
|
2019-01-18 23:26:39 +01:00
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
if (result == Result.Success)
|
2019-01-18 23:26:39 +01:00
|
|
|
{
|
|
|
|
result = currentThread.ObjSyncResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
public Result SendAsyncRequest(KWritableEvent asyncEvent, ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
|
2020-07-17 06:19:07 +02:00
|
|
|
{
|
2020-12-09 23:20:05 +01:00
|
|
|
KThread currentThread = KernelStatic.GetCurrentThread();
|
2020-07-17 06:19:07 +02:00
|
|
|
|
|
|
|
KSessionRequest request = new KSessionRequest(currentThread, customCmdBuffAddr, customCmdBuffSize, asyncEvent);
|
|
|
|
|
|
|
|
KernelContext.CriticalSection.Enter();
|
|
|
|
|
2023-01-04 23:15:45 +01:00
|
|
|
Result result = _parent.ServerSession.EnqueueRequest(request);
|
2020-07-17 06:19:07 +02:00
|
|
|
|
|
|
|
KernelContext.CriticalSection.Leave();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DisconnectFromPort()
|
|
|
|
{
|
|
|
|
if (ParentPort != null)
|
|
|
|
{
|
|
|
|
ParentPort.Disconnect();
|
|
|
|
ParentPort.DecrementReferenceCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-18 23:26:39 +01:00
|
|
|
protected override void Destroy()
|
|
|
|
{
|
|
|
|
_parent.DisconnectClient();
|
|
|
|
_parent.DecrementReferenceCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|