add deref_pointer_as

This commit is contained in:
DrMeepster 2023-06-02 16:24:41 -07:00
parent 13c20f297f
commit 9d1d651d1d
2 changed files with 19 additions and 3 deletions

View file

@ -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,

View file

@ -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;
@ -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 => {