From edf7e628cadd51e019f6d3723d120e727e50d32e Mon Sep 17 00:00:00 2001 From: Andrey Sukharev Date: Mon, 12 Dec 2022 17:10:05 +0300 Subject: Use method overloads that support trimming. Mark some types to be trimming friendly (#4083) * Use method overloads that support trimming. Mark some types to be trimming friendly * Use generic version of marshalling method --- Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs | 2 +- .../Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs | 3 ++- Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/INfp.cs | 16 ++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) (limited to 'Ryujinx.HLE/HOS') diff --git a/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs b/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs index bd321f6f..ba7efbd7 100644 --- a/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs +++ b/Ryujinx.HLE/HOS/Applets/Error/ErrorApplet.cs @@ -47,7 +47,7 @@ namespace Ryujinx.HLE.HOS.Applets.Error _errorStorage = _normalSession.Pop(); _errorCommonHeader = IApplet.ReadStruct(_errorStorage); - _errorStorage = _errorStorage.Skip(Marshal.SizeOf(typeof(ErrorCommonHeader))).ToArray(); + _errorStorage = _errorStorage.Skip(Marshal.SizeOf()).ToArray(); switch (_errorCommonHeader.Type) { diff --git a/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs b/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs index 74073420..4077ad42 100644 --- a/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs +++ b/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardApplet.cs @@ -9,6 +9,7 @@ using Ryujinx.HLE.Ui.Input; using Ryujinx.Memory; using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -797,7 +798,7 @@ namespace Ryujinx.HLE.HOS.Applets return sb.ToString(); } - private static T ReadStruct(byte[] data) + private static T ReadStruct<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(byte[] data) where T : struct { GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); diff --git a/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/INfp.cs b/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/INfp.cs index fc0c0647..f4ad0366 100644 --- a/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/INfp.cs +++ b/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/INfp.cs @@ -589,9 +589,9 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp ulong outputPosition = context.Request.RecvListBuff[0].Position; - context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize((uint)Marshal.SizeOf(typeof(TagInfo))); + context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize((uint)Marshal.SizeOf()); - MemoryHelper.FillWithZeros(context.Memory, outputPosition, Marshal.SizeOf(typeof(TagInfo))); + MemoryHelper.FillWithZeros(context.Memory, outputPosition, Marshal.SizeOf()); uint deviceHandle = (uint)context.RequestData.ReadUInt64(); @@ -665,9 +665,9 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp ulong outputPosition = context.Request.RecvListBuff[0].Position; - context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize((uint)Marshal.SizeOf(typeof(RegisterInfo))); + context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize((uint)Marshal.SizeOf()); - MemoryHelper.FillWithZeros(context.Memory, outputPosition, Marshal.SizeOf(typeof(RegisterInfo))); + MemoryHelper.FillWithZeros(context.Memory, outputPosition, Marshal.SizeOf()); uint deviceHandle = (uint)context.RequestData.ReadUInt64(); @@ -728,9 +728,9 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp ulong outputPosition = context.Request.RecvListBuff[0].Position; - context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize((uint)Marshal.SizeOf(typeof(CommonInfo))); + context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize((uint)Marshal.SizeOf()); - MemoryHelper.FillWithZeros(context.Memory, outputPosition, Marshal.SizeOf(typeof(CommonInfo))); + MemoryHelper.FillWithZeros(context.Memory, outputPosition, Marshal.SizeOf()); uint deviceHandle = (uint)context.RequestData.ReadUInt64(); @@ -788,9 +788,9 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp ulong outputPosition = context.Request.RecvListBuff[0].Position; - context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize((uint)Marshal.SizeOf(typeof(ModelInfo))); + context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize((uint)Marshal.SizeOf()); - MemoryHelper.FillWithZeros(context.Memory, outputPosition, Marshal.SizeOf(typeof(ModelInfo))); + MemoryHelper.FillWithZeros(context.Memory, outputPosition, Marshal.SizeOf()); uint deviceHandle = (uint)context.RequestData.ReadUInt64(); -- cgit v1.2.3