Skip to content

Commit 7ad60d4

Browse files
committed
Pass Pointer to read function
1 parent 27ddaea commit 7ad60d4

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

src/shims/unix/fd.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub trait FileDescription: std::fmt::Debug + Any {
3131
_self_ref: &FileDescriptionRef,
3232
_communicate_allowed: bool,
3333
_bytes: &mut [u8],
34+
_ptr: Pointer,
3435
_ecx: &mut MiriInterpCx<'tcx>,
3536
) -> InterpResult<'tcx, io::Result<usize>> {
3637
throw_unsup_format!("cannot read from {}", self.name());
@@ -126,6 +127,7 @@ impl FileDescription for io::Stdin {
126127
_self_ref: &FileDescriptionRef,
127128
communicate_allowed: bool,
128129
bytes: &mut [u8],
130+
_ptr: Pointer,
129131
_ecx: &mut MiriInterpCx<'tcx>,
130132
) -> InterpResult<'tcx, io::Result<usize>> {
131133
if !communicate_allowed {
@@ -562,9 +564,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
562564
// We want to read at most `count` bytes. We are sure that `count` is not negative
563565
// because it was a target's `usize`. Also we are sure that its smaller than
564566
// `usize::MAX` because it is bounded by the host's `isize`.
567+
568+
// TODO: shouldn't pass vec, just pass pointer and write it.
565569
let mut bytes = vec![0; usize::try_from(count).unwrap()];
566570
let result = match offset {
567-
None => fd.read(&fd, communicate, &mut bytes, this),
571+
None => fd.read(&fd, communicate, &mut bytes, buf, this),
568572
Some(offset) => {
569573
let Ok(offset) = u64::try_from(offset) else {
570574
let einval = this.eval_libc("EINVAL");
@@ -577,10 +581,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
577581

578582
// `File::read` never returns a value larger than `count`, so this cannot fail.
579583
match result?.map(|c| i64::try_from(c).unwrap()) {
584+
// TODO: get the byte out the result, then write the ptr.
585+
// try to pass this the write_ptr inside write
586+
// Pass the pointer inside the write function.
580587
Ok(read_bytes) => {
581588
// If reading to `bytes` did not fail, we write those bytes to the buffer.
582589
// Crucially, if fewer than `bytes.len()` bytes were read, only write
583590
// that much into the output buffer!
591+
592+
// TODO: write to pointer here.
584593
this.write_bytes_ptr(
585594
buf,
586595
bytes[..usize::try_from(read_bytes).unwrap()].iter().copied(),

src/shims/unix/fs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl FileDescription for FileHandle {
3535
_self_ref: &FileDescriptionRef,
3636
communicate_allowed: bool,
3737
bytes: &mut [u8],
38+
_ptr: Pointer,
3839
_ecx: &mut MiriInterpCx<'tcx>,
3940
) -> InterpResult<'tcx, io::Result<usize>> {
4041
assert!(communicate_allowed, "isolation should have prevented even opening a file");

src/shims/unix/linux/eventfd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ impl FileDescription for Event {
6363
self_ref: &FileDescriptionRef,
6464
_communicate_allowed: bool,
6565
bytes: &mut [u8],
66+
_ptr: Pointer,
6667
ecx: &mut MiriInterpCx<'tcx>,
6768
) -> InterpResult<'tcx, io::Result<usize>> {
6869
// Check the size of slice, and return error only if the size of the slice < 8.

src/shims/unix/unnamed_socket.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ impl FileDescription for AnonSocket {
127127
_self_ref: &FileDescriptionRef,
128128
_communicate_allowed: bool,
129129
bytes: &mut [u8],
130+
_ptr: Pointer,
130131
ecx: &mut MiriInterpCx<'tcx>,
131132
) -> InterpResult<'tcx, io::Result<usize>> {
132133
let request_byte_size = bytes.len();

0 commit comments

Comments
 (0)