mirror of
https://git.743378673.xyz/MeloNX/MeloNX.git
synced 2025-08-03 12:07:10 +02:00
Ipc refactor (#9)
* Start refactoring IPC objects (started with IFile and IFileSystem) * End refactoring IPC objects (#8) * End refactoring IPC objects * End refactoring IPC objects corrections
This commit is contained in:
parent
7f4a190665
commit
322f28668d
62 changed files with 935 additions and 619 deletions
176
Ryujinx/OsHle/Objects/Vi/IApplicationDisplayService.cs
Normal file
176
Ryujinx/OsHle/Objects/Vi/IApplicationDisplayService.cs
Normal file
|
@ -0,0 +1,176 @@
|
|||
using ChocolArm64.Memory;
|
||||
using Ryujinx.OsHle.Handles;
|
||||
using Ryujinx.OsHle.Ipc;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using static Ryujinx.OsHle.Objects.Android.Parcel;
|
||||
using static Ryujinx.OsHle.Objects.ObjHelper;
|
||||
|
||||
namespace Ryujinx.OsHle.Objects.Vi
|
||||
{
|
||||
class IApplicationDisplayService : IIpcInterface
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
public IApplicationDisplayService()
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 100, GetRelayService },
|
||||
{ 101, GetSystemDisplayService },
|
||||
{ 102, GetManagerDisplayService },
|
||||
{ 103, GetIndirectDisplayTransactionService },
|
||||
{ 1010, OpenDisplay },
|
||||
{ 2020, OpenLayer },
|
||||
{ 2030, CreateStrayLayer },
|
||||
{ 2101, SetLayerScalingMode },
|
||||
{ 5202, GetDisplayVSyncEvent }
|
||||
};
|
||||
}
|
||||
|
||||
public long GetRelayService(ServiceCtx Context)
|
||||
{
|
||||
MakeObject(Context, new IHOSBinderDriver());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetSystemDisplayService(ServiceCtx Context)
|
||||
{
|
||||
MakeObject(Context, new ISystemDisplayService());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetManagerDisplayService(ServiceCtx Context)
|
||||
{
|
||||
MakeObject(Context, new IManagerDisplayService());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetIndirectDisplayTransactionService(ServiceCtx Context)
|
||||
{
|
||||
MakeObject(Context, new IHOSBinderDriver());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long OpenDisplay(ServiceCtx Context)
|
||||
{
|
||||
string Name = GetDisplayName(Context);
|
||||
|
||||
long DisplayId = Context.Ns.Os.Displays.GenerateId(new Display(Name));
|
||||
|
||||
Context.ResponseData.Write(DisplayId);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long OpenLayer(ServiceCtx Context)
|
||||
{
|
||||
long LayerId = Context.RequestData.ReadInt64();
|
||||
long UserId = Context.RequestData.ReadInt64();
|
||||
|
||||
long ParcelPtr = Context.Request.ReceiveBuff[0].Position;
|
||||
|
||||
byte[] Parcel = MakeIGraphicsBufferProducer(ParcelPtr);
|
||||
|
||||
AMemoryHelper.WriteBytes(Context.Memory, ParcelPtr, Parcel);
|
||||
|
||||
Context.ResponseData.Write((long)Parcel.Length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long CreateStrayLayer(ServiceCtx Context)
|
||||
{
|
||||
long LayerFlags = Context.RequestData.ReadInt64();
|
||||
long DisplayId = Context.RequestData.ReadInt64();
|
||||
|
||||
long ParcelPtr = Context.Request.ReceiveBuff[0].Position;
|
||||
|
||||
Display Disp = Context.Ns.Os.Displays.GetData<Display>((int)DisplayId);
|
||||
|
||||
byte[] Parcel = MakeIGraphicsBufferProducer(ParcelPtr);
|
||||
|
||||
AMemoryHelper.WriteBytes(Context.Memory, ParcelPtr, Parcel);
|
||||
|
||||
Context.ResponseData.Write(0L);
|
||||
Context.ResponseData.Write((long)Parcel.Length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long SetLayerScalingMode(ServiceCtx Context)
|
||||
{
|
||||
int ScalingMode = Context.RequestData.ReadInt32();
|
||||
long Unknown = Context.RequestData.ReadInt64();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetDisplayVSyncEvent(ServiceCtx Context)
|
||||
{
|
||||
string Name = GetDisplayName(Context);
|
||||
|
||||
int Handle = Context.Ns.Os.Handles.GenerateId(new HEvent());
|
||||
|
||||
Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private byte[] MakeIGraphicsBufferProducer(long BasePtr)
|
||||
{
|
||||
long Id = 0x20;
|
||||
long CookiePtr = 0L;
|
||||
|
||||
using (MemoryStream MS = new MemoryStream())
|
||||
{
|
||||
BinaryWriter Writer = new BinaryWriter(MS);
|
||||
|
||||
//flat_binder_object (size is 0x28)
|
||||
Writer.Write(2); //Type (BINDER_TYPE_WEAK_BINDER)
|
||||
Writer.Write(0); //Flags
|
||||
Writer.Write((int)(Id >> 0));
|
||||
Writer.Write((int)(Id >> 32));
|
||||
Writer.Write((int)(CookiePtr >> 0));
|
||||
Writer.Write((int)(CookiePtr >> 32));
|
||||
Writer.Write((byte)'d');
|
||||
Writer.Write((byte)'i');
|
||||
Writer.Write((byte)'s');
|
||||
Writer.Write((byte)'p');
|
||||
Writer.Write((byte)'d');
|
||||
Writer.Write((byte)'r');
|
||||
Writer.Write((byte)'v');
|
||||
Writer.Write((byte)'\0');
|
||||
Writer.Write(0L); //Pad
|
||||
|
||||
return MakeParcel(MS.ToArray(), new byte[] { 0, 0, 0, 0 });
|
||||
}
|
||||
}
|
||||
|
||||
private string GetDisplayName(ServiceCtx Context)
|
||||
{
|
||||
string Name = string.Empty;
|
||||
|
||||
for (int Index = 0; Index < 8 &&
|
||||
Context.RequestData.BaseStream.Position <
|
||||
Context.RequestData.BaseStream.Length; Index++)
|
||||
{
|
||||
byte Chr = Context.RequestData.ReadByte();
|
||||
|
||||
if (Chr >= 0x20 && Chr < 0x7f)
|
||||
{
|
||||
Name += (char)Chr;
|
||||
}
|
||||
}
|
||||
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
221
Ryujinx/OsHle/Objects/Vi/IHOSBinderDriver.cs
Normal file
221
Ryujinx/OsHle/Objects/Vi/IHOSBinderDriver.cs
Normal file
|
@ -0,0 +1,221 @@
|
|||
using ChocolArm64.Memory;
|
||||
using Ryujinx.OsHle.Handles;
|
||||
using Ryujinx.OsHle.Ipc;
|
||||
using Ryujinx.OsHle.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
using static Ryujinx.OsHle.Objects.Android.Parcel;
|
||||
|
||||
namespace Ryujinx.OsHle.Objects.Vi
|
||||
{
|
||||
class IHOSBinderDriver : IIpcInterface
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
private delegate long ServiceProcessRequest2(ServiceCtx Context, byte[] ParcelData);
|
||||
|
||||
private Dictionary<(string, int), ServiceProcessRequest2> InterfaceMthd =
|
||||
new Dictionary<(string, int), ServiceProcessRequest2>()
|
||||
{
|
||||
{ ("android.gui.IGraphicBufferProducer", 0x1), GraphicBufferProducerRequestBuffer },
|
||||
{ ("android.gui.IGraphicBufferProducer", 0x3), GraphicBufferProducerDequeueBuffer },
|
||||
{ ("android.gui.IGraphicBufferProducer", 0x7), GraphicBufferProducerQueueBuffer },
|
||||
//{ ("android.gui.IGraphicBufferProducer", 0x8), GraphicBufferProducerCancelBuffer },
|
||||
{ ("android.gui.IGraphicBufferProducer", 0x9), GraphicBufferProducerQuery },
|
||||
{ ("android.gui.IGraphicBufferProducer", 0xa), GraphicBufferProducerConnect },
|
||||
{ ("android.gui.IGraphicBufferProducer", 0xe), GraphicBufferPreallocateBuffer },
|
||||
};
|
||||
|
||||
private class BufferObj
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public IdPoolWithObj BufferSlots { get; private set; }
|
||||
|
||||
public byte[] Gbfr;
|
||||
|
||||
public IHOSBinderDriver()
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, TransactParcel },
|
||||
{ 1, AdjustRefcount },
|
||||
{ 2, GetNativeHandle }
|
||||
};
|
||||
|
||||
BufferSlots = new IdPoolWithObj();
|
||||
}
|
||||
|
||||
public long TransactParcel(ServiceCtx Context)
|
||||
{
|
||||
int Id = Context.RequestData.ReadInt32();
|
||||
int Code = Context.RequestData.ReadInt32();
|
||||
|
||||
long DataPos = Context.Request.SendBuff[0].Position;
|
||||
long DataSize = Context.Request.SendBuff[0].Size;
|
||||
|
||||
byte[] Data = AMemoryHelper.ReadBytes(Context.Memory, DataPos, (int)DataSize);
|
||||
|
||||
Data = GetParcelData(Data);
|
||||
|
||||
using (MemoryStream MS = new MemoryStream(Data))
|
||||
{
|
||||
BinaryReader Reader = new BinaryReader(MS);
|
||||
|
||||
MS.Seek(4, SeekOrigin.Current);
|
||||
|
||||
int StrSize = Reader.ReadInt32();
|
||||
|
||||
string InterfaceName = Encoding.Unicode.GetString(Data, 8, StrSize * 2);
|
||||
|
||||
if (InterfaceMthd.TryGetValue((InterfaceName, Code), out ServiceProcessRequest2 ProcReq))
|
||||
{
|
||||
return ProcReq(Context, Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException($"{InterfaceName} {Code}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static long GraphicBufferProducerRequestBuffer(ServiceCtx Context, byte[] ParcelData)
|
||||
{
|
||||
IHOSBinderDriver BinderDriver = Context.GetObject<IHOSBinderDriver>();
|
||||
|
||||
int GbfrSize = BinderDriver.Gbfr?.Length ?? 0;
|
||||
|
||||
byte[] Data = new byte[GbfrSize + 4];
|
||||
|
||||
if (BinderDriver.Gbfr != null)
|
||||
{
|
||||
Buffer.BlockCopy(BinderDriver.Gbfr, 0, Data, 0, GbfrSize);
|
||||
}
|
||||
|
||||
return MakeReplyParcel(Context, Data);
|
||||
}
|
||||
|
||||
private static long GraphicBufferProducerDequeueBuffer(ServiceCtx Context, byte[] ParcelData)
|
||||
{
|
||||
IHOSBinderDriver BinderDriver = Context.GetObject<IHOSBinderDriver>();
|
||||
|
||||
//Note: It seems that the maximum number of slots is 64, because if we return
|
||||
//a Slot number > 63, it seems to cause a buffer overrun and it reads garbage.
|
||||
//Note 2: The size of each object associated with the slot is 0x30.
|
||||
int Slot = BinderDriver.BufferSlots.GenerateId(new BufferObj());
|
||||
|
||||
return MakeReplyParcel(Context, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
private static long GraphicBufferProducerQueueBuffer(ServiceCtx Context, byte[] ParcelData)
|
||||
{
|
||||
return MakeReplyParcel(Context, 1280, 720, 0, 0, 0);
|
||||
}
|
||||
|
||||
private static long GraphicBufferProducerCancelBuffer(ServiceCtx Context, byte[] ParcelData)
|
||||
{
|
||||
IHOSBinderDriver BinderDriver = Context.GetObject<IHOSBinderDriver>();
|
||||
|
||||
using (MemoryStream MS = new MemoryStream(ParcelData))
|
||||
{
|
||||
BinaryReader Reader = new BinaryReader(MS);
|
||||
|
||||
MS.Seek(0x50, SeekOrigin.Begin);
|
||||
|
||||
int Slot = Reader.ReadInt32();
|
||||
|
||||
BinderDriver.BufferSlots.Delete(Slot);
|
||||
|
||||
return MakeReplyParcel(Context, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private static long GraphicBufferProducerQuery(ServiceCtx Context, byte[] ParcelData)
|
||||
{
|
||||
return MakeReplyParcel(Context, 0, 0);
|
||||
}
|
||||
|
||||
private static long GraphicBufferProducerConnect(ServiceCtx Context, byte[] ParcelData)
|
||||
{
|
||||
return MakeReplyParcel(Context, 1280, 720, 0, 0, 0);
|
||||
}
|
||||
|
||||
private static long GraphicBufferPreallocateBuffer(ServiceCtx Context, byte[] ParcelData)
|
||||
{
|
||||
IHOSBinderDriver BinderDriver = Context.GetObject<IHOSBinderDriver>();
|
||||
|
||||
int GbfrSize = ParcelData.Length - 0x54;
|
||||
|
||||
BinderDriver.Gbfr = new byte[GbfrSize];
|
||||
|
||||
Buffer.BlockCopy(ParcelData, 0x54, BinderDriver.Gbfr, 0, GbfrSize);
|
||||
|
||||
using (MemoryStream MS = new MemoryStream(ParcelData))
|
||||
{
|
||||
BinaryReader Reader = new BinaryReader(MS);
|
||||
|
||||
MS.Seek(0xd4, SeekOrigin.Begin);
|
||||
|
||||
int Handle = Reader.ReadInt32();
|
||||
|
||||
HNvMap NvMap = Context.Ns.Os.Handles.GetData<HNvMap>(Handle);
|
||||
|
||||
Context.Ns.Gpu.Renderer.FrameBufferPtr = NvMap.Address;
|
||||
}
|
||||
|
||||
return MakeReplyParcel(Context, 0);
|
||||
}
|
||||
|
||||
private static long MakeReplyParcel(ServiceCtx Context, params int[] Ints)
|
||||
{
|
||||
using (MemoryStream MS = new MemoryStream())
|
||||
{
|
||||
BinaryWriter Writer = new BinaryWriter(MS);
|
||||
|
||||
foreach (int Int in Ints)
|
||||
{
|
||||
Writer.Write(Int);
|
||||
}
|
||||
|
||||
return MakeReplyParcel(Context, MS.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
private static long MakeReplyParcel(ServiceCtx Context, byte[] Data)
|
||||
{
|
||||
long ReplyPos = Context.Request.ReceiveBuff[0].Position;
|
||||
long ReplySize = Context.Request.ReceiveBuff[0].Position;
|
||||
|
||||
byte[] Reply = MakeParcel(Data, new byte[0]);
|
||||
|
||||
AMemoryHelper.WriteBytes(Context.Memory, ReplyPos, Reply);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long AdjustRefcount(ServiceCtx Context)
|
||||
{
|
||||
int Id = Context.RequestData.ReadInt32();
|
||||
int AddVal = Context.RequestData.ReadInt32();
|
||||
int Type = Context.RequestData.ReadInt32();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetNativeHandle(ServiceCtx Context)
|
||||
{
|
||||
int Id = Context.RequestData.ReadInt32();
|
||||
uint Unk = Context.RequestData.ReadUInt32();
|
||||
|
||||
Context.Response.HandleDesc = IpcHandleDesc.MakeMove(0xbadcafe);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
33
Ryujinx/OsHle/Objects/Vi/IManagerDisplayService.cs
Normal file
33
Ryujinx/OsHle/Objects/Vi/IManagerDisplayService.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using Ryujinx.OsHle.Ipc;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.OsHle.Objects.Vi
|
||||
{
|
||||
class IManagerDisplayService : IIpcInterface
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
public IManagerDisplayService()
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 2010, CreateManagedLayer },
|
||||
{ 6000, AddToLayerStack }
|
||||
};
|
||||
}
|
||||
|
||||
public static long CreateManagedLayer(ServiceCtx Context)
|
||||
{
|
||||
Context.ResponseData.Write(0L); //LayerId
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static long AddToLayerStack(ServiceCtx Context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
25
Ryujinx/OsHle/Objects/Vi/ISystemDisplayService.cs
Normal file
25
Ryujinx/OsHle/Objects/Vi/ISystemDisplayService.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using Ryujinx.OsHle.Ipc;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.OsHle.Objects.Vi
|
||||
{
|
||||
class ISystemDisplayService : IIpcInterface
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
public ISystemDisplayService()
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 2205, SetLayerZ }
|
||||
};
|
||||
}
|
||||
|
||||
public static long SetLayerZ(ServiceCtx Context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue