11use rustc_middle:: mir;
2- use rustc_target:: abi:: Size ;
32use rustc_target:: spec:: abi:: Abi ;
43
54use log:: trace;
@@ -11,7 +10,6 @@ use crate::*;
1110
1211#[ derive( Debug , Copy , Clone ) ]
1312pub enum Dlsym {
14- NtWriteFile ,
1513 SetThreadDescription ,
1614 WaitOnAddress ,
1715 WakeByAddressSingle ,
@@ -23,7 +21,6 @@ impl Dlsym {
2321 pub fn from_str < ' tcx > ( name : & str ) -> InterpResult < ' tcx , Option < Dlsym > > {
2422 Ok ( match name {
2523 "GetSystemTimePreciseAsFileTime" => None ,
26- "NtWriteFile" => Some ( Dlsym :: NtWriteFile ) ,
2724 "SetThreadDescription" => Some ( Dlsym :: SetThreadDescription ) ,
2825 "WaitOnAddress" => Some ( Dlsym :: WaitOnAddress ) ,
2926 "WakeByAddressSingle" => Some ( Dlsym :: WakeByAddressSingle ) ,
@@ -49,72 +46,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
4946 this. check_abi ( abi, Abi :: System { unwind : false } ) ?;
5047
5148 match dlsym {
52- Dlsym :: NtWriteFile => {
53- if !this. frame_in_std ( ) {
54- throw_unsup_format ! (
55- "`NtWriteFile` support is crude and just enough for stdout to work"
56- ) ;
57- }
58-
59- let [
60- handle,
61- _event,
62- _apc_routine,
63- _apc_context,
64- io_status_block,
65- buf,
66- n,
67- byte_offset,
68- _key,
69- ] = check_arg_count ( args) ?;
70- let handle = this. read_target_isize ( handle) ?;
71- let buf = this. read_pointer ( buf) ?;
72- let n = this. read_scalar ( n) ?. to_u32 ( ) ?;
73- let byte_offset = this. read_target_usize ( byte_offset) ?; // is actually a pointer
74- let io_status_block = this. deref_operand ( io_status_block) ?;
75-
76- if byte_offset != 0 {
77- throw_unsup_format ! (
78- "`NtWriteFile` `ByteOffset` paremeter is non-null, which is unsupported"
79- ) ;
80- }
81-
82- let written = if handle == -11 || handle == -12 {
83- // stdout/stderr
84- use std:: io:: { self , Write } ;
85-
86- let buf_cont =
87- this. read_bytes_ptr_strip_provenance ( buf, Size :: from_bytes ( u64:: from ( n) ) ) ?;
88- let res = if this. machine . mute_stdout_stderr {
89- Ok ( buf_cont. len ( ) )
90- } else if handle == -11 {
91- io:: stdout ( ) . write ( buf_cont)
92- } else {
93- io:: stderr ( ) . write ( buf_cont)
94- } ;
95- // We write at most `n` bytes, which is a `u32`, so we cannot have written more than that.
96- res. ok ( ) . map ( |n| u32:: try_from ( n) . unwrap ( ) )
97- } else {
98- throw_unsup_format ! (
99- "on Windows, writing to anything except stdout/stderr is not supported"
100- )
101- } ;
102- // We have to put the result into io_status_block.
103- if let Some ( n) = written {
104- let io_status_information =
105- this. mplace_field_named ( & io_status_block, "Information" ) ?;
106- this. write_scalar (
107- Scalar :: from_target_usize ( n. into ( ) , this) ,
108- & io_status_information. into ( ) ,
109- ) ?;
110- }
111- // Return whether this was a success. >= 0 is success.
112- // For the error code we arbitrarily pick 0xC0000185, STATUS_IO_DEVICE_ERROR.
113- this. write_scalar (
114- Scalar :: from_u32 ( if written. is_some ( ) { 0 } else { 0xC0000185u32 } ) ,
115- dest,
116- ) ?;
117- }
11849 Dlsym :: SetThreadDescription => {
11950 let [ handle, name] = check_arg_count ( args) ?;
12051
0 commit comments