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