@@ -71,9 +71,7 @@ impl<'tcx> UnixEnvVars<'tcx> {
7171 self . environ . ptr ( )
7272 }
7373
74- /// Implementation detail for [`InterpCx::get_env_var`]. This basically does `getenv`, complete
75- /// with the reads of the environment, but returns an [`OsString`] instead of a pointer.
76- pub ( crate ) fn get < ' mir > (
74+ fn get_ptr < ' mir > (
7775 & self ,
7876 ecx : & InterpCx < ' mir , ' tcx , MiriMachine < ' mir , ' tcx > > ,
7977 name : & OsStr ,
@@ -91,6 +89,22 @@ impl<'tcx> UnixEnvVars<'tcx> {
9189 ) ?;
9290 Ok ( Some ( var_ptr) )
9391 }
92+
93+ /// Implementation detail for [`InterpCx::get_env_var`]. This basically does `getenv`, complete
94+ /// with the reads of the environment, but returns an [`OsString`] instead of a pointer.
95+ pub ( crate ) fn get < ' mir > (
96+ & self ,
97+ ecx : & InterpCx < ' mir , ' tcx , MiriMachine < ' mir , ' tcx > > ,
98+ name : & OsStr ,
99+ ) -> InterpResult < ' tcx , Option < OsString > > {
100+ let var_ptr = self . get_ptr ( ecx, name) ?;
101+ if let Some ( ptr) = var_ptr {
102+ let var = ecx. read_os_str_from_c_str ( ptr) ?;
103+ Ok ( Some ( var. to_owned ( ) ) )
104+ } else {
105+ Ok ( None )
106+ }
107+ }
94108}
95109
96110fn alloc_env_var < ' mir , ' tcx > (
@@ -137,7 +151,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
137151 let name_ptr = this. read_pointer ( name_op) ?;
138152 let name = this. read_os_str_from_c_str ( name_ptr) ?;
139153
140- let var_ptr = this. machine . env_vars . unix ( ) . get ( this, name) ?;
154+ let var_ptr = this. machine . env_vars . unix ( ) . get_ptr ( this, name) ?;
141155 Ok ( var_ptr. unwrap_or_else ( Pointer :: null) )
142156 }
143157
0 commit comments