Skip to content

Commit bcbcbff

Browse files
committed
bootstrap: pass correct struct size to winapi
1 parent 7d97c59 commit bcbcbff

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/bootstrap/src/bin/rustc.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,7 @@ fn format_rusage_data(child: Child) -> Option<String> {
317317

318318
use windows::{
319319
Win32::Foundation::HANDLE,
320-
Win32::System::ProcessStatus::{
321-
K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS, PROCESS_MEMORY_COUNTERS_EX,
322-
},
320+
Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS},
323321
Win32::System::Threading::GetProcessTimes,
324322
Win32::System::Time::FileTimeToSystemTime,
325323
};
@@ -331,6 +329,7 @@ fn format_rusage_data(child: Child) -> Option<String> {
331329
let mut kernel_filetime = Default::default();
332330
let mut kernel_time = Default::default();
333331
let mut memory_counters = PROCESS_MEMORY_COUNTERS::default();
332+
let memory_counters_size = std::mem::size_of_val(&memory_counters);
334333

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

348347
// Unlike on Linux with RUSAGE_CHILDREN, this will only return memory information for the process
349348
// with the given handle and none of that process's children.
350-
unsafe {
351-
K32GetProcessMemoryInfo(
352-
handle,
353-
&mut memory_counters,
354-
std::mem::size_of::<PROCESS_MEMORY_COUNTERS_EX>() as u32,
355-
)
356-
}
357-
.ok()
358-
.ok()?;
349+
unsafe { K32GetProcessMemoryInfo(handle, &mut memory_counters, memory_counters_size as u32) }
350+
.ok()
351+
.ok()?;
359352

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

0 commit comments

Comments
 (0)