From 9e923b1473ca565df2012de10d319e336eab67f4 Mon Sep 17 00:00:00 2001 From: jduncanator <1518948+jduncanator@users.noreply.github.com> Date: Sat, 20 Apr 2019 12:23:13 +1000 Subject: [PATCH] Implement IIrSensorServer GetIrsensorSharedMemoryHandle (#664) * Implement IIrSensorServer GetIrsensorSharedMemoryHandle Resolves #620 * Set _irsSharedMem --- Ryujinx.HLE/HOS/Horizon.cs | 6 ++++ .../HOS/Services/Irs/IIrSensorServer.cs | 30 ++++++++++++++++--- Ryujinx.HLE/HOS/Services/ServiceFactory.cs | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Ryujinx.HLE/HOS/Horizon.cs b/Ryujinx.HLE/HOS/Horizon.cs index b5ce555a1..e152846e4 100644 --- a/Ryujinx.HLE/HOS/Horizon.cs +++ b/Ryujinx.HLE/HOS/Horizon.cs @@ -30,6 +30,7 @@ namespace Ryujinx.HLE.HOS internal const int HidSize = 0x40000; internal const int FontSize = 0x1100000; + internal const int IirsSize = 0x8000; private const int MemoryBlockAllocatorSize = 0x2710; @@ -81,6 +82,7 @@ namespace Ryujinx.HLE.HOS internal KSharedMemory HidSharedMem { get; private set; } internal KSharedMemory FontSharedMem { get; private set; } + internal KSharedMemory IirsSharedMem { get; private set; } internal SharedFontManager Font { get; private set; } @@ -151,17 +153,21 @@ namespace Ryujinx.HLE.HOS ulong hidPa = region.Address; ulong fontPa = region.Address + HidSize; + ulong iirsPa = region.Address + HidSize + FontSize; HidBaseAddress = (long)(hidPa - DramMemoryMap.DramBase); KPageList hidPageList = new KPageList(); KPageList fontPageList = new KPageList(); + KPageList iirsPageList = new KPageList(); hidPageList .AddRange(hidPa, HidSize / KMemoryManager.PageSize); fontPageList.AddRange(fontPa, FontSize / KMemoryManager.PageSize); + iirsPageList.AddRange(iirsPa, IirsSize / KMemoryManager.PageSize); HidSharedMem = new KSharedMemory(this, hidPageList, 0, 0, MemoryPermission.Read); FontSharedMem = new KSharedMemory(this, fontPageList, 0, 0, MemoryPermission.Read); + IirsSharedMem = new KSharedMemory(this, iirsPageList, 0, 0, MemoryPermission.Read); AppletState = new AppletStateMgr(this); diff --git a/Ryujinx.HLE/HOS/Services/Irs/IIrSensorServer.cs b/Ryujinx.HLE/HOS/Services/Irs/IIrSensorServer.cs index b63f99c84..500d5f107 100644 --- a/Ryujinx.HLE/HOS/Services/Irs/IIrSensorServer.cs +++ b/Ryujinx.HLE/HOS/Services/Irs/IIrSensorServer.cs @@ -1,6 +1,8 @@ using Ryujinx.Common.Logging; using Ryujinx.HLE.Exceptions; using Ryujinx.HLE.HOS.Ipc; +using Ryujinx.HLE.HOS.Kernel.Common; +using Ryujinx.HLE.HOS.Kernel.Memory; using System; using System.Collections.Generic; @@ -12,14 +14,19 @@ namespace Ryujinx.HLE.HOS.Services.Irs public override IReadOnlyDictionary Commands => _commands; - public IIrSensorServer() + private KSharedMemory _irsSharedMem; + + public IIrSensorServer(KSharedMemory irsSharedMem) { _commands = new Dictionary { - { 302, ActivateIrsensor }, - { 303, DeactivateIrsensor }, - { 311, GetNpadIrCameraHandle } + { 302, ActivateIrsensor }, + { 303, DeactivateIrsensor }, + { 304, GetIrsensorSharedMemoryHandle }, + { 311, GetNpadIrCameraHandle } }; + + _irsSharedMem = irsSharedMem; } // ActivateIrsensor(nn::applet::AppletResourceUserId, pid) @@ -42,6 +49,21 @@ namespace Ryujinx.HLE.HOS.Services.Irs return 0; } + // GetIrsensorSharedMemoryHandle(nn::applet::AppletResourceUserId, pid) -> handle + public long GetIrsensorSharedMemoryHandle(ServiceCtx context) + { + var handleTable = context.Process.HandleTable; + + if (handleTable.GenerateHandle(_irsSharedMem, out int handle) != KernelResult.Success) + { + throw new InvalidOperationException("Out of handles!"); + } + + context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle); + + return 0; + } + // GetNpadIrCameraHandle(u32) -> nn::irsensor::IrCameraHandle public long GetNpadIrCameraHandle(ServiceCtx context) { diff --git a/Ryujinx.HLE/HOS/Services/ServiceFactory.cs b/Ryujinx.HLE/HOS/Services/ServiceFactory.cs index 113bbe51c..3bde7b877 100644 --- a/Ryujinx.HLE/HOS/Services/ServiceFactory.cs +++ b/Ryujinx.HLE/HOS/Services/ServiceFactory.cs @@ -112,7 +112,7 @@ namespace Ryujinx.HLE.HOS.Services return new IHidServer(system); case "irs": - return new IIrSensorServer(); + return new IIrSensorServer(system.IirsSharedMem); case "ldr:ro": return new IRoInterface();