Skip to content

Commit cf692d6

Browse files
committed
Failed test commit: some fail-dep test start to emit UB message
1 parent 043843c commit cf692d6

File tree

4 files changed

+48
-28
lines changed

4 files changed

+48
-28
lines changed

src/shims/unix/fd.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,19 @@ impl FileDescription for io::Stdout {
161161
_self_ref: &FileDescriptionRef,
162162
_communicate_allowed: bool,
163163
bytes: &[u8],
164-
_dest: &MPlaceTy<'tcx>,
165-
_ecx: &mut MiriInterpCx<'tcx>,
164+
dest: &MPlaceTy<'tcx>,
165+
ecx: &mut MiriInterpCx<'tcx>,
166166
) -> InterpResult<'tcx, io::Result<usize>> {
167167
// We allow writing to stderr even with isolation enabled.
168-
let result = Write::write(&mut { self }, bytes);
168+
let result = Ok(Write::write(&mut { self }, bytes));
169169
// Stdout is buffered, flush to make sure it appears on the
170170
// screen. This is the write() syscall of the interpreted
171171
// program, we want it to correspond to a write() syscall on
172172
// the host -- there is no good in adding extra buffering
173173
// here.
174174
io::stdout().flush().unwrap();
175-
176-
Ok(result)
175+
ecx.write_byte_helper(result, dest)?;
176+
Ok(Ok(0))
177177
}
178178

179179
fn is_tty(&self, communicate_allowed: bool) -> bool {
@@ -191,12 +191,14 @@ impl FileDescription for io::Stderr {
191191
_self_ref: &FileDescriptionRef,
192192
_communicate_allowed: bool,
193193
bytes: &[u8],
194-
_dest: &MPlaceTy<'tcx>,
195-
_ecx: &mut MiriInterpCx<'tcx>,
194+
dest: &MPlaceTy<'tcx>,
195+
ecx: &mut MiriInterpCx<'tcx>,
196196
) -> InterpResult<'tcx, io::Result<usize>> {
197197
// We allow writing to stderr even with isolation enabled.
198198
// No need to flush, stderr is not buffered.
199-
Ok(Write::write(&mut { self }, bytes))
199+
let result = Ok(Write::write(&mut { self }, bytes));
200+
ecx.write_byte_helper(result, dest)?;
201+
Ok(Ok(0))
200202
}
201203

202204
fn is_tty(&self, communicate_allowed: bool) -> bool {
@@ -218,11 +220,13 @@ impl FileDescription for NullOutput {
218220
_self_ref: &FileDescriptionRef,
219221
_communicate_allowed: bool,
220222
bytes: &[u8],
221-
_dest: &MPlaceTy<'tcx>,
222-
_ecx: &mut MiriInterpCx<'tcx>,
223+
dest: &MPlaceTy<'tcx>,
224+
ecx: &mut MiriInterpCx<'tcx>,
223225
) -> InterpResult<'tcx, io::Result<usize>> {
224226
// We just don't write anything, but report to the user that we did.
225-
Ok(Ok(bytes.len()))
227+
let result = Ok(Ok(bytes.len()));
228+
ecx.write_byte_helper(result, dest)?;
229+
Ok(Ok(0))
226230
}
227231
}
228232

@@ -627,7 +631,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
627631
return Ok(());
628632
};
629633

630-
let result = match offset {
634+
let _result = match offset {
631635
None => fd.write(&fd, communicate, &bytes, dest, this),
632636
Some(offset) => {
633637
let Ok(offset) = u64::try_from(offset) else {
@@ -640,9 +644,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
640644
fd.pwrite(communicate, &bytes, offset, dest, this)
641645
}
642646
};
643-
self.write_byte_helper(result, dest)?;
644647
Ok(())
645-
//Ok(Scalar::from_target_isize(this.try_unwrap_io_result(result)?, this))
646648
}
647649

648650
/// This function write bytes to the user supplied buffer and write the total number of bytes

src/shims/unix/fs.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ impl FileDescription for FileHandle {
5151
_self_ref: &FileDescriptionRef,
5252
communicate_allowed: bool,
5353
bytes: &[u8],
54-
_dest: &MPlaceTy<'tcx>,
55-
_ecx: &mut MiriInterpCx<'tcx>,
54+
dest: &MPlaceTy<'tcx>,
55+
ecx: &mut MiriInterpCx<'tcx>,
5656
) -> InterpResult<'tcx, io::Result<usize>> {
5757
assert!(communicate_allowed, "isolation should have prevented even opening a file");
58-
Ok((&mut &self.file).write(bytes))
58+
let result = Ok((&mut &self.file).write(bytes));
59+
ecx.write_byte_helper(result, dest)?;
60+
Ok(Ok(0))
5961
}
6062

