also pass actual arguments to Windows

This commit is contained in:
Ralf Jung 2019-02-08 20:37:07 +01:00
parent e400b42c21
commit 5e468766b7
2 changed files with 12 additions and 2 deletions

View file

@ -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.

View file

@ -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::<Pointer<Borrow>>::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<u16> = CMD.encode_utf16().collect();
let cmd_utf16: Vec<u16> = 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(),