/// Extra global memory data
#[derive(Clone, Debug)]
-pub struct MemoryExtra<'tcx> {
+pub struct MemoryExtra {
pub stacked_borrows: Option<stacked_borrows::MemoryExtra>,
pub intptrcast: intptrcast::MemoryExtra,
/// An allocation ID to report when it is being allocated
/// (helps for debugging memory leaks).
tracked_alloc_id: Option<AllocId>,
-
- /// Place where the `environ` static is stored. Lazily initialized, but then never changes.
- pub(crate) environ: Option<MPlaceTy<'tcx, Tag>>,
}
-impl<'tcx> MemoryExtra<'tcx> {
+impl MemoryExtra {
pub fn new(rng: StdRng, stacked_borrows: bool, tracked_pointer_tag: Option<PtrId>, tracked_alloc_id: Option<AllocId>) -> Self {
let stacked_borrows = if stacked_borrows {
Some(Rc::new(RefCell::new(stacked_borrows::GlobalState::new(tracked_pointer_tag))))
extern_statics: FxHashMap::default(),
rng: RefCell::new(rng),
tracked_alloc_id,
- environ: None,
}
}
/// Sets up the "extern statics" for this machine.
- pub fn init_extern_statics<'mir>(
+ pub fn init_extern_statics<'tcx, 'mir>(
this: &mut MiriEvalContext<'mir, 'tcx>,
) -> InterpResult<'tcx> {
let target_os = this.tcx.sess.target.target.target_os.as_str();
this.memory
.extra
.extern_statics
- .insert(Symbol::intern("environ"), this.memory.extra.environ.unwrap().ptr.assert_ptr().alloc_id)
+ .insert(Symbol::intern("environ"), this.machine.env_vars.environ.unwrap().ptr.assert_ptr().alloc_id)
.unwrap_none();
}
_ => {} // No "extern statics" supported on this platform
pub struct Evaluator<'tcx> {
/// Environment variables set by `setenv`.
/// Miri does not expose env vars from the host to the emulated program.
- pub(crate) env_vars: EnvVars,
+ pub(crate) env_vars: EnvVars<'tcx>,
/// Program arguments (`Option` because we can only initialize them after creating the ecx).
/// These are *pointers* to argc/argv because macOS.
type MemoryKinds = MiriMemoryKind;
type FrameExtra = FrameData<'tcx>;
- type MemoryExtra = MemoryExtra<'tcx>;
+ type MemoryExtra = MemoryExtra;
type AllocExtra = AllocExtra;
type PointerTag = Tag;
type ExtraFnVal = Dlsym;
}
fn init_allocation_extra<'b>(
- memory_extra: &MemoryExtra<'tcx>,
+ memory_extra: &MemoryExtra,
id: AllocId,
alloc: Cow<'b, Allocation>,
kind: Option<MemoryKind<Self::MemoryKinds>>,
}
#[inline(always)]
- fn tag_static_base_pointer(memory_extra: &MemoryExtra<'tcx>, id: AllocId) -> Self::PointerTag {
+ fn tag_static_base_pointer(memory_extra: &MemoryExtra, id: AllocId) -> Self::PointerTag {
if let Some(stacked_borrows) = memory_extra.stacked_borrows.as_ref() {
stacked_borrows.borrow_mut().static_base_ptr(id)
} else {
use rustc_mir::interpret::Pointer;
#[derive(Default)]
-pub struct EnvVars {
+pub struct EnvVars<'tcx> {
/// Stores pointers to the environment variables. These variables must be stored as
/// null-terminated C strings with the `"{name}={value}"` format.
map: FxHashMap<OsString, Pointer<Tag>>,
+
+ /// Place where the `environ` static is stored. Lazily initialized, but then never changes.
+ pub(crate) environ: Option<MPlaceTy<'tcx, Tag>>,
}
-impl EnvVars {
- pub(crate) fn init<'mir, 'tcx>(
+impl<'tcx> EnvVars<'tcx> {
+ pub(crate) fn init<'mir>(
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
excluded_env_vars: Vec<String>,
) -> InterpResult<'tcx> {
fn update_environ(&mut self) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
// Deallocate the old environ value, if any.
- if let Some(environ) = this.memory.extra.environ {
+ if let Some(environ) = this.machine.env_vars.environ {
let old_vars_ptr = this.read_scalar(environ.into())?.not_undef()?;
this.memory.deallocate(this.force_ptr(old_vars_ptr)?, None, MiriMemoryKind::Machine.into())?;
} else {
let layout = this.layout_of(this.tcx.types.usize)?;
let place = this.allocate(layout, MiriMemoryKind::Machine.into());
this.write_scalar(Scalar::from_machine_usize(0, &*this.tcx), place.into())?;
- this.memory.extra.environ = Some(place);
+ this.machine.env_vars.environ = Some(place);
}
// Collect all the pointers to each variable in a vector.
}
this.write_scalar(
vars_place.ptr,
- this.memory.extra.environ.unwrap().into(),
+ this.machine.env_vars.environ.unwrap().into(),
)?;
Ok(())