From 723d1ef7758496c313ade397e818aaa2b55154b1 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Wed, 17 Nov 2021 21:58:09 -0800 Subject: [PATCH] Convert System.Net.* over to GeneratedDllImport --- .../Interop.Ssl.ProtocolSupport.cs | 8 +-- .../Interop.Ssl.cs | 72 +++++++++---------- .../Interop.X509.cs | 24 +++---- .../Interop.ProtocolStatistics.cs | 24 +++---- .../Interop.TcpConnectionInfo.cs | 16 ++--- .../Interop.X509Chain.cs | 4 +- .../Unix/System.Native/Interop.Disconnect.cs | 4 +- .../Interop.EnumerateInterfaceAddresses.cs | 12 ++-- .../System.Native/Interop.GetDomainName.cs | 4 +- .../Interop.GetDomainSocketSizes.cs | 4 +- .../Interop.GetMaximumAddressSize.cs | 4 +- .../Unix/System.Native/Interop.GetSockOpt.cs | 4 +- .../Interop.IPPacketInformation.cs | 4 +- .../Interop.InterfaceNameToIndex.cs | 4 +- .../System.Native/Interop.LingerOption.cs | 4 +- .../Unix/System.Native/Interop.MapTcpState.cs | 4 +- .../System.Native/Interop.NetworkChange.cs | 12 ++-- .../Interop.PlatformSocketSupport.cs | 4 +- .../Unix/System.Native/Interop.SetSockOpt.cs | 4 +- .../Unix/System.Native/Interop.Shutdown.cs | 4 +- .../Unix/System.Native/Interop.SocketEvent.cs | 24 +++---- .../Advapi32/Interop.LsaLookupNames2.cs | 5 +- .../IpHlpApi/Interop.GetNetworkParams.cs | 4 +- .../IpHlpApi/Interop.NetworkInformation.cs | 42 ++++++----- .../IpHlpApi/Interop.if_nametoindex.cs | 4 +- .../Windows/SspiCli/Interop.LsaLogonUser.cs | 3 + .../Interop/Windows/SspiCli/Interop.SSPI.cs | 8 ++- .../Interop.WebSocketBeginClientHandshake.cs | 4 +- .../Interop.WebSocketBeginServerHandshake.cs | 4 +- .../Windows/WinHttp/Interop.winhttp.cs | 9 ++- .../Windows/WinSock/Interop.WSAIoctl.cs | 3 + .../Windows/WinSock/Interop.getsockopt.cs | 3 + .../Windows/WinSock/Interop.setsockopt.cs | 3 + 33 files changed, 185 insertions(+), 151 deletions(-) diff --git a/src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.Ssl.ProtocolSupport.cs b/src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.Ssl.ProtocolSupport.cs index 29efbe7b040b2..f0f7356bbe9f3 100644 --- a/src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.Ssl.ProtocolSupport.cs +++ b/src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.Ssl.ProtocolSupport.cs @@ -8,11 +8,11 @@ internal static partial class Interop { internal static partial class AndroidCrypto { - [DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLGetSupportedProtocols")] - internal static extern SslProtocols SSLGetSupportedProtocols(); + [GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLGetSupportedProtocols")] + internal static partial SslProtocols SSLGetSupportedProtocols(); - [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLSupportsApplicationProtocolsConfiguration")] + [GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLSupportsApplicationProtocolsConfiguration")] [return:MarshalAs(UnmanagedType.U1)] - internal static extern bool SSLSupportsApplicationProtocolsConfiguration(); + internal static partial bool SSLSupportsApplicationProtocolsConfiguration(); } } diff --git a/src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.Ssl.cs b/src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.Ssl.cs index 6f0c53bac516c..f1200eabdd2a7 100644 --- a/src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.Ssl.cs +++ b/src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.Ssl.cs @@ -31,11 +31,11 @@ internal enum PAL_SSLStreamStatus Closed = 4, }; - [DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamCreate")] - internal static extern SafeSslHandle SSLStreamCreate(); + [GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamCreate")] + internal static partial SafeSslHandle SSLStreamCreate(); - [DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamCreateWithCertificates")] - private static extern SafeSslHandle SSLStreamCreateWithCertificates( + [GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamCreateWithCertificates")] + private static partial SafeSslHandle SSLStreamCreateWithCertificates( ref byte pkcs8PrivateKey, int pkcs8PrivateKeyLen, PAL_KeyAlgorithm algorithm, @@ -51,8 +51,8 @@ ref MemoryMarshal.GetReference(pkcs8PrivateKey), certificates.Length); } - [DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamInitialize")] - private static extern int SSLStreamInitializeImpl( + [GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamInitialize")] + private static partial int SSLStreamInitializeImpl( SafeSslHandle sslHandle, [MarshalAs(UnmanagedType.U1)] bool isServer, SSLReadCallback streamRead, @@ -70,8 +70,8 @@ internal static void SSLStreamInitialize( throw new SslException(); } - [DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamSetTargetHost")] - private static extern int SSLStreamSetTargetHostImpl( + [GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamSetTargetHost")] + private static partial int SSLStreamSetTargetHostImpl( SafeSslHandle sslHandle, [MarshalAs(UnmanagedType.LPUTF8Str)] string targetHost); internal static void SSLStreamSetTargetHost( @@ -85,8 +85,8 @@ internal static void SSLStreamSetTargetHost( throw new SslException(); } - [DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamRequestClientAuthentication")] - internal static extern void SSLStreamRequestClientAuthentication(SafeSslHandle sslHandle); + [GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamRequestClientAuthentication")] + internal static partial void SSLStreamRequestClientAuthentication(SafeSslHandle sslHandle); [StructLayout(LayoutKind.Sequential)] private unsafe struct ApplicationProtocolData @@ -95,8 +95,8 @@ private unsafe struct ApplicationProtocolData public int Length; } - [DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamSetApplicationProtocols")] - private static unsafe extern int SSLStreamSetApplicationProtocols(SafeSslHandle sslHandle, ApplicationProtocolData[] protocolData, int count); + [GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamSetApplicationProtocols")] + private static unsafe partial int SSLStreamSetApplicationProtocols(SafeSslHandle sslHandle, ApplicationProtocolData[] protocolData, int count); internal static unsafe void SSLStreamSetApplicationProtocols(SafeSslHandle sslHandle, List protocols) { int count = protocols.Count; @@ -129,8 +129,8 @@ internal static unsafe void SSLStreamSetApplicationProtocols(SafeSslHandle sslHa } } - [DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamSetEnabledProtocols")] - private static extern int SSLStreamSetEnabledProtocols(SafeSslHandle sslHandle, ref SslProtocols protocols, int length); + [GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamSetEnabledProtocols")] + private static partial int SSLStreamSetEnabledProtocols(SafeSslHandle sslHandle, ref SslProtocols protocols, int length); internal static void SSLStreamSetEnabledProtocols(SafeSslHandle sslHandle, ReadOnlySpan protocols) { int ret = SSLStreamSetEnabledProtocols(sslHandle, ref MemoryMarshal.GetReference(protocols), protocols.Length); @@ -138,11 +138,11 @@ internal static void SSLStreamSetEnabledProtocols(SafeSslHandle sslHandle, ReadO throw new SslException(); } - [DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamHandshake")] - internal static extern PAL_SSLStreamStatus SSLStreamHandshake(SafeSslHandle sslHandle); + [GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamHandshake")] + internal static partial PAL_SSLStreamStatus SSLStreamHandshake(SafeSslHandle sslHandle); - [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetApplicationProtocol")] - private static extern int SSLStreamGetApplicationProtocol(SafeSslHandle ssl, [Out] byte[]? buf, ref int len); + [GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetApplicationProtocol")] + private static partial int SSLStreamGetApplicationProtocol(SafeSslHandle ssl, byte[]? buf, ref int len); internal static byte[]? SSLStreamGetApplicationProtocol(SafeSslHandle ssl) { int len = 0; @@ -158,8 +158,8 @@ internal static void SSLStreamSetEnabledProtocols(SafeSslHandle sslHandle, ReadO return bytes; } - [DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamRead")] - private static unsafe extern PAL_SSLStreamStatus SSLStreamRead( + [GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamRead")] + private static unsafe partial PAL_SSLStreamStatus SSLStreamRead( SafeSslHandle sslHandle, byte* buffer, int length, @@ -175,8 +175,8 @@ internal static unsafe PAL_SSLStreamStatus SSLStreamRead( } } - [DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamWrite")] - private static unsafe extern PAL_SSLStreamStatus SSLStreamWrite( + [GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamWrite")] + private static unsafe partial PAL_SSLStreamStatus SSLStreamWrite( SafeSslHandle sslHandle, byte* buffer, int length); @@ -190,8 +190,8 @@ internal static unsafe PAL_SSLStreamStatus SSLStreamWrite( } } - [DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamRelease")] - internal static extern void SSLStreamRelease(IntPtr ptr); + [GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamRelease")] + internal static partial void SSLStreamRelease(IntPtr ptr); internal sealed class SslException : Exception { @@ -205,8 +205,8 @@ internal SslException(int errorCode) } } - [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetProtocol")] - private static extern int SSLStreamGetProtocol(SafeSslHandle ssl, out IntPtr protocol); + [GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetProtocol")] + private static partial int SSLStreamGetProtocol(SafeSslHandle ssl, out IntPtr protocol); internal static string SSLStreamGetProtocol(SafeSslHandle ssl) { IntPtr protocolPtr; @@ -222,11 +222,11 @@ internal static string SSLStreamGetProtocol(SafeSslHandle ssl) return protocol; } - [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetPeerCertificate")] - internal static extern SafeX509Handle SSLStreamGetPeerCertificate(SafeSslHandle ssl); + [GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetPeerCertificate")] + internal static partial SafeX509Handle SSLStreamGetPeerCertificate(SafeSslHandle ssl); - [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetPeerCertificates")] - private static extern void SSLStreamGetPeerCertificates( + [GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetPeerCertificates")] + private static partial void SSLStreamGetPeerCertificates( SafeSslHandle ssl, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] out IntPtr[] certs, out int count); @@ -238,8 +238,8 @@ private static extern void SSLStreamGetPeerCertificates( return ptrs; } - [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetCipherSuite")] - private static extern int SSLStreamGetCipherSuite(SafeSslHandle ssl, out IntPtr cipherSuite); + [GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetCipherSuite")] + private static partial int SSLStreamGetCipherSuite(SafeSslHandle ssl, out IntPtr cipherSuite); internal static string SSLStreamGetCipherSuite(SafeSslHandle ssl) { IntPtr cipherSuitePtr; @@ -255,13 +255,13 @@ internal static string SSLStreamGetCipherSuite(SafeSslHandle ssl) return cipherSuite; } - [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamShutdown")] + [GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamShutdown")] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool SSLStreamShutdown(SafeSslHandle ssl); + internal static partial bool SSLStreamShutdown(SafeSslHandle ssl); - [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamVerifyHostname")] + [GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamVerifyHostname")] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool SSLStreamVerifyHostname( + internal static partial bool SSLStreamVerifyHostname( SafeSslHandle ssl, [MarshalAs(UnmanagedType.LPUTF8Str)] string hostname); } diff --git a/src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.X509.cs b/src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.X509.cs index 5c3f986eb314d..ee0bf3c7e552e 100644 --- a/src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.X509.cs +++ b/src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.X509.cs @@ -13,11 +13,11 @@ internal static partial class AndroidCrypto private const int INSUFFICIENT_BUFFER = -1; private const int SUCCESS = 1; - [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509Decode")] - internal static extern SafeX509Handle X509Decode(ref byte buf, int len); + [GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509Decode")] + internal static partial SafeX509Handle X509Decode(ref byte buf, int len); - [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509Encode")] - private static extern int X509Encode(SafeX509Handle x, [Out] byte[]? buf, ref int len); + [GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509Encode")] + private static partial int X509Encode(SafeX509Handle x, byte[]? buf, ref int len); internal static byte[] X509Encode(SafeX509Handle x) { int len = 0; @@ -33,8 +33,8 @@ internal static byte[] X509Encode(SafeX509Handle x) return encoded; } - [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509DecodeCollection")] - private static extern int X509DecodeCollection(ref byte buf, int bufLen, IntPtr[]? ptrs, ref int handlesLen); + [GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509DecodeCollection")] + private static partial int X509DecodeCollection(ref byte buf, int bufLen, IntPtr[]? ptrs, ref int handlesLen); internal static SafeX509Handle[] X509DecodeCollection(ReadOnlySpan data) { ref byte buf = ref MemoryMarshal.GetReference(data); @@ -60,8 +60,8 @@ internal static SafeX509Handle[] X509DecodeCollection(ReadOnlySpan data) return handles; } - [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509ExportPkcs7")] - private static extern int X509ExportPkcs7(IntPtr[] certs, int certsLen, [Out] byte[]? buf, ref int len); + [GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509ExportPkcs7")] + private static partial int X509ExportPkcs7(IntPtr[] certs, int certsLen, byte[]? buf, ref int len); internal static byte[] X509ExportPkcs7(IntPtr[] certHandles) { int len = 0; @@ -77,8 +77,8 @@ internal static byte[] X509ExportPkcs7(IntPtr[] certHandles) return encoded; } - [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509GetContentType")] - private static extern X509ContentType X509GetContentType(ref byte buf, int len); + [GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509GetContentType")] + private static partial X509ContentType X509GetContentType(ref byte buf, int len); internal static X509ContentType X509GetContentType(ReadOnlySpan data) { return X509GetContentType(ref MemoryMarshal.GetReference(data), data.Length); @@ -92,8 +92,8 @@ internal enum PAL_KeyAlgorithm UnknownAlgorithm = -1, } - [DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509PublicKey")] - internal static extern IntPtr X509GetPublicKey(SafeX509Handle x, PAL_KeyAlgorithm algorithm); + [GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509PublicKey")] + internal static partial IntPtr X509GetPublicKey(SafeX509Handle x, PAL_KeyAlgorithm algorithm); } } diff --git a/src/libraries/Common/src/Interop/BSD/System.Native/Interop.ProtocolStatistics.cs b/src/libraries/Common/src/Interop/BSD/System.Native/Interop.ProtocolStatistics.cs index 476b7a653edb1..b7548f7138514 100644 --- a/src/libraries/Common/src/Interop/BSD/System.Native/Interop.ProtocolStatistics.cs +++ b/src/libraries/Common/src/Interop/BSD/System.Native/Interop.ProtocolStatistics.cs @@ -33,8 +33,8 @@ public readonly struct TcpGlobalStatistics private readonly int __padding; } - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetTcpGlobalStatistics")] - public static unsafe extern int GetTcpGlobalStatistics(TcpGlobalStatistics* statistics); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetTcpGlobalStatistics")] + public static unsafe partial int GetTcpGlobalStatistics(TcpGlobalStatistics* statistics); [StructLayoutAttribute(LayoutKind.Sequential)] public readonly struct IPv4GlobalStatistics @@ -55,8 +55,8 @@ public readonly struct IPv4GlobalStatistics public readonly int Forwarding; } - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPv4GlobalStatistics")] - public static unsafe extern int GetIPv4GlobalStatistics(IPv4GlobalStatistics* statistics); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPv4GlobalStatistics")] + public static unsafe partial int GetIPv4GlobalStatistics(IPv4GlobalStatistics* statistics); [StructLayoutAttribute(LayoutKind.Sequential)] public readonly struct UdpGlobalStatistics @@ -68,8 +68,8 @@ public readonly struct UdpGlobalStatistics public readonly ulong UdpListeners; } - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetUdpGlobalStatistics")] - public static unsafe extern int GetUdpGlobalStatistics(UdpGlobalStatistics* statistics); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetUdpGlobalStatistics")] + public static unsafe partial int GetUdpGlobalStatistics(UdpGlobalStatistics* statistics); [StructLayoutAttribute(LayoutKind.Sequential)] public readonly struct Icmpv4GlobalStatistics @@ -98,8 +98,8 @@ public readonly struct Icmpv4GlobalStatistics public readonly ulong TimestampRequestsSent; } - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIcmpv4GlobalStatistics")] - public static unsafe extern int GetIcmpv4GlobalStatistics(Icmpv4GlobalStatistics* statistics); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIcmpv4GlobalStatistics")] + public static unsafe partial int GetIcmpv4GlobalStatistics(Icmpv4GlobalStatistics* statistics); [StructLayoutAttribute(LayoutKind.Sequential)] public readonly struct Icmpv6GlobalStatistics @@ -134,8 +134,8 @@ public readonly struct Icmpv6GlobalStatistics public readonly ulong TimeExceededMessagesSent; } - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIcmpv6GlobalStatistics")] - public static unsafe extern int GetIcmpv6GlobalStatistics(Icmpv6GlobalStatistics* statistics); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIcmpv6GlobalStatistics")] + public static unsafe partial int GetIcmpv6GlobalStatistics(Icmpv6GlobalStatistics* statistics); public readonly struct NativeIPInterfaceStatistics { @@ -158,7 +158,7 @@ public readonly struct NativeIPInterfaceStatistics [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNativeIPInterfaceStatistics", CharSet = CharSet.Ansi)] public static partial int GetNativeIPInterfaceStatistics(string name, out NativeIPInterfaceStatistics stats); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNumRoutes")] - public static extern int GetNumRoutes(); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNumRoutes")] + public static partial int GetNumRoutes(); } } diff --git a/src/libraries/Common/src/Interop/BSD/System.Native/Interop.TcpConnectionInfo.cs b/src/libraries/Common/src/Interop/BSD/System.Native/Interop.TcpConnectionInfo.cs index 3d48cd67060ae..35a6b9dd5b545 100644 --- a/src/libraries/Common/src/Interop/BSD/System.Native/Interop.TcpConnectionInfo.cs +++ b/src/libraries/Common/src/Interop/BSD/System.Native/Interop.TcpConnectionInfo.cs @@ -25,16 +25,16 @@ public struct NativeTcpConnectionInformation public TcpState State; } - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEstimatedTcpConnectionCount")] - public static extern int GetEstimatedTcpConnectionCount(); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEstimatedTcpConnectionCount")] + public static partial int GetEstimatedTcpConnectionCount(); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetActiveTcpConnectionInfos")] - public static extern unsafe int GetActiveTcpConnectionInfos(NativeTcpConnectionInformation* infos, int* infoCount); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetActiveTcpConnectionInfos")] + public static unsafe partial int GetActiveTcpConnectionInfos(NativeTcpConnectionInformation* infos, int* infoCount); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEstimatedUdpListenerCount")] - public static extern int GetEstimatedUdpListenerCount(); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEstimatedUdpListenerCount")] + public static partial int GetEstimatedUdpListenerCount(); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetActiveUdpListeners")] - public static extern unsafe int GetActiveUdpListeners(IPEndPointInfo* infos, int* infoCount); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetActiveUdpListeners")] + public static unsafe partial int GetActiveUdpListeners(IPEndPointInfo* infos, int* infoCount); } } diff --git a/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.X509Chain.cs b/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.X509Chain.cs index 16525bfd370c8..e82ebf958787a 100644 --- a/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.X509Chain.cs +++ b/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.X509Chain.cs @@ -43,8 +43,8 @@ internal static partial int AppleCryptoNative_X509ChainEvaluate( [GeneratedDllImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_X509ChainGetStatusAtIndex")] internal static partial int X509ChainGetStatusAtIndex(SafeCreateHandle trustResults, long index, out int pdwStatus); - [DllImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_GetOSStatusForChainStatus")] - internal static extern int GetOSStatusForChainStatus(X509ChainStatusFlags flag); + [GeneratedDllImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_GetOSStatusForChainStatus")] + internal static partial int GetOSStatusForChainStatus(X509ChainStatusFlags flag); [GeneratedDllImport(Libraries.AppleCryptoNative, EntryPoint = "AppleCryptoNative_X509ChainSetTrustAnchorCertificates")] internal static partial int X509ChainSetTrustAnchorCertificates(SafeX509ChainHandle chain, SafeCreateHandle anchorCertificates); diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Disconnect.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Disconnect.cs index 0ecfc3192373d..55c79888f18b0 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Disconnect.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Disconnect.cs @@ -8,7 +8,7 @@ internal static partial class Interop { internal static partial class Sys { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Disconnect")] - internal static extern Error Disconnect(IntPtr socket); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Disconnect")] + internal static partial Error Disconnect(IntPtr socket); } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs index 2ad68069e48c0..b4896fc0a744f 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs @@ -42,18 +42,18 @@ public unsafe struct NetworkInterfaceInfo private fixed byte __padding[3]; } - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_EnumerateInterfaceAddresses")] - public static extern unsafe int EnumerateInterfaceAddresses( + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_EnumerateInterfaceAddresses")] + public static unsafe partial int EnumerateInterfaceAddresses( void* context, delegate* unmanaged ipv4Found, delegate* unmanaged ipv6Found, delegate* unmanaged linkLayerFound); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_EnumerateGatewayAddressesForInterface")] - public static extern unsafe int EnumerateGatewayAddressesForInterface(void* context, uint interfaceIndex, delegate* unmanaged onGatewayFound); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_EnumerateGatewayAddressesForInterface")] + public static unsafe partial int EnumerateGatewayAddressesForInterface(void* context, uint interfaceIndex, delegate* unmanaged onGatewayFound); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNetworkInterfaces")] - public static unsafe extern int GetNetworkInterfaces(int* count, NetworkInterfaceInfo** addrs, int* addressCount, IpAddressInfo** aa); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNetworkInterfaces")] + public static unsafe partial int GetNetworkInterfaces(int* count, NetworkInterfaceInfo** addrs, int* addressCount, IpAddressInfo** aa); } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetDomainName.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetDomainName.cs index 466afb7b0101d..74946795ca860 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetDomainName.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetDomainName.cs @@ -10,8 +10,8 @@ internal static partial class Interop { internal static partial class Sys { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetDomainName")] - private static extern unsafe int GetDomainName(byte* name, int len); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetDomainName")] + private static unsafe partial int GetDomainName(byte* name, int len); internal static unsafe string GetDomainName() { diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetDomainSocketSizes.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetDomainSocketSizes.cs index 7daf1ba2aef34..35263979dc318 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetDomainSocketSizes.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetDomainSocketSizes.cs @@ -8,8 +8,8 @@ internal static partial class Interop { internal static partial class Sys { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetDomainSocketSizes")] + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetDomainSocketSizes")] [SuppressGCTransition] - internal static unsafe extern void GetDomainSocketSizes(int* pathOffset, int* pathSize, int* addressSize); + internal static unsafe partial void GetDomainSocketSizes(int* pathOffset, int* pathSize, int* addressSize); } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetMaximumAddressSize.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetMaximumAddressSize.cs index 44617551080a0..6ad3e4e3cd669 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetMaximumAddressSize.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetMaximumAddressSize.cs @@ -8,8 +8,8 @@ internal static partial class Interop { internal static partial class Sys { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetMaximumAddressSize")] + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetMaximumAddressSize")] [SuppressGCTransition] - internal static extern int GetMaximumAddressSize(); + internal static partial int GetMaximumAddressSize(); } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetSockOpt.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetSockOpt.cs index 0a0dbae00073f..49d4b0d703e37 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetSockOpt.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetSockOpt.cs @@ -12,8 +12,8 @@ internal static partial class Sys [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetSockOpt")] internal static unsafe partial Error GetSockOpt(SafeHandle socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte* optionValue, int* optionLen); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetSockOpt")] - internal static extern unsafe Error GetSockOpt(IntPtr socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte* optionValue, int* optionLen); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetSockOpt")] + internal static unsafe partial Error GetSockOpt(IntPtr socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte* optionValue, int* optionLen); [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetRawSockOpt")] internal static unsafe partial Error GetRawSockOpt(SafeHandle socket, int optionLevel, int optionName, byte* optionValue, int* optionLen); diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.IPPacketInformation.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.IPPacketInformation.cs index 37dab53c69365..7c10ff98bf70c 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.IPPacketInformation.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.IPPacketInformation.cs @@ -16,9 +16,9 @@ internal struct IPPacketInformation private int _padding; // Pad out to 8-byte alignment } - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetControlMessageBufferSize")] + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetControlMessageBufferSize")] [SuppressGCTransition] - internal static extern int GetControlMessageBufferSize(int isIPv4, int isIPv6); + internal static partial int GetControlMessageBufferSize(int isIPv4, int isIPv6); [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_TryGetIPPacketInformation")] internal static unsafe partial bool TryGetIPPacketInformation(MessageHeader* messageHeader, bool isIPv4, IPPacketInformation* packetInfo); diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.InterfaceNameToIndex.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.InterfaceNameToIndex.cs index 74fab3ed6d6a2..7d0c0dd64c2a7 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.InterfaceNameToIndex.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.InterfaceNameToIndex.cs @@ -8,7 +8,7 @@ internal static partial class Interop { internal static partial class Sys { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_InterfaceNameToIndex", SetLastError = true)] - public static extern uint InterfaceNameToIndex(string name); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_InterfaceNameToIndex", CharSet = CharSet.Ansi, SetLastError = true)] + public static partial uint InterfaceNameToIndex(string name); } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.LingerOption.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.LingerOption.cs index 5092a15151dbb..ecaae2b40abb9 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.LingerOption.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.LingerOption.cs @@ -21,7 +21,7 @@ internal struct LingerOption [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetLingerOption")] internal static unsafe partial Error SetLingerOption(SafeHandle socket, LingerOption* option); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetLingerOption")] - internal static extern unsafe Error SetLingerOption(IntPtr socket, LingerOption* option); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetLingerOption")] + internal static unsafe partial Error SetLingerOption(IntPtr socket, LingerOption* option); } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MapTcpState.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MapTcpState.cs index d16be7edf49a5..3d689c57f387e 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MapTcpState.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MapTcpState.cs @@ -8,8 +8,8 @@ internal static partial class Interop { internal static partial class Sys { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_MapTcpState")] + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_MapTcpState")] [SuppressGCTransition] - internal static extern TcpState MapTcpState(int nativeState); + internal static partial TcpState MapTcpState(int nativeState); } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.NetworkChange.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.NetworkChange.cs index 152588f507885..5b5e7ccd8bba3 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.NetworkChange.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.NetworkChange.cs @@ -16,13 +16,13 @@ public enum NetworkChangeKind AvailabilityChanged = 2 } - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CreateNetworkChangeListenerSocket")] - public static unsafe extern Error CreateNetworkChangeListenerSocket(int* socket); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CreateNetworkChangeListenerSocket")] + public static unsafe partial Error CreateNetworkChangeListenerSocket(int* socket); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CloseNetworkChangeListenerSocket")] - public static extern Error CloseNetworkChangeListenerSocket(int socket); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CloseNetworkChangeListenerSocket")] + public static partial Error CloseNetworkChangeListenerSocket(int socket); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReadEvents")] - public static extern unsafe void ReadEvents(int socket, delegate* unmanaged onNetworkChange); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReadEvents")] + public static unsafe partial void ReadEvents(int socket, delegate* unmanaged onNetworkChange); } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.PlatformSocketSupport.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.PlatformSocketSupport.cs index 0e406162f9ac5..550aaff995add 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.PlatformSocketSupport.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.PlatformSocketSupport.cs @@ -7,8 +7,8 @@ internal static partial class Interop { internal static partial class Sys { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PlatformSupportsDualModeIPv4PacketInfo")] + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PlatformSupportsDualModeIPv4PacketInfo")] [SuppressGCTransition] - internal static extern int PlatformSupportsDualModeIPv4PacketInfo(); + internal static partial int PlatformSupportsDualModeIPv4PacketInfo(); } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.SetSockOpt.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.SetSockOpt.cs index 10760287e439e..66048b39bacf4 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.SetSockOpt.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.SetSockOpt.cs @@ -12,8 +12,8 @@ internal static partial class Sys [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetSockOpt")] internal static unsafe partial Error SetSockOpt(SafeHandle socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte* optionValue, int optionLen); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetSockOpt")] - internal static extern unsafe Error SetSockOpt(IntPtr socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte* optionValue, int optionLen); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetSockOpt")] + internal static unsafe partial Error SetSockOpt(IntPtr socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte* optionValue, int optionLen); [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetRawSockOpt")] internal static unsafe partial Error SetRawSockOpt(SafeHandle socket, int optionLevel, int optionName, byte* optionValue, int optionLen); diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Shutdown.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Shutdown.cs index ee516a59c2e86..6a04ca805a286 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Shutdown.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Shutdown.cs @@ -12,7 +12,7 @@ internal static partial class Sys [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Shutdown")] internal static partial Error Shutdown(SafeHandle socket, SocketShutdown how); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Shutdown")] - internal static extern Error Shutdown(IntPtr socket, SocketShutdown how); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Shutdown")] + internal static partial Error Shutdown(IntPtr socket, SocketShutdown how); } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.SocketEvent.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.SocketEvent.cs index c3e6769ac6cdd..45eb91559c0ab 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.SocketEvent.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.SocketEvent.cs @@ -27,25 +27,25 @@ internal struct SocketEvent private int _padding; } - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CreateSocketEventPort")] - internal static unsafe extern Error CreateSocketEventPort(IntPtr* port); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CreateSocketEventPort")] + internal static unsafe partial Error CreateSocketEventPort(IntPtr* port); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CloseSocketEventPort")] - internal static extern Error CloseSocketEventPort(IntPtr port); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CloseSocketEventPort")] + internal static partial Error CloseSocketEventPort(IntPtr port); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CreateSocketEventBuffer")] - internal static unsafe extern Error CreateSocketEventBuffer(int count, SocketEvent** buffer); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CreateSocketEventBuffer")] + internal static unsafe partial Error CreateSocketEventBuffer(int count, SocketEvent** buffer); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FreeSocketEventBuffer")] - internal static extern unsafe Error FreeSocketEventBuffer(SocketEvent* buffer); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FreeSocketEventBuffer")] + internal static unsafe partial Error FreeSocketEventBuffer(SocketEvent* buffer); [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_TryChangeSocketEventRegistration")] internal static partial Error TryChangeSocketEventRegistration(IntPtr port, SafeHandle socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_TryChangeSocketEventRegistration")] - internal static extern Error TryChangeSocketEventRegistration(IntPtr port, IntPtr socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_TryChangeSocketEventRegistration")] + internal static partial Error TryChangeSocketEventRegistration(IntPtr port, IntPtr socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_WaitForSocketEvents")] - internal static extern unsafe Error WaitForSocketEvents(IntPtr port, SocketEvent* buffer, int* count); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_WaitForSocketEvents")] + internal static unsafe partial Error WaitForSocketEvents(IntPtr port, SocketEvent* buffer, int* count); } } diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LsaLookupNames2.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LsaLookupNames2.cs index 5b9092c7f8889..1e4c0309a09d9 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LsaLookupNames2.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LsaLookupNames2.cs @@ -9,7 +9,9 @@ internal static partial class Interop { internal static partial class Advapi32 { - [DllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaLookupNames2", SetLastError = true, CharSet = CharSet.Unicode)] +#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time + [DllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaLookupNames2", CharSet = CharSet.Unicode, SetLastError = true)] + // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs. internal static extern uint LsaLookupNames2( SafeLsaPolicyHandle handle, int flags, @@ -18,6 +20,7 @@ internal static extern uint LsaLookupNames2( out SafeLsaMemoryHandle referencedDomains, out SafeLsaMemoryHandle sids ); +#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] internal struct MARSHALLED_UNICODE_STRING diff --git a/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.GetNetworkParams.cs b/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.GetNetworkParams.cs index f731ce50e7a38..0e88f19ab0113 100644 --- a/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.GetNetworkParams.cs +++ b/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.GetNetworkParams.cs @@ -8,7 +8,7 @@ internal static partial class Interop { internal static partial class IpHlpApi { - [DllImport(Interop.Libraries.IpHlpApi, ExactSpelling = true)] - internal static unsafe extern uint GetNetworkParams(IntPtr pFixedInfo, uint* pOutBufLen); + [GeneratedDllImport(Interop.Libraries.IpHlpApi, ExactSpelling = true)] + internal static unsafe partial uint GetNetworkParams(IntPtr pFixedInfo, uint* pOutBufLen); } } diff --git a/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.NetworkInformation.cs b/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.NetworkInformation.cs index 40d3df8e16079..b3c412c4b8cbf 100644 --- a/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.NetworkInformation.cs +++ b/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.NetworkInformation.cs @@ -508,34 +508,40 @@ internal unsafe struct MibUdp6RowOwnerPid internal ReadOnlySpan localAddrAsSpan => MemoryMarshal.CreateSpan(ref localAddr[0], 16); } - [DllImport(Interop.Libraries.IpHlpApi)] - internal static unsafe extern uint GetAdaptersAddresses( + [GeneratedDllImport(Interop.Libraries.IpHlpApi)] + internal static unsafe partial uint GetAdaptersAddresses( AddressFamily family, uint flags, IntPtr pReserved, IntPtr adapterAddresses, uint* outBufLen); - [DllImport(Interop.Libraries.IpHlpApi)] - internal static unsafe extern uint GetBestInterfaceEx(byte* ipAddress, int* index); + [GeneratedDllImport(Interop.Libraries.IpHlpApi)] + internal static unsafe partial uint GetBestInterfaceEx(byte* ipAddress, int* index); +#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [DllImport(Interop.Libraries.IpHlpApi)] + // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable types. internal static extern uint GetIfEntry2(ref MibIfRow2 pIfRow); +#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time - [DllImport(Interop.Libraries.IpHlpApi)] - internal static unsafe extern uint GetIpStatisticsEx(MibIpStats* statistics, AddressFamily family); + [GeneratedDllImport(Interop.Libraries.IpHlpApi)] + internal static unsafe partial uint GetIpStatisticsEx(MibIpStats* statistics, AddressFamily family); - [DllImport(Interop.Libraries.IpHlpApi)] - internal static unsafe extern uint GetTcpStatisticsEx(MibTcpStats* statistics, AddressFamily family); + [GeneratedDllImport(Interop.Libraries.IpHlpApi)] + internal static unsafe partial uint GetTcpStatisticsEx(MibTcpStats* statistics, AddressFamily family); - [DllImport(Interop.Libraries.IpHlpApi)] - internal static unsafe extern uint GetUdpStatisticsEx(MibUdpStats* statistics, AddressFamily family); + [GeneratedDllImport(Interop.Libraries.IpHlpApi)] + internal static unsafe partial uint GetUdpStatisticsEx(MibUdpStats* statistics, AddressFamily family); - [DllImport(Interop.Libraries.IpHlpApi)] - internal static unsafe extern uint GetIcmpStatistics(MibIcmpInfo* statistics); + [GeneratedDllImport(Interop.Libraries.IpHlpApi)] + internal static unsafe partial uint GetIcmpStatistics(MibIcmpInfo* statistics); +#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [DllImport(Interop.Libraries.IpHlpApi)] + // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable types. internal static extern uint GetIcmpStatisticsEx(out MibIcmpInfoEx statistics, AddressFamily family); +#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [GeneratedDllImport(Interop.Libraries.IpHlpApi)] internal static unsafe partial uint GetTcpTable(IntPtr pTcpTable, uint* dwOutBufLen, bool order); @@ -551,14 +557,14 @@ internal static unsafe partial uint GetExtendedTcpTable(IntPtr pTcpTable, uint* internal static unsafe partial uint GetExtendedUdpTable(IntPtr pUdpTable, uint* dwOutBufLen, bool order, uint IPVersion, UdpTableClass tableClass, uint reserved); - [DllImport(Interop.Libraries.IpHlpApi)] - internal static unsafe extern uint GetPerAdapterInfo(uint IfIndex, IntPtr pPerAdapterInfo, uint* pOutBufLen); + [GeneratedDllImport(Interop.Libraries.IpHlpApi)] + internal static unsafe partial uint GetPerAdapterInfo(uint IfIndex, IntPtr pPerAdapterInfo, uint* pOutBufLen); - [DllImport(Interop.Libraries.IpHlpApi)] - internal static extern void FreeMibTable(IntPtr handle); + [GeneratedDllImport(Interop.Libraries.IpHlpApi)] + internal static partial void FreeMibTable(IntPtr handle); - [DllImport(Interop.Libraries.IpHlpApi)] - internal static extern uint CancelMibChangeNotify2(IntPtr notificationHandle); + [GeneratedDllImport(Interop.Libraries.IpHlpApi)] + internal static partial uint CancelMibChangeNotify2(IntPtr notificationHandle); [GeneratedDllImport(Interop.Libraries.IpHlpApi)] internal static unsafe partial uint NotifyStableUnicastIpAddressTable( diff --git a/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.if_nametoindex.cs b/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.if_nametoindex.cs index d544a94747f51..01235ca5f7340 100644 --- a/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.if_nametoindex.cs +++ b/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.if_nametoindex.cs @@ -8,7 +8,7 @@ internal static partial class Interop { internal static partial class IpHlpApi { - [DllImport(Interop.Libraries.IpHlpApi, SetLastError = true)] - internal static extern uint if_nametoindex(string name); + [GeneratedDllImport(Interop.Libraries.IpHlpApi, CharSet = CharSet.Ansi, SetLastError = true)] + internal static partial uint if_nametoindex(string name); } } diff --git a/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.LsaLogonUser.cs b/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.LsaLogonUser.cs index 82aaec9af71fe..6be3ad7e6dd8e 100644 --- a/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.LsaLogonUser.cs +++ b/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.LsaLogonUser.cs @@ -10,7 +10,9 @@ internal static partial class Interop { internal static partial class SspiCli { +#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [DllImport(Libraries.SspiCli)] + // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs. internal static extern int LsaLogonUser( [In] SafeLsaHandle LsaHandle, [In] ref Advapi32.LSA_STRING OriginName, @@ -27,5 +29,6 @@ internal static extern int LsaLogonUser( [Out] out QUOTA_LIMITS Quotas, [Out] out int SubStatus ); +#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time } } diff --git a/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.SSPI.cs b/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.SSPI.cs index c22ae17d4edb4..251d3dafd7e76 100644 --- a/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.SSPI.cs +++ b/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.SSPI.cs @@ -344,10 +344,13 @@ internal static unsafe partial int DecryptMessage( uint sequenceNumber, uint* qualityOfProtection); +#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs. internal static extern int QuerySecurityContextToken( ref CredHandle phContext, out SecurityContextTokenHandle handle); +#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [GeneratedDllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static partial int FreeContextBuffer( @@ -475,12 +478,15 @@ internal static partial SECURITY_STATUS SspiEncodeStringsAsAuthIdentity( string password, out SafeSspiAuthDataHandle authData); - // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid) +#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [DllImport(Interop.Libraries.SspiCli, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)] + // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs. internal static extern SECURITY_STATUS SetCredentialsAttributesW( in CredHandle handlePtr, long ulAttribute, in SecPkgCred_ClientCertPolicy pBuffer, long cbBuffer); +#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time + } } diff --git a/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginClientHandshake.cs b/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginClientHandshake.cs index 5d49f4d7eab7b..554d62ab1601a 100644 --- a/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginClientHandshake.cs +++ b/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginClientHandshake.cs @@ -3,13 +3,14 @@ using System; using System.Runtime.InteropServices; -using System.Security; internal static partial class Interop { internal static partial class WebSocket { +#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [DllImport(Libraries.WebSocket)] + // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs. internal static extern int WebSocketBeginClientHandshake( [In] SafeHandle webSocketHandle, [In] IntPtr subProtocols, @@ -20,5 +21,6 @@ internal static extern int WebSocketBeginClientHandshake( [In] uint initialHeaderCount, [Out] out IntPtr additionalHeadersPtr, [Out] out uint additionalHeaderCount); +#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time } } diff --git a/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginServerHandshake.cs b/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginServerHandshake.cs index 019a75a7c671e..68c10a704cb74 100644 --- a/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginServerHandshake.cs +++ b/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginServerHandshake.cs @@ -3,13 +3,14 @@ using System; using System.Runtime.InteropServices; -using System.Security; internal static partial class Interop { internal static partial class WebSocket { +#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [DllImport(Libraries.WebSocket)] + // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs. internal static extern int WebSocketBeginServerHandshake( [In] SafeHandle webSocketHandle, [In] IntPtr subProtocol, @@ -19,5 +20,6 @@ internal static extern int WebSocketBeginServerHandshake( [In] uint requestHeaderCount, [Out] out IntPtr responseHeadersPtr, [Out] out uint responseHeaderCount); +#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time } } diff --git a/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp.cs b/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp.cs index 85ca830e06f18..ccd5084c43018 100644 --- a/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp.cs +++ b/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp.cs @@ -187,12 +187,15 @@ public static partial bool WinHttpSetTimeouts( public static partial bool WinHttpGetIEProxyConfigForCurrentUser( out WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxyConfig); +#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool WinHttpGetProxyForUrl( - SafeWinHttpHandle? sessionHandle, string url, + // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs. + [return: MarshalAs(UnmanagedType.Bool)]public static extern bool WinHttpGetProxyForUrl( + SafeWinHttpHandle? sessionHandle, + string url, ref WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions, out WINHTTP_PROXY_INFO proxyInfo); +#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [GeneratedDllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)] public static partial IntPtr WinHttpSetStatusCallback( diff --git a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.WSAIoctl.cs b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.WSAIoctl.cs index 37265789dc827..2508a98bc2f9d 100644 --- a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.WSAIoctl.cs +++ b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.WSAIoctl.cs @@ -9,8 +9,10 @@ internal static partial class Interop { internal static partial class Winsock { +#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time // Used with SIOGETEXTENSIONFUNCTIONPOINTER - we're assuming that will never block. [DllImport(Interop.Libraries.Ws2_32, SetLastError = true)] + // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid) internal static extern SocketError WSAIoctl( SafeSocketHandle socketHandle, [In] int ioControlCode, @@ -21,6 +23,7 @@ internal static extern SocketError WSAIoctl( [Out] out int bytesTransferred, [In] IntPtr shouldBeNull, [In] IntPtr shouldBeNull2); +#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [GeneratedDllImport(Interop.Libraries.Ws2_32, EntryPoint = "WSAIoctl", SetLastError = true)] internal static partial SocketError WSAIoctl_Blocking( diff --git a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.getsockopt.cs b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.getsockopt.cs index bdfd0e49be9f0..047d46b484e89 100644 --- a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.getsockopt.cs +++ b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.getsockopt.cs @@ -32,12 +32,15 @@ internal static partial SocketError getsockopt( out IPMulticastRequest optionValue, ref int optionLength); +#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [DllImport(Interop.Libraries.Ws2_32, SetLastError = true)] + // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittale structs. internal static extern SocketError getsockopt( [In] SafeSocketHandle socketHandle, [In] SocketOptionLevel optionLevel, [In] SocketOptionName optionName, [Out] out IPv6MulticastRequest optionValue, [In, Out] ref int optionLength); +#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time } } diff --git a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.setsockopt.cs b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.setsockopt.cs index 98a9a3d4f3295..2aeb51a0c4d21 100644 --- a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.setsockopt.cs +++ b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.setsockopt.cs @@ -57,12 +57,15 @@ internal static partial SocketError setsockopt( ref IPMulticastRequest mreq, int optionLength); +#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time [DllImport(Interop.Libraries.Ws2_32, SetLastError = true)] + // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittale structs. internal static extern SocketError setsockopt( [In] SafeSocketHandle socketHandle, [In] SocketOptionLevel optionLevel, [In] SocketOptionName optionName, [In] ref IPv6MulticastRequest mreq, [In] int optionLength); +#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time } }