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