Project

General

Profile

Statistics
| Revision:

root / lab4 / .minix-src / include / sys / event.h @ 13

History | View | Annotate | Download (8.14 KB)

1
/*        $NetBSD: event.h,v 1.24 2015/01/14 22:21:00 christos Exp $        */
2

    
3
/*-
4
 * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 * 1. Redistributions of source code must retain the above copyright
11
 *    notice, this list of conditions and the following disclaimer.
12
 * 2. Redistributions in binary form must reproduce the above copyright
13
 *    notice, this list of conditions and the following disclaimer in the
14
 *    documentation and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
 * SUCH DAMAGE.
27
 *
28
 *        $FreeBSD: src/sys/sys/event.h,v 1.12 2001/02/24 01:44:03 jlemon Exp $
29
 */
30

    
31
#ifndef _SYS_EVENT_H_
32
#define        _SYS_EVENT_H_
33

    
34
#include <sys/featuretest.h>
35
#include <sys/types.h>                        /* for size_t */
36
#include <sys/inttypes.h>                /* for uintptr_t */
37
#include <sys/null.h>                        /* for NULL */
38

    
39
#define        EVFILT_READ                0U
40
#define        EVFILT_WRITE                1U
41
#define        EVFILT_AIO                2U        /* attached to aio requests */
42
#define        EVFILT_VNODE                3U        /* attached to vnodes */
43
#define        EVFILT_PROC                4U        /* attached to struct proc */
44
#define        EVFILT_SIGNAL                5U        /* attached to struct proc */
45
#define        EVFILT_TIMER                6U        /* arbitrary timer (in ms) */
46
#define        EVFILT_SYSCOUNT                7U        /* number of filters */
47

    
48
#define        EV_SET(kevp, a, b, c, d, e, f)                                        \
49
do {                                                                        \
50
        (kevp)->ident = (a);                                                \
51
        (kevp)->filter = (b);                                                \
52
        (kevp)->flags = (c);                                                \
53
        (kevp)->fflags = (d);                                                \
54
        (kevp)->data = (e);                                                \
55
        (kevp)->udata = (f);                                                \
56
} while (/* CONSTCOND */ 0)
57

    
58

    
59
struct kevent {
60
        uintptr_t        ident;                /* identifier for this event */
61
        uint32_t        filter;                /* filter for event */
62
        uint32_t        flags;                /* action flags for kqueue */
63
        uint32_t        fflags;                /* filter flag value */
64
        int64_t                data;                /* filter data value */
65
        intptr_t        udata;                /* opaque user data identifier */
66
};
67

    
68
/* actions */
69
#define        EV_ADD                0x0001U                /* add event to kq (implies ENABLE) */
70
#define        EV_DELETE        0x0002U                /* delete event from kq */
71
#define        EV_ENABLE        0x0004U                /* enable event */
72
#define        EV_DISABLE        0x0008U                /* disable event (not reported) */
73

    
74
/* flags */
75
#define        EV_ONESHOT        0x0010U                /* only report one occurrence */
76
#define        EV_CLEAR        0x0020U                /* clear event state after reporting */
77

    
78
#define        EV_SYSFLAGS        0xF000U                /* reserved by system */
79
#define        EV_FLAG1        0x2000U                /* filter-specific flag */
80

    
81
/* returned values */
82
#define        EV_EOF                0x8000U                /* EOF detected */
83
#define        EV_ERROR        0x4000U                /* error, data contains errno */
84

    
85
/*
86
 * hint flag for in-kernel use - must not equal any existing note
87
 */
88
#ifdef _KERNEL
89
#define NOTE_SUBMIT        0x01000000U                /* initial knote submission */
90
#endif
91
/*
92
 * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace
93
 */
94
#define        NOTE_LOWAT        0x0001U                        /* low water mark */
95

    
96
/*
97
 * data/hint flags for EVFILT_VNODE, shared with userspace
98
 */
99
#define        NOTE_DELETE        0x0001U                        /* vnode was removed */
100
#define        NOTE_WRITE        0x0002U                        /* data contents changed */
101
#define        NOTE_EXTEND        0x0004U                        /* size increased */
102
#define        NOTE_ATTRIB        0x0008U                        /* attributes changed */
103
#define        NOTE_LINK        0x0010U                        /* link count changed */
104
#define        NOTE_RENAME        0x0020U                        /* vnode was renamed */
105
#define        NOTE_REVOKE        0x0040U                        /* vnode access was revoked */
106

    
107
/*
108
 * data/hint flags for EVFILT_PROC, shared with userspace
109
 */
110
#define        NOTE_EXIT        0x80000000U                /* process exited */
111
#define        NOTE_FORK        0x40000000U                /* process forked */
112
#define        NOTE_EXEC        0x20000000U                /* process exec'd */
113
#define        NOTE_PCTRLMASK        0xf0000000U                /* mask for hint bits */
114
#define        NOTE_PDATAMASK        0x000fffffU                /* mask for pid */
115

    
116
/* additional flags for EVFILT_PROC */
117
#define        NOTE_TRACK        0x00000001U                /* follow across forks */
118
#define        NOTE_TRACKERR        0x00000002U                /* could not track child */
119
#define        NOTE_CHILD        0x00000004U                /* am a child process */
120

    
121
/*
122
 * This is currently visible to userland to work around broken
123
 * programs which pull in <sys/proc.h> or <sys/select.h>.
124
 */
