FreeRDP
include/winpr/io.h
1 
20 #ifndef WINPR_IO_H
21 #define WINPR_IO_H
22 
23 #include <winpr/winpr.h>
24 #include <winpr/wtypes.h>
25 #include <winpr/handle.h>
26 
27 WINPR_PRAGMA_DIAG_PUSH
28 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
29 
30 #ifdef _WIN32
31 
32 #include <winioctl.h>
33 
34 #else
35 
36 #include <winpr/nt.h>
37 
38 typedef struct
39 {
40  ULONG_PTR Internal;
41  ULONG_PTR InternalHigh;
42  union
43  {
44  struct
45  {
46  DWORD Offset;
47  DWORD OffsetHigh;
48  } DUMMYSTRUCTNAME;
49  PVOID Pointer;
50  } DUMMYUNIONNAME;
51  HANDLE hEvent;
53 
54 typedef struct
55 {
56  ULONG_PTR lpCompletionKey;
57  LPOVERLAPPED lpOverlapped;
58  ULONG_PTR Internal;
59  DWORD dwNumberOfBytesTransferred;
61 
62 #ifdef __cplusplus
63 extern "C"
64 {
65 #endif
66 
67  WINPR_API BOOL GetOverlappedResult(HANDLE hFile, LPOVERLAPPED lpOverlapped,
68  LPDWORD lpNumberOfBytesTransferred, BOOL bWait);
69 
70  WINPR_API BOOL GetOverlappedResultEx(HANDLE hFile, LPOVERLAPPED lpOverlapped,
71  LPDWORD lpNumberOfBytesTransferred, DWORD dwMilliseconds,
72  BOOL bAlertable);
73 
74  WINPR_API BOOL DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer,
75  DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize,
76  LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped);
77 
78  WINPR_ATTR_MALLOC(CloseHandle, 1)
79  WINPR_API HANDLE CreateIoCompletionPort(HANDLE FileHandle, HANDLE ExistingCompletionPort,
80  ULONG_PTR CompletionKey,
81  DWORD NumberOfConcurrentThreads);
82 
83  WINPR_API BOOL GetQueuedCompletionStatus(HANDLE CompletionPort,
84  LPDWORD lpNumberOfBytesTransferred,
85  PULONG_PTR lpCompletionKey, LPOVERLAPPED* lpOverlapped,
86  DWORD dwMilliseconds);
87 
88  WINPR_API BOOL GetQueuedCompletionStatusEx(HANDLE CompletionPort,
89  LPOVERLAPPED_ENTRY lpCompletionPortEntries,
90  ULONG ulCount, PULONG ulNumEntriesRemoved,
91  DWORD dwMilliseconds, BOOL fAlertable);
92 
93  WINPR_API BOOL PostQueuedCompletionStatus(HANDLE CompletionPort,
94  DWORD dwNumberOfBytesTransferred,
95  ULONG_PTR dwCompletionKey, LPOVERLAPPED lpOverlapped);
96 
97  WINPR_API BOOL CancelIo(HANDLE hFile);
98 
99  WINPR_API BOOL CancelIoEx(HANDLE hFile, LPOVERLAPPED lpOverlapped);
100 
101  WINPR_API BOOL CancelSynchronousIo(HANDLE hThread);
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 #define DEVICE_TYPE ULONG
108 
109 #define FILE_DEVICE_BEEP 0x00000001
110 #define FILE_DEVICE_CD_ROM 0x00000002
111 #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
112 #define FILE_DEVICE_CONTROLLER 0x00000004
113 #define FILE_DEVICE_DATALINK 0x00000005
114 #define FILE_DEVICE_DFS 0x00000006
115 #define FILE_DEVICE_DISK 0x00000007
116 #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
117 #define FILE_DEVICE_FILE_SYSTEM 0x00000009
118 #define FILE_DEVICE_INPORT_PORT 0x0000000a
119 #define FILE_DEVICE_KEYBOARD 0x0000000b
120 #define FILE_DEVICE_MAILSLOT 0x0000000c
121 #define FILE_DEVICE_MIDI_IN 0x0000000d
122 #define FILE_DEVICE_MIDI_OUT 0x0000000e
123 #define FILE_DEVICE_MOUSE 0x0000000f
124 #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
125 #define FILE_DEVICE_NAMED_PIPE 0x00000011
126 #define FILE_DEVICE_NETWORK 0x00000012
127 #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
128 #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
129 #define FILE_DEVICE_NULL 0x00000015
130 #define FILE_DEVICE_PARALLEL_PORT 0x00000016
131 #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
132 #define FILE_DEVICE_PRINTER 0x00000018
133 #define FILE_DEVICE_SCANNER 0x00000019
134 #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
135 #define FILE_DEVICE_SERIAL_PORT 0x0000001b
136 #define FILE_DEVICE_SCREEN 0x0000001c
137 #define FILE_DEVICE_SOUND 0x0000001d
138 #define FILE_DEVICE_STREAMS 0x0000001e
139 #define FILE_DEVICE_TAPE 0x0000001f
140 #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
141 #define FILE_DEVICE_TRANSPORT 0x00000021
142 #define FILE_DEVICE_UNKNOWN 0x00000022
143 #define FILE_DEVICE_VIDEO 0x00000023
144 #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
145 #define FILE_DEVICE_WAVE_IN 0x00000025
146 #define FILE_DEVICE_WAVE_OUT 0x00000026
147 #define FILE_DEVICE_8042_PORT 0x00000027
148 #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
149 #define FILE_DEVICE_BATTERY 0x00000029
150 #define FILE_DEVICE_BUS_EXTENDER 0x0000002a
151 #define FILE_DEVICE_MODEM 0x0000002b
152 #define FILE_DEVICE_VDM 0x0000002c
153 #define FILE_DEVICE_MASS_STORAGE 0x0000002d
154 #define FILE_DEVICE_SMB 0x0000002e
155 #define FILE_DEVICE_KS 0x0000002f
156 #define FILE_DEVICE_CHANGER 0x00000030
157 #define FILE_DEVICE_SMARTCARD 0x00000031
158 #define FILE_DEVICE_ACPI 0x00000032
159 #define FILE_DEVICE_DVD 0x00000033
160 #define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
161 #define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
162 #define FILE_DEVICE_DFS_VOLUME 0x00000036
163 #define FILE_DEVICE_SERENUM 0x00000037
164 #define FILE_DEVICE_TERMSRV 0x00000038
165 #define FILE_DEVICE_KSEC 0x00000039
166 #define FILE_DEVICE_FIPS 0x0000003A
167 #define FILE_DEVICE_INFINIBAND 0x0000003B
168 #define FILE_DEVICE_VMBUS 0x0000003E
169 #define FILE_DEVICE_CRYPT_PROVIDER 0x0000003F
170 #define FILE_DEVICE_WPD 0x00000040
171 #define FILE_DEVICE_BLUETOOTH 0x00000041
172 #define FILE_DEVICE_MT_COMPOSITE 0x00000042
173 #define FILE_DEVICE_MT_TRANSPORT 0x00000043
174 #define FILE_DEVICE_BIOMETRIC 0x00000044
175 #define FILE_DEVICE_PMI 0x00000045
176 
177 #define CTL_CODE(DeviceType, Function, Method, Access) \
178  (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
179 
180 #define DEVICE_TYPE_FROM_CTL_CODE(ctrlCode) (((DWORD)(ctrlCode & 0xFFFF0000)) >> 16)
181 
182 #define METHOD_FROM_CTL_CODE(ctrlCode) ((DWORD)(ctrlCode & 3))
183 
184 #define METHOD_BUFFERED 0
185 #define METHOD_IN_DIRECT 1
186 #define METHOD_OUT_DIRECT 2
187 #define METHOD_NEITHER 3
188 
189 #define FILE_ANY_ACCESS 0
190 #define FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS)
191 #define FILE_READ_ACCESS (0x0001)
192 #define FILE_WRITE_ACCESS (0x0002)
193 
194 /*
195  * WinPR I/O Manager Custom API
196  */
197 
198 typedef HANDLE PDRIVER_OBJECT_EX;
199 typedef HANDLE PDEVICE_OBJECT_EX;
200 
201 WINPR_API NTSTATUS _IoCreateDeviceEx(PDRIVER_OBJECT_EX DriverObject, ULONG DeviceExtensionSize,
202  PUNICODE_STRING DeviceName, DEVICE_TYPE DeviceType,
203  ULONG DeviceCharacteristics, BOOLEAN Exclusive,
204  PDEVICE_OBJECT_EX* DeviceObject);
205 
206 WINPR_API VOID _IoDeleteDeviceEx(PDEVICE_OBJECT_EX DeviceObject);
207 
208 #endif
209 
210 #ifdef _UWP
211 
212 #ifdef __cplusplus
213 extern "C"
214 {
215 #endif
216 
217  WINPR_API BOOL GetOverlappedResult(HANDLE hFile, LPOVERLAPPED lpOverlapped,
218  LPDWORD lpNumberOfBytesTransferred, BOOL bWait);
219 
220  WINPR_API BOOL DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer,
221  DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize,
222  LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped);
223 
224  WINPR_API HANDLE CreateIoCompletionPort(HANDLE FileHandle, HANDLE ExistingCompletionPort,
225  ULONG_PTR CompletionKey,
226  DWORD NumberOfConcurrentThreads);
227 
228  WINPR_API BOOL GetQueuedCompletionStatus(HANDLE CompletionPort,
229  LPDWORD lpNumberOfBytesTransferred,
230  PULONG_PTR lpCompletionKey, LPOVERLAPPED* lpOverlapped,
231  DWORD dwMilliseconds);
232 
233  WINPR_API BOOL GetQueuedCompletionStatusEx(HANDLE CompletionPort,
234  LPOVERLAPPED_ENTRY lpCompletionPortEntries,
235  ULONG ulCount, PULONG ulNumEntriesRemoved,
236  DWORD dwMilliseconds, BOOL fAlertable);
237 
238  WINPR_API BOOL PostQueuedCompletionStatus(HANDLE CompletionPort,
239  DWORD dwNumberOfBytesTransferred,
240  ULONG_PTR dwCompletionKey, LPOVERLAPPED lpOverlapped);
241 
242  WINPR_API BOOL CancelIo(HANDLE hFile);
243 
244  WINPR_API BOOL CancelSynchronousIo(HANDLE hThread);
245 
246 #ifdef __cplusplus
247 }
248 #endif
249 
250 #endif
251 
256 #define ACCESS_FROM_CTL_CODE(ctrlCode) ((DWORD)((ctrlCode >> 14) & 0x3))
257 #define FUNCTION_FROM_CTL_CODE(ctrlCode) ((DWORD)((ctrlCode >> 2) & 0xFFF))
258 
259 WINPR_PRAGMA_DIAG_POP
260 
261 #endif /* WINPR_IO_H */