Skip to content

Commit

Permalink
winapi: Implement GetOverlappedResult
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryzee119 committed May 4, 2024
1 parent a21a4f5 commit 7539aa0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/winapi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ WINAPI_SRCS := \
$(NXDK_DIR)/lib/winapi/filemanip.c \
$(NXDK_DIR)/lib/winapi/findfile.c \
$(NXDK_DIR)/lib/winapi/handleapi.c \
$(NXDK_DIR)/lib/winapi/ioapi.c \
$(NXDK_DIR)/lib/winapi/memory.c \
$(NXDK_DIR)/lib/winapi/libloaderapi.c \
$(NXDK_DIR)/lib/winapi/profiling.c \
Expand Down
47 changes: 47 additions & 0 deletions lib/winapi/ioapi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: MIT

// SPDX-FileCopyrightText: 2023 Ryan Wendland

#include <synchapi.h>
#include <winbase.h>
#include <winerror.h>
#include <xboxkrnl/xboxkrnl.h>

BOOL GetOverlappedResult (HANDLE hFile, LPOVERLAPPED lpOverlapped, LPDWORD lpNumberOfBytesTransferred, BOOL bWait)
{
DWORD status;
HANDLE waitHandle;

status = (DWORD)lpOverlapped->Internal;

if (status == STATUS_PENDING && bWait == FALSE) {
SetLastError(ERROR_IO_INCOMPLETE);
return FALSE;
}

// If the hEvent member of the OVERLAPPED structure is NULL, the system
// uses the state of the hFile handle to signal when the operation has been completed
if (lpOverlapped->hEvent == NULL) {
waitHandle = hFile;
} else {
waitHandle = lpOverlapped->hEvent;
}

if (status == STATUS_PENDING) {
if (WaitForSingleObject(waitHandle, INFINITE) != WAIT_OBJECT_0) {
SetLastError(ERROR_IO_INCOMPLETE);
return FALSE;
}
// Get final status of the transfer
status = (DWORD)lpOverlapped->Internal;
}

// InternalHigh contains the actual number of bytes transferred for the I/O request
*lpNumberOfBytesTransferred = (DWORD)lpOverlapped->InternalHigh;

if (!NT_SUCCESS(status)) {
SetLastError(RtlNtStatusToDosError(status));
return FALSE;
}
return TRUE;
}
2 changes: 2 additions & 0 deletions lib/winapi/winbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ void WINAPI OutputDebugStringA (LPCTSTR lpOutputString);

BOOL IsBadWritePtr (LPVOID lp, UINT_PTR ucb);

BOOL GetOverlappedResult (HANDLE hFile, LPOVERLAPPED lpOverlapped, LPDWORD lpNumberOfBytesTransferred, BOOL bWait);

#ifndef UNICODE
#define OutputDebugString OutputDebugStringA
#else
Expand Down

0 comments on commit 7539aa0

Please sign in to comment.