Reorganize shims::env::EnvVars
This commit is contained in:
parent
67d13577aa
commit
afc6713e41
4 changed files with 14 additions and 11 deletions
|
|
@ -12,8 +12,8 @@ use crate::{
|
|||
InterpResult, InterpError, InterpCx, StackPopCleanup, struct_error,
|
||||
Scalar, Tag, Pointer, FnVal,
|
||||
MemoryExtra, MiriMemoryKind, Evaluator, TlsEvalContextExt, HelpersEvalContextExt,
|
||||
ShimsEnvVars,
|
||||
};
|
||||
use crate::shims::env::EnvVars;
|
||||
|
||||
/// Configuration needed to spawn a Miri instance.
|
||||
#[derive(Clone)]
|
||||
|
|
@ -40,6 +40,8 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
|
|||
MemoryExtra::new(StdRng::seed_from_u64(config.seed.unwrap_or(0)), config.validate),
|
||||
);
|
||||
|
||||
ShimsEnvVars::init(config.communicate, &mut ecx, &tcx);
|
||||
|
||||
let main_instance = ty::Instance::mono(ecx.tcx.tcx, main_id);
|
||||
let main_mir = ecx.load_mir(main_instance.def)?;
|
||||
|
||||
|
|
@ -164,10 +166,6 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
|
|||
|
||||
assert!(args.next().is_none(), "start lang item has more arguments than expected");
|
||||
|
||||
if config.communicate {
|
||||
EnvVars::init(&mut ecx, &tcx);
|
||||
}
|
||||
|
||||
Ok(ecx)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ pub use crate::shims::foreign_items::EvalContextExt as ForeignItemsEvalContextEx
|
|||
pub use crate::shims::intrinsics::EvalContextExt as IntrinsicsEvalContextExt;
|
||||
pub use crate::shims::tls::{EvalContextExt as TlsEvalContextExt, TlsData};
|
||||
pub use crate::shims::dlsym::{Dlsym, EvalContextExt as DlsymEvalContextExt};
|
||||
pub use crate::shims::env::{EnvVars as ShimsEnvVars};
|
||||
pub use crate::operator::EvalContextExt as OperatorEvalContextExt;
|
||||
pub use crate::range_map::RangeMap;
|
||||
pub use crate::helpers::{EvalContextExt as HelpersEvalContextExt};
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ use rustc::ty::{self, layout::{Size, LayoutOf}, TyCtxt};
|
|||
use rustc::mir;
|
||||
|
||||
use crate::*;
|
||||
use crate::shims::env::EnvVars;
|
||||
|
||||
// Some global facts about the emulated machine.
|
||||
pub const PAGE_SIZE: u64 = 4*1024; // FIXME: adjust to target architecture
|
||||
|
|
@ -79,7 +78,7 @@ impl MemoryExtra {
|
|||
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: ShimsEnvVars,
|
||||
|
||||
/// Program arguments (`Option` because we can only initialize them after creating the ecx).
|
||||
/// These are *pointers* to argc/argv because macOS.
|
||||
|
|
@ -101,7 +100,9 @@ pub struct Evaluator<'tcx> {
|
|||
impl<'tcx> Evaluator<'tcx> {
|
||||
pub(crate) fn new(communicate: bool) -> Self {
|
||||
Evaluator {
|
||||
env_vars: EnvVars::default(),
|
||||
// `env_vars` could be initialized properly here if `Memory` were available before
|
||||
// calling this method.
|
||||
env_vars: ShimsEnvVars::default(),
|
||||
argc: None,
|
||||
argv: None,
|
||||
cmd_line: None,
|
||||
|
|
|
|||
|
|
@ -12,12 +12,15 @@ pub struct EnvVars {
|
|||
|
||||
impl EnvVars {
|
||||
pub(crate) fn init<'mir, 'tcx>(
|
||||
communicate: bool,
|
||||
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
|
||||
tcx: &TyCtxt<'tcx>,
|
||||
) {
|
||||
for (name, value) in std::env::vars() {
|
||||
let value = alloc_env_value(value.as_bytes(), ecx.memory_mut(), tcx);
|
||||
ecx.machine.env_vars.map.insert(name.into_bytes(), value);
|
||||
if communicate {
|
||||
for (name, value) in std::env::vars() {
|
||||
let value = alloc_env_value(value.as_bytes(), ecx.memory_mut(), tcx);
|
||||
ecx.machine.env_vars.map.insert(name.into_bytes(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue