Skip to content

Commit 4bd6bc9

Browse files
committed
use dirent64_layout and field projections for writing dirent info
1 parent f7f34f2 commit 4bd6bc9

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/helpers.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
104104
this.layout_of(ty)
105105
}
106106

107+
/// Write a uint of the appropriate size to `dest`.
108+
fn write_uint(&mut self, i: impl Into<u128>, dest: &PlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
109+
self.eval_context_mut().write_scalar(Scalar::from_uint(i, dest.layout.size), dest)
110+
}
111+
112+
/// Write an int of the appropriate size to `dest`.
113+
fn write_int(&mut self, i: impl Into<i128>, dest: &PlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
114+
self.eval_context_mut().write_scalar(Scalar::from_int(i, dest.layout.size), dest)
115+
}
116+
107117
/// Write a 0 of the appropriate size to `dest`.
108118
fn write_null(&mut self, dest: &PlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
109-
self.eval_context_mut().write_scalar(Scalar::from_int(0, dest.layout.size), dest)
119+
self.write_int(0, dest)
110120
}
111121

112122
/// Test if this pointer equals 0.

src/shims/posix/fs.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,12 +1270,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
12701270
let entry =
12711271
this.malloc(size, /*zero_init:*/ false, MiriMemoryKind::Runtime)?;
12721272

1273-
// FIXME: make use of dirent64_layout
1274-
let ino64_t_layout = this.libc_ty_layout("ino64_t")?;
1275-
let off64_t_layout = this.libc_ty_layout("off64_t")?;
1276-
let c_ushort_layout = this.libc_ty_layout("c_ushort")?;
1277-
let c_uchar_layout = this.libc_ty_layout("c_uchar")?;
1278-
12791273
// If the host is a Unix system, fill in the inode number with its real value.
12801274
// If not, use 0 as a fallback value.
12811275
#[cfg(unix)]
@@ -1285,15 +1279,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
12851279

12861280
let file_type = this.file_type_to_d_type(dir_entry.file_type())?;
12871281

1288-
let imms = [
1289-
immty_from_uint_checked(ino, ino64_t_layout)?, // d_ino
1290-
immty_from_uint_checked(0u128, off64_t_layout)?, // d_off
1291-
immty_from_uint_checked(size, c_ushort_layout)?, // d_reclen
1292-
immty_from_int_checked(file_type, c_uchar_layout)?, // d_type
1293-
];
1294-
let entry_layout = this.layout_of(this.tcx.mk_array(this.tcx.types.u8, size))?;
1295-
let entry_place = MPlaceTy::from_aligned_ptr(entry, entry_layout);
1296-
this.write_packed_immediates(&entry_place, &imms)?;
1282+
let entry_place = MPlaceTy::from_aligned_ptr(entry, dirent64_layout);
1283+
this.write_uint(ino, &this.mplace_field(&entry_place, 0)?.into())?; // d_ino
1284+
this.write_uint(0u128, &this.mplace_field(&entry_place, 1)?.into())?; // d_off
1285+
this.write_uint(size, &this.mplace_field(&entry_place, 2)?.into())?; // d_reclen
1286+
this.write_int(file_type, &this.mplace_field(&entry_place, 3)?.into())?; // d_type
12971287

12981288
let name_ptr = entry.offset(Size::from_bytes(d_name_offset), this)?;
12991289
this.memory.write_bytes(name_ptr, name_bytes.iter().copied())?;

0 commit comments

Comments
 (0)