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 NI_MAXHOST: DWORD = 1025;
159 pub const MAX_PROTOCOL_CHAIN: DWORD = 7;
161 pub const TOKEN_READ: DWORD = 0x20008;
162 pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024;
163 pub const FSCTL_GET_REPARSE_POINT: DWORD = 0x900a8;
164 pub const IO_REPARSE_TAG_SYMLINK: DWORD = 0xa000000c;
165 pub const IO_REPARSE_TAG_MOUNT_POINT: DWORD = 0xa0000003;
166 pub const SYMLINK_FLAG_RELATIVE: DWORD = 0x00000001;
167 pub const FSCTL_SET_REPARSE_POINT: DWORD = 0x900a4;
169 pub const SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 0x1;
171 // Note that these are not actually HANDLEs, just values to pass to GetStdHandle
172 pub const STD_INPUT_HANDLE: DWORD = -10i32 as DWORD;
173 pub const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
174 pub const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
176 pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001;
178 pub const PROGRESS_CONTINUE: DWORD = 0;
180 pub const ERROR_FILE_NOT_FOUND: DWORD = 2;
181 pub const ERROR_PATH_NOT_FOUND: DWORD = 3;
182 pub const ERROR_ACCESS_DENIED: DWORD = 5;
183 pub const ERROR_INVALID_HANDLE: DWORD = 6;
184 pub const ERROR_NO_MORE_FILES: DWORD = 18;
185 pub const ERROR_HANDLE_EOF: DWORD = 38;
186 pub const ERROR_BROKEN_PIPE: DWORD = 109;
187 pub const ERROR_CALL_NOT_IMPLEMENTED: DWORD = 120;
188 pub const ERROR_INSUFFICIENT_BUFFER: DWORD = 122;
189 pub const ERROR_ALREADY_EXISTS: DWORD = 183;
190 pub const ERROR_NO_DATA: DWORD = 232;
191 pub const ERROR_ENVVAR_NOT_FOUND: DWORD = 203;
192 pub const ERROR_OPERATION_ABORTED: DWORD = 995;
193 pub const ERROR_IO_PENDING: DWORD = 997;
194 pub const ERROR_TIMEOUT: DWORD = 0x5B4;
196 pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE;
198 pub const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000;
199 pub const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200;
201 pub const TLS_OUT_OF_INDEXES: DWORD = 0xFFFFFFFF;
203 pub const DLL_THREAD_DETACH: DWORD = 3;
204 pub const DLL_PROCESS_DETACH: DWORD = 0;
206 pub const INFINITE: DWORD = !0;
208 pub const DUPLICATE_SAME_ACCESS: DWORD = 0x00000002;
210 pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE {
211 ptr: ptr::null_mut(),
213 pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: ptr::null_mut() };
215 pub const DETACHED_PROCESS: DWORD = 0x00000008;
216 pub const CREATE_NEW_PROCESS_GROUP: DWORD = 0x00000200;
217 pub const CREATE_UNICODE_ENVIRONMENT: DWORD = 0x00000400;
218 pub const STARTF_USESTDHANDLES: DWORD = 0x00000100;
220 pub const AF_INET: c_int = 2;
221 pub const AF_INET6: c_int = 23;
222 pub const SD_BOTH: c_int = 2;
223 pub const SD_RECEIVE: c_int = 0;
224 pub const SD_SEND: c_int = 1;
225 pub const SOCK_DGRAM: c_int = 2;
226 pub const SOCK_STREAM: c_int = 1;
227 pub const SOL_SOCKET: c_int = 0xffff;
228 pub const SO_RCVTIMEO: c_int = 0x1006;
229 pub const SO_SNDTIMEO: c_int = 0x1005;
230 pub const SO_REUSEADDR: c_int = 0x0004;
231 pub const IPPROTO_IP: c_int = 0;
232 pub const IPPROTO_TCP: c_int = 6;
233 pub const IPPROTO_IPV6: c_int = 41;
234 pub const TCP_NODELAY: c_int = 0x0001;
235 pub const IP_TTL: c_int = 4;
236 pub const IPV6_V6ONLY: c_int = 27;
237 pub const SO_ERROR: c_int = 0x1007;
238 pub const SO_BROADCAST: c_int = 0x0020;
239 pub const IP_MULTICAST_LOOP: c_int = 11;
240 pub const IPV6_MULTICAST_LOOP: c_int = 11;
241 pub const IP_MULTICAST_TTL: c_int = 10;
242 pub const IP_ADD_MEMBERSHIP: c_int = 12;
243 pub const IP_DROP_MEMBERSHIP: c_int = 13;
244 pub const IPV6_ADD_MEMBERSHIP: c_int = 12;
245 pub const IPV6_DROP_MEMBERSHIP: c_int = 13;
249 pub imr_multiaddr: in_addr,
250 pub imr_interface: in_addr,
254 pub struct ipv6_mreq {
255 pub ipv6mr_multiaddr: in6_addr,
256 pub ipv6mr_interface: c_uint,
259 pub const VOLUME_NAME_DOS: DWORD = 0x0;
260 pub const MOVEFILE_REPLACE_EXISTING: DWORD = 1;
262 pub const FILE_BEGIN: DWORD = 0;
263 pub const FILE_CURRENT: DWORD = 1;
264 pub const FILE_END: DWORD = 2;
266 pub const WAIT_OBJECT_0: DWORD = 0x00000000;
268 #[cfg(target_env = "msvc")]
269 pub const MAX_SYM_NAME: usize = 2000;
270 #[cfg(target_arch = "x86")]
271 pub const IMAGE_FILE_MACHINE_I386: DWORD = 0x014c;
272 #[cfg(target_arch = "x86_64")]
273 pub const IMAGE_FILE_MACHINE_AMD64: DWORD = 0x8664;
275 pub const PROV_RSA_FULL: DWORD = 1;
276 pub const CRYPT_SILENT: DWORD = 64;
277 pub const CRYPT_VERIFYCONTEXT: DWORD = 0xF0000000;
279 pub const EXCEPTION_CONTINUE_SEARCH: LONG = 0;
280 pub const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd;
281 pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15;
282 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
283 pub const EXCEPTION_NONCONTINUABLE: DWORD = 0x1; // Noncontinuable exception
284 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
285 pub const EXCEPTION_UNWINDING: DWORD = 0x2; // Unwind is in progress
286 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
287 pub const EXCEPTION_EXIT_UNWIND: DWORD = 0x4; // Exit unwind is in progress
288 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
289 pub const EXCEPTION_TARGET_UNWIND: DWORD = 0x20; // Target unwind in progress
290 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
291 pub const EXCEPTION_COLLIDED_UNWIND: DWORD = 0x40; // Collided exception handler call
292 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
293 pub const EXCEPTION_UNWIND: DWORD = EXCEPTION_UNWINDING |
294 EXCEPTION_EXIT_UNWIND |
295 EXCEPTION_TARGET_UNWIND |
296 EXCEPTION_COLLIDED_UNWIND;
298 pub const PIPE_ACCESS_INBOUND: DWORD = 0x00000001;
299 pub const FILE_FLAG_FIRST_PIPE_INSTANCE: DWORD = 0x00080000;
300 pub const FILE_FLAG_OVERLAPPED: DWORD = 0x40000000;
301 pub const PIPE_WAIT: DWORD = 0x00000000;
302 pub const PIPE_TYPE_BYTE: DWORD = 0x00000000;
303 pub const PIPE_REJECT_REMOTE_CLIENTS: DWORD = 0x00000008;
304 pub const PIPE_READMODE_BYTE: DWORD = 0x00000000;
307 #[cfg(target_arch = "x86")]
310 pub wHighVersion: WORD,
311 pub szDescription: [u8; WSADESCRIPTION_LEN + 1],
312 pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
313 pub iMaxSockets: u16,
315 pub lpVendorInfo: *mut u8,
318 #[cfg(target_arch = "x86_64")]
321 pub wHighVersion: WORD,
322 pub iMaxSockets: u16,
324 pub lpVendorInfo: *mut u8,
325 pub szDescription: [u8; WSADESCRIPTION_LEN + 1],
326 pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
329 pub type WSAEVENT = HANDLE;
332 pub struct WSAPROTOCOL_INFO {
333 pub dwServiceFlags1: DWORD,
334 pub dwServiceFlags2: DWORD,
335 pub dwServiceFlags3: DWORD,
336 pub dwServiceFlags4: DWORD,
337 pub dwProviderFlags: DWORD,
338 pub ProviderId: GUID,
339 pub dwCatalogEntryId: DWORD,
340 pub ProtocolChain: WSAPROTOCOLCHAIN,
342 pub iAddressFamily: c_int,
343 pub iMaxSockAddr: c_int,
344 pub iMinSockAddr: c_int,
345 pub iSocketType: c_int,
346 pub iProtocol: c_int,
347 pub iProtocolMaxOffset: c_int,
348 pub iNetworkByteOrder: c_int,
349 pub iSecurityScheme: c_int,
350 pub dwMessageSize: DWORD,
351 pub dwProviderReserved: DWORD,
352 pub szProtocol: [u16; (WSAPROTOCOL_LEN as usize) + 1],
356 #[derive(Copy, Clone)]
357 pub struct WIN32_FILE_ATTRIBUTE_DATA {
358 pub dwFileAttributes: DWORD,
359 pub ftCreationTime: FILETIME,
360 pub ftLastAccessTime: FILETIME,
361 pub ftLastWriteTime: FILETIME,
362 pub nFileSizeHigh: DWORD,
363 pub nFileSizeLow: DWORD,
367 pub struct BY_HANDLE_FILE_INFORMATION {
368 pub dwFileAttributes: DWORD,
369 pub ftCreationTime: FILETIME,
370 pub ftLastAccessTime: FILETIME,
371 pub ftLastWriteTime: FILETIME,
372 pub dwVolumeSerialNumber: DWORD,
373 pub nFileSizeHigh: DWORD,
374 pub nFileSizeLow: DWORD,
375 pub nNumberOfLinks: DWORD,
376 pub nFileIndexHigh: DWORD,
377 pub nFileIndexLow: DWORD,
381 #[allow(dead_code)] // we only use some variants
382 pub enum FILE_INFO_BY_HANDLE_CLASS {
384 FileStandardInfo = 1,
387 FileDispositionInfo = 4,
388 FileAllocationInfo = 5,
389 FileEndOfFileInfo = 6,
391 FileCompressionInfo = 8,
392 FileAttributeTagInfo = 9,
393 FileIdBothDirectoryInfo = 10, // 0xA
394 FileIdBothDirectoryRestartInfo = 11, // 0xB
395 FileIoPriorityHintInfo = 12, // 0xC
396 FileRemoteProtocolInfo = 13, // 0xD
397 FileFullDirectoryInfo = 14, // 0xE
398 FileFullDirectoryRestartInfo = 15, // 0xF
399 FileStorageInfo = 16, // 0x10
400 FileAlignmentInfo = 17, // 0x11
401 FileIdInfo = 18, // 0x12
402 FileIdExtdDirectoryInfo = 19, // 0x13
403 FileIdExtdDirectoryRestartInfo = 20, // 0x14
404 MaximumFileInfoByHandlesClass
408 pub struct FILE_END_OF_FILE_INFO {
409 pub EndOfFile: LARGE_INTEGER,
413 pub struct REPARSE_DATA_BUFFER {
414 pub ReparseTag: c_uint,
415 pub ReparseDataLength: c_ushort,
416 pub Reserved: c_ushort,
421 pub struct SYMBOLIC_LINK_REPARSE_BUFFER {
422 pub SubstituteNameOffset: c_ushort,
423 pub SubstituteNameLength: c_ushort,
424 pub PrintNameOffset: c_ushort,
425 pub PrintNameLength: c_ushort,
427 pub PathBuffer: WCHAR,
431 pub struct MOUNT_POINT_REPARSE_BUFFER {
432 pub SubstituteNameOffset: c_ushort,
433 pub SubstituteNameLength: c_ushort,
434 pub PrintNameOffset: c_ushort,
435 pub PrintNameLength: c_ushort,
436 pub PathBuffer: WCHAR,
439 pub type LPPROGRESS_ROUTINE = ::option::Option<unsafe extern "system" fn(
440 TotalFileSize: LARGE_INTEGER,
441 TotalBytesTransferred: LARGE_INTEGER,
442 StreamSize: LARGE_INTEGER,
443 StreamBytesTransferred: LARGE_INTEGER,
444 dwStreamNumber: DWORD,
445 dwCallbackReason: DWORD,
447 hDestinationFile: HANDLE,
452 pub struct CONDITION_VARIABLE { pub ptr: LPVOID }
454 pub struct SRWLOCK { pub ptr: LPVOID }
456 pub struct CRITICAL_SECTION {
457 CriticalSectionDebug: LPVOID,
459 RecursionCount: LONG,
460 OwningThread: HANDLE,
461 LockSemaphore: HANDLE,
466 pub struct REPARSE_MOUNTPOINT_DATA_BUFFER {
467 pub ReparseTag: DWORD,
468 pub ReparseDataLength: DWORD,
470 pub ReparseTargetLength: WORD,
471 pub ReparseTargetMaximumLength: WORD,
473 pub ReparseTarget: WCHAR,
477 pub struct EXCEPTION_RECORD {
478 pub ExceptionCode: DWORD,
479 pub ExceptionFlags: DWORD,
480 pub ExceptionRecord: *mut EXCEPTION_RECORD,
481 pub ExceptionAddress: LPVOID,
482 pub NumberParameters: DWORD,
483 pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS]
487 pub struct EXCEPTION_POINTERS {
488 pub ExceptionRecord: *mut EXCEPTION_RECORD,
489 pub ContextRecord: *mut CONTEXT,
492 pub type PVECTORED_EXCEPTION_HANDLER = extern "system"
493 fn(ExceptionInfo: *mut EXCEPTION_POINTERS) -> LONG;
500 pub Data4: [BYTE; 8],
504 pub struct WSAPROTOCOLCHAIN {
506 pub ChainEntries: [DWORD; MAX_PROTOCOL_CHAIN as usize],
510 pub struct SECURITY_ATTRIBUTES {
512 pub lpSecurityDescriptor: LPVOID,
513 pub bInheritHandle: BOOL,
517 pub struct PROCESS_INFORMATION {
518 pub hProcess: HANDLE,
520 pub dwProcessId: DWORD,
521 pub dwThreadId: DWORD,
525 pub struct STARTUPINFO {
527 pub lpReserved: LPWSTR,
528 pub lpDesktop: LPWSTR,
534 pub dwXCountChars: DWORD,
535 pub dwYCountCharts: DWORD,
536 pub dwFillAttribute: DWORD,
538 pub wShowWindow: WORD,
539 pub cbReserved2: WORD,
540 pub lpReserved2: LPBYTE,
541 pub hStdInput: HANDLE,
542 pub hStdOutput: HANDLE,
543 pub hStdError: HANDLE,
547 pub struct SOCKADDR {
548 pub sa_family: ADDRESS_FAMILY,
549 pub sa_data: [CHAR; 14],
553 #[derive(Copy, Clone)]
554 pub struct FILETIME {
555 pub dwLowDateTime: DWORD,
556 pub dwHighDateTime: DWORD,
560 pub struct OVERLAPPED {
561 pub Internal: *mut c_ulong,
562 pub InternalHigh: *mut c_ulong,
564 pub OffsetHigh: DWORD,
569 #[cfg(target_env = "msvc")]
570 pub struct SYMBOL_INFO {
571 pub SizeOfStruct: c_ulong,
572 pub TypeIndex: c_ulong,
573 pub Reserved: [u64; 2],
580 pub Register: c_ulong,
583 pub NameLen: c_ulong,
584 pub MaxNameLen: c_ulong,
585 // note that windows has this as 1, but it basically just means that
586 // the name is inline at the end of the struct. For us, we just bump
587 // the struct size up to MAX_SYM_NAME.
588 pub Name: [c_char; MAX_SYM_NAME],
592 #[cfg(target_env = "msvc")]
593 pub struct IMAGEHLP_LINE64 {
594 pub SizeOfStruct: u32,
595 pub Key: *const c_void,
597 pub Filename: *const c_char,
602 #[allow(dead_code)] // we only use some variants
603 pub enum ADDRESS_MODE {
611 pub struct ADDRESS64 {
614 pub Mode: ADDRESS_MODE,
618 pub struct STACKFRAME64 {
619 pub AddrPC: ADDRESS64,
620 pub AddrReturn: ADDRESS64,
621 pub AddrFrame: ADDRESS64,
622 pub AddrStack: ADDRESS64,
623 pub AddrBStore: ADDRESS64,
624 pub FuncTableEntry: *mut c_void,
625 pub Params: [u64; 4],
628 pub Reserved: [u64; 3],
629 pub KdHelp: KDHELP64,
633 pub struct KDHELP64 {
635 pub ThCallbackStack: DWORD,
636 pub ThCallbackBStore: DWORD,
637 pub NextCallback: DWORD,
638 pub FramePointer: DWORD,
639 pub KiCallUserMode: u64,
640 pub KeUserCallbackDispatcher: u64,
641 pub SystemRangeStart: u64,
642 pub KiUserExceptionDispatcher: u64,
645 pub Reserved: [u64; 5],
648 #[cfg(target_arch = "x86")]
651 pub ContextFlags: DWORD,
658 pub FloatSave: FLOATING_SAVE_AREA,
675 pub ExtendedRegisters: [u8; 512],
678 #[cfg(target_arch = "x86")]
680 pub struct FLOATING_SAVE_AREA {
681 pub ControlWord: DWORD,
682 pub StatusWord: DWORD,
684 pub ErrorOffset: DWORD,
685 pub ErrorSelector: DWORD,
686 pub DataOffset: DWORD,
687 pub DataSelector: DWORD,
688 pub RegisterArea: [u8; 80],
689 pub Cr0NpxState: DWORD,
692 #[cfg(target_arch = "x86_64")]
695 _align_hack: [u64x2; 0], // FIXME align on 16-byte
696 pub P1Home: DWORDLONG,
697 pub P2Home: DWORDLONG,
698 pub P3Home: DWORDLONG,
699 pub P4Home: DWORDLONG,
700 pub P5Home: DWORDLONG,
701 pub P6Home: DWORDLONG,
703 pub ContextFlags: DWORD,
740 pub FltSave: FLOATING_SAVE_AREA,
742 pub VectorRegister: [M128A; 26],
743 pub VectorControl: DWORDLONG,
745 pub DebugControl: DWORDLONG,
746 pub LastBranchToRip: DWORDLONG,
747 pub LastBranchFromRip: DWORDLONG,
748 pub LastExceptionToRip: DWORDLONG,
749 pub LastExceptionFromRip: DWORDLONG,
752 #[cfg(target_arch = "x86_64")]
755 _align_hack: [u64x2; 0], // FIXME align on 16-byte
756 pub Low: c_ulonglong,
760 #[cfg(target_arch = "x86_64")]
762 pub struct FLOATING_SAVE_AREA {
763 _align_hack: [u64x2; 0], // FIXME align on 16-byte
764 _Dummy: [u8; 512] // FIXME: Fill this out
768 pub struct SOCKADDR_STORAGE_LH {
769 pub ss_family: ADDRESS_FAMILY,
770 pub __ss_pad1: [CHAR; 6],
772 pub __ss_pad2: [CHAR; 112],
776 pub struct ADDRINFOA {
778 pub ai_family: c_int,
779 pub ai_socktype: c_int,
780 pub ai_protocol: c_int,
781 pub ai_addrlen: size_t,
782 pub ai_canonname: *mut c_char,
783 pub ai_addr: *mut SOCKADDR,
784 pub ai_next: *mut ADDRINFOA,
788 #[derive(Copy, Clone)]
789 pub struct sockaddr_in {
790 pub sin_family: ADDRESS_FAMILY,
791 pub sin_port: USHORT,
792 pub sin_addr: in_addr,
793 pub sin_zero: [CHAR; 8],
797 #[derive(Copy, Clone)]
798 pub struct sockaddr_in6 {
799 pub sin6_family: ADDRESS_FAMILY,
800 pub sin6_port: USHORT,
801 pub sin6_flowinfo: c_ulong,
802 pub sin6_addr: in6_addr,
803 pub sin6_scope_id: c_ulong,
807 #[derive(Copy, Clone)]
813 #[derive(Copy, Clone)]
814 pub struct in6_addr {
815 pub s6_addr: [u8; 16],
818 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
819 pub enum UNWIND_HISTORY_TABLE {}
822 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
823 pub struct RUNTIME_FUNCTION {
824 pub BeginAddress: DWORD,
825 pub EndAddress: DWORD,
826 pub UnwindData: DWORD,
830 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
831 pub struct DISPATCHER_CONTEXT {
832 pub ControlPc: LPVOID,
833 pub ImageBase: LPVOID,
834 pub FunctionEntry: *const RUNTIME_FUNCTION,
835 pub EstablisherFrame: LPVOID,
836 pub TargetIp: LPVOID,
837 pub ContextRecord: *const CONTEXT,
838 pub LanguageHandler: LPVOID,
839 pub HandlerData: *const u8,
840 pub HistoryTable: *const UNWIND_HISTORY_TABLE,
844 #[derive(Copy, Clone)]
845 #[allow(dead_code)] // we only use some variants
846 pub enum EXCEPTION_DISPOSITION {
847 ExceptionContinueExecution,
848 ExceptionContinueSearch,
849 ExceptionNestedException,
850 ExceptionCollidedUnwind
853 #[link(name = "ws2_32")]
854 #[link(name = "userenv")]
855 #[link(name = "shell32")]
856 #[link(name = "advapi32")]
857 #[cfg(not(cargobuild))]
861 pub fn WSAStartup(wVersionRequested: WORD,
862 lpWSAData: LPWSADATA) -> c_int;
863 pub fn WSACleanup() -> c_int;
864 pub fn WSAGetLastError() -> c_int;
865 pub fn WSADuplicateSocketW(s: SOCKET,
867 lpProtocolInfo: LPWSAPROTOCOL_INFO)
869 pub fn GetCurrentProcessId() -> DWORD;
870 pub fn WSASocketW(af: c_int,
873 lpProtocolInfo: LPWSAPROTOCOL_INFO,
875 dwFlags: DWORD) -> SOCKET;
876 pub fn ioctlsocket(s: SOCKET, cmd: c_long, argp: *mut c_ulong) -> c_int;
877 pub fn InitializeCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
878 pub fn EnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
879 pub fn TryEnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION) -> BOOLEAN;
880 pub fn LeaveCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
881 pub fn DeleteCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
883 // FIXME - pInputControl should be PCONSOLE_READCONSOLE_CONTROL
884 pub fn ReadConsoleW(hConsoleInput: HANDLE,
886 nNumberOfCharsToRead: DWORD,
887 lpNumberOfCharsRead: LPDWORD,
888 pInputControl: LPVOID) -> BOOL;
890 pub fn WriteConsoleW(hConsoleOutput: HANDLE,
892 nNumberOfCharsToWrite: DWORD,
893 lpNumberOfCharsWritten: LPDWORD,
894 lpReserved: LPVOID) -> BOOL;
896 pub fn GetConsoleMode(hConsoleHandle: HANDLE,
897 lpMode: LPDWORD) -> BOOL;
898 pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
899 pub fn SetFileAttributesW(lpFileName: LPCWSTR,
900 dwFileAttributes: DWORD) -> BOOL;
901 pub fn GetFileInformationByHandle(hFile: HANDLE,
902 lpFileInformation: LPBY_HANDLE_FILE_INFORMATION)
905 pub fn SetLastError(dwErrCode: DWORD);
906 pub fn GetCommandLineW() -> *mut LPCWSTR;
907 pub fn LocalFree(ptr: *mut c_void);
908 pub fn CommandLineToArgvW(lpCmdLine: *mut LPCWSTR,
909 pNumArgs: *mut c_int) -> *mut *mut u16;
910 pub fn GetTempPathW(nBufferLength: DWORD,
911 lpBuffer: LPCWSTR) -> DWORD;
912 pub fn OpenProcessToken(ProcessHandle: HANDLE,
913 DesiredAccess: DWORD,
914 TokenHandle: *mut HANDLE) -> BOOL;
915 pub fn GetCurrentProcess() -> HANDLE;
916 pub fn GetCurrentThread() -> HANDLE;
917 pub fn GetStdHandle(which: DWORD) -> HANDLE;
918 pub fn ExitProcess(uExitCode: c_uint) -> !;
919 pub fn DeviceIoControl(hDevice: HANDLE,
920 dwIoControlCode: DWORD,
922 nInBufferSize: DWORD,
924 nOutBufferSize: DWORD,
925 lpBytesReturned: LPDWORD,
926 lpOverlapped: LPOVERLAPPED) -> BOOL;
927 pub fn CreateThread(lpThreadAttributes: LPSECURITY_ATTRIBUTES,
929 lpStartAddress: extern "system" fn(*mut c_void)
932 dwCreationFlags: DWORD,
933 lpThreadId: LPDWORD) -> HANDLE;
934 pub fn WaitForSingleObject(hHandle: HANDLE,
935 dwMilliseconds: DWORD) -> DWORD;
936 pub fn SwitchToThread() -> BOOL;
937 pub fn Sleep(dwMilliseconds: DWORD);
938 pub fn GetProcessId(handle: HANDLE) -> DWORD;
939 pub fn GetUserProfileDirectoryW(hToken: HANDLE,
940 lpProfileDir: LPCWSTR,
941 lpcchSize: *mut DWORD) -> BOOL;
942 pub fn SetHandleInformation(hObject: HANDLE,
944 dwFlags: DWORD) -> BOOL;
945 pub fn CopyFileExW(lpExistingFileName: LPCWSTR,
946 lpNewFileName: LPCWSTR,
947 lpProgressRoutine: LPPROGRESS_ROUTINE,
950 dwCopyFlags: DWORD) -> BOOL;
951 pub fn AddVectoredExceptionHandler(FirstHandler: ULONG,
952 VectoredHandler: PVECTORED_EXCEPTION_HANDLER)
954 pub fn FormatMessageW(flags: DWORD,
962 pub fn TlsAlloc() -> DWORD;
963 pub fn TlsFree(dwTlsIndex: DWORD) -> BOOL;
964 pub fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID;
965 pub fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL;
966 pub fn GetLastError() -> DWORD;
967 pub fn QueryPerformanceFrequency(lpFrequency: *mut LARGE_INTEGER) -> BOOL;
968 pub fn QueryPerformanceCounter(lpPerformanceCount: *mut LARGE_INTEGER)
970 pub fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: LPDWORD) -> BOOL;
971 pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) -> BOOL;
972 pub fn CreateProcessW(lpApplicationName: LPCWSTR,
973 lpCommandLine: LPWSTR,
974 lpProcessAttributes: LPSECURITY_ATTRIBUTES,
975 lpThreadAttributes: LPSECURITY_ATTRIBUTES,
976 bInheritHandles: BOOL,
977 dwCreationFlags: DWORD,
978 lpEnvironment: LPVOID,
979 lpCurrentDirectory: LPCWSTR,
980 lpStartupInfo: LPSTARTUPINFO,
981 lpProcessInformation: LPPROCESS_INFORMATION)
983 pub fn GetEnvironmentVariableW(n: LPCWSTR, v: LPWSTR, nsize: DWORD) -> DWORD;
984 pub fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL;
985 pub fn GetEnvironmentStringsW() -> LPWCH;
986 pub fn FreeEnvironmentStringsW(env_ptr: LPWCH) -> BOOL;
987 pub fn GetModuleFileNameW(hModule: HMODULE,
991 pub fn CreateDirectoryW(lpPathName: LPCWSTR,
992 lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
994 pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
995 pub fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: LPWSTR) -> DWORD;
996 pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
998 pub fn closesocket(socket: SOCKET) -> c_int;
999 pub fn recv(socket: SOCKET, buf: *mut c_void, len: c_int,
1000 flags: c_int) -> c_int;
1001 pub fn send(socket: SOCKET, buf: *const c_void, len: c_int,
1002 flags: c_int) -> c_int;
1003 pub fn recvfrom(socket: SOCKET,
1007 addr: *mut SOCKADDR,
1008 addrlen: *mut c_int)
1010 pub fn sendto(socket: SOCKET,
1014 addr: *const SOCKADDR,
1017 pub fn shutdown(socket: SOCKET, how: c_int) -> c_int;
1018 pub fn accept(socket: SOCKET,
1019 address: *mut SOCKADDR,
1020 address_len: *mut c_int)
1022 pub fn DuplicateHandle(hSourceProcessHandle: HANDLE,
1023 hSourceHandle: HANDLE,
1024 hTargetProcessHandle: HANDLE,
1025 lpTargetHandle: LPHANDLE,
1026 dwDesiredAccess: DWORD,
1027 bInheritHandle: BOOL,
1030 pub fn ReadFile(hFile: HANDLE,
1032 nNumberOfBytesToRead: DWORD,
1033 lpNumberOfBytesRead: LPDWORD,
1034 lpOverlapped: LPOVERLAPPED)
1036 pub fn WriteFile(hFile: HANDLE,
1038 nNumberOfBytesToWrite: DWORD,
1039 lpNumberOfBytesWritten: LPDWORD,
1040 lpOverlapped: LPOVERLAPPED)
1042 pub fn CloseHandle(hObject: HANDLE) -> BOOL;
1043 pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR,
1044 lpTargetFileName: LPCWSTR,
1045 lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
1047 pub fn MoveFileExW(lpExistingFileName: LPCWSTR,
1048 lpNewFileName: LPCWSTR,
1051 pub fn SetFilePointerEx(hFile: HANDLE,
1052 liDistanceToMove: LARGE_INTEGER,
1053 lpNewFilePointer: PLARGE_INTEGER,
1054 dwMoveMethod: DWORD)
1056 pub fn FlushFileBuffers(hFile: HANDLE) -> BOOL;
1057 pub fn CreateFileW(lpFileName: LPCWSTR,
1058 dwDesiredAccess: DWORD,
1060 lpSecurityAttributes: LPSECURITY_ATTRIBUTES,
1061 dwCreationDisposition: DWORD,
1062 dwFlagsAndAttributes: DWORD,
1063 hTemplateFile: HANDLE)
1066 pub fn FindFirstFileW(fileName: LPCWSTR,
1067 findFileData: LPWIN32_FIND_DATAW)
1069 pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW)
1071 pub fn FindClose(findFile: HANDLE) -> BOOL;
1072 pub fn RtlCaptureContext(ctx: *mut CONTEXT);
1073 pub fn getsockopt(s: SOCKET,
1076 optval: *mut c_char,
1079 pub fn setsockopt(s: SOCKET,
1082 optval: *const c_void,
1085 pub fn getsockname(socket: SOCKET,
1086 address: *mut SOCKADDR,
1087 address_len: *mut c_int)
1089 pub fn getpeername(socket: SOCKET,
1090 address: *mut SOCKADDR,
1091 address_len: *mut c_int)
1093 pub fn bind(socket: SOCKET, address: *const SOCKADDR,
1094 address_len: socklen_t) -> c_int;
1095 pub fn listen(socket: SOCKET, backlog: c_int) -> c_int;
1096 pub fn connect(socket: SOCKET, address: *const SOCKADDR, len: c_int)
1098 pub fn getaddrinfo(node: *const c_char, service: *const c_char,
1099 hints: *const ADDRINFOA,
1100 res: *mut *mut ADDRINFOA) -> c_int;
1101 pub fn freeaddrinfo(res: *mut ADDRINFOA);
1102 pub fn getnameinfo(sa: *const SOCKADDR, salen: c_int,
1103 host: *mut c_char, hostlen: DWORD,
1104 serv: *mut c_char, servlen: DWORD,
1105 flags: c_int) -> c_int;
1107 pub fn LoadLibraryW(name: LPCWSTR) -> HMODULE;
1108 pub fn GetModuleHandleExW(dwFlags: DWORD, name: LPCWSTR,
1109 handle: *mut HMODULE) -> BOOL;
1110 pub fn GetProcAddress(handle: HMODULE,
1111 name: LPCSTR) -> *mut c_void;
1112 pub fn FreeLibrary(handle: HMODULE) -> BOOL;
1113 pub fn SetErrorMode(uMode: c_uint) -> c_uint;
1114 pub fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE;
1115 pub fn CryptAcquireContextA(phProv: *mut HCRYPTPROV,
1116 pszContainer: LPCSTR,
1117 pszProvider: LPCSTR,
1119 dwFlags: DWORD) -> BOOL;
1120 pub fn CryptGenRandom(hProv: HCRYPTPROV,
1122 pbBuffer: *mut BYTE) -> BOOL;
1123 pub fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL;
1126 #[cfg(any(target_arch = "x86_64", target_env = "msvc"))]
1127 pub fn RaiseException(dwExceptionCode: DWORD,
1128 dwExceptionFlags: DWORD,
1129 nNumberOfArguments: DWORD,
1130 lpArguments: *const ULONG_PTR);
1131 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
1132 pub fn RtlUnwindEx(TargetFrame: LPVOID,
1134 ExceptionRecord: *const EXCEPTION_RECORD,
1135 ReturnValue: LPVOID,
1136 OriginalContext: *const CONTEXT,
1137 HistoryTable: *const UNWIND_HISTORY_TABLE);
1138 pub fn GetSystemTimeAsFileTime(lpSystemTimeAsFileTime: LPFILETIME);
1140 pub fn CreateEventW(lpEventAttributes: LPSECURITY_ATTRIBUTES,
1142 bInitialState: BOOL,
1143 lpName: LPCWSTR) -> HANDLE;
1144 pub fn WaitForMultipleObjects(nCount: DWORD,
1145 lpHandles: *const HANDLE,
1147 dwMilliseconds: DWORD) -> DWORD;
1148 pub fn CreateNamedPipeW(lpName: LPCWSTR,
1151 nMaxInstances: DWORD,
1152 nOutBufferSize: DWORD,
1153 nInBufferSize: DWORD,
1154 nDefaultTimeOut: DWORD,
1155 lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
1157 pub fn CancelIo(handle: HANDLE) -> BOOL;
1158 pub fn GetOverlappedResult(hFile: HANDLE,
1159 lpOverlapped: LPOVERLAPPED,
1160 lpNumberOfBytesTransferred: LPDWORD,
1161 bWait: BOOL) -> BOOL;
1164 // Functions that aren't available on Windows XP, but we still use them and just
1165 // provide some form of a fallback implementation.
1169 pub fn CreateSymbolicLinkW(_lpSymlinkFileName: LPCWSTR,
1170 _lpTargetFileName: LPCWSTR,
1171 _dwFlags: DWORD) -> BOOLEAN {
1172 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1174 pub fn GetFinalPathNameByHandleW(_hFile: HANDLE,
1175 _lpszFilePath: LPCWSTR,
1176 _cchFilePath: DWORD,
1177 _dwFlags: DWORD) -> DWORD {
1178 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1180 pub fn SetThreadErrorMode(_dwNewMode: DWORD,
1181 _lpOldMode: *mut DWORD) -> c_uint {
1182 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1184 pub fn SetThreadStackGuarantee(_size: *mut c_ulong) -> BOOL {
1185 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1187 pub fn SetFileInformationByHandle(_hFile: HANDLE,
1188 _FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,
1189 _lpFileInformation: LPVOID,
1190 _dwBufferSize: DWORD) -> BOOL {
1191 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1193 pub fn SleepConditionVariableSRW(ConditionVariable: PCONDITION_VARIABLE,
1195 dwMilliseconds: DWORD,
1196 Flags: ULONG) -> BOOL {
1197 panic!("condition variables not available")
1199 pub fn WakeConditionVariable(ConditionVariable: PCONDITION_VARIABLE)
1201 panic!("condition variables not available")
1203 pub fn WakeAllConditionVariable(ConditionVariable: PCONDITION_VARIABLE)
1205 panic!("condition variables not available")
1207 pub fn AcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> () {
1208 panic!("rwlocks not available")
1210 pub fn AcquireSRWLockShared(SRWLock: PSRWLOCK) -> () {
1211 panic!("rwlocks not available")
1213 pub fn ReleaseSRWLockExclusive(SRWLock: PSRWLOCK) -> () {
1214 panic!("rwlocks not available")
1216 pub fn ReleaseSRWLockShared(SRWLock: PSRWLOCK) -> () {
1217 panic!("rwlocks not available")
1219 pub fn TryAcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> BOOLEAN {
1220 panic!("rwlocks not available")
1222 pub fn TryAcquireSRWLockShared(SRWLock: PSRWLOCK) -> BOOLEAN {
1223 panic!("rwlocks not available")