Skip to content
This repository was archived by the owner on Jul 26, 2023. It is now read-only.

Add NativeOverlapped overloads #495

Merged
merged 3 commits into from
Jul 19, 2020
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
2 changes: 1 addition & 1 deletion src/Kernel32.Tests/storebanned/Kernel32Facts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public unsafe void CancelIoEx_CancelWriteAll()
Assert.Equal(Win32ErrorCode.ERROR_IO_PENDING, lastError);
try
{
var cancelled = CancelIoEx(file, null);
var cancelled = CancelIoEx(file, (NativeOverlapped*)null);

// We can't assert that it's true as if the IO finished already it'll fail with ERROR_NOT_FOUND
if (!cancelled)
Expand Down
49 changes: 49 additions & 0 deletions src/Kernel32/Kernel32.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace PInvoke
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

/// <content>
/// Methods and nested types that are not strictly P/Invokes but provide
Expand Down Expand Up @@ -256,6 +257,54 @@ public static ArraySegment<byte> ReadFile(SafeObjectHandle hFile, int nNumberOfB
return new ArraySegment<byte>(buffer, 0, bytesRead);
}

/// <inheritdoc cref="CancelIoEx(SafeObjectHandle, OVERLAPPED*)" />
[NoFriendlyOverloads]
public static unsafe bool CancelIoEx(
SafeObjectHandle hFile,
NativeOverlapped* lpOverlapped)
{
return CancelIoEx(hFile, (OVERLAPPED*)lpOverlapped);
}

/// <inheritdoc cref="ReadFile(SafeObjectHandle, void*, int, int*, OVERLAPPED*)"/>
[NoFriendlyOverloads]
public static unsafe bool ReadFile(
SafeObjectHandle hFile,
void* lpBuffer,
int nNumberOfBytesToRead,
int* lpNumberOfBytesRead,
NativeOverlapped* lpOverlapped)
{
return ReadFile(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, (OVERLAPPED*)lpOverlapped);
}

/// <inheritdoc cref="WriteFile(SafeObjectHandle, void*, int, int*, OVERLAPPED*)"/>
[NoFriendlyOverloads]
public static unsafe bool WriteFile(
SafeObjectHandle hFile,
void* lpBuffer,
int nNumberOfBytesToWrite,
int* lpNumberOfBytesWritten,
NativeOverlapped* lpOverlapped)
{
return WriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, (OVERLAPPED*)lpOverlapped);
}

/// <inheritdoc cref="DeviceIoControl(SafeObjectHandle, int, void*, int, void*, int, out int, OVERLAPPED*)"/>
[NoFriendlyOverloads]
public static unsafe bool DeviceIoControl(
SafeObjectHandle hDevice,
int dwIoControlCode,
void* inBuffer,
int nInBufferSize,
void* outBuffer,
int nOutBufferSize,
out int pBytesReturned,
NativeOverlapped* lpOverlapped)
{
return DeviceIoControl(hDevice, dwIoControlCode, inBuffer, nInBufferSize, outBuffer, nOutBufferSize, out pBytesReturned, (OVERLAPPED*)lpOverlapped);
}

