From 0088715411c2fcb3ea36cdbb969fb9966d722320 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 7 Mar 2022 12:46:53 -0500 Subject: [PATCH] Rename MiriMemoryKind::Env to Runtime In preparation to use it for other runtime-internal allocations. --- src/data_race.rs | 2 +- src/machine.rs | 9 +++++---- src/shims/env.rs | 25 +++++++++++++------------ src/stacked_borrows.rs | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/data_race.rs b/src/data_race.rs index a6ef56a0c204..1e91c66b859e 100644 --- a/src/data_race.rs +++ b/src/data_race.rs @@ -743,7 +743,7 @@ impl VClockAlloc { MemoryKind::Machine( MiriMemoryKind::Global | MiriMemoryKind::Machine - | MiriMemoryKind::Env + | MiriMemoryKind::Runtime | MiriMemoryKind::ExternStatic | MiriMemoryKind::Tls, ) diff --git a/src/machine.rs b/src/machine.rs index 481808dc7819..bb43cb95507c 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -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"), diff --git a/src/shims/env.rs b/src/shims/env.rs index dfd1ef207d96..fd7728688580 100644 --- a/src/shims/env.rs +++ b/src/shims/env.rs @@ -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())?; diff --git a/src/stacked_borrows.rs b/src/stacked_borrows.rs index 37ecb749a487..0e47a9e1c3b0 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -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.