Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use memory field instead of memory() #1004

Merged
merged 2 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d28a9c38fe14396e86ae274c7847e20ee0f78ca9
fa0f7d0080d8e7e9eb20aa9cbf8013f96c81287f
12 changes: 6 additions & 6 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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()),
);
}
Expand All @@ -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;
Expand All @@ -157,15 +157,15 @@ 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(),
);
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(
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)]
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
20 changes: 10 additions & 10 deletions src/shims/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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) => {
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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));
Expand All @@ -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(
Expand Down
Loading