diff options
| author | Andy Russell <arussell123@gmail.com> | 2023-01-15 13:43:15 -0500 |
|---|---|---|
| committer | Andy Russell <arussell123@gmail.com> | 2023-03-20 13:19:35 -0400 |
| commit | bb7c373fdf6c7c3fb8e204dcc178d870644fcc4b (patch) | |
| tree | 32094fdb49a0bb37a86af2e10f3189c9070cf513 /src/bootstrap/bin | |
| parent | 13b7aa4d7faafbed78d195c27f6868f6bd90c2f8 (diff) | |
| download | rust-bb7c373fdf6c7c3fb8e204dcc178d870644fcc4b.tar.gz rust-bb7c373fdf6c7c3fb8e204dcc178d870644fcc4b.zip | |
migrate compiler, bootstrap, and compiletest to windows-rs
Diffstat (limited to 'src/bootstrap/bin')
| -rw-r--r-- | src/bootstrap/bin/rustc.rs | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 9611c866df5..040fec3615b 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -281,41 +281,49 @@ fn format_rusage_data(_child: Child) -> Option<String> { #[cfg(windows)] fn format_rusage_data(child: Child) -> Option<String> { use std::os::windows::io::AsRawHandle; - use winapi::um::{processthreadsapi, psapi, timezoneapi}; - let handle = child.as_raw_handle(); - macro_rules! try_bool { - ($e:expr) => { - if $e != 1 { - return None; - } - }; - } + + use windows::{ + Win32::Foundation::HANDLE, + Win32::System::ProcessStatus::{ + K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS, PROCESS_MEMORY_COUNTERS_EX, + }, + Win32::System::Threading::GetProcessTimes, + Win32::System::Time::FileTimeToSystemTime, + }; + + let handle = HANDLE(child.as_raw_handle() as isize); let mut user_filetime = Default::default(); let mut user_time = Default::default(); let mut kernel_filetime = Default::default(); let mut kernel_time = Default::default(); - let mut memory_counters = psapi::PROCESS_MEMORY_COUNTERS::default(); + let mut memory_counters = PROCESS_MEMORY_COUNTERS::default(); unsafe { - try_bool!(processthreadsapi::GetProcessTimes( + GetProcessTimes( handle, &mut Default::default(), &mut Default::default(), &mut kernel_filetime, &mut user_filetime, - )); - try_bool!(timezoneapi::FileTimeToSystemTime(&user_filetime, &mut user_time)); - try_bool!(timezoneapi::FileTimeToSystemTime(&kernel_filetime, &mut kernel_time)); - - // Unlike on Linux with RUSAGE_CHILDREN, this will only return memory information for the process - // with the given handle and none of that process's children. - try_bool!(psapi::GetProcessMemoryInfo( - handle as _, - &mut memory_counters as *mut _ as _, - std::mem::size_of::<psapi::PROCESS_MEMORY_COUNTERS_EX>() as u32, - )); + ) + } + .ok() + .ok()?; + unsafe { FileTimeToSystemTime(&user_filetime, &mut user_time) }.ok().ok()?; + unsafe { FileTimeToSystemTime(&kernel_filetime, &mut kernel_time) }.ok().ok()?; + + // Unlike on Linux with RUSAGE_CHILDREN, this will only return memory information for the process + // with the given handle and none of that process's children. + unsafe { + K32GetProcessMemoryInfo( + handle, + &mut memory_counters, + std::mem::size_of::<PROCESS_MEMORY_COUNTERS_EX>() as u32, + ) } + .ok() + .ok()?; // Guide on interpreting these numbers: // https://docs.microsoft.com/en-us/windows/win32/psapi/process-memory-usage-information |
