diff options
author | Mary <me@thog.eu> | 2021-11-01 23:38:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-01 19:38:13 -0300 |
commit | f41687f4c1948e9e111afd70e979e98ea5de52fa (patch) | |
tree | e7e34e4f8a986c7165cb3eb2fb3e216329d1c04d /Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRenderer.cs | |
parent | e48530e9d9f0bbaeb8fa5978d1a66c99e6fecbac (diff) |
hle: Make Ryujinx.HLE project entirely safe (#2789)
* Remove a bit of unsafety around
* Regenerate StructArrayHelpers with a max element value of 256
* hle: remove unsafe marker from all struct that had it
* hle: make SoftwareKeyboardRenderer.TryCopyTo safe
* hle: remove unsafety in NpadDevice and remove AllowUnsafeBlocks from csproj
* Revert "Regenerate StructArrayHelpers with a max element value of 256"
This reverts commit f32a6e5be094f50571970eb1116b65c080781d05.
* Introduce ByteArray of various size and use that instead of ArrayXXX to avoid stackoverflow in .NET runtime type resolution
* Use ByteArray more
* Add some missing spaces on Pack = 1 for various structs
* Fix broken logic for TryCopyTo
* Address gdkchan's comment
* Address gdkchan's comment
Diffstat (limited to 'Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRenderer.cs')
-rw-r--r-- | Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRenderer.cs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRenderer.cs b/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRenderer.cs index c16b861e..dfd10925 100644 --- a/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRenderer.cs +++ b/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/SoftwareKeyboardRenderer.cs @@ -1,12 +1,14 @@ using Ryujinx.HLE.Ui; using Ryujinx.Memory; using System; +using System.Buffers.Binary; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Drawing.Text; using System.IO; +using System.Numerics; using System.Reflection; using System.Runtime.InteropServices; using System.Threading; @@ -652,7 +654,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard DrawString(graphics, ControllerToggleText, _labelsTextFont, _textNormalBrush, labelPosition); } - private unsafe bool TryCopyTo(IVirtualMemoryManager destination, ulong position) + private bool TryCopyTo(IVirtualMemoryManager destination, ulong position) { if (_surface == null) { @@ -666,23 +668,21 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard Debug.Assert(surfaceData.Stride * surfaceData.Height == _surfaceInfo.Size); // Convert the pixel format used in System.Drawing to the one required by a Switch Surface. - int dataLength = surfaceData.Stride * surfaceData.Height; - byte* dataPointer = (byte*)surfaceData.Scan0; - byte* dataEnd = dataPointer + dataLength; + int dataLength = surfaceData.Stride * surfaceData.Height; - for (; dataPointer < dataEnd; dataPointer += 4) + byte[] data = new byte[dataLength]; + Span<uint> dataConvert = MemoryMarshal.Cast<byte, uint>(data); + + Marshal.Copy(surfaceData.Scan0, data, 0, dataLength); + + for (int i = 0; i < dataConvert.Length; i++) { - *(uint*)dataPointer = (uint)( - (*(dataPointer + 0) << 16) | - (*(dataPointer + 1) << 8 ) | - (*(dataPointer + 2) << 0 ) | - (*(dataPointer + 3) << 24)); + dataConvert[i] = BitOperations.RotateRight(BinaryPrimitives.ReverseEndianness(dataConvert[i]), 8); } try { - Span<byte> dataSpan = new Span<byte>((void*)surfaceData.Scan0, dataLength); - destination.Write(position, dataSpan); + destination.Write(position, data); } finally { |