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;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
public KernelResult SendSyncRequest(ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
|
|
|
|
{
|
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;
|
|
|
|
currentThread.ObjSyncResult = KernelResult.Success;
|
|
|
|
|
|
|
|
KernelResult result = _parent.ServerSession.EnqueueRequest(request);
|
|
|
|
|
2020-05-04 05:41:29 +02:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 23:26:39 +01:00
|
|
|
|
|
|
|
if (result == KernelResult.Success)
|
|
|
|
{
|
|
|
|
result = currentThread.ObjSyncResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-07-17 06:19:07 +02:00
|
|
|
public KernelResult SendAsyncRequest(KWritableEvent asyncEvent, ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
|
|
|
|
{
|
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();
|
|
|
|
|
|
|
|
KernelResult result = _parent.ServerSession.EnqueueRequest(request);
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|