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