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 // List of Windows system error codes with descriptions:
165 // https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes#system-error-codes
166 pub const ERROR_FILE_NOT_FOUND
: DWORD
= 2;
167 pub const ERROR_PATH_NOT_FOUND
: DWORD
= 3;
168 pub const ERROR_ACCESS_DENIED
: DWORD
= 5;
169 pub const ERROR_INVALID_HANDLE
: DWORD
= 6;
170 pub const ERROR_NO_MORE_FILES
: DWORD
= 18;
171 pub const ERROR_HANDLE_EOF
: DWORD
= 38;
172 pub const ERROR_FILE_EXISTS
: DWORD
= 80;
173 pub const ERROR_INVALID_PARAMETER
: DWORD
= 87;
174 pub const ERROR_BROKEN_PIPE
: DWORD
= 109;
175 pub const ERROR_CALL_NOT_IMPLEMENTED
: DWORD
= 120;
176 pub const ERROR_SEM_TIMEOUT
: DWORD
= 121;
177 pub const ERROR_INSUFFICIENT_BUFFER
: DWORD
= 122;
178 pub const ERROR_ALREADY_EXISTS
: DWORD
= 183;
179 pub const ERROR_ENVVAR_NOT_FOUND
: DWORD
= 203;
180 pub const ERROR_NO_DATA
: DWORD
= 232;
181 pub const ERROR_DRIVER_CANCEL_TIMEOUT
: DWORD
= 594;
182 pub const ERROR_OPERATION_ABORTED
: DWORD
= 995;
183 pub const ERROR_IO_PENDING
: DWORD
= 997;
184 pub const ERROR_SERVICE_REQUEST_TIMEOUT
: DWORD
= 1053;
185 pub const ERROR_COUNTER_TIMEOUT
: DWORD
= 1121;
186 pub const ERROR_TIMEOUT
: DWORD
= 1460;
187 pub const ERROR_RESOURCE_CALL_TIMED_OUT
: DWORD
= 5910;
188 pub const ERROR_CTX_MODEM_RESPONSE_TIMEOUT
: DWORD
= 7012;
189 pub const ERROR_CTX_CLIENT_QUERY_TIMEOUT
: DWORD
= 7040;
190 pub const FRS_ERR_SYSVOL_POPULATE_TIMEOUT
: DWORD
= 8014;
191 pub const ERROR_DS_TIMELIMIT_EXCEEDED
: DWORD
= 8226;
192 pub const DNS_ERROR_RECORD_TIMED_OUT
: DWORD
= 9705;
193 pub const ERROR_IPSEC_IKE_TIMED_OUT
: DWORD
= 13805;
194 pub const ERROR_RUNLEVEL_SWITCH_TIMEOUT
: DWORD
= 15402;
195 pub const ERROR_RUNLEVEL_SWITCH_AGENT_TIMEOUT
: DWORD
= 15403;
197 pub const E_NOTIMPL
: HRESULT
= 0x80004001u32 as HRESULT
;
199 pub const INVALID_HANDLE_VALUE
: HANDLE
= !0 as HANDLE
;
201 pub const FACILITY_NT_BIT
: DWORD
= 0x1000_0000;
203 pub const FORMAT_MESSAGE_FROM_SYSTEM
: DWORD
= 0x00001000;
204 pub const FORMAT_MESSAGE_FROM_HMODULE
: DWORD
= 0x00000800;
205 pub const FORMAT_MESSAGE_IGNORE_INSERTS
: DWORD
= 0x00000200;
207 pub const TLS_OUT_OF_INDEXES
: DWORD
= 0xFFFFFFFF;
209 pub const DLL_THREAD_DETACH
: DWORD
= 3;
210 pub const DLL_PROCESS_DETACH
: DWORD
= 0;
212 pub const INFINITE
: DWORD
= !0;
214 pub const DUPLICATE_SAME_ACCESS
: DWORD
= 0x00000002;
216 pub const CONDITION_VARIABLE_INIT
: CONDITION_VARIABLE
= CONDITION_VARIABLE { ptr: ptr::null_mut() }
;
217 pub const SRWLOCK_INIT
: SRWLOCK
= SRWLOCK { ptr: ptr::null_mut() }
;
219 pub const DETACHED_PROCESS
: DWORD
= 0x00000008;
220 pub const CREATE_NEW_PROCESS_GROUP
: DWORD
= 0x00000200;
221 pub const CREATE_UNICODE_ENVIRONMENT
: DWORD
= 0x00000400;
222 pub const STARTF_USESTDHANDLES
: DWORD
= 0x00000100;
224 pub const AF_INET
: c_int
= 2;
225 pub const AF_INET6
: c_int
= 23;
226 pub const SD_BOTH
: c_int
= 2;
227 pub const SD_RECEIVE
: c_int
= 0;
228 pub const SD_SEND
: c_int
= 1;
229 pub const SOCK_DGRAM
: c_int
= 2;
230 pub const SOCK_STREAM
: c_int
= 1;
231 pub const SOL_SOCKET
: c_int
= 0xffff;
232 pub const SO_RCVTIMEO
: c_int
= 0x1006;
233 pub const SO_SNDTIMEO
: c_int
= 0x1005;
234 pub const IPPROTO_IP
: c_int
= 0;
235 pub const IPPROTO_TCP
: c_int
= 6;
236 pub const IPPROTO_IPV6
: c_int
= 41;
237 pub const TCP_NODELAY
: c_int
= 0x0001;
238 pub const IP_TTL
: c_int
= 4;
239 pub const IPV6_V6ONLY
: c_int
= 27;
240 pub const SO_ERROR
: c_int
= 0x1007;
241 pub const SO_BROADCAST
: c_int
= 0x0020;
242 pub const IP_MULTICAST_LOOP
: c_int
= 11;
243 pub const IPV6_MULTICAST_LOOP
: c_int
= 11;
244 pub const IP_MULTICAST_TTL
: c_int
= 10;
245 pub const IP_ADD_MEMBERSHIP
: c_int
= 12;
246 pub const IP_DROP_MEMBERSHIP
: c_int
= 13;
247 pub const IPV6_ADD_MEMBERSHIP
: c_int
= 12;
248 pub const IPV6_DROP_MEMBERSHIP
: c_int
= 13;
249 pub const MSG_PEEK
: c_int
= 0x2;
253 pub imr_multiaddr
: in_addr
,
254 pub imr_interface
: in_addr
,
258 pub struct ipv6_mreq
{
259 pub ipv6mr_multiaddr
: in6_addr
,
260 pub ipv6mr_interface
: c_uint
,
263 pub const VOLUME_NAME_DOS
: DWORD
= 0x0;
264 pub const MOVEFILE_REPLACE_EXISTING
: DWORD
= 1;
266 pub const FILE_BEGIN
: DWORD
= 0;
267 pub const FILE_CURRENT
: DWORD
= 1;
268 pub const FILE_END
: DWORD
= 2;
270 pub const WAIT_OBJECT_0
: DWORD
= 0x00000000;
271 pub const WAIT_TIMEOUT
: DWORD
= 258;
272 pub const WAIT_FAILED
: DWORD
= 0xFFFFFFFF;
274 pub const PIPE_ACCESS_INBOUND
: DWORD
= 0x00000001;
275 pub const PIPE_ACCESS_OUTBOUND
: DWORD
= 0x00000002;
276 pub const FILE_FLAG_FIRST_PIPE_INSTANCE
: DWORD
= 0x00080000;
277 pub const FILE_FLAG_OVERLAPPED
: DWORD
= 0x40000000;
278 pub const PIPE_WAIT
: DWORD
= 0x00000000;
279 pub const PIPE_TYPE_BYTE
: DWORD
= 0x00000000;
280 pub const PIPE_REJECT_REMOTE_CLIENTS
: DWORD
= 0x00000008;
281 pub const PIPE_READMODE_BYTE
: DWORD
= 0x00000000;
283 pub const FD_SETSIZE
: usize = 64;
285 pub const STACK_SIZE_PARAM_IS_A_RESERVATION
: DWORD
= 0x00010000;
287 pub const HEAP_ZERO_MEMORY
: DWORD
= 0x00000008;
290 #[cfg(not(target_pointer_width = "64"))]
293 pub wHighVersion
: WORD
,
294 pub szDescription
: [u8; WSADESCRIPTION_LEN
+ 1],
295 pub szSystemStatus
: [u8; WSASYS_STATUS_LEN
+ 1],
296 pub iMaxSockets
: u16,
298 pub lpVendorInfo
: *mut u8,
301 #[cfg(target_pointer_width = "64")]
304 pub wHighVersion
: WORD
,
305 pub iMaxSockets
: u16,
307 pub lpVendorInfo
: *mut u8,
308 pub szDescription
: [u8; WSADESCRIPTION_LEN
+ 1],
309 pub szSystemStatus
: [u8; WSASYS_STATUS_LEN
+ 1],
312 #[derive(Copy, Clone)]
320 pub struct WSAPROTOCOL_INFO
{
321 pub dwServiceFlags1
: DWORD
,
322 pub dwServiceFlags2
: DWORD
,
323 pub dwServiceFlags3
: DWORD
,
324 pub dwServiceFlags4
: DWORD
,
325 pub dwProviderFlags
: DWORD
,
326 pub ProviderId
: GUID
,
327 pub dwCatalogEntryId
: DWORD
,
328 pub ProtocolChain
: WSAPROTOCOLCHAIN
,
330 pub iAddressFamily
: c_int
,
331 pub iMaxSockAddr
: c_int
,
332 pub iMinSockAddr
: c_int
,
333 pub iSocketType
: c_int
,
334 pub iProtocol
: c_int
,
335 pub iProtocolMaxOffset
: c_int
,
336 pub iNetworkByteOrder
: c_int
,
337 pub iSecurityScheme
: c_int
,
338 pub dwMessageSize
: DWORD
,
339 pub dwProviderReserved
: DWORD
,
340 pub szProtocol
: [u16; (WSAPROTOCOL_LEN
as usize) + 1],
344 #[derive(Copy, Clone)]
345 pub struct WIN32_FILE_ATTRIBUTE_DATA
{
346 pub dwFileAttributes
: DWORD
,
347 pub ftCreationTime
: FILETIME
,
348 pub ftLastAccessTime
: FILETIME
,
349 pub ftLastWriteTime
: FILETIME
,
350 pub nFileSizeHigh
: DWORD
,
351 pub nFileSizeLow
: DWORD
,
355 #[allow(dead_code)] // we only use some variants
356 pub enum FILE_INFO_BY_HANDLE_CLASS
{
358 FileStandardInfo
= 1,
361 FileDispositionInfo
= 4,
362 FileAllocationInfo
= 5,
363 FileEndOfFileInfo
= 6,
365 FileCompressionInfo
= 8,
366 FileAttributeTagInfo
= 9,
367 FileIdBothDirectoryInfo
= 10, // 0xA
368 FileIdBothDirectoryRestartInfo
= 11, // 0xB
369 FileIoPriorityHintInfo
= 12, // 0xC
370 FileRemoteProtocolInfo
= 13, // 0xD
371 FileFullDirectoryInfo
= 14, // 0xE
372 FileFullDirectoryRestartInfo
= 15, // 0xF
373 FileStorageInfo
= 16, // 0x10
374 FileAlignmentInfo
= 17, // 0x11
375 FileIdInfo
= 18, // 0x12
376 FileIdExtdDirectoryInfo
= 19, // 0x13
377 FileIdExtdDirectoryRestartInfo
= 20, // 0x14
378 MaximumFileInfoByHandlesClass
,
382 pub struct FILE_BASIC_INFO
{
383 pub CreationTime
: LARGE_INTEGER
,
384 pub LastAccessTime
: LARGE_INTEGER
,
385 pub LastWriteTime
: LARGE_INTEGER
,
386 pub ChangeTime
: LARGE_INTEGER
,
387 pub FileAttributes
: DWORD
,
391 pub struct FILE_END_OF_FILE_INFO
{
392 pub EndOfFile
: LARGE_INTEGER
,
396 pub struct REPARSE_DATA_BUFFER
{
397 pub ReparseTag
: c_uint
,
398 pub ReparseDataLength
: c_ushort
,
399 pub Reserved
: c_ushort
,
404 pub struct SYMBOLIC_LINK_REPARSE_BUFFER
{
405 pub SubstituteNameOffset
: c_ushort
,
406 pub SubstituteNameLength
: c_ushort
,
407 pub PrintNameOffset
: c_ushort
,
408 pub PrintNameLength
: c_ushort
,
410 pub PathBuffer
: WCHAR
,
414 pub struct MOUNT_POINT_REPARSE_BUFFER
{
415 pub SubstituteNameOffset
: c_ushort
,
416 pub SubstituteNameLength
: c_ushort
,
417 pub PrintNameOffset
: c_ushort
,
418 pub PrintNameLength
: c_ushort
,
419 pub PathBuffer
: WCHAR
,
422 pub type LPPROGRESS_ROUTINE
= crate::option
::Option
<
423 unsafe extern "system" fn(
424 TotalFileSize
: LARGE_INTEGER
,
425 TotalBytesTransferred
: LARGE_INTEGER
,
426 StreamSize
: LARGE_INTEGER
,
427 StreamBytesTransferred
: LARGE_INTEGER
,
428 dwStreamNumber
: DWORD
,
429 dwCallbackReason
: DWORD
,
431 hDestinationFile
: HANDLE
,
437 pub struct CONDITION_VARIABLE
{
445 pub struct CRITICAL_SECTION
{
446 CriticalSectionDebug
: LPVOID
,
448 RecursionCount
: LONG
,
449 OwningThread
: HANDLE
,
450 LockSemaphore
: HANDLE
,
451 SpinCount
: ULONG_PTR
,
455 pub struct REPARSE_MOUNTPOINT_DATA_BUFFER
{
456 pub ReparseTag
: DWORD
,
457 pub ReparseDataLength
: DWORD
,
459 pub ReparseTargetLength
: WORD
,
460 pub ReparseTargetMaximumLength
: WORD
,
462 pub ReparseTarget
: WCHAR
,
470 pub Data4
: [BYTE
; 8],
474 pub struct WSAPROTOCOLCHAIN
{
476 pub ChainEntries
: [DWORD
; MAX_PROTOCOL_CHAIN
as usize],
480 pub struct SECURITY_ATTRIBUTES
{
482 pub lpSecurityDescriptor
: LPVOID
,
483 pub bInheritHandle
: BOOL
,
487 pub struct PROCESS_INFORMATION
{
488 pub hProcess
: HANDLE
,
490 pub dwProcessId
: DWORD
,
491 pub dwThreadId
: DWORD
,
495 pub struct STARTUPINFO
{
497 pub lpReserved
: LPWSTR
,
498 pub lpDesktop
: LPWSTR
,
504 pub dwXCountChars
: DWORD
,
505 pub dwYCountCharts
: DWORD
,
506 pub dwFillAttribute
: DWORD
,
508 pub wShowWindow
: WORD
,
509 pub cbReserved2
: WORD
,
510 pub lpReserved2
: LPBYTE
,
511 pub hStdInput
: HANDLE
,
512 pub hStdOutput
: HANDLE
,
513 pub hStdError
: HANDLE
,
517 pub struct SOCKADDR
{
518 pub sa_family
: ADDRESS_FAMILY
,
519 pub sa_data
: [CHAR
; 14],
523 #[derive(Copy, Clone)]
524 pub struct FILETIME
{
525 pub dwLowDateTime
: DWORD
,
526 pub dwHighDateTime
: DWORD
,
530 pub struct OVERLAPPED
{
531 pub Internal
: *mut c_ulong
,
532 pub InternalHigh
: *mut c_ulong
,
534 pub OffsetHigh
: DWORD
,
539 #[allow(dead_code)] // we only use some variants
540 pub enum ADDRESS_MODE
{
548 pub struct SOCKADDR_STORAGE_LH
{
549 pub ss_family
: ADDRESS_FAMILY
,
550 pub __ss_pad1
: [CHAR
; 6],
552 pub __ss_pad2
: [CHAR
; 112],
556 pub struct ADDRINFOA
{
558 pub ai_family
: c_int
,
559 pub ai_socktype
: c_int
,
560 pub ai_protocol
: c_int
,
561 pub ai_addrlen
: size_t
,
562 pub ai_canonname
: *mut c_char
,
563 pub ai_addr
: *mut SOCKADDR
,
564 pub ai_next
: *mut ADDRINFOA
,
568 #[derive(Copy, Clone)]
569 pub struct sockaddr_in
{
570 pub sin_family
: ADDRESS_FAMILY
,
571 pub sin_port
: USHORT
,
572 pub sin_addr
: in_addr
,
573 pub sin_zero
: [CHAR
; 8],
577 #[derive(Copy, Clone)]
578 pub struct sockaddr_in6
{
579 pub sin6_family
: ADDRESS_FAMILY
,
580 pub sin6_port
: USHORT
,
581 pub sin6_flowinfo
: c_ulong
,
582 pub sin6_addr
: in6_addr
,
583 pub sin6_scope_id
: c_ulong
,
587 #[derive(Copy, Clone)]
593 #[derive(Copy, Clone)]
594 pub struct in6_addr
{
595 pub s6_addr
: [u8; 16],
599 #[derive(Copy, Clone)]
600 #[allow(dead_code)] // we only use some variants
601 pub enum EXCEPTION_DISPOSITION
{
602 ExceptionContinueExecution
,
603 ExceptionContinueSearch
,
604 ExceptionNestedException
,
605 ExceptionCollidedUnwind
,
611 pub fd_count
: c_uint
,
612 pub fd_array
: [SOCKET
; FD_SETSIZE
],
615 impl Clone
for fd_set
{
616 fn clone(&self) -> fd_set
{
622 #[derive(Copy, Clone)]
628 // Functions forbidden when targeting UWP
630 if #[cfg(not(target_vendor = "uwp"))] {
631 pub const EXCEPTION_CONTINUE_SEARCH
: LONG
= 0;
632 pub const EXCEPTION_STACK_OVERFLOW
: DWORD
= 0xc00000fd;
633 pub const EXCEPTION_MAXIMUM_PARAMETERS
: usize = 15;
636 pub struct EXCEPTION_RECORD
{
637 pub ExceptionCode
: DWORD
,
638 pub ExceptionFlags
: DWORD
,
639 pub ExceptionRecord
: *mut EXCEPTION_RECORD
,
640 pub ExceptionAddress
: LPVOID
,
641 pub NumberParameters
: DWORD
,
642 pub ExceptionInformation
: [LPVOID
; EXCEPTION_MAXIMUM_PARAMETERS
]
648 pub struct EXCEPTION_POINTERS
{
649 pub ExceptionRecord
: *mut EXCEPTION_RECORD
,
650 pub ContextRecord
: *mut CONTEXT
,
653 pub type PVECTORED_EXCEPTION_HANDLER
= extern "system"
654 fn(ExceptionInfo
: *mut EXCEPTION_POINTERS
) -> LONG
;
657 #[derive(Copy, Clone)]
658 pub struct CONSOLE_READCONSOLE_CONTROL
{
660 pub nInitialChars
: ULONG
,
661 pub dwCtrlWakeupMask
: ULONG
,
662 pub dwControlKeyState
: ULONG
,
665 pub type PCONSOLE_READCONSOLE_CONTROL
= *mut CONSOLE_READCONSOLE_CONTROL
;
668 pub struct BY_HANDLE_FILE_INFORMATION
{
669 pub dwFileAttributes
: DWORD
,
670 pub ftCreationTime
: FILETIME
,
671 pub ftLastAccessTime
: FILETIME
,
672 pub ftLastWriteTime
: FILETIME
,
673 pub dwVolumeSerialNumber
: DWORD
,
674 pub nFileSizeHigh
: DWORD
,
675 pub nFileSizeLow
: DWORD
,
676 pub nNumberOfLinks
: DWORD
,
677 pub nFileIndexHigh
: DWORD
,
678 pub nFileIndexLow
: DWORD
,
681 pub type LPBY_HANDLE_FILE_INFORMATION
= *mut BY_HANDLE_FILE_INFORMATION
;
682 pub type LPCVOID
= *const c_void
;
684 pub const HANDLE_FLAG_INHERIT
: DWORD
= 0x00000001;
686 pub const TOKEN_READ
: DWORD
= 0x20008;
689 #[link_name = "SystemFunction036"]
690 pub fn RtlGenRandom(RandomBuffer
: *mut u8, RandomBufferLength
: ULONG
) -> BOOLEAN
;
692 pub fn ReadConsoleW(hConsoleInput
: HANDLE
,
694 nNumberOfCharsToRead
: DWORD
,
695 lpNumberOfCharsRead
: LPDWORD
,
696 pInputControl
: PCONSOLE_READCONSOLE_CONTROL
) -> BOOL
;
698 pub fn WriteConsoleW(hConsoleOutput
: HANDLE
,
700 nNumberOfCharsToWrite
: DWORD
,
701 lpNumberOfCharsWritten
: LPDWORD
,
702 lpReserved
: LPVOID
) -> BOOL
;
704 pub fn GetConsoleMode(hConsoleHandle
: HANDLE
,
705 lpMode
: LPDWORD
) -> BOOL
;
706 // Allowed but unused by UWP
707 pub fn OpenProcessToken(ProcessHandle
: HANDLE
,
708 DesiredAccess
: DWORD
,
709 TokenHandle
: *mut HANDLE
) -> BOOL
;
710 pub fn GetUserProfileDirectoryW(hToken
: HANDLE
,
711 lpProfileDir
: LPWSTR
,
712 lpcchSize
: *mut DWORD
) -> BOOL
;
713 pub fn GetFileInformationByHandle(hFile
: HANDLE
,
714 lpFileInformation
: LPBY_HANDLE_FILE_INFORMATION
)
716 pub fn SetHandleInformation(hObject
: HANDLE
,
718 dwFlags
: DWORD
) -> BOOL
;
719 pub fn AddVectoredExceptionHandler(FirstHandler
: ULONG
,
720 VectoredHandler
: PVECTORED_EXCEPTION_HANDLER
)
722 pub fn CreateHardLinkW(lpSymlinkFileName
: LPCWSTR
,
723 lpTargetFileName
: LPCWSTR
,
724 lpSecurityAttributes
: LPSECURITY_ATTRIBUTES
)
730 // UWP specific functions & types
732 if #[cfg(target_vendor = "uwp")] {
733 pub const BCRYPT_USE_SYSTEM_PREFERRED_RNG
: DWORD
= 0x00000002;
736 pub struct FILE_STANDARD_INFO
{
737 pub AllocationSize
: LARGE_INTEGER
,
738 pub EndOfFile
: LARGE_INTEGER
,
739 pub NumberOfLinks
: DWORD
,
740 pub DeletePending
: BOOLEAN
,
741 pub Directory
: BOOLEAN
,
745 pub fn GetFileInformationByHandleEx(hFile
: HANDLE
,
746 fileInfoClass
: FILE_INFO_BY_HANDLE_CLASS
,
747 lpFileInformation
: LPVOID
,
748 dwBufferSize
: DWORD
) -> BOOL
;
749 pub fn BCryptGenRandom(hAlgorithm
: LPVOID
, pBuffer
: *mut u8,
750 cbBuffer
: ULONG
, dwFlags
: ULONG
) -> LONG
;
755 // Shared between Desktop & UWP
757 pub fn WSAStartup(wVersionRequested
: WORD
, lpWSAData
: LPWSADATA
) -> c_int
;
758 pub fn WSACleanup() -> c_int
;
759 pub fn WSAGetLastError() -> c_int
;
760 pub fn WSADuplicateSocketW(
763 lpProtocolInfo
: LPWSAPROTOCOL_INFO
,
768 dwBufferCount
: DWORD
,
769 lpNumberOfBytesSent
: LPDWORD
,
771 lpOverlapped
: LPWSAOVERLAPPED
,
772 lpCompletionRoutine
: LPWSAOVERLAPPED_COMPLETION_ROUTINE
,
777 dwBufferCount
: DWORD
,
778 lpNumberOfBytesRecvd
: LPDWORD
,
780 lpOverlapped
: LPWSAOVERLAPPED
,
781 lpCompletionRoutine
: LPWSAOVERLAPPED_COMPLETION_ROUTINE
,
783 pub fn GetCurrentProcessId() -> DWORD
;
788 lpProtocolInfo
: LPWSAPROTOCOL_INFO
,
792 pub fn ioctlsocket(s
: SOCKET
, cmd
: c_long
, argp
: *mut c_ulong
) -> c_int
;
793 pub fn InitializeCriticalSection(CriticalSection
: *mut CRITICAL_SECTION
);
794 pub fn EnterCriticalSection(CriticalSection
: *mut CRITICAL_SECTION
);
795 pub fn TryEnterCriticalSection(CriticalSection
: *mut CRITICAL_SECTION
) -> BOOL
;
796 pub fn LeaveCriticalSection(CriticalSection
: *mut CRITICAL_SECTION
);
797 pub fn DeleteCriticalSection(CriticalSection
: *mut CRITICAL_SECTION
);
799 pub fn RemoveDirectoryW(lpPathName
: LPCWSTR
) -> BOOL
;
800 pub fn SetFileAttributesW(lpFileName
: LPCWSTR
, dwFileAttributes
: DWORD
) -> BOOL
;
801 pub fn SetLastError(dwErrCode
: DWORD
);
802 pub fn GetCommandLineW() -> *mut LPCWSTR
;
803 pub fn GetTempPathW(nBufferLength
: DWORD
, lpBuffer
: LPCWSTR
) -> DWORD
;
804 pub fn GetCurrentProcess() -> HANDLE
;
805 pub fn GetCurrentThread() -> HANDLE
;
806 pub fn GetStdHandle(which
: DWORD
) -> HANDLE
;
807 pub fn ExitProcess(uExitCode
: c_uint
) -> !;
808 pub fn DeviceIoControl(
810 dwIoControlCode
: DWORD
,
812 nInBufferSize
: DWORD
,
814 nOutBufferSize
: DWORD
,
815 lpBytesReturned
: LPDWORD
,
816 lpOverlapped
: LPOVERLAPPED
,
819 lpThreadAttributes
: LPSECURITY_ATTRIBUTES
,
821 lpStartAddress
: extern "system" fn(*mut c_void
) -> DWORD
,
823 dwCreationFlags
: DWORD
,
826 pub fn WaitForSingleObject(hHandle
: HANDLE
, dwMilliseconds
: DWORD
) -> DWORD
;
827 pub fn SwitchToThread() -> BOOL
;
828 pub fn Sleep(dwMilliseconds
: DWORD
);
829 pub fn GetProcessId(handle
: HANDLE
) -> DWORD
;
831 lpExistingFileName
: LPCWSTR
,
832 lpNewFileName
: LPCWSTR
,
833 lpProgressRoutine
: LPPROGRESS_ROUTINE
,
838 pub fn FormatMessageW(
847 pub fn TlsAlloc() -> DWORD
;
848 pub fn TlsGetValue(dwTlsIndex
: DWORD
) -> LPVOID
;
849 pub fn TlsSetValue(dwTlsIndex
: DWORD
, lpTlsvalue
: LPVOID
) -> BOOL
;
850 pub fn GetLastError() -> DWORD
;
851 pub fn QueryPerformanceFrequency(lpFrequency
: *mut LARGE_INTEGER
) -> BOOL
;
852 pub fn QueryPerformanceCounter(lpPerformanceCount
: *mut LARGE_INTEGER
) -> BOOL
;
853 pub fn GetExitCodeProcess(hProcess
: HANDLE
, lpExitCode
: LPDWORD
) -> BOOL
;
854 pub fn TerminateProcess(hProcess
: HANDLE
, uExitCode
: UINT
) -> BOOL
;
855 pub fn CreateProcessW(
856 lpApplicationName
: LPCWSTR
,
857 lpCommandLine
: LPWSTR
,
858 lpProcessAttributes
: LPSECURITY_ATTRIBUTES
,
859 lpThreadAttributes
: LPSECURITY_ATTRIBUTES
,
860 bInheritHandles
: BOOL
,
861 dwCreationFlags
: DWORD
,
862 lpEnvironment
: LPVOID
,
863 lpCurrentDirectory
: LPCWSTR
,
864 lpStartupInfo
: LPSTARTUPINFO
,
865 lpProcessInformation
: LPPROCESS_INFORMATION
,
867 pub fn GetEnvironmentVariableW(n
: LPCWSTR
, v
: LPWSTR
, nsize
: DWORD
) -> DWORD
;
868 pub fn SetEnvironmentVariableW(n
: LPCWSTR
, v
: LPCWSTR
) -> BOOL
;
869 pub fn GetEnvironmentStringsW() -> LPWCH
;
870 pub fn FreeEnvironmentStringsW(env_ptr
: LPWCH
) -> BOOL
;
871 pub fn GetModuleFileNameW(hModule
: HMODULE
, lpFilename
: LPWSTR
, nSize
: DWORD
) -> DWORD
;
872 pub fn CreateDirectoryW(
874 lpSecurityAttributes
: LPSECURITY_ATTRIBUTES
,
876 pub fn DeleteFileW(lpPathName
: LPCWSTR
) -> BOOL
;
877 pub fn GetCurrentDirectoryW(nBufferLength
: DWORD
, lpBuffer
: LPWSTR
) -> DWORD
;
878 pub fn SetCurrentDirectoryW(lpPathName
: LPCWSTR
) -> BOOL
;
879 pub fn WideCharToMultiByte(
882 lpWideCharStr
: LPCWSTR
,
884 lpMultiByteStr
: LPSTR
,
886 lpDefaultChar
: LPCSTR
,
887 lpUsedDefaultChar
: LPBOOL
,
890 pub fn closesocket(socket
: SOCKET
) -> c_int
;
891 pub fn recv(socket
: SOCKET
, buf
: *mut c_void
, len
: c_int
, flags
: c_int
) -> c_int
;
892 pub fn send(socket
: SOCKET
, buf
: *const c_void
, len
: c_int
, flags
: c_int
) -> c_int
;
906 addr
: *const SOCKADDR
,
909 pub fn shutdown(socket
: SOCKET
, how
: c_int
) -> c_int
;
910 pub fn accept(socket
: SOCKET
, address
: *mut SOCKADDR
, address_len
: *mut c_int
) -> SOCKET
;
911 pub fn DuplicateHandle(
912 hSourceProcessHandle
: HANDLE
,
913 hSourceHandle
: HANDLE
,
914 hTargetProcessHandle
: HANDLE
,
915 lpTargetHandle
: LPHANDLE
,
916 dwDesiredAccess
: DWORD
,
917 bInheritHandle
: BOOL
,
923 nNumberOfBytesToRead
: DWORD
,
924 lpNumberOfBytesRead
: LPDWORD
,
925 lpOverlapped
: LPOVERLAPPED
,
930 nNumberOfBytesToWrite
: DWORD
,
931 lpNumberOfBytesWritten
: LPDWORD
,
932 lpOverlapped
: LPOVERLAPPED
,
934 pub fn CloseHandle(hObject
: HANDLE
) -> BOOL
;
935 pub fn MoveFileExW(lpExistingFileName
: LPCWSTR
, lpNewFileName
: LPCWSTR
, dwFlags
: DWORD
)
937 pub fn SetFilePointerEx(
939 liDistanceToMove
: LARGE_INTEGER
,
940 lpNewFilePointer
: PLARGE_INTEGER
,
943 pub fn FlushFileBuffers(hFile
: HANDLE
) -> BOOL
;
946 dwDesiredAccess
: DWORD
,
948 lpSecurityAttributes
: LPSECURITY_ATTRIBUTES
,
949 dwCreationDisposition
: DWORD
,
950 dwFlagsAndAttributes
: DWORD
,
951 hTemplateFile
: HANDLE
,
954 pub fn FindFirstFileW(fileName
: LPCWSTR
, findFileData
: LPWIN32_FIND_DATAW
) -> HANDLE
;
955 pub fn FindNextFileW(findFile
: HANDLE
, findFileData
: LPWIN32_FIND_DATAW
) -> BOOL
;
956 pub fn FindClose(findFile
: HANDLE
) -> BOOL
;
968 optval
: *const c_void
,
971 pub fn getsockname(socket
: SOCKET
, address
: *mut SOCKADDR
, address_len
: *mut c_int
) -> c_int
;
972 pub fn getpeername(socket
: SOCKET
, address
: *mut SOCKADDR
, address_len
: *mut c_int
) -> c_int
;
973 pub fn bind(socket
: SOCKET
, address
: *const SOCKADDR
, address_len
: socklen_t
) -> c_int
;
974 pub fn listen(socket
: SOCKET
, backlog
: c_int
) -> c_int
;
975 pub fn connect(socket
: SOCKET
, address
: *const SOCKADDR
, len
: c_int
) -> c_int
;
978 service
: *const c_char
,
979 hints
: *const ADDRINFOA
,
980 res
: *mut *mut ADDRINFOA
,
982 pub fn freeaddrinfo(res
: *mut ADDRINFOA
);
984 pub fn GetProcAddress(handle
: HMODULE
, name
: LPCSTR
) -> *mut c_void
;
985 pub fn GetModuleHandleW(lpModuleName
: LPCWSTR
) -> HMODULE
;
987 pub fn GetSystemTimeAsFileTime(lpSystemTimeAsFileTime
: LPFILETIME
);
990 lpEventAttributes
: LPSECURITY_ATTRIBUTES
,
995 pub fn WaitForMultipleObjects(
997 lpHandles
: *const HANDLE
,
999 dwMilliseconds
: DWORD
,
1001 pub fn CreateNamedPipeW(
1005 nMaxInstances
: DWORD
,
1006 nOutBufferSize
: DWORD
,
1007 nInBufferSize
: DWORD
,
1008 nDefaultTimeOut
: DWORD
,
1009 lpSecurityAttributes
: LPSECURITY_ATTRIBUTES
,
1011 pub fn CancelIo(handle
: HANDLE
) -> BOOL
;
1012 pub fn GetOverlappedResult(
1014 lpOverlapped
: LPOVERLAPPED
,
1015 lpNumberOfBytesTransferred
: LPDWORD
,
1020 readfds
: *mut fd_set
,
1021 writefds
: *mut fd_set
,
1022 exceptfds
: *mut fd_set
,
1023 timeout
: *const timeval
,
1026 pub fn GetProcessHeap() -> HANDLE
;
1027 pub fn HeapAlloc(hHeap
: HANDLE
, dwFlags
: DWORD
, dwBytes
: SIZE_T
) -> LPVOID
;
1028 pub fn HeapReAlloc(hHeap
: HANDLE
, dwFlags
: DWORD
, lpMem
: LPVOID
, dwBytes
: SIZE_T
) -> LPVOID
;
1029 pub fn HeapFree(hHeap
: HANDLE
, dwFlags
: DWORD
, lpMem
: LPVOID
) -> BOOL
;
1032 // Functions that aren't available on every version of Windows that we support,
1033 // but we still use them and just provide some form of a fallback implementation.
1037 pub fn CreateSymbolicLinkW(_lpSymlinkFileName
: LPCWSTR
,
1038 _lpTargetFileName
: LPCWSTR
,
1039 _dwFlags
: DWORD
) -> BOOLEAN
{
1040 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
as DWORD
); 0
1042 pub fn GetFinalPathNameByHandleW(_hFile
: HANDLE
,
1043 _lpszFilePath
: LPCWSTR
,
1044 _cchFilePath
: DWORD
,
1045 _dwFlags
: DWORD
) -> DWORD
{
1046 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
as DWORD
); 0
1048 #[cfg(not(target_vendor = "uwp"))]
1049 pub fn SetThreadStackGuarantee(_size
: *mut c_ulong
) -> BOOL
{
1050 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
as DWORD
); 0
1052 pub fn SetThreadDescription(hThread
: HANDLE
,
1053 lpThreadDescription
: LPCWSTR
) -> HRESULT
{
1054 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
as DWORD
); E_NOTIMPL
1056 pub fn SetFileInformationByHandle(_hFile
: HANDLE
,
1057 _FileInformationClass
: FILE_INFO_BY_HANDLE_CLASS
,
1058 _lpFileInformation
: LPVOID
,
1059 _dwBufferSize
: DWORD
) -> BOOL
{
1060 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
as DWORD
); 0
1062 pub fn GetSystemTimePreciseAsFileTime(lpSystemTimeAsFileTime
: LPFILETIME
)
1064 GetSystemTimeAsFileTime(lpSystemTimeAsFileTime
)
1066 pub fn SleepConditionVariableSRW(ConditionVariable
: PCONDITION_VARIABLE
,
1068 dwMilliseconds
: DWORD
,
1069 Flags
: ULONG
) -> BOOL
{
1070 panic
!("condition variables not available")
1072 pub fn WakeConditionVariable(ConditionVariable
: PCONDITION_VARIABLE
)
1074 panic
!("condition variables not available")
1076 pub fn WakeAllConditionVariable(ConditionVariable
: PCONDITION_VARIABLE
)
1078 panic
!("condition variables not available")
1080 pub fn AcquireSRWLockExclusive(SRWLock
: PSRWLOCK
) -> () {
1081 panic
!("rwlocks not available")
1083 pub fn AcquireSRWLockShared(SRWLock
: PSRWLOCK
) -> () {
1084 panic
!("rwlocks not available")
1086 pub fn ReleaseSRWLockExclusive(SRWLock
: PSRWLOCK
) -> () {
1087 panic
!("rwlocks not available")
1089 pub fn ReleaseSRWLockShared(SRWLock
: PSRWLOCK
) -> () {
1090 panic
!("rwlocks not available")
1092 pub fn TryAcquireSRWLockExclusive(SRWLock
: PSRWLOCK
) -> BOOLEAN
{
1093 panic
!("rwlocks not available")
1095 pub fn TryAcquireSRWLockShared(SRWLock
: PSRWLOCK
) -> BOOLEAN
{
1096 panic
!("rwlocks not available")