From 515c11935969f6bffc42ab2e4cece862f109bb31 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 25 Dec 2019 11:39:57 -0500 Subject: [PATCH] Add padding on 64-bits only --- src/shims/fs.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/shims/fs.rs b/src/shims/fs.rs index 78ec2169fd68..adc60a52e6d1 100644 --- a/src/shims/fs.rs +++ b/src/shims/fs.rs @@ -295,6 +295,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx "S_IFLNK" }; + // FIXME: use Scalar::to_u16 let mode = this.eval_libc(mode_name)?.to_bits(Size::from_bits(16))? as u16; let size = metadata.len(); @@ -316,6 +317,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let blksize_t_layout = this.libc_ty_layout("blksize_t")?; let uint32_t_layout = this.libc_ty_layout("uint32_t")?; + // We need to add 32 bits of padding after `st_rdev` if we are in a 64-bit platform. To do + // this, we store `st_rdev` as a `c_long` instead of a `dev_t`. + let st_rdev_layout = if this.tcx.sess.target.ptr_width == 64 { + long_layout + } else { + dev_t_layout + }; + let imms = [ immty_from_uint_checked(0u128, dev_t_layout)?, // st_dev immty_from_uint_checked(mode, mode_t_layout)?, // st_mode @@ -323,8 +332,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx immty_from_uint_checked(0u128, ino_t_layout)?, // st_ino immty_from_uint_checked(0u128, uid_t_layout)?, // st_uid immty_from_uint_checked(0u128, gid_t_layout)?, // st_gid - immty_from_uint_checked(0u128, dev_t_layout)?, // st_rdev - immty_from_uint_checked(0u128, dev_t_layout)?, // padding + immty_from_uint_checked(0u128, st_rdev_layout)?, // st_rdev immty_from_uint_checked(access_sec, time_t_layout)?, // st_atime immty_from_uint_checked(access_nsec, long_layout)?, // st_atime_nsec immty_from_uint_checked(modified_sec, time_t_layout)?, // st_mtime