@@ -31,6 +31,7 @@ pub trait FileDescription: std::fmt::Debug + Any {
31
31
_self_ref : & FileDescriptionRef ,
32
32
_communicate_allowed : bool ,
33
33
_bytes : & mut [ u8 ] ,
34
+ _len : usize ,
34
35
_ptr : Pointer ,
35
36
_dest : & MPlaceTy < ' tcx > ,
36
37
_ecx : & mut MiriInterpCx < ' tcx > ,
@@ -132,6 +133,7 @@ impl FileDescription for io::Stdin {
132
133
_self_ref : & FileDescriptionRef ,
133
134
communicate_allowed : bool ,
134
135
bytes : & mut [ u8 ] ,
136
+ _len : usize ,
135
137
ptr : Pointer ,
136
138
dest : & MPlaceTy < ' tcx > ,
137
139
ecx : & mut MiriInterpCx < ' tcx > ,
@@ -584,9 +586,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
584
586
// because it was a target's `usize`. Also we are sure that its smaller than
585
587
// `usize::MAX` because it is bounded by the host's `isize`.
586
588
587
- let mut bytes = vec ! [ 0 ; usize :: try_from( count) . unwrap( ) ] ;
589
+ let len = usize:: try_from ( count) . unwrap ( ) ;
590
+ let mut bytes = vec ! [ 0 ; len] ;
588
591
match offset {
589
- None => fd. read ( & fd, communicate, & mut bytes, buf, dest, this) ?,
592
+ None => fd. read ( & fd, communicate, & mut bytes, len , buf, dest, this) ?,
590
593
Some ( offset) => {
591
594
let Ok ( offset) = u64:: try_from ( offset) else {
592
595
let einval = this. eval_libc ( "EINVAL" ) ;
@@ -677,6 +680,39 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
677
680
}
678
681
}
679
682
683
+
684
+ /// This function either writes to the user supplied buffer and to dest place, or return error.
685
+ // TODO: this is only used for eventfd
686
+ fn read_byte_helper_ev (
687
+ & mut self ,
688
+ buf_place : & MPlaceTy < ' tcx > ,
689
+ read_val : Option < u64 > ,
690
+ result : io:: Result < usize > ,
691
+ dest : & MPlaceTy < ' tcx > ,
692
+ ) -> InterpResult < ' tcx > {
693
+ let this = self . eval_context_mut ( ) ;
694
+ // `File::read` never returns a value larger than `count`, so this cannot fail.
695
+ match result. map ( |c| i64:: try_from ( c) . unwrap ( ) ) {
696
+ // try to pass this the write_ptr inside write
697
+ // Pass the pointer inside the write function.
698
+ Ok ( read_bytes) => {
699
+ // If reading to `bytes` did not fail, we write those bytes to the buffer.
700
+ // Crucially, if fewer than `bytes.len()` bytes were read, only write
701
+ // that much into the output buffer!
702
+ // Write to the user supplied buffer.
703
+ this. write_int ( read_val. unwrap ( ) , buf_place) ?;
704
+ // Write to the function return value place.
705
+ this. write_int ( read_bytes, dest) ?;
706
+ return Ok ( ( ) ) ;
707
+ }
708
+ Err ( e) => {
709
+ this. set_last_error_from_io_error ( e) ?;
710
+ this. write_int ( -1 , dest) ?;
711
+ return Ok ( ( ) ) ;
712
+ }
713
+ }
714
+ }
715
+
680
716
/// This function either writes the number of written bytes to dest place or return error.
681
717
fn write_byte_helper (
682
718
& mut self ,
0 commit comments