williamr@2
|
1 |
/*-
|
williamr@2
|
2 |
* Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
|
williamr@2
|
3 |
* All rights reserved.
|
williamr@2
|
4 |
*
|
williamr@2
|
5 |
* Redistribution and use in source and binary forms, with or without
|
williamr@2
|
6 |
* modification, are permitted provided that the following conditions
|
williamr@2
|
7 |
* are met:
|
williamr@2
|
8 |
* 1. Redistributions of source code must retain the above copyright
|
williamr@2
|
9 |
* notice, this list of conditions and the following disclaimer.
|
williamr@2
|
10 |
* 2. Redistributions in binary form must reproduce the above copyright
|
williamr@2
|
11 |
* notice, this list of conditions and the following disclaimer in the
|
williamr@2
|
12 |
* documentation and/or other materials provided with the distribution.
|
williamr@2
|
13 |
*
|
williamr@2
|
14 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
williamr@2
|
15 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
williamr@2
|
16 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
williamr@2
|
17 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
williamr@2
|
18 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
williamr@2
|
19 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
williamr@2
|
20 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
williamr@2
|
21 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
williamr@2
|
22 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
williamr@2
|
23 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
williamr@2
|
24 |
* SUCH DAMAGE.
|
williamr@2
|
25 |
* © Portions copyright (c) 2007 Symbian Software Ltd. All rights reserved.
|
williamr@2
|
26 |
* $FreeBSD: src/sys/sys/event.h,v 1.32 2005/07/01 16:28:32 ssouhlal Exp $
|
williamr@2
|
27 |
*/
|
williamr@2
|
28 |
|
williamr@2
|
29 |
#ifndef _SYS_EVENT_H_
|
williamr@2
|
30 |
#define _SYS_EVENT_H_
|
williamr@2
|
31 |
|
williamr@2
|
32 |
#define EVFILT_READ (-1)
|
williamr@2
|
33 |
#define EVFILT_WRITE (-2)
|
williamr@2
|
34 |
#define EVFILT_AIO (-3) /* attached to aio requests */
|
williamr@2
|
35 |
#define EVFILT_VNODE (-4) /* attached to vnodes */
|
williamr@2
|
36 |
#define EVFILT_PROC (-5) /* attached to struct proc */
|
williamr@2
|
37 |
#define EVFILT_SIGNAL (-6) /* attached to struct proc */
|
williamr@2
|
38 |
#define EVFILT_TIMER (-7) /* timers */
|
williamr@2
|
39 |
#define EVFILT_NETDEV (-8) /* network devices */
|
williamr@2
|
40 |
#define EVFILT_FS (-9) /* filesystem events */
|
williamr@2
|
41 |
|
williamr@2
|
42 |
#define EVFILT_SYSCOUNT 9
|
williamr@2
|
43 |
|
williamr@2
|
44 |
#define EV_SET(kevp_, a, b, c, d, e, f) do { \
|
williamr@2
|
45 |
struct kevent *kevp = (kevp_); \
|
williamr@2
|
46 |
(kevp)->ident = (a); \
|
williamr@2
|
47 |
(kevp)->filter = (b); \
|
williamr@2
|
48 |
(kevp)->flags = (c); \
|
williamr@2
|
49 |
(kevp)->fflags = (d); \
|
williamr@2
|
50 |
(kevp)->data = (e); \
|
williamr@2
|
51 |
(kevp)->udata = (f); \
|
williamr@2
|
52 |
} while(0)
|
williamr@2
|
53 |
|
williamr@2
|
54 |
struct kevent {
|
williamr@2
|
55 |
uintptr_t ident; /* identifier for this event */
|
williamr@2
|
56 |
short filter; /* filter for event */
|
williamr@2
|
57 |
u_short flags;
|
williamr@2
|
58 |
u_int fflags;
|
williamr@2
|
59 |
intptr_t data;
|
williamr@2
|
60 |
void *udata; /* opaque user data identifier */
|
williamr@2
|
61 |
};
|
williamr@2
|
62 |
|
williamr@2
|
63 |
/* actions */
|
williamr@2
|
64 |
#define EV_ADD 0x0001 /* add event to kq (implies enable) */
|
williamr@2
|
65 |
#define EV_DELETE 0x0002 /* delete event from kq */
|
williamr@2
|
66 |
#define EV_ENABLE 0x0004 /* enable event */
|
williamr@2
|
67 |
#define EV_DISABLE 0x0008 /* disable event (not reported) */
|
williamr@2
|
68 |
|
williamr@2
|
69 |
/* flags */
|
williamr@2
|
70 |
#define EV_ONESHOT 0x0010 /* only report one occurrence */
|
williamr@2
|
71 |
#define EV_CLEAR 0x0020 /* clear event state after reporting */
|
williamr@2
|
72 |
|
williamr@2
|
73 |
#define EV_SYSFLAGS 0xF000 /* reserved by system */
|
williamr@2
|
74 |
#define EV_FLAG1 0x2000 /* filter-specific flag */
|
williamr@2
|
75 |
|
williamr@2
|
76 |
/* returned values */
|
williamr@2
|
77 |
#define EV_EOF 0x8000 /* EOF detected */
|
williamr@2
|
78 |
#define EV_ERROR 0x4000 /* error, data contains errno */
|
williamr@2
|
79 |
|
williamr@2
|
80 |
/*
|
williamr@2
|
81 |
* data/hint flags for EVFILT_{READ|WRITE}, shared with userspace
|
williamr@2
|
82 |
*/
|
williamr@2
|
83 |
#define NOTE_LOWAT 0x0001 /* low water mark */
|
williamr@2
|
84 |
|
williamr@2
|
85 |
/*
|
williamr@2
|
86 |
* data/hint flags for EVFILT_VNODE, shared with userspace
|
williamr@2
|
87 |
*/
|
williamr@2
|
88 |
#define NOTE_DELETE 0x0001 /* vnode was removed */
|
williamr@2
|
89 |
#define NOTE_WRITE 0x0002 /* data contents changed */
|
williamr@2
|
90 |
#define NOTE_EXTEND 0x0004 /* size increased */
|
williamr@2
|
91 |
#define NOTE_ATTRIB 0x0008 /* attributes changed */
|
williamr@2
|
92 |
#define NOTE_LINK 0x0010 /* link count changed */
|
williamr@2
|
93 |
#define NOTE_RENAME 0x0020 /* vnode was renamed */
|
williamr@2
|
94 |
#define NOTE_REVOKE 0x0040 /* vnode access was revoked */
|
williamr@2
|
95 |
|
williamr@2
|
96 |
/*
|
williamr@2
|
97 |
* data/hint flags for EVFILT_PROC, shared with userspace
|
williamr@2
|
98 |
*/
|
williamr@2
|
99 |
#define NOTE_EXIT 0x80000000 /* process exited */
|
williamr@2
|
100 |
#define NOTE_FORK 0x40000000 /* process forked */
|
williamr@2
|
101 |
#define NOTE_EXEC 0x20000000 /* process exec'd */
|
williamr@2
|
102 |
#define NOTE_PCTRLMASK 0xf0000000 /* mask for hint bits */
|
williamr@2
|
103 |
#define NOTE_PDATAMASK 0x000fffff /* mask for pid */
|
williamr@2
|
104 |
|
williamr@2
|
105 |
/* additional flags for EVFILT_PROC */
|
williamr@2
|
106 |
#define NOTE_TRACK 0x00000001 /* follow across forks */
|
williamr@2
|
107 |
#define NOTE_TRACKERR 0x00000002 /* could not track child */
|
williamr@2
|
108 |
#define NOTE_CHILD 0x00000004 /* am a child process */
|
williamr@2
|
109 |
|
williamr@2
|
110 |
/*
|
williamr@2
|
111 |
* data/hint flags for EVFILT_NETDEV, shared with userspace
|
williamr@2
|
112 |
*/
|
williamr@2
|
113 |
#define NOTE_LINKUP 0x0001 /* link is up */
|
williamr@2
|
114 |
#define NOTE_LINKDOWN 0x0002 /* link is down */
|
williamr@2
|
115 |
#define NOTE_LINKINV 0x0004 /* link state is invalid */
|
williamr@2
|
116 |
|
williamr@2
|
117 |
/*
|
williamr@2
|
118 |
* This is currently visible to userland to work around broken
|
williamr@2
|
119 |
* programs which pull in <sys/proc.h>.
|
williamr@2
|
120 |
*/
|
williamr@2
|
121 |
#include <sys/queue.h>
|
williamr@2
|
122 |
#include <sys/_lock.h>
|
williamr@2
|
123 |
#include <sys/_mutex.h>
|
williamr@2
|
124 |
struct knote;
|
williamr@2
|
125 |
struct kqueue;
|
williamr@2
|
126 |
struct knlist {
|
williamr@2
|
127 |
struct klist kl_list;
|
williamr@2
|
128 |
void (*kl_lock)(void *); /* lock function */
|
williamr@2
|
129 |
void (*kl_unlock)(void *);
|
williamr@2
|
130 |
int (*kl_locked)(void *);
|
williamr@2
|
131 |
void *kl_lockarg; /* argument passed to kl_lockf() */
|
williamr@2
|
132 |
};
|
williamr@2
|
133 |
|
williamr@2
|
134 |
|
williamr@2
|
135 |
#ifdef _KERNEL
|
williamr@2
|
136 |
|
williamr@2
|
137 |
#define KNLIST_EMPTY(list) SLIST_EMPTY(&(list)->kl_list)
|
williamr@2
|
138 |
|
williamr@2
|
139 |
/*
|
williamr@2
|
140 |
* Flag indicating hint is a signal. Used by EVFILT_SIGNAL, and also
|
williamr@2
|
141 |
* shared by EVFILT_PROC (all knotes attached to p->p_klist)
|
williamr@2
|
142 |
*/
|
williamr@2
|
143 |
#define NOTE_SIGNAL 0x08000000
|
williamr@2
|
144 |
|
williamr@2
|
145 |
struct filterops {
|
williamr@2
|
146 |
int f_isfd; /* true if ident == filedescriptor */
|
williamr@2
|
147 |
int (*f_attach)(struct knote *kn);
|
williamr@2
|
148 |
void (*f_detach)(struct knote *kn);
|
williamr@2
|
149 |
int (*f_event)(struct knote *kn, long hint);
|
williamr@2
|
150 |
};
|
williamr@2
|
151 |
|
williamr@2
|
152 |
/*
|
williamr@2
|
153 |
* Setting the KN_INFLUX flag enables you to unlock the kq that this knote
|
williamr@2
|
154 |
* is on, and modify kn_status as if you had the KQ lock.
|
williamr@2
|
155 |
*
|
williamr@2
|
156 |
* kn_sfflags, kn_sdata, and kn_kevent are protected by the knlist lock.
|
williamr@2
|
157 |
*/
|
williamr@2
|
158 |
struct knote {
|
williamr@2
|
159 |
SLIST_ENTRY(knote) kn_link; /* for kq */
|
williamr@2
|
160 |
SLIST_ENTRY(knote) kn_selnext; /* for struct selinfo */
|
williamr@2
|
161 |
struct knlist *kn_knlist; /* f_attach populated */
|
williamr@2
|
162 |
TAILQ_ENTRY(knote) kn_tqe;
|
williamr@2
|
163 |
struct kqueue *kn_kq; /* which queue we are on */
|
williamr@2
|
164 |
struct kevent kn_kevent;
|
williamr@2
|
165 |
int kn_status; /* protected by kq lock */
|
williamr@2
|
166 |
#define KN_ACTIVE 0x01 /* event has been triggered */
|
williamr@2
|
167 |
#define KN_QUEUED 0x02 /* event is on queue */
|
williamr@2
|
168 |
#define KN_DISABLED 0x04 /* event is disabled */
|
williamr@2
|
169 |
#define KN_DETACHED 0x08 /* knote is detached */
|
williamr@2
|
170 |
#define KN_INFLUX 0x10 /* knote is in flux */
|
williamr@2
|
171 |
#define KN_MARKER 0x20 /* ignore this knote */
|
williamr@2
|
172 |
#define KN_KQUEUE 0x40 /* this knote belongs to a kq */
|
williamr@2
|
173 |
#define KN_HASKQLOCK 0x80 /* for _inevent */
|
williamr@2
|
174 |
int kn_sfflags; /* saved filter flags */
|
williamr@2
|
175 |
intptr_t kn_sdata; /* saved data field */
|
williamr@2
|
176 |
union {
|
williamr@2
|
177 |
struct file *p_fp; /* file data pointer */
|
williamr@2
|
178 |
struct proc *p_proc; /* proc pointer */
|
williamr@2
|
179 |
} kn_ptr;
|
williamr@2
|
180 |
struct filterops *kn_fop;
|
williamr@2
|
181 |
void *kn_hook;
|
williamr@2
|
182 |
|
williamr@2
|
183 |
#define kn_id kn_kevent.ident
|
williamr@2
|
184 |
#define kn_filter kn_kevent.filter
|
williamr@2
|
185 |
#define kn_flags kn_kevent.flags
|
williamr@2
|
186 |
#define kn_fflags kn_kevent.fflags
|
williamr@2
|
187 |
#define kn_data kn_kevent.data
|
williamr@2
|
188 |
#define kn_fp kn_ptr.p_fp
|
williamr@2
|
189 |
};
|
williamr@2
|
190 |
struct kevent_copyops {
|
williamr@2
|
191 |
void *arg;
|
williamr@2
|
192 |
int (*k_copyout)(void *arg, struct kevent *kevp, int count);
|
williamr@2
|
193 |
int (*k_copyin)(void *arg, struct kevent *kevp, int count);
|
williamr@2
|
194 |
};
|
williamr@2
|
195 |
|
williamr@2
|
196 |
struct thread;
|
williamr@2
|
197 |
struct proc;
|
williamr@2
|
198 |
struct knlist;
|
williamr@2
|
199 |
|
williamr@2
|
200 |
#endif /* !_KERNEL */
|
williamr@2
|
201 |
|
williamr@2
|
202 |
#endif /* !_SYS_EVENT_H_ */
|