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