rustup to e7c23ab933ebc1f205c3b59f4ebc85d40f67d404

This commit is contained in:
Tomasz Miąsko 2021-02-20 00:00:00 +00:00
parent 277b59c0b3
commit 0eb341417c
29 changed files with 505 additions and 502 deletions

View File

@ -1 +1 @@
d1462d8558cf4551608457f63d9b999185ebf3bf
e7c23ab933ebc1f205c3b59f4ebc85d40f67d404

View File

@ -446,7 +446,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
/// Atomic variant of read_scalar_at_offset.
fn read_scalar_at_offset_atomic(
&self,
op: OpTy<'tcx, Tag>,
op: &OpTy<'tcx, Tag>,
offset: u64,
layout: TyAndLayout<'tcx>,
atomic: AtomicReadOp,
@ -458,13 +458,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
// Ensure that the following read at an offset is within bounds.
assert!(op_place.layout.size >= offset + layout.size);
let value_place = op_place.offset(offset, MemPlaceMeta::None, layout, this)?;
this.read_scalar_atomic(value_place, atomic)
this.read_scalar_atomic(&value_place, atomic)
}
/// Atomic variant of write_scalar_at_offset.
fn write_scalar_at_offset_atomic(
&mut self,
op: OpTy<'tcx, Tag>,
op: &OpTy<'tcx, Tag>,
offset: u64,
value: impl Into<ScalarMaybeUninit<Tag>>,
layout: TyAndLayout<'tcx>,
@ -477,17 +477,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
// Ensure that the following read at an offset is within bounds.
assert!(op_place.layout.size >= offset + layout.size);
let value_place = op_place.offset(offset, MemPlaceMeta::None, layout, this)?;
this.write_scalar_atomic(value.into(), value_place, atomic)
this.write_scalar_atomic(value.into(), &value_place, atomic)
}
/// Perform an atomic read operation at the memory location.
fn read_scalar_atomic(
&self,
place: MPlaceTy<'tcx, Tag>,
place: &MPlaceTy<'tcx, Tag>,
atomic: AtomicReadOp,
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
let this = self.eval_context_ref();
let scalar = this.allow_data_races_ref(move |this| this.read_scalar(place.into()))?;
let scalar = this.allow_data_races_ref(move |this| this.read_scalar(&place.into()))?;
self.validate_atomic_load(place, atomic)?;
Ok(scalar)
}
@ -496,31 +496,31 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
fn write_scalar_atomic(
&mut self,
val: ScalarMaybeUninit<Tag>,
dest: MPlaceTy<'tcx, Tag>,
dest: &MPlaceTy<'tcx, Tag>,
atomic: AtomicWriteOp,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
this.allow_data_races_mut(move |this| this.write_scalar(val, dest.into()))?;
this.allow_data_races_mut(move |this| this.write_scalar(val, &(*dest).into()))?;
self.validate_atomic_store(dest, atomic)
}
/// Perform a atomic operation on a memory location.
fn atomic_op_immediate(
&mut self,
place: MPlaceTy<'tcx, Tag>,
rhs: ImmTy<'tcx, Tag>,
place: &MPlaceTy<'tcx, Tag>,
rhs: &ImmTy<'tcx, Tag>,
op: mir::BinOp,
neg: bool,
atomic: AtomicRwOp,
) -> InterpResult<'tcx, ImmTy<'tcx, Tag>> {
let this = self.eval_context_mut();
let old = this.allow_data_races_mut(|this| this.read_immediate(place.into()))?;
let old = this.allow_data_races_mut(|this| this.read_immediate(&place.into()))?;
// Atomics wrap around on overflow.
let val = this.binary_op(op, old, rhs)?;
let val = if neg { this.unary_op(mir::UnOp::Not, val)? } else { val };
this.allow_data_races_mut(|this| this.write_immediate(*val, place.into()))?;
let val = this.binary_op(op, &old, rhs)?;
let val = if neg { this.unary_op(mir::UnOp::Not, &val)? } else { val };
this.allow_data_races_mut(|this| this.write_immediate(*val, &(*place).into()))?;
this.validate_atomic_rmw(place, atomic)?;
Ok(old)
@ -530,14 +530,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
/// scalar value, the old value is returned.
fn atomic_exchange_scalar(
&mut self,
place: MPlaceTy<'tcx, Tag>,
place: &MPlaceTy<'tcx, Tag>,
new: ScalarMaybeUninit<Tag>,
atomic: AtomicRwOp,
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
let this = self.eval_context_mut();
let old = this.allow_data_races_mut(|this| this.read_scalar(place.into()))?;
this.allow_data_races_mut(|this| this.write_scalar(new, place.into()))?;
let old = this.allow_data_races_mut(|this| this.read_scalar(&place.into()))?;
this.allow_data_races_mut(|this| this.write_scalar(new, &(*place).into()))?;
this.validate_atomic_rmw(place, atomic)?;
Ok(old)
}
@ -550,8 +550,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
/// identical.
fn atomic_compare_exchange_scalar(
&mut self,
place: MPlaceTy<'tcx, Tag>,
expect_old: ImmTy<'tcx, Tag>,
place: &MPlaceTy<'tcx, Tag>,
expect_old: &ImmTy<'tcx, Tag>,
new: ScalarMaybeUninit<Tag>,
success: AtomicRwOp,
fail: AtomicReadOp,
@ -564,9 +564,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
// to read with the failure ordering and if successful then try again with the success
// read ordering and write in the success case.
// Read as immediate for the sake of `binary_op()`
let old = this.allow_data_races_mut(|this| this.read_immediate(place.into()))?;
let old = this.allow_data_races_mut(|this| this.read_immediate(&(place.into())))?;
// `binary_op` will bail if either of them is not a scalar.
let eq = this.overflowing_binary_op(mir::BinOp::Eq, old, expect_old)?.0;
let eq = this.overflowing_binary_op(mir::BinOp::Eq, &old, expect_old)?.0;
// If the operation would succeed, but is "weak", fail some portion
// of the time, based on `rate`.
let rate = this.memory.extra.cmpxchg_weak_failure_rate;
@ -581,7 +581,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
// if successful, perform a full rw-atomic validation
// otherwise treat this as an atomic load with the fail ordering.
if cmpxchg_success {
this.allow_data_races_mut(|this| this.write_scalar(new, place.into()))?;
this.allow_data_races_mut(|this| this.write_scalar(new, &(*place).into()))?;
this.validate_atomic_rmw(place, success)?;
} else {
this.validate_atomic_load(place, fail)?;
@ -595,7 +595,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
/// associated memory-place and on the current thread.
fn validate_atomic_load(
&self,
place: MPlaceTy<'tcx, Tag>,
place: &MPlaceTy<'tcx, Tag>,
atomic: AtomicReadOp,
) -> InterpResult<'tcx> {
let this = self.eval_context_ref();
@ -617,7 +617,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
/// associated memory-place and on the current thread.
fn validate_atomic_store(
&mut self,
place: MPlaceTy<'tcx, Tag>,
place: &MPlaceTy<'tcx, Tag>,
atomic: AtomicWriteOp,
) -> InterpResult<'tcx> {
let this = self.eval_context_ref();
@ -639,7 +639,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
/// at the associated memory place and on the current thread.
fn validate_atomic_rmw(
&mut self,
place: MPlaceTy<'tcx, Tag>,
place: &MPlaceTy<'tcx, Tag>,
atomic: AtomicRwOp,
) -> InterpResult<'tcx> {
use AtomicRwOp::*;
@ -973,7 +973,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
/// atomic-stores/atomic-rmw?
fn validate_atomic_op<A: Debug + Copy>(
&self,
place: MPlaceTy<'tcx, Tag>,
place: &MPlaceTy<'tcx, Tag>,
atomic: A,
description: &str,
mut op: impl FnMut(

View File

@ -138,8 +138,8 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
ecx.layout_of(tcx.mk_array(tcx.mk_imm_ptr(tcx.types.u8), u64::try_from(argvs.len()).unwrap()))?;
let argvs_place = ecx.allocate(argvs_layout, MiriMemoryKind::Machine.into());
for (idx, arg) in argvs.into_iter().enumerate() {
let place = ecx.mplace_field(argvs_place, idx)?;
ecx.write_scalar(arg, place.into())?;
let place = ecx.mplace_field(&argvs_place, idx)?;
ecx.write_scalar(arg, &place.into())?;
}
ecx.memory.mark_immutable(argvs_place.ptr.assert_ptr().alloc_id)?;
// A pointer to that place is the 3rd argument for main.
@ -148,14 +148,14 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
{
let argc_place =
ecx.allocate(ecx.machine.layouts.isize, MiriMemoryKind::Machine.into());
ecx.write_scalar(argc, argc_place.into())?;
ecx.write_scalar(argc, &argc_place.into())?;
ecx.machine.argc = Some(argc_place.ptr);
let argv_place = ecx.allocate(
ecx.layout_of(tcx.mk_imm_ptr(tcx.types.unit))?,
MiriMemoryKind::Machine.into(),
);
ecx.write_scalar(argv, argv_place.into())?;
ecx.write_scalar(argv, &argv_place.into())?;
ecx.machine.argv = Some(argv_place.ptr);
}
// Store command line as UTF-16 for Windows `GetCommandLineW`.
@ -177,8 +177,8 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
ecx.machine.cmd_line = Some(cmd_place.ptr);
// Store the UTF-16 string. We just allocated so we know the bounds are fine.
for (idx, &c) in cmd_utf16.iter().enumerate() {
let place = ecx.mplace_field(cmd_place, idx)?;
ecx.write_scalar(Scalar::from_u16(c), place.into())?;
let place = ecx.mplace_field(&cmd_place, idx)?;
ecx.write_scalar(Scalar::from_u16(c), &place.into())?;
}
}
argv
@ -190,7 +190,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
ecx.call_function(
start_instance,
&[main_ptr.into(), argc.into(), argv.into()],
Some(ret_place.into()),
Some(&ret_place.into()),
StackPopCleanup::None { cleanup: true },
)?;
@ -239,7 +239,7 @@ pub fn eval_main<'tcx>(tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig) ->
}
ecx.process_diagnostics(info);
}
let return_code = ecx.read_scalar(ret_place.into())?.check_init()?.to_machine_isize(&ecx)?;
let return_code = ecx.read_scalar(&ret_place.into())?.check_init()?.to_machine_isize(&ecx)?;
Ok(return_code)
})();

View File

