ServiceSm.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Ryujinx.Core.OsHle.Handles;
  2. using Ryujinx.Core.OsHle.Ipc;
  3. using System.Collections.Generic;
  4. namespace Ryujinx.Core.OsHle.IpcServices.Sm
  5. {
  6. class ServiceSm : IIpcService
  7. {
  8. private Dictionary<int, ServiceProcessRequest> m_Commands;
  9. public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  10. public ServiceSm()
  11. {
  12. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  13. {
  14. { 0, Initialize },
  15. { 1, GetService }
  16. };
  17. }
  18. private const int SmNotInitialized = 0x415;
  19. public long Initialize(ServiceCtx Context)
  20. {
  21. Context.Session.Initialize();
  22. return 0;
  23. }
  24. public long GetService(ServiceCtx Context)
  25. {
  26. //Only for kernel version > 3.0.0.
  27. if (!Context.Session.IsInitialized)
  28. {
  29. //return SmNotInitialized;
  30. }
  31. string Name = string.Empty;
  32. for (int Index = 0; Index < 8 &&
  33. Context.RequestData.BaseStream.Position <
  34. Context.RequestData.BaseStream.Length; Index++)
  35. {
  36. byte Chr = Context.RequestData.ReadByte();
  37. if (Chr >= 0x20 && Chr < 0x7f)
  38. {
  39. Name += (char)Chr;
  40. }
  41. }
  42. if (Name == string.Empty)
  43. {
  44. return 0;
  45. }
  46. HSession Session = new HSession(ServiceFactory.MakeService(Name));
  47. int Handle = Context.Ns.Os.Handles.GenerateId(Session);
  48. Context.Response.HandleDesc = IpcHandleDesc.MakeMove(Handle);
  49. return 0;
  50. }
  51. }
  52. }