11use std:: any:: Any ;
22use std:: collections:: BTreeMap ;
33use std:: fs:: { File , Metadata } ;
4- use std:: io:: { ErrorKind , IsTerminal , Seek , SeekFrom , Write } ;
4+ use std:: io:: { ErrorKind , IsTerminal , Read , Seek , SeekFrom , Write } ;
55use std:: marker:: CoercePointee ;
66use std:: ops:: Deref ;
77use std:: rc:: { Rc , Weak } ;
@@ -245,7 +245,8 @@ impl FileDescription for io::Stdin {
245245 helpers:: isolation_abort_error ( "`read` from stdin" ) ?;
246246 }
247247
248- let result = ecx. read_from_host ( & * self , len, ptr) ?;
248+ let mut stdin = & * self ;
249+ let result = ecx. read_from_host ( |buf| stdin. read ( buf) , len, ptr) ?;
249250 finish. call ( ecx, result)
250251 }
251252
@@ -356,7 +357,8 @@ impl FileDescription for FileHandle {
356357 ) -> InterpResult < ' tcx > {
357358 assert ! ( communicate_allowed, "isolation should have prevented even opening a file" ) ;
358359
359- let result = ecx. read_from_host ( & self . file , len, ptr) ?;
360+ let mut file = & self . file ;
361+ let result = ecx. read_from_host ( |buf| file. read ( buf) , len, ptr) ?;
360362 finish. call ( ecx, result)
361363 }
362364
@@ -576,14 +578,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
576578 /// and return whether that worked.
577579 fn read_from_host (
578580 & mut self ,
579- mut file : impl io:: Read ,
581+ mut read_cb : impl FnMut ( & mut [ u8 ] ) -> io:: Result < usize > ,
580582 len : usize ,
581583 ptr : Pointer ,
582584 ) -> InterpResult < ' tcx , Result < usize , IoError > > {
583585 let this = self . eval_context_mut ( ) ;
584586
585587 let mut bytes = vec ! [ 0 ; len] ;
586- let result = file . read ( & mut bytes) ;
588+ let result = read_cb ( & mut bytes) ;
587589 match result {
588590 Ok ( read_size) => {
589591 // If reading to `bytes` did not fail, we write those bytes to the buffer.
@@ -596,7 +598,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
596598 }
597599 }
598600
599- /// Write data to a host `Write` type, withthe bytes taken from machine memory.
601+ /// Write data to a host `Write` type, with the bytes taken from machine memory.
600602 fn write_to_host (
601603 & mut self ,
602604 mut file : impl io:: Write ,
0 commit comments