1
- use lazy_static:: lazy_static;
2
1
use ntapi:: ntioapi:: { IO_STATUS_BLOCK_u , IO_STATUS_BLOCK } ;
3
2
use ntapi:: ntioapi:: { NtCancelIoFileEx , NtDeviceIoControlFile } ;
4
3
use ntapi:: ntrtl:: RtlNtStatusToDosError ;
5
- use std:: ffi:: OsStr ;
6
4
use std:: fmt;
7
5
use std:: fs:: File ;
8
6
use std:: io;
9
7
use std:: mem:: size_of;
10
- use std:: os:: windows:: ffi:: OsStrExt ;
11
8
use std:: os:: windows:: io:: AsRawHandle ;
12
9
use std:: ptr:: null_mut;
13
10
use winapi:: shared:: ntdef:: {
14
- HANDLE , LARGE_INTEGER , NTSTATUS , OBJECT_ATTRIBUTES , PVOID , ULONG , UNICODE_STRING ,
11
+ HANDLE , LARGE_INTEGER , NTSTATUS , PVOID , ULONG ,
15
12
} ;
16
13
use winapi:: shared:: ntstatus:: { STATUS_NOT_FOUND , STATUS_PENDING , STATUS_SUCCESS } ;
17
14
18
15
const IOCTL_AFD_POLL : ULONG = 0x00012024 ;
19
16
20
- lazy_static ! {
21
- static ref AFD_HELPER_NAME : Vec <u16 > = {
22
- OsStr :: new( "\\ Device\\ Afd\\ Mio" )
23
- . encode_wide( )
24
- . collect:: <Vec <_>>( )
25
- } ;
26
- }
27
-
28
- struct UnicodeString ( UNICODE_STRING ) ;
29
- unsafe impl Send for UnicodeString { }
30
- unsafe impl Sync for UnicodeString { }
31
-
32
- struct ObjectAttributes ( OBJECT_ATTRIBUTES ) ;
33
- unsafe impl Send for ObjectAttributes { }
34
- unsafe impl Sync for ObjectAttributes { }
35
-
36
- lazy_static ! {
37
- static ref AFD_OBJ_NAME : UnicodeString = UnicodeString ( UNICODE_STRING {
38
- // Lengths are calced in bytes
39
- Length : ( AFD_HELPER_NAME . len( ) * 2 ) as u16 ,
40
- MaximumLength : ( AFD_HELPER_NAME . len( ) * 2 ) as u16 ,
41
- Buffer : AFD_HELPER_NAME . as_ptr( ) as * mut _,
42
- } ) ;
43
- static ref AFD_HELPER_ATTRIBUTES : ObjectAttributes = ObjectAttributes ( OBJECT_ATTRIBUTES {
44
- Length : size_of:: <OBJECT_ATTRIBUTES >( ) as ULONG ,
45
- RootDirectory : null_mut( ) as HANDLE ,
46
- ObjectName : & AFD_OBJ_NAME . 0 as * const _ as * mut _,
47
- Attributes : 0 as ULONG ,
48
- SecurityDescriptor : null_mut( ) as PVOID ,
49
- SecurityQualityOfService : null_mut( ) as PVOID ,
50
- } ) ;
51
- }
52
-
53
17
/// Winsock2 AFD driver instance.
54
18
///
55
19
/// All operations are unsafe due to IO_STATUS_BLOCK parameter are being used by Afd driver during STATUS_PENDING before I/O Completion Port returns its result.
@@ -156,11 +120,45 @@ cfg_net! {
156
120
use std:: mem:: zeroed;
157
121
use std:: os:: windows:: io:: { FromRawHandle , RawHandle } ;
158
122
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
123
+ use winapi:: shared:: ntdef:: { OBJECT_ATTRIBUTES , UNICODE_STRING , USHORT , WCHAR } ;
159
124
use winapi:: um:: handleapi:: INVALID_HANDLE_VALUE ;
160
125
use winapi:: um:: winbase:: { SetFileCompletionNotificationModes , FILE_SKIP_SET_EVENT_ON_HANDLE } ;
161
126
use winapi:: um:: winnt:: SYNCHRONIZE ;
162
127
use winapi:: um:: winnt:: { FILE_SHARE_READ , FILE_SHARE_WRITE } ;
163
128
129
+ const AFD_HELPER_ATTRIBUTES : OBJECT_ATTRIBUTES = OBJECT_ATTRIBUTES {
130
+ Length : size_of:: <OBJECT_ATTRIBUTES >( ) as ULONG ,
131
+ RootDirectory : null_mut( ) ,
132
+ ObjectName : & AFD_OBJ_NAME as * const _ as * mut _,
133
+ Attributes : 0 ,
134
+ SecurityDescriptor : null_mut( ) ,
135
+ SecurityQualityOfService : null_mut( ) ,
136
+ } ;
137
+
138
+ const AFD_OBJ_NAME : UNICODE_STRING = UNICODE_STRING {
139
+ Length : ( AFD_HELPER_NAME . len( ) * size_of:: <WCHAR >( ) ) as USHORT ,
140
+ MaximumLength : ( AFD_HELPER_NAME . len( ) * size_of:: <WCHAR >( ) ) as USHORT ,
141
+ Buffer : AFD_HELPER_NAME . as_ptr( ) as * mut _,
142
+ } ;
143
+
144
+ const AFD_HELPER_NAME : & [ WCHAR ] = & [
145
+ '\\' as _,
146
+ 'D' as _,
147
+ 'e' as _,
148
+ 'v' as _,
149
+ 'i' as _,
150
+ 'c' as _,
151
+ 'e' as _,
152
+ '\\' as _,
153
+ 'A' as _,
154
+ 'f' as _,
155
+ 'd' as _,
156
+ '\\' as _,
157
+ 'M' as _,
158
+ 'i' as _,
159
+ 'o' as _
160
+ ] ;
161
+
164
162
static NEXT_TOKEN : AtomicUsize = AtomicUsize :: new( 0 ) ;
165
163
166
164
impl AfdPollInfo {
@@ -182,7 +180,7 @@ cfg_net! {
182
180
let status = NtCreateFile (
183
181
& mut afd_helper_handle as * mut _,
184
182
SYNCHRONIZE ,
185
- & AFD_HELPER_ATTRIBUTES . 0 as * const _ as * mut _,
183
+ & AFD_HELPER_ATTRIBUTES as * const _ as * mut _,
186
184
& mut iosb,
187
185
null_mut( ) ,
188
186
0 as ULONG ,
0 commit comments