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