X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fshims%2Fwindows%2Fforeign_items.rs;h=f9cf755c5b4f5752c053327eaa6a1dd2eec37a87;hb=63e98aee0cc005c27431a0eca317fecf6706b072;hp=8fc599dd2d0b1827da73a67ef6be66e3626afc7e;hpb=c4ee368acb065b783f3bc094077b4a5cdd1d7a27;p=rust.git diff --git a/src/shims/windows/foreign_items.rs b/src/shims/windows/foreign_items.rs index 8fc599dd2d0..f9cf755c5b4 100644 --- a/src/shims/windows/foreign_items.rs +++ b/src/shims/windows/foreign_items.rs @@ -111,6 +111,8 @@ fn emulate_foreign_item_by_name( // Querying system information "GetSystemInfo" => { + use crate::rustc_middle::ty::{layout::LayoutOf, TyKind, UintTy}; + let [system_info] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; let system_info = this.deref_operand(system_info)?; @@ -119,21 +121,28 @@ fn emulate_foreign_item_by_name( system_info.ptr, iter::repeat(0u8).take(system_info.layout.size.bytes() as usize), )?; - let dword_size = Size::from_bytes(4); - - // In WinApi SYSTEM_INFO's first field is a 4-byte union, but num_cpus - // 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 selected fields. + let dword_ty = this.tcx.mk_ty(TyKind::Uint(UintTy::U32)); + let dword_layout = this.layout_of(dword_ty)?; // 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. - 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