From f8c34f5cca3394b60028d9f639ae286111a86fff Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Wed, 9 Jun 2021 12:05:32 -0700 Subject: [PATCH] Use GeneratedDllImport in System.IO.Pipes (#53947) --- .../Unix/System.Native/Interop.Fcntl.Pipe.cs | 8 ++++---- .../Unix/System.Native/Interop.GetPeerID.cs | 4 ++-- .../Unix/System.Native/Interop.GetPeerUserName.cs | 4 ++-- .../Unix/System.Native/Interop.Read.Pipe.cs | 4 ++-- .../Unix/System.Native/Interop.Stat.Pipe.cs | 4 ++-- .../Unix/System.Native/Interop.Write.Pipe.cs | 4 ++-- .../Advapi32/Interop.ImpersonateNamedPipeClient.cs | 4 ++-- .../Windows/Kernel32/Interop.ConnectNamedPipe.cs | 8 ++++---- .../Windows/Kernel32/Interop.CreateNamedPipe.cs | 4 ++-- .../Kernel32/Interop.CreateNamedPipeClient.cs | 4 ++-- .../Kernel32/Interop.CreatePipe_SafePipeHandle.cs | 4 ++-- .../Kernel32/Interop.DisconnectNamedPipe.cs | 4 ++-- .../Interop.DuplicateHandle_SafePipeHandle.cs | 4 ++-- .../Windows/Kernel32/Interop.FlushFileBuffers.cs | 6 ++++++ .../Kernel32/Interop.GetFileType_SafeHandle.cs | 5 +++++ .../Kernel32/Interop.GetNamedPipeHandleState.cs | 4 ++-- .../Windows/Kernel32/Interop.GetNamedPipeInfo.cs | 4 ++-- .../Kernel32/Interop.ReadFile_SafeHandle_IntPtr.cs | 5 +++++ ...Interop.ReadFile_SafeHandle_NativeOverlapped.cs | 10 +++++++++ .../Kernel32/Interop.SetNamedPipeHandleState.cs | 4 ++-- .../Windows/Kernel32/Interop.WaitNamedPipe.cs | 4 ++-- .../Interop.WriteFile_SafeHandle_IntPtr.cs | 12 ++++++++++- ...nterop.WriteFile_SafeHandle_NativeOverlapped.cs | 24 ++++++++++++++++++++-- 23 files changed, 97 insertions(+), 41 deletions(-) diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Fcntl.Pipe.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Fcntl.Pipe.cs index 9e86930..6361f87 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Fcntl.Pipe.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Fcntl.Pipe.cs @@ -13,11 +13,11 @@ internal static partial class Interop { internal static readonly bool CanGetSetPipeSz = (FcntlCanGetSetPipeSz() != 0); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FcntlGetPipeSz", SetLastError=true)] - internal static extern int GetPipeSz(SafePipeHandle fd); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FcntlGetPipeSz", SetLastError=true)] + internal static partial int GetPipeSz(SafePipeHandle fd); - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FcntlSetPipeSz", SetLastError=true)] - internal static extern int SetPipeSz(SafePipeHandle fd, int size); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FcntlSetPipeSz", SetLastError=true)] + internal static partial int SetPipeSz(SafePipeHandle fd, int size); [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FcntlCanGetSetPipeSz")] [SuppressGCTransition] diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPeerID.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPeerID.cs index 2e9e6f1..23a338a 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPeerID.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPeerID.cs @@ -8,7 +8,7 @@ internal static partial class Interop { internal static partial class Sys { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPeerID", SetLastError = true)] - internal static extern int GetPeerID(SafeHandle socket, out uint euid); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPeerID", SetLastError = true)] + internal static partial int GetPeerID(SafeHandle socket, out uint euid); } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPeerUserName.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPeerUserName.cs index ccc7d9c..f45a343 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPeerUserName.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetPeerUserName.cs @@ -9,7 +9,7 @@ internal static partial class Interop { internal static partial class Sys { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPeerUserName", SetLastError = true)] - internal static extern string GetPeerUserName(SafeHandle socket); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPeerUserName", SetLastError = true, CharSet = CharSet.Ansi)] + internal static partial string GetPeerUserName(SafeHandle socket); } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Read.Pipe.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Read.Pipe.cs index 09d21bc..c2ecd36 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Read.Pipe.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Read.Pipe.cs @@ -18,7 +18,7 @@ internal static partial class Interop /// Returns the number of bytes read on success; otherwise, -1 is returned /// Note - on fail. the position of the stream may change depending on the platform; consult man 2 read for more info /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Read", SetLastError = true)] - internal static extern unsafe int Read(SafePipeHandle fd, byte* buffer, int count); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Read", SetLastError = true)] + internal static unsafe partial int Read(SafePipeHandle fd, byte* buffer, int count); } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Stat.Pipe.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Stat.Pipe.cs index 1852f98..ccf6a41 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Stat.Pipe.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Stat.Pipe.cs @@ -9,7 +9,7 @@ internal static partial class Interop { internal static partial class Sys { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FStat", SetLastError = true)] - internal static extern int FStat(SafePipeHandle fd, out FileStatus output); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FStat", SetLastError = true)] + internal static partial int FStat(SafePipeHandle fd, out FileStatus output); } } diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Write.Pipe.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Write.Pipe.cs index 2543be8..b71b9c5 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Write.Pipe.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Write.Pipe.cs @@ -17,7 +17,7 @@ internal static partial class Interop /// /// Returns the number of bytes written on success; otherwise, returns -1 and sets errno /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Write", SetLastError = true)] - internal static extern unsafe int Write(SafePipeHandle fd, byte* buffer, int bufferSize); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Write", SetLastError = true)] + internal static unsafe partial int Write(SafePipeHandle fd, byte* buffer, int bufferSize); } } diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.ImpersonateNamedPipeClient.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.ImpersonateNamedPipeClient.cs index 2b72ecd..2aef33a 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.ImpersonateNamedPipeClient.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.ImpersonateNamedPipeClient.cs @@ -9,8 +9,8 @@ internal static partial class Interop { internal static partial class Advapi32 { - [DllImport(Interop.Libraries.Advapi32, SetLastError = true)] + [GeneratedDllImport(Interop.Libraries.Advapi32, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool ImpersonateNamedPipeClient(SafePipeHandle hNamedPipe); + internal static partial bool ImpersonateNamedPipeClient(SafePipeHandle hNamedPipe); } } diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ConnectNamedPipe.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ConnectNamedPipe.cs index 2805d3d..1838d72 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ConnectNamedPipe.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ConnectNamedPipe.cs @@ -10,12 +10,12 @@ internal static partial class Interop { internal static partial class Kernel32 { - [DllImport(Libraries.Kernel32, SetLastError = true)] + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool ConnectNamedPipe(SafePipeHandle handle, NativeOverlapped* overlapped); + internal static unsafe partial bool ConnectNamedPipe(SafePipeHandle handle, NativeOverlapped* overlapped); - [DllImport(Libraries.Kernel32, SetLastError = true)] + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool ConnectNamedPipe(SafePipeHandle handle, IntPtr overlapped); + internal static partial bool ConnectNamedPipe(SafePipeHandle handle, IntPtr overlapped); } } diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateNamedPipe.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateNamedPipe.cs index 3d88bf3..9afae1e 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateNamedPipe.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateNamedPipe.cs @@ -9,8 +9,8 @@ internal static partial class Interop { internal static partial class Kernel32 { - [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false, EntryPoint = "CreateNamedPipeW")] - internal static extern SafePipeHandle CreateNamedPipe( + [GeneratedDllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, EntryPoint = "CreateNamedPipeW")] + internal static partial SafePipeHandle CreateNamedPipe( string pipeName, int openMode, int pipeMode, diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateNamedPipeClient.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateNamedPipeClient.cs index 4c8b9cb..f5cad97 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateNamedPipeClient.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateNamedPipeClient.cs @@ -10,8 +10,8 @@ internal static partial class Interop { internal static partial class Kernel32 { - [DllImport(Libraries.Kernel32, EntryPoint = "CreateFileW", CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)] - internal static extern SafePipeHandle CreateNamedPipeClient( + [GeneratedDllImport(Libraries.Kernel32, EntryPoint = "CreateFileW", CharSet = CharSet.Unicode, SetLastError = true)] + internal static partial SafePipeHandle CreateNamedPipeClient( string? lpFileName, int dwDesiredAccess, System.IO.FileShare dwShareMode, diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreatePipe_SafePipeHandle.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreatePipe_SafePipeHandle.cs index 92a3257..0b1e88a 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreatePipe_SafePipeHandle.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreatePipe_SafePipeHandle.cs @@ -9,7 +9,7 @@ internal static partial class Interop { internal static partial class Kernel32 { - [DllImport(Libraries.Kernel32, SetLastError = true)] - internal static extern bool CreatePipe(out SafePipeHandle hReadPipe, out SafePipeHandle hWritePipe, ref SECURITY_ATTRIBUTES lpPipeAttributes, int nSize); + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] + internal static partial bool CreatePipe(out SafePipeHandle hReadPipe, out SafePipeHandle hWritePipe, ref SECURITY_ATTRIBUTES lpPipeAttributes, int nSize); } } diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DisconnectNamedPipe.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DisconnectNamedPipe.cs index ccef10e..c0d1376 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DisconnectNamedPipe.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DisconnectNamedPipe.cs @@ -9,8 +9,8 @@ internal static partial class Interop { internal static partial class Kernel32 { - [DllImport(Libraries.Kernel32, SetLastError = true)] + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool DisconnectNamedPipe(SafePipeHandle hNamedPipe); + internal static partial bool DisconnectNamedPipe(SafePipeHandle hNamedPipe); } } diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DuplicateHandle_SafePipeHandle.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DuplicateHandle_SafePipeHandle.cs index 96726ab..88f2b8c 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DuplicateHandle_SafePipeHandle.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DuplicateHandle_SafePipeHandle.cs @@ -9,8 +9,8 @@ internal static partial class Interop { internal static partial class Kernel32 { - [DllImport(Libraries.Kernel32, SetLastError = true)] - internal static extern bool DuplicateHandle( + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] + internal static partial bool DuplicateHandle( IntPtr hSourceProcessHandle, SafeHandle hSourceHandle, IntPtr hTargetProcessHandle, diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FlushFileBuffers.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FlushFileBuffers.cs index 094ef61..9b0e857 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FlushFileBuffers.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FlushFileBuffers.cs @@ -7,8 +7,14 @@ internal static partial class Interop { internal static partial class Kernel32 { +#if DLLIMPORTGENERATOR_ENABLED + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static partial bool FlushFileBuffers(SafeHandle hHandle); +#else [DllImport(Libraries.Kernel32, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool FlushFileBuffers(SafeHandle hHandle); +#endif } } diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFileType_SafeHandle.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFileType_SafeHandle.cs index 557866d..d5d2062 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFileType_SafeHandle.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFileType_SafeHandle.cs @@ -7,7 +7,12 @@ internal static partial class Interop { internal static partial class Kernel32 { +#if DLLIMPORTGENERATOR_ENABLED + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] + internal static partial int GetFileType(SafeHandle hFile); +#else [DllImport(Libraries.Kernel32, SetLastError = true)] internal static extern int GetFileType(SafeHandle hFile); +#endif } } diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetNamedPipeHandleState.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetNamedPipeHandleState.cs index f98c2c1..74c60e6 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetNamedPipeHandleState.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetNamedPipeHandleState.cs @@ -8,8 +8,8 @@ internal static partial class Interop { internal static partial class Kernel32 { - [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)] - internal static extern unsafe bool GetNamedPipeHandleStateW( + [GeneratedDllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)] + internal static unsafe partial bool GetNamedPipeHandleStateW( SafePipeHandle hNamedPipe, uint* lpState, uint* lpCurInstances, diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetNamedPipeInfo.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetNamedPipeInfo.cs index 586f661..b370c8e 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetNamedPipeInfo.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetNamedPipeInfo.cs @@ -8,8 +8,8 @@ internal static partial class Interop { internal static partial class Kernel32 { - [DllImport(Libraries.Kernel32, SetLastError = true)] - internal static extern unsafe bool GetNamedPipeInfo( + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] + internal static unsafe partial bool GetNamedPipeInfo( SafePipeHandle hNamedPipe, uint* lpFlags, uint* lpOutBufferSize, diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_IntPtr.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_IntPtr.cs index d2ab765..9651a10 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_IntPtr.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_IntPtr.cs @@ -8,8 +8,13 @@ internal static partial class Interop { internal static partial class Kernel32 { +#if DLLIMPORTGENERATOR_ENABLED + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] + internal static unsafe partial int ReadFile( +#else [DllImport(Libraries.Kernel32, SetLastError = true)] internal static extern unsafe int ReadFile( +#endif SafeHandle handle, byte* bytes, int numBytesToRead, diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_NativeOverlapped.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_NativeOverlapped.cs index c6fb2c4..ba9b6a9 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_NativeOverlapped.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ReadFile_SafeHandle_NativeOverlapped.cs @@ -9,16 +9,26 @@ internal static partial class Interop { internal static partial class Kernel32 { +#if DLLIMPORTGENERATOR_ENABLED + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] + internal static unsafe partial int ReadFile( +#else [DllImport(Libraries.Kernel32, SetLastError = true)] internal static extern unsafe int ReadFile( +#endif SafeHandle handle, byte* bytes, int numBytesToRead, IntPtr numBytesRead_mustBeZero, NativeOverlapped* overlapped); +#if DLLIMPORTGENERATOR_ENABLED + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] + internal static unsafe partial int ReadFile( +#else [DllImport(Libraries.Kernel32, SetLastError = true)] internal static extern unsafe int ReadFile( +#endif SafeHandle handle, byte* bytes, int numBytesToRead, diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.SetNamedPipeHandleState.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.SetNamedPipeHandleState.cs index 70f0ab1..2ee9911 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.SetNamedPipeHandleState.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.SetNamedPipeHandleState.cs @@ -9,9 +9,9 @@ internal static partial class Interop { internal static partial class Kernel32 { - [DllImport(Libraries.Kernel32, SetLastError = true)] + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool SetNamedPipeHandleState( + internal static unsafe partial bool SetNamedPipeHandleState( SafePipeHandle hNamedPipe, int* lpMode, IntPtr lpMaxCollectionCount, diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WaitNamedPipe.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WaitNamedPipe.cs index cb95a8e..76abe2b 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WaitNamedPipe.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WaitNamedPipe.cs @@ -7,8 +7,8 @@ internal static partial class Interop { internal static partial class Kernel32 { - [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false, EntryPoint = "WaitNamedPipeW")] + [GeneratedDllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, EntryPoint = "WaitNamedPipeW")] [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool WaitNamedPipe(string? name, int timeout); + internal static partial bool WaitNamedPipe(string? name, int timeout); } } diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_IntPtr.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_IntPtr.cs index 9101041..6354c1a 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_IntPtr.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_IntPtr.cs @@ -15,7 +15,17 @@ internal static partial class Interop // struct in a callback (or an EndWrite method called by that callback), // and pass in an address for the numBytesRead parameter. +#if DLLIMPORTGENERATOR_ENABLED + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] + internal static unsafe partial int WriteFile( +#else [DllImport(Libraries.Kernel32, SetLastError = true)] - internal static extern unsafe int WriteFile(SafeHandle handle, byte* bytes, int numBytesToWrite, out int numBytesWritten, IntPtr mustBeZero); + internal static extern unsafe int WriteFile( +#endif + SafeHandle handle, + byte* bytes, + int numBytesToWrite, + out int numBytesWritten, + IntPtr mustBeZero); } } diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_NativeOverlapped.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_NativeOverlapped.cs index 3eaff9c..0f66079 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_NativeOverlapped.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WriteFile_SafeHandle_NativeOverlapped.cs @@ -15,10 +15,30 @@ internal static partial class Interop // simultaneously: overlapped IO, free the memory for the overlapped // struct in a callback (or an EndWrite method called by that callback), // and pass in an address for the numBytesRead parameter. +#if DLLIMPORTGENERATOR_ENABLED + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] + internal static unsafe partial int WriteFile( +#else [DllImport(Libraries.Kernel32, SetLastError = true)] - internal static extern unsafe int WriteFile(SafeHandle handle, byte* bytes, int numBytesToWrite, IntPtr numBytesWritten_mustBeZero, NativeOverlapped* lpOverlapped); + internal static extern unsafe int WriteFile( +#endif + SafeHandle handle, + byte* bytes, + int numBytesToWrite, + IntPtr numBytesWritten_mustBeZero, + NativeOverlapped* lpOverlapped); +#if DLLIMPORTGENERATOR_ENABLED + [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)] + internal static unsafe partial int WriteFile( +#else [DllImport(Libraries.Kernel32, SetLastError = true)] - internal static extern unsafe int WriteFile(SafeHandle handle, byte* bytes, int numBytesToWrite, out int numBytesWritten, NativeOverlapped* lpOverlapped); + internal static extern unsafe int WriteFile( +#endif + SafeHandle handle, + byte* bytes, + int numBytesToWrite, + out int numBytesWritten, + NativeOverlapped* lpOverlapped); } } -- 2.7.4