|
1 | | -use std::cell::Cell; |
| 1 | +use std::io; |
| 2 | + |
| 3 | +use rustc_data_structures::fx::FxHashMap; |
2 | 4 |
|
3 | 5 | use crate::shims::unix::*; |
4 | 6 | use crate::*; |
5 | | -use epoll::{Epoll, EpollEvent}; |
6 | | -use event::Event; |
7 | 7 |
|
8 | | -pub mod epoll; |
9 | | -pub mod event; |
| 8 | +/// An `Epoll` file descriptor connects file handles and epoll events |
| 9 | +#[derive(Clone, Debug, Default)] |
| 10 | +struct Epoll { |
| 11 | + /// The file descriptors we are watching, and what we are watching for. |
| 12 | + file_descriptors: FxHashMap<i32, EpollEvent>, |
| 13 | +} |
| 14 | + |
| 15 | +/// Epoll Events associate events with data. |
| 16 | +/// These fields are currently unused by miri. |
| 17 | +/// This matches the `epoll_event` struct defined |
| 18 | +/// by the epoll_ctl man page. For more information |
| 19 | +/// see the man page: |
| 20 | +/// |
| 21 | +/// <https://man7.org/linux/man-pages/man2/epoll_ctl.2.html> |
| 22 | +#[derive(Clone, Debug)] |
| 23 | +struct EpollEvent { |
| 24 | + #[allow(dead_code)] |
| 25 | + events: u32, |
| 26 | + /// `Scalar<Provenance>` is used to represent the |
| 27 | + /// `epoll_data` type union. |
| 28 | + #[allow(dead_code)] |
| 29 | + data: Scalar<Provenance>, |
| 30 | +} |
| 31 | + |
| 32 | +impl FileDescriptor for Epoll { |
| 33 | + fn name(&self) -> &'static str { |
| 34 | + "epoll" |
| 35 | + } |
| 36 | + |
| 37 | + fn dup(&mut self) -> io::Result<Box<dyn FileDescriptor>> { |
| 38 | + Ok(Box::new(self.clone())) |
| 39 | + } |
| 40 | + |
| 41 | + fn close<'tcx>( |
| 42 | + self: Box<Self>, |
| 43 | + _communicate_allowed: bool, |
| 44 | + ) -> InterpResult<'tcx, io::Result<i32>> { |
| 45 | + Ok(Ok(0)) |
| 46 | + } |
| 47 | +} |
10 | 48 |
|
11 | 49 | impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {} |
12 | 50 | pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { |
@@ -156,49 +194,4 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { |
156 | 194 | Ok(Scalar::from_i32(this.fd_not_found()?)) |
157 | 195 | } |
158 | 196 | } |
159 | | - |
160 | | - /// This function creates an `Event` that is used as an event wait/notify mechanism by |
161 | | - /// user-space applications, and by the kernel to notify user-space applications of events. |
162 | | - /// The `Event` contains an `u64` counter maintained by the kernel. The counter is initialized |
163 | | - /// with the value specified in the `initval` argument. |
164 | | - /// |
165 | | - /// A new file descriptor referring to the `Event` is returned. The `read`, `write`, `poll`, |
166 | | - /// `select`, and `close` operations can be performed on the file descriptor. For more |
167 | | - /// information on these operations, see the man page linked below. |
168 | | - /// |
169 | | - /// The `flags` are not currently implemented for eventfd. |
170 | | - /// The `flags` may be bitwise ORed to change the behavior of `eventfd`: |
171 | | - /// `EFD_CLOEXEC` - Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor. |
172 | | - /// `EFD_NONBLOCK` - Set the `O_NONBLOCK` file status flag on the new open file description. |
173 | | - /// `EFD_SEMAPHORE` - miri does not support semaphore-like semantics. |
174 | | - /// |
175 | | - /// <https://linux.die.net/man/2/eventfd> |
176 | | - #[expect(clippy::needless_if)] |
177 | | - fn eventfd( |
178 | | - &mut self, |
179 | | - val: &OpTy<'tcx, Provenance>, |
180 | | - flags: &OpTy<'tcx, Provenance>, |
181 | | - ) -> InterpResult<'tcx, Scalar<Provenance>> { |
182 | | - let this = self.eval_context_mut(); |
183 | | - |
184 | | - let val = this.read_scalar(val)?.to_u32()?; |
185 | | - let flags = this.read_scalar(flags)?.to_i32()?; |
186 | | - |
187 | | - let efd_cloexec = this.eval_libc_i32("EFD_CLOEXEC"); |
188 | | - let efd_nonblock = this.eval_libc_i32("EFD_NONBLOCK"); |
189 | | - let efd_semaphore = this.eval_libc_i32("EFD_SEMAPHORE"); |
190 | | - |
191 | | - if flags & (efd_cloexec | efd_nonblock | efd_semaphore) == 0 { |
192 | | - throw_unsup_format!("{flags} is unsupported"); |
193 | | - } |
194 | | - // FIXME handle the cloexec and nonblock flags |
195 | | - if flags & efd_cloexec == efd_cloexec {} |
196 | | - if flags & efd_nonblock == efd_nonblock {} |
197 | | - if flags & efd_semaphore == efd_semaphore { |
198 | | - throw_unsup_format!("EFD_SEMAPHORE is unsupported"); |
199 | | - } |
200 | | - |
201 | | - let fd = this.machine.fds.insert_fd(Box::new(Event { val: Cell::new(val.into()) })); |
202 | | - Ok(Scalar::from_i32(fd)) |
203 | | - } |
204 | 197 | } |
0 commit comments