Skip to content

Commit 4a8047b

Browse files
committed
Move write_byte_helper to ecx
1 parent 0cac82a commit 4a8047b

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

src/shims/unix/fd.rs

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
621621
this.write_scalar(Scalar::from_target_isize(res, this), dest)?;
622622
return Ok(());
623623
};
624-
write_byte_helper(offset, fd, bytes, communicate, dest, this)?;
624+
self.write_byte_helper(offset, fd, bytes, communicate, dest)?;
625625
Ok(())
626626
}
627627

@@ -657,32 +657,34 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
657657
}
658658
}
659659
}
660-
}
661660

662-
fn write_byte_helper<'tcx>(
663-
offset: Option<i128>,
664-
fd: FileDescriptionRef,
665-
bytes: Vec<u8>,
666-
communicate: bool,
667-
dest: &MPlaceTy<'tcx>,
668-
ecx: &mut MiriInterpCx<'tcx>,
669-
) -> InterpResult<'tcx> {
670-
let result = match offset {
671-
None => fd.write(&fd, communicate, &bytes, ecx),
672-
Some(offset) => {
673-
let Ok(offset) = u64::try_from(offset) else {
674-
let einval = ecx.eval_libc("EINVAL");
675-
ecx.set_last_error(einval)?;
676-
let res = Scalar::from_target_isize(-1, ecx);
677-
ecx.write_scalar(res, dest)?;
678-
return Ok(());
679-
};
680-
fd.pwrite(communicate, &bytes, offset, ecx)
681-
}
682-
};
683-
// Write the result to the dest place.
684-
let result = result?.map(|c| i64::try_from(c).unwrap());
685-
let res = Scalar::from_target_isize(ecx.try_unwrap_io_result(result)?, ecx);
686-
ecx.write_scalar(res, dest)?;
687-
return Ok(());
661+
fn write_byte_helper(
662+
&mut self,
663+
offset: Option<i128>,
664+
fd: FileDescriptionRef,
665+
bytes: Vec<u8>,
666+
communicate: bool,
667+
dest: &MPlaceTy<'tcx>,
668+
) -> InterpResult<'tcx> {
669+
let this = self.eval_context_mut();
670+
671+
let result = match offset {
672+
None => fd.write(&fd, communicate, &bytes, this),
673+
Some(offset) => {
674+
let Ok(offset) = u64::try_from(offset) else {
675+
let einval = this.eval_libc("EINVAL");
676+
this.set_last_error(einval)?;
677+
let res = Scalar::from_target_isize(-1, this);
678+
this.write_scalar(res, dest)?;
679+
return Ok(());
680+
};
681+
fd.pwrite(communicate, &bytes, offset, this)
682+
}
683+
};
684+
// Write the result to the dest place.
685+
let result = result?.map(|c| i64::try_from(c).unwrap());
686+
let res = Scalar::from_target_isize(this.try_unwrap_io_result(result)?, this);
687+
this.write_scalar(res, dest)?;
688+
return Ok(());
689+
}
688690
}

0 commit comments

Comments
 (0)