Skip to content

Commit b8149a8

Browse files
committed
Pass the dest place into write function
1 parent 29774e9 commit b8149a8

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/shims/unix/fd.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
594594
buf: Pointer,
595595
count: u64,
596596
offset: Option<i128>,
597-
) -> InterpResult<'tcx, Scalar> {
597+
dest: &MPlaceTy<'tcx>,
598+
) -> InterpResult<'tcx> {
598599
let this = self.eval_context_mut();
599600

600601
// Isolation check is done via `FileDescriptor` trait.
@@ -612,7 +613,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
612613
let bytes = this.read_bytes_ptr_strip_provenance(buf, Size::from_bytes(count))?.to_owned();
613614
// We temporarily dup the FD to be able to retain mutable access to `this`.
614615
let Some(fd) = this.machine.fds.get(fd) else {
615-
return Ok(Scalar::from_target_isize(this.fd_not_found()?, this));
616+
let res = this.fd_not_found()?;
617+
this.write_scalar(Scalar::from_target_isize(res, this), dest)?;
618+
return Ok(());
616619
};
617620

618621
let result = match offset {
@@ -621,17 +624,19 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
621624
let Ok(offset) = u64::try_from(offset) else {
622625
let einval = this.eval_libc("EINVAL");
623626
this.set_last_error(einval)?;
624-
return Ok(Scalar::from_target_isize(-1, this));
627+
this.write_scalar(Scalar::from_target_isize(-1, this), dest)?;
628+
return Ok(());
625629
};
626630
fd.pwrite(communicate, &bytes, offset, this)
627631
}
628632
};
629633

630634
let result = result?.map(|c| i64::try_from(c).unwrap());
631-
Ok(Scalar::from_target_isize(this.try_unwrap_io_result(result)?, this))
635+
let res = this.try_unwrap_io_result(result)?;
636+
this.write_scalar(Scalar::from_target_isize(res, this), dest)?;
637+
Ok(())
632638
}
633639
}
634-
// TODO: move this as a free function later
635640
fn write_byte_helper<'tcx>(
636641
buf: Pointer,
637642
bytes: Vec<u8>,

src/shims/unix/foreign_items.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
100100
let buf = this.read_pointer(buf)?;
101101
let count = this.read_target_usize(n)?;
102102
trace!("Called write({:?}, {:?}, {:?})", fd, buf, count);
103-
let result = this.write(fd, buf, count, None)?;
104-
// Now, `result` is the value we return back to the program.
105-
this.write_scalar(result, dest)?;
103+
this.write(fd, buf, count, None, dest)?;
106104
}
107105
"pread" => {
108106
let [fd, buf, count, offset] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
@@ -119,9 +117,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
119117
let count = this.read_target_usize(n)?;
120118
let offset = this.read_scalar(offset)?.to_int(this.libc_ty_layout("off_t").size)?;
121119
trace!("Called pwrite({:?}, {:?}, {:?}, {:?})", fd, buf, count, offset);
122-
let result = this.write(fd, buf, count, Some(offset))?;
123-
// Now, `result` is the value we return back to the program.
124-
this.write_scalar(result, dest)?;
120+
this.write(fd, buf, count, Some(offset), dest)?;
125121
}
126122
"pread64" => {
127123
let [fd, buf, count, offset] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
@@ -138,9 +134,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
138134
let count = this.read_target_usize(n)?;
139135
let offset = this.read_scalar(offset)?.to_int(this.libc_ty_layout("off64_t").size)?;
140136
trace!("Called pwrite64({:?}, {:?}, {:?}, {:?})", fd, buf, count, offset);
141-
let result = this.write(fd, buf, count, Some(offset))?;
142-
// Now, `result` is the value we return back to the program.
143-
this.write_scalar(result, dest)?;
137+
this.write(fd, buf, count, Some(offset), dest)?;
144138
}
145139
"close" => {
146140
let [fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;

0 commit comments

Comments
 (0)