@@ -220,8 +220,10 @@ impl Default for MiriConfig {
220
220
enum MainThreadState < ' tcx > {
221
221
GlobalCtors {
222
222
ctor_state : ctor:: GlobalCtorState < ' tcx > ,
223
+ /// The main function to call.
223
224
entry_id : DefId ,
224
225
entry_type : MiriEntryFnType ,
226
+ /// Arguments passed to `main`.
225
227
argc : ImmTy < ' tcx > ,
226
228
argv : ImmTy < ' tcx > ,
227
229
} ,
@@ -324,12 +326,9 @@ pub fn create_ecx<'tcx>(
324
326
MiriMachine :: new ( config, layout_cx, genmc_ctx) ,
325
327
) ;
326
328
327
- // First argument is constructed later, because it's skipped for `miri_start.`
328
-
329
- // Second argument (argc): length of `config.args`.
329
+ // Compute argc and argv from `config.args`.
330
330
let argc =
331
331
ImmTy :: from_int ( i64:: try_from ( config. args . len ( ) ) . unwrap ( ) , ecx. machine . layouts . isize ) ;
332
- // Third argument (`argv`): created from `config.args`.
333
332
let argv = {
334
333
// Put each argument in memory, collect pointers.
335
334
let mut argvs = Vec :: < Immediate < Provenance > > :: with_capacity ( config. args . len ( ) ) ;
@@ -354,7 +353,7 @@ pub fn create_ecx<'tcx>(
354
353
ecx. write_immediate ( arg, & place) ?;
355
354
}
356
355
ecx. mark_immutable ( & argvs_place) ;
357
- // Store `argc` and `argv` for macOS `_NSGetArg{c,v}`.
356
+ // Store `argc` and `argv` for macOS `_NSGetArg{c,v}`, and for the GC to see them .
358
357
{
359
358
let argc_place =
360
359
ecx. allocate ( ecx. machine . layouts . isize , MiriMemoryKind :: Machine . into ( ) ) ?;
@@ -369,7 +368,7 @@ pub fn create_ecx<'tcx>(
369
368
ecx. machine . argv = Some ( argv_place. ptr ( ) ) ;
370
369
}
371
370
// Store command line as UTF-16 for Windows `GetCommandLineW`.
372
- {
371
+ if tcx . sess . target . os == "windows" {
373
372
// Construct a command string with all the arguments.
374
373
let cmd_utf16: Vec < u16 > = args_to_utf16_command_string ( config. args . iter ( ) ) ;
375
374
@@ -392,7 +391,7 @@ pub fn create_ecx<'tcx>(
392
391
393
392
// Some parts of initialization require a full `InterpCx`.
394
393
MiriMachine :: late_init ( & mut ecx, config, {
395
- let mut state = MainThreadState :: GlobalCtors {
394
+ let mut main_thread_state = MainThreadState :: GlobalCtors {
396
395
entry_id,
397
396
entry_type,
398
397
argc,
@@ -401,7 +400,9 @@ pub fn create_ecx<'tcx>(
401
400
} ;
402
401
403
402
// Cannot capture anything GC-relevant here.
404
- Box :: new ( move |m| state. on_main_stack_empty ( m) )
403
+ // `argc` and `argv` *are* GC_relevant, but they also get stored in `machine.argc` and
404
+ // `machine.argv` so we are good.
405
+ Box :: new ( move |m| main_thread_state. on_main_stack_empty ( m) )
405
406
} ) ?;
406
407
407
408
// Make sure we have MIR. We check MIR for some stable monomorphic function in libcore.
0 commit comments