IHOSBinderDriver.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using Ryujinx.Graphics.Gal;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel;
  4. using Ryujinx.HLE.HOS.Services.Android;
  5. using System;
  6. using System.Collections.Generic;
  7. namespace Ryujinx.HLE.HOS.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 BinderEvent;
  14. private NvFlinger Flinger;
  15. public IHOSBinderDriver(Horizon System, 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. BinderEvent = new KEvent(System);
  25. BinderEvent.ReadableEvent.Signal();
  26. Flinger = new NvFlinger(Renderer, BinderEvent);
  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 = Context.Memory.ReadBytes(DataPos, DataSize);
  35. Data = Parcel.GetParcelData(Data);
  36. return Flinger.ProcessParcelRequest(Context, Data, Code);
  37. }
  38. public long TransactParcelAuto(ServiceCtx Context)
  39. {
  40. int Id = Context.RequestData.ReadInt32();
  41. int Code = Context.RequestData.ReadInt32();
  42. (long DataPos, long DataSize) = Context.Request.GetBufferType0x21();
  43. byte[] Data = Context.Memory.ReadBytes(DataPos, DataSize);
  44. Data = Parcel.GetParcelData(Data);
  45. return Flinger.ProcessParcelRequest(Context, Data, Code);
  46. }
  47. public long AdjustRefcount(ServiceCtx Context)
  48. {
  49. int Id = Context.RequestData.ReadInt32();
  50. int AddVal = Context.RequestData.ReadInt32();
  51. int Type = Context.RequestData.ReadInt32();
  52. return 0;
  53. }
  54. public long GetNativeHandle(ServiceCtx Context)
  55. {
  56. int Id = Context.RequestData.ReadInt32();
  57. uint Unk = Context.RequestData.ReadUInt32();
  58. if (Context.Process.HandleTable.GenerateHandle(BinderEvent.ReadableEvent, out int Handle) != KernelResult.Success)
  59. {
  60. throw new InvalidOperationException("Out of handles!");
  61. }
  62. Context.Response.HandleDesc = IpcHandleDesc.MakeMove(Handle);
  63. return 0;
  64. }
  65. public void Dispose()
  66. {
  67. Dispose(true);
  68. }
  69. protected virtual void Dispose(bool Disposing)
  70. {
  71. if (Disposing)
  72. {
  73. Flinger.Dispose();
  74. }
  75. }
  76. }
  77. }