Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable env communication #894

Merged
merged 12 commits into from
Aug 14, 2019
8 changes: 3 additions & 5 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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);
pvdrz marked this conversation as resolved.
Show resolved Hide resolved

let main_instance = ty::Instance::mono(ecx.tcx.tcx, main_id);
pvdrz marked this conversation as resolved.
Show resolved Hide resolved
let main_mir = ecx.load_mir(main_instance.def)?;

Expand Down Expand Up @@ -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)
}

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
pvdrz marked this conversation as resolved.
Show resolved Hide resolved
pub use crate::operator::EvalContextExt as OperatorEvalContextExt;
pub use crate::range_map::RangeMap;
pub use crate::helpers::{EvalContextExt as HelpersEvalContextExt};
Expand Down
7 changes: 4 additions & 3 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions src/shims/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ pub struct EnvVars {

impl EnvVars {
pub(crate) fn init<'mir, 'tcx>(
communicate: bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I entirely forgot that the machine has this flag. So can you remove this parameter, and use ecx.machine.communicate instead?

Copy link
Member

@RalfJung RalfJung Aug 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are probably asleep, I'll do this as part of #909.

ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
tcx: &TyCtxt<'tcx>,
pvdrz marked this conversation as resolved.
Show resolved Hide resolved
) {
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);
}
}
}

Expand Down