2018-02-04 16:08:20 -07:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
|
2018-08-16 17:47:36 -06:00
|
|
|
namespace Ryujinx.HLE.HOS.Ipc
|
2018-02-04 16:08:20 -07:00
|
|
|
{
|
|
|
|
class IpcHandleDesc
|
|
|
|
{
|
2018-12-04 17:52:39 -07:00
|
|
|
public bool HasPId { get; private set; }
|
2018-02-04 16:08:20 -07:00
|
|
|
|
2018-12-04 17:52:39 -07:00
|
|
|
public long PId { get; private set; }
|
2018-02-04 16:08:20 -07:00
|
|
|
|
2018-12-04 17:52:39 -07:00
|
|
|
public int[] ToCopy { get; private set; }
|
|
|
|
public int[] ToMove { get; private set; }
|
2018-02-04 16:08:20 -07:00
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
public IpcHandleDesc(BinaryReader reader)
|
2018-02-04 16:08:20 -07:00
|
|
|
{
|
2018-12-06 04:16:24 -07:00
|
|
|
int word = reader.ReadInt32();
|
2018-02-04 16:08:20 -07:00
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
HasPId = (word & 1) != 0;
|
2018-02-04 16:08:20 -07:00
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
ToCopy = new int[(word >> 1) & 0xf];
|
|
|
|
ToMove = new int[(word >> 5) & 0xf];
|
2018-02-04 16:08:20 -07:00
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
PId = HasPId ? reader.ReadInt64() : 0;
|
2018-02-04 16:08:20 -07:00
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
for (int index = 0; index < ToCopy.Length; index++)
|
2018-02-04 16:08:20 -07:00
|
|
|
{
|
2018-12-06 04:16:24 -07:00
|
|
|
ToCopy[index] = reader.ReadInt32();
|
2018-02-04 16:08:20 -07:00
|
|
|
}
|
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
for (int index = 0; index < ToMove.Length; index++)
|
2018-02-04 16:08:20 -07:00
|
|
|
{
|
2018-12-06 04:16:24 -07:00
|
|
|
ToMove[index] = reader.ReadInt32();
|
2018-02-04 16:08:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
public IpcHandleDesc(int[] copy, int[] move)
|
2018-02-04 16:08:20 -07:00
|
|
|
{
|
2018-12-06 04:16:24 -07:00
|
|
|
ToCopy = copy ?? throw new ArgumentNullException(nameof(copy));
|
|
|
|
ToMove = move ?? throw new ArgumentNullException(nameof(move));
|
2018-02-04 16:08:20 -07:00
|
|
|
}
|
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
public IpcHandleDesc(int[] copy, int[] move, long pId) : this(copy, move)
|
2018-02-04 16:08:20 -07:00
|
|
|
{
|
2018-12-06 04:16:24 -07:00
|
|
|
PId = pId;
|
2018-02-04 16:08:20 -07:00
|
|
|
|
|
|
|
HasPId = true;
|
|
|
|
}
|
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
public static IpcHandleDesc MakeCopy(params int[] handles)
|
2018-07-28 22:36:29 -06:00
|
|
|
{
|
2018-12-06 04:16:24 -07:00
|
|
|
return new IpcHandleDesc(handles, new int[0]);
|
2018-07-28 22:36:29 -06:00
|
|
|
}
|
2018-02-04 16:08:20 -07:00
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
public static IpcHandleDesc MakeMove(params int[] handles)
|
2018-07-28 22:36:29 -06:00
|
|
|
{
|
2018-12-06 04:16:24 -07:00
|
|
|
return new IpcHandleDesc(new int[0], handles);
|
2018-07-28 22:36:29 -06:00
|
|
|
}
|
2018-02-04 16:08:20 -07:00
|
|
|
|
|
|
|
public byte[] GetBytes()
|
|
|
|
{
|
2018-12-06 04:16:24 -07:00
|
|
|
using (MemoryStream ms = new MemoryStream())
|
2018-02-04 16:08:20 -07:00
|
|
|
{
|
2018-12-06 04:16:24 -07:00
|
|
|
BinaryWriter writer = new BinaryWriter(ms);
|
2018-02-04 16:08:20 -07:00
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
int word = HasPId ? 1 : 0;
|
2018-02-04 16:08:20 -07:00
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
word |= (ToCopy.Length & 0xf) << 1;
|
|
|
|
word |= (ToMove.Length & 0xf) << 5;
|
2018-02-04 16:08:20 -07:00
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
writer.Write(word);
|
2018-02-04 16:08:20 -07:00
|
|
|
|
|
|
|
if (HasPId)
|
|
|
|
{
|
2018-12-06 04:16:24 -07:00
|
|
|
writer.Write(PId);
|
2018-02-04 16:08:20 -07:00
|
|
|
}
|
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
foreach (int handle in ToCopy)
|
2018-02-04 16:08:20 -07:00
|
|
|
{
|
2018-12-06 04:16:24 -07:00
|
|
|
writer.Write(handle);
|
2018-02-04 16:08:20 -07:00
|
|
|
}
|
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
foreach (int handle in ToMove)
|
2018-02-04 16:08:20 -07:00
|
|
|
{
|
2018-12-06 04:16:24 -07:00
|
|
|
writer.Write(handle);
|
2018-02-04 16:08:20 -07:00
|
|
|
}
|
|
|
|
|
2018-12-06 04:16:24 -07:00
|
|
|
return ms.ToArray();
|
2018-02-04 16:08:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|