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