Skip to content

Commit 0cac82a

Browse files
committed
Let FileDescription::pread to do the actual read
1 parent 24dc050 commit 0cac82a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/shims/unix/fd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub trait FileDescription: std::fmt::Debug + Any {
5656
_communicate_allowed: bool,
5757
_bytes: &mut [u8],
5858
_offset: u64,
59+
_ptr: Pointer,
60+
_dest: &MPlaceTy<'tcx>,
5961
_ecx: &mut MiriInterpCx<'tcx>,
6062
) -> InterpResult<'tcx, io::Result<usize>> {
6163
throw_unsup_format!("cannot pread from {}", self.name());
@@ -584,9 +586,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
584586
this.write_scalar(Scalar::from_target_isize(-1, this), dest)?;
585587
return Ok(());
586588
};
587-
let result = fd.pread(communicate, &mut bytes, offset, this);
588-
self.read_byte_helper(buf, bytes, result, dest)?;
589-
return Ok(());
589+
fd.pread(communicate, &mut bytes, offset, buf, dest, this)?
590590
}
591591
};
592592
Ok(())

src/shims/unix/fs.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ impl FileDescription for FileHandle {
6262
communicate_allowed: bool,
6363
bytes: &mut [u8],
6464
offset: u64,
65-
_ecx: &mut MiriInterpCx<'tcx>,
65+
ptr: Pointer,
66+
dest: &MPlaceTy<'tcx>,
67+
ecx: &mut MiriInterpCx<'tcx>,
6668
) -> InterpResult<'tcx, io::Result<usize>> {
6769
assert!(communicate_allowed, "isolation should have prevented even opening a file");
6870
// Emulates pread using seek + read + seek to restore cursor position.
@@ -78,7 +80,10 @@ impl FileDescription for FileHandle {
7880
.expect("failed to restore file position, this shouldn't be possible");
7981
res
8082
};
81-
Ok(f())
83+
let result = Ok(f());
84+
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
85+
// TODO: remove the usize later
86+
Ok(Ok(0))
8287
}
8388

8489
fn pwrite<'tcx>(

0 commit comments

Comments
 (0)