4
4
#![ cfg_attr( test, allow( dead_code) ) ]
5
5
#![ unstable( issue = "0" , feature = "windows_c" ) ]
6
6
7
+ macro_rules! ifdef {
8
+ ( $( $t: tt) * ) => ( $( $t) * )
9
+ }
10
+
7
11
use crate :: os:: raw:: { c_int, c_uint, c_ulong, c_long, c_longlong, c_ushort, c_char} ;
8
12
use crate :: ptr;
9
13
@@ -34,9 +38,7 @@ pub type ULONG = c_ulong;
34
38
35
39
pub type LPBOOL = * mut BOOL ;
36
40
pub type LPBYTE = * mut BYTE ;
37
- pub type LPBY_HANDLE_FILE_INFORMATION = * mut BY_HANDLE_FILE_INFORMATION ;
38
41
pub type LPCSTR = * const CHAR ;
39
- pub type LPCVOID = * const c_void ;
40
42
pub type LPCWSTR = * const WCHAR ;
41
43
pub type LPDWORD = * mut DWORD ;
42
44
pub type LPHANDLE = * mut HANDLE ;
@@ -121,6 +123,7 @@ impl Clone for WIN32_FIND_DATAW {
121
123
}
122
124
123
125
pub const WSA_FLAG_OVERLAPPED : DWORD = 0x01 ;
126
+ pub const WSA_FLAG_NO_HANDLE_INHERIT : DWORD = 0x80 ;
124
127
125
128
pub const WSADESCRIPTION_LEN : usize = 256 ;
126
129
pub const WSASYS_STATUS_LEN : usize = 128 ;
@@ -130,6 +133,7 @@ pub const INVALID_SOCKET: SOCKET = !0;
130
133
pub const WSAEACCES : c_int = 10013 ;
131
134
pub const WSAEINVAL : c_int = 10022 ;
132
135
pub const WSAEWOULDBLOCK : c_int = 10035 ;
136
+ pub const WSAEPROTOTYPE : c_int = 10041 ;
133
137
pub const WSAEADDRINUSE : c_int = 10048 ;
134
138
pub const WSAEADDRNOTAVAIL : c_int = 10049 ;
135
139
pub const WSAECONNABORTED : c_int = 10053 ;
@@ -141,7 +145,6 @@ pub const WSAECONNREFUSED: c_int = 10061;
141
145
142
146
pub const MAX_PROTOCOL_CHAIN : DWORD = 7 ;
143
147
144
- pub const TOKEN_READ : DWORD = 0x20008 ;
145
148
pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE : usize = 16 * 1024 ;
146
149
pub const FSCTL_GET_REPARSE_POINT : DWORD = 0x900a8 ;
147
150
pub const IO_REPARSE_TAG_SYMLINK : DWORD = 0xa000000c ;
@@ -157,8 +160,6 @@ pub const STD_INPUT_HANDLE: DWORD = -10i32 as DWORD;
157
160
pub const STD_OUTPUT_HANDLE : DWORD = -11i32 as DWORD ;
158
161
pub const STD_ERROR_HANDLE : DWORD = -12i32 as DWORD ;
159
162
160
- pub const HANDLE_FLAG_INHERIT : DWORD = 0x00000001 ;
161
-
162
163
pub const PROGRESS_CONTINUE : DWORD = 0 ;
163
164
164
165
pub const ERROR_FILE_NOT_FOUND : DWORD = 2 ;
@@ -259,10 +260,6 @@ pub const WAIT_OBJECT_0: DWORD = 0x00000000;
259
260
pub const WAIT_TIMEOUT : DWORD = 258 ;
260
261
pub const WAIT_FAILED : DWORD = 0xFFFFFFFF ;
261
262
262
- pub const EXCEPTION_CONTINUE_SEARCH : LONG = 0 ;
263
- pub const EXCEPTION_STACK_OVERFLOW : DWORD = 0xc00000fd ;
264
- pub const EXCEPTION_MAXIMUM_PARAMETERS : usize = 15 ;
265
-
266
263
pub const PIPE_ACCESS_INBOUND : DWORD = 0x00000001 ;
267
264
pub const PIPE_ACCESS_OUTBOUND : DWORD = 0x00000002 ;
268
265
pub const FILE_FLAG_FIRST_PIPE_INSTANCE : DWORD = 0x00080000 ;
@@ -342,20 +339,6 @@ pub struct WIN32_FILE_ATTRIBUTE_DATA {
342
339
pub nFileSizeLow : DWORD ,
343
340
}
344
341
345
- #[ repr( C ) ]
346
- pub struct BY_HANDLE_FILE_INFORMATION {
347
- pub dwFileAttributes : DWORD ,
348
- pub ftCreationTime : FILETIME ,
349
- pub ftLastAccessTime : FILETIME ,
350
- pub ftLastWriteTime : FILETIME ,
351
- pub dwVolumeSerialNumber : DWORD ,
352
- pub nFileSizeHigh : DWORD ,
353
- pub nFileSizeLow : DWORD ,
354
- pub nNumberOfLinks : DWORD ,
355
- pub nFileIndexHigh : DWORD ,
356
- pub nFileIndexLow : DWORD ,
357
- }
358
-
359
342
#[ repr( C ) ]
360
343
#[ allow( dead_code) ] // we only use some variants
361
344
pub enum FILE_INFO_BY_HANDLE_CLASS {
@@ -461,25 +444,6 @@ pub struct REPARSE_MOUNTPOINT_DATA_BUFFER {
461
444
pub ReparseTarget : WCHAR ,
462
445
}
463
446
464
- #[ repr( C ) ]
465
- pub struct EXCEPTION_RECORD {
466
- pub ExceptionCode : DWORD ,
467
- pub ExceptionFlags : DWORD ,
468
- pub ExceptionRecord : * mut EXCEPTION_RECORD ,
469
- pub ExceptionAddress : LPVOID ,
470
- pub NumberParameters : DWORD ,
471
- pub ExceptionInformation : [ LPVOID ; EXCEPTION_MAXIMUM_PARAMETERS ]
472
- }
473
-
474
- #[ repr( C ) ]
475
- pub struct EXCEPTION_POINTERS {
476
- pub ExceptionRecord : * mut EXCEPTION_RECORD ,
477
- pub ContextRecord : * mut CONTEXT ,
478
- }
479
-
480
- pub type PVECTORED_EXCEPTION_HANDLER = extern "system"
481
- fn ( ExceptionInfo : * mut EXCEPTION_POINTERS ) -> LONG ;
482
-
483
447
#[ repr( C ) ]
484
448
pub struct GUID {
485
449
pub Data1 : DWORD ,
@@ -562,8 +526,6 @@ pub enum ADDRESS_MODE {
562
526
AddrModeFlat ,
563
527
}
564
528
565
- pub enum CONTEXT { }
566
-
567
529
#[ repr( C ) ]
568
530
pub struct SOCKADDR_STORAGE_LH {
569
531
pub ss_family : ADDRESS_FAMILY ,
@@ -625,16 +587,6 @@ pub enum EXCEPTION_DISPOSITION {
625
587
ExceptionCollidedUnwind
626
588
}
627
589
628
- #[ repr( C ) ]
629
- #[ derive( Copy , Clone ) ]
630
- pub struct CONSOLE_READCONSOLE_CONTROL {
631
- pub nLength : ULONG ,
632
- pub nInitialChars : ULONG ,
633
- pub dwCtrlWakeupMask : ULONG ,
634
- pub dwControlKeyState : ULONG ,
635
- }
636
- pub type PCONSOLE_READCONSOLE_CONTROL = * mut CONSOLE_READCONSOLE_CONTROL ;
637
-
638
590
#[ repr( C ) ]
639
591
#[ derive( Copy ) ]
640
592
pub struct fd_set {
@@ -655,6 +607,132 @@ pub struct timeval {
655
607
pub tv_usec : c_long ,
656
608
}
657
609
610
+ // Functions forbidden when targeting UWP
611
+ #[ cfg( not( target_vendor = "uwp" ) ) ]
612
+ ifdef ! {
613
+ pub const EXCEPTION_CONTINUE_SEARCH : LONG = 0 ;
614
+ pub const EXCEPTION_STACK_OVERFLOW : DWORD = 0xc00000fd ;
615
+ pub const EXCEPTION_MAXIMUM_PARAMETERS : usize = 15 ;
616
+
617
+ #[ repr( C ) ]
618
+ pub struct EXCEPTION_RECORD {
619
+ pub ExceptionCode : DWORD ,
620
+ pub ExceptionFlags : DWORD ,
621
+ pub ExceptionRecord : * mut EXCEPTION_RECORD ,
622
+ pub ExceptionAddress : LPVOID ,
623
+ pub NumberParameters : DWORD ,
624
+ pub ExceptionInformation : [ LPVOID ; EXCEPTION_MAXIMUM_PARAMETERS ]
625
+ }
626
+
627
+ pub enum CONTEXT { }
628
+
629
+ #[ repr( C ) ]
630
+ pub struct EXCEPTION_POINTERS {
631
+ pub ExceptionRecord : * mut EXCEPTION_RECORD ,
632
+ pub ContextRecord : * mut CONTEXT ,
633
+ }
634
+
635
+ pub type PVECTORED_EXCEPTION_HANDLER = extern "system"
636
+ fn ( ExceptionInfo : * mut EXCEPTION_POINTERS ) -> LONG ;
637
+
638
+ #[ repr( C ) ]
639
+ #[ derive( Copy , Clone ) ]
640
+ pub struct CONSOLE_READCONSOLE_CONTROL {
641
+ pub nLength: ULONG ,
642
+ pub nInitialChars: ULONG ,
643
+ pub dwCtrlWakeupMask: ULONG ,
644
+ pub dwControlKeyState: ULONG ,
645
+ }
646
+
647
+ pub type PCONSOLE_READCONSOLE_CONTROL = * mut CONSOLE_READCONSOLE_CONTROL ;
648
+
649
+ #[ repr( C ) ]
650
+ pub struct BY_HANDLE_FILE_INFORMATION {
651
+ pub dwFileAttributes: DWORD ,
652
+ pub ftCreationTime: FILETIME ,
653
+ pub ftLastAccessTime: FILETIME ,
654
+ pub ftLastWriteTime: FILETIME ,
655
+ pub dwVolumeSerialNumber: DWORD ,
656
+ pub nFileSizeHigh: DWORD ,
657
+ pub nFileSizeLow: DWORD ,
658
+ pub nNumberOfLinks: DWORD ,
659
+ pub nFileIndexHigh: DWORD ,
660
+ pub nFileIndexLow: DWORD ,
661
+ }
662
+
663
+ pub type LPBY_HANDLE_FILE_INFORMATION = * mut BY_HANDLE_FILE_INFORMATION ;
664
+ pub type LPCVOID = * const c_void;
665
+
666
+ pub const HANDLE_FLAG_INHERIT : DWORD = 0x00000001 ;
667
+
668
+ pub const TOKEN_READ : DWORD = 0x20008 ;
669
+
670
+ extern "system" {
671
+ #[ link_name = "SystemFunction036" ]
672
+ pub fn RtlGenRandom ( RandomBuffer : * mut u8 , RandomBufferLength : ULONG ) -> BOOLEAN ;
673
+
674
+ pub fn ReadConsoleW ( hConsoleInput: HANDLE ,
675
+ lpBuffer: LPVOID ,
676
+ nNumberOfCharsToRead: DWORD ,
677
+ lpNumberOfCharsRead: LPDWORD ,
678
+ pInputControl: PCONSOLE_READCONSOLE_CONTROL ) -> BOOL ;
679
+
680
+ pub fn WriteConsoleW ( hConsoleOutput: HANDLE ,
681
+ lpBuffer: LPCVOID ,
682
+ nNumberOfCharsToWrite: DWORD ,
683
+ lpNumberOfCharsWritten: LPDWORD ,
684
+ lpReserved: LPVOID ) -> BOOL ;
685
+
686
+ pub fn GetConsoleMode ( hConsoleHandle: HANDLE ,
687
+ lpMode: LPDWORD ) -> BOOL ;
688
+ // Allowed but unused by UWP
689
+ pub fn OpenProcessToken ( ProcessHandle : HANDLE ,
690
+ DesiredAccess : DWORD ,
691
+ TokenHandle : * mut HANDLE ) -> BOOL ;
692
+ pub fn GetUserProfileDirectoryW ( hToken: HANDLE ,
693
+ lpProfileDir: LPWSTR ,
694
+ lpcchSize: * mut DWORD ) -> BOOL ;
695
+ pub fn GetFileInformationByHandle ( hFile: HANDLE ,
696
+ lpFileInformation: LPBY_HANDLE_FILE_INFORMATION )
697
+ -> BOOL ;
698
+ pub fn SetHandleInformation ( hObject: HANDLE ,
699
+ dwMask: DWORD ,
700
+ dwFlags: DWORD ) -> BOOL ;
701
+ pub fn AddVectoredExceptionHandler ( FirstHandler : ULONG ,
702
+ VectoredHandler : PVECTORED_EXCEPTION_HANDLER )
703
+ -> LPVOID ;
704
+ pub fn CreateHardLinkW ( lpSymlinkFileName: LPCWSTR ,
705
+ lpTargetFileName: LPCWSTR ,
706
+ lpSecurityAttributes: LPSECURITY_ATTRIBUTES )
707
+ -> BOOL ;
708
+ }
709
+ }
710
+
711
+ // UWP specific functions & types
712
+ #[ cfg( target_vendor = "uwp" ) ]
713
+ ifdef ! {
714
+ pub const BCRYPT_USE_SYSTEM_PREFERRED_RNG : DWORD = 0x00000002 ;
715
+
716
+ #[ repr( C ) ]
717
+ pub struct FILE_STANDARD_INFO {
718
+ pub AllocationSize : LARGE_INTEGER ,
719
+ pub EndOfFile : LARGE_INTEGER ,
720
+ pub NumberOfLink : DWORD ,
721
+ pub DeletePending : BOOLEAN ,
722
+ pub Directory : BOOLEAN ,
723
+ }
724
+
725
+ extern "system" {
726
+ pub fn GetFileInformationByHandleEx ( hFile: HANDLE ,
727
+ fileInfoClass: FILE_INFO_BY_HANDLE_CLASS ,
728
+ lpFileInformation: LPVOID ,
729
+ dwBufferSize: DWORD ) -> BOOL ;
730
+ pub fn BCryptGenRandom ( hAlgorithm: LPVOID , pBuffer: * mut u8 ,
731
+ cbBuffer: ULONG , dwFlags: ULONG ) -> LONG ;
732
+ }
733
+ }
734
+
735
+ // Shared between Desktop & UWP
658
736
extern "system" {
659
737
pub fn WSAStartup ( wVersionRequested : WORD ,
660
738
lpWSAData : LPWSADATA ) -> c_int ;
@@ -694,34 +772,13 @@ extern "system" {
694
772
pub fn LeaveCriticalSection ( CriticalSection : * mut CRITICAL_SECTION ) ;
695
773
pub fn DeleteCriticalSection ( CriticalSection : * mut CRITICAL_SECTION ) ;
696
774
697
- pub fn ReadConsoleW ( hConsoleInput : HANDLE ,
698
- lpBuffer : LPVOID ,
699
- nNumberOfCharsToRead : DWORD ,
700
- lpNumberOfCharsRead : LPDWORD ,
701
- pInputControl : PCONSOLE_READCONSOLE_CONTROL ) -> BOOL ;
702
-
703
- pub fn WriteConsoleW ( hConsoleOutput : HANDLE ,
704
- lpBuffer : LPCVOID ,
705
- nNumberOfCharsToWrite : DWORD ,
706
- lpNumberOfCharsWritten : LPDWORD ,
707
- lpReserved : LPVOID ) -> BOOL ;
708
-
709
- pub fn GetConsoleMode ( hConsoleHandle : HANDLE ,
710
- lpMode : LPDWORD ) -> BOOL ;
711
775
pub fn RemoveDirectoryW ( lpPathName : LPCWSTR ) -> BOOL ;
712
776
pub fn SetFileAttributesW ( lpFileName : LPCWSTR ,
713
777
dwFileAttributes : DWORD ) -> BOOL ;
714
- pub fn GetFileInformationByHandle ( hFile : HANDLE ,
715
- lpFileInformation : LPBY_HANDLE_FILE_INFORMATION )
716
- -> BOOL ;
717
-
718
778
pub fn SetLastError ( dwErrCode : DWORD ) ;
719
779
pub fn GetCommandLineW ( ) -> * mut LPCWSTR ;
720
780
pub fn GetTempPathW ( nBufferLength : DWORD ,
721
781
lpBuffer : LPCWSTR ) -> DWORD ;
722
- pub fn OpenProcessToken ( ProcessHandle : HANDLE ,
723
- DesiredAccess : DWORD ,
724
- TokenHandle : * mut HANDLE ) -> BOOL ;
725
782
pub fn GetCurrentProcess ( ) -> HANDLE ;
726
783
pub fn GetCurrentThread ( ) -> HANDLE ;
727
784
pub fn GetStdHandle ( which : DWORD ) -> HANDLE ;
@@ -746,21 +803,12 @@ extern "system" {
746
803
pub fn SwitchToThread ( ) -> BOOL ;
747
804
pub fn Sleep ( dwMilliseconds : DWORD ) ;
748
805
pub fn GetProcessId ( handle : HANDLE ) -> DWORD ;
749
- pub fn GetUserProfileDirectoryW ( hToken : HANDLE ,
750
- lpProfileDir : LPWSTR ,
751
- lpcchSize : * mut DWORD ) -> BOOL ;
752
- pub fn SetHandleInformation ( hObject : HANDLE ,
753
- dwMask : DWORD ,
754
- dwFlags : DWORD ) -> BOOL ;
755
806
pub fn CopyFileExW ( lpExistingFileName : LPCWSTR ,
756
807
lpNewFileName : LPCWSTR ,
757
808
lpProgressRoutine : LPPROGRESS_ROUTINE ,
758
809
lpData : LPVOID ,
759
810
pbCancel : LPBOOL ,
760
811
dwCopyFlags : DWORD ) -> BOOL ;
761
- pub fn AddVectoredExceptionHandler ( FirstHandler : ULONG ,
762
- VectoredHandler : PVECTORED_EXCEPTION_HANDLER )
763
- -> LPVOID ;
764
812
pub fn FormatMessageW ( flags : DWORD ,
765
813
lpSrc : LPVOID ,
766
814
msgId : DWORD ,
@@ -857,10 +905,6 @@ extern "system" {
857
905
lpOverlapped : LPOVERLAPPED )
858
906
-> BOOL ;
859
907
pub fn CloseHandle ( hObject : HANDLE ) -> BOOL ;
860
- pub fn CreateHardLinkW ( lpSymlinkFileName : LPCWSTR ,
861
- lpTargetFileName : LPCWSTR ,
862
- lpSecurityAttributes : LPSECURITY_ATTRIBUTES )
863
- -> BOOL ;
864
908
pub fn MoveFileExW ( lpExistingFileName : LPCWSTR ,
865
909
lpNewFileName : LPCWSTR ,
866
910
dwFlags : DWORD )
@@ -950,8 +994,6 @@ extern "system" {
950
994
exceptfds : * mut fd_set ,
951
995
timeout : * const timeval ) -> c_int ;
952
996
953
- #[ link_name = "SystemFunction036" ]
954
- pub fn RtlGenRandom ( RandomBuffer : * mut u8 , RandomBufferLength : ULONG ) -> BOOLEAN ;
955
997
956
998
pub fn GetProcessHeap ( ) -> HANDLE ;
957
999
pub fn HeapAlloc ( hHeap : HANDLE , dwFlags : DWORD , dwBytes : SIZE_T ) -> LPVOID ;
@@ -975,6 +1017,7 @@ compat_fn! {
975
1017
_dwFlags: DWORD ) -> DWORD {
976
1018
SetLastError ( ERROR_CALL_NOT_IMPLEMENTED as DWORD ) ; 0
977
1019
}
1020
+ #[ cfg( not( target_vendor = "uwp" ) ) ]
978
1021
pub fn SetThreadStackGuarantee ( _size: * mut c_ulong) -> BOOL {
979
1022
SetLastError ( ERROR_CALL_NOT_IMPLEMENTED as DWORD ) ; 0
980
1023
}
0 commit comments