Skip to content

Commit 439ff7d

Browse files
committed
Pass Pointer to read function
1 parent 4d87818 commit 439ff7d

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 {
@@ -563,9 +565,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
563565
// We want to read at most `count` bytes. We are sure that `count` is not negative
564566
// because it was a target's `usize`. Also we are sure that its smaller than
565567
// `usize::MAX` because it is bounded by the host's `isize`.
568+
569+
// TODO: shouldn't pass vec, just pass pointer and write it.
566570
let mut bytes = vec![0; usize::try_from(count).unwrap()];
567571
let result = match offset {
568-
None => fd.read(&fd, communicate, &mut bytes, this),
572+
None => fd.read(&fd, communicate, &mut bytes, buf, this),
569573
Some(offset) => {
570574
let Ok(offset) = u64::try_from(offset) else {
571575
let einval = this.eval_libc("EINVAL");
@@ -578,10 +582,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
578582

579583
// `File::read` never returns a value larger than `count`, so this cannot fail.
580584
match result?.map(|c| i64::try_from(c).unwrap()) {
585+
// TODO: get the byte out the result, then write the ptr.
586+
// try to pass this the write_ptr inside write
587+
// Pass the pointer inside the write function.
581588
Ok(read_bytes) => {
582589
// If reading to `bytes` did not fail, we write those bytes to the buffer.
583590
// Crucially, if fewer than `bytes.len()` bytes were read, only write
584591
// that much into the output buffer!
592+
593+
// TODO: write to pointer here.
585594
this.write_bytes_ptr(
586595
buf,
587596
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)