Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c4ee368

Browse files
committed
Set page size in GetSystemInfo.
1 parent e932ea5 commit c4ee368

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/shims/windows/foreign_items.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,20 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
119119
system_info.ptr,
120120
iter::repeat(0u8).take(system_info.layout.size.bytes() as usize),
121121
)?;
122-
// Set number of processors.
123122
let dword_size = Size::from_bytes(4);
124-
let num_cpus = this.mplace_field(&system_info, 6)?;
123+
124+
// In WinApi SYSTEM_INFO's first field is a 4-byte union, but num_cpus
125+
// inlines it as two 2-byte fields. In num_cpus case all fields are offset by 1
126+
// compared to WinApi. See https://github.com/rust-lang/miri/issues/2136#issuecomment-1133661262.
127+
let first_field = this.mplace_field(&system_info, 0)?;
128+
let offset = if first_field.layout.size.bytes() == 2 { 1 } else { 0 };
129+
130+
let page_size = this.mplace_field(&system_info, 1 + offset)?;
131+
let num_cpus = this.mplace_field(&system_info, 5 + offset)?;
132+
133+
// Set page size.
134+
this.write_scalar(Scalar::from_int(PAGE_SIZE, dword_size), &page_size.into())?;
135+
// Set number of processors.
125136
this.write_scalar(Scalar::from_int(NUM_CPUS, dword_size), &num_cpus.into())?;
126137
}
127138

0 commit comments

Comments
 (0)