]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/windows/c.rs
Auto merge of #31652 - semarie:openbsd-os-raw, r=alexcrichton
[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, overflowing_literals, dead_code, deprecated, unused_imports)]
14
15 use os::raw::{c_int, c_uint, c_ulong, c_long, c_longlong, c_ushort};
16 use os::raw::{c_char, c_short, c_ulonglong};
17 use libc::{wchar_t, size_t, c_void};
18 use ptr;
19
20 #[repr(simd)]
21 #[repr(C)]
22 struct u64x2(u64, u64);
23
24 pub use self::GET_FILEEX_INFO_LEVELS::*;
25 pub use self::FILE_INFO_BY_HANDLE_CLASS::*;
26 pub use self::EXCEPTION_DISPOSITION::*;
27
28 pub type DWORD = c_ulong;
29 pub type HANDLE = LPVOID;
30 pub type HINSTANCE = HANDLE;
31 pub type HMODULE = HINSTANCE;
32 pub type BOOL = c_int;
33 pub type BYTE = u8;
34 pub type BOOLEAN = BYTE;
35 pub type GROUP = c_uint;
36 pub type LONG_PTR = isize;
37 pub type LARGE_INTEGER = c_longlong;
38 pub type LONG = c_long;
39 pub type UINT = c_uint;
40 pub type WCHAR = u16;
41 pub type USHORT = c_ushort;
42 pub type SIZE_T = usize;
43 pub type WORD = u16;
44 pub type CHAR = c_char;
45 pub type HCRYPTPROV = LONG_PTR;
46 pub type ULONG_PTR = c_ulonglong;
47 pub type ULONG = c_ulong;
48 pub type ULONGLONG = u64;
49 pub type DWORDLONG = ULONGLONG;
50
51 pub type LPBOOL = *mut BOOL;
52 pub type LPBYTE = *mut BYTE;
53 pub type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION;
54 pub type LPCSTR = *const CHAR;
55 pub type LPCVOID = *const c_void;
56 pub type LPCWSTR = *const WCHAR;
57 pub type LPDWORD = *mut DWORD;
58 pub type LPHANDLE = *mut HANDLE;
59 pub type LPOVERLAPPED = *mut OVERLAPPED;
60 pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION;
61 pub type LPSECURITY_ATTRIBUTES = *mut SECURITY_ATTRIBUTES;
62 pub type LPSTARTUPINFO = *mut STARTUPINFO;
63 pub type LPVOID = *mut c_void;
64 pub type LPWCH = *mut WCHAR;
65 pub type LPWIN32_FIND_DATAW = *mut WIN32_FIND_DATAW;
66 pub type LPWSADATA = *mut WSADATA;
67 pub type LPWSANETWORKEVENTS = *mut WSANETWORKEVENTS;
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;
72
73 pub type PCONDITION_VARIABLE = *mut CONDITION_VARIABLE;
74 pub type PLARGE_INTEGER = *mut c_longlong;
75 pub type PSRWLOCK = *mut SRWLOCK;
76
77 pub type SOCKET = ::os::windows::raw::SOCKET;
78 pub type socklen_t = c_int;
79 pub type ADDRESS_FAMILY = USHORT;
80
81 pub const TRUE: BOOL = 1;
82 pub const FALSE: BOOL = 0;
83
84 pub const FILE_ATTRIBUTE_READONLY: DWORD = 0x1;
85 pub const FILE_ATTRIBUTE_DIRECTORY: DWORD = 0x10;
86 pub const FILE_ATTRIBUTE_NORMAL: DWORD = 0x80;
87 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;
91 pub const CREATE_ALWAYS: DWORD = 2;
92 pub const CREATE_NEW: DWORD = 1;
93 pub const OPEN_ALWAYS: DWORD = 4;
94 pub const OPEN_EXISTING: DWORD = 3;
95 pub const TRUNCATE_EXISTING: DWORD = 5;
96
97 pub const FILE_READ_DATA: DWORD = 0x00000001;
98 pub const FILE_WRITE_DATA: DWORD = 0x00000002;
99 pub const FILE_APPEND_DATA: DWORD = 0x00000004;
100 pub const FILE_READ_EA: DWORD = 0x00000008;
101 pub const FILE_WRITE_EA: DWORD = 0x00000010;
102 pub const FILE_EXECUTE: DWORD = 0x00000020;
103 pub const FILE_READ_ATTRIBUTES: DWORD = 0x00000080;
104 pub const FILE_WRITE_ATTRIBUTES: DWORD = 0x00000100;
105
106 pub const DELETE: DWORD = 0x00008000;
107 pub const READ_CONTROL: DWORD = 0x00020000;
108 pub const WRITE_DAC: DWORD = 0x00040000;
109 pub const WRITE_OWNER: DWORD = 0x00080000;
110 pub const SYNCHRONIZE: DWORD = 0x00100000;
111
112 pub const GENERIC_READ: DWORD = 0x80000000;
113 pub const GENERIC_WRITE: DWORD = 0x40000000;
114 pub const GENERIC_EXECUTE: DWORD = 0x20000000;
115 pub const GENERIC_ALL: DWORD = 0x10000000;
116
117 pub const STANDARD_RIGHTS_READ: DWORD = READ_CONTROL;
118 pub const STANDARD_RIGHTS_WRITE: DWORD = READ_CONTROL;
119 pub const STANDARD_RIGHTS_EXECUTE: DWORD = READ_CONTROL;
120 pub const FILE_GENERIC_READ: DWORD = STANDARD_RIGHTS_READ | FILE_READ_DATA |
121                                      FILE_READ_ATTRIBUTES |
122                                      FILE_READ_EA |
123                                      SYNCHRONIZE;
124 pub const FILE_GENERIC_WRITE: DWORD = STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA |
125                                       FILE_WRITE_ATTRIBUTES |
126                                       FILE_WRITE_EA |
127                                       FILE_APPEND_DATA |
128                                       SYNCHRONIZE;
129
130 pub const SECURITY_ANONYMOUS: DWORD = 0 << 16;
131 pub const SECURITY_IDENTIFICATION: DWORD = 1 << 16;
132 pub const SECURITY_IMPERSONATION: DWORD = 2 << 16;
133 pub const SECURITY_DELEGATION: DWORD = 3 << 16;
134 pub const SECURITY_CONTEXT_TRACKING: DWORD = 0x00040000;
135 pub const SECURITY_EFFECTIVE_ONLY: DWORD = 0x00080000;
136 pub const SECURITY_SQOS_PRESENT: DWORD = 0x00100000;
137
138 #[repr(C)]
139 #[derive(Copy)]
140 pub struct WIN32_FIND_DATAW {
141     pub dwFileAttributes: DWORD,
142     pub ftCreationTime: FILETIME,
143     pub ftLastAccessTime: FILETIME,
144     pub ftLastWriteTime: FILETIME,
145     pub nFileSizeHigh: DWORD,
146     pub nFileSizeLow: DWORD,
147     pub dwReserved0: DWORD,
148     pub dwReserved1: DWORD,
149     pub cFileName: [wchar_t; 260], // #define MAX_PATH 260
150     pub cAlternateFileName: [wchar_t; 14],
151 }
152 impl Clone for WIN32_FIND_DATAW {
153     fn clone(&self) -> Self { *self }
154 }
155
156 pub const FIONBIO: c_long = 0x8004667e;
157 pub const FD_SETSIZE: usize = 64;
158 pub const MSG_DONTWAIT: c_int = 0;
159 pub const ENABLE_ECHO_INPUT: DWORD = 0x4;
160 pub const ENABLE_EXTENDED_FLAGS: DWORD = 0x80;
161 pub const ENABLE_INSERT_MODE: DWORD = 0x20;
162 pub const ENABLE_LINE_INPUT: DWORD = 0x2;
163 pub const ENABLE_PROCESSED_INPUT: DWORD = 0x1;
164 pub const ENABLE_QUICK_EDIT_MODE: DWORD = 0x40;
165
166 pub const FD_ACCEPT: c_long = 0x08;
167 pub const FD_MAX_EVENTS: usize = 10;
168
169 pub const WSA_INVALID_EVENT: WSAEVENT = 0 as WSAEVENT;
170 pub const WSA_INFINITE: DWORD = INFINITE;
171 pub const WSA_WAIT_TIMEOUT: DWORD = WAIT_TIMEOUT;
172 pub const WSA_WAIT_EVENT_0: DWORD = WAIT_OBJECT_0;
173 pub const WSA_WAIT_FAILED: DWORD = WAIT_FAILED;
174 pub const WSA_FLAG_OVERLAPPED: DWORD = 0x01;
175 pub const WSA_FLAG_NO_HANDLE_INHERIT: DWORD = 0x80;
176
177 pub const WSADESCRIPTION_LEN: usize = 256;
178 pub const WSASYS_STATUS_LEN: usize = 128;
179 pub const WSAPROTOCOL_LEN: DWORD = 255;
180 pub const INVALID_SOCKET: SOCKET = !0;
181
182 pub const WSAEINTR: c_int = 10004;
183 pub const WSAEBADF: c_int = 10009;
184 pub const WSAEACCES: c_int = 10013;
185 pub const WSAEFAULT: c_int = 10014;
186 pub const WSAEINVAL: c_int = 10022;
187 pub const WSAEMFILE: c_int = 10024;
188 pub const WSAEWOULDBLOCK: c_int = 10035;
189 pub const WSAEINPROGRESS: c_int = 10036;
190 pub const WSAEALREADY: c_int = 10037;
191 pub const WSAENOTSOCK: c_int = 10038;
192 pub const WSAEDESTADDRREQ: c_int = 10039;
193 pub const WSAEMSGSIZE: c_int = 10040;
194 pub const WSAEPROTOTYPE: c_int = 10041;
195 pub const WSAENOPROTOOPT: c_int = 10042;
196 pub const WSAEPROTONOSUPPORT: c_int = 10043;
197 pub const WSAESOCKTNOSUPPORT: c_int = 10044;
198 pub const WSAEOPNOTSUPP: c_int = 10045;
199 pub const WSAEPFNOSUPPORT: c_int = 10046;
200 pub const WSAEAFNOSUPPORT: c_int = 10047;
201 pub const WSAEADDRINUSE: c_int = 10048;
202 pub const WSAEADDRNOTAVAIL: c_int = 10049;
203 pub const WSAENETDOWN: c_int = 10050;
204 pub const WSAENETUNREACH: c_int = 10051;
205 pub const WSAENETRESET: c_int = 10052;
206 pub const WSAECONNABORTED: c_int = 10053;
207 pub const WSAECONNRESET: c_int = 10054;
208 pub const WSAENOBUFS: c_int = 10055;
209 pub const WSAEISCONN: c_int = 10056;
210 pub const WSAENOTCONN: c_int = 10057;
211 pub const WSAESHUTDOWN: c_int = 10058;
212 pub const WSAETOOMANYREFS: c_int = 10059;
213 pub const WSAETIMEDOUT: c_int = 10060;
214 pub const WSAECONNREFUSED: c_int = 10061;
215 pub const WSAELOOP: c_int = 10062;
216 pub const WSAENAMETOOLONG: c_int = 10063;
217 pub const WSAEHOSTDOWN: c_int = 10064;
218 pub const WSAEHOSTUNREACH: c_int = 10065;
219 pub const WSAENOTEMPTY: c_int = 10066;
220 pub const WSAEPROCLIM: c_int = 10067;
221 pub const WSAEUSERS: c_int = 10068;
222 pub const WSAEDQUOT: c_int = 10069;
223 pub const WSAESTALE: c_int = 10070;
224 pub const WSAEREMOTE: c_int = 10071;
225 pub const WSASYSNOTREADY: c_int = 10091;
226 pub const WSAVERNOTSUPPORTED: c_int = 10092;
227 pub const WSANOTINITIALISED: c_int = 10093;
228 pub const WSAEDISCON: c_int = 10101;
229 pub const WSAENOMORE: c_int = 10102;
230 pub const WSAECANCELLED: c_int = 10103;
231 pub const WSAEINVALIDPROCTABLE: c_int = 10104;
232 pub const NI_MAXHOST: DWORD = 1025;
233
234 pub const MAX_PROTOCOL_CHAIN: DWORD = 7;
235
236 pub const TOKEN_READ: DWORD = 0x20008;
237 pub const FILE_FLAG_OPEN_REPARSE_POINT: DWORD = 0x00200000;
238 pub const FILE_FLAG_BACKUP_SEMANTICS: DWORD = 0x02000000;
239 pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024;
240 pub const FSCTL_GET_REPARSE_POINT: DWORD = 0x900a8;
241 pub const IO_REPARSE_TAG_SYMLINK: DWORD = 0xa000000c;
242 pub const IO_REPARSE_TAG_MOUNT_POINT: DWORD = 0xa0000003;
243 pub const SYMLINK_FLAG_RELATIVE: DWORD = 0x00000001;
244 pub const FSCTL_SET_REPARSE_POINT: DWORD = 0x900a4;
245 pub const FSCTL_DELETE_REPARSE_POINT: DWORD = 0x900ac;
246
247 pub const SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 0x1;
248
249 // Note that these are not actually HANDLEs, just values to pass to GetStdHandle
250 pub const STD_INPUT_HANDLE: DWORD = -10i32 as DWORD;
251 pub const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
252 pub const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
253
254 pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001;
255
256 pub const PROGRESS_CONTINUE: DWORD = 0;
257 pub const PROGRESS_CANCEL: DWORD = 1;
258 pub const PROGRESS_STOP: DWORD = 2;
259 pub const PROGRESS_QUIET: DWORD = 3;
260
261 pub const TOKEN_ADJUST_PRIVILEGES: DWORD = 0x0020;
262 pub const SE_PRIVILEGE_ENABLED: DWORD = 2;
263
264
265 pub const ERROR_SUCCESS: DWORD = 0;
266 pub const ERROR_INVALID_FUNCTION: DWORD = 1;
267 pub const ERROR_FILE_NOT_FOUND: DWORD = 2;
268 pub const ERROR_PATH_NOT_FOUND: DWORD = 3;
269 pub const ERROR_ACCESS_DENIED: DWORD = 5;
270 pub const ERROR_INVALID_HANDLE: DWORD = 6;
271 pub const ERROR_NO_MORE_FILES: DWORD = 18;
272 pub const ERROR_BROKEN_PIPE: DWORD = 109;
273 pub const ERROR_DISK_FULL: DWORD = 112;
274 pub const ERROR_CALL_NOT_IMPLEMENTED: DWORD = 120;
275 pub const ERROR_INSUFFICIENT_BUFFER: DWORD = 122;
276 pub const ERROR_INVALID_NAME: DWORD = 123;
277 pub const ERROR_ALREADY_EXISTS: DWORD = 183;
278 pub const ERROR_PIPE_BUSY: DWORD = 231;
279 pub const ERROR_NO_DATA: DWORD = 232;
280 pub const ERROR_INVALID_ADDRESS: DWORD = 487;
281 pub const ERROR_PIPE_CONNECTED: DWORD = 535;
282 pub const ERROR_ILLEGAL_CHARACTER: DWORD = 582;
283 pub const ERROR_ENVVAR_NOT_FOUND: DWORD = 203;
284 pub const ERROR_NOTHING_TO_TERMINATE: DWORD = 758;
285 pub const ERROR_OPERATION_ABORTED: DWORD = 995;
286 pub const ERROR_IO_PENDING: DWORD = 997;
287 pub const ERROR_FILE_INVALID: DWORD = 1006;
288 pub const ERROR_NOT_FOUND: DWORD = 1168;
289 pub const ERROR_TIMEOUT: DWORD = 0x5B4;
290
291 pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE;
292
293 pub const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000;
294 pub const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200;
295
296 pub const TLS_OUT_OF_INDEXES: DWORD = 0xFFFFFFFF;
297
298 pub const DLL_THREAD_DETACH: DWORD = 3;
299 pub const DLL_PROCESS_DETACH: DWORD = 0;
300
301 pub const INFINITE: DWORD = !0;
302
303 pub const DUPLICATE_SAME_ACCESS: DWORD = 0x00000002;
304
305 pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE {
306     ptr: ptr::null_mut(),
307 };
308 pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: ptr::null_mut() };
309
310 pub const STILL_ACTIVE: DWORD = 259;
311
312 pub const DETACHED_PROCESS: DWORD = 0x00000008;
313 pub const CREATE_NEW_PROCESS_GROUP: DWORD = 0x00000200;
314 pub const CREATE_UNICODE_ENVIRONMENT: DWORD = 0x00000400;
315 pub const STARTF_USESTDHANDLES: DWORD = 0x00000100;
316
317 pub const AF_INET: c_int = 2;
318 pub const AF_INET6: c_int = 23;
319 pub const SD_BOTH: c_int = 2;
320 pub const SD_RECEIVE: c_int = 0;
321 pub const SD_SEND: c_int = 1;
322 pub const SOCK_DGRAM: c_int = 2;
323 pub const SOCK_STREAM: c_int = 1;
324 pub const SOL_SOCKET: c_int = 0xffff;
325 pub const SO_RCVTIMEO: c_int = 0x1006;
326 pub const SO_SNDTIMEO: c_int = 0x1005;
327 pub const SO_REUSEADDR: c_int = 0x0004;
328
329 pub const VOLUME_NAME_DOS: DWORD = 0x0;
330 pub const MOVEFILE_REPLACE_EXISTING: DWORD = 1;
331
332 pub const FILE_BEGIN: DWORD = 0;
333 pub const FILE_CURRENT: DWORD = 1;
334 pub const FILE_END: DWORD = 2;
335
336 pub const WAIT_ABANDONED: DWORD = 0x00000080;
337 pub const WAIT_OBJECT_0: DWORD = 0x00000000;
338 pub const WAIT_TIMEOUT: DWORD = 0x00000102;
339 pub const WAIT_FAILED: DWORD = !0;
340
341 pub const MAX_SYM_NAME: usize = 2000;
342 pub const IMAGE_FILE_MACHINE_I386: DWORD = 0x014c;
343 pub const IMAGE_FILE_MACHINE_IA64: DWORD = 0x0200;
344 pub const IMAGE_FILE_MACHINE_AMD64: DWORD = 0x8664;
345
346 pub const PROV_RSA_FULL: DWORD = 1;
347 pub const CRYPT_SILENT: DWORD = 64;
348 pub const CRYPT_VERIFYCONTEXT: DWORD = 0xF0000000;
349
350 pub const EXCEPTION_CONTINUE_SEARCH: LONG = 0;
351 pub const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd;
352 pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15;
353 pub const EXCEPTION_NONCONTINUABLE: DWORD = 0x1;   // Noncontinuable exception
354 pub const EXCEPTION_UNWINDING: DWORD = 0x2;        // Unwind is in progress
355 pub const EXCEPTION_EXIT_UNWIND: DWORD = 0x4;      // Exit unwind is in progress
356 pub const EXCEPTION_STACK_INVALID: DWORD = 0x8;    // Stack out of limits or unaligned
357 pub const EXCEPTION_NESTED_CALL: DWORD = 0x10;     // Nested exception handler call
358 pub const EXCEPTION_TARGET_UNWIND: DWORD = 0x20;   // Target unwind in progress
359 pub const EXCEPTION_COLLIDED_UNWIND: DWORD = 0x40; // Collided exception handler call
360 pub const EXCEPTION_UNWIND: DWORD = EXCEPTION_UNWINDING |
361                                     EXCEPTION_EXIT_UNWIND |
362                                     EXCEPTION_TARGET_UNWIND |
363                                     EXCEPTION_COLLIDED_UNWIND;
364
365 #[repr(C)]
366 #[cfg(target_arch = "x86")]
367 pub struct WSADATA {
368     pub wVersion: WORD,
369     pub wHighVersion: WORD,
370     pub szDescription: [u8; WSADESCRIPTION_LEN + 1],
371     pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
372     pub iMaxSockets: u16,
373     pub iMaxUdpDg: u16,
374     pub lpVendorInfo: *mut u8,
375 }
376 #[repr(C)]
377 #[cfg(target_arch = "x86_64")]
378 pub struct WSADATA {
379     pub wVersion: WORD,
380     pub wHighVersion: WORD,
381     pub iMaxSockets: u16,
382     pub iMaxUdpDg: u16,
383     pub lpVendorInfo: *mut u8,
384     pub szDescription: [u8; WSADESCRIPTION_LEN + 1],
385     pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
386 }
387
388 #[repr(C)]
389 pub struct WSANETWORKEVENTS {
390     pub lNetworkEvents: c_long,
391     pub iErrorCode: [c_int; FD_MAX_EVENTS],
392 }
393
394 pub type WSAEVENT = HANDLE;
395
396 #[repr(C)]
397 pub struct WSAPROTOCOL_INFO {
398     pub dwServiceFlags1: DWORD,
399     pub dwServiceFlags2: DWORD,
400     pub dwServiceFlags3: DWORD,
401     pub dwServiceFlags4: DWORD,
402     pub dwProviderFlags: DWORD,
403     pub ProviderId: GUID,
404     pub dwCatalogEntryId: DWORD,
405     pub ProtocolChain: WSAPROTOCOLCHAIN,
406     pub iVersion: c_int,
407     pub iAddressFamily: c_int,
408     pub iMaxSockAddr: c_int,
409     pub iMinSockAddr: c_int,
410     pub iSocketType: c_int,
411     pub iProtocol: c_int,
412     pub iProtocolMaxOffset: c_int,
413     pub iNetworkByteOrder: c_int,
414     pub iSecurityScheme: c_int,
415     pub dwMessageSize: DWORD,
416     pub dwProviderReserved: DWORD,
417     pub szProtocol: [u16; (WSAPROTOCOL_LEN as usize) + 1],
418 }
419
420 #[repr(C)]
421 pub struct fd_set {
422     fd_count: c_uint,
423     fd_array: [SOCKET; FD_SETSIZE],
424 }
425
426 pub fn fd_set(set: &mut fd_set, s: SOCKET) {
427     set.fd_array[set.fd_count as usize] = s;
428     set.fd_count += 1;
429 }
430
431 pub type SHORT = c_short;
432
433 #[repr(C)]
434 pub struct COORD {
435     pub X: SHORT,
436     pub Y: SHORT,
437 }
438
439 #[repr(C)]
440 pub struct SMALL_RECT {
441     pub Left: SHORT,
442     pub Top: SHORT,
443     pub Right: SHORT,
444     pub Bottom: SHORT,
445 }
446
447 #[repr(C)]
448 pub struct CONSOLE_SCREEN_BUFFER_INFO {
449     pub dwSize: COORD,
450     pub dwCursorPosition: COORD,
451     pub wAttributes: WORD,
452     pub srWindow: SMALL_RECT,
453     pub dwMaximumWindowSize: COORD,
454 }
455 pub type PCONSOLE_SCREEN_BUFFER_INFO = *mut CONSOLE_SCREEN_BUFFER_INFO;
456
457 #[repr(C)]
458 #[derive(Copy, Clone)]
459 pub struct WIN32_FILE_ATTRIBUTE_DATA {
460     pub dwFileAttributes: DWORD,
461     pub ftCreationTime: FILETIME,
462     pub ftLastAccessTime: FILETIME,
463     pub ftLastWriteTime: FILETIME,
464     pub nFileSizeHigh: DWORD,
465     pub nFileSizeLow: DWORD,
466 }
467
468 #[repr(C)]
469 pub struct BY_HANDLE_FILE_INFORMATION {
470     pub dwFileAttributes: DWORD,
471     pub ftCreationTime: FILETIME,
472     pub ftLastAccessTime: FILETIME,
473     pub ftLastWriteTime: FILETIME,
474     pub dwVolumeSerialNumber: DWORD,
475     pub nFileSizeHigh: DWORD,
476     pub nFileSizeLow: DWORD,
477     pub nNumberOfLinks: DWORD,
478     pub nFileIndexHigh: DWORD,
479     pub nFileIndexLow: DWORD,
480 }
481
482 #[repr(C)]
483 pub enum GET_FILEEX_INFO_LEVELS {
484     GetFileExInfoStandard,
485     GetFileExMaxInfoLevel
486 }
487
488 #[repr(C)]
489 pub enum FILE_INFO_BY_HANDLE_CLASS {
490     FileBasicInfo                   = 0,
491     FileStandardInfo                = 1,
492     FileNameInfo                    = 2,
493     FileRenameInfo                  = 3,
494     FileDispositionInfo             = 4,
495     FileAllocationInfo              = 5,
496     FileEndOfFileInfo               = 6,
497     FileStreamInfo                  = 7,
498     FileCompressionInfo             = 8,
499     FileAttributeTagInfo            = 9,
500     FileIdBothDirectoryInfo         = 10, // 0xA
501     FileIdBothDirectoryRestartInfo  = 11, // 0xB
502     FileIoPriorityHintInfo          = 12, // 0xC
503     FileRemoteProtocolInfo          = 13, // 0xD
504     FileFullDirectoryInfo           = 14, // 0xE
505     FileFullDirectoryRestartInfo    = 15, // 0xF
506     FileStorageInfo                 = 16, // 0x10
507     FileAlignmentInfo               = 17, // 0x11
508     FileIdInfo                      = 18, // 0x12
509     FileIdExtdDirectoryInfo         = 19, // 0x13
510     FileIdExtdDirectoryRestartInfo  = 20, // 0x14
511     MaximumFileInfoByHandlesClass
512 }
513
514 #[repr(C)]
515 pub struct FILE_END_OF_FILE_INFO {
516     pub EndOfFile: LARGE_INTEGER,
517 }
518
519 #[repr(C)]
520 pub struct REPARSE_DATA_BUFFER {
521     pub ReparseTag: c_uint,
522     pub ReparseDataLength: c_ushort,
523     pub Reserved: c_ushort,
524     pub rest: (),
525 }
526
527 #[repr(C)]
528 pub struct SYMBOLIC_LINK_REPARSE_BUFFER {
529     pub SubstituteNameOffset: c_ushort,
530     pub SubstituteNameLength: c_ushort,
531     pub PrintNameOffset: c_ushort,
532     pub PrintNameLength: c_ushort,
533     pub Flags: c_ulong,
534     pub PathBuffer: WCHAR,
535 }
536
537 #[repr(C)]
538 pub struct MOUNT_POINT_REPARSE_BUFFER {
539     pub SubstituteNameOffset: c_ushort,
540     pub SubstituteNameLength: c_ushort,
541     pub PrintNameOffset: c_ushort,
542     pub PrintNameLength: c_ushort,
543     pub PathBuffer: WCHAR,
544 }
545
546 pub type LPPROGRESS_ROUTINE = ::option::Option<unsafe extern "system" fn(
547     TotalFileSize: LARGE_INTEGER,
548     TotalBytesTransferred: LARGE_INTEGER,
549     StreamSize: LARGE_INTEGER,
550     StreamBytesTransferred: LARGE_INTEGER,
551     dwStreamNumber: DWORD,
552     dwCallbackReason: DWORD,
553     hSourceFile: HANDLE,
554     hDestinationFile: HANDLE,
555     lpData: LPVOID,
556 ) -> DWORD>;
557
558 #[repr(C)]
559 pub struct CONDITION_VARIABLE { pub ptr: LPVOID }
560 #[repr(C)]
561 pub struct SRWLOCK { pub ptr: LPVOID }
562 #[repr(C)]
563 pub struct CRITICAL_SECTION {
564     CriticalSectionDebug: LPVOID,
565     LockCount: LONG,
566     RecursionCount: LONG,
567     OwningThread: HANDLE,
568     LockSemaphore: HANDLE,
569     SpinCount: ULONG_PTR
570 }
571
572 #[repr(C)]
573 pub struct LUID {
574     pub LowPart: DWORD,
575     pub HighPart: c_long,
576 }
577
578 pub type PLUID = *mut LUID;
579
580 #[repr(C)]
581 pub struct TOKEN_PRIVILEGES {
582     pub PrivilegeCount: DWORD,
583     pub Privileges: [LUID_AND_ATTRIBUTES; 1],
584 }
585
586 pub type PTOKEN_PRIVILEGES = *mut TOKEN_PRIVILEGES;
587
588 #[repr(C)]
589 pub struct LUID_AND_ATTRIBUTES {
590     pub Luid: LUID,
591     pub Attributes: DWORD,
592 }
593
594 #[repr(C)]
595 pub struct REPARSE_MOUNTPOINT_DATA_BUFFER {
596     pub ReparseTag: DWORD,
597     pub ReparseDataLength: DWORD,
598     pub Reserved: WORD,
599     pub ReparseTargetLength: WORD,
600     pub ReparseTargetMaximumLength: WORD,
601     pub Reserved1: WORD,
602     pub ReparseTarget: WCHAR,
603 }
604
605 #[repr(C)]
606 pub struct EXCEPTION_RECORD {
607     pub ExceptionCode: DWORD,
608     pub ExceptionFlags: DWORD,
609     pub ExceptionRecord: *mut EXCEPTION_RECORD,
610     pub ExceptionAddress: LPVOID,
611     pub NumberParameters: DWORD,
612     pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS]
613 }
614
615 #[repr(C)]
616 pub struct EXCEPTION_POINTERS {
617     pub ExceptionRecord: *mut EXCEPTION_RECORD,
618     pub ContextRecord: *mut CONTEXT,
619 }
620
621 pub type PVECTORED_EXCEPTION_HANDLER = extern "system"
622         fn(ExceptionInfo: *mut EXCEPTION_POINTERS) -> LONG;
623
624 #[repr(C)]
625 pub struct GUID {
626     pub Data1: DWORD,
627     pub Data2: WORD,
628     pub Data3: WORD,
629     pub Data4: [BYTE; 8],
630 }
631
632 #[repr(C)]
633 pub struct WSAPROTOCOLCHAIN {
634     pub ChainLen: c_int,
635     pub ChainEntries: [DWORD; MAX_PROTOCOL_CHAIN as usize],
636 }
637
638 #[repr(C)]
639 pub struct SECURITY_ATTRIBUTES {
640     pub nLength: DWORD,
641     pub lpSecurityDescriptor: LPVOID,
642     pub bInheritHandle: BOOL,
643 }
644
645 #[repr(C)]
646 pub struct PROCESS_INFORMATION {
647     pub hProcess: HANDLE,
648     pub hThread: HANDLE,
649     pub dwProcessId: DWORD,
650     pub dwThreadId: DWORD,
651 }
652
653 #[repr(C)]
654 pub struct STARTUPINFO {
655     pub cb: DWORD,
656     pub lpReserved: LPWSTR,
657     pub lpDesktop: LPWSTR,
658     pub lpTitle: LPWSTR,
659     pub dwX: DWORD,
660     pub dwY: DWORD,
661     pub dwXSize: DWORD,
662     pub dwYSize: DWORD,
663     pub dwXCountChars: DWORD,
664     pub dwYCountCharts: DWORD,
665     pub dwFillAttribute: DWORD,
666     pub dwFlags: DWORD,
667     pub wShowWindow: WORD,
668     pub cbReserved2: WORD,
669     pub lpReserved2: LPBYTE,
670     pub hStdInput: HANDLE,
671     pub hStdOutput: HANDLE,
672     pub hStdError: HANDLE,
673 }
674
675 #[repr(C)]
676 pub struct SOCKADDR {
677     pub sa_family: ADDRESS_FAMILY,
678     pub sa_data: [CHAR; 14],
679 }
680
681 #[repr(C)]
682 #[derive(Copy, Clone)]
683 pub struct FILETIME {
684     pub dwLowDateTime: DWORD,
685     pub dwHighDateTime: DWORD,
686 }
687
688 #[repr(C)]
689 pub struct OVERLAPPED {
690     pub Internal: *mut c_ulong,
691     pub InternalHigh: *mut c_ulong,
692     pub Offset: DWORD,
693     pub OffsetHigh: DWORD,
694     pub hEvent: HANDLE,
695 }
696
697 #[repr(C)]
698 pub struct SYMBOL_INFO {
699     pub SizeOfStruct: c_ulong,
700     pub TypeIndex: c_ulong,
701     pub Reserved: [u64; 2],
702     pub Index: c_ulong,
703     pub Size: c_ulong,
704     pub ModBase: u64,
705     pub Flags: c_ulong,
706     pub Value: u64,
707     pub Address: u64,
708     pub Register: c_ulong,
709     pub Scope: c_ulong,
710     pub Tag: c_ulong,
711     pub NameLen: c_ulong,
712     pub MaxNameLen: c_ulong,
713     // note that windows has this as 1, but it basically just means that
714     // the name is inline at the end of the struct. For us, we just bump
715     // the struct size up to MAX_SYM_NAME.
716     pub Name: [c_char; MAX_SYM_NAME],
717 }
718
719 #[repr(C)]
720 pub struct IMAGEHLP_LINE64 {
721     pub SizeOfStruct: u32,
722     pub Key: *const c_void,
723     pub LineNumber: u32,
724     pub Filename: *const c_char,
725     pub Address: u64,
726 }
727
728 #[repr(C)]
729 pub enum ADDRESS_MODE {
730     AddrMode1616,
731     AddrMode1632,
732     AddrModeReal,
733     AddrModeFlat,
734 }
735
736 #[repr(C)]
737 pub struct ADDRESS64 {
738     pub Offset: u64,
739     pub Segment: u16,
740     pub Mode: ADDRESS_MODE,
741 }
742
743 #[repr(C)]
744 pub struct STACKFRAME64 {
745     pub AddrPC: ADDRESS64,
746     pub AddrReturn: ADDRESS64,
747     pub AddrFrame: ADDRESS64,
748     pub AddrStack: ADDRESS64,
749     pub AddrBStore: ADDRESS64,
750     pub FuncTableEntry: *mut c_void,
751     pub Params: [u64; 4],
752     pub Far: BOOL,
753     pub Virtual: BOOL,
754     pub Reserved: [u64; 3],
755     pub KdHelp: KDHELP64,
756 }
757
758 #[repr(C)]
759 pub struct KDHELP64 {
760     pub Thread: u64,
761     pub ThCallbackStack: DWORD,
762     pub ThCallbackBStore: DWORD,
763     pub NextCallback: DWORD,
764     pub FramePointer: DWORD,
765     pub KiCallUserMode: u64,
766     pub KeUserCallbackDispatcher: u64,
767     pub SystemRangeStart: u64,
768     pub KiUserExceptionDispatcher: u64,
769     pub StackBase: u64,
770     pub StackLimit: u64,
771     pub Reserved: [u64; 5],
772 }
773
774 #[cfg(target_arch = "x86")]
775 #[repr(C)]
776 pub struct CONTEXT {
777     pub ContextFlags: DWORD,
778     pub Dr0: DWORD,
779     pub Dr1: DWORD,
780     pub Dr2: DWORD,
781     pub Dr3: DWORD,
782     pub Dr6: DWORD,
783     pub Dr7: DWORD,
784     pub FloatSave: FLOATING_SAVE_AREA,
785     pub SegGs: DWORD,
786     pub SegFs: DWORD,
787     pub SegEs: DWORD,
788     pub SegDs: DWORD,
789     pub Edi: DWORD,
790     pub Esi: DWORD,
791     pub Ebx: DWORD,
792     pub Edx: DWORD,
793     pub Ecx: DWORD,
794     pub Eax: DWORD,
795     pub Ebp: DWORD,
796     pub Eip: DWORD,
797     pub SegCs: DWORD,
798     pub EFlags: DWORD,
799     pub Esp: DWORD,
800     pub SegSs: DWORD,
801     pub ExtendedRegisters: [u8; 512],
802 }
803
804 #[cfg(target_arch = "x86")]
805 #[repr(C)]
806 pub struct FLOATING_SAVE_AREA {
807     pub ControlWord: DWORD,
808     pub StatusWord: DWORD,
809     pub TagWord: DWORD,
810     pub ErrorOffset: DWORD,
811     pub ErrorSelector: DWORD,
812     pub DataOffset: DWORD,
813     pub DataSelector: DWORD,
814     pub RegisterArea: [u8; 80],
815     pub Cr0NpxState: DWORD,
816 }
817
818 #[cfg(target_arch = "x86_64")]
819 #[repr(C)]
820 pub struct CONTEXT {
821     _align_hack: [u64x2; 0], // FIXME align on 16-byte
822     pub P1Home: DWORDLONG,
823     pub P2Home: DWORDLONG,
824     pub P3Home: DWORDLONG,
825     pub P4Home: DWORDLONG,
826     pub P5Home: DWORDLONG,
827     pub P6Home: DWORDLONG,
828
829     pub ContextFlags: DWORD,
830     pub MxCsr: DWORD,
831
832     pub SegCs: WORD,
833     pub SegDs: WORD,
834     pub SegEs: WORD,
835     pub SegFs: WORD,
836     pub SegGs: WORD,
837     pub SegSs: WORD,
838     pub EFlags: DWORD,
839
840     pub Dr0: DWORDLONG,
841     pub Dr1: DWORDLONG,
842     pub Dr2: DWORDLONG,
843     pub Dr3: DWORDLONG,
844     pub Dr6: DWORDLONG,
845     pub Dr7: DWORDLONG,
846
847     pub Rax: DWORDLONG,
848     pub Rcx: DWORDLONG,
849     pub Rdx: DWORDLONG,
850     pub Rbx: DWORDLONG,
851     pub Rsp: DWORDLONG,
852     pub Rbp: DWORDLONG,
853     pub Rsi: DWORDLONG,
854     pub Rdi: DWORDLONG,
855     pub R8:  DWORDLONG,
856     pub R9:  DWORDLONG,
857     pub R10: DWORDLONG,
858     pub R11: DWORDLONG,
859     pub R12: DWORDLONG,
860     pub R13: DWORDLONG,
861     pub R14: DWORDLONG,
862     pub R15: DWORDLONG,
863
864     pub Rip: DWORDLONG,
865
866     pub FltSave: FLOATING_SAVE_AREA,
867
868     pub VectorRegister: [M128A; 26],
869     pub VectorControl: DWORDLONG,
870
871     pub DebugControl: DWORDLONG,
872     pub LastBranchToRip: DWORDLONG,
873     pub LastBranchFromRip: DWORDLONG,
874     pub LastExceptionToRip: DWORDLONG,
875     pub LastExceptionFromRip: DWORDLONG,
876 }
877
878 #[cfg(target_arch = "x86_64")]
879 #[repr(C)]
880 pub struct M128A {
881     _align_hack: [u64x2; 0], // FIXME align on 16-byte
882     pub Low:  c_ulonglong,
883     pub High: c_longlong
884 }
885
886 #[cfg(target_arch = "x86_64")]
887 #[repr(C)]
888 pub struct FLOATING_SAVE_AREA {
889     _align_hack: [u64x2; 0], // FIXME align on 16-byte
890     _Dummy: [u8; 512] // FIXME: Fill this out
891 }
892
893 #[repr(C)]
894 pub struct SOCKADDR_STORAGE_LH {
895     pub ss_family: ADDRESS_FAMILY,
896     pub __ss_pad1: [CHAR; 6],
897     pub __ss_align: i64,
898     pub __ss_pad2: [CHAR; 112],
899 }
900
901 #[repr(C)]
902 pub struct ADDRINFOA {
903     pub ai_flags: c_int,
904     pub ai_family: c_int,
905     pub ai_socktype: c_int,
906     pub ai_protocol: c_int,
907     pub ai_addrlen: size_t,
908     pub ai_canonname: *mut c_char,
909     pub ai_addr: *mut SOCKADDR,
910     pub ai_next: *mut ADDRINFOA,
911 }
912
913 #[repr(C)]
914 #[derive(Copy, Clone)]
915 pub struct sockaddr_in {
916     pub sin_family: ADDRESS_FAMILY,
917     pub sin_port: USHORT,
918     pub sin_addr: in_addr,
919     pub sin_zero: [CHAR; 8],
920 }
921
922 #[repr(C)]
923 #[derive(Copy, Clone)]
924 pub struct sockaddr_in6 {
925     pub sin6_family: ADDRESS_FAMILY,
926     pub sin6_port: USHORT,
927     pub sin6_flowinfo: c_ulong,
928     pub sin6_addr: in6_addr,
929     pub sin6_scope_id: c_ulong,
930 }
931
932 #[repr(C)]
933 #[derive(Copy, Clone)]
934 pub struct in_addr {
935     pub s_addr: u32,
936 }
937
938 #[repr(C)]
939 #[derive(Copy, Clone)]
940 pub struct in6_addr {
941     pub s6_addr: [u8; 16],
942 }
943
944 pub enum UNWIND_HISTORY_TABLE {}
945
946 #[repr(C)]
947 pub struct RUNTIME_FUNCTION {
948     pub BeginAddress: DWORD,
949     pub EndAddress: DWORD,
950     pub UnwindData: DWORD,
951 }
952
953 #[repr(C)]
954 pub struct DISPATCHER_CONTEXT {
955     pub ControlPc: LPVOID,
956     pub ImageBase: LPVOID,
957     pub FunctionEntry: *const RUNTIME_FUNCTION,
958     pub EstablisherFrame: LPVOID,
959     pub TargetIp: LPVOID,
960     pub ContextRecord: *const CONTEXT,
961     pub LanguageHandler: LPVOID,
962     pub HandlerData: *const u8,
963     pub HistoryTable: *const UNWIND_HISTORY_TABLE,
964 }
965
966 #[repr(C)]
967 #[derive(Copy, Clone)]
968 pub enum EXCEPTION_DISPOSITION {
969     ExceptionContinueExecution,
970     ExceptionContinueSearch,
971     ExceptionNestedException,
972     ExceptionCollidedUnwind
973 }
974
975 #[link(name = "ws2_32")]
976 #[link(name = "userenv")]
977 #[link(name = "shell32")]
978 #[link(name = "advapi32")]
979 #[cfg(not(cargobuild))]
980 extern {}
981
982 extern "system" {
983     pub fn WSAStartup(wVersionRequested: WORD,
984                       lpWSAData: LPWSADATA) -> c_int;
985     pub fn WSACleanup() -> c_int;
986     pub fn WSAGetLastError() -> c_int;
987     pub fn WSADuplicateSocketW(s: SOCKET,
988                                dwProcessId: DWORD,
989                                lpProtocolInfo: LPWSAPROTOCOL_INFO)
990                                -> c_int;
991     pub fn GetCurrentProcessId() -> DWORD;
992     pub fn WSASocketW(af: c_int,
993                       kind: c_int,
994                       protocol: c_int,
995                       lpProtocolInfo: LPWSAPROTOCOL_INFO,
996                       g: GROUP,
997                       dwFlags: DWORD) -> SOCKET;
998     pub fn InitializeCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
999     pub fn EnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
1000     pub fn TryEnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION) -> BOOLEAN;
1001     pub fn LeaveCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
1002     pub fn DeleteCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
1003
1004     // FIXME - pInputControl should be PCONSOLE_READCONSOLE_CONTROL
1005     pub fn ReadConsoleW(hConsoleInput: HANDLE,
1006                         lpBuffer: LPVOID,
1007                         nNumberOfCharsToRead: DWORD,
1008                         lpNumberOfCharsRead: LPDWORD,
1009                         pInputControl: LPVOID) -> BOOL;
1010
1011     pub fn WriteConsoleW(hConsoleOutput: HANDLE,
1012                          lpBuffer: LPCVOID,
1013                          nNumberOfCharsToWrite: DWORD,
1014                          lpNumberOfCharsWritten: LPDWORD,
1015                          lpReserved: LPVOID) -> BOOL;
1016
1017     pub fn GetConsoleMode(hConsoleHandle: HANDLE,
1018                           lpMode: LPDWORD) -> BOOL;
1019     pub fn GetFileAttributesExW(lpFileName: LPCWSTR,
1020                                 fInfoLevelId: GET_FILEEX_INFO_LEVELS,
1021                                 lpFileInformation: LPVOID) -> BOOL;
1022     pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
1023     pub fn SetFileAttributesW(lpFileName: LPCWSTR,
1024                               dwFileAttributes: DWORD) -> BOOL;
1025     pub fn GetFileInformationByHandle(hFile: HANDLE,
1026                             lpFileInformation: LPBY_HANDLE_FILE_INFORMATION)
1027                             -> BOOL;
1028
1029     pub fn SetLastError(dwErrCode: DWORD);
1030     pub fn GetCommandLineW() -> *mut LPCWSTR;
1031     pub fn LocalFree(ptr: *mut c_void);
1032     pub fn CommandLineToArgvW(lpCmdLine: *mut LPCWSTR,
1033                               pNumArgs: *mut c_int) -> *mut *mut u16;
1034     pub fn GetTempPathW(nBufferLength: DWORD,
1035                         lpBuffer: LPCWSTR) -> DWORD;
1036     pub fn OpenProcessToken(ProcessHandle: HANDLE,
1037                             DesiredAccess: DWORD,
1038                             TokenHandle: *mut HANDLE) -> BOOL;
1039     pub fn GetCurrentProcess() -> HANDLE;
1040     pub fn GetCurrentThread() -> HANDLE;
1041     pub fn GetStdHandle(which: DWORD) -> HANDLE;
1042     pub fn ExitProcess(uExitCode: c_uint) -> !;
1043     pub fn DeviceIoControl(hDevice: HANDLE,
1044                            dwIoControlCode: DWORD,
1045                            lpInBuffer: LPVOID,
1046                            nInBufferSize: DWORD,
1047                            lpOutBuffer: LPVOID,
1048                            nOutBufferSize: DWORD,
1049                            lpBytesReturned: LPDWORD,
1050                            lpOverlapped: LPOVERLAPPED) -> BOOL;
1051     pub fn CreatePipe(hReadPipe: LPHANDLE,
1052                       hWritePipe: LPHANDLE,
1053                       lpPipeAttributes: LPSECURITY_ATTRIBUTES,
1054                       nSize: DWORD) -> BOOL;
1055     pub fn CreateThread(lpThreadAttributes: LPSECURITY_ATTRIBUTES,
1056                         dwStackSize: SIZE_T,
1057                         lpStartAddress: extern "system" fn(*mut c_void)
1058                                                            -> DWORD,
1059                         lpParameter: LPVOID,
1060                         dwCreationFlags: DWORD,
1061                         lpThreadId: LPDWORD) -> HANDLE;
1062     pub fn WaitForSingleObject(hHandle: HANDLE,
1063                                dwMilliseconds: DWORD) -> DWORD;
1064     pub fn SwitchToThread() -> BOOL;
1065     pub fn Sleep(dwMilliseconds: DWORD);
1066     pub fn GetProcessId(handle: HANDLE) -> DWORD;
1067     pub fn GetUserProfileDirectoryW(hToken: HANDLE,
1068                                     lpProfileDir: LPCWSTR,
1069                                     lpcchSize: *mut DWORD) -> BOOL;
1070     pub fn SetHandleInformation(hObject: HANDLE,
1071                                 dwMask: DWORD,
1072                                 dwFlags: DWORD) -> BOOL;
1073     pub fn CopyFileExW(lpExistingFileName: LPCWSTR,
1074                        lpNewFileName: LPCWSTR,
1075                        lpProgressRoutine: LPPROGRESS_ROUTINE,
1076                        lpData: LPVOID,
1077                        pbCancel: LPBOOL,
1078                        dwCopyFlags: DWORD) -> BOOL;
1079     pub fn LookupPrivilegeValueW(lpSystemName: LPCWSTR,
1080                                  lpName: LPCWSTR,
1081                                  lpLuid: PLUID) -> BOOL;
1082     pub fn AdjustTokenPrivileges(TokenHandle: HANDLE,
1083                                  DisableAllPrivileges: BOOL,
1084                                  NewState: PTOKEN_PRIVILEGES,
1085                                  BufferLength: DWORD,
1086                                  PreviousState: PTOKEN_PRIVILEGES,
1087                                  ReturnLength: *mut DWORD) -> BOOL;
1088     pub fn AddVectoredExceptionHandler(FirstHandler: ULONG,
1089                                        VectoredHandler: PVECTORED_EXCEPTION_HANDLER)
1090                                        -> LPVOID;
1091     pub fn FormatMessageW(flags: DWORD,
1092                           lpSrc: LPVOID,
1093                           msgId: DWORD,
1094                           langId: DWORD,
1095                           buf: LPWSTR,
1096                           nsize: DWORD,
1097                           args: *const c_void)
1098                           -> DWORD;
1099     pub fn TlsAlloc() -> DWORD;
1100     pub fn TlsFree(dwTlsIndex: DWORD) -> BOOL;
1101     pub fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID;
1102     pub fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL;
1103     pub fn GetLastError() -> DWORD;
1104     pub fn QueryPerformanceFrequency(lpFrequency: *mut LARGE_INTEGER) -> BOOL;
1105     pub fn QueryPerformanceCounter(lpPerformanceCount: *mut LARGE_INTEGER)
1106                                    -> BOOL;
1107     pub fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: LPDWORD) -> BOOL;
1108     pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) -> BOOL;
1109     pub fn CreateProcessW(lpApplicationName: LPCWSTR,
1110                           lpCommandLine: LPWSTR,
1111                           lpProcessAttributes: LPSECURITY_ATTRIBUTES,
1112                           lpThreadAttributes: LPSECURITY_ATTRIBUTES,
1113                           bInheritHandles: BOOL,
1114                           dwCreationFlags: DWORD,
1115                           lpEnvironment: LPVOID,
1116                           lpCurrentDirectory: LPCWSTR,
1117                           lpStartupInfo: LPSTARTUPINFO,
1118                           lpProcessInformation: LPPROCESS_INFORMATION)
1119                           -> BOOL;
1120     pub fn GetEnvironmentVariableW(n: LPCWSTR, v: LPWSTR, nsize: DWORD) -> DWORD;
1121     pub fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL;
1122     pub fn GetEnvironmentStringsW() -> LPWCH;
1123     pub fn FreeEnvironmentStringsW(env_ptr: LPWCH) -> BOOL;
1124     pub fn GetModuleFileNameW(hModule: HMODULE,
1125                               lpFilename: LPWSTR,
1126                               nSize: DWORD)
1127                               -> DWORD;
1128     pub fn CreateDirectoryW(lpPathName: LPCWSTR,
1129                             lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
1130                             -> BOOL;
1131     pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
1132     pub fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: LPWSTR) -> DWORD;
1133     pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
1134
1135     pub fn closesocket(socket: SOCKET) -> c_int;
1136     pub fn recv(socket: SOCKET, buf: *mut c_void, len: c_int,
1137                 flags: c_int) -> c_int;
1138     pub fn send(socket: SOCKET, buf: *const c_void, len: c_int,
1139                 flags: c_int) -> c_int;
1140     pub fn recvfrom(socket: SOCKET,
1141                     buf: *mut c_void,
1142                     len: c_int,
1143                     flags: c_int,
1144                     addr: *mut SOCKADDR,
1145                     addrlen: *mut c_int)
1146                     -> c_int;
1147     pub fn sendto(socket: SOCKET,
1148                   buf: *const c_void,
1149                   len: c_int,
1150                   flags: c_int,
1151                   addr: *const SOCKADDR,
1152                   addrlen: c_int)
1153                   -> c_int;
1154     pub fn shutdown(socket: SOCKET, how: c_int) -> c_int;
1155     pub fn accept(socket: SOCKET,
1156                   address: *mut SOCKADDR,
1157                   address_len: *mut c_int)
1158                   -> SOCKET;
1159     pub fn DuplicateHandle(hSourceProcessHandle: HANDLE,
1160                            hSourceHandle: HANDLE,
1161                            hTargetProcessHandle: HANDLE,
1162                            lpTargetHandle: LPHANDLE,
1163                            dwDesiredAccess: DWORD,
1164                            bInheritHandle: BOOL,
1165                            dwOptions: DWORD)
1166                            -> BOOL;
1167     pub fn ReadFile(hFile: HANDLE,
1168                     lpBuffer: LPVOID,
1169                     nNumberOfBytesToRead: DWORD,
1170                     lpNumberOfBytesRead: LPDWORD,
1171                     lpOverlapped: LPOVERLAPPED)
1172                     -> BOOL;
1173     pub fn WriteFile(hFile: HANDLE,
1174                      lpBuffer: LPVOID,
1175                      nNumberOfBytesToWrite: DWORD,
1176                      lpNumberOfBytesWritten: LPDWORD,
1177                      lpOverlapped: LPOVERLAPPED)
1178                      -> BOOL;
1179     pub fn CloseHandle(hObject: HANDLE) -> BOOL;
1180     pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR,
1181                            lpTargetFileName: LPCWSTR,
1182                            lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
1183                            -> BOOL;
1184     pub fn MoveFileExW(lpExistingFileName: LPCWSTR,
1185                        lpNewFileName: LPCWSTR,
1186                        dwFlags: DWORD)
1187                        -> BOOL;
1188     pub fn SetFilePointerEx(hFile: HANDLE,
1189                             liDistanceToMove: LARGE_INTEGER,
1190                             lpNewFilePointer: PLARGE_INTEGER,
1191                             dwMoveMethod: DWORD)
1192                             -> BOOL;
1193     pub fn FlushFileBuffers(hFile: HANDLE) -> BOOL;
1194     pub fn CreateFileW(lpFileName: LPCWSTR,
1195                        dwDesiredAccess: DWORD,
1196                        dwShareMode: DWORD,
1197                        lpSecurityAttributes: LPSECURITY_ATTRIBUTES,
1198                        dwCreationDisposition: DWORD,
1199                        dwFlagsAndAttributes: DWORD,
1200                        hTemplateFile: HANDLE)
1201                        -> HANDLE;
1202
1203     pub fn FindFirstFileW(fileName: LPCWSTR,
1204                           findFileData: LPWIN32_FIND_DATAW)
1205                           -> HANDLE;
1206     pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW)
1207                          -> BOOL;
1208     pub fn FindClose(findFile: HANDLE) -> BOOL;
1209     pub fn RtlCaptureContext(ctx: *mut CONTEXT);
1210     pub fn getsockopt(s: SOCKET,
1211                       level: c_int,
1212                       optname: c_int,
1213                       optval: *mut c_char,
1214                       optlen: *mut c_int)
1215                       -> c_int;
1216     pub fn setsockopt(s: SOCKET,
1217                       level: c_int,
1218                       optname: c_int,
1219                       optval: *const c_void,
1220                       optlen: c_int)
1221                       -> c_int;
1222     pub fn getsockname(socket: SOCKET,
1223                        address: *mut SOCKADDR,
1224                        address_len: *mut c_int)
1225                        -> c_int;
1226     pub fn getpeername(socket: SOCKET,
1227                        address: *mut SOCKADDR,
1228                        address_len: *mut c_int)
1229                        -> c_int;
1230     pub fn bind(socket: SOCKET, address: *const SOCKADDR,
1231                 address_len: socklen_t) -> c_int;
1232     pub fn listen(socket: SOCKET, backlog: c_int) -> c_int;
1233     pub fn connect(socket: SOCKET, address: *const SOCKADDR, len: c_int)
1234                    -> c_int;
1235     pub fn getaddrinfo(node: *const c_char, service: *const c_char,
1236                        hints: *const ADDRINFOA,
1237                        res: *mut *mut ADDRINFOA) -> c_int;
1238     pub fn freeaddrinfo(res: *mut ADDRINFOA);
1239     pub fn getnameinfo(sa: *const SOCKADDR, salen: c_int,
1240                        host: *mut c_char, hostlen: DWORD,
1241                        serv: *mut c_char, servlen: DWORD,
1242                        flags: c_int) -> c_int;
1243
1244     pub fn LoadLibraryW(name: LPCWSTR) -> HMODULE;
1245     pub fn GetModuleHandleExW(dwFlags: DWORD, name: LPCWSTR,
1246                               handle: *mut HMODULE) -> BOOL;
1247     pub fn GetProcAddress(handle: HMODULE,
1248                           name: LPCSTR) -> *mut c_void;
1249     pub fn FreeLibrary(handle: HMODULE) -> BOOL;
1250     pub fn SetErrorMode(uMode: c_uint) -> c_uint;
1251     pub fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE;
1252     pub fn CryptAcquireContextA(phProv: *mut HCRYPTPROV,
1253                                 pszContainer: LPCSTR,
1254                                 pszProvider: LPCSTR,
1255                                 dwProvType: DWORD,
1256                                 dwFlags: DWORD) -> BOOL;
1257     pub fn CryptGenRandom(hProv: HCRYPTPROV,
1258                           dwLen: DWORD,
1259                           pbBuffer: *mut BYTE) -> BOOL;
1260     pub fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL;
1261
1262     #[unwind]
1263     pub fn RaiseException(dwExceptionCode: DWORD,
1264                           dwExceptionFlags: DWORD,
1265                           nNumberOfArguments: DWORD,
1266                           lpArguments: *const ULONG_PTR);
1267     pub fn RtlUnwindEx(TargetFrame: LPVOID,
1268                        TargetIp: LPVOID,
1269                        ExceptionRecord: *const EXCEPTION_RECORD,
1270                        ReturnValue: LPVOID,
1271                        OriginalContext: *const CONTEXT,
1272                        HistoryTable: *const UNWIND_HISTORY_TABLE);
1273     pub fn GetSystemTimeAsFileTime(lpSystemTimeAsFileTime: LPFILETIME);
1274 }
1275
1276 // Functions that aren't available on Windows XP, but we still use them and just
1277 // provide some form of a fallback implementation.
1278 compat_fn! {
1279     kernel32:
1280
1281     pub fn CreateSymbolicLinkW(_lpSymlinkFileName: LPCWSTR,
1282                                _lpTargetFileName: LPCWSTR,
1283                                _dwFlags: DWORD) -> BOOLEAN {
1284         SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1285     }
1286     pub fn GetFinalPathNameByHandleW(_hFile: HANDLE,
1287                                      _lpszFilePath: LPCWSTR,
1288                                      _cchFilePath: DWORD,
1289                                      _dwFlags: DWORD) -> DWORD {
1290         SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1291     }
1292     pub fn SetThreadErrorMode(_dwNewMode: DWORD,
1293                               _lpOldMode: *mut DWORD) -> c_uint {
1294         SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1295     }
1296     pub fn SetThreadStackGuarantee(_size: *mut c_ulong) -> BOOL {
1297         SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1298     }
1299     pub fn SetFileInformationByHandle(_hFile: HANDLE,
1300                     _FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,
1301                     _lpFileInformation: LPVOID,
1302                     _dwBufferSize: DWORD) -> BOOL {
1303         SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1304     }
1305     pub fn SleepConditionVariableSRW(ConditionVariable: PCONDITION_VARIABLE,
1306                                      SRWLock: PSRWLOCK,
1307                                      dwMilliseconds: DWORD,
1308                                      Flags: ULONG) -> BOOL {
1309         panic!("condition variables not available")
1310     }
1311     pub fn WakeConditionVariable(ConditionVariable: PCONDITION_VARIABLE)
1312                                  -> () {
1313         panic!("condition variables not available")
1314     }
1315     pub fn WakeAllConditionVariable(ConditionVariable: PCONDITION_VARIABLE)
1316                                     -> () {
1317         panic!("condition variables not available")
1318     }
1319     pub fn AcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> () {
1320         panic!("rwlocks not available")
1321     }
1322     pub fn AcquireSRWLockShared(SRWLock: PSRWLOCK) -> () {
1323         panic!("rwlocks not available")
1324     }
1325     pub fn ReleaseSRWLockExclusive(SRWLock: PSRWLOCK) -> () {
1326         panic!("rwlocks not available")
1327     }
1328     pub fn ReleaseSRWLockShared(SRWLock: PSRWLOCK) -> () {
1329         panic!("rwlocks not available")
1330     }
1331     pub fn TryAcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> BOOLEAN {
1332         panic!("rwlocks not available")
1333     }
1334     pub fn TryAcquireSRWLockShared(SRWLock: PSRWLOCK) -> BOOLEAN {
1335         panic!("rwlocks not available")
1336     }
1337 }