Skip to content

bootstrap: pass correct struct size to winapi #127270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions src/bootstrap/src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ fn format_rusage_data(child: Child) -> Option<String> {

use windows::{
Win32::Foundation::HANDLE,
Win32::System::ProcessStatus::{
K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS, PROCESS_MEMORY_COUNTERS_EX,
},
Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS},
Win32::System::Threading::GetProcessTimes,
Win32::System::Time::FileTimeToSystemTime,
};
Expand All @@ -331,6 +329,7 @@ fn format_rusage_data(child: Child) -> Option<String> {
let mut kernel_filetime = Default::default();
let mut kernel_time = Default::default();
let mut memory_counters = PROCESS_MEMORY_COUNTERS::default();
let memory_counters_size = std::mem::size_of_val(&memory_counters);

unsafe {
GetProcessTimes(
Expand All @@ -347,15 +346,9 @@ fn format_rusage_data(child: Child) -> Option<String> {

// 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()?;
unsafe { K32GetProcessMemoryInfo(handle, &mut memory_counters, memory_counters_size as u32) }
.ok()
.ok()?;

// Guide on interpreting these numbers:
// https://docs.microsoft.com/en-us/windows/win32/psapi/process-memory-usage-information
Expand Down
Loading