@@ -72,7 +72,7 @@ impl FileDescription for Event {
7272 // Check the size of slice, and return error only if the size of the slice < 8.
7373 if len < U64_ARRAY_SIZE . try_into ( ) . unwrap ( ) {
7474 let result = Err ( Error :: from ( ErrorKind :: InvalidInput ) ) ;
75- ecx . read_byte_helper_ev ( & buf_place, None , result, dest) ?;
75+ read_byte_helper_ev ( & buf_place, None , result, dest, ecx ) ?;
7676 return Ok ( ( ) ) ;
7777 }
7878
@@ -81,7 +81,7 @@ impl FileDescription for Event {
8181 if counter == 0 {
8282 if self . is_nonblock {
8383 let result = Err ( Error :: from ( ErrorKind :: WouldBlock ) ) ;
84- ecx . read_byte_helper_ev ( & buf_place, None , result, dest) ?;
84+ read_byte_helper_ev ( & buf_place, None , result, dest, ecx ) ?;
8585 return Ok ( ( ) ) ;
8686 } else {
8787 //FIXME: blocking is not supported
@@ -91,7 +91,7 @@ impl FileDescription for Event {
9191 // Synchronize with all prior `write` calls to this FD.
9292 ecx. acquire_clock ( & self . clock . borrow ( ) ) ;
9393 let result = Ok ( U64_ARRAY_SIZE ) ;
94- ecx . read_byte_helper_ev ( & buf_place, Some ( counter) , result, dest) ?;
94+ read_byte_helper_ev ( & buf_place, Some ( counter) , result, dest, ecx ) ?;
9595 self . counter . set ( 0 ) ;
9696 // When any of the event happened, we check and update the status of all supported event
9797 // types for current file description.
@@ -230,3 +230,27 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
230230 Ok ( Scalar :: from_i32 ( fd_value) )
231231 }
232232}
233+
234+ /// This function either writes to the user supplied buffer and to dest place, or return error.
235+ fn read_byte_helper_ev < ' tcx > (
236+ buf_place : & MPlaceTy < ' tcx > ,
237+ read_val : Option < u64 > ,
238+ result : io:: Result < usize > ,
239+ dest : & MPlaceTy < ' tcx > ,
240+ ecx : & mut MiriInterpCx < ' tcx > ,
241+ ) -> InterpResult < ' tcx > {
242+ match result. map ( |c| i64:: try_from ( c) . unwrap ( ) ) {
243+ Ok ( read_bytes) => {
244+ // Write to the user supplied buffer.
245+ ecx. write_int ( read_val. unwrap ( ) , buf_place) ?;
246+ // Write to the function return value place.
247+ ecx. write_int ( read_bytes, dest) ?;
248+ return Ok ( ( ) ) ;
249+ }
250+ Err ( e) => {
251+ ecx. set_last_error_from_io_error ( e) ?;
252+ ecx. write_int ( -1 , dest) ?;
253+ return Ok ( ( ) ) ;
254+ }
255+ }
256+ }
0 commit comments