@@ -34,21 +34,21 @@ mod imp {
3434
3535#[ cfg( windows) ]
3636mod imp {
37- extern crate kernel32;
3837 extern crate winapi;
39- extern crate psapi;
4038
4139 use std:: ffi:: OsString ;
4240 use std:: io;
4341 use std:: mem;
4442 use std:: os:: windows:: prelude:: * ;
43+ use winapi:: shared:: * ;
44+ use winapi:: um:: * ;
4545
4646 pub struct Setup {
4747 job : Handle ,
4848 }
4949
5050 pub struct Handle {
51- inner : winapi :: HANDLE ,
51+ inner : ntdef :: HANDLE ,
5252 }
5353
5454 fn last_err ( ) -> io:: Error {
@@ -65,7 +65,7 @@ mod imp {
6565 // use job objects, so we instead just ignore errors and assume that
6666 // we're otherwise part of someone else's job object in this case.
6767
68- let job = kernel32 :: CreateJobObjectW ( 0 as * mut _ , 0 as * const _ ) ;
68+ let job = jobapi2 :: CreateJobObjectW ( 0 as * mut _ , 0 as * const _ ) ;
6969 if job. is_null ( ) {
7070 return None
7171 }
@@ -75,22 +75,22 @@ mod imp {
7575 // process in the object should be killed. Note that this includes our
7676 // entire process tree by default because we've added ourselves and and
7777 // 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 ;
7979 info = mem:: zeroed ( ) ;
8080 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 ) ;
8686 if r == 0 {
8787 return None
8888 }
8989
9090 // Assign our process to this job object, meaning that our children will
9191 // 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) ;
9494 if r == 0 {
9595 return None
9696 }
@@ -118,13 +118,13 @@ mod imp {
118118 info ! ( "killed some, going for more" ) ;
119119 }
120120
121- let mut info: winapi :: JOBOBJECT_EXTENDED_LIMIT_INFORMATION ;
121+ let mut info: winnt :: JOBOBJECT_EXTENDED_LIMIT_INFORMATION ;
122122 info = mem:: zeroed ( ) ;
123- let r = kernel32 :: SetInformationJobObject (
123+ let r = jobapi2 :: SetInformationJobObject (
124124 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 ) ;
128128 if r == 0 {
129129 info ! ( "failed to configure job object to defaults: {}" ,
130130 last_err( ) ) ;
@@ -137,16 +137,16 @@ mod imp {
137137 unsafe fn kill_remaining ( & mut self ) -> bool {
138138 #[ repr( C ) ]
139139 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 ] ,
142142 }
143143
144144 let mut jobs: Jobs = mem:: zeroed ( ) ;
145- let r = kernel32 :: QueryInformationJobObject (
145+ let r = jobapi2 :: QueryInformationJobObject (
146146 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 ,
150150 0 as * mut _ ) ;
151151 if r == 0 {
152152 info ! ( "failed to query job object: {}" , last_err( ) ) ;
@@ -159,17 +159,17 @@ mod imp {
159159
160160 let list = list. iter ( ) . filter ( |& & id| {
161161 // let's not kill ourselves
162- id as winapi :: DWORD != kernel32 :: GetCurrentProcessId ( )
162+ id as minwindef :: DWORD != processthreadsapi :: GetCurrentProcessId ( )
163163 } ) . filter_map ( |& id| {
164164 // Open the process with the necessary rights, and if this
165165 // fails then we probably raced with the process exiting so we
166166 // 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 ) ;
173173 if p. is_null ( ) {
174174 None
175175 } else {
@@ -180,12 +180,12 @@ mod imp {
180180 // If it's not then we likely raced with something else
181181 // recycling this PID, so we just skip this step.
182182 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) ;
184184 if r == 0 {
185185 info ! ( "failed to test is process in job: {}" , last_err( ) ) ;
186186 return false
187187 }
188- res == winapi :: TRUE
188+ res == minwindef :: TRUE
189189 } ) ;
190190
191191
@@ -195,7 +195,7 @@ mod imp {
195195 let mut buf = [ 0 ; 1024 ] ;
196196 let r = psapi:: GetProcessImageFileNameW ( p. inner ,
197197 buf. as_mut_ptr ( ) ,
198- buf. len ( ) as winapi :: DWORD ) ;
198+ buf. len ( ) as minwindef :: DWORD ) ;
199199 if r == 0 {
200200 info ! ( "failed to get image name: {}" , last_err( ) ) ;
201201 continue
@@ -224,14 +224,14 @@ mod imp {
224224 // Ok, this isn't mspdbsrv, let's kill the process. After we
225225 // kill it we wait on it to ensure that the next time around in
226226 // 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 ) ;
228228 if r == 0 {
229229 info ! ( "\t failed to kill subprocess: {}" , last_err( ) ) ;
230230 info ! ( "\t assuming subprocess is dead..." ) ;
231231 } else {
232232 info ! ( "\t terminated subprocess" ) ;
233233 }
234- let r = kernel32 :: WaitForSingleObject ( p. inner , winapi :: INFINITE ) ;
234+ let r = synchapi :: WaitForSingleObject ( p. inner , winbase :: INFINITE ) ;
235235 if r != 0 {
236236 info ! ( "failed to wait for process to die: {}" , last_err( ) ) ;
237237 return false
@@ -245,7 +245,7 @@ mod imp {
245245
246246 impl Drop for Handle {
247247 fn drop ( & mut self ) {
248- unsafe { kernel32 :: CloseHandle ( self . inner ) ; }
248+ unsafe { handleapi :: CloseHandle ( self . inner ) ; }
249249 }
250250 }
251251}
0 commit comments