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> _commands;
  12. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  13. private KEvent _binderEvent;
  14. private NvFlinger _flinger;
  15. public IhosBinderDriver(Horizon system, IGalRenderer renderer)
  16. {
  17. _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. }