williamr@2: /*- williamr@2: * Copyright (c) 1999,2000,2001 Jonathan Lemon williamr@2: * All rights reserved. williamr@2: * williamr@2: * Redistribution and use in source and binary forms, with or without williamr@2: * modification, are permitted provided that the following conditions williamr@2: * are met: williamr@2: * 1. Redistributions of source code must retain the above copyright williamr@2: * notice, this list of conditions and the following disclaimer. williamr@2: * 2. Redistributions in binary form must reproduce the above copyright williamr@2: * notice, this list of conditions and the following disclaimer in the williamr@2: * documentation and/or other materials provided with the distribution. williamr@2: * williamr@2: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND williamr@2: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE williamr@2: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE williamr@2: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE williamr@2: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL williamr@2: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS williamr@2: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) williamr@2: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT williamr@2: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY williamr@2: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF williamr@2: * SUCH DAMAGE. williamr@2: * © Portions copyright (c) 2007 Symbian Software Ltd. All rights reserved. williamr@2: * $FreeBSD: src/sys/sys/event.h,v 1.32 2005/07/01 16:28:32 ssouhlal Exp $ williamr@2: */ williamr@2: williamr@2: #ifndef _SYS_EVENT_H_ williamr@2: #define _SYS_EVENT_H_ williamr@2: williamr@2: #define EVFILT_READ (-1) williamr@2: #define EVFILT_WRITE (-2) williamr@2: #define EVFILT_AIO (-3) /* attached to aio requests */ williamr@2: #define EVFILT_VNODE (-4) /* attached to vnodes */ williamr@2: #define EVFILT_PROC (-5) /* attached to struct proc */ williamr@2: #define EVFILT_SIGNAL (-6) /* attached to struct proc */ williamr@2: #define EVFILT_TIMER (-7) /* timers */ williamr@2: #define EVFILT_NETDEV (-8) /* network devices */ williamr@2: #define EVFILT_FS (-9) /* filesystem events */ williamr@2: williamr@2: #define EVFILT_SYSCOUNT 9 williamr@2: williamr@2: #define EV_SET(kevp_, a, b, c, d, e, f) do { \ williamr@2: struct kevent *kevp = (kevp_); \ williamr@2: (kevp)->ident = (a); \ williamr@2: (kevp)->filter = (b); \ williamr@2: (kevp)->flags = (c); \ williamr@2: (kevp)->fflags = (d); \ williamr@2: (kevp)->data = (e); \ williamr@2: (kevp)->udata = (f); \ williamr@2: } while(0) williamr@2: williamr@2: struct kevent { williamr@2: uintptr_t ident; /* identifier for this event */ williamr@2: short filter; /* filter for event */ williamr@2: u_short flags; williamr@2: u_int fflags; williamr@2: intptr_t data; williamr@2: void *udata; /* opaque user data identifier */ williamr@2: }; williamr@2: williamr@2: /* actions */ williamr@2: #define EV_ADD 0x0001 /* add event to kq (implies enable) */ williamr@2: #define EV_DELETE 0x0002 /* delete event from kq */ williamr@2: #define EV_ENABLE 0x0004 /* enable event */ williamr@2: #define EV_DISABLE 0x0008 /* disable event (not reported) */ williamr@2: williamr@2: /* flags */ williamr@2: #define EV_ONESHOT 0x0010 /* only report one occurrence */ williamr@2: #define EV_CLEAR 0x0020 /* clear event state after reporting */ williamr@2: williamr@2: #define EV_SYSFLAGS 0xF000 /* reserved by system */ williamr@2: #define EV_FLAG1 0x2000 /* filter-specific flag */ williamr@2: williamr@2: /* returned values */ williamr@2: #define EV_EOF 0x8000 /* EOF detected */ williamr@2: #define EV_ERROR 0x4000 /* error, data contains errno */ williamr@2: williamr@2: /* williamr@2: * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace williamr@2: */ williamr@2: #define NOTE_LOWAT 0x0001 /* low water mark */ williamr@2: williamr@2: /* williamr@2: * data/hint flags for EVFILT_VNODE, shared with userspace williamr@2: */ williamr@2: #define NOTE_DELETE 0x0001 /* vnode was removed */ williamr@2: #define NOTE_WRITE 0x0002 /* data contents changed */ williamr@2: #define NOTE_EXTEND 0x0004 /* size increased */ williamr@2: #define NOTE_ATTRIB 0x0008 /* attributes changed */ williamr@2: #define NOTE_LINK 0x0010 /* link count changed */ williamr@2: #define NOTE_RENAME 0x0020 /* vnode was renamed */ williamr@2: #define NOTE_REVOKE 0x0040 /* vnode access was revoked */ williamr@2: williamr@2: /* williamr@2: * data/hint flags for EVFILT_PROC, shared with userspace williamr@2: */ williamr@2: #define NOTE_EXIT 0x80000000 /* process exited */ williamr@2: #define NOTE_FORK 0x40000000 /* process forked */ williamr@2: #define NOTE_EXEC 0x20000000 /* process exec'd */ williamr@2: #define NOTE_PCTRLMASK 0xf0000000 /* mask for hint bits */ williamr@2: #define NOTE_PDATAMASK 0x000fffff /* mask for pid */ williamr@2: williamr@2: /* additional flags for EVFILT_PROC */ williamr@2: #define NOTE_TRACK 0x00000001 /* follow across forks */ williamr@2: #define NOTE_TRACKERR 0x00000002 /* could not track child */ williamr@2: #define NOTE_CHILD 0x00000004 /* am a child process */ williamr@2: williamr@2: /* williamr@2: * data/hint flags for EVFILT_NETDEV, shared with userspace williamr@2: */ williamr@2: #define NOTE_LINKUP 0x0001 /* link is up */ williamr@2: #define NOTE_LINKDOWN 0x0002 /* link is down */ williamr@2: #define NOTE_LINKINV 0x0004 /* link state is invalid */ williamr@2: williamr@2: /* williamr@2: * This is currently visible to userland to work around broken williamr@2: * programs which pull in . williamr@2: */ williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: struct knote; williamr@2: struct kqueue; williamr@2: struct knlist { williamr@2: struct klist kl_list; williamr@2: void (*kl_lock)(void *); /* lock function */ williamr@2: void (*kl_unlock)(void *); williamr@2: int (*kl_locked)(void *); williamr@2: void *kl_lockarg; /* argument passed to kl_lockf() */ williamr@2: }; williamr@2: williamr@2: williamr@2: #ifdef _KERNEL williamr@2: williamr@2: #define KNLIST_EMPTY(list) SLIST_EMPTY(&(list)->kl_list) williamr@2: williamr@2: /* williamr@2: * Flag indicating hint is a signal. Used by EVFILT_SIGNAL, and also williamr@2: * shared by EVFILT_PROC (all knotes attached to p->p_klist) williamr@2: */ williamr@2: #define NOTE_SIGNAL 0x08000000 williamr@2: williamr@2: struct filterops { williamr@2: int f_isfd; /* true if ident == filedescriptor */ williamr@2: int (*f_attach)(struct knote *kn); williamr@2: void (*f_detach)(struct knote *kn); williamr@2: int (*f_event)(struct knote *kn, long hint); williamr@2: }; williamr@2: williamr@2: /* williamr@2: * Setting the KN_INFLUX flag enables you to unlock the kq that this knote williamr@2: * is on, and modify kn_status as if you had the KQ lock. williamr@2: * williamr@2: * kn_sfflags, kn_sdata, and kn_kevent are protected by the knlist lock. williamr@2: */ williamr@2: struct knote { williamr@2: SLIST_ENTRY(knote) kn_link; /* for kq */ williamr@2: SLIST_ENTRY(knote) kn_selnext; /* for struct selinfo */ williamr@2: struct knlist *kn_knlist; /* f_attach populated */ williamr@2: TAILQ_ENTRY(knote) kn_tqe; williamr@2: struct kqueue *kn_kq; /* which queue we are on */ williamr@2: struct kevent kn_kevent; williamr@2: int kn_status; /* protected by kq lock */ williamr@2: #define KN_ACTIVE 0x01 /* event has been triggered */ williamr@2: #define KN_QUEUED 0x02 /* event is on queue */ williamr@2: #define KN_DISABLED 0x04 /* event is disabled */ williamr@2: #define KN_DETACHED 0x08 /* knote is detached */ williamr@2: #define KN_INFLUX 0x10 /* knote is in flux */ williamr@2: #define KN_MARKER 0x20 /* ignore this knote */ williamr@2: #define KN_KQUEUE 0x40 /* this knote belongs to a kq */ williamr@2: #define KN_HASKQLOCK 0x80 /* for _inevent */ williamr@2: int kn_sfflags; /* saved filter flags */ williamr@2: intptr_t kn_sdata; /* saved data field */ williamr@2: union { williamr@2: struct file *p_fp; /* file data pointer */ williamr@2: struct proc *p_proc; /* proc pointer */ williamr@2: } kn_ptr; williamr@2: struct filterops *kn_fop; williamr@2: void *kn_hook; williamr@2: williamr@2: #define kn_id kn_kevent.ident williamr@2: #define kn_filter kn_kevent.filter williamr@2: #define kn_flags kn_kevent.flags williamr@2: #define kn_fflags kn_kevent.fflags williamr@2: #define kn_data kn_kevent.data williamr@2: #define kn_fp kn_ptr.p_fp williamr@2: }; williamr@2: struct kevent_copyops { williamr@2: void *arg; williamr@2: int (*k_copyout)(void *arg, struct kevent *kevp, int count); williamr@2: int (*k_copyin)(void *arg, struct kevent *kevp, int count); williamr@2: }; williamr@2: williamr@2: struct thread; williamr@2: struct proc; williamr@2: struct knlist; williamr@2: williamr@2: #endif /* !_KERNEL */ williamr@2: williamr@2: #endif /* !_SYS_EVENT_H_ */