@@ -26,7 +26,9 @@ pub trait FileDescription: std::fmt::Debug + Any {
26
26
fn name ( & self ) -> & ' static str ;
27
27
28
28
/// Reads as much as possible into the given buffer, and returns the number of bytes read.
29
- /// `ptr` is the pointer to user supplied read buffer.
29
+ /// `ptr` is the pointer to the user supplied read buffer.
30
+ /// `len` indicates how many bytes the user requested.
31
+ /// `dest` is where the return value should be stored.
30
32
fn read < ' tcx > (
31
33
& self ,
32
34
_self_ref : & FileDescriptionRef ,
@@ -40,6 +42,8 @@ pub trait FileDescription: std::fmt::Debug + Any {
40
42
}
41
43
42
44
/// Writes as much as possible from the given buffer, and returns the number of bytes written.
45
+ /// `bytes` is the buffer of bytes supplied by the caller to be written.
46
+ /// `dest` is where the return value should be stored.
43
47
fn write < ' tcx > (
44
48
& self ,
45
49
_self_ref : & FileDescriptionRef ,
@@ -53,6 +57,9 @@ pub trait FileDescription: std::fmt::Debug + Any {
53
57
54
58
/// Reads as much as possible into the given buffer from a given offset,
55
59
/// and returns the number of bytes read.
60
+ /// `ptr` is the pointer to the user supplied read buffer.
61
+ /// `len` indicates how many bytes the user requested.
62
+ /// `dest` is where the return value should be stored.
56
63
fn pread < ' tcx > (
57
64
& self ,
58
65
_communicate_allowed : bool ,
@@ -67,6 +74,8 @@ pub trait FileDescription: std::fmt::Debug + Any {
67
74
68
75
/// Writes as much as possible from the given buffer starting at a given offset,
69
76
/// and returns the number of bytes written.
77
+ /// `bytes` is the buffer of bytes supplied by the caller to be written.
78
+ /// `dest` is where the return value should be stored.
70
79
fn pwrite < ' tcx > (
71
80
& self ,
72
81
_communicate_allowed : bool ,
@@ -143,7 +152,7 @@ impl FileDescription for io::Stdin {
143
152
helpers:: isolation_abort_error ( "`read` from stdin" ) ?;
144
153
}
145
154
let result = Read :: read ( & mut { self } , & mut bytes) ;
146
- ecx. return_read_bytes_and_count ( ptr, bytes, result, dest)
155
+ ecx. return_read_bytes_and_count ( ptr, & bytes, result, dest)
147
156
}
148
157
149
158
fn is_tty ( & self , communicate_allowed : bool ) -> bool {
@@ -641,12 +650,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
641
650
Ok ( ( ) )
642
651
}
643
652
644
- /// This function either writes to the user supplied buffer and to dest place, or sets the
645
- /// last libc error and writes -1 to dest.
653
+ /// Helper to implement `FileDescription::read`:
654
+ /// `result` should be the return value of some underlying `read` call that used `bytes` as its output buffer.
655
+ /// The length of `bytes` must not exceed either the host's or the target's `isize`.
656
+ /// If `Result` indicates success, `bytes` is written to `buf` and the size is written to `dest`.
657
+ /// Otherwise, `-1` is written to `dest` and the last libc error is set appropriately.
646
658
fn return_read_bytes_and_count (
647
659
& mut self ,
648
660
buf : Pointer ,
649
- bytes : Vec < u8 > ,
661
+ bytes : & [ u8 ] ,
650
662
result : io:: Result < usize > ,
651
663
dest : & MPlaceTy < ' tcx > ,
652
664
) -> InterpResult < ' tcx > {
@@ -657,7 +669,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
657
669
// Crucially, if fewer than `bytes.len()` bytes were read, only write
658
670
// that much into the output buffer!
659
671
this. write_bytes_ptr ( buf, bytes[ ..read_bytes] . iter ( ) . copied ( ) ) ?;
660
- // The actual read size is always lesser than `count` so this cannot fail.
672
+ // The actual read size is always less than what got originally requested so this cannot fail.
661
673
this. write_int ( u64:: try_from ( read_bytes) . unwrap ( ) , dest) ?;
662
674
return Ok ( ( ) ) ;
663
675
}
@@ -669,7 +681,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
669
681
}
670
682
}
671
683
672
- /// This function writes the number of written bytes to dest place , or sets the
684
+ /// This function writes the number of written bytes (given in `result`) to ` dest` , or sets the
673
685
/// last libc error and writes -1 to dest.
674
686
fn return_written_byte_count_or_error (
675
687
& mut self ,
0 commit comments