2023-03-17 12:14:50 +00:00
|
|
|
using Microsoft.IO;
|
|
|
|
using Ryujinx.Common;
|
|
|
|
using Ryujinx.Common.Memory;
|
2018-02-04 23:08:20 +00:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
|
2018-08-16 23:47:36 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Ipc
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
|
|
|
class IpcHandleDesc
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
public bool HasPId { get; private set; }
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2022-02-09 20:18:07 +00:00
|
|
|
public ulong PId { get; private set; }
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public int[] ToCopy { get; private set; }
|
|
|
|
public int[] ToMove { get; private set; }
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
public IpcHandleDesc(BinaryReader reader)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
int word = reader.ReadInt32();
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
HasPId = (word & 1) != 0;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2022-02-09 20:18:07 +00:00
|
|
|
PId = HasPId ? reader.ReadUInt64() : 0;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2023-03-17 12:14:50 +00:00
|
|
|
int toCopySize = (word >> 1) & 0xf;
|
|
|
|
int[] toCopy = toCopySize == 0 ? Array.Empty<int>() : new int[toCopySize];
|
|
|
|
|
|
|
|
for (int index = 0; index < toCopy.Length; index++)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2023-03-17 12:14:50 +00:00
|
|
|
toCopy[index] = reader.ReadInt32();
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 12:14:50 +00:00
|
|
|
ToCopy = toCopy;
|
|
|
|
|
|
|
|
int toMoveSize = (word >> 5) & 0xf;
|
|
|
|
int[] toMove = toMoveSize == 0 ? Array.Empty<int>() : new int[toMoveSize];
|
|
|
|
|
|
|
|
for (int index = 0; index < toMove.Length; index++)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2023-03-17 12:14:50 +00:00
|
|
|
toMove[index] = reader.ReadInt32();
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
2023-03-17 12:14:50 +00:00
|
|
|
|
|
|
|
ToMove = toMove;
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
public IpcHandleDesc(int[] copy, int[] move)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
ToCopy = copy ?? throw new ArgumentNullException(nameof(copy));
|
|
|
|
ToMove = move ?? throw new ArgumentNullException(nameof(move));
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2022-02-09 20:18:07 +00:00
|
|
|
public IpcHandleDesc(int[] copy, int[] move, ulong pId) : this(copy, move)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
PId = pId;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
|
|
|
HasPId = true;
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
public static IpcHandleDesc MakeCopy(params int[] handles)
|
2018-07-29 04:36:29 +00:00
|
|
|
{
|
2023-03-11 20:05:48 +00:00
|
|
|
return new IpcHandleDesc(handles, Array.Empty<int>());
|
2018-07-29 04:36:29 +00:00
|
|
|
}
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
public static IpcHandleDesc MakeMove(params int[] handles)
|
2018-07-29 04:36:29 +00:00
|
|
|
{
|
2023-03-11 20:05:48 +00:00
|
|
|
return new IpcHandleDesc(Array.Empty<int>(), handles);
|
2018-07-29 04:36:29 +00:00
|
|
|
}
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2023-03-17 12:14:50 +00:00
|
|
|
public RecyclableMemoryStream GetStream()
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2023-03-17 12:14:50 +00:00
|
|
|
RecyclableMemoryStream ms = MemoryStreamManager.Shared.GetStream();
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2023-03-17 12:14:50 +00:00
|
|
|
int word = HasPId ? 1 : 0;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2023-03-17 12:14:50 +00:00
|
|
|
word |= (ToCopy.Length & 0xf) << 1;
|
|
|
|
word |= (ToMove.Length & 0xf) << 5;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2023-03-17 12:14:50 +00:00
|
|
|
ms.Write(word);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2023-03-17 12:14:50 +00:00
|
|
|
if (HasPId)
|
|
|
|
{
|
|
|
|
ms.Write(PId);
|
|
|
|
}
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2023-03-17 12:14:50 +00:00
|
|
|
ms.Write(ToCopy);
|
|
|
|
ms.Write(ToMove);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2023-03-17 12:14:50 +00:00
|
|
|
ms.Position = 0;
|
|
|
|
return ms;
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|