125
#include <sys/queue.h>
126
struct knote;
127
SLIST_HEAD(klist, knote);
128

    
129

    
130
/*
131
 * ioctl(2)s supported on kqueue descriptors.
132
 */
133
#include <sys/ioctl.h>
134

    
135
struct kfilter_mapping {
136
        char                *name;                /* name to lookup or return */
137
        size_t                len;                /* length of name */
138
        uint32_t        filter;                /* filter to lookup or return */
139
};
140

    
141
/* map filter to name (max size len) */
142
#define KFILTER_BYFILTER        _IOWR('k', 0, struct kfilter_mapping)
143
/* map name to filter (len ignored) */
144
#define KFILTER_BYNAME                _IOWR('k', 1, struct kfilter_mapping)
145

    
146
#ifdef _KERNEL
147

    
148
#define        KNOTE(list, hint)        if (!SLIST_EMPTY(list)) knote(list, hint)
149

    
150
/*
151
 * Flag indicating hint is a signal.  Used by EVFILT_SIGNAL, and also
152
 * shared by EVFILT_PROC  (all knotes attached to p->p_klist)
153
 */
154
#define        NOTE_SIGNAL        0x08000000U
155

    
156
/*
157
 * Callback methods for each filter type.
158
 */
159
struct filterops {
160
        int        f_isfd;                        /* true if ident == filedescriptor */
161
        int        (*f_attach)        (struct knote *);
162
                                        /* called when knote is ADDed */
163
        void        (*f_detach)        (struct knote *);
164
                                        /* called when knote is DELETEd */
165
        int        (*f_event)        (struct knote *, long);
166
                                        /* called when event is triggered */
167
};
168

    
169
/*
170
 * Field locking:
171
 *
172
 * f        kn_kq->kq_fdp->fd_lock
173
 * q        kn_kq->kq_lock
174
 * o        object mutex (e.g. device driver or vnode interlock)
175
 */
176
struct kfilter;
177

    
178
struct knote {
179
        SLIST_ENTRY(knote)        kn_link;        /* f: for fd */
180
        SLIST_ENTRY(knote)        kn_selnext;        /* o: for struct selinfo */
181
        TAILQ_ENTRY(knote)        kn_tqe;                /* q: for struct kqueue */
182
        struct kqueue                *kn_kq;                /* q: which queue we are on */
183
        struct kevent                kn_kevent;
184
        uint32_t                kn_status;
185
        uint32_t                kn_sfflags;        /*   saved filter flags */
186
        uintptr_t                kn_sdata;        /*   saved data field */
187
        void                        *kn_obj;        /*   pointer to monitored obj */
188
        const struct filterops        *kn_fop;
189
        struct kfilter                *kn_kfilter;
190
        void                         *kn_hook;
191

    
192
#define        KN_ACTIVE        0x01U                        /* event has been triggered */
193
#define        KN_QUEUED        0x02U                        /* event is on queue */
194
#define        KN_DISABLED        0x04U                        /* event is disabled */
195
#define        KN_DETACHED        0x08U                        /* knote is detached */
196
#define        KN_MARKER        0x10U                        /* is a marker */
197

    
198
#define        kn_id                kn_kevent.ident
199
#define        kn_filter        kn_kevent.filter
200
#define        kn_flags        kn_kevent.flags
201
#define        kn_fflags        kn_kevent.fflags
202
#define        kn_data                kn_kevent.data
203
};
204

    
205
#include <sys/systm.h> /* for copyin_t */
206

    
207
struct lwp;
208
struct timespec;
209

    
210
void        kqueue_init(void);
211
void        knote(struct klist *, long);
212
void        knote_fdclose(int);
213

    
214
typedef        int (*kevent_fetch_changes_t)(void *, const struct kevent *,
215
    struct kevent *, size_t, int);
216
typedef        int (*kevent_put_events_t)(void *, struct kevent *, struct kevent *,
217
    size_t, int);
218

    
219
struct kevent_ops {
220
        void *keo_private;
221
        copyin_t keo_fetch_timeout;
222
        kevent_fetch_changes_t keo_fetch_changes;
223
        kevent_put_events_t keo_put_events;
224
};
225

    
226

    
227
int        kevent_fetch_changes(void *, const struct kevent *, struct kevent *,
228
    size_t, int);
229
int         kevent_put_events(void *, struct kevent *, struct kevent *, size_t,
230
    int);
231
int        kevent1(register_t *, int, const struct kevent *,
232
    size_t, struct kevent *, size_t, const struct timespec *,
233
    const struct kevent_ops *);
234

    
235
int        kfilter_register(const char *, const struct filterops *, int *);
236
int        kfilter_unregister(const char *);
237

    
238
int        filt_seltrue(struct knote *, long);
239
extern const struct filterops seltrue_filtops;
240

    
241
#else         /* !_KERNEL */
242

    
243
#include <sys/cdefs.h>
244
struct timespec;
245

    
246
__BEGIN_DECLS
247
#if defined(_NETBSD_SOURCE)
248
int        kqueue(void);
249
int        kqueue1(int);
250
#ifndef __LIBC12_SOURCE__
251
int        kevent(int, const struct kevent *, size_t, struct kevent *, size_t,
252
                    const struct timespec *) __RENAME(__kevent50);
253
#endif
254
#endif /* !_POSIX_C_SOURCE */
255
__END_DECLS
256

    
257
#endif /* !_KERNEL */
258

    
259
#endif /* !_SYS_EVENT_H_ */