mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-11-25 03:25:13 +00:00
Completely remove static methods inside Ipc interfaces, also remove GetObject method from ServiceCtx as it is no longer needed with this change
This commit is contained in:
parent
3d0b4d345f
commit
276f9f6d48
5 changed files with 41 additions and 74 deletions
|
@ -25,9 +25,7 @@ namespace Ryujinx.OsHle.Objects.Am
|
|||
|
||||
public long Open(ServiceCtx Context)
|
||||
{
|
||||
IStorage Storage = Context.GetObject<IStorage>();
|
||||
|
||||
MakeObject(Context, new IStorageAccessor(Storage));
|
||||
MakeObject(Context, new IStorageAccessor(this));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Ryujinx.OsHle.Objects.Am
|
|||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
public IStorage Storage { get; private set; }
|
||||
private IStorage Storage;
|
||||
|
||||
public IStorageAccessor(IStorage Storage)
|
||||
{
|
||||
|
@ -26,19 +26,13 @@ namespace Ryujinx.OsHle.Objects.Am
|
|||
|
||||
public long GetSize(ServiceCtx Context)
|
||||
{
|
||||
IStorageAccessor Accessor = Context.GetObject<IStorageAccessor>();
|
||||
|
||||
Context.ResponseData.Write((long)Accessor.Storage.Data.Length);
|
||||
Context.ResponseData.Write((long)Storage.Data.Length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long Read(ServiceCtx Context)
|
||||
{
|
||||
IStorageAccessor Accessor = Context.GetObject<IStorageAccessor>();
|
||||
|
||||
IStorage Storage = Accessor.Storage;
|
||||
|
||||
long ReadPosition = Context.RequestData.ReadInt64();
|
||||
|
||||
if (Context.Request.RecvListBuff.Count > 0)
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Ryujinx.OsHle.Objects.FspSrv
|
|||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
public Stream BaseStream { get; private set; }
|
||||
private Stream BaseStream;
|
||||
|
||||
public IStorage(Stream BaseStream)
|
||||
{
|
||||
|
@ -23,10 +23,8 @@ namespace Ryujinx.OsHle.Objects.FspSrv
|
|||
this.BaseStream = BaseStream;
|
||||
}
|
||||
|
||||
public static long Read(ServiceCtx Context)
|
||||
public long Read(ServiceCtx Context)
|
||||
{
|
||||
IStorage Storage = Context.GetObject<IStorage>();
|
||||
|
||||
long Offset = Context.RequestData.ReadInt64();
|
||||
long Size = Context.RequestData.ReadInt64();
|
||||
|
||||
|
@ -42,8 +40,8 @@ namespace Ryujinx.OsHle.Objects.FspSrv
|
|||
|
||||
byte[] Data = new byte[Size];
|
||||
|
||||
Storage.BaseStream.Seek(Offset, SeekOrigin.Begin);
|
||||
Storage.BaseStream.Read(Data, 0, Data.Length);
|
||||
BaseStream.Seek(Offset, SeekOrigin.Begin);
|
||||
BaseStream.Read(Data, 0, Data.Length);
|
||||
|
||||
AMemoryHelper.WriteBytes(Context.Memory, BuffDesc.Position, Data);
|
||||
}
|
||||
|
|
|
@ -13,32 +13,22 @@ namespace Ryujinx.OsHle.Objects.Vi
|
|||
{
|
||||
class IHOSBinderDriver : IIpcInterface
|
||||
{
|
||||
private delegate long ServiceProcessParcel(ServiceCtx Context, byte[] ParcelData);
|
||||
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
private Dictionary<(string, int), ServiceProcessParcel> m_Methods;
|
||||
|
||||
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; }
|
||||
private IdPoolWithObj BufferSlots;
|
||||
|
||||
public byte[] Gbfr;
|
||||
private byte[] Gbfr;
|
||||
|
||||
public IHOSBinderDriver()
|
||||
{
|
||||
|
@ -49,6 +39,17 @@ namespace Ryujinx.OsHle.Objects.Vi
|
|||
{ 2, GetNativeHandle }
|
||||
};
|
||||
|
||||
m_Methods = new Dictionary<(string, int), ServiceProcessParcel>()
|
||||
{
|
||||
{ ("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 }
|
||||
};
|
||||
|
||||
BufferSlots = new IdPoolWithObj();
|
||||
}
|
||||
|
||||
|
@ -74,7 +75,7 @@ namespace Ryujinx.OsHle.Objects.Vi
|
|||
|
||||
string InterfaceName = Encoding.Unicode.GetString(Data, 8, StrSize * 2);
|
||||
|
||||
if (InterfaceMthd.TryGetValue((InterfaceName, Code), out ServiceProcessRequest2 ProcReq))
|
||||
if (m_Methods.TryGetValue((InterfaceName, Code), out ServiceProcessParcel ProcReq))
|
||||
{
|
||||
return ProcReq(Context, Data);
|
||||
}
|
||||
|
@ -85,43 +86,37 @@ namespace Ryujinx.OsHle.Objects.Vi
|
|||
}
|
||||
}
|
||||
|
||||
private static long GraphicBufferProducerRequestBuffer(ServiceCtx Context, byte[] ParcelData)
|
||||
private long GraphicBufferProducerRequestBuffer(ServiceCtx Context, byte[] ParcelData)
|
||||
{
|
||||
IHOSBinderDriver BinderDriver = Context.GetObject<IHOSBinderDriver>();
|
||||
|
||||
int GbfrSize = BinderDriver.Gbfr?.Length ?? 0;
|
||||
int GbfrSize = Gbfr?.Length ?? 0;
|
||||
|
||||
byte[] Data = new byte[GbfrSize + 4];
|
||||
|
||||
if (BinderDriver.Gbfr != null)
|
||||
if (Gbfr != null)
|
||||
{
|
||||
Buffer.BlockCopy(BinderDriver.Gbfr, 0, Data, 0, GbfrSize);
|
||||
Buffer.BlockCopy(Gbfr, 0, Data, 0, GbfrSize);
|
||||
}
|
||||
|
||||
return MakeReplyParcel(Context, Data);
|
||||
}
|
||||
|
||||
private static long GraphicBufferProducerDequeueBuffer(ServiceCtx Context, byte[] ParcelData)
|
||||
private 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());
|
||||
int Slot = 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)
|
||||
private long GraphicBufferProducerQueueBuffer(ServiceCtx Context, byte[] ParcelData)
|
||||
{
|
||||
return MakeReplyParcel(Context, 1280, 720, 0, 0, 0);
|
||||
}
|
||||
|
||||
private static long GraphicBufferProducerCancelBuffer(ServiceCtx Context, byte[] ParcelData)
|
||||
private long GraphicBufferProducerCancelBuffer(ServiceCtx Context, byte[] ParcelData)
|
||||
{
|
||||
IHOSBinderDriver BinderDriver = Context.GetObject<IHOSBinderDriver>();
|
||||
|
||||
using (MemoryStream MS = new MemoryStream(ParcelData))
|
||||
{
|
||||
BinaryReader Reader = new BinaryReader(MS);
|
||||
|
@ -130,31 +125,29 @@ namespace Ryujinx.OsHle.Objects.Vi
|
|||
|
||||
int Slot = Reader.ReadInt32();
|
||||
|
||||
BinderDriver.BufferSlots.Delete(Slot);
|
||||
BufferSlots.Delete(Slot);
|
||||
|
||||
return MakeReplyParcel(Context, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private static long GraphicBufferProducerQuery(ServiceCtx Context, byte[] ParcelData)
|
||||
private long GraphicBufferProducerQuery(ServiceCtx Context, byte[] ParcelData)
|
||||
{
|
||||
return MakeReplyParcel(Context, 0, 0);
|
||||
}
|
||||
|
||||
private static long GraphicBufferProducerConnect(ServiceCtx Context, byte[] ParcelData)
|
||||
private long GraphicBufferProducerConnect(ServiceCtx Context, byte[] ParcelData)
|
||||
{
|
||||
return MakeReplyParcel(Context, 1280, 720, 0, 0, 0);
|
||||
}
|
||||
|
||||
private static long GraphicBufferPreallocateBuffer(ServiceCtx Context, byte[] ParcelData)
|
||||
private long GraphicBufferPreallocateBuffer(ServiceCtx Context, byte[] ParcelData)
|
||||
{
|
||||
IHOSBinderDriver BinderDriver = Context.GetObject<IHOSBinderDriver>();
|
||||
|
||||
int GbfrSize = ParcelData.Length - 0x54;
|
||||
|
||||
BinderDriver.Gbfr = new byte[GbfrSize];
|
||||
Gbfr = new byte[GbfrSize];
|
||||
|
||||
Buffer.BlockCopy(ParcelData, 0x54, BinderDriver.Gbfr, 0, GbfrSize);
|
||||
Buffer.BlockCopy(ParcelData, 0x54, Gbfr, 0, GbfrSize);
|
||||
|
||||
using (MemoryStream MS = new MemoryStream(ParcelData))
|
||||
{
|
||||
|
@ -172,7 +165,7 @@ namespace Ryujinx.OsHle.Objects.Vi
|
|||
return MakeReplyParcel(Context, 0);
|
||||
}
|
||||
|
||||
private static long MakeReplyParcel(ServiceCtx Context, params int[] Ints)
|
||||
private long MakeReplyParcel(ServiceCtx Context, params int[] Ints)
|
||||
{
|
||||
using (MemoryStream MS = new MemoryStream())
|
||||
{
|
||||
|
@ -187,7 +180,7 @@ namespace Ryujinx.OsHle.Objects.Vi
|
|||
}
|
||||
}
|
||||
|
||||
private static long MakeReplyParcel(ServiceCtx Context, byte[] Data)
|
||||
private long MakeReplyParcel(ServiceCtx Context, byte[] Data)
|
||||
{
|
||||
long ReplyPos = Context.Request.ReceiveBuff[0].Position;
|
||||
long ReplySize = Context.Request.ReceiveBuff[0].Position;
|
||||
|
|
|
@ -32,21 +32,5 @@ namespace Ryujinx.OsHle
|
|||
this.RequestData = RequestData;
|
||||
this.ResponseData = ResponseData;
|
||||
}
|
||||
|
||||
public T GetObject<T>()
|
||||
{
|
||||
object Obj = null;
|
||||
|
||||
if (Session is HSessionObj SessionObj)
|
||||
{
|
||||
Obj = SessionObj.Obj;
|
||||
}
|
||||
if (Session is HDomain Dom)
|
||||
{
|
||||
Obj = Dom.GetObject(Request.DomObjId);
|
||||
}
|
||||
|
||||
return Obj is T ? (T)Obj : default(T);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue