@@ -622,8 +622,21 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
622
622
this. write_scalar ( Scalar :: from_target_isize ( res, this) , dest) ?;
623
623
return Ok ( ( ) ) ;
624
624
} ;
625
- self . write_byte_helper ( offset, fd, bytes, communicate, dest) ?;
626
- Ok ( ( ) )
625
+
626
+ let result = match offset {
627
+ None => fd. write ( & fd, communicate, & bytes, this) ,
628
+ Some ( offset) => {
629
+ let Ok ( offset) = u64:: try_from ( offset) else {
630
+ let einval = this. eval_libc ( "EINVAL" ) ;
631
+ this. set_last_error ( einval) ?;
632
+ return Ok ( Scalar :: from_target_isize ( -1 , this) ) ;
633
+ } ;
634
+ fd. pwrite ( communicate, & bytes, offset, this)
635
+ }
636
+ } ;
637
+
638
+ let result = result?. map ( |c| i64:: try_from ( c) . unwrap ( ) ) ;
639
+ Ok ( Scalar :: from_target_isize ( this. try_unwrap_io_result ( result) ?, this) )
627
640
}
628
641
629
642
/// This function write bytes to the user supplied buffer and write the total number of bytes
@@ -658,34 +671,4 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
658
671
}
659
672
}
660
673
}
661
-
662
- fn write_byte_helper (
663
- & mut self ,
664
- offset : Option < i128 > ,
665
- fd : FileDescriptionRef ,
666
- bytes : Vec < u8 > ,
667
- communicate : bool ,
668
- dest : & MPlaceTy < ' tcx > ,
669
- ) -> InterpResult < ' tcx > {
670
- let this = self . eval_context_mut ( ) ;
671
-
672
- let result = match offset {
673
- None => fd. write ( & fd, communicate, & bytes, this) ,
674
- Some ( offset) => {
675
- let Ok ( offset) = u64:: try_from ( offset) else {
676
- let einval = this. eval_libc ( "EINVAL" ) ;
677
- this. set_last_error ( einval) ?;
678
- let res = Scalar :: from_target_isize ( -1 , this) ;
679
- this. write_scalar ( res, dest) ?;
680
- return Ok ( ( ) ) ;
681
- } ;
682
- fd. pwrite ( communicate, & bytes, offset, this)
683
- }
684
- } ;
685
- // Write the result to the dest place.
686
- let result = result?. map ( |c| i64:: try_from ( c) . unwrap ( ) ) ;
687
- let res = Scalar :: from_target_isize ( this. try_unwrap_io_result ( result) ?, this) ;
688
- this. write_scalar ( res, dest) ?;
689
- return Ok ( ( ) ) ;
690
- }
691
674
}
0 commit comments