]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | //! C definitions used by libnative that don't belong in liblibc |
2 | ||
b7449926 | 3 | #![allow(nonstandard_style)] |
7453a54e | 4 | #![cfg_attr(test, allow(dead_code))] |
dfeec247 | 5 | #![unstable(issue = "none", feature = "windows_c")] |
1a4d82fc | 6 | |
dfeec247 | 7 | use crate::os::raw::{c_char, c_int, c_long, c_longlong, c_uint, c_ulong, c_ushort}; |
532ac7d7 XL |
8 | use crate::ptr; |
9 | ||
dfeec247 | 10 | use libc::{c_void, size_t, wchar_t}; |
9cc50fc6 | 11 | |
92a42be0 | 12 | pub use self::EXCEPTION_DISPOSITION::*; |
dfeec247 | 13 | pub use self::FILE_INFO_BY_HANDLE_CLASS::*; |
85aaf69f | 14 | |
92a42be0 SL |
15 | pub type DWORD = c_ulong; |
16 | pub type HANDLE = LPVOID; | |
17 | pub type HINSTANCE = HANDLE; | |
18 | pub type HMODULE = HINSTANCE; | |
ea8adc8c | 19 | pub type HRESULT = LONG; |
92a42be0 SL |
20 | pub type BOOL = c_int; |
21 | pub type BYTE = u8; | |
22 | pub type BOOLEAN = BYTE; | |
23 | pub type GROUP = c_uint; | |
92a42be0 SL |
24 | pub type LARGE_INTEGER = c_longlong; |
25 | pub type LONG = c_long; | |
26 | pub type UINT = c_uint; | |
27 | pub type WCHAR = u16; | |
28 | pub type USHORT = c_ushort; | |
29 | pub type SIZE_T = usize; | |
30 | pub type WORD = u16; | |
31 | pub type CHAR = c_char; | |
7cac9316 | 32 | pub type ULONG_PTR = usize; |
92a42be0 | 33 | pub type ULONG = c_ulong; |
fc512014 XL |
34 | pub type NTSTATUS = LONG; |
35 | pub type ACCESS_MASK = DWORD; | |
92a42be0 SL |
36 | |
37 | pub type LPBOOL = *mut BOOL; | |
38 | pub type LPBYTE = *mut BYTE; | |
92a42be0 | 39 | pub type LPCSTR = *const CHAR; |
92a42be0 SL |
40 | pub type LPCWSTR = *const WCHAR; |
41 | pub type LPDWORD = *mut DWORD; | |
42 | pub type LPHANDLE = *mut HANDLE; | |
43 | pub type LPOVERLAPPED = *mut OVERLAPPED; | |
44 | pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION; | |
45 | pub type LPSECURITY_ATTRIBUTES = *mut SECURITY_ATTRIBUTES; | |
46 | pub type LPSTARTUPINFO = *mut STARTUPINFO; | |
47 | pub type LPVOID = *mut c_void; | |
48 | pub type LPWCH = *mut WCHAR; | |
49 | pub type LPWIN32_FIND_DATAW = *mut WIN32_FIND_DATAW; | |
50 | pub type LPWSADATA = *mut WSADATA; | |
92a42be0 SL |
51 | pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO; |
52 | pub type LPWSTR = *mut WCHAR; | |
53 | pub type LPFILETIME = *mut FILETIME; | |
9fa01778 XL |
54 | pub type LPWSABUF = *mut WSABUF; |
55 | pub type LPWSAOVERLAPPED = *mut c_void; | |
56 | pub type LPWSAOVERLAPPED_COMPLETION_ROUTINE = *mut c_void; | |
92a42be0 SL |
57 | |
58 | pub type PCONDITION_VARIABLE = *mut CONDITION_VARIABLE; | |
59 | pub type PLARGE_INTEGER = *mut c_longlong; | |
60 | pub type PSRWLOCK = *mut SRWLOCK; | |
61 | ||
532ac7d7 | 62 | pub type SOCKET = crate::os::windows::raw::SOCKET; |
92a42be0 SL |
63 | pub type socklen_t = c_int; |
64 | pub type ADDRESS_FAMILY = USHORT; | |
65 | ||
66 | pub const TRUE: BOOL = 1; | |
67 | pub const FALSE: BOOL = 0; | |
68 | ||
69 | pub const FILE_ATTRIBUTE_READONLY: DWORD = 0x1; | |
70 | pub const FILE_ATTRIBUTE_DIRECTORY: DWORD = 0x10; | |
92a42be0 | 71 | pub const FILE_ATTRIBUTE_REPARSE_POINT: DWORD = 0x400; |
7453a54e | 72 | |
92a42be0 SL |
73 | pub const FILE_SHARE_DELETE: DWORD = 0x4; |
74 | pub const FILE_SHARE_READ: DWORD = 0x1; | |
75 | pub const FILE_SHARE_WRITE: DWORD = 0x2; | |
7453a54e | 76 | |
92a42be0 SL |
77 | pub const CREATE_ALWAYS: DWORD = 2; |
78 | pub const CREATE_NEW: DWORD = 1; | |
79 | pub const OPEN_ALWAYS: DWORD = 4; | |
80 | pub const OPEN_EXISTING: DWORD = 3; | |
81 | pub const TRUNCATE_EXISTING: DWORD = 5; | |
7453a54e | 82 | |
92a42be0 | 83 | pub const FILE_WRITE_DATA: DWORD = 0x00000002; |
7453a54e | 84 | pub const FILE_APPEND_DATA: DWORD = 0x00000004; |
92a42be0 | 85 | pub const FILE_WRITE_EA: DWORD = 0x00000010; |
92a42be0 | 86 | pub const FILE_WRITE_ATTRIBUTES: DWORD = 0x00000100; |
7453a54e SL |
87 | pub const READ_CONTROL: DWORD = 0x00020000; |
88 | pub const SYNCHRONIZE: DWORD = 0x00100000; | |
89 | pub const GENERIC_READ: DWORD = 0x80000000; | |
90 | pub const GENERIC_WRITE: DWORD = 0x40000000; | |
91 | pub const STANDARD_RIGHTS_WRITE: DWORD = READ_CONTROL; | |
dfeec247 XL |
92 | pub const FILE_GENERIC_WRITE: DWORD = STANDARD_RIGHTS_WRITE |
93 | | FILE_WRITE_DATA | |
94 | | FILE_WRITE_ATTRIBUTES | |
95 | | FILE_WRITE_EA | |
96 | | FILE_APPEND_DATA | |
97 | | SYNCHRONIZE; | |
92a42be0 | 98 | |
7453a54e SL |
99 | pub const FILE_FLAG_OPEN_REPARSE_POINT: DWORD = 0x00200000; |
100 | pub const FILE_FLAG_BACKUP_SEMANTICS: DWORD = 0x02000000; | |
101 | pub const SECURITY_SQOS_PRESENT: DWORD = 0x00100000; | |
102 | ||
54a0048b SL |
103 | pub const FIONBIO: c_ulong = 0x8004667e; |
104 | ||
92a42be0 SL |
105 | #[repr(C)] |
106 | #[derive(Copy)] | |
107 | pub struct WIN32_FIND_DATAW { | |
108 | pub dwFileAttributes: DWORD, | |
109 | pub ftCreationTime: FILETIME, | |
110 | pub ftLastAccessTime: FILETIME, | |
111 | pub ftLastWriteTime: FILETIME, | |
112 | pub nFileSizeHigh: DWORD, | |
113 | pub nFileSizeLow: DWORD, | |
114 | pub dwReserved0: DWORD, | |
115 | pub dwReserved1: DWORD, | |
116 | pub cFileName: [wchar_t; 260], // #define MAX_PATH 260 | |
117 | pub cAlternateFileName: [wchar_t; 14], | |
118 | } | |
119 | impl Clone for WIN32_FIND_DATAW { | |
dfeec247 XL |
120 | fn clone(&self) -> Self { |
121 | *self | |
122 | } | |
92a42be0 SL |
123 | } |
124 | ||
92a42be0 | 125 | pub const WSA_FLAG_OVERLAPPED: DWORD = 0x01; |
416331ca | 126 | pub const WSA_FLAG_NO_HANDLE_INHERIT: DWORD = 0x80; |
92a42be0 SL |
127 | |
128 | pub const WSADESCRIPTION_LEN: usize = 256; | |
129 | pub const WSASYS_STATUS_LEN: usize = 128; | |
130 | pub const WSAPROTOCOL_LEN: DWORD = 255; | |
131 | pub const INVALID_SOCKET: SOCKET = !0; | |
132 | ||
92a42be0 | 133 | pub const WSAEACCES: c_int = 10013; |
92a42be0 | 134 | pub const WSAEINVAL: c_int = 10022; |
92a42be0 | 135 | pub const WSAEWOULDBLOCK: c_int = 10035; |
416331ca | 136 | pub const WSAEPROTOTYPE: c_int = 10041; |
92a42be0 SL |
137 | pub const WSAEADDRINUSE: c_int = 10048; |
138 | pub const WSAEADDRNOTAVAIL: c_int = 10049; | |
92a42be0 SL |
139 | pub const WSAECONNABORTED: c_int = 10053; |
140 | pub const WSAECONNRESET: c_int = 10054; | |
92a42be0 SL |
141 | pub const WSAENOTCONN: c_int = 10057; |
142 | pub const WSAESHUTDOWN: c_int = 10058; | |
92a42be0 SL |
143 | pub const WSAETIMEDOUT: c_int = 10060; |
144 | pub const WSAECONNREFUSED: c_int = 10061; | |
7453a54e | 145 | |
92a42be0 SL |
146 | pub const MAX_PROTOCOL_CHAIN: DWORD = 7; |
147 | ||
9346a6ac | 148 | pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024; |
92a42be0 SL |
149 | pub const FSCTL_GET_REPARSE_POINT: DWORD = 0x900a8; |
150 | pub const IO_REPARSE_TAG_SYMLINK: DWORD = 0xa000000c; | |
151 | pub const IO_REPARSE_TAG_MOUNT_POINT: DWORD = 0xa0000003; | |
7453a54e | 152 | pub const SYMLINK_FLAG_RELATIVE: DWORD = 0x00000001; |
92a42be0 | 153 | pub const FSCTL_SET_REPARSE_POINT: DWORD = 0x900a4; |
1a4d82fc | 154 | |
92a42be0 | 155 | pub const SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 0x1; |
8bb4bdeb | 156 | pub const SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE: DWORD = 0x2; |
d9579d0f | 157 | |
c34b1796 | 158 | // Note that these are not actually HANDLEs, just values to pass to GetStdHandle |
92a42be0 SL |
159 | pub const STD_INPUT_HANDLE: DWORD = -10i32 as DWORD; |
160 | pub const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD; | |
161 | pub const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD; | |
162 | ||
92a42be0 | 163 | pub const PROGRESS_CONTINUE: DWORD = 0; |
92a42be0 | 164 | |
f035d41b XL |
165 | // List of Windows system error codes with descriptions: |
166 | // https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes#system-error-codes | |
92a42be0 SL |
167 | pub const ERROR_FILE_NOT_FOUND: DWORD = 2; |
168 | pub const ERROR_PATH_NOT_FOUND: DWORD = 3; | |
169 | pub const ERROR_ACCESS_DENIED: DWORD = 5; | |
170 | pub const ERROR_INVALID_HANDLE: DWORD = 6; | |
171 | pub const ERROR_NO_MORE_FILES: DWORD = 18; | |
54a0048b | 172 | pub const ERROR_HANDLE_EOF: DWORD = 38; |
3157f602 | 173 | pub const ERROR_FILE_EXISTS: DWORD = 80; |
476ff2be | 174 | pub const ERROR_INVALID_PARAMETER: DWORD = 87; |
92a42be0 | 175 | pub const ERROR_BROKEN_PIPE: DWORD = 109; |
92a42be0 | 176 | pub const ERROR_CALL_NOT_IMPLEMENTED: DWORD = 120; |
f035d41b | 177 | pub const ERROR_SEM_TIMEOUT: DWORD = 121; |
92a42be0 | 178 | pub const ERROR_INSUFFICIENT_BUFFER: DWORD = 122; |
92a42be0 | 179 | pub const ERROR_ALREADY_EXISTS: DWORD = 183; |
92a42be0 | 180 | pub const ERROR_ENVVAR_NOT_FOUND: DWORD = 203; |
f035d41b XL |
181 | pub const ERROR_NO_DATA: DWORD = 232; |
182 | pub const ERROR_DRIVER_CANCEL_TIMEOUT: DWORD = 594; | |
92a42be0 | 183 | pub const ERROR_OPERATION_ABORTED: DWORD = 995; |
54a0048b | 184 | pub const ERROR_IO_PENDING: DWORD = 997; |
f035d41b XL |
185 | pub const ERROR_SERVICE_REQUEST_TIMEOUT: DWORD = 1053; |
186 | pub const ERROR_COUNTER_TIMEOUT: DWORD = 1121; | |
187 | pub const ERROR_TIMEOUT: DWORD = 1460; | |
188 | pub const ERROR_RESOURCE_CALL_TIMED_OUT: DWORD = 5910; | |
189 | pub const ERROR_CTX_MODEM_RESPONSE_TIMEOUT: DWORD = 7012; | |
190 | pub const ERROR_CTX_CLIENT_QUERY_TIMEOUT: DWORD = 7040; | |
191 | pub const FRS_ERR_SYSVOL_POPULATE_TIMEOUT: DWORD = 8014; | |
192 | pub const ERROR_DS_TIMELIMIT_EXCEEDED: DWORD = 8226; | |
193 | pub const DNS_ERROR_RECORD_TIMED_OUT: DWORD = 9705; | |
194 | pub const ERROR_IPSEC_IKE_TIMED_OUT: DWORD = 13805; | |
195 | pub const ERROR_RUNLEVEL_SWITCH_TIMEOUT: DWORD = 15402; | |
196 | pub const ERROR_RUNLEVEL_SWITCH_AGENT_TIMEOUT: DWORD = 15403; | |
92a42be0 | 197 | |
ea8adc8c XL |
198 | pub const E_NOTIMPL: HRESULT = 0x80004001u32 as HRESULT; |
199 | ||
92a42be0 SL |
200 | pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE; |
201 | ||
7cac9316 XL |
202 | pub const FACILITY_NT_BIT: DWORD = 0x1000_0000; |
203 | ||
92a42be0 | 204 | pub const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000; |
7cac9316 | 205 | pub const FORMAT_MESSAGE_FROM_HMODULE: DWORD = 0x00000800; |
92a42be0 SL |
206 | pub const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200; |
207 | ||
208 | pub const TLS_OUT_OF_INDEXES: DWORD = 0xFFFFFFFF; | |
209 | ||
210 | pub const DLL_THREAD_DETACH: DWORD = 3; | |
211 | pub const DLL_PROCESS_DETACH: DWORD = 0; | |
212 | ||
213 | pub const INFINITE: DWORD = !0; | |
214 | ||
215 | pub const DUPLICATE_SAME_ACCESS: DWORD = 0x00000002; | |
216 | ||
dfeec247 | 217 | pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE { ptr: ptr::null_mut() }; |
92a42be0 | 218 | pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: ptr::null_mut() }; |
c1a9b12d | 219 | |
92a42be0 SL |
220 | pub const DETACHED_PROCESS: DWORD = 0x00000008; |
221 | pub const CREATE_NEW_PROCESS_GROUP: DWORD = 0x00000200; | |
222 | pub const CREATE_UNICODE_ENVIRONMENT: DWORD = 0x00000400; | |
223 | pub const STARTF_USESTDHANDLES: DWORD = 0x00000100; | |
224 | ||
225 | pub const AF_INET: c_int = 2; | |
226 | pub const AF_INET6: c_int = 23; | |
227 | pub const SD_BOTH: c_int = 2; | |
228 | pub const SD_RECEIVE: c_int = 0; | |
229 | pub const SD_SEND: c_int = 1; | |
230 | pub const SOCK_DGRAM: c_int = 2; | |
231 | pub const SOCK_STREAM: c_int = 1; | |
232 | pub const SOL_SOCKET: c_int = 0xffff; | |
233 | pub const SO_RCVTIMEO: c_int = 0x1006; | |
234 | pub const SO_SNDTIMEO: c_int = 0x1005; | |
54a0048b SL |
235 | pub const IPPROTO_IP: c_int = 0; |
236 | pub const IPPROTO_TCP: c_int = 6; | |
237 | pub const IPPROTO_IPV6: c_int = 41; | |
238 | pub const TCP_NODELAY: c_int = 0x0001; | |
239 | pub const IP_TTL: c_int = 4; | |
240 | pub const IPV6_V6ONLY: c_int = 27; | |
241 | pub const SO_ERROR: c_int = 0x1007; | |
242 | pub const SO_BROADCAST: c_int = 0x0020; | |
243 | pub const IP_MULTICAST_LOOP: c_int = 11; | |
244 | pub const IPV6_MULTICAST_LOOP: c_int = 11; | |
245 | pub const IP_MULTICAST_TTL: c_int = 10; | |
246 | pub const IP_ADD_MEMBERSHIP: c_int = 12; | |
247 | pub const IP_DROP_MEMBERSHIP: c_int = 13; | |
248 | pub const IPV6_ADD_MEMBERSHIP: c_int = 12; | |
249 | pub const IPV6_DROP_MEMBERSHIP: c_int = 13; | |
8bb4bdeb | 250 | pub const MSG_PEEK: c_int = 0x2; |
54a0048b SL |
251 | |
252 | #[repr(C)] | |
253 | pub struct ip_mreq { | |
254 | pub imr_multiaddr: in_addr, | |
255 | pub imr_interface: in_addr, | |
256 | } | |
257 | ||
258 | #[repr(C)] | |
259 | pub struct ipv6_mreq { | |
260 | pub ipv6mr_multiaddr: in6_addr, | |
261 | pub ipv6mr_interface: c_uint, | |
262 | } | |
92a42be0 SL |
263 | |
264 | pub const VOLUME_NAME_DOS: DWORD = 0x0; | |
265 | pub const MOVEFILE_REPLACE_EXISTING: DWORD = 1; | |
266 | ||
267 | pub const FILE_BEGIN: DWORD = 0; | |
268 | pub const FILE_CURRENT: DWORD = 1; | |
269 | pub const FILE_END: DWORD = 2; | |
270 | ||
92a42be0 | 271 | pub const WAIT_OBJECT_0: DWORD = 0x00000000; |
32a655c1 | 272 | pub const WAIT_TIMEOUT: DWORD = 258; |
3b2f2976 | 273 | pub const WAIT_FAILED: DWORD = 0xFFFFFFFF; |
92a42be0 | 274 | |
54a0048b | 275 | pub const PIPE_ACCESS_INBOUND: DWORD = 0x00000001; |
476ff2be | 276 | pub const PIPE_ACCESS_OUTBOUND: DWORD = 0x00000002; |
54a0048b SL |
277 | pub const FILE_FLAG_FIRST_PIPE_INSTANCE: DWORD = 0x00080000; |
278 | pub const FILE_FLAG_OVERLAPPED: DWORD = 0x40000000; | |
279 | pub const PIPE_WAIT: DWORD = 0x00000000; | |
280 | pub const PIPE_TYPE_BYTE: DWORD = 0x00000000; | |
281 | pub const PIPE_REJECT_REMOTE_CLIENTS: DWORD = 0x00000008; | |
282 | pub const PIPE_READMODE_BYTE: DWORD = 0x00000000; | |
283 | ||
041b39d2 XL |
284 | pub const FD_SETSIZE: usize = 64; |
285 | ||
b7449926 XL |
286 | pub const STACK_SIZE_PARAM_IS_A_RESERVATION: DWORD = 0x00010000; |
287 | ||
a1dfa0c6 XL |
288 | pub const HEAP_ZERO_MEMORY: DWORD = 0x00000008; |
289 | ||
fc512014 XL |
290 | pub const STATUS_SUCCESS: NTSTATUS = 0x00000000; |
291 | ||
1a4d82fc | 292 | #[repr(C)] |
3b2f2976 | 293 | #[cfg(not(target_pointer_width = "64"))] |
1a4d82fc | 294 | pub struct WSADATA { |
92a42be0 SL |
295 | pub wVersion: WORD, |
296 | pub wHighVersion: WORD, | |
1a4d82fc JJ |
297 | pub szDescription: [u8; WSADESCRIPTION_LEN + 1], |
298 | pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1], | |
299 | pub iMaxSockets: u16, | |
300 | pub iMaxUdpDg: u16, | |
301 | pub lpVendorInfo: *mut u8, | |
302 | } | |
303 | #[repr(C)] | |
3b2f2976 | 304 | #[cfg(target_pointer_width = "64")] |
1a4d82fc | 305 | pub struct WSADATA { |
92a42be0 SL |
306 | pub wVersion: WORD, |
307 | pub wHighVersion: WORD, | |
1a4d82fc JJ |
308 | pub iMaxSockets: u16, |
309 | pub iMaxUdpDg: u16, | |
310 | pub lpVendorInfo: *mut u8, | |
311 | pub szDescription: [u8; WSADESCRIPTION_LEN + 1], | |
312 | pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1], | |
313 | } | |
314 | ||
ba9703b0 | 315 | #[derive(Copy, Clone)] |
9fa01778 XL |
316 | #[repr(C)] |
317 | pub struct WSABUF { | |
318 | pub len: ULONG, | |
319 | pub buf: *mut CHAR, | |
320 | } | |
321 | ||
85aaf69f | 322 | #[repr(C)] |
85aaf69f | 323 | pub struct WSAPROTOCOL_INFO { |
92a42be0 SL |
324 | pub dwServiceFlags1: DWORD, |
325 | pub dwServiceFlags2: DWORD, | |
326 | pub dwServiceFlags3: DWORD, | |
327 | pub dwServiceFlags4: DWORD, | |
328 | pub dwProviderFlags: DWORD, | |
85aaf69f | 329 | pub ProviderId: GUID, |
92a42be0 | 330 | pub dwCatalogEntryId: DWORD, |
85aaf69f | 331 | pub ProtocolChain: WSAPROTOCOLCHAIN, |
92a42be0 SL |
332 | pub iVersion: c_int, |
333 | pub iAddressFamily: c_int, | |
334 | pub iMaxSockAddr: c_int, | |
335 | pub iMinSockAddr: c_int, | |
336 | pub iSocketType: c_int, | |
337 | pub iProtocol: c_int, | |
338 | pub iProtocolMaxOffset: c_int, | |
339 | pub iNetworkByteOrder: c_int, | |
340 | pub iSecurityScheme: c_int, | |
341 | pub dwMessageSize: DWORD, | |
342 | pub dwProviderReserved: DWORD, | |
85aaf69f SL |
343 | pub szProtocol: [u16; (WSAPROTOCOL_LEN as usize) + 1], |
344 | } | |
345 | ||
85aaf69f | 346 | #[repr(C)] |
92a42be0 | 347 | #[derive(Copy, Clone)] |
85aaf69f | 348 | pub struct WIN32_FILE_ATTRIBUTE_DATA { |
92a42be0 SL |
349 | pub dwFileAttributes: DWORD, |
350 | pub ftCreationTime: FILETIME, | |
351 | pub ftLastAccessTime: FILETIME, | |
352 | pub ftLastWriteTime: FILETIME, | |
353 | pub nFileSizeHigh: DWORD, | |
354 | pub nFileSizeLow: DWORD, | |
85aaf69f SL |
355 | } |
356 | ||
85aaf69f | 357 | #[repr(C)] |
7453a54e | 358 | #[allow(dead_code)] // we only use some variants |
85aaf69f | 359 | pub enum FILE_INFO_BY_HANDLE_CLASS { |
dfeec247 XL |
360 | FileBasicInfo = 0, |
361 | FileStandardInfo = 1, | |
362 | FileNameInfo = 2, | |
363 | FileRenameInfo = 3, | |
364 | FileDispositionInfo = 4, | |
365 | FileAllocationInfo = 5, | |
366 | FileEndOfFileInfo = 6, | |
367 | FileStreamInfo = 7, | |
368 | FileCompressionInfo = 8, | |
369 | FileAttributeTagInfo = 9, | |
370 | FileIdBothDirectoryInfo = 10, // 0xA | |
371 | FileIdBothDirectoryRestartInfo = 11, // 0xB | |
372 | FileIoPriorityHintInfo = 12, // 0xC | |
373 | FileRemoteProtocolInfo = 13, // 0xD | |
374 | FileFullDirectoryInfo = 14, // 0xE | |
375 | FileFullDirectoryRestartInfo = 15, // 0xF | |
376 | FileStorageInfo = 16, // 0x10 | |
377 | FileAlignmentInfo = 17, // 0x11 | |
378 | FileIdInfo = 18, // 0x12 | |
379 | FileIdExtdDirectoryInfo = 19, // 0x13 | |
380 | FileIdExtdDirectoryRestartInfo = 20, // 0x14 | |
381 | MaximumFileInfoByHandlesClass, | |
85aaf69f SL |
382 | } |
383 | ||
476ff2be SL |
384 | #[repr(C)] |
385 | pub struct FILE_BASIC_INFO { | |
386 | pub CreationTime: LARGE_INTEGER, | |
387 | pub LastAccessTime: LARGE_INTEGER, | |
388 | pub LastWriteTime: LARGE_INTEGER, | |
389 | pub ChangeTime: LARGE_INTEGER, | |
390 | pub FileAttributes: DWORD, | |
391 | } | |
392 | ||
85aaf69f SL |
393 | #[repr(C)] |
394 | pub struct FILE_END_OF_FILE_INFO { | |
92a42be0 | 395 | pub EndOfFile: LARGE_INTEGER, |
85aaf69f SL |
396 | } |
397 | ||
9346a6ac AL |
398 | #[repr(C)] |
399 | pub struct REPARSE_DATA_BUFFER { | |
92a42be0 SL |
400 | pub ReparseTag: c_uint, |
401 | pub ReparseDataLength: c_ushort, | |
402 | pub Reserved: c_ushort, | |
9346a6ac AL |
403 | pub rest: (), |
404 | } | |
405 | ||
406 | #[repr(C)] | |
407 | pub struct SYMBOLIC_LINK_REPARSE_BUFFER { | |
92a42be0 SL |
408 | pub SubstituteNameOffset: c_ushort, |
409 | pub SubstituteNameLength: c_ushort, | |
410 | pub PrintNameOffset: c_ushort, | |
411 | pub PrintNameLength: c_ushort, | |
412 | pub Flags: c_ulong, | |
413 | pub PathBuffer: WCHAR, | |
9346a6ac AL |
414 | } |
415 | ||
7453a54e SL |
416 | #[repr(C)] |
417 | pub struct MOUNT_POINT_REPARSE_BUFFER { | |
418 | pub SubstituteNameOffset: c_ushort, | |
419 | pub SubstituteNameLength: c_ushort, | |
420 | pub PrintNameOffset: c_ushort, | |
421 | pub PrintNameLength: c_ushort, | |
422 | pub PathBuffer: WCHAR, | |
423 | } | |
424 | ||
dfeec247 XL |
425 | pub type LPPROGRESS_ROUTINE = crate::option::Option< |
426 | unsafe extern "system" fn( | |
427 | TotalFileSize: LARGE_INTEGER, | |
428 | TotalBytesTransferred: LARGE_INTEGER, | |
429 | StreamSize: LARGE_INTEGER, | |
430 | StreamBytesTransferred: LARGE_INTEGER, | |
431 | dwStreamNumber: DWORD, | |
432 | dwCallbackReason: DWORD, | |
433 | hSourceFile: HANDLE, | |
434 | hDestinationFile: HANDLE, | |
435 | lpData: LPVOID, | |
436 | ) -> DWORD, | |
437 | >; | |
c1a9b12d SL |
438 | |
439 | #[repr(C)] | |
dfeec247 XL |
440 | pub struct CONDITION_VARIABLE { |
441 | pub ptr: LPVOID, | |
442 | } | |
c1a9b12d | 443 | #[repr(C)] |
dfeec247 XL |
444 | pub struct SRWLOCK { |
445 | pub ptr: LPVOID, | |
446 | } | |
c1a9b12d SL |
447 | #[repr(C)] |
448 | pub struct CRITICAL_SECTION { | |
449 | CriticalSectionDebug: LPVOID, | |
450 | LockCount: LONG, | |
451 | RecursionCount: LONG, | |
452 | OwningThread: HANDLE, | |
453 | LockSemaphore: HANDLE, | |
dfeec247 | 454 | SpinCount: ULONG_PTR, |
c1a9b12d SL |
455 | } |
456 | ||
c1a9b12d SL |
457 | #[repr(C)] |
458 | pub struct REPARSE_MOUNTPOINT_DATA_BUFFER { | |
92a42be0 SL |
459 | pub ReparseTag: DWORD, |
460 | pub ReparseDataLength: DWORD, | |
461 | pub Reserved: WORD, | |
462 | pub ReparseTargetLength: WORD, | |
463 | pub ReparseTargetMaximumLength: WORD, | |
464 | pub Reserved1: WORD, | |
465 | pub ReparseTarget: WCHAR, | |
c1a9b12d SL |
466 | } |
467 | ||
92a42be0 SL |
468 | #[repr(C)] |
469 | pub struct GUID { | |
470 | pub Data1: DWORD, | |
471 | pub Data2: WORD, | |
472 | pub Data3: WORD, | |
473 | pub Data4: [BYTE; 8], | |
474 | } | |
475 | ||
476 | #[repr(C)] | |
477 | pub struct WSAPROTOCOLCHAIN { | |
478 | pub ChainLen: c_int, | |
479 | pub ChainEntries: [DWORD; MAX_PROTOCOL_CHAIN as usize], | |
480 | } | |
481 | ||
482 | #[repr(C)] | |
483 | pub struct SECURITY_ATTRIBUTES { | |
484 | pub nLength: DWORD, | |
485 | pub lpSecurityDescriptor: LPVOID, | |
486 | pub bInheritHandle: BOOL, | |
487 | } | |
488 | ||
489 | #[repr(C)] | |
490 | pub struct PROCESS_INFORMATION { | |
491 | pub hProcess: HANDLE, | |
492 | pub hThread: HANDLE, | |
493 | pub dwProcessId: DWORD, | |
494 | pub dwThreadId: DWORD, | |
495 | } | |
496 | ||
497 | #[repr(C)] | |
498 | pub struct STARTUPINFO { | |
499 | pub cb: DWORD, | |
500 | pub lpReserved: LPWSTR, | |
501 | pub lpDesktop: LPWSTR, | |
502 | pub lpTitle: LPWSTR, | |
503 | pub dwX: DWORD, | |
504 | pub dwY: DWORD, | |
505 | pub dwXSize: DWORD, | |
506 | pub dwYSize: DWORD, | |
507 | pub dwXCountChars: DWORD, | |
508 | pub dwYCountCharts: DWORD, | |
509 | pub dwFillAttribute: DWORD, | |
510 | pub dwFlags: DWORD, | |
511 | pub wShowWindow: WORD, | |
512 | pub cbReserved2: WORD, | |
513 | pub lpReserved2: LPBYTE, | |
514 | pub hStdInput: HANDLE, | |
515 | pub hStdOutput: HANDLE, | |
516 | pub hStdError: HANDLE, | |
517 | } | |
518 | ||
519 | #[repr(C)] | |
520 | pub struct SOCKADDR { | |
521 | pub sa_family: ADDRESS_FAMILY, | |
522 | pub sa_data: [CHAR; 14], | |
523 | } | |
524 | ||
525 | #[repr(C)] | |
526 | #[derive(Copy, Clone)] | |
527 | pub struct FILETIME { | |
528 | pub dwLowDateTime: DWORD, | |
529 | pub dwHighDateTime: DWORD, | |
530 | } | |
531 | ||
532 | #[repr(C)] | |
533 | pub struct OVERLAPPED { | |
534 | pub Internal: *mut c_ulong, | |
535 | pub InternalHigh: *mut c_ulong, | |
536 | pub Offset: DWORD, | |
537 | pub OffsetHigh: DWORD, | |
538 | pub hEvent: HANDLE, | |
539 | } | |
540 | ||
92a42be0 | 541 | #[repr(C)] |
7453a54e | 542 | #[allow(dead_code)] // we only use some variants |
92a42be0 SL |
543 | pub enum ADDRESS_MODE { |
544 | AddrMode1616, | |
545 | AddrMode1632, | |
546 | AddrModeReal, | |
547 | AddrModeFlat, | |
548 | } | |
549 | ||
92a42be0 SL |
550 | #[repr(C)] |
551 | pub struct SOCKADDR_STORAGE_LH { | |
552 | pub ss_family: ADDRESS_FAMILY, | |
553 | pub __ss_pad1: [CHAR; 6], | |
554 | pub __ss_align: i64, | |
555 | pub __ss_pad2: [CHAR; 112], | |
556 | } | |
557 | ||
558 | #[repr(C)] | |
559 | pub struct ADDRINFOA { | |
560 | pub ai_flags: c_int, | |
561 | pub ai_family: c_int, | |
562 | pub ai_socktype: c_int, | |
563 | pub ai_protocol: c_int, | |
564 | pub ai_addrlen: size_t, | |
565 | pub ai_canonname: *mut c_char, | |
566 | pub ai_addr: *mut SOCKADDR, | |
567 | pub ai_next: *mut ADDRINFOA, | |
568 | } | |
569 | ||
570 | #[repr(C)] | |
571 | #[derive(Copy, Clone)] | |
572 | pub struct sockaddr_in { | |
573 | pub sin_family: ADDRESS_FAMILY, | |
574 | pub sin_port: USHORT, | |
575 | pub sin_addr: in_addr, | |
576 | pub sin_zero: [CHAR; 8], | |
577 | } | |
578 | ||
579 | #[repr(C)] | |
580 | #[derive(Copy, Clone)] | |
581 | pub struct sockaddr_in6 { | |
582 | pub sin6_family: ADDRESS_FAMILY, | |
583 | pub sin6_port: USHORT, | |
584 | pub sin6_flowinfo: c_ulong, | |
585 | pub sin6_addr: in6_addr, | |
586 | pub sin6_scope_id: c_ulong, | |
587 | } | |
588 | ||
589 | #[repr(C)] | |
590 | #[derive(Copy, Clone)] | |
591 | pub struct in_addr { | |
592 | pub s_addr: u32, | |
593 | } | |
594 | ||
595 | #[repr(C)] | |
596 | #[derive(Copy, Clone)] | |
597 | pub struct in6_addr { | |
598 | pub s6_addr: [u8; 16], | |
599 | } | |
600 | ||
92a42be0 SL |
601 | #[repr(C)] |
602 | #[derive(Copy, Clone)] | |
7453a54e | 603 | #[allow(dead_code)] // we only use some variants |
92a42be0 SL |
604 | pub enum EXCEPTION_DISPOSITION { |
605 | ExceptionContinueExecution, | |
606 | ExceptionContinueSearch, | |
607 | ExceptionNestedException, | |
dfeec247 | 608 | ExceptionCollidedUnwind, |
92a42be0 SL |
609 | } |
610 | ||
041b39d2 XL |
611 | #[repr(C)] |
612 | #[derive(Copy)] | |
613 | pub struct fd_set { | |
614 | pub fd_count: c_uint, | |
615 | pub fd_array: [SOCKET; FD_SETSIZE], | |
616 | } | |
617 | ||
618 | impl Clone for fd_set { | |
619 | fn clone(&self) -> fd_set { | |
620 | *self | |
621 | } | |
622 | } | |
623 | ||
624 | #[repr(C)] | |
625 | #[derive(Copy, Clone)] | |
626 | pub struct timeval { | |
627 | pub tv_sec: c_long, | |
628 | pub tv_usec: c_long, | |
629 | } | |
630 | ||
416331ca XL |
631 | // Functions forbidden when targeting UWP |
632 | cfg_if::cfg_if! { | |
633 | if #[cfg(not(target_vendor = "uwp"))] { | |
634 | pub const EXCEPTION_CONTINUE_SEARCH: LONG = 0; | |
635 | pub const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd; | |
636 | pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15; | |
637 | ||
638 | #[repr(C)] | |
639 | pub struct EXCEPTION_RECORD { | |
640 | pub ExceptionCode: DWORD, | |
641 | pub ExceptionFlags: DWORD, | |
642 | pub ExceptionRecord: *mut EXCEPTION_RECORD, | |
643 | pub ExceptionAddress: LPVOID, | |
644 | pub NumberParameters: DWORD, | |
645 | pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS] | |
646 | } | |
647 | ||
648 | pub enum CONTEXT {} | |
649 | ||
650 | #[repr(C)] | |
651 | pub struct EXCEPTION_POINTERS { | |
652 | pub ExceptionRecord: *mut EXCEPTION_RECORD, | |
653 | pub ContextRecord: *mut CONTEXT, | |
654 | } | |
655 | ||
656 | pub type PVECTORED_EXCEPTION_HANDLER = extern "system" | |
657 | fn(ExceptionInfo: *mut EXCEPTION_POINTERS) -> LONG; | |
658 | ||
659 | #[repr(C)] | |
660 | #[derive(Copy, Clone)] | |
661 | pub struct CONSOLE_READCONSOLE_CONTROL { | |
662 | pub nLength: ULONG, | |
663 | pub nInitialChars: ULONG, | |
664 | pub dwCtrlWakeupMask: ULONG, | |
665 | pub dwControlKeyState: ULONG, | |
666 | } | |
667 | ||
668 | pub type PCONSOLE_READCONSOLE_CONTROL = *mut CONSOLE_READCONSOLE_CONTROL; | |
669 | ||
670 | #[repr(C)] | |
671 | pub struct BY_HANDLE_FILE_INFORMATION { | |
672 | pub dwFileAttributes: DWORD, | |
673 | pub ftCreationTime: FILETIME, | |
674 | pub ftLastAccessTime: FILETIME, | |
675 | pub ftLastWriteTime: FILETIME, | |
676 | pub dwVolumeSerialNumber: DWORD, | |
677 | pub nFileSizeHigh: DWORD, | |
678 | pub nFileSizeLow: DWORD, | |
679 | pub nNumberOfLinks: DWORD, | |
680 | pub nFileIndexHigh: DWORD, | |
681 | pub nFileIndexLow: DWORD, | |
682 | } | |
683 | ||
684 | pub type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION; | |
685 | pub type LPCVOID = *const c_void; | |
686 | ||
687 | pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001; | |
688 | ||
689 | pub const TOKEN_READ: DWORD = 0x20008; | |
690 | ||
691 | extern "system" { | |
692 | #[link_name = "SystemFunction036"] | |
693 | pub fn RtlGenRandom(RandomBuffer: *mut u8, RandomBufferLength: ULONG) -> BOOLEAN; | |
694 | ||
695 | pub fn ReadConsoleW(hConsoleInput: HANDLE, | |
696 | lpBuffer: LPVOID, | |
697 | nNumberOfCharsToRead: DWORD, | |
698 | lpNumberOfCharsRead: LPDWORD, | |
699 | pInputControl: PCONSOLE_READCONSOLE_CONTROL) -> BOOL; | |
700 | ||
701 | pub fn WriteConsoleW(hConsoleOutput: HANDLE, | |
702 | lpBuffer: LPCVOID, | |
703 | nNumberOfCharsToWrite: DWORD, | |
704 | lpNumberOfCharsWritten: LPDWORD, | |
705 | lpReserved: LPVOID) -> BOOL; | |
706 | ||
707 | pub fn GetConsoleMode(hConsoleHandle: HANDLE, | |
708 | lpMode: LPDWORD) -> BOOL; | |
709 | // Allowed but unused by UWP | |
710 | pub fn OpenProcessToken(ProcessHandle: HANDLE, | |
711 | DesiredAccess: DWORD, | |
712 | TokenHandle: *mut HANDLE) -> BOOL; | |
713 | pub fn GetUserProfileDirectoryW(hToken: HANDLE, | |
714 | lpProfileDir: LPWSTR, | |
715 | lpcchSize: *mut DWORD) -> BOOL; | |
716 | pub fn GetFileInformationByHandle(hFile: HANDLE, | |
717 | lpFileInformation: LPBY_HANDLE_FILE_INFORMATION) | |
718 | -> BOOL; | |
719 | pub fn SetHandleInformation(hObject: HANDLE, | |
720 | dwMask: DWORD, | |
721 | dwFlags: DWORD) -> BOOL; | |
722 | pub fn AddVectoredExceptionHandler(FirstHandler: ULONG, | |
723 | VectoredHandler: PVECTORED_EXCEPTION_HANDLER) | |
724 | -> LPVOID; | |
725 | pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR, | |
726 | lpTargetFileName: LPCWSTR, | |
727 | lpSecurityAttributes: LPSECURITY_ATTRIBUTES) | |
728 | -> BOOL; | |
729 | } | |
730 | } | |
731 | } | |
732 | ||
733 | // UWP specific functions & types | |
734 | cfg_if::cfg_if! { | |
735 | if #[cfg(target_vendor = "uwp")] { | |
736 | pub const BCRYPT_USE_SYSTEM_PREFERRED_RNG: DWORD = 0x00000002; | |
737 | ||
738 | #[repr(C)] | |
739 | pub struct FILE_STANDARD_INFO { | |
740 | pub AllocationSize: LARGE_INTEGER, | |
741 | pub EndOfFile: LARGE_INTEGER, | |
e1599b0c | 742 | pub NumberOfLinks: DWORD, |
416331ca XL |
743 | pub DeletePending: BOOLEAN, |
744 | pub Directory: BOOLEAN, | |
745 | } | |
746 | ||
747 | extern "system" { | |
748 | pub fn GetFileInformationByHandleEx(hFile: HANDLE, | |
749 | fileInfoClass: FILE_INFO_BY_HANDLE_CLASS, | |
750 | lpFileInformation: LPVOID, | |
751 | dwBufferSize: DWORD) -> BOOL; | |
752 | pub fn BCryptGenRandom(hAlgorithm: LPVOID, pBuffer: *mut u8, | |
753 | cbBuffer: ULONG, dwFlags: ULONG) -> LONG; | |
754 | } | |
755 | } | |
756 | } | |
757 | ||
758 | // Shared between Desktop & UWP | |
1a4d82fc | 759 | extern "system" { |
dfeec247 | 760 | pub fn WSAStartup(wVersionRequested: WORD, lpWSAData: LPWSADATA) -> c_int; |
92a42be0 SL |
761 | pub fn WSACleanup() -> c_int; |
762 | pub fn WSAGetLastError() -> c_int; | |
dfeec247 XL |
763 | pub fn WSADuplicateSocketW( |
764 | s: SOCKET, | |
765 | dwProcessId: DWORD, | |
766 | lpProtocolInfo: LPWSAPROTOCOL_INFO, | |
767 | ) -> c_int; | |
768 | pub fn WSASend( | |
769 | s: SOCKET, | |
770 | lpBuffers: LPWSABUF, | |
771 | dwBufferCount: DWORD, | |
772 | lpNumberOfBytesSent: LPDWORD, | |
773 | dwFlags: DWORD, | |
774 | lpOverlapped: LPWSAOVERLAPPED, | |
775 | lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE, | |
776 | ) -> c_int; | |
777 | pub fn WSARecv( | |
778 | s: SOCKET, | |
779 | lpBuffers: LPWSABUF, | |
780 | dwBufferCount: DWORD, | |
781 | lpNumberOfBytesRecvd: LPDWORD, | |
782 | lpFlags: LPDWORD, | |
783 | lpOverlapped: LPWSAOVERLAPPED, | |
784 | lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE, | |
785 | ) -> c_int; | |
92a42be0 | 786 | pub fn GetCurrentProcessId() -> DWORD; |
dfeec247 XL |
787 | pub fn WSASocketW( |
788 | af: c_int, | |
789 | kind: c_int, | |
790 | protocol: c_int, | |
791 | lpProtocolInfo: LPWSAPROTOCOL_INFO, | |
792 | g: GROUP, | |
793 | dwFlags: DWORD, | |
794 | ) -> SOCKET; | |
54a0048b | 795 | pub fn ioctlsocket(s: SOCKET, cmd: c_long, argp: *mut c_ulong) -> c_int; |
c1a9b12d SL |
796 | pub fn InitializeCriticalSection(CriticalSection: *mut CRITICAL_SECTION); |
797 | pub fn EnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION); | |
ba9703b0 | 798 | pub fn TryEnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION) -> BOOL; |
c1a9b12d SL |
799 | pub fn LeaveCriticalSection(CriticalSection: *mut CRITICAL_SECTION); |
800 | pub fn DeleteCriticalSection(CriticalSection: *mut CRITICAL_SECTION); | |
1a4d82fc | 801 | |
92a42be0 | 802 | pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL; |
dfeec247 | 803 | pub fn SetFileAttributesW(lpFileName: LPCWSTR, dwFileAttributes: DWORD) -> BOOL; |
92a42be0 SL |
804 | pub fn SetLastError(dwErrCode: DWORD); |
805 | pub fn GetCommandLineW() -> *mut LPCWSTR; | |
dfeec247 | 806 | pub fn GetTempPathW(nBufferLength: DWORD, lpBuffer: LPCWSTR) -> DWORD; |
92a42be0 SL |
807 | pub fn GetCurrentProcess() -> HANDLE; |
808 | pub fn GetCurrentThread() -> HANDLE; | |
809 | pub fn GetStdHandle(which: DWORD) -> HANDLE; | |
810 | pub fn ExitProcess(uExitCode: c_uint) -> !; | |
dfeec247 XL |
811 | pub fn DeviceIoControl( |
812 | hDevice: HANDLE, | |
813 | dwIoControlCode: DWORD, | |
814 | lpInBuffer: LPVOID, | |
815 | nInBufferSize: DWORD, | |
816 | lpOutBuffer: LPVOID, | |
817 | nOutBufferSize: DWORD, | |
818 | lpBytesReturned: LPDWORD, | |
819 | lpOverlapped: LPOVERLAPPED, | |
820 | ) -> BOOL; | |
821 | pub fn CreateThread( | |
822 | lpThreadAttributes: LPSECURITY_ATTRIBUTES, | |
823 | dwStackSize: SIZE_T, | |
824 | lpStartAddress: extern "system" fn(*mut c_void) -> DWORD, | |
825 | lpParameter: LPVOID, | |
826 | dwCreationFlags: DWORD, | |
827 | lpThreadId: LPDWORD, | |
828 | ) -> HANDLE; | |
829 | pub fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) -> DWORD; | |
92a42be0 SL |
830 | pub fn SwitchToThread() -> BOOL; |
831 | pub fn Sleep(dwMilliseconds: DWORD); | |
832 | pub fn GetProcessId(handle: HANDLE) -> DWORD; | |
dfeec247 XL |
833 | pub fn CopyFileExW( |
834 | lpExistingFileName: LPCWSTR, | |
835 | lpNewFileName: LPCWSTR, | |
836 | lpProgressRoutine: LPPROGRESS_ROUTINE, | |
837 | lpData: LPVOID, | |
838 | pbCancel: LPBOOL, | |
839 | dwCopyFlags: DWORD, | |
840 | ) -> BOOL; | |
841 | pub fn FormatMessageW( | |
842 | flags: DWORD, | |
843 | lpSrc: LPVOID, | |
844 | msgId: DWORD, | |
845 | langId: DWORD, | |
846 | buf: LPWSTR, | |
847 | nsize: DWORD, | |
848 | args: *const c_void, | |
849 | ) -> DWORD; | |
92a42be0 | 850 | pub fn TlsAlloc() -> DWORD; |
92a42be0 SL |
851 | pub fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID; |
852 | pub fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL; | |
853 | pub fn GetLastError() -> DWORD; | |
854 | pub fn QueryPerformanceFrequency(lpFrequency: *mut LARGE_INTEGER) -> BOOL; | |
dfeec247 | 855 | pub fn QueryPerformanceCounter(lpPerformanceCount: *mut LARGE_INTEGER) -> BOOL; |
92a42be0 SL |
856 | pub fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: LPDWORD) -> BOOL; |
857 | pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) -> BOOL; | |
dfeec247 XL |
858 | pub fn CreateProcessW( |
859 | lpApplicationName: LPCWSTR, | |
860 | lpCommandLine: LPWSTR, | |
861 | lpProcessAttributes: LPSECURITY_ATTRIBUTES, | |
862 | lpThreadAttributes: LPSECURITY_ATTRIBUTES, | |
863 | bInheritHandles: BOOL, | |
864 | dwCreationFlags: DWORD, | |
865 | lpEnvironment: LPVOID, | |
866 | lpCurrentDirectory: LPCWSTR, | |
867 | lpStartupInfo: LPSTARTUPINFO, | |
868 | lpProcessInformation: LPPROCESS_INFORMATION, | |
869 | ) -> BOOL; | |
92a42be0 SL |
870 | pub fn GetEnvironmentVariableW(n: LPCWSTR, v: LPWSTR, nsize: DWORD) -> DWORD; |
871 | pub fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL; | |
872 | pub fn GetEnvironmentStringsW() -> LPWCH; | |
873 | pub fn FreeEnvironmentStringsW(env_ptr: LPWCH) -> BOOL; | |
dfeec247 XL |
874 | pub fn GetModuleFileNameW(hModule: HMODULE, lpFilename: LPWSTR, nSize: DWORD) -> DWORD; |
875 | pub fn CreateDirectoryW( | |
876 | lpPathName: LPCWSTR, | |
877 | lpSecurityAttributes: LPSECURITY_ATTRIBUTES, | |
878 | ) -> BOOL; | |
92a42be0 SL |
879 | pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL; |
880 | pub fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: LPWSTR) -> DWORD; | |
881 | pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL; | |
882 | ||
883 | pub fn closesocket(socket: SOCKET) -> c_int; | |
dfeec247 XL |
884 | pub fn recv(socket: SOCKET, buf: *mut c_void, len: c_int, flags: c_int) -> c_int; |
885 | pub fn send(socket: SOCKET, buf: *const c_void, len: c_int, flags: c_int) -> c_int; | |
886 | pub fn recvfrom( | |
887 | socket: SOCKET, | |
888 | buf: *mut c_void, | |
889 | len: c_int, | |
890 | flags: c_int, | |
891 | addr: *mut SOCKADDR, | |
892 | addrlen: *mut c_int, | |
893 | ) -> c_int; | |
894 | pub fn sendto( | |
895 | socket: SOCKET, | |
896 | buf: *const c_void, | |
897 | len: c_int, | |
898 | flags: c_int, | |
899 | addr: *const SOCKADDR, | |
900 | addrlen: c_int, | |
901 | ) -> c_int; | |
92a42be0 | 902 | pub fn shutdown(socket: SOCKET, how: c_int) -> c_int; |
dfeec247 XL |
903 | pub fn accept(socket: SOCKET, address: *mut SOCKADDR, address_len: *mut c_int) -> SOCKET; |
904 | pub fn DuplicateHandle( | |
905 | hSourceProcessHandle: HANDLE, | |
906 | hSourceHandle: HANDLE, | |
907 | hTargetProcessHandle: HANDLE, | |
908 | lpTargetHandle: LPHANDLE, | |
909 | dwDesiredAccess: DWORD, | |
910 | bInheritHandle: BOOL, | |
911 | dwOptions: DWORD, | |
912 | ) -> BOOL; | |
913 | pub fn ReadFile( | |
914 | hFile: HANDLE, | |
915 | lpBuffer: LPVOID, | |
916 | nNumberOfBytesToRead: DWORD, | |
917 | lpNumberOfBytesRead: LPDWORD, | |
918 | lpOverlapped: LPOVERLAPPED, | |
919 | ) -> BOOL; | |
920 | pub fn WriteFile( | |
921 | hFile: HANDLE, | |
922 | lpBuffer: LPVOID, | |
923 | nNumberOfBytesToWrite: DWORD, | |
924 | lpNumberOfBytesWritten: LPDWORD, | |
925 | lpOverlapped: LPOVERLAPPED, | |
926 | ) -> BOOL; | |
92a42be0 | 927 | pub fn CloseHandle(hObject: HANDLE) -> BOOL; |
dfeec247 XL |
928 | pub fn MoveFileExW(lpExistingFileName: LPCWSTR, lpNewFileName: LPCWSTR, dwFlags: DWORD) |
929 | -> BOOL; | |
930 | pub fn SetFilePointerEx( | |
931 | hFile: HANDLE, | |
932 | liDistanceToMove: LARGE_INTEGER, | |
933 | lpNewFilePointer: PLARGE_INTEGER, | |
934 | dwMoveMethod: DWORD, | |
935 | ) -> BOOL; | |
92a42be0 | 936 | pub fn FlushFileBuffers(hFile: HANDLE) -> BOOL; |
dfeec247 XL |
937 | pub fn CreateFileW( |
938 | lpFileName: LPCWSTR, | |
939 | dwDesiredAccess: DWORD, | |
940 | dwShareMode: DWORD, | |
941 | lpSecurityAttributes: LPSECURITY_ATTRIBUTES, | |
942 | dwCreationDisposition: DWORD, | |
943 | dwFlagsAndAttributes: DWORD, | |
944 | hTemplateFile: HANDLE, | |
945 | ) -> HANDLE; | |
946 | ||
947 | pub fn FindFirstFileW(fileName: LPCWSTR, findFileData: LPWIN32_FIND_DATAW) -> HANDLE; | |
948 | pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW) -> BOOL; | |
92a42be0 | 949 | pub fn FindClose(findFile: HANDLE) -> BOOL; |
dfeec247 XL |
950 | pub fn getsockopt( |
951 | s: SOCKET, | |
952 | level: c_int, | |
953 | optname: c_int, | |
954 | optval: *mut c_char, | |
955 | optlen: *mut c_int, | |
956 | ) -> c_int; | |
957 | pub fn setsockopt( | |
958 | s: SOCKET, | |
959 | level: c_int, | |
960 | optname: c_int, | |
961 | optval: *const c_void, | |
962 | optlen: c_int, | |
963 | ) -> c_int; | |
964 | pub fn getsockname(socket: SOCKET, address: *mut SOCKADDR, address_len: *mut c_int) -> c_int; | |
965 | pub fn getpeername(socket: SOCKET, address: *mut SOCKADDR, address_len: *mut c_int) -> c_int; | |
966 | pub fn bind(socket: SOCKET, address: *const SOCKADDR, address_len: socklen_t) -> c_int; | |
92a42be0 | 967 | pub fn listen(socket: SOCKET, backlog: c_int) -> c_int; |
dfeec247 XL |
968 | pub fn connect(socket: SOCKET, address: *const SOCKADDR, len: c_int) -> c_int; |
969 | pub fn getaddrinfo( | |
970 | node: *const c_char, | |
971 | service: *const c_char, | |
972 | hints: *const ADDRINFOA, | |
973 | res: *mut *mut ADDRINFOA, | |
974 | ) -> c_int; | |
92a42be0 | 975 | pub fn freeaddrinfo(res: *mut ADDRINFOA); |
92a42be0 | 976 | |
dfeec247 | 977 | pub fn GetProcAddress(handle: HMODULE, name: LPCSTR) -> *mut c_void; |
5869c6ff | 978 | pub fn GetModuleHandleA(lpModuleName: LPCSTR) -> HMODULE; |
92a42be0 | 979 | pub fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE; |
92a42be0 | 980 | |
92a42be0 | 981 | pub fn GetSystemTimeAsFileTime(lpSystemTimeAsFileTime: LPFILETIME); |
54a0048b | 982 | |
dfeec247 XL |
983 | pub fn CreateEventW( |
984 | lpEventAttributes: LPSECURITY_ATTRIBUTES, | |
985 | bManualReset: BOOL, | |
986 | bInitialState: BOOL, | |
987 | lpName: LPCWSTR, | |
988 | ) -> HANDLE; | |
989 | pub fn WaitForMultipleObjects( | |
990 | nCount: DWORD, | |
991 | lpHandles: *const HANDLE, | |
992 | bWaitAll: BOOL, | |
993 | dwMilliseconds: DWORD, | |
994 | ) -> DWORD; | |
995 | pub fn CreateNamedPipeW( | |
996 | lpName: LPCWSTR, | |
997 | dwOpenMode: DWORD, | |
998 | dwPipeMode: DWORD, | |
999 | nMaxInstances: DWORD, | |
1000 | nOutBufferSize: DWORD, | |
1001 | nInBufferSize: DWORD, | |
1002 | nDefaultTimeOut: DWORD, | |
1003 | lpSecurityAttributes: LPSECURITY_ATTRIBUTES, | |
1004 | ) -> HANDLE; | |
54a0048b | 1005 | pub fn CancelIo(handle: HANDLE) -> BOOL; |
dfeec247 XL |
1006 | pub fn GetOverlappedResult( |
1007 | hFile: HANDLE, | |
1008 | lpOverlapped: LPOVERLAPPED, | |
1009 | lpNumberOfBytesTransferred: LPDWORD, | |
1010 | bWait: BOOL, | |
1011 | ) -> BOOL; | |
1012 | pub fn select( | |
1013 | nfds: c_int, | |
1014 | readfds: *mut fd_set, | |
1015 | writefds: *mut fd_set, | |
1016 | exceptfds: *mut fd_set, | |
1017 | timeout: *const timeval, | |
1018 | ) -> c_int; | |
a1dfa0c6 XL |
1019 | |
1020 | pub fn GetProcessHeap() -> HANDLE; | |
1021 | pub fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID; | |
1022 | pub fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID, dwBytes: SIZE_T) -> LPVOID; | |
1023 | pub fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL; | |
5869c6ff XL |
1024 | |
1025 | // >= Vista / Server 2008 | |
6a06907d | 1026 | // https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createsymboliclinkw |
5869c6ff XL |
1027 | pub fn CreateSymbolicLinkW( |
1028 | lpSymlinkFileName: LPCWSTR, | |
1029 | lpTargetFileName: LPCWSTR, | |
1030 | dwFlags: DWORD, | |
1031 | ) -> BOOLEAN; | |
1032 | ||
1033 | // >= Vista / Server 2008 | |
1034 | // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlew | |
1035 | pub fn GetFinalPathNameByHandleW( | |
1036 | hFile: HANDLE, | |
1037 | lpszFilePath: LPCWSTR, | |
1038 | cchFilePath: DWORD, | |
1039 | dwFlags: DWORD, | |
1040 | ) -> DWORD; | |
1041 | ||
1042 | // >= Vista / Server 2003 | |
1043 | // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreadstackguarantee | |
1044 | #[cfg(not(target_vendor = "uwp"))] | |
1045 | pub fn SetThreadStackGuarantee(_size: *mut c_ulong) -> BOOL; | |
1046 | ||
1047 | // >= Vista / Server 2008 | |
1048 | // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfileinformationbyhandle | |
1049 | pub fn SetFileInformationByHandle( | |
1050 | hFile: HANDLE, | |
1051 | FileInformationClass: FILE_INFO_BY_HANDLE_CLASS, | |
1052 | lpFileInformation: LPVOID, | |
1053 | dwBufferSize: DWORD, | |
1054 | ) -> BOOL; | |
1055 | ||
1056 | // >= Vista / Server 2008 | |
1057 | // https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-sleepconditionvariablesrw | |
1058 | pub fn SleepConditionVariableSRW( | |
1059 | ConditionVariable: PCONDITION_VARIABLE, | |
1060 | SRWLock: PSRWLOCK, | |
1061 | dwMilliseconds: DWORD, | |
1062 | Flags: ULONG, | |
1063 | ) -> BOOL; | |
1064 | ||
1065 | // >= Vista / Server 2008 | |
1066 | // https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-wakeconditionvariable | |
1067 | pub fn WakeConditionVariable(ConditionVariable: PCONDITION_VARIABLE); | |
1068 | pub fn WakeAllConditionVariable(ConditionVariable: PCONDITION_VARIABLE); | |
1069 | ||
1070 | // >= Vista / Server 2008 | |
1071 | // https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-acquiresrwlockexclusive | |
1072 | pub fn AcquireSRWLockExclusive(SRWLock: PSRWLOCK); | |
1073 | pub fn AcquireSRWLockShared(SRWLock: PSRWLOCK); | |
1074 | pub fn ReleaseSRWLockExclusive(SRWLock: PSRWLOCK); | |
1075 | pub fn ReleaseSRWLockShared(SRWLock: PSRWLOCK); | |
1076 | pub fn TryAcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> BOOLEAN; | |
1077 | pub fn TryAcquireSRWLockShared(SRWLock: PSRWLOCK) -> BOOLEAN; | |
c1a9b12d SL |
1078 | } |
1079 | ||
ea8adc8c XL |
1080 | // Functions that aren't available on every version of Windows that we support, |
1081 | // but we still use them and just provide some form of a fallback implementation. | |
c1a9b12d | 1082 | compat_fn! { |
1b1a35ee | 1083 | "kernel32": |
c1a9b12d | 1084 | |
5869c6ff XL |
1085 | // >= Win10 1607 |
1086 | // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreaddescription | |
ea8adc8c XL |
1087 | pub fn SetThreadDescription(hThread: HANDLE, |
1088 | lpThreadDescription: LPCWSTR) -> HRESULT { | |
1089 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); E_NOTIMPL | |
1090 | } | |
5869c6ff XL |
1091 | |
1092 | // >= Win8 / Server 2012 | |
1093 | // https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimepreciseasfiletime | |
ba9703b0 XL |
1094 | pub fn GetSystemTimePreciseAsFileTime(lpSystemTimeAsFileTime: LPFILETIME) |
1095 | -> () { | |
1096 | GetSystemTimeAsFileTime(lpSystemTimeAsFileTime) | |
1097 | } | |
1a4d82fc | 1098 | } |
5869c6ff | 1099 | |
fc512014 XL |
1100 | compat_fn! { |
1101 | "api-ms-win-core-synch-l1-2-0": | |
5869c6ff XL |
1102 | |
1103 | // >= Windows 8 / Server 2012 | |
1104 | // https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitonaddress | |
fc512014 XL |
1105 | pub fn WaitOnAddress( |
1106 | Address: LPVOID, | |
1107 | CompareAddress: LPVOID, | |
1108 | AddressSize: SIZE_T, | |
1109 | dwMilliseconds: DWORD | |
1110 | ) -> BOOL { | |
1111 | panic!("WaitOnAddress not available") | |
1112 | } | |
1113 | pub fn WakeByAddressSingle(Address: LPVOID) -> () { | |
1114 | // If this api is unavailable, there cannot be anything waiting, because | |
1115 | // WaitOnAddress would've panicked. So it's fine to do nothing here. | |
1116 | } | |
1117 | } | |
1118 | ||
1119 | compat_fn! { | |
1120 | "ntdll": | |
1121 | pub fn NtCreateKeyedEvent( | |
1122 | KeyedEventHandle: LPHANDLE, | |
1123 | DesiredAccess: ACCESS_MASK, | |
1124 | ObjectAttributes: LPVOID, | |
1125 | Flags: ULONG | |
1126 | ) -> NTSTATUS { | |
1127 | panic!("keyed events not available") | |
1128 | } | |
1129 | pub fn NtReleaseKeyedEvent( | |
1130 | EventHandle: HANDLE, | |
1131 | Key: LPVOID, | |
1132 | Alertable: BOOLEAN, | |
1133 | Timeout: PLARGE_INTEGER | |
1134 | ) -> NTSTATUS { | |
1135 | panic!("keyed events not available") | |
1136 | } | |
1137 | pub fn NtWaitForKeyedEvent( | |
1138 | EventHandle: HANDLE, | |
1139 | Key: LPVOID, | |
1140 | Alertable: BOOLEAN, | |
1141 | Timeout: PLARGE_INTEGER | |
1142 | ) -> NTSTATUS { | |
1143 | panic!("keyed events not available") | |
1144 | } | |
1145 | } |