فهرست منبع

Implement IIrSensorServer GetIrsensorSharedMemoryHandle (#664)

* Implement IIrSensorServer GetIrsensorSharedMemoryHandle

Resolves #620

* Set _irsSharedMem
jduncanator 7 سال پیش
والد
کامیت
9e923b1473
3فایلهای تغییر یافته به همراه33 افزوده شده و 5 حذف شده
  1. 6 0
      Ryujinx.HLE/HOS/Horizon.cs
  2. 26 4
      Ryujinx.HLE/HOS/Services/Irs/IIrSensorServer.cs
  3. 1 1
      Ryujinx.HLE/HOS/Services/ServiceFactory.cs

+ 6 - 0
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);
 

+ 26 - 4
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<int, ServiceProcessRequest> Commands => _commands;
 
-        public IIrSensorServer()
+        private KSharedMemory _irsSharedMem;
+
+        public IIrSensorServer(KSharedMemory irsSharedMem)
         {
             _commands = new Dictionary<int, ServiceProcessRequest>
             {
-                { 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<copy>
+        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)
         {

+ 1 - 1
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();