@@ -34,21 +34,21 @@ mod imp {
34
34
35
35
#[ cfg( windows) ]
36
36
mod imp {
37
- extern crate kernel32;
38
37
extern crate winapi;
39
- extern crate psapi;
40
38
41
39
use std:: ffi:: OsString ;
42
40
use std:: io;
43
41
use std:: mem;
44
42
use std:: os:: windows:: prelude:: * ;
43
+ use winapi:: shared:: * ;
44
+ use winapi:: um:: * ;
45
45
46
46
pub struct Setup {
47
47
job : Handle ,
48
48
}
49
49
50
50
pub struct Handle {
51
- inner : winapi :: HANDLE ,
51
+ inner : ntdef :: HANDLE ,
52
52
}
53
53
54
54
fn last_err ( ) -> io:: Error {
@@ -65,7 +65,7 @@ mod imp {
65
65
// use job objects, so we instead just ignore errors and assume that
66
66
// we're otherwise part of someone else's job object in this case.
67
67
68
- let job = kernel32 :: CreateJobObjectW ( 0 as * mut _ , 0 as * const _ ) ;
68
+ let job = jobapi2 :: CreateJobObjectW ( 0 as * mut _ , 0 as * const _ ) ;
69
69
if job. is_null ( ) {
70
70
return None
71
71
}
@@ -75,22 +75,22 @@ mod imp {
75
75
// process in the object should be killed. Note that this includes our
76
76
// entire process tree by default because we've added ourselves and and
77
77
// our children will reside in the job once we spawn a process.
78
- let mut info: winapi :: JOBOBJECT_EXTENDED_LIMIT_INFORMATION ;
78
+ let mut info: winnt :: JOBOBJECT_EXTENDED_LIMIT_INFORMATION ;
79
79
info = mem:: zeroed ( ) ;
80
80
info. BasicLimitInformation . LimitFlags =
81
- winapi :: JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE ;
82
- let r = kernel32 :: SetInformationJobObject ( job. inner ,
83
- winapi :: JobObjectExtendedLimitInformation ,
84
- & mut info as * mut _ as winapi :: LPVOID ,
85
- mem:: size_of_val ( & info) as winapi :: DWORD ) ;
81
+ winnt :: JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE ;
82
+ let r = jobapi2 :: SetInformationJobObject ( job. inner ,
83
+ winnt :: JobObjectExtendedLimitInformation ,
84
+ & mut info as * mut _ as minwindef :: LPVOID ,
85
+ mem:: size_of_val ( & info) as minwindef :: DWORD ) ;
86
86
if r == 0 {
87
87
return None
88
88
}
89
89
90
90
// Assign our process to this job object, meaning that our children will
91
91
// now live or die based on our existence.
92
- let me = kernel32 :: GetCurrentProcess ( ) ;
93
- let r = kernel32 :: AssignProcessToJobObject ( job. inner , me) ;
92
+ let me = processthreadsapi :: GetCurrentProcess ( ) ;
93
+ let r = jobapi2 :: AssignProcessToJobObject ( job. inner , me) ;
94
94
if r == 0 {
95
95
return None
96
96
}
@@ -118,13 +118,13 @@ mod imp {
118
118
info ! ( "killed some, going for more" ) ;
119
119
}
120
120
121
- let mut info: winapi :: JOBOBJECT_EXTENDED_LIMIT_INFORMATION ;
121
+ let mut info: winnt :: JOBOBJECT_EXTENDED_LIMIT_INFORMATION ;
122
122
info = mem:: zeroed ( ) ;
123
- let r = kernel32 :: SetInformationJobObject (
123
+ let r = jobapi2 :: SetInformationJobObject (
124
124
self . job . inner ,
125
- winapi :: JobObjectExtendedLimitInformation ,
126
- & mut info as * mut _ as winapi :: LPVOID ,
127
- mem:: size_of_val ( & info) as winapi :: DWORD ) ;
125
+ winnt :: JobObjectExtendedLimitInformation ,
126
+ & mut info as * mut _ as minwindef :: LPVOID ,
127
+ mem:: size_of_val ( & info) as minwindef :: DWORD ) ;
128
128
if r == 0 {
129
129
info ! ( "failed to configure job object to defaults: {}" ,
130
130
last_err( ) ) ;
@@ -137,16 +137,16 @@ mod imp {
137
137
unsafe fn kill_remaining ( & mut self ) -> bool {
138
138
#[ repr( C ) ]
139
139
struct Jobs {
140
- header : winapi :: JOBOBJECT_BASIC_PROCESS_ID_LIST ,
141
- list : [ winapi :: ULONG_PTR ; 1024 ] ,
140
+ header : winnt :: JOBOBJECT_BASIC_PROCESS_ID_LIST ,
141
+ list : [ basetsd :: ULONG_PTR ; 1024 ] ,
142
142
}
143
143
144
144
let mut jobs: Jobs = mem:: zeroed ( ) ;
145
- let r = kernel32 :: QueryInformationJobObject (
145
+ let r = jobapi2 :: QueryInformationJobObject (
146
146
self . job . inner ,
147
- winapi :: JobObjectBasicProcessIdList ,
148
- & mut jobs as * mut _ as winapi :: LPVOID ,
149
- mem:: size_of_val ( & jobs) as winapi :: DWORD ,
147
+ winnt :: JobObjectBasicProcessIdList ,
148
+ & mut jobs as * mut _ as minwindef :: LPVOID ,
149
+ mem:: size_of_val ( & jobs) as minwindef :: DWORD ,
150
150
0 as * mut _ ) ;
151
151
if r == 0 {
152
152
info ! ( "failed to query job object: {}" , last_err( ) ) ;
@@ -159,17 +159,17 @@ mod imp {
159
159
160
160
let list = list. iter ( ) . filter ( |& & id| {
161
161
// let's not kill ourselves
162
- id as winapi :: DWORD != kernel32 :: GetCurrentProcessId ( )
162
+ id as minwindef :: DWORD != processthreadsapi :: GetCurrentProcessId ( )
163
163
} ) . filter_map ( |& id| {
164
164
// Open the process with the necessary rights, and if this
165
165
// fails then we probably raced with the process exiting so we
166
166
// ignore the problem.
167
- let flags = winapi :: PROCESS_QUERY_INFORMATION |
168
- winapi :: PROCESS_TERMINATE |
169
- winapi :: SYNCHRONIZE ;
170
- let p = kernel32 :: OpenProcess ( flags,
171
- winapi :: FALSE ,
172
- id as winapi :: DWORD ) ;
167
+ let flags = winnt :: PROCESS_QUERY_INFORMATION |
168
+ winnt :: PROCESS_TERMINATE |
169
+ winnt :: SYNCHRONIZE ;
170
+ let p = processthreadsapi :: OpenProcess ( flags,
171
+ minwindef :: FALSE ,
172
+ id as minwindef :: DWORD ) ;
173
173
if p. is_null ( ) {
174
174
None
175
175
} else {
@@ -180,12 +180,12 @@ mod imp {
180
180
// If it's not then we likely raced with something else
181
181
// recycling this PID, so we just skip this step.
182
182
let mut res = 0 ;
183
- let r = kernel32 :: IsProcessInJob ( p. inner , self . job . inner , & mut res) ;
183
+ let r = jobapi :: IsProcessInJob ( p. inner , self . job . inner , & mut res) ;
184
184
if r == 0 {
185
185
info ! ( "failed to test is process in job: {}" , last_err( ) ) ;
186
186
return false
187
187
}
188
- res == winapi :: TRUE
188
+ res == minwindef :: TRUE
189
189
} ) ;
190
190
191
191
@@ -195,7 +195,7 @@ mod imp {
195
195
let mut buf = [ 0 ; 1024 ] ;
196
196
let r = psapi:: GetProcessImageFileNameW ( p. inner ,
197
197
buf. as_mut_ptr ( ) ,
198
- buf. len ( ) as winapi :: DWORD ) ;
198
+ buf. len ( ) as minwindef :: DWORD ) ;
199
199
if r == 0 {
200
200
info ! ( "failed to get image name: {}" , last_err( ) ) ;
201
201
continue
@@ -224,14 +224,14 @@ mod imp {
224
224
// Ok, this isn't mspdbsrv, let's kill the process. After we
225
225
// kill it we wait on it to ensure that the next time around in
226
226
// this function we're not going to see it again.
227
- let r = kernel32 :: TerminateProcess ( p. inner , 1 ) ;
227
+ let r = processthreadsapi :: TerminateProcess ( p. inner , 1 ) ;
228
228
if r == 0 {
229
229
info ! ( "\t failed to kill subprocess: {}" , last_err( ) ) ;
230
230
info ! ( "\t assuming subprocess is dead..." ) ;
231
231
} else {
232
232
info ! ( "\t terminated subprocess" ) ;
233
233
}
234
- let r = kernel32 :: WaitForSingleObject ( p. inner , winapi :: INFINITE ) ;
234
+ let r = synchapi :: WaitForSingleObject ( p. inner , winbase :: INFINITE ) ;
235
235
if r != 0 {
236
236
info ! ( "failed to wait for process to die: {}" , last_err( ) ) ;
237
237
return false
@@ -245,7 +245,7 @@ mod imp {
245
245
246
246
impl Drop for Handle {
247
247
fn drop ( & mut self ) {
248
- unsafe { kernel32 :: CloseHandle ( self . inner ) ; }
248
+ unsafe { handleapi :: CloseHandle ( self . inner ) ; }
249
249
}
250
250
}
251
251
}
0 commit comments