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