@@ -583,7 +583,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
583
583
fd. pread ( communicate, & mut bytes, offset, this)
584
584
}
585
585
} ;
586
- let res = write_byte_helper ( buf, bytes, result, this) ?;
586
+ let res = read_byte_helper ( buf, bytes, result, this) ?;
587
587
this. write_scalar ( res, dest) ?;
588
588
Ok ( ( ) )
589
589
}
@@ -617,27 +617,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
617
617
this. write_scalar ( Scalar :: from_target_isize ( res, this) , dest) ?;
618
618
return Ok ( ( ) ) ;
619
619
} ;
620
-
621
- let result = match offset {
622
- None => fd. write ( & fd, communicate, & bytes, this) ,
623
- Some ( offset) => {
624
- let Ok ( offset) = u64:: try_from ( offset) else {
625
- let einval = this. eval_libc ( "EINVAL" ) ;
626
- this. set_last_error ( einval) ?;
627
- this. write_scalar ( Scalar :: from_target_isize ( -1 , this) , dest) ?;
628
- return Ok ( ( ) ) ;
629
- } ;
630
- fd. pwrite ( communicate, & bytes, offset, this)
631
- }
632
- } ;
633
-
634
- let result = result?. map ( |c| i64:: try_from ( c) . unwrap ( ) ) ;
635
- let res = this. try_unwrap_io_result ( result) ?;
636
- this. write_scalar ( Scalar :: from_target_isize ( res, this) , dest) ?;
620
+ let res = write_byte_helper ( offset, fd, bytes, communicate, this) ?;
621
+ this. write_scalar ( res, dest) ?;
637
622
Ok ( ( ) )
638
623
}
639
624
}
640
- fn write_byte_helper < ' tcx > (
625
+ fn read_byte_helper < ' tcx > (
641
626
buf : Pointer ,
642
627
bytes : Vec < u8 > ,
643
628
result : InterpResult < ' tcx , io:: Result < usize > > ,
@@ -665,3 +650,26 @@ fn write_byte_helper<'tcx>(
665
650
}
666
651
}
667
652
}
653
+
654
+ fn write_byte_helper < ' tcx > (
655
+ offset : Option < i128 > ,
656
+ fd : FileDescriptionRef ,
657
+ bytes : Vec < u8 > ,
658
+ communicate : bool ,
659
+ ecx : & mut MiriInterpCx < ' tcx > ,
660
+ ) -> InterpResult < ' tcx , Scalar > {
661
+ let result = match offset {
662
+ None => fd. write ( & fd, communicate, & bytes, ecx) ,
663
+ Some ( offset) => {
664
+ let Ok ( offset) = u64:: try_from ( offset) else {
665
+ let einval = ecx. eval_libc ( "EINVAL" ) ;
666
+ ecx. set_last_error ( einval) ?;
667
+ return Ok ( Scalar :: from_target_isize ( -1 , ecx) ) ;
668
+ } ;
669
+ fd. pwrite ( communicate, & bytes, offset, ecx)
670
+ }
671
+ } ;
672
+ let result = result?. map ( |c| i64:: try_from ( c) . unwrap ( ) ) ;
673
+ let res = ecx. try_unwrap_io_result ( result) ?;
674
+ Ok ( Scalar :: from_target_isize ( res, ecx) )
675
+ }
0 commit comments