Skip to content

Commit a7e4c0b

Browse files
committed
Rename MiriMemoryKind::Env to Runtime
In preparation to use it for other runtime-internal allocations.
1 parent dd42a47 commit a7e4c0b

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

src/data_race.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ impl VClockAlloc {
743743
MemoryKind::Machine(
744744
MiriMemoryKind::Global
745745
| MiriMemoryKind::Machine
746-
| MiriMemoryKind::Env
746+
| MiriMemoryKind::Runtime
747747
| MiriMemoryKind::ExternStatic
748748
| MiriMemoryKind::Tls,
749749
)

src/machine.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ pub enum MiriMemoryKind {
7171
/// Memory for args, errno, and other parts of the machine-managed environment.
7272
/// This memory may leak.
7373
Machine,
74-
/// Memory for env vars. Separate from `Machine` because we clean it up and leak-check it.
75-
Env,
74+
/// Memory allocated by the runtime (e.g. env vars). Separate from `Machine`
75+
/// because we clean it up and leak-check it.
76+
Runtime,
7677
/// Globals copied from `tcx`.
7778
/// This memory may leak.
7879
Global,
@@ -96,7 +97,7 @@ impl MayLeak for MiriMemoryKind {
9697
fn may_leak(self) -> bool {
9798
use self::MiriMemoryKind::*;
9899
match self {
99-
Rust | C | WinHeap | Env => false,
100+
Rust | C | WinHeap | Runtime => false,
100101
Machine | Global | ExternStatic | Tls => true,
101102
}
102103
}
@@ -110,7 +111,7 @@ impl fmt::Display for MiriMemoryKind {
110111
C => write!(f, "C heap"),
111112
WinHeap => write!(f, "Windows heap"),
112113
Machine => write!(f, "machine-managed memory"),
113-
Env => write!(f, "environment variable"),
114+
Runtime => write!(f, "runtime implementation heap"),
114115
Global => write!(f, "global (static or const)"),
115116
ExternStatic => write!(f, "extern static"),
116117
Tls => write!(f, "thread-local static"),

src/shims/env.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ impl<'tcx> EnvVars<'tcx> {
7878
) -> InterpResult<'tcx> {
7979
// Deallocate individual env vars.
8080
for (_name, ptr) in ecx.machine.env_vars.map.drain() {
81-
ecx.memory.deallocate(ptr, None, MiriMemoryKind::Env.into())?;
81+
ecx.memory.deallocate(ptr, None, MiriMemoryKind::Runtime.into())?;
8282
}
8383
// Deallocate environ var list.
8484
let environ = ecx.machine.env_vars.environ.unwrap();
8585
let old_vars_ptr = ecx.read_pointer(&environ.into())?;
86-
ecx.memory.deallocate(old_vars_ptr, None, MiriMemoryKind::Env.into())?;
86+
ecx.memory.deallocate(old_vars_ptr, None, MiriMemoryKind::Runtime.into())?;
8787
Ok(())
8888
}
8989
}
@@ -96,7 +96,7 @@ fn alloc_env_var_as_c_str<'mir, 'tcx>(
9696
let mut name_osstring = name.to_os_string();
9797
name_osstring.push("=");
9898
name_osstring.push(value);
99-
ecx.alloc_os_str_as_c_str(name_osstring.as_os_str(), MiriMemoryKind::Env.into())
99+
ecx.alloc_os_str_as_c_str(name_osstring.as_os_str(), MiriMemoryKind::Runtime.into())
100100
}
101101

102102
fn alloc_env_var_as_wide_str<'mir, 'tcx>(
@@ -107,7 +107,7 @@ fn alloc_env_var_as_wide_str<'mir, 'tcx>(
107107
let mut name_osstring = name.to_os_string();
108108
name_osstring.push("=");
109109
name_osstring.push(value);
110-
ecx.alloc_os_str_as_wide_str(name_osstring.as_os_str(), MiriMemoryKind::Env.into())
110+
ecx.alloc_os_str_as_wide_str(name_osstring.as_os_str(), MiriMemoryKind::Runtime.into())
111111
}
112112

113113
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
@@ -186,7 +186,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
186186
}
187187
// Allocate environment block & Store environment variables to environment block.
188188
// Final null terminator(block terminator) is added by `alloc_os_str_to_wide_str`.
189-
let envblock_ptr = this.alloc_os_str_as_wide_str(&env_vars, MiriMemoryKind::Env.into())?;
189+
let envblock_ptr =
190+
this.alloc_os_str_as_wide_str(&env_vars, MiriMemoryKind::Runtime.into())?;
190191
// If the function succeeds, the return value is a pointer to the environment block of the current process.
191192
Ok(envblock_ptr)
192193
}
@@ -200,7 +201,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
200201
this.assert_target_os("windows", "FreeEnvironmentStringsW");
201202

202203
let env_block_ptr = this.read_pointer(env_block_op)?;
203-
let result = this.memory.deallocate(env_block_ptr, None, MiriMemoryKind::Env.into());
204+
let result = this.memory.deallocate(env_block_ptr, None, MiriMemoryKind::Runtime.into());
204205
// If the function succeeds, the return value is nonzero.
205206
Ok(result.is_ok() as i32)
206207
}
@@ -231,7 +232,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
231232
if let Some((name, value)) = new {
232233
let var_ptr = alloc_env_var_as_c_str(&name, &value, &mut this)?;
233234
if let Some(var) = this.machine.env_vars.map.insert(name, var_ptr) {
234-
this.memory.deallocate(var, None, MiriMemoryKind::Env.into())?;
235+
this.memory.deallocate(var, None, MiriMemoryKind::Runtime.into())?;
235236
}
236237
this.update_environ()?;
237238
Ok(0) // return zero on success
@@ -268,15 +269,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
268269
} else if this.ptr_is_null(value_ptr)? {
269270
// Delete environment variable `{name}`
270271
if let Some(var) = this.machine.env_vars.map.remove(&name) {
271-
this.memory.deallocate(var, None, MiriMemoryKind::Env.into())?;
272+
this.memory.deallocate(var, None, MiriMemoryKind::Runtime.into())?;
272273
this.update_environ()?;
273274
}
274275
Ok(1) // return non-zero on success
275276
} else {
276277
let value = this.read_os_str_from_wide_str(value_ptr)?;
277278
let var_ptr = alloc_env_var_as_wide_str(&name, &value, &mut this)?;
278279
if let Some(var) = this.machine.env_vars.map.insert(name, var_ptr) {
279-
this.memory.deallocate(var, None, MiriMemoryKind::Env.into())?;
280+
this.memory.deallocate(var, None, MiriMemoryKind::Runtime.into())?;
280281
}
281282
this.update_environ()?;
282283
Ok(1) // return non-zero on success
@@ -301,7 +302,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
301302
}
302303
if let Some(old) = success {
303304
if let Some(var) = old {
304-
this.memory.deallocate(var, None, MiriMemoryKind::Env.into())?;
305+
this.memory.deallocate(var, None, MiriMemoryKind::Runtime.into())?;
305306
}
306307
this.update_environ()?;
307308
Ok(0)
@@ -437,7 +438,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
437438
// Deallocate the old environ list, if any.
438439
if let Some(environ) = this.machine.env_vars.environ {
439440
let old_vars_ptr = this.read_pointer(&environ.into())?;
440-
this.memory.deallocate(old_vars_ptr, None, MiriMemoryKind::Env.into())?;
441+
this.memory.deallocate(old_vars_ptr, None, MiriMemoryKind::Runtime.into())?;
441442
} else {
442443
// No `environ` allocated yet, let's do that.
443444
// This is memory backing an extern static, hence `ExternStatic`, not `Env`.
@@ -455,7 +456,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
455456
let tcx = this.tcx;
456457
let vars_layout =
457458
this.layout_of(tcx.mk_array(tcx.types.usize, u64::try_from(vars.len()).unwrap()))?;
458-
let vars_place = this.allocate(vars_layout, MiriMemoryKind::Env.into())?;
459+
let vars_place = this.allocate(vars_layout, MiriMemoryKind::Runtime.into())?;
459460
for (idx, var) in vars.into_iter().enumerate() {
460461
let place = this.mplace_field(&vars_place, idx)?;
461462
this.write_pointer(var, &place.into())?;

src/stacked_borrows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl Stacks {
535535
MiriMemoryKind::Global
536536
| MiriMemoryKind::ExternStatic
537537
| MiriMemoryKind::Tls
538-
| MiriMemoryKind::Env
538+
| MiriMemoryKind::Runtime
539539
| MiriMemoryKind::Machine,
540540
) => (extra.base_tag(id), Permission::SharedReadWrite),
541541
// Heap allocations we only track precisely when raw pointers are tagged, for now.

0 commit comments

Comments
 (0)