IRequest.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel.Common;
  4. using Ryujinx.HLE.HOS.Kernel.Threading;
  5. using System;
  6. namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
  7. {
  8. class IRequest : IpcService
  9. {
  10. private KEvent _event0;
  11. private KEvent _event1;
  12. private int _event0Handle;
  13. private int _event1Handle;
  14. private uint _version;
  15. public IRequest(Horizon system, uint version)
  16. {
  17. _event0 = new KEvent(system.KernelContext);
  18. _event1 = new KEvent(system.KernelContext);
  19. _version = version;
  20. }
  21. [CommandHipc(0)]
  22. // GetRequestState() -> u32
  23. public ResultCode GetRequestState(ServiceCtx context)
  24. {
  25. context.ResponseData.Write(1);
  26. Logger.Stub?.PrintStub(LogClass.ServiceNifm);
  27. return ResultCode.Success;
  28. }
  29. [CommandHipc(1)]
  30. // GetResult()
  31. public ResultCode GetResult(ServiceCtx context)
  32. {
  33. Logger.Stub?.PrintStub(LogClass.ServiceNifm);
  34. return GetResultImpl();
  35. }
  36. private ResultCode GetResultImpl()
  37. {
  38. return ResultCode.Success;
  39. }
  40. [CommandHipc(2)]
  41. // GetSystemEventReadableHandles() -> (handle<copy>, handle<copy>)
  42. public ResultCode GetSystemEventReadableHandles(ServiceCtx context)
  43. {
  44. if (_event0Handle == 0)
  45. {
  46. if (context.Process.HandleTable.GenerateHandle(_event0.ReadableEvent, out _event0Handle) != KernelResult.Success)
  47. {
  48. throw new InvalidOperationException("Out of handles!");
  49. }
  50. }
  51. if (_event1Handle == 0)
  52. {
  53. if (context.Process.HandleTable.GenerateHandle(_event1.ReadableEvent, out _event1Handle) != KernelResult.Success)
  54. {
  55. throw new InvalidOperationException("Out of handles!");
  56. }
  57. }
  58. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_event0Handle, _event1Handle);
  59. return ResultCode.Success;
  60. }
  61. [CommandHipc(3)]
  62. // Cancel()
  63. public ResultCode Cancel(ServiceCtx context)
  64. {
  65. Logger.Stub?.PrintStub(LogClass.ServiceNifm);
  66. return ResultCode.Success;
  67. }
  68. [CommandHipc(4)]
  69. // Submit()
  70. public ResultCode Submit(ServiceCtx context)
  71. {
  72. Logger.Stub?.PrintStub(LogClass.ServiceNifm);
  73. return ResultCode.Success;
  74. }
  75. [CommandHipc(11)]
  76. // SetConnectionConfirmationOption(i8)
  77. public ResultCode SetConnectionConfirmationOption(ServiceCtx context)
  78. {
  79. Logger.Stub?.PrintStub(LogClass.ServiceNifm);
  80. return ResultCode.Success;
  81. }
  82. [CommandHipc(21)]
  83. // GetAppletInfo(u32) -> (u32, u32, u32, buffer<bytes, 6>)
  84. public ResultCode GetAppletInfo(ServiceCtx context)
  85. {
  86. uint themeColor = context.RequestData.ReadUInt32();
  87. Logger.Stub?.PrintStub(LogClass.ServiceNifm);
  88. ResultCode result = GetResultImpl();
  89. if (result == ResultCode.Success || (ResultCode)((int)result & 0x3fffff) == ResultCode.Unknown112)
  90. {
  91. return ResultCode.Unknown180;
  92. }
  93. // Returns appletId, libraryAppletMode, outSize and a buffer.
  94. // Returned applet ids- (0x19, 0xf, 0xe)
  95. // libraryAppletMode seems to be 0 for all applets supported.
  96. // TODO: check order
  97. context.ResponseData.Write(0xe); // Use error applet as default for now
  98. context.ResponseData.Write(0); // libraryAppletMode
  99. context.ResponseData.Write(0); // outSize
  100. return ResultCode.Success;
  101. }
  102. }
  103. }