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