[BACK]Return to event.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / sys

Annotation of src/sys/sys/event.h, Revision 1.15.4.1

1.15.4.1! yamt        1: /*     $NetBSD: event.h,v 1.15 2005/02/26 22:25:34 perry Exp $ */
1.1       lukem       2: /*-
                      3:  * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
                      4:  * All rights reserved.
                      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  * 1. Redistributions of source code must retain the above copyright
                     10:  *    notice, this list of conditions and the following disclaimer.
                     11:  * 2. Redistributions in binary form must reproduce the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer in the
                     13:  *    documentation and/or other materials provided with the distribution.
                     14:  *
                     15:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     16:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     17:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     18:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     19:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     20:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     21:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     22:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     23:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     24:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     25:  * SUCH DAMAGE.
                     26:  *
                     27:  *     $FreeBSD: src/sys/sys/event.h,v 1.12 2001/02/24 01:44:03 jlemon Exp $
                     28:  */
                     29:
                     30: #ifndef _SYS_EVENT_H_
1.3       jdolecek   31: #define        _SYS_EVENT_H_
                     32:
1.8       bjh21      33: #include <sys/featuretest.h>
1.7       tron       34: #include <sys/types.h>                 /* for size_t */
1.3       jdolecek   35: #include <sys/inttypes.h>              /* for uintptr_t */
                     36: #include <sys/null.h>                  /* for NULL */
                     37:
                     38: #define        EVFILT_READ             0
                     39: #define        EVFILT_WRITE            1
                     40: #define        EVFILT_AIO              2       /* attached to aio requests */
                     41: #define        EVFILT_VNODE            3       /* attached to vnodes */
                     42: #define        EVFILT_PROC             4       /* attached to struct proc */
                     43: #define        EVFILT_SIGNAL           5       /* attached to struct proc */
1.6       jdolecek   44: #define        EVFILT_TIMER            6       /* arbitrary timer (in ms) */
                     45: #define        EVFILT_SYSCOUNT         7       /* number of filters */
1.3       jdolecek   46:
                     47: #define        EV_SET(kevp, a, b, c, d, e, f)                                  \
                     48: do {                                                                   \
                     49:        (kevp)->ident = (a);                                            \
                     50:        (kevp)->filter = (b);                                           \
                     51:        (kevp)->flags = (c);                                            \
                     52:        (kevp)->fflags = (d);                                           \
                     53:        (kevp)->data = (e);                                             \
                     54:        (kevp)->udata = (f);                                            \
                     55: } while (/* CONSTCOND */ 0)
1.1       lukem      56:
                     57:
                     58: struct kevent {
                     59:        uintptr_t       ident;          /* identifier for this event */
1.3       jdolecek   60:        uint32_t        filter;         /* filter for event */
                     61:        uint32_t        flags;          /* action flags for kqueue */
                     62:        uint32_t        fflags;         /* filter flag value */
                     63:        int64_t         data;           /* filter data value */
                     64:        intptr_t        udata;          /* opaque user data identifier */
1.1       lukem      65: };
                     66:
                     67: /* actions */
1.3       jdolecek   68: #define        EV_ADD          0x0001          /* add event to kq (implies ENABLE) */
                     69: #define        EV_DELETE       0x0002          /* delete event from kq */
                     70: #define        EV_ENABLE       0x0004          /* enable event */
                     71: #define        EV_DISABLE      0x0008          /* disable event (not reported) */
1.1       lukem      72:
                     73: /* flags */
1.3       jdolecek   74: #define        EV_ONESHOT      0x0010          /* only report one occurrence */
                     75: #define        EV_CLEAR        0x0020          /* clear event state after reporting */
1.1       lukem      76:
1.3       jdolecek   77: #define        EV_SYSFLAGS     0xF000          /* reserved by system */
                     78: #define        EV_FLAG1        0x2000          /* filter-specific flag */
1.1       lukem      79:
                     80: /* returned values */
1.3       jdolecek   81: #define        EV_EOF          0x8000          /* EOF detected */
                     82: #define        EV_ERROR        0x4000          /* error, data contains errno */
1.1       lukem      83:
                     84: /*
1.12      jdolecek   85:  * hint flag for in-kernel use - must not equal any existing note
                     86:  */
                     87: #ifdef _KERNEL
                     88: #define NOTE_SUBMIT    0x01000000              /* initial knote submission */
                     89: #endif
                     90: /*
1.1       lukem      91:  * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace
                     92:  */
