Skip to content

Commit c6eec52

Browse files
committed
add deref_pointer_as
1 parent f65a699 commit c6eec52

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/helpers.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,20 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
746746
Ok(mplace)
747747
}
748748

749+
fn deref_pointer_as(
750+
&self,
751+
val: &ImmTy<'tcx, Provenance>,
752+
layout: TyAndLayout<'tcx>,
753+
) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> {
754+
let this = self.eval_context_ref();
755+
let mut mplace = this.ref_to_mplace(val)?;
756+
757+
mplace.layout = layout;
758+
mplace.align = layout.align.abi;
759+
760+
Ok(mplace)
761+
}
762+
749763
/// Calculates the MPlaceTy given the offset and layout of an access on an operand
750764
fn deref_operand_and_offset(
751765
&self,

src/shims/unix/linux/sync.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ pub fn futex<'tcx>(
8585
return Ok(());
8686
}
8787

88-
let timeout_op = &args[3];
89-
let timeout_time = if this.ptr_is_null(this.read_pointer(timeout_op)?)? {
88+
let timeout = this.deref_pointer_as(
89+
&this.read_immediate(&args[3])?,
90+
this.libc_ty_layout("timespec"),
91+
)?;
92+
let timeout_time = if this.ptr_is_null(timeout.ptr)? {
9093
None
9194
} else {
9295
let realtime = op & futex_realtime == futex_realtime;
@@ -95,7 +98,6 @@ pub fn futex<'tcx>(
9598
"`futex` syscall with `op=FUTEX_WAIT` and non-null timeout with `FUTEX_CLOCK_REALTIME`",
9699
)?;
97100
}
98-
let timeout = this.deref_operand_as(timeout_op, this.libc_ty_layout("timespec"))?;
99101
let duration = match this.read_timespec(&timeout)? {
100102
Some(duration) => duration,
101103
None => {

0 commit comments

Comments
 (0)