File tree Expand file tree Collapse file tree 3 files changed +16
-5
lines changed Expand file tree Collapse file tree 3 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -306,6 +306,11 @@ fn parse_comma_list<T: FromStr>(input: &str) -> Result<Vec<T>, T::Err> {
306
306
}
307
307
308
308
fn main ( ) {
309
+ // Snapshot a copy of the environment before `rustc` starts messing with it.
310
+ // (`install_ice_hook` might change `RUST_BACKTRACE`.)
311
+ let env_snapshot = env:: vars_os ( ) . collect :: < Vec < _ > > ( ) ;
312
+
313
+ // Earliest rustc setup.
309
314
rustc_driver:: install_ice_hook ( ) ;
310
315
311
316
// If the environment asks us to actually be rustc, then do that.
@@ -333,6 +338,8 @@ fn main() {
333
338
334
339
// Parse our arguments and split them across `rustc` and `miri`.
335
340
let mut miri_config = miri:: MiriConfig :: default ( ) ;
341
+ miri_config. env = env_snapshot;
342
+
336
343
let mut rustc_args = vec ! [ ] ;
337
344
let mut after_dashdash = false ;
338
345
Original file line number Diff line number Diff line change 1
1
//! Main evaluator loop and setting up the initial stack frame.
2
2
3
3
use std:: collections:: HashSet ;
4
- use std:: ffi:: OsStr ;
4
+ use std:: ffi:: { OsStr , OsString } ;
5
5
use std:: iter;
6
6
use std:: panic:: { self , AssertUnwindSafe } ;
7
7
use std:: thread;
@@ -72,6 +72,9 @@ pub enum BacktraceStyle {
72
72
/// Configuration needed to spawn a Miri instance.
73
73
#[ derive( Clone ) ]
74
74
pub struct MiriConfig {
75
+ /// The host environment snapshot to use as basis for what is provided to the interpreted program.
76
+ /// (This is still subject to isolation as well as `excluded_env_vars` and `forwarded_env_vars`.)
77
+ pub env : Vec < ( OsString , OsString ) > ,
75
78
/// Determine if validity checking is enabled.
76
79
pub validate : bool ,
77
80
/// Determines if Stacked Borrows is enabled.
@@ -130,6 +133,7 @@ pub struct MiriConfig {
130
133
impl Default for MiriConfig {
131
134
fn default ( ) -> MiriConfig {
132
135
MiriConfig {
136
+ env : vec ! [ ] ,
133
137
validate : true ,
134
138
stacked_borrows : true ,
135
139
check_alignment : AlignmentCheck :: Int ,
Original file line number Diff line number Diff line change @@ -49,11 +49,11 @@ impl<'tcx> EnvVars<'tcx> {
49
49
50
50
// Skip the loop entirely if we don't want to forward anything.
51
51
if ecx. machine . communicate ( ) || !config. forwarded_env_vars . is_empty ( ) {
52
- for ( name, value) in env:: vars_os ( ) {
52
+ for ( name, value) in & config . env {
53
53
// Always forward what is in `forwarded_env_vars`; that list can take precedence over excluded_env_vars.
54
- let forward = config. forwarded_env_vars . iter ( ) . any ( |v| * * v == name)
54
+ let forward = config. forwarded_env_vars . iter ( ) . any ( |v| * * v == * name)
55
55
|| ( ecx. machine . communicate ( )
56
- && !excluded_env_vars. iter ( ) . any ( |v| * * v == name) ) ;
56
+ && !excluded_env_vars. iter ( ) . any ( |v| * * v == * name) ) ;
57
57
if forward {
58
58
let var_ptr = match target_os {
59
59
target if target_os_is_unix ( target) =>
@@ -65,7 +65,7 @@ impl<'tcx> EnvVars<'tcx> {
65
65
unsupported
66
66
) ,
67
67
} ;
68
- ecx. machine . env_vars . map . insert ( name, var_ptr) ;
68
+ ecx. machine . env_vars . map . insert ( name. clone ( ) , var_ptr) ;
69
69
}
70
70
}
71
71
}
You can’t perform that action at this time.
0 commit comments