@@ -121,7 +121,11 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
121
121
122
122
// Second argument (argc): 1
123
123
let dest = ecx. eval_place ( & mir:: Place :: Local ( args. next ( ) . unwrap ( ) ) ) ?;
124
- ecx. write_scalar ( Scalar :: from_int ( 1 , dest. layout . size ) , dest) ?;
124
+ let argc = Scalar :: from_int ( 1 , dest. layout . size ) ;
125
+ ecx. write_scalar ( argc, dest) ?;
126
+ let argc_place = ecx. allocate ( dest. layout , MiriMemoryKind :: Env . into ( ) ) ?;
127
+ ecx. write_scalar ( argc, argc_place. into ( ) ) ?;
128
+ ecx. machine . argc = Some ( argc_place. ptr . to_ptr ( ) ?) ;
125
129
126
130
// FIXME: extract main source file path
127
131
// Third argument (argv): &[b"foo"]
@@ -132,7 +136,11 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
132
136
let foo_place = ecx. allocate ( foo_layout, MiriMemoryKind :: Env . into ( ) ) ?;
133
137
ecx. write_scalar ( Scalar :: Ptr ( foo) , foo_place. into ( ) ) ?;
134
138
ecx. memory_mut ( ) . mark_immutable ( foo_place. to_ptr ( ) ?. alloc_id ) ?;
135
- ecx. write_scalar ( foo_place. ptr , dest) ?;
139
+ let argv = foo_place. ptr ;
140
+ ecx. write_scalar ( argv, dest) ?;
141
+ let argv_place = ecx. allocate ( dest. layout , MiriMemoryKind :: Env . into ( ) ) ?;
142
+ ecx. write_scalar ( argv, argv_place. into ( ) ) ?;
143
+ ecx. machine . argc = Some ( argv_place. ptr . to_ptr ( ) ?) ;
136
144
137
145
assert ! ( args. next( ) . is_none( ) , "start lang item has more arguments than expected" ) ;
138
146
@@ -253,6 +261,11 @@ pub struct Evaluator<'tcx> {
253
261
/// Miri does not expose env vars from the host to the emulated program
254
262
pub ( crate ) env_vars : HashMap < Vec < u8 > , Pointer < Borrow > > ,
255
263
264
+ /// Program arguments (`Option` because we can only initialize them after creating the ecx).
265
+ /// These are *pointers* to argc/argv because macOS.
266
+ pub ( crate ) argc : Option < Pointer < Borrow > > ,
267
+ pub ( crate ) argv : Option < Pointer < Borrow > > ,
268
+
256
269
/// TLS state
257
270
pub ( crate ) tls : TlsData < ' tcx > ,
258
271
@@ -267,6 +280,8 @@ impl<'tcx> Evaluator<'tcx> {
267
280
fn new ( validate : bool ) -> Self {
268
281
Evaluator {
269
282
env_vars : HashMap :: default ( ) ,
283
+ argc : None ,
284
+ argv : None ,
270
285
tls : TlsData :: default ( ) ,
271
286
validate,
272
287
stacked_borrows : stacked_borrows:: State :: default ( ) ,
0 commit comments