Skip to content

Commit 04b669d

Browse files
committed
populate environ static
1 parent dfb4369 commit 04b669d

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/eval.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
5353
StdRng::seed_from_u64(config.seed.unwrap_or(0)),
5454
config.validate,
5555
config.tracked_pointer_tag,
56-
Scalar::from_int(0, tcx.data_layout.pointer_size),
5756
),
5857
);
5958
// Complete initialization.

src/machine.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,21 @@ pub struct MemoryExtra {
7878

7979
/// Whether to enforce the validity invariant.
8080
pub(crate) validate: bool,
81-
82-
environ: Scalar<Tag>,
81+
/// Contains the `environ` static.
82+
pub(crate) environ: Option<Allocation<Tag, AllocExtra>>,
8383
}
8484

8585
impl MemoryExtra {
8686
pub fn new(
8787
rng: StdRng, validate: bool,
8888
tracked_pointer_tag: Option<PtrId>,
89-
environ: Scalar<Tag>
9089
) -> Self {
9190
MemoryExtra {
9291
stacked_borrows: Rc::new(RefCell::new(GlobalState::new(tracked_pointer_tag))),
9392
intptrcast: Default::default(),
9493
rng: RefCell::new(rng),
9594
validate,
96-
environ,
95+
environ: None,
9796
}
9897
}
9998
}

src/shims/env.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::ffi::{OsString, OsStr};
33
use std::env;
44

55
use crate::stacked_borrows::Tag;
6+
use crate::rustc_target::abi::LayoutOf;
67
use crate::*;
78

89
use rustc::ty::layout::Size;
@@ -20,15 +21,31 @@ impl EnvVars {
2021
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
2122
excluded_env_vars: Vec<String>,
2223
) {
24+
let mut vars = Vec::new();
2325
if ecx.machine.communicate {
26+
// Put each environment variable pointer in `EnvVars`, collect pointers.
2427
for (name, value) in env::vars() {
2528
if !excluded_env_vars.contains(&name) {
2629
let var_ptr =
2730
alloc_env_var_as_c_str(name.as_ref(), value.as_ref(), ecx);
2831
ecx.machine.env_vars.map.insert(OsString::from(name), var_ptr);
32+
vars.push(var_ptr);
2933
}
3034
}
3135
}
36+
// Make an array with all these pointers, in the Miri memory.
37+
let tcx = ecx.tcx;
38+
let environ_layout =
39+
ecx.layout_of(tcx.mk_array(tcx.mk_imm_ptr(tcx.types.u8), vars.len() as u64)).unwrap();
40+
let environ_place = ecx.allocate(environ_layout, MiriMemoryKind::Env.into());
41+
for (idx, var) in vars.into_iter().enumerate() {
42+
let place = ecx.mplace_field(environ_place, idx as u64).unwrap();
43+
ecx.write_scalar(var, place.into()).unwrap();
44+
}
45+
ecx.memory.mark_immutable(environ_place.ptr.assert_ptr().alloc_id).unwrap();
46+
// A pointer to that place corresponds to the `environ` static.
47+
let environ_alloc = ecx.memory.get_raw(environ_place.ptr.assert_ptr().alloc_id).unwrap().clone();
48+
ecx.memory.extra.environ = Some(environ_alloc);
3249
}
3350
}
3451

0 commit comments

Comments
 (0)