* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0052 warnings * Address or silence dotnet format IDE1006 warnings * Address dotnet format CA1816 warnings * Address or silence dotnet format CA2208 warnings * Address or silence dotnet format CA1806 and a few CA1854 warnings * Address dotnet format CA2211 warnings * Address dotnet format CA1822 warnings * Address or silence dotnet format CA1069 warnings * Make dotnet format succeed in style mode * Address or silence dotnet format CA2211 warnings * Address review comments * Address dotnet format CA2208 warnings properly * Make ProcessResult readonly * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Add previously silenced warnings back I have no clue how these disappeared * Revert formatting changes for while and for-loops * Format if-blocks correctly * Run dotnet format style after rebase * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format analyzers after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Disable 'prefer switch expression' rule * Add comments to disabled warnings * Fix a few disabled warnings * Fix naming rule violation, Convert shader properties to auto-property and convert values to const * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Start working on disabled warnings * Fix and silence a few dotnet-format warnings again * Run dotnet format after rebase * Use using declaration instead of block syntax * Address IDE0251 warnings * Address a few disabled IDE0060 warnings * Silence IDE0060 in .editorconfig * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Fix naming rule violations * Fix typo * Add trailing commas, use targeted new and use array initializer * Fix build issues * Fix remaining build issues * Remove SuppressMessage for CA1069 where possible * Address dotnet format issues * Address formatting issues Co-authored-by: Ac_K <acoustik666@gmail.com> * Add GetHashCode implementation for RenderingSurfaceInfo * Explicitly silence CA1822 for every affected method in Syscall * Address formatting issues in Demangler.cs * Address review feedback Co-authored-by: Ac_K <acoustik666@gmail.com> * Revert marking service methods as static * Next dotnet format pass * Address review feedback --------- Co-authored-by: Ac_K <acoustik666@gmail.com>
224 lines
6.8 KiB
C#
224 lines
6.8 KiB
C#
using Ryujinx.Common;
|
|
using Ryujinx.Common.Utilities;
|
|
using Ryujinx.HLE.HOS.Services.SurfaceFlinger.Types;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
|
{
|
|
class Parcel
|
|
{
|
|
private readonly byte[] _rawData;
|
|
|
|
private Span<byte> Raw => new(_rawData);
|
|
|
|
private ref ParcelHeader Header => ref MemoryMarshal.Cast<byte, ParcelHeader>(_rawData)[0];
|
|
|
|
private Span<byte> Payload => Raw.Slice((int)Header.PayloadOffset, (int)Header.PayloadSize);
|
|
|
|
private Span<byte> Objects => Raw.Slice((int)Header.ObjectOffset, (int)Header.ObjectsSize);
|
|
|
|
private int _payloadPosition;
|
|
private int _objectPosition;
|
|
|
|
public Parcel(byte[] rawData)
|
|
{
|
|
_rawData = rawData;
|
|
|
|
_payloadPosition = 0;
|
|
_objectPosition = 0;
|
|
}
|
|
|
|
public Parcel(uint payloadSize, uint objectsSize)
|
|
{
|
|
uint headerSize = (uint)Unsafe.SizeOf<ParcelHeader>();
|
|
|
|
_rawData = new byte[BitUtils.AlignUp<uint>(headerSize + payloadSize + objectsSize, 4)];
|
|
|
|
Header.PayloadSize = payloadSize;
|
|
Header.ObjectsSize = objectsSize;
|
|
Header.PayloadOffset = headerSize;
|
|
Header.ObjectOffset = Header.PayloadOffset + Header.ObjectsSize;
|
|
}
|
|
|
|
public string ReadInterfaceToken()
|
|
{
|
|
// Ignore the policy flags
|
|
#pragma warning disable IDE0059 // Remove unnecessary value assignment
|
|
int strictPolicy = ReadInt32();
|
|
#pragma warning restore IDE0059
|
|
|
|
return ReadString16();
|
|
}
|
|
|
|
public string ReadString16()
|
|
{
|
|
int size = ReadInt32();
|
|
|
|
if (size < 0)
|
|
{
|
|
return "";
|
|
}
|
|
|
|
ReadOnlySpan<byte> data = ReadInPlace((size + 1) * 2);
|
|
|
|
// Return the unicode string without the last character (null terminator)
|
|
return Encoding.Unicode.GetString(data[..(size * 2)]);
|
|
}
|
|
|
|
public int ReadInt32() => ReadUnmanagedType<int>();
|
|
public uint ReadUInt32() => ReadUnmanagedType<uint>();
|
|
public bool ReadBoolean() => ReadUnmanagedType<uint>() != 0;
|
|
public long ReadInt64() => ReadUnmanagedType<long>();
|
|
public ulong ReadUInt64() => ReadUnmanagedType<ulong>();
|
|
|
|
public T ReadFlattenable<T>() where T : unmanaged, IFlattenable
|
|
{
|
|
long flattenableSize = ReadInt64();
|
|
|
|
T result = new();
|
|
|
|
Debug.Assert(flattenableSize == result.GetFlattenedSize());
|
|
|
|
result.Unflatten(this);
|
|
|
|
return result;
|
|
}
|
|
|
|
public T ReadUnmanagedType<T>() where T : unmanaged
|
|
{
|
|
ReadOnlySpan<byte> data = ReadInPlace(Unsafe.SizeOf<T>());
|
|
|
|
return MemoryMarshal.Cast<byte, T>(data)[0];
|
|
}
|
|
|
|
public ReadOnlySpan<byte> ReadInPlace(int size)
|
|
{
|
|
ReadOnlySpan<byte> result = Payload.Slice(_payloadPosition, size);
|
|
|
|
_payloadPosition += BitUtils.AlignUp(size, 4);
|
|
|
|
return result;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential, Size = 0x28)]
|
|
private struct FlatBinderObject
|
|
{
|
|
public int Type;
|
|
public int Flags;
|
|
public long BinderId;
|
|
public long Cookie;
|
|
|
|
private byte _serviceNameStart;
|
|
|
|
public Span<byte> ServiceName => MemoryMarshal.CreateSpan(ref _serviceNameStart, 0x8);
|
|
}
|
|
|
|
public void WriteObject<T>(T obj, string serviceName) where T : IBinder
|
|
{
|
|
FlatBinderObject flatBinderObject = new()
|
|
{
|
|
Type = 2,
|
|
Flags = 0,
|
|
BinderId = HOSBinderDriverServer.GetBinderId(obj),
|
|
};
|
|
|
|
Encoding.ASCII.GetBytes(serviceName).CopyTo(flatBinderObject.ServiceName);
|
|
|
|
WriteUnmanagedType(ref flatBinderObject);
|
|
|
|
// TODO: figure out what this value is
|
|
|
|
WriteInplaceObject(new byte[4] { 0, 0, 0, 0 });
|
|
}
|
|
|
|
public AndroidStrongPointer<T> ReadStrongPointer<T>() where T : unmanaged, IFlattenable
|
|
{
|
|
bool hasObject = ReadBoolean();
|
|
|
|
if (hasObject)
|
|
{
|
|
T obj = ReadFlattenable<T>();
|
|
|
|
return new AndroidStrongPointer<T>(obj);
|
|
}
|
|
else
|
|
{
|
|
return new AndroidStrongPointer<T>();
|
|
}
|
|
}
|
|
|
|
public void WriteStrongPointer<T>(ref AndroidStrongPointer<T> value) where T : unmanaged, IFlattenable
|
|
{
|
|
WriteBoolean(!value.IsNull);
|
|
|
|
if (!value.IsNull)
|
|
{
|
|
WriteFlattenable<T>(ref value.Object);
|
|
}
|
|
}
|
|
|
|
public void WriteFlattenable<T>(ref T value) where T : unmanaged, IFlattenable
|
|
{
|
|
WriteInt64(value.GetFlattenedSize());
|
|
|
|
value.Flatten(this);
|
|
}
|
|
|
|
public void WriteStatus(Status status) => WriteUnmanagedType(ref status);
|
|
public void WriteBoolean(bool value) => WriteUnmanagedType(ref value);
|
|
public void WriteInt32(int value) => WriteUnmanagedType(ref value);
|
|
public void WriteUInt32(uint value) => WriteUnmanagedType(ref value);
|
|
public void WriteInt64(long value) => WriteUnmanagedType(ref value);
|
|
public void WriteUInt64(ulong value) => WriteUnmanagedType(ref value);
|
|
|
|
public void WriteUnmanagedSpan<T>(ReadOnlySpan<T> value) where T : unmanaged
|
|
{
|
|
WriteInplace(MemoryMarshal.Cast<T, byte>(value));
|
|
}
|
|
|
|
public void WriteUnmanagedType<T>(ref T value) where T : unmanaged
|
|
{
|
|
WriteInplace(SpanHelpers.AsByteSpan(ref value));
|
|
}
|
|
|
|
public void WriteInplace(ReadOnlySpan<byte> data)
|
|
{
|
|
Span<byte> result = Payload.Slice(_payloadPosition, data.Length);
|
|
|
|
data.CopyTo(result);
|
|
|
|
_payloadPosition += BitUtils.AlignUp(data.Length, 4);
|
|
}
|
|
|
|
public void WriteInplaceObject(ReadOnlySpan<byte> data)
|
|
{
|
|
Span<byte> result = Objects.Slice(_objectPosition, data.Length);
|
|
|
|
data.CopyTo(result);
|
|
|
|
_objectPosition += BitUtils.AlignUp(data.Length, 4);
|
|
}
|
|
|
|
private void UpdateHeader()
|
|
{
|
|
uint headerSize = (uint)Unsafe.SizeOf<ParcelHeader>();
|
|
|
|
Header.PayloadSize = (uint)_payloadPosition;
|
|
Header.ObjectsSize = (uint)_objectPosition;
|
|
Header.PayloadOffset = headerSize;
|
|
Header.ObjectOffset = Header.PayloadOffset + Header.PayloadSize;
|
|
}
|
|
|
|
public ReadOnlySpan<byte> Finish()
|
|
{
|
|
UpdateHeader();
|
|
|
|
return Raw[..(int)(Header.PayloadSize + Header.ObjectsSize + Unsafe.SizeOf<ParcelHeader>())];
|
|
}
|
|
}
|
|
}
|