IUserInterface.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using Ryujinx.HLE.HOS.Ipc;
  2. using Ryujinx.HLE.HOS.Kernel.Common;
  3. using Ryujinx.HLE.HOS.Kernel.Ipc;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace Ryujinx.HLE.HOS.Services.Sm
  7. {
  8. class IUserInterface : IpcService
  9. {
  10. private Dictionary<int, ServiceProcessRequest> _commands;
  11. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  12. private bool _isInitialized;
  13. public IUserInterface()
  14. {
  15. _commands = new Dictionary<int, ServiceProcessRequest>
  16. {
  17. { 0, Initialize },
  18. { 1, GetService }
  19. };
  20. }
  21. private const int SmNotInitialized = 0x415;
  22. public long Initialize(ServiceCtx context)
  23. {
  24. _isInitialized = true;
  25. return 0;
  26. }
  27. public long GetService(ServiceCtx context)
  28. {
  29. //Only for kernel version > 3.0.0.
  30. if (!_isInitialized)
  31. {
  32. //return SmNotInitialized;
  33. }
  34. string name = string.Empty;
  35. for (int index = 0; index < 8 &&
  36. context.RequestData.BaseStream.Position <
  37. context.RequestData.BaseStream.Length; index++)
  38. {
  39. byte chr = context.RequestData.ReadByte();
  40. if (chr >= 0x20 && chr < 0x7f)
  41. {
  42. name += (char)chr;
  43. }
  44. }
  45. if (name == string.Empty)
  46. {
  47. return 0;
  48. }
  49. KSession session = new KSession(ServiceFactory.MakeService(context.Device.System, name), name);
  50. if (context.Process.HandleTable.GenerateHandle(session, out int handle) != KernelResult.Success)
  51. {
  52. throw new InvalidOperationException("Out of handles!");
  53. }
  54. context.Response.HandleDesc = IpcHandleDesc.MakeMove(handle);
  55. return 0;
  56. }
  57. }
  58. }