Skip to content

Commit afc6713

Browse files
committed
Reorganize shims::env::EnvVars
1 parent 67d1357 commit afc6713

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

src/eval.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::{
1212
InterpResult, InterpError, InterpCx, StackPopCleanup, struct_error,
1313
Scalar, Tag, Pointer, FnVal,
1414
MemoryExtra, MiriMemoryKind, Evaluator, TlsEvalContextExt, HelpersEvalContextExt,
15+
ShimsEnvVars,
1516
};
16-
use crate::shims::env::EnvVars;
1717

1818
/// Configuration needed to spawn a Miri instance.
1919
#[derive(Clone)]
@@ -40,6 +40,8 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
4040
MemoryExtra::new(StdRng::seed_from_u64(config.seed.unwrap_or(0)), config.validate),
4141
);
4242

43+
ShimsEnvVars::init(config.communicate, &mut ecx, &tcx);
44+
4345
let main_instance = ty::Instance::mono(ecx.tcx.tcx, main_id);
4446
let main_mir = ecx.load_mir(main_instance.def)?;
4547

@@ -164,10 +166,6 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
164166

165167
assert!(args.next().is_none(), "start lang item has more arguments than expected");
166168

167-
if config.communicate {
168-
EnvVars::init(&mut ecx, &tcx);
169-
}
170-
171169
Ok(ecx)
172170
}
173171

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub use crate::shims::foreign_items::EvalContextExt as ForeignItemsEvalContextEx
3333
pub use crate::shims::intrinsics::EvalContextExt as IntrinsicsEvalContextExt;
3434
pub use crate::shims::tls::{EvalContextExt as TlsEvalContextExt, TlsData};
3535
pub use crate::shims::dlsym::{Dlsym, EvalContextExt as DlsymEvalContextExt};
36+
pub use crate::shims::env::{EnvVars as ShimsEnvVars};
3637
pub use crate::operator::EvalContextExt as OperatorEvalContextExt;
3738
pub use crate::range_map::RangeMap;
3839
pub use crate::helpers::{EvalContextExt as HelpersEvalContextExt};

src/machine.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc::ty::{self, layout::{Size, LayoutOf}, TyCtxt};
1414
use rustc::mir;
1515

1616
use crate::*;
17-
use crate::shims::env::EnvVars;
1817

1918
// Some global facts about the emulated machine.
2019
pub const PAGE_SIZE: u64 = 4*1024; // FIXME: adjust to target architecture
@@ -79,7 +78,7 @@ impl MemoryExtra {
7978
pub struct Evaluator<'tcx> {
8079
/// Environment variables set by `setenv`.
8180
/// Miri does not expose env vars from the host to the emulated program.
82-
pub(crate) env_vars: EnvVars,
81+
pub(crate) env_vars: ShimsEnvVars,
8382

8483
/// Program arguments (`Option` because we can only initialize them after creating the ecx).
8584
/// These are *pointers* to argc/argv because macOS.
@@ -101,7 +100,9 @@ pub struct Evaluator<'tcx> {
101100
impl<'tcx> Evaluator<'tcx> {
102101
pub(crate) fn new(communicate: bool) -> Self {
103102
Evaluator {
104-
env_vars: EnvVars::default(),
103+
// `env_vars` could be initialized properly here if `Memory` were available before
104+
// calling this method.
105+
env_vars: ShimsEnvVars::default(),
105106
argc: None,
106107
argv: None,
107108
cmd_line: None,

src/shims/env.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ pub struct EnvVars {
1212

1313
impl EnvVars {
1414
pub(crate) fn init<'mir, 'tcx>(
15+
communicate: bool,
1516
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
1617
tcx: &TyCtxt<'tcx>,
1718
) {
18-
for (name, value) in std::env::vars() {
19-
let value = alloc_env_value(value.as_bytes(), ecx.memory_mut(), tcx);
20-
ecx.machine.env_vars.map.insert(name.into_bytes(), value);
19+
if communicate {
20+
for (name, value) in std::env::vars() {
21+
let value = alloc_env_value(value.as_bytes(), ecx.memory_mut(), tcx);
22+
ecx.machine.env_vars.map.insert(name.into_bytes(), value);
23+
}
2124
}
2225
}
2326

0 commit comments

Comments
 (0)