]> git.lizzy.rs Git - rust.git/commitdiff
Add -Zmiri-env-exclude flag
authorChristian Poveda <christianpoveda@protonmail.com>
Wed, 28 Aug 2019 22:20:50 +0000 (17:20 -0500)
committerChristian Poveda <christianpoveda@protonmail.com>
Wed, 28 Aug 2019 22:57:35 +0000 (17:57 -0500)
README.md
src/bin/miri-rustc-tests.rs
src/bin/miri.rs
src/eval.rs

index d3e4adfa1785e238bc3997e90122f745e3d372be..3cc4872eb7f099e7c00b63e43a963a5d8dc47eef 100644 (file)
--- a/README.md
+++ b/README.md
@@ -160,6 +160,8 @@ Several `-Z` flags are relevant for Miri:
 * `-Zmiri-disable-isolation` disables host host isolation.  As a consequence,
   the program has access to host resources such as environment variables and
   randomness (and, eventually, file systems and more).
+* `-Zmiri-env-exclude=<var>` keeps the `var` environment variable isolated from 
+  the host. It can be used multiple times to exclude several variables.
 * `-Zmir-opt-level` controls how many MIR optimizations are performed.  Miri
   overrides the default to be `0`; be advised that using any higher level can
   make Miri miss bugs in your program because they got optimized away.
index 9ef64c38638b7033fd22e20c1d1c7342f3baf3e5..f8bd92afbec7f07648f65ae66bb04850c99f7867 100644 (file)
@@ -51,6 +51,7 @@ fn visit_item(&mut self, i: &'hir hir::Item) {
                                 let config = MiriConfig {
                                     validate: true,
                                     communicate: false,
+                                    excluded_env_vars: vec![],
                                     args: vec![],
                                     seed: None,
                                 };
index 55522a52e012891158249c42abf73a0dbf9326ed..6e4bf4a6c269ea10f016a2fb12b6f5d2823be532 100644 (file)
@@ -135,6 +135,7 @@ fn main() {
     let mut rustc_args = vec![];
     let mut miri_args = vec![];
     let mut after_dashdash = false;
+    let mut excluded_env_vars = vec![];
     for arg in std::env::args() {
         if rustc_args.is_empty() {
             // Very first arg: for `rustc`.
@@ -175,6 +176,9 @@ fn main() {
                     seed = Some(u64::from_be_bytes(bytes));
 
                 },
+                arg if arg.starts_with("-Zmiri-env-exclude=") => {
+                    excluded_env_vars.push(arg.trim_start_matches("-Zmiri-env-exclude=").to_owned());
+                },
                 _ => {
                     rustc_args.push(arg);
                 }
@@ -200,7 +204,13 @@ fn main() {
 
     debug!("rustc arguments: {:?}", rustc_args);
     debug!("miri arguments: {:?}", miri_args);
-    let miri_config = miri::MiriConfig { validate, communicate, args: miri_args, seed };
+    let miri_config = miri::MiriConfig {
+        validate,
+        communicate,
+        excluded_env_vars,
+        seed,
+        args: miri_args,
+    };
     let result = rustc_driver::report_ices_to_stderr_if_any(move || {
         rustc_driver::run_compiler(&rustc_args, &mut MiriCompilerCalls { miri_config }, None, None)
     }).and_then(|result| result);
index bd4d8a0bef85e2fb3ba53cffbf16be971747b278..463f21d30ec7a9336b7e2c0fd216f7f80722a055 100644 (file)
@@ -22,6 +22,8 @@ pub struct MiriConfig {
     pub validate: bool,
     /// Determines if communication with the host environment is enabled.
     pub communicate: bool,
+    /// Environment variables that should always be isolated from the host.
+    pub excluded_env_vars: Vec<String>,
     pub args: Vec<String>,
     /// The seed to use when non-determinism or randomness are required (e.g. ptr-to-int cast, `getrandom()`).
     pub seed: Option<u64>,