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