Skip to content

Commit 51ed485

Browse files
committed
implement stdout/stderr on Windows
1 parent d8956f0 commit 51ed485

File tree

7 files changed

+44
-9
lines changed

7 files changed

+44
-9
lines changed

src/fn_call.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,18 +596,59 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
596596
this.write_scalar(Scalar::from_uint(key, dest.layout.size), dest)?;
597597
}
598598
"TlsGetValue" => {
599-
let key = this.read_scalar(args[0])?.to_bits(args[0].layout.size)?;
599+
let key = this.read_scalar(args[0])?.to_u32()? as u128;
600600
let ptr = this.machine.tls.load_tls(key)?;
601601
this.write_scalar(ptr, dest)?;
602602
}
603603
"TlsSetValue" => {
604-
let key = this.read_scalar(args[0])?.to_bits(args[0].layout.size)?;
604+
let key = this.read_scalar(args[0])?.to_u32()? as u128;
605605
let new_ptr = this.read_scalar(args[1])?.not_undef()?;
606606
this.machine.tls.store_tls(key, new_ptr)?;
607607

608608
// Return success (1)
609609
this.write_scalar(Scalar::from_int(1, dest.layout.size), dest)?;
610610
}
611+
"GetStdHandle" => {
612+
let which = this.read_scalar(args[0])?.to_i32()?;
613+
// We just make this the identity function, so we know later in "WriteFile"
614+
// which one it is.
615+
this.write_scalar(Scalar::from_int(which, this.pointer_size()), dest)?;
616+
}
617+
"WriteFile" => {
618+
let handle = this.read_scalar(args[0])?.to_isize(this)?;
619+
let buf = this.read_scalar(args[1])?.not_undef()?;
620+
let n = this.read_scalar(args[2])?.to_u32()?;
621+
let written_place = this.deref_operand(args[3])?;
622+
this.write_null(written_place.into())?; // spec says we always write 0 first
623+
let written = if handle == -11 || handle == -12 {
624+
// stdout/stderr
625+
use std::io::{self, Write};
626+
627+
let buf_cont = this.memory().read_bytes(buf, Size::from_bytes(u64::from(n)))?;
628+
let res = if handle == -11 {
629+
io::stdout().write(buf_cont)
630+
} else {
631+
io::stderr().write(buf_cont)
632+
};
633+
res.ok().map(|n| n as u32)
634+
} else {
635+
eprintln!("Miri: Ignored output to handle {}", handle);
636+
Some(n) // pretend it all went well
637+
};
638+
// If there was no error, write back how much was written
639+
if let Some(n) = written {
640+
this.write_scalar(Scalar::from_uint(n, Size::from_bits(32)), written_place.into())?;
641+
}
642+
// Return whether this was a success
643+
this.write_scalar(
644+
Scalar::from_int(if written.is_some() { 1 } else { 0 }, dest.layout.size),
645+
dest,
646+
)?;
647+
}
648+
"GetConsoleMode" => {
649+
// Everything is a pipe
650+
this.write_null(dest)?;
651+
}
611652

612653
// We can't execute anything else
613654
_ => {

tests/run-pass/box-pair-to-vec.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//ignore-msvc: Stdout not implemented on Windows
2-
31
#[repr(C)]
42
#[derive(Debug)]
53
struct PairFoo {

tests/run-pass/catch.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//ignore-msvc: Stdout not implemented on Windows
21
use std::panic::{catch_unwind, AssertUnwindSafe};
32

43
fn main() {

tests/run-pass/format.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//ignore-msvc: Stdout not implemented on Windows
21
fn main() {
32
println!("Hello {}", 13);
43
}

tests/run-pass/hello.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//ignore-msvc: Stdout not implemented on Windows
21
fn main() {
32
println!("Hello, world!");
43
}

tests/run-pass/issue-17877.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

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

1414
#![feature(slice_patterns)]
1515

tests/run-pass/issue-3794.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

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

1413
trait T {

0 commit comments

Comments
 (0)