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