Skip to content

Commit

Permalink
populate environ static
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdrz committed Jan 9, 2020
1 parent dfb4369 commit 04b669d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
StdRng::seed_from_u64(config.seed.unwrap_or(0)),
config.validate,
config.tracked_pointer_tag,
Scalar::from_int(0, tcx.data_layout.pointer_size),
),
);
// Complete initialization.
Expand Down
7 changes: 3 additions & 4 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,21 @@ pub struct MemoryExtra {

/// Whether to enforce the validity invariant.
pub(crate) validate: bool,

environ: Scalar<Tag>,
/// Contains the `environ` static.
pub(crate) environ: Option<Allocation<Tag, AllocExtra>>,
}

impl MemoryExtra {
pub fn new(
rng: StdRng, validate: bool,
tracked_pointer_tag: Option<PtrId>,
environ: Scalar<Tag>
) -> Self {
MemoryExtra {
stacked_borrows: Rc::new(RefCell::new(GlobalState::new(tracked_pointer_tag))),
intptrcast: Default::default(),
rng: RefCell::new(rng),
validate,
environ,
environ: None,
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/shims/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::ffi::{OsString, OsStr};
use std::env;

use crate::stacked_borrows::Tag;
use crate::rustc_target::abi::LayoutOf;
use crate::*;

use rustc::ty::layout::Size;
Expand All @@ -20,15 +21,31 @@ impl EnvVars {
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
excluded_env_vars: Vec<String>,
) {
let mut vars = Vec::new();
if ecx.machine.communicate {
// Put each environment variable pointer in `EnvVars`, collect pointers.
for (name, value) in env::vars() {
if !excluded_env_vars.contains(&name) {
let var_ptr =
alloc_env_var_as_c_str(name.as_ref(), value.as_ref(), ecx);
ecx.machine.env_vars.map.insert(OsString::from(name), var_ptr);
vars.push(var_ptr);
}
}
}
// Make an array with all these pointers, in the Miri memory.
let tcx = ecx.tcx;
let environ_layout =
ecx.layout_of(tcx.mk_array(tcx.mk_imm_ptr(tcx.types.u8), vars.len() as u64)).unwrap();
let environ_place = ecx.allocate(environ_layout, MiriMemoryKind::Env.into());
for (idx, var) in vars.into_iter().enumerate() {
let place = ecx.mplace_field(environ_place, idx as u64).unwrap();
ecx.write_scalar(var, place.into()).unwrap();
}
ecx.memory.mark_immutable(environ_place.ptr.assert_ptr().alloc_id).unwrap();
// A pointer to that place corresponds to the `environ` static.
let environ_alloc = ecx.memory.get_raw(environ_place.ptr.assert_ptr().alloc_id).unwrap().clone();
ecx.memory.extra.environ = Some(environ_alloc);
}
}

Expand Down

0 comments on commit 04b669d

Please sign in to comment.