1.12      jdolecek   93: #define        NOTE_LOWAT      0x0001                  /* low water mark */
1.1       lukem      94:
                     95: /*
                     96:  * data/hint flags for EVFILT_VNODE, shared with userspace
                     97:  */
                     98: #define        NOTE_DELETE     0x0001                  /* vnode was removed */
                     99: #define        NOTE_WRITE      0x0002                  /* data contents changed */
                    100: #define        NOTE_EXTEND     0x0004                  /* size increased */
                    101: #define        NOTE_ATTRIB     0x0008                  /* attributes changed */
                    102: #define        NOTE_LINK       0x0010                  /* link count changed */
                    103: #define        NOTE_RENAME     0x0020                  /* vnode was renamed */
                    104: #define        NOTE_REVOKE     0x0040                  /* vnode access was revoked */
                    105:
                    106: /*
                    107:  * data/hint flags for EVFILT_PROC, shared with userspace
                    108:  */
                    109: #define        NOTE_EXIT       0x80000000              /* process exited */
                    110: #define        NOTE_FORK       0x40000000              /* process forked */
                    111: #define        NOTE_EXEC       0x20000000              /* process exec'd */
                    112: #define        NOTE_PCTRLMASK  0xf0000000              /* mask for hint bits */
                    113: #define        NOTE_PDATAMASK  0x000fffff              /* mask for pid */
                    114:
                    115: /* additional flags for EVFILT_PROC */
                    116: #define        NOTE_TRACK      0x00000001              /* follow across forks */
                    117: #define        NOTE_TRACKERR   0x00000002              /* could not track child */
                    118: #define        NOTE_CHILD      0x00000004              /* am a child process */
                    119:
                    120: /*
                    121:  * This is currently visible to userland to work around broken
                    122:  * programs which pull in <sys/proc.h> or <sys/select.h>.
                    123:  */
1.15      perry     124: #include <sys/queue.h>
1.1       lukem     125: struct knote;
                    126: SLIST_HEAD(klist, knote);
                    127:
1.3       jdolecek  128:
                    129: /*
                    130:  * ioctl(2)s supported on kqueue descriptors.
                    131:  */
                    132: #include <sys/ioctl.h>
                    133:
                    134: struct kfilter_mapping {
                    135:        char            *name;          /* name to lookup or return */
                    136:        size_t          len;            /* length of name */
                    137:        uint32_t        filter;         /* filter to lookup or return */
                    138: };
                    139:
1.15      perry     140: /* map filter to name (max size len) */
1.3       jdolecek  141: #define KFILTER_BYFILTER       _IOWR('k', 0, struct kfilter_mapping)
                    142: /* map name to filter (len ignored) */
                    143: #define KFILTER_BYNAME         _IOWR('k', 1, struct kfilter_mapping)
                    144:
1.1       lukem     145: #ifdef _KERNEL
1.5       christos  146: #include <sys/mallocvar.h>             /* for malloc types */
1.4       thorpej   147:
                    148: MALLOC_DECLARE(M_KEVENT);
1.1       lukem     149:
1.3       jdolecek  150: #define        KNOTE(list, hint)       if (!SLIST_EMPTY(list)) knote(list, hint)
1.1       lukem     151:
                    152: /*
                    153:  * Flag indicating hint is a signal.  Used by EVFILT_SIGNAL, and also
                    154:  * shared by EVFILT_PROC  (all knotes attached to p->p_klist)
                    155:  */
1.3       jdolecek  156: #define        NOTE_SIGNAL     0x08000000
1.1       lukem     157:
1.3       jdolecek  158: /*
                    159:  * Callback methods for each filter type.
                    160:  */
