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