33#include <sys/kernel.h>
34#include <sys/malloc.h>
35#include <sys/limits.h>
42#include <sys/filedesc.h>
50#include <sys/selinfo.h>
51#include <sys/eventfd.h>
53#include <security/audit/audit.h>
82 .fo_flags = DFLAG_PASSABLE
115 AUDIT_ARG_FFLAGS(
flags);
116 AUDIT_ARG_VALUE(initval);
118 efd =
malloc(
sizeof(*efd), M_EVENTFD, M_WAITOK | M_ZERO);
121 mtx_init(&efd->
efd_lock,
"eventfd", NULL, MTX_DEF);
124 fflags = FREAD | FWRITE;
125 if ((
flags & EFD_NONBLOCK) != 0)
141 free(efd, M_EVENTFD);
146eventfd_read(
struct file *fp,
struct uio *uio,
struct ucred *active_cred,
147 int flags,
struct thread *td)
153 if (uio->uio_resid <
sizeof(eventfd_t))
159 while (error == 0 && efd->
efd_count == 0) {
160 if ((fp->f_flag & FNONBLOCK) != 0) {
169 if ((efd->
efd_flags & EFD_SEMAPHORE) != 0) {
176 KNOTE_LOCKED(&efd->
efd_sel.si_note, 0);
189 int flags,
struct thread *td)
195 if (uio->uio_resid <
sizeof(eventfd_t))
201 if (
count == UINT64_MAX)
208 if ((fp->f_flag & FNONBLOCK) != 0) {
211 uio->uio_resid +=
sizeof(eventfd_t);
222 KNOTE_LOCKED(&efd->
efd_sel.si_note, 0);
241 if ((events & (POLLIN | POLLRDNORM)) != 0 && efd->
efd_count > 0)
242 revents |= events & (POLLIN | POLLRDNORM);
243 if ((events & (POLLOUT | POLLWRNORM)) != 0 && UINT64_MAX - 1 >
245 revents |= events & (POLLOUT | POLLWRNORM);
256 struct eventfd *efd = fp->f_data;
259 switch (kn->kn_filter) {
281 struct eventfd *efd = kn->kn_hook;
291 struct eventfd *efd = kn->kn_hook;
294 mtx_assert(&efd->
efd_lock, MA_OWNED);
304 struct eventfd *efd = kn->kn_hook;
307 mtx_assert(&efd->
efd_lock, MA_OWNED);
308 kn->kn_data = (int64_t)(UINT64_MAX - 1 - efd->
efd_count);
316 struct ucred *active_cred,
struct thread *td)
330 bzero((
void *)
st,
sizeof *
st);
331 st->st_mode = S_IFIFO;
338 struct eventfd *efd = fp->f_data;
340 kif->kf_type = KF_TYPE_EVENTFD;
342 kif->kf_un.kf_eventfd.kf_eventfd_value = efd->
efd_count;
343 kif->kf_un.kf_eventfd.kf_eventfd_flags = efd->
efd_flags;
static struct bt_table st
int invfo_truncate(struct file *fp, off_t length, struct ucred *active_cred, struct thread *td)
int invfo_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred, struct thread *td)
void finit(struct file *fp, u_int flag, short type, void *data, struct fileops *ops)
int invfo_sendfile(struct file *fp, int sockfd, struct uio *hdr_uio, struct uio *trl_uio, off_t offset, size_t nbytes, off_t *sent, int flags, struct thread *td)
int invfo_chmod(struct file *fp, mode_t mode, struct ucred *active_cred, struct thread *td)
void knlist_remove(struct knlist *knl, struct knote *kn, int islocked)
void knlist_add(struct knlist *knl, struct knote *kn, int islocked)
void knlist_destroy(struct knlist *knl)
void knote(struct knlist *list, long hint, int lockflags)
void knlist_init_mtx(struct knlist *knl, struct mtx *lock)
void *() malloc(size_t size, struct malloc_type *mtp, int flags)
void free(void *addr, struct malloc_type *mtp)
void wakeup(const void *ident)
int uiomove(void *cp, int n, struct uio *uio)
static fo_close_t eventfd_close
MALLOC_DEFINE(M_EVENTFD, "eventfd", "eventfd structures")
static fo_rdwr_t eventfd_read
static int filt_eventfdwrite(struct knote *kn, long hint)
static void filt_eventfddetach(struct knote *kn)
static int filt_eventfdread(struct knote *kn, long hint)
static struct fileops eventfdops
static struct filterops eventfd_rfiltops
static fo_fill_kinfo_t eventfd_fill_kinfo
static struct filterops eventfd_wfiltops
static fo_stat_t eventfd_stat
int eventfd_create_file(struct thread *td, struct file *fp, uint32_t initval, int flags)
_Static_assert(EFD_CLOEXEC==O_CLOEXEC, "Mismatched EFD_CLOEXEC")
static fo_poll_t eventfd_poll
static fo_ioctl_t eventfd_ioctl
static fo_kqfilter_t eventfd_kqfilter
static fo_rdwr_t eventfd_write
void seldrain(struct selinfo *sip)
void selrecord(struct thread *selector, struct selinfo *sip)
void selwakeup(struct selinfo *sip)