aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2019-01-18 20:26:39 -0200
committerGitHub <noreply@github.com>2019-01-18 20:26:39 -0200
commit22bacc618815170c0d186a82e1ea4558e36b7063 (patch)
tree79b97959481fea1ac301da6d4e9dea9b991ece6f /Ryujinx.HLE/HOS/Services
parent3731d0ce8412c3c48286c242842bcb4940b4ca6d (diff)
Improve kernel IPC implementation (#550)
* Implement some IPC related kernel SVCs properly * Fix BLZ decompression when the segment also has a uncompressed chunck * Set default cpu core on process start from ProgramLoader, remove debug message * Load process capabilities properly on KIPs * Fix a copy/paste error in UnmapPhysicalMemory64 * Implement smarter switching between old and new IPC system to support the old HLE services implementation without the manual switch * Implement RegisterService on sm and AcceptSession (partial) * Misc fixes and improvements on new IPC methods * Move IPC related SVCs into a separate file, and logging on RegisterService (sm) * Some small fixes related to receive list buffers and error cases * Load NSOs using the correct pool partition * Fix corner case on GetMaskFromMinMax where range is 64, doesn't happen in pratice however * Fix send static buffer copy * Session release, implement closing requests on client disconnect * Implement ConnectToPort SVC * KLightSession init
Diffstat (limited to 'Ryujinx.HLE/HOS/Services')
-rw-r--r--Ryujinx.HLE/HOS/Services/IpcService.cs10
-rw-r--r--Ryujinx.HLE/HOS/Services/Psm/IPsmSession.cs2
-rw-r--r--Ryujinx.HLE/HOS/Services/Sm/IUserInterface.cs106
-rw-r--r--Ryujinx.HLE/HOS/Services/Sm/SmErr.cs9
4 files changed, 107 insertions, 20 deletions
diff --git a/Ryujinx.HLE/HOS/Services/IpcService.cs b/Ryujinx.HLE/HOS/Services/IpcService.cs
index 5c7fa18d..71683ce3 100644
--- a/Ryujinx.HLE/HOS/Services/IpcService.cs
+++ b/Ryujinx.HLE/HOS/Services/IpcService.cs
@@ -116,7 +116,7 @@ namespace Ryujinx.HLE.HOS.Services
}
else
{
- string dbgMessage = $"{context.Session.ServiceName} {service.GetType().Name}: {commandId}";
+ string dbgMessage = $"{service.GetType().FullName}: {commandId}";
throw new ServiceNotImplementedException(context, dbgMessage);
}
@@ -132,9 +132,11 @@ namespace Ryujinx.HLE.HOS.Services
}
else
{
- KSession session = new KSession(obj, context.Session.ServiceName);
+ KSession session = new KSession(context.Device.System);
- if (context.Process.HandleTable.GenerateHandle(session, out int handle) != KernelResult.Success)
+ session.ClientSession.Service = obj;
+
+ if (context.Process.HandleTable.GenerateHandle(session.ClientSession, out int handle) != KernelResult.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -151,7 +153,7 @@ namespace Ryujinx.HLE.HOS.Services
{
int handle = context.Request.HandleDesc.ToMove[index];
- KSession session = context.Process.HandleTable.GetObject<KSession>(handle);
+ KClientSession session = context.Process.HandleTable.GetObject<KClientSession>(handle);
return session?.Service is T ? (T)session.Service : null;
}
diff --git a/Ryujinx.HLE/HOS/Services/Psm/IPsmSession.cs b/Ryujinx.HLE/HOS/Services/Psm/IPsmSession.cs
index aeeeb052..3db3bd27 100644
--- a/Ryujinx.HLE/HOS/Services/Psm/IPsmSession.cs
+++ b/Ryujinx.HLE/HOS/Services/Psm/IPsmSession.cs
@@ -35,7 +35,7 @@ namespace Ryujinx.HLE.HOS.Services.Psm
{
if (_stateChangeEventHandle == -1)
{
- KernelResult resultCode = context.Process.HandleTable.GenerateHandle(_stateChangeEvent, out int stateChangeEventHandle);
+ KernelResult resultCode = context.Process.HandleTable.GenerateHandle(_stateChangeEvent.ReadableEvent, out int stateChangeEventHandle);
if (resultCode != KernelResult.Success)
{
diff --git a/Ryujinx.HLE/HOS/Services/Sm/IUserInterface.cs b/Ryujinx.HLE/HOS/Services/Sm/IUserInterface.cs
index df551a41..6940bfc8 100644
--- a/Ryujinx.HLE/HOS/Services/Sm/IUserInterface.cs
+++ b/Ryujinx.HLE/HOS/Services/Sm/IUserInterface.cs
@@ -1,8 +1,11 @@
+using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Ipc;
using System;
+using System.Collections.Concurrent;
using System.Collections.Generic;
+using System.IO;
namespace Ryujinx.HLE.HOS.Services.Sm
{
@@ -12,18 +15,30 @@ namespace Ryujinx.HLE.HOS.Services.Sm
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
+ private ConcurrentDictionary<string, KPort> _registeredServices;
+
private bool _isInitialized;
public IUserInterface()
{
_commands = new Dictionary<int, ServiceProcessRequest>
{
- { 0, Initialize },
- { 1, GetService }
+ { 0, Initialize },
+ { 1, GetService },
+ { 2, RegisterService }
};
+
+ _registeredServices = new ConcurrentDictionary<string, KPort>();
}
- private const int SmNotInitialized = 0x415;
+ public static void InitializePort(Horizon system)
+ {
+ KPort port = new KPort(system, 256, false, 0);
+
+ port.ClientPort.SetName("sm:");
+
+ port.ClientPort.Service = new IUserInterface();
+ }
public long Initialize(ServiceCtx context)
{
@@ -34,34 +49,76 @@ namespace Ryujinx.HLE.HOS.Services.Sm
public long GetService(ServiceCtx context)
{
- //Only for kernel version > 3.0.0.
if (!_isInitialized)
{
- //return SmNotInitialized;
+ return ErrorCode.MakeError(ErrorModule.Sm, SmErr.NotInitialized);
}
- string name = string.Empty;
+ string name = ReadName(context);
- for (int index = 0; index < 8 &&
- context.RequestData.BaseStream.Position <
- context.RequestData.BaseStream.Length; index++)
+ if (name == string.Empty)
{
- byte chr = context.RequestData.ReadByte();
+ return ErrorCode.MakeError(ErrorModule.Sm, SmErr.InvalidName);
+ }
- if (chr >= 0x20 && chr < 0x7f)
+ KSession session = new KSession(context.Device.System);
+
+ if (_registeredServices.TryGetValue(name, out KPort port))
+ {
+ KernelResult result = port.EnqueueIncomingSession(session.ServerSession);
+
+ if (result != KernelResult.Success)
{
- name += (char)chr;
+ throw new InvalidOperationException($"Session enqueue on port returned error \"{result}\".");
}
}
+ else
+ {
+ session.ClientSession.Service = ServiceFactory.MakeService(context.Device.System, name);
+ }
+
+ if (context.Process.HandleTable.GenerateHandle(session.ClientSession, out int handle) != KernelResult.Success)
+ {
+ throw new InvalidOperationException("Out of handles!");
+ }
+
+ context.Response.HandleDesc = IpcHandleDesc.MakeMove(handle);
+
+ return 0;
+ }
+
+ public long RegisterService(ServiceCtx context)
+ {
+ if (!_isInitialized)
+ {
+ return ErrorCode.MakeError(ErrorModule.Sm, SmErr.NotInitialized);
+ }
+
+ long namePosition = context.RequestData.BaseStream.Position;
+
+ string name = ReadName(context);
+
+ context.RequestData.BaseStream.Seek(namePosition + 8, SeekOrigin.Begin);
+
+ bool isLight = (context.RequestData.ReadInt32() & 1) != 0;
+
+ int maxSessions = context.RequestData.ReadInt32();
if (name == string.Empty)
{
- return 0;
+ return ErrorCode.MakeError(ErrorModule.Sm, SmErr.InvalidName);
}
- KSession session = new KSession(ServiceFactory.MakeService(context.Device.System, name), name);
+ Logger.PrintInfo(LogClass.ServiceSm, $"Register \"{name}\".");
+
+ KPort port = new KPort(context.Device.System, maxSessions, isLight, 0);
- if (context.Process.HandleTable.GenerateHandle(session, out int handle) != KernelResult.Success)
+ if (!_registeredServices.TryAdd(name, port))
+ {
+ return ErrorCode.MakeError(ErrorModule.Sm, SmErr.AlreadyRegistered);
+ }
+
+ if (context.Process.HandleTable.GenerateHandle(port.ServerPort, out int handle) != KernelResult.Success)
{
throw new InvalidOperationException("Out of handles!");
}
@@ -70,5 +127,24 @@ namespace Ryujinx.HLE.HOS.Services.Sm
return 0;
}
+
+ private static string ReadName(ServiceCtx context)
+ {
+ string name = string.Empty;
+
+ for (int index = 0; index < 8 &&
+ context.RequestData.BaseStream.Position <
+ context.RequestData.BaseStream.Length; index++)
+ {
+ byte chr = context.RequestData.ReadByte();
+
+ if (chr >= 0x20 && chr < 0x7f)
+ {
+ name += (char)chr;
+ }
+ }
+
+ return name;
+ }
}
} \ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Sm/SmErr.cs b/Ryujinx.HLE/HOS/Services/Sm/SmErr.cs
new file mode 100644
index 00000000..5b5a66dc
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Sm/SmErr.cs
@@ -0,0 +1,9 @@
+namespace Ryujinx.HLE.HOS.Services.Sm
+{
+ static class SmErr
+ {
+ public const int NotInitialized = 2;
+ public const int AlreadyRegistered = 4;
+ public const int InvalidName = 6;
+ }
+} \ No newline at end of file