2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
24 * All rights reserved.
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
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.
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
47 * $FreeBSD: src/sys/sys/event.h,v 1.5.2.5 2001/12/14 19:21:22 jlemon Exp $
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 */
63 #define EVFILT_SYSCOUNT 9
66 uintptr_t ident
; /* identifier for this event */
67 short filter
; /* filter for event */
71 void *udata
; /* opaque user data identifier */
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); \
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) */
91 #define EV_ONESHOT 0x0010 /* only report one occurrence */
92 #define EV_CLEAR 0x0020 /* clear event state after reporting */
94 #define EV_SYSFLAGS 0xF000 /* reserved by system */
95 #define EV_FLAG1 0x2000 /* filter-specific flag */
98 #define EV_EOF 0x8000 /* EOF detected */
99 #define EV_ERROR 0x4000 /* error, data contains errno */
102 * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace
104 #define NOTE_LOWAT 0x0001 /* low water mark */
107 * data/hint flags for EVFILT_VNODE, shared with userspace
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 */
118 * data/hint flags for EVFILT_PROC, shared with userspace
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 */
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 */
132 #ifdef KERNEL_PRIVATE
134 #include <sys/queue.h>
136 #ifdef MALLOC_DECLARE
137 MALLOC_DECLARE(M_KQUEUE
);
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)
144 #define NOTE_SIGNAL 0x08000000
147 /* JMM - line these up with wait_queue_link */
149 struct wait_queue_link kn_wql
; /* wait queue linkage */
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 */
157 TAILQ_ENTRY(knote
) kn_tqe
; /* ...ready to process */
159 struct file
*p_fp
; /* file data pointer */
160 struct proc
*p_proc
; /* proc pointer */
162 struct filterops
*kn_fop
;
164 int kn_sfflags
; /* saved filter flags */
165 struct kevent kn_kevent
;
166 intptr_t kn_sdata
; /* saved data field */
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 */
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
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
));
190 SLIST_HEAD(klist
, knote
);
191 extern void klist_init(struct klist
*list
);
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)
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
);
206 #else /* !KERNEL_PRIVATE */
209 * This is currently visible to userland to work around broken
210 * programs which pull in <sys/proc.h> or <sys/select.h>.
212 #include <sys/queue.h>
214 SLIST_HEAD(klist
, knote
);
216 #include <sys/cdefs.h>
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
));
226 #include <sys/appleapiopts.h>
228 #ifdef __APPLE_API_PRIVATE
229 #include <mach/mach.h>
232 mach_port_t kqueue_portset_np
__P((int kq
));
233 int kqueue_from_portset_np
__P((mach_port_t portset
));
235 #endif /* __APPLE_API_PRIVATE */
237 #endif /* !KERNEL_PRIVATE */
239 #endif /* !_SYS_EVENT_H_ */