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;
119 pub struct WIN32_FIND_DATAW {
120 pub dwFileAttributes: DWORD,
121 pub ftCreationTime: FILETIME,
122 pub ftLastAccessTime: FILETIME,
123 pub ftLastWriteTime: FILETIME,
124 pub nFileSizeHigh: DWORD,
125 pub nFileSizeLow: DWORD,
126 pub dwReserved0: DWORD,
127 pub dwReserved1: DWORD,
128 pub cFileName: [wchar_t; 260], // #define MAX_PATH 260
129 pub cAlternateFileName: [wchar_t; 14],
131 impl Clone for WIN32_FIND_DATAW {
132 fn clone(&self) -> Self { *self }
135 pub const WSA_FLAG_OVERLAPPED: DWORD = 0x01;
137 pub const WSADESCRIPTION_LEN: usize = 256;
138 pub const WSASYS_STATUS_LEN: usize = 128;
139 pub const WSAPROTOCOL_LEN: DWORD = 255;
140 pub const INVALID_SOCKET: SOCKET = !0;
142 pub const WSAEACCES: c_int = 10013;
143 pub const WSAEINVAL: c_int = 10022;
144 pub const WSAEWOULDBLOCK: c_int = 10035;
145 pub const WSAEADDRINUSE: c_int = 10048;
146 pub const WSAEADDRNOTAVAIL: c_int = 10049;
147 pub const WSAECONNABORTED: c_int = 10053;
148 pub const WSAECONNRESET: c_int = 10054;
149 pub const WSAENOTCONN: c_int = 10057;
150 pub const WSAESHUTDOWN: c_int = 10058;
151 pub const WSAETIMEDOUT: c_int = 10060;
152 pub const WSAECONNREFUSED: c_int = 10061;
154 pub const NI_MAXHOST: DWORD = 1025;
156 pub const MAX_PROTOCOL_CHAIN: DWORD = 7;
158 pub const TOKEN_READ: DWORD = 0x20008;
159 pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024;
160 pub const FSCTL_GET_REPARSE_POINT: DWORD = 0x900a8;
161 pub const IO_REPARSE_TAG_SYMLINK: DWORD = 0xa000000c;
162 pub const IO_REPARSE_TAG_MOUNT_POINT: DWORD = 0xa0000003;
163 pub const SYMLINK_FLAG_RELATIVE: DWORD = 0x00000001;
164 pub const FSCTL_SET_REPARSE_POINT: DWORD = 0x900a4;
166 pub const SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 0x1;
168 // Note that these are not actually HANDLEs, just values to pass to GetStdHandle
169 pub const STD_INPUT_HANDLE: DWORD = -10i32 as DWORD;
170 pub const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
171 pub const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
173 pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001;
175 pub const PROGRESS_CONTINUE: DWORD = 0;
177 pub const ERROR_FILE_NOT_FOUND: DWORD = 2;
178 pub const ERROR_PATH_NOT_FOUND: DWORD = 3;
179 pub const ERROR_ACCESS_DENIED: DWORD = 5;
180 pub const ERROR_INVALID_HANDLE: DWORD = 6;
181 pub const ERROR_NO_MORE_FILES: DWORD = 18;
182 pub const ERROR_BROKEN_PIPE: DWORD = 109;
183 pub const ERROR_CALL_NOT_IMPLEMENTED: DWORD = 120;
184 pub const ERROR_INSUFFICIENT_BUFFER: DWORD = 122;
185 pub const ERROR_ALREADY_EXISTS: DWORD = 183;
186 pub const ERROR_NO_DATA: DWORD = 232;
187 pub const ERROR_ENVVAR_NOT_FOUND: DWORD = 203;
188 pub const ERROR_OPERATION_ABORTED: DWORD = 995;
189 pub const ERROR_TIMEOUT: DWORD = 0x5B4;
191 pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE;
193 pub const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000;
194 pub const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200;
196 pub const TLS_OUT_OF_INDEXES: DWORD = 0xFFFFFFFF;
198 pub const DLL_THREAD_DETACH: DWORD = 3;
199 pub const DLL_PROCESS_DETACH: DWORD = 0;
201 pub const INFINITE: DWORD = !0;
203 pub const DUPLICATE_SAME_ACCESS: DWORD = 0x00000002;
205 pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE {
206 ptr: ptr::null_mut(),
208 pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: ptr::null_mut() };
210 pub const DETACHED_PROCESS: DWORD = 0x00000008;
211 pub const CREATE_NEW_PROCESS_GROUP: DWORD = 0x00000200;
212 pub const CREATE_UNICODE_ENVIRONMENT: DWORD = 0x00000400;
213 pub const STARTF_USESTDHANDLES: DWORD = 0x00000100;
215 pub const AF_INET: c_int = 2;
216 pub const AF_INET6: c_int = 23;
217 pub const SD_BOTH: c_int = 2;
218 pub const SD_RECEIVE: c_int = 0;
219 pub const SD_SEND: c_int = 1;
220 pub const SOCK_DGRAM: c_int = 2;
221 pub const SOCK_STREAM: c_int = 1;
222 pub const SOL_SOCKET: c_int = 0xffff;
223 pub const SO_RCVTIMEO: c_int = 0x1006;
224 pub const SO_SNDTIMEO: c_int = 0x1005;
225 pub const SO_REUSEADDR: c_int = 0x0004;
227 pub const VOLUME_NAME_DOS: DWORD = 0x0;
228 pub const MOVEFILE_REPLACE_EXISTING: DWORD = 1;
230 pub const FILE_BEGIN: DWORD = 0;
231 pub const FILE_CURRENT: DWORD = 1;
232 pub const FILE_END: DWORD = 2;
234 pub const WAIT_OBJECT_0: DWORD = 0x00000000;
236 #[cfg(target_env = "msvc")]
237 pub const MAX_SYM_NAME: usize = 2000;
238 #[cfg(target_arch = "x86")]
239 pub const IMAGE_FILE_MACHINE_I386: DWORD = 0x014c;
240 #[cfg(target_arch = "x86_64")]
241 pub const IMAGE_FILE_MACHINE_AMD64: DWORD = 0x8664;
243 pub const PROV_RSA_FULL: DWORD = 1;
244 pub const CRYPT_SILENT: DWORD = 64;
245 pub const CRYPT_VERIFYCONTEXT: DWORD = 0xF0000000;
247 pub const EXCEPTION_CONTINUE_SEARCH: LONG = 0;
248 pub const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd;
249 pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15;
250 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
251 pub const EXCEPTION_NONCONTINUABLE: DWORD = 0x1; // Noncontinuable exception
252 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
253 pub const EXCEPTION_UNWINDING: DWORD = 0x2; // Unwind is in progress
254 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
255 pub const EXCEPTION_EXIT_UNWIND: DWORD = 0x4; // Exit unwind is in progress
256 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
257 pub const EXCEPTION_TARGET_UNWIND: DWORD = 0x20; // Target unwind in progress
258 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
259 pub const EXCEPTION_COLLIDED_UNWIND: DWORD = 0x40; // Collided exception handler call
260 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
261 pub const EXCEPTION_UNWIND: DWORD = EXCEPTION_UNWINDING |
262 EXCEPTION_EXIT_UNWIND |
263 EXCEPTION_TARGET_UNWIND |
264 EXCEPTION_COLLIDED_UNWIND;
267 #[cfg(target_arch = "x86")]
270 pub wHighVersion: WORD,
271 pub szDescription: [u8; WSADESCRIPTION_LEN + 1],
272 pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
273 pub iMaxSockets: u16,
275 pub lpVendorInfo: *mut u8,
278 #[cfg(target_arch = "x86_64")]
281 pub wHighVersion: WORD,
282 pub iMaxSockets: u16,
284 pub lpVendorInfo: *mut u8,
285 pub szDescription: [u8; WSADESCRIPTION_LEN + 1],
286 pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
289 pub type WSAEVENT = HANDLE;
292 pub struct WSAPROTOCOL_INFO {
293 pub dwServiceFlags1: DWORD,
294 pub dwServiceFlags2: DWORD,
295 pub dwServiceFlags3: DWORD,
296 pub dwServiceFlags4: DWORD,
297 pub dwProviderFlags: DWORD,
298 pub ProviderId: GUID,
299 pub dwCatalogEntryId: DWORD,
300 pub ProtocolChain: WSAPROTOCOLCHAIN,
302 pub iAddressFamily: c_int,
303 pub iMaxSockAddr: c_int,
304 pub iMinSockAddr: c_int,
305 pub iSocketType: c_int,
306 pub iProtocol: c_int,
307 pub iProtocolMaxOffset: c_int,
308 pub iNetworkByteOrder: c_int,
309 pub iSecurityScheme: c_int,
310 pub dwMessageSize: DWORD,
311 pub dwProviderReserved: DWORD,
312 pub szProtocol: [u16; (WSAPROTOCOL_LEN as usize) + 1],
316 #[derive(Copy, Clone)]
317 pub struct WIN32_FILE_ATTRIBUTE_DATA {
318 pub dwFileAttributes: DWORD,
319 pub ftCreationTime: FILETIME,
320 pub ftLastAccessTime: FILETIME,
321 pub ftLastWriteTime: FILETIME,
322 pub nFileSizeHigh: DWORD,
323 pub nFileSizeLow: DWORD,
327 pub struct BY_HANDLE_FILE_INFORMATION {
328 pub dwFileAttributes: DWORD,
329 pub ftCreationTime: FILETIME,
330 pub ftLastAccessTime: FILETIME,
331 pub ftLastWriteTime: FILETIME,
332 pub dwVolumeSerialNumber: DWORD,
333 pub nFileSizeHigh: DWORD,
334 pub nFileSizeLow: DWORD,
335 pub nNumberOfLinks: DWORD,
336 pub nFileIndexHigh: DWORD,
337 pub nFileIndexLow: DWORD,
341 #[allow(dead_code)] // we only use some variants
342 pub enum FILE_INFO_BY_HANDLE_CLASS {
344 FileStandardInfo = 1,
347 FileDispositionInfo = 4,
348 FileAllocationInfo = 5,
349 FileEndOfFileInfo = 6,
351 FileCompressionInfo = 8,
352 FileAttributeTagInfo = 9,
353 FileIdBothDirectoryInfo = 10, // 0xA
354 FileIdBothDirectoryRestartInfo = 11, // 0xB
355 FileIoPriorityHintInfo = 12, // 0xC
356 FileRemoteProtocolInfo = 13, // 0xD
357 FileFullDirectoryInfo = 14, // 0xE
358 FileFullDirectoryRestartInfo = 15, // 0xF
359 FileStorageInfo = 16, // 0x10
360 FileAlignmentInfo = 17, // 0x11
361 FileIdInfo = 18, // 0x12
362 FileIdExtdDirectoryInfo = 19, // 0x13
363 FileIdExtdDirectoryRestartInfo = 20, // 0x14
364 MaximumFileInfoByHandlesClass
368 pub struct FILE_END_OF_FILE_INFO {
369 pub EndOfFile: LARGE_INTEGER,
373 pub struct REPARSE_DATA_BUFFER {
374 pub ReparseTag: c_uint,
375 pub ReparseDataLength: c_ushort,
376 pub Reserved: c_ushort,
381 pub struct SYMBOLIC_LINK_REPARSE_BUFFER {
382 pub SubstituteNameOffset: c_ushort,
383 pub SubstituteNameLength: c_ushort,
384 pub PrintNameOffset: c_ushort,
385 pub PrintNameLength: c_ushort,
387 pub PathBuffer: WCHAR,
391 pub struct MOUNT_POINT_REPARSE_BUFFER {
392 pub SubstituteNameOffset: c_ushort,
393 pub SubstituteNameLength: c_ushort,
394 pub PrintNameOffset: c_ushort,
395 pub PrintNameLength: c_ushort,
396 pub PathBuffer: WCHAR,
399 pub type LPPROGRESS_ROUTINE = ::option::Option<unsafe extern "system" fn(
400 TotalFileSize: LARGE_INTEGER,
401 TotalBytesTransferred: LARGE_INTEGER,
402 StreamSize: LARGE_INTEGER,
403 StreamBytesTransferred: LARGE_INTEGER,
404 dwStreamNumber: DWORD,
405 dwCallbackReason: DWORD,
407 hDestinationFile: HANDLE,
412 pub struct CONDITION_VARIABLE { pub ptr: LPVOID }
414 pub struct SRWLOCK { pub ptr: LPVOID }
416 pub struct CRITICAL_SECTION {
417 CriticalSectionDebug: LPVOID,
419 RecursionCount: LONG,
420 OwningThread: HANDLE,
421 LockSemaphore: HANDLE,
426 pub struct REPARSE_MOUNTPOINT_DATA_BUFFER {
427 pub ReparseTag: DWORD,
428 pub ReparseDataLength: DWORD,
430 pub ReparseTargetLength: WORD,
431 pub ReparseTargetMaximumLength: WORD,
433 pub ReparseTarget: WCHAR,
437 pub struct EXCEPTION_RECORD {
438 pub ExceptionCode: DWORD,
439 pub ExceptionFlags: DWORD,
440 pub ExceptionRecord: *mut EXCEPTION_RECORD,
441 pub ExceptionAddress: LPVOID,
442 pub NumberParameters: DWORD,
443 pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS]
447 pub struct EXCEPTION_POINTERS {
448 pub ExceptionRecord: *mut EXCEPTION_RECORD,
449 pub ContextRecord: *mut CONTEXT,
452 pub type PVECTORED_EXCEPTION_HANDLER = extern "system"
453 fn(ExceptionInfo: *mut EXCEPTION_POINTERS) -> LONG;
460 pub Data4: [BYTE; 8],
464 pub struct WSAPROTOCOLCHAIN {
466 pub ChainEntries: [DWORD; MAX_PROTOCOL_CHAIN as usize],
470 pub struct SECURITY_ATTRIBUTES {
472 pub lpSecurityDescriptor: LPVOID,
473 pub bInheritHandle: BOOL,
477 pub struct PROCESS_INFORMATION {
478 pub hProcess: HANDLE,
480 pub dwProcessId: DWORD,
481 pub dwThreadId: DWORD,
485 pub struct STARTUPINFO {
487 pub lpReserved: LPWSTR,
488 pub lpDesktop: LPWSTR,
494 pub dwXCountChars: DWORD,
495 pub dwYCountCharts: DWORD,
496 pub dwFillAttribute: DWORD,
498 pub wShowWindow: WORD,
499 pub cbReserved2: WORD,
500 pub lpReserved2: LPBYTE,
501 pub hStdInput: HANDLE,
502 pub hStdOutput: HANDLE,
503 pub hStdError: HANDLE,
507 pub struct SOCKADDR {
508 pub sa_family: ADDRESS_FAMILY,
509 pub sa_data: [CHAR; 14],
513 #[derive(Copy, Clone)]
514 pub struct FILETIME {
515 pub dwLowDateTime: DWORD,
516 pub dwHighDateTime: DWORD,
520 pub struct OVERLAPPED {
521 pub Internal: *mut c_ulong,
522 pub InternalHigh: *mut c_ulong,
524 pub OffsetHigh: DWORD,
529 #[cfg(target_env = "msvc")]
530 pub struct SYMBOL_INFO {
531 pub SizeOfStruct: c_ulong,
532 pub TypeIndex: c_ulong,
533 pub Reserved: [u64; 2],
540 pub Register: c_ulong,
543 pub NameLen: c_ulong,
544 pub MaxNameLen: c_ulong,
545 // note that windows has this as 1, but it basically just means that
546 // the name is inline at the end of the struct. For us, we just bump
547 // the struct size up to MAX_SYM_NAME.
548 pub Name: [c_char; MAX_SYM_NAME],
552 #[cfg(target_env = "msvc")]
553 pub struct IMAGEHLP_LINE64 {
554 pub SizeOfStruct: u32,
555 pub Key: *const c_void,
557 pub Filename: *const c_char,
562 #[allow(dead_code)] // we only use some variants
563 pub enum ADDRESS_MODE {
571 pub struct ADDRESS64 {
574 pub Mode: ADDRESS_MODE,
578 pub struct STACKFRAME64 {
579 pub AddrPC: ADDRESS64,
580 pub AddrReturn: ADDRESS64,
581 pub AddrFrame: ADDRESS64,
582 pub AddrStack: ADDRESS64,
583 pub AddrBStore: ADDRESS64,
584 pub FuncTableEntry: *mut c_void,
585 pub Params: [u64; 4],
588 pub Reserved: [u64; 3],
589 pub KdHelp: KDHELP64,
593 pub struct KDHELP64 {
595 pub ThCallbackStack: DWORD,
596 pub ThCallbackBStore: DWORD,
597 pub NextCallback: DWORD,
598 pub FramePointer: DWORD,
599 pub KiCallUserMode: u64,
600 pub KeUserCallbackDispatcher: u64,
601 pub SystemRangeStart: u64,
602 pub KiUserExceptionDispatcher: u64,
605 pub Reserved: [u64; 5],
608 #[cfg(target_arch = "x86")]
611 pub ContextFlags: DWORD,
618 pub FloatSave: FLOATING_SAVE_AREA,
635 pub ExtendedRegisters: [u8; 512],
638 #[cfg(target_arch = "x86")]
640 pub struct FLOATING_SAVE_AREA {
641 pub ControlWord: DWORD,
642 pub StatusWord: DWORD,
644 pub ErrorOffset: DWORD,
645 pub ErrorSelector: DWORD,
646 pub DataOffset: DWORD,
647 pub DataSelector: DWORD,
648 pub RegisterArea: [u8; 80],
649 pub Cr0NpxState: DWORD,
652 #[cfg(target_arch = "x86_64")]
655 _align_hack: [u64x2; 0], // FIXME align on 16-byte
656 pub P1Home: DWORDLONG,
657 pub P2Home: DWORDLONG,
658 pub P3Home: DWORDLONG,
659 pub P4Home: DWORDLONG,
660 pub P5Home: DWORDLONG,
661 pub P6Home: DWORDLONG,
663 pub ContextFlags: DWORD,
700 pub FltSave: FLOATING_SAVE_AREA,
702 pub VectorRegister: [M128A; 26],
703 pub VectorControl: DWORDLONG,
705 pub DebugControl: DWORDLONG,
706 pub LastBranchToRip: DWORDLONG,
707 pub LastBranchFromRip: DWORDLONG,
708 pub LastExceptionToRip: DWORDLONG,
709 pub LastExceptionFromRip: DWORDLONG,
712 #[cfg(target_arch = "x86_64")]
715 _align_hack: [u64x2; 0], // FIXME align on 16-byte
716 pub Low: c_ulonglong,
720 #[cfg(target_arch = "x86_64")]
722 pub struct FLOATING_SAVE_AREA {
723 _align_hack: [u64x2; 0], // FIXME align on 16-byte
724 _Dummy: [u8; 512] // FIXME: Fill this out
728 pub struct SOCKADDR_STORAGE_LH {
729 pub ss_family: ADDRESS_FAMILY,
730 pub __ss_pad1: [CHAR; 6],
732 pub __ss_pad2: [CHAR; 112],
736 pub struct ADDRINFOA {
738 pub ai_family: c_int,
739 pub ai_socktype: c_int,
740 pub ai_protocol: c_int,
741 pub ai_addrlen: size_t,
742 pub ai_canonname: *mut c_char,
743 pub ai_addr: *mut SOCKADDR,
744 pub ai_next: *mut ADDRINFOA,
748 #[derive(Copy, Clone)]
749 pub struct sockaddr_in {
750 pub sin_family: ADDRESS_FAMILY,
751 pub sin_port: USHORT,
752 pub sin_addr: in_addr,
753 pub sin_zero: [CHAR; 8],
757 #[derive(Copy, Clone)]
758 pub struct sockaddr_in6 {
759 pub sin6_family: ADDRESS_FAMILY,
760 pub sin6_port: USHORT,
761 pub sin6_flowinfo: c_ulong,
762 pub sin6_addr: in6_addr,
763 pub sin6_scope_id: c_ulong,
767 #[derive(Copy, Clone)]
773 #[derive(Copy, Clone)]
774 pub struct in6_addr {
775 pub s6_addr: [u8; 16],
778 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
779 pub enum UNWIND_HISTORY_TABLE {}
782 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
783 pub struct RUNTIME_FUNCTION {
784 pub BeginAddress: DWORD,
785 pub EndAddress: DWORD,
786 pub UnwindData: DWORD,
790 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
791 pub struct DISPATCHER_CONTEXT {
792 pub ControlPc: LPVOID,
793 pub ImageBase: LPVOID,
794 pub FunctionEntry: *const RUNTIME_FUNCTION,
795 pub EstablisherFrame: LPVOID,
796 pub TargetIp: LPVOID,
797 pub ContextRecord: *const CONTEXT,
798 pub LanguageHandler: LPVOID,
799 pub HandlerData: *const u8,
800 pub HistoryTable: *const UNWIND_HISTORY_TABLE,
804 #[derive(Copy, Clone)]
805 #[allow(dead_code)] // we only use some variants
806 pub enum EXCEPTION_DISPOSITION {
807 ExceptionContinueExecution,
808 ExceptionContinueSearch,
809 ExceptionNestedException,
810 ExceptionCollidedUnwind
813 #[link(name = "ws2_32")]
814 #[link(name = "userenv")]
815 #[link(name = "shell32")]
816 #[link(name = "advapi32")]
817 #[cfg(not(cargobuild))]
821 pub fn WSAStartup(wVersionRequested: WORD,
822 lpWSAData: LPWSADATA) -> c_int;
823 pub fn WSACleanup() -> c_int;
824 pub fn WSAGetLastError() -> c_int;
825 pub fn WSADuplicateSocketW(s: SOCKET,
827 lpProtocolInfo: LPWSAPROTOCOL_INFO)
829 pub fn GetCurrentProcessId() -> DWORD;
830 pub fn WSASocketW(af: c_int,
833 lpProtocolInfo: LPWSAPROTOCOL_INFO,
835 dwFlags: DWORD) -> SOCKET;
836 pub fn InitializeCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
837 pub fn EnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
838 pub fn TryEnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION) -> BOOLEAN;
839 pub fn LeaveCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
840 pub fn DeleteCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
842 // FIXME - pInputControl should be PCONSOLE_READCONSOLE_CONTROL
843 pub fn ReadConsoleW(hConsoleInput: HANDLE,
845 nNumberOfCharsToRead: DWORD,
846 lpNumberOfCharsRead: LPDWORD,
847 pInputControl: LPVOID) -> BOOL;
849 pub fn WriteConsoleW(hConsoleOutput: HANDLE,
851 nNumberOfCharsToWrite: DWORD,
852 lpNumberOfCharsWritten: LPDWORD,
853 lpReserved: LPVOID) -> BOOL;
855 pub fn GetConsoleMode(hConsoleHandle: HANDLE,
856 lpMode: LPDWORD) -> BOOL;
857 pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
858 pub fn SetFileAttributesW(lpFileName: LPCWSTR,
859 dwFileAttributes: DWORD) -> BOOL;
860 pub fn GetFileInformationByHandle(hFile: HANDLE,
861 lpFileInformation: LPBY_HANDLE_FILE_INFORMATION)
864 pub fn SetLastError(dwErrCode: DWORD);
865 pub fn GetCommandLineW() -> *mut LPCWSTR;
866 pub fn LocalFree(ptr: *mut c_void);
867 pub fn CommandLineToArgvW(lpCmdLine: *mut LPCWSTR,
868 pNumArgs: *mut c_int) -> *mut *mut u16;
869 pub fn GetTempPathW(nBufferLength: DWORD,
870 lpBuffer: LPCWSTR) -> DWORD;
871 pub fn OpenProcessToken(ProcessHandle: HANDLE,
872 DesiredAccess: DWORD,
873 TokenHandle: *mut HANDLE) -> BOOL;
874 pub fn GetCurrentProcess() -> HANDLE;
875 pub fn GetCurrentThread() -> HANDLE;
876 pub fn GetStdHandle(which: DWORD) -> HANDLE;
877 pub fn ExitProcess(uExitCode: c_uint) -> !;
878 pub fn DeviceIoControl(hDevice: HANDLE,
879 dwIoControlCode: DWORD,
881 nInBufferSize: DWORD,
883 nOutBufferSize: DWORD,
884 lpBytesReturned: LPDWORD,
885 lpOverlapped: LPOVERLAPPED) -> BOOL;
886 pub fn CreatePipe(hReadPipe: LPHANDLE,
887 hWritePipe: LPHANDLE,
888 lpPipeAttributes: LPSECURITY_ATTRIBUTES,
889 nSize: DWORD) -> BOOL;
890 pub fn CreateThread(lpThreadAttributes: LPSECURITY_ATTRIBUTES,
892 lpStartAddress: extern "system" fn(*mut c_void)
895 dwCreationFlags: DWORD,
896 lpThreadId: LPDWORD) -> HANDLE;
897 pub fn WaitForSingleObject(hHandle: HANDLE,
898 dwMilliseconds: DWORD) -> DWORD;
899 pub fn SwitchToThread() -> BOOL;
900 pub fn Sleep(dwMilliseconds: DWORD);
901 pub fn GetProcessId(handle: HANDLE) -> DWORD;
902 pub fn GetUserProfileDirectoryW(hToken: HANDLE,
903 lpProfileDir: LPCWSTR,
904 lpcchSize: *mut DWORD) -> BOOL;
905 pub fn SetHandleInformation(hObject: HANDLE,
907 dwFlags: DWORD) -> BOOL;
908 pub fn CopyFileExW(lpExistingFileName: LPCWSTR,
909 lpNewFileName: LPCWSTR,
910 lpProgressRoutine: LPPROGRESS_ROUTINE,
913 dwCopyFlags: DWORD) -> BOOL;
914 pub fn AddVectoredExceptionHandler(FirstHandler: ULONG,
915 VectoredHandler: PVECTORED_EXCEPTION_HANDLER)
917 pub fn FormatMessageW(flags: DWORD,
925 pub fn TlsAlloc() -> DWORD;
926 pub fn TlsFree(dwTlsIndex: DWORD) -> BOOL;
927 pub fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID;
928 pub fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL;
929 pub fn GetLastError() -> DWORD;
930 pub fn QueryPerformanceFrequency(lpFrequency: *mut LARGE_INTEGER) -> BOOL;
931 pub fn QueryPerformanceCounter(lpPerformanceCount: *mut LARGE_INTEGER)
933 pub fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: LPDWORD) -> BOOL;
934 pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) -> BOOL;
935 pub fn CreateProcessW(lpApplicationName: LPCWSTR,
936 lpCommandLine: LPWSTR,
937 lpProcessAttributes: LPSECURITY_ATTRIBUTES,
938 lpThreadAttributes: LPSECURITY_ATTRIBUTES,
939 bInheritHandles: BOOL,
940 dwCreationFlags: DWORD,
941 lpEnvironment: LPVOID,
942 lpCurrentDirectory: LPCWSTR,
943 lpStartupInfo: LPSTARTUPINFO,
944 lpProcessInformation: LPPROCESS_INFORMATION)
946 pub fn GetEnvironmentVariableW(n: LPCWSTR, v: LPWSTR, nsize: DWORD) -> DWORD;
947 pub fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL;
948 pub fn GetEnvironmentStringsW() -> LPWCH;
949 pub fn FreeEnvironmentStringsW(env_ptr: LPWCH) -> BOOL;
950 pub fn GetModuleFileNameW(hModule: HMODULE,
954 pub fn CreateDirectoryW(lpPathName: LPCWSTR,
955 lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
957 pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
958 pub fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: LPWSTR) -> DWORD;
959 pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
961 pub fn closesocket(socket: SOCKET) -> c_int;
962 pub fn recv(socket: SOCKET, buf: *mut c_void, len: c_int,
963 flags: c_int) -> c_int;
964 pub fn send(socket: SOCKET, buf: *const c_void, len: c_int,
965 flags: c_int) -> c_int;
966 pub fn recvfrom(socket: SOCKET,
973 pub fn sendto(socket: SOCKET,
977 addr: *const SOCKADDR,
980 pub fn shutdown(socket: SOCKET, how: c_int) -> c_int;
981 pub fn accept(socket: SOCKET,
982 address: *mut SOCKADDR,
983 address_len: *mut c_int)
985 pub fn DuplicateHandle(hSourceProcessHandle: HANDLE,
986 hSourceHandle: HANDLE,
987 hTargetProcessHandle: HANDLE,
988 lpTargetHandle: LPHANDLE,
989 dwDesiredAccess: DWORD,
990 bInheritHandle: BOOL,
993 pub fn ReadFile(hFile: HANDLE,
995 nNumberOfBytesToRead: DWORD,
996 lpNumberOfBytesRead: LPDWORD,
997 lpOverlapped: LPOVERLAPPED)
999 pub fn WriteFile(hFile: HANDLE,
1001 nNumberOfBytesToWrite: DWORD,
1002 lpNumberOfBytesWritten: LPDWORD,
1003 lpOverlapped: LPOVERLAPPED)
1005 pub fn CloseHandle(hObject: HANDLE) -> BOOL;
1006 pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR,
1007 lpTargetFileName: LPCWSTR,
1008 lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
1010 pub fn MoveFileExW(lpExistingFileName: LPCWSTR,
1011 lpNewFileName: LPCWSTR,
1014 pub fn SetFilePointerEx(hFile: HANDLE,
1015 liDistanceToMove: LARGE_INTEGER,
1016 lpNewFilePointer: PLARGE_INTEGER,
1017 dwMoveMethod: DWORD)
1019 pub fn FlushFileBuffers(hFile: HANDLE) -> BOOL;
1020 pub fn CreateFileW(lpFileName: LPCWSTR,
1021 dwDesiredAccess: DWORD,
1023 lpSecurityAttributes: LPSECURITY_ATTRIBUTES,
1024 dwCreationDisposition: DWORD,
1025 dwFlagsAndAttributes: DWORD,
1026 hTemplateFile: HANDLE)
1029 pub fn FindFirstFileW(fileName: LPCWSTR,
1030 findFileData: LPWIN32_FIND_DATAW)
1032 pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW)
1034 pub fn FindClose(findFile: HANDLE) -> BOOL;
1035 pub fn RtlCaptureContext(ctx: *mut CONTEXT);
1036 pub fn getsockopt(s: SOCKET,
1039 optval: *mut c_char,
1042 pub fn setsockopt(s: SOCKET,
1045 optval: *const c_void,
1048 pub fn getsockname(socket: SOCKET,
1049 address: *mut SOCKADDR,
1050 address_len: *mut c_int)
1052 pub fn getpeername(socket: SOCKET,
1053 address: *mut SOCKADDR,
1054 address_len: *mut c_int)
1056 pub fn bind(socket: SOCKET, address: *const SOCKADDR,
1057 address_len: socklen_t) -> c_int;
1058 pub fn listen(socket: SOCKET, backlog: c_int) -> c_int;
1059 pub fn connect(socket: SOCKET, address: *const SOCKADDR, len: c_int)
1061 pub fn getaddrinfo(node: *const c_char, service: *const c_char,
1062 hints: *const ADDRINFOA,
1063 res: *mut *mut ADDRINFOA) -> c_int;
1064 pub fn freeaddrinfo(res: *mut ADDRINFOA);
1065 pub fn getnameinfo(sa: *const SOCKADDR, salen: c_int,
1066 host: *mut c_char, hostlen: DWORD,
1067 serv: *mut c_char, servlen: DWORD,
1068 flags: c_int) -> c_int;
1070 pub fn LoadLibraryW(name: LPCWSTR) -> HMODULE;
1071 pub fn GetModuleHandleExW(dwFlags: DWORD, name: LPCWSTR,
1072 handle: *mut HMODULE) -> BOOL;
1073 pub fn GetProcAddress(handle: HMODULE,
1074 name: LPCSTR) -> *mut c_void;
1075 pub fn FreeLibrary(handle: HMODULE) -> BOOL;
1076 pub fn SetErrorMode(uMode: c_uint) -> c_uint;
1077 pub fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE;
1078 pub fn CryptAcquireContextA(phProv: *mut HCRYPTPROV,
1079 pszContainer: LPCSTR,
1080 pszProvider: LPCSTR,
1082 dwFlags: DWORD) -> BOOL;
1083 pub fn CryptGenRandom(hProv: HCRYPTPROV,
1085 pbBuffer: *mut BYTE) -> BOOL;
1086 pub fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL;
1089 pub fn RaiseException(dwExceptionCode: DWORD,
1090 dwExceptionFlags: DWORD,
1091 nNumberOfArguments: DWORD,
1092 lpArguments: *const ULONG_PTR);
1093 #[cfg(all(target_arch = "x86_64", target_env = "gnu"))]
1094 pub fn RtlUnwindEx(TargetFrame: LPVOID,
1096 ExceptionRecord: *const EXCEPTION_RECORD,
1097 ReturnValue: LPVOID,
1098 OriginalContext: *const CONTEXT,
1099 HistoryTable: *const UNWIND_HISTORY_TABLE);
1100 pub fn GetSystemTimeAsFileTime(lpSystemTimeAsFileTime: LPFILETIME);
1103 // Functions that aren't available on Windows XP, but we still use them and just
1104 // provide some form of a fallback implementation.
1108 pub fn CreateSymbolicLinkW(_lpSymlinkFileName: LPCWSTR,
1109 _lpTargetFileName: LPCWSTR,
1110 _dwFlags: DWORD) -> BOOLEAN {
1111 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1113 pub fn GetFinalPathNameByHandleW(_hFile: HANDLE,
1114 _lpszFilePath: LPCWSTR,
1115 _cchFilePath: DWORD,
1116 _dwFlags: DWORD) -> DWORD {
1117 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1119 pub fn SetThreadErrorMode(_dwNewMode: DWORD,
1120 _lpOldMode: *mut DWORD) -> c_uint {
1121 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1123 pub fn SetThreadStackGuarantee(_size: *mut c_ulong) -> BOOL {
1124 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1126 pub fn SetFileInformationByHandle(_hFile: HANDLE,
1127 _FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,
1128 _lpFileInformation: LPVOID,
1129 _dwBufferSize: DWORD) -> BOOL {
1130 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1132 pub fn SleepConditionVariableSRW(ConditionVariable: PCONDITION_VARIABLE,
1134 dwMilliseconds: DWORD,
1135 Flags: ULONG) -> BOOL {
1136 panic!("condition variables not available")
1138 pub fn WakeConditionVariable(ConditionVariable: PCONDITION_VARIABLE)
1140 panic!("condition variables not available")
1142 pub fn WakeAllConditionVariable(ConditionVariable: PCONDITION_VARIABLE)
1144 panic!("condition variables not available")
1146 pub fn AcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> () {
1147 panic!("rwlocks not available")
1149 pub fn AcquireSRWLockShared(SRWLock: PSRWLOCK) -> () {
1150 panic!("rwlocks not available")
1152 pub fn ReleaseSRWLockExclusive(SRWLock: PSRWLOCK) -> () {
1153 panic!("rwlocks not available")
1155 pub fn ReleaseSRWLockShared(SRWLock: PSRWLOCK) -> () {
1156 panic!("rwlocks not available")
1158 pub fn TryAcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> BOOLEAN {
1159 panic!("rwlocks not available")
1161 pub fn TryAcquireSRWLockShared(SRWLock: PSRWLOCK) -> BOOLEAN {
1162 panic!("rwlocks not available")