IHOSBinderDriver.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Ryujinx.Graphics.Gal;
  2. using Ryujinx.HLE.OsHle.Handles;
  3. using Ryujinx.HLE.OsHle.Ipc;
  4. using Ryujinx.HLE.OsHle.Services.Android;
  5. using System;
  6. using System.Collections.Generic;
  7. namespace Ryujinx.HLE.OsHle.Services.Vi
  8. {
  9. class IHOSBinderDriver : IpcService, IDisposable
  10. {
  11. private Dictionary<int, ServiceProcessRequest> m_Commands;
  12. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  13. private KEvent ReleaseEvent;
  14. private NvFlinger Flinger;
  15. public IHOSBinderDriver(IGalRenderer Renderer)
  16. {
  17. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  18. {
  19. { 0, TransactParcel },
  20. { 1, AdjustRefcount },
  21. { 2, GetNativeHandle },
  22. { 3, TransactParcelAuto }
  23. };
  24. ReleaseEvent = new KEvent();
  25. Flinger = new NvFlinger(Renderer, ReleaseEvent);
  26. }
  27. public long TransactParcel(ServiceCtx Context)
  28. {
  29. int Id = Context.RequestData.ReadInt32();
  30. int Code = Context.RequestData.ReadInt32();
  31. long DataPos = Context.Request.SendBuff[0].Position;
  32. long DataSize = Context.Request.SendBuff[0].Size;
  33. byte[] Data = Context.Memory.ReadBytes(DataPos, DataSize);
  34. Data = Parcel.GetParcelData(Data);
  35. return Flinger.ProcessParcelRequest(Context, Data, Code);
  36. }
  37. public long TransactParcelAuto(ServiceCtx Context)
  38. {
  39. int Id = Context.RequestData.ReadInt32();
  40. int Code = Context.RequestData.ReadInt32();
  41. (long DataPos, long DataSize) = Context.Request.GetBufferType0x21();
  42. byte[] Data = Context.Memory.ReadBytes(DataPos, DataSize);
  43. Data = Parcel.GetParcelData(Data);
  44. return Flinger.ProcessParcelRequest(Context, Data, Code);
  45. }
  46. public long AdjustRefcount(ServiceCtx Context)
  47. {
  48. int Id = Context.RequestData.ReadInt32();
  49. int AddVal = Context.RequestData.ReadInt32();
  50. int Type = Context.RequestData.ReadInt32();
  51. return 0;
  52. }
  53. public long GetNativeHandle(ServiceCtx Context)
  54. {
  55. int Id = Context.RequestData.ReadInt32();
  56. uint Unk = Context.RequestData.ReadUInt32();
  57. int Handle = Context.Process.HandleTable.OpenHandle(ReleaseEvent);
  58. Context.Response.HandleDesc = IpcHandleDesc.MakeMove(Handle);
  59. return 0;
  60. }
  61. public void Dispose()
  62. {
  63. Dispose(true);
  64. }
  65. protected virtual void Dispose(bool Disposing)
  66. {
  67. if (Disposing)
  68. {
  69. ReleaseEvent.Dispose();
  70. Flinger.Dispose();
  71. }
  72. }
  73. }
  74. }