@@ -90,11 +90,9 @@ impl FileDescription for AnonSocket {
90
90
dest: &MPlaceTy<'tcx>,
91
91
ecx: &mut MiriInterpCx<'tcx>,
92
92
) -> InterpResult<'tcx> {
93
- let mut bytes = vec![0; len];
94
-
95
93
// Always succeed on read size 0.
96
94
if len == 0 {
97
- return ecx.return_read_success(ptr, &bytes , 0, dest);
95
+ return ecx.return_read_success(ptr, &[] , 0, dest);
98
96
}
99
97
100
98
let Some(readbuf) = &self.readbuf else {
@@ -106,7 +104,7 @@ impl FileDescription for AnonSocket {
106
104
if self.peer_fd().upgrade().is_none() {
107
105
// Socketpair with no peer and empty buffer.
108
106
// 0 bytes successfully read indicates end-of-file.
109
- return ecx.return_read_success(ptr, &bytes , 0, dest);
107
+ return ecx.return_read_success(ptr, &[] , 0, dest);
110
108
} else {
111
109
if self.is_nonblock {
112
110
// Non-blocking socketpair with writer and empty buffer.
@@ -123,7 +121,7 @@ impl FileDescription for AnonSocket {
123
121
}
124
122
}
125
123
// TODO: We might need to decide what to do if peer_fd is closed when read is blocked.
126
- anonsocket_read(self, self.peer_fd().upgrade(), &mut bytes , ptr, dest, ecx)
124
+ anonsocket_read(self, self.peer_fd().upgrade(), len , ptr, dest, ecx)
127
125
}
128
126
129
127
fn write<'tcx>(
@@ -211,11 +209,13 @@ fn anonsocket_write<'tcx>(
211
209
fn anonsocket_read<'tcx>(
212
210
anonsocket: &AnonSocket,
213
211
peer_fd: Option<FileDescriptionRef>,
214
- bytes: &mut [u8] ,
212
+ len: usize ,
215
213
ptr: Pointer,
216
214
dest: &MPlaceTy<'tcx>,
217
215
ecx: &mut MiriInterpCx<'tcx>,
218
216
) -> InterpResult<'tcx> {
217
+ let mut bytes = vec![0; len];
218
+
219
219
let Some(readbuf) = &anonsocket.readbuf else {
220
220
// FIXME: This should return EBADF, but there's no nice way to do that as there's no
221
221
// corresponding ErrorKind variant.
@@ -230,7 +230,7 @@ fn anonsocket_read<'tcx>(
230
230
231
231
// Do full read / partial read based on the space available.
232
232
// Conveniently, `read` exists on `VecDeque` and has exactly the desired behavior.
233
- let actual_read_size = readbuf.buf.read(bytes).unwrap();
233
+ let actual_read_size = readbuf.buf.read(&mut bytes[..] ).unwrap();
234
234
235
235
// Need to drop before others can access the readbuf again.
236
236
drop(readbuf);
@@ -246,7 +246,7 @@ fn anonsocket_read<'tcx>(
246
246
ecx.check_and_update_readiness(&peer_fd)?;
247
247
}
248
248
249
- ecx.return_read_success(ptr, bytes, actual_read_size, dest)
249
+ ecx.return_read_success(ptr, & bytes, actual_read_size, dest)
250
250
}
251
251
252
252
impl UnixFileDescription for AnonSocket {
0 commit comments