@@ -11,6 +11,7 @@ use std::time::SystemTime;
1111use log:: trace;
1212
1313use rustc_data_structures:: fx:: FxHashMap ;
14+ use rustc_middle:: ty:: TyCtxt ;
1415use rustc_target:: abi:: { Align , Size } ;
1516
1617use crate :: shims:: os_str:: bytes_to_os_str;
@@ -31,6 +32,7 @@ pub trait FileDescriptor: std::fmt::Debug + helpers::AsAny {
3132 & mut self ,
3233 _communicate_allowed : bool ,
3334 _bytes : & mut [ u8 ] ,
35+ _tcx : TyCtxt < ' tcx > ,
3436 ) -> InterpResult < ' tcx , io:: Result < usize > > {
3537 throw_unsup_format ! ( "cannot read from {}" , self . name( ) ) ;
3638 }
@@ -39,6 +41,7 @@ pub trait FileDescriptor: std::fmt::Debug + helpers::AsAny {
3941 & self ,
4042 _communicate_allowed : bool ,
4143 _bytes : & [ u8 ] ,
44+ _tcx : TyCtxt < ' tcx > ,
4245 ) -> InterpResult < ' tcx , io:: Result < usize > > {
4346 throw_unsup_format ! ( "cannot write to {}" , self . name( ) ) ;
4447 }
@@ -79,6 +82,7 @@ impl FileDescriptor for FileHandle {
7982 & mut self ,
8083 communicate_allowed : bool ,
8184 bytes : & mut [ u8 ] ,
85+ _tcx : TyCtxt < ' tcx > ,
8286 ) -> InterpResult < ' tcx , io:: Result < usize > > {
8387 assert ! ( communicate_allowed, "isolation should have prevented even opening a file" ) ;
8488 Ok ( self . file . read ( bytes) )
@@ -88,6 +92,7 @@ impl FileDescriptor for FileHandle {
8892 & self ,
8993 communicate_allowed : bool ,
9094 bytes : & [ u8 ] ,
95+ _tcx : TyCtxt < ' tcx > ,
9196 ) -> InterpResult < ' tcx , io:: Result < usize > > {
9297 assert ! ( communicate_allowed, "isolation should have prevented even opening a file" ) ;
9398 Ok ( ( & mut & self . file ) . write ( bytes) )
@@ -153,6 +158,7 @@ impl FileDescriptor for io::Stdin {
153158 & mut self ,
154159 communicate_allowed : bool ,
155160 bytes : & mut [ u8 ] ,
161+ _tcx : TyCtxt < ' tcx > ,
156162 ) -> InterpResult < ' tcx , io:: Result < usize > > {
157163 if !communicate_allowed {
158164 // 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 {
184190 & self ,
185191 _communicate_allowed : bool ,
186192 bytes : & [ u8 ] ,
193+ _tcx : TyCtxt < ' tcx > ,
187194 ) -> InterpResult < ' tcx , io:: Result < usize > > {
188195 // We allow writing to stderr even with isolation enabled.
189196 let result = Write :: write ( & mut { self } , bytes) ;
@@ -220,6 +227,7 @@ impl FileDescriptor for io::Stderr {
220227 & self ,
221228 _communicate_allowed : bool ,
222229 bytes : & [ u8 ] ,
230+ _tcx : TyCtxt < ' tcx > ,
223231 ) -> InterpResult < ' tcx , io:: Result < usize > > {
224232 // We allow writing to stderr even with isolation enabled.
225233 // No need to flush, stderr is not buffered.
@@ -252,6 +260,7 @@ impl FileDescriptor for NullOutput {
252260 & self ,
253261 _communicate_allowed : bool ,
254262 bytes : & [ u8 ] ,
263+ _tcx : TyCtxt < ' tcx > ,
255264 ) -> InterpResult < ' tcx , io:: Result < usize > > {
256265 // We just don't write anything, but report to the user that we did.
257266 Ok ( Ok ( bytes. len ( ) ) )
@@ -756,8 +765,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
756765 let mut bytes = vec ! [ 0 ; usize :: try_from( count) . unwrap( ) ] ;
757766 // `File::read` never returns a value larger than `count`,
758767 // 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 ( ) ) ;
761771
762772 match result {
763773 Ok ( read_bytes) => {
@@ -803,8 +813,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
803813
804814 if let Some ( file_descriptor) = this. machine . file_handler . handles . get ( & fd) {
805815 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 ( ) ) ;
808819 this. try_unwrap_io_result ( result)
809820 } else {
810821 this. handle_not_found ( )
0 commit comments