From 23fba86c3b1e3c1d42de5a8f35c206c766059dc2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 3 Apr 2024 15:16:36 +0200 Subject: [PATCH 1/2] eventfd: fix flag check and note a FIXME --- src/tools/miri/src/shims/unix/linux/eventfd.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/tools/miri/src/shims/unix/linux/eventfd.rs b/src/tools/miri/src/shims/unix/linux/eventfd.rs index 4e066493d274..0f28b69ac4a8 100644 --- a/src/tools/miri/src/shims/unix/linux/eventfd.rs +++ b/src/tools/miri/src/shims/unix/linux/eventfd.rs @@ -29,6 +29,7 @@ impl FileDescriptor for Event { } fn dup(&mut self) -> io::Result> { + // FIXME: this is wrong, the new and old FD should refer to the same event object! Ok(Box::new(Event { val: self.val.clone() })) } @@ -91,7 +92,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { /// `EFD_SEMAPHORE` - miri does not support semaphore-like semantics. /// /// - #[expect(clippy::needless_if)] fn eventfd( &mut self, val: &OpTy<'tcx, Provenance>, @@ -106,14 +106,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { let efd_nonblock = this.eval_libc_i32("EFD_NONBLOCK"); let efd_semaphore = this.eval_libc_i32("EFD_SEMAPHORE"); - if flags & (efd_cloexec | efd_nonblock | efd_semaphore) == 0 { - throw_unsup_format!("{flags} is unsupported"); + if flags & (efd_cloexec | efd_nonblock | efd_semaphore) != flags { + throw_unsup_format!("eventfd: flag {flags:#x} is unsupported"); + } + if flags & efd_cloexec == efd_cloexec { + // cloexec does nothing as we don't support `exec` + } + if flags & efd_nonblock == efd_nonblock { + // FIXME remember the nonblock flag } - // FIXME handle the cloexec and nonblock flags - if flags & efd_cloexec == efd_cloexec {} - if flags & efd_nonblock == efd_nonblock {} if flags & efd_semaphore == efd_semaphore { - throw_unsup_format!("EFD_SEMAPHORE is unsupported"); + throw_unsup_format!("eventfd: EFD_SEMAPHORE is unsupported"); } let fd = this.machine.fds.insert_fd(Box::new(Event { val: Cell::new(val.into()) })); From f2120893c696886317e1ef66e4f1e6419a147989 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 3 Apr 2024 15:19:33 +0200 Subject: [PATCH 2/2] epoll: note a FIXME --- src/tools/miri/src/shims/unix/linux/epoll.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools/miri/src/shims/unix/linux/epoll.rs b/src/tools/miri/src/shims/unix/linux/epoll.rs index 82e0bffff77d..5161d91ca363 100644 --- a/src/tools/miri/src/shims/unix/linux/epoll.rs +++ b/src/tools/miri/src/shims/unix/linux/epoll.rs @@ -35,6 +35,8 @@ impl FileDescriptor for Epoll { } fn dup(&mut self) -> io::Result> { + // FIXME: this is probably wrong -- check if the `dup`ed descriptor truly uses an + // independent event set. Ok(Box::new(self.clone())) }