aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/IpcService.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2018-08-16 20:47:36 -0300
committerGitHub <noreply@github.com>2018-08-16 20:47:36 -0300
commit521751795a1c97c0d97f6f8904a3be69b13d3a9d (patch)
tree942a05899c40e2de6d92a38b93a494bd96ee64b8 /Ryujinx.HLE/HOS/Services/IpcService.cs
parent182d716867ae477c2b15a5332430dc2641fa1cc3 (diff)
Code style fixes and nits on the HLE project (#355)
* Some style fixes and nits on ITimeZoneService * Remove some unneeded usings * Remove the Ryujinx.HLE.OsHle.Handles namespace * Remove hbmenu automatic load on process exit * Rename Ns to Device, rename Os to System, rename SystemState to State * Move Exceptions and Utilities out of OsHle * Rename OsHle to HOS * Rename OsHle folder to HOS * IManagerDisplayService and ISystemDisplayService style fixes * BsdError shouldn't be public * Add a empty new line before using static * Remove unused file * Some style fixes on NPDM * Exit gracefully when the application is closed * Code style fixes on IGeneralService * Add 0x prefix on values printed as hex * Small improvements on finalization code * Move ProcessId and ThreadId out of AThreadState * Rename VFs to FileSystem * FsAccessHeader shouldn't be public. Also fix file names casing * More case changes on NPDM * Remove unused files * Move using to the correct place on NPDM * Use properties on KernelAccessControlMmio * Address PR feedback
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/IpcService.cs')
-rw-r--r--Ryujinx.HLE/HOS/Services/IpcService.cs183
1 files changed, 183 insertions, 0 deletions
diff --git a/Ryujinx.HLE/HOS/Services/IpcService.cs b/Ryujinx.HLE/HOS/Services/IpcService.cs
new file mode 100644
index 00000000..8e487d55
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/IpcService.cs
@@ -0,0 +1,183 @@
+using Ryujinx.HLE.HOS.Ipc;
+using Ryujinx.HLE.HOS.Kernel;
+using Ryujinx.HLE.Logging;
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace Ryujinx.HLE.HOS.Services
+{
+ abstract class IpcService : IIpcService
+ {
+ public abstract IReadOnlyDictionary<int, ServiceProcessRequest> Commands { get; }
+
+ private IdDictionary DomainObjects;
+
+ private int SelfId;
+
+ private bool IsDomain;
+
+ public IpcService()
+ {
+ DomainObjects = new IdDictionary();
+
+ SelfId = -1;
+ }
+
+ public int ConvertToDomain()
+ {
+ if (SelfId == -1)
+ {
+ SelfId = DomainObjects.Add(this);
+ }
+
+ IsDomain = true;
+
+ return SelfId;
+ }
+
+ public void ConvertToSession()
+ {
+ IsDomain = false;
+ }
+
+ public void CallMethod(ServiceCtx Context)
+ {
+ IIpcService Service = this;
+
+ if (IsDomain)
+ {
+ int DomainWord0 = Context.RequestData.ReadInt32();
+ int DomainObjId = Context.RequestData.ReadInt32();
+
+ int DomainCmd = (DomainWord0 >> 0) & 0xff;
+ int InputObjCount = (DomainWord0 >> 8) & 0xff;
+ int DataPayloadSize = (DomainWord0 >> 16) & 0xffff;
+
+ Context.RequestData.BaseStream.Seek(0x10 + DataPayloadSize, SeekOrigin.Begin);
+
+ for (int Index = 0; Index < InputObjCount; Index++)
+ {
+ Context.Request.ObjectIds.Add(Context.RequestData.ReadInt32());
+ }
+
+ Context.RequestData.BaseStream.Seek(0x10, SeekOrigin.Begin);
+
+ if (DomainCmd == 1)
+ {
+ Service = GetObject(DomainObjId);
+
+ Context.ResponseData.Write(0L);
+ Context.ResponseData.Write(0L);
+ }
+ else if (DomainCmd == 2)
+ {
+ Delete(DomainObjId);
+
+ Context.ResponseData.Write(0L);
+
+ return;
+ }
+ else
+ {
+ throw new NotImplementedException($"Domain command: {DomainCmd}");
+ }
+ }
+
+ long SfciMagic = Context.RequestData.ReadInt64();
+ int CommandId = (int)Context.RequestData.ReadInt64();
+
+ if (Service.Commands.TryGetValue(CommandId, out ServiceProcessRequest ProcessRequest))
+ {
+ Context.ResponseData.BaseStream.Seek(IsDomain ? 0x20 : 0x10, SeekOrigin.Begin);
+
+ Context.Device.Log.PrintDebug(LogClass.KernelIpc, $"{Service.GetType().Name}: {ProcessRequest.Method.Name}");
+
+ long Result = ProcessRequest(Context);
+
+ if (IsDomain)
+ {
+ foreach (int Id in Context.Response.ObjectIds)
+ {
+ Context.ResponseData.Write(Id);
+ }
+
+ Context.ResponseData.BaseStream.Seek(0, SeekOrigin.Begin);
+
+ Context.ResponseData.Write(Context.Response.ObjectIds.Count);
+ }
+
+ Context.ResponseData.BaseStream.Seek(IsDomain ? 0x10 : 0, SeekOrigin.Begin);
+
+ Context.ResponseData.Write(IpcMagic.Sfco);
+ Context.ResponseData.Write(Result);
+ }
+ else
+ {
+ string DbgMessage = $"{Context.Session.ServiceName} {Service.GetType().Name}: {CommandId}";
+
+ throw new NotImplementedException(DbgMessage);
+ }
+ }
+
+ protected static void MakeObject(ServiceCtx Context, IpcService Obj)
+ {
+ IpcService Service = Context.Session.Service;
+
+ if (Service.IsDomain)
+ {
+ Context.Response.ObjectIds.Add(Service.Add(Obj));
+ }
+ else
+ {
+ KSession Session = new KSession(Obj, Context.Session.ServiceName);
+
+ int Handle = Context.Process.HandleTable.OpenHandle(Session);
+
+ Context.Response.HandleDesc = IpcHandleDesc.MakeMove(Handle);
+ }
+ }
+
+ protected static 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];
+
+ KSession Session = Context.Process.HandleTable.GetData<KSession>(Handle);
+
+ return Session?.Service is T ? (T)Session.Service : null;
+ }
+
+ int ObjId = Context.Request.ObjectIds[Index];
+
+ IIpcService Obj = Service.GetObject(ObjId);
+
+ return Obj is T ? (T)Obj : null;
+ }
+
+ private int Add(IIpcService Obj)
+ {
+ return DomainObjects.Add(Obj);
+ }
+
+ private bool Delete(int Id)
+ {
+ object Obj = DomainObjects.Delete(Id);
+
+ if (Obj is IDisposable DisposableObj)
+ {
+ DisposableObj.Dispose();
+ }
+
+ return Obj != null;
+ }
+
+ private IIpcService GetObject(int Id)
+ {
+ return DomainObjects.GetData<IIpcService>(Id);
+ }
+ }
+} \ No newline at end of file