6163
fn pread<'tcx>(
@@ -92,8 +94,8 @@ impl FileDescription for FileHandle {
9294
communicate_allowed: bool,
9395
bytes: &[u8],
9496
offset: u64,
95-
_dest: &MPlaceTy<'tcx>,
96-
_ecx: &mut MiriInterpCx<'tcx>,
97+
dest: &MPlaceTy<'tcx>,
98+
ecx: &mut MiriInterpCx<'tcx>,
9799
) -> InterpResult<'tcx, io::Result<usize>> {
98100
assert!(communicate_allowed, "isolation should have prevented even opening a file");
99101
// Emulates pwrite using seek + write + seek to restore cursor position.
@@ -109,7 +111,9 @@ impl FileDescription for FileHandle {
109111
.expect("failed to restore file position, this shouldn't be possible");
110112
res
111113
};
112-
Ok(f())
114+
let result = Ok(f());
115+
ecx.write_byte_helper(result, dest)?;
116+
Ok(Ok(0))
113117
}
114118

115119
fn seek<'tcx>(

src/shims/unix/linux/eventfd.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,14 @@ impl FileDescription for Event {
123123
self_ref: &FileDescriptionRef,
124124
_communicate_allowed: bool,
125125
bytes: &[u8],
126-
_dest: &MPlaceTy<'tcx>,
126+
dest: &MPlaceTy<'tcx>,
127127
ecx: &mut MiriInterpCx<'tcx>,
128128
) -> InterpResult<'tcx, io::Result<usize>> {
129129
// Check the size of slice, and return error only if the size of the slice < 8.
130130
let Some(bytes) = bytes.first_chunk::<U64_ARRAY_SIZE>() else {
131-
return Ok(Err(Error::from(ErrorKind::InvalidInput)));
131+
let result = Ok(Err(Error::from(ErrorKind::InvalidInput)));
132+
ecx.write_byte_helper(result, dest)?;
133+
return Ok(Ok(0));
132134
};
133135
// Convert from bytes to int according to host endianness.
134136
let num = match ecx.tcx.sess.target.endian {
@@ -137,7 +139,9 @@ impl FileDescription for Event {
137139
};
138140
// u64::MAX as input is invalid because the maximum value of counter is u64::MAX - 1.
139141
if num == u64::MAX {
140-
return Ok(Err(Error::from(ErrorKind::InvalidInput)));
142+
let result = Ok(Err(Error::from(ErrorKind::InvalidInput)));
143+
ecx.write_byte_helper(result, dest)?;
144+
return Ok(Ok(0));
141145
}
142146
// If the addition does not let the counter to exceed the maximum value, update the counter.
143147
// Else, block.
@@ -151,7 +155,9 @@ impl FileDescription for Event {
151155
}
152156
None | Some(u64::MAX) => {
153157
if self.is_nonblock {
154-
return Ok(Err(Error::from(ErrorKind::WouldBlock)));
158+
let result = Ok(Err(Error::from(ErrorKind::WouldBlock)));
159+
ecx.write_byte_helper(result, dest)?;
160+
return Ok(Ok(0));
155161
} else {
156162
//FIXME: blocking is not supported
157163
throw_unsup_format!("eventfd: blocking is unsupported");
@@ -162,7 +168,9 @@ impl FileDescription for Event {
162168
// types for current file description.
163169
ecx.check_and_update_readiness(self_ref)?;
164170

165-
Ok(Ok(U64_ARRAY_SIZE))
171+
let result = Ok(Ok(U64_ARRAY_SIZE));
172+
ecx.write_byte_helper(result, dest)?;
173+
Ok(Ok(0))
166174
}
167175
}
168176

src/shims/unix/unnamed_socket.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,25 @@ impl FileDescription for AnonSocket {
208208
_self_ref: &FileDescriptionRef,
209209
_communicate_allowed: bool,
210210
bytes: &[u8],
211-
_dest: &MPlaceTy<'tcx>,
211+
dest: &MPlaceTy<'tcx>,
212212
ecx: &mut MiriInterpCx<'tcx>,
213213
) -> InterpResult<'tcx, io::Result<usize>> {
214214
let write_size = bytes.len();
215215
// Always succeed on write size 0.
216216
// ("If count is zero and fd refers to a file other than a regular file, the results are not specified.")
217217
if write_size == 0 {
218+
let result = Ok(Ok(0));
219+
ecx.write_byte_helper(result, dest)?;
218220
return Ok(Ok(0));
219221
}
220222

221223
// We are writing to our peer's readbuf.
222224
let Some(peer_fd) = self.peer_fd().upgrade() else {
223225
// If the upgrade from Weak to Rc fails, it indicates that all read ends have been
224226
// closed.
225-
return Ok(Err(Error::from(ErrorKind::BrokenPipe)));
227+
let result = Ok(Err(Error::from(ErrorKind::BrokenPipe)));
228+
ecx.write_byte_helper(result, dest)?;
229+
return Ok(Ok(0));
226230
};
227231

228232
let Some(writebuf) = &peer_fd.downcast::<AnonSocket>().unwrap().readbuf else {
@@ -257,7 +261,9 @@ impl FileDescription for AnonSocket {
257261
// The kernel does this even if the fd was already readable before, so we follow suit.
258262
ecx.check_and_update_readiness(&peer_fd)?;
259263

260-
return Ok(Ok(actual_write_size));
264+
let result = Ok(Ok(actual_write_size));
265+
ecx.write_byte_helper(result, dest)?;
266+
return Ok(Ok(0));
261267
}
262268
}
263269

0 commit comments

Comments
 (0)