2019-01-18 17:26:39 -05: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 00:19:07 -04:00
|
|
|
public KClientPort ParentPort { get; }
|
|
|
|
|
|
|
|
public KClientSession(KernelContext context, KSession parent, KClientPort parentPort) : base(context)
|
2019-01-18 17:26:39 -05:00
|
|
|
{
|
2020-07-17 00:19:07 -04:00
|
|
|
_parent = parent;
|
|
|
|
ParentPort = parentPort;
|
|
|
|
|
|
|
|
parentPort?.IncrementReferenceCount();
|
2019-01-18 17:26:39 -05:00
|
|
|
|
|
|
|
State = ChannelState.Open;
|
|
|
|
|
2020-12-09 17:20:05 -05:00
|
|
|
CreatorProcess = KernelStatic.GetCurrentProcess();
|
2019-01-18 17:26:39 -05:00
|
|
|
CreatorProcess.IncrementReferenceCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
public KernelResult SendSyncRequest(ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
|
|
|
|
{
|
2020-12-09 17:20:05 -05:00
|
|
|
KThread currentThread = KernelStatic.GetCurrentThread();
|
2019-01-18 17:26:39 -05:00
|
|
|
|
|
|
|
KSessionRequest request = new KSessionRequest(currentThread, customCmdBuffAddr, customCmdBuffSize);
|
|
|
|
|
2020-05-03 23:41:29 -04:00
|
|
|
KernelContext.CriticalSection.Enter();
|
2019-01-18 17:26:39 -05:00
|
|
|
|
|
|
|
currentThread.SignaledObj = null;
|
|
|
|
currentThread.ObjSyncResult = KernelResult.Success;
|
|
|
|
|
|
|
|
KernelResult result = _parent.ServerSession.EnqueueRequest(request);
|
|
|
|
|
2020-05-03 23:41:29 -04:00
|
|
|
KernelContext.CriticalSection.Leave();
|
2019-01-18 17:26:39 -05:00
|
|
|
|
|
|
|
if (result == KernelResult.Success)
|
|
|
|
{
|
|
|
|
result = currentThread.ObjSyncResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-07-17 00:19:07 -04:00
|
|
|
public KernelResult SendAsyncRequest(KWritableEvent asyncEvent, ulong customCmdBuffAddr = 0, ulong customCmdBuffSize = 0)
|
|
|
|
{
|
2020-12-09 17:20:05 -05:00
|
|
|
KThread currentThread = KernelStatic.GetCurrentThread();
|
2020-07-17 00:19:07 -04: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 17:26:39 -05:00
|
|
|
protected override void Destroy()
|
|
|
|
{
|
|
|
|
_parent.DisconnectClient();
|
|
|
|
_parent.DecrementReferenceCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|