1 //! C definitions used by libnative that don't belong in liblibc
3 #![allow(nonstandard_style)]
4 #![cfg_attr(test, allow(dead_code))]
5 #![unstable(issue = "none", feature = "windows_c")]
7 use crate::os::raw::{c_char, c_int, c_long, c_longlong, c_uint, c_ulong, c_ushort};
10 use libc::{c_void, size_t, wchar_t};
12 pub use self::EXCEPTION_DISPOSITION::*;
13 pub use self::FILE_INFO_BY_HANDLE_CLASS::*;
15 pub type DWORD = c_ulong;
16 pub type HANDLE = LPVOID;
17 pub type HINSTANCE = HANDLE;
18 pub type HMODULE = HINSTANCE;
19 pub type HRESULT = LONG;
20 pub type BOOL = c_int;
22 pub type BOOLEAN = BYTE;
23 pub type GROUP = c_uint;
24 pub type LARGE_INTEGER = c_longlong;
25 pub type LONG = c_long;
26 pub type UINT = c_uint;
28 pub type USHORT = c_ushort;
29 pub type SIZE_T = usize;
31 pub type CHAR = c_char;
32 pub type ULONG_PTR = usize;
33 pub type ULONG = c_ulong;
35 pub type LPBOOL = *mut BOOL;
36 pub type LPBYTE = *mut BYTE;
37 pub type LPCSTR = *const CHAR;
38 pub type LPCWSTR = *const WCHAR;
39 pub type LPDWORD = *mut DWORD;
40 pub type LPHANDLE = *mut HANDLE;
41 pub type LPOVERLAPPED = *mut OVERLAPPED;
42 pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION;
43 pub type LPSECURITY_ATTRIBUTES = *mut SECURITY_ATTRIBUTES;
44 pub type LPSTARTUPINFO = *mut STARTUPINFO;
45 pub type LPVOID = *mut c_void;
46 pub type LPWCH = *mut WCHAR;
47 pub type LPWIN32_FIND_DATAW = *mut WIN32_FIND_DATAW;
48 pub type LPWSADATA = *mut WSADATA;
49 pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO;
50 pub type LPSTR = *mut CHAR;
51 pub type LPWSTR = *mut WCHAR;
52 pub type LPFILETIME = *mut FILETIME;
53 pub type LPWSABUF = *mut WSABUF;
54 pub type LPWSAOVERLAPPED = *mut c_void;
55 pub type LPWSAOVERLAPPED_COMPLETION_ROUTINE = *mut c_void;
57 pub type PCONDITION_VARIABLE = *mut CONDITION_VARIABLE;
58 pub type PLARGE_INTEGER = *mut c_longlong;
59 pub type PSRWLOCK = *mut SRWLOCK;
61 pub type SOCKET = crate::os::windows::raw::SOCKET;
62 pub type socklen_t = c_int;
63 pub type ADDRESS_FAMILY = USHORT;
65 pub const TRUE: BOOL = 1;
66 pub const FALSE: BOOL = 0;
68 pub const FILE_ATTRIBUTE_READONLY: DWORD = 0x1;
69 pub const FILE_ATTRIBUTE_DIRECTORY: DWORD = 0x10;
70 pub const FILE_ATTRIBUTE_REPARSE_POINT: DWORD = 0x400;
72 pub const FILE_SHARE_DELETE: DWORD = 0x4;
73 pub const FILE_SHARE_READ: DWORD = 0x1;
74 pub const FILE_SHARE_WRITE: DWORD = 0x2;
76 pub const CREATE_ALWAYS: DWORD = 2;
77 pub const CREATE_NEW: DWORD = 1;
78 pub const OPEN_ALWAYS: DWORD = 4;
79 pub const OPEN_EXISTING: DWORD = 3;
80 pub const TRUNCATE_EXISTING: DWORD = 5;
82 pub const FILE_WRITE_DATA: DWORD = 0x00000002;
83 pub const FILE_APPEND_DATA: DWORD = 0x00000004;
84 pub const FILE_WRITE_EA: DWORD = 0x00000010;
85 pub const FILE_WRITE_ATTRIBUTES: DWORD = 0x00000100;
86 pub const READ_CONTROL: DWORD = 0x00020000;
87 pub const SYNCHRONIZE: DWORD = 0x00100000;
88 pub const GENERIC_READ: DWORD = 0x80000000;
89 pub const GENERIC_WRITE: DWORD = 0x40000000;
90 pub const STANDARD_RIGHTS_WRITE: DWORD = READ_CONTROL;
91 pub const FILE_GENERIC_WRITE: DWORD = STANDARD_RIGHTS_WRITE
93 | FILE_WRITE_ATTRIBUTES
98 pub const FILE_FLAG_OPEN_REPARSE_POINT: DWORD = 0x00200000;
99 pub const FILE_FLAG_BACKUP_SEMANTICS: DWORD = 0x02000000;
100 pub const SECURITY_SQOS_PRESENT: DWORD = 0x00100000;
102 pub const FIONBIO: c_ulong = 0x8004667e;
106 pub struct WIN32_FIND_DATAW {
107 pub dwFileAttributes: DWORD,
108 pub ftCreationTime: FILETIME,
109 pub ftLastAccessTime: FILETIME,
110 pub ftLastWriteTime: FILETIME,
111 pub nFileSizeHigh: DWORD,
112 pub nFileSizeLow: DWORD,
113 pub dwReserved0: DWORD,
114 pub dwReserved1: DWORD,
115 pub cFileName: [wchar_t; 260], // #define MAX_PATH 260
116 pub cAlternateFileName: [wchar_t; 14],
118 impl Clone for WIN32_FIND_DATAW {
119 fn clone(&self) -> Self {
124 pub const WSA_FLAG_OVERLAPPED: DWORD = 0x01;
125 pub const WSA_FLAG_NO_HANDLE_INHERIT: DWORD = 0x80;
127 pub const WSADESCRIPTION_LEN: usize = 256;
128 pub const WSASYS_STATUS_LEN: usize = 128;
129 pub const WSAPROTOCOL_LEN: DWORD = 255;
130 pub const INVALID_SOCKET: SOCKET = !0;
132 pub const WSAEACCES: c_int = 10013;
133 pub const WSAEINVAL: c_int = 10022;
134 pub const WSAEWOULDBLOCK: c_int = 10035;
135 pub const WSAEPROTOTYPE: c_int = 10041;
136 pub const WSAEADDRINUSE: c_int = 10048;
137 pub const WSAEADDRNOTAVAIL: c_int = 10049;
138 pub const WSAECONNABORTED: c_int = 10053;
139 pub const WSAECONNRESET: c_int = 10054;
140 pub const WSAENOTCONN: c_int = 10057;
141 pub const WSAESHUTDOWN: c_int = 10058;
142 pub const WSAETIMEDOUT: c_int = 10060;
143 pub const WSAECONNREFUSED: c_int = 10061;
145 pub const MAX_PROTOCOL_CHAIN: DWORD = 7;
147 pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024;
148 pub const FSCTL_GET_REPARSE_POINT: DWORD = 0x900a8;
149 pub const IO_REPARSE_TAG_SYMLINK: DWORD = 0xa000000c;
150 pub const IO_REPARSE_TAG_MOUNT_POINT: DWORD = 0xa0000003;
151 pub const SYMLINK_FLAG_RELATIVE: DWORD = 0x00000001;
152 pub const FSCTL_SET_REPARSE_POINT: DWORD = 0x900a4;
154 pub const SYMBOLIC_LINK_FLAG_DIRECTORY: DWORD = 0x1;
155 pub const SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE: DWORD = 0x2;
157 // Note that these are not actually HANDLEs, just values to pass to GetStdHandle
158 pub const STD_INPUT_HANDLE: DWORD = -10i32 as DWORD;
159 pub const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
160 pub const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
162 pub const PROGRESS_CONTINUE: DWORD = 0;
164 pub const ERROR_FILE_NOT_FOUND: DWORD = 2;
165 pub const ERROR_PATH_NOT_FOUND: DWORD = 3;
166 pub const ERROR_ACCESS_DENIED: DWORD = 5;
167 pub const ERROR_INVALID_HANDLE: DWORD = 6;
168 pub const ERROR_NO_MORE_FILES: DWORD = 18;
169 pub const ERROR_HANDLE_EOF: DWORD = 38;
170 pub const ERROR_FILE_EXISTS: DWORD = 80;
171 pub const ERROR_INVALID_PARAMETER: DWORD = 87;
172 pub const ERROR_BROKEN_PIPE: DWORD = 109;
173 pub const ERROR_CALL_NOT_IMPLEMENTED: DWORD = 120;
174 pub const ERROR_INSUFFICIENT_BUFFER: DWORD = 122;
175 pub const ERROR_ALREADY_EXISTS: DWORD = 183;
176 pub const ERROR_NO_DATA: DWORD = 232;
177 pub const ERROR_ENVVAR_NOT_FOUND: DWORD = 203;
178 pub const ERROR_OPERATION_ABORTED: DWORD = 995;
179 pub const ERROR_IO_PENDING: DWORD = 997;
180 pub const ERROR_TIMEOUT: DWORD = 0x5B4;
182 pub const E_NOTIMPL: HRESULT = 0x80004001u32 as HRESULT;
184 pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE;
186 pub const FACILITY_NT_BIT: DWORD = 0x1000_0000;
188 pub const FORMAT_MESSAGE_FROM_SYSTEM: DWORD = 0x00001000;
189 pub const FORMAT_MESSAGE_FROM_HMODULE: DWORD = 0x00000800;
190 pub const FORMAT_MESSAGE_IGNORE_INSERTS: DWORD = 0x00000200;
192 pub const TLS_OUT_OF_INDEXES: DWORD = 0xFFFFFFFF;
194 pub const DLL_THREAD_DETACH: DWORD = 3;
195 pub const DLL_PROCESS_DETACH: DWORD = 0;
197 pub const INFINITE: DWORD = !0;
199 pub const DUPLICATE_SAME_ACCESS: DWORD = 0x00000002;
201 pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE { ptr: ptr::null_mut() };
202 pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: ptr::null_mut() };
204 pub const DETACHED_PROCESS: DWORD = 0x00000008;
205 pub const CREATE_NEW_PROCESS_GROUP: DWORD = 0x00000200;
206 pub const CREATE_UNICODE_ENVIRONMENT: DWORD = 0x00000400;
207 pub const STARTF_USESTDHANDLES: DWORD = 0x00000100;
209 pub const AF_INET: c_int = 2;
210 pub const AF_INET6: c_int = 23;
211 pub const SD_BOTH: c_int = 2;
212 pub const SD_RECEIVE: c_int = 0;
213 pub const SD_SEND: c_int = 1;
214 pub const SOCK_DGRAM: c_int = 2;
215 pub const SOCK_STREAM: c_int = 1;
216 pub const SOL_SOCKET: c_int = 0xffff;
217 pub const SO_RCVTIMEO: c_int = 0x1006;
218 pub const SO_SNDTIMEO: c_int = 0x1005;
219 pub const SO_REUSEADDR: c_int = 0x0004;
220 pub const IPPROTO_IP: c_int = 0;
221 pub const IPPROTO_TCP: c_int = 6;
222 pub const IPPROTO_IPV6: c_int = 41;
223 pub const TCP_NODELAY: c_int = 0x0001;
224 pub const IP_TTL: c_int = 4;
225 pub const IPV6_V6ONLY: c_int = 27;
226 pub const SO_ERROR: c_int = 0x1007;
227 pub const SO_BROADCAST: c_int = 0x0020;
228 pub const IP_MULTICAST_LOOP: c_int = 11;
229 pub const IPV6_MULTICAST_LOOP: c_int = 11;
230 pub const IP_MULTICAST_TTL: c_int = 10;
231 pub const IP_ADD_MEMBERSHIP: c_int = 12;
232 pub const IP_DROP_MEMBERSHIP: c_int = 13;
233 pub const IPV6_ADD_MEMBERSHIP: c_int = 12;
234 pub const IPV6_DROP_MEMBERSHIP: c_int = 13;
235 pub const MSG_PEEK: c_int = 0x2;
239 pub imr_multiaddr: in_addr,
240 pub imr_interface: in_addr,
244 pub struct ipv6_mreq {
245 pub ipv6mr_multiaddr: in6_addr,
246 pub ipv6mr_interface: c_uint,
249 pub const VOLUME_NAME_DOS: DWORD = 0x0;
250 pub const MOVEFILE_REPLACE_EXISTING: DWORD = 1;
252 pub const FILE_BEGIN: DWORD = 0;
253 pub const FILE_CURRENT: DWORD = 1;
254 pub const FILE_END: DWORD = 2;
256 pub const WAIT_OBJECT_0: DWORD = 0x00000000;
257 pub const WAIT_TIMEOUT: DWORD = 258;
258 pub const WAIT_FAILED: DWORD = 0xFFFFFFFF;
260 pub const PIPE_ACCESS_INBOUND: DWORD = 0x00000001;
261 pub const PIPE_ACCESS_OUTBOUND: DWORD = 0x00000002;
262 pub const FILE_FLAG_FIRST_PIPE_INSTANCE: DWORD = 0x00080000;
263 pub const FILE_FLAG_OVERLAPPED: DWORD = 0x40000000;
264 pub const PIPE_WAIT: DWORD = 0x00000000;
265 pub const PIPE_TYPE_BYTE: DWORD = 0x00000000;
266 pub const PIPE_REJECT_REMOTE_CLIENTS: DWORD = 0x00000008;
267 pub const PIPE_READMODE_BYTE: DWORD = 0x00000000;
269 pub const FD_SETSIZE: usize = 64;
271 pub const STACK_SIZE_PARAM_IS_A_RESERVATION: DWORD = 0x00010000;
273 pub const HEAP_ZERO_MEMORY: DWORD = 0x00000008;
276 #[cfg(not(target_pointer_width = "64"))]
279 pub wHighVersion: WORD,
280 pub szDescription: [u8; WSADESCRIPTION_LEN + 1],
281 pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
282 pub iMaxSockets: u16,
284 pub lpVendorInfo: *mut u8,
287 #[cfg(target_pointer_width = "64")]
290 pub wHighVersion: WORD,
291 pub iMaxSockets: u16,
293 pub lpVendorInfo: *mut u8,
294 pub szDescription: [u8; WSADESCRIPTION_LEN + 1],
295 pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1],
305 pub struct WSAPROTOCOL_INFO {
306 pub dwServiceFlags1: DWORD,
307 pub dwServiceFlags2: DWORD,
308 pub dwServiceFlags3: DWORD,
309 pub dwServiceFlags4: DWORD,
310 pub dwProviderFlags: DWORD,
311 pub ProviderId: GUID,
312 pub dwCatalogEntryId: DWORD,
313 pub ProtocolChain: WSAPROTOCOLCHAIN,
315 pub iAddressFamily: c_int,
316 pub iMaxSockAddr: c_int,
317 pub iMinSockAddr: c_int,
318 pub iSocketType: c_int,
319 pub iProtocol: c_int,
320 pub iProtocolMaxOffset: c_int,
321 pub iNetworkByteOrder: c_int,
322 pub iSecurityScheme: c_int,
323 pub dwMessageSize: DWORD,
324 pub dwProviderReserved: DWORD,
325 pub szProtocol: [u16; (WSAPROTOCOL_LEN as usize) + 1],
329 #[derive(Copy, Clone)]
330 pub struct WIN32_FILE_ATTRIBUTE_DATA {
331 pub dwFileAttributes: DWORD,
332 pub ftCreationTime: FILETIME,
333 pub ftLastAccessTime: FILETIME,
334 pub ftLastWriteTime: FILETIME,
335 pub nFileSizeHigh: DWORD,
336 pub nFileSizeLow: DWORD,
340 #[allow(dead_code)] // we only use some variants
341 pub enum FILE_INFO_BY_HANDLE_CLASS {
343 FileStandardInfo = 1,
346 FileDispositionInfo = 4,
347 FileAllocationInfo = 5,
348 FileEndOfFileInfo = 6,
350 FileCompressionInfo = 8,
351 FileAttributeTagInfo = 9,
352 FileIdBothDirectoryInfo = 10, // 0xA
353 FileIdBothDirectoryRestartInfo = 11, // 0xB
354 FileIoPriorityHintInfo = 12, // 0xC
355 FileRemoteProtocolInfo = 13, // 0xD
356 FileFullDirectoryInfo = 14, // 0xE
357 FileFullDirectoryRestartInfo = 15, // 0xF
358 FileStorageInfo = 16, // 0x10
359 FileAlignmentInfo = 17, // 0x11
360 FileIdInfo = 18, // 0x12
361 FileIdExtdDirectoryInfo = 19, // 0x13
362 FileIdExtdDirectoryRestartInfo = 20, // 0x14
363 MaximumFileInfoByHandlesClass,
367 pub struct FILE_BASIC_INFO {
368 pub CreationTime: LARGE_INTEGER,
369 pub LastAccessTime: LARGE_INTEGER,
370 pub LastWriteTime: LARGE_INTEGER,
371 pub ChangeTime: LARGE_INTEGER,
372 pub FileAttributes: DWORD,
376 pub struct FILE_END_OF_FILE_INFO {
377 pub EndOfFile: LARGE_INTEGER,
381 pub struct REPARSE_DATA_BUFFER {
382 pub ReparseTag: c_uint,
383 pub ReparseDataLength: c_ushort,
384 pub Reserved: c_ushort,
389 pub struct SYMBOLIC_LINK_REPARSE_BUFFER {
390 pub SubstituteNameOffset: c_ushort,
391 pub SubstituteNameLength: c_ushort,
392 pub PrintNameOffset: c_ushort,
393 pub PrintNameLength: c_ushort,
395 pub PathBuffer: WCHAR,
399 pub struct MOUNT_POINT_REPARSE_BUFFER {
400 pub SubstituteNameOffset: c_ushort,
401 pub SubstituteNameLength: c_ushort,
402 pub PrintNameOffset: c_ushort,
403 pub PrintNameLength: c_ushort,
404 pub PathBuffer: WCHAR,
407 pub type LPPROGRESS_ROUTINE = crate::option::Option<
408 unsafe extern "system" fn(
409 TotalFileSize: LARGE_INTEGER,
410 TotalBytesTransferred: LARGE_INTEGER,
411 StreamSize: LARGE_INTEGER,
412 StreamBytesTransferred: LARGE_INTEGER,
413 dwStreamNumber: DWORD,
414 dwCallbackReason: DWORD,
416 hDestinationFile: HANDLE,
422 pub struct CONDITION_VARIABLE {
430 pub struct CRITICAL_SECTION {
431 CriticalSectionDebug: LPVOID,
433 RecursionCount: LONG,
434 OwningThread: HANDLE,
435 LockSemaphore: HANDLE,
436 SpinCount: ULONG_PTR,
440 pub struct REPARSE_MOUNTPOINT_DATA_BUFFER {
441 pub ReparseTag: DWORD,
442 pub ReparseDataLength: DWORD,
444 pub ReparseTargetLength: WORD,
445 pub ReparseTargetMaximumLength: WORD,
447 pub ReparseTarget: WCHAR,
455 pub Data4: [BYTE; 8],
459 pub struct WSAPROTOCOLCHAIN {
461 pub ChainEntries: [DWORD; MAX_PROTOCOL_CHAIN as usize],
465 pub struct SECURITY_ATTRIBUTES {
467 pub lpSecurityDescriptor: LPVOID,
468 pub bInheritHandle: BOOL,
472 pub struct PROCESS_INFORMATION {
473 pub hProcess: HANDLE,
475 pub dwProcessId: DWORD,
476 pub dwThreadId: DWORD,
480 pub struct STARTUPINFO {
482 pub lpReserved: LPWSTR,
483 pub lpDesktop: LPWSTR,
489 pub dwXCountChars: DWORD,
490 pub dwYCountCharts: DWORD,
491 pub dwFillAttribute: DWORD,
493 pub wShowWindow: WORD,
494 pub cbReserved2: WORD,
495 pub lpReserved2: LPBYTE,
496 pub hStdInput: HANDLE,
497 pub hStdOutput: HANDLE,
498 pub hStdError: HANDLE,
502 pub struct SOCKADDR {
503 pub sa_family: ADDRESS_FAMILY,
504 pub sa_data: [CHAR; 14],
508 #[derive(Copy, Clone)]
509 pub struct FILETIME {
510 pub dwLowDateTime: DWORD,
511 pub dwHighDateTime: DWORD,
515 pub struct OVERLAPPED {
516 pub Internal: *mut c_ulong,
517 pub InternalHigh: *mut c_ulong,
519 pub OffsetHigh: DWORD,
524 #[allow(dead_code)] // we only use some variants
525 pub enum ADDRESS_MODE {
533 pub struct SOCKADDR_STORAGE_LH {
534 pub ss_family: ADDRESS_FAMILY,
535 pub __ss_pad1: [CHAR; 6],
537 pub __ss_pad2: [CHAR; 112],
541 pub struct ADDRINFOA {
543 pub ai_family: c_int,
544 pub ai_socktype: c_int,
545 pub ai_protocol: c_int,
546 pub ai_addrlen: size_t,
547 pub ai_canonname: *mut c_char,
548 pub ai_addr: *mut SOCKADDR,
549 pub ai_next: *mut ADDRINFOA,
553 #[derive(Copy, Clone)]
554 pub struct sockaddr_in {
555 pub sin_family: ADDRESS_FAMILY,
556 pub sin_port: USHORT,
557 pub sin_addr: in_addr,
558 pub sin_zero: [CHAR; 8],
562 #[derive(Copy, Clone)]
563 pub struct sockaddr_in6 {
564 pub sin6_family: ADDRESS_FAMILY,
565 pub sin6_port: USHORT,
566 pub sin6_flowinfo: c_ulong,
567 pub sin6_addr: in6_addr,
568 pub sin6_scope_id: c_ulong,
572 #[derive(Copy, Clone)]
578 #[derive(Copy, Clone)]
579 pub struct in6_addr {
580 pub s6_addr: [u8; 16],
584 #[derive(Copy, Clone)]
585 #[allow(dead_code)] // we only use some variants
586 pub enum EXCEPTION_DISPOSITION {
587 ExceptionContinueExecution,
588 ExceptionContinueSearch,
589 ExceptionNestedException,
590 ExceptionCollidedUnwind,
596 pub fd_count: c_uint,
597 pub fd_array: [SOCKET; FD_SETSIZE],
600 impl Clone for fd_set {
601 fn clone(&self) -> fd_set {
607 #[derive(Copy, Clone)]
613 // Functions forbidden when targeting UWP
615 if #[cfg(not(target_vendor = "uwp"))] {
616 pub const EXCEPTION_CONTINUE_SEARCH: LONG = 0;
617 pub const EXCEPTION_STACK_OVERFLOW: DWORD = 0xc00000fd;
618 pub const EXCEPTION_MAXIMUM_PARAMETERS: usize = 15;
621 pub struct EXCEPTION_RECORD {
622 pub ExceptionCode: DWORD,
623 pub ExceptionFlags: DWORD,
624 pub ExceptionRecord: *mut EXCEPTION_RECORD,
625 pub ExceptionAddress: LPVOID,
626 pub NumberParameters: DWORD,
627 pub ExceptionInformation: [LPVOID; EXCEPTION_MAXIMUM_PARAMETERS]
633 pub struct EXCEPTION_POINTERS {
634 pub ExceptionRecord: *mut EXCEPTION_RECORD,
635 pub ContextRecord: *mut CONTEXT,
638 pub type PVECTORED_EXCEPTION_HANDLER = extern "system"
639 fn(ExceptionInfo: *mut EXCEPTION_POINTERS) -> LONG;
642 #[derive(Copy, Clone)]
643 pub struct CONSOLE_READCONSOLE_CONTROL {
645 pub nInitialChars: ULONG,
646 pub dwCtrlWakeupMask: ULONG,
647 pub dwControlKeyState: ULONG,
650 pub type PCONSOLE_READCONSOLE_CONTROL = *mut CONSOLE_READCONSOLE_CONTROL;
653 pub struct BY_HANDLE_FILE_INFORMATION {
654 pub dwFileAttributes: DWORD,
655 pub ftCreationTime: FILETIME,
656 pub ftLastAccessTime: FILETIME,
657 pub ftLastWriteTime: FILETIME,
658 pub dwVolumeSerialNumber: DWORD,
659 pub nFileSizeHigh: DWORD,
660 pub nFileSizeLow: DWORD,
661 pub nNumberOfLinks: DWORD,
662 pub nFileIndexHigh: DWORD,
663 pub nFileIndexLow: DWORD,
666 pub type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION;
667 pub type LPCVOID = *const c_void;
669 pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001;
671 pub const TOKEN_READ: DWORD = 0x20008;
674 #[link_name = "SystemFunction036"]
675 pub fn RtlGenRandom(RandomBuffer: *mut u8, RandomBufferLength: ULONG) -> BOOLEAN;
677 pub fn ReadConsoleW(hConsoleInput: HANDLE,
679 nNumberOfCharsToRead: DWORD,
680 lpNumberOfCharsRead: LPDWORD,
681 pInputControl: PCONSOLE_READCONSOLE_CONTROL) -> BOOL;
683 pub fn WriteConsoleW(hConsoleOutput: HANDLE,
685 nNumberOfCharsToWrite: DWORD,
686 lpNumberOfCharsWritten: LPDWORD,
687 lpReserved: LPVOID) -> BOOL;
689 pub fn GetConsoleMode(hConsoleHandle: HANDLE,
690 lpMode: LPDWORD) -> BOOL;
691 // Allowed but unused by UWP
692 pub fn OpenProcessToken(ProcessHandle: HANDLE,
693 DesiredAccess: DWORD,
694 TokenHandle: *mut HANDLE) -> BOOL;
695 pub fn GetUserProfileDirectoryW(hToken: HANDLE,
696 lpProfileDir: LPWSTR,
697 lpcchSize: *mut DWORD) -> BOOL;
698 pub fn GetFileInformationByHandle(hFile: HANDLE,
699 lpFileInformation: LPBY_HANDLE_FILE_INFORMATION)
701 pub fn SetHandleInformation(hObject: HANDLE,
703 dwFlags: DWORD) -> BOOL;
704 pub fn AddVectoredExceptionHandler(FirstHandler: ULONG,
705 VectoredHandler: PVECTORED_EXCEPTION_HANDLER)
707 pub fn CreateHardLinkW(lpSymlinkFileName: LPCWSTR,
708 lpTargetFileName: LPCWSTR,
709 lpSecurityAttributes: LPSECURITY_ATTRIBUTES)
715 // UWP specific functions & types
717 if #[cfg(target_vendor = "uwp")] {
718 pub const BCRYPT_USE_SYSTEM_PREFERRED_RNG: DWORD = 0x00000002;
721 pub struct FILE_STANDARD_INFO {
722 pub AllocationSize: LARGE_INTEGER,
723 pub EndOfFile: LARGE_INTEGER,
724 pub NumberOfLinks: DWORD,
725 pub DeletePending: BOOLEAN,
726 pub Directory: BOOLEAN,
730 pub fn GetFileInformationByHandleEx(hFile: HANDLE,
731 fileInfoClass: FILE_INFO_BY_HANDLE_CLASS,
732 lpFileInformation: LPVOID,
733 dwBufferSize: DWORD) -> BOOL;
734 pub fn BCryptGenRandom(hAlgorithm: LPVOID, pBuffer: *mut u8,
735 cbBuffer: ULONG, dwFlags: ULONG) -> LONG;
740 // Shared between Desktop & UWP
742 pub fn WSAStartup(wVersionRequested: WORD, lpWSAData: LPWSADATA) -> c_int;
743 pub fn WSACleanup() -> c_int;
744 pub fn WSAGetLastError() -> c_int;
745 pub fn WSADuplicateSocketW(
748 lpProtocolInfo: LPWSAPROTOCOL_INFO,
753 dwBufferCount: DWORD,
754 lpNumberOfBytesSent: LPDWORD,
756 lpOverlapped: LPWSAOVERLAPPED,
757 lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE,
762 dwBufferCount: DWORD,
763 lpNumberOfBytesRecvd: LPDWORD,
765 lpOverlapped: LPWSAOVERLAPPED,
766 lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE,
768 pub fn GetCurrentProcessId() -> DWORD;
773 lpProtocolInfo: LPWSAPROTOCOL_INFO,
777 pub fn ioctlsocket(s: SOCKET, cmd: c_long, argp: *mut c_ulong) -> c_int;
778 pub fn InitializeCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
779 pub fn EnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
780 pub fn TryEnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION) -> BOOLEAN;
781 pub fn LeaveCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
782 pub fn DeleteCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
784 pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
785 pub fn SetFileAttributesW(lpFileName: LPCWSTR, dwFileAttributes: DWORD) -> BOOL;
786 pub fn SetLastError(dwErrCode: DWORD);
787 pub fn GetCommandLineW() -> *mut LPCWSTR;
788 pub fn GetTempPathW(nBufferLength: DWORD, lpBuffer: LPCWSTR) -> DWORD;
789 pub fn GetCurrentProcess() -> HANDLE;
790 pub fn GetCurrentThread() -> HANDLE;
791 pub fn GetStdHandle(which: DWORD) -> HANDLE;
792 pub fn ExitProcess(uExitCode: c_uint) -> !;
793 pub fn DeviceIoControl(
795 dwIoControlCode: DWORD,
797 nInBufferSize: DWORD,
799 nOutBufferSize: DWORD,
800 lpBytesReturned: LPDWORD,
801 lpOverlapped: LPOVERLAPPED,
804 lpThreadAttributes: LPSECURITY_ATTRIBUTES,
806 lpStartAddress: extern "system" fn(*mut c_void) -> DWORD,
808 dwCreationFlags: DWORD,
811 pub fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) -> DWORD;
812 pub fn SwitchToThread() -> BOOL;
813 pub fn Sleep(dwMilliseconds: DWORD);
814 pub fn GetProcessId(handle: HANDLE) -> DWORD;
816 lpExistingFileName: LPCWSTR,
817 lpNewFileName: LPCWSTR,
818 lpProgressRoutine: LPPROGRESS_ROUTINE,
823 pub fn FormatMessageW(
832 pub fn TlsAlloc() -> DWORD;
833 pub fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID;
834 pub fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL;
835 pub fn GetLastError() -> DWORD;
836 pub fn QueryPerformanceFrequency(lpFrequency: *mut LARGE_INTEGER) -> BOOL;
837 pub fn QueryPerformanceCounter(lpPerformanceCount: *mut LARGE_INTEGER) -> BOOL;
838 pub fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: LPDWORD) -> BOOL;
839 pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) -> BOOL;
840 pub fn CreateProcessW(
841 lpApplicationName: LPCWSTR,
842 lpCommandLine: LPWSTR,
843 lpProcessAttributes: LPSECURITY_ATTRIBUTES,
844 lpThreadAttributes: LPSECURITY_ATTRIBUTES,
845 bInheritHandles: BOOL,
846 dwCreationFlags: DWORD,
847 lpEnvironment: LPVOID,
848 lpCurrentDirectory: LPCWSTR,
849 lpStartupInfo: LPSTARTUPINFO,
850 lpProcessInformation: LPPROCESS_INFORMATION,
852 pub fn GetEnvironmentVariableW(n: LPCWSTR, v: LPWSTR, nsize: DWORD) -> DWORD;
853 pub fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL;
854 pub fn GetEnvironmentStringsW() -> LPWCH;
855 pub fn FreeEnvironmentStringsW(env_ptr: LPWCH) -> BOOL;
856 pub fn GetModuleFileNameW(hModule: HMODULE, lpFilename: LPWSTR, nSize: DWORD) -> DWORD;
857 pub fn CreateDirectoryW(
859 lpSecurityAttributes: LPSECURITY_ATTRIBUTES,
861 pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
862 pub fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: LPWSTR) -> DWORD;
863 pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
864 pub fn WideCharToMultiByte(
867 lpWideCharStr: LPCWSTR,
869 lpMultiByteStr: LPSTR,
871 lpDefaultChar: LPCSTR,
872 lpUsedDefaultChar: LPBOOL,
875 pub fn closesocket(socket: SOCKET) -> c_int;
876 pub fn recv(socket: SOCKET, buf: *mut c_void, len: c_int, flags: c_int) -> c_int;
877 pub fn send(socket: SOCKET, buf: *const c_void, len: c_int, flags: c_int) -> c_int;
891 addr: *const SOCKADDR,
894 pub fn shutdown(socket: SOCKET, how: c_int) -> c_int;
895 pub fn accept(socket: SOCKET, address: *mut SOCKADDR, address_len: *mut c_int) -> SOCKET;
896 pub fn DuplicateHandle(
897 hSourceProcessHandle: HANDLE,
898 hSourceHandle: HANDLE,
899 hTargetProcessHandle: HANDLE,
900 lpTargetHandle: LPHANDLE,
901 dwDesiredAccess: DWORD,
902 bInheritHandle: BOOL,
908 nNumberOfBytesToRead: DWORD,
909 lpNumberOfBytesRead: LPDWORD,
910 lpOverlapped: LPOVERLAPPED,
915 nNumberOfBytesToWrite: DWORD,
916 lpNumberOfBytesWritten: LPDWORD,
917 lpOverlapped: LPOVERLAPPED,
919 pub fn CloseHandle(hObject: HANDLE) -> BOOL;
920 pub fn MoveFileExW(lpExistingFileName: LPCWSTR, lpNewFileName: LPCWSTR, dwFlags: DWORD)
922 pub fn SetFilePointerEx(
924 liDistanceToMove: LARGE_INTEGER,
925 lpNewFilePointer: PLARGE_INTEGER,
928 pub fn FlushFileBuffers(hFile: HANDLE) -> BOOL;
931 dwDesiredAccess: DWORD,
933 lpSecurityAttributes: LPSECURITY_ATTRIBUTES,
934 dwCreationDisposition: DWORD,
935 dwFlagsAndAttributes: DWORD,
936 hTemplateFile: HANDLE,
939 pub fn FindFirstFileW(fileName: LPCWSTR, findFileData: LPWIN32_FIND_DATAW) -> HANDLE;
940 pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW) -> BOOL;
941 pub fn FindClose(findFile: HANDLE) -> BOOL;
953 optval: *const c_void,
956 pub fn getsockname(socket: SOCKET, address: *mut SOCKADDR, address_len: *mut c_int) -> c_int;
957 pub fn getpeername(socket: SOCKET, address: *mut SOCKADDR, address_len: *mut c_int) -> c_int;
958 pub fn bind(socket: SOCKET, address: *const SOCKADDR, address_len: socklen_t) -> c_int;
959 pub fn listen(socket: SOCKET, backlog: c_int) -> c_int;
960 pub fn connect(socket: SOCKET, address: *const SOCKADDR, len: c_int) -> c_int;
963 service: *const c_char,
964 hints: *const ADDRINFOA,
965 res: *mut *mut ADDRINFOA,
967 pub fn freeaddrinfo(res: *mut ADDRINFOA);
969 pub fn GetProcAddress(handle: HMODULE, name: LPCSTR) -> *mut c_void;
970 pub fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE;
972 pub fn GetSystemTimeAsFileTime(lpSystemTimeAsFileTime: LPFILETIME);
975 lpEventAttributes: LPSECURITY_ATTRIBUTES,
980 pub fn WaitForMultipleObjects(
982 lpHandles: *const HANDLE,
984 dwMilliseconds: DWORD,
986 pub fn CreateNamedPipeW(
990 nMaxInstances: DWORD,
991 nOutBufferSize: DWORD,
992 nInBufferSize: DWORD,
993 nDefaultTimeOut: DWORD,
994 lpSecurityAttributes: LPSECURITY_ATTRIBUTES,
996 pub fn CancelIo(handle: HANDLE) -> BOOL;
997 pub fn GetOverlappedResult(
999 lpOverlapped: LPOVERLAPPED,
1000 lpNumberOfBytesTransferred: LPDWORD,
1005 readfds: *mut fd_set,
1006 writefds: *mut fd_set,
1007 exceptfds: *mut fd_set,
1008 timeout: *const timeval,
1011 pub fn GetProcessHeap() -> HANDLE;
1012 pub fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID;
1013 pub fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID, dwBytes: SIZE_T) -> LPVOID;
1014 pub fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL;
1017 // Functions that aren't available on every version of Windows that we support,
1018 // but we still use them and just provide some form of a fallback implementation.
1022 pub fn CreateSymbolicLinkW(_lpSymlinkFileName: LPCWSTR,
1023 _lpTargetFileName: LPCWSTR,
1024 _dwFlags: DWORD) -> BOOLEAN {
1025 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1027 pub fn GetFinalPathNameByHandleW(_hFile: HANDLE,
1028 _lpszFilePath: LPCWSTR,
1029 _cchFilePath: DWORD,
1030 _dwFlags: DWORD) -> DWORD {
1031 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1033 #[cfg(not(target_vendor = "uwp"))]
1034 pub fn SetThreadStackGuarantee(_size: *mut c_ulong) -> BOOL {
1035 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1037 pub fn SetThreadDescription(hThread: HANDLE,
1038 lpThreadDescription: LPCWSTR) -> HRESULT {
1039 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); E_NOTIMPL
1041 pub fn SetFileInformationByHandle(_hFile: HANDLE,
1042 _FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,
1043 _lpFileInformation: LPVOID,
1044 _dwBufferSize: DWORD) -> BOOL {
1045 SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
1047 pub fn SleepConditionVariableSRW(ConditionVariable: PCONDITION_VARIABLE,
1049 dwMilliseconds: DWORD,
1050 Flags: ULONG) -> BOOL {
1051 panic!("condition variables not available")
1053 pub fn WakeConditionVariable(ConditionVariable: PCONDITION_VARIABLE)
1055 panic!("condition variables not available")
1057 pub fn WakeAllConditionVariable(ConditionVariable: PCONDITION_VARIABLE)
1059 panic!("condition variables not available")
1061 pub fn AcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> () {
1062 panic!("rwlocks not available")
1064 pub fn AcquireSRWLockShared(SRWLock: PSRWLOCK) -> () {
1065 panic!("rwlocks not available")
1067 pub fn ReleaseSRWLockExclusive(SRWLock: PSRWLOCK) -> () {
1068 panic!("rwlocks not available")
1070 pub fn ReleaseSRWLockShared(SRWLock: PSRWLOCK) -> () {
1071 panic!("rwlocks not available")
1073 pub fn TryAcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> BOOLEAN {
1074 panic!("rwlocks not available")
1076 pub fn TryAcquireSRWLockShared(SRWLock: PSRWLOCK) -> BOOLEAN {
1077 panic!("rwlocks not available")