Skip to content

Commit

Permalink
add deref_pointer_as
Browse files Browse the repository at this point in the history
  • Loading branch information
beepster4096 committed Jun 2, 2023
1 parent 13c20f2 commit 9d1d651
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/tools/miri/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,20 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
Ok(mplace)
}

fn deref_pointer_as(
&self,
val: &ImmTy<'tcx, Provenance>,
layout: TyAndLayout<'tcx>,
) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> {
let this = self.eval_context_ref();
let mut mplace = this.ref_to_mplace(val)?;

mplace.layout = layout;
mplace.align = layout.align.abi;

Ok(mplace)
}

/// Calculates the MPlaceTy given the offset and layout of an access on an operand
fn deref_operand_and_offset(
&self,
Expand Down
8 changes: 5 additions & 3 deletions src/tools/miri/src/shims/unix/linux/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ pub fn futex<'tcx>(
return Ok(());
}

let timeout_op = &args[3];
let timeout_time = if this.ptr_is_null(this.read_pointer(timeout_op)?)? {
let timeout = this.deref_pointer_as(
&this.read_immediate(&args[3])?,
this.libc_ty_layout("timespec"),
)?;
let timeout_time = if this.ptr_is_null(timeout.ptr)? {
None
} else {
let realtime = op & futex_realtime == futex_realtime;
Expand All @@ -95,7 +98,6 @@ pub fn futex<'tcx>(
"`futex` syscall with `op=FUTEX_WAIT` and non-null timeout with `FUTEX_CLOCK_REALTIME`",
)?;
}
let timeout = this.deref_operand_as(timeout_op, this.libc_ty_layout("timespec"))?;
let duration = match this.read_timespec(&timeout)? {
Some(duration) => duration,
None => {
Expand Down

0 comments on commit 9d1d651

Please sign in to comment.