Rename MiriMemoryKind::Env to Runtime

In preparation to use it for other runtime-internal allocations.
This commit is contained in:
Tavian Barnes 2022-03-07 12:46:53 -05:00
parent ccaf7206e1
commit 0088715411
4 changed files with 20 additions and 18 deletions

View File

@ -743,7 +743,7 @@ impl VClockAlloc {
MemoryKind::Machine(
MiriMemoryKind::Global
| MiriMemoryKind::Machine
| MiriMemoryKind::Env
| MiriMemoryKind::Runtime
| MiriMemoryKind::ExternStatic
| MiriMemoryKind::Tls,
)

View File

@ -71,8 +71,9 @@ pub enum MiriMemoryKind {
/// Memory for args, errno, and other parts of the machine-managed environment.
/// This memory may leak.
Machine,
/// Memory for env vars. Separate from `Machine` because we clean it up and leak-check it.
Env,
/// Memory allocated by the runtime (e.g. env vars). Separate from `Machine`
/// because we clean it up and leak-check it.
Runtime,
/// Globals copied from `tcx`.
/// This memory may leak.
Global,
@ -96,7 +97,7 @@ impl MayLeak for MiriMemoryKind {
fn may_leak(self) -> bool {
use self::MiriMemoryKind::*;
match self {
Rust | C | WinHeap | Env => false,
Rust | C | WinHeap | Runtime => false,
Machine | Global | ExternStatic | Tls => true,
}
}
@ -110,7 +111,7 @@ impl fmt::Display for MiriMemoryKind {
C => write!(f, "C heap"),
WinHeap => write!(f, "Windows heap"),
Machine => write!(f, "machine-managed memory"),
Env => write!(f, "environment variable"),
Runtime => write!(f, "language runtime memory"),
Global => write!(f, "global (static or const)"),
ExternStatic => write!(f, "extern static"),
Tls => write!(f, "thread-local static"),

View File

@ -78,12 +78,12 @@ impl<'tcx> EnvVars<'tcx> {
) -> InterpResult<'tcx> {
// Deallocate individual env vars.
for (_name, ptr) in ecx.machine.env_vars.map.drain() {
ecx.memory.deallocate(ptr, None, MiriMemoryKind::Env.into())?;
ecx.memory.deallocate(ptr, None, MiriMemoryKind::Runtime.into())?;
}
// Deallocate environ var list.
let environ = ecx.machine.env_vars.environ.unwrap();
let old_vars_ptr = ecx.read_pointer(&environ.into())?;
ecx.memory.deallocate(old_vars_ptr, None, MiriMemoryKind::Env.into())?;
ecx.memory.deallocate(old_vars_ptr, None, MiriMemoryKind::Runtime.into())?;
Ok(())
}
}
@ -96,7 +96,7 @@ fn alloc_env_var_as_c_str<'mir, 'tcx>(
let mut name_osstring = name.to_os_string();
name_osstring.push("=");
name_osstring.push(value);
ecx.alloc_os_str_as_c_str(name_osstring.as_os_str(), MiriMemoryKind::Env.into())
ecx.alloc_os_str_as_c_str(name_osstring.as_os_str(), MiriMemoryKind::Runtime.into())
}
fn alloc_env_var_as_wide_str<'mir, 'tcx>(
@ -107,7 +107,7 @@ fn alloc_env_var_as_wide_str<'mir, 'tcx>(
let mut name_osstring = name.to_os_string();
name_osstring.push("=");
name_osstring.push(value);
ecx.alloc_os_str_as_wide_str(name_osstring.as_os_str(), MiriMemoryKind::Env.into())
ecx.alloc_os_str_as_wide_str(name_osstring.as_os_str(), MiriMemoryKind::Runtime.into())
}
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
}
// Allocate environment block & Store environment variables to environment block.
// Final null terminator(block terminator) is added by `alloc_os_str_to_wide_str`.
let envblock_ptr = this.alloc_os_str_as_wide_str(&env_vars, MiriMemoryKind::Env.into())?;
let envblock_ptr =
this.alloc_os_str_as_wide_str(&env_vars, MiriMemoryKind::Runtime.into())?;
// If the function succeeds, the return value is a pointer to the environment block of the current process.
Ok(envblock_ptr)
}
@ -200,7 +201,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.assert_target_os("windows", "FreeEnvironmentStringsW");
let env_block_ptr = this.read_pointer(env_block_op)?;
let result = this.memory.deallocate(env_block_ptr, None, MiriMemoryKind::Env.into());
let result = this.memory.deallocate(env_block_ptr, None, MiriMemoryKind::Runtime.into());
// If the function succeeds, the return value is nonzero.
Ok(result.is_ok() as i32)
}
@ -231,7 +232,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
if let Some((name, value)) = new {
let var_ptr = alloc_env_var_as_c_str(&name, &value, &mut this)?;
if let Some(var) = this.machine.env_vars.map.insert(name, var_ptr) {
this.memory.deallocate(var, None, MiriMemoryKind::Env.into())?;
this.memory.deallocate(var, None, MiriMemoryKind::Runtime.into())?;
}
this.update_environ()?;
Ok(0) // return zero on success
@ -268,7 +269,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
} else if this.ptr_is_null(value_ptr)? {
// Delete environment variable `{name}`
if let Some(var) = this.machine.env_vars.map.remove(&name) {
this.memory.deallocate(var, None, MiriMemoryKind::Env.into())?;
this.memory.deallocate(var, None, MiriMemoryKind::Runtime.into())?;
this.update_environ()?;
}
Ok(1) // return non-zero on success
@ -276,7 +277,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let value = this.read_os_str_from_wide_str(value_ptr)?;
let var_ptr = alloc_env_var_as_wide_str(&name, &value, &mut this)?;
if let Some(var) = this.machine.env_vars.map.insert(name, var_ptr) {
this.memory.deallocate(var, None, MiriMemoryKind::Env.into())?;
this.memory.deallocate(var, None, MiriMemoryKind::Runtime.into())?;
}
this.update_environ()?;
Ok(1) // return non-zero on success
@ -301,7 +302,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
if let Some(old) = success {
if let Some(var) = old {
this.memory.deallocate(var, None, MiriMemoryKind::Env.into())?;
this.memory.deallocate(var, None, MiriMemoryKind::Runtime.into())?;
}
this.update_environ()?;
Ok(0)
@ -437,7 +438,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Deallocate the old environ list, if any.
if let Some(environ) = this.machine.env_vars.environ {
let old_vars_ptr = this.read_pointer(&environ.into())?;
this.memory.deallocate(old_vars_ptr, None, MiriMemoryKind::Env.into())?;
this.memory.deallocate(old_vars_ptr, None, MiriMemoryKind::Runtime.into())?;
} else {
// No `environ` allocated yet, let's do that.
// 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
let tcx = this.tcx;
let vars_layout =
this.layout_of(tcx.mk_array(tcx.types.usize, u64::try_from(vars.len()).unwrap()))?;
let vars_place = this.allocate(vars_layout, MiriMemoryKind::Env.into())?;
let vars_place = this.allocate(vars_layout, MiriMemoryKind::Runtime.into())?;
for (idx, var) in vars.into_iter().enumerate() {
let place = this.mplace_field(&vars_place, idx)?;
this.write_pointer(var, &place.into())?;

View File

@ -535,7 +535,7 @@ impl Stacks {
MiriMemoryKind::Global
| MiriMemoryKind::ExternStatic
| MiriMemoryKind::Tls
| MiriMemoryKind::Env
| MiriMemoryKind::Runtime
| MiriMemoryKind::Machine,
) => (extra.base_tag(id), Permission::SharedReadWrite),
// Heap allocations we only track precisely when raw pointers are tagged, for now.