Skip to content

Commit 1ae1d71

Browse files
committed
Add -Zmiri-env-exclude flag
1 parent 2661580 commit 1ae1d71

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ Several `-Z` flags are relevant for Miri:
160160
* `-Zmiri-disable-isolation` disables host host isolation. As a consequence,
161161
the program has access to host resources such as environment variables and
162162
randomness (and, eventually, file systems and more).
163+
* `-Zmiri-env-exclude=<var>` keeps the `var` environment variable isolated from
164+
the host. It can be used multiple times to exclude several variables.
163165
* `-Zmir-opt-level` controls how many MIR optimizations are performed. Miri
164166
overrides the default to be `0`; be advised that using any higher level can
165167
make Miri miss bugs in your program because they got optimized away.

src/bin/miri-rustc-tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
5151
let config = MiriConfig {
5252
validate: true,
5353
communicate: false,
54+
excluded_env_vars: vec![],
5455
args: vec![],
5556
seed: None,
5657
};

src/bin/miri.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ fn main() {
135135
let mut rustc_args = vec![];
136136
let mut miri_args = vec![];
137137
let mut after_dashdash = false;
138+
let mut excluded_env_vars = vec![];
138139
for arg in std::env::args() {
139140
if rustc_args.is_empty() {
140141
// Very first arg: for `rustc`.
@@ -175,6 +176,9 @@ fn main() {
175176
seed = Some(u64::from_be_bytes(bytes));
176177

177178
},
179+
arg if arg.starts_with("-Zmiri-env-exclude=") => {
180+
excluded_env_vars.push(arg.trim_start_matches("-Zmiri-env-exclude=").to_owned());
181+
},
178182
_ => {
179183
rustc_args.push(arg);
180184
}
@@ -200,7 +204,13 @@ fn main() {
200204

201205
debug!("rustc arguments: {:?}", rustc_args);
202206
debug!("miri arguments: {:?}", miri_args);
203-
let miri_config = miri::MiriConfig { validate, communicate, args: miri_args, seed };
207+
let miri_config = miri::MiriConfig {
208+
validate,
209+
communicate,
210+
excluded_env_vars,
211+
seed,
212+
args: miri_args,
213+
};
204214
let result = rustc_driver::report_ices_to_stderr_if_any(move || {
205215
rustc_driver::run_compiler(&rustc_args, &mut MiriCompilerCalls { miri_config }, None, None)
206216
}).and_then(|result| result);

src/eval.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub struct MiriConfig {
2222
pub validate: bool,
2323
/// Determines if communication with the host environment is enabled.
2424
pub communicate: bool,
25+
/// Environment variables that should always be isolated from the host.
26+
pub excluded_env_vars: Vec<String>,
2527
pub args: Vec<String>,
2628
/// The seed to use when non-determinism or randomness are required (e.g. ptr-to-int cast, `getrandom()`).
2729
pub seed: Option<u64>,

0 commit comments

Comments
 (0)