]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/windows/c.rs
4daab31c28f4927872b196de575ff01640af948a
[rust.git] / src / libstd / sys / windows / c.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! C definitions used by libnative that don't belong in liblibc
12
13 #![allow(bad_style)]
14 #![cfg_attr(test, allow(dead_code))]
15 #![unstable(issue = "0", feature = "windows_c")]
16
17 use os::raw::{c_int, c_uint, c_ulong, c_long, c_longlong, c_ushort,};
18 use os::raw::{c_char, c_ulonglong};
19 use libc::{wchar_t, size_t, c_void};
20 use ptr;
21
22 #[repr(simd)]
23 #[repr(C)]
24 #[cfg(target_arch = "x86_64")]
25 struct u64x2(u64, u64);
26
27 pub use self::FILE_INFO_BY_HANDLE_CLASS::*;
28 pub use self::EXCEPTION_DISPOSITION::*;
29
30 pub type DWORD = c_ulong;
31 pub type HANDLE = LPVOID;
32 pub type HINSTANCE = HANDLE;
33 pub type HMODULE = HINSTANCE;
34 pub type BOOL = c_int;
35 pub type BYTE = u8;
36 pub type BOOLEAN = BYTE;
37 pub type GROUP = c_uint;
38 pub type LONG_PTR = isize;
39 pub type LARGE_INTEGER = c_longlong;
40 pub type LONG = c_long;
41 pub type UINT = c_uint;
42 pub type WCHAR = u16;
43 pub type USHORT = c_ushort;
44 pub type SIZE_T = usize;
45 pub type WORD = u16;
46 pub type CHAR = c_char;
47 pub type HCRYPTPROV = LONG_PTR;
48 pub type ULONG_PTR = c_ulonglong;
49 pub type ULONG = c_ulong;
50 #[cfg(target_arch = "x86_64")]
51 pub type ULONGLONG = u64;
52 #[cfg(target_arch = "x86_64")]
53 pub type DWORDLONG = ULONGLONG;
54
55 pub type LPBOOL = *mut BOOL;
56 pub type LPBYTE = *mut BYTE;
57 pub type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION;
58 pub type LPCSTR = *const CHAR;
59 pub type LPCVOID = *const c_void;
60 pub type LPCWSTR = *const WCHAR;
61 pub type LPDWORD = *mut DWORD;
62 pub type LPHANDLE = *mut HANDLE;
63 pub type LPOVERLAPPED = *mut OVERLAPPED;
64 pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION;
65 pub type LPSECURITY_ATTRIBUTES = *mut SECURITY_ATTRIBUTES;
66 pub type LPSTARTUPINFO = *mut STARTUPINFO;
67 pub type LPVOID = *mut c_void;
68 pub type LPWCH = *mut WCHAR;
69 pub type LPWIN32_FIND_DATAW = *mut WIN32_FIND_DATAW;
70 pub type LPWSADATA = *mut WSADATA;
71 pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO;
72 pub type LPSTR = *mut CHAR;
73 pub type LPWSTR = *mut WCHAR;
74 pub type LPFILETIME = *mut FILETIME;
75
76 pub type PCONDITION_VARIABLE = *mut CONDITION_VARIABLE;
77 pub type PLARGE_INTEGER = *mut c_longlong;
78 pub type PSRWLOCK = *mut SRWLOCK;
79
80 pub type SOCKET = ::os::windows::raw::SOCKET;
81 pub type socklen_t = c_int;
82 pub type ADDRESS_FAMILY = USHORT;
83
84 pub const TRUE: BOOL = 1;
85 pub const FALSE: BOOL = 0;
86
87 pub const FILE_ATTRIBUTE_READONLY: DWORD = 0x1;
88 pub const FILE_ATTRIBUTE_DIRECTORY: DWORD = 0x10;
89 pub const FILE_ATTRIBUTE_REPARSE_POINT: DWORD = 0x400;
90
91 pub const FILE_SHARE_DELETE: DWORD = 0x4;
92 pub const FILE_SHARE_READ: DWORD = 0x1;
93 pub const FILE_SHARE_WRITE: DWORD = 0x2;
94
95 pub const CREATE_ALWAYS: DWORD = 2;
96 pub const CREATE_NEW: DWORD = 1;
97 pub const OPEN_ALWAYS: DWORD = 4;
98 pub const OPEN_EXISTING: DWORD = 3;
99 pub const TRUNCATE_EXISTING: DWORD = 5;
100
101 pub const FILE_WRITE_DATA: DWORD = 0x00000002;
102 pub const FILE_APPEND_DATA: DWORD = 0x00000004;
103 pub const FILE_WRITE_EA: DWORD = 0x00000010;
104 pub const FILE_WRITE_ATTRIBUTES: DWORD = 0x00000100;
105 pub const READ_CONTROL: DWORD = 0x00020000;
106 pub const SYNCHRONIZE: DWORD = 0x00100000;
107 pub const GENERIC_READ: DWORD = 0x80000000;
108 pub const GENERIC_WRITE: DWORD = 0x40000000;
109 pub const STANDARD_RIGHTS_WRITE: DWORD = READ_CONTROL;
110 pub const FILE_GENERIC_WRITE: DWORD = STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA |
111                                       FILE_WRITE_ATTRIBUTES |
112                                       FILE_WRITE_EA |
113                                       FILE_APPEND_DATA |
114                                       SYNCHRONIZE;
115
116 pub const FILE_FLAG_OPEN_REPARSE_POINT: DWORD = 0x00200000;
117 pub const FILE_FLAG_BACKUP_SEMANTICS: DWORD = 0x02000000;
118 pub const SECURITY_SQOS_PRESENT: DWORD = 0x00100000;
119
120 pub const FIONBIO: c_ulong = 0x8004667e;
121
122 #[repr(C)]
123 #[derive(Copy)]
124 pub struct WIN32_FIND_DATAW {
125     pub dwFileAttributes: DWORD,
126     pub ftCreationTime: FILETIME,
127     pub ftLastAccessTime: FILETIME,
128     pub ftLastWriteTime: FILETIME,
129     pub nFileSizeHigh: DWORD,
130     pub nFileSizeLow: DWORD,
131     pub dwReserved0: DWORD,
132     pub dwReserved1: DWORD,
133     pub cFileName: [wchar_t; 260], // #define MAX_PATH 260
134     pub cAlternateFileName: [wchar_t; 14],
135 }
136 impl Clone for WIN32_FIND_DATAW {
137     fn clone(&self) -> Self { *self }
138 }
139
140 pub const WSA_FLAG_OVERLAPPED: DWORD = 0x01;
141
142 pub const WSADESCRIPTION_LEN: usize = 256;
143 pub const WSASYS_STATUS_LEN: usize = 128;
144 pub const WSAPROTOCOL_LEN: DWORD = 255;
145 pub const INVALID_SOCKET: SOCKET = !0;
146
147 pub const WSAEACCES: c_int = 10013;
148 pub const WSAEINVAL: c_int = 10022;
149 pub const WSAEWOULDBLOCK: c_int = 10035;
150 pub const WSAEADDRINUSE: c_int = 10048;
151 pub const WSAEADDRNOTAVAIL: c_int = 10049;
152 pub const WSAECONNABORTED: c_int = 10053;
153 pub const WSAECONNRESET: c_int = 10054;
154 pub const WSAENOTCONN: c_int = 10057;
155 pub const WSAESHUTDOWN: c_int = 10058;
156 pub const WSAETIMEDOUT: c_int = 10060;
157 pub const WSAECONNREFUSED: c_int = 10061;
158
159 pub const MAX_PROTOCOL_CHAIN: DWORD = 7;
160
161 pub const TOKEN_READ: DWORD = 0x20008;
162 pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024;
163 pub const FSCTL_GET_REPARSE_POINT: DWORD = 0x900a8;
164 pub const IO_REPARSE_TAG_SYMLINK: DWORD = 0xa000000c;
165 pub const IO_REPARSE_TAG_MOUNT_POINT: DWORD = 0xa0000003;
166 pub const SYMLINK_FLAG_RELATIVE: DWORD = 0x00000001;
167 pub const FSCTL_SET_REPARSE_POINT: DWORD = 0x900a4;
168
169 pub const SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 0x1;
170 pub const SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE: DWORD = 0x2;
171
172 // Note that these are not actually HANDLEs, just values to pass to GetStdHandle
173 pub const STD_INPUT_HANDLE: DWORD = -10i32 as DWORD;
174 pub const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
175 pub const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
176
177 pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001;
178
179 pub const PROGRESS_CONTINUE: DWORD = 0;
180
181 pub const ERROR_FILE_NOT_FOUND: DWORD = 2;
182 pub const ERROR_PATH_NOT_FOUND: DWORD = 3;
183 pub const ERROR_ACCESS_DENIED: DWORD = 5;
184 pub const ERROR_INVALID_HANDLE: DWORD = 6;
185 pub const ERROR_NO_MORE_FILES: DWORD = 18;
186 pub const ERROR_HANDLE_EOF: DWORD = 38;
187 pub const ERROR_FILE_EXISTS: DWORD = 80;
188 pub const ERROR_INVALID_PARAMETER: DWORD = 87;
189 pub const ERROR_BROKEN_PIPE: DWORD = 109;
190 pub const ERROR_CALL_NOT_IMPLEMENTED: DWORD = 120;
191 pub const ERROR_INSUFFICIENT_BUFFER: DWORD = 122;
192 pub const ERROR_ALREADY_EXISTS: DWORD = 183;
193 pub const ERROR_NO_DATA: DWORD = 232;
194 pub const ERROR_ENVVAR_NOT_FOUND: DWORD = 203;
195 pub const ERROR_OPERATION_ABORTED: DWORD = 995;
196 pub const ERROR_IO_PENDING: DWORD = 997;
197 pub const ERROR_TIMEOUT: DWORD = 0x5B4;
198
199 pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE;
200
201 pub const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000;
202 pub const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200;
203
204 pub const TLS_OUT_OF_INDEXES: DWORD = 0xFFFFFFFF;
205
206 pub const DLL_THREAD_DETACH: DWORD = 3;
207 pub const DLL_PROCESS_DETACH: DWORD = 0;
208
209 pub const INFINITE: DWORD = !0;
210
211 pub const DUPLICATE_SAME_ACCESS: DWORD = 0x00000002;
212
213 pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE {
214     ptr: ptr::null_mut(),
215 };
216 pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: ptr::null_mut() };
217
218 pub const DETACHED_PROCESS: DWORD = 0x00000008;
219 pub const CREATE_NEW_PROCESS_GROUP: DWORD = 0x00000200;
220 pub const CREATE_UNICODE_ENVIRONMENT: DWORD = 0x00000400;
221 pub const STARTF_USESTDHANDLES: DWORD = 0x00000100;
222
223 pub const AF_INET: c_int = 2;
224 pub const AF_INET6: c_int = 23;
225 pub const SD_BOTH: c_int = 2;
226 pub const SD_RECEIVE: c_int = 0;
227 pub const SD_SEND: c_int = 1;
228 pub const SOCK_DGRAM: c_int = 2;
229 pub const SOCK_STREAM: c_int = 1;
230 pub const SOL_SOCKET: c_int = 0xffff;
231 pub const SO_RCVTIMEO: c_int = 0x1006;
232 pub const SO_SNDTIMEO: c_int = 0x1005;
233 pub const SO_REUSEADDR: c_int = 0x0004;
234 pub const IPPROTO_IP: c_int = 0;
235 pub const IPPROTO_TCP: c_int = 6;
236 pub const IPPROTO_IPV6: c_int = 41;
237 pub const TCP_NODELAY: c_int = 0x0001;
238 pub const IP_TTL: c_int = 4;
239 pub const IPV6_V6ONLY: c_int = 27;
240 pub const SO_ERROR: c_int = 0x1007;
241 pub const SO_BROADCAST: c_int = 0x0020;
242 pub const IP_MULTICAST_LOOP: c_int = 11;
243 pub const IPV6_MULTICAST_LOOP: c_int = 11;
244 pub const IP_MULTICAST_TTL: c_int = 10;
245 pub const IP_ADD_MEMBERSHIP: c_int = 12;
246 pub const IP_DROP_MEMBERSHIP: c_int = 13;
247 pub const IPV6_ADD_MEMBERSHIP: c_int = 12;
248 pub const IPV6_DROP_MEMBERSHIP: c_int = 13;
249 pub const MSG_PEEK: c_int = 0x2;
250
251 #[repr(C)]
252 pub struct ip_mreq {
253     pub imr_multiaddr: in_addr,
254     pub imr_interface: in_addr,
255 }
256
257 #[repr(C)]
258 pub struct ipv6_mreq {
259     pub ipv6mr_multiaddr: in6_addr,
260     pub ipv6mr_interface: c_uint,
261 }
262
263 pub const VOLUME_NAME_DOS: DWORD = 0x0;
264 pub const MOVEFILE_REPLACE_EXISTING: DWORD = 1;
265
266 pub const FILE_BEGIN: DWORD = 0;
267 pub const FILE_CURRENT: DWORD = 1;
268 pub const FILE_END: DWORD = 2;
269
270 pub const WAIT_OBJECT_0: DWORD = 0x00000000;
271 pub const WAIT_TIMEOUT: DWORD = 258;
272
273 #[cfg(target_env = "msvc")]
274 pub const MAX_SYM_NAME: usize = 2000;
275 #[cfg(target_arch = "x86")]
276 pub const IMAGE_FILE_MACHINE_I386: DWORD = 0x014c;
277 #[cfg(target_arch = "x86_64")]
278 pub const IMAGE_FILE_MACHINE_AMD64: DWORD = 0x8664;
279
280 pub const PROV_RSA_FULL: DWORD = 1;
281 pub const CRYPT_SILENT: DWORD = 64;
282 pub const CRYPT_VERIFYCONTEXT: DWORD = 0xF0000000;
283
284 pub const EXCEPTION_CONTINUE_SEARCH: LONG = 0;
285 pub const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd;
286 pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15;
287
288 pub const PIPE_ACCESS_INBOUND: DWORD = 0x00000001;
289 pub const PIPE_ACCESS_OUTBOUND: DWORD = 0x00000002;
290 pub const FILE_FLAG_FIRST_PIPE_INSTANCE: DWORD = 0x00080000;
291 pub const FILE_FLAG_OVERLAPPED: DWORD = 0x40000000;
292 pub const PIPE_WAIT: DWORD = 0x00000000;
293 pub const PIPE_TYPE_BYTE: DWORD = 0x00000000;
294 pub const PIPE_REJECT_REMOTE_CLIENTS: DWORD = 0x00000008;
295 pub const PIPE_READMODE_BYTE: DWORD = 0x00000000;
296
297 #[repr(C)]
298 #[cfg(target_arch = "x86")]
299 pub struct WSADATA {
300     pub wVersion: WORD,
301     pub wHighVersion: WORD,
302     pub szDescription: [u8; WSADESCRIPTION_LEN + 1],
303     pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
304     pub iMaxSockets: u16,
305     pub iMaxUdpDg: u16,
306     pub lpVendorInfo: *mut u8,
307 }
308 #[repr(C)]
309 #[cfg(target_arch = "x86_64")]
310 pub struct WSADATA {
311     pub wVersion: WORD,
312     pub wHighVersion: WORD,
313     pub iMaxSockets: u16,
314     pub iMaxUdpDg: u16,
315     pub lpVendorInfo: *mut u8,
316     pub szDescription: [u8; WSADESCRIPTION_LEN + 1],
317     pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
318 }
319
320 #[repr(C)]
321 pub struct WSAPROTOCOL_INFO {
322     pub dwServiceFlags1: DWORD,
323     pub dwServiceFlags2: DWORD,
324     pub dwServiceFlags3: DWORD,
325     pub dwServiceFlags4: DWORD,
326     pub dwProviderFlags: DWORD,
327     pub ProviderId: GUID,
328     pub dwCatalogEntryId: DWORD,
329     pub ProtocolChain: WSAPROTOCOLCHAIN,
330     pub iVersion: c_int,
331     pub iAddressFamily: c_int,
332     pub iMaxSockAddr: c_int,
333     pub iMinSockAddr: c_int,
334     pub iSocketType: c_int,
335     pub iProtocol: c_int,
336     pub iProtocolMaxOffset: c_int,
337     pub iNetworkByteOrder: c_int,
338     pub iSecurityScheme: c_int,
339     pub dwMessageSize: DWORD,
340     pub dwProviderReserved: DWORD,
341     pub szProtocol: [u16; (WSAPROTOCOL_LEN as usize) + 1],
342 }
343
344 #[repr(C)]
345 #[derive(Copy, Clone)]
346 pub struct WIN32_FILE_ATTRIBUTE_DATA {
347     pub dwFileAttributes: DWORD,
348     pub ftCreationTime: FILETIME,
349     pub ftLastAccessTime: FILETIME,
350     pub ftLastWriteTime: FILETIME,
351     pub nFileSizeHigh: DWORD,
352     pub nFileSizeLow: DWORD,
353 }
354
355 #[repr(C)]
356 pub struct BY_HANDLE_FILE_INFORMATION {
357     pub dwFileAttributes: DWORD,
358     pub ftCreationTime: FILETIME,
359     pub ftLastAccessTime: FILETIME,
360     pub ftLastWriteTime: FILETIME,
361     pub dwVolumeSerialNumber: DWORD,
362     pub nFileSizeHigh: DWORD,
363     pub nFileSizeLow: DWORD,
364     pub nNumberOfLinks: DWORD,
365     pub nFileIndexHigh: DWORD,
366     pub nFileIndexLow: DWORD,
367 }
368
369 #[repr(C)]
370 #[allow(dead_code)] // we only use some variants
371 pub enum FILE_INFO_BY_HANDLE_CLASS {
372     FileBasicInfo                   = 0,
373     FileStandardInfo                = 1,
374     FileNameInfo                    = 2,
375     FileRenameInfo                  = 3,
376     FileDispositionInfo             = 4,
377     FileAllocationInfo              = 5,
378     FileEndOfFileInfo               = 6,
379     FileStreamInfo                  = 7,
380     FileCompressionInfo             = 8,
381     FileAttributeTagInfo            = 9,
382     FileIdBothDirectoryInfo         = 10, // 0xA
383     FileIdBothDirectoryRestartInfo  = 11, // 0xB
384     FileIoPriorityHintInfo          = 12, // 0xC
385     FileRemoteProtocolInfo          = 13, // 0xD
386     FileFullDirectoryInfo           = 14, // 0xE
387     FileFullDirectoryRestartInfo    = 15, // 0xF
388     FileStorageInfo                 = 16, // 0x10
389     FileAlignmentInfo               = 17, // 0x11
390     FileIdInfo                      = 18, // 0x12
391     FileIdExtdDirectoryInfo         = 19, // 0x13
392     FileIdExtdDirectoryRestartInfo  = 20, // 0x14
393     MaximumFileInfoByHandlesClass
394 }
395
396 #[repr(C)]
397 pub struct FILE_BASIC_INFO {
398     pub CreationTime: LARGE_INTEGER,
399     pub LastAccessTime: LARGE_INTEGER,
400     pub LastWriteTime: LARGE_INTEGER,
401     pub ChangeTime: LARGE_INTEGER,
402     pub FileAttributes: DWORD,
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 #[repr(C)]
817 #[derive(Copy, Clone)]
818 #[allow(dead_code)] // we only use some variants
819 pub enum EXCEPTION_DISPOSITION {
820     ExceptionContinueExecution,
821     ExceptionContinueSearch,
822     ExceptionNestedException,
823     ExceptionCollidedUnwind
824 }
825
826 #[repr(C)]
827 #[derive(Copy, Clone)]
828 pub struct CONSOLE_READCONSOLE_CONTROL {
829     pub nLength: ULONG,
830     pub nInitialChars: ULONG,
831     pub dwCtrlWakeupMask: ULONG,
832     pub dwControlKeyState: ULONG,
833 }
834 pub type PCONSOLE_READCONSOLE_CONTROL = *mut CONSOLE_READCONSOLE_CONTROL;
835
836 extern "system" {
837     pub fn WSAStartup(wVersionRequested: WORD,
838                       lpWSAData: LPWSADATA) -> c_int;
839     pub fn WSACleanup() -> c_int;
840     pub fn WSAGetLastError() -> c_int;
841     pub fn WSADuplicateSocketW(s: SOCKET,
842                                dwProcessId: DWORD,
843                                lpProtocolInfo: LPWSAPROTOCOL_INFO)
844                                -> c_int;
845     pub fn GetCurrentProcessId() -> DWORD;
846     pub fn WSASocketW(af: c_int,
847                       kind: c_int,
848                       protocol: c_int,
849                       lpProtocolInfo: LPWSAPROTOCOL_INFO,
850                       g: GROUP,
851                       dwFlags: DWORD) -> SOCKET;
852     pub fn ioctlsocket(s: SOCKET, cmd: c_long, argp: *mut c_ulong) -> c_int;
853     pub fn InitializeCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
854     pub fn EnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
855     pub fn TryEnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION) -> BOOLEAN;
856     pub fn LeaveCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
857     pub fn DeleteCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
858
859     pub fn ReadConsoleW(hConsoleInput: HANDLE,
860                         lpBuffer: LPVOID,
861                         nNumberOfCharsToRead: DWORD,
862                         lpNumberOfCharsRead: LPDWORD,
863                         pInputControl: PCONSOLE_READCONSOLE_CONTROL) -> BOOL;
864
865     pub fn WriteConsoleW(hConsoleOutput: HANDLE,
866                          lpBuffer: LPCVOID,
867                          nNumberOfCharsToWrite: DWORD,
868                          lpNumberOfCharsWritten: LPDWORD,
869                          lpReserved: LPVOID) -> BOOL;
870
871     pub fn GetConsoleMode(hConsoleHandle: HANDLE,
872                           lpMode: LPDWORD) -> BOOL;
873     pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
874     pub fn SetFileAttributesW(lpFileName: LPCWSTR,
875                               dwFileAttributes: DWORD) -> BOOL;
876     pub fn GetFileInformationByHandle(hFile: HANDLE,
877                             lpFileInformation: LPBY_HANDLE_FILE_INFORMATION)
878                             -> BOOL;
879
880     pub fn SetLastError(dwErrCode: DWORD);
881     pub fn GetCommandLineW() -> *mut LPCWSTR;
882     pub fn LocalFree(ptr: *mut c_void);
883     pub fn CommandLineToArgvW(lpCmdLine: *mut LPCWSTR,
884                               pNumArgs: *mut c_int) -> *mut *mut u16;
885     pub fn GetTempPathW(nBufferLength: DWORD,
886                         lpBuffer: LPCWSTR) -> DWORD;
887     pub fn OpenProcessToken(ProcessHandle: HANDLE,
888                             DesiredAccess: DWORD,
889                             TokenHandle: *mut HANDLE) -> BOOL;
890     pub fn GetCurrentProcess() -> HANDLE;
891     pub fn GetCurrentThread() -> HANDLE;
892     pub fn GetStdHandle(which: DWORD) -> HANDLE;
893     pub fn ExitProcess(uExitCode: c_uint) -> !;
894     pub fn DeviceIoControl(hDevice: HANDLE,
895                            dwIoControlCode: DWORD,
896                            lpInBuffer: LPVOID,
897                            nInBufferSize: DWORD,
898                            lpOutBuffer: LPVOID,
899                            nOutBufferSize: DWORD,
900                            lpBytesReturned: LPDWORD,
901                            lpOverlapped: LPOVERLAPPED) -> BOOL;
902     pub fn CreateThread(lpThreadAttributes: LPSECURITY_ATTRIBUTES,
903                         dwStackSize: SIZE_T,
904                         lpStartAddress: extern "system" fn(*mut c_void)
905                                                            -> DWORD,
906                         lpParameter: LPVOID,
907                         dwCreationFlags: DWORD,
908                         lpThreadId: LPDWORD) -> HANDLE;
909     pub fn WaitForSingleObject(hHandle: HANDLE,
910                                dwMilliseconds: DWORD) -> DWORD;
911     pub fn SwitchToThread() -> BOOL;
912     pub fn Sleep(dwMilliseconds: DWORD);
913     pub fn GetProcessId(handle: HANDLE) -> DWORD;
914     pub fn GetUserProfileDirectoryW(hToken: HANDLE,
915                                     lpProfileDir: LPWSTR,
916                                     lpcchSize: *mut DWORD) -> BOOL;
917     pub fn SetHandleInformation(hObject: HANDLE,
918                                 dwMask: DWORD,
919                                 dwFlags: DWORD) -> BOOL;
920     pub fn CopyFileExW(lpExistingFileName: LPCWSTR,
921                        lpNewFileName: LPCWSTR,
922                        lpProgressRoutine: LPPROGRESS_ROUTINE,
923                        lpData: LPVOID,
924                        pbCancel: LPBOOL,
925                        dwCopyFlags: DWORD) -> BOOL;
926     pub fn AddVectoredExceptionHandler(FirstHandler: ULONG,
927                                        VectoredHandler: PVECTORED_EXCEPTION_HANDLER)
928                                        -> LPVOID;
929     pub fn FormatMessageW(flags: DWORD,
930                           lpSrc: LPVOID,
931                           msgId: DWORD,
932                           langId: DWORD,
933                           buf: LPWSTR,
934                           nsize: DWORD,
935                           args: *const c_void)
936                           -> DWORD;
937     pub fn TlsAlloc() -> DWORD;
938     pub fn TlsFree(dwTlsIndex: DWORD) -> BOOL;
939     pub fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID;
940     pub fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL;
941     pub fn GetLastError() -> DWORD;
942     pub fn QueryPerformanceFrequency(lpFrequency: *mut LARGE_INTEGER) -> BOOL;
943     pub fn QueryPerformanceCounter(lpPerformanceCount: *mut LARGE_INTEGER)
944                                    -> BOOL;
945     pub fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: LPDWORD) -> BOOL;
946     pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) -> BOOL;
947     pub fn CreateProcessW(lpApplicationName: LPCWSTR,
948                           lpCommandLine: LPWSTR,
949                           lpProcessAttributes: LPSECURITY_ATTRIBUTES,
950                           lpThreadAttributes: LPSECURITY_ATTRIBUTES,
951                           bInheritHandles: BOOL,
952                           dwCreationFlags: DWORD,
953                           lpEnvironment: LPVOID,
954                           lpCurrentDirectory: LPCWSTR,
955                           lpStartupInfo: LPSTARTUPINFO,
956                           lpProcessInformation: LPPROCESS_INFORMATION)
957                           -> BOOL;
958     pub fn GetEnvironmentVariableW(n: LPCWSTR, v: LPWSTR, nsize: DWORD) -> DWORD;
959     pub fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL;
960     pub fn GetEnvironmentStringsW() -> LPWCH;
961     pub fn FreeEnvironmentStringsW(env_ptr: LPWCH) -> BOOL;
962     pub fn GetModuleFileNameW(hModule: HMODULE,
963                               lpFilename: LPWSTR,
964                               nSize: DWORD)
965                               -> DWORD;
966     pub fn CreateDirectoryW(lpPathName: LPCWSTR,
967                             lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
968                             -> BOOL;
969     pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
970     pub fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: LPWSTR) -> DWORD;
971     pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
972     pub fn WideCharToMultiByte(CodePage: UINT,
973                                dwFlags: DWORD,
974                                lpWideCharStr: LPCWSTR,
975                                cchWideChar: c_int,
976                                lpMultiByteStr: LPSTR,
977                                cbMultiByte: c_int,
978                                lpDefaultChar: LPCSTR,
979                                lpUsedDefaultChar: LPBOOL) -> c_int;
980
981     pub fn closesocket(socket: SOCKET) -> c_int;
982     pub fn recv(socket: SOCKET, buf: *mut c_void, len: c_int,
983                 flags: c_int) -> c_int;
984     pub fn send(socket: SOCKET, buf: *const c_void, len: c_int,
985                 flags: c_int) -> c_int;
986     pub fn recvfrom(socket: SOCKET,
987                     buf: *mut c_void,
988                     len: c_int,
989                     flags: c_int,
990                     addr: *mut SOCKADDR,
991                     addrlen: *mut c_int)
992                     -> c_int;
993     pub fn sendto(socket: SOCKET,
994                   buf: *const c_void,
995                   len: c_int,
996                   flags: c_int,
997                   addr: *const SOCKADDR,
998                   addrlen: c_int)
999                   -> c_int;
1000     pub fn shutdown(socket: SOCKET, how: c_int) -> c_int;
1001     pub fn accept(socket: SOCKET,
1002                   address: *mut SOCKADDR,
1003                   address_len: *mut c_int)
1004                   -> SOCKET;
1005     pub fn DuplicateHandle(hSourceProcessHandle: HANDLE,
1006                            hSourceHandle: HANDLE,
1007                            hTargetProcessHandle: HANDLE,
1008                            lpTargetHandle: LPHANDLE,
1009                            dwDesiredAccess: DWORD,
1010                            bInheritHandle: BOOL,
1011                            dwOptions: DWORD)
1012                            -> BOOL;
1013     pub fn ReadFile(hFile: HANDLE,
1014                     lpBuffer: LPVOID,
1015                     nNumberOfBytesToRead: DWORD,
1016                     lpNumberOfBytesRead: LPDWORD,
1017                     lpOverlapped: LPOVERLAPPED)
1018                     -> BOOL;
1019     pub fn WriteFile(hFile: HANDLE,
1020                      lpBuffer: LPVOID,
1021                      nNumberOfBytesToWrite: DWORD,
1022                      lpNumberOfBytesWritten: LPDWORD,
1023                      lpOverlapped: LPOVERLAPPED)
1024                      -> BOOL;
1025     pub fn CloseHandle(hObject: HANDLE) -> BOOL;
1026     pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR,
1027                            lpTargetFileName: LPCWSTR,
1028                            lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
1029                            -> BOOL;
1030     pub fn MoveFileExW(lpExistingFileName: LPCWSTR,
1031                        lpNewFileName: LPCWSTR,
1032                        dwFlags: DWORD)
1033                        -> BOOL;
1034     pub fn SetFilePointerEx(hFile: HANDLE,
1035                             liDistanceToMove: LARGE_INTEGER,
1036                             lpNewFilePointer: PLARGE_INTEGER,
1037                             dwMoveMethod: DWORD)
1038                             -> BOOL;
1039     pub fn FlushFileBuffers(hFile: HANDLE) -> BOOL;
1040     pub fn CreateFileW(lpFileName: LPCWSTR,
1041                        dwDesiredAccess: DWORD,
1042                        dwShareMode: DWORD,
1043                        lpSecurityAttributes: LPSECURITY_ATTRIBUTES,
1044                        dwCreationDisposition: DWORD,
1045                        dwFlagsAndAttributes: DWORD,
1046                        hTemplateFile: HANDLE)
1047                        -> HANDLE;
1048
1049     pub fn FindFirstFileW(fileName: LPCWSTR,
1050                           findFileData: LPWIN32_FIND_DATAW)
1051                           -> HANDLE;
1052     pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW)
1053                          -> BOOL;
1054     pub fn FindClose(findFile: HANDLE) -> BOOL;
1055     pub fn RtlCaptureContext(ctx: *mut CONTEXT);
1056     pub fn getsockopt(s: SOCKET,
1057                       level: c_int,
1058                       optname: c_int,
1059                       optval: *mut c_char,
1060                       optlen: *mut c_int)
1061                       -> c_int;
1062     pub fn setsockopt(s: SOCKET,
1063                       level: c_int,
1064                       optname: c_int,
1065                       optval: *const c_void,
1066                       optlen: c_int)
1067                       -> c_int;
1068     pub fn getsockname(socket: SOCKET,
1069                        address: *mut SOCKADDR,
1070                        address_len: *mut c_int)
1071                        -> c_int;
1072     pub fn getpeername(socket: SOCKET,
1073                        address: *mut SOCKADDR,
1074                        address_len: *mut c_int)
1075                        -> c_int;
1076     pub fn bind(socket: SOCKET, address: *const SOCKADDR,
1077                 address_len: socklen_t) -> c_int;
1078     pub fn listen(socket: SOCKET, backlog: c_int) -> c_int;
1079     pub fn connect(socket: SOCKET, address: *const SOCKADDR, len: c_int)
1080                    -> c_int;
1081     pub fn getaddrinfo(node: *const c_char, service: *const c_char,
1082                        hints: *const ADDRINFOA,
1083                        res: *mut *mut ADDRINFOA) -> c_int;
1084     pub fn freeaddrinfo(res: *mut ADDRINFOA);
1085
1086     pub fn LoadLibraryW(name: LPCWSTR) -> HMODULE;
1087     pub fn FreeLibrary(handle: HMODULE) -> BOOL;
1088     pub fn GetProcAddress(handle: HMODULE,
1089                           name: LPCSTR) -> *mut c_void;
1090     pub fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE;
1091     pub fn CryptAcquireContextA(phProv: *mut HCRYPTPROV,
1092                                 pszContainer: LPCSTR,
1093                                 pszProvider: LPCSTR,
1094                                 dwProvType: DWORD,
1095                                 dwFlags: DWORD) -> BOOL;
1096     pub fn CryptGenRandom(hProv: HCRYPTPROV,
1097                           dwLen: DWORD,
1098                           pbBuffer: *mut BYTE) -> BOOL;
1099     pub fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL;
1100
1101     pub fn GetSystemTimeAsFileTime(lpSystemTimeAsFileTime: LPFILETIME);
1102
1103     pub fn CreateEventW(lpEventAttributes: LPSECURITY_ATTRIBUTES,
1104                         bManualReset: BOOL,
1105                         bInitialState: BOOL,
1106                         lpName: LPCWSTR) -> HANDLE;
1107     pub fn WaitForMultipleObjects(nCount: DWORD,
1108                                   lpHandles: *const HANDLE,
1109                                   bWaitAll: BOOL,
1110                                   dwMilliseconds: DWORD) -> DWORD;
1111     pub fn CreateNamedPipeW(lpName: LPCWSTR,
1112                             dwOpenMode: DWORD,
1113                             dwPipeMode: DWORD,
1114                             nMaxInstances: DWORD,
1115                             nOutBufferSize: DWORD,
1116                             nInBufferSize: DWORD,
1117                             nDefaultTimeOut: DWORD,
1118                             lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
1119                             -> HANDLE;
1120     pub fn CancelIo(handle: HANDLE) -> BOOL;
1121     pub fn GetOverlappedResult(hFile: HANDLE,
1122                                lpOverlapped: LPOVERLAPPED,
1123                                lpNumberOfBytesTransferred: LPDWORD,
1124                                bWait: BOOL) -> BOOL;
1125 }
1126
1127 // Functions that aren't available on Windows XP, but we still use them and just
1128 // provide some form of a fallback implementation.
1129 compat_fn! {
1130     kernel32:
1131
1132     pub fn CreateSymbolicLinkW(_lpSymlinkFileName: LPCWSTR,
1133                                _lpTargetFileName: LPCWSTR,
1134                                _dwFlags: DWORD) -> BOOLEAN {
1135         SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1136     }
1137     pub fn GetFinalPathNameByHandleW(_hFile: HANDLE,
1138                                      _lpszFilePath: LPCWSTR,
1139                                      _cchFilePath: DWORD,
1140                                      _dwFlags: DWORD) -> DWORD {
1141         SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1142     }
1143     pub fn SetThreadStackGuarantee(_size: *mut c_ulong) -> BOOL {
1144         SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1145     }
1146     pub fn SetFileInformationByHandle(_hFile: HANDLE,
1147                     _FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,
1148                     _lpFileInformation: LPVOID,
1149                     _dwBufferSize: DWORD) -> BOOL {
1150         SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1151     }
1152     pub fn SleepConditionVariableSRW(ConditionVariable: PCONDITION_VARIABLE,
1153                                      SRWLock: PSRWLOCK,
1154                                      dwMilliseconds: DWORD,
1155                                      Flags: ULONG) -> BOOL {
1156         panic!("condition variables not available")
1157     }
1158     pub fn WakeConditionVariable(ConditionVariable: PCONDITION_VARIABLE)
1159                                  -> () {
1160         panic!("condition variables not available")
1161     }
1162     pub fn WakeAllConditionVariable(ConditionVariable: PCONDITION_VARIABLE)
1163                                     -> () {
1164         panic!("condition variables not available")
1165     }
1166     pub fn AcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> () {
1167         panic!("rwlocks not available")
1168     }
1169     pub fn AcquireSRWLockShared(SRWLock: PSRWLOCK) -> () {
1170         panic!("rwlocks not available")
1171     }
1172     pub fn ReleaseSRWLockExclusive(SRWLock: PSRWLOCK) -> () {
1173         panic!("rwlocks not available")
1174     }
1175     pub fn ReleaseSRWLockShared(SRWLock: PSRWLOCK) -> () {
1176         panic!("rwlocks not available")
1177     }
1178     pub fn TryAcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> BOOLEAN {
1179         panic!("rwlocks not available")
1180     }
1181     pub fn TryAcquireSRWLockShared(SRWLock: PSRWLOCK) -> BOOLEAN {
1182         panic!("rwlocks not available")
1183     }
1184 }
1185
1186 #[cfg(target_env = "gnu")]
1187 mod gnu {
1188     use super::*;
1189
1190     pub const PROCESS_QUERY_INFORMATION: DWORD = 0x0400;
1191
1192     pub const CP_ACP: UINT = 0;
1193
1194     pub const WC_NO_BEST_FIT_CHARS: DWORD = 0x00000400;
1195
1196     extern "system" {
1197         pub fn OpenProcess(dwDesiredAccess: DWORD,
1198                            bInheritHandle: BOOL,
1199                            dwProcessId: DWORD) -> HANDLE;
1200     }
1201
1202     compat_fn! {
1203         kernel32:
1204
1205         pub fn QueryFullProcessImageNameW(_hProcess: HANDLE,
1206                                           _dwFlags: DWORD,
1207                                           _lpExeName: LPWSTR,
1208                                           _lpdwSize: LPDWORD) -> BOOL {
1209             SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1210         }
1211     }
1212 }
1213
1214 #[cfg(target_env = "gnu")]
1215 pub use self::gnu::*;