IHOSBinderDriver.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. };
  24. ReleaseEvent = new KEvent();
  25. Flinger = new NvFlinger(Renderer, ReleaseEvent);
  26. }
  27. public long TransactParcel(ServiceCtx Context)
  28. {
  29. int Id = Context.RequestData.ReadInt32();
  30. int Code = Context.RequestData.ReadInt32();
  31. long DataPos = Context.Request.SendBuff[0].Position;
  32. long DataSize = Context.Request.SendBuff[0].Size;
  33. byte[] Data = AMemoryHelper.ReadBytes(Context.Memory, DataPos, DataSize);
  34. Data = Parcel.GetParcelData(Data);
  35. return Flinger.ProcessParcelRequest(Context, Data, Code);
  36. }
  37. public long AdjustRefcount(ServiceCtx Context)
  38. {
  39. int Id = Context.RequestData.ReadInt32();
  40. int AddVal = Context.RequestData.ReadInt32();
  41. int Type = Context.RequestData.ReadInt32();
  42. return 0;
  43. }
  44. public long GetNativeHandle(ServiceCtx Context)
  45. {
  46. int Id = Context.RequestData.ReadInt32();
  47. uint Unk = Context.RequestData.ReadUInt32();
  48. int Handle = Context.Process.HandleTable.OpenHandle(ReleaseEvent);
  49. Context.Response.HandleDesc = IpcHandleDesc.MakeMove(Handle);
  50. return 0;
  51. }
  52. public void Dispose()
  53. {
  54. Dispose(true);
  55. }
  56. protected virtual void Dispose(bool Disposing)
  57. {
  58. if (Disposing)
  59. {
  60. ReleaseEvent.Dispose();
  61. Flinger.Dispose();
  62. }
  63. }
  64. }
  65. }