@@ -11,6 +11,7 @@ use std::time::SystemTime;
11
11
use log:: trace;
12
12
13
13
use rustc_data_structures:: fx:: FxHashMap ;
14
+ use rustc_middle:: ty:: TyCtxt ;
14
15
use rustc_target:: abi:: { Align , Size } ;
15
16
16
17
use crate :: shims:: os_str:: bytes_to_os_str;
@@ -31,6 +32,7 @@ pub trait FileDescriptor: std::fmt::Debug + helpers::AsAny {
31
32
& mut self ,
32
33
_communicate_allowed : bool ,
33
34
_bytes : & mut [ u8 ] ,
35
+ _tcx : TyCtxt < ' tcx > ,
34
36
) -> InterpResult < ' tcx , io:: Result < usize > > {
35
37
throw_unsup_format ! ( "cannot read from {}" , self . name( ) ) ;
36
38
}
@@ -39,6 +41,7 @@ pub trait FileDescriptor: std::fmt::Debug + helpers::AsAny {
39
41
& self ,
40
42
_communicate_allowed : bool ,
41
43
_bytes : & [ u8 ] ,
44
+ _tcx : TyCtxt < ' tcx > ,
42
45
) -> InterpResult < ' tcx , io:: Result < usize > > {
43
46
throw_unsup_format ! ( "cannot write to {}" , self . name( ) ) ;
44
47
}
@@ -79,6 +82,7 @@ impl FileDescriptor for FileHandle {
79
82
& mut self ,
80
83
communicate_allowed : bool ,
81
84
bytes : & mut [ u8 ] ,
85
+ _tcx : TyCtxt < ' tcx > ,
82
86
) -> InterpResult < ' tcx , io:: Result < usize > > {
83
87
assert ! ( communicate_allowed, "isolation should have prevented even opening a file" ) ;
84
88
Ok ( self . file . read ( bytes) )
@@ -88,6 +92,7 @@ impl FileDescriptor for FileHandle {
88
92
& self ,
89
93
communicate_allowed : bool ,
90
94
bytes : & [ u8 ] ,
95
+ _tcx : TyCtxt < ' tcx > ,
91
96
) -> InterpResult < ' tcx , io:: Result < usize > > {
92
97
assert ! ( communicate_allowed, "isolation should have prevented even opening a file" ) ;
93
98
Ok ( ( & mut & self . file ) . write ( bytes) )
@@ -153,6 +158,7 @@ impl FileDescriptor for io::Stdin {
153
158
& mut self ,
154
159
communicate_allowed : bool ,
155
160
bytes : & mut [ u8 ] ,
161
+ _tcx : TyCtxt < ' tcx > ,
156
162
) -> InterpResult < ' tcx , io:: Result < usize > > {
157
163
if !communicate_allowed {
158
164
// We want isolation mode to be deterministic, so we have to disallow all reads, even stdin.
@@ -184,6 +190,7 @@ impl FileDescriptor for io::Stdout {
184
190
& self ,
185
191
_communicate_allowed : bool ,
186
192
bytes : & [ u8 ] ,
193
+ _tcx : TyCtxt < ' tcx > ,
187
194
) -> InterpResult < ' tcx , io:: Result < usize > > {
188
195
// We allow writing to stderr even with isolation enabled.
189
196
let result = Write :: write ( & mut { self } , bytes) ;
@@ -220,6 +227,7 @@ impl FileDescriptor for io::Stderr {
220
227
& self ,
221
228
_communicate_allowed : bool ,
222
229
bytes : & [ u8 ] ,
230
+ _tcx : TyCtxt < ' tcx > ,
223
231
) -> InterpResult < ' tcx , io:: Result < usize > > {
224
232
// We allow writing to stderr even with isolation enabled.
225
233
// No need to flush, stderr is not buffered.
@@ -252,6 +260,7 @@ impl FileDescriptor for NullOutput {
252
260
& self ,
253
261
_communicate_allowed : bool ,
254
262
bytes : & [ u8 ] ,
263
+ _tcx : TyCtxt < ' tcx > ,
255
264
) -> InterpResult < ' tcx , io:: Result < usize > > {
256
265
// We just don't write anything, but report to the user that we did.
257
266
Ok ( Ok ( bytes. len ( ) ) )
@@ -756,8 +765,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
756
765
let mut bytes = vec ! [ 0 ; usize :: try_from( count) . unwrap( ) ] ;
757
766
// `File::read` never returns a value larger than `count`,
758
767
// so this cannot fail.
759
- let result =
760
- file_descriptor. read ( communicate, & mut bytes) ?. map ( |c| i64:: try_from ( c) . unwrap ( ) ) ;
768
+ let result = file_descriptor
769
+ . read ( communicate, & mut bytes, * this. tcx ) ?
770
+ . map ( |c| i64:: try_from ( c) . unwrap ( ) ) ;
761
771
762
772
match result {
763
773
Ok ( read_bytes) => {
@@ -803,8 +813,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
803
813
804
814
if let Some ( file_descriptor) = this. machine . file_handler . handles . get ( & fd) {
805
815
let bytes = this. read_bytes_ptr_strip_provenance ( buf, Size :: from_bytes ( count) ) ?;
806
- let result =
807
- file_descriptor. write ( communicate, bytes) ?. map ( |c| i64:: try_from ( c) . unwrap ( ) ) ;
816
+ let result = file_descriptor
817
+ . write ( communicate, bytes, * this. tcx ) ?
818
+ . map ( |c| i64:: try_from ( c) . unwrap ( ) ) ;
808
819
this. try_unwrap_io_result ( result)
809
820
} else {
810
821
this. handle_not_found ( )
0 commit comments