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