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