]> git.lizzy.rs Git - rust.git/commitdiff
move environ place to EnvVars
authorChristian Poveda <git@christianpoveda.xyz>
Sun, 8 Mar 2020 16:54:47 +0000 (11:54 -0500)
committerChristian Poveda <git@christianpoveda.xyz>
Sun, 8 Mar 2020 16:58:20 +0000 (11:58 -0500)
src/machine.rs
src/shims/env.rs
src/shims/foreign_items/posix/macos.rs

index d21ff328975735763ffa64d438345fa649059709..f69606e48f52c7a76054dcb4f63876eb51f1acae 100644 (file)
@@ -70,7 +70,7 @@ pub struct AllocExtra {
 
 /// 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,
 
@@ -84,12 +84,9 @@ pub struct MemoryExtra<'tcx> {
     /// 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))))
@@ -102,12 +99,11 @@ pub fn new(rng: StdRng, stacked_borrows: bool, tracked_pointer_tag: Option<PtrId
             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();
@@ -127,7 +123,7 @@ pub fn init_extern_statics<'mir>(
                 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
@@ -140,7 +136,7 @@ pub fn init_extern_statics<'mir>(
 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.
@@ -214,7 +210,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
     type MemoryKinds = MiriMemoryKind;
 
     type FrameExtra = FrameData<'tcx>;
-    type MemoryExtra = MemoryExtra<'tcx>;
+    type MemoryExtra = MemoryExtra;
     type AllocExtra = AllocExtra;
     type PointerTag = Tag;
     type ExtraFnVal = Dlsym;
@@ -340,7 +336,7 @@ fn canonical_alloc_id(mem: &Memory<'mir, 'tcx, Self>, id: AllocId) -> AllocId {
     }
 
     fn init_allocation_extra<'b>(
-        memory_extra: &MemoryExtra<'tcx>,
+        memory_extra: &MemoryExtra,
         id: AllocId,
         alloc: Cow<'b, Allocation>,
         kind: Option<MemoryKind<Self::MemoryKinds>>,
@@ -377,7 +373,7 @@ fn init_allocation_extra<'b>(
     }
 
     #[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 {
index b06db5676f3e9e5e7927d94c00c2cab9307d67c2..7c6b6c942e5e3aee470015f4726177aa441c65cd 100644 (file)
 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> {
@@ -160,7 +163,7 @@ fn chdir(&mut self, path_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
     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 {
@@ -168,7 +171,7 @@ fn update_environ(&mut self) -> InterpResult<'tcx> {
             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.
@@ -186,7 +189,7 @@ fn update_environ(&mut self) -> InterpResult<'tcx> {
         }
         this.write_scalar(
             vars_place.ptr,
-            this.memory.extra.environ.unwrap().into(),
+            this.machine.env_vars.environ.unwrap().into(),
         )?;
 
         Ok(())
index c5c6423e8501ee09687605fbc73fb349c7214029..0d067cc04138a6015b2ed7dc4fb10d54c913052a 100644 (file)
@@ -58,7 +58,7 @@ fn emulate_foreign_item_by_name(
 
             // Environment related shims
             "_NSGetEnviron" => {
-                this.write_scalar(this.memory.extra.environ.unwrap().ptr, dest)?;
+                this.write_scalar(this.machine.env_vars.environ.unwrap().ptr, dest)?;
             }
 
             // Time related shims