diff --git a/Cargo.toml b/Cargo.toml index 16b5b2361bd4..721ebe5cfd46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,7 @@ directories = { version = "1.0", optional = true } rustc_version = { version = "0.2.3", optional = true } env_logger = "0.6" log = "0.4" +shell-escape = "0.1.4" # A noop dependency that changes in the Rust repository, it's a bit of a hack. # See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust` # for more information. diff --git a/src/lib.rs b/src/lib.rs index 49c39201d006..f59a476ed94e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,9 +139,19 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>( // FIXME: extract main source file path // Third argument (argv): Created from config.args let dest = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?; + // For Windows, construct a command string with all the aguments + let mut cmd = String::new(); + for arg in config.args.iter() { + if !cmd.is_empty() { + cmd.push(' '); + } + cmd.push_str(&*shell_escape::windows::escape(arg.as_str().into())); + } + cmd.push(std::char::from_u32(0).unwrap()); // don't forget 0 terminator // Collect the pointers to the individual strings. let mut argvs = Vec::>::new(); for arg in config.args { + // Add 0 terminator let mut arg = arg.into_bytes(); arg.push(0); argvs.push(ecx.memory_mut().allocate_static_bytes(arg.as_slice()).with_default_tag()); @@ -165,9 +175,8 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>( } // Store cmdline as UTF-16 for Windows GetCommandLineW { - const CMD: &str = "running-in-miri\0"; let tcx = &{ecx.tcx.tcx}; - let cmd_utf16: Vec = CMD.encode_utf16().collect(); + let cmd_utf16: Vec = cmd.encode_utf16().collect(); let cmd_ptr = ecx.memory_mut().allocate( Size::from_bytes(cmd_utf16.len() as u64 * 2), Align::from_bytes(2).unwrap(),