Skip to content

Commit f108e34

Browse files
committed
Auto merge of #2055 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 8acc9b2 + b4c4d65 commit f108e34

File tree

6 files changed

+94
-41
lines changed

6 files changed

+94
-41
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bbe9d27b8ff36da56638aa43d6d0cdfdf89a4e57
1+
1a4b9a85634c17a60e8802307510c300a35a4b9b

src/machine.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
605605

606606
#[inline(always)]
607607
fn memory_read(
608+
_tcx: TyCtxt<'tcx>,
608609
machine: &Self,
609610
alloc_extra: &AllocExtra,
610611
tag: Tag,
@@ -627,6 +628,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
627628

628629
#[inline(always)]
629630
fn memory_written(
631+
_tcx: TyCtxt<'tcx>,
630632
machine: &mut Self,
631633
alloc_extra: &mut AllocExtra,
632634
tag: Tag,
@@ -649,6 +651,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
649651

650652
#[inline(always)]
651653
fn memory_deallocated(
654+
_tcx: TyCtxt<'tcx>,
652655
machine: &mut Self,
653656
alloc_extra: &mut AllocExtra,
654657
tag: Tag,

src/shims/windows/dlsym.rs

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
use rustc_middle::mir;
2+
use rustc_target::abi::Size;
23
use rustc_target::spec::abi::Abi;
34

5+
use log::trace;
6+
7+
use crate::helpers::check_arg_count;
48
use crate::*;
59

610
#[derive(Debug, Copy, Clone)]
7-
pub enum Dlsym {}
11+
pub enum Dlsym {
12+
NtWriteFile,
13+
}
814

915
impl Dlsym {
1016
// Returns an error for unsupported symbols, and None if this symbol
1117
// should become a NULL pointer (pretend it does not exist).
1218
pub fn from_str(name: &str) -> InterpResult<'static, Option<Dlsym>> {
1319
Ok(match name {
1420
"GetSystemTimePreciseAsFileTime" => None,
21+
"NtWriteFile" => Some(Dlsym::NtWriteFile),
1522
_ => throw_unsup_format!("unsupported Windows dlsym: {}", name),
1623
})
1724
}
@@ -23,15 +30,85 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2330
&mut self,
2431
dlsym: Dlsym,
2532
abi: Abi,
26-
_args: &[OpTy<'tcx, Tag>],
33+
args: &[OpTy<'tcx, Tag>],
2734
ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
2835
) -> InterpResult<'tcx> {
2936
let this = self.eval_context_mut();
30-
let (_dest, _ret) = ret.expect("we don't support any diverging dlsym");
37+
let (dest, ret) = ret.expect("we don't support any diverging dlsym");
3138
assert!(this.tcx.sess.target.os == "windows");
3239

3340
this.check_abi(abi, Abi::System { unwind: false })?;
3441

35-
match dlsym {}
42+
match dlsym {
43+
Dlsym::NtWriteFile => {
44+
if !this.frame_in_std() {
45+
throw_unsup_format!(
46+
"NtWriteFile support is crude and just enough for stdout to work"
47+
);
48+
}
49+
50+
let &[
51+
ref handle,
52+
ref _event,
53+
ref _apc_routine,
54+
ref _apc_context,
55+
ref io_status_block,
56+
ref buf,
57+
ref n,
58+
ref byte_offset,
59+
ref _key,
60+
] = check_arg_count(args)?;
61+
let handle = this.read_scalar(handle)?.to_machine_isize(this)?;
62+
let buf = this.read_pointer(buf)?;
63+
let n = this.read_scalar(n)?.to_u32()?;
64+
let byte_offset = this.read_scalar(byte_offset)?.to_machine_usize(this)?;
65+
let io_status_block = this.deref_operand(io_status_block)?;
66+
67+
if byte_offset != 0 {
68+
throw_unsup_format!(
69+
"NtWriteFile ByteOffset paremeter is non-null, which is unsupported"
70+
);
71+
}
72+
73+
let written = if handle == -11 || handle == -12 {
74+
// stdout/stderr
75+
use std::io::{self, Write};
76+
77+
let buf_cont = this.read_bytes_ptr(buf, Size::from_bytes(u64::from(n)))?;
78+
let res = if handle == -11 {
79+
io::stdout().write(buf_cont)
80+
} else {
81+
io::stderr().write(buf_cont)
82+
};
83+
res.ok().map(|n| n as u32)
84+
} else {
85+
throw_unsup_format!(
86+
"on Windows, writing to anything except stdout/stderr is not supported"
87+
)
88+
};
89+
// We have to put the result into io_status_block.
90+
if let Some(n) = written {
91+
let io_status_information =
92+
this.mplace_field_named(&io_status_block, "Information")?;
93+
this.write_scalar(
94+
Scalar::from_machine_usize(n.into(), this),
95+
&io_status_information.into(),
96+
)?;
97+
}
98+
// Return whether this was a success. >= 0 is success.
99+
// For the error code we arbitrarily pick 0xC0000185, STATUS_IO_DEVICE_ERROR.
100+
this.write_scalar(
101+
Scalar::from_machine_isize(
102+
if written.is_some() { 0 } else { (0xC0000185u32 as i32).into() },
103+
this,
104+
),
105+
dest,
106+
)?;
107+
}
108+
}
109+
110+
trace!("{:?}", this.dump_place(**dest));
111+
this.go_to_block(ret);
112+
Ok(())
36113
}
37114
}

src/shims/windows/foreign_items.rs

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,43 +69,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6969
let &[ref which] =
7070
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
7171
let which = this.read_scalar(which)?.to_i32()?;
72-
// We just make this the identity function, so we know later in `WriteFile`
72+
// We just make this the identity function, so we know later in `NtWriteFile`
7373
// which one it is.
7474
this.write_scalar(Scalar::from_machine_isize(which.into(), this), dest)?;
7575
}
76-
"WriteFile" => {
77-
let &[ref handle, ref buf, ref n, ref written_ptr, ref overlapped] =
78-
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
79-
this.read_scalar(overlapped)?.to_machine_usize(this)?; // this is a poiner, that we ignore
80-
let handle = this.read_scalar(handle)?.to_machine_isize(this)?;
81-
let buf = this.read_pointer(buf)?;
82-
let n = this.read_scalar(n)?.to_u32()?;
83-
let written_place = this.deref_operand(written_ptr)?;
84-
// Spec says to always write `0` first.
85-
this.write_null(&written_place.into())?;
86-
let written = if handle == -11 || handle == -12 {
87-
// stdout/stderr
88-
use std::io::{self, Write};
89-
90-
let buf_cont = this.read_bytes_ptr(buf, Size::from_bytes(u64::from(n)))?;
91-
let res = if handle == -11 {
92-
io::stdout().write(buf_cont)
93-
} else {
94-
io::stderr().write(buf_cont)
95-
};
96-
res.ok().map(|n| n as u32)
97-
} else {
98-
throw_unsup_format!(
99-
"on Windows, writing to anything except stdout/stderr is not supported"
100-
)
101-
};
102-
// If there was no error, write back how much was written.
103-
if let Some(n) = written {
104-
this.write_scalar(Scalar::from_u32(n), &written_place.into())?;
105-
}
106-
// Return whether this was a success.
107-
this.write_scalar(Scalar::from_i32(if written.is_some() { 1 } else { 0 }), dest)?;
108-
}
10976

11077
// Allocation
11178
"HeapAlloc" => {
@@ -350,6 +317,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
350317
// Just fake a HANDLE
351318
this.write_scalar(Scalar::from_machine_isize(1, this), dest)?;
352319
}
320+
"GetModuleHandleA" if this.frame_in_std() => {
321+
#[allow(non_snake_case)]
322+
let &[_lpModuleName] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
323+
// We need to return something non-null here to make `compat_fn!` work.
324+
this.write_scalar(Scalar::from_machine_isize(1, this), dest)?;
325+
}
353326
"SetConsoleTextAttribute" if this.frame_in_std() => {
354327
#[allow(non_snake_case)]
355328
let &[ref _hConsoleOutput, ref _wAttribute] =

tests/run-pass/concurrency/simple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
2-
// compile-flags: -Zmiri-check-number-validity
2+
// compile-flags: -Zmiri-strict-provenance
33

44
use std::thread;
55

tests/run-pass/vecdeque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626
assert_eq!(**a, 2);
2727
}
2828

29-
// Regression test for Debug and Diaplay impl's
29+
// Regression test for Debug impl's
3030
println!("{:?} {:?}", dst, dst.iter());
3131
println!("{:?}", VecDeque::<u32>::new().iter());
3232

0 commit comments

Comments
 (0)