aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/IpcService.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-12-01 20:23:43 -0300
committerGitHub <noreply@github.com>2020-12-02 00:23:43 +0100
commitcf6cd714884c41e9550757e364c2f4f5b04fc7f3 (patch)
treebea748b4d1a350e5b8075d63ec9d39d49693829d /Ryujinx.HLE/HOS/Services/IpcService.cs
parent461c24092ae6e148d896c18aa3e86220c89981f8 (diff)
IPC refactor part 2: Use ReplyAndReceive on HLE services and remove special handling from kernel (#1458)
* IPC refactor part 2: Use ReplyAndReceive on HLE services and remove special handling from kernel * Fix for applet transfer memory + some nits * Keep handles if possible to avoid server handle table exhaustion * Fix IPC ZeroFill bug * am: Correctly implement CreateManagedDisplayLayer and implement CreateManagedDisplaySeparableLayer CreateManagedDisplaySeparableLayer is requires since 10.x+ when appletResourceUserId != 0 * Make it exit properly * Make ServiceNotImplementedException show the full message again * Allow yielding execution to avoid starving other threads * Only wait if active * Merge IVirtualMemoryManager and IAddressSpaceManager * Fix Ro loading data from the wrong process Co-authored-by: Thog <me@thog.eu>
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/IpcService.cs')
-rw-r--r--Ryujinx.HLE/HOS/Services/IpcService.cs62
1 files changed, 24 insertions, 38 deletions
diff --git a/Ryujinx.HLE/HOS/Services/IpcService.cs b/Ryujinx.HLE/HOS/Services/IpcService.cs
index 9d40d80f..f9858107 100644
--- a/Ryujinx.HLE/HOS/Services/IpcService.cs
+++ b/Ryujinx.HLE/HOS/Services/IpcService.cs
@@ -1,8 +1,6 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.Exceptions;
using Ryujinx.HLE.HOS.Ipc;
-using Ryujinx.HLE.HOS.Kernel.Common;
-using Ryujinx.HLE.HOS.Kernel.Ipc;
using System;
using System.Collections.Generic;
using System.IO;
@@ -17,6 +15,7 @@ namespace Ryujinx.HLE.HOS.Services
public ServerBase Server { get; private set; }
+ private IpcService _parent;
private IdDictionary _domainObjects;
private int _selfId;
private bool _isDomain;
@@ -32,6 +31,7 @@ namespace Ryujinx.HLE.HOS.Services
Server = server;
+ _parent = this;
_domainObjects = new IdDictionary();
_selfId = -1;
}
@@ -62,8 +62,8 @@ namespace Ryujinx.HLE.HOS.Services
int domainWord0 = context.RequestData.ReadInt32();
int domainObjId = context.RequestData.ReadInt32();
- int domainCmd = (domainWord0 >> 0) & 0xff;
- int inputObjCount = (domainWord0 >> 8) & 0xff;
+ int domainCmd = (domainWord0 >> 0) & 0xff;
+ int inputObjCount = (domainWord0 >> 8) & 0xff;
int dataPayloadSize = (domainWord0 >> 16) & 0xffff;
context.RequestData.BaseStream.Seek(0x10 + dataPayloadSize, SeekOrigin.Begin);
@@ -96,8 +96,8 @@ namespace Ryujinx.HLE.HOS.Services
}
}
- long sfciMagic = context.RequestData.ReadInt64();
- int commandId = (int)context.RequestData.ReadInt64();
+ long sfciMagic = context.RequestData.ReadInt64();
+ int commandId = (int)context.RequestData.ReadInt64();
bool serviceExists = service.Commands.TryGetValue(commandId, out MethodInfo processRequest);
@@ -145,56 +145,37 @@ namespace Ryujinx.HLE.HOS.Services
{
string dbgMessage = $"{service.GetType().FullName}: {commandId}";
- throw new ServiceNotImplementedException(context, dbgMessage);
+ throw new ServiceNotImplementedException(service, context, dbgMessage);
}
}
- protected static void MakeObject(ServiceCtx context, IpcService obj)
+ protected void MakeObject(ServiceCtx context, IpcService obj)
{
- IpcService service = context.Session.Service;
+ obj.TrySetServer(_parent.Server);
- obj.TrySetServer(service.Server);
-
- if (service._isDomain)
+ if (_parent._isDomain)
{
- context.Response.ObjectIds.Add(service.Add(obj));
+ obj._parent = _parent;
+
+ context.Response.ObjectIds.Add(_parent.Add(obj));
}
else
{
- KSession session = new KSession(context.Device.System.KernelContext);
-
- session.ClientSession.Service = obj;
-
- if (context.Process.HandleTable.GenerateHandle(session.ClientSession, out int handle) != KernelResult.Success)
- {
- throw new InvalidOperationException("Out of handles!");
- }
+ context.Device.System.KernelContext.Syscall.CreateSession(false, 0, out int serverSessionHandle, out int clientSessionHandle);
- session.ServerSession.DecrementReferenceCount();
- session.ClientSession.DecrementReferenceCount();
+ obj.Server.AddSessionObj(serverSessionHandle, obj);
- context.Response.HandleDesc = IpcHandleDesc.MakeMove(handle);
+ context.Response.HandleDesc = IpcHandleDesc.MakeMove(clientSessionHandle);
}
}
- protected static T GetObject<T>(ServiceCtx context, int index) where T : IpcService
+ protected T GetObject<T>(ServiceCtx context, int index) where T : IpcService
{
- IpcService service = context.Session.Service;
-
- if (!service._isDomain)
- {
- int handle = context.Request.HandleDesc.ToMove[index];
-
- KClientSession session = context.Process.HandleTable.GetObject<KClientSession>(handle);
-
- return session?.Service is T ? (T)session.Service : null;
- }
-
int objId = context.Request.ObjectIds[index];
- IIpcService obj = service.GetObject(objId);
+ IIpcService obj = _parent.GetObject(objId);
- return obj is T ? (T)obj : null;
+ return obj is T t ? t : null;
}
public bool TrySetServer(ServerBase newServer)
@@ -230,5 +211,10 @@ namespace Ryujinx.HLE.HOS.Services
{
return _domainObjects.GetData<IIpcService>(id);
}
+
+ public void SetParent(IpcService parent)
+ {
+ _parent = parent._parent;
+ }
}
}