From 05afb4714a674ee8d6ffac27baad5ed0f15b4299 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Thu, 14 Dec 2017 20:58:55 -0800 Subject: [PATCH 1/5] Convert uses of the Dangerous APIs to use MemoryMarshal.GetReference --- .../src/Interop/BSD/System.Native/Interop.Sysctl.cs | 2 +- .../src/Interop/OSX/Interop.CoreFoundation.CFData.cs | 2 +- .../Interop.Digest.cs | 4 ++-- .../Interop.Hmac.cs | 4 ++-- .../Interop.RSA.cs | 8 ++++---- .../Interop.SecKeyRef.cs | 12 ++++++------ .../Interop.Dsa.cs | 4 ++-- .../Interop.EVP.cs | 2 +- .../Interop.EcDsa.cs | 4 ++-- .../Interop.Hmac.cs | 2 +- .../Interop.OpenSsl.cs | 2 +- .../Interop.Rsa.cs | 8 ++++---- .../Windows/BCrypt/Interop.BCryptFinishHash.cs | 2 +- .../Interop/Windows/BCrypt/Interop.BCryptHashData.cs | 2 +- .../Interop/Windows/NCrypt/Interop.EncryptDecrypt.cs | 4 ++-- .../src/Interop/Windows/NCrypt/Interop.SignVerify.cs | 4 ++-- .../Windows/kernel32/Interop.GetSystemDirectoryW.cs | 2 +- .../System/Globalization/FormatProvider.Number.cs | 12 ++++++------ .../src/System/Memory/FixedBufferExtensions.cs | 6 ++++-- src/Common/src/System/Net/SocketAddressPal.Unix.cs | 4 ++-- .../src/System/Security/Cryptography/AsnReader.cs | 6 +++--- .../src/System/Security/Cryptography/AsnWriter.cs | 8 ++++---- .../src/System.IO.Compression.csproj | 1 + .../src/System/IO/Compression/Crc32Helper.ZLib.cs | 3 ++- .../IO/Compression/DeflateZLib/DeflateStream.cs | 3 ++- .../System/IO/Compression/DeflateZLib/Inflater.cs | 2 +- .../src/System/IO/CharSpanExtensions.Unix.cs | 5 +++-- .../src/System/IO/CharSpanExtensions.Windows.cs | 4 ++-- .../src/System/IO/PathHelpers.Windows.cs | 4 +++- .../src/System/IO/PathHelpers.cs | 9 +++++---- src/System.IO.Pipes/src/System.IO.Pipes.csproj | 1 + .../src/System/IO/Pipes/PipeStream.Unix.cs | 7 ++++--- .../src/System/IO/Pipes/PipeStream.Windows.cs | 4 ++-- .../src/System/Buffers/Binary/Reader.cs | 5 +++-- .../src/System/Buffers/Binary/Writer.cs | 5 +++-- .../src/System/Buffers/Text/Base64Decoder.cs | 7 ++++--- .../src/System/Buffers/Text/Base64Encoder.cs | 7 ++++--- .../Text/Utf8Formatter/Utf8Formatter.Date.G.cs | 3 ++- .../Text/Utf8Formatter/Utf8Formatter.Date.L.cs | 3 ++- .../Text/Utf8Formatter/Utf8Formatter.Date.O.cs | 3 ++- .../Text/Utf8Formatter/Utf8Formatter.Date.R.cs | 3 ++- .../Buffers/Text/Utf8Formatter/Utf8Formatter.Guid.cs | 3 ++- .../Utf8Formatter/Utf8Formatter.Integer.Signed.D.cs | 3 ++- .../Utf8Formatter/Utf8Formatter.Integer.Signed.N.cs | 3 ++- .../Utf8Formatter.Integer.Unsigned.D.cs | 4 +++- .../Utf8Formatter.Integer.Unsigned.N.cs | 3 ++- .../Utf8Formatter.Integer.Unsigned.X.cs | 3 ++- .../Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs | 3 ++- .../tests/MemoryMarshal/GetReference.cs | 2 +- .../src/System/Net/Http/ByteArrayHelpers.cs | 3 ++- .../src/System/Net/Http/Headers/KnownHeaders.cs | 3 ++- .../src/System/Net/Http/Managed/HttpConnection.cs | 3 ++- .../src/System/Net/Http/ReadOnlyMemoryContent.cs | 3 ++- .../src/System/Net/IPAddressParser.cs | 7 ++++--- .../tests/UnitTests/SslApplicationProtocolTests.cs | 3 ++- src/System.Net.Sockets/src/System.Net.Sockets.csproj | 1 + .../src/System/Net/Sockets/Socket.Tasks.cs | 3 ++- .../System/Net/Sockets/SocketAsyncContext.Unix.cs | 4 ++-- .../Net/Sockets/SocketAsyncEventArgs.Windows.cs | 8 ++++---- .../src/System/Net/Sockets/SocketPal.Unix.cs | 6 +++--- .../src/System/Net/Sockets/SocketPal.Windows.cs | 4 ++-- .../src/System.Net.WebSockets.Client.csproj | 1 + .../src/System/Net/WebSockets/WinHttpWebSocket.cs | 2 +- .../src/System/Net/WebSockets/ManagedWebSocket.cs | 2 +- .../src/System/Net/WebSockets/WebSocket.cs | 3 ++- src/System.Private.Xml/src/System.Private.Xml.csproj | 1 + .../src/System/Xml/Core/XmlTextReaderImpl.cs | 3 ++- .../src/System/IO/StreamReader.cs | 3 ++- .../src/System/IO/StreamWriter.cs | 5 +++-- .../src/System/IO/TextWriter.cs | 5 +++-- .../src/System/Numerics/BigInteger.cs | 2 +- .../src/System/Numerics/BigNumber.cs | 2 +- .../tests/System/StringTests.netcoreapp.cs | 2 +- .../Cryptography/HashProviderDispenser.Unix.cs | 6 +++--- .../RandomNumberGeneratorImplementation.cs | 4 +++- .../System.Security.Cryptography.Algorithms.csproj | 1 + .../src/System.Security.Cryptography.Cng.csproj | 1 + .../tests/Asn1/Reader/ComprehensiveReadTests.cs | 4 ++-- .../tests/Asn1/Reader/PeekTests.cs | 4 ++-- .../tests/Asn1/Reader/ReadBMPString.cs | 2 +- .../tests/Asn1/Reader/ReadBitString.cs | 2 +- .../tests/Asn1/Reader/ReadIA5String.cs | 2 +- .../tests/Asn1/Reader/ReadOctetString.cs | 2 +- .../tests/Asn1/Reader/ReadUTF8String.cs | 2 +- .../tests/Asn1/Serializer/SimpleDeserialize.cs | 2 +- 85 files changed, 182 insertions(+), 136 deletions(-) diff --git a/src/Common/src/Interop/BSD/System.Native/Interop.Sysctl.cs b/src/Common/src/Interop/BSD/System.Native/Interop.Sysctl.cs index 2b4c51e165dc..d887b072bc39 100644 --- a/src/Common/src/Interop/BSD/System.Native/Interop.Sysctl.cs +++ b/src/Common/src/Interop/BSD/System.Native/Interop.Sysctl.cs @@ -26,7 +26,7 @@ internal static partial class Sys public static unsafe int Sysctl(Span name, ref byte* value, ref int len) { - fixed (int * ptr = &name.DangerousGetPinnableReference()) + fixed (int * ptr = &MemoryMarshal.GetReference(name)) { return Sysctl(ptr, name.Length, ref value, ref len); } diff --git a/src/Common/src/Interop/OSX/Interop.CoreFoundation.CFData.cs b/src/Common/src/Interop/OSX/Interop.CoreFoundation.CFData.cs index 0e736a4d0a5e..5920e32038e8 100644 --- a/src/Common/src/Interop/OSX/Interop.CoreFoundation.CFData.cs +++ b/src/Common/src/Interop/OSX/Interop.CoreFoundation.CFData.cs @@ -62,7 +62,7 @@ internal static unsafe bool TryCFWriteData(SafeCFDataHandle cfData, Span d } byte* dataBytes = CFDataGetBytePtr(cfData); - fixed (byte* destinationPtr = &destination.DangerousGetPinnableReference()) + fixed (byte* destinationPtr = &MemoryMarshal.GetReference(destination)) { Buffer.MemoryCopy(dataBytes, destinationPtr, destination.Length, length); } diff --git a/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Digest.cs b/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Digest.cs index 8d8b13aeb3bf..9135ee7e62bb 100644 --- a/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Digest.cs +++ b/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Digest.cs @@ -17,13 +17,13 @@ internal static partial class AppleCrypto internal static extern SafeDigestCtxHandle DigestCreate(PAL_HashAlgorithm algorithm, out int cbDigest); internal static int DigestUpdate(SafeDigestCtxHandle ctx, ReadOnlySpan pbData, int cbData) => - DigestUpdate(ctx, ref pbData.DangerousGetPinnableReference(), cbData); + DigestUpdate(ctx, ref MemoryMarshal.GetReference(pbData), cbData); [DllImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_DigestUpdate")] private static extern int DigestUpdate(SafeDigestCtxHandle ctx, ref byte pbData, int cbData); internal static int DigestFinal(SafeDigestCtxHandle ctx, Span pbOutput, int cbOutput) => - DigestFinal(ctx, ref pbOutput.DangerousGetPinnableReference(), cbOutput); + DigestFinal(ctx, ref MemoryMarshal.GetReference(pbOutput), cbOutput); [DllImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_DigestFinal")] private static extern int DigestFinal(SafeDigestCtxHandle ctx, ref byte pbOutput, int cbOutput); diff --git a/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Hmac.cs b/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Hmac.cs index 6dc7d97d7142..1120aca17734 100644 --- a/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Hmac.cs +++ b/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Hmac.cs @@ -20,13 +20,13 @@ internal static partial class AppleCrypto internal static extern unsafe int HmacInit(SafeHmacHandle ctx, [In] byte[] pbKey, int cbKey); internal static int HmacUpdate(SafeHmacHandle ctx, ReadOnlySpan pbData, int cbData) => - HmacUpdate(ctx, ref pbData.DangerousGetPinnableReference(), cbData); + HmacUpdate(ctx, ref MemoryMarshal.GetReference(pbData), cbData); [DllImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_HmacUpdate")] private static extern int HmacUpdate(SafeHmacHandle ctx, ref byte pbData, int cbData); internal static int HmacFinal(SafeHmacHandle ctx, ReadOnlySpan pbOutput, int cbOutput) => - HmacFinal(ctx, ref pbOutput.DangerousGetPinnableReference(), cbOutput); + HmacFinal(ctx, ref MemoryMarshal.GetReference(pbOutput), cbOutput); [DllImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_HmacFinal")] private static extern unsafe int HmacFinal(SafeHmacHandle ctx, ref byte pbOutput, int cbOutput); diff --git a/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.RSA.cs b/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.RSA.cs index 06d86859095c..1c99e6c5e6da 100644 --- a/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.RSA.cs +++ b/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.RSA.cs @@ -28,7 +28,7 @@ private static int RsaEncryptOaep( PAL_HashAlgorithm mgfAlgorithm, out SafeCFDataHandle pEncryptedOut, out SafeCFErrorHandle pErrorOut) => - RsaEncryptOaep(publicKey, ref pbData.DangerousGetPinnableReference(), cbData, mgfAlgorithm, out pEncryptedOut, out pErrorOut); + RsaEncryptOaep(publicKey, ref MemoryMarshal.GetReference(pbData), cbData, mgfAlgorithm, out pEncryptedOut, out pErrorOut); [DllImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_RsaEncryptOaep")] private static extern int RsaEncryptOaep( @@ -45,7 +45,7 @@ private static int RsaEncryptPkcs( int cbData, out SafeCFDataHandle pEncryptedOut, out SafeCFErrorHandle pErrorOut) => - RsaEncryptPkcs(publicKey, ref pbData.DangerousGetPinnableReference(), cbData, out pEncryptedOut, out pErrorOut); + RsaEncryptPkcs(publicKey, ref MemoryMarshal.GetReference(pbData), cbData, out pEncryptedOut, out pErrorOut); [DllImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_RsaEncryptPkcs")] private static extern int RsaEncryptPkcs( @@ -62,7 +62,7 @@ private static int RsaDecryptOaep( PAL_HashAlgorithm mgfAlgorithm, out SafeCFDataHandle pEncryptedOut, out SafeCFErrorHandle pErrorOut) => - RsaDecryptOaep(publicKey, ref pbData.DangerousGetPinnableReference(), cbData, mgfAlgorithm, out pEncryptedOut, out pErrorOut); + RsaDecryptOaep(publicKey, ref MemoryMarshal.GetReference(pbData), cbData, mgfAlgorithm, out pEncryptedOut, out pErrorOut); [DllImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_RsaDecryptOaep")] private static extern int RsaDecryptOaep( @@ -79,7 +79,7 @@ private static int RsaDecryptPkcs( int cbData, out SafeCFDataHandle pEncryptedOut, out SafeCFErrorHandle pErrorOut) => - RsaDecryptPkcs(publicKey, ref pbData.DangerousGetPinnableReference(), cbData, out pEncryptedOut, out pErrorOut); + RsaDecryptPkcs(publicKey, ref MemoryMarshal.GetReference(pbData), cbData, out pEncryptedOut, out pErrorOut); [DllImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_RsaDecryptPkcs")] private static extern int RsaDecryptPkcs( diff --git a/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.cs b/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.cs index 83fa6433ca1b..37dd66d5acb2 100644 --- a/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.cs +++ b/src/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.cs @@ -28,7 +28,7 @@ private static int AppleCryptoNative_GenerateSignature( out SafeCFDataHandle pSignatureOut, out SafeCFErrorHandle pErrorOut) => AppleCryptoNative_GenerateSignature( - privateKey, ref pbDataHash.DangerousGetPinnableReference(), cbDataHash, out pSignatureOut, out pErrorOut); + privateKey, ref MemoryMarshal.GetReference(pbDataHash), cbDataHash, out pSignatureOut, out pErrorOut); [DllImport(Libraries.AppleCryptoNative)] private static extern int AppleCryptoNative_GenerateSignature( @@ -46,7 +46,7 @@ private static int AppleCryptoNative_GenerateSignatureWithHashAlgorithm( out SafeCFDataHandle pSignatureOut, out SafeCFErrorHandle pErrorOut) => AppleCryptoNative_GenerateSignatureWithHashAlgorithm( - privateKey, ref pbDataHash.DangerousGetPinnableReference(), cbDataHash, hashAlgorithm, out pSignatureOut, out pErrorOut); + privateKey, ref MemoryMarshal.GetReference(pbDataHash), cbDataHash, hashAlgorithm, out pSignatureOut, out pErrorOut); [DllImport(Libraries.AppleCryptoNative)] private static extern int AppleCryptoNative_GenerateSignatureWithHashAlgorithm( @@ -66,9 +66,9 @@ private static int AppleCryptoNative_VerifySignature( out SafeCFErrorHandle pErrorOut) => AppleCryptoNative_VerifySignature( publicKey, - ref pbDataHash.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(pbDataHash), cbDataHash, - ref pbSignature.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(pbSignature), cbSignature, out pErrorOut); @@ -91,9 +91,9 @@ private static int AppleCryptoNative_VerifySignatureWithHashAlgorithm( out SafeCFErrorHandle pErrorOut) => AppleCryptoNative_VerifySignatureWithHashAlgorithm( publicKey, - ref pbDataHash.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(pbDataHash), cbDataHash, - ref pbSignature.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(pbSignature), cbSignature, hashAlgorithm, out pErrorOut); diff --git a/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Dsa.cs b/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Dsa.cs index 4144e9d710a0..bb610f60f3ad 100644 --- a/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Dsa.cs +++ b/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Dsa.cs @@ -67,14 +67,14 @@ internal static int DsaKeySize(SafeDsaHandle dsa) } internal static bool DsaSign(SafeDsaHandle dsa, ReadOnlySpan hash, int hashLength, ReadOnlySpan refSignature, out int outSignatureLength) => - DsaSign(dsa, ref hash.DangerousGetPinnableReference(), hashLength, ref refSignature.DangerousGetPinnableReference(), out outSignatureLength); + DsaSign(dsa, ref MemoryMarshal.GetReference(hash), hashLength, ref MemoryMarshal.GetReference(refSignature), out outSignatureLength); [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DsaSign")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool DsaSign(SafeDsaHandle dsa, ref byte hash, int hashLength, ref byte refSignature, out int outSignatureLength); internal static bool DsaVerify(SafeDsaHandle dsa, ReadOnlySpan hash, int hashLength, ReadOnlySpan signature, int signatureLength) => - DsaVerify(dsa, ref hash.DangerousGetPinnableReference(), hashLength, ref signature.DangerousGetPinnableReference(), signatureLength); + DsaVerify(dsa, ref MemoryMarshal.GetReference(hash), hashLength, ref MemoryMarshal.GetReference(signature), signatureLength); [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DsaVerify")] [return: MarshalAs(UnmanagedType.Bool)] diff --git a/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.cs b/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.cs index b2ce394c75b4..67a9b542306a 100644 --- a/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.cs +++ b/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.cs @@ -20,7 +20,7 @@ internal static partial class Crypto internal extern static int EvpDigestReset(SafeEvpMdCtxHandle ctx, IntPtr type); internal static int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ReadOnlySpan d, int cnt) => - EvpDigestUpdate(ctx, ref d.DangerousGetPinnableReference(), cnt); + EvpDigestUpdate(ctx, ref MemoryMarshal.GetReference(d), cnt); [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpDigestUpdate")] private extern static int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ref byte d, int cnt); diff --git a/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.cs b/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.cs index d466797e7137..91c1beab99fe 100644 --- a/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.cs +++ b/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.cs @@ -11,14 +11,14 @@ internal static partial class Interop internal static partial class Crypto { internal static bool EcDsaSign(ReadOnlySpan dgst, int dlen, Span sig, [In, Out] ref int siglen, SafeEcKeyHandle ecKey) => - EcDsaSign(ref dgst.DangerousGetPinnableReference(), dlen, ref sig.DangerousGetPinnableReference(), ref siglen, ecKey); + EcDsaSign(ref MemoryMarshal.GetReference(dgst), dlen, ref MemoryMarshal.GetReference(sig), ref siglen, ecKey); [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EcDsaSign")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool EcDsaSign(ref byte dgst, int dlen, ref byte sig, [In, Out] ref int siglen, SafeEcKeyHandle ecKey); internal static unsafe int EcDsaVerify(ReadOnlySpan dgst, int dgst_len, ReadOnlySpan sigbuf, int sig_len, SafeEcKeyHandle ecKey) => - EcDsaVerify(ref dgst.DangerousGetPinnableReference(), dgst_len, ref sigbuf.DangerousGetPinnableReference(), sig_len, ecKey); + EcDsaVerify(ref MemoryMarshal.GetReference(dgst), dgst_len, ref MemoryMarshal.GetReference(sigbuf), sig_len, ecKey); /*- * returns diff --git a/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Hmac.cs b/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Hmac.cs index bf151fa0aea8..6849b4f2e09e 100644 --- a/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Hmac.cs +++ b/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Hmac.cs @@ -20,7 +20,7 @@ internal static partial class Crypto internal extern static int HmacReset(SafeHmacCtxHandle ctx); internal static int HmacUpdate(SafeHmacCtxHandle ctx, ReadOnlySpan data, int len) => - HmacUpdate(ctx, ref data.DangerousGetPinnableReference(), len); + HmacUpdate(ctx, ref MemoryMarshal.GetReference(data), len); [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_HmacUpdate")] private extern static int HmacUpdate(SafeHmacCtxHandle ctx, ref byte data, int len); diff --git a/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs b/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs index c37b1306043e..2edbc6c1950d 100644 --- a/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs +++ b/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs @@ -377,7 +377,7 @@ private static unsafe int AlpnServerSelectCallback(IntPtr ssl, out byte* outp, o Span clientProto = clientList.Slice(1, length); if (clientProto.SequenceEqual(protocolList[i].Protocol.Span)) { - outp = (byte*)Unsafe.AsPointer(ref clientProto.DangerousGetPinnableReference()); + outp = (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(clientProto)); outlen = length; return Ssl.SSL_TLSEXT_ERR_OK; } diff --git a/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Rsa.cs b/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Rsa.cs index 549727b31dce..1748a66547c8 100644 --- a/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Rsa.cs +++ b/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Rsa.cs @@ -31,7 +31,7 @@ internal static int RsaPublicEncrypt( Span to, SafeRsaHandle rsa, RsaPadding padding) => - RsaPublicEncrypt(flen, ref from.DangerousGetPinnableReference(), ref to.DangerousGetPinnableReference(), rsa, padding); + RsaPublicEncrypt(flen, ref MemoryMarshal.GetReference(from), ref MemoryMarshal.GetReference(to), rsa, padding); [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaPublicEncrypt")] private extern static int RsaPublicEncrypt( @@ -47,7 +47,7 @@ internal static int RsaPrivateDecrypt( Span to, SafeRsaHandle rsa, RsaPadding padding) => - RsaPrivateDecrypt(flen, ref from.DangerousGetPinnableReference(), ref to.DangerousGetPinnableReference(), rsa, padding); + RsaPrivateDecrypt(flen, ref MemoryMarshal.GetReference(from), ref MemoryMarshal.GetReference(to), rsa, padding); [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaPrivateDecrypt")] private extern static int RsaPrivateDecrypt( @@ -64,14 +64,14 @@ private extern static int RsaPrivateDecrypt( internal static extern int RsaGenerateKeyEx(SafeRsaHandle rsa, int bits, SafeBignumHandle e); internal static bool RsaSign(int type, ReadOnlySpan m, int m_len, Span sigret, out int siglen, SafeRsaHandle rsa) => - RsaSign(type, ref m.DangerousGetPinnableReference(), m_len, ref sigret.DangerousGetPinnableReference(), out siglen, rsa); + RsaSign(type, ref MemoryMarshal.GetReference(m), m_len, ref MemoryMarshal.GetReference(sigret), out siglen, rsa); [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaSign")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool RsaSign(int type, ref byte m, int m_len, ref byte sigret, out int siglen, SafeRsaHandle rsa); internal static bool RsaVerify(int type, ReadOnlySpan m, int m_len, ReadOnlySpan sigbuf, int siglen, SafeRsaHandle rsa) => - RsaVerify(type, ref m.DangerousGetPinnableReference(), m_len, ref sigbuf.DangerousGetPinnableReference(), siglen, rsa); + RsaVerify(type, ref MemoryMarshal.GetReference(m), m_len, ref MemoryMarshal.GetReference(sigbuf), siglen, rsa); [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaVerify")] [return: MarshalAs(UnmanagedType.Bool)] diff --git a/src/Common/src/Interop/Windows/BCrypt/Interop.BCryptFinishHash.cs b/src/Common/src/Interop/Windows/BCrypt/Interop.BCryptFinishHash.cs index 3bf2877685d0..7ffda6ca6c03 100644 --- a/src/Common/src/Interop/Windows/BCrypt/Interop.BCryptFinishHash.cs +++ b/src/Common/src/Interop/Windows/BCrypt/Interop.BCryptFinishHash.cs @@ -11,7 +11,7 @@ internal partial class Interop internal partial class BCrypt { internal static NTSTATUS BCryptFinishHash(SafeBCryptHashHandle hHash, Span pbOutput, int cbOutput, int dwFlags) => - BCryptFinishHash(hHash, ref pbOutput.DangerousGetPinnableReference(), cbOutput, dwFlags); + BCryptFinishHash(hHash, ref MemoryMarshal.GetReference(pbOutput), cbOutput, dwFlags); [DllImport(Libraries.BCrypt, CharSet = CharSet.Unicode)] private static extern NTSTATUS BCryptFinishHash(SafeBCryptHashHandle hHash, ref byte pbOutput, int cbOutput, int dwFlags); diff --git a/src/Common/src/Interop/Windows/BCrypt/Interop.BCryptHashData.cs b/src/Common/src/Interop/Windows/BCrypt/Interop.BCryptHashData.cs index 1ea3ade6ec4c..2832c7b68c44 100644 --- a/src/Common/src/Interop/Windows/BCrypt/Interop.BCryptHashData.cs +++ b/src/Common/src/Interop/Windows/BCrypt/Interop.BCryptHashData.cs @@ -12,7 +12,7 @@ internal partial class Interop internal partial class BCrypt { internal static NTSTATUS BCryptHashData(SafeBCryptHashHandle hHash, ReadOnlySpan pbInput, int cbInput, int dwFlags) => - BCryptHashData(hHash, ref pbInput.DangerousGetPinnableReference(), cbInput, dwFlags); + BCryptHashData(hHash, ref MemoryMarshal.GetReference(pbInput), cbInput, dwFlags); [DllImport(Libraries.BCrypt, CharSet = CharSet.Unicode)] private static extern NTSTATUS BCryptHashData(SafeBCryptHashHandle hHash, ref byte pbInput, int cbInput, int dwFlags); diff --git a/src/Common/src/Interop/Windows/NCrypt/Interop.EncryptDecrypt.cs b/src/Common/src/Interop/Windows/NCrypt/Interop.EncryptDecrypt.cs index 1690876e8b61..d9d9a397c7c2 100644 --- a/src/Common/src/Interop/Windows/NCrypt/Interop.EncryptDecrypt.cs +++ b/src/Common/src/Interop/Windows/NCrypt/Interop.EncryptDecrypt.cs @@ -11,13 +11,13 @@ internal static partial class Interop internal static partial class NCrypt { internal static unsafe ErrorCode NCryptEncrypt(SafeNCryptKeyHandle hKey, ReadOnlySpan pbInput, int cbInput, void* pPaddingInfo, Span pbOutput, int cbOutput, out int pcbResult, AsymmetricPaddingMode dwFlags) => - NCryptEncrypt(hKey, ref pbInput.DangerousGetPinnableReference(), cbInput, pPaddingInfo, ref pbOutput.DangerousGetPinnableReference(), cbOutput, out pcbResult, dwFlags); + NCryptEncrypt(hKey, ref MemoryMarshal.GetReference(pbInput), cbInput, pPaddingInfo, ref MemoryMarshal.GetReference(pbOutput), cbOutput, out pcbResult, dwFlags); [DllImport(Interop.Libraries.NCrypt, CharSet = CharSet.Unicode)] private static extern unsafe ErrorCode NCryptEncrypt(SafeNCryptKeyHandle hKey, ref byte pbInput, int cbInput, void* pPaddingInfo, ref byte pbOutput, int cbOutput, out int pcbResult, AsymmetricPaddingMode dwFlags); internal static unsafe ErrorCode NCryptDecrypt(SafeNCryptKeyHandle hKey, ReadOnlySpan pbInput, int cbInput, void* pPaddingInfo, Span pbOutput, int cbOutput, out int pcbResult, AsymmetricPaddingMode dwFlags) => - NCryptDecrypt(hKey, ref pbInput.DangerousGetPinnableReference(), cbInput, pPaddingInfo, ref pbOutput.DangerousGetPinnableReference(), cbOutput, out pcbResult, dwFlags); + NCryptDecrypt(hKey, ref MemoryMarshal.GetReference(pbInput), cbInput, pPaddingInfo, ref MemoryMarshal.GetReference(pbOutput), cbOutput, out pcbResult, dwFlags); [DllImport(Interop.Libraries.NCrypt, CharSet = CharSet.Unicode)] private static extern unsafe ErrorCode NCryptDecrypt(SafeNCryptKeyHandle hKey, ref byte pbInput, int cbInput, void* pPaddingInfo, ref byte pbOutput, int cbOutput, out int pcbResult, AsymmetricPaddingMode dwFlags); diff --git a/src/Common/src/Interop/Windows/NCrypt/Interop.SignVerify.cs b/src/Common/src/Interop/Windows/NCrypt/Interop.SignVerify.cs index ddbaa508c14a..9626e0ba2e43 100644 --- a/src/Common/src/Interop/Windows/NCrypt/Interop.SignVerify.cs +++ b/src/Common/src/Interop/Windows/NCrypt/Interop.SignVerify.cs @@ -11,13 +11,13 @@ internal static partial class Interop internal static partial class NCrypt { internal static unsafe ErrorCode NCryptSignHash(SafeNCryptKeyHandle hKey, void* pPaddingInfo, ReadOnlySpan pbHashValue, int cbHashValue, Span pbSignature, int cbSignature, out int pcbResult, AsymmetricPaddingMode dwFlags) => - NCryptSignHash(hKey, pPaddingInfo, ref pbHashValue.DangerousGetPinnableReference(), cbHashValue, ref pbSignature.DangerousGetPinnableReference(), cbSignature, out pcbResult, dwFlags); + NCryptSignHash(hKey, pPaddingInfo, ref MemoryMarshal.GetReference(pbHashValue), cbHashValue, ref MemoryMarshal.GetReference(pbSignature), cbSignature, out pcbResult, dwFlags); [DllImport(Libraries.NCrypt, CharSet = CharSet.Unicode)] private static extern unsafe ErrorCode NCryptSignHash(SafeNCryptKeyHandle hKey, void* pPaddingInfo, ref byte pbHashValue, int cbHashValue, ref byte pbSignature, int cbSignature, out int pcbResult, AsymmetricPaddingMode dwFlags); internal static unsafe ErrorCode NCryptVerifySignature(SafeNCryptKeyHandle hKey, void* pPaddingInfo, ReadOnlySpan pbHashValue, int cbHashValue, ReadOnlySpan pbSignature, int cbSignature, AsymmetricPaddingMode dwFlags) => - NCryptVerifySignature(hKey, pPaddingInfo, ref pbHashValue.DangerousGetPinnableReference(), cbHashValue, ref pbSignature.DangerousGetPinnableReference(), cbSignature, dwFlags); + NCryptVerifySignature(hKey, pPaddingInfo, ref MemoryMarshal.GetReference(pbHashValue), cbHashValue, ref MemoryMarshal.GetReference(pbSignature), cbSignature, dwFlags); [DllImport(Libraries.NCrypt, CharSet = CharSet.Unicode)] private static extern unsafe ErrorCode NCryptVerifySignature(SafeNCryptKeyHandle hKey, void* pPaddingInfo, ref byte pbHashValue, int cbHashValue, ref byte pbSignature, int cbSignature, AsymmetricPaddingMode dwFlags); diff --git a/src/Common/src/Interop/Windows/kernel32/Interop.GetSystemDirectoryW.cs b/src/Common/src/Interop/Windows/kernel32/Interop.GetSystemDirectoryW.cs index 25c59d743bb1..cf1b31d62c0c 100644 --- a/src/Common/src/Interop/Windows/kernel32/Interop.GetSystemDirectoryW.cs +++ b/src/Common/src/Interop/Windows/kernel32/Interop.GetSystemDirectoryW.cs @@ -14,7 +14,7 @@ internal static partial class Kernel32 internal static unsafe int GetSystemDirectoryW(Span buffer) { - fixed (char* bufferPtr = &buffer.DangerousGetPinnableReference()) + fixed (char* bufferPtr = &MemoryMarshal.GetReference(buffer)) { return GetSystemDirectoryW(bufferPtr, buffer.Length); } diff --git a/src/Common/src/System/Globalization/FormatProvider.Number.cs b/src/Common/src/System/Globalization/FormatProvider.Number.cs index d2690f964ae7..7b5f20f6dc7a 100644 --- a/src/Common/src/System/Globalization/FormatProvider.Number.cs +++ b/src/Common/src/System/Globalization/FormatProvider.Number.cs @@ -549,7 +549,7 @@ private static unsafe bool ParseNumber(ref char* str, NumberStyles options, ref private static unsafe bool TrailingZeros(ReadOnlySpan s, int index) { - fixed (char* sPtr = &s.DangerousGetPinnableReference()) + fixed (char* sPtr = &MemoryMarshal.GetReference(s)) { var span = new Span(sPtr, s.Length); // For compatibility, we need to allow trailing zeros at the end of a number string @@ -568,7 +568,7 @@ internal static unsafe bool TryStringToNumber(ReadOnlySpan str, NumberStyl { Debug.Assert(numfmt != null); - fixed (char* stringPointer = &str.DangerousGetPinnableReference()) + fixed (char* stringPointer = &MemoryMarshal.GetReference(str)) { char* p = stringPointer; if (!ParseNumber(ref p, options, ref number, sb, numfmt, parseDecimal) @@ -638,7 +638,7 @@ internal static unsafe void Int32ToDecChars(char* buffer, ref int index, uint va internal static unsafe char ParseFormatSpecifier(ReadOnlySpan format, out int digits) { - fixed (char* formatPtr = &format.DangerousGetPinnableReference()) + fixed (char* formatPtr = &MemoryMarshal.GetReference(format)) { var formatSpan = new Span(formatPtr, format.Length); char c = default; @@ -1219,7 +1219,7 @@ private static unsafe int FindSection(ReadOnlySpan format, int section) return 0; } - fixed (char* pFormat = &format.DangerousGetPinnableReference()) + fixed (char* pFormat = &MemoryMarshal.GetReference(format)) { int src = 0; for (;;) @@ -1295,7 +1295,7 @@ internal static unsafe void NumberToStringFormat(ref ValueStringBuilder sb, ref scaleAdjust = 0; src = section; - fixed (char* pFormat = &format.DangerousGetPinnableReference()) + fixed (char* pFormat = &MemoryMarshal.GetReference(format)) { while (src < format.Length && (ch = pFormat[src++]) != 0 && ch != ';') { @@ -1485,7 +1485,7 @@ internal static unsafe void NumberToStringFormat(ref ValueStringBuilder sb, ref bool decimalWritten = false; - fixed (char* pFormat = &format.DangerousGetPinnableReference()) + fixed (char* pFormat = &MemoryMarshal.GetReference(format)) { char* cur = dig; diff --git a/src/Common/src/System/Memory/FixedBufferExtensions.cs b/src/Common/src/System/Memory/FixedBufferExtensions.cs index 08589a7ea3dc..97fe385e59c0 100644 --- a/src/Common/src/System/Memory/FixedBufferExtensions.cs +++ b/src/Common/src/System/Memory/FixedBufferExtensions.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Runtime.InteropServices; + namespace System { internal static class FixedBufferExtensions @@ -11,7 +13,7 @@ internal static class FixedBufferExtensions /// internal unsafe static string GetStringFromFixedBuffer(this ReadOnlySpan span) { - fixed (char* c = &span.DangerousGetPinnableReference()) + fixed (char* c = &MemoryMarshal.GetReference(span)) { return new string(c, 0, span.GetFixedBufferStringLength()); } @@ -35,7 +37,7 @@ internal unsafe static bool FixedBufferEqualsString(this ReadOnlySpan span if (value == null || value.Length > span.Length) return false; - fixed (char* spanPtr = &span.DangerousGetPinnableReference()) + fixed (char* spanPtr = &MemoryMarshal.GetReference(span)) { var readWriteSpan = new Span(spanPtr, span.Length); int i = 0; diff --git a/src/Common/src/System/Net/SocketAddressPal.Unix.cs b/src/Common/src/System/Net/SocketAddressPal.Unix.cs index 93f3377939bc..5e5267024581 100644 --- a/src/Common/src/System/Net/SocketAddressPal.Unix.cs +++ b/src/Common/src/System/Net/SocketAddressPal.Unix.cs @@ -119,7 +119,7 @@ public static unsafe void GetIPv6Address(byte[] buffer, Span address, out uint localScope; Interop.Error err; fixed (byte* rawAddress = buffer) - fixed (byte* ipAddress = &address.DangerousGetPinnableReference()) + fixed (byte* ipAddress = &MemoryMarshal.GetReference(address)) { err = Interop.Sys.GetIPv6Address(rawAddress, buffer.Length, ipAddress, address.Length, &localScope); } @@ -147,7 +147,7 @@ public static unsafe void SetIPv4Address(byte[] buffer, byte* address) public static unsafe void SetIPv6Address(byte[] buffer, Span address, uint scope) { - fixed (byte* rawInput = &address.DangerousGetPinnableReference()) + fixed (byte* rawInput = &MemoryMarshal.GetReference(address)) { SetIPv6Address(buffer, rawInput, address.Length, scope); } diff --git a/src/Common/src/System/Security/Cryptography/AsnReader.cs b/src/Common/src/System/Security/Cryptography/AsnReader.cs index 0d8e69665c13..f46529440a16 100644 --- a/src/Common/src/System/Security/Cryptography/AsnReader.cs +++ b/src/Common/src/System/Security/Cryptography/AsnReader.cs @@ -1930,8 +1930,8 @@ private static unsafe bool TryCopyCharacterString( return true; } - fixed (byte* bytePtr = &source.DangerousGetPinnableReference()) - fixed (char* charPtr = &destination.DangerousGetPinnableReference()) + fixed (byte* bytePtr = &MemoryMarshal.GetReference(source)) + fixed (char* charPtr = &MemoryMarshal.GetReference(destination)) { try { @@ -1981,7 +1981,7 @@ private string GetCharacterString( { unsafe { - fixed (byte* bytePtr = &contents.DangerousGetPinnableReference()) + fixed (byte* bytePtr = &MemoryMarshal.GetReference(contents)) { try { diff --git a/src/Common/src/System/Security/Cryptography/AsnWriter.cs b/src/Common/src/System/Security/Cryptography/AsnWriter.cs index dec1154ef455..432dd1d55bdb 100644 --- a/src/Common/src/System/Security/Cryptography/AsnWriter.cs +++ b/src/Common/src/System/Security/Cryptography/AsnWriter.cs @@ -1414,7 +1414,7 @@ private void WriteCharacterStringCore(Asn1Tag tag, Text.Encoding encoding, ReadO // TODO: Split this for netstandard vs netcoreapp for span?. unsafe { - fixed (char* strPtr = &str.DangerousGetPinnableReference()) + fixed (char* strPtr = &MemoryMarshal.GetReference(str)) { size = encoding.GetByteCount(strPtr, str.Length); @@ -1431,7 +1431,7 @@ private void WriteCharacterStringCore(Asn1Tag tag, Text.Encoding encoding, ReadO // TODO: Split this for netstandard vs netcoreapp for span?. unsafe { - fixed (char* strPtr = &str.DangerousGetPinnableReference()) + fixed (char* strPtr = &MemoryMarshal.GetReference(str)) { if (size < 0) { @@ -1443,7 +1443,7 @@ private void WriteCharacterStringCore(Asn1Tag tag, Text.Encoding encoding, ReadO WriteLength(size); Span dest = _buffer.AsSpan().Slice(_offset, size); - fixed (byte* destPtr = &dest.DangerousGetPinnableReference()) + fixed (byte* destPtr = &MemoryMarshal.GetReference(dest)) { int written = encoding.GetBytes(strPtr, str.Length, destPtr, dest.Length); @@ -1468,7 +1468,7 @@ private void WriteConstructedCerCharacterString(Asn1Tag tag, Text.Encoding encod // TODO: Split this for netstandard vs netcoreapp for span?. unsafe { - fixed (char* strPtr = &str.DangerousGetPinnableReference()) + fixed (char* strPtr = &MemoryMarshal.GetReference(str)) { tmp = ArrayPool.Shared.Rent(size); diff --git a/src/System.IO.Compression/src/System.IO.Compression.csproj b/src/System.IO.Compression/src/System.IO.Compression.csproj index 7f0beb87da08..7144c677ef79 100644 --- a/src/System.IO.Compression/src/System.IO.Compression.csproj +++ b/src/System.IO.Compression/src/System.IO.Compression.csproj @@ -103,6 +103,7 @@ + diff --git a/src/System.IO.Compression/src/System/IO/Compression/Crc32Helper.ZLib.cs b/src/System.IO.Compression/src/System/IO/Compression/Crc32Helper.ZLib.cs index bbfe6acd6e04..459252ae4b97 100644 --- a/src/System.IO.Compression/src/System/IO/Compression/Crc32Helper.ZLib.cs +++ b/src/System.IO.Compression/src/System/IO/Compression/Crc32Helper.ZLib.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using System.Runtime.InteropServices; namespace System.IO.Compression { @@ -20,7 +21,7 @@ public static unsafe uint UpdateCrc32(uint crc32, byte[] buffer, int offset, int public static unsafe uint UpdateCrc32(uint crc32, ReadOnlySpan buffer) { - fixed (byte* bufferPtr = &buffer.DangerousGetPinnableReference()) + fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer)) { return Interop.zlib.crc32(crc32, bufferPtr, buffer.Length); } diff --git a/src/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs b/src/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs index 7a7b9f07edee..26939accc608 100644 --- a/src/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs +++ b/src/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs @@ -5,6 +5,7 @@ using System.Buffers; using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -493,7 +494,7 @@ internal void WriteCore(ReadOnlySpan source) unsafe { // Pass new bytes through deflater and write them too: - fixed (byte* bufferPtr = &source.DangerousGetPinnableReference()) + fixed (byte* bufferPtr = &MemoryMarshal.GetReference(source)) { _deflater.SetInput(bufferPtr, source.Length); WriteDeflaterOutput(); diff --git a/src/System.IO.Compression/src/System/IO/Compression/DeflateZLib/Inflater.cs b/src/System.IO.Compression/src/System/IO/Compression/DeflateZLib/Inflater.cs index e55da6de3cfb..e045555d3615 100644 --- a/src/System.IO.Compression/src/System/IO/Compression/DeflateZLib/Inflater.cs +++ b/src/System.IO.Compression/src/System/IO/Compression/DeflateZLib/Inflater.cs @@ -70,7 +70,7 @@ public unsafe int Inflate(Span destination) if (destination.Length == 0) return 0; - fixed (byte* bufPtr = &destination.DangerousGetPinnableReference()) + fixed (byte* bufPtr = &MemoryMarshal.GetReference(destination)) { return InflateVerified(bufPtr, destination.Length); } diff --git a/src/System.IO.FileSystem/src/System/IO/CharSpanExtensions.Unix.cs b/src/System.IO.FileSystem/src/System/IO/CharSpanExtensions.Unix.cs index e985003d2e47..a1fae547774f 100644 --- a/src/System.IO.FileSystem/src/System/IO/CharSpanExtensions.Unix.cs +++ b/src/System.IO.FileSystem/src/System/IO/CharSpanExtensions.Unix.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Runtime.InteropServices; namespace System.IO { @@ -16,8 +17,8 @@ internal static unsafe bool EqualsOrdinal(ReadOnlySpan first, ReadOnlySpan if (!ignoreCase) return first.SequenceEqual(second); - fixed (char* fp = &first.DangerousGetPinnableReference()) - fixed (char* sp = &second.DangerousGetPinnableReference()) + fixed (char* fp = &MemoryMarshal.GetReference(first)) + fixed (char* sp = &MemoryMarshal.GetReference(second)) { char* f = fp; char* s = sp; diff --git a/src/System.IO.FileSystem/src/System/IO/CharSpanExtensions.Windows.cs b/src/System.IO.FileSystem/src/System/IO/CharSpanExtensions.Windows.cs index a0c1481048ca..05036350384a 100644 --- a/src/System.IO.FileSystem/src/System/IO/CharSpanExtensions.Windows.cs +++ b/src/System.IO.FileSystem/src/System/IO/CharSpanExtensions.Windows.cs @@ -13,9 +13,9 @@ internal static partial class CharSpanExtensions internal static unsafe int CompareOrdinal(ReadOnlySpan first, ReadOnlySpan second, bool ignoreCase = false) { int result = Interop.Kernel32.CompareStringOrdinal( - ref first.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(first), first.Length, - ref second.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(second), second.Length, ignoreCase); diff --git a/src/System.IO.FileSystem/src/System/IO/PathHelpers.Windows.cs b/src/System.IO.FileSystem/src/System/IO/PathHelpers.Windows.cs index 8fa39312e5aa..990527577b05 100644 --- a/src/System.IO.FileSystem/src/System/IO/PathHelpers.Windows.cs +++ b/src/System.IO.FileSystem/src/System/IO/PathHelpers.Windows.cs @@ -2,13 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Runtime.InteropServices; + namespace System.IO { internal static partial class PathInternal { internal static unsafe int GetRootLength(ReadOnlySpan path) { - fixed (char* p = &path.DangerousGetPinnableReference()) + fixed (char* p = &MemoryMarshal.GetReference(path)) { return (int)GetRootLength(p, (uint)path.Length); } diff --git a/src/System.IO.FileSystem/src/System/IO/PathHelpers.cs b/src/System.IO.FileSystem/src/System/IO/PathHelpers.cs index fb72afbff635..886b14721044 100644 --- a/src/System.IO.FileSystem/src/System/IO/PathHelpers.cs +++ b/src/System.IO.FileSystem/src/System/IO/PathHelpers.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.IO { @@ -113,7 +114,7 @@ internal unsafe static string CombineNoChecks(string first, string second) private unsafe static string CombineNoChecksInternal(ReadOnlySpan first, ReadOnlySpan second) { Debug.Assert(first.Length > 0 && second.Length > 0, "should have dealt with empty paths"); - fixed (char* f = &first.DangerousGetPinnableReference(), s = &second.DangerousGetPinnableReference()) + fixed (char* f = &MemoryMarshal.GetReference(first), s = &MemoryMarshal.GetReference(second)) { var firstSpan = new Span(f, first.Length); var secondSpan = new Span(s, second.Length); @@ -137,7 +138,7 @@ private unsafe static string CombineNoChecksInternal(ReadOnlySpan first, R private unsafe static string CombineNoChecksInternal(ReadOnlySpan first, ReadOnlySpan second, ReadOnlySpan third) { Debug.Assert(first.Length > 0 && second.Length > 0 && third.Length > 0, "should have dealt with empty paths"); - fixed (char* f = &first.DangerousGetPinnableReference(), s = &second.DangerousGetPinnableReference(), t = &third.DangerousGetPinnableReference()) + fixed (char* f = &MemoryMarshal.GetReference(first), s = &MemoryMarshal.GetReference(second), t = &MemoryMarshal.GetReference(third)) { var firstSpan = new Span(f, first.Length); var secondSpan = new Span(s, second.Length); @@ -171,7 +172,7 @@ private unsafe static string CombineNoChecksInternal(ReadOnlySpan first, R [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe bool IsDotOrDotDot(ReadOnlySpan fileName) { - fixed (char* fileNamePtr = &fileName.DangerousGetPinnableReference()) + fixed (char* fileNamePtr = &MemoryMarshal.GetReference(fileName)) { var fileNameSpan = new Span(fileNamePtr, fileName.Length); return !(fileName.Length > 2 @@ -187,7 +188,7 @@ public static unsafe ReadOnlySpan GetDirectoryNameNoChecks(ReadOnlySpan(pathPtr, path.Length); if (i > root) diff --git a/src/System.IO.Pipes/src/System.IO.Pipes.csproj b/src/System.IO.Pipes/src/System.IO.Pipes.csproj index fb683ea8dc9b..e927afffe58f 100644 --- a/src/System.IO.Pipes/src/System.IO.Pipes.csproj +++ b/src/System.IO.Pipes/src/System.IO.Pipes.csproj @@ -245,6 +245,7 @@ + diff --git a/src/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs b/src/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs index 4a44d62487dc..1f4d2a9e263a 100644 --- a/src/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs +++ b/src/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Net.Sockets; +using System.Runtime.InteropServices; using System.Security; using System.Threading; using System.Threading.Tasks; @@ -114,7 +115,7 @@ private unsafe int ReadCore(Span buffer) } // For anonymous pipes, read from the file descriptor. - fixed (byte* bufPtr = &buffer.DangerousGetPinnableReference()) + fixed (byte* bufPtr = &MemoryMarshal.GetReference(buffer)) { int result = CheckPipeCall(Interop.Sys.Read(_handle, bufPtr, buffer.Length)); Debug.Assert(result <= buffer.Length); @@ -149,7 +150,7 @@ private unsafe void WriteCore(ReadOnlySpan buffer) } // For anonymous pipes, write the file descriptor. - fixed (byte* bufPtr = &buffer.DangerousGetPinnableReference()) + fixed (byte* bufPtr = &MemoryMarshal.GetReference(buffer)) { while (buffer.Length > 0) { @@ -223,7 +224,7 @@ private async Task WriteAsyncCore(ReadOnlyMemory source, CancellationToken // accepts a Memory in the near future. byte[] buffer; int offset, count; - if (source.DangerousTryGetArray(out ArraySegment segment)) + if (MemoryMarshal.TryGetArray(source, out ArraySegment segment)) { buffer = segment.Array; offset = segment.Offset; diff --git a/src/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs b/src/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs index 7d5fe092c108..7f5e654bc8ba 100644 --- a/src/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs +++ b/src/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs @@ -343,7 +343,7 @@ private unsafe int ReadFileNative(SafePipeHandle handle, Span buffer, Nati int r = 0; int numBytesRead = 0; - fixed (byte* p = &buffer.DangerousGetPinnableReference()) + fixed (byte* p = &MemoryMarshal.GetReference(buffer)) { r = _isAsync ? Interop.Kernel32.ReadFile(handle, p, buffer.Length, IntPtr.Zero, overlapped) : @@ -381,7 +381,7 @@ private unsafe int WriteFileNative(SafePipeHandle handle, ReadOnlySpan buf int r = 0; int numBytesWritten = 0; - fixed (byte* p = &buffer.DangerousGetPinnableReference()) + fixed (byte* p = &MemoryMarshal.GetReference(buffer)) { r = _isAsync ? Interop.Kernel32.WriteFile(handle, p, buffer.Length, IntPtr.Zero, overlapped) : diff --git a/src/System.Memory/src/System/Buffers/Binary/Reader.cs b/src/System.Memory/src/System/Buffers/Binary/Reader.cs index 177d92a04a59..4ad5d720088e 100644 --- a/src/System.Memory/src/System/Buffers/Binary/Reader.cs +++ b/src/System.Memory/src/System/Buffers/Binary/Reader.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Buffers.Binary { @@ -116,7 +117,7 @@ public static T ReadMachineEndian(ReadOnlySpan buffer) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length); } - return Unsafe.ReadUnaligned(ref buffer.DangerousGetPinnableReference()); + return Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(buffer)); } /// @@ -143,7 +144,7 @@ public static bool TryReadMachineEndian(ReadOnlySpan buffer, out T valu value = default; return false; } - value = Unsafe.ReadUnaligned(ref buffer.DangerousGetPinnableReference()); + value = Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(buffer)); return true; } } diff --git a/src/System.Memory/src/System/Buffers/Binary/Writer.cs b/src/System.Memory/src/System/Buffers/Binary/Writer.cs index 2a7f11f05eba..25719769c90b 100644 --- a/src/System.Memory/src/System/Buffers/Binary/Writer.cs +++ b/src/System.Memory/src/System/Buffers/Binary/Writer.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Buffers.Binary { @@ -30,7 +31,7 @@ public static void WriteMachineEndian(Span buffer, ref T value) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length); } - Unsafe.WriteUnaligned(ref buffer.DangerousGetPinnableReference(), value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(buffer), value); } /// @@ -56,7 +57,7 @@ public static bool TryWriteMachineEndian(Span buffer, ref T value) { return false; } - Unsafe.WriteUnaligned(ref buffer.DangerousGetPinnableReference(), value); + Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(buffer), value); return true; } } diff --git a/src/System.Memory/src/System/Buffers/Text/Base64Decoder.cs b/src/System.Memory/src/System/Buffers/Text/Base64Decoder.cs index 73d345a69512..9f2979409e68 100644 --- a/src/System.Memory/src/System/Buffers/Text/Base64Decoder.cs +++ b/src/System.Memory/src/System/Buffers/Text/Base64Decoder.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Buffers.Text { @@ -27,8 +28,8 @@ public static partial class Base64 /// public static OperationStatus DecodeFromUtf8(ReadOnlySpan utf8, Span bytes, out int consumed, out int written, bool isFinalBlock = true) { - ref byte srcBytes = ref utf8.DangerousGetPinnableReference(); - ref byte destBytes = ref bytes.DangerousGetPinnableReference(); + ref byte srcBytes = ref MemoryMarshal.GetReference(utf8); + ref byte destBytes = ref MemoryMarshal.GetReference(bytes); int srcLength = utf8.Length & ~0x3; // only decode input up to the closest multiple of 4. int destLength = bytes.Length; @@ -207,7 +208,7 @@ public static OperationStatus DecodeFromUtf8InPlace(Span buffer, out int w if (bufferLength == 0) goto DoneExit; - ref byte bufferBytes = ref buffer.DangerousGetPinnableReference(); + ref byte bufferBytes = ref MemoryMarshal.GetReference(buffer); ref sbyte decodingMap = ref s_decodingMap[0]; diff --git a/src/System.Memory/src/System/Buffers/Text/Base64Encoder.cs b/src/System.Memory/src/System/Buffers/Text/Base64Encoder.cs index 8dac2ca80cdd..ee76758fbf4d 100644 --- a/src/System.Memory/src/System/Buffers/Text/Base64Encoder.cs +++ b/src/System.Memory/src/System/Buffers/Text/Base64Encoder.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Buffers.Text { @@ -28,8 +29,8 @@ public static partial class Base64 /// public static OperationStatus EncodeToUtf8(ReadOnlySpan bytes, Span utf8, out int consumed, out int written, bool isFinalBlock = true) { - ref byte srcBytes = ref bytes.DangerousGetPinnableReference(); - ref byte destBytes = ref utf8.DangerousGetPinnableReference(); + ref byte srcBytes = ref MemoryMarshal.GetReference(bytes); + ref byte destBytes = ref MemoryMarshal.GetReference(utf8); int srcLength = bytes.Length; int destLength = utf8.Length; @@ -137,7 +138,7 @@ public static OperationStatus EncodeToUtf8InPlace(Span buffer, int dataLen int result = 0; ref byte encodingMap = ref s_encodingMap[0]; - ref byte bufferBytes = ref buffer.DangerousGetPinnableReference(); + ref byte bufferBytes = ref MemoryMarshal.GetReference(buffer); // encode last pack to avoid conditional in the main loop if (leftover != 0) diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.G.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.G.cs index 9c52817aa687..936e94fc21ad 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.G.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.G.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Buffers.Text { @@ -38,7 +39,7 @@ private static bool TryFormatDateTimeG(DateTime value, TimeSpan offset, Span buffer, out in return false; } - ref byte utf8Bytes = ref buffer.DangerousGetPinnableReference(); + ref byte utf8Bytes = ref MemoryMarshal.GetReference(buffer); byte[] dayAbbrev = DayAbbreviationsLowercase[(int)value.DayOfWeek]; Unsafe.Add(ref utf8Bytes, 0) = dayAbbrev[0]; diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.O.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.O.cs index 4c5fefd37240..7736fb16afa9 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.O.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Date.O.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Buffers.Text { @@ -48,7 +49,7 @@ private static bool TryFormatDateTimeO(DateTime value, TimeSpan offset, Span buffer, out in return false; } - ref byte utf8Bytes = ref buffer.DangerousGetPinnableReference(); + ref byte utf8Bytes = ref MemoryMarshal.GetReference(buffer); byte[] dayAbbrev = DayAbbreviations[(int)value.DayOfWeek]; Unsafe.Add(ref utf8Bytes, 0) = dayAbbrev[0]; diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Guid.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Guid.cs index 59ee9f2c23f8..a4a8806597ae 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Guid.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Guid.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Buffers.Text { @@ -82,7 +83,7 @@ public static unsafe bool TryFormat(Guid value, Span buffer, out int bytes return false; } - ref byte utf8Bytes = ref buffer.DangerousGetPinnableReference(); + ref byte utf8Bytes = ref MemoryMarshal.GetReference(buffer); byte* bytes = (byte*)&value; int idx = 0; diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.D.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.D.cs index 87b477731abb..991e9b2d59ee 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.D.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.D.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Buffers.Text { @@ -26,7 +27,7 @@ private static bool TryFormatInt64D(long value, byte precision, Span buffe return false; } - ref byte utf8Bytes = ref buffer.DangerousGetPinnableReference(); + ref byte utf8Bytes = ref MemoryMarshal.GetReference(buffer); int idx = 0; if (value < 0) diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.N.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.N.cs index fc2a8f1ddf02..0b2b6ed9d947 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.N.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Signed.N.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Buffers.Text { @@ -35,7 +36,7 @@ private static bool TryFormatInt64N(long value, byte precision, Span buffe return false; } - ref byte utf8Bytes = ref buffer.DangerousGetPinnableReference(); + ref byte utf8Bytes = ref MemoryMarshal.GetReference(buffer); long v = value; if (v < 0) diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.D.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.D.cs index 8b598934b1a7..fe16bd8f30e5 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.D.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.D.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Runtime.InteropServices; + namespace System.Buffers.Text { /// @@ -32,7 +34,7 @@ private static bool TryFormatUInt64D(ulong value, byte precision, Span buf return false; } - ref byte utf8Bytes = ref buffer.DangerousGetPinnableReference(); + ref byte utf8Bytes = ref MemoryMarshal.GetReference(buffer); FormattingHelpers.WriteDigits(lastDigit, 1, ref utf8Bytes, bytesWritten); bytesWritten += 1; return true; diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.N.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.N.cs index 1a25cefa0ba1..33a01728ec3d 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.N.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.N.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Buffers.Text { @@ -42,7 +43,7 @@ private static bool TryFormatUInt64N(ulong value, byte precision, Span buf return false; } - ref byte utf8Bytes = ref buffer.DangerousGetPinnableReference(); + ref byte utf8Bytes = ref MemoryMarshal.GetReference(buffer); // Write the last group Unsafe.Add(ref utf8Bytes, idx++) = Utf8Constants.Separator; diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.X.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.X.cs index 48fc223fd998..4444899b64b3 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.X.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.Integer.Unsigned.X.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Buffers.Text { @@ -48,7 +49,7 @@ private static bool TryFormatUInt64X(ulong value, byte precision, bool useLower, } string hexTable = useLower ? HexTableLower : HexTableUpper; - ref byte utf8Bytes = ref buffer.DangerousGetPinnableReference(); + ref byte utf8Bytes = ref MemoryMarshal.GetReference(buffer); int idx = bytesWritten; for (v = value; digits-- > 0; v >>= 4) diff --git a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs index a1502d9e5ffc..4b1af56881ed 100644 --- a/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs +++ b/src/System.Memory/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace System.Buffers.Text { @@ -82,7 +83,7 @@ public static bool TryFormat(TimeSpan value, Span buffer, out int bytesWri return false; } - ref byte utf8Bytes = ref buffer.DangerousGetPinnableReference(); + ref byte utf8Bytes = ref MemoryMarshal.GetReference(buffer); int idx = 0; if (showSign) diff --git a/src/System.Memory/tests/MemoryMarshal/GetReference.cs b/src/System.Memory/tests/MemoryMarshal/GetReference.cs index f0a58c7a8cf6..3993b353e089 100644 --- a/src/System.Memory/tests/MemoryMarshal/GetReference.cs +++ b/src/System.Memory/tests/MemoryMarshal/GetReference.cs @@ -4,9 +4,9 @@ using Xunit; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using static System.TestHelpers; -using System.Runtime.InteropServices; namespace System.SpanTests { diff --git a/src/System.Net.Http/src/System/Net/Http/ByteArrayHelpers.cs b/src/System.Net.Http/src/System/Net/Http/ByteArrayHelpers.cs index 0105cc7e18bc..8ae15c6ce61d 100644 --- a/src/System.Net.Http/src/System/Net/Http/ByteArrayHelpers.cs +++ b/src/System.Net.Http/src/System/Net/Http/ByteArrayHelpers.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using System.Runtime.InteropServices; using System.Text; namespace System @@ -44,7 +45,7 @@ internal static bool EqualsOrdinalAsciiIgnoreCase(string left, ReadOnlySpan bytes) { // TODO #22431: Use new Span-based Encoding overload when available - fixed (byte* p = &bytes.DangerousGetPinnableReference()) + fixed (byte* p = &MemoryMarshal.GetReference(bytes)) { return Encoding.ASCII.GetString(p, bytes.Length); } diff --git a/src/System.Net.Http/src/System/Net/Http/Headers/KnownHeaders.cs b/src/System.Net.Http/src/System/Net/Http/Headers/KnownHeaders.cs index 128da03b1a87..2d1d035bf00e 100644 --- a/src/System.Net.Http/src/System/Net/Http/Headers/KnownHeaders.cs +++ b/src/System.Net.Http/src/System/Net/Http/Headers/KnownHeaders.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using System.Runtime.InteropServices; namespace System.Net.Http.Headers { @@ -370,7 +371,7 @@ internal static KnownHeader TryGetKnownHeader(string name) internal unsafe static KnownHeader TryGetKnownHeader(ReadOnlySpan name) { - fixed (byte* p = &name.DangerousGetPinnableReference()) + fixed (byte* p = &MemoryMarshal.GetReference(name)) { KnownHeader candidate = GetCandidate(new BytePtrAccessor(p, name.Length)); if (candidate != null && ByteArrayHelpers.EqualsOrdinalAsciiIgnoreCase(candidate.Name, name)) diff --git a/src/System.Net.Http/src/System/Net/Http/Managed/HttpConnection.cs b/src/System.Net.Http/src/System/Net/Http/Managed/HttpConnection.cs index 8d3ad634dffe..1e54d7bf649a 100644 --- a/src/System.Net.Http/src/System/Net/Http/Managed/HttpConnection.cs +++ b/src/System.Net.Http/src/System/Net/Http/Managed/HttpConnection.cs @@ -9,6 +9,7 @@ using System.Net.Http.Headers; using System.Net.Security; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -547,7 +548,7 @@ private void ParseStatusLine(Span line, HttpResponseMessage response) { try { - fixed (byte* reasonPtr = &reasonBytes.DangerousGetPinnableReference()) + fixed (byte* reasonPtr = &MemoryMarshal.GetReference(reasonBytes)) { response.ReasonPhrase = Encoding.ASCII.GetString(reasonPtr, reasonBytes.Length); } diff --git a/src/System.Net.Http/src/System/Net/Http/ReadOnlyMemoryContent.cs b/src/System.Net.Http/src/System/Net/Http/ReadOnlyMemoryContent.cs index 2f42bd197320..0a9588d71ac5 100644 --- a/src/System.Net.Http/src/System/Net/Http/ReadOnlyMemoryContent.cs +++ b/src/System.Net.Http/src/System/Net/Http/ReadOnlyMemoryContent.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.IO; +using System.Runtime.InteropServices; using System.Threading.Tasks; namespace System.Net.Http @@ -14,7 +15,7 @@ public sealed class ReadOnlyMemoryContent : HttpContent public ReadOnlyMemoryContent(ReadOnlyMemory content) { _content = content; - if (content.DangerousTryGetArray(out ArraySegment array)) + if (MemoryMarshal.TryGetArray(content, out ArraySegment array)) { // If we have an array, allow HttpClient to take optimized paths by just // giving it the array content to use as its already buffered data. diff --git a/src/System.Net.Primitives/src/System/Net/IPAddressParser.cs b/src/System.Net.Primitives/src/System/Net/IPAddressParser.cs index ba02a6278db1..930914f9b2dc 100644 --- a/src/System.Net.Primitives/src/System/Net/IPAddressParser.cs +++ b/src/System.Net.Primitives/src/System/Net/IPAddressParser.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.IO; using System.Net.Sockets; +using System.Runtime.InteropServices; using System.Text; namespace System.Net @@ -53,7 +54,7 @@ internal static unsafe bool IPv4AddressToString(uint address, Span formatt return false; } - fixed (char* formattedPtr = &formatted.DangerousGetPinnableReference()) + fixed (char* formattedPtr = &MemoryMarshal.GetReference(formatted)) { charsWritten = IPv4AddressToStringHelper(address, formattedPtr); } @@ -160,7 +161,7 @@ public static unsafe bool Ipv4StringToAddress(ReadOnlySpan ipSpan, out lon int end = ipSpan.Length; long tmpAddr; - fixed (char* ipStringPtr = &ipSpan.DangerousGetPinnableReference()) + fixed (char* ipStringPtr = &MemoryMarshal.GetReference(ipSpan)) { tmpAddr = IPv4AddressHelper.ParseNonCanonical(ipStringPtr, 0, ref end, notImplicitFile: true); } @@ -192,7 +193,7 @@ public static unsafe bool Ipv6StringToAddress(ReadOnlySpan ipSpan, ushort* int end = ipSpan.Length; bool isValid = false; - fixed (char* ipStringPtr = &ipSpan.DangerousGetPinnableReference()) + fixed (char* ipStringPtr = &MemoryMarshal.GetReference(ipSpan)) { isValid = IPv6AddressHelper.IsValidStrict(ipStringPtr, 0, ref end); } diff --git a/src/System.Net.Security/tests/UnitTests/SslApplicationProtocolTests.cs b/src/System.Net.Security/tests/UnitTests/SslApplicationProtocolTests.cs index 8aeeefbb199c..0706c73300ad 100644 --- a/src/System.Net.Security/tests/UnitTests/SslApplicationProtocolTests.cs +++ b/src/System.Net.Security/tests/UnitTests/SslApplicationProtocolTests.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; +using System.Runtime.InteropServices; using System.Text; using Xunit; @@ -45,7 +46,7 @@ public void Constructor_ByteArray_Copies() SslApplicationProtocol byteProtocol = new SslApplicationProtocol(expected); ArraySegment arraySegment; - Assert.True(byteProtocol.Protocol.DangerousTryGetArray(out arraySegment)); + Assert.True(MemoryMarshal.TryGetArray(byteProtocol.Protocol, out arraySegment)); Assert.Equal(expected, arraySegment.Array); Assert.NotSame(expected, arraySegment.Array); } diff --git a/src/System.Net.Sockets/src/System.Net.Sockets.csproj b/src/System.Net.Sockets/src/System.Net.Sockets.csproj index bb6914ed6942..b302e83ca288 100644 --- a/src/System.Net.Sockets/src/System.Net.Sockets.csproj +++ b/src/System.Net.Sockets/src/System.Net.Sockets.csproj @@ -399,6 +399,7 @@ + diff --git a/src/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs b/src/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs index 368bfed8381e..f43940c43842 100644 --- a/src/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs +++ b/src/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -388,7 +389,7 @@ internal ValueTask SendAsync(ReadOnlyMemory buffer, SocketFlags socke /// Implements Task-returning SendAsync on top of Begin/EndSend. private Task SendAsyncApm(ReadOnlyMemory buffer, SocketFlags socketFlags) { - if (buffer.DangerousTryGetArray(out ArraySegment bufferArray)) + if (MemoryMarshal.TryGetArray(buffer, out ArraySegment bufferArray)) { var tcs = new TaskCompletionSource(this); BeginSend(bufferArray.Array, bufferArray.Offset, bufferArray.Count, socketFlags, iar => diff --git a/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs b/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs index 195dc869b14d..8b1f163a6eeb 100644 --- a/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs +++ b/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs @@ -1302,7 +1302,7 @@ public unsafe SocketError ReceiveFrom(Span buffer, ref SocketFlags flags, return errorCode; } - fixed (byte* bufferPtr = &buffer.DangerousGetPinnableReference()) + fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer)) { var operation = new BufferPtrReceiveOperation(this) { @@ -1564,7 +1564,7 @@ public unsafe SocketError SendTo(ReadOnlySpan buffer, SocketFlags flags, b return errorCode; } - fixed (byte* bufferPtr = &buffer.DangerousGetPinnableReference()) + fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer)) { var operation = new BufferPtrSendOperation(this) { diff --git a/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.Windows.cs b/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.Windows.cs index 6622d2db7593..7bcabcfba40c 100644 --- a/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.Windows.cs +++ b/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.Windows.cs @@ -271,7 +271,7 @@ internal unsafe SocketError DoOperationReceiveSingleBuffer(SafeCloseSocket handl NativeOverlapped* overlapped = AllocateNativeOverlapped(); try { - fixed (byte* bufferPtr = &_buffer.Span.DangerousGetPinnableReference()) + fixed (byte* bufferPtr = &MemoryMarshal.GetReference(_buffer.Span)) { Debug.Assert(_singleBufferHandleState == SingleBufferHandleState.None, $"Expected None, got {_singleBufferHandleState}"); _singleBufferHandleState = SingleBufferHandleState.InProcess; @@ -350,7 +350,7 @@ internal unsafe SocketError DoOperationReceiveFromSingleBuffer(SafeCloseSocket h NativeOverlapped* overlapped = AllocateNativeOverlapped(); try { - fixed (byte* bufferPtr = &_buffer.Span.DangerousGetPinnableReference()) + fixed (byte* bufferPtr = &MemoryMarshal.GetReference(_buffer.Span)) { Debug.Assert(_singleBufferHandleState == SingleBufferHandleState.None); _singleBufferHandleState = SingleBufferHandleState.InProcess; @@ -558,7 +558,7 @@ internal unsafe SocketError DoOperationSendSingleBuffer(SafeCloseSocket handle) NativeOverlapped* overlapped = AllocateNativeOverlapped(); try { - fixed (byte* bufferPtr = &_buffer.Span.DangerousGetPinnableReference()) + fixed (byte* bufferPtr = &MemoryMarshal.GetReference(_buffer.Span)) { Debug.Assert(_singleBufferHandleState == SingleBufferHandleState.None); _singleBufferHandleState = SingleBufferHandleState.InProcess; @@ -739,7 +739,7 @@ internal unsafe SocketError DoOperationSendToSingleBuffer(SafeCloseSocket handle NativeOverlapped* overlapped = AllocateNativeOverlapped(); try { - fixed (byte* bufferPtr = &_buffer.Span.DangerousGetPinnableReference()) + fixed (byte* bufferPtr = &MemoryMarshal.GetReference(_buffer.Span)) { Debug.Assert(_singleBufferHandleState == SingleBufferHandleState.None); _singleBufferHandleState = SingleBufferHandleState.InProcess; diff --git a/src/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs b/src/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs index e3555325cdae..3367ac02594a 100644 --- a/src/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs +++ b/src/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs @@ -69,7 +69,7 @@ private static unsafe int Receive(SafeCloseSocket socket, SocketFlags flags, Spa int sockAddrLen = socketAddress != null ? socketAddressLen : 0; fixed (byte* sockAddr = socketAddress) - fixed (byte* b = &buffer.DangerousGetPinnableReference()) + fixed (byte* b = &MemoryMarshal.GetReference(buffer)) { var iov = new Interop.Sys.IOVector { Base = b, @@ -107,7 +107,7 @@ private static unsafe int Send(SafeCloseSocket socket, SocketFlags flags, ReadOn { int sent; fixed (byte* sockAddr = socketAddress) - fixed (byte* b = &buffer.DangerousGetPinnableReference()) + fixed (byte* b = &MemoryMarshal.GetReference(buffer)) { var iov = new Interop.Sys.IOVector { @@ -355,7 +355,7 @@ private static unsafe int ReceiveMessageFrom(SafeCloseSocket socket, SocketFlags long received; fixed (byte* rawSocketAddress = socketAddress) - fixed (byte* b = &buffer.DangerousGetPinnableReference()) + fixed (byte* b = &MemoryMarshal.GetReference(buffer)) { var iov = new Interop.Sys.IOVector { Base = b, diff --git a/src/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs b/src/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs index 61d118ea2394..226fabd2d1d8 100644 --- a/src/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs +++ b/src/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs @@ -175,7 +175,7 @@ public static unsafe SocketError Send(SafeCloseSocket handle, byte[] buffer, int public static unsafe SocketError Send(SafeCloseSocket handle, ReadOnlySpan buffer, SocketFlags socketFlags, out int bytesTransferred) { int bytesSent; - fixed (byte* bufferPtr = &buffer.DangerousGetPinnableReference()) + fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer)) { bytesSent = Interop.Winsock.send(handle.DangerousGetHandle(), bufferPtr, buffer.Length, socketFlags); } @@ -295,7 +295,7 @@ public static unsafe SocketError Receive(SafeCloseSocket handle, byte[] buffer, public static unsafe SocketError Receive(SafeCloseSocket handle, Span buffer, SocketFlags socketFlags, out int bytesTransferred) { int bytesReceived; - fixed (byte* bufferPtr = &buffer.DangerousGetPinnableReference()) + fixed (byte* bufferPtr = &MemoryMarshal.GetReference(buffer)) { bytesReceived = Interop.Winsock.recv(handle.DangerousGetHandle(), bufferPtr, buffer.Length, socketFlags); } diff --git a/src/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj b/src/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj index 7cbd0c258503..95869a0b9904 100644 --- a/src/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj +++ b/src/System.Net.WebSockets.Client/src/System.Net.WebSockets.Client.csproj @@ -123,6 +123,7 @@ + diff --git a/src/System.Net.WebSockets.Client/src/System/Net/WebSockets/WinHttpWebSocket.cs b/src/System.Net.WebSockets.Client/src/System/Net/WebSockets/WinHttpWebSocket.cs index 58157456456f..62052b29bb30 100644 --- a/src/System.Net.WebSockets.Client/src/System/Net/WebSockets/WinHttpWebSocket.cs +++ b/src/System.Net.WebSockets.Client/src/System/Net/WebSockets/WinHttpWebSocket.cs @@ -429,7 +429,7 @@ private Task InternalReceiveAsync(Memory pinnedBuffer) IntPtr pinnedBufferPtr; unsafe { - fixed (byte* p = &pinnedBuffer.Span.DangerousGetPinnableReference()) + fixed (byte* p = &MemoryMarshal.GetReference(pinnedBuffer.Span)) { pinnedBufferPtr = (IntPtr)p; } diff --git a/src/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.cs b/src/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.cs index 89857f1e5f73..410c43afc198 100644 --- a/src/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.cs +++ b/src/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.cs @@ -1265,7 +1265,7 @@ private static unsafe int ApplyMask(Span toMask, int mask, int maskIndex) int count = toMask.Length; if (count > 0) { - fixed (byte* toMaskPtr = &toMask.DangerousGetPinnableReference()) + fixed (byte* toMaskPtr = &MemoryMarshal.GetReference(toMask)) { byte* p = toMaskPtr; diff --git a/src/System.Net.WebSockets/src/System/Net/WebSockets/WebSocket.cs b/src/System.Net.WebSockets/src/System/Net/WebSockets/WebSocket.cs index 42b87b027460..8013388494bc 100644 --- a/src/System.Net.WebSockets/src/System/Net/WebSockets/WebSocket.cs +++ b/src/System.Net.WebSockets/src/System/Net/WebSockets/WebSocket.cs @@ -5,6 +5,7 @@ using System.Buffers; using System.ComponentModel; using System.IO; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -56,7 +57,7 @@ public virtual async ValueTask ReceiveAsync(Memory< } public virtual Task SendAsync(ReadOnlyMemory buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) => - buffer.DangerousTryGetArray(out ArraySegment arraySegment) ? + MemoryMarshal.TryGetArray(buffer, out ArraySegment arraySegment) ? SendAsync(arraySegment, messageType, endOfMessage, cancellationToken) : SendWithArrayPoolAsync(buffer, messageType, endOfMessage, cancellationToken); diff --git a/src/System.Private.Xml/src/System.Private.Xml.csproj b/src/System.Private.Xml/src/System.Private.Xml.csproj index 0148daf3afc2..fa2aa252789c 100644 --- a/src/System.Private.Xml/src/System.Private.Xml.csproj +++ b/src/System.Private.Xml/src/System.Private.Xml.csproj @@ -522,6 +522,7 @@ + diff --git a/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs b/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs index d87ca813ea5b..178ef54791d9 100644 --- a/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs +++ b/src/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs @@ -9,6 +9,7 @@ using System.Globalization; using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Threading.Tasks; namespace System.Xml @@ -3217,7 +3218,7 @@ private unsafe void EatPreamble() ReadOnlySpan preamble = _ps.encoding.Preamble; int preambleLen = preamble.Length; int i; - fixed (byte* preamblePtr = &preamble.DangerousGetPinnableReference()) + fixed (byte* preamblePtr = &MemoryMarshal.GetReference(preamble)) { var preambleSpan = new Span(preamblePtr, preambleLen); for (i = 0; i < preambleLen && i < _ps.bytesUsed; i++) diff --git a/src/System.Runtime.Extensions/src/System/IO/StreamReader.cs b/src/System.Runtime.Extensions/src/System/IO/StreamReader.cs index 330d0529c3ea..568bb83c5b4c 100644 --- a/src/System.Runtime.Extensions/src/System/IO/StreamReader.cs +++ b/src/System.Runtime.Extensions/src/System/IO/StreamReader.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; +using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -571,7 +572,7 @@ private unsafe bool IsPreamble() Debug.Assert(_bytePos <= preamble.Length, "_compressPreamble was called with the current bytePos greater than the preamble buffer length. Are two threads using this StreamReader at the same time?"); int len = (_byteLen >= (preamble.Length)) ? (preamble.Length - _bytePos) : (_byteLen - _bytePos); - fixed (byte* preamblePtr = &preamble.DangerousGetPinnableReference()) + fixed (byte* preamblePtr = &MemoryMarshal.GetReference(preamble)) { var preambleSpan = new Span(preamblePtr, preamble.Length); for (int i = 0; i < len; i++, _bytePos++) diff --git a/src/System.Runtime.Extensions/src/System/IO/StreamWriter.cs b/src/System.Runtime.Extensions/src/System/IO/StreamWriter.cs index b15a85699ebd..374103587af2 100644 --- a/src/System.Runtime.Extensions/src/System/IO/StreamWriter.cs +++ b/src/System.Runtime.Extensions/src/System/IO/StreamWriter.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -375,7 +376,7 @@ private unsafe void WriteCore(ReadOnlySpan buffer, bool autoFlush) { // For very short buffers and when we don't need to worry about running out of space // in the char buffer, just copy the chars individually. - fixed (char* bufferPtr = &buffer.DangerousGetPinnableReference()) + fixed (char* bufferPtr = &MemoryMarshal.GetReference(buffer)) { Span bufferSpan = new Span(bufferPtr, buffer.Length); for (int i = 0; i < buffer.Length; i++) @@ -398,7 +399,7 @@ private unsafe void WriteCore(ReadOnlySpan buffer, bool autoFlush) throw new ObjectDisposedException(null, SR.ObjectDisposed_WriterClosed); } - fixed (char* bufferPtr = &buffer.DangerousGetPinnableReference()) + fixed (char* bufferPtr = &MemoryMarshal.GetReference(buffer)) fixed (char* dstPtr = &charBuffer[0]) { char* srcPtr = bufferPtr; diff --git a/src/System.Runtime.Extensions/src/System/IO/TextWriter.cs b/src/System.Runtime.Extensions/src/System/IO/TextWriter.cs index 4748c706f0e6..48e702be6744 100644 --- a/src/System.Runtime.Extensions/src/System/IO/TextWriter.cs +++ b/src/System.Runtime.Extensions/src/System/IO/TextWriter.cs @@ -7,6 +7,7 @@ using System.Globalization; using System.Threading.Tasks; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Buffers; namespace System.IO @@ -548,7 +549,7 @@ public virtual Task WriteAsync(char[] buffer, int index, int count) } public virtual Task WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default(CancellationToken)) => - buffer.DangerousTryGetArray(out ArraySegment array) ? + MemoryMarshal.TryGetArray(buffer, out ArraySegment array) ? WriteAsync(array.Array, array.Offset, array.Count) : Task.Factory.StartNew(state => { @@ -600,7 +601,7 @@ public virtual Task WriteLineAsync(char[] buffer, int index, int count) } public virtual Task WriteLineAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default(CancellationToken)) => - buffer.DangerousTryGetArray(out ArraySegment array) ? + MemoryMarshal.TryGetArray(buffer, out ArraySegment array) ? WriteLineAsync(array.Array, array.Offset, array.Count) : Task.Factory.StartNew(state => { diff --git a/src/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs b/src/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs index 11dd1aa8024d..492af85261e3 100644 --- a/src/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs +++ b/src/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs @@ -258,7 +258,7 @@ public BigInteger(byte[] value) : public unsafe BigInteger(ReadOnlySpan value, bool isUnsigned=false, bool isBigEndian=false) { - fixed (byte* valuePtr = &value.DangerousGetPinnableReference()) + fixed (byte* valuePtr = &MemoryMarshal.GetReference(value)) { var valueSpan = new Span(valuePtr, value.Length); int byteCount = valueSpan.Length; diff --git a/src/System.Runtime.Numerics/src/System/Numerics/BigNumber.cs b/src/System.Runtime.Numerics/src/System/Numerics/BigNumber.cs index c90e15e99185..124bd74ce5c3 100644 --- a/src/System.Runtime.Numerics/src/System/Numerics/BigNumber.cs +++ b/src/System.Runtime.Numerics/src/System/Numerics/BigNumber.cs @@ -477,7 +477,7 @@ internal static unsafe char ParseFormatSpecifier(ReadOnlySpan format, out return 'R'; } - fixed (char* formatPtr = &format.DangerousGetPinnableReference()) + fixed (char* formatPtr = &MemoryMarshal.GetReference(format)) { var formatSpan = new Span(formatPtr, format.Length); int i = 0; diff --git a/src/System.Runtime/tests/System/StringTests.netcoreapp.cs b/src/System.Runtime/tests/System/StringTests.netcoreapp.cs index b29b8cf13790..cf27b8358633 100644 --- a/src/System.Runtime/tests/System/StringTests.netcoreapp.cs +++ b/src/System.Runtime/tests/System/StringTests.netcoreapp.cs @@ -565,7 +565,7 @@ public static unsafe void ImplicitCast_ResultingSpanMatches(string s) ReadOnlySpan span = s; Assert.Equal(s.Length, span.Length); fixed (char* stringPtr = s) - fixed (char* spanPtr = &span.DangerousGetPinnableReference()) + fixed (char* spanPtr = &MemoryMarshal.GetReference(span)) { Assert.Equal((IntPtr)stringPtr, (IntPtr)spanPtr); } diff --git a/src/System.Security.Cryptography.Algorithms/src/Internal/Cryptography/HashProviderDispenser.Unix.cs b/src/System.Security.Cryptography.Algorithms/src/Internal/Cryptography/HashProviderDispenser.Unix.cs index 01f5b4da0af0..999167d6d178 100644 --- a/src/System.Security.Cryptography.Algorithms/src/Internal/Cryptography/HashProviderDispenser.Unix.cs +++ b/src/System.Security.Cryptography.Algorithms/src/Internal/Cryptography/HashProviderDispenser.Unix.cs @@ -95,7 +95,7 @@ public override bool TryFinalizeHashAndReset(Span destination, out int byt } uint length = (uint)destination.Length; - Check(Interop.Crypto.EvpDigestFinalEx(_ctx, ref destination.DangerousGetPinnableReference(), ref length)); + Check(Interop.Crypto.EvpDigestFinalEx(_ctx, ref MemoryMarshal.GetReference(destination), ref length)); Debug.Assert(length == _hashSize); bytesWritten = (int)length; @@ -132,7 +132,7 @@ public HmacHashProvider(IntPtr algorithmEvp, byte[] key) throw new CryptographicException(); } - _hmacCtx = Interop.Crypto.HmacCreate(ref new Span(key).DangerousGetPinnableReference(), key.Length, algorithmEvp); + _hmacCtx = Interop.Crypto.HmacCreate(ref MemoryMarshal.GetReference(new Span(key)), key.Length, algorithmEvp); Interop.Crypto.CheckValidOpenSslHandle(_hmacCtx); } @@ -157,7 +157,7 @@ public override unsafe bool TryFinalizeHashAndReset(Span destination, out } int length = destination.Length; - Check(Interop.Crypto.HmacFinal(_hmacCtx, ref destination.DangerousGetPinnableReference(), ref length)); + Check(Interop.Crypto.HmacFinal(_hmacCtx, ref MemoryMarshal.GetReference(destination), ref length)); Debug.Assert(length == _hashSize); bytesWritten = length; diff --git a/src/System.Security.Cryptography.Algorithms/src/Internal/Cryptography/RandomNumberGeneratorImplementation.cs b/src/System.Security.Cryptography.Algorithms/src/Internal/Cryptography/RandomNumberGeneratorImplementation.cs index 57e0be7b794b..5d528f158f12 100644 --- a/src/System.Security.Cryptography.Algorithms/src/Internal/Cryptography/RandomNumberGeneratorImplementation.cs +++ b/src/System.Security.Cryptography.Algorithms/src/Internal/Cryptography/RandomNumberGeneratorImplementation.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Runtime.InteropServices; + namespace System.Security.Cryptography { internal sealed partial class RandomNumberGeneratorImplementation : RandomNumberGenerator @@ -22,7 +24,7 @@ public override void GetBytes(Span data) { if (data.Length > 0) { - GetBytes(ref data.DangerousGetPinnableReference(), data.Length); + GetBytes(ref MemoryMarshal.GetReference(data), data.Length); } } diff --git a/src/System.Security.Cryptography.Algorithms/src/System.Security.Cryptography.Algorithms.csproj b/src/System.Security.Cryptography.Algorithms/src/System.Security.Cryptography.Algorithms.csproj index 2b1d29be342d..5c3405383857 100644 --- a/src/System.Security.Cryptography.Algorithms/src/System.Security.Cryptography.Algorithms.csproj +++ b/src/System.Security.Cryptography.Algorithms/src/System.Security.Cryptography.Algorithms.csproj @@ -481,6 +481,7 @@ + diff --git a/src/System.Security.Cryptography.Cng/src/System.Security.Cryptography.Cng.csproj b/src/System.Security.Cryptography.Cng/src/System.Security.Cryptography.Cng.csproj index 00dbe6f98a8a..203784556094 100644 --- a/src/System.Security.Cryptography.Cng/src/System.Security.Cryptography.Cng.csproj +++ b/src/System.Security.Cryptography.Cng/src/System.Security.Cryptography.Cng.csproj @@ -280,6 +280,7 @@ + diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ComprehensiveReadTests.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ComprehensiveReadTests.cs index 768a56e94808..ee3e549a76b3 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ComprehensiveReadTests.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ComprehensiveReadTests.cs @@ -190,7 +190,7 @@ private static void AssertRdn( Assert.Equal(valueTag, actualTag); AssertRefSame( - ref valueSpan.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(valueSpan), ref bytes[offset], $"{label} is at bytes[{offset}]"); @@ -207,7 +207,7 @@ ref valueSpan.DangerousGetPinnableReference(), private static void AssertRefSame(ReadOnlyMemory a, ref byte b, string msg) { - AssertRefSame(ref a.Span.DangerousGetPinnableReference(), ref b, msg); + AssertRefSame(ref MemoryMarshal.GetReference(a.Span), ref b, msg); } private static void AssertRefSame(ref byte a, ref byte b, string msg) diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/PeekTests.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/PeekTests.cs index c5814b41c83d..b8cb0d1987c9 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/PeekTests.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/PeekTests.cs @@ -172,7 +172,7 @@ public static void PeekContentSpan_ExtremelyNested(bool fullArray) AsnReader reader = new AsnReader(dataBytes, AsnEncodingRules.BER); ReadOnlyMemory contents = reader.PeekContentBytes(); Assert.Equal(expectedLength, contents.Length); - Assert.True(Unsafe.AreSame(ref dataBytes[2], ref contents.Span.DangerousGetPinnableReference())); + Assert.True(Unsafe.AreSame(ref dataBytes[2], ref MemoryMarshal.GetReference(contents.Span))); } [Theory] @@ -207,7 +207,7 @@ public static void PeekEncodedValue_ExtremelyNested(bool fullArray) AsnReader reader = new AsnReader(dataBytes, AsnEncodingRules.BER); ReadOnlyMemory contents = reader.PeekEncodedValue(); Assert.Equal(expectedLength, contents.Length); - Assert.True(Unsafe.AreSame(ref dataBytes[0], ref contents.Span.DangerousGetPinnableReference())); + Assert.True(Unsafe.AreSame(ref dataBytes[0], ref MemoryMarshal.GetReference(contents.Span))); } } } diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs index c8e8c42cea51..d72f825bdde4 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs @@ -229,7 +229,7 @@ public static void TryGetBMPStringBytes( Assert.True( Unsafe.AreSame( - ref contents.Span.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(contents.Span), ref inputData[2])); } else diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs index 2455c2efcb14..0e57aafb954d 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs @@ -149,7 +149,7 @@ public static void TryGetBitStringBytes_Success_CER_MaxLength() // Check that it is, in fact, the same memory. No copies with this API. Assert.True( Unsafe.AreSame( - ref contents.Span.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(contents.Span), ref input[5])); } diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs index 83194935133f..146ca51eeec0 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs @@ -223,7 +223,7 @@ public static void TryGetIA5StringBytes( Assert.True( Unsafe.AreSame( - ref contents.Span.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(contents.Span), ref inputData[2])); } else diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs index 4167418b4310..575f23176613 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs @@ -124,7 +124,7 @@ public static void TryGetOctetStringBytes_Success_CER_MaxLength() // Check that it is, in fact, the same memory. No copies with this API. Assert.True( Unsafe.AreSame( - ref contents.Span.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(contents.Span), ref input[4])); } diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs index 8397bfc65419..55375f23ab04 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs @@ -237,7 +237,7 @@ public static void TryGetUTF8StringBytes( Assert.True( Unsafe.AreSame( - ref contents.Span.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(contents.Span), ref inputData[2])); } else diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Serializer/SimpleDeserialize.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Serializer/SimpleDeserialize.cs index 2fe1e1acb4ec..358e3b7cea80 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Serializer/SimpleDeserialize.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Serializer/SimpleDeserialize.cs @@ -403,7 +403,7 @@ public static void ReadAnyValueWithExpectedTag() Assert.Equal("0.0", data.Id); Assert.Equal(5, data.Data.Length); - Assert.True(Unsafe.AreSame(ref data.Data.Span.DangerousGetPinnableReference(), ref inputData[5])); + Assert.True(Unsafe.AreSame(ref MemoryMarshal.GetReference(data.Data.Span), ref inputData[5])); // Change [Constructed] SEQUENCE to [Constructed] Context-Specific 0. inputData[5] = 0xA0; From b7777a67e0b06158a8dc5d687839fbba93e5973c Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Sat, 16 Dec 2017 14:31:54 -0800 Subject: [PATCH 2/5] Fix unresolved merge conflict. --- .../src/System/IO/PathHelpers.cs | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/src/System.IO.FileSystem/src/System/IO/PathHelpers.cs b/src/System.IO.FileSystem/src/System/IO/PathHelpers.cs index eb82643b1f0f..aa54d434febe 100644 --- a/src/System.IO.FileSystem/src/System/IO/PathHelpers.cs +++ b/src/System.IO.FileSystem/src/System/IO/PathHelpers.cs @@ -137,14 +137,6 @@ private unsafe static string CombineNoChecksInternal(ReadOnlySpan first, R private unsafe static string CombineNoChecksInternal(ReadOnlySpan first, ReadOnlySpan second, ReadOnlySpan third) { Debug.Assert(first.Length > 0 && second.Length > 0 && third.Length > 0, "should have dealt with empty paths"); -<<<<<<< HEAD - fixed (char* f = &MemoryMarshal.GetReference(first), s = &MemoryMarshal.GetReference(second), t = &MemoryMarshal.GetReference(third)) - { - var firstSpan = new Span(f, first.Length); - var secondSpan = new Span(s, second.Length); - var thirdSpan = new Span(t, third.Length); -======= ->>>>>>> 79d708b2faf8a75089b1873fbb101b0a957c1fbd bool firstHasSeparator = PathInternal.IsDirectorySeparator(first[first.Length - 1]) || PathInternal.IsDirectorySeparator(second[0]); @@ -176,19 +168,9 @@ private unsafe static string CombineNoChecksInternal(ReadOnlySpan first, R [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe bool IsDotOrDotDot(ReadOnlySpan fileName) { -<<<<<<< HEAD - fixed (char* fileNamePtr = &MemoryMarshal.GetReference(fileName)) - { - var fileNameSpan = new Span(fileNamePtr, fileName.Length); - return !(fileName.Length > 2 - || fileNameSpan[0] != '.' - || (fileName.Length == 2 && fileNameSpan[1] != '.')); - } -======= return !(fileName.Length > 2 || fileName[0] != '.' || (fileName.Length == 2 && fileName[1] != '.')); ->>>>>>> 79d708b2faf8a75089b1873fbb101b0a957c1fbd } public static ReadOnlySpan GetDirectoryNameNoChecks(ReadOnlySpan path) @@ -198,11 +180,7 @@ public static ReadOnlySpan GetDirectoryNameNoChecks(ReadOnlySpan pat int root = PathInternal.GetRootLength(path); int i = path.Length; -<<<<<<< HEAD - fixed (char* pathPtr = &MemoryMarshal.GetReference(path)) -======= if (i > root) ->>>>>>> 79d708b2faf8a75089b1873fbb101b0a957c1fbd { while (i > root && !PathInternal.IsDirectorySeparator(path[--i])) ; return path.Slice(0, i); From 14d6cbf5a35cea3566d1cd18467e80b95689e1a4 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Thu, 21 Dec 2017 07:23:21 -0800 Subject: [PATCH 3/5] Add using directive --- src/Common/src/System/Security/Cryptography/AsnWriter.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Common/src/System/Security/Cryptography/AsnWriter.cs b/src/Common/src/System/Security/Cryptography/AsnWriter.cs index 3826742c9cb1..27ae44e153e8 100644 --- a/src/Common/src/System/Security/Cryptography/AsnWriter.cs +++ b/src/Common/src/System/Security/Cryptography/AsnWriter.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Numerics; +using System.Runtime.InteropServices; namespace System.Security.Cryptography.Asn1 { From 16b6b66585caebc721744fda9277303a2c658058 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Thu, 21 Dec 2017 08:23:18 -0800 Subject: [PATCH 4/5] Add missing using directives. --- src/Common/src/System/Globalization/FormatProvider.Number.cs | 1 + src/Common/src/System/Net/SocketAddressPal.Unix.cs | 1 + .../src/System/Net/Sockets/SocketAsyncContext.Unix.cs | 1 + src/System.Runtime/tests/System/StringTests.netcoreapp.cs | 1 + .../tests/Asn1/Reader/ComprehensiveReadTests.cs | 1 + .../tests/Asn1/Reader/PeekTests.cs | 1 + .../tests/Asn1/Reader/ReadBMPString.cs | 1 + .../tests/Asn1/Reader/ReadBitString.cs | 1 + .../tests/Asn1/Reader/ReadIA5String.cs | 1 + .../tests/Asn1/Reader/ReadOctetString.cs | 1 + .../tests/Asn1/Reader/ReadUTF8String.cs | 1 + 11 files changed, 11 insertions(+) diff --git a/src/Common/src/System/Globalization/FormatProvider.Number.cs b/src/Common/src/System/Globalization/FormatProvider.Number.cs index 43162111e56a..fa92c9cce9bc 100644 --- a/src/Common/src/System/Globalization/FormatProvider.Number.cs +++ b/src/Common/src/System/Globalization/FormatProvider.Number.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using System.Runtime.InteropServices; using System.Text; namespace System.Globalization diff --git a/src/Common/src/System/Net/SocketAddressPal.Unix.cs b/src/Common/src/System/Net/SocketAddressPal.Unix.cs index 5e5267024581..f7eaf04fbde2 100644 --- a/src/Common/src/System/Net/SocketAddressPal.Unix.cs +++ b/src/Common/src/System/Net/SocketAddressPal.Unix.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.Net.Sockets; +using System.Runtime.InteropServices; using System.Text; namespace System.Net diff --git a/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs b/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs index 8b1f163a6eeb..deecfe35e20e 100644 --- a/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs +++ b/src/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Threading; namespace System.Net.Sockets diff --git a/src/System.Runtime/tests/System/StringTests.netcoreapp.cs b/src/System.Runtime/tests/System/StringTests.netcoreapp.cs index cf27b8358633..8f14fe13e670 100644 --- a/src/System.Runtime/tests/System/StringTests.netcoreapp.cs +++ b/src/System.Runtime/tests/System/StringTests.netcoreapp.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Runtime.InteropServices; using Xunit; namespace System.Tests diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ComprehensiveReadTests.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ComprehensiveReadTests.cs index ee3e549a76b3..0d80672dad5f 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ComprehensiveReadTests.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ComprehensiveReadTests.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security.Cryptography.Asn1; using Test.Cryptography; using Xunit; diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/PeekTests.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/PeekTests.cs index b8cb0d1987c9..f09e92095e89 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/PeekTests.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/PeekTests.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security.Cryptography.Asn1; using Test.Cryptography; using Xunit; diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs index d72f825bdde4..62b8439e0ae2 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security.Cryptography.Asn1; using Test.Cryptography; using Xunit; diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs index 0e57aafb954d..7d4bae41d326 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security.Cryptography.Asn1; using Test.Cryptography; using Xunit; diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs index 146ca51eeec0..42dc62a77ea7 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security.Cryptography.Asn1; using Test.Cryptography; using Xunit; diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs index 575f23176613..2283f4f95a69 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security.Cryptography.Asn1; using Test.Cryptography; using Xunit; diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs index 55375f23ab04..5ab1b6dc518d 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security.Cryptography.Asn1; using Test.Cryptography; using Xunit; From b133137c1f42b7fcc5191e59b7e324313e65b92b Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Thu, 21 Dec 2017 08:48:13 -0800 Subject: [PATCH 5/5] Add references to System.Memory --- .../src/System.Net.NameResolution.csproj | 1 + src/System.Net.Ping/src/System.Net.Ping.csproj | 1 + .../src/System.Security.Cryptography.OpenSsl.csproj | 1 + .../src/System.Security.Cryptography.X509Certificates.csproj | 1 + 4 files changed, 4 insertions(+) diff --git a/src/System.Net.NameResolution/src/System.Net.NameResolution.csproj b/src/System.Net.NameResolution/src/System.Net.NameResolution.csproj index 6b4b016d2683..bc0ed8ff90eb 100644 --- a/src/System.Net.NameResolution/src/System.Net.NameResolution.csproj +++ b/src/System.Net.NameResolution/src/System.Net.NameResolution.csproj @@ -180,6 +180,7 @@ + diff --git a/src/System.Net.Ping/src/System.Net.Ping.csproj b/src/System.Net.Ping/src/System.Net.Ping.csproj index b5b56273c127..61b55ca48d5d 100644 --- a/src/System.Net.Ping/src/System.Net.Ping.csproj +++ b/src/System.Net.Ping/src/System.Net.Ping.csproj @@ -144,6 +144,7 @@ + diff --git a/src/System.Security.Cryptography.OpenSsl/src/System.Security.Cryptography.OpenSsl.csproj b/src/System.Security.Cryptography.OpenSsl/src/System.Security.Cryptography.OpenSsl.csproj index a653c9eff82e..89245e9cb1c3 100644 --- a/src/System.Security.Cryptography.OpenSsl/src/System.Security.Cryptography.OpenSsl.csproj +++ b/src/System.Security.Cryptography.OpenSsl/src/System.Security.Cryptography.OpenSsl.csproj @@ -124,6 +124,7 @@ + diff --git a/src/System.Security.Cryptography.X509Certificates/src/System.Security.Cryptography.X509Certificates.csproj b/src/System.Security.Cryptography.X509Certificates/src/System.Security.Cryptography.X509Certificates.csproj index c235728e73c0..a63a66ff53ed 100644 --- a/src/System.Security.Cryptography.X509Certificates/src/System.Security.Cryptography.X509Certificates.csproj +++ b/src/System.Security.Cryptography.X509Certificates/src/System.Security.Cryptography.X509Certificates.csproj @@ -412,6 +412,7 @@ +