IHOSBinderDriver.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using Ryujinx.HLE.HOS.Ipc;
  2. using Ryujinx.HLE.HOS.Kernel.Common;
  3. using Ryujinx.HLE.HOS.Kernel.Threading;
  4. using System;
  5. namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
  6. {
  7. abstract class IHOSBinderDriver : IpcService
  8. {
  9. public IHOSBinderDriver() { }
  10. [CommandHipc(0)]
  11. // TransactParcel(s32, u32, u32, buffer<unknown, 5, 0>) -> buffer<unknown, 6, 0>
  12. public ResultCode TransactParcel(ServiceCtx context)
  13. {
  14. int binderId = context.RequestData.ReadInt32();
  15. uint code = context.RequestData.ReadUInt32();
  16. uint flags = context.RequestData.ReadUInt32();
  17. ulong dataPos = context.Request.SendBuff[0].Position;
  18. ulong dataSize = context.Request.SendBuff[0].Size;
  19. ulong replyPos = context.Request.ReceiveBuff[0].Position;
  20. ulong replySize = context.Request.ReceiveBuff[0].Size;
  21. ReadOnlySpan<byte> inputParcel = context.Memory.GetSpan(dataPos, (int)dataSize);
  22. Span<byte> outputParcel = new Span<byte>(new byte[replySize]);
  23. ResultCode result = OnTransact(binderId, code, flags, inputParcel, outputParcel);
  24. if (result == ResultCode.Success)
  25. {
  26. context.Memory.Write(replyPos, outputParcel);
  27. }
  28. return result;
  29. }
  30. [CommandHipc(1)]
  31. // AdjustRefcount(s32, s32, s32)
  32. public ResultCode AdjustRefcount(ServiceCtx context)
  33. {
  34. int binderId = context.RequestData.ReadInt32();
  35. int addVal = context.RequestData.ReadInt32();
  36. int type = context.RequestData.ReadInt32();
  37. return AdjustRefcount(binderId, addVal, type);
  38. }
  39. [CommandHipc(2)]
  40. // GetNativeHandle(s32, s32) -> handle<copy>
  41. public ResultCode GetNativeHandle(ServiceCtx context)
  42. {
  43. int binderId = context.RequestData.ReadInt32();
  44. uint typeId = context.RequestData.ReadUInt32();
  45. GetNativeHandle(binderId, typeId, out KReadableEvent readableEvent);
  46. if (context.Process.HandleTable.GenerateHandle(readableEvent, out int handle) != KernelResult.Success)
  47. {
  48. throw new InvalidOperationException("Out of handles!");
  49. }
  50. context.Response.HandleDesc = IpcHandleDesc.MakeMove(handle);
  51. return ResultCode.Success;
  52. }
  53. [CommandHipc(3)] // 3.0.0+
  54. // TransactParcelAuto(s32, u32, u32, buffer<unknown, 21, 0>) -> buffer<unknown, 22, 0>
  55. public ResultCode TransactParcelAuto(ServiceCtx context)
  56. {
  57. int binderId = context.RequestData.ReadInt32();
  58. uint code = context.RequestData.ReadUInt32();
  59. uint flags = context.RequestData.ReadUInt32();
  60. (ulong dataPos, ulong dataSize) = context.Request.GetBufferType0x21();
  61. (ulong replyPos, ulong replySize) = context.Request.GetBufferType0x22();
  62. ReadOnlySpan<byte> inputParcel = context.Memory.GetSpan(dataPos, (int)dataSize);
  63. Span<byte> outputParcel = new Span<byte>(new byte[replySize]);
  64. ResultCode result = OnTransact(binderId, code, flags, inputParcel, outputParcel);
  65. if (result == ResultCode.Success)
  66. {
  67. context.Memory.Write(replyPos, outputParcel);
  68. }
  69. return result;
  70. }
  71. protected abstract ResultCode AdjustRefcount(int binderId, int addVal, int type);
  72. protected abstract void GetNativeHandle(int binderId, uint typeId, out KReadableEvent readableEvent);
  73. protected abstract ResultCode OnTransact(int binderId, uint code, uint flags, ReadOnlySpan<byte> inputParcel, Span<byte> outputParcel);
  74. }
  75. }