]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | //! C definitions used by libnative that don't belong in liblibc | |
12 | ||
7453a54e SL |
13 | #![allow(bad_style)] |
14 | #![cfg_attr(test, allow(dead_code))] | |
54a0048b | 15 | #![unstable(issue = "0", feature = "windows_c")] |
1a4d82fc | 16 | |
7cac9316 XL |
17 | use os::raw::{c_int, c_uint, c_ulong, c_long, c_longlong, c_ushort, c_char}; |
18 | #[cfg(target_arch = "x86_64")] | |
19 | use os::raw::c_ulonglong; | |
92a42be0 | 20 | use libc::{wchar_t, size_t, c_void}; |
e9174d1e | 21 | use ptr; |
9cc50fc6 SL |
22 | |
23 | #[repr(simd)] | |
24 | #[repr(C)] | |
7453a54e | 25 | #[cfg(target_arch = "x86_64")] |
9cc50fc6 | 26 | struct u64x2(u64, u64); |
1a4d82fc | 27 | |
85aaf69f | 28 | pub use self::FILE_INFO_BY_HANDLE_CLASS::*; |
92a42be0 | 29 | pub use self::EXCEPTION_DISPOSITION::*; |
85aaf69f | 30 | |
92a42be0 SL |
31 | pub type DWORD = c_ulong; |
32 | pub type HANDLE = LPVOID; | |
33 | pub type HINSTANCE = HANDLE; | |
34 | pub type HMODULE = HINSTANCE; | |
ea8adc8c | 35 | pub type HRESULT = LONG; |
92a42be0 SL |
36 | pub type BOOL = c_int; |
37 | pub type BYTE = u8; | |
38 | pub type BOOLEAN = BYTE; | |
39 | pub type GROUP = c_uint; | |
40 | pub type LONG_PTR = isize; | |
41 | pub type LARGE_INTEGER = c_longlong; | |
42 | pub type LONG = c_long; | |
43 | pub type UINT = c_uint; | |
44 | pub type WCHAR = u16; | |
45 | pub type USHORT = c_ushort; | |
46 | pub type SIZE_T = usize; | |
47 | pub type WORD = u16; | |
48 | pub type CHAR = c_char; | |
49 | pub type HCRYPTPROV = LONG_PTR; | |
7cac9316 | 50 | pub type ULONG_PTR = usize; |
92a42be0 | 51 | pub type ULONG = c_ulong; |
476ff2be | 52 | #[cfg(target_arch = "x86_64")] |
92a42be0 | 53 | pub type ULONGLONG = u64; |
476ff2be | 54 | #[cfg(target_arch = "x86_64")] |
92a42be0 SL |
55 | pub type DWORDLONG = ULONGLONG; |
56 | ||
57 | pub type LPBOOL = *mut BOOL; | |
58 | pub type LPBYTE = *mut BYTE; | |
59 | pub type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION; | |
60 | pub type LPCSTR = *const CHAR; | |
61 | pub type LPCVOID = *const c_void; | |
62 | pub type LPCWSTR = *const WCHAR; | |
63 | pub type LPDWORD = *mut DWORD; | |
64 | pub type LPHANDLE = *mut HANDLE; | |
65 | pub type LPOVERLAPPED = *mut OVERLAPPED; | |
66 | pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION; | |
67 | pub type LPSECURITY_ATTRIBUTES = *mut SECURITY_ATTRIBUTES; | |
68 | pub type LPSTARTUPINFO = *mut STARTUPINFO; | |
69 | pub type LPVOID = *mut c_void; | |
70 | pub type LPWCH = *mut WCHAR; | |
71 | pub type LPWIN32_FIND_DATAW = *mut WIN32_FIND_DATAW; | |
72 | pub type LPWSADATA = *mut WSADATA; | |
92a42be0 | 73 | pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO; |
32a655c1 | 74 | pub type LPSTR = *mut CHAR; |
92a42be0 SL |
75 | pub type LPWSTR = *mut WCHAR; |
76 | pub type LPFILETIME = *mut FILETIME; | |
77 | ||
78 | pub type PCONDITION_VARIABLE = *mut CONDITION_VARIABLE; | |
79 | pub type PLARGE_INTEGER = *mut c_longlong; | |
80 | pub type PSRWLOCK = *mut SRWLOCK; | |
81 | ||
82 | pub type SOCKET = ::os::windows::raw::SOCKET; | |
83 | pub type socklen_t = c_int; | |
84 | pub type ADDRESS_FAMILY = USHORT; | |
85 | ||
86 | pub const TRUE: BOOL = 1; | |
87 | pub const FALSE: BOOL = 0; | |
88 | ||
89 | pub const FILE_ATTRIBUTE_READONLY: DWORD = 0x1; | |
90 | pub const FILE_ATTRIBUTE_DIRECTORY: DWORD = 0x10; | |
92a42be0 | 91 | pub const FILE_ATTRIBUTE_REPARSE_POINT: DWORD = 0x400; |
7453a54e | 92 | |
92a42be0 SL |
93 | pub const FILE_SHARE_DELETE: DWORD = 0x4; |
94 | pub const FILE_SHARE_READ: DWORD = 0x1; | |
95 | pub const FILE_SHARE_WRITE: DWORD = 0x2; | |
7453a54e | 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 | |
92a42be0 | 103 | pub const FILE_WRITE_DATA: DWORD = 0x00000002; |
7453a54e | 104 | pub const FILE_APPEND_DATA: DWORD = 0x00000004; |
92a42be0 | 105 | pub const FILE_WRITE_EA: DWORD = 0x00000010; |
92a42be0 | 106 | pub const FILE_WRITE_ATTRIBUTES: DWORD = 0x00000100; |
7453a54e SL |
107 | pub const READ_CONTROL: DWORD = 0x00020000; |
108 | pub const SYNCHRONIZE: DWORD = 0x00100000; | |
109 | pub const GENERIC_READ: DWORD = 0x80000000; | |
110 | pub const GENERIC_WRITE: DWORD = 0x40000000; | |
111 | pub const STANDARD_RIGHTS_WRITE: DWORD = READ_CONTROL; | |
92a42be0 SL |
112 | pub const FILE_GENERIC_WRITE: DWORD = STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA | |
113 | FILE_WRITE_ATTRIBUTES | | |
114 | FILE_WRITE_EA | | |
115 | FILE_APPEND_DATA | | |
116 | SYNCHRONIZE; | |
117 | ||
7453a54e SL |
118 | pub const FILE_FLAG_OPEN_REPARSE_POINT: DWORD = 0x00200000; |
119 | pub const FILE_FLAG_BACKUP_SEMANTICS: DWORD = 0x02000000; | |
120 | pub const SECURITY_SQOS_PRESENT: DWORD = 0x00100000; | |
121 | ||
54a0048b SL |
122 | pub const FIONBIO: c_ulong = 0x8004667e; |
123 | ||
92a42be0 SL |
124 | #[repr(C)] |
125 | #[derive(Copy)] | |
126 | pub struct WIN32_FIND_DATAW { | |
127 | pub dwFileAttributes: DWORD, | |
128 | pub ftCreationTime: FILETIME, | |
129 | pub ftLastAccessTime: FILETIME, | |
130 | pub ftLastWriteTime: FILETIME, | |
131 | pub nFileSizeHigh: DWORD, | |
132 | pub nFileSizeLow: DWORD, | |
133 | pub dwReserved0: DWORD, | |
134 | pub dwReserved1: DWORD, | |
135 | pub cFileName: [wchar_t; 260], // #define MAX_PATH 260 | |
136 | pub cAlternateFileName: [wchar_t; 14], | |
137 | } | |
138 | impl Clone for WIN32_FIND_DATAW { | |
139 | fn clone(&self) -> Self { *self } | |
140 | } | |
141 | ||
92a42be0 | 142 | pub const WSA_FLAG_OVERLAPPED: DWORD = 0x01; |
92a42be0 SL |
143 | |
144 | pub const WSADESCRIPTION_LEN: usize = 256; | |
145 | pub const WSASYS_STATUS_LEN: usize = 128; | |
146 | pub const WSAPROTOCOL_LEN: DWORD = 255; | |
147 | pub const INVALID_SOCKET: SOCKET = !0; | |
148 | ||
92a42be0 | 149 | pub const WSAEACCES: c_int = 10013; |
92a42be0 | 150 | pub const WSAEINVAL: c_int = 10022; |
92a42be0 | 151 | pub const WSAEWOULDBLOCK: c_int = 10035; |
92a42be0 SL |
152 | pub const WSAEADDRINUSE: c_int = 10048; |
153 | pub const WSAEADDRNOTAVAIL: c_int = 10049; | |
92a42be0 SL |
154 | pub const WSAECONNABORTED: c_int = 10053; |
155 | pub const WSAECONNRESET: c_int = 10054; | |
92a42be0 SL |
156 | pub const WSAENOTCONN: c_int = 10057; |
157 | pub const WSAESHUTDOWN: c_int = 10058; | |
92a42be0 SL |
158 | pub const WSAETIMEDOUT: c_int = 10060; |
159 | pub const WSAECONNREFUSED: c_int = 10061; | |
7453a54e | 160 | |
92a42be0 SL |
161 | pub const MAX_PROTOCOL_CHAIN: DWORD = 7; |
162 | ||
163 | pub const TOKEN_READ: DWORD = 0x20008; | |
9346a6ac | 164 | pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024; |
92a42be0 SL |
165 | pub const FSCTL_GET_REPARSE_POINT: DWORD = 0x900a8; |
166 | pub const IO_REPARSE_TAG_SYMLINK: DWORD = 0xa000000c; | |
167 | pub const IO_REPARSE_TAG_MOUNT_POINT: DWORD = 0xa0000003; | |
7453a54e | 168 | pub const SYMLINK_FLAG_RELATIVE: DWORD = 0x00000001; |
92a42be0 | 169 | pub const FSCTL_SET_REPARSE_POINT: DWORD = 0x900a4; |
1a4d82fc | 170 | |
92a42be0 | 171 | pub const SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 0x1; |
8bb4bdeb | 172 | pub const SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE: DWORD = 0x2; |
d9579d0f | 173 | |
c34b1796 | 174 | // Note that these are not actually HANDLEs, just values to pass to GetStdHandle |
92a42be0 SL |
175 | pub const STD_INPUT_HANDLE: DWORD = -10i32 as DWORD; |
176 | pub const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD; | |
177 | pub const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD; | |
178 | ||
179 | pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001; | |
180 | ||
181 | pub const PROGRESS_CONTINUE: DWORD = 0; | |
92a42be0 | 182 | |
92a42be0 SL |
183 | pub const ERROR_FILE_NOT_FOUND: DWORD = 2; |
184 | pub const ERROR_PATH_NOT_FOUND: DWORD = 3; | |
185 | pub const ERROR_ACCESS_DENIED: DWORD = 5; | |
186 | pub const ERROR_INVALID_HANDLE: DWORD = 6; | |
187 | pub const ERROR_NO_MORE_FILES: DWORD = 18; | |
54a0048b | 188 | pub const ERROR_HANDLE_EOF: DWORD = 38; |
3157f602 | 189 | pub const ERROR_FILE_EXISTS: DWORD = 80; |
476ff2be | 190 | pub const ERROR_INVALID_PARAMETER: DWORD = 87; |
92a42be0 | 191 | pub const ERROR_BROKEN_PIPE: DWORD = 109; |
92a42be0 SL |
192 | pub const ERROR_CALL_NOT_IMPLEMENTED: DWORD = 120; |
193 | pub const ERROR_INSUFFICIENT_BUFFER: DWORD = 122; | |
92a42be0 | 194 | pub const ERROR_ALREADY_EXISTS: DWORD = 183; |
92a42be0 | 195 | pub const ERROR_NO_DATA: DWORD = 232; |
92a42be0 | 196 | pub const ERROR_ENVVAR_NOT_FOUND: DWORD = 203; |
92a42be0 | 197 | pub const ERROR_OPERATION_ABORTED: DWORD = 995; |
54a0048b | 198 | pub const ERROR_IO_PENDING: DWORD = 997; |
92a42be0 SL |
199 | pub const ERROR_TIMEOUT: DWORD = 0x5B4; |
200 | ||
ea8adc8c XL |
201 | pub const E_NOTIMPL: HRESULT = 0x80004001u32 as HRESULT; |
202 | ||
92a42be0 SL |
203 | pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE; |
204 | ||
7cac9316 XL |
205 | pub const FACILITY_NT_BIT: DWORD = 0x1000_0000; |
206 | ||
92a42be0 | 207 | pub const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000; |
7cac9316 | 208 | pub const FORMAT_MESSAGE_FROM_HMODULE: DWORD = 0x00000800; |
92a42be0 SL |
209 | pub const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200; |
210 | ||
211 | pub const TLS_OUT_OF_INDEXES: DWORD = 0xFFFFFFFF; | |
212 | ||
213 | pub const DLL_THREAD_DETACH: DWORD = 3; | |
214 | pub const DLL_PROCESS_DETACH: DWORD = 0; | |
215 | ||
216 | pub const INFINITE: DWORD = !0; | |
217 | ||
218 | pub const DUPLICATE_SAME_ACCESS: DWORD = 0x00000002; | |
219 | ||
220 | pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE { | |
221 | ptr: ptr::null_mut(), | |
222 | }; | |
223 | pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: ptr::null_mut() }; | |
c1a9b12d | 224 | |
92a42be0 SL |
225 | pub const DETACHED_PROCESS: DWORD = 0x00000008; |
226 | pub const CREATE_NEW_PROCESS_GROUP: DWORD = 0x00000200; | |
227 | pub const CREATE_UNICODE_ENVIRONMENT: DWORD = 0x00000400; | |
228 | pub const STARTF_USESTDHANDLES: DWORD = 0x00000100; | |
229 | ||
230 | pub const AF_INET: c_int = 2; | |
231 | pub const AF_INET6: c_int = 23; | |
232 | pub const SD_BOTH: c_int = 2; | |
233 | pub const SD_RECEIVE: c_int = 0; | |
234 | pub const SD_SEND: c_int = 1; | |
235 | pub const SOCK_DGRAM: c_int = 2; | |
236 | pub const SOCK_STREAM: c_int = 1; | |
237 | pub const SOL_SOCKET: c_int = 0xffff; | |
238 | pub const SO_RCVTIMEO: c_int = 0x1006; | |
239 | pub const SO_SNDTIMEO: c_int = 0x1005; | |
240 | pub const SO_REUSEADDR: c_int = 0x0004; | |
54a0048b SL |
241 | pub const IPPROTO_IP: c_int = 0; |
242 | pub const IPPROTO_TCP: c_int = 6; | |
243 | pub const IPPROTO_IPV6: c_int = 41; | |
244 | pub const TCP_NODELAY: c_int = 0x0001; | |
245 | pub const IP_TTL: c_int = 4; | |
246 | pub const IPV6_V6ONLY: c_int = 27; | |
247 | pub const SO_ERROR: c_int = 0x1007; | |
248 | pub const SO_BROADCAST: c_int = 0x0020; | |
249 | pub const IP_MULTICAST_LOOP: c_int = 11; | |
250 | pub const IPV6_MULTICAST_LOOP: c_int = 11; | |
251 | pub const IP_MULTICAST_TTL: c_int = 10; | |
252 | pub const IP_ADD_MEMBERSHIP: c_int = 12; | |
253 | pub const IP_DROP_MEMBERSHIP: c_int = 13; | |
254 | pub const IPV6_ADD_MEMBERSHIP: c_int = 12; | |
255 | pub const IPV6_DROP_MEMBERSHIP: c_int = 13; | |
8bb4bdeb | 256 | pub const MSG_PEEK: c_int = 0x2; |
54a0048b SL |
257 | |
258 | #[repr(C)] | |
259 | pub struct ip_mreq { | |
260 | pub imr_multiaddr: in_addr, | |
261 | pub imr_interface: in_addr, | |
262 | } | |
263 | ||
264 | #[repr(C)] | |
265 | pub struct ipv6_mreq { | |
266 | pub ipv6mr_multiaddr: in6_addr, | |
267 | pub ipv6mr_interface: c_uint, | |
268 | } | |
92a42be0 SL |
269 | |
270 | pub const VOLUME_NAME_DOS: DWORD = 0x0; | |
271 | pub const MOVEFILE_REPLACE_EXISTING: DWORD = 1; | |
272 | ||
273 | pub const FILE_BEGIN: DWORD = 0; | |
274 | pub const FILE_CURRENT: DWORD = 1; | |
275 | pub const FILE_END: DWORD = 2; | |
276 | ||
92a42be0 | 277 | pub const WAIT_OBJECT_0: DWORD = 0x00000000; |
32a655c1 | 278 | pub const WAIT_TIMEOUT: DWORD = 258; |
3b2f2976 | 279 | pub const WAIT_FAILED: DWORD = 0xFFFFFFFF; |
92a42be0 | 280 | |
7453a54e | 281 | #[cfg(target_env = "msvc")] |
ea8adc8c | 282 | #[cfg(feature = "backtrace")] |
92a42be0 | 283 | pub const MAX_SYM_NAME: usize = 2000; |
7453a54e | 284 | #[cfg(target_arch = "x86")] |
ea8adc8c | 285 | #[cfg(feature = "backtrace")] |
92a42be0 | 286 | pub const IMAGE_FILE_MACHINE_I386: DWORD = 0x014c; |
7453a54e | 287 | #[cfg(target_arch = "x86_64")] |
ea8adc8c | 288 | #[cfg(feature = "backtrace")] |
92a42be0 SL |
289 | pub const IMAGE_FILE_MACHINE_AMD64: DWORD = 0x8664; |
290 | ||
291 | pub const PROV_RSA_FULL: DWORD = 1; | |
292 | pub const CRYPT_SILENT: DWORD = 64; | |
293 | pub const CRYPT_VERIFYCONTEXT: DWORD = 0xF0000000; | |
c1a9b12d | 294 | |
e9174d1e | 295 | pub const EXCEPTION_CONTINUE_SEARCH: LONG = 0; |
e9174d1e | 296 | pub const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd; |
92a42be0 | 297 | pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15; |
b039eaaf | 298 | |
54a0048b | 299 | pub const PIPE_ACCESS_INBOUND: DWORD = 0x00000001; |
476ff2be | 300 | pub const PIPE_ACCESS_OUTBOUND: DWORD = 0x00000002; |
54a0048b SL |
301 | pub const FILE_FLAG_FIRST_PIPE_INSTANCE: DWORD = 0x00080000; |
302 | pub const FILE_FLAG_OVERLAPPED: DWORD = 0x40000000; | |
303 | pub const PIPE_WAIT: DWORD = 0x00000000; | |
304 | pub const PIPE_TYPE_BYTE: DWORD = 0x00000000; | |
305 | pub const PIPE_REJECT_REMOTE_CLIENTS: DWORD = 0x00000008; | |
306 | pub const PIPE_READMODE_BYTE: DWORD = 0x00000000; | |
307 | ||
041b39d2 XL |
308 | pub const FD_SETSIZE: usize = 64; |
309 | ||
1a4d82fc | 310 | #[repr(C)] |
3b2f2976 | 311 | #[cfg(not(target_pointer_width = "64"))] |
1a4d82fc | 312 | pub struct WSADATA { |
92a42be0 SL |
313 | pub wVersion: WORD, |
314 | pub wHighVersion: WORD, | |
1a4d82fc JJ |
315 | pub szDescription: [u8; WSADESCRIPTION_LEN + 1], |
316 | pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1], | |
317 | pub iMaxSockets: u16, | |
318 | pub iMaxUdpDg: u16, | |
319 | pub lpVendorInfo: *mut u8, | |
320 | } | |
321 | #[repr(C)] | |
3b2f2976 | 322 | #[cfg(target_pointer_width = "64")] |
1a4d82fc | 323 | pub struct WSADATA { |
92a42be0 SL |
324 | pub wVersion: WORD, |
325 | pub wHighVersion: WORD, | |
1a4d82fc JJ |
326 | pub iMaxSockets: u16, |
327 | pub iMaxUdpDg: u16, | |
328 | pub lpVendorInfo: *mut u8, | |
329 | pub szDescription: [u8; WSADESCRIPTION_LEN + 1], | |
330 | pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1], | |
331 | } | |
332 | ||
85aaf69f | 333 | #[repr(C)] |
85aaf69f | 334 | pub struct WSAPROTOCOL_INFO { |
92a42be0 SL |
335 | pub dwServiceFlags1: DWORD, |
336 | pub dwServiceFlags2: DWORD, | |
337 | pub dwServiceFlags3: DWORD, | |
338 | pub dwServiceFlags4: DWORD, | |
339 | pub dwProviderFlags: DWORD, | |
85aaf69f | 340 | pub ProviderId: GUID, |
92a42be0 | 341 | pub dwCatalogEntryId: DWORD, |
85aaf69f | 342 | pub ProtocolChain: WSAPROTOCOLCHAIN, |
92a42be0 SL |
343 | pub iVersion: c_int, |
344 | pub iAddressFamily: c_int, | |
345 | pub iMaxSockAddr: c_int, | |
346 | pub iMinSockAddr: c_int, | |
347 | pub iSocketType: c_int, | |
348 | pub iProtocol: c_int, | |
349 | pub iProtocolMaxOffset: c_int, | |
350 | pub iNetworkByteOrder: c_int, | |
351 | pub iSecurityScheme: c_int, | |
352 | pub dwMessageSize: DWORD, | |
353 | pub dwProviderReserved: DWORD, | |
85aaf69f SL |
354 | pub szProtocol: [u16; (WSAPROTOCOL_LEN as usize) + 1], |
355 | } | |
356 | ||
85aaf69f | 357 | #[repr(C)] |
92a42be0 | 358 | #[derive(Copy, Clone)] |
85aaf69f | 359 | pub struct WIN32_FILE_ATTRIBUTE_DATA { |
92a42be0 SL |
360 | pub dwFileAttributes: DWORD, |
361 | pub ftCreationTime: FILETIME, | |
362 | pub ftLastAccessTime: FILETIME, | |
363 | pub ftLastWriteTime: FILETIME, | |
364 | pub nFileSizeHigh: DWORD, | |
365 | pub nFileSizeLow: DWORD, | |
85aaf69f SL |
366 | } |
367 | ||
368 | #[repr(C)] | |
369 | pub struct BY_HANDLE_FILE_INFORMATION { | |
92a42be0 SL |
370 | pub dwFileAttributes: DWORD, |
371 | pub ftCreationTime: FILETIME, | |
372 | pub ftLastAccessTime: FILETIME, | |
373 | pub ftLastWriteTime: FILETIME, | |
374 | pub dwVolumeSerialNumber: DWORD, | |
375 | pub nFileSizeHigh: DWORD, | |
376 | pub nFileSizeLow: DWORD, | |
377 | pub nNumberOfLinks: DWORD, | |
378 | pub nFileIndexHigh: DWORD, | |
379 | pub nFileIndexLow: DWORD, | |
85aaf69f SL |
380 | } |
381 | ||
85aaf69f | 382 | #[repr(C)] |
7453a54e | 383 | #[allow(dead_code)] // we only use some variants |
85aaf69f SL |
384 | pub enum FILE_INFO_BY_HANDLE_CLASS { |
385 | FileBasicInfo = 0, | |
386 | FileStandardInfo = 1, | |
387 | FileNameInfo = 2, | |
388 | FileRenameInfo = 3, | |
389 | FileDispositionInfo = 4, | |
390 | FileAllocationInfo = 5, | |
391 | FileEndOfFileInfo = 6, | |
392 | FileStreamInfo = 7, | |
393 | FileCompressionInfo = 8, | |
394 | FileAttributeTagInfo = 9, | |
395 | FileIdBothDirectoryInfo = 10, // 0xA | |
396 | FileIdBothDirectoryRestartInfo = 11, // 0xB | |
397 | FileIoPriorityHintInfo = 12, // 0xC | |
398 | FileRemoteProtocolInfo = 13, // 0xD | |
399 | FileFullDirectoryInfo = 14, // 0xE | |
400 | FileFullDirectoryRestartInfo = 15, // 0xF | |
401 | FileStorageInfo = 16, // 0x10 | |
402 | FileAlignmentInfo = 17, // 0x11 | |
403 | FileIdInfo = 18, // 0x12 | |
404 | FileIdExtdDirectoryInfo = 19, // 0x13 | |
405 | FileIdExtdDirectoryRestartInfo = 20, // 0x14 | |
406 | MaximumFileInfoByHandlesClass | |
407 | } | |
408 | ||
476ff2be SL |
409 | #[repr(C)] |
410 | pub struct FILE_BASIC_INFO { | |
411 | pub CreationTime: LARGE_INTEGER, | |
412 | pub LastAccessTime: LARGE_INTEGER, | |
413 | pub LastWriteTime: LARGE_INTEGER, | |
414 | pub ChangeTime: LARGE_INTEGER, | |
415 | pub FileAttributes: DWORD, | |
416 | } | |
417 | ||
85aaf69f SL |
418 | #[repr(C)] |
419 | pub struct FILE_END_OF_FILE_INFO { | |
92a42be0 | 420 | pub EndOfFile: LARGE_INTEGER, |
85aaf69f SL |
421 | } |
422 | ||
9346a6ac AL |
423 | #[repr(C)] |
424 | pub struct REPARSE_DATA_BUFFER { | |
92a42be0 SL |
425 | pub ReparseTag: c_uint, |
426 | pub ReparseDataLength: c_ushort, | |
427 | pub Reserved: c_ushort, | |
9346a6ac AL |
428 | pub rest: (), |
429 | } | |
430 | ||
431 | #[repr(C)] | |
432 | pub struct SYMBOLIC_LINK_REPARSE_BUFFER { | |
92a42be0 SL |
433 | pub SubstituteNameOffset: c_ushort, |
434 | pub SubstituteNameLength: c_ushort, | |
435 | pub PrintNameOffset: c_ushort, | |
436 | pub PrintNameLength: c_ushort, | |
437 | pub Flags: c_ulong, | |
438 | pub PathBuffer: WCHAR, | |
9346a6ac AL |
439 | } |
440 | ||
7453a54e SL |
441 | #[repr(C)] |
442 | pub struct MOUNT_POINT_REPARSE_BUFFER { | |
443 | pub SubstituteNameOffset: c_ushort, | |
444 | pub SubstituteNameLength: c_ushort, | |
445 | pub PrintNameOffset: c_ushort, | |
446 | pub PrintNameLength: c_ushort, | |
447 | pub PathBuffer: WCHAR, | |
448 | } | |
449 | ||
c1a9b12d | 450 | pub type LPPROGRESS_ROUTINE = ::option::Option<unsafe extern "system" fn( |
92a42be0 SL |
451 | TotalFileSize: LARGE_INTEGER, |
452 | TotalBytesTransferred: LARGE_INTEGER, | |
453 | StreamSize: LARGE_INTEGER, | |
454 | StreamBytesTransferred: LARGE_INTEGER, | |
c1a9b12d SL |
455 | dwStreamNumber: DWORD, |
456 | dwCallbackReason: DWORD, | |
457 | hSourceFile: HANDLE, | |
458 | hDestinationFile: HANDLE, | |
459 | lpData: LPVOID, | |
460 | ) -> DWORD>; | |
461 | ||
462 | #[repr(C)] | |
463 | pub struct CONDITION_VARIABLE { pub ptr: LPVOID } | |
464 | #[repr(C)] | |
465 | pub struct SRWLOCK { pub ptr: LPVOID } | |
466 | #[repr(C)] | |
467 | pub struct CRITICAL_SECTION { | |
468 | CriticalSectionDebug: LPVOID, | |
469 | LockCount: LONG, | |
470 | RecursionCount: LONG, | |
471 | OwningThread: HANDLE, | |
472 | LockSemaphore: HANDLE, | |
473 | SpinCount: ULONG_PTR | |
474 | } | |
475 | ||
c1a9b12d SL |
476 | #[repr(C)] |
477 | pub struct REPARSE_MOUNTPOINT_DATA_BUFFER { | |
92a42be0 SL |
478 | pub ReparseTag: DWORD, |
479 | pub ReparseDataLength: DWORD, | |
480 | pub Reserved: WORD, | |
481 | pub ReparseTargetLength: WORD, | |
482 | pub ReparseTargetMaximumLength: WORD, | |
483 | pub Reserved1: WORD, | |
484 | pub ReparseTarget: WCHAR, | |
c1a9b12d SL |
485 | } |
486 | ||
e9174d1e SL |
487 | #[repr(C)] |
488 | pub struct EXCEPTION_RECORD { | |
489 | pub ExceptionCode: DWORD, | |
490 | pub ExceptionFlags: DWORD, | |
491 | pub ExceptionRecord: *mut EXCEPTION_RECORD, | |
492 | pub ExceptionAddress: LPVOID, | |
493 | pub NumberParameters: DWORD, | |
494 | pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS] | |
495 | } | |
496 | ||
497 | #[repr(C)] | |
498 | pub struct EXCEPTION_POINTERS { | |
499 | pub ExceptionRecord: *mut EXCEPTION_RECORD, | |
92a42be0 | 500 | pub ContextRecord: *mut CONTEXT, |
e9174d1e SL |
501 | } |
502 | ||
503 | pub type PVECTORED_EXCEPTION_HANDLER = extern "system" | |
504 | fn(ExceptionInfo: *mut EXCEPTION_POINTERS) -> LONG; | |
c1a9b12d | 505 | |
92a42be0 SL |
506 | #[repr(C)] |
507 | pub struct GUID { | |
508 | pub Data1: DWORD, | |
509 | pub Data2: WORD, | |
510 | pub Data3: WORD, | |
511 | pub Data4: [BYTE; 8], | |
512 | } | |
513 | ||
514 | #[repr(C)] | |
515 | pub struct WSAPROTOCOLCHAIN { | |
516 | pub ChainLen: c_int, | |
517 | pub ChainEntries: [DWORD; MAX_PROTOCOL_CHAIN as usize], | |
518 | } | |
519 | ||
520 | #[repr(C)] | |
521 | pub struct SECURITY_ATTRIBUTES { | |
522 | pub nLength: DWORD, | |
523 | pub lpSecurityDescriptor: LPVOID, | |
524 | pub bInheritHandle: BOOL, | |
525 | } | |
526 | ||
527 | #[repr(C)] | |
528 | pub struct PROCESS_INFORMATION { | |
529 | pub hProcess: HANDLE, | |
530 | pub hThread: HANDLE, | |
531 | pub dwProcessId: DWORD, | |
532 | pub dwThreadId: DWORD, | |
533 | } | |
534 | ||
535 | #[repr(C)] | |
536 | pub struct STARTUPINFO { | |
537 | pub cb: DWORD, | |
538 | pub lpReserved: LPWSTR, | |
539 | pub lpDesktop: LPWSTR, | |
540 | pub lpTitle: LPWSTR, | |
541 | pub dwX: DWORD, | |
542 | pub dwY: DWORD, | |
543 | pub dwXSize: DWORD, | |
544 | pub dwYSize: DWORD, | |
545 | pub dwXCountChars: DWORD, | |
546 | pub dwYCountCharts: DWORD, | |
547 | pub dwFillAttribute: DWORD, | |
548 | pub dwFlags: DWORD, | |
549 | pub wShowWindow: WORD, | |
550 | pub cbReserved2: WORD, | |
551 | pub lpReserved2: LPBYTE, | |
552 | pub hStdInput: HANDLE, | |
553 | pub hStdOutput: HANDLE, | |
554 | pub hStdError: HANDLE, | |
555 | } | |
556 | ||
557 | #[repr(C)] | |
558 | pub struct SOCKADDR { | |
559 | pub sa_family: ADDRESS_FAMILY, | |
560 | pub sa_data: [CHAR; 14], | |
561 | } | |
562 | ||
563 | #[repr(C)] | |
564 | #[derive(Copy, Clone)] | |
565 | pub struct FILETIME { | |
566 | pub dwLowDateTime: DWORD, | |
567 | pub dwHighDateTime: DWORD, | |
568 | } | |
569 | ||
570 | #[repr(C)] | |
571 | pub struct OVERLAPPED { | |
572 | pub Internal: *mut c_ulong, | |
573 | pub InternalHigh: *mut c_ulong, | |
574 | pub Offset: DWORD, | |
575 | pub OffsetHigh: DWORD, | |
576 | pub hEvent: HANDLE, | |
577 | } | |
578 | ||
579 | #[repr(C)] | |
7453a54e | 580 | #[cfg(target_env = "msvc")] |
ea8adc8c | 581 | #[cfg(feature = "backtrace")] |
92a42be0 SL |
582 | pub struct SYMBOL_INFO { |
583 | pub SizeOfStruct: c_ulong, | |
584 | pub TypeIndex: c_ulong, | |
585 | pub Reserved: [u64; 2], | |
586 | pub Index: c_ulong, | |
587 | pub Size: c_ulong, | |
588 | pub ModBase: u64, | |
589 | pub Flags: c_ulong, | |
590 | pub Value: u64, | |
591 | pub Address: u64, | |
592 | pub Register: c_ulong, | |
593 | pub Scope: c_ulong, | |
594 | pub Tag: c_ulong, | |
595 | pub NameLen: c_ulong, | |
596 | pub MaxNameLen: c_ulong, | |
597 | // note that windows has this as 1, but it basically just means that | |
598 | // the name is inline at the end of the struct. For us, we just bump | |
599 | // the struct size up to MAX_SYM_NAME. | |
600 | pub Name: [c_char; MAX_SYM_NAME], | |
601 | } | |
602 | ||
603 | #[repr(C)] | |
7453a54e | 604 | #[cfg(target_env = "msvc")] |
ea8adc8c | 605 | #[cfg(feature = "backtrace")] |
92a42be0 SL |
606 | pub struct IMAGEHLP_LINE64 { |
607 | pub SizeOfStruct: u32, | |
608 | pub Key: *const c_void, | |
609 | pub LineNumber: u32, | |
610 | pub Filename: *const c_char, | |
611 | pub Address: u64, | |
612 | } | |
613 | ||
614 | #[repr(C)] | |
7453a54e | 615 | #[allow(dead_code)] // we only use some variants |
92a42be0 SL |
616 | pub enum ADDRESS_MODE { |
617 | AddrMode1616, | |
618 | AddrMode1632, | |
619 | AddrModeReal, | |
620 | AddrModeFlat, | |
621 | } | |
622 | ||
623 | #[repr(C)] | |
ea8adc8c | 624 | #[cfg(feature = "backtrace")] |
92a42be0 SL |
625 | pub struct ADDRESS64 { |
626 | pub Offset: u64, | |
627 | pub Segment: u16, | |
628 | pub Mode: ADDRESS_MODE, | |
629 | } | |
630 | ||
631 | #[repr(C)] | |
ea8adc8c | 632 | #[cfg(feature = "backtrace")] |
92a42be0 SL |
633 | pub struct STACKFRAME64 { |
634 | pub AddrPC: ADDRESS64, | |
635 | pub AddrReturn: ADDRESS64, | |
636 | pub AddrFrame: ADDRESS64, | |
637 | pub AddrStack: ADDRESS64, | |
638 | pub AddrBStore: ADDRESS64, | |
639 | pub FuncTableEntry: *mut c_void, | |
640 | pub Params: [u64; 4], | |
641 | pub Far: BOOL, | |
642 | pub Virtual: BOOL, | |
643 | pub Reserved: [u64; 3], | |
644 | pub KdHelp: KDHELP64, | |
645 | } | |
646 | ||
647 | #[repr(C)] | |
ea8adc8c | 648 | #[cfg(feature = "backtrace")] |
92a42be0 SL |
649 | pub struct KDHELP64 { |
650 | pub Thread: u64, | |
651 | pub ThCallbackStack: DWORD, | |
652 | pub ThCallbackBStore: DWORD, | |
653 | pub NextCallback: DWORD, | |
654 | pub FramePointer: DWORD, | |
655 | pub KiCallUserMode: u64, | |
656 | pub KeUserCallbackDispatcher: u64, | |
657 | pub SystemRangeStart: u64, | |
658 | pub KiUserExceptionDispatcher: u64, | |
659 | pub StackBase: u64, | |
660 | pub StackLimit: u64, | |
661 | pub Reserved: [u64; 5], | |
662 | } | |
663 | ||
664 | #[cfg(target_arch = "x86")] | |
665 | #[repr(C)] | |
666 | pub struct CONTEXT { | |
667 | pub ContextFlags: DWORD, | |
668 | pub Dr0: DWORD, | |
669 | pub Dr1: DWORD, | |
670 | pub Dr2: DWORD, | |
671 | pub Dr3: DWORD, | |
672 | pub Dr6: DWORD, | |
673 | pub Dr7: DWORD, | |
674 | pub FloatSave: FLOATING_SAVE_AREA, | |
675 | pub SegGs: DWORD, | |
676 | pub SegFs: DWORD, | |
677 | pub SegEs: DWORD, | |
678 | pub SegDs: DWORD, | |
679 | pub Edi: DWORD, | |
680 | pub Esi: DWORD, | |
681 | pub Ebx: DWORD, | |
682 | pub Edx: DWORD, | |
683 | pub Ecx: DWORD, | |
684 | pub Eax: DWORD, | |
685 | pub Ebp: DWORD, | |
686 | pub Eip: DWORD, | |
687 | pub SegCs: DWORD, | |
688 | pub EFlags: DWORD, | |
689 | pub Esp: DWORD, | |
690 | pub SegSs: DWORD, | |
691 | pub ExtendedRegisters: [u8; 512], | |
692 | } | |
693 | ||
694 | #[cfg(target_arch = "x86")] | |
695 | #[repr(C)] | |
696 | pub struct FLOATING_SAVE_AREA { | |
697 | pub ControlWord: DWORD, | |
698 | pub StatusWord: DWORD, | |
699 | pub TagWord: DWORD, | |
700 | pub ErrorOffset: DWORD, | |
701 | pub ErrorSelector: DWORD, | |
702 | pub DataOffset: DWORD, | |
703 | pub DataSelector: DWORD, | |
704 | pub RegisterArea: [u8; 80], | |
705 | pub Cr0NpxState: DWORD, | |
706 | } | |
707 | ||
708 | #[cfg(target_arch = "x86_64")] | |
709 | #[repr(C)] | |
710 | pub struct CONTEXT { | |
9cc50fc6 | 711 | _align_hack: [u64x2; 0], // FIXME align on 16-byte |
92a42be0 SL |
712 | pub P1Home: DWORDLONG, |
713 | pub P2Home: DWORDLONG, | |
714 | pub P3Home: DWORDLONG, | |
715 | pub P4Home: DWORDLONG, | |
716 | pub P5Home: DWORDLONG, | |
717 | pub P6Home: DWORDLONG, | |
718 | ||
719 | pub ContextFlags: DWORD, | |
720 | pub MxCsr: DWORD, | |
721 | ||
722 | pub SegCs: WORD, | |
723 | pub SegDs: WORD, | |
724 | pub SegEs: WORD, | |
725 | pub SegFs: WORD, | |
726 | pub SegGs: WORD, | |
727 | pub SegSs: WORD, | |
728 | pub EFlags: DWORD, | |
729 | ||
730 | pub Dr0: DWORDLONG, | |
731 | pub Dr1: DWORDLONG, | |
732 | pub Dr2: DWORDLONG, | |
733 | pub Dr3: DWORDLONG, | |
734 | pub Dr6: DWORDLONG, | |
735 | pub Dr7: DWORDLONG, | |
736 | ||
737 | pub Rax: DWORDLONG, | |
738 | pub Rcx: DWORDLONG, | |
739 | pub Rdx: DWORDLONG, | |
740 | pub Rbx: DWORDLONG, | |
741 | pub Rsp: DWORDLONG, | |
742 | pub Rbp: DWORDLONG, | |
743 | pub Rsi: DWORDLONG, | |
744 | pub Rdi: DWORDLONG, | |
745 | pub R8: DWORDLONG, | |
746 | pub R9: DWORDLONG, | |
747 | pub R10: DWORDLONG, | |
748 | pub R11: DWORDLONG, | |
749 | pub R12: DWORDLONG, | |
750 | pub R13: DWORDLONG, | |
751 | pub R14: DWORDLONG, | |
752 | pub R15: DWORDLONG, | |
753 | ||
754 | pub Rip: DWORDLONG, | |
755 | ||
756 | pub FltSave: FLOATING_SAVE_AREA, | |
757 | ||
758 | pub VectorRegister: [M128A; 26], | |
759 | pub VectorControl: DWORDLONG, | |
760 | ||
761 | pub DebugControl: DWORDLONG, | |
762 | pub LastBranchToRip: DWORDLONG, | |
763 | pub LastBranchFromRip: DWORDLONG, | |
764 | pub LastExceptionToRip: DWORDLONG, | |
765 | pub LastExceptionFromRip: DWORDLONG, | |
766 | } | |
767 | ||
768 | #[cfg(target_arch = "x86_64")] | |
769 | #[repr(C)] | |
770 | pub struct M128A { | |
9cc50fc6 | 771 | _align_hack: [u64x2; 0], // FIXME align on 16-byte |
92a42be0 SL |
772 | pub Low: c_ulonglong, |
773 | pub High: c_longlong | |
774 | } | |
775 | ||
776 | #[cfg(target_arch = "x86_64")] | |
777 | #[repr(C)] | |
778 | pub struct FLOATING_SAVE_AREA { | |
9cc50fc6 | 779 | _align_hack: [u64x2; 0], // FIXME align on 16-byte |
92a42be0 SL |
780 | _Dummy: [u8; 512] // FIXME: Fill this out |
781 | } | |
782 | ||
3b2f2976 XL |
783 | // FIXME(#43348): This structure is used for backtrace only, and a fake |
784 | // definition is provided here only to allow rustdoc to pass type-check. This | |
785 | // will not appear in the final documentation. This should be also defined for | |
786 | // other architectures supported by Windows such as ARM, and for historical | |
787 | // interest, maybe MIPS and PowerPC as well. | |
788 | #[cfg(all(dox, not(any(target_arch = "x86_64", target_arch = "x86"))))] | |
789 | pub enum CONTEXT {} | |
790 | ||
92a42be0 SL |
791 | #[repr(C)] |
792 | pub struct SOCKADDR_STORAGE_LH { | |
793 | pub ss_family: ADDRESS_FAMILY, | |
794 | pub __ss_pad1: [CHAR; 6], | |
795 | pub __ss_align: i64, | |
796 | pub __ss_pad2: [CHAR; 112], | |
797 | } | |
798 | ||
799 | #[repr(C)] | |
800 | pub struct ADDRINFOA { | |
801 | pub ai_flags: c_int, | |
802 | pub ai_family: c_int, | |
803 | pub ai_socktype: c_int, | |
804 | pub ai_protocol: c_int, | |
805 | pub ai_addrlen: size_t, | |
806 | pub ai_canonname: *mut c_char, | |
807 | pub ai_addr: *mut SOCKADDR, | |
808 | pub ai_next: *mut ADDRINFOA, | |
809 | } | |
810 | ||
811 | #[repr(C)] | |
812 | #[derive(Copy, Clone)] | |
813 | pub struct sockaddr_in { | |
814 | pub sin_family: ADDRESS_FAMILY, | |
815 | pub sin_port: USHORT, | |
816 | pub sin_addr: in_addr, | |
817 | pub sin_zero: [CHAR; 8], | |
818 | } | |
819 | ||
820 | #[repr(C)] | |
821 | #[derive(Copy, Clone)] | |
822 | pub struct sockaddr_in6 { | |
823 | pub sin6_family: ADDRESS_FAMILY, | |
824 | pub sin6_port: USHORT, | |
825 | pub sin6_flowinfo: c_ulong, | |
826 | pub sin6_addr: in6_addr, | |
827 | pub sin6_scope_id: c_ulong, | |
828 | } | |
829 | ||
830 | #[repr(C)] | |
831 | #[derive(Copy, Clone)] | |
832 | pub struct in_addr { | |
833 | pub s_addr: u32, | |
834 | } | |
835 | ||
836 | #[repr(C)] | |
837 | #[derive(Copy, Clone)] | |
838 | pub struct in6_addr { | |
839 | pub s6_addr: [u8; 16], | |
840 | } | |
841 | ||
92a42be0 SL |
842 | #[repr(C)] |
843 | #[derive(Copy, Clone)] | |
7453a54e | 844 | #[allow(dead_code)] // we only use some variants |
92a42be0 SL |
845 | pub enum EXCEPTION_DISPOSITION { |
846 | ExceptionContinueExecution, | |
847 | ExceptionContinueSearch, | |
848 | ExceptionNestedException, | |
849 | ExceptionCollidedUnwind | |
850 | } | |
851 | ||
32a655c1 SL |
852 | #[repr(C)] |
853 | #[derive(Copy, Clone)] | |
854 | pub struct CONSOLE_READCONSOLE_CONTROL { | |
855 | pub nLength: ULONG, | |
856 | pub nInitialChars: ULONG, | |
857 | pub dwCtrlWakeupMask: ULONG, | |
858 | pub dwControlKeyState: ULONG, | |
859 | } | |
860 | pub type PCONSOLE_READCONSOLE_CONTROL = *mut CONSOLE_READCONSOLE_CONTROL; | |
861 | ||
041b39d2 XL |
862 | #[repr(C)] |
863 | #[derive(Copy)] | |
864 | pub struct fd_set { | |
865 | pub fd_count: c_uint, | |
866 | pub fd_array: [SOCKET; FD_SETSIZE], | |
867 | } | |
868 | ||
869 | impl Clone for fd_set { | |
870 | fn clone(&self) -> fd_set { | |
871 | *self | |
872 | } | |
873 | } | |
874 | ||
875 | #[repr(C)] | |
876 | #[derive(Copy, Clone)] | |
877 | pub struct timeval { | |
878 | pub tv_sec: c_long, | |
879 | pub tv_usec: c_long, | |
880 | } | |
881 | ||
1a4d82fc | 882 | extern "system" { |
92a42be0 SL |
883 | pub fn WSAStartup(wVersionRequested: WORD, |
884 | lpWSAData: LPWSADATA) -> c_int; | |
885 | pub fn WSACleanup() -> c_int; | |
886 | pub fn WSAGetLastError() -> c_int; | |
887 | pub fn WSADuplicateSocketW(s: SOCKET, | |
888 | dwProcessId: DWORD, | |
85aaf69f | 889 | lpProtocolInfo: LPWSAPROTOCOL_INFO) |
92a42be0 SL |
890 | -> c_int; |
891 | pub fn GetCurrentProcessId() -> DWORD; | |
892 | pub fn WSASocketW(af: c_int, | |
893 | kind: c_int, | |
894 | protocol: c_int, | |
85aaf69f SL |
895 | lpProtocolInfo: LPWSAPROTOCOL_INFO, |
896 | g: GROUP, | |
92a42be0 | 897 | dwFlags: DWORD) -> SOCKET; |
54a0048b | 898 | pub fn ioctlsocket(s: SOCKET, cmd: c_long, argp: *mut c_ulong) -> c_int; |
c1a9b12d SL |
899 | pub fn InitializeCriticalSection(CriticalSection: *mut CRITICAL_SECTION); |
900 | pub fn EnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION); | |
901 | pub fn TryEnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION) -> BOOLEAN; | |
902 | pub fn LeaveCriticalSection(CriticalSection: *mut CRITICAL_SECTION); | |
903 | pub fn DeleteCriticalSection(CriticalSection: *mut CRITICAL_SECTION); | |
1a4d82fc | 904 | |
92a42be0 SL |
905 | pub fn ReadConsoleW(hConsoleInput: HANDLE, |
906 | lpBuffer: LPVOID, | |
907 | nNumberOfCharsToRead: DWORD, | |
908 | lpNumberOfCharsRead: LPDWORD, | |
32a655c1 | 909 | pInputControl: PCONSOLE_READCONSOLE_CONTROL) -> BOOL; |
92a42be0 SL |
910 | |
911 | pub fn WriteConsoleW(hConsoleOutput: HANDLE, | |
912 | lpBuffer: LPCVOID, | |
913 | nNumberOfCharsToWrite: DWORD, | |
914 | lpNumberOfCharsWritten: LPDWORD, | |
915 | lpReserved: LPVOID) -> BOOL; | |
916 | ||
917 | pub fn GetConsoleMode(hConsoleHandle: HANDLE, | |
918 | lpMode: LPDWORD) -> BOOL; | |
92a42be0 SL |
919 | pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL; |
920 | pub fn SetFileAttributesW(lpFileName: LPCWSTR, | |
921 | dwFileAttributes: DWORD) -> BOOL; | |
922 | pub fn GetFileInformationByHandle(hFile: HANDLE, | |
85aaf69f | 923 | lpFileInformation: LPBY_HANDLE_FILE_INFORMATION) |
92a42be0 SL |
924 | -> BOOL; |
925 | ||
926 | pub fn SetLastError(dwErrCode: DWORD); | |
927 | pub fn GetCommandLineW() -> *mut LPCWSTR; | |
928 | pub fn LocalFree(ptr: *mut c_void); | |
929 | pub fn CommandLineToArgvW(lpCmdLine: *mut LPCWSTR, | |
930 | pNumArgs: *mut c_int) -> *mut *mut u16; | |
931 | pub fn GetTempPathW(nBufferLength: DWORD, | |
932 | lpBuffer: LPCWSTR) -> DWORD; | |
933 | pub fn OpenProcessToken(ProcessHandle: HANDLE, | |
934 | DesiredAccess: DWORD, | |
935 | TokenHandle: *mut HANDLE) -> BOOL; | |
936 | pub fn GetCurrentProcess() -> HANDLE; | |
937 | pub fn GetCurrentThread() -> HANDLE; | |
938 | pub fn GetStdHandle(which: DWORD) -> HANDLE; | |
939 | pub fn ExitProcess(uExitCode: c_uint) -> !; | |
940 | pub fn DeviceIoControl(hDevice: HANDLE, | |
941 | dwIoControlCode: DWORD, | |
942 | lpInBuffer: LPVOID, | |
943 | nInBufferSize: DWORD, | |
944 | lpOutBuffer: LPVOID, | |
945 | nOutBufferSize: DWORD, | |
946 | lpBytesReturned: LPDWORD, | |
947 | lpOverlapped: LPOVERLAPPED) -> BOOL; | |
92a42be0 SL |
948 | pub fn CreateThread(lpThreadAttributes: LPSECURITY_ATTRIBUTES, |
949 | dwStackSize: SIZE_T, | |
950 | lpStartAddress: extern "system" fn(*mut c_void) | |
951 | -> DWORD, | |
952 | lpParameter: LPVOID, | |
953 | dwCreationFlags: DWORD, | |
954 | lpThreadId: LPDWORD) -> HANDLE; | |
955 | pub fn WaitForSingleObject(hHandle: HANDLE, | |
956 | dwMilliseconds: DWORD) -> DWORD; | |
957 | pub fn SwitchToThread() -> BOOL; | |
958 | pub fn Sleep(dwMilliseconds: DWORD); | |
959 | pub fn GetProcessId(handle: HANDLE) -> DWORD; | |
960 | pub fn GetUserProfileDirectoryW(hToken: HANDLE, | |
8bb4bdeb | 961 | lpProfileDir: LPWSTR, |
92a42be0 SL |
962 | lpcchSize: *mut DWORD) -> BOOL; |
963 | pub fn SetHandleInformation(hObject: HANDLE, | |
964 | dwMask: DWORD, | |
965 | dwFlags: DWORD) -> BOOL; | |
966 | pub fn CopyFileExW(lpExistingFileName: LPCWSTR, | |
967 | lpNewFileName: LPCWSTR, | |
c1a9b12d | 968 | lpProgressRoutine: LPPROGRESS_ROUTINE, |
92a42be0 | 969 | lpData: LPVOID, |
c1a9b12d | 970 | pbCancel: LPBOOL, |
92a42be0 | 971 | dwCopyFlags: DWORD) -> BOOL; |
e9174d1e SL |
972 | pub fn AddVectoredExceptionHandler(FirstHandler: ULONG, |
973 | VectoredHandler: PVECTORED_EXCEPTION_HANDLER) | |
974 | -> LPVOID; | |
92a42be0 SL |
975 | pub fn FormatMessageW(flags: DWORD, |
976 | lpSrc: LPVOID, | |
977 | msgId: DWORD, | |
978 | langId: DWORD, | |
979 | buf: LPWSTR, | |
980 | nsize: DWORD, | |
981 | args: *const c_void) | |
982 | -> DWORD; | |
983 | pub fn TlsAlloc() -> DWORD; | |
92a42be0 SL |
984 | pub fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID; |
985 | pub fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL; | |
986 | pub fn GetLastError() -> DWORD; | |
987 | pub fn QueryPerformanceFrequency(lpFrequency: *mut LARGE_INTEGER) -> BOOL; | |
988 | pub fn QueryPerformanceCounter(lpPerformanceCount: *mut LARGE_INTEGER) | |
989 | -> BOOL; | |
990 | pub fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: LPDWORD) -> BOOL; | |
991 | pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) -> BOOL; | |
992 | pub fn CreateProcessW(lpApplicationName: LPCWSTR, | |
993 | lpCommandLine: LPWSTR, | |
994 | lpProcessAttributes: LPSECURITY_ATTRIBUTES, | |
995 | lpThreadAttributes: LPSECURITY_ATTRIBUTES, | |
996 | bInheritHandles: BOOL, | |
997 | dwCreationFlags: DWORD, | |
998 | lpEnvironment: LPVOID, | |
999 | lpCurrentDirectory: LPCWSTR, | |
1000 | lpStartupInfo: LPSTARTUPINFO, | |
1001 | lpProcessInformation: LPPROCESS_INFORMATION) | |
1002 | -> BOOL; | |
1003 | pub fn GetEnvironmentVariableW(n: LPCWSTR, v: LPWSTR, nsize: DWORD) -> DWORD; | |
1004 | pub fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL; | |
1005 | pub fn GetEnvironmentStringsW() -> LPWCH; | |
1006 | pub fn FreeEnvironmentStringsW(env_ptr: LPWCH) -> BOOL; | |
1007 | pub fn GetModuleFileNameW(hModule: HMODULE, | |
1008 | lpFilename: LPWSTR, | |
1009 | nSize: DWORD) | |
1010 | -> DWORD; | |
1011 | pub fn CreateDirectoryW(lpPathName: LPCWSTR, | |
1012 | lpSecurityAttributes: LPSECURITY_ATTRIBUTES) | |
1013 | -> BOOL; | |
1014 | pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL; | |
1015 | pub fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: LPWSTR) -> DWORD; | |
1016 | pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL; | |
32a655c1 SL |
1017 | pub fn WideCharToMultiByte(CodePage: UINT, |
1018 | dwFlags: DWORD, | |
1019 | lpWideCharStr: LPCWSTR, | |
1020 | cchWideChar: c_int, | |
1021 | lpMultiByteStr: LPSTR, | |
1022 | cbMultiByte: c_int, | |
1023 | lpDefaultChar: LPCSTR, | |
1024 | lpUsedDefaultChar: LPBOOL) -> c_int; | |
92a42be0 SL |
1025 | |
1026 | pub fn closesocket(socket: SOCKET) -> c_int; | |
1027 | pub fn recv(socket: SOCKET, buf: *mut c_void, len: c_int, | |
1028 | flags: c_int) -> c_int; | |
1029 | pub fn send(socket: SOCKET, buf: *const c_void, len: c_int, | |
1030 | flags: c_int) -> c_int; | |
1031 | pub fn recvfrom(socket: SOCKET, | |
1032 | buf: *mut c_void, | |
1033 | len: c_int, | |
1034 | flags: c_int, | |
1035 | addr: *mut SOCKADDR, | |
1036 | addrlen: *mut c_int) | |
1037 | -> c_int; | |
1038 | pub fn sendto(socket: SOCKET, | |
1039 | buf: *const c_void, | |
1040 | len: c_int, | |
1041 | flags: c_int, | |
1042 | addr: *const SOCKADDR, | |
1043 | addrlen: c_int) | |
1044 | -> c_int; | |
1045 | pub fn shutdown(socket: SOCKET, how: c_int) -> c_int; | |
1046 | pub fn accept(socket: SOCKET, | |
1047 | address: *mut SOCKADDR, | |
1048 | address_len: *mut c_int) | |
1049 | -> SOCKET; | |
1050 | pub fn DuplicateHandle(hSourceProcessHandle: HANDLE, | |
1051 | hSourceHandle: HANDLE, | |
1052 | hTargetProcessHandle: HANDLE, | |
1053 | lpTargetHandle: LPHANDLE, | |
1054 | dwDesiredAccess: DWORD, | |
1055 | bInheritHandle: BOOL, | |
1056 | dwOptions: DWORD) | |
1057 | -> BOOL; | |
1058 | pub fn ReadFile(hFile: HANDLE, | |
1059 | lpBuffer: LPVOID, | |
1060 | nNumberOfBytesToRead: DWORD, | |
1061 | lpNumberOfBytesRead: LPDWORD, | |
1062 | lpOverlapped: LPOVERLAPPED) | |
1063 | -> BOOL; | |
1064 | pub fn WriteFile(hFile: HANDLE, | |
1065 | lpBuffer: LPVOID, | |
1066 | nNumberOfBytesToWrite: DWORD, | |
1067 | lpNumberOfBytesWritten: LPDWORD, | |
1068 | lpOverlapped: LPOVERLAPPED) | |
1069 | -> BOOL; | |
1070 | pub fn CloseHandle(hObject: HANDLE) -> BOOL; | |
1071 | pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR, | |
1072 | lpTargetFileName: LPCWSTR, | |
1073 | lpSecurityAttributes: LPSECURITY_ATTRIBUTES) | |
1074 | -> BOOL; | |
1075 | pub fn MoveFileExW(lpExistingFileName: LPCWSTR, | |
1076 | lpNewFileName: LPCWSTR, | |
1077 | dwFlags: DWORD) | |
1078 | -> BOOL; | |
1079 | pub fn SetFilePointerEx(hFile: HANDLE, | |
1080 | liDistanceToMove: LARGE_INTEGER, | |
1081 | lpNewFilePointer: PLARGE_INTEGER, | |
1082 | dwMoveMethod: DWORD) | |
1083 | -> BOOL; | |
1084 | pub fn FlushFileBuffers(hFile: HANDLE) -> BOOL; | |
1085 | pub fn CreateFileW(lpFileName: LPCWSTR, | |
1086 | dwDesiredAccess: DWORD, | |
1087 | dwShareMode: DWORD, | |
1088 | lpSecurityAttributes: LPSECURITY_ATTRIBUTES, | |
1089 | dwCreationDisposition: DWORD, | |
1090 | dwFlagsAndAttributes: DWORD, | |
1091 | hTemplateFile: HANDLE) | |
1092 | -> HANDLE; | |
1093 | ||
1094 | pub fn FindFirstFileW(fileName: LPCWSTR, | |
1095 | findFileData: LPWIN32_FIND_DATAW) | |
1096 | -> HANDLE; | |
1097 | pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW) | |
1098 | -> BOOL; | |
1099 | pub fn FindClose(findFile: HANDLE) -> BOOL; | |
ea8adc8c | 1100 | #[cfg(feature = "backtrace")] |
92a42be0 SL |
1101 | pub fn RtlCaptureContext(ctx: *mut CONTEXT); |
1102 | pub fn getsockopt(s: SOCKET, | |
1103 | level: c_int, | |
1104 | optname: c_int, | |
1105 | optval: *mut c_char, | |
1106 | optlen: *mut c_int) | |
1107 | -> c_int; | |
1108 | pub fn setsockopt(s: SOCKET, | |
1109 | level: c_int, | |
1110 | optname: c_int, | |
1111 | optval: *const c_void, | |
1112 | optlen: c_int) | |
1113 | -> c_int; | |
1114 | pub fn getsockname(socket: SOCKET, | |
1115 | address: *mut SOCKADDR, | |
1116 | address_len: *mut c_int) | |
1117 | -> c_int; | |
1118 | pub fn getpeername(socket: SOCKET, | |
1119 | address: *mut SOCKADDR, | |
1120 | address_len: *mut c_int) | |
1121 | -> c_int; | |
1122 | pub fn bind(socket: SOCKET, address: *const SOCKADDR, | |
1123 | address_len: socklen_t) -> c_int; | |
1124 | pub fn listen(socket: SOCKET, backlog: c_int) -> c_int; | |
1125 | pub fn connect(socket: SOCKET, address: *const SOCKADDR, len: c_int) | |
1126 | -> c_int; | |
1127 | pub fn getaddrinfo(node: *const c_char, service: *const c_char, | |
1128 | hints: *const ADDRINFOA, | |
1129 | res: *mut *mut ADDRINFOA) -> c_int; | |
1130 | pub fn freeaddrinfo(res: *mut ADDRINFOA); | |
92a42be0 | 1131 | |
ea8adc8c | 1132 | #[cfg(feature = "backtrace")] |
92a42be0 | 1133 | pub fn LoadLibraryW(name: LPCWSTR) -> HMODULE; |
ea8adc8c | 1134 | #[cfg(feature = "backtrace")] |
54a0048b | 1135 | pub fn FreeLibrary(handle: HMODULE) -> BOOL; |
92a42be0 SL |
1136 | pub fn GetProcAddress(handle: HMODULE, |
1137 | name: LPCSTR) -> *mut c_void; | |
92a42be0 SL |
1138 | pub fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE; |
1139 | pub fn CryptAcquireContextA(phProv: *mut HCRYPTPROV, | |
1140 | pszContainer: LPCSTR, | |
1141 | pszProvider: LPCSTR, | |
1142 | dwProvType: DWORD, | |
1143 | dwFlags: DWORD) -> BOOL; | |
1144 | pub fn CryptGenRandom(hProv: HCRYPTPROV, | |
1145 | dwLen: DWORD, | |
1146 | pbBuffer: *mut BYTE) -> BOOL; | |
1147 | pub fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL; | |
1148 | ||
92a42be0 | 1149 | pub fn GetSystemTimeAsFileTime(lpSystemTimeAsFileTime: LPFILETIME); |
54a0048b SL |
1150 | |
1151 | pub fn CreateEventW(lpEventAttributes: LPSECURITY_ATTRIBUTES, | |
1152 | bManualReset: BOOL, | |
1153 | bInitialState: BOOL, | |
1154 | lpName: LPCWSTR) -> HANDLE; | |
1155 | pub fn WaitForMultipleObjects(nCount: DWORD, | |
1156 | lpHandles: *const HANDLE, | |
1157 | bWaitAll: BOOL, | |
1158 | dwMilliseconds: DWORD) -> DWORD; | |
1159 | pub fn CreateNamedPipeW(lpName: LPCWSTR, | |
1160 | dwOpenMode: DWORD, | |
1161 | dwPipeMode: DWORD, | |
1162 | nMaxInstances: DWORD, | |
1163 | nOutBufferSize: DWORD, | |
1164 | nInBufferSize: DWORD, | |
1165 | nDefaultTimeOut: DWORD, | |
1166 | lpSecurityAttributes: LPSECURITY_ATTRIBUTES) | |
1167 | -> HANDLE; | |
1168 | pub fn CancelIo(handle: HANDLE) -> BOOL; | |
1169 | pub fn GetOverlappedResult(hFile: HANDLE, | |
1170 | lpOverlapped: LPOVERLAPPED, | |
1171 | lpNumberOfBytesTransferred: LPDWORD, | |
1172 | bWait: BOOL) -> BOOL; | |
041b39d2 XL |
1173 | pub fn select(nfds: c_int, |
1174 | readfds: *mut fd_set, | |
1175 | writefds: *mut fd_set, | |
1176 | exceptfds: *mut fd_set, | |
1177 | timeout: *const timeval) -> c_int; | |
c1a9b12d SL |
1178 | } |
1179 | ||
ea8adc8c XL |
1180 | // Functions that aren't available on every version of Windows that we support, |
1181 | // but we still use them and just provide some form of a fallback implementation. | |
c1a9b12d SL |
1182 | compat_fn! { |
1183 | kernel32: | |
1184 | ||
1185 | pub fn CreateSymbolicLinkW(_lpSymlinkFileName: LPCWSTR, | |
1186 | _lpTargetFileName: LPCWSTR, | |
1187 | _dwFlags: DWORD) -> BOOLEAN { | |
1188 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 | |
1189 | } | |
1190 | pub fn GetFinalPathNameByHandleW(_hFile: HANDLE, | |
1191 | _lpszFilePath: LPCWSTR, | |
1192 | _cchFilePath: DWORD, | |
1193 | _dwFlags: DWORD) -> DWORD { | |
1194 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 | |
1195 | } | |
c1a9b12d SL |
1196 | pub fn SetThreadStackGuarantee(_size: *mut c_ulong) -> BOOL { |
1197 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 | |
1198 | } | |
ea8adc8c XL |
1199 | pub fn SetThreadDescription(hThread: HANDLE, |
1200 | lpThreadDescription: LPCWSTR) -> HRESULT { | |
1201 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); E_NOTIMPL | |
1202 | } | |
c1a9b12d SL |
1203 | pub fn SetFileInformationByHandle(_hFile: HANDLE, |
1204 | _FileInformationClass: FILE_INFO_BY_HANDLE_CLASS, | |
1205 | _lpFileInformation: LPVOID, | |
1206 | _dwBufferSize: DWORD) -> BOOL { | |
1207 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 | |
1208 | } | |
1209 | pub fn SleepConditionVariableSRW(ConditionVariable: PCONDITION_VARIABLE, | |
1210 | SRWLock: PSRWLOCK, | |
1211 | dwMilliseconds: DWORD, | |
1212 | Flags: ULONG) -> BOOL { | |
1213 | panic!("condition variables not available") | |
1214 | } | |
1215 | pub fn WakeConditionVariable(ConditionVariable: PCONDITION_VARIABLE) | |
1216 | -> () { | |
1217 | panic!("condition variables not available") | |
1218 | } | |
1219 | pub fn WakeAllConditionVariable(ConditionVariable: PCONDITION_VARIABLE) | |
1220 | -> () { | |
1221 | panic!("condition variables not available") | |
1222 | } | |
1223 | pub fn AcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> () { | |
1224 | panic!("rwlocks not available") | |
1225 | } | |
1226 | pub fn AcquireSRWLockShared(SRWLock: PSRWLOCK) -> () { | |
1227 | panic!("rwlocks not available") | |
1228 | } | |
1229 | pub fn ReleaseSRWLockExclusive(SRWLock: PSRWLOCK) -> () { | |
1230 | panic!("rwlocks not available") | |
1231 | } | |
1232 | pub fn ReleaseSRWLockShared(SRWLock: PSRWLOCK) -> () { | |
1233 | panic!("rwlocks not available") | |
1234 | } | |
1235 | pub fn TryAcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> BOOLEAN { | |
1236 | panic!("rwlocks not available") | |
1237 | } | |
1238 | pub fn TryAcquireSRWLockShared(SRWLock: PSRWLOCK) -> BOOLEAN { | |
1239 | panic!("rwlocks not available") | |
1240 | } | |
1a4d82fc | 1241 | } |
32a655c1 SL |
1242 | |
1243 | #[cfg(target_env = "gnu")] | |
1244 | mod gnu { | |
1245 | use super::*; | |
1246 | ||
1247 | pub const PROCESS_QUERY_INFORMATION: DWORD = 0x0400; | |
1248 | ||
1249 | pub const CP_ACP: UINT = 0; | |
1250 | ||
1251 | pub const WC_NO_BEST_FIT_CHARS: DWORD = 0x00000400; | |
1252 | ||
1253 | extern "system" { | |
1254 | pub fn OpenProcess(dwDesiredAccess: DWORD, | |
1255 | bInheritHandle: BOOL, | |
1256 | dwProcessId: DWORD) -> HANDLE; | |
1257 | } | |
1258 | ||
1259 | compat_fn! { | |
1260 | kernel32: | |
1261 | ||
1262 | pub fn QueryFullProcessImageNameW(_hProcess: HANDLE, | |
1263 | _dwFlags: DWORD, | |
1264 | _lpExeName: LPWSTR, | |
1265 | _lpdwSize: LPDWORD) -> BOOL { | |
1266 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 | |
1267 | } | |
1268 | } | |
1269 | } | |
1270 | ||
1271 | #[cfg(target_env = "gnu")] | |
1272 | pub use self::gnu::*; |