/// <summary>
/// Tries to get the error message text using the supplied buffer.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Kernel32/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const PInvoke.Kernel32.PROCESS_MEMORY_EXHAUSTION_INFO.PME_CURRENT_VERSION = 1 ->
const PInvoke.Kernel32.PROCESS_POWER_THROTTLING_STATE.PROCESS_POWER_THROTTLING_CURRENT_VERSION = 1 -> uint
override PInvoke.Kernel32.SafePseudoConsoleHandle.IsInvalid.get -> bool
override PInvoke.Kernel32.SafePseudoConsoleHandle.ReleaseHandle() -> bool
static PInvoke.Kernel32.CancelIoEx(PInvoke.Kernel32.SafeObjectHandle hFile, System.Threading.NativeOverlapped* lpOverlapped) -> bool
static PInvoke.Kernel32.CreateRemoteThread(System.IntPtr hProcess, PInvoke.Kernel32.SECURITY_ATTRIBUTES? lpThreadAttributes, System.UIntPtr dwStackSize, PInvoke.Kernel32.THREAD_START_ROUTINE lpStartAddress, System.IntPtr lpParameter, PInvoke.Kernel32.CreateThreadFlags dwCreationFlags, ref uint? lpThreadId) -> PInvoke.Kernel32.SafeObjectHandle
static PInvoke.Kernel32.CreateRemoteThread(System.IntPtr hProcess, PInvoke.Kernel32.SECURITY_ATTRIBUTES? lpThreadAttributes, System.UIntPtr dwStackSize, PInvoke.Kernel32.THREAD_START_ROUTINE lpStartAddress, void* lpParameter, PInvoke.Kernel32.CreateThreadFlags dwCreationFlags, ref uint? lpThreadId) -> PInvoke.Kernel32.SafeObjectHandle
static PInvoke.Kernel32.CreateRemoteThread(System.IntPtr hProcess, System.IntPtr lpThreadAttributes, System.UIntPtr dwStackSize, PInvoke.Kernel32.THREAD_START_ROUTINE lpStartAddress, System.IntPtr lpParameter, PInvoke.Kernel32.CreateThreadFlags dwCreationFlags, System.IntPtr lpThreadId) -> PInvoke.Kernel32.SafeObjectHandle
Expand All @@ -212,6 +213,7 @@ static PInvoke.Kernel32.CreateRemoteThreadEx(System.IntPtr hProcess, System.IntP
static PInvoke.Kernel32.CreateThread(PInvoke.Kernel32.SECURITY_ATTRIBUTES? lpThreadAttributes, System.UIntPtr dwStackSize, PInvoke.Kernel32.THREAD_START_ROUTINE lpStartAddress, System.IntPtr lpParameter, PInvoke.Kernel32.CreateThreadFlags dwCreationFlags, ref uint? lpThreadId) -> PInvoke.Kernel32.SafeObjectHandle
static PInvoke.Kernel32.CreateThread(PInvoke.Kernel32.SECURITY_ATTRIBUTES? lpThreadAttributes, System.UIntPtr dwStackSize, PInvoke.Kernel32.THREAD_START_ROUTINE lpStartAddress, void* lpParameter, PInvoke.Kernel32.CreateThreadFlags dwCreationFlags, ref uint? lpThreadId) -> PInvoke.Kernel32.SafeObjectHandle
static PInvoke.Kernel32.CreateThread(System.IntPtr lpThreadAttributes, System.UIntPtr dwStackSize, PInvoke.Kernel32.THREAD_START_ROUTINE lpStartAddress, System.IntPtr lpParameter, PInvoke.Kernel32.CreateThreadFlags dwCreationFlags, System.IntPtr lpThreadId) -> PInvoke.Kernel32.SafeObjectHandle
static PInvoke.Kernel32.DeviceIoControl(PInvoke.Kernel32.SafeObjectHandle hDevice, int dwIoControlCode, void* inBuffer, int nInBufferSize, void* outBuffer, int nOutBufferSize, out int pBytesReturned, System.Threading.NativeOverlapped* lpOverlapped) -> bool
static PInvoke.Kernel32.DeviceIoControlAsync<TInput, TOutput>(PInvoke.Kernel32.SafeObjectHandle hDevice, uint dwIoControlCode, System.Memory<TInput> inBuffer, System.Memory<TOutput> outBuffer, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<uint>
static PInvoke.Kernel32.DosDateTimeToFileTime(ushort wFatDate, ushort wFatTime, System.IntPtr lpFileTime) -> bool
static PInvoke.Kernel32.DosDateTimeToFileTime(ushort wFatDate, ushort wFatTime, out PInvoke.Kernel32.FILETIME lpFileTime) -> bool
Expand All @@ -220,14 +222,17 @@ static PInvoke.Kernel32.GetCurrentProcessorNumberEx(System.IntPtr ProcNumber) ->
static PInvoke.Kernel32.GetCurrentProcessorNumberEx(out PInvoke.Kernel32.PROCESSOR_NUMBER ProcNumber) -> void
static PInvoke.Kernel32.GetNativeSystemInfo(System.IntPtr lpSystemInfo) -> void
static PInvoke.Kernel32.GetNativeSystemInfo(out PInvoke.Kernel32.SYSTEM_INFO lpSystemInfo) -> void
static PInvoke.Kernel32.GetOverlappedResult(PInvoke.Kernel32.SafeObjectHandle hFile, System.Threading.NativeOverlapped* lpOverlapped, out int lpNumberOfBytesTransferred, bool bWait) -> bool
static PInvoke.Kernel32.GetProcessInformation(PInvoke.Kernel32.SafeObjectHandle hProcess, PInvoke.Kernel32.PROCESS_INFORMATION_CLASS ProcessInformationClass, System.IntPtr ProcessInformation, uint ProcessInformationSize) -> bool
static PInvoke.Kernel32.GetVolumeInformation(string lpRootPathName, System.IntPtr lpVolumeNameBuffer, int nVolumeNameSize, out uint lpVolumeSerialNumber, out int lpMaximumComponentLength, out PInvoke.Kernel32.FileSystemFlags lpFileSystemFlags, System.IntPtr lpFileSystemNameBuffer, int nFileSystemNameSize) -> bool
static PInvoke.Kernel32.GetVolumeInformation(string lpRootPathName, char[] lpVolumeNameBuffer, int nVolumeNameSize, out uint lpVolumeSerialNumber, out int lpMaximumComponentLength, out PInvoke.Kernel32.FileSystemFlags lpFileSystemFlags, char[] lpFileSystemNameBuffer, int nFileSystemNameSize) -> bool
static PInvoke.Kernel32.OSVERSIONINFO.Create() -> PInvoke.Kernel32.OSVERSIONINFO
static PInvoke.Kernel32.ReadFile(PInvoke.Kernel32.SafeObjectHandle hFile, void* lpBuffer, int nNumberOfBytesToRead, int* lpNumberOfBytesRead, System.Threading.NativeOverlapped* lpOverlapped) -> bool
static PInvoke.Kernel32.ReadProcessMemory(PInvoke.Kernel32.SafeObjectHandle hProcess, System.IntPtr lpBaseAddress, System.IntPtr lpBuffer, System.UIntPtr nSize, out System.UIntPtr lpNumberOfBytesRead) -> bool
static PInvoke.Kernel32.SetFilePointer(PInvoke.Kernel32.SafeObjectHandle hFile, int lDistanceToMove, System.IntPtr lpDistanceToMoveHigh, System.IO.SeekOrigin dwMoveMethod) -> int
static PInvoke.Kernel32.SetFilePointer(PInvoke.Kernel32.SafeObjectHandle hFile, int lDistanceToMove, ref int? lpDistanceToMoveHigh, System.IO.SeekOrigin dwMoveMethod) -> int
static PInvoke.Kernel32.SetProcessInformation(PInvoke.Kernel32.SafeObjectHandle hProcess, PInvoke.Kernel32.PROCESS_INFORMATION_CLASS ProcessInformationClass, System.IntPtr ProcessInformation, uint ProcessInformationSize) -> bool
static PInvoke.Kernel32.WriteFile(PInvoke.Kernel32.SafeObjectHandle hFile, void* lpBuffer, int nNumberOfBytesToWrite, int* lpNumberOfBytesWritten, System.Threading.NativeOverlapped* lpOverlapped) -> bool
static extern PInvoke.Kernel32.CreatePseudoConsole(PInvoke.COORD size, PInvoke.Kernel32.SafeObjectHandle hInput, PInvoke.Kernel32.SafeObjectHandle hOutput, PInvoke.Kernel32.CreatePseudoConsoleFlags dwFlags, out PInvoke.Kernel32.SafePseudoConsoleHandle phPC) -> PInvoke.HResult
static extern PInvoke.Kernel32.CreateRemoteThread(System.IntPtr hProcess, PInvoke.Kernel32.SECURITY_ATTRIBUTES* lpThreadAttributes, System.UIntPtr dwStackSize, PInvoke.Kernel32.THREAD_START_ROUTINE lpStartAddress, void* lpParameter, PInvoke.Kernel32.CreateThreadFlags dwCreationFlags, uint* lpThreadId) -> PInvoke.Kernel32.SafeObjectHandle
static extern PInvoke.Kernel32.CreateRemoteThreadEx(System.IntPtr hProcess, PInvoke.Kernel32.SECURITY_ATTRIBUTES* lpThreadAttributes, System.UIntPtr dwStackSize, PInvoke.Kernel32.THREAD_START_ROUTINE lpStartAddress, void* lpParameter, PInvoke.Kernel32.CreateThreadFlags dwCreationFlags, PInvoke.Kernel32.PROC_THREAD_ATTRIBUTE_LIST* lpAttributeList, uint* lpThreadId) -> PInvoke.Kernel32.SafeObjectHandle
Expand Down
11 changes: 11 additions & 0 deletions src/Kernel32/storebanned/Kernel32.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,5 +382,16 @@ public static unsafe ValueTask<uint> DeviceIoControlAsync<TInput, TOutput>(
}
}
}

/// <inheritdoc cref="GetOverlappedResult(SafeObjectHandle, OVERLAPPED*, out int, bool)"/>
[NoFriendlyOverloads]
public static unsafe bool GetOverlappedResult(
SafeObjectHandle hFile,
NativeOverlapped* lpOverlapped,
out int lpNumberOfBytesTransferred,
bool bWait)
{
return GetOverlappedResult(hFile, (OVERLAPPED*)lpOverlapped, out lpNumberOfBytesTransferred, bWait);
}
}
}