Skip to content

Commit fbc1d91

Browse files
committed
Auto merge of #1004 - JohnTitor:use-memory, r=RalfJung
Use memory field instead of memory() Rustup for rust-lang/rust#65319
2 parents 089c7e8 + 17449fb commit fbc1d91

File tree

11 files changed

+73
-73
lines changed

11 files changed

+73
-73
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d28a9c38fe14396e86ae274c7847e20ee0f78ca9
1+
fa0f7d0080d8e7e9eb20aa9cbf8013f96c81287f

src/eval.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
9393

9494
// First argument: pointer to `main()`.
9595
let main_ptr = ecx
96-
.memory_mut()
96+
.memory
9797
.create_fn_alloc(FnVal::Instance(main_instance));
9898
let dest = ecx.local_place(args.next().unwrap())?;
9999
ecx.write_scalar(Scalar::Ptr(main_ptr), dest)?;
@@ -128,7 +128,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
128128
let mut arg = arg.into_bytes();
129129
arg.push(0);
130130
argvs.push(
131-
ecx.memory_mut()
131+
ecx.memory
132132
.allocate_static_bytes(arg.as_slice(), MiriMemoryKind::Static.into()),
133133
);
134134
}
@@ -142,7 +142,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
142142
let place = ecx.mplace_field(argvs_place, idx as u64)?;
143143
ecx.write_scalar(Scalar::Ptr(arg), place.into())?;
144144
}
145-
ecx.memory_mut()
145+
ecx.memory
146146
.mark_immutable(argvs_place.ptr.assert_ptr().alloc_id)?;
147147
// Write a pointer to that place as the argument.
148148
let argv = argvs_place.ptr;
@@ -157,15 +157,15 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
157157
{
158158
let tcx = &{ ecx.tcx.tcx };
159159
let cmd_utf16: Vec<u16> = cmd.encode_utf16().collect();
160-
let cmd_ptr = ecx.memory_mut().allocate(
160+
let cmd_ptr = ecx.memory.allocate(
161161
Size::from_bytes(cmd_utf16.len() as u64 * 2),
162162
Align::from_bytes(2).unwrap(),
163163
MiriMemoryKind::Env.into(),
164164
);
165165
ecx.machine.cmd_line = Some(cmd_ptr);
166166
// Store the UTF-16 string.
167167
let char_size = Size::from_bytes(2);
168-
let cmd_alloc = ecx.memory_mut().get_mut(cmd_ptr.alloc_id)?;
168+
let cmd_alloc = ecx.memory.get_mut(cmd_ptr.alloc_id)?;
169169
let mut cur_ptr = cmd_ptr;
170170
for &c in cmd_utf16.iter() {
171171
cmd_alloc.write_scalar(
@@ -211,7 +211,7 @@ pub fn eval_main<'tcx>(tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig) {
211211
// Process the result.
212212
match res {
213213
Ok(()) => {
214-
let leaks = ecx.memory().leak_report();
214+
let leaks = ecx.memory.leak_report();
215215
// Disable the leak test on some platforms where we do not
216216
// correctly implement TLS destructors.
217217
let target_os = ecx.tcx.tcx.sess.target.target.target_os.to_lowercase();

src/helpers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
5757
/// Test if this immediate equals 0.
5858
fn is_null(&self, val: Scalar<Tag>) -> InterpResult<'tcx, bool> {
5959
let this = self.eval_context_ref();
60-
let null = Scalar::from_int(0, this.memory().pointer_size());
60+
let null = Scalar::from_int(0, this.memory.pointer_size());
6161
this.ptr_eq(val, null)
6262
}
6363

@@ -94,7 +94,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
9494
}
9595
let this = self.eval_context_mut();
9696

97-
let ptr = this.memory().check_ptr_access(
97+
let ptr = this.memory.check_ptr_access(
9898
ptr,
9999
Size::from_bytes(len as u64),
100100
Align::from_bytes(1).unwrap()
@@ -108,12 +108,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
108108
.map_err(|err| err_unsup_format!("getrandom failed: {}", err))?;
109109
}
110110
else {
111-
let rng = this.memory_mut().extra.rng.get_mut();
111+
let rng = this.memory.extra.rng.get_mut();
112112
rng.fill_bytes(&mut data);
113113
}
114114

115115
let tcx = &{this.tcx.tcx};
116-
this.memory_mut().get_mut(ptr.alloc_id)?.write_bytes(tcx, ptr, &data)
116+
this.memory.get_mut(ptr.alloc_id)?.write_bytes(tcx, ptr, &data)
117117
}
118118

119119
/// Visits the memory covered by `place`, sensitive to freezing: the 3rd parameter

src/machine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
164164

165165
#[inline(always)]
166166
fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
167-
ecx.memory().extra.validate
167+
ecx.memory.extra.validate
168168
}
169169

170170
#[inline(always)]
@@ -349,7 +349,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
349349
fn stack_push(
350350
ecx: &mut InterpCx<'mir, 'tcx, Self>,
351351
) -> InterpResult<'tcx, stacked_borrows::CallId> {
352-
Ok(ecx.memory().extra.stacked_borrows.borrow_mut().new_call())
352+
Ok(ecx.memory.extra.stacked_borrows.borrow_mut().new_call())
353353
}
354354

355355
#[inline(always)]
@@ -358,7 +358,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
358358
extra: stacked_borrows::CallId,
359359
) -> InterpResult<'tcx> {
360360
Ok(ecx
361-
.memory()
361+
.memory
362362
.extra
363363
.stacked_borrows
364364
.borrow_mut()

src/operator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
3434
/// Test if the pointer is in-bounds of a live allocation.
3535
#[inline]
3636
fn pointer_inbounds(&self, ptr: Pointer<Tag>) -> InterpResult<'tcx> {
37-
let (size, _align) = self.memory().get_size_and_align(ptr.alloc_id, AllocCheck::Live)?;
37+
let (size, _align) = self.memory.get_size_and_align(ptr.alloc_id, AllocCheck::Live)?;
3838
ptr.check_inbounds_alloc(size, CheckInAllocMsg::InboundsTest)
3939
}
4040

src/shims/env.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl EnvVars {
2626
for (name, value) in env::vars() {
2727
if !excluded_env_vars.contains(&name) {
2828
let var_ptr =
29-
alloc_env_var(name.as_bytes(), value.as_bytes(), ecx.memory_mut());
29+
alloc_env_var(name.as_bytes(), value.as_bytes(), &mut ecx.memory);
3030
ecx.machine.env_vars.map.insert(name.into_bytes(), var_ptr);
3131
}
3232
}
@@ -52,7 +52,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
5252
let this = self.eval_context_mut();
5353

5454
let name_ptr = this.read_scalar(name_op)?.not_undef()?;
55-
let name = this.memory().read_c_str(name_ptr)?;
55+
let name = this.memory.read_c_str(name_ptr)?;
5656
Ok(match this.machine.env_vars.map.get(name) {
5757
// The offset is used to strip the "{name}=" part of the string.
5858
Some(var_ptr) => {
@@ -71,18 +71,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
7171

7272
let name_ptr = this.read_scalar(name_op)?.not_undef()?;
7373
let value_ptr = this.read_scalar(value_op)?.not_undef()?;
74-
let value = this.memory().read_c_str(value_ptr)?;
74+
let value = this.memory.read_c_str(value_ptr)?;
7575
let mut new = None;
7676
if !this.is_null(name_ptr)? {
77-
let name = this.memory().read_c_str(name_ptr)?;
77+
let name = this.memory.read_c_str(name_ptr)?;
7878
if !name.is_empty() && !name.contains(&b'=') {
7979
new = Some((name.to_owned(), value.to_owned()));
8080
}
8181
}
8282
if let Some((name, value)) = new {
83-
let var_ptr = alloc_env_var(&name, &value, this.memory_mut());
83+
let var_ptr = alloc_env_var(&name, &value, &mut this.memory);
8484
if let Some(var) = this.machine.env_vars.map.insert(name.to_owned(), var_ptr) {
85-
this.memory_mut()
85+
this.memory
8686
.deallocate(var, None, MiriMemoryKind::Env.into())?;
8787
}
8888
Ok(0)
@@ -97,14 +97,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
9797
let name_ptr = this.read_scalar(name_op)?.not_undef()?;
9898
let mut success = None;
9999
if !this.is_null(name_ptr)? {
100-
let name = this.memory().read_c_str(name_ptr)?.to_owned();
100+
let name = this.memory.read_c_str(name_ptr)?.to_owned();
101101
if !name.is_empty() && !name.contains(&b'=') {
102102
success = Some(this.machine.env_vars.map.remove(&name));
103103
}
104104
}
105105
if let Some(old) = success {
106106
if let Some(var) = old {
107-
this.memory_mut()
107+
this.memory
108108
.deallocate(var, None, MiriMemoryKind::Env.into())?;
109109
}
110110
Ok(0)
@@ -140,7 +140,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
140140
// This is ok because the buffer was strictly larger than `bytes`, so after
141141
// adding the null terminator, the buffer size is larger or equal to
142142
// `bytes.len()`, meaning that `bytes` actually fit inside tbe buffer.
143-
this.memory_mut()
143+
this.memory
144144
.get_mut(buf.alloc_id)?
145145
.write_bytes(tcx, buf, &bytes)?;
146146
return Ok(Scalar::Ptr(buf));
@@ -159,7 +159,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
159159
this.check_no_isolation("chdir")?;
160160

161161
let path_bytes = this
162-
.memory()
162+
.memory
163163
.read_c_str(this.read_scalar(path_op)?.not_undef()?)?;
164164

165165
let path = Path::new(

0 commit comments

Comments
 (0)