Skip to content

Commit 9250984

Browse files
committed
Auto merge of #3446 - RalfJung:eventfd, r=RalfJung
eventfd: fix flag check and note a FIXME
2 parents 1981895 + f212089 commit 9250984

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/tools/miri/src/shims/unix/linux/epoll.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ impl FileDescriptor for Epoll {
3535
}
3636

3737
fn dup(&mut self) -> io::Result<Box<dyn FileDescriptor>> {
38+
// FIXME: this is probably wrong -- check if the `dup`ed descriptor truly uses an
39+
// independent event set.
3840
Ok(Box::new(self.clone()))
3941
}
4042

src/tools/miri/src/shims/unix/linux/eventfd.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ impl FileDescriptor for Event {
2929
}
3030

3131
fn dup(&mut self) -> io::Result<Box<dyn FileDescriptor>> {
32+
// FIXME: this is wrong, the new and old FD should refer to the same event object!
3233
Ok(Box::new(Event { val: self.val.clone() }))
3334
}
3435

@@ -91,7 +92,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
9192
/// `EFD_SEMAPHORE` - miri does not support semaphore-like semantics.
9293
///
9394
/// <https://linux.die.net/man/2/eventfd>
94-
#[expect(clippy::needless_if)]
9595
fn eventfd(
9696
&mut self,
9797
val: &OpTy<'tcx, Provenance>,
@@ -106,14 +106,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
106106
let efd_nonblock = this.eval_libc_i32("EFD_NONBLOCK");
107107
let efd_semaphore = this.eval_libc_i32("EFD_SEMAPHORE");
108108

109-
if flags & (efd_cloexec | efd_nonblock | efd_semaphore) == 0 {
110-
throw_unsup_format!("{flags} is unsupported");
109+
if flags & (efd_cloexec | efd_nonblock | efd_semaphore) != flags {
110+
throw_unsup_format!("eventfd: flag {flags:#x} is unsupported");
111+
}
112+
if flags & efd_cloexec == efd_cloexec {
113+
// cloexec does nothing as we don't support `exec`
114+
}
115+
if flags & efd_nonblock == efd_nonblock {
116+
// FIXME remember the nonblock flag
111117
}
112-
// FIXME handle the cloexec and nonblock flags
113-
if flags & efd_cloexec == efd_cloexec {}
114-
if flags & efd_nonblock == efd_nonblock {}
115118
if flags & efd_semaphore == efd_semaphore {
116-
throw_unsup_format!("EFD_SEMAPHORE is unsupported");
119+
throw_unsup_format!("eventfd: EFD_SEMAPHORE is unsupported");
117120
}
118121

119122
let fd = this.machine.fds.insert_fd(Box::new(Event { val: Cell::new(val.into()) }));

0 commit comments

Comments
 (0)