Skip to content

Commit df9c34a

Browse files
committed
Add EPOLLER flag to epoll machinery
1 parent 207fb21 commit df9c34a

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/shims/unix/linux/epoll.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,27 @@ pub struct EpollReadyEvents {
7676
/// epollrdhup also gets set when only the write half is closed, which is possible
7777
/// via `shutdown(_, SHUT_WR)`.
7878
pub epollhup: bool,
79+
/// Error condition happened on the associated file descriptor.
80+
pub epollerr: bool,
7981
}
8082

8183
impl EpollReadyEvents {
8284
pub fn new() -> Self {
83-
EpollReadyEvents { epollin: false, epollout: false, epollrdhup: false, epollhup: false }
85+
EpollReadyEvents {
86+
epollin: false,
87+
epollout: false,
88+
epollrdhup: false,
89+
epollhup: false,
90+
epollerr: false,
91+
}
8492
}
8593

8694
pub fn get_event_bitmask<'tcx>(&self, ecx: &MiriInterpCx<'tcx>) -> u32 {
8795
let epollin = ecx.eval_libc_u32("EPOLLIN");
8896
let epollout = ecx.eval_libc_u32("EPOLLOUT");
8997
let epollrdhup = ecx.eval_libc_u32("EPOLLRDHUP");
9098
let epollhup = ecx.eval_libc_u32("EPOLLHUP");
99+
let epollerr = ecx.eval_libc_u32("EPOLLERR");
91100

92101
let mut bitmask = 0;
93102
if self.epollin {
@@ -102,6 +111,9 @@ impl EpollReadyEvents {
102111
if self.epollhup {
103112
bitmask |= epollhup;
104113
}
114+
if self.epollerr {
115+
bitmask |= epollerr;
116+
}
105117
bitmask
106118
}
107119
}
@@ -229,6 +241,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
229241
let epollrdhup = this.eval_libc_u32("EPOLLRDHUP");
230242
let epollet = this.eval_libc_u32("EPOLLET");
231243
let epollhup = this.eval_libc_u32("EPOLLHUP");
244+
let epollerr = this.eval_libc_u32("EPOLLERR");
232245

233246
// Fail on unsupported operations.
234247
if op & epoll_ctl_add != epoll_ctl_add
@@ -261,10 +274,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
261274

262275
// Unset the flag we support to discover if any unsupported flags are used.
263276
let mut flags = events;
264-
// epoll_wait(2) will always wait for epollhup; it is not
277+
// epoll_wait(2) will always wait for epollhup and epoller; it is not
265278
// necessary to set it in events when calling epoll_ctl().
266-
// So we will always set this event type.
279+
// So we will always set these two event types.
267280
events |= epollhup;
281+
events |= epollerr;
268282

269283
if events & epollet != epollet {
270284
// We only support edge-triggered notification for now.
@@ -284,6 +298,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
284298
if flags & epollhup == epollhup {
285299
flags &= !epollhup;
286300
}
301+
if flags & epollerr == epollerr {
302+
flags &= !epollerr;
303+
}
287304
if flags != 0 {
288305
throw_unsup_format!(
289306
"epoll_ctl: encountered unknown unsupported flags {:#x}",

src/shims/unix/unnamed_socket.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! are entirely implemented inside Miri.
33
//! We also use the same infrastructure to implement unnamed pipes.
44
5-
use std::cell::{OnceCell, RefCell};
5+
use std::cell::{Cell, OnceCell, RefCell};
66
use std::collections::VecDeque;
77
use std::io;
88
use std::io::{Error, ErrorKind, Read};
@@ -27,6 +27,10 @@ struct AnonSocket {
2727
/// writing to. This is a weak reference because the other side may be closed before us; all
2828
/// future writes will then trigger EPIPE.
2929
peer_fd: OnceCell<WeakFileDescriptionRef>,
30+
/// Indicates whether the peer has lost data when the file description is closed.
31+
/// This flag is set to `true` if the peer's `readbuf` is non-empty at the time
32+
/// of closure.
33+
peer_lost_data: Cell<bool>,
3034
is_nonblock: bool,
3135
}
3236

0 commit comments

Comments
 (0)