IHOSBinderDriver.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using Ryujinx.Graphics.Gal;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel.Common;
  4. using Ryujinx.HLE.HOS.Kernel.Threading;
  5. using Ryujinx.HLE.HOS.Services.Android;
  6. using System;
  7. using System.Collections.Generic;
  8. namespace Ryujinx.HLE.HOS.Services.Vi
  9. {
  10. class IhosBinderDriver : IpcService, IDisposable
  11. {
  12. private Dictionary<int, ServiceProcessRequest> _commands;
  13. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  14. private KEvent _binderEvent;
  15. private NvFlinger _flinger;
  16. public IhosBinderDriver(Horizon system, IGalRenderer renderer)
  17. {
  18. _commands = new Dictionary<int, ServiceProcessRequest>
  19. {
  20. { 0, TransactParcel },
  21. { 1, AdjustRefcount },
  22. { 2, GetNativeHandle },
  23. { 3, TransactParcelAuto }
  24. };
  25. _binderEvent = new KEvent(system);
  26. _binderEvent.ReadableEvent.Signal();
  27. _flinger = new NvFlinger(renderer, _binderEvent);
  28. }
  29. public long TransactParcel(ServiceCtx context)
  30. {
  31. int id = context.RequestData.ReadInt32();
  32. int code = context.RequestData.ReadInt32();
  33. long dataPos = context.Request.SendBuff[0].Position;
  34. long dataSize = context.Request.SendBuff[0].Size;
  35. byte[] data = context.Memory.ReadBytes(dataPos, dataSize);
  36. data = Parcel.GetParcelData(data);
  37. return _flinger.ProcessParcelRequest(context, data, code);
  38. }
  39. public long TransactParcelAuto(ServiceCtx context)
  40. {
  41. int id = context.RequestData.ReadInt32();
  42. int code = context.RequestData.ReadInt32();
  43. (long dataPos, long dataSize) = context.Request.GetBufferType0x21();
  44. byte[] data = context.Memory.ReadBytes(dataPos, dataSize);
  45. data = Parcel.GetParcelData(data);
  46. return _flinger.ProcessParcelRequest(context, data, code);
  47. }
  48. public long AdjustRefcount(ServiceCtx context)
  49. {
  50. int id = context.RequestData.ReadInt32();
  51. int addVal = context.RequestData.ReadInt32();
  52. int type = context.RequestData.ReadInt32();
  53. return 0;
  54. }
  55. public long GetNativeHandle(ServiceCtx context)
  56. {
  57. int id = context.RequestData.ReadInt32();
  58. uint unk = context.RequestData.ReadUInt32();
  59. if (context.Process.HandleTable.GenerateHandle(_binderEvent.ReadableEvent, out int handle) != KernelResult.Success)
  60. {
  61. throw new InvalidOperationException("Out of handles!");
  62. }
  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. _flinger.Dispose();
  75. }
  76. }
  77. }
  78. }