20 #ifndef WINPR_HANDLE_PRIVATE_H
21 #define WINPR_HANDLE_PRIVATE_H
23 #include <winpr/handle.h>
24 #include <winpr/file.h>
25 #include <winpr/synch.h>
26 #include <winpr/winsock.h>
28 #define HANDLE_TYPE_NONE 0
29 #define HANDLE_TYPE_PROCESS 1
30 #define HANDLE_TYPE_THREAD 2
31 #define HANDLE_TYPE_EVENT 3
32 #define HANDLE_TYPE_MUTEX 4
33 #define HANDLE_TYPE_SEMAPHORE 5
34 #define HANDLE_TYPE_TIMER 6
35 #define HANDLE_TYPE_NAMED_PIPE 7
36 #define HANDLE_TYPE_ANONYMOUS_PIPE 8
37 #define HANDLE_TYPE_ACCESS_TOKEN 9
38 #define HANDLE_TYPE_FILE 10
39 #define HANDLE_TYPE_TIMER_QUEUE 11
40 #define HANDLE_TYPE_TIMER_QUEUE_TIMER 12
41 #define HANDLE_TYPE_COMM 13
43 typedef BOOL (*pcIsHandled)(HANDLE handle);
44 typedef BOOL (*pcCloseHandle)(HANDLE handle);
45 typedef int (*pcGetFd)(HANDLE handle);
46 typedef DWORD (*pcCleanupHandle)(HANDLE handle);
47 typedef BOOL (*pcReadFile)(PVOID Object, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
49 typedef BOOL (*pcReadFileEx)(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
51 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
53 DWORD nNumberOfBytesToRead, LPDWORD lpReserved,
55 typedef BOOL (*pcWriteFile)(PVOID Object, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
56 LPDWORD lpNumberOfBytesWritten,
LPOVERLAPPED lpOverlapped);
57 typedef BOOL (*pcWriteFileEx)(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
59 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
61 DWORD nNumberOfBytesToWrite, LPDWORD lpReserved,
63 typedef DWORD (*pcGetFileSize)(HANDLE handle, LPDWORD lpFileSizeHigh);
64 typedef BOOL (*pcGetFileInformationByHandle)(HANDLE handle,
66 typedef BOOL (*pcFlushFileBuffers)(HANDLE hFile);
67 typedef BOOL (*pcSetEndOfFile)(HANDLE handle);
68 typedef DWORD (*pcSetFilePointer)(HANDLE handle, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh,
70 typedef BOOL (*pcSetFilePointerEx)(HANDLE hFile,
LARGE_INTEGER liDistanceToMove,
71 PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod);
72 typedef BOOL (*pcLockFile)(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh,
73 DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh);
74 typedef BOOL (*pcLockFileEx)(HANDLE hFile, DWORD dwFlags, DWORD dwReserved,
75 DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh,
77 typedef BOOL (*pcUnlockFile)(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh,
78 DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh);
79 typedef BOOL (*pcUnlockFileEx)(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow,
80 DWORD nNumberOfBytesToUnlockHigh,
LPOVERLAPPED lpOverlapped);
81 typedef BOOL (*pcSetFileTime)(HANDLE hFile,
const FILETIME* lpCreationTime,
86 pcIsHandled IsHandled;
87 pcCloseHandle CloseHandle;
89 pcCleanupHandle CleanupHandle;
91 pcReadFileEx ReadFileEx;
92 pcReadFileScatter ReadFileScatter;
93 pcWriteFile WriteFile;
94 pcWriteFileEx WriteFileEx;
95 pcWriteFileGather WriteFileGather;
96 pcGetFileSize GetFileSize;
97 pcFlushFileBuffers FlushFileBuffers;
98 pcSetEndOfFile SetEndOfFile;
99 pcSetFilePointer SetFilePointer;
100 pcSetFilePointerEx SetFilePointerEx;
102 pcLockFileEx LockFileEx;
103 pcUnlockFile UnlockFile;
104 pcUnlockFileEx UnlockFileEx;
105 pcSetFileTime SetFileTime;
106 pcGetFileInformationByHandle GetFileInformationByHandle;
116 static INLINE BOOL WINPR_HANDLE_IS_HANDLED(HANDLE handle, ULONG type, BOOL invalidValue)
119 BOOL invalid = !pWinprHandle;
123 if (INVALID_HANDLE_VALUE == pWinprHandle)
127 if (invalid || (pWinprHandle->Type != type))
129 SetLastError(ERROR_INVALID_HANDLE);
136 static INLINE
void WINPR_HANDLE_SET_TYPE_AND_MODE(
void* _handle, ULONG _type, ULONG _mode)
144 static INLINE BOOL winpr_Handle_GetInfo(HANDLE handle, ULONG* pType,
WINPR_HANDLE** pObject)
153 #ifndef __clang_analyzer__
154 if (handle == INVALID_HANDLE_VALUE)
160 *pType = wHandle->Type;
166 static INLINE
int winpr_Handle_getFd(HANDLE handle)
171 if (!winpr_Handle_GetInfo(handle, &type, &hdl))
174 if (!hdl || !hdl->ops || !hdl->ops->GetFd)
177 return hdl->ops->GetFd(handle);
180 static INLINE DWORD winpr_Handle_cleanup(HANDLE handle)
185 if (!winpr_Handle_GetInfo(handle, &type, &hdl))
188 if (!hdl || !hdl->ops)
192 if (!hdl->ops->CleanupHandle)
193 return WAIT_OBJECT_0;
195 return hdl->ops->CleanupHandle(handle);