Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GeneratedDllImport in System.IO.Pipes #53947

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ internal static partial class Fcntl
{
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal static partial class Sys
/// 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
/// </returns>
[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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static partial class Sys
/// <returns>
/// Returns the number of bytes written on success; otherwise, returns -1 and sets errno
/// </returns>
[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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ internal static partial class Kernel32
// 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,30 @@ internal static partial class Kernel32
// 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);
}
}