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))]
16 use os::raw::{c_int, c_uint, c_ulong, c_long, c_longlong, c_ushort,};
17 use os::raw::{c_char, c_ulonglong};
18 use libc::{wchar_t, size_t, c_void};
23 #[cfg(target_arch = "x86_64")]
24 struct u64x2(u64, u64);
26 pub use self::FILE_INFO_BY_HANDLE_CLASS::*;
27 pub use self::EXCEPTION_DISPOSITION::*;
29 pub type DWORD = c_ulong;
30 pub type HANDLE = LPVOID;
31 pub type HINSTANCE = HANDLE;
32 pub type HMODULE = HINSTANCE;
33 pub type BOOL = c_int;
35 pub type BOOLEAN = BYTE;
36 pub type GROUP = c_uint;
37 pub type LONG_PTR = isize;
38 pub type LARGE_INTEGER = c_longlong;
39 pub type LONG = c_long;
40 pub type UINT = c_uint;
42 pub type USHORT = c_ushort;
43 pub type SIZE_T = usize;
45 pub type CHAR = c_char;
46 pub type HCRYPTPROV = LONG_PTR;
47 pub type ULONG_PTR = c_ulonglong;
48 pub type ULONG = c_ulong;
49 pub type ULONGLONG = u64;
50 pub type DWORDLONG = ULONGLONG;
52 pub type LPBOOL = *mut BOOL;
53 pub type LPBYTE = *mut BYTE;
54 pub type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION;
55 pub type LPCSTR = *const CHAR;
56 pub type LPCVOID = *const c_void;
57 pub type LPCWSTR = *const WCHAR;
58 pub type LPDWORD = *mut DWORD;
59 pub type LPHANDLE = *mut HANDLE;
60 pub type LPOVERLAPPED = *mut OVERLAPPED;
61 pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION;
62 pub type LPSECURITY_ATTRIBUTES = *mut SECURITY_ATTRIBUTES;
63 pub type LPSTARTUPINFO = *mut STARTUPINFO;
64 pub type LPVOID = *mut c_void;
65 pub type LPWCH = *mut WCHAR;
66 pub type LPWIN32_FIND_DATAW = *mut WIN32_FIND_DATAW;
67 pub type LPWSADATA = *mut WSADATA;
68 pub type LPWSAPROTOCOLCHAIN = *mut WSAPROTOCOLCHAIN;
69 pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO;
70 pub type LPWSTR = *mut WCHAR;
71 pub type LPFILETIME = *mut FILETIME;
73 pub type PCONDITION_VARIABLE = *mut CONDITION_VARIABLE;
74 pub type PLARGE_INTEGER = *mut c_longlong;
75 pub type PSRWLOCK = *mut SRWLOCK;
77 pub type SOCKET = ::os::windows::raw::SOCKET;
78 pub type socklen_t = c_int;
79 pub type ADDRESS_FAMILY = USHORT;
81 pub const TRUE: BOOL = 1;
82 pub const FALSE: BOOL = 0;
84 pub const FILE_ATTRIBUTE_READONLY: DWORD = 0x1;
85 pub const FILE_ATTRIBUTE_DIRECTORY: DWORD = 0x10;
86 pub const FILE_ATTRIBUTE_REPARSE_POINT: DWORD = 0x400;
88 pub const FILE_SHARE_DELETE: DWORD = 0x4;
89 pub const FILE_SHARE_READ: DWORD = 0x1;
90 pub const FILE_SHARE_WRITE: DWORD = 0x2;
92 pub const CREATE_ALWAYS: DWORD = 2;
93 pub const CREATE_NEW: DWORD = 1;
94 pub const OPEN_ALWAYS: DWORD = 4;
95 pub const OPEN_EXISTING: DWORD = 3;
96 pub const TRUNCATE_EXISTING: DWORD = 5;
98 pub const FILE_WRITE_DATA: DWORD = 0x00000002;
99 pub const FILE_APPEND_DATA: DWORD = 0x00000004;
100 pub const FILE_WRITE_EA: DWORD = 0x00000010;
101 pub const FILE_WRITE_ATTRIBUTES: DWORD = 0x00000100;
102 pub const READ_CONTROL: DWORD = 0x00020000;
103 pub const SYNCHRONIZE: DWORD = 0x00100000;
104 pub const GENERIC_READ: DWORD = 0x80000000;
105 pub const GENERIC_WRITE: DWORD = 0x40000000;
106 pub const STANDARD_RIGHTS_WRITE: DWORD = READ_CONTROL;
107 pub const FILE_GENERIC_WRITE: DWORD = STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA |
108 FILE_WRITE_ATTRIBUTES |
113 pub const FILE_FLAG_OPEN_REPARSE_POINT: DWORD = 0x00200000;
114 pub const FILE_FLAG_BACKUP_SEMANTICS: DWORD = 0x02000000;
115 pub const SECURITY_SQOS_PRESENT: DWORD = 0x00100000;
117 pub const FIONBIO: c_ulong = 0x8004667e;
121 pub struct WIN32_FIND_DATAW {
122 pub dwFileAttributes: DWORD,
123 pub ftCreationTime: FILETIME,
124 pub ftLastAccessTime: FILETIME,
125 pub ftLastWriteTime: FILETIME,
126 pub nFileSizeHigh: DWORD,
127 pub nFileSizeLow: DWORD,
128 pub dwReserved0: DWORD,
129 pub dwReserved1: DWORD,
130 pub cFileName: [wchar_t; 260], // #define MAX_PATH 260
131 pub cAlternateFileName: [wchar_t; 14],
133 impl Clone for WIN32_FIND_DATAW {
134 fn clone(&self) -> Self { *self }
137 pub const WSA_FLAG_OVERLAPPED: DWORD = 0x01;
139 pub const WSADESCRIPTION_LEN: usize = 256;
140 pub const WSASYS_STATUS_LEN: usize = 128;
141 pub const WSAPROTOCOL_LEN: DWORD = 255;
142 pub const INVALID_SOCKET: SOCKET = !0;
144 pub const WSAEACCES: c_int = 10013;
145 pub const WSAEINVAL: c_int = 10022;
146 pub const WSAEWOULDBLOCK: c_int = 10035;
147 pub const WSAEADDRINUSE: c_int = 10048;
148 pub const WSAEADDRNOTAVAIL: c_int = 10049;
149 pub const WSAECONNABORTED: c_int = 10053;
150 pub const WSAECONNRESET: c_int = 10054;
151 pub const WSAENOTCONN: c_int = 10057;
152 pub const WSAESHUTDOWN: c_int = 10058;
153 pub const WSAETIMEDOUT: c_int = 10060;
154 pub const WSAECONNREFUSED: c_int = 10061;
156 pub const NI_MAXHOST: DWORD = 1025;
158 pub const MAX_PROTOCOL_CHAIN: DWORD = 7;
160 pub const TOKEN_READ: DWORD = 0x20008;
161 pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024;
162 pub const FSCTL_GET_REPARSE_POINT: DWORD = 0x900a8;
163 pub const IO_REPARSE_TAG_SYMLINK: DWORD = 0xa000000c;
164 pub const IO_REPARSE_TAG_MOUNT_POINT: DWORD = 0xa0000003;
165 pub const SYMLINK_FLAG_RELATIVE: DWORD = 0x00000001;
166 pub const FSCTL_SET_REPARSE_POINT: DWORD = 0x900a4;
168 pub const SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 0x1;
170 // Note that these are not actually HANDLEs, just values to pass to GetStdHandle
171 pub const STD_INPUT_HANDLE: DWORD = -10i32 as DWORD;
172 pub const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
173 pub const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
175 pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001;
177 pub const PROGRESS_CONTINUE: DWORD = 0;
179 pub const ERROR_FILE_NOT_FOUND: DWORD = 2;
180 pub const ERROR_PATH_NOT_FOUND: DWORD = 3;
181 pub const ERROR_ACCESS_DENIED: DWORD = 5;
182 pub const ERROR_INVALID_HANDLE: DWORD = 6;
183 pub const ERROR_NO_MORE_FILES: DWORD = 18;
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_TIMEOUT: DWORD = 0x5B4;
193 pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE;
195 pub const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000;
196 pub const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200;
198 pub const TLS_OUT_OF_INDEXES: DWORD = 0xFFFFFFFF;
200 pub const DLL_THREAD_DETACH: DWORD = 3;
201 pub const DLL_PROCESS_DETACH: DWORD = 0;
203 pub const INFINITE: DWORD = !0;
205 pub const DUPLICATE_SAME_ACCESS: DWORD = 0x00000002;
207 pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE {
208 ptr: ptr::null_mut(),
210 pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: ptr::null_mut() };
212 pub const DETACHED_PROCESS: DWORD = 0x00000008;
213 pub const CREATE_NEW_PROCESS_GROUP: DWORD = 0x00000200;
214 pub const CREATE_UNICODE_ENVIRONMENT: DWORD = 0x00000400;
215 pub const STARTF_USESTDHANDLES: DWORD = 0x00000100;
217 pub const AF_INET: c_int = 2;
218 pub const AF_INET6: c_int = 23;
219 pub const SD_BOTH: c_int = 2;
220 pub const SD_RECEIVE: c_int = 0;
221 pub const SD_SEND: c_int = 1;
222 pub const SOCK_DGRAM: c_int = 2;
223 pub const SOCK_STREAM: c_int = 1;
224 pub const SOL_SOCKET: c_int = 0xffff;
225 pub const SO_RCVTIMEO: c_int = 0x1006;
226 pub const SO_SNDTIMEO: c_int = 0x1005;
227 pub const SO_REUSEADDR: c_int = 0x0004;
228 pub const IPPROTO_IP: c_int = 0;
229 pub const IPPROTO_TCP: c_int = 6;
230 pub const IPPROTO_IPV6: c_int = 41;
231 pub const TCP_NODELAY: c_int = 0x0001;
232 pub const IP_TTL: c_int = 4;
233 pub const IPV6_V6ONLY: c_int = 27;
234 pub const SO_ERROR: c_int = 0x1007;
235 pub const SO_BROADCAST: c_int = 0x0020;
236 pub const IP_MULTICAST_LOOP: c_int = 11;
237 pub const IPV6_MULTICAST_LOOP: c_int = 11;
238 pub const IP_MULTICAST_TTL: c_int = 10;
239 pub const IP_ADD_MEMBERSHIP: c_int = 12;
240 pub const IP_DROP_MEMBERSHIP: c_int = 13;
241 pub const IPV6_ADD_MEMBERSHIP: c_int = 12;
242 pub const IPV6_DROP_MEMBERSHIP: c_int = 13;
246 pub imr_multiaddr: in_addr,
247 pub imr_interface: in_addr,
251 pub struct ipv6_mreq {
252 pub ipv6mr_multiaddr: in6_addr,
253 pub ipv6mr_interface: c_uint,
256 pub const VOLUME_NAME_DOS: DWORD = 0x0;
257 pub const MOVEFILE_REPLACE_EXISTING: DWORD = 1;
259 pub const FILE_BEGIN: DWORD = 0;
260 pub const FILE_CURRENT: DWORD = 1;
261 pub const FILE_END: DWORD = 2;
263 pub const WAIT_OBJECT_0: DWORD = 0x00000000;
265 #[cfg(target_env = "msvc")]
266 pub const MAX_SYM_NAME: usize = 2000;
267 #[cfg(target_arch = "x86")]
268 pub const IMAGE_FILE_MACHINE_I386: DWORD = 0x014c;
269 #[cfg(target_arch = "x86_64")]
270 pub const IMAGE_FILE_MACHINE_AMD64: DWORD = 0x8664;
272 pub const PROV_RSA_FULL: DWORD = 1;
273 pub const CRYPT_SILENT: DWORD = 64;
274 pub const CRYPT_VERIFYCONTEXT: DWORD = 0xF0000000;
276 pub const EXCEPTION_CONTINUE_SEARCH: LONG = 0;
277 pub const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd;
278 pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15;
279 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
280 pub const EXCEPTION_NONCONTINUABLE: DWORD = 0x1; // Noncontinuable exception
281 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
282 pub const EXCEPTION_UNWINDING: DWORD = 0x2; // Unwind is in progress
283 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
284 pub const EXCEPTION_EXIT_UNWIND: DWORD = 0x4; // Exit unwind is in progress
285 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
286 pub const EXCEPTION_TARGET_UNWIND: DWORD = 0x20; // Target unwind in progress
287 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
288 pub const EXCEPTION_COLLIDED_UNWIND: DWORD = 0x40; // Collided exception handler call
289 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
290 pub const EXCEPTION_UNWIND: DWORD = EXCEPTION_UNWINDING |
291 EXCEPTION_EXIT_UNWIND |
292 EXCEPTION_TARGET_UNWIND |
293 EXCEPTION_COLLIDED_UNWIND;
296 #[cfg(target_arch = "x86")]
299 pub wHighVersion: WORD,
300 pub szDescription: [u8; WSADESCRIPTION_LEN + 1],
301 pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
302 pub iMaxSockets: u16,
304 pub lpVendorInfo: *mut u8,
307 #[cfg(target_arch = "x86_64")]
310 pub wHighVersion: WORD,
311 pub iMaxSockets: u16,
313 pub lpVendorInfo: *mut u8,
314 pub szDescription: [u8; WSADESCRIPTION_LEN + 1],
315 pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
318 pub type WSAEVENT = HANDLE;
321 pub struct WSAPROTOCOL_INFO {
322 pub dwServiceFlags1: DWORD,
323 pub dwServiceFlags2: DWORD,
324 pub dwServiceFlags3: DWORD,
325 pub dwServiceFlags4: DWORD,
326 pub dwProviderFlags: DWORD,
327 pub ProviderId: GUID,
328 pub dwCatalogEntryId: DWORD,
329 pub ProtocolChain: WSAPROTOCOLCHAIN,
331 pub iAddressFamily: c_int,
332 pub iMaxSockAddr: c_int,
333 pub iMinSockAddr: c_int,
334 pub iSocketType: c_int,
335 pub iProtocol: c_int,
336 pub iProtocolMaxOffset: c_int,
337 pub iNetworkByteOrder: c_int,
338 pub iSecurityScheme: c_int,
339 pub dwMessageSize: DWORD,
340 pub dwProviderReserved: DWORD,
341 pub szProtocol: [u16; (WSAPROTOCOL_LEN as usize) + 1],
345 #[derive(Copy, Clone)]
346 pub struct WIN32_FILE_ATTRIBUTE_DATA {
347 pub dwFileAttributes: DWORD,
348 pub ftCreationTime: FILETIME,
349 pub ftLastAccessTime: FILETIME,
350 pub ftLastWriteTime: FILETIME,
351 pub nFileSizeHigh: DWORD,
352 pub nFileSizeLow: DWORD,
356 pub struct BY_HANDLE_FILE_INFORMATION {
357 pub dwFileAttributes: DWORD,
358 pub ftCreationTime: FILETIME,
359 pub ftLastAccessTime: FILETIME,
360 pub ftLastWriteTime: FILETIME,
361 pub dwVolumeSerialNumber: DWORD,
362 pub nFileSizeHigh: DWORD,
363 pub nFileSizeLow: DWORD,
364 pub nNumberOfLinks: DWORD,
365 pub nFileIndexHigh: DWORD,
366 pub nFileIndexLow: DWORD,
370 #[allow(dead_code)] // we only use some variants
371 pub enum FILE_INFO_BY_HANDLE_CLASS {
373 FileStandardInfo = 1,
376 FileDispositionInfo = 4,
377 FileAllocationInfo = 5,
378 FileEndOfFileInfo = 6,
380 FileCompressionInfo = 8,
381 FileAttributeTagInfo = 9,
382 FileIdBothDirectoryInfo = 10, // 0xA
383 FileIdBothDirectoryRestartInfo = 11, // 0xB
384 FileIoPriorityHintInfo = 12, // 0xC
385 FileRemoteProtocolInfo = 13, // 0xD
386 FileFullDirectoryInfo = 14, // 0xE
387 FileFullDirectoryRestartInfo = 15, // 0xF
388 FileStorageInfo = 16, // 0x10
389 FileAlignmentInfo = 17, // 0x11
390 FileIdInfo = 18, // 0x12
391 FileIdExtdDirectoryInfo = 19, // 0x13
392 FileIdExtdDirectoryRestartInfo = 20, // 0x14
393 MaximumFileInfoByHandlesClass
397 pub struct FILE_END_OF_FILE_INFO {
398 pub EndOfFile: LARGE_INTEGER,
402 pub struct REPARSE_DATA_BUFFER {
403 pub ReparseTag: c_uint,
404 pub ReparseDataLength: c_ushort,
405 pub Reserved: c_ushort,
410 pub struct SYMBOLIC_LINK_REPARSE_BUFFER {
411 pub SubstituteNameOffset: c_ushort,
412 pub SubstituteNameLength: c_ushort,
413 pub PrintNameOffset: c_ushort,
414 pub PrintNameLength: c_ushort,
416 pub PathBuffer: WCHAR,
420 pub struct MOUNT_POINT_REPARSE_BUFFER {
421 pub SubstituteNameOffset: c_ushort,
422 pub SubstituteNameLength: c_ushort,
423 pub PrintNameOffset: c_ushort,
424 pub PrintNameLength: c_ushort,
425 pub PathBuffer: WCHAR,
428 pub type LPPROGRESS_ROUTINE = ::option::Option<unsafe extern "system" fn(
429 TotalFileSize: LARGE_INTEGER,
430 TotalBytesTransferred: LARGE_INTEGER,
431 StreamSize: LARGE_INTEGER,
432 StreamBytesTransferred: LARGE_INTEGER,
433 dwStreamNumber: DWORD,
434 dwCallbackReason: DWORD,
436 hDestinationFile: HANDLE,
441 pub struct CONDITION_VARIABLE { pub ptr: LPVOID }
443 pub struct SRWLOCK { pub ptr: LPVOID }
445 pub struct CRITICAL_SECTION {
446 CriticalSectionDebug: LPVOID,
448 RecursionCount: LONG,
449 OwningThread: HANDLE,
450 LockSemaphore: HANDLE,
455 pub struct REPARSE_MOUNTPOINT_DATA_BUFFER {
456 pub ReparseTag: DWORD,
457 pub ReparseDataLength: DWORD,
459 pub ReparseTargetLength: WORD,
460 pub ReparseTargetMaximumLength: WORD,
462 pub ReparseTarget: WCHAR,
466 pub struct EXCEPTION_RECORD {
467 pub ExceptionCode: DWORD,
468 pub ExceptionFlags: DWORD,
469 pub ExceptionRecord: *mut EXCEPTION_RECORD,
470 pub ExceptionAddress: LPVOID,
471 pub NumberParameters: DWORD,
472 pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS]
476 pub struct EXCEPTION_POINTERS {
477 pub ExceptionRecord: *mut EXCEPTION_RECORD,
478 pub ContextRecord: *mut CONTEXT,
481 pub type PVECTORED_EXCEPTION_HANDLER = extern "system"
482 fn(ExceptionInfo: *mut EXCEPTION_POINTERS) -> LONG;
489 pub Data4: [BYTE; 8],
493 pub struct WSAPROTOCOLCHAIN {
495 pub ChainEntries: [DWORD; MAX_PROTOCOL_CHAIN as usize],
499 pub struct SECURITY_ATTRIBUTES {
501 pub lpSecurityDescriptor: LPVOID,
502 pub bInheritHandle: BOOL,
506 pub struct PROCESS_INFORMATION {
507 pub hProcess: HANDLE,
509 pub dwProcessId: DWORD,
510 pub dwThreadId: DWORD,
514 pub struct STARTUPINFO {
516 pub lpReserved: LPWSTR,
517 pub lpDesktop: LPWSTR,
523 pub dwXCountChars: DWORD,
524 pub dwYCountCharts: DWORD,
525 pub dwFillAttribute: DWORD,
527 pub wShowWindow: WORD,
528 pub cbReserved2: WORD,
529 pub lpReserved2: LPBYTE,
530 pub hStdInput: HANDLE,
531 pub hStdOutput: HANDLE,
532 pub hStdError: HANDLE,
536 pub struct SOCKADDR {
537 pub sa_family: ADDRESS_FAMILY,
538 pub sa_data: [CHAR; 14],
542 #[derive(Copy, Clone)]
543 pub struct FILETIME {
544 pub dwLowDateTime: DWORD,
545 pub dwHighDateTime: DWORD,
549 pub struct OVERLAPPED {
550 pub Internal: *mut c_ulong,
551 pub InternalHigh: *mut c_ulong,
553 pub OffsetHigh: DWORD,
558 #[cfg(target_env = "msvc")]
559 pub struct SYMBOL_INFO {
560 pub SizeOfStruct: c_ulong,
561 pub TypeIndex: c_ulong,
562 pub Reserved: [u64; 2],
569 pub Register: c_ulong,
572 pub NameLen: c_ulong,
573 pub MaxNameLen: c_ulong,
574 // note that windows has this as 1, but it basically just means that
575 // the name is inline at the end of the struct. For us, we just bump
576 // the struct size up to MAX_SYM_NAME.
577 pub Name: [c_char; MAX_SYM_NAME],
581 #[cfg(target_env = "msvc")]
582 pub struct IMAGEHLP_LINE64 {
583 pub SizeOfStruct: u32,
584 pub Key: *const c_void,
586 pub Filename: *const c_char,
591 #[allow(dead_code)] // we only use some variants
592 pub enum ADDRESS_MODE {
600 pub struct ADDRESS64 {
603 pub Mode: ADDRESS_MODE,
607 pub struct STACKFRAME64 {
608 pub AddrPC: ADDRESS64,
609 pub AddrReturn: ADDRESS64,
610 pub AddrFrame: ADDRESS64,
611 pub AddrStack: ADDRESS64,
612 pub AddrBStore: ADDRESS64,
613 pub FuncTableEntry: *mut c_void,
614 pub Params: [u64; 4],
617 pub Reserved: [u64; 3],
618 pub KdHelp: KDHELP64,
622 pub struct KDHELP64 {
624 pub ThCallbackStack: DWORD,
625 pub ThCallbackBStore: DWORD,
626 pub NextCallback: DWORD,
627 pub FramePointer: DWORD,
628 pub KiCallUserMode: u64,
629 pub KeUserCallbackDispatcher: u64,
630 pub SystemRangeStart: u64,
631 pub KiUserExceptionDispatcher: u64,
634 pub Reserved: [u64; 5],
637 #[cfg(target_arch = "x86")]
640 pub ContextFlags: DWORD,
647 pub FloatSave: FLOATING_SAVE_AREA,
664 pub ExtendedRegisters: [u8; 512],
667 #[cfg(target_arch = "x86")]
669 pub struct FLOATING_SAVE_AREA {
670 pub ControlWord: DWORD,
671 pub StatusWord: DWORD,
673 pub ErrorOffset: DWORD,
674 pub ErrorSelector: DWORD,
675 pub DataOffset: DWORD,
676 pub DataSelector: DWORD,
677 pub RegisterArea: [u8; 80],
678 pub Cr0NpxState: DWORD,
681 #[cfg(target_arch = "x86_64")]
684 _align_hack: [u64x2; 0], // FIXME align on 16-byte
685 pub P1Home: DWORDLONG,
686 pub P2Home: DWORDLONG,
687 pub P3Home: DWORDLONG,
688 pub P4Home: DWORDLONG,
689 pub P5Home: DWORDLONG,
690 pub P6Home: DWORDLONG,
692 pub ContextFlags: DWORD,
729 pub FltSave: FLOATING_SAVE_AREA,
731 pub VectorRegister: [M128A; 26],
732 pub VectorControl: DWORDLONG,
734 pub DebugControl: DWORDLONG,
735 pub LastBranchToRip: DWORDLONG,
736 pub LastBranchFromRip: DWORDLONG,
737 pub LastExceptionToRip: DWORDLONG,
738 pub LastExceptionFromRip: DWORDLONG,
741 #[cfg(target_arch = "x86_64")]
744 _align_hack: [u64x2; 0], // FIXME align on 16-byte
745 pub Low: c_ulonglong,
749 #[cfg(target_arch = "x86_64")]
751 pub struct FLOATING_SAVE_AREA {
752 _align_hack: [u64x2; 0], // FIXME align on 16-byte
753 _Dummy: [u8; 512] // FIXME: Fill this out
757 pub struct SOCKADDR_STORAGE_LH {
758 pub ss_family: ADDRESS_FAMILY,
759 pub __ss_pad1: [CHAR; 6],
761 pub __ss_pad2: [CHAR; 112],
765 pub struct ADDRINFOA {
767 pub ai_family: c_int,
768 pub ai_socktype: c_int,
769 pub ai_protocol: c_int,
770 pub ai_addrlen: size_t,
771 pub ai_canonname: *mut c_char,
772 pub ai_addr: *mut SOCKADDR,
773 pub ai_next: *mut ADDRINFOA,
777 #[derive(Copy, Clone)]
778 pub struct sockaddr_in {
779 pub sin_family: ADDRESS_FAMILY,
780 pub sin_port: USHORT,
781 pub sin_addr: in_addr,
782 pub sin_zero: [CHAR; 8],
786 #[derive(Copy, Clone)]
787 pub struct sockaddr_in6 {
788 pub sin6_family: ADDRESS_FAMILY,
789 pub sin6_port: USHORT,
790 pub sin6_flowinfo: c_ulong,
791 pub sin6_addr: in6_addr,
792 pub sin6_scope_id: c_ulong,
796 #[derive(Copy, Clone)]
802 #[derive(Copy, Clone)]
803 pub struct in6_addr {
804 pub s6_addr: [u8; 16],
807 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
808 pub enum UNWIND_HISTORY_TABLE {}
811 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
812 pub struct RUNTIME_FUNCTION {
813 pub BeginAddress: DWORD,
814 pub EndAddress: DWORD,
815 pub UnwindData: DWORD,
819 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
820 pub struct DISPATCHER_CONTEXT {
821 pub ControlPc: LPVOID,
822 pub ImageBase: LPVOID,
823 pub FunctionEntry: *const RUNTIME_FUNCTION,
824 pub EstablisherFrame: LPVOID,
825 pub TargetIp: LPVOID,
826 pub ContextRecord: *const CONTEXT,
827 pub LanguageHandler: LPVOID,
828 pub HandlerData: *const u8,
829 pub HistoryTable: *const UNWIND_HISTORY_TABLE,
833 #[derive(Copy, Clone)]
834 #[allow(dead_code)] // we only use some variants
835 pub enum EXCEPTION_DISPOSITION {
836 ExceptionContinueExecution,
837 ExceptionContinueSearch,
838 ExceptionNestedException,
839 ExceptionCollidedUnwind
842 #[link(name = "ws2_32")]
843 #[link(name = "userenv")]
844 #[link(name = "shell32")]
845 #[link(name = "advapi32")]
846 #[cfg(not(cargobuild))]
850 pub fn WSAStartup(wVersionRequested: WORD,
851 lpWSAData: LPWSADATA) -> c_int;
852 pub fn WSACleanup() -> c_int;
853 pub fn WSAGetLastError() -> c_int;
854 pub fn WSADuplicateSocketW(s: SOCKET,
856 lpProtocolInfo: LPWSAPROTOCOL_INFO)
858 pub fn GetCurrentProcessId() -> DWORD;
859 pub fn WSASocketW(af: c_int,
862 lpProtocolInfo: LPWSAPROTOCOL_INFO,
864 dwFlags: DWORD) -> SOCKET;
865 pub fn ioctlsocket(s: SOCKET, cmd: c_long, argp: *mut c_ulong) -> c_int;
866 pub fn InitializeCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
867 pub fn EnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
868 pub fn TryEnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION) -> BOOLEAN;
869 pub fn LeaveCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
870 pub fn DeleteCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
872 // FIXME - pInputControl should be PCONSOLE_READCONSOLE_CONTROL
873 pub fn ReadConsoleW(hConsoleInput: HANDLE,
875 nNumberOfCharsToRead: DWORD,
876 lpNumberOfCharsRead: LPDWORD,
877 pInputControl: LPVOID) -> BOOL;
879 pub fn WriteConsoleW(hConsoleOutput: HANDLE,
881 nNumberOfCharsToWrite: DWORD,
882 lpNumberOfCharsWritten: LPDWORD,
883 lpReserved: LPVOID) -> BOOL;
885 pub fn GetConsoleMode(hConsoleHandle: HANDLE,
886 lpMode: LPDWORD) -> BOOL;
887 pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
888 pub fn SetFileAttributesW(lpFileName: LPCWSTR,
889 dwFileAttributes: DWORD) -> BOOL;
890 pub fn GetFileInformationByHandle(hFile: HANDLE,
891 lpFileInformation: LPBY_HANDLE_FILE_INFORMATION)
894 pub fn SetLastError(dwErrCode: DWORD);
895 pub fn GetCommandLineW() -> *mut LPCWSTR;
896 pub fn LocalFree(ptr: *mut c_void);
897 pub fn CommandLineToArgvW(lpCmdLine: *mut LPCWSTR,
898 pNumArgs: *mut c_int) -> *mut *mut u16;
899 pub fn GetTempPathW(nBufferLength: DWORD,
900 lpBuffer: LPCWSTR) -> DWORD;
901 pub fn OpenProcessToken(ProcessHandle: HANDLE,
902 DesiredAccess: DWORD,
903 TokenHandle: *mut HANDLE) -> BOOL;
904 pub fn GetCurrentProcess() -> HANDLE;
905 pub fn GetCurrentThread() -> HANDLE;
906 pub fn GetStdHandle(which: DWORD) -> HANDLE;
907 pub fn ExitProcess(uExitCode: c_uint) -> !;
908 pub fn DeviceIoControl(hDevice: HANDLE,
909 dwIoControlCode: DWORD,
911 nInBufferSize: DWORD,
913 nOutBufferSize: DWORD,
914 lpBytesReturned: LPDWORD,
915 lpOverlapped: LPOVERLAPPED) -> BOOL;
916 pub fn CreatePipe(hReadPipe: LPHANDLE,
917 hWritePipe: LPHANDLE,
918 lpPipeAttributes: LPSECURITY_ATTRIBUTES,
919 nSize: DWORD) -> BOOL;
920 pub fn CreateThread(lpThreadAttributes: LPSECURITY_ATTRIBUTES,
922 lpStartAddress: extern "system" fn(*mut c_void)
925 dwCreationFlags: DWORD,
926 lpThreadId: LPDWORD) -> HANDLE;
927 pub fn WaitForSingleObject(hHandle: HANDLE,
928 dwMilliseconds: DWORD) -> DWORD;
929 pub fn SwitchToThread() -> BOOL;
930 pub fn Sleep(dwMilliseconds: DWORD);
931 pub fn GetProcessId(handle: HANDLE) -> DWORD;
932 pub fn GetUserProfileDirectoryW(hToken: HANDLE,
933 lpProfileDir: LPCWSTR,
934 lpcchSize: *mut DWORD) -> BOOL;
935 pub fn SetHandleInformation(hObject: HANDLE,
937 dwFlags: DWORD) -> BOOL;
938 pub fn CopyFileExW(lpExistingFileName: LPCWSTR,
939 lpNewFileName: LPCWSTR,
940 lpProgressRoutine: LPPROGRESS_ROUTINE,
943 dwCopyFlags: DWORD) -> BOOL;
944 pub fn AddVectoredExceptionHandler(FirstHandler: ULONG,
945 VectoredHandler: PVECTORED_EXCEPTION_HANDLER)
947 pub fn FormatMessageW(flags: DWORD,
955 pub fn TlsAlloc() -> DWORD;
956 pub fn TlsFree(dwTlsIndex: DWORD) -> BOOL;
957 pub fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID;
958 pub fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL;
959 pub fn GetLastError() -> DWORD;
960 pub fn QueryPerformanceFrequency(lpFrequency: *mut LARGE_INTEGER) -> BOOL;
961 pub fn QueryPerformanceCounter(lpPerformanceCount: *mut LARGE_INTEGER)
963 pub fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: LPDWORD) -> BOOL;
964 pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) -> BOOL;
965 pub fn CreateProcessW(lpApplicationName: LPCWSTR,
966 lpCommandLine: LPWSTR,
967 lpProcessAttributes: LPSECURITY_ATTRIBUTES,
968 lpThreadAttributes: LPSECURITY_ATTRIBUTES,
969 bInheritHandles: BOOL,
970 dwCreationFlags: DWORD,
971 lpEnvironment: LPVOID,
972 lpCurrentDirectory: LPCWSTR,
973 lpStartupInfo: LPSTARTUPINFO,
974 lpProcessInformation: LPPROCESS_INFORMATION)
976 pub fn GetEnvironmentVariableW(n: LPCWSTR, v: LPWSTR, nsize: DWORD) -> DWORD;
977 pub fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL;
978 pub fn GetEnvironmentStringsW() -> LPWCH;
979 pub fn FreeEnvironmentStringsW(env_ptr: LPWCH) -> BOOL;
980 pub fn GetModuleFileNameW(hModule: HMODULE,
984 pub fn CreateDirectoryW(lpPathName: LPCWSTR,
985 lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
987 pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
988 pub fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: LPWSTR) -> DWORD;
989 pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
991 pub fn closesocket(socket: SOCKET) -> c_int;
992 pub fn recv(socket: SOCKET, buf: *mut c_void, len: c_int,
993 flags: c_int) -> c_int;
994 pub fn send(socket: SOCKET, buf: *const c_void, len: c_int,
995 flags: c_int) -> c_int;
996 pub fn recvfrom(socket: SOCKET,
1000 addr: *mut SOCKADDR,
1001 addrlen: *mut c_int)
1003 pub fn sendto(socket: SOCKET,
1007 addr: *const SOCKADDR,
1010 pub fn shutdown(socket: SOCKET, how: c_int) -> c_int;
1011 pub fn accept(socket: SOCKET,
1012 address: *mut SOCKADDR,
1013 address_len: *mut c_int)
1015 pub fn DuplicateHandle(hSourceProcessHandle: HANDLE,
1016 hSourceHandle: HANDLE,
1017 hTargetProcessHandle: HANDLE,
1018 lpTargetHandle: LPHANDLE,
1019 dwDesiredAccess: DWORD,
1020 bInheritHandle: BOOL,
1023 pub fn ReadFile(hFile: HANDLE,
1025 nNumberOfBytesToRead: DWORD,
1026 lpNumberOfBytesRead: LPDWORD,
1027 lpOverlapped: LPOVERLAPPED)
1029 pub fn WriteFile(hFile: HANDLE,
1031 nNumberOfBytesToWrite: DWORD,
1032 lpNumberOfBytesWritten: LPDWORD,
1033 lpOverlapped: LPOVERLAPPED)
1035 pub fn CloseHandle(hObject: HANDLE) -> BOOL;
1036 pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR,
1037 lpTargetFileName: LPCWSTR,
1038 lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
1040 pub fn MoveFileExW(lpExistingFileName: LPCWSTR,
1041 lpNewFileName: LPCWSTR,
1044 pub fn SetFilePointerEx(hFile: HANDLE,
1045 liDistanceToMove: LARGE_INTEGER,
1046 lpNewFilePointer: PLARGE_INTEGER,
1047 dwMoveMethod: DWORD)
1049 pub fn FlushFileBuffers(hFile: HANDLE) -> BOOL;
1050 pub fn CreateFileW(lpFileName: LPCWSTR,
1051 dwDesiredAccess: DWORD,
1053 lpSecurityAttributes: LPSECURITY_ATTRIBUTES,
1054 dwCreationDisposition: DWORD,
1055 dwFlagsAndAttributes: DWORD,
1056 hTemplateFile: HANDLE)
1059 pub fn FindFirstFileW(fileName: LPCWSTR,
1060 findFileData: LPWIN32_FIND_DATAW)
1062 pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW)
1064 pub fn FindClose(findFile: HANDLE) -> BOOL;
1065 pub fn RtlCaptureContext(ctx: *mut CONTEXT);
1066 pub fn getsockopt(s: SOCKET,
1069 optval: *mut c_char,
1072 pub fn setsockopt(s: SOCKET,
1075 optval: *const c_void,
1078 pub fn getsockname(socket: SOCKET,
1079 address: *mut SOCKADDR,
1080 address_len: *mut c_int)
1082 pub fn getpeername(socket: SOCKET,
1083 address: *mut SOCKADDR,
1084 address_len: *mut c_int)
1086 pub fn bind(socket: SOCKET, address: *const SOCKADDR,
1087 address_len: socklen_t) -> c_int;
1088 pub fn listen(socket: SOCKET, backlog: c_int) -> c_int;
1089 pub fn connect(socket: SOCKET, address: *const SOCKADDR, len: c_int)
1091 pub fn getaddrinfo(node: *const c_char, service: *const c_char,
1092 hints: *const ADDRINFOA,
1093 res: *mut *mut ADDRINFOA) -> c_int;
1094 pub fn freeaddrinfo(res: *mut ADDRINFOA);
1095 pub fn getnameinfo(sa: *const SOCKADDR, salen: c_int,
1096 host: *mut c_char, hostlen: DWORD,
1097 serv: *mut c_char, servlen: DWORD,
1098 flags: c_int) -> c_int;
1100 pub fn LoadLibraryW(name: LPCWSTR) -> HMODULE;
1101 pub fn GetModuleHandleExW(dwFlags: DWORD, name: LPCWSTR,
1102 handle: *mut HMODULE) -> BOOL;
1103 pub fn GetProcAddress(handle: HMODULE,
1104 name: LPCSTR) -> *mut c_void;
1105 pub fn FreeLibrary(handle: HMODULE) -> BOOL;
1106 pub fn SetErrorMode(uMode: c_uint) -> c_uint;
1107 pub fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE;
1108 pub fn CryptAcquireContextA(phProv: *mut HCRYPTPROV,
1109 pszContainer: LPCSTR,
1110 pszProvider: LPCSTR,
1112 dwFlags: DWORD) -> BOOL;
1113 pub fn CryptGenRandom(hProv: HCRYPTPROV,
1115 pbBuffer: *mut BYTE) -> BOOL;
1116 pub fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL;
1119 #[cfg(any(target_arch = "x86_64", target_env = "msvc"))]
1120 pub fn RaiseException(dwExceptionCode: DWORD,
1121 dwExceptionFlags: DWORD,
1122 nNumberOfArguments: DWORD,
1123 lpArguments: *const ULONG_PTR);
1124 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
1125 pub fn RtlUnwindEx(TargetFrame: LPVOID,
1127 ExceptionRecord: *const EXCEPTION_RECORD,
1128 ReturnValue: LPVOID,
1129 OriginalContext: *const CONTEXT,
1130 HistoryTable: *const UNWIND_HISTORY_TABLE);
1131 pub fn GetSystemTimeAsFileTime(lpSystemTimeAsFileTime: LPFILETIME);
1134 // Functions that aren't available on Windows XP, but we still use them and just
1135 // provide some form of a fallback implementation.
1139 pub fn CreateSymbolicLinkW(_lpSymlinkFileName: LPCWSTR,
1140 _lpTargetFileName: LPCWSTR,
1141 _dwFlags: DWORD) -> BOOLEAN {
1142 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1144 pub fn GetFinalPathNameByHandleW(_hFile: HANDLE,
1145 _lpszFilePath: LPCWSTR,
1146 _cchFilePath: DWORD,
1147 _dwFlags: DWORD) -> DWORD {
1148 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1150 pub fn SetThreadErrorMode(_dwNewMode: DWORD,
1151 _lpOldMode: *mut DWORD) -> c_uint {
1152 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1154 pub fn SetThreadStackGuarantee(_size: *mut c_ulong) -> BOOL {
1155 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1157 pub fn SetFileInformationByHandle(_hFile: HANDLE,
1158 _FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,
1159 _lpFileInformation: LPVOID,
1160 _dwBufferSize: DWORD) -> BOOL {
1161 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1163 pub fn SleepConditionVariableSRW(ConditionVariable: PCONDITION_VARIABLE,
1165 dwMilliseconds: DWORD,
1166 Flags: ULONG) -> BOOL {
1167 panic!("condition variables not available")
1169 pub fn WakeConditionVariable(ConditionVariable: PCONDITION_VARIABLE)
1171 panic!("condition variables not available")
1173 pub fn WakeAllConditionVariable(ConditionVariable: PCONDITION_VARIABLE)
1175 panic!("condition variables not available")
1177 pub fn AcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> () {
1178 panic!("rwlocks not available")
1180 pub fn AcquireSRWLockShared(SRWLock: PSRWLOCK) -> () {
1181 panic!("rwlocks not available")
1183 pub fn ReleaseSRWLockExclusive(SRWLock: PSRWLOCK) -> () {
1184 panic!("rwlocks not available")
1186 pub fn ReleaseSRWLockShared(SRWLock: PSRWLOCK) -> () {
1187 panic!("rwlocks not available")
1189 pub fn TryAcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> BOOLEAN {
1190 panic!("rwlocks not available")
1192 pub fn TryAcquireSRWLockShared(SRWLock: PSRWLOCK) -> BOOLEAN {
1193 panic!("rwlocks not available")