Auto merge of #1004 - JohnTitor:use-memory, r=RalfJung
Use memory field instead of memory() Rustup for rust-lang/rust#65319
This commit is contained in:
commit
fbc1d91f79
11 changed files with 73 additions and 73 deletions
|
|
@ -1 +1 @@
|
|||
d28a9c38fe14396e86ae274c7847e20ee0f78ca9
|
||||
fa0f7d0080d8e7e9eb20aa9cbf8013f96c81287f
|
||||
|
|
|
|||
12
src/eval.rs
12
src/eval.rs
|
|
@ -93,7 +93,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
|
|||
|
||||
// First argument: pointer to `main()`.
|
||||
let main_ptr = ecx
|
||||
.memory_mut()
|
||||
.memory
|
||||
.create_fn_alloc(FnVal::Instance(main_instance));
|
||||
let dest = ecx.local_place(args.next().unwrap())?;
|
||||
ecx.write_scalar(Scalar::Ptr(main_ptr), dest)?;
|
||||
|
|
@ -128,7 +128,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
|
|||
let mut arg = arg.into_bytes();
|
||||
arg.push(0);
|
||||
argvs.push(
|
||||
ecx.memory_mut()
|
||||
ecx.memory
|
||||
.allocate_static_bytes(arg.as_slice(), MiriMemoryKind::Static.into()),
|
||||
);
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
|
|||
let place = ecx.mplace_field(argvs_place, idx as u64)?;
|
||||
ecx.write_scalar(Scalar::Ptr(arg), place.into())?;
|
||||
}
|
||||
ecx.memory_mut()
|
||||
ecx.memory
|
||||
.mark_immutable(argvs_place.ptr.assert_ptr().alloc_id)?;
|
||||
// Write a pointer to that place as the argument.
|
||||
let argv = argvs_place.ptr;
|
||||
|
|
@ -157,7 +157,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
|
|||
{
|
||||
let tcx = &{ ecx.tcx.tcx };
|
||||
let cmd_utf16: Vec<u16> = cmd.encode_utf16().collect();
|
||||
let cmd_ptr = ecx.memory_mut().allocate(
|
||||
let cmd_ptr = ecx.memory.allocate(
|
||||
Size::from_bytes(cmd_utf16.len() as u64 * 2),
|
||||
Align::from_bytes(2).unwrap(),
|
||||
MiriMemoryKind::Env.into(),
|
||||
|
|
@ -165,7 +165,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
|
|||
ecx.machine.cmd_line = Some(cmd_ptr);
|
||||
// Store the UTF-16 string.
|
||||
let char_size = Size::from_bytes(2);
|
||||
let cmd_alloc = ecx.memory_mut().get_mut(cmd_ptr.alloc_id)?;
|
||||
let cmd_alloc = ecx.memory.get_mut(cmd_ptr.alloc_id)?;
|
||||
let mut cur_ptr = cmd_ptr;
|
||||
for &c in cmd_utf16.iter() {
|
||||
cmd_alloc.write_scalar(
|
||||
|
|
@ -211,7 +211,7 @@ pub fn eval_main<'tcx>(tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig) {
|
|||
// Process the result.
|
||||
match res {
|
||||
Ok(()) => {
|
||||
let leaks = ecx.memory().leak_report();
|
||||
let leaks = ecx.memory.leak_report();
|
||||
// Disable the leak test on some platforms where we do not
|
||||
// correctly implement TLS destructors.
|
||||
let target_os = ecx.tcx.tcx.sess.target.target.target_os.to_lowercase();
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
/// Test if this immediate equals 0.
|
||||
fn is_null(&self, val: Scalar<Tag>) -> InterpResult<'tcx, bool> {
|
||||
let this = self.eval_context_ref();
|
||||
let null = Scalar::from_int(0, this.memory().pointer_size());
|
||||
let null = Scalar::from_int(0, this.memory.pointer_size());
|
||||
this.ptr_eq(val, null)
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
}
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let ptr = this.memory().check_ptr_access(
|
||||
let ptr = this.memory.check_ptr_access(
|
||||
ptr,
|
||||
Size::from_bytes(len as u64),
|
||||
Align::from_bytes(1).unwrap()
|
||||
|
|
@ -108,12 +108,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
.map_err(|err| err_unsup_format!("getrandom failed: {}", err))?;
|
||||
}
|
||||
else {
|
||||
let rng = this.memory_mut().extra.rng.get_mut();
|
||||
let rng = this.memory.extra.rng.get_mut();
|
||||
rng.fill_bytes(&mut data);
|
||||
}
|
||||
|
||||
let tcx = &{this.tcx.tcx};
|
||||
this.memory_mut().get_mut(ptr.alloc_id)?.write_bytes(tcx, ptr, &data)
|
||||
this.memory.get_mut(ptr.alloc_id)?.write_bytes(tcx, ptr, &data)
|
||||
}
|
||||
|
||||
/// Visits the memory covered by `place`, sensitive to freezing: the 3rd parameter
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
|
|||
|
||||
#[inline(always)]
|
||||
fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
|
||||
ecx.memory().extra.validate
|
||||
ecx.memory.extra.validate
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
@ -349,7 +349,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
|
|||
fn stack_push(
|
||||
ecx: &mut InterpCx<'mir, 'tcx, Self>,
|
||||
) -> InterpResult<'tcx, stacked_borrows::CallId> {
|
||||
Ok(ecx.memory().extra.stacked_borrows.borrow_mut().new_call())
|
||||
Ok(ecx.memory.extra.stacked_borrows.borrow_mut().new_call())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
@ -358,7 +358,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
|
|||
extra: stacked_borrows::CallId,
|
||||
) -> InterpResult<'tcx> {
|
||||
Ok(ecx
|
||||
.memory()
|
||||
.memory
|
||||
.extra
|
||||
.stacked_borrows
|
||||
.borrow_mut()
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
|
|||
/// Test if the pointer is in-bounds of a live allocation.
|
||||
#[inline]
|
||||
fn pointer_inbounds(&self, ptr: Pointer<Tag>) -> InterpResult<'tcx> {
|
||||
let (size, _align) = self.memory().get_size_and_align(ptr.alloc_id, AllocCheck::Live)?;
|
||||
let (size, _align) = self.memory.get_size_and_align(ptr.alloc_id, AllocCheck::Live)?;
|
||||
ptr.check_inbounds_alloc(size, CheckInAllocMsg::InboundsTest)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ impl EnvVars {
|
|||
for (name, value) in env::vars() {
|
||||
if !excluded_env_vars.contains(&name) {
|
||||
let var_ptr =
|
||||
alloc_env_var(name.as_bytes(), value.as_bytes(), ecx.memory_mut());
|
||||
alloc_env_var(name.as_bytes(), value.as_bytes(), &mut ecx.memory);
|
||||
ecx.machine.env_vars.map.insert(name.into_bytes(), var_ptr);
|
||||
}
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
let this = self.eval_context_mut();
|
||||
|
||||
let name_ptr = this.read_scalar(name_op)?.not_undef()?;
|
||||
let name = this.memory().read_c_str(name_ptr)?;
|
||||
let name = this.memory.read_c_str(name_ptr)?;
|
||||
Ok(match this.machine.env_vars.map.get(name) {
|
||||
// The offset is used to strip the "{name}=" part of the string.
|
||||
Some(var_ptr) => {
|
||||
|
|
@ -71,18 +71,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
|
||||
let name_ptr = this.read_scalar(name_op)?.not_undef()?;
|
||||
let value_ptr = this.read_scalar(value_op)?.not_undef()?;
|
||||
let value = this.memory().read_c_str(value_ptr)?;
|
||||
let value = this.memory.read_c_str(value_ptr)?;
|
||||
let mut new = None;
|
||||
if !this.is_null(name_ptr)? {
|
||||
let name = this.memory().read_c_str(name_ptr)?;
|
||||
let name = this.memory.read_c_str(name_ptr)?;
|
||||
if !name.is_empty() && !name.contains(&b'=') {
|
||||
new = Some((name.to_owned(), value.to_owned()));
|
||||
}
|
||||
}
|
||||
if let Some((name, value)) = new {
|
||||
let var_ptr = alloc_env_var(&name, &value, this.memory_mut());
|
||||
let var_ptr = alloc_env_var(&name, &value, &mut this.memory);
|
||||
if let Some(var) = this.machine.env_vars.map.insert(name.to_owned(), var_ptr) {
|
||||
this.memory_mut()
|
||||
this.memory
|
||||
.deallocate(var, None, MiriMemoryKind::Env.into())?;
|
||||
}
|
||||
Ok(0)
|
||||
|
|
@ -97,14 +97,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
let name_ptr = this.read_scalar(name_op)?.not_undef()?;
|
||||
let mut success = None;
|
||||
if !this.is_null(name_ptr)? {
|
||||
let name = this.memory().read_c_str(name_ptr)?.to_owned();
|
||||
let name = this.memory.read_c_str(name_ptr)?.to_owned();
|
||||
if !name.is_empty() && !name.contains(&b'=') {
|
||||
success = Some(this.machine.env_vars.map.remove(&name));
|
||||
}
|
||||
}
|
||||
if let Some(old) = success {
|
||||
if let Some(var) = old {
|
||||
this.memory_mut()
|
||||
this.memory
|
||||
.deallocate(var, None, MiriMemoryKind::Env.into())?;
|
||||
}
|
||||
Ok(0)
|
||||
|
|
@ -140,7 +140,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
// This is ok because the buffer was strictly larger than `bytes`, so after
|
||||
// adding the null terminator, the buffer size is larger or equal to
|
||||
// `bytes.len()`, meaning that `bytes` actually fit inside tbe buffer.
|
||||
this.memory_mut()
|
||||
this.memory
|
||||
.get_mut(buf.alloc_id)?
|
||||
.write_bytes(tcx, buf, &bytes)?;
|
||||
return Ok(Scalar::Ptr(buf));
|
||||
|
|
@ -159,7 +159,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
this.check_no_isolation("chdir")?;
|
||||
|
||||
let path_bytes = this
|
||||
.memory()
|
||||
.memory
|
||||
.read_c_str(this.read_scalar(path_op)?.not_undef()?)?;
|
||||
|
||||
let path = Path::new(
|
||||
|
|
|
|||
|
|
@ -48,11 +48,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
} else {
|
||||
let align = this.min_align(size, kind);
|
||||
let ptr = this
|
||||
.memory_mut()
|
||||
.memory
|
||||
.allocate(Size::from_bytes(size), align, kind.into());
|
||||
if zero_init {
|
||||
// We just allocated this, the access cannot fail
|
||||
this.memory_mut()
|
||||
this.memory
|
||||
.get_mut(ptr.alloc_id)
|
||||
.unwrap()
|
||||
.write_repeat(tcx, ptr, 0, Size::from_bytes(size))
|
||||
|
|
@ -66,7 +66,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
let this = self.eval_context_mut();
|
||||
if !this.is_null(ptr)? {
|
||||
let ptr = this.force_ptr(ptr)?;
|
||||
this.memory_mut().deallocate(ptr, None, kind.into())?;
|
||||
this.memory.deallocate(ptr, None, kind.into())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -84,13 +84,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
Ok(Scalar::from_int(0, this.pointer_size()))
|
||||
} else {
|
||||
let new_ptr =
|
||||
this.memory_mut()
|
||||
this.memory
|
||||
.allocate(Size::from_bytes(new_size), new_align, kind.into());
|
||||
Ok(Scalar::Ptr(new_ptr))
|
||||
}
|
||||
} else {
|
||||
let old_ptr = this.force_ptr(old_ptr)?;
|
||||
let memory = this.memory_mut();
|
||||
let memory = &mut this.memory;
|
||||
if new_size == 0 {
|
||||
memory.deallocate(old_ptr, None, kind.into())?;
|
||||
Ok(Scalar::from_int(0, this.pointer_size()))
|
||||
|
|
@ -179,7 +179,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
if size == 0 {
|
||||
this.write_null(ret.into())?;
|
||||
} else {
|
||||
let ptr = this.memory_mut().allocate(
|
||||
let ptr = this.memory.allocate(
|
||||
Size::from_bytes(size),
|
||||
Align::from_bytes(align).unwrap(),
|
||||
MiriMemoryKind::C.into(),
|
||||
|
|
@ -208,7 +208,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
if !align.is_power_of_two() {
|
||||
throw_unsup!(HeapAllocNonPowerOfTwoAlignment(align));
|
||||
}
|
||||
let ptr = this.memory_mut().allocate(
|
||||
let ptr = this.memory.allocate(
|
||||
Size::from_bytes(size),
|
||||
Align::from_bytes(align).unwrap(),
|
||||
MiriMemoryKind::Rust.into(),
|
||||
|
|
@ -224,13 +224,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
if !align.is_power_of_two() {
|
||||
throw_unsup!(HeapAllocNonPowerOfTwoAlignment(align));
|
||||
}
|
||||
let ptr = this.memory_mut().allocate(
|
||||
let ptr = this.memory.allocate(
|
||||
Size::from_bytes(size),
|
||||
Align::from_bytes(align).unwrap(),
|
||||
MiriMemoryKind::Rust.into(),
|
||||
);
|
||||
// We just allocated this, the access cannot fail
|
||||
this.memory_mut()
|
||||
this.memory
|
||||
.get_mut(ptr.alloc_id)
|
||||
.unwrap()
|
||||
.write_repeat(tcx, ptr, 0, Size::from_bytes(size))
|
||||
|
|
@ -248,7 +248,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
throw_unsup!(HeapAllocNonPowerOfTwoAlignment(align));
|
||||
}
|
||||
let ptr = this.force_ptr(ptr)?;
|
||||
this.memory_mut().deallocate(
|
||||
this.memory.deallocate(
|
||||
ptr,
|
||||
Some((
|
||||
Size::from_bytes(old_size),
|
||||
|
|
@ -269,7 +269,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
throw_unsup!(HeapAllocNonPowerOfTwoAlignment(align));
|
||||
}
|
||||
let align = Align::from_bytes(align).unwrap();
|
||||
let new_ptr = this.memory_mut().reallocate(
|
||||
let new_ptr = this.memory.reallocate(
|
||||
ptr,
|
||||
Some((Size::from_bytes(old_size), align)),
|
||||
Size::from_bytes(new_size),
|
||||
|
|
@ -304,11 +304,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
"dlsym" => {
|
||||
let _handle = this.read_scalar(args[0])?;
|
||||
let symbol = this.read_scalar(args[1])?.not_undef()?;
|
||||
let symbol_name = this.memory().read_c_str(symbol)?;
|
||||
let symbol_name = this.memory.read_c_str(symbol)?;
|
||||
let err = format!("bad c unicode symbol: {:?}", symbol_name);
|
||||
let symbol_name = ::std::str::from_utf8(symbol_name).unwrap_or(&err);
|
||||
if let Some(dlsym) = Dlsym::from_str(symbol_name)? {
|
||||
let ptr = this.memory_mut().create_fn_alloc(FnVal::Other(dlsym));
|
||||
let ptr = this.memory.create_fn_alloc(FnVal::Other(dlsym));
|
||||
this.write_scalar(Scalar::from(ptr), dest)?;
|
||||
} else {
|
||||
this.write_null(dest)?;
|
||||
|
|
@ -325,7 +325,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
// We abort on panic, so not much is going on here, but we still have to call the closure.
|
||||
let f = this.read_scalar(args[0])?.not_undef()?;
|
||||
let data = this.read_scalar(args[1])?.not_undef()?;
|
||||
let f_instance = this.memory().get_fn(f)?.as_instance()?;
|
||||
let f_instance = this.memory.get_fn(f)?.as_instance()?;
|
||||
this.write_null(dest)?;
|
||||
trace!("__rust_maybe_catch_panic: {:?}", f_instance);
|
||||
|
||||
|
|
@ -369,8 +369,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
let n = Size::from_bytes(this.read_scalar(args[2])?.to_usize(this)?);
|
||||
|
||||
let result = {
|
||||
let left_bytes = this.memory().read_bytes(left, n)?;
|
||||
let right_bytes = this.memory().read_bytes(right, n)?;
|
||||
let left_bytes = this.memory.read_bytes(left, n)?;
|
||||
let right_bytes = this.memory.read_bytes(right, n)?;
|
||||
|
||||
use std::cmp::Ordering::*;
|
||||
match left_bytes.cmp(right_bytes) {
|
||||
|
|
@ -388,7 +388,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
let val = this.read_scalar(args[1])?.to_i32()? as u8;
|
||||
let num = this.read_scalar(args[2])?.to_usize(this)?;
|
||||
if let Some(idx) = this
|
||||
.memory()
|
||||
.memory
|
||||
.read_bytes(ptr, Size::from_bytes(num))?
|
||||
.iter()
|
||||
.rev()
|
||||
|
|
@ -406,7 +406,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
let val = this.read_scalar(args[1])?.to_i32()? as u8;
|
||||
let num = this.read_scalar(args[2])?.to_usize(this)?;
|
||||
let idx = this
|
||||
.memory()
|
||||
.memory
|
||||
.read_bytes(ptr, Size::from_bytes(num))?
|
||||
.iter()
|
||||
.position(|&c| c == val);
|
||||
|
|
@ -477,7 +477,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
// stdout/stderr
|
||||
use std::io::{self, Write};
|
||||
|
||||
let buf_cont = this.memory().read_bytes(buf, Size::from_bytes(n))?;
|
||||
let buf_cont = this.memory.read_bytes(buf, Size::from_bytes(n))?;
|
||||
// We need to flush to make sure this actually appears on the screen
|
||||
let res = if fd == 1 {
|
||||
// Stdout is buffered, flush to make sure it appears on the screen.
|
||||
|
|
@ -519,7 +519,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
|
||||
"strlen" => {
|
||||
let ptr = this.read_scalar(args[0])?.not_undef()?;
|
||||
let n = this.memory().read_c_str(ptr)?.len();
|
||||
let n = this.memory.read_c_str(ptr)?.len();
|
||||
this.write_scalar(Scalar::from_uint(n as u64, dest.layout.size), dest)?;
|
||||
}
|
||||
|
||||
|
|
@ -649,7 +649,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
|
||||
// Extract the function type out of the signature (that seems easier than constructing it ourselves).
|
||||
let dtor = match this.test_null(this.read_scalar(args[1])?.not_undef()?)? {
|
||||
Some(dtor_ptr) => Some(this.memory().get_fn(dtor_ptr)?.as_instance()?),
|
||||
Some(dtor_ptr) => Some(this.memory.get_fn(dtor_ptr)?.as_instance()?),
|
||||
None => None,
|
||||
};
|
||||
|
||||
|
|
@ -671,10 +671,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
}
|
||||
|
||||
let key_ptr = this
|
||||
.memory()
|
||||
.memory
|
||||
.check_ptr_access(key_ptr, key_layout.size, key_layout.align.abi)?
|
||||
.expect("cannot be a ZST");
|
||||
this.memory_mut().get_mut(key_ptr.alloc_id)?.write_scalar(
|
||||
this.memory.get_mut(key_ptr.alloc_id)?.write_scalar(
|
||||
tcx,
|
||||
key_ptr,
|
||||
Scalar::from_uint(key, key_layout.size).into(),
|
||||
|
|
@ -859,13 +859,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
.check_mplace_access(system_info, None)?
|
||||
.expect("cannot be a ZST");
|
||||
// Initialize with `0`.
|
||||
this.memory_mut()
|
||||
this.memory
|
||||
.get_mut(system_info_ptr.alloc_id)?
|
||||
.write_repeat(tcx, system_info_ptr, 0, system_info.layout.size)?;
|
||||
// Set number of processors.
|
||||
let dword_size = Size::from_bytes(4);
|
||||
let offset = 2 * dword_size + 3 * tcx.pointer_size();
|
||||
this.memory_mut()
|
||||
this.memory
|
||||
.get_mut(system_info_ptr.alloc_id)?
|
||||
.write_scalar(
|
||||
tcx,
|
||||
|
|
@ -920,7 +920,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
use std::io::{self, Write};
|
||||
|
||||
let buf_cont = this
|
||||
.memory()
|
||||
.memory
|
||||
.read_bytes(buf, Size::from_bytes(u64::from(n)))?;
|
||||
let res = if handle == -11 {
|
||||
io::stdout().write(buf_cont)
|
||||
|
|
@ -995,7 +995,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
let this = self.eval_context_mut();
|
||||
let tcx = &{ this.tcx.tcx };
|
||||
let errno_ptr = this.machine.last_error.unwrap();
|
||||
this.memory_mut().get_mut(errno_ptr.alloc_id)?.write_scalar(
|
||||
this.memory.get_mut(errno_ptr.alloc_id)?.write_scalar(
|
||||
tcx,
|
||||
errno_ptr,
|
||||
scalar.into(),
|
||||
|
|
@ -1007,7 +1007,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
let this = self.eval_context_mut();
|
||||
let tcx = &{ this.tcx.tcx };
|
||||
let errno_ptr = this.machine.last_error.unwrap();
|
||||
this.memory()
|
||||
this.memory
|
||||
.get(errno_ptr.alloc_id)?
|
||||
.read_scalar(tcx, errno_ptr, Size::from_bits(32))?
|
||||
.not_undef()
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
}
|
||||
|
||||
let path_bytes = this
|
||||
.memory()
|
||||
.memory
|
||||
.read_c_str(this.read_scalar(path_op)?.not_undef()?)?;
|
||||
let path = std::str::from_utf8(path_bytes)
|
||||
.map_err(|_| err_unsup_format!("{:?} is not a valid utf-8 string", path_bytes))?;
|
||||
|
|
@ -171,7 +171,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
this.remove_handle_and(fd, |mut handle, this| {
|
||||
// Don't use `?` to avoid returning before reinserting the handle
|
||||
let bytes = this.force_ptr(buf_scalar).and_then(|buf| {
|
||||
this.memory_mut()
|
||||
this.memory
|
||||
.get_mut(buf.alloc_id)?
|
||||
.get_bytes_mut(tcx, buf, Size::from_bytes(count))
|
||||
.map(|buffer| handle.file.read(buffer))
|
||||
|
|
@ -203,7 +203,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
let buf = this.force_ptr(this.read_scalar(buf_op)?.not_undef()?)?;
|
||||
|
||||
this.remove_handle_and(fd, |mut handle, this| {
|
||||
let bytes = this.memory().get(buf.alloc_id).and_then(|alloc| {
|
||||
let bytes = this.memory.get(buf.alloc_id).and_then(|alloc| {
|
||||
alloc
|
||||
.get_bytes(tcx, buf, Size::from_bytes(count))
|
||||
.map(|bytes| handle.file.write(bytes).map(|bytes| bytes as i64))
|
||||
|
|
@ -219,7 +219,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
this.check_no_isolation("unlink")?;
|
||||
|
||||
let path_bytes = this
|
||||
.memory()
|
||||
.memory
|
||||
.read_c_str(this.read_scalar(path_op)?.not_undef()?)?;
|
||||
let path = std::str::from_utf8(path_bytes)
|
||||
.map_err(|_| err_unsup_format!("{:?} is not a valid utf-8 string", path_bytes))?;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
// even if the type they wrap would be less aligned (e.g. AtomicU64 on 32bit must
|
||||
// be 8-aligned).
|
||||
let align = Align::from_bytes(place.layout.size.bytes()).unwrap();
|
||||
this.memory().check_ptr_access(place.ptr, place.layout.size, align)?;
|
||||
this.memory.check_ptr_access(place.ptr, place.layout.size, align)?;
|
||||
|
||||
this.write_scalar(val, dest)?;
|
||||
}
|
||||
|
|
@ -83,7 +83,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
// even if the type they wrap would be less aligned (e.g. AtomicU64 on 32bit must
|
||||
// be 8-aligned).
|
||||
let align = Align::from_bytes(place.layout.size.bytes()).unwrap();
|
||||
this.memory().check_ptr_access(place.ptr, place.layout.size, align)?;
|
||||
this.memory.check_ptr_access(place.ptr, place.layout.size, align)?;
|
||||
|
||||
this.write_scalar(val, place.into())?;
|
||||
}
|
||||
|
|
@ -104,7 +104,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
// even if the type they wrap would be less aligned (e.g. AtomicU64 on 32bit must
|
||||
// be 8-aligned).
|
||||
let align = Align::from_bytes(place.layout.size.bytes()).unwrap();
|
||||
this.memory().check_ptr_access(place.ptr, place.layout.size, align)?;
|
||||
this.memory.check_ptr_access(place.ptr, place.layout.size, align)?;
|
||||
|
||||
this.write_scalar(old, dest)?; // old value is returned
|
||||
this.write_scalar(new, place.into())?;
|
||||
|
|
@ -120,7 +120,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
// even if the type they wrap would be less aligned (e.g. AtomicU64 on 32bit must
|
||||
// be 8-aligned).
|
||||
let align = Align::from_bytes(place.layout.size.bytes()).unwrap();
|
||||
this.memory().check_ptr_access(place.ptr, place.layout.size, align)?;
|
||||
this.memory.check_ptr_access(place.ptr, place.layout.size, align)?;
|
||||
|
||||
// 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;
|
||||
|
|
@ -173,7 +173,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
// even if the type they wrap would be less aligned (e.g. AtomicU64 on 32bit must
|
||||
// be 8-aligned).
|
||||
let align = Align::from_bytes(place.layout.size.bytes()).unwrap();
|
||||
this.memory().check_ptr_access(place.ptr, place.layout.size, align)?;
|
||||
this.memory.check_ptr_access(place.ptr, place.layout.size, align)?;
|
||||
|
||||
this.write_immediate(*old, dest)?; // old value is returned
|
||||
let (op, neg) = match intrinsic_name.split('_').nth(1).unwrap() {
|
||||
|
|
@ -207,12 +207,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
|
||||
let size = Size::from_bytes(count * elem_size);
|
||||
let src = this.read_scalar(args[0])?.not_undef()?;
|
||||
let src = this.memory().check_ptr_access(src, size, elem_align)?;
|
||||
let src = this.memory.check_ptr_access(src, size, elem_align)?;
|
||||
let dest = this.read_scalar(args[1])?.not_undef()?;
|
||||
let dest = this.memory().check_ptr_access(dest, size, elem_align)?;
|
||||
let dest = this.memory.check_ptr_access(dest, size, elem_align)?;
|
||||
|
||||
if let (Some(src), Some(dest)) = (src, dest) {
|
||||
this.memory_mut().copy(
|
||||
this.memory.copy(
|
||||
src,
|
||||
dest,
|
||||
size,
|
||||
|
|
@ -359,7 +359,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
assert!(mplace.meta.is_none());
|
||||
// not a zst, must be valid pointer
|
||||
let ptr = mplace.ptr.to_ptr()?;
|
||||
this.memory_mut().get_mut(ptr.alloc_id)?.write_repeat(tcx, ptr, 0, dest.layout.size)?;
|
||||
this.memory.get_mut(ptr.alloc_id)?.write_repeat(tcx, ptr, 0, dest.layout.size)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -548,7 +548,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
let mplace = this.force_allocation(dest)?;
|
||||
assert!(mplace.meta.is_none());
|
||||
let ptr = mplace.ptr.to_ptr()?;
|
||||
this.memory_mut()
|
||||
this.memory
|
||||
.get_mut(ptr.alloc_id)?
|
||||
.mark_definedness(ptr, dest.layout.size, false);
|
||||
}
|
||||
|
|
@ -563,9 +563,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
let ptr = this.read_scalar(args[0])?.not_undef()?;
|
||||
let count = this.read_scalar(args[2])?.to_usize(this)?;
|
||||
let byte_count = ty_layout.size * count;
|
||||
match this.memory().check_ptr_access(ptr, byte_count, ty_layout.align.abi)? {
|
||||
match this.memory.check_ptr_access(ptr, byte_count, ty_layout.align.abi)? {
|
||||
Some(ptr) => {
|
||||
this.memory_mut()
|
||||
this.memory
|
||||
.get_mut(ptr.alloc_id)?
|
||||
.write_repeat(tcx, ptr, val_byte, byte_count)?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
let ptr_scalar = this.read_scalar(ptr_op)?.not_undef()?;
|
||||
|
||||
if let Ok(ptr) = this.force_ptr(ptr_scalar) {
|
||||
let cur_align = this.memory().get(ptr.alloc_id)?.align.bytes() as usize;
|
||||
let cur_align = this.memory.get(ptr.alloc_id)?.align.bytes() as usize;
|
||||
if cur_align >= req_align {
|
||||
// if the allocation alignment is at least the required alignment we use the
|
||||
// libcore implementation
|
||||
|
|
|
|||
|
|
@ -533,14 +533,14 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
) -> InterpResult<'tcx> {
|
||||
let this = self.eval_context_mut();
|
||||
let protector = if protect { Some(this.frame().extra) } else { None };
|
||||
let ptr = this.memory().check_ptr_access(place.ptr, size, place.align)
|
||||
let ptr = this.memory.check_ptr_access(place.ptr, size, place.align)
|
||||
.expect("validity checks should have excluded dangling/unaligned pointer")
|
||||
.expect("we shouldn't get here for ZST");
|
||||
trace!("reborrow: {} reference {:?} derived from {:?} (pointee {}): {:?}, size {}",
|
||||
kind, new_tag, ptr.tag, place.layout.ty, ptr.erase_tag(), size.bytes());
|
||||
|
||||
// Get the allocation. It might not be mutable, so we cannot use `get_mut`.
|
||||
let alloc = this.memory().get(ptr.alloc_id)?;
|
||||
let alloc = this.memory.get(ptr.alloc_id)?;
|
||||
let stacked_borrows = alloc.extra.stacked_borrows.as_ref().expect("we should have Stacked Borrows data");
|
||||
// Update the stacks.
|
||||
// Make sure that raw pointers and mutable shared references are reborrowed "weak":
|
||||
|
|
@ -592,7 +592,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
// Compute new borrow.
|
||||
let new_tag = match kind {
|
||||
RefKind::Raw { .. } => Tag::Untagged,
|
||||
_ => Tag::Tagged(this.memory().extra.stacked_borrows.borrow_mut().new_ptr()),
|
||||
_ => Tag::Tagged(this.memory.extra.stacked_borrows.borrow_mut().new_ptr()),
|
||||
};
|
||||
|
||||
// Reborrow.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue