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