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