Skip to content

Commit 5bd5eec

Browse files
committed
Pass the dest place into write function
1 parent a3844aa commit 5bd5eec

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
@@ -593,7 +593,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
593593
buf: Pointer,
594594
count: u64,
595595
offset: Option<i128>,
596-
) -> InterpResult<'tcx, Scalar> {
596+
dest: &MPlaceTy<'tcx>,
597+
) -> InterpResult<'tcx> {
597598
let this = self.eval_context_mut();
598599

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

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

629633
let result = result?.map(|c| i64::try_from(c).unwrap());
630-
Ok(Scalar::from_target_isize(this.try_unwrap_io_result(result)?, this))
634+
let res = this.try_unwrap_io_result(result)?;
635+
this.write_scalar(Scalar::from_target_isize(res, this), dest)?;
636+
Ok(())
631637
}
632638
}
633-
// TODO: move this as a free function later
634639
fn write_byte_helper<'tcx>(
635640
buf: Pointer,
636641
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)