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