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