Skip to content

Commit

Permalink
implement stdout/stderr on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 19, 2018
1 parent d8956f0 commit 51ed485
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
45 changes: 43 additions & 2 deletions src/fn_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,18 +596,59 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
this.write_scalar(Scalar::from_uint(key, dest.layout.size), dest)?;
}
"TlsGetValue" => {
let key = this.read_scalar(args[0])?.to_bits(args[0].layout.size)?;
let key = this.read_scalar(args[0])?.to_u32()? as u128;
let ptr = this.machine.tls.load_tls(key)?;
this.write_scalar(ptr, dest)?;
}
"TlsSetValue" => {
let key = this.read_scalar(args[0])?.to_bits(args[0].layout.size)?;
let key = this.read_scalar(args[0])?.to_u32()? as u128;
let new_ptr = this.read_scalar(args[1])?.not_undef()?;
this.machine.tls.store_tls(key, new_ptr)?;

// Return success (1)
this.write_scalar(Scalar::from_int(1, dest.layout.size), dest)?;
}
"GetStdHandle" => {
let which = this.read_scalar(args[0])?.to_i32()?;
// We just make this the identity function, so we know later in "WriteFile"
// which one it is.
this.write_scalar(Scalar::from_int(which, this.pointer_size()), dest)?;
}
"WriteFile" => {
let handle = this.read_scalar(args[0])?.to_isize(this)?;
let buf = this.read_scalar(args[1])?.not_undef()?;
let n = this.read_scalar(args[2])?.to_u32()?;
let written_place = this.deref_operand(args[3])?;
this.write_null(written_place.into())?; // spec says we always write 0 first
let written = if handle == -11 || handle == -12 {
// stdout/stderr
use std::io::{self, Write};

let buf_cont = this.memory().read_bytes(buf, Size::from_bytes(u64::from(n)))?;
let res = if handle == -11 {
io::stdout().write(buf_cont)
} else {
io::stderr().write(buf_cont)
};
res.ok().map(|n| n as u32)
} else {
eprintln!("Miri: Ignored output to handle {}", handle);
Some(n) // pretend it all went well
};
// If there was no error, write back how much was written
if let Some(n) = written {
this.write_scalar(Scalar::from_uint(n, Size::from_bits(32)), written_place.into())?;
}
// Return whether this was a success
this.write_scalar(
Scalar::from_int(if written.is_some() { 1 } else { 0 }, dest.layout.size),
dest,
)?;
}
"GetConsoleMode" => {
// Everything is a pipe
this.write_null(dest)?;
}

// We can't execute anything else
_ => {
Expand Down
2 changes: 0 additions & 2 deletions tests/run-pass/box-pair-to-vec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//ignore-msvc: Stdout not implemented on Windows

#[repr(C)]
#[derive(Debug)]
struct PairFoo {
Expand Down
1 change: 0 additions & 1 deletion tests/run-pass/catch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//ignore-msvc: Stdout not implemented on Windows
use std::panic::{catch_unwind, AssertUnwindSafe};

fn main() {
Expand Down
1 change: 0 additions & 1 deletion tests/run-pass/format.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//ignore-msvc: Stdout not implemented on Windows
fn main() {
println!("Hello {}", 13);
}
1 change: 0 additions & 1 deletion tests/run-pass/hello.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//ignore-msvc: Stdout not implemented on Windows
fn main() {
println!("Hello, world!");
}
2 changes: 1 addition & 1 deletion tests/run-pass/issue-17877.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

//ignore-windows: Causes a stack overflow?!? Likely a rustc bug: https://github.com/rust-lang/rust/issues/53820
//Once that bug is fixed, increase the size to 16*1024 and enable on all platforms.
//FIXME: Once that bug is fixed, increase the size to 16*1024 and enable on all platforms.

#![feature(slice_patterns)]

Expand Down
1 change: 0 additions & 1 deletion tests/run-pass/issue-3794.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//ignore-msvc: Stdout not implemented on Windows
#![feature(box_syntax)]

trait T {
Expand Down

0 comments on commit 51ed485

Please sign in to comment.