}
// Store command line as UTF-16 for Windows `GetCommandLineW`.
{
- let tcx = &{ ecx.tcx.tcx };
let cmd_utf16: Vec<u16> = cmd.encode_utf16().collect();
let cmd_ptr = ecx.memory.allocate(
Size::from_bytes(cmd_utf16.len() as u64 * 2),
let mut cur_ptr = cmd_ptr;
for &c in cmd_utf16.iter() {
cmd_alloc.write_scalar(
- tcx,
+ &*ecx.tcx,
cur_ptr,
Scalar::from_uint(c, char_size).into(),
char_size,
)?;
- cur_ptr = cur_ptr.offset(char_size, tcx)?;
+ cur_ptr = cur_ptr.offset(char_size, &*ecx.tcx)?;
}
}
rng.fill_bytes(&mut data);
}
- let tcx = &{this.tcx.tcx};
- this.memory.get_mut(ptr.alloc_id)?.write_bytes(tcx, ptr, &data)
+ this.memory.get_mut(ptr.alloc_id)?.write_bytes(&*this.tcx, ptr, &data)
}
/// Visits the memory covered by `place`, sensitive to freezing: the 3rd parameter
/// Helper function to get the `TyLayout` of a `libc` type
fn libc_ty_layout(&mut self, name: &str) -> InterpResult<'tcx, TyLayout<'tcx>> {
let this = self.eval_context_mut();
- let tcx = &{ this.tcx.tcx };
- let ty = this.resolve_path(&["libc", name])?.ty(*tcx);
+ let ty = this.resolve_path(&["libc", name])?.ty(*this.tcx);
this.layout_of(ty)
}
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
- let tcx = &{ this.tcx.tcx };
-
let mut offset = Size::from_bytes(0);
for &imm in imms {
this.write_immediate_to_mplace(
*imm,
- place.offset(offset, None, imm.layout, tcx)?,
+ place.offset(offset, None, imm.layout, &*this.tcx)?,
)?;
offset += imm.layout.size;
}
this.check_no_isolation("getcwd")?;
- let tcx = &{ this.tcx.tcx };
-
let buf = this.force_ptr(this.read_scalar(buf_op)?.not_undef()?)?;
- let size = this.read_scalar(size_op)?.to_usize(&*tcx)?;
+ let size = this.read_scalar(size_op)?.to_usize(&*this.tcx)?;
// If we cannot get the current directory, we return null
match env::current_dir() {
Ok(cwd) => {
// `bytes.len()`, meaning that `bytes` actually fit inside tbe buffer.
this.memory
.get_mut(buf.alloc_id)?
- .write_bytes(tcx, buf, &bytes)?;
+ .write_bytes(&*this.tcx, buf, &bytes)?;
return Ok(Scalar::Ptr(buf));
}
let erange = this.eval_libc("ERANGE")?;
}
Err(e) => this.consume_io_error(e)?,
}
- Ok(Scalar::ptr_null(&*tcx))
+ Ok(Scalar::ptr_null(&*this.tcx))
}
fn chdir(&mut self, path_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
fn malloc(&mut self, size: u64, zero_init: bool, kind: MiriMemoryKind) -> Scalar<Tag> {
let this = self.eval_context_mut();
- let tcx = &{ this.tcx.tcx };
if size == 0 {
Scalar::from_int(0, this.pointer_size())
} else {
this.memory
.get_mut(ptr.alloc_id)
.unwrap()
- .write_repeat(tcx, ptr, 0, Size::from_bytes(size))
+ .write_repeat(&*this.tcx, ptr, 0, Size::from_bytes(size))
.unwrap();
}
Scalar::Ptr(ptr)
}
} else {
let old_ptr = this.force_ptr(old_ptr)?;
- let memory = &mut this.memory;
if new_size == 0 {
- memory.deallocate(old_ptr, None, kind.into())?;
+ this.memory.deallocate(old_ptr, None, kind.into())?;
Ok(Scalar::from_int(0, this.pointer_size()))
} else {
- let new_ptr = memory.reallocate(
+ let new_ptr = this.memory.reallocate(
old_ptr,
None,
Size::from_bytes(new_size),
// for the TLS destructors, and of course `eval_main`.
let mir = this.load_mir(f_instance.def, None)?;
let ret_place =
- MPlaceTy::dangling(this.layout_of(this.tcx.mk_unit())?, this).into();
+ MPlaceTy::dangling(this.layout_of(tcx.mk_unit())?, this).into();
this.push_stack_frame(
f_instance,
mir.span,
"write" => {
let fd = this.read_scalar(args[0])?.to_i32()?;
let buf = this.read_scalar(args[1])?.not_undef()?;
- let n = this.read_scalar(args[2])?.to_usize(&*this.tcx)?;
+ let n = this.read_scalar(args[2])?.to_usize(tcx)?;
trace!("Called write({:?}, {:?}, {:?})", fd, buf, n);
let result = if fd == 1 || fd == 2 {
// stdout/stderr
fn set_last_error(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
- let tcx = &{ this.tcx.tcx };
let errno_ptr = this.machine.last_error.unwrap();
this.memory.get_mut(errno_ptr.alloc_id)?.write_scalar(
- tcx,
+ &*this.tcx,
errno_ptr,
scalar.into(),
Size::from_bits(32),
fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar<Tag>> {
let this = self.eval_context_mut();
- let tcx = &{ this.tcx.tcx };
let errno_ptr = this.machine.last_error.unwrap();
this.memory
.get(errno_ptr.alloc_id)?
- .read_scalar(tcx, errno_ptr, Size::from_bits(32))?
+ .read_scalar(&*this.tcx, errno_ptr, Size::from_bits(32))?
.not_undef()
}
this.check_no_isolation("read")?;
- let tcx = &{ this.tcx.tcx };
-
let count = this.read_scalar(count_op)?.to_usize(&*this.tcx)?;
// Reading zero bytes should not change `buf`
if count == 0 {
let bytes = this.force_ptr(buf_scalar).and_then(|buf| {
this.memory
.get_mut(buf.alloc_id)?
- .get_bytes_mut(tcx, buf, Size::from_bytes(count))
+ .get_bytes_mut(&*this.tcx, buf, Size::from_bytes(count))
.map(|buffer| handle.file.read(buffer))
});
// Reinsert the file handle
this.check_no_isolation("write")?;
- let tcx = &{ this.tcx.tcx };
-
let count = this.read_scalar(count_op)?.to_usize(&*this.tcx)?;
// Writing zero bytes should not change `buf`
if count == 0 {
this.remove_handle_and(fd, |mut handle, this| {
let bytes = this.memory.get(buf.alloc_id).and_then(|alloc| {
alloc
- .get_bytes(tcx, buf, Size::from_bytes(count))
+ .get_bytes(&*this.tcx, buf, Size::from_bytes(count))
.map(|bytes| handle.file.write(bytes).map(|bytes| bytes as i64))
});
this.machine.file_handler.handles.insert(fd, handle);
// (as opposed to through a place), we have to remember to erase any tag
// that might still hang around!
- let intrinsic_name = &*this.tcx.item_name(instance.def_id()).as_str();
+ let intrinsic_name = &*tcx.item_name(instance.def_id()).as_str();
match intrinsic_name {
"arith_offset" => {
let offset = this.read_scalar(args[1])?.to_isize(this)?;