2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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.
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
50 * $FreeBSD: src/sys/sys/event.h,v 1.5.2.5 2001/12/14 19:21:22 jlemon Exp $
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 */
66 #define EVFILT_SYSCOUNT 9
69 uintptr_t ident
; /* identifier for this event */
70 short filter
; /* filter for event */
74 void *udata
; /* opaque user data identifier */
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); \
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) */
94 #define EV_ONESHOT 0x0010 /* only report one occurrence */
95 #define EV_CLEAR 0x0020 /* clear event state after reporting */
97 #define EV_SYSFLAGS 0xF000 /* reserved by system */
98 #define EV_FLAG1 0x2000 /* filter-specific flag */
100 /* returned values */
101 #define EV_EOF 0x8000 /* EOF detected */
102 #define EV_ERROR 0x4000 /* error, data contains errno */
105 * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace
107 #define NOTE_LOWAT 0x0001 /* low water mark */
110 * data/hint flags for EVFILT_VNODE, shared with userspace
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 */
121 * data/hint flags for EVFILT_PROC, shared with userspace
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 */
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 */
135 #ifdef KERNEL_PRIVATE
137 #include <sys/queue.h>
139 #ifdef MALLOC_DECLARE
140 MALLOC_DECLARE(M_KQUEUE
);
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)
147 #define NOTE_SIGNAL 0x08000000
150 /* JMM - line these up with wait_queue_link */
152 struct wait_queue_link kn_wql
; /* wait queue linkage */
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 */
160 TAILQ_ENTRY(knote
) kn_tqe
; /* ...ready to process */
162 struct file
*p_fp
; /* file data pointer */
163 struct proc
*p_proc
; /* proc pointer */
165 struct filterops
*kn_fop
;
167 int kn_sfflags
; /* saved filter flags */
168 struct kevent kn_kevent
;
169 intptr_t kn_sdata
; /* saved data field */
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 */
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
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
));
193 SLIST_HEAD(klist
, knote
);
194 extern void klist_init(struct klist
*list
);
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)
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
);
209 #else /* !KERNEL_PRIVATE */
212 * This is currently visible to userland to work around broken
213 * programs which pull in <sys/proc.h> or <sys/select.h>.
215 #include <sys/queue.h>
217 SLIST_HEAD(klist
, knote
);
219 #include <sys/cdefs.h>
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
));
229 #include <sys/appleapiopts.h>
231 #ifdef __APPLE_API_PRIVATE
232 #include <mach/mach.h>
235 mach_port_t kqueue_portset_np
__P((int kq
));
236 int kqueue_from_portset_np
__P((mach_port_t portset
));
238 #endif /* __APPLE_API_PRIVATE */
240 #endif /* !KERNEL_PRIVATE */
242 #endif /* !_SYS_EVENT_H_ */