@ -61,7 +61,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let instance = this.resolve_path(path);
let cid = GlobalId { instance, promoted: None };
let const_val = this.eval_to_allocation(cid)?;
let const_val = this.read_scalar(const_val.into())?;
let const_val = this.read_scalar(&const_val.into())?;
return Ok(const_val);
}
@ -106,7 +106,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
/// Write a 0 of the appropriate size to `dest`.
fn write_null(&mut self, dest: PlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
fn write_null(&mut self, dest: &PlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
self.eval_context_mut().write_scalar(Scalar::from_int(0, dest.layout.size), dest)
}
@ -162,7 +162,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
&mut self,
f: ty::Instance<'tcx>,
args: &[Immediate<Tag>],
dest: Option<PlaceTy<'tcx, Tag>>,
dest: Option<&PlaceTy<'tcx, Tag>>,
stack_pop: StackPopCleanup,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
@ -177,7 +177,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let callee_arg = this.local_place(
callee_args.next().expect("callee has fewer arguments than expected"),
)?;
this.write_immediate(*arg, callee_arg)?;
this.write_immediate(*arg, &callee_arg)?;
}
callee_args.next().expect_none("callee has more arguments than expected");
@ -188,7 +188,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
/// will be true if this is frozen, false if this is in an `UnsafeCell`.
fn visit_freeze_sensitive(
&self,
place: MPlaceTy<'tcx, Tag>,
place: &MPlaceTy<'tcx, Tag>,
size: Size,
mut action: impl FnMut(Pointer<Tag>, Size, bool) -> InterpResult<'tcx>,
) -> InterpResult<'tcx> {
@ -237,7 +237,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
trace!("unsafe_cell_action on {:?}", place.ptr);
// We need a size to go on.
let unsafe_cell_size = this
.size_and_align_of_mplace(place)?
.size_and_align_of_mplace(&place)?
.map(|(size, _)| size)
// for extern types, just cover what we can
.unwrap_or_else(|| place.layout.size);
@ -261,7 +261,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
/// whether we are inside an `UnsafeCell` or not.
struct UnsafeCellVisitor<'ecx, 'mir, 'tcx, F>
where
F: FnMut(MPlaceTy<'tcx, Tag>) -> InterpResult<'tcx>,
F: FnMut(&MPlaceTy<'tcx, Tag>) -> InterpResult<'tcx>,
{
ecx: &'ecx MiriEvalContext<'mir, 'tcx>,
unsafe_cell_action: F,
@ -270,7 +270,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
impl<'ecx, 'mir, 'tcx: 'mir, F> ValueVisitor<'mir, 'tcx, Evaluator<'mir, 'tcx>>
for UnsafeCellVisitor<'ecx, 'mir, 'tcx, F>
where
F: FnMut(MPlaceTy<'tcx, Tag>) -> InterpResult<'tcx>,
F: FnMut(&MPlaceTy<'tcx, Tag>) -> InterpResult<'tcx>,
{
type V = MPlaceTy<'tcx, Tag>;
@ -280,7 +280,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
// Hook to detect `UnsafeCell`.
fn visit_value(&mut self, v: MPlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
fn visit_value(&mut self, v: &MPlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
trace!("UnsafeCellVisitor: {:?} {:?}", *v, v.layout.ty);
let is_unsafe_cell = match v.layout.ty.kind() {
ty::Adt(adt, _) =>
@ -323,7 +323,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Make sure we visit aggregrates in increasing offset order.
fn visit_aggregate(
&mut self,
place: MPlaceTy<'tcx, Tag>,
place: &MPlaceTy<'tcx, Tag>,
fields: impl Iterator<Item = InterpResult<'tcx, MPlaceTy<'tcx, Tag>>>,
) -> InterpResult<'tcx> {
match place.layout.fields {
@ -346,7 +346,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
fn visit_union(&mut self, _v: MPlaceTy<'tcx, Tag>, _fields: NonZeroUsize) -> InterpResult<'tcx> {
fn visit_union(&mut self, _v: &MPlaceTy<'tcx, Tag>, _fields: NonZeroUsize) -> InterpResult<'tcx> {
bug!("we should have already handled unions in `visit_value`")
}
}
@ -356,7 +356,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// different values into a struct.
fn write_packed_immediates(
&mut self,
place: MPlaceTy<'tcx, Tag>,
place: &MPlaceTy<'tcx, Tag>,
imms: &[ImmTy<'tcx, Tag>],
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
@ -366,7 +366,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
for &imm in imms {
this.write_immediate_to_mplace(
*imm,
place.offset(offset, MemPlaceMeta::None, imm.layout, &*this.tcx)?,
&place.offset(offset, MemPlaceMeta::None, imm.layout, &*this.tcx)?,
)?;
offset += imm.layout.size;
}
@ -406,7 +406,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Allocate new place, set initial value to 0.
let errno_layout = this.machine.layouts.u32;
let errno_place = this.allocate(errno_layout, MiriMemoryKind::Machine.into());
this.write_scalar(Scalar::from_u32(0), errno_place.into())?;
this.write_scalar(Scalar::from_u32(0), &errno_place.into())?;
this.active_thread_mut().last_error = Some(errno_place);
Ok(errno_place)
}
@ -416,14 +416,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn set_last_error(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let errno_place = this.last_error_place()?;
this.write_scalar(scalar, errno_place.into())
this.write_scalar(scalar, &errno_place.into())
}
/// Gets the last error variable.
fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar<Tag>> {
let this = self.eval_context_mut();
let errno_place = this.last_error_place()?;
this.read_scalar(errno_place.into())?.check_init()
this.read_scalar(&errno_place.into())?.check_init()
}
/// Sets the last OS error using a `std::io::Error`. This function tries to produce the most
@ -486,7 +486,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn read_scalar_at_offset(
&self,
op: OpTy<'tcx, Tag>,
op: &OpTy<'tcx, Tag>,
offset: u64,
layout: TyAndLayout<'tcx>,
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
@ -496,12 +496,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Ensure that the following read at an offset is within bounds
assert!(op_place.layout.size >= offset + layout.size);
let value_place = op_place.offset(offset, MemPlaceMeta::None, layout, this)?;
this.read_scalar(value_place.into())
this.read_scalar(&value_place.into())
}
fn write_scalar_at_offset(
&mut self,
op: OpTy<'tcx, Tag>,
op: &OpTy<'tcx, Tag>,
offset: u64,
value: impl Into<ScalarMaybeUninit<Tag>>,
layout: TyAndLayout<'tcx>,
@ -512,7 +512,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Ensure that the following read at an offset is within bounds
assert!(op_place.layout.size >= offset + layout.size);
let value_place = op_place.offset(offset, MemPlaceMeta::None, layout, this)?;
this.write_scalar(value, value_place.into())
this.write_scalar(value, &value_place.into())
}
/// Parse a `timespec` struct and return it as a `std::time::Duration`. It returns `None`
@ -520,15 +520,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
/// `EINVAL` in this case.
fn read_timespec(
&mut self,
timespec_ptr_op: OpTy<'tcx, Tag>,
timespec_ptr_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, Option<Duration>> {
let this = self.eval_context_mut();
let tp = this.deref_operand(timespec_ptr_op)?;
let seconds_place = this.mplace_field(tp, 0)?;
let seconds_scalar = this.read_scalar(seconds_place.into())?;
let seconds_place = this.mplace_field(&tp, 0)?;
let seconds_scalar = this.read_scalar(&seconds_place.into())?;
let seconds = seconds_scalar.to_machine_isize(this)?;
let nanoseconds_place = this.mplace_field(tp, 1)?;
let nanoseconds_scalar = this.read_scalar(nanoseconds_place.into())?;
let nanoseconds_place = this.mplace_field(&tp, 1)?;
let nanoseconds_scalar = this.read_scalar(&nanoseconds_place.into())?;
let nanoseconds = nanoseconds_scalar.to_machine_isize(this)?;
Ok(try {

View File

@ -193,7 +193,7 @@ impl MemoryExtra {
// This should be all-zero, pointer-sized.
let layout = this.machine.layouts.usize;
let place = this.allocate(layout, MiriMemoryKind::ExternStatic.into());
this.write_scalar(Scalar::from_machine_usize(0, this), place.into())?;
this.write_scalar(Scalar::from_machine_usize(0, this), &place.into())?;
Self::add_extern_static(this, "__cxa_thread_atexit_impl", place.ptr);
// "environ"
Self::add_extern_static(this, "environ", this.machine.env_vars.environ.unwrap().ptr);
@ -203,7 +203,7 @@ impl MemoryExtra {
// This is some obscure hack that is part of the Windows TLS story. It's a `u8`.
let layout = this.machine.layouts.u8;
let place = this.allocate(layout, MiriMemoryKind::ExternStatic.into());
this.write_scalar(Scalar::from_u8(0), place.into())?;
this.write_scalar(Scalar::from_u8(0), &place.into())?;
Self::add_extern_static(this, "_tls_used", place.ptr);
}
_ => {} // No "extern statics" supported on this target
@ -359,7 +359,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
instance: ty::Instance<'tcx>,
abi: Abi,
args: &[OpTy<'tcx, Tag>],
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> {
ecx.find_mir_or_eval_fn(instance, abi, args, ret, unwind)
@ -371,7 +371,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
fn_val: Dlsym,
abi: Abi,
args: &[OpTy<'tcx, Tag>],
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
_unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx> {
ecx.call_dlsym(fn_val, abi, args, ret)
@ -382,7 +382,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
ecx: &mut rustc_mir::interpret::InterpCx<'mir, 'tcx, Self>,
instance: ty::Instance<'tcx>,
args: &[OpTy<'tcx, Tag>],
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx> {
ecx.call_intrinsic(instance, args, ret, unwind)
@ -406,15 +406,15 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
fn binary_ptr_op(
ecx: &rustc_mir::interpret::InterpCx<'mir, 'tcx, Self>,
bin_op: mir::BinOp,
left: ImmTy<'tcx, Tag>,
right: ImmTy<'tcx, Tag>,
left: &ImmTy<'tcx, Tag>,
right: &ImmTy<'tcx, Tag>,
) -> InterpResult<'tcx, (Scalar<Tag>, bool, ty::Ty<'tcx>)> {
ecx.binary_ptr_op(bin_op, left, right)
}
fn box_alloc(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
dest: PlaceTy<'tcx, Tag>,
dest: &PlaceTy<'tcx, Tag>,
) -> InterpResult<'tcx> {
trace!("box_alloc for {:?}", dest.layout.ty);
let layout = ecx.layout_of(dest.layout.ty.builtin_deref(false).unwrap().ty)?;
@ -542,7 +542,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
fn retag(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
kind: mir::RetagKind,
place: PlaceTy<'tcx, Tag>,
place: &PlaceTy<'tcx, Tag>,
) -> InterpResult<'tcx> {
if ecx.memory.extra.stacked_borrows.is_some() {
ecx.retag(kind, place)

View File

@ -8,8 +8,8 @@ pub trait EvalContextExt<'tcx> {
fn binary_ptr_op(
&self,
bin_op: mir::BinOp,
left: ImmTy<'tcx, Tag>,
right: ImmTy<'tcx, Tag>,
left: &ImmTy<'tcx, Tag>,
right: &ImmTy<'tcx, Tag>,
) -> InterpResult<'tcx, (Scalar<Tag>, bool, Ty<'tcx>)>;
fn ptr_eq(&self, left: Scalar<Tag>, right: Scalar<Tag>) -> InterpResult<'tcx, bool>;
@ -19,8 +19,8 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
fn binary_ptr_op(
&self,
bin_op: mir::BinOp,
left: ImmTy<'tcx, Tag>,
right: ImmTy<'tcx, Tag>,
left: &ImmTy<'tcx, Tag>,
right: &ImmTy<'tcx, Tag>,
) -> InterpResult<'tcx, (Scalar<Tag>, bool, Ty<'tcx>)> {
use rustc_middle::mir::BinOp::*;
@ -30,7 +30,7 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
Eq | Ne => {
// This supports fat pointers.
#[rustfmt::skip]
let eq = match (*left, *right) {
let eq = match (**left, **right) {
(Immediate::Scalar(left), Immediate::Scalar(right)) => {
self.ptr_eq(left.check_init()?, right.check_init()?)?
}

View File

@ -13,11 +13,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn handle_miri_get_backtrace(
&mut self,
args: &[OpTy<'tcx, Tag>],
dest: PlaceTy<'tcx, Tag>
dest: &PlaceTy<'tcx, Tag>
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let tcx = this.tcx;
let &[flags] = check_arg_count(args)?;
let &[ref flags] = check_arg_count(args)?;
let flags = this.read_scalar(flags)?.to_u64()?;
if flags != 0 {
@ -59,8 +59,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Write pointers into array
let alloc = this.allocate(this.layout_of(array_ty).unwrap(), MiriMemoryKind::Rust.into());
for (i, ptr) in ptrs.into_iter().enumerate() {
let place = this.mplace_index(alloc, i as u64)?;
this.write_immediate_to_mplace(ptr.into(), place)?;
let place = this.mplace_index(&alloc, i as u64)?;
this.write_immediate_to_mplace(ptr.into(), &place)?;
}
this.write_immediate(Immediate::new_slice(alloc.ptr.into(), len.try_into().unwrap(), this), dest)?;
@ -70,11 +70,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn handle_miri_resolve_frame(
&mut self,
args: &[OpTy<'tcx, Tag>],
dest: PlaceTy<'tcx, Tag>
dest: &PlaceTy<'tcx, Tag>
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let tcx = this.tcx;
let &[ptr, flags] = check_arg_count(args)?;
let &[ref ptr, ref flags] = check_arg_count(args)?;
let flags = this.read_scalar(flags)?.to_u64()?;
if flags != 0 {
@ -125,15 +125,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
this.write_immediate(name_alloc.to_ref(), this.mplace_field(dest, 0)?.into())?;
this.write_immediate(filename_alloc.to_ref(), this.mplace_field(dest, 1)?.into())?;
this.write_scalar(lineno_alloc, this.mplace_field(dest, 2)?.into())?;
this.write_scalar(colno_alloc, this.mplace_field(dest, 3)?.into())?;
this.write_immediate(name_alloc.to_ref(), &this.mplace_field(&dest, 0)?.into())?;
this.write_immediate(filename_alloc.to_ref(), &this.mplace_field(&dest, 1)?.into())?;
this.write_scalar(lineno_alloc, &this.mplace_field(&dest, 2)?.into())?;
this.write_scalar(colno_alloc, &this.mplace_field(&dest, 3)?.into())?;
// Support a 4-field struct for now - this is deprecated
// and slated for removal.
if num_fields == 5 {
this.write_scalar(fn_ptr, this.mplace_field(dest, 4)?.into())?;
this.write_scalar(fn_ptr, &this.mplace_field(&dest, 4)?.into())?;
}
Ok(())

View File

@ -32,7 +32,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
dlsym: Dlsym,
abi: Abi,
args: &[OpTy<'tcx, Tag>],
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
match dlsym {

View File

@ -69,7 +69,7 @@ impl<'tcx> EnvVars<'tcx> {
}
// Deallocate environ var list.
let environ = ecx.machine.env_vars.environ.unwrap();
let old_vars_ptr = ecx.read_scalar(environ.into())?.check_init()?;
let old_vars_ptr = ecx.read_scalar(&environ.into())?.check_init()?;
ecx.memory.deallocate(ecx.force_ptr(old_vars_ptr)?, None, MiriMemoryKind::Env.into())?;
Ok(())
}
@ -99,7 +99,7 @@ fn alloc_env_var_as_wide_str<'mir, 'tcx>(
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
fn getenv(&mut self, name_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, Scalar<Tag>> {
fn getenv(&mut self, name_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, Scalar<Tag>> {
let this = self.eval_context_mut();
let target_os = &this.tcx.sess.target.os;
assert!(target_os == "linux" || target_os == "macos", "`getenv` is only available for the UNIX target family");
@ -118,9 +118,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
#[allow(non_snake_case)]
fn GetEnvironmentVariableW(
&mut self,
name_op: OpTy<'tcx, Tag>, // LPCWSTR
buf_op: OpTy<'tcx, Tag>, // LPWSTR
size_op: OpTy<'tcx, Tag>, // DWORD
name_op: &OpTy<'tcx, Tag>, // LPCWSTR
buf_op: &OpTy<'tcx, Tag>, // LPWSTR
size_op: &OpTy<'tcx, Tag>, // DWORD
) -> InterpResult<'tcx, u32> { // Returns DWORD (u32 in Windows)
let this = self.eval_context_mut();
this.assert_target_os("windows", "GetEnvironmentVariableW");
@ -169,7 +169,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
#[allow(non_snake_case)]
fn FreeEnvironmentStringsW(&mut self, env_block_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn FreeEnvironmentStringsW(&mut self, env_block_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
this.assert_target_os("windows", "FreeEnvironmentStringsW");
@ -181,8 +181,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn setenv(
&mut self,
name_op: OpTy<'tcx, Tag>,
value_op: OpTy<'tcx, Tag>,
name_op: &OpTy<'tcx, Tag>,
value_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let mut this = self.eval_context_mut();
let target_os = &this.tcx.sess.target.os;
@ -218,8 +218,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
#[allow(non_snake_case)]
fn SetEnvironmentVariableW(
&mut self,
name_op: OpTy<'tcx, Tag>, // LPCWSTR
value_op: OpTy<'tcx, Tag>, // LPCWSTR
name_op: &OpTy<'tcx, Tag>, // LPCWSTR
value_op: &OpTy<'tcx, Tag>, // LPCWSTR
) -> InterpResult<'tcx, i32> {
let mut this = self.eval_context_mut();
this.assert_target_os("windows", "SetEnvironmentVariableW");
@ -256,7 +256,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
fn unsetenv(&mut self, name_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn unsetenv(&mut self, name_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let target_os = &this.tcx.sess.target.os;
assert!(target_os == "linux" || target_os == "macos", "`unsetenv` is only available for the UNIX target family");
@ -286,8 +286,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn getcwd(
&mut self,
buf_op: OpTy<'tcx, Tag>,
size_op: OpTy<'tcx, Tag>,
buf_op: &OpTy<'tcx, Tag>,
size_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, Scalar<Tag>> {
let this = self.eval_context_mut();
let target_os = &this.tcx.sess.target.os;
@ -295,8 +295,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.check_no_isolation("`getcwd`")?;
let buf = this.read_scalar(buf_op)?.check_init()?;
let size = this.read_scalar(size_op)?.to_machine_usize(&*this.tcx)?;
let buf = this.read_scalar(&buf_op)?.check_init()?;
let size = this.read_scalar(&size_op)?.to_machine_usize(&*this.tcx)?;
// If we cannot get the current directory, we return null
match env::current_dir() {
Ok(cwd) => {
@ -314,8 +314,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
#[allow(non_snake_case)]
fn GetCurrentDirectoryW(
&mut self,
size_op: OpTy<'tcx, Tag>, // DWORD
buf_op: OpTy<'tcx, Tag>, // LPTSTR
size_op: &OpTy<'tcx, Tag>, // DWORD
buf_op: &OpTy<'tcx, Tag>, // LPTSTR
) -> InterpResult<'tcx, u32> {
let this = self.eval_context_mut();
this.assert_target_os("windows", "GetCurrentDirectoryW");
@ -334,7 +334,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
Ok(0)
}
fn chdir(&mut self, path_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn chdir(&mut self, path_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let target_os = &this.tcx.sess.target.os;
assert!(target_os == "linux" || target_os == "macos", "`getcwd` is only available for the UNIX target family");
@ -355,7 +355,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
#[allow(non_snake_case)]
fn SetCurrentDirectoryW (
&mut self,
path_op: OpTy<'tcx, Tag> // LPCTSTR
path_op: &OpTy<'tcx, Tag> // LPCTSTR
) -> InterpResult<'tcx, i32> { // Returns BOOL (i32 in Windows)
let this = self.eval_context_mut();
this.assert_target_os("windows", "SetCurrentDirectoryW");
@ -379,7 +379,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let this = self.eval_context_mut();
// Deallocate the old environ list, if any.
if let Some(environ) = this.machine.env_vars.environ {
let old_vars_ptr = this.read_scalar(environ.into())?.check_init()?;
let old_vars_ptr = this.read_scalar(&environ.into())?.check_init()?;
this.memory.deallocate(this.force_ptr(old_vars_ptr)?, None, MiriMemoryKind::Env.into())?;
} else {
// No `environ` allocated yet, let's do that.
@ -399,12 +399,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.layout_of(tcx.mk_array(tcx.types.usize, u64::try_from(vars.len()).unwrap()))?;
let vars_place = this.allocate(vars_layout, MiriMemoryKind::Env.into());
for (idx, var) in vars.into_iter().enumerate() {
let place = this.mplace_field(vars_place, idx)?;
this.write_scalar(var, place.into())?;
let place = this.mplace_field(&vars_place, idx)?;
this.write_scalar(var, &place.into())?;
}
this.write_scalar(
vars_place.ptr,
this.machine.env_vars.environ.unwrap().into(),
&this.machine.env_vars.environ.unwrap().into(),
)?;
Ok(())

View File

@ -114,7 +114,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
def_id: DefId,
abi: Abi,
args: &[OpTy<'tcx, Tag>],
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> {
let this = self.eval_context_mut();
@ -147,7 +147,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
| "ExitProcess"
=> {
check_abi(abi, if link_name == "exit" { Abi::C } else { Abi::System })?;
let &[code] = check_arg_count(args)?;
let &[ref code] = check_arg_count(args)?;
// it's really u32 for ExitProcess, but we have to put it into the `Exit` variant anyway
let code = this.read_scalar(code)?.to_i32()?;
throw_machine_stop!(TerminationInfo::Exit(code.into()));
@ -186,7 +186,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Third: functions that return.
if this.emulate_foreign_item_by_name(link_name, abi, args, dest, ret)? {
trace!("{:?}", this.dump_place(*dest));
trace!("{:?}", this.dump_place(**dest));
this.go_to_block(ret);
}
@ -201,7 +201,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
link_name: &str,
abi: Abi,
args: &[OpTy<'tcx, Tag>],
dest: PlaceTy<'tcx, Tag>,
dest: &PlaceTy<'tcx, Tag>,
ret: mir::BasicBlock,
) -> InterpResult<'tcx, bool> {
let this = self.eval_context_mut();
@ -212,7 +212,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Miri-specific extern functions
"miri_static_root" => {
check_abi(abi, Abi::Rust)?;
let &[ptr] = check_arg_count(args)?;
let &[ref ptr] = check_arg_count(args)?;
let ptr = this.read_scalar(ptr)?.check_init()?;
let ptr = this.force_ptr(ptr)?;
if ptr.offset != Size::ZERO {
@ -237,14 +237,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Standard C allocation
"malloc" => {
check_abi(abi, Abi::C)?;
let &[size] = check_arg_count(args)?;
let &[ref size] = check_arg_count(args)?;
let size = this.read_scalar(size)?.to_machine_usize(this)?;
let res = this.malloc(size, /*zero_init:*/ false, MiriMemoryKind::C);
this.write_scalar(res, dest)?;
}
"calloc" => {
check_abi(abi, Abi::C)?;
let &[items, len] = check_arg_count(args)?;
let &[ref items, ref len] = check_arg_count(args)?;
let items = this.read_scalar(items)?.to_machine_usize(this)?;
let len = this.read_scalar(len)?.to_machine_usize(this)?;
let size =
@ -254,13 +254,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"free" => {
check_abi(abi, Abi::C)?;
let &[ptr] = check_arg_count(args)?;
let &[ref ptr] = check_arg_count(args)?;
let ptr = this.read_scalar(ptr)?.check_init()?;
this.free(ptr, MiriMemoryKind::C)?;
}
"realloc" => {
check_abi(abi, Abi::C)?;
let &[old_ptr, new_size] = check_arg_count(args)?;
let &[ref old_ptr, ref new_size] = check_arg_count(args)?;
let old_ptr = this.read_scalar(old_ptr)?.check_init()?;
let new_size = this.read_scalar(new_size)?.to_machine_usize(this)?;
let res = this.realloc(old_ptr, new_size, MiriMemoryKind::C)?;
@ -272,7 +272,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// allocation that also checks that all conditions are met, such as not permitting zero-sized allocations.)
"__rust_alloc" => {
check_abi(abi, Abi::Rust)?;
let &[size, align] = check_arg_count(args)?;
let &[ref size, ref align] = check_arg_count(args)?;
let size = this.read_scalar(size)?.to_machine_usize(this)?;
let align = this.read_scalar(align)?.to_machine_usize(this)?;
Self::check_alloc_request(size, align)?;
@ -285,7 +285,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"__rust_alloc_zeroed" => {
check_abi(abi, Abi::Rust)?;
let &[size, align] = check_arg_count(args)?;
let &[ref size, ref align] = check_arg_count(args)?;
let size = this.read_scalar(size)?.to_machine_usize(this)?;
let align = this.read_scalar(align)?.to_machine_usize(this)?;
Self::check_alloc_request(size, align)?;
@ -300,7 +300,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"__rust_dealloc" => {
check_abi(abi, Abi::Rust)?;
let &[ptr, old_size, align] = check_arg_count(args)?;
let &[ref ptr, ref old_size, ref align] = check_arg_count(args)?;
let ptr = this.read_scalar(ptr)?.check_init()?;
let old_size = this.read_scalar(old_size)?.to_machine_usize(this)?;
let align = this.read_scalar(align)?.to_machine_usize(this)?;
@ -314,7 +314,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"__rust_realloc" => {
check_abi(abi, Abi::Rust)?;
let &[ptr, old_size, align, new_size] = check_arg_count(args)?;
let &[ref ptr, ref old_size, ref align, ref new_size] = check_arg_count(args)?;
let ptr = this.force_ptr(this.read_scalar(ptr)?.check_init()?)?;
let old_size = this.read_scalar(old_size)?.to_machine_usize(this)?;
let align = this.read_scalar(align)?.to_machine_usize(this)?;
@ -335,7 +335,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// C memory handling functions
"memcmp" => {
check_abi(abi, Abi::C)?;
let &[left, right, n] = check_arg_count(args)?;
let &[ref left, ref right, ref n] = check_arg_count(args)?;
let left = this.read_scalar(left)?.check_init()?;
let right = this.read_scalar(right)?.check_init()?;
let n = Size::from_bytes(this.read_scalar(n)?.to_machine_usize(this)?);
@ -356,7 +356,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"memrchr" => {
check_abi(abi, Abi::C)?;
let &[ptr, val, num] = check_arg_count(args)?;
let &[ref ptr, ref val, ref num] = check_arg_count(args)?;
let ptr = this.read_scalar(ptr)?.check_init()?;
let val = this.read_scalar(val)?.to_i32()? as u8;
let num = this.read_scalar(num)?.to_machine_usize(this)?;
@ -375,7 +375,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"memchr" => {
check_abi(abi, Abi::C)?;
let &[ptr, val, num] = check_arg_count(args)?;
let &[ref ptr, ref val, ref num] = check_arg_count(args)?;
let ptr = this.read_scalar(ptr)?.check_init()?;
let val = this.read_scalar(val)?.to_i32()? as u8;
let num = this.read_scalar(num)?.to_machine_usize(this)?;
@ -393,7 +393,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"strlen" => {
check_abi(abi, Abi::C)?;
let &[ptr] = check_arg_count(args)?;
let &[ref ptr] = check_arg_count(args)?;
let ptr = this.read_scalar(ptr)?.check_init()?;
let n = this.memory.read_c_str(ptr)?.len();
this.write_scalar(Scalar::from_machine_usize(u64::try_from(n).unwrap(), this), dest)?;
@ -409,7 +409,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
| "atanf"
=> {
check_abi(abi, Abi::C)?;
let &[f] = check_arg_count(args)?;
let &[ref f] = check_arg_count(args)?;
// FIXME: Using host floats.
let f = f32::from_bits(this.read_scalar(f)?.to_u32()?);
let f = match link_name {
@ -429,7 +429,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
| "atan2f"
=> {
check_abi(abi, Abi::C)?;
let &[f1, f2] = check_arg_count(args)?;
let &[ref f1, ref f2] = check_arg_count(args)?;
// underscore case for windows, here and below
// (see https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/floating-point-primitives?view=vs-2019)
// FIXME: Using host floats.
@ -451,7 +451,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
| "atan"
=> {
check_abi(abi, Abi::C)?;
let &[f] = check_arg_count(args)?;
let &[ref f] = check_arg_count(args)?;
// FIXME: Using host floats.
let f = f64::from_bits(this.read_scalar(f)?.to_u64()?);
let f = match link_name {
@ -471,7 +471,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
| "atan2"
=> {
check_abi(abi, Abi::C)?;
let &[f1, f2] = check_arg_count(args)?;
let &[ref f1, ref f2] = check_arg_count(args)?;
// FIXME: Using host floats.
let f1 = f64::from_bits(this.read_scalar(f1)?.to_u64()?);
let f2 = f64::from_bits(this.read_scalar(f2)?.to_u64()?);
@ -487,7 +487,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
| "scalbn"
=> {
check_abi(abi, Abi::C)?;
let &[x, exp] = check_arg_count(args)?;
let &[ref x, ref exp] = check_arg_count(args)?;
// For radix-2 (binary) systems, `ldexp` and `scalbn` are the same.
let x = this.read_scalar(x)?.to_f64()?;
let exp = this.read_scalar(exp)?.to_i32()?;
@ -514,7 +514,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"llvm.aarch64.hint" if this.tcx.sess.target.arch == "aarch64" => {
check_abi(abi, Abi::C)?;
let &[hint] = check_arg_count(args)?;
let &[ref hint] = check_arg_count(args)?;
let hint = this.read_scalar(hint)?.to_i32()?;
match hint {
1 => { // HINT_YIELD

View File

@ -16,7 +16,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
&mut self,
instance: ty::Instance<'tcx>,
args: &[OpTy<'tcx, Tag>],
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
_unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
@ -36,32 +36,32 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
match intrinsic_name {
// Miri overwriting CTFE intrinsics.
"ptr_guaranteed_eq" => {
let &[left, right] = check_arg_count(args)?;
let &[ref left, ref right] = check_arg_count(args)?;
let left = this.read_immediate(left)?;
let right = this.read_immediate(right)?;
this.binop_ignore_overflow(mir::BinOp::Eq, left, right, dest)?;
this.binop_ignore_overflow(mir::BinOp::Eq, &left, &right, dest)?;
}
"ptr_guaranteed_ne" => {
let &[left, right] = check_arg_count(args)?;
let &[ref left, ref right] = check_arg_count(args)?;
let left = this.read_immediate(left)?;
let right = this.read_immediate(right)?;
this.binop_ignore_overflow(mir::BinOp::Ne, left, right, dest)?;
this.binop_ignore_overflow(mir::BinOp::Ne, &left, &right, dest)?;
}
// Raw memory accesses
"volatile_load" => {
let &[place] = check_arg_count(args)?;
let &[ref place] = check_arg_count(args)?;
let place = this.deref_operand(place)?;
this.copy_op(place.into(), dest)?;
this.copy_op(&place.into(), dest)?;
}
"volatile_store" => {
let &[place, dest] = check_arg_count(args)?;
let &[ref place, ref dest] = check_arg_count(args)?;
let place = this.deref_operand(place)?;
this.copy_op(dest, place.into())?;
this.copy_op(dest, &place.into())?;
}
"write_bytes" => {
let &[ptr, val_byte, count] = check_arg_count(args)?;
let &[ref ptr, ref val_byte, ref count] = check_arg_count(args)?;
let ty = instance.substs.type_at(0);
let ty_layout = this.layout_of(ty)?;
let val_byte = this.read_scalar(val_byte)?.to_u8()?;
@ -89,7 +89,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
| "truncf32"
| "roundf32"
=> {
let &[f] = check_arg_count(args)?;
let &[ref f] = check_arg_count(args)?;
// FIXME: Using host floats.
let f = f32::from_bits(this.read_scalar(f)?.to_u32()?);
let f = match intrinsic_name {
@ -126,7 +126,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
| "truncf64"
| "roundf64"
=> {
let &[f] = check_arg_count(args)?;
let &[ref f] = check_arg_count(args)?;
// FIXME: Using host floats.
let f = f64::from_bits(this.read_scalar(f)?.to_u64()?);
let f = match intrinsic_name {
@ -155,7 +155,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
| "fdiv_fast"
| "frem_fast"
=> {
let &[a, b] = check_arg_count(args)?;
let &[ref a, ref b] = check_arg_count(args)?;
let a = this.read_immediate(a)?;
let b = this.read_immediate(b)?;
let op = match intrinsic_name {
@ -166,7 +166,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
"frem_fast" => mir::BinOp::Rem,
_ => bug!(),
};
this.binop_ignore_overflow(op, a, b, dest)?;
this.binop_ignore_overflow(op, &a, &b, dest)?;
}
#[rustfmt::skip]
@ -174,7 +174,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
| "maxnumf32"
| "copysignf32"
=> {
let &[a, b] = check_arg_count(args)?;
let &[ref a, ref b] = check_arg_count(args)?;
let a = this.read_scalar(a)?.to_f32()?;
let b = this.read_scalar(b)?.to_f32()?;
let res = match intrinsic_name {
@ -191,7 +191,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
| "maxnumf64"
| "copysignf64"
=> {
let &[a, b] = check_arg_count(args)?;
let &[ref a, ref b] = check_arg_count(args)?;
let a = this.read_scalar(a)?.to_f64()?;
let b = this.read_scalar(b)?.to_f64()?;
let res = match intrinsic_name {
@ -204,7 +204,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"powf32" => {
let &[f, f2] = check_arg_count(args)?;
let &[ref f, ref f2] = check_arg_count(args)?;
// FIXME: Using host floats.
let f = f32::from_bits(this.read_scalar(f)?.to_u32()?);
let f2 = f32::from_bits(this.read_scalar(f2)?.to_u32()?);
@ -212,7 +212,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"powf64" => {
let &[f, f2] = check_arg_count(args)?;
let &[ref f, ref f2] = check_arg_count(args)?;
// FIXME: Using host floats.
let f = f64::from_bits(this.read_scalar(f)?.to_u64()?);
let f2 = f64::from_bits(this.read_scalar(f2)?.to_u64()?);
@ -220,7 +220,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"fmaf32" => {
let &[a, b, c] = check_arg_count(args)?;
let &[ref a, ref b, ref c] = check_arg_count(args)?;
let a = this.read_scalar(a)?.to_f32()?;
let b = this.read_scalar(b)?.to_f32()?;
let c = this.read_scalar(c)?.to_f32()?;
@ -229,7 +229,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"fmaf64" => {
let &[a, b, c] = check_arg_count(args)?;
let &[ref a, ref b, ref c] = check_arg_count(args)?;
let a = this.read_scalar(a)?.to_f64()?;
let b = this.read_scalar(b)?.to_f64()?;
let c = this.read_scalar(c)?.to_f64()?;
@ -238,7 +238,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"powif32" => {
let &[f, i] = check_arg_count(args)?;
let &[ref f, ref i] = check_arg_count(args)?;
// FIXME: Using host floats.
let f = f32::from_bits(this.read_scalar(f)?.to_u32()?);
let i = this.read_scalar(i)?.to_i32()?;
@ -246,7 +246,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"powif64" => {
let &[f, i] = check_arg_count(args)?;
let &[ref f, ref i] = check_arg_count(args)?;
// FIXME: Using host floats.
let f = f64::from_bits(this.read_scalar(f)?.to_u64()?);
let i = this.read_scalar(i)?.to_i32()?;
@ -254,7 +254,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"float_to_int_unchecked" => {
let &[val] = check_arg_count(args)?;
let &[ref val] = check_arg_count(args)?;
let val = this.read_immediate(val)?;
let res = match val.layout.ty.kind() {
@ -404,8 +404,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Other
"exact_div" => {
let &[num, denom] = check_arg_count(args)?;
this.exact_div(this.read_immediate(num)?, this.read_immediate(denom)?, dest)?;
let &[ref num, ref denom] = check_arg_count(args)?;
this.exact_div(&this.read_immediate(num)?, &this.read_immediate(denom)?, dest)?;
}
"try" => return this.handle_try(args, dest, ret),
@ -413,23 +413,23 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
name => throw_unsup_format!("unimplemented intrinsic: {}", name),
}
trace!("{:?}", this.dump_place(*dest));
trace!("{:?}", this.dump_place(**dest));
this.go_to_block(ret);
Ok(())
}
fn atomic_load(
&mut self, args: &[OpTy<'tcx, Tag>], dest: PlaceTy<'tcx, Tag>,
&mut self, args: &[OpTy<'tcx, Tag>], dest: &PlaceTy<'tcx, Tag>,
atomic: AtomicReadOp
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let &[place] = check_arg_count(args)?;
let &[ref place] = check_arg_count(args)?;
let place = this.deref_operand(place)?;
// make sure it fits into a scalar; otherwise it cannot be atomic
let val = this.read_scalar_atomic(place, atomic)?;
let val = this.read_scalar_atomic(&place, atomic)?;
// Check alignment requirements. Atomics must always be aligned to their size,
// even if the type they wrap would be less aligned (e.g. AtomicU64 on 32bit must
@ -443,7 +443,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn atomic_store(&mut self, args: &[OpTy<'tcx, Tag>], atomic: AtomicWriteOp) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let &[place, val] = check_arg_count(args)?;
let &[ref place, ref val] = check_arg_count(args)?;
let place = this.deref_operand(place)?;
let val = this.read_scalar(val)?; // make sure it fits into a scalar; otherwise it cannot be atomic
@ -454,7 +454,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.memory.check_ptr_access(place.ptr, place.layout.size, align)?;
// Perform atomic store
this.write_scalar_atomic(val, place, atomic)?;
this.write_scalar_atomic(val, &place, atomic)?;
Ok(())
}
@ -473,12 +473,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
fn atomic_op(
&mut self, args: &[OpTy<'tcx, Tag>], dest: PlaceTy<'tcx, Tag>,
&mut self, args: &[OpTy<'tcx, Tag>], dest: &PlaceTy<'tcx, Tag>,
op: mir::BinOp, neg: bool, atomic: AtomicRwOp
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let &[place, rhs] = check_arg_count(args)?;
let &[ref place, ref rhs] = check_arg_count(args)?;
let place = this.deref_operand(place)?;
if !place.layout.ty.is_integral() {
bug!("Atomic arithmetic operations only work on integer types");
@ -491,17 +491,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let align = Align::from_bytes(place.layout.size.bytes()).unwrap();
this.memory.check_ptr_access(place.ptr, place.layout.size, align)?;
let old = this.atomic_op_immediate(place, rhs, op, neg, atomic)?;
let old = this.atomic_op_immediate(&place, &rhs, op, neg, atomic)?;
this.write_immediate(*old, dest)?; // old value is returned
Ok(())
}
fn atomic_exchange(
&mut self, args: &[OpTy<'tcx, Tag>], dest: PlaceTy<'tcx, Tag>, atomic: AtomicRwOp
&mut self, args: &[OpTy<'tcx, Tag>], dest: &PlaceTy<'tcx, Tag>, atomic: AtomicRwOp
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let &[place, new] = check_arg_count(args)?;
let &[ref place, ref new] = check_arg_count(args)?;
let place = this.deref_operand(place)?;
let new = this.read_scalar(new)?;
@ -511,18 +511,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let align = Align::from_bytes(place.layout.size.bytes()).unwrap();
this.memory.check_ptr_access(place.ptr, place.layout.size, align)?;
let old = this.atomic_exchange_scalar(place, new, atomic)?;
let old = this.atomic_exchange_scalar(&place, new, atomic)?;
this.write_scalar(old, dest)?; // old value is returned
Ok(())
}
fn atomic_compare_exchange_impl(
&mut self, args: &[OpTy<'tcx, Tag>], dest: PlaceTy<'tcx, Tag>,
&mut self, args: &[OpTy<'tcx, Tag>], dest: &PlaceTy<'tcx, Tag>,
success: AtomicRwOp, fail: AtomicReadOp, can_fail_spuriously: bool
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let &[place, expect_old, new] = check_arg_count(args)?;
let &[ref place, ref expect_old, ref new] = check_arg_count(args)?;
let place = this.deref_operand(place)?;
let expect_old = this.read_immediate(expect_old)?; // read as immediate for the sake of `binary_op()`
let new = this.read_scalar(new)?;
@ -536,7 +536,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let old = this.atomic_compare_exchange_scalar(
place, expect_old, new, success, fail, can_fail_spuriously
&place, &expect_old, new, success, fail, can_fail_spuriously
)?;
// Return old value.
@ -545,14 +545,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
fn atomic_compare_exchange(
&mut self, args: &[OpTy<'tcx, Tag>], dest: PlaceTy<'tcx, Tag>,
&mut self, args: &[OpTy<'tcx, Tag>], dest: &PlaceTy<'tcx, Tag>,
success: AtomicRwOp, fail: AtomicReadOp
) -> InterpResult<'tcx> {
self.atomic_compare_exchange_impl(args, dest, success, fail, false)
}
fn atomic_compare_exchange_weak(
&mut self, args: &[OpTy<'tcx, Tag>], dest: PlaceTy<'tcx, Tag>,
&mut self, args: &[OpTy<'tcx, Tag>], dest: &PlaceTy<'tcx, Tag>,
success: AtomicRwOp, fail: AtomicReadOp
) -> InterpResult<'tcx> {
self.atomic_compare_exchange_impl(args, dest, success, fail, true)

View File

@ -28,15 +28,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
instance: ty::Instance<'tcx>,
abi: Abi,
args: &[OpTy<'tcx, Tag>],
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> {
let this = self.eval_context_mut();
trace!("eval_fn_call: {:#?}, {:?}", instance, ret.map(|p| *p.0));
trace!("eval_fn_call: {:#?}, {:?}", instance, ret.map(|p| p.0));
// There are some more lang items we want to hook that CTFE does not hook (yet).
if this.tcx.lang_items().align_offset_fn() == Some(instance.def.def_id()) {
let &[ptr, align] = check_arg_count(args)?;
let &[ref ptr, ref align] = check_arg_count(args)?;
if this.align_offset(ptr, align, ret, unwind)? {
return Ok(None);
}
@ -61,9 +61,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
/// the actual MIR of `align_offset`.
fn align_offset(
&mut self,
ptr_op: OpTy<'tcx, Tag>,
align_op: OpTy<'tcx, Tag>,
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
ptr_op: &OpTy<'tcx, Tag>,
align_op: &OpTy<'tcx, Tag>,
ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx, bool> {
let this = self.eval_context_mut();

View File

@ -48,7 +48,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
assert_eq!(this.tcx.sess.panic_strategy(), PanicStrategy::Unwind);
// Get the raw pointer stored in arg[0] (the panic payload).
let &[payload] = check_arg_count(args)?;
let &[ref payload] = check_arg_count(args)?;
let payload = this.read_scalar(payload)?.check_init()?;
let thread = this.active_thread_mut();
assert!(
@ -66,7 +66,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn handle_try(
&mut self,
args: &[OpTy<'tcx, Tag>],
dest: PlaceTy<'tcx, Tag>,
dest: &PlaceTy<'tcx, Tag>,
ret: mir::BasicBlock,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
@ -83,7 +83,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// a pointer to `Box<dyn Any + Send + 'static>`.
// Get all the arguments.
let &[try_fn, data, catch_fn] = check_arg_count(args)?;
let &[ref try_fn, ref data, ref catch_fn] = check_arg_count(args)?;
let try_fn = this.read_scalar(try_fn)?.check_init()?;
let data = this.read_scalar(data)?.check_init()?;
let catch_fn = this.read_scalar(catch_fn)?.check_init()?;
@ -95,7 +95,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.call_function(
f_instance,
&[data.into()],
Some(ret_place),
Some(&ret_place),
// Directly return to caller.
StackPopCleanup::Goto { ret: Some(ret), unwind: None },
)?;
@ -107,7 +107,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// This lets `handle_stack_pop` (below) know that we should stop unwinding
// when we pop this frame.
if this.tcx.sess.panic_strategy() == PanicStrategy::Unwind {
this.frame_mut().extra.catch_unwind = Some(CatchUnwindData { catch_fn, data, dest, ret });
this.frame_mut().extra.catch_unwind = Some(CatchUnwindData { catch_fn, data, dest: *dest, ret });
}
return Ok(());
@ -133,7 +133,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
trace!("unwinding: found catch_panic frame during unwinding: {:?}", this.frame().instance);
// We set the return value of `try` to 1, since there was a panic.
this.write_scalar(Scalar::from_i32(1), catch_unwind.dest)?;
this.write_scalar(Scalar::from_i32(1), &catch_unwind.dest)?;
// The Thread's `panic_payload` holds what was passed to `miri_start_panic`.
// This is exactly the second argument we need to pass to `catch_fn`.
@ -146,7 +146,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.call_function(
f_instance,
&[catch_unwind.data.into(), payload.into()],
Some(ret_place),
Some(&ret_place),
// Directly return to caller of `try`.
StackPopCleanup::Goto { ret: Some(catch_unwind.ret), unwind: None },
)?;
@ -193,9 +193,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Forward to `panic_bounds_check` lang item.
// First arg: index.
let index = this.read_scalar(this.eval_operand(index, None)?)?;
let index = this.read_scalar(&this.eval_operand(index, None)?)?;
// Second arg: len.
let len = this.read_scalar(this.eval_operand(len, None)?)?;
let len = this.read_scalar(&this.eval_operand(len, None)?)?;
// Call the lang item.
let panic_bounds_check = this.tcx.lang_items().panic_bounds_check_fn().unwrap();

View File

@ -31,7 +31,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
dlsym: Dlsym,
abi: Abi,
args: &[OpTy<'tcx, Tag>],
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();

View File

@ -17,7 +17,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
link_name: &str,
abi: Abi,
args: &[OpTy<'tcx, Tag>],
dest: PlaceTy<'tcx, Tag>,
dest: &PlaceTy<'tcx, Tag>,
ret: mir::BasicBlock,
) -> InterpResult<'tcx, bool> {
let this = self.eval_context_mut();
@ -27,35 +27,35 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
match link_name {
// Environment related shims
"getenv" => {
let &[name] = check_arg_count(args)?;
let &[ref name] = check_arg_count(args)?;
let result = this.getenv(name)?;
this.write_scalar(result, dest)?;
}
"unsetenv" => {
let &[name] = check_arg_count(args)?;
let &[ref name] = check_arg_count(args)?;
let result = this.unsetenv(name)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"setenv" => {
let &[name, value, overwrite] = check_arg_count(args)?;
let &[ref name, ref value, ref overwrite] = check_arg_count(args)?;
this.read_scalar(overwrite)?.to_i32()?;
let result = this.setenv(name, value)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"getcwd" => {
let &[buf, size] = check_arg_count(args)?;
let &[ref buf, ref size] = check_arg_count(args)?;
let result = this.getcwd(buf, size)?;
this.write_scalar(result, dest)?;
}
"chdir" => {
let &[path] = check_arg_count(args)?;
let &[ref path] = check_arg_count(args)?;
let result = this.chdir(path)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
// File related shims
"open" | "open64" => {
let &[path, flag, mode] = check_arg_count(args)?;
let &[ref path, ref flag, ref mode] = check_arg_count(args)?;
let result = this.open(path, flag, mode)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
@ -64,7 +64,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"read" => {
let &[fd, buf, count] = check_arg_count(args)?;
let &[ref fd, ref buf, ref count] = check_arg_count(args)?;
let fd = this.read_scalar(fd)?.to_i32()?;
let buf = this.read_scalar(buf)?.check_init()?;
let count = this.read_scalar(count)?.to_machine_usize(this)?;
@ -72,7 +72,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_scalar(Scalar::from_machine_isize(result, this), dest)?;
}
"write" => {
let &[fd, buf, n] = check_arg_count(args)?;
let &[ref fd, ref buf, ref n] = check_arg_count(args)?;
let fd = this.read_scalar(fd)?.to_i32()?;
let buf = this.read_scalar(buf)?.check_init()?;
let count = this.read_scalar(n)?.to_machine_usize(this)?;
@ -82,60 +82,60 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_scalar(Scalar::from_machine_isize(result, this), dest)?;
}
"unlink" => {
let &[path] = check_arg_count(args)?;
let &[ref path] = check_arg_count(args)?;
let result = this.unlink(path)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"symlink" => {
let &[target, linkpath] = check_arg_count(args)?;
let &[ref target, ref linkpath] = check_arg_count(args)?;
let result = this.symlink(target, linkpath)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"rename" => {
let &[oldpath, newpath] = check_arg_count(args)?;
let &[ref oldpath, ref newpath] = check_arg_count(args)?;
let result = this.rename(oldpath, newpath)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"mkdir" => {
let &[path, mode] = check_arg_count(args)?;
let &[ref path, ref mode] = check_arg_count(args)?;
let result = this.mkdir(path, mode)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"rmdir" => {
let &[path] = check_arg_count(args)?;
let &[ref path] = check_arg_count(args)?;
let result = this.rmdir(path)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"closedir" => {
let &[dirp] = check_arg_count(args)?;
let &[ref dirp] = check_arg_count(args)?;
let result = this.closedir(dirp)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"lseek" | "lseek64" => {
let &[fd, offset, whence] = check_arg_count(args)?;
let &[ref fd, ref offset, ref whence] = check_arg_count(args)?;
let result = this.lseek64(fd, offset, whence)?;
// "lseek" is only used on macOS which is 64bit-only, so `i64` always works.
this.write_scalar(Scalar::from_i64(result), dest)?;
}
"fsync" => {
let &[fd] = check_arg_count(args)?;
let &[ref fd] = check_arg_count(args)?;
let result = this.fsync(fd)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"fdatasync" => {
let &[fd] = check_arg_count(args)?;
let &[ref fd] = check_arg_count(args)?;
let result = this.fdatasync(fd)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"readlink" => {
let &[pathname, buf, bufsize] = check_arg_count(args)?;
let &[ref pathname, ref buf, ref bufsize] = check_arg_count(args)?;
let result = this.readlink(pathname, buf, bufsize)?;
this.write_scalar(Scalar::from_machine_isize(result, this), dest)?;
}
// Allocation
"posix_memalign" => {
let &[ret, align, size] = check_arg_count(args)?;
let &[ref ret, ref align, ref size] = check_arg_count(args)?;
let ret = this.deref_operand(ret)?;
let align = this.read_scalar(align)?.to_machine_usize(this)?;
let size = this.read_scalar(size)?.to_machine_usize(this)?;
@ -151,21 +151,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
if size == 0 {
this.write_null(ret.into())?;
this.write_null(&ret.into())?;
} else {
let ptr = this.memory.allocate(
Size::from_bytes(size),
Align::from_bytes(align).unwrap(),
MiriMemoryKind::C.into(),
);
this.write_scalar(ptr, ret.into())?;
this.write_scalar(ptr, &ret.into())?;
}
this.write_null(dest)?;
}
// Dynamic symbol loading
"dlsym" => {
let &[handle, symbol] = check_arg_count(args)?;
let &[ref handle, ref symbol] = check_arg_count(args)?;
this.read_scalar(handle)?.to_machine_usize(this)?;
let symbol = this.read_scalar(symbol)?.check_init()?;
let symbol_name = this.memory.read_c_str(symbol)?;
@ -179,7 +179,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Querying system information
"sysconf" => {
let &[name] = check_arg_count(args)?;
let &[ref name] = check_arg_count(args)?;
let name = this.read_scalar(name)?.to_i32()?;
let sysconfs = &[
@ -204,7 +204,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Thread-local storage
"pthread_key_create" => {
let &[key, dtor] = check_arg_count(args)?;
let &[ref key, ref dtor] = check_arg_count(args)?;
let key_place = this.deref_operand(key)?;
let dtor = this.read_scalar(dtor)?.check_init()?;
@ -226,27 +226,27 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Create key and write it into the memory where `key_ptr` wants it.
let key = this.machine.tls.create_tls_key(dtor, key_layout.size)?;
this.write_scalar(Scalar::from_uint(key, key_layout.size), key_place.into())?;
this.write_scalar(Scalar::from_uint(key, key_layout.size), &key_place.into())?;
// Return success (`0`).
this.write_null(dest)?;
}
"pthread_key_delete" => {
let &[key] = check_arg_count(args)?;
let &[ref key] = check_arg_count(args)?;
let key = this.force_bits(this.read_scalar(key)?.check_init()?, key.layout.size)?;
this.machine.tls.delete_tls_key(key)?;
// Return success (0)
this.write_null(dest)?;
}
"pthread_getspecific" => {
let &[key] = check_arg_count(args)?;
let &[ref key] = check_arg_count(args)?;
let key = this.force_bits(this.read_scalar(key)?.check_init()?, key.layout.size)?;
let active_thread = this.get_active_thread();
let ptr = this.machine.tls.load_tls(key, active_thread, this)?;
this.write_scalar(ptr, dest)?;
}
"pthread_setspecific" => {
let &[key, new_ptr] = check_arg_count(args)?;
let &[ref key, ref new_ptr] = check_arg_count(args)?;
let key = this.force_bits(this.read_scalar(key)?.check_init()?, key.layout.size)?;
let active_thread = this.get_active_thread();
let new_ptr = this.read_scalar(new_ptr)?.check_init()?;
@ -258,128 +258,128 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Synchronization primitives
"pthread_mutexattr_init" => {
let &[attr] = check_arg_count(args)?;
let &[ref attr] = check_arg_count(args)?;
let result = this.pthread_mutexattr_init(attr)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_mutexattr_settype" => {
let &[attr, kind] = check_arg_count(args)?;
let &[ref attr, ref kind] = check_arg_count(args)?;
let result = this.pthread_mutexattr_settype(attr, kind)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_mutexattr_destroy" => {
let &[attr] = check_arg_count(args)?;
let &[ref attr] = check_arg_count(args)?;
let result = this.pthread_mutexattr_destroy(attr)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_mutex_init" => {
let &[mutex, attr] = check_arg_count(args)?;
let &[ref mutex, ref attr] = check_arg_count(args)?;
let result = this.pthread_mutex_init(mutex, attr)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_mutex_lock" => {
let &[mutex] = check_arg_count(args)?;
let &[ref mutex] = check_arg_count(args)?;
let result = this.pthread_mutex_lock(mutex)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_mutex_trylock" => {
let &[mutex] = check_arg_count(args)?;
let &[ref mutex] = check_arg_count(args)?;
let result = this.pthread_mutex_trylock(mutex)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_mutex_unlock" => {
let &[mutex] = check_arg_count(args)?;
let &[ref mutex] = check_arg_count(args)?;
let result = this.pthread_mutex_unlock(mutex)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_mutex_destroy" => {
let &[mutex] = check_arg_count(args)?;
let &[ref mutex] = check_arg_count(args)?;
let result = this.pthread_mutex_destroy(mutex)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_rwlock_rdlock" => {
let &[rwlock] = check_arg_count(args)?;
let &[ref rwlock] = check_arg_count(args)?;
let result = this.pthread_rwlock_rdlock(rwlock)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_rwlock_tryrdlock" => {
let &[rwlock] = check_arg_count(args)?;
let &[ref rwlock] = check_arg_count(args)?;
let result = this.pthread_rwlock_tryrdlock(rwlock)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_rwlock_wrlock" => {
let &[rwlock] = check_arg_count(args)?;
let &[ref rwlock] = check_arg_count(args)?;
let result = this.pthread_rwlock_wrlock(rwlock)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_rwlock_trywrlock" => {
let &[rwlock] = check_arg_count(args)?;
let &[ref rwlock] = check_arg_count(args)?;
let result = this.pthread_rwlock_trywrlock(rwlock)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_rwlock_unlock" => {
let &[rwlock] = check_arg_count(args)?;
let &[ref rwlock] = check_arg_count(args)?;
let result = this.pthread_rwlock_unlock(rwlock)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_rwlock_destroy" => {
let &[rwlock] = check_arg_count(args)?;
let &[ref rwlock] = check_arg_count(args)?;
let result = this.pthread_rwlock_destroy(rwlock)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_condattr_init" => {
let &[attr] = check_arg_count(args)?;
let &[ref attr] = check_arg_count(args)?;
let result = this.pthread_condattr_init(attr)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_condattr_destroy" => {
let &[attr] = check_arg_count(args)?;
let &[ref attr] = check_arg_count(args)?;
let result = this.pthread_condattr_destroy(attr)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_cond_init" => {
let &[cond, attr] = check_arg_count(args)?;
let &[ref cond, ref attr] = check_arg_count(args)?;
let result = this.pthread_cond_init(cond, attr)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_cond_signal" => {
let &[cond] = check_arg_count(args)?;
let &[ref cond] = check_arg_count(args)?;
let result = this.pthread_cond_signal(cond)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_cond_broadcast" => {
let &[cond] = check_arg_count(args)?;
let &[ref cond] = check_arg_count(args)?;
let result = this.pthread_cond_broadcast(cond)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_cond_wait" => {
let &[cond, mutex] = check_arg_count(args)?;
let &[ref cond, ref mutex] = check_arg_count(args)?;
let result = this.pthread_cond_wait(cond, mutex)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_cond_timedwait" => {
let &[cond, mutex, abstime] = check_arg_count(args)?;
let &[ref cond, ref mutex, ref abstime] = check_arg_count(args)?;
this.pthread_cond_timedwait(cond, mutex, abstime, dest)?;
}
"pthread_cond_destroy" => {
let &[cond] = check_arg_count(args)?;
let &[ref cond] = check_arg_count(args)?;
let result = this.pthread_cond_destroy(cond)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
// Threading
"pthread_create" => {
let &[thread, attr, start, arg] = check_arg_count(args)?;
let &[ref thread, ref attr, ref start, ref arg] = check_arg_count(args)?;
let result = this.pthread_create(thread, attr, start, arg)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_join" => {
let &[thread, retval] = check_arg_count(args)?;
let &[ref thread, ref retval] = check_arg_count(args)?;
let result = this.pthread_join(thread, retval)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_detach" => {
let &[thread] = check_arg_count(args)?;
let &[ref thread] = check_arg_count(args)?;
let result = this.pthread_detach(thread)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
@ -393,14 +393,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"nanosleep" => {
let &[req, rem] = check_arg_count(args)?;
let &[ref req, ref rem] = check_arg_count(args)?;
let result = this.nanosleep(req, rem)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
// Miscellaneous
"isatty" => {
let &[fd] = check_arg_count(args)?;
let &[ref fd] = check_arg_count(args)?;
this.read_scalar(fd)?.to_i32()?;
// "returns 1 if fd is an open file descriptor referring to a terminal; otherwise 0 is returned, and errno is set to indicate the error"
// FIXME: we just say nothing is a terminal.
@ -409,7 +409,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_null(dest)?;
}
"pthread_atfork" => {
let &[prepare, parent, child] = check_arg_count(args)?;
let &[ref prepare, ref parent, ref child] = check_arg_count(args)?;
this.force_bits(this.read_scalar(prepare)?.check_init()?, this.memory.pointer_size())?;
this.force_bits(this.read_scalar(parent)?.check_init()?, this.memory.pointer_size())?;
this.force_bits(this.read_scalar(child)?.check_init()?, this.memory.pointer_size())?;
@ -421,10 +421,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// These shims are enabled only when the caller is in the standard library.
"pthread_attr_getguardsize"
if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
let &[_attr, guard_size] = check_arg_count(args)?;
let &[ref _attr, ref guard_size] = check_arg_count(args)?;
let guard_size = this.deref_operand(guard_size)?;
let guard_size_layout = this.libc_ty_layout("size_t")?;
this.write_scalar(Scalar::from_uint(crate::PAGE_SIZE, guard_size_layout.size), guard_size.into())?;
this.write_scalar(Scalar::from_uint(crate::PAGE_SIZE, guard_size_layout.size), &guard_size.into())?;
// Return success (`0`).
this.write_null(dest)?;

View File

@ -237,8 +237,8 @@ trait EvalContextExtPrivate<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, '
fn macos_stat_or_lstat(
&mut self,
follow_symlink: bool,
path_op: OpTy<'tcx, Tag>,
buf_op: OpTy<'tcx, Tag>,
path_op: &OpTy<'tcx, Tag>,
buf_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -255,7 +255,7 @@ trait EvalContextExtPrivate<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, '
fn macos_stat_write_buf(
&mut self,
metadata: FileMetadata,
buf_op: OpTy<'tcx, Tag>,
buf_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -303,7 +303,7 @@ trait EvalContextExtPrivate<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, '
];
let buf = this.deref_operand(buf_op)?;
this.write_packed_immediates(buf, &imms)?;
this.write_packed_immediates(&buf, &imms)?;
Ok(0)
}
@ -412,9 +412,9 @@ impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mi
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
fn open(
&mut self,
path_op: OpTy<'tcx, Tag>,
flag_op: OpTy<'tcx, Tag>,
mode_op: OpTy<'tcx, Tag>,
path_op: &OpTy<'tcx, Tag>,
flag_op: &OpTy<'tcx, Tag>,
mode_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -516,8 +516,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
if args.len() < 2 {
throw_ub_format!("incorrect number of arguments for fcntl: got {}, expected at least 2", args.len());
}
let fd = this.read_scalar(args[0])?.to_i32()?;
let cmd = this.read_scalar(args[1])?.to_i32()?;
let fd = this.read_scalar(&args[0])?.to_i32()?;
let cmd = this.read_scalar(&args[1])?.to_i32()?;
// We only support getting the flags for a descriptor.
if cmd == this.eval_libc_i32("F_GETFD")? {
// Currently this is the only flag that `F_GETFD` returns. It is OK to just return the
@ -537,7 +537,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// because exec() isn't supported. The F_DUPFD and F_DUPFD_CLOEXEC commands only
// differ in whether the FD_CLOEXEC flag is pre-set on the new file descriptor,
// thus they can share the same implementation here.
let &[_, _, start] = check_arg_count(args)?;
let &[_, _, ref start] = check_arg_count(args)?;
let start = this.read_scalar(start)?.to_i32()?;
let fh = &mut this.machine.file_handler;
@ -572,7 +572,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
fn close(&mut self, fd_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn close(&mut self, fd_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let fd = this.read_scalar(fd_op)?.to_i32()?;
@ -671,9 +671,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn lseek64(
&mut self,
fd_op: OpTy<'tcx, Tag>,
offset_op: OpTy<'tcx, Tag>,
whence_op: OpTy<'tcx, Tag>,
fd_op: &OpTy<'tcx, Tag>,
offset_op: &OpTy<'tcx, Tag>,
whence_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i64> {
let this = self.eval_context_mut();
@ -705,7 +705,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
fn unlink(&mut self, path_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn unlink(&mut self, path_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
this.check_no_isolation("`unlink`")?;
@ -718,8 +718,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn symlink(
&mut self,
target_op: OpTy<'tcx, Tag>,
linkpath_op: OpTy<'tcx, Tag>
target_op: &OpTy<'tcx, Tag>,
linkpath_op: &OpTy<'tcx, Tag>
) -> InterpResult<'tcx, i32> {
#[cfg(unix)]
fn create_link(src: &Path, dst: &Path) -> std::io::Result<()> {
@ -749,8 +749,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn macos_stat(
&mut self,
path_op: OpTy<'tcx, Tag>,
buf_op: OpTy<'tcx, Tag>,
path_op: &OpTy<'tcx, Tag>,
buf_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
this.assert_target_os("macos", "stat");
@ -762,8 +762,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// `lstat` is used to get symlink metadata.
fn macos_lstat(
&mut self,
path_op: OpTy<'tcx, Tag>,
buf_op: OpTy<'tcx, Tag>,
path_op: &OpTy<'tcx, Tag>,
buf_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
this.assert_target_os("macos", "lstat");
@ -773,8 +773,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn macos_fstat(
&mut self,
fd_op: OpTy<'tcx, Tag>,
buf_op: OpTy<'tcx, Tag>,
fd_op: &OpTy<'tcx, Tag>,
buf_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -792,11 +792,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn linux_statx(
&mut self,
dirfd_op: OpTy<'tcx, Tag>, // Should be an `int`
pathname_op: OpTy<'tcx, Tag>, // Should be a `const char *`
flags_op: OpTy<'tcx, Tag>, // Should be an `int`
_mask_op: OpTy<'tcx, Tag>, // Should be an `unsigned int`
statxbuf_op: OpTy<'tcx, Tag>, // Should be a `struct statx *`
dirfd_op: &OpTy<'tcx, Tag>, // Should be an `int`
pathname_op: &OpTy<'tcx, Tag>, // Should be a `const char *`
flags_op: &OpTy<'tcx, Tag>, // Should be an `int`
_mask_op: &OpTy<'tcx, Tag>, // Should be an `unsigned int`
statxbuf_op: &OpTy<'tcx, Tag>, // Should be a `struct statx *`
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -827,7 +827,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let statxbuf_ty = this.tcx.mk_mut_ptr(statx_ty);
let statxbuf_layout = this.layout_of(statxbuf_ty)?;
let statxbuf_imm = ImmTy::from_scalar(statxbuf_scalar, statxbuf_layout);
this.ref_to_mplace(statxbuf_imm)?
this.ref_to_mplace(&statxbuf_imm)?
};
let path = this.read_path_from_c_str(pathname_scalar)?.into_owned();
@ -941,15 +941,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
immty_from_uint_checked(0u128, __u64_layout)?, // stx_dev_minor
];
this.write_packed_immediates(statxbuf_place, &imms)?;
this.write_packed_immediates(&statxbuf_place, &imms)?;
Ok(0)
}
fn rename(
&mut self,
oldpath_op: OpTy<'tcx, Tag>,
newpath_op: OpTy<'tcx, Tag>,
oldpath_op: &OpTy<'tcx, Tag>,
newpath_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -974,8 +974,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn mkdir(
&mut self,
path_op: OpTy<'tcx, Tag>,
mode_op: OpTy<'tcx, Tag>,
path_op: &OpTy<'tcx, Tag>,
mode_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -1008,7 +1008,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn rmdir(
&mut self,
path_op: OpTy<'tcx, Tag>,
path_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -1021,7 +1021,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.try_unwrap_io_result(result)
}
fn opendir(&mut self, name_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, Scalar<Tag>> {
fn opendir(&mut self, name_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, Scalar<Tag>> {
let this = self.eval_context_mut();
this.check_no_isolation("`opendir`")?;
@ -1048,9 +1048,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn linux_readdir64_r(
&mut self,
dirp_op: OpTy<'tcx, Tag>,
entry_op: OpTy<'tcx, Tag>,
result_op: OpTy<'tcx, Tag>,
dirp_op: &OpTy<'tcx, Tag>,
entry_op: &OpTy<'tcx, Tag>,
result_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -1078,7 +1078,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// }
let entry_place = this.deref_operand(entry_op)?;
let name_place = this.mplace_field(entry_place, 4)?;
let name_place = this.mplace_field(&entry_place, 4)?;
let file_name = dir_entry.file_name(); // not a Path as there are no separators!
let (name_fits, _) = this.write_os_str_to_c_str(
@ -1111,16 +1111,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
immty_from_uint_checked(0u128, c_ushort_layout)?, // d_reclen
immty_from_int_checked(file_type, c_uchar_layout)?, // d_type
];
this.write_packed_immediates(entry_place, &imms)?;
this.write_packed_immediates(&entry_place, &imms)?;
let result_place = this.deref_operand(result_op)?;
this.write_scalar(this.read_scalar(entry_op)?, result_place.into())?;
this.write_scalar(this.read_scalar(entry_op)?, &result_place.into())?;
Ok(0)
}
None => {
// end of stream: return 0, assign *result=NULL
this.write_null(this.deref_operand(result_op)?.into())?;
this.write_null(&this.deref_operand(result_op)?.into())?;
Ok(0)
}
Some(Err(e)) => match e.raw_os_error() {
@ -1135,9 +1135,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn macos_readdir_r(
&mut self,
dirp_op: OpTy<'tcx, Tag>,
entry_op: OpTy<'tcx, Tag>,
result_op: OpTy<'tcx, Tag>,
dirp_op: &OpTy<'tcx, Tag>,
entry_op: &OpTy<'tcx, Tag>,
result_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -1166,7 +1166,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// }
let entry_place = this.deref_operand(entry_op)?;
let name_place = this.mplace_field(entry_place, 5)?;
let name_place = this.mplace_field(&entry_place, 5)?;
let file_name = dir_entry.file_name(); // not a Path as there are no separators!
let (name_fits, file_name_len) = this.write_os_str_to_c_str(
@ -1200,16 +1200,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
immty_from_uint_checked(file_name_len, c_ushort_layout)?, // d_namlen
immty_from_int_checked(file_type, c_uchar_layout)?, // d_type
];
this.write_packed_immediates(entry_place, &imms)?;
this.write_packed_immediates(&entry_place, &imms)?;
let result_place = this.deref_operand(result_op)?;
this.write_scalar(this.read_scalar(entry_op)?, result_place.into())?;
this.write_scalar(this.read_scalar(entry_op)?, &result_place.into())?;
Ok(0)
}
None => {
// end of stream: return 0, assign *result=NULL
this.write_null(this.deref_operand(result_op)?.into())?;
this.write_null(&this.deref_operand(result_op)?.into())?;
Ok(0)
}
Some(Err(e)) => match e.raw_os_error() {
@ -1222,7 +1222,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
fn closedir(&mut self, dirp_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn closedir(&mut self, dirp_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
this.check_no_isolation("`closedir`")?;
@ -1239,8 +1239,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn ftruncate64(
&mut self,
fd_op: OpTy<'tcx, Tag>,
length_op: OpTy<'tcx, Tag>,
fd_op: &OpTy<'tcx, Tag>,
length_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -1271,7 +1271,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
fn fsync(&mut self, fd_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn fsync(&mut self, fd_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
// On macOS, `fsync` (unlike `fcntl(F_FULLFSYNC)`) does not wait for the
// underlying disk to finish writing. In the interest of host compatibility,
// we conservatively implement this with `sync_all`, which
@ -1292,7 +1292,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
fn fdatasync(&mut self, fd_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn fdatasync(&mut self, fd_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
this.check_no_isolation("`fdatasync`")?;
@ -1310,10 +1310,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn sync_file_range(
&mut self,
fd_op: OpTy<'tcx, Tag>,
offset_op: OpTy<'tcx, Tag>,
nbytes_op: OpTy<'tcx, Tag>,
flags_op: OpTy<'tcx, Tag>,
fd_op: &OpTy<'tcx, Tag>,
offset_op: &OpTy<'tcx, Tag>,
nbytes_op: &OpTy<'tcx, Tag>,
flags_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -1350,9 +1350,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn readlink(
&mut self,
pathname_op: OpTy<'tcx, Tag>,
buf_op: OpTy<'tcx, Tag>,
bufsize_op: OpTy<'tcx, Tag>
pathname_op: &OpTy<'tcx, Tag>,
buf_op: &OpTy<'tcx, Tag>,
bufsize_op: &OpTy<'tcx, Tag>
) -> InterpResult<'tcx, i64> {
let this = self.eval_context_mut();

View File

@ -25,7 +25,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
&mut self,
dlsym: Dlsym,
_args: &[OpTy<'tcx, Tag>],
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let (_dest, _ret) = ret.expect("we don't support any diverging dlsym");

View File

@ -13,7 +13,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
&mut self,
link_name: &str,
args: &[OpTy<'tcx, Tag>],
dest: PlaceTy<'tcx, Tag>,
dest: &PlaceTy<'tcx, Tag>,
_ret: mir::BasicBlock,
) -> InterpResult<'tcx, bool> {
let this = self.eval_context_mut();
@ -30,28 +30,28 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// These symbols have different names on Linux and macOS, which is the only reason they are not
// in the `posix` module.
"close" => {
let &[fd] = check_arg_count(args)?;
let &[ref fd] = check_arg_count(args)?;
let result = this.close(fd)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"opendir" => {
let &[name] = check_arg_count(args)?;
let &[ref name] = check_arg_count(args)?;
let result = this.opendir(name)?;
this.write_scalar(result, dest)?;
}
"readdir64_r" => {
let &[dirp, entry, result] = check_arg_count(args)?;
let &[ref dirp, ref entry, ref result] = check_arg_count(args)?;
let result = this.linux_readdir64_r(dirp, entry, result)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"ftruncate64" => {
let &[fd, length] = check_arg_count(args)?;
let &[ref fd, ref length] = check_arg_count(args)?;
let result = this.ftruncate64(fd, length)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
// Linux-only
"posix_fadvise" => {
let &[fd, offset, len, advice] = check_arg_count(args)?;
let &[ref fd, ref offset, ref len, ref advice] = check_arg_count(args)?;
this.read_scalar(fd)?.to_i32()?;
this.read_scalar(offset)?.to_machine_isize(this)?;
this.read_scalar(len)?.to_machine_isize(this)?;
@ -60,7 +60,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_null(dest)?;
}
"sync_file_range" => {
let &[fd, offset, nbytes, flags] = check_arg_count(args)?;
let &[ref fd, ref offset, ref nbytes, ref flags] = check_arg_count(args)?;
let result = this.sync_file_range(fd, offset, nbytes, flags)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
@ -68,7 +68,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Time related shims
"clock_gettime" => {
// This is a POSIX function but it has only been tested on linux.
let &[clk_id, tp] = check_arg_count(args)?;
let &[ref clk_id, ref tp] = check_arg_count(args)?;
let result = this.clock_gettime(clk_id, tp)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
@ -76,18 +76,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Querying system information
"pthread_attr_getstack" => {
// We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here.
let &[attr_place, addr_place, size_place] = check_arg_count(args)?;
let &[ref attr_place, ref addr_place, ref size_place] = check_arg_count(args)?;
this.deref_operand(attr_place)?;
let addr_place = this.deref_operand(addr_place)?;
let size_place = this.deref_operand(size_place)?;
this.write_scalar(
Scalar::from_uint(STACK_ADDR, this.pointer_size()),
addr_place.into(),
&addr_place.into(),
)?;
this.write_scalar(
Scalar::from_uint(STACK_SIZE, this.pointer_size()),
size_place.into(),
&size_place.into(),
)?;
// Return success (`0`).
@ -96,17 +96,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Threading
"prctl" => {
let &[option, arg2, arg3, arg4, arg5] = check_arg_count(args)?;
let &[ref option, ref arg2, ref arg3, ref arg4, ref arg5] = check_arg_count(args)?;
let result = this.prctl(option, arg2, arg3, arg4, arg5)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_condattr_setclock" => {
let &[attr, clock_id] = check_arg_count(args)?;
let &[ref attr, ref clock_id] = check_arg_count(args)?;
let result = this.pthread_condattr_setclock(attr, clock_id)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"pthread_condattr_getclock" => {
let &[attr, clock_id] = check_arg_count(args)?;
let &[ref attr, ref clock_id] = check_arg_count(args)?;
let result = this.pthread_condattr_getclock(attr, clock_id)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
@ -137,7 +137,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
if args.is_empty() {
throw_ub_format!("incorrect number of arguments for syscall: got 0, expected at least 1");
}
match this.read_scalar(args[0])?.to_machine_usize(this)? {
match this.read_scalar(&args[0])?.to_machine_usize(this)? {
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
// is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
id if id == sys_getrandom => {
@ -145,7 +145,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
if args.len() < 4 {
throw_ub_format!("incorrect number of arguments for `getrandom` syscall: got {}, expected at least 4", args.len());
}
getrandom(this, args[1], args[2], args[3], dest)?;
getrandom(this, &args[1], &args[2], &args[3], dest)?;
}
// `statx` is used by `libstd` to retrieve metadata information on `linux`
// instead of using `stat`,`lstat` or `fstat` as on `macos`.
@ -154,7 +154,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
if args.len() < 6 {
throw_ub_format!("incorrect number of arguments for `statx` syscall: got {}, expected at least 6", args.len());
}
let result = this.linux_statx(args[1], args[2], args[3], args[4], args[5])?;
let result = this.linux_statx(&args[1], &args[2], &args[3], &args[4], &args[5])?;
this.write_scalar(Scalar::from_machine_isize(result.into(), this), dest)?;
}
// `futex` is used by some synchonization primitives.
@ -167,11 +167,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Miscelanneous
"getrandom" => {
let &[ptr, len, flags] = check_arg_count(args)?;
let &[ref ptr, ref len, ref flags] = check_arg_count(args)?;
getrandom(this, ptr, len, flags, dest)?;
}
"sched_getaffinity" => {
let &[pid, cpusetsize, mask] = check_arg_count(args)?;
let &[ref pid, ref cpusetsize, ref mask] = check_arg_count(args)?;
this.read_scalar(pid)?.to_i32()?;
this.read_scalar(cpusetsize)?.to_machine_usize(this)?;
this.deref_operand(mask)?;
@ -184,7 +184,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Incomplete shims that we "stub out" just to get pre-main initialization code to work.
// These shims are enabled only when the caller is in the standard library.
"pthread_getattr_np" if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
let &[_thread, _attr] = check_arg_count(args)?;
let &[ref _thread, ref _attr] = check_arg_count(args)?;
this.write_null(dest)?;
}
@ -198,10 +198,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Shims the linux `getrandom` syscall.
fn getrandom<'tcx>(
this: &mut MiriEvalContext<'_, 'tcx>,
ptr: OpTy<'tcx, Tag>,
len: OpTy<'tcx, Tag>,
flags: OpTy<'tcx, Tag>,
dest: PlaceTy<'tcx, Tag>,
ptr: &OpTy<'tcx, Tag>,
len: &OpTy<'tcx, Tag>,
flags: &OpTy<'tcx, Tag>,
dest: &PlaceTy<'tcx, Tag>,
) -> InterpResult<'tcx> {
let ptr = this.read_scalar(ptr)?.check_init()?;
let len = this.read_scalar(len)?.to_machine_usize(this)?;

View File

@ -7,7 +7,7 @@ use std::time::{Instant, SystemTime};
pub fn futex<'tcx>(
this: &mut MiriEvalContext<'_, 'tcx>,
args: &[OpTy<'tcx, Tag>],
dest: PlaceTy<'tcx, Tag>,
dest: &PlaceTy<'tcx, Tag>,
) -> InterpResult<'tcx> {
// The amount of arguments used depends on the type of futex operation.
// The full futex syscall takes six arguments (excluding the syscall
@ -24,9 +24,9 @@ pub fn futex<'tcx>(
// The first three arguments (after the syscall number itself) are the same to all futex operations:
// (int *addr, int op, int val).
// We checked above that these definitely exist.
let addr = this.read_immediate(args[1])?;
let op = this.read_scalar(args[2])?.to_i32()?;
let val = this.read_scalar(args[3])?.to_i32()?;
let addr = this.read_immediate(&args[1])?;
let op = this.read_scalar(&args[2])?.to_i32()?;
let val = this.read_scalar(&args[3])?.to_i32()?;
// The raw pointer value is used to identify the mutex.
// Not all mutex operations actually read from this address or even require this address to exist.
@ -51,7 +51,7 @@ pub fn futex<'tcx>(
if args.len() < 5 {
throw_ub_format!("incorrect number of arguments for `futex` syscall with `op=FUTEX_WAIT`: got {}, expected at least 5", args.len());
}
let timeout = args[4];
let timeout = &args[4];
let timeout_time = if this.is_null(this.read_scalar(timeout)?.check_init()?)? {
None
} else {
@ -88,7 +88,7 @@ pub fn futex<'tcx>(
// SeqCst is total order over all operations.
// FIXME: check if this should be changed when weak memory orders are added.
let futex_val = this.read_scalar_at_offset_atomic(
addr.into(), 0, this.machine.layouts.i32, AtomicReadOp::SeqCst
&addr.into(), 0, this.machine.layouts.i32, AtomicReadOp::SeqCst
)?.to_i32()?;
if val == futex_val {
// The value still matches, so we block the trait make it wait for FUTEX_WAKE.
@ -98,6 +98,7 @@ pub fn futex<'tcx>(
this.write_scalar(Scalar::from_machine_isize(0, this), dest)?;
// Register a timeout callback if a timeout was specified.
// This callback will override the return value when the timeout triggers.
let dest = *dest;
if let Some(timeout_time) = timeout_time {
this.register_timeout_callback(
thread,
@ -107,7 +108,7 @@ pub fn futex<'tcx>(
this.futex_remove_waiter(futex_ptr, thread);
let etimedout = this.eval_libc("ETIMEDOUT")?;
this.set_last_error(etimedout)?;
this.write_scalar(Scalar::from_machine_isize(-1, this), dest)?;
this.write_scalar(Scalar::from_machine_isize(-1, this), &dest)?;
Ok(())
}),
);

View File

@ -28,7 +28,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
&mut self,
dlsym: Dlsym,
args: &[OpTy<'tcx, Tag>],
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let (dest, ret) = ret.expect("we don't support any diverging dlsym");
@ -36,7 +36,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
match dlsym {
Dlsym::getentropy => {
let &[ptr, len] = check_arg_count(args)?;
let &[ref ptr, ref len] = check_arg_count(args)?;
let ptr = this.read_scalar(ptr)?.check_init()?;
let len = this.read_scalar(len)?.to_machine_usize(this)?;
this.gen_random(ptr, len)?;
@ -44,7 +44,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
trace!("{:?}", this.dump_place(*dest));
trace!("{:?}", this.dump_place(**dest));
this.go_to_block(ret);
Ok(())
}

View File

@ -11,7 +11,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
&mut self,
link_name: &str,
args: &[OpTy<'tcx, Tag>],
dest: PlaceTy<'tcx, Tag>,
dest: &PlaceTy<'tcx, Tag>,
_ret: mir::BasicBlock,
) -> InterpResult<'tcx, bool> {
let this = self.eval_context_mut();
@ -26,37 +26,37 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// File related shims
"close" | "close$NOCANCEL" => {
let &[result] = check_arg_count(args)?;
let &[ref result] = check_arg_count(args)?;
let result = this.close(result)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"stat" | "stat$INODE64" => {
let &[path, buf] = check_arg_count(args)?;
let &[ref path, ref buf] = check_arg_count(args)?;
let result = this.macos_stat(path, buf)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"lstat" | "lstat$INODE64" => {
let &[path, buf] = check_arg_count(args)?;
let &[ref path, ref buf] = check_arg_count(args)?;
let result = this.macos_lstat(path, buf)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"fstat" | "fstat$INODE64" => {
let &[fd, buf] = check_arg_count(args)?;
let &[ref fd, ref buf] = check_arg_count(args)?;
let result = this.macos_fstat(fd, buf)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"opendir" | "opendir$INODE64" => {
let &[name] = check_arg_count(args)?;
let &[ref name] = check_arg_count(args)?;
let result = this.opendir(name)?;
this.write_scalar(result, dest)?;
}
"readdir_r" | "readdir_r$INODE64" => {
let &[dirp, entry, result] = check_arg_count(args)?;
let &[ref dirp, ref entry, ref result] = check_arg_count(args)?;
let result = this.macos_readdir_r(dirp, entry, result)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"ftruncate" => {
let &[fd, length] = check_arg_count(args)?;
let &[ref fd, ref length] = check_arg_count(args)?;
let result = this.ftruncate64(fd, length)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
@ -69,7 +69,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Time related shims
"gettimeofday" => {
let &[tv, tz] = check_arg_count(args)?;
let &[ref tv, ref tz] = check_arg_count(args)?;
let result = this.gettimeofday(tv, tz)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
@ -80,7 +80,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"mach_timebase_info" => {
let &[info] = check_arg_count(args)?;
let &[ref info] = check_arg_count(args)?;
let result = this.mach_timebase_info(info)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
},
@ -97,7 +97,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Thread-local storage
"_tlv_atexit" => {
let &[dtor, data] = check_arg_count(args)?;
let &[ref dtor, ref data] = check_arg_count(args)?;
let dtor = this.read_scalar(dtor)?.check_init()?;
let dtor = this.memory.get_fn(dtor)?.as_instance()?;
let data = this.read_scalar(data)?.check_init()?;
@ -107,13 +107,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Querying system information
"pthread_get_stackaddr_np" => {
let &[thread] = check_arg_count(args)?;
let &[ref thread] = check_arg_count(args)?;
this.read_scalar(thread)?.to_machine_usize(this)?;
let stack_addr = Scalar::from_uint(STACK_ADDR, this.pointer_size());
this.write_scalar(stack_addr, dest)?;
}
"pthread_get_stacksize_np" => {
let &[thread] = check_arg_count(args)?;
let &[ref thread] = check_arg_count(args)?;
this.read_scalar(thread)?.to_machine_usize(this)?;
let stack_size = Scalar::from_uint(STACK_SIZE, this.pointer_size());
this.write_scalar(stack_size, dest)?;
@ -121,7 +121,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Threading
"pthread_setname_np" => {
let &[name] = check_arg_count(args)?;
let &[ref name] = check_arg_count(args)?;
let name = this.read_scalar(name)?.check_init()?;
this.pthread_setname_np(name)?;
}
@ -130,7 +130,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// These shims are enabled only when the caller is in the standard library.
"mmap" if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
// This is a horrible hack, but since the guard page mechanism calls mmap and expects a particular return value, we just give it that value.
let &[addr, _, _, _, _, _] = check_arg_count(args)?;
let &[ref addr, _, _, _, _, _] = check_arg_count(args)?;
let addr = this.read_scalar(addr)?.check_init()?;
this.write_scalar(addr, dest)?;
}

View File

@ -35,14 +35,14 @@ fn is_mutex_kind_normal<'mir, 'tcx: 'mir>(
fn mutexattr_get_kind<'mir, 'tcx: 'mir>(
ecx: &MiriEvalContext<'mir, 'tcx>,
attr_op: OpTy<'tcx, Tag>,
attr_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
ecx.read_scalar_at_offset(attr_op, 0, ecx.machine.layouts.i32)
}
fn mutexattr_set_kind<'mir, 'tcx: 'mir>(
ecx: &mut MiriEvalContext<'mir, 'tcx>,
attr_op: OpTy<'tcx, Tag>,
attr_op: &OpTy<'tcx, Tag>,
kind: impl Into<ScalarMaybeUninit<Tag>>,
) -> InterpResult<'tcx, ()> {
ecx.write_scalar_at_offset(attr_op, 0, kind, ecx.machine.layouts.i32)
@ -59,7 +59,7 @@ fn mutexattr_set_kind<'mir, 'tcx: 'mir>(
fn mutex_get_kind<'mir, 'tcx: 'mir>(
ecx: &mut MiriEvalContext<'mir, 'tcx>,
mutex_op: OpTy<'tcx, Tag>,
mutex_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
let offset = if ecx.pointer_size().bytes() == 8 { 16 } else { 12 };
ecx.read_scalar_at_offset_atomic(
@ -70,7 +70,7 @@ fn mutex_get_kind<'mir, 'tcx: 'mir>(
fn mutex_set_kind<'mir, 'tcx: 'mir>(
ecx: &mut MiriEvalContext<'mir, 'tcx>,
mutex_op: OpTy<'tcx, Tag>,
mutex_op: &OpTy<'tcx, Tag>,
kind: impl Into<ScalarMaybeUninit<Tag>>,
) -> InterpResult<'tcx, ()> {
let offset = if ecx.pointer_size().bytes() == 8 { 16 } else { 12 };
@ -82,7 +82,7 @@ fn mutex_set_kind<'mir, 'tcx: 'mir>(
fn mutex_get_id<'mir, 'tcx: 'mir>(
ecx: &MiriEvalContext<'mir, 'tcx>,
mutex_op: OpTy<'tcx, Tag>,
mutex_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
ecx.read_scalar_at_offset_atomic(
mutex_op, 4, ecx.machine.layouts.u32,
@ -92,7 +92,7 @@ fn mutex_get_id<'mir, 'tcx: 'mir>(
fn mutex_set_id<'mir, 'tcx: 'mir>(
ecx: &mut MiriEvalContext<'mir, 'tcx>,
mutex_op: OpTy<'tcx, Tag>,
mutex_op: &OpTy<'tcx, Tag>,
id: impl Into<ScalarMaybeUninit<Tag>>,
) -> InterpResult<'tcx, ()> {
ecx.write_scalar_at_offset_atomic(
@ -103,7 +103,7 @@ fn mutex_set_id<'mir, 'tcx: 'mir>(
fn mutex_get_or_create_id<'mir, 'tcx: 'mir>(
ecx: &mut MiriEvalContext<'mir, 'tcx>,
mutex_op: OpTy<'tcx, Tag>,
mutex_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, MutexId> {
let id = mutex_get_id(ecx, mutex_op)?.to_u32()?;
if id == 0 {
@ -126,7 +126,7 @@ fn mutex_get_or_create_id<'mir, 'tcx: 'mir>(
fn rwlock_get_id<'mir, 'tcx: 'mir>(
ecx: &MiriEvalContext<'mir, 'tcx>,
rwlock_op: OpTy<'tcx, Tag>,
rwlock_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
ecx.read_scalar_at_offset_atomic(
rwlock_op, 4, ecx.machine.layouts.u32,
@ -136,7 +136,7 @@ fn rwlock_get_id<'mir, 'tcx: 'mir>(
fn rwlock_set_id<'mir, 'tcx: 'mir>(
ecx: &mut MiriEvalContext<'mir, 'tcx>,
rwlock_op: OpTy<'tcx, Tag>,
rwlock_op: &OpTy<'tcx, Tag>,
id: impl Into<ScalarMaybeUninit<Tag>>,
) -> InterpResult<'tcx, ()> {
ecx.write_scalar_at_offset_atomic(
@ -147,7 +147,7 @@ fn rwlock_set_id<'mir, 'tcx: 'mir>(
fn rwlock_get_or_create_id<'mir, 'tcx: 'mir>(
ecx: &mut MiriEvalContext<'mir, 'tcx>,
rwlock_op: OpTy<'tcx, Tag>,
rwlock_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, RwLockId> {
let id = rwlock_get_id(ecx, rwlock_op)?.to_u32()?;
if id == 0 {
@ -169,14 +169,14 @@ fn rwlock_get_or_create_id<'mir, 'tcx: 'mir>(
fn condattr_get_clock_id<'mir, 'tcx: 'mir>(
ecx: &MiriEvalContext<'mir, 'tcx>,
attr_op: OpTy<'tcx, Tag>,
attr_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
ecx.read_scalar_at_offset(attr_op, 0, ecx.machine.layouts.i32)
}
fn condattr_set_clock_id<'mir, 'tcx: 'mir>(
ecx: &mut MiriEvalContext<'mir, 'tcx>,
attr_op: OpTy<'tcx, Tag>,
attr_op: &OpTy<'tcx, Tag>,
clock_id: impl Into<ScalarMaybeUninit<Tag>>,
) -> InterpResult<'tcx, ()> {
ecx.write_scalar_at_offset(attr_op, 0, clock_id, ecx.machine.layouts.i32)
@ -193,7 +193,7 @@ fn condattr_set_clock_id<'mir, 'tcx: 'mir>(
fn cond_get_id<'mir, 'tcx: 'mir>(
ecx: &MiriEvalContext<'mir, 'tcx>,
cond_op: OpTy<'tcx, Tag>,
cond_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
ecx.read_scalar_at_offset_atomic(
cond_op, 4, ecx.machine.layouts.u32,
@ -203,7 +203,7 @@ fn cond_get_id<'mir, 'tcx: 'mir>(
fn cond_set_id<'mir, 'tcx: 'mir>(
ecx: &mut MiriEvalContext<'mir, 'tcx>,
cond_op: OpTy<'tcx, Tag>,
cond_op: &OpTy<'tcx, Tag>,
id: impl Into<ScalarMaybeUninit<Tag>>,
) -> InterpResult<'tcx, ()> {
ecx.write_scalar_at_offset_atomic(
@ -214,7 +214,7 @@ fn cond_set_id<'mir, 'tcx: 'mir>(
fn cond_get_or_create_id<'mir, 'tcx: 'mir>(
ecx: &mut MiriEvalContext<'mir, 'tcx>,
cond_op: OpTy<'tcx, Tag>,
cond_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, CondvarId> {
let id = cond_get_id(ecx, cond_op)?.to_u32()?;
if id == 0 {
@ -230,14 +230,14 @@ fn cond_get_or_create_id<'mir, 'tcx: 'mir>(
fn cond_get_clock_id<'mir, 'tcx: 'mir>(
ecx: &MiriEvalContext<'mir, 'tcx>,
cond_op: OpTy<'tcx, Tag>,
cond_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
ecx.read_scalar_at_offset(cond_op, 8, ecx.machine.layouts.i32)
}
fn cond_set_clock_id<'mir, 'tcx: 'mir>(
ecx: &mut MiriEvalContext<'mir, 'tcx>,
cond_op: OpTy<'tcx, Tag>,
cond_op: &OpTy<'tcx, Tag>,
clock_id: impl Into<ScalarMaybeUninit<Tag>>,
) -> InterpResult<'tcx, ()> {
ecx.write_scalar_at_offset(cond_op, 8, clock_id, ecx.machine.layouts.i32)
@ -294,7 +294,7 @@ fn release_cond_mutex_and_block<'mir, 'tcx: 'mir>(
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
fn pthread_mutexattr_init(&mut self, attr_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_mutexattr_init(&mut self, attr_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let default_kind = this.eval_libc("PTHREAD_MUTEX_DEFAULT")?;
@ -305,8 +305,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn pthread_mutexattr_settype(
&mut self,
attr_op: OpTy<'tcx, Tag>,
kind_op: OpTy<'tcx, Tag>,
attr_op: &OpTy<'tcx, Tag>,
kind_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -344,7 +344,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
Ok(0)
}
fn pthread_mutexattr_destroy(&mut self, attr_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_mutexattr_destroy(&mut self, attr_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
mutexattr_set_kind(this, attr_op, ScalarMaybeUninit::Uninit)?;
@ -354,8 +354,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn pthread_mutex_init(
&mut self,
mutex_op: OpTy<'tcx, Tag>,
attr_op: OpTy<'tcx, Tag>,
mutex_op: &OpTy<'tcx, Tag>,
attr_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -374,7 +374,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
Ok(0)
}
fn pthread_mutex_lock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_mutex_lock(&mut self, mutex_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let kind = mutex_get_kind(this, mutex_op)?.check_init()?;
@ -411,7 +411,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
fn pthread_mutex_trylock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_mutex_trylock(&mut self, mutex_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let kind = mutex_get_kind(this, mutex_op)?.check_init()?;
@ -444,7 +444,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
fn pthread_mutex_unlock(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_mutex_unlock(&mut self, mutex_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let kind = mutex_get_kind(this, mutex_op)?.check_init()?;
@ -476,7 +476,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
fn pthread_mutex_destroy(&mut self, mutex_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_mutex_destroy(&mut self, mutex_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let id = mutex_get_or_create_id(this, mutex_op)?;
@ -492,7 +492,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
Ok(0)
}
fn pthread_rwlock_rdlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_rwlock_rdlock(&mut self, rwlock_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let id = rwlock_get_or_create_id(this, rwlock_op)?;
@ -507,7 +507,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
fn pthread_rwlock_tryrdlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_rwlock_tryrdlock(&mut self, rwlock_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let id = rwlock_get_or_create_id(this, rwlock_op)?;
@ -521,7 +521,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
fn pthread_rwlock_wrlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_rwlock_wrlock(&mut self, rwlock_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let id = rwlock_get_or_create_id(this, rwlock_op)?;
@ -548,7 +548,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
Ok(0)
}
fn pthread_rwlock_trywrlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_rwlock_trywrlock(&mut self, rwlock_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let id = rwlock_get_or_create_id(this, rwlock_op)?;
@ -562,7 +562,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
fn pthread_rwlock_unlock(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_rwlock_unlock(&mut self, rwlock_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let id = rwlock_get_or_create_id(this, rwlock_op)?;
@ -577,7 +577,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
fn pthread_rwlock_destroy(&mut self, rwlock_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_rwlock_destroy(&mut self, rwlock_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let id = rwlock_get_or_create_id(this, rwlock_op)?;
@ -592,7 +592,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
Ok(0)
}
fn pthread_condattr_init(&mut self, attr_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_condattr_init(&mut self, attr_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
// The default value of the clock attribute shall refer to the system
@ -606,8 +606,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn pthread_condattr_setclock(
&mut self,
attr_op: OpTy<'tcx, Tag>,
clock_id_op: OpTy<'tcx, Tag>,
attr_op: &OpTy<'tcx, Tag>,
clock_id_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -626,18 +626,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn pthread_condattr_getclock(
&mut self,
attr_op: OpTy<'tcx, Tag>,
clk_id_op: OpTy<'tcx, Tag>,
attr_op: &OpTy<'tcx, Tag>,
clk_id_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let clock_id = condattr_get_clock_id(this, attr_op)?;
this.write_scalar(clock_id, this.deref_operand(clk_id_op)?.into())?;
this.write_scalar(clock_id, &this.deref_operand(clk_id_op)?.into())?;
Ok(0)
}
fn pthread_condattr_destroy(&mut self, attr_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_condattr_destroy(&mut self, attr_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
condattr_set_clock_id(this, attr_op, ScalarMaybeUninit::Uninit)?;
@ -647,8 +647,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn pthread_cond_init(
&mut self,
cond_op: OpTy<'tcx, Tag>,
attr_op: OpTy<'tcx, Tag>,
cond_op: &OpTy<'tcx, Tag>,
attr_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -667,7 +667,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
Ok(0)
}
fn pthread_cond_signal(&mut self, cond_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_cond_signal(&mut self, cond_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let id = cond_get_or_create_id(this, cond_op)?;
if let Some((thread, mutex)) = this.condvar_signal(id) {
@ -677,7 +677,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
Ok(0)
}
fn pthread_cond_broadcast(&mut self, cond_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_cond_broadcast(&mut self, cond_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let id = cond_get_or_create_id(this, cond_op)?;
@ -690,8 +690,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn pthread_cond_wait(
&mut self,
cond_op: OpTy<'tcx, Tag>,
mutex_op: OpTy<'tcx, Tag>,
cond_op: &OpTy<'tcx, Tag>,
mutex_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -707,10 +707,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn pthread_cond_timedwait(
&mut self,
cond_op: OpTy<'tcx, Tag>,
mutex_op: OpTy<'tcx, Tag>,
abstime_op: OpTy<'tcx, Tag>,
dest: PlaceTy<'tcx, Tag>,
cond_op: &OpTy<'tcx, Tag>,
mutex_op: &OpTy<'tcx, Tag>,
abstime_op: &OpTy<'tcx, Tag>,
dest: &PlaceTy<'tcx, Tag>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
@ -745,6 +745,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// We return success for now and override it in the timeout callback.
this.write_scalar(Scalar::from_i32(0), dest)?;
let dest = *dest;
// Register the timeout callback.
this.register_timeout_callback(
active_thread,
@ -759,7 +761,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Set the return value: we timed out.
let etimedout = ecx.eval_libc("ETIMEDOUT")?;
ecx.write_scalar(etimedout, dest)?;
ecx.write_scalar(etimedout, &dest)?;
Ok(())
}),
@ -768,7 +770,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
Ok(())
}
fn pthread_cond_destroy(&mut self, cond_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_cond_destroy(&mut self, cond_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let id = cond_get_or_create_id(this, cond_op)?;

View File

@ -7,10 +7,10 @@ impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tc
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
fn pthread_create(
&mut self,
thread: OpTy<'tcx, Tag>,
_attr: OpTy<'tcx, Tag>,
start_routine: OpTy<'tcx, Tag>,
arg: OpTy<'tcx, Tag>,
thread: &OpTy<'tcx, Tag>,
_attr: &OpTy<'tcx, Tag>,
start_routine: &OpTy<'tcx, Tag>,
arg: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -26,7 +26,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let thread_info_place = this.deref_operand(thread)?;
this.write_scalar(
Scalar::from_uint(new_thread_id.to_u32(), thread_info_place.layout.size),
thread_info_place.into(),
&thread_info_place.into(),
)?;
// Read the function argument that will be sent to the new thread
@ -51,7 +51,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.call_function(
instance,
&[*func_arg],
Some(ret_place.into()),
Some(&ret_place.into()),
StackPopCleanup::None { cleanup: true },
)?;
@ -63,8 +63,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn pthread_join(
&mut self,
thread: OpTy<'tcx, Tag>,
retval: OpTy<'tcx, Tag>,
thread: &OpTy<'tcx, Tag>,
retval: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -79,7 +79,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
Ok(0)
}
fn pthread_detach(&mut self, thread: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn pthread_detach(&mut self, thread: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
let thread_id = this.read_scalar(thread)?.to_machine_usize(this)?;
@ -88,7 +88,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
Ok(0)
}
fn pthread_self(&mut self, dest: PlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
fn pthread_self(&mut self, dest: &PlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let thread_id = this.get_active_thread();
@ -97,11 +97,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn prctl(
&mut self,
option: OpTy<'tcx, Tag>,
arg2: OpTy<'tcx, Tag>,
_arg3: OpTy<'tcx, Tag>,
_arg4: OpTy<'tcx, Tag>,
_arg5: OpTy<'tcx, Tag>,
option: &OpTy<'tcx, Tag>,
arg2: &OpTy<'tcx, Tag>,
_arg3: &OpTy<'tcx, Tag>,
_arg4: &OpTy<'tcx, Tag>,
_arg5: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
this.assert_target_os("linux", "prctl");

View File

@ -16,8 +16,8 @@ impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mi
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
fn clock_gettime(
&mut self,
clk_id_op: OpTy<'tcx, Tag>,
tp_op: OpTy<'tcx, Tag>,
clk_id_op: &OpTy<'tcx, Tag>,
tp_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -47,15 +47,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
immty_from_int_checked(tv_nsec, this.libc_ty_layout("c_long")?)?,
];
this.write_packed_immediates(tp, &imms)?;
this.write_packed_immediates(&tp, &imms)?;
Ok(0)
}
fn gettimeofday(
&mut self,
tv_op: OpTy<'tcx, Tag>,
tz_op: OpTy<'tcx, Tag>,
tv_op: &OpTy<'tcx, Tag>,
tz_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
@ -81,13 +81,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
immty_from_int_checked(tv_usec, this.libc_ty_layout("suseconds_t")?)?,
];
this.write_packed_immediates(tv, &imms)?;
this.write_packed_immediates(&tv, &imms)?;
Ok(0)
}
#[allow(non_snake_case)]
fn GetSystemTimeAsFileTime(&mut self, LPFILETIME_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx> {
fn GetSystemTimeAsFileTime(&mut self, LPFILETIME_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
this.assert_target_os("windows", "GetSystemTimeAsFileTime");
@ -110,12 +110,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
immty_from_uint_checked(dwLowDateTime, DWORD_tylayout)?,
immty_from_uint_checked(dwHighDateTime, DWORD_tylayout)?,
];
this.write_packed_immediates(this.deref_operand(LPFILETIME_op)?, &imms)?;
this.write_packed_immediates(&this.deref_operand(LPFILETIME_op)?, &imms)?;
Ok(())
}
#[allow(non_snake_case)]
fn QueryPerformanceCounter(&mut self, lpPerformanceCount_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn QueryPerformanceCounter(&mut self, lpPerformanceCount_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
this.assert_target_os("windows", "QueryPerformanceCounter");
@ -126,12 +126,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let duration = Instant::now().duration_since(this.machine.time_anchor);
let qpc = i64::try_from(duration.as_nanos())
.map_err(|_| err_unsup_format!("programs running longer than 2^63 nanoseconds are not supported"))?;
this.write_scalar(Scalar::from_i64(qpc), this.deref_operand(lpPerformanceCount_op)?.into())?;
this.write_scalar(Scalar::from_i64(qpc), &this.deref_operand(lpPerformanceCount_op)?.into())?;
Ok(-1) // return non-zero on success
}
#[allow(non_snake_case)]
fn QueryPerformanceFrequency(&mut self, lpFrequency_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn QueryPerformanceFrequency(&mut self, lpFrequency_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
this.assert_target_os("windows", "QueryPerformanceFrequency");
@ -142,7 +142,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// is consistent across all processors.
// Miri emulates a "hardware" performance counter with a resolution of 1ns,
// and thus 10^9 counts per second.
this.write_scalar(Scalar::from_i64(1_000_000_000), this.deref_operand(lpFrequency_op)?.into())?;
this.write_scalar(Scalar::from_i64(1_000_000_000), &this.deref_operand(lpFrequency_op)?.into())?;
Ok(-1) // Return non-zero on success
}
@ -159,7 +159,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
.map_err(|_| err_unsup_format!("programs running longer than 2^64 nanoseconds are not supported").into())
}
fn mach_timebase_info(&mut self, info_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn mach_timebase_info(&mut self, info_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
this.assert_target_os("macos", "mach_timebase_info");
@ -175,14 +175,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
immty_from_int_checked(denom, this.machine.layouts.u32)?
];
this.write_packed_immediates(info, &imms)?;
this.write_packed_immediates(&info, &imms)?;
Ok(0) // KERN_SUCCESS
}
fn nanosleep(
&mut self,
req_op: OpTy<'tcx, Tag>,
_rem: OpTy<'tcx, Tag>,
req_op: &OpTy<'tcx, Tag>,
_rem: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
// Signal handlers are not supported, so rem will never be written to.

View File

@ -245,7 +245,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.call_function(
thread_callback,
&[Scalar::null_ptr(this).into(), reason.into(), Scalar::null_ptr(this).into()],
Some(ret_place),
Some(&ret_place),
StackPopCleanup::None { cleanup: true },
)?;
@ -267,7 +267,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.call_function(
instance,
&[data.into()],
Some(ret_place),
Some(&ret_place),
StackPopCleanup::None { cleanup: true },
)?;
@ -307,7 +307,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.call_function(
instance,
&[ptr.into()],
Some(ret_place),
Some(&ret_place),
StackPopCleanup::None { cleanup: true },
)?;

View File

@ -26,7 +26,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
dlsym: Dlsym,
abi: Abi,
_args: &[OpTy<'tcx, Tag>],
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let (_dest, _ret) = ret.expect("we don't support any diverging dlsym");

View File

@ -15,7 +15,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
link_name: &str,
abi: Abi,
args: &[OpTy<'tcx, Tag>],
dest: PlaceTy<'tcx, Tag>,
dest: &PlaceTy<'tcx, Tag>,
_ret: mir::BasicBlock,
) -> InterpResult<'tcx, bool> {
let this = self.eval_context_mut();
@ -30,12 +30,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
match link_name {
// Environment related shims
"GetEnvironmentVariableW" => {
let &[name, buf, size] = check_arg_count(args)?;
let &[ref name, ref buf, ref size] = check_arg_count(args)?;
let result = this.GetEnvironmentVariableW(name, buf, size)?;
this.write_scalar(Scalar::from_u32(result), dest)?;
}
"SetEnvironmentVariableW" => {
let &[name, value] = check_arg_count(args)?;
let &[ref name, ref value] = check_arg_count(args)?;
let result = this.SetEnvironmentVariableW(name, value)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
@ -45,38 +45,38 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_scalar(result, dest)?;
}
"FreeEnvironmentStringsW" => {
let &[env_block] = check_arg_count(args)?;
let &[ref env_block] = check_arg_count(args)?;
let result = this.FreeEnvironmentStringsW(env_block)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"GetCurrentDirectoryW" => {
let &[size, buf] = check_arg_count(args)?;
let &[ref size, ref buf] = check_arg_count(args)?;
let result = this.GetCurrentDirectoryW(size, buf)?;
this.write_scalar(Scalar::from_u32(result), dest)?;
}
"SetCurrentDirectoryW" => {
let &[path] = check_arg_count(args)?;
let &[ref path] = check_arg_count(args)?;
let result = this.SetCurrentDirectoryW(path)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
// File related shims
"GetStdHandle" => {
let &[which] = check_arg_count(args)?;
let &[ref which] = check_arg_count(args)?;
let which = this.read_scalar(which)?.to_i32()?;
// We just make this the identity function, so we know later in `WriteFile`
// which one it is.
this.write_scalar(Scalar::from_machine_isize(which.into(), this), dest)?;
}
"WriteFile" => {
let &[handle, buf, n, written_ptr, overlapped] = check_arg_count(args)?;
let &[ref handle, ref buf, ref n, ref written_ptr, ref overlapped] = check_arg_count(args)?;
this.read_scalar(overlapped)?.to_machine_usize(this)?; // this is a poiner, that we ignore
let handle = this.read_scalar(handle)?.to_machine_isize(this)?;
let buf = this.read_scalar(buf)?.check_init()?;
let n = this.read_scalar(n)?.to_u32()?;
let written_place = this.deref_operand(written_ptr)?;
// Spec says to always write `0` first.
this.write_null(written_place.into())?;
this.write_null(&written_place.into())?;
let written = if handle == -11 || handle == -12 {
// stdout/stderr
use std::io::{self, Write};
@ -93,7 +93,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
};
// If there was no error, write back how much was written.
if let Some(n) = written {
this.write_scalar(Scalar::from_u32(n), written_place.into())?;
this.write_scalar(Scalar::from_u32(n), &written_place.into())?;
}
// Return whether this was a success.
this.write_scalar(
@ -104,7 +104,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Allocation
"HeapAlloc" => {
let &[handle, flags, size] = check_arg_count(args)?;
let &[ref handle, ref flags, ref size] = check_arg_count(args)?;
this.read_scalar(handle)?.to_machine_isize(this)?;
let flags = this.read_scalar(flags)?.to_u32()?;
let size = this.read_scalar(size)?.to_machine_usize(this)?;
@ -113,7 +113,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_scalar(res, dest)?;
}
"HeapFree" => {
let &[handle, flags, ptr] = check_arg_count(args)?;
let &[ref handle, ref flags, ref ptr] = check_arg_count(args)?;
this.read_scalar(handle)?.to_machine_isize(this)?;
this.read_scalar(flags)?.to_u32()?;
let ptr = this.read_scalar(ptr)?.check_init()?;
@ -121,7 +121,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_scalar(Scalar::from_i32(1), dest)?;
}
"HeapReAlloc" => {
let &[handle, flags, ptr, size] = check_arg_count(args)?;
let &[ref handle, ref flags, ref ptr, ref size] = check_arg_count(args)?;
this.read_scalar(handle)?.to_machine_isize(this)?;
this.read_scalar(flags)?.to_u32()?;
let ptr = this.read_scalar(ptr)?.check_init()?;
@ -132,7 +132,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// errno
"SetLastError" => {
let &[error] = check_arg_count(args)?;
let &[ref error] = check_arg_count(args)?;
let error = this.read_scalar(error)?.check_init()?;
this.set_last_error(error)?;
}
@ -144,7 +144,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Querying system information
"GetSystemInfo" => {
let &[system_info] = check_arg_count(args)?;
let &[ref system_info] = check_arg_count(args)?;
let system_info = this.deref_operand(system_info)?;
// Initialize with `0`.
this.memory.write_bytes(
@ -153,8 +153,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
)?;
// Set number of processors.
let dword_size = Size::from_bytes(4);
let num_cpus = this.mplace_field(system_info, 6)?;
this.write_scalar(Scalar::from_int(NUM_CPUS, dword_size), num_cpus.into())?;
let num_cpus = this.mplace_field(&system_info, 6)?;
this.write_scalar(Scalar::from_int(NUM_CPUS, dword_size), &num_cpus.into())?;
}
// Thread-local storage
@ -167,14 +167,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_scalar(Scalar::from_uint(key, dest.layout.size), dest)?;
}
"TlsGetValue" => {
let &[key] = check_arg_count(args)?;
let &[ref key] = check_arg_count(args)?;
let key = u128::from(this.read_scalar(key)?.to_u32()?);
let active_thread = this.get_active_thread();
let ptr = this.machine.tls.load_tls(key, active_thread, this)?;
this.write_scalar(ptr, dest)?;
}
"TlsSetValue" => {
let &[key, new_ptr] = check_arg_count(args)?;
let &[ref key, ref new_ptr] = check_arg_count(args)?;
let key = u128::from(this.read_scalar(key)?.to_u32()?);
let active_thread = this.get_active_thread();
let new_ptr = this.read_scalar(new_ptr)?.check_init()?;
@ -196,46 +196,46 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Time related shims
"GetSystemTimeAsFileTime" => {
#[allow(non_snake_case)]
let &[LPFILETIME] = check_arg_count(args)?;
let &[ref LPFILETIME] = check_arg_count(args)?;
this.GetSystemTimeAsFileTime(LPFILETIME)?;
}
"QueryPerformanceCounter" => {
#[allow(non_snake_case)]
let &[lpPerformanceCount] = check_arg_count(args)?;
let &[ref lpPerformanceCount] = check_arg_count(args)?;
let result = this.QueryPerformanceCounter(lpPerformanceCount)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"QueryPerformanceFrequency" => {
#[allow(non_snake_case)]
let &[lpFrequency] = check_arg_count(args)?;
let &[ref lpFrequency] = check_arg_count(args)?;
let result = this.QueryPerformanceFrequency(lpFrequency)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
// Synchronization primitives
"AcquireSRWLockExclusive" => {
let &[ptr] = check_arg_count(args)?;
let &[ref ptr] = check_arg_count(args)?;
this.AcquireSRWLockExclusive(ptr)?;
}
"ReleaseSRWLockExclusive" => {
let &[ptr] = check_arg_count(args)?;
let &[ref ptr] = check_arg_count(args)?;
this.ReleaseSRWLockExclusive(ptr)?;
}
"TryAcquireSRWLockExclusive" => {
let &[ptr] = check_arg_count(args)?;
let &[ref ptr] = check_arg_count(args)?;
let ret = this.TryAcquireSRWLockExclusive(ptr)?;
this.write_scalar(Scalar::from_u8(ret), dest)?;
}
"AcquireSRWLockShared" => {
let &[ptr] = check_arg_count(args)?;
let &[ref ptr] = check_arg_count(args)?;
this.AcquireSRWLockShared(ptr)?;
}
"ReleaseSRWLockShared" => {
let &[ptr] = check_arg_count(args)?;
let &[ref ptr] = check_arg_count(args)?;
this.ReleaseSRWLockShared(ptr)?;
}
"TryAcquireSRWLockShared" => {
let &[ptr] = check_arg_count(args)?;
let &[ref ptr] = check_arg_count(args)?;
let ret = this.TryAcquireSRWLockShared(ptr)?;
this.write_scalar(Scalar::from_u8(ret), dest)?;
}
@ -243,7 +243,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Dynamic symbol loading
"GetProcAddress" => {
#[allow(non_snake_case)]
let &[hModule, lpProcName] = check_arg_count(args)?;
let &[ref hModule, ref lpProcName] = check_arg_count(args)?;
this.read_scalar(hModule)?.to_machine_isize(this)?;
let name = this.memory.read_c_str(this.read_scalar(lpProcName)?.check_init()?)?;
if let Some(dlsym) = Dlsym::from_str(name, &this.tcx.sess.target.os)? {
@ -257,7 +257,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Miscellaneous
"SystemFunction036" => {
// The actual name of 'RtlGenRandom'
let &[ptr, len] = check_arg_count(args)?;
let &[ref ptr, ref len] = check_arg_count(args)?;
let ptr = this.read_scalar(ptr)?.check_init()?;
let len = this.read_scalar(len)?.to_u32()?;
this.gen_random(ptr, len.into())?;
@ -265,7 +265,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"GetConsoleScreenBufferInfo" => {
// `term` needs this, so we fake it.
let &[console, buffer_info] = check_arg_count(args)?;
let &[ref console, ref buffer_info] = check_arg_count(args)?;
this.read_scalar(console)?.to_machine_isize(this)?;
this.deref_operand(buffer_info)?;
// Indicate an error.
@ -274,7 +274,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"GetConsoleMode" => {
// Windows "isatty" (in libtest) needs this, so we fake it.
let &[console, mode] = check_arg_count(args)?;
let &[ref console, ref mode] = check_arg_count(args)?;
this.read_scalar(console)?.to_machine_isize(this)?;
this.deref_operand(mode)?;
// Indicate an error.
@ -302,13 +302,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"SetConsoleTextAttribute" if this.frame().instance.to_string().starts_with("std::sys::windows::") => {
#[allow(non_snake_case)]
let &[_hConsoleOutput, _wAttribute] = check_arg_count(args)?;
let &[ref _hConsoleOutput, ref _wAttribute] = check_arg_count(args)?;
// Pretend these does not exist / nothing happened, by returning zero.
this.write_null(dest)?;
}
"AddVectoredExceptionHandler" if this.frame().instance.to_string().starts_with("std::sys::windows::") => {
#[allow(non_snake_case)]
let &[_First, _Handler] = check_arg_count(args)?;
let &[ref _First, ref _Handler] = check_arg_count(args)?;
// Any non zero value works for the stdlib. This is just used for stack overflows anyway.
this.write_scalar(Scalar::from_machine_usize(1, this), dest)?;
}
@ -324,7 +324,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
| "DeleteCriticalSection"
if this.frame().instance.to_string().starts_with("std::sys::windows::") => {
#[allow(non_snake_case)]
let &[_lpCriticalSection] = check_arg_count(args)?;
let &[ref _lpCriticalSection] = check_arg_count(args)?;
assert_eq!(this.get_total_thread_count(), 1, "concurrency on Windows is not supported");
// Nothing to do, not even a return value.
// (Windows locks are reentrant, and we have only 1 thread,
@ -333,7 +333,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
"TryEnterCriticalSection"
if this.frame().instance.to_string().starts_with("std::sys::windows::") => {
#[allow(non_snake_case)]
let &[_lpCriticalSection] = check_arg_count(args)?;
let &[ref _lpCriticalSection] = check_arg_count(args)?;
assert_eq!(this.get_total_thread_count(), 1, "concurrency on Windows is not supported");
// There is only one thread, so this always succeeds and returns TRUE.
this.write_scalar(Scalar::from_i32(1), dest)?;

View File

@ -5,7 +5,7 @@ use crate::*;
fn srwlock_get_or_create_id<'mir, 'tcx: 'mir>(
ecx: &mut MiriEvalContext<'mir, 'tcx>,
lock_op: OpTy<'tcx, Tag>,
lock_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, RwLockId> {
let id = ecx.read_scalar_at_offset(lock_op, 0, ecx.machine.layouts.u32)?.to_u32()?;
if id == 0 {
@ -24,7 +24,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
#[allow(non_snake_case)]
fn AcquireSRWLockExclusive(
&mut self,
lock_op: OpTy<'tcx, Tag>,
lock_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let id = srwlock_get_or_create_id(this, lock_op)?;
@ -49,7 +49,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
#[allow(non_snake_case)]
fn TryAcquireSRWLockExclusive(
&mut self,
lock_op: OpTy<'tcx, Tag>,
lock_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, u8> {
let this = self.eval_context_mut();
let id = srwlock_get_or_create_id(this, lock_op)?;
@ -67,7 +67,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
#[allow(non_snake_case)]
fn ReleaseSRWLockExclusive(
&mut self,
lock_op: OpTy<'tcx, Tag>,
lock_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let id = srwlock_get_or_create_id(this, lock_op)?;
@ -84,7 +84,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
#[allow(non_snake_case)]
fn AcquireSRWLockShared(
&mut self,
lock_op: OpTy<'tcx, Tag>,
lock_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let id = srwlock_get_or_create_id(this, lock_op)?;
@ -102,7 +102,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
#[allow(non_snake_case)]
fn TryAcquireSRWLockShared(
&mut self,
lock_op: OpTy<'tcx, Tag>,
lock_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, u8> {
let this = self.eval_context_mut();
let id = srwlock_get_or_create_id(this, lock_op)?;
@ -119,7 +119,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
#[allow(non_snake_case)]
fn ReleaseSRWLockShared(
&mut self,
lock_op: OpTy<'tcx, Tag>,
lock_op: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let id = srwlock_get_or_create_id(this, lock_op)?;

View File

@ -521,7 +521,7 @@ impl<'mir, 'tcx: 'mir> EvalContextPrivExt<'mir, 'tcx> for crate::MiriEvalContext
trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
fn reborrow(
&mut self,
place: MPlaceTy<'tcx, Tag>,
place: &MPlaceTy<'tcx, Tag>,
size: Size,
kind: RefKind,
new_tag: Tag,
@ -577,7 +577,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
/// `mutbl` can be `None` to make this a raw pointer.
fn retag_reference(
&mut self,
val: ImmTy<'tcx, Tag>,
val: &ImmTy<'tcx, Tag>,
kind: RefKind,
protect: bool,
) -> InterpResult<'tcx, ImmTy<'tcx, Tag>> {
@ -585,7 +585,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// We want a place for where the ptr *points to*, so we get one.
let place = this.ref_to_mplace(val)?;
let size = this
.size_and_align_of_mplace(place)?
.size_and_align_of_mplace(&place)?
.map(|(size, _)| size)
.unwrap_or_else(|| place.layout.size);
// `reborrow` relies on getting a `Pointer` and everything being in-bounds,
@ -595,7 +595,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let place = this.mplace_access_checked(place, Some(Align::from_bytes(1).unwrap()))?;
// Nothing to do for ZSTs.
if size == Size::ZERO {
return Ok(val);
return Ok(*val);
}
// Compute new borrow.
@ -610,7 +610,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
};
// Reborrow.
this.reborrow(place, size, kind, new_tag, protect)?;
this.reborrow(&place, size, kind, new_tag, protect)?;
let new_place = place.replace_tag(new_tag);
// Return new pointer.
@ -620,7 +620,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
fn retag(&mut self, kind: RetagKind, place: PlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
fn retag(&mut self, kind: RetagKind, place: &PlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
// Determine mutability and whether to add a protector.
// Cannot use `builtin_deref` because that reports *immutable* for `Box`,
@ -649,8 +649,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// but might also cost us optimization and analyses. We will have to experiment more with this.
if let Some((mutbl, protector)) = qualify(place.layout.ty, kind) {
// Fast path.
let val = this.read_immediate(this.place_to_op(place)?)?;
let val = this.retag_reference(val, mutbl, protector)?;
let val = this.read_immediate(&this.place_to_op(place)?)?;
let val = this.retag_reference(&val, mutbl, protector)?;
this.write_immediate(*val, place)?;
}
@ -675,16 +675,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
return Ok(());
}
// We need this to be in-memory to use tagged pointers.
let return_place = this.force_allocation(return_place)?;
let return_place = this.force_allocation(&return_place)?;
// We have to turn the place into a pointer to use the existing code.
// (The pointer type does not matter, so we use a raw pointer.)
let ptr_layout = this.layout_of(this.tcx.mk_mut_ptr(return_place.layout.ty))?;
let val = ImmTy::from_immediate(return_place.to_ref(), ptr_layout);
// Reborrow it.
let val = this.retag_reference(val, RefKind::Unique { two_phase: false }, /*protector*/ true)?;
let val = this.retag_reference(&val, RefKind::Unique { two_phase: false }, /*protector*/ true)?;
// And use reborrowed pointer for return place.
let return_place = this.ref_to_mplace(val)?;
let return_place = this.ref_to_mplace(&val)?;
this.frame_mut().return_place = Some(return_place.into());
Ok(())