]>
Commit | Line | Data |
---|---|---|
55e303ae A |
1 | /* |
2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. | |
7 | * | |
8 | * This file contains Original Code and/or Modifications of Original Code | |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
22 | * | |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /*- | |
26 | * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org> | |
27 | * All rights reserved. | |
28 | * | |
29 | * Redistribution and use in source and binary forms, with or without | |
30 | * modification, are permitted provided that the following conditions | |
31 | * are met: | |
32 | * 1. Redistributions of source code must retain the above copyright | |
33 | * notice, this list of conditions and the following disclaimer. | |
34 | * 2. Redistributions in binary form must reproduce the above copyright | |
35 | * notice, this list of conditions and the following disclaimer in the | |
36 | * documentation and/or other materials provided with the distribution. | |
37 | * | |
38 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
39 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
40 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
41 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
42 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
43 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
44 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
46 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
47 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
48 | * SUCH DAMAGE. | |
49 | * | |
50 | * $FreeBSD: src/sys/sys/event.h,v 1.5.2.5 2001/12/14 19:21:22 jlemon Exp $ | |
51 | */ | |
52 | ||
53 | #ifndef _SYS_EVENT_H_ | |
54 | #define _SYS_EVENT_H_ | |
55 | ||
56 | #define EVFILT_READ (-1) | |
57 | #define EVFILT_WRITE (-2) | |
58 | #define EVFILT_AIO (-3) /* attached to aio requests */ | |
59 | #define EVFILT_VNODE (-4) /* attached to vnodes */ | |
60 | #define EVFILT_PROC (-5) /* attached to struct proc */ | |
61 | #define EVFILT_SIGNAL (-6) /* attached to struct proc */ | |
62 | #define EVFILT_TIMER (-7) /* timers */ | |
63 | #define EVFILT_MACHPORT (-8) /* Mach ports */ | |
64 | #define EVFILT_FS (-9) /* Filesystem events */ | |
65 | ||
66 | #define EVFILT_SYSCOUNT 9 | |
67 | ||
68 | struct kevent { | |
69 | uintptr_t ident; /* identifier for this event */ | |
70 | short filter; /* filter for event */ | |
71 | u_short flags; | |
72 | u_int fflags; | |
73 | intptr_t data; | |
74 | void *udata; /* opaque user data identifier */ | |
75 | }; | |
76 | ||
77 | #define EV_SET(kevp, a, b, c, d, e, f) do { \ | |
78 | struct kevent *__kevp__ = (kevp); \ | |
79 | __kevp__->ident = (a); \ | |
80 | __kevp__->filter = (b); \ | |
81 | __kevp__->flags = (c); \ | |
82 | __kevp__->fflags = (d); \ | |
83 | __kevp__->data = (e); \ | |
84 | __kevp__->udata = (f); \ | |
85 | } while(0) | |
86 | ||
87 | /* actions */ | |
88 | #define EV_ADD 0x0001 /* add event to kq (implies enable) */ | |
89 | #define EV_DELETE 0x0002 /* delete event from kq */ | |
90 | #define EV_ENABLE 0x0004 /* enable event */ | |
91 | #define EV_DISABLE 0x0008 /* disable event (not reported) */ | |
92 | ||
93 | /* flags */ | |
94 | #define EV_ONESHOT 0x0010 /* only report one occurrence */ | |
95 | #define EV_CLEAR 0x0020 /* clear event state after reporting */ | |
96 | ||
97 | #define EV_SYSFLAGS 0xF000 /* reserved by system */ | |
98 | #define EV_FLAG1 0x2000 /* filter-specific flag */ | |
99 | ||
100 | /* returned values */ | |
101 | #define EV_EOF 0x8000 /* EOF detected */ | |
102 | #define EV_ERROR 0x4000 /* error, data contains errno */ | |
103 | ||
104 | /* | |
105 | * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace | |
106 | */ | |
107 | #define NOTE_LOWAT 0x0001 /* low water mark */ | |
108 | ||
109 | /* | |
110 | * data/hint flags for EVFILT_VNODE, shared with userspace | |
111 | */ | |
112 | #define NOTE_DELETE 0x0001 /* vnode was removed */ | |
113 | #define NOTE_WRITE 0x0002 /* data contents changed */ | |
114 | #define NOTE_EXTEND 0x0004 /* size increased */ | |
115 | #define NOTE_ATTRIB 0x0008 /* attributes changed */ | |
116 | #define NOTE_LINK 0x0010 /* link count changed */ | |
117 | #define NOTE_RENAME 0x0020 /* vnode was renamed */ | |
118 | #define NOTE_REVOKE 0x0040 /* vnode access was revoked */ | |
119 | ||
120 | /* | |
121 | * data/hint flags for EVFILT_PROC, shared with userspace | |
122 | */ | |
123 | #define NOTE_EXIT 0x80000000 /* process exited */ | |
124 | #define NOTE_FORK 0x40000000 /* process forked */ | |
125 | #define NOTE_EXEC 0x20000000 /* process exec'd */ | |
126 | #define NOTE_PCTRLMASK 0xf0000000 /* mask for hint bits */ | |
127 | #define NOTE_PDATAMASK 0x000fffff /* mask for pid */ | |
128 | ||
129 | /* additional flags for EVFILT_PROC */ | |
130 | #define NOTE_TRACK 0x00000001 /* follow across forks */ | |
131 | #define NOTE_TRACKERR 0x00000002 /* could not track child */ | |
132 | #define NOTE_CHILD 0x00000004 /* am a child process */ | |
133 | ||
134 | ||
135 | #ifdef KERNEL_PRIVATE | |
136 | ||
137 | #include <sys/queue.h> | |
138 | ||
139 | #ifdef MALLOC_DECLARE | |
140 | MALLOC_DECLARE(M_KQUEUE); | |
141 | #endif | |
142 | ||
143 | /* | |
144 | * Flag indicating hint is a signal. Used by EVFILT_SIGNAL, and also | |
145 | * shared by EVFILT_PROC (all knotes attached to p->p_klist) | |
146 | */ | |
147 | #define NOTE_SIGNAL 0x08000000 | |
148 | ||
149 | struct knote { | |
150 | /* JMM - line these up with wait_queue_link */ | |
151 | #if 0 | |
152 | struct wait_queue_link kn_wql; /* wait queue linkage */ | |
153 | #else | |
154 | SLIST_ENTRY(knote) kn_selnext; /* klist element chain */ | |
155 | void *kn_type; /* knote vs. thread */ | |
156 | struct klist *kn_list; /* pointer to list we are on */ | |
157 | SLIST_ENTRY(knote) kn_link; /* members of kqueue */ | |
158 | struct kqueue *kn_kq; /* which kqueue we are on */ | |
159 | #endif | |
160 | TAILQ_ENTRY(knote) kn_tqe; /* ...ready to process */ | |
161 | union { | |
162 | struct file *p_fp; /* file data pointer */ | |
163 | struct proc *p_proc; /* proc pointer */ | |
164 | } kn_ptr; | |
165 | struct filterops *kn_fop; | |
166 | int kn_status; | |
167 | int kn_sfflags; /* saved filter flags */ | |
168 | struct kevent kn_kevent; | |
169 | intptr_t kn_sdata; /* saved data field */ | |
170 | caddr_t kn_hook; | |
171 | #define KN_ACTIVE 0x01 /* event has been triggered */ | |
172 | #define KN_QUEUED 0x02 /* event is on queue */ | |
173 | #define KN_DISABLED 0x04 /* event is disabled */ | |
174 | #define KN_DETACHED 0x08 /* knote is detached */ | |
175 | ||
176 | #define kn_id kn_kevent.ident | |
177 | #define kn_filter kn_kevent.filter | |
178 | #define kn_flags kn_kevent.flags | |
179 | #define kn_fflags kn_kevent.fflags | |
180 | #define kn_data kn_kevent.data | |
181 | #define kn_fp kn_ptr.p_fp | |
182 | }; | |
183 | ||
184 | struct filterops { | |
185 | int f_isfd; /* true if ident == filedescriptor */ | |
186 | int (*f_attach) __P((struct knote *kn)); | |
187 | void (*f_detach) __P((struct knote *kn)); | |
188 | int (*f_event) __P((struct knote *kn, long hint)); | |
189 | }; | |
190 | ||
191 | struct proc; | |
192 | ||
193 | SLIST_HEAD(klist, knote); | |
194 | extern void klist_init(struct klist *list); | |
195 | ||
196 | #define KNOTE(list, hint) knote(list, hint) | |
197 | #define KNOTE_ATTACH(list, kn) knote_attach(list, kn) | |
198 | #define KNOTE_DETACH(list, kn) knote_detach(list, kn) | |
199 | ||
200 | ||
201 | extern void knote(struct klist *list, long hint); | |
202 | extern int knote_attach(struct klist *list, struct knote *kn); | |
203 | extern int knote_detach(struct klist *list, struct knote *kn); | |
204 | extern void knote_remove(struct proc *p, struct klist *list); | |
205 | extern void knote_fdclose(struct proc *p, int fd); | |
206 | extern int kqueue_register(struct kqueue *kq, | |
207 | struct kevent *kev, struct proc *p); | |
208 | ||
209 | #else /* !KERNEL_PRIVATE */ | |
210 | ||
211 | /* | |
212 | * This is currently visible to userland to work around broken | |
213 | * programs which pull in <sys/proc.h> or <sys/select.h>. | |
214 | */ | |
215 | #include <sys/queue.h> | |
216 | struct knote; | |
217 | SLIST_HEAD(klist, knote); | |
218 | ||
219 | #include <sys/cdefs.h> | |
220 | struct timespec; | |
221 | ||
222 | __BEGIN_DECLS | |
223 | int kqueue __P((void)); | |
224 | int kevent __P((int kq, const struct kevent *changelist, int nchanges, | |
225 | struct kevent *eventlist, int nevents, | |
226 | const struct timespec *timeout)); | |
227 | __END_DECLS | |
228 | ||
229 | #include <sys/appleapiopts.h> | |
230 | ||
231 | #ifdef __APPLE_API_PRIVATE | |
232 | #include <mach/mach.h> | |
233 | ||
234 | __BEGIN_DECLS | |
235 | mach_port_t kqueue_portset_np __P((int kq)); | |
236 | int kqueue_from_portset_np __P((mach_port_t portset)); | |
237 | __END_DECLS | |
238 | #endif /* __APPLE_API_PRIVATE */ | |
239 | ||
240 | #endif /* !KERNEL_PRIVATE */ | |
241 | ||
242 | #endif /* !_SYS_EVENT_H_ */ |