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