@@ -3,6 +3,7 @@ use std::ffi::{OsString, OsStr};
3
3
use std:: env;
4
4
5
5
use crate :: stacked_borrows:: Tag ;
6
+ use crate :: rustc_target:: abi:: LayoutOf ;
6
7
use crate :: * ;
7
8
8
9
use rustc:: ty:: layout:: Size ;
@@ -20,15 +21,31 @@ impl EnvVars {
20
21
ecx : & mut InterpCx < ' mir , ' tcx , Evaluator < ' tcx > > ,
21
22
excluded_env_vars : Vec < String > ,
22
23
) {
24
+ let mut vars = Vec :: new ( ) ;
23
25
if ecx. machine . communicate {
26
+ // Put each environment variable pointer in `EnvVars`, collect pointers.
24
27
for ( name, value) in env:: vars ( ) {
25
28
if !excluded_env_vars. contains ( & name) {
26
29
let var_ptr =
27
30
alloc_env_var_as_c_str ( name. as_ref ( ) , value. as_ref ( ) , ecx) ;
28
31
ecx. machine . env_vars . map . insert ( OsString :: from ( name) , var_ptr) ;
32
+ vars. push ( var_ptr) ;
29
33
}
30
34
}
31
35
}
36
+ // Make an array with all these pointers, in the Miri memory.
37
+ let tcx = ecx. tcx ;
38
+ let environ_layout =
39
+ ecx. layout_of ( tcx. mk_array ( tcx. mk_imm_ptr ( tcx. types . u8 ) , vars. len ( ) as u64 ) ) . unwrap ( ) ;
40
+ let environ_place = ecx. allocate ( environ_layout, MiriMemoryKind :: Env . into ( ) ) ;
41
+ for ( idx, var) in vars. into_iter ( ) . enumerate ( ) {
42
+ let place = ecx. mplace_field ( environ_place, idx as u64 ) . unwrap ( ) ;
43
+ ecx. write_scalar ( var, place. into ( ) ) . unwrap ( ) ;
44
+ }
45
+ ecx. memory . mark_immutable ( environ_place. ptr . assert_ptr ( ) . alloc_id ) . unwrap ( ) ;
46
+ // A pointer to that place corresponds to the `environ` static.
47
+ let environ_alloc = ecx. memory . get_raw ( environ_place. ptr . assert_ptr ( ) . alloc_id ) . unwrap ( ) . clone ( ) ;
48
+ ecx. memory . extra . environ = Some ( environ_alloc) ;
32
49
}
33
50
}
34
51
0 commit comments