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