]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/sys/event.h
xnu-1504.9.37.tar.gz
[apple/xnu.git] / bsd / sys / event.h
... / ...
CommitLineData
1/*
2 * Copyright (c) 2003-2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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
59#include <machine/types.h>
60#include <sys/cdefs.h>
61#include <stdint.h>
62
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 portsets */
71#define EVFILT_FS (-9) /* Filesystem events */
72#define EVFILT_USER (-10) /* User events */
73#define EVFILT_SESSION (-11) /* Audit session events */
74
75#define EVFILT_SYSCOUNT 11
76#define EVFILT_THREADMARKER EVFILT_SYSCOUNT /* Internal use only */
77
78#pragma pack(4)
79
80struct kevent {
81 uintptr_t ident; /* identifier for this event */
82 int16_t filter; /* filter for event */
83 uint16_t flags; /* general flags */
84 uint32_t fflags; /* filter-specific flags */
85 intptr_t data; /* filter-specific data */
86 void *udata; /* opaque user data identifier */
87};
88
89#ifdef KERNEL_PRIVATE
90
91struct user64_kevent {
92 uint64_t ident; /* identifier for this event */
93 int16_t filter; /* filter for event */
94 uint16_t flags; /* general flags */
95 uint32_t fflags; /* filter-specific flags */
96 int64_t data; /* filter-specific data */
97 user_addr_t udata; /* opaque user data identifier */
98};
99
100struct user32_kevent {
101 uint32_t ident; /* identifier for this event */
102 int16_t filter; /* filter for event */
103 uint16_t flags; /* general flags */
104 uint32_t fflags; /* filter-specific flags */
105 int32_t data; /* filter-specific data */
106 user32_addr_t udata; /* opaque user data identifier */
107};
108
109#endif
110
111#pragma pack()
112
113struct kevent64_s {
114 uint64_t ident; /* identifier for this event */
115 int16_t filter; /* filter for event */
116 uint16_t flags; /* general flags */
117 uint32_t fflags; /* filter-specific flags */
118 int64_t data; /* filter-specific data */
119 uint64_t udata; /* opaque user data identifier */
120 uint64_t ext[2]; /* filter-specific extensions */
121};
122
123#define EV_SET(kevp, a, b, c, d, e, f) do { \
124 struct kevent *__kevp__ = (kevp); \
125 __kevp__->ident = (a); \
126 __kevp__->filter = (b); \
127 __kevp__->flags = (c); \
128 __kevp__->fflags = (d); \
129 __kevp__->data = (e); \
130 __kevp__->udata = (f); \
131} while(0)
132
133#define EV_SET64(kevp, a, b, c, d, e, f, g, h) do { \
134 struct kevent64_s *__kevp__ = (kevp); \
135 __kevp__->ident = (a); \
136 __kevp__->filter = (b); \
137 __kevp__->flags = (c); \
138 __kevp__->fflags = (d); \
139 __kevp__->data = (e); \
140 __kevp__->udata = (f); \
141 __kevp__->ext[0] = (g); \
142 __kevp__->ext[1] = (h); \
143} while(0)
144
145/* actions */
146#define EV_ADD 0x0001 /* add event to kq (implies enable) */
147#define EV_DELETE 0x0002 /* delete event from kq */
148#define EV_ENABLE 0x0004 /* enable event */
149#define EV_DISABLE 0x0008 /* disable event (not reported) */
150#define EV_RECEIPT 0x0040 /* force EV_ERROR on success, data == 0 */
151
152/* flags */
153#define EV_ONESHOT 0x0010 /* only report one occurrence */
154#define EV_CLEAR 0x0020 /* clear event state after reporting */
155#define EV_DISPATCH 0x0080 /* disable event after reporting */
156
157#define EV_SYSFLAGS 0xF000 /* reserved by system */
158#define EV_FLAG0 0x1000 /* filter-specific flag */
159#define EV_FLAG1 0x2000 /* filter-specific flag */
160
161/* returned values */
162#define EV_EOF 0x8000 /* EOF detected */
163#define EV_ERROR 0x4000 /* error, data contains errno */
164
165/*
166 * Filter specific flags for EVFILT_READ
167 *
168 * The default behavior for EVFILT_READ is to make the "read" determination
169 * relative to the current file descriptor read pointer. The EV_POLL
170 * flag indicates the determination should be made via poll(2) semantics
171 * (which always returns true for regular files - regardless of the amount
172 * of unread data in the file).
173 *
174 * On input, EV_OOBAND specifies that only OOB data should be looked for.
175 * The returned data count is the number of bytes beyond the current OOB marker.
176 *
177 * On output, EV_OOBAND indicates that OOB data is present
178 * If it was not specified as an input parameter, then the data count is the
179 * number of bytes before the current OOB marker. If at the marker, the
180 * data count indicates the number of bytes available after it. In either
181 * case, it's the amount of data one could expect to receive next.
182 */
183#define EV_POLL EV_FLAG0
184#define EV_OOBAND EV_FLAG1
185
186/*
187 * data/hint fflags for EVFILT_USER, shared with userspace
188 */
189
190/*
191 * On input, NOTE_TRIGGER causes the event to be triggered for output.
192 */
193#define NOTE_TRIGGER 0x01000000
194#define EV_TRIGGER 0x0100 /*deprecated--for backwards compatibility only*/
195
196/*
197 * On input, the top two bits of fflags specifies how the lower twenty four
198 * bits should be applied to the stored value of fflags.
199 *
200 * On output, the top two bits will always be set to NOTE_FFNOP and the
201 * remaining twenty four bits will contain the stored fflags value.
202 */
203#define NOTE_FFNOP 0x00000000 /* ignore input fflags */
204#define NOTE_FFAND 0x40000000 /* and fflags */
205#define NOTE_FFOR 0x80000000 /* or fflags */
206#define NOTE_FFCOPY 0xc0000000 /* copy fflags */
207#define NOTE_FFCTRLMASK 0xc0000000 /* mask for operations */
208#define NOTE_FFLAGSMASK 0x00ffffff
209
210/*
211 * data/hint fflags for EVFILT_{READ|WRITE}, shared with userspace
212 *
213 * The default behavior for EVFILT_READ is to make the determination
214 * realtive to the current file descriptor read pointer.
215 */
216#define NOTE_LOWAT 0x00000001 /* low water mark */
217/*
218 * data/hint fflags for EVFILT_VNODE, shared with userspace
219 */
220#define NOTE_DELETE 0x00000001 /* vnode was removed */
221#define NOTE_WRITE 0x00000002 /* data contents changed */
222#define NOTE_EXTEND 0x00000004 /* size increased */
223#define NOTE_ATTRIB 0x00000008 /* attributes changed */
224#define NOTE_LINK 0x00000010 /* link count changed */
225#define NOTE_RENAME 0x00000020 /* vnode was renamed */
226#define NOTE_REVOKE 0x00000040 /* vnode access was revoked */
227#define NOTE_NONE 0x00000080 /* No specific vnode event: to test for EVFILT_READ activation*/
228
229/*
230 * data/hint fflags for EVFILT_PROC, shared with userspace
231 *
232 * Please note that EVFILT_PROC and EVFILT_SIGNAL share the same knote list
233 * that hangs off the proc structure. They also both play games with the hint
234 * passed to KNOTE(). If NOTE_SIGNAL is passed as a hint, then the lower bits
235 * of the hint contain the signal. IF NOTE_FORK is passed, then the lower bits
236 * contain the PID of the child.
237 */
238#define NOTE_EXIT 0x80000000 /* process exited */
239#define NOTE_FORK 0x40000000 /* process forked */
240#define NOTE_EXEC 0x20000000 /* process exec'd */
241#define NOTE_REAP 0x10000000 /* process reaped */
242#define NOTE_SIGNAL 0x08000000 /* shared with EVFILT_SIGNAL */
243#define NOTE_PDATAMASK 0x000fffff /* mask for pid/signal */
244#define NOTE_PCTRLMASK (~NOTE_PDATAMASK)
245
246/*
247 * data/hint fflags for EVFILT_TIMER, shared with userspace.
248 * The default is a (repeating) interval timer with the data
249 * specifying the timeout interval in milliseconds.
250 *
251 * All timeouts are implicitly EV_CLEAR events.
252 */
253#define NOTE_SECONDS 0x00000001 /* data is seconds */
254#define NOTE_USECONDS 0x00000002 /* data is microseconds */
255#define NOTE_NSECONDS 0x00000004 /* data is nanoseconds */
256#define NOTE_ABSOLUTE 0x00000008 /* absolute timeout */
257 /* ... implicit EV_ONESHOT */
258/*
259 * data/hint fflags for EVFILT_MACHPORT, shared with userspace.
260 *
261 * Only portsets are support at this time.
262 *
263 * The fflags field can optionally contain the MACH_RCV_MSG, MACH_RCV_LARGE,
264 * and related trailer receive options as defined in <mach/message.h>.
265 * The presence of these flags directs the kevent64() call to attempt to receive
266 * the message during kevent delivery, rather than just indicate that a message exists.
267 * On setup, The ext[0] field contains the receive buffer pointer and ext[1] contains
268 * the receive buffer length. Upon event delivery, the actual received message size
269 * is returned in ext[1]. As with mach_msg(), the buffer must be large enough to
270 * receive the message and the requested (or default) message trailers. In addition,
271 * the fflags field contains the return code normally returned by mach_msg().
272 *
273 * If no message receipt options were provided in the fflags field on setup, no
274 * message is received by this call. Instead, on output, the data field simply
275 * contains the name of the actual port detected with a message waiting.
276 */
277
278/*
279 * data/hint fflags for EVFILT_SESSION, shared with userspace.
280 *
281 * The kevent ident field should be set to AU_SESSION_ANY_ASID if interested
282 * in events for any session.
283 *
284 * NOTE_AS_UPDATE may be going away since struct auditinfo_addr may become
285 * immutable once initially set.
286 */
287#define NOTE_AS_START 0x00000001 /* start of new session */
288#define NOTE_AS_END 0x00000002 /* start of new session */
289#define NOTE_AS_ERR 0x00000004 /* error tracking new session */
290#define NOTE_AS_CLOSE 0x00000008 /* currently unsupported */
291#define NOTE_AS_UPDATE 0x00000010 /* session data updated */
292
293/*
294 * Kevent ident value for any session.
295 */
296#define AS_ANY_ASID 0xFFFFFFFF
297
298struct au_sentry; /* Audit session entry */
299
300
301/*
302 * DEPRECATED!!!!!!!!!
303 * NOTE_TRACK, NOTE_TRACKERR, and NOTE_CHILD are no longer supported as of 10.5
304 */
305/* additional flags for EVFILT_PROC */
306#define NOTE_TRACK 0x00000001 /* follow across forks */
307#define NOTE_TRACKERR 0x00000002 /* could not track child */
308#define NOTE_CHILD 0x00000004 /* am a child process */
309
310
311
312#ifndef KERNEL
313/* Temporay solution for BootX to use inode.h till kqueue moves to vfs layer */
314#include <sys/queue.h>
315struct knote;
316SLIST_HEAD(klist, knote);
317#endif
318
319#ifdef KERNEL
320
321#ifdef KERNEL_PRIVATE
322#include <sys/queue.h>
323
324#ifdef MALLOC_DECLARE
325MALLOC_DECLARE(M_KQUEUE);
326#endif
327
328TAILQ_HEAD(kqtailq, knote); /* a list of "queued" events */
329
330struct knote {
331 int kn_inuse; /* inuse count */
332 struct kqtailq *kn_tq; /* pointer to tail queue */
333 TAILQ_ENTRY(knote) kn_tqe; /* linkage for tail queue */
334 struct kqueue *kn_kq; /* which kqueue we are on */
335 SLIST_ENTRY(knote) kn_link; /* linkage for search list */
336 SLIST_ENTRY(knote) kn_selnext; /* klist element chain */
337 union {
338 struct fileproc *p_fp; /* file data pointer */
339 struct proc *p_proc; /* proc pointer */
340 struct ipc_pset *p_pset; /* pset pointer */
341 struct au_sentry *p_se; /* Audit session ptr */
342 } kn_ptr;
343 struct filterops *kn_fop;
344 int kn_status; /* status bits */
345 int kn_sfflags; /* saved filter flags */
346 struct kevent64_s kn_kevent;
347 void *kn_hook;
348 int kn_hookid;
349 int64_t kn_sdata; /* saved data field */
350
351#define KN_ACTIVE 0x01 /* event has been triggered */
352#define KN_QUEUED 0x02 /* event is on queue */
353#define KN_DISABLED 0x04 /* event is disabled */
354#define KN_DROPPING 0x08 /* knote is being dropped */
355#define KN_USEWAIT 0x10 /* wait for knote use */
356#define KN_ATTACHING 0x20 /* event is pending attach */
357#define KN_STAYQUEUED 0x40 /* force event to stay on queue */
358
359#define kn_id kn_kevent.ident
360#define kn_filter kn_kevent.filter
361#define kn_flags kn_kevent.flags
362#define kn_fflags kn_kevent.fflags
363#define kn_data kn_kevent.data
364#define kn_udata kn_kevent.udata
365#define kn_ext kn_kevent.ext
366#define kn_fp kn_ptr.p_fp
367};
368
369/* Hint values for f_touch filter operation */
370#define EVENT_REGISTER 1
371#define EVENT_PROCESS 2
372
373struct filterops {
374 int f_isfd; /* true if ident == filedescriptor */
375 int (*f_attach)(struct knote *kn);
376 void (*f_detach)(struct knote *kn);
377 int (*f_event)(struct knote *kn, long hint);
378 /* Optional f_touch operation, called only if !f_isfd && non-NULL */
379 void (*f_touch)(struct knote *kn, struct kevent64_s *kev, long type);
380 /* Optional f_peek operation, called only if KN_STAYQUEUED is set */
381 int (*f_peek)(struct knote *kn);
382};
383
384struct proc;
385struct wait_queue;
386
387SLIST_HEAD(klist, knote);
388extern void knote_init(void) __attribute__((section("__TEXT, initcode")));
389extern void klist_init(struct klist *list);
390
391#define KNOTE(list, hint) knote(list, hint)
392#define KNOTE_ATTACH(list, kn) knote_attach(list, kn)
393#define KNOTE_DETACH(list, kn) knote_detach(list, kn)
394
395
396extern void knote(struct klist *list, long hint);
397extern int knote_attach(struct klist *list, struct knote *kn);
398extern int knote_detach(struct klist *list, struct knote *kn);
399extern int knote_link_wait_queue(struct knote *kn, struct wait_queue *wq);
400extern void knote_unlink_wait_queue(struct knote *kn, struct wait_queue *wq);
401extern void knote_fdclose(struct proc *p, int fd);
402
403#endif /* !KERNEL_PRIVATE */
404
405#else /* KERNEL */
406
407
408struct timespec;
409
410__BEGIN_DECLS
411int kqueue(void);
412int kevent(int kq, const struct kevent *changelist, int nchanges,
413 struct kevent *eventlist, int nevents,
414 const struct timespec *timeout);
415int kevent64(int kq, const struct kevent64_s *changelist,
416 int nchanges, struct kevent64_s *eventlist,
417 int nevents, unsigned int flags,
418 const struct timespec *timeout);
419__END_DECLS
420
421
422#endif /* KERNEL */
423
424
425#endif /* !_SYS_EVENT_H_ */