1.1       lukem     161: struct filterops {
1.3       jdolecek  162:        int     f_isfd;                 /* true if ident == filedescriptor */
1.14      perry     163:        int     (*f_attach)     (struct knote *);
1.3       jdolecek  164:                                        /* called when knote is ADDed */
1.14      perry     165:        void    (*f_detach)     (struct knote *);
1.3       jdolecek  166:                                        /* called when knote is DELETEd */
1.14      perry     167:        int     (*f_event)      (struct knote *, long);
1.3       jdolecek  168:                                        /* called when event is triggered */
1.1       lukem     169: };
                    170:
                    171: struct knote {
                    172:        SLIST_ENTRY(knote)      kn_link;        /* for fd */
                    173:        SLIST_ENTRY(knote)      kn_selnext;     /* for struct selinfo */
                    174:        TAILQ_ENTRY(knote)      kn_tqe;
1.3       jdolecek  175:        struct kqueue           *kn_kq;         /* which queue we are on */
                    176:        struct kevent           kn_kevent;
                    177:        uint32_t                kn_status;
                    178:        uint32_t                kn_sfflags;     /* saved filter flags */
                    179:        uintptr_t               kn_sdata;       /* saved data field */
1.1       lukem     180:        union {
1.3       jdolecek  181:                struct file     *p_fp;          /* file data pointer */
                    182:                struct proc     *p_proc;        /* proc pointer */
                    183:                void            *p_opaque;      /* opaque/misc pointer */
1.1       lukem     184:        } kn_ptr;
1.3       jdolecek  185:        const struct filterops  *kn_fop;
                    186:        void                    *kn_hook;
                    187:
                    188: #define        KN_ACTIVE       0x01                    /* event has been triggered */
                    189: #define        KN_QUEUED       0x02                    /* event is on queue */
                    190: #define        KN_DISABLED     0x04                    /* event is disabled */
                    191: #define        KN_DETACHED     0x08                    /* knote is detached */
                    192:
                    193: #define        kn_id           kn_kevent.ident
                    194: #define        kn_filter       kn_kevent.filter
                    195: #define        kn_flags        kn_kevent.flags
                    196: #define        kn_fflags       kn_kevent.fflags
                    197: #define        kn_data         kn_kevent.data
                    198: #define        kn_fp           kn_ptr.p_fp
1.1       lukem     199: };
                    200:
1.15.4.1! yamt      201: #include <sys/systm.h> /* for copyin_t */
        !           202:
        !           203: struct lwp;
        !           204: struct timespec;
1.1       lukem     205:
1.11      itojun    206: void   knote(struct klist *, long);
1.15.4.1! yamt      207: void   knote_remove(struct lwp *, struct klist *);
        !           208: void   knote_fdclose(struct lwp *, int);
        !           209: int    kqueue_register(struct kqueue *, struct kevent *, struct lwp *);
        !           210:
        !           211: typedef        int (*kevent_fetch_changes_t)(void *, const struct kevent *,
        !           212:     struct kevent *, size_t, int);
        !           213: typedef        int (*kevent_put_events_t)(void *, struct kevent *, struct kevent *,
        !           214:     size_t, int);
        !           215:
        !           216: struct kevent_ops {
        !           217:        void *keo_private;
        !           218:        copyin_t keo_fetch_timeout;
        !           219:        kevent_fetch_changes_t keo_fetch_changes;
        !           220:        kevent_put_events_t keo_put_events;
        !           221: };
        !           222:
        !           223: int    kevent1(struct lwp *, register_t *, int, const struct kevent *,
        !           224:     size_t, struct kevent *, size_t, const struct timespec *,
        !           225:     const struct kevent_ops *);
1.3       jdolecek  226:
1.11      itojun    227: int    kfilter_register(const char *, const struct filterops *, int *);
                    228: int    kfilter_unregister(const char *);
                    229:
                    230: int    filt_seltrue(struct knote *, long);
                    231: int    seltrue_kqfilter(dev_t, struct knote *);
1.3       jdolecek  232:
1.1       lukem     233: #else  /* !_KERNEL */
                    234:
                    235: #include <sys/cdefs.h>
                    236: struct timespec;
                    237:
                    238: __BEGIN_DECLS
1.8       bjh21     239: #if defined(_NETBSD_SOURCE)
1.14      perry     240: int    kqueue(void);
                    241: int    kevent(int, const struct kevent *, size_t, struct kevent *, size_t,
                    242:                    const struct timespec *);
1.3       jdolecek  243: #endif /* !_POSIX_C_SOURCE */
1.1       lukem     244: __END_DECLS
                    245:
                    246: #endif /* !_KERNEL */
                    247:
                    248: #endif /* !_SYS_EVENT_H_ */

CVSweb <webmaster@jp.NetBSD.org>