Implement IIrSensorServer GetIrsensorSharedMemoryHandle (#664)

* Implement IIrSensorServer GetIrsensorSharedMemoryHandle

Resolves #620

* Set _irsSharedMem
This commit is contained in:
jduncanator 2019-04-20 12:23:13 +10:00 committed by GitHub
parent bea73895f5
commit 9e923b1473
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 5 deletions

View file

@ -30,6 +30,7 @@ namespace Ryujinx.HLE.HOS
internal const int HidSize = 0x40000; internal const int HidSize = 0x40000;
internal const int FontSize = 0x1100000; internal const int FontSize = 0x1100000;
internal const int IirsSize = 0x8000;
private const int MemoryBlockAllocatorSize = 0x2710; private const int MemoryBlockAllocatorSize = 0x2710;
@ -81,6 +82,7 @@ namespace Ryujinx.HLE.HOS
internal KSharedMemory HidSharedMem { get; private set; } internal KSharedMemory HidSharedMem { get; private set; }
internal KSharedMemory FontSharedMem { get; private set; } internal KSharedMemory FontSharedMem { get; private set; }
internal KSharedMemory IirsSharedMem { get; private set; }
internal SharedFontManager Font { get; private set; } internal SharedFontManager Font { get; private set; }
@ -151,17 +153,21 @@ namespace Ryujinx.HLE.HOS
ulong hidPa = region.Address; ulong hidPa = region.Address;
ulong fontPa = region.Address + HidSize; ulong fontPa = region.Address + HidSize;
ulong iirsPa = region.Address + HidSize + FontSize;
HidBaseAddress = (long)(hidPa - DramMemoryMap.DramBase); HidBaseAddress = (long)(hidPa - DramMemoryMap.DramBase);
KPageList hidPageList = new KPageList(); KPageList hidPageList = new KPageList();
KPageList fontPageList = new KPageList(); KPageList fontPageList = new KPageList();
KPageList iirsPageList = new KPageList();
hidPageList .AddRange(hidPa, HidSize / KMemoryManager.PageSize); hidPageList .AddRange(hidPa, HidSize / KMemoryManager.PageSize);
fontPageList.AddRange(fontPa, FontSize / KMemoryManager.PageSize); fontPageList.AddRange(fontPa, FontSize / KMemoryManager.PageSize);
iirsPageList.AddRange(iirsPa, IirsSize / KMemoryManager.PageSize);
HidSharedMem = new KSharedMemory(this, hidPageList, 0, 0, MemoryPermission.Read); HidSharedMem = new KSharedMemory(this, hidPageList, 0, 0, MemoryPermission.Read);
FontSharedMem = new KSharedMemory(this, fontPageList, 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); AppletState = new AppletStateMgr(this);

View file

@ -1,6 +1,8 @@
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.HLE.Exceptions; using Ryujinx.HLE.Exceptions;
using Ryujinx.HLE.HOS.Ipc; using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Memory;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -12,14 +14,19 @@ namespace Ryujinx.HLE.HOS.Services.Irs
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands; public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public IIrSensorServer() private KSharedMemory _irsSharedMem;
public IIrSensorServer(KSharedMemory irsSharedMem)
{ {
_commands = new Dictionary<int, ServiceProcessRequest> _commands = new Dictionary<int, ServiceProcessRequest>
{ {
{ 302, ActivateIrsensor }, { 302, ActivateIrsensor },
{ 303, DeactivateIrsensor }, { 303, DeactivateIrsensor },
{ 311, GetNpadIrCameraHandle } { 304, GetIrsensorSharedMemoryHandle },
{ 311, GetNpadIrCameraHandle }
}; };
_irsSharedMem = irsSharedMem;
} }
// ActivateIrsensor(nn::applet::AppletResourceUserId, pid) // ActivateIrsensor(nn::applet::AppletResourceUserId, pid)
@ -42,6 +49,21 @@ namespace Ryujinx.HLE.HOS.Services.Irs
return 0; 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 // GetNpadIrCameraHandle(u32) -> nn::irsensor::IrCameraHandle
public long GetNpadIrCameraHandle(ServiceCtx context) public long GetNpadIrCameraHandle(ServiceCtx context)
{ {

View file

@ -112,7 +112,7 @@ namespace Ryujinx.HLE.HOS.Services
return new IHidServer(system); return new IHidServer(system);
case "irs": case "irs":
return new IIrSensorServer(); return new IIrSensorServer(system.IirsSharedMem);
case "ldr:ro": case "ldr:ro":
return new IRoInterface(); return new IRoInterface();