]>
Commit | Line | Data |
---|---|---|
55e303ae | 1 | /* |
91447636 | 2 | * Copyright (c) 2003-2005 Apple Computer, Inc. All rights reserved. |
55e303ae A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
ff6e181a A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
55e303ae | 12 | * |
ff6e181a A |
13 | * The Original Code and all software distributed under the License are |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
55e303ae A |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
ff6e181a A |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
55e303ae A |
20 | * |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | /*- | |
24 | * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org> | |
25 | * All rights reserved. | |
26 | * | |
27 | * Redistribution and use in source and binary forms, with or without | |
28 | * modification, are permitted provided that the following conditions | |
29 | * are met: | |
30 | * 1. Redistributions of source code must retain the above copyright | |
31 | * notice, this list of conditions and the following disclaimer. | |
32 | * 2. Redistributions in binary form must reproduce the above copyright | |
33 | * notice, this list of conditions and the following disclaimer in the | |
34 | * documentation and/or other materials provided with the distribution. | |
35 | * | |
36 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
37 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
39 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
40 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
41 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
42 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
44 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
45 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
46 | * SUCH DAMAGE. | |
47 | * | |
48 | * $FreeBSD: src/sys/sys/event.h,v 1.5.2.5 2001/12/14 19:21:22 jlemon Exp $ | |
49 | */ | |
50 | ||
51 | #ifndef _SYS_EVENT_H_ | |
52 | #define _SYS_EVENT_H_ | |
53 | ||
91447636 A |
54 | #include <machine/types.h> |
55 | #include <sys/cdefs.h> | |
56 | #include <stdint.h> | |
57 | ||
55e303ae A |
58 | #define EVFILT_READ (-1) |
59 | #define EVFILT_WRITE (-2) | |
60 | #define EVFILT_AIO (-3) /* attached to aio requests */ | |
61 | #define EVFILT_VNODE (-4) /* attached to vnodes */ | |
62 | #define EVFILT_PROC (-5) /* attached to struct proc */ | |
63 | #define EVFILT_SIGNAL (-6) /* attached to struct proc */ | |
64 | #define EVFILT_TIMER (-7) /* timers */ | |
65 | #define EVFILT_MACHPORT (-8) /* Mach ports */ | |
66 | #define EVFILT_FS (-9) /* Filesystem events */ | |
67 | ||
68 | #define EVFILT_SYSCOUNT 9 | |
91447636 A |
69 | #define EVFILT_THREADMARKER EVFILT_SYSCOUNT /* Internal use only */ |
70 | ||
71 | #if __DARWIN_ALIGN_POWER | |
72 | #pragma options align=power | |
73 | #endif | |
55e303ae A |
74 | |
75 | struct kevent { | |
76 | uintptr_t ident; /* identifier for this event */ | |
77 | short filter; /* filter for event */ | |
91447636 A |
78 | unsigned short flags; /* general flags */ |
79 | unsigned int fflags; /* filter-specific flags */ | |
80 | intptr_t data; /* filter-specific data */ | |
81 | #ifdef KERNEL_PRIVATE | |
82 | user_addr_t udata; /* opaque user data identifier */ | |
83 | #else | |
55e303ae | 84 | void *udata; /* opaque user data identifier */ |
91447636 A |
85 | #endif |
86 | }; | |
87 | ||
88 | #ifdef KERNEL_PRIVATE | |
89 | ||
90 | struct user_kevent { | |
91 | uint64_t ident; /* identifier for this event */ | |
92 | short filter; /* filter for event */ | |
93 | unsigned short flags; /* general flags */ | |
94 | unsigned int fflags; /* filter-specific flags */ | |
95 | int64_t data; /* filter-specific data */ | |
96 | user_addr_t udata; /* opaque user data identifier */ | |
55e303ae A |
97 | }; |
98 | ||
91447636 A |
99 | #endif |
100 | ||
101 | #if __DARWIN_ALIGN_POWER | |
102 | #pragma options align=reset | |
103 | #endif | |
104 | ||
55e303ae A |
105 | #define EV_SET(kevp, a, b, c, d, e, f) do { \ |
106 | struct kevent *__kevp__ = (kevp); \ | |
107 | __kevp__->ident = (a); \ | |
108 | __kevp__->filter = (b); \ | |
109 | __kevp__->flags = (c); \ | |
110 | __kevp__->fflags = (d); \ | |
111 | __kevp__->data = (e); \ | |
112 | __kevp__->udata = (f); \ | |
113 | } while(0) | |
114 | ||
115 | /* actions */ | |
116 | #define EV_ADD 0x0001 /* add event to kq (implies enable) */ | |
117 | #define EV_DELETE 0x0002 /* delete event from kq */ | |
118 | #define EV_ENABLE 0x0004 /* enable event */ | |
119 | #define EV_DISABLE 0x0008 /* disable event (not reported) */ | |
120 | ||
121 | /* flags */ | |
122 | #define EV_ONESHOT 0x0010 /* only report one occurrence */ | |
123 | #define EV_CLEAR 0x0020 /* clear event state after reporting */ | |
124 | ||
125 | #define EV_SYSFLAGS 0xF000 /* reserved by system */ | |
91447636 | 126 | #define EV_FLAG0 0x1000 /* filter-specific flag */ |
55e303ae A |
127 | #define EV_FLAG1 0x2000 /* filter-specific flag */ |
128 | ||
129 | /* returned values */ | |
130 | #define EV_EOF 0x8000 /* EOF detected */ | |
131 | #define EV_ERROR 0x4000 /* error, data contains errno */ | |
132 | ||
133 | /* | |
91447636 A |
134 | * Filter specific flags for EVFILT_READ |
135 | * | |
136 | * The default behavior for EVFILT_READ is to make the "read" determination | |
137 | * relative to the current file descriptor read pointer. The EV_POLL | |
138 | * flag indicates the determination should be made via poll(2) semantics | |
139 | * (which always returns true for regular files - regardless of the amount | |
140 | * of unread data in the file). | |
141 | * | |
142 | * On input, EV_OOBAND specifies that only OOB data should be looked for. | |
143 | * The returned data count is the number of bytes beyond the current OOB marker. | |
144 | * | |
145 | * On output, EV_OOBAND indicates that OOB data is present | |
146 | * If it was not specified as an input parameter, then the data count is the | |
147 | * number of bytes before the current OOB marker. If at the marker, the | |
148 | * data count indicates the number of bytes available after it. In either | |
149 | * case, it's the amount of data one could expect to receive next. | |
55e303ae | 150 | */ |
91447636 A |
151 | #define EV_POLL EV_FLAG0 |
152 | #define EV_OOBAND EV_FLAG1 | |
55e303ae A |
153 | |
154 | /* | |
91447636 A |
155 | * data/hint fflags for EVFILT_{READ|WRITE}, shared with userspace |
156 | * | |
157 | * The default behavior for EVFILT_READ is to make the determination | |
158 | * realtive to the current file descriptor read pointer. | |
159 | */ | |
160 | #define NOTE_LOWAT 0x00000001 /* low water mark */ | |
161 | /* | |
162 | * data/hint fflags for EVFILT_VNODE, shared with userspace | |
55e303ae | 163 | */ |
91447636 A |
164 | #define NOTE_DELETE 0x00000001 /* vnode was removed */ |
165 | #define NOTE_WRITE 0x00000002 /* data contents changed */ | |
166 | #define NOTE_EXTEND 0x00000004 /* size increased */ | |
167 | #define NOTE_ATTRIB 0x00000008 /* attributes changed */ | |
168 | #define NOTE_LINK 0x00000010 /* link count changed */ | |
169 | #define NOTE_RENAME 0x00000020 /* vnode was renamed */ | |
170 | #define NOTE_REVOKE 0x00000040 /* vnode access was revoked */ | |
55e303ae A |
171 | |
172 | /* | |
91447636 | 173 | * data/hint fflags for EVFILT_PROC, shared with userspace |
55e303ae A |
174 | */ |
175 | #define NOTE_EXIT 0x80000000 /* process exited */ | |
176 | #define NOTE_FORK 0x40000000 /* process forked */ | |
177 | #define NOTE_EXEC 0x20000000 /* process exec'd */ | |
178 | #define NOTE_PCTRLMASK 0xf0000000 /* mask for hint bits */ | |
179 | #define NOTE_PDATAMASK 0x000fffff /* mask for pid */ | |
180 | ||
91447636 A |
181 | /* |
182 | * data/hint fflags for EVFILT_TIMER, shared with userspace. | |
183 | * The default is a (repeating) interval timer with the data | |
184 | * specifying the timeout interval in milliseconds. | |
185 | * | |
186 | * All timeouts are implicitly EV_CLEAR events. | |
187 | */ | |
188 | #define NOTE_SECONDS 0x00000001 /* data is seconds */ | |
189 | #define NOTE_USECONDS 0x00000002 /* data is microseconds */ | |
190 | #define NOTE_NSECONDS 0x00000004 /* data is nanoseconds */ | |
191 | #define NOTE_ABSOLUTE 0x00000008 /* absolute timeout */ | |
192 | /* ... implicit EV_ONESHOT */ | |
193 | ||
55e303ae A |
194 | /* additional flags for EVFILT_PROC */ |
195 | #define NOTE_TRACK 0x00000001 /* follow across forks */ | |
196 | #define NOTE_TRACKERR 0x00000002 /* could not track child */ | |
197 | #define NOTE_CHILD 0x00000004 /* am a child process */ | |
198 | ||
199 | ||
55e303ae | 200 | |
91447636 A |
201 | #ifndef KERNEL |
202 | /* Temporay solution for BootX to use inode.h till kqueue moves to vfs layer */ | |
203 | #include <sys/queue.h> | |
204 | struct knote; | |
205 | SLIST_HEAD(klist, knote); | |
206 | #endif | |
207 | ||
208 | #ifdef KERNEL | |
209 | ||
210 | #ifdef KERNEL_PRIVATE | |
55e303ae A |
211 | #include <sys/queue.h> |
212 | ||
213 | #ifdef MALLOC_DECLARE | |
214 | MALLOC_DECLARE(M_KQUEUE); | |
215 | #endif | |
216 | ||
217 | /* | |
218 | * Flag indicating hint is a signal. Used by EVFILT_SIGNAL, and also | |
219 | * shared by EVFILT_PROC (all knotes attached to p->p_klist) | |
220 | */ | |
221 | #define NOTE_SIGNAL 0x08000000 | |
222 | ||
91447636 A |
223 | TAILQ_HEAD(kqtailq, knote); /* a list of "queued" events */ |
224 | ||
55e303ae | 225 | struct knote { |
91447636 A |
226 | int kn_inuse; /* inuse count */ |
227 | struct kqtailq *kn_tq; /* pointer to tail queue */ | |
228 | TAILQ_ENTRY(knote) kn_tqe; /* linkage for tail queue */ | |
229 | struct kqueue *kn_kq; /* which kqueue we are on */ | |
230 | SLIST_ENTRY(knote) kn_link; /* linkage for search list */ | |
55e303ae | 231 | SLIST_ENTRY(knote) kn_selnext; /* klist element chain */ |
55e303ae | 232 | union { |
91447636 | 233 | struct fileproc *p_fp; /* file data pointer */ |
55e303ae A |
234 | struct proc *p_proc; /* proc pointer */ |
235 | } kn_ptr; | |
236 | struct filterops *kn_fop; | |
91447636 | 237 | int kn_status; /* status bits */ |
55e303ae A |
238 | int kn_sfflags; /* saved filter flags */ |
239 | struct kevent kn_kevent; | |
55e303ae | 240 | caddr_t kn_hook; |
91447636 A |
241 | int kn_hookid; |
242 | int64_t kn_sdata; /* saved data field */ | |
243 | ||
55e303ae A |
244 | #define KN_ACTIVE 0x01 /* event has been triggered */ |
245 | #define KN_QUEUED 0x02 /* event is on queue */ | |
246 | #define KN_DISABLED 0x04 /* event is disabled */ | |
91447636 A |
247 | #define KN_DROPPING 0x08 /* knote is being dropped */ |
248 | #define KN_USEWAIT 0x10 /* wait for knote use */ | |
249 | #define KN_DROPWAIT 0x20 /* wait for knote drop */ | |
55e303ae A |
250 | |
251 | #define kn_id kn_kevent.ident | |
252 | #define kn_filter kn_kevent.filter | |
253 | #define kn_flags kn_kevent.flags | |
254 | #define kn_fflags kn_kevent.fflags | |
255 | #define kn_data kn_kevent.data | |
256 | #define kn_fp kn_ptr.p_fp | |
257 | }; | |
258 | ||
259 | struct filterops { | |
260 | int f_isfd; /* true if ident == filedescriptor */ | |
91447636 A |
261 | int (*f_attach)(struct knote *kn); |
262 | void (*f_detach)(struct knote *kn); | |
263 | int (*f_event)(struct knote *kn, long hint); | |
55e303ae A |
264 | }; |
265 | ||
266 | struct proc; | |
267 | ||
268 | SLIST_HEAD(klist, knote); | |
269 | extern void klist_init(struct klist *list); | |
270 | ||
271 | #define KNOTE(list, hint) knote(list, hint) | |
272 | #define KNOTE_ATTACH(list, kn) knote_attach(list, kn) | |
273 | #define KNOTE_DETACH(list, kn) knote_detach(list, kn) | |
274 | ||
275 | ||
276 | extern void knote(struct klist *list, long hint); | |
277 | extern int knote_attach(struct klist *list, struct knote *kn); | |
278 | extern int knote_detach(struct klist *list, struct knote *kn); | |
55e303ae | 279 | extern void knote_fdclose(struct proc *p, int fd); |
55e303ae | 280 | |
91447636 A |
281 | #endif /* !KERNEL_PRIVATE */ |
282 | ||
283 | #else /* KERNEL */ | |
55e303ae | 284 | |
55e303ae | 285 | |
55e303ae A |
286 | struct timespec; |
287 | ||
288 | __BEGIN_DECLS | |
91447636 A |
289 | int kqueue(void); |
290 | int kevent(int kq, const struct kevent *changelist, int nchanges, | |
55e303ae | 291 | struct kevent *eventlist, int nevents, |
91447636 | 292 | const struct timespec *timeout); |
55e303ae A |
293 | __END_DECLS |
294 | ||
55e303ae | 295 | |
91447636 A |
296 | #ifdef PRIVATE |
297 | #include <mach/port.h> | |
55e303ae A |
298 | |
299 | __BEGIN_DECLS | |
91447636 A |
300 | mach_port_t kqueue_portset_np(int kq); |
301 | int kqueue_from_portset_np(mach_port_t portset); | |
55e303ae | 302 | __END_DECLS |
91447636 A |
303 | #endif /* PRIVATE */ |
304 | ||
305 | #endif /* KERNEL */ | |
55e303ae | 306 | |
55e303ae A |
307 | |
308 | #endif /* !_SYS_EVENT_H_ */ |