@@ -72,7 +72,7 @@ impl FileDescription for Event {
72
72
// Check the size of slice, and return error only if the size of the slice < 8.
73
73
if len < U64_ARRAY_SIZE . try_into ( ) . unwrap ( ) {
74
74
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 ) ?;
76
76
return Ok ( ( ) ) ;
77
77
}
78
78
@@ -81,7 +81,7 @@ impl FileDescription for Event {
81
81
if counter == 0 {
82
82
if self . is_nonblock {
83
83
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 ) ?;
85
85
return Ok ( ( ) ) ;
86
86
} else {
87
87
//FIXME: blocking is not supported
@@ -91,7 +91,7 @@ impl FileDescription for Event {
91
91
// Synchronize with all prior `write` calls to this FD.
92
92
ecx. acquire_clock ( & self . clock . borrow ( ) ) ;
93
93
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 ) ?;
95
95
self . counter . set ( 0 ) ;
96
96
// When any of the event happened, we check and update the status of all supported event
97
97
// types for current file description.
@@ -230,3 +230,27 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
230
230
Ok ( Scalar :: from_i32 ( fd_value) )
231
231
}
232
232
}
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