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.
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.
11 //! C definitions used by libnative that don't belong in liblibc
14 #![cfg_attr(test, allow(dead_code))]
15 #![unstable(issue = "0", feature = "windows_c")]
17 use os::raw::{c_int, c_uint, c_ulong, c_long, c_longlong, c_ushort,};
18 use os::raw::{c_char, c_ulonglong};
19 use libc::{wchar_t, size_t, c_void};
24 #[cfg(target_arch = "x86_64")]
25 struct u64x2(u64, u64);
27 pub use self::FILE_INFO_BY_HANDLE_CLASS::*;
28 pub use self::EXCEPTION_DISPOSITION::*;
30 pub type DWORD = c_ulong;
31 pub type HANDLE = LPVOID;
32 pub type HINSTANCE = HANDLE;
33 pub type HMODULE = HINSTANCE;
34 pub type BOOL = c_int;
36 pub type BOOLEAN = BYTE;
37 pub type GROUP = c_uint;
38 pub type LONG_PTR = isize;
39 pub type LARGE_INTEGER = c_longlong;
40 pub type LONG = c_long;
41 pub type UINT = c_uint;
43 pub type USHORT = c_ushort;
44 pub type SIZE_T = usize;
46 pub type CHAR = c_char;
47 pub type HCRYPTPROV = LONG_PTR;
48 pub type ULONG_PTR = c_ulonglong;
49 pub type ULONG = c_ulong;
50 pub type ULONGLONG = u64;
51 pub type DWORDLONG = ULONGLONG;
53 pub type LPBOOL = *mut BOOL;
54 pub type LPBYTE = *mut BYTE;
55 pub type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION;
56 pub type LPCSTR = *const CHAR;
57 pub type LPCVOID = *const c_void;
58 pub type LPCWSTR = *const WCHAR;
59 pub type LPDWORD = *mut DWORD;
60 pub type LPHANDLE = *mut HANDLE;
61 pub type LPOVERLAPPED = *mut OVERLAPPED;
62 pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION;
63 pub type LPSECURITY_ATTRIBUTES = *mut SECURITY_ATTRIBUTES;
64 pub type LPSTARTUPINFO = *mut STARTUPINFO;
65 pub type LPVOID = *mut c_void;
66 pub type LPWCH = *mut WCHAR;
67 pub type LPWIN32_FIND_DATAW = *mut WIN32_FIND_DATAW;
68 pub type LPWSADATA = *mut WSADATA;
69 pub type LPWSAPROTOCOLCHAIN = *mut WSAPROTOCOLCHAIN;
70 pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO;
71 pub type LPWSTR = *mut WCHAR;
72 pub type LPFILETIME = *mut FILETIME;
74 pub type PCONDITION_VARIABLE = *mut CONDITION_VARIABLE;
75 pub type PLARGE_INTEGER = *mut c_longlong;
76 pub type PSRWLOCK = *mut SRWLOCK;
78 pub type SOCKET = ::os::windows::raw::SOCKET;
79 pub type socklen_t = c_int;
80 pub type ADDRESS_FAMILY = USHORT;
82 pub const TRUE: BOOL = 1;
83 pub const FALSE: BOOL = 0;
85 pub const FILE_ATTRIBUTE_READONLY: DWORD = 0x1;
86 pub const FILE_ATTRIBUTE_DIRECTORY: DWORD = 0x10;
87 pub const FILE_ATTRIBUTE_REPARSE_POINT: DWORD = 0x400;
89 pub const FILE_SHARE_DELETE: DWORD = 0x4;
90 pub const FILE_SHARE_READ: DWORD = 0x1;
91 pub const FILE_SHARE_WRITE: DWORD = 0x2;
93 pub const CREATE_ALWAYS: DWORD = 2;
94 pub const CREATE_NEW: DWORD = 1;
95 pub const OPEN_ALWAYS: DWORD = 4;
96 pub const OPEN_EXISTING: DWORD = 3;
97 pub const TRUNCATE_EXISTING: DWORD = 5;
99 pub const FILE_WRITE_DATA: DWORD = 0x00000002;
100 pub const FILE_APPEND_DATA: DWORD = 0x00000004;
101 pub const FILE_WRITE_EA: DWORD = 0x00000010;
102 pub const FILE_WRITE_ATTRIBUTES: DWORD = 0x00000100;
103 pub const READ_CONTROL: DWORD = 0x00020000;
104 pub const SYNCHRONIZE: DWORD = 0x00100000;
105 pub const GENERIC_READ: DWORD = 0x80000000;
106 pub const GENERIC_WRITE: DWORD = 0x40000000;
107 pub const STANDARD_RIGHTS_WRITE: DWORD = READ_CONTROL;
108 pub const FILE_GENERIC_WRITE: DWORD = STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA |
109 FILE_WRITE_ATTRIBUTES |
114 pub const FILE_FLAG_OPEN_REPARSE_POINT: DWORD = 0x00200000;
115 pub const FILE_FLAG_BACKUP_SEMANTICS: DWORD = 0x02000000;
116 pub const SECURITY_SQOS_PRESENT: DWORD = 0x00100000;
118 pub const FIONBIO: c_ulong = 0x8004667e;
122 pub struct WIN32_FIND_DATAW {
123 pub dwFileAttributes: DWORD,
124 pub ftCreationTime: FILETIME,
125 pub ftLastAccessTime: FILETIME,
126 pub ftLastWriteTime: FILETIME,
127 pub nFileSizeHigh: DWORD,
128 pub nFileSizeLow: DWORD,
129 pub dwReserved0: DWORD,
130 pub dwReserved1: DWORD,
131 pub cFileName: [wchar_t; 260], // #define MAX_PATH 260
132 pub cAlternateFileName: [wchar_t; 14],
134 impl Clone for WIN32_FIND_DATAW {
135 fn clone(&self) -> Self { *self }
138 pub const WSA_FLAG_OVERLAPPED: DWORD = 0x01;
140 pub const WSADESCRIPTION_LEN: usize = 256;
141 pub const WSASYS_STATUS_LEN: usize = 128;
142 pub const WSAPROTOCOL_LEN: DWORD = 255;
143 pub const INVALID_SOCKET: SOCKET = !0;
145 pub const WSAEACCES: c_int = 10013;
146 pub const WSAEINVAL: c_int = 10022;
147 pub const WSAEWOULDBLOCK: c_int = 10035;
148 pub const WSAEADDRINUSE: c_int = 10048;
149 pub const WSAEADDRNOTAVAIL: c_int = 10049;
150 pub const WSAECONNABORTED: c_int = 10053;
151 pub const WSAECONNRESET: c_int = 10054;
152 pub const WSAENOTCONN: c_int = 10057;
153 pub const WSAESHUTDOWN: c_int = 10058;
154 pub const WSAETIMEDOUT: c_int = 10060;
155 pub const WSAECONNREFUSED: c_int = 10061;
157 pub const MAX_PROTOCOL_CHAIN: DWORD = 7;
159 pub const TOKEN_READ: DWORD = 0x20008;
160 pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024;
161 pub const FSCTL_GET_REPARSE_POINT: DWORD = 0x900a8;
162 pub const IO_REPARSE_TAG_SYMLINK: DWORD = 0xa000000c;
163 pub const IO_REPARSE_TAG_MOUNT_POINT: DWORD = 0xa0000003;
164 pub const SYMLINK_FLAG_RELATIVE: DWORD = 0x00000001;
165 pub const FSCTL_SET_REPARSE_POINT: DWORD = 0x900a4;
167 pub const SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 0x1;
169 // Note that these are not actually HANDLEs, just values to pass to GetStdHandle
170 pub const STD_INPUT_HANDLE: DWORD = -10i32 as DWORD;
171 pub const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
172 pub const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
174 pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001;
176 pub const PROGRESS_CONTINUE: DWORD = 0;
178 pub const ERROR_FILE_NOT_FOUND: DWORD = 2;
179 pub const ERROR_PATH_NOT_FOUND: DWORD = 3;
180 pub const ERROR_ACCESS_DENIED: DWORD = 5;
181 pub const ERROR_INVALID_HANDLE: DWORD = 6;
182 pub const ERROR_NO_MORE_FILES: DWORD = 18;
183 pub const ERROR_HANDLE_EOF: DWORD = 38;
184 pub const ERROR_BROKEN_PIPE: DWORD = 109;
185 pub const ERROR_CALL_NOT_IMPLEMENTED: DWORD = 120;
186 pub const ERROR_INSUFFICIENT_BUFFER: DWORD = 122;
187 pub const ERROR_ALREADY_EXISTS: DWORD = 183;
188 pub const ERROR_NO_DATA: DWORD = 232;
189 pub const ERROR_ENVVAR_NOT_FOUND: DWORD = 203;
190 pub const ERROR_OPERATION_ABORTED: DWORD = 995;
191 pub const ERROR_IO_PENDING: DWORD = 997;
192 pub const ERROR_TIMEOUT: DWORD = 0x5B4;
194 pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE;
196 pub const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000;
197 pub const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200;
199 pub const TLS_OUT_OF_INDEXES: DWORD = 0xFFFFFFFF;
201 pub const DLL_THREAD_DETACH: DWORD = 3;
202 pub const DLL_PROCESS_DETACH: DWORD = 0;
204 pub const INFINITE: DWORD = !0;
206 pub const DUPLICATE_SAME_ACCESS: DWORD = 0x00000002;
208 pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE {
209 ptr: ptr::null_mut(),
211 pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: ptr::null_mut() };
213 pub const DETACHED_PROCESS: DWORD = 0x00000008;
214 pub const CREATE_NEW_PROCESS_GROUP: DWORD = 0x00000200;
215 pub const CREATE_UNICODE_ENVIRONMENT: DWORD = 0x00000400;
216 pub const STARTF_USESTDHANDLES: DWORD = 0x00000100;
218 pub const AF_INET: c_int = 2;
219 pub const AF_INET6: c_int = 23;
220 pub const SD_BOTH: c_int = 2;
221 pub const SD_RECEIVE: c_int = 0;
222 pub const SD_SEND: c_int = 1;
223 pub const SOCK_DGRAM: c_int = 2;
224 pub const SOCK_STREAM: c_int = 1;
225 pub const SOL_SOCKET: c_int = 0xffff;
226 pub const SO_RCVTIMEO: c_int = 0x1006;
227 pub const SO_SNDTIMEO: c_int = 0x1005;
228 pub const SO_REUSEADDR: c_int = 0x0004;
229 pub const IPPROTO_IP: c_int = 0;
230 pub const IPPROTO_TCP: c_int = 6;
231 pub const IPPROTO_IPV6: c_int = 41;
232 pub const TCP_NODELAY: c_int = 0x0001;
233 pub const IP_TTL: c_int = 4;
234 pub const IPV6_V6ONLY: c_int = 27;
235 pub const SO_ERROR: c_int = 0x1007;
236 pub const SO_BROADCAST: c_int = 0x0020;
237 pub const IP_MULTICAST_LOOP: c_int = 11;
238 pub const IPV6_MULTICAST_LOOP: c_int = 11;
239 pub const IP_MULTICAST_TTL: c_int = 10;
240 pub const IP_ADD_MEMBERSHIP: c_int = 12;
241 pub const IP_DROP_MEMBERSHIP: c_int = 13;
242 pub const IPV6_ADD_MEMBERSHIP: c_int = 12;
243 pub const IPV6_DROP_MEMBERSHIP: c_int = 13;
247 pub imr_multiaddr: in_addr,
248 pub imr_interface: in_addr,
252 pub struct ipv6_mreq {
253 pub ipv6mr_multiaddr: in6_addr,
254 pub ipv6mr_interface: c_uint,
257 pub const VOLUME_NAME_DOS: DWORD = 0x0;
258 pub const MOVEFILE_REPLACE_EXISTING: DWORD = 1;
260 pub const FILE_BEGIN: DWORD = 0;
261 pub const FILE_CURRENT: DWORD = 1;
262 pub const FILE_END: DWORD = 2;
264 pub const WAIT_OBJECT_0: DWORD = 0x00000000;
266 #[cfg(target_env = "msvc")]
267 pub const MAX_SYM_NAME: usize = 2000;
268 #[cfg(target_arch = "x86")]
269 pub const IMAGE_FILE_MACHINE_I386: DWORD = 0x014c;
270 #[cfg(target_arch = "x86_64")]
271 pub const IMAGE_FILE_MACHINE_AMD64: DWORD = 0x8664;
273 pub const PROV_RSA_FULL: DWORD = 1;
274 pub const CRYPT_SILENT: DWORD = 64;
275 pub const CRYPT_VERIFYCONTEXT: DWORD = 0xF0000000;
277 pub const EXCEPTION_CONTINUE_SEARCH: LONG = 0;
278 pub const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd;
279 pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15;
280 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
281 pub const EXCEPTION_NONCONTINUABLE: DWORD = 0x1; // Noncontinuable exception
282 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
283 pub const EXCEPTION_UNWINDING: DWORD = 0x2; // Unwind is in progress
284 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
285 pub const EXCEPTION_EXIT_UNWIND: DWORD = 0x4; // Exit unwind is in progress
286 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
287 pub const EXCEPTION_TARGET_UNWIND: DWORD = 0x20; // Target unwind in progress
288 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
289 pub const EXCEPTION_COLLIDED_UNWIND: DWORD = 0x40; // Collided exception handler call
290 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
291 pub const EXCEPTION_UNWIND: DWORD = EXCEPTION_UNWINDING |
292 EXCEPTION_EXIT_UNWIND |
293 EXCEPTION_TARGET_UNWIND |
294 EXCEPTION_COLLIDED_UNWIND;
296 pub const PIPE_ACCESS_INBOUND: DWORD = 0x00000001;
297 pub const FILE_FLAG_FIRST_PIPE_INSTANCE: DWORD = 0x00080000;
298 pub const FILE_FLAG_OVERLAPPED: DWORD = 0x40000000;
299 pub const PIPE_WAIT: DWORD = 0x00000000;
300 pub const PIPE_TYPE_BYTE: DWORD = 0x00000000;
301 pub const PIPE_REJECT_REMOTE_CLIENTS: DWORD = 0x00000008;
302 pub const PIPE_READMODE_BYTE: DWORD = 0x00000000;
305 #[cfg(target_arch = "x86")]
308 pub wHighVersion: WORD,
309 pub szDescription: [u8; WSADESCRIPTION_LEN + 1],
310 pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
311 pub iMaxSockets: u16,
313 pub lpVendorInfo: *mut u8,
316 #[cfg(target_arch = "x86_64")]
319 pub wHighVersion: WORD,
320 pub iMaxSockets: u16,
322 pub lpVendorInfo: *mut u8,
323 pub szDescription: [u8; WSADESCRIPTION_LEN + 1],
324 pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
327 pub type WSAEVENT = HANDLE;
330 pub struct WSAPROTOCOL_INFO {
331 pub dwServiceFlags1: DWORD,
332 pub dwServiceFlags2: DWORD,
333 pub dwServiceFlags3: DWORD,
334 pub dwServiceFlags4: DWORD,
335 pub dwProviderFlags: DWORD,
336 pub ProviderId: GUID,
337 pub dwCatalogEntryId: DWORD,
338 pub ProtocolChain: WSAPROTOCOLCHAIN,
340 pub iAddressFamily: c_int,
341 pub iMaxSockAddr: c_int,
342 pub iMinSockAddr: c_int,
343 pub iSocketType: c_int,
344 pub iProtocol: c_int,
345 pub iProtocolMaxOffset: c_int,
346 pub iNetworkByteOrder: c_int,
347 pub iSecurityScheme: c_int,
348 pub dwMessageSize: DWORD,
349 pub dwProviderReserved: DWORD,
350 pub szProtocol: [u16; (WSAPROTOCOL_LEN as usize) + 1],
354 #[derive(Copy, Clone)]
355 pub struct WIN32_FILE_ATTRIBUTE_DATA {
356 pub dwFileAttributes: DWORD,
357 pub ftCreationTime: FILETIME,
358 pub ftLastAccessTime: FILETIME,
359 pub ftLastWriteTime: FILETIME,
360 pub nFileSizeHigh: DWORD,
361 pub nFileSizeLow: DWORD,
365 pub struct BY_HANDLE_FILE_INFORMATION {
366 pub dwFileAttributes: DWORD,
367 pub ftCreationTime: FILETIME,
368 pub ftLastAccessTime: FILETIME,
369 pub ftLastWriteTime: FILETIME,
370 pub dwVolumeSerialNumber: DWORD,
371 pub nFileSizeHigh: DWORD,
372 pub nFileSizeLow: DWORD,
373 pub nNumberOfLinks: DWORD,
374 pub nFileIndexHigh: DWORD,
375 pub nFileIndexLow: DWORD,
379 #[allow(dead_code)] // we only use some variants
380 pub enum FILE_INFO_BY_HANDLE_CLASS {
382 FileStandardInfo = 1,
385 FileDispositionInfo = 4,
386 FileAllocationInfo = 5,
387 FileEndOfFileInfo = 6,
389 FileCompressionInfo = 8,
390 FileAttributeTagInfo = 9,
391 FileIdBothDirectoryInfo = 10, // 0xA
392 FileIdBothDirectoryRestartInfo = 11, // 0xB
393 FileIoPriorityHintInfo = 12, // 0xC
394 FileRemoteProtocolInfo = 13, // 0xD
395 FileFullDirectoryInfo = 14, // 0xE
396 FileFullDirectoryRestartInfo = 15, // 0xF
397 FileStorageInfo = 16, // 0x10
398 FileAlignmentInfo = 17, // 0x11
399 FileIdInfo = 18, // 0x12
400 FileIdExtdDirectoryInfo = 19, // 0x13
401 FileIdExtdDirectoryRestartInfo = 20, // 0x14
402 MaximumFileInfoByHandlesClass
406 pub struct FILE_END_OF_FILE_INFO {
407 pub EndOfFile: LARGE_INTEGER,
411 pub struct REPARSE_DATA_BUFFER {
412 pub ReparseTag: c_uint,
413 pub ReparseDataLength: c_ushort,
414 pub Reserved: c_ushort,
419 pub struct SYMBOLIC_LINK_REPARSE_BUFFER {
420 pub SubstituteNameOffset: c_ushort,
421 pub SubstituteNameLength: c_ushort,
422 pub PrintNameOffset: c_ushort,
423 pub PrintNameLength: c_ushort,
425 pub PathBuffer: WCHAR,
429 pub struct MOUNT_POINT_REPARSE_BUFFER {
430 pub SubstituteNameOffset: c_ushort,
431 pub SubstituteNameLength: c_ushort,
432 pub PrintNameOffset: c_ushort,
433 pub PrintNameLength: c_ushort,
434 pub PathBuffer: WCHAR,
437 pub type LPPROGRESS_ROUTINE = ::option::Option<unsafe extern "system" fn(
438 TotalFileSize: LARGE_INTEGER,
439 TotalBytesTransferred: LARGE_INTEGER,
440 StreamSize: LARGE_INTEGER,
441 StreamBytesTransferred: LARGE_INTEGER,
442 dwStreamNumber: DWORD,
443 dwCallbackReason: DWORD,
445 hDestinationFile: HANDLE,
450 pub struct CONDITION_VARIABLE { pub ptr: LPVOID }
452 pub struct SRWLOCK { pub ptr: LPVOID }
454 pub struct CRITICAL_SECTION {
455 CriticalSectionDebug: LPVOID,
457 RecursionCount: LONG,
458 OwningThread: HANDLE,
459 LockSemaphore: HANDLE,
464 pub struct REPARSE_MOUNTPOINT_DATA_BUFFER {
465 pub ReparseTag: DWORD,
466 pub ReparseDataLength: DWORD,
468 pub ReparseTargetLength: WORD,
469 pub ReparseTargetMaximumLength: WORD,
471 pub ReparseTarget: WCHAR,
475 pub struct EXCEPTION_RECORD {
476 pub ExceptionCode: DWORD,
477 pub ExceptionFlags: DWORD,
478 pub ExceptionRecord: *mut EXCEPTION_RECORD,
479 pub ExceptionAddress: LPVOID,
480 pub NumberParameters: DWORD,
481 pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS]
485 pub struct EXCEPTION_POINTERS {
486 pub ExceptionRecord: *mut EXCEPTION_RECORD,
487 pub ContextRecord: *mut CONTEXT,
490 pub type PVECTORED_EXCEPTION_HANDLER = extern "system"
491 fn(ExceptionInfo: *mut EXCEPTION_POINTERS) -> LONG;
498 pub Data4: [BYTE; 8],
502 pub struct WSAPROTOCOLCHAIN {
504 pub ChainEntries: [DWORD; MAX_PROTOCOL_CHAIN as usize],
508 pub struct SECURITY_ATTRIBUTES {
510 pub lpSecurityDescriptor: LPVOID,
511 pub bInheritHandle: BOOL,
515 pub struct PROCESS_INFORMATION {
516 pub hProcess: HANDLE,
518 pub dwProcessId: DWORD,
519 pub dwThreadId: DWORD,
523 pub struct STARTUPINFO {
525 pub lpReserved: LPWSTR,
526 pub lpDesktop: LPWSTR,
532 pub dwXCountChars: DWORD,
533 pub dwYCountCharts: DWORD,
534 pub dwFillAttribute: DWORD,
536 pub wShowWindow: WORD,
537 pub cbReserved2: WORD,
538 pub lpReserved2: LPBYTE,
539 pub hStdInput: HANDLE,
540 pub hStdOutput: HANDLE,
541 pub hStdError: HANDLE,
545 pub struct SOCKADDR {
546 pub sa_family: ADDRESS_FAMILY,
547 pub sa_data: [CHAR; 14],
551 #[derive(Copy, Clone)]
552 pub struct FILETIME {
553 pub dwLowDateTime: DWORD,
554 pub dwHighDateTime: DWORD,
558 pub struct OVERLAPPED {
559 pub Internal: *mut c_ulong,
560 pub InternalHigh: *mut c_ulong,
562 pub OffsetHigh: DWORD,
567 #[cfg(target_env = "msvc")]
568 pub struct SYMBOL_INFO {
569 pub SizeOfStruct: c_ulong,
570 pub TypeIndex: c_ulong,
571 pub Reserved: [u64; 2],
578 pub Register: c_ulong,
581 pub NameLen: c_ulong,
582 pub MaxNameLen: c_ulong,
583 // note that windows has this as 1, but it basically just means that
584 // the name is inline at the end of the struct. For us, we just bump
585 // the struct size up to MAX_SYM_NAME.
586 pub Name: [c_char; MAX_SYM_NAME],
590 #[cfg(target_env = "msvc")]
591 pub struct IMAGEHLP_LINE64 {
592 pub SizeOfStruct: u32,
593 pub Key: *const c_void,
595 pub Filename: *const c_char,
600 #[allow(dead_code)] // we only use some variants
601 pub enum ADDRESS_MODE {
609 pub struct ADDRESS64 {
612 pub Mode: ADDRESS_MODE,
616 pub struct STACKFRAME64 {
617 pub AddrPC: ADDRESS64,
618 pub AddrReturn: ADDRESS64,
619 pub AddrFrame: ADDRESS64,
620 pub AddrStack: ADDRESS64,
621 pub AddrBStore: ADDRESS64,
622 pub FuncTableEntry: *mut c_void,
623 pub Params: [u64; 4],
626 pub Reserved: [u64; 3],
627 pub KdHelp: KDHELP64,
631 pub struct KDHELP64 {
633 pub ThCallbackStack: DWORD,
634 pub ThCallbackBStore: DWORD,
635 pub NextCallback: DWORD,
636 pub FramePointer: DWORD,
637 pub KiCallUserMode: u64,
638 pub KeUserCallbackDispatcher: u64,
639 pub SystemRangeStart: u64,
640 pub KiUserExceptionDispatcher: u64,
643 pub Reserved: [u64; 5],
646 #[cfg(target_arch = "x86")]
649 pub ContextFlags: DWORD,
656 pub FloatSave: FLOATING_SAVE_AREA,
673 pub ExtendedRegisters: [u8; 512],
676 #[cfg(target_arch = "x86")]
678 pub struct FLOATING_SAVE_AREA {
679 pub ControlWord: DWORD,
680 pub StatusWord: DWORD,
682 pub ErrorOffset: DWORD,
683 pub ErrorSelector: DWORD,
684 pub DataOffset: DWORD,
685 pub DataSelector: DWORD,
686 pub RegisterArea: [u8; 80],
687 pub Cr0NpxState: DWORD,
690 #[cfg(target_arch = "x86_64")]
693 _align_hack: [u64x2; 0], // FIXME align on 16-byte
694 pub P1Home: DWORDLONG,
695 pub P2Home: DWORDLONG,
696 pub P3Home: DWORDLONG,
697 pub P4Home: DWORDLONG,
698 pub P5Home: DWORDLONG,
699 pub P6Home: DWORDLONG,
701 pub ContextFlags: DWORD,
738 pub FltSave: FLOATING_SAVE_AREA,
740 pub VectorRegister: [M128A; 26],
741 pub VectorControl: DWORDLONG,
743 pub DebugControl: DWORDLONG,
744 pub LastBranchToRip: DWORDLONG,
745 pub LastBranchFromRip: DWORDLONG,
746 pub LastExceptionToRip: DWORDLONG,
747 pub LastExceptionFromRip: DWORDLONG,
750 #[cfg(target_arch = "x86_64")]
753 _align_hack: [u64x2; 0], // FIXME align on 16-byte
754 pub Low: c_ulonglong,
758 #[cfg(target_arch = "x86_64")]
760 pub struct FLOATING_SAVE_AREA {
761 _align_hack: [u64x2; 0], // FIXME align on 16-byte
762 _Dummy: [u8; 512] // FIXME: Fill this out
766 pub struct SOCKADDR_STORAGE_LH {
767 pub ss_family: ADDRESS_FAMILY,
768 pub __ss_pad1: [CHAR; 6],
770 pub __ss_pad2: [CHAR; 112],
774 pub struct ADDRINFOA {
776 pub ai_family: c_int,
777 pub ai_socktype: c_int,
778 pub ai_protocol: c_int,
779 pub ai_addrlen: size_t,
780 pub ai_canonname: *mut c_char,
781 pub ai_addr: *mut SOCKADDR,
782 pub ai_next: *mut ADDRINFOA,
786 #[derive(Copy, Clone)]
787 pub struct sockaddr_in {
788 pub sin_family: ADDRESS_FAMILY,
789 pub sin_port: USHORT,
790 pub sin_addr: in_addr,
791 pub sin_zero: [CHAR; 8],
795 #[derive(Copy, Clone)]
796 pub struct sockaddr_in6 {
797 pub sin6_family: ADDRESS_FAMILY,
798 pub sin6_port: USHORT,
799 pub sin6_flowinfo: c_ulong,
800 pub sin6_addr: in6_addr,
801 pub sin6_scope_id: c_ulong,
805 #[derive(Copy, Clone)]
811 #[derive(Copy, Clone)]
812 pub struct in6_addr {
813 pub s6_addr: [u8; 16],
816 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
817 pub enum UNWIND_HISTORY_TABLE {}
820 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
821 pub struct RUNTIME_FUNCTION {
822 pub BeginAddress: DWORD,
823 pub EndAddress: DWORD,
824 pub UnwindData: DWORD,
828 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
829 pub struct DISPATCHER_CONTEXT {
830 pub ControlPc: LPVOID,
831 pub ImageBase: LPVOID,
832 pub FunctionEntry: *const RUNTIME_FUNCTION,
833 pub EstablisherFrame: LPVOID,
834 pub TargetIp: LPVOID,
835 pub ContextRecord: *const CONTEXT,
836 pub LanguageHandler: LPVOID,
837 pub HandlerData: *const u8,
838 pub HistoryTable: *const UNWIND_HISTORY_TABLE,
842 #[derive(Copy, Clone)]
843 #[allow(dead_code)] // we only use some variants
844 pub enum EXCEPTION_DISPOSITION {
845 ExceptionContinueExecution,
846 ExceptionContinueSearch,
847 ExceptionNestedException,
848 ExceptionCollidedUnwind
851 #[link(name = "ws2_32")]
852 #[link(name = "userenv")]
853 #[link(name = "shell32")]
854 #[link(name = "advapi32")]
855 #[cfg(not(cargobuild))]
859 pub fn WSAStartup(wVersionRequested: WORD,
860 lpWSAData: LPWSADATA) -> c_int;
861 pub fn WSACleanup() -> c_int;
862 pub fn WSAGetLastError() -> c_int;
863 pub fn WSADuplicateSocketW(s: SOCKET,
865 lpProtocolInfo: LPWSAPROTOCOL_INFO)
867 pub fn GetCurrentProcessId() -> DWORD;
868 pub fn WSASocketW(af: c_int,
871 lpProtocolInfo: LPWSAPROTOCOL_INFO,
873 dwFlags: DWORD) -> SOCKET;
874 pub fn ioctlsocket(s: SOCKET, cmd: c_long, argp: *mut c_ulong) -> c_int;
875 pub fn InitializeCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
876 pub fn EnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
877 pub fn TryEnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION) -> BOOLEAN;
878 pub fn LeaveCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
879 pub fn DeleteCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
881 // FIXME - pInputControl should be PCONSOLE_READCONSOLE_CONTROL
882 pub fn ReadConsoleW(hConsoleInput: HANDLE,
884 nNumberOfCharsToRead: DWORD,
885 lpNumberOfCharsRead: LPDWORD,
886 pInputControl: LPVOID) -> BOOL;
888 pub fn WriteConsoleW(hConsoleOutput: HANDLE,
890 nNumberOfCharsToWrite: DWORD,
891 lpNumberOfCharsWritten: LPDWORD,
892 lpReserved: LPVOID) -> BOOL;
894 pub fn GetConsoleMode(hConsoleHandle: HANDLE,
895 lpMode: LPDWORD) -> BOOL;
896 pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
897 pub fn SetFileAttributesW(lpFileName: LPCWSTR,
898 dwFileAttributes: DWORD) -> BOOL;
899 pub fn GetFileInformationByHandle(hFile: HANDLE,
900 lpFileInformation: LPBY_HANDLE_FILE_INFORMATION)
903 pub fn SetLastError(dwErrCode: DWORD);
904 pub fn GetCommandLineW() -> *mut LPCWSTR;
905 pub fn LocalFree(ptr: *mut c_void);
906 pub fn CommandLineToArgvW(lpCmdLine: *mut LPCWSTR,
907 pNumArgs: *mut c_int) -> *mut *mut u16;
908 pub fn GetTempPathW(nBufferLength: DWORD,
909 lpBuffer: LPCWSTR) -> DWORD;
910 pub fn OpenProcessToken(ProcessHandle: HANDLE,
911 DesiredAccess: DWORD,
912 TokenHandle: *mut HANDLE) -> BOOL;
913 pub fn GetCurrentProcess() -> HANDLE;
914 pub fn GetCurrentThread() -> HANDLE;
915 pub fn GetStdHandle(which: DWORD) -> HANDLE;
916 pub fn ExitProcess(uExitCode: c_uint) -> !;
917 pub fn DeviceIoControl(hDevice: HANDLE,
918 dwIoControlCode: DWORD,
920 nInBufferSize: DWORD,
922 nOutBufferSize: DWORD,
923 lpBytesReturned: LPDWORD,
924 lpOverlapped: LPOVERLAPPED) -> BOOL;
925 pub fn CreateThread(lpThreadAttributes: LPSECURITY_ATTRIBUTES,
927 lpStartAddress: extern "system" fn(*mut c_void)
930 dwCreationFlags: DWORD,
931 lpThreadId: LPDWORD) -> HANDLE;
932 pub fn WaitForSingleObject(hHandle: HANDLE,
933 dwMilliseconds: DWORD) -> DWORD;
934 pub fn SwitchToThread() -> BOOL;
935 pub fn Sleep(dwMilliseconds: DWORD);
936 pub fn GetProcessId(handle: HANDLE) -> DWORD;
937 pub fn GetUserProfileDirectoryW(hToken: HANDLE,
938 lpProfileDir: LPCWSTR,
939 lpcchSize: *mut DWORD) -> BOOL;
940 pub fn SetHandleInformation(hObject: HANDLE,
942 dwFlags: DWORD) -> BOOL;
943 pub fn CopyFileExW(lpExistingFileName: LPCWSTR,
944 lpNewFileName: LPCWSTR,
945 lpProgressRoutine: LPPROGRESS_ROUTINE,
948 dwCopyFlags: DWORD) -> BOOL;
949 pub fn AddVectoredExceptionHandler(FirstHandler: ULONG,
950 VectoredHandler: PVECTORED_EXCEPTION_HANDLER)
952 pub fn FormatMessageW(flags: DWORD,
960 pub fn TlsAlloc() -> DWORD;
961 pub fn TlsFree(dwTlsIndex: DWORD) -> BOOL;
962 pub fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID;
963 pub fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL;
964 pub fn GetLastError() -> DWORD;
965 pub fn QueryPerformanceFrequency(lpFrequency: *mut LARGE_INTEGER) -> BOOL;
966 pub fn QueryPerformanceCounter(lpPerformanceCount: *mut LARGE_INTEGER)
968 pub fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: LPDWORD) -> BOOL;
969 pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) -> BOOL;
970 pub fn CreateProcessW(lpApplicationName: LPCWSTR,
971 lpCommandLine: LPWSTR,
972 lpProcessAttributes: LPSECURITY_ATTRIBUTES,
973 lpThreadAttributes: LPSECURITY_ATTRIBUTES,
974 bInheritHandles: BOOL,
975 dwCreationFlags: DWORD,
976 lpEnvironment: LPVOID,
977 lpCurrentDirectory: LPCWSTR,
978 lpStartupInfo: LPSTARTUPINFO,
979 lpProcessInformation: LPPROCESS_INFORMATION)
981 pub fn GetEnvironmentVariableW(n: LPCWSTR, v: LPWSTR, nsize: DWORD) -> DWORD;
982 pub fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL;
983 pub fn GetEnvironmentStringsW() -> LPWCH;
984 pub fn FreeEnvironmentStringsW(env_ptr: LPWCH) -> BOOL;
985 pub fn GetModuleFileNameW(hModule: HMODULE,
989 pub fn CreateDirectoryW(lpPathName: LPCWSTR,
990 lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
992 pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
993 pub fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: LPWSTR) -> DWORD;
994 pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
996 pub fn closesocket(socket: SOCKET) -> c_int;
997 pub fn recv(socket: SOCKET, buf: *mut c_void, len: c_int,
998 flags: c_int) -> c_int;
999 pub fn send(socket: SOCKET, buf: *const c_void, len: c_int,
1000 flags: c_int) -> c_int;
1001 pub fn recvfrom(socket: SOCKET,
1005 addr: *mut SOCKADDR,
1006 addrlen: *mut c_int)
1008 pub fn sendto(socket: SOCKET,
1012 addr: *const SOCKADDR,
1015 pub fn shutdown(socket: SOCKET, how: c_int) -> c_int;
1016 pub fn accept(socket: SOCKET,
1017 address: *mut SOCKADDR,
1018 address_len: *mut c_int)
1020 pub fn DuplicateHandle(hSourceProcessHandle: HANDLE,
1021 hSourceHandle: HANDLE,
1022 hTargetProcessHandle: HANDLE,
1023 lpTargetHandle: LPHANDLE,
1024 dwDesiredAccess: DWORD,
1025 bInheritHandle: BOOL,
1028 pub fn ReadFile(hFile: HANDLE,
1030 nNumberOfBytesToRead: DWORD,
1031 lpNumberOfBytesRead: LPDWORD,
1032 lpOverlapped: LPOVERLAPPED)
1034 pub fn WriteFile(hFile: HANDLE,
1036 nNumberOfBytesToWrite: DWORD,
1037 lpNumberOfBytesWritten: LPDWORD,
1038 lpOverlapped: LPOVERLAPPED)
1040 pub fn CloseHandle(hObject: HANDLE) -> BOOL;
1041 pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR,
1042 lpTargetFileName: LPCWSTR,
1043 lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
1045 pub fn MoveFileExW(lpExistingFileName: LPCWSTR,
1046 lpNewFileName: LPCWSTR,
1049 pub fn SetFilePointerEx(hFile: HANDLE,
1050 liDistanceToMove: LARGE_INTEGER,
1051 lpNewFilePointer: PLARGE_INTEGER,
1052 dwMoveMethod: DWORD)
1054 pub fn FlushFileBuffers(hFile: HANDLE) -> BOOL;
1055 pub fn CreateFileW(lpFileName: LPCWSTR,
1056 dwDesiredAccess: DWORD,
1058 lpSecurityAttributes: LPSECURITY_ATTRIBUTES,
1059 dwCreationDisposition: DWORD,
1060 dwFlagsAndAttributes: DWORD,
1061 hTemplateFile: HANDLE)
1064 pub fn FindFirstFileW(fileName: LPCWSTR,
1065 findFileData: LPWIN32_FIND_DATAW)
1067 pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW)
1069 pub fn FindClose(findFile: HANDLE) -> BOOL;
1070 pub fn RtlCaptureContext(ctx: *mut CONTEXT);
1071 pub fn getsockopt(s: SOCKET,
1074 optval: *mut c_char,
1077 pub fn setsockopt(s: SOCKET,
1080 optval: *const c_void,
1083 pub fn getsockname(socket: SOCKET,
1084 address: *mut SOCKADDR,
1085 address_len: *mut c_int)
1087 pub fn getpeername(socket: SOCKET,
1088 address: *mut SOCKADDR,
1089 address_len: *mut c_int)
1091 pub fn bind(socket: SOCKET, address: *const SOCKADDR,
1092 address_len: socklen_t) -> c_int;
1093 pub fn listen(socket: SOCKET, backlog: c_int) -> c_int;
1094 pub fn connect(socket: SOCKET, address: *const SOCKADDR, len: c_int)
1096 pub fn getaddrinfo(node: *const c_char, service: *const c_char,
1097 hints: *const ADDRINFOA,
1098 res: *mut *mut ADDRINFOA) -> c_int;
1099 pub fn freeaddrinfo(res: *mut ADDRINFOA);
1101 pub fn LoadLibraryW(name: LPCWSTR) -> HMODULE;
1102 pub fn FreeLibrary(handle: HMODULE) -> BOOL;
1103 pub fn GetProcAddress(handle: HMODULE,
1104 name: LPCSTR) -> *mut c_void;
1105 pub fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE;
1106 pub fn CryptAcquireContextA(phProv: *mut HCRYPTPROV,
1107 pszContainer: LPCSTR,
1108 pszProvider: LPCSTR,
1110 dwFlags: DWORD) -> BOOL;
1111 pub fn CryptGenRandom(hProv: HCRYPTPROV,
1113 pbBuffer: *mut BYTE) -> BOOL;
1114 pub fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL;
1117 #[cfg(any(target_arch = "x86_64", target_env = "msvc"))]
1118 pub fn RaiseException(dwExceptionCode: DWORD,
1119 dwExceptionFlags: DWORD,
1120 nNumberOfArguments: DWORD,
1121 lpArguments: *const ULONG_PTR);
1122 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
1123 pub fn RtlUnwindEx(TargetFrame: LPVOID,
1125 ExceptionRecord: *const EXCEPTION_RECORD,
1126 ReturnValue: LPVOID,
1127 OriginalContext: *const CONTEXT,
1128 HistoryTable: *const UNWIND_HISTORY_TABLE);
1129 pub fn GetSystemTimeAsFileTime(lpSystemTimeAsFileTime: LPFILETIME);
1131 pub fn CreateEventW(lpEventAttributes: LPSECURITY_ATTRIBUTES,
1133 bInitialState: BOOL,
1134 lpName: LPCWSTR) -> HANDLE;
1135 pub fn WaitForMultipleObjects(nCount: DWORD,
1136 lpHandles: *const HANDLE,
1138 dwMilliseconds: DWORD) -> DWORD;
1139 pub fn CreateNamedPipeW(lpName: LPCWSTR,
1142 nMaxInstances: DWORD,
1143 nOutBufferSize: DWORD,
1144 nInBufferSize: DWORD,
1145 nDefaultTimeOut: DWORD,
1146 lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
1148 pub fn CancelIo(handle: HANDLE) -> BOOL;
1149 pub fn GetOverlappedResult(hFile: HANDLE,
1150 lpOverlapped: LPOVERLAPPED,
1151 lpNumberOfBytesTransferred: LPDWORD,
1152 bWait: BOOL) -> BOOL;
1155 // Functions that aren't available on Windows XP, but we still use them and just
1156 // provide some form of a fallback implementation.
1160 pub fn CreateSymbolicLinkW(_lpSymlinkFileName: LPCWSTR,
1161 _lpTargetFileName: LPCWSTR,
1162 _dwFlags: DWORD) -> BOOLEAN {
1163 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1165 pub fn GetFinalPathNameByHandleW(_hFile: HANDLE,
1166 _lpszFilePath: LPCWSTR,
1167 _cchFilePath: DWORD,
1168 _dwFlags: DWORD) -> DWORD {
1169 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1171 pub fn SetThreadStackGuarantee(_size: *mut c_ulong) -> BOOL {
1172 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1174 pub fn SetFileInformationByHandle(_hFile: HANDLE,
1175 _FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,
1176 _lpFileInformation: LPVOID,
1177 _dwBufferSize: DWORD) -> BOOL {
1178 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1180 pub fn SleepConditionVariableSRW(ConditionVariable: PCONDITION_VARIABLE,
1182 dwMilliseconds: DWORD,
1183 Flags: ULONG) -> BOOL {
1184 panic!("condition variables not available")
1186 pub fn WakeConditionVariable(ConditionVariable: PCONDITION_VARIABLE)
1188 panic!("condition variables not available")
1190 pub fn WakeAllConditionVariable(ConditionVariable: PCONDITION_VARIABLE)
1192 panic!("condition variables not available")
1194 pub fn AcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> () {
1195 panic!("rwlocks not available")
1197 pub fn AcquireSRWLockShared(SRWLock: PSRWLOCK) -> () {
1198 panic!("rwlocks not available")
1200 pub fn ReleaseSRWLockExclusive(SRWLock: PSRWLOCK) -> () {
1201 panic!("rwlocks not available")
1203 pub fn ReleaseSRWLockShared(SRWLock: PSRWLOCK) -> () {
1204 panic!("rwlocks not available")
1206 pub fn TryAcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> BOOLEAN {
1207 panic!("rwlocks not available")
1209 pub fn TryAcquireSRWLockShared(SRWLock: PSRWLOCK) -> BOOLEAN {
1210 panic!("rwlocks not available")