IHOSBinderDriver.cs 3.1 KB

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