Skip to content

Commit 963982c

Browse files
committed
Auto merge of #1322 - steffengy:master, r=alexcrichton
migrate to winapi 0.3 - [x] Some of those changes should also be applied to cargo, to keep those common files consistent. filed rust-lang/cargo#4877
2 parents 57fc3c0 + fc1aa1f commit 963982c

File tree

17 files changed

+113
-187
lines changed

17 files changed

+113
-187
lines changed

Cargo.lock

Lines changed: 5 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,9 @@ url = "1.1.0"
5757
wait-timeout = "0.1.5"
5858

5959
[target."cfg(windows)".dependencies]
60-
winapi = "0.2.8"
60+
winapi = { version = "0.3", features = ["jobapi", "jobapi2", "processthreadsapi", "psapi", "synchapi", "winuser"] }
6161
winreg = "0.4.0"
62-
user32-sys = "0.2.0"
63-
kernel32-sys = "0.2.1"
6462
gcc = "0.3.50"
65-
psapi-sys = "0.1"
6663

6764
[dev-dependencies]
6865
rustup-mock = { path = "src/rustup-mock", version = "1.1.0" }

src/rustup-cli/job.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ mod imp {
3434

3535
#[cfg(windows)]
3636
mod 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!("\tfailed to kill subprocess: {}", last_err());
230230
info!("\tassuming subprocess is dead...");
231231
} else {
232232
info!("\tterminated 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
}

src/rustup-cli/main.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ extern crate gcc;
4040
extern crate winapi;
4141
#[cfg(windows)]
4242
extern crate winreg;
43-
#[cfg(windows)]
44-
extern crate user32;
45-
#[cfg(windows)]
46-
extern crate kernel32;
4743
extern crate libc;
4844

4945
#[macro_use]
@@ -172,8 +168,7 @@ fn make_environment_compatible() {
172168
#[cfg(windows)]
173169
fn fix_windows_reg_key() {
174170
use winreg::RegKey;
175-
use winreg::enums::RegType;
176-
use winapi::*;
171+
use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE};
177172

178173
let root = RegKey::predef(HKEY_CURRENT_USER);
179174
let env = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE);

0 commit comments

Comments
 (0)