Change GetSystemInfo to explicit offset.
This commit is contained in:
parent
c4ee368acb
commit
63e98aee0c
@ -111,6 +111,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||||||
|
|
||||||
// Querying system information
|
// Querying system information
|
||||||
"GetSystemInfo" => {
|
"GetSystemInfo" => {
|
||||||
|
use crate::rustc_middle::ty::{layout::LayoutOf, TyKind, UintTy};
|
||||||
|
|
||||||
let [system_info] =
|
let [system_info] =
|
||||||
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
|
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
|
||||||
let system_info = this.deref_operand(system_info)?;
|
let system_info = this.deref_operand(system_info)?;
|
||||||
@ -119,21 +121,28 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||||||
system_info.ptr,
|
system_info.ptr,
|
||||||
iter::repeat(0u8).take(system_info.layout.size.bytes() as usize),
|
iter::repeat(0u8).take(system_info.layout.size.bytes() as usize),
|
||||||
)?;
|
)?;
|
||||||
let dword_size = Size::from_bytes(4);
|
// Set selected fields.
|
||||||
|
let dword_ty = this.tcx.mk_ty(TyKind::Uint(UintTy::U32));
|
||||||
// In WinApi SYSTEM_INFO's first field is a 4-byte union, but num_cpus
|
let dword_layout = this.layout_of(dword_ty)?;
|
||||||
// inlines it as two 2-byte fields. In num_cpus case all fields are offset by 1
|
|
||||||
// compared to WinApi. See https://github.com/rust-lang/miri/issues/2136#issuecomment-1133661262.
|
|
||||||
let first_field = this.mplace_field(&system_info, 0)?;
|
|
||||||
let offset = if first_field.layout.size.bytes() == 2 { 1 } else { 0 };
|
|
||||||
|
|
||||||
let page_size = this.mplace_field(&system_info, 1 + offset)?;
|
|
||||||
let num_cpus = this.mplace_field(&system_info, 5 + offset)?;
|
|
||||||
|
|
||||||
// Set page size.
|
// Set page size.
|
||||||
this.write_scalar(Scalar::from_int(PAGE_SIZE, dword_size), &page_size.into())?;
|
let page_size = system_info.offset(
|
||||||
|
Size::from_bytes(4),
|
||||||
|
MemPlaceMeta::None,
|
||||||
|
dword_layout,
|
||||||
|
&this.tcx,
|
||||||
|
)?;
|
||||||
|
this.write_scalar(
|
||||||
|
Scalar::from_int(PAGE_SIZE, dword_layout.size),
|
||||||
|
&page_size.into(),
|
||||||
|
)?;
|
||||||
// Set number of processors.
|
// Set number of processors.
|
||||||
this.write_scalar(Scalar::from_int(NUM_CPUS, dword_size), &num_cpus.into())?;
|
let num_cpus = system_info.offset(
|
||||||
|
Size::from_bytes(32),
|
||||||
|
MemPlaceMeta::None,
|
||||||
|
dword_layout,
|
||||||
|
&this.tcx,
|
||||||
|
)?;
|
||||||
|
this.write_scalar(Scalar::from_int(NUM_CPUS, dword_layout.size), &num_cpus.into())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Thread-local storage
|
// Thread-local storage
|
||||||
|
Loading…
x
Reference in New Issue
Block a user