]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/event.h
xnu-792.6.61.tar.gz
[apple/xnu.git] / bsd / sys / event.h
CommitLineData
55e303ae 1/*
91447636 2 * Copyright (c) 2003-2005 Apple Computer, Inc. All rights reserved.
55e303ae
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
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 *
37839358
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,
37839358
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
91447636
A
53#include <machine/types.h>
54#include <sys/cdefs.h>
55#include <stdint.h>
56
55e303ae
A
57#define EVFILT_READ (-1)
58#define EVFILT_WRITE (-2)
59#define EVFILT_AIO (-3) /* attached to aio requests */
60#define EVFILT_VNODE (-4) /* attached to vnodes */
61#define EVFILT_PROC (-5) /* attached to struct proc */
62#define EVFILT_SIGNAL (-6) /* attached to struct proc */
63#define EVFILT_TIMER (-7) /* timers */
64#define EVFILT_MACHPORT (-8) /* Mach ports */
65#define EVFILT_FS (-9) /* Filesystem events */
66
67#define EVFILT_SYSCOUNT 9
91447636
A
68#define EVFILT_THREADMARKER EVFILT_SYSCOUNT /* Internal use only */
69
70#if __DARWIN_ALIGN_POWER
71#pragma options align=power
72#endif
55e303ae
A
73
74struct kevent {
75 uintptr_t ident; /* identifier for this event */
76 short filter; /* filter for event */
91447636
A
77 unsigned short flags; /* general flags */
78 unsigned int fflags; /* filter-specific flags */
79 intptr_t data; /* filter-specific data */
80#ifdef KERNEL_PRIVATE
81 user_addr_t udata; /* opaque user data identifier */
82#else
55e303ae 83 void *udata; /* opaque user data identifier */
91447636
A
84#endif
85};
86
87#ifdef KERNEL_PRIVATE
88
89struct user_kevent {
90 uint64_t ident; /* identifier for this event */
91 short filter; /* filter for event */
92 unsigned short flags; /* general flags */
93 unsigned int fflags; /* filter-specific flags */
94 int64_t data; /* filter-specific data */
95 user_addr_t udata; /* opaque user data identifier */
55e303ae
A
96};
97
91447636
A
98#endif
99
100#if __DARWIN_ALIGN_POWER
101#pragma options align=reset
102#endif
103
55e303ae
A
104#define EV_SET(kevp, a, b, c, d, e, f) do { \
105 struct kevent *__kevp__ = (kevp); \
106 __kevp__->ident = (a); \
107 __kevp__->filter = (b); \
108 __kevp__->flags = (c); \
109 __kevp__->fflags = (d); \
110 __kevp__->data = (e); \
111 __kevp__->udata = (f); \
112} while(0)
113
114/* actions */
115#define EV_ADD 0x0001 /* add event to kq (implies enable) */
116#define EV_DELETE 0x0002 /* delete event from kq */
117#define EV_ENABLE 0x0004 /* enable event */
118#define EV_DISABLE 0x0008 /* disable event (not reported) */
119
120/* flags */
121#define EV_ONESHOT 0x0010 /* only report one occurrence */
122#define EV_CLEAR 0x0020 /* clear event state after reporting */
123
124#define EV_SYSFLAGS 0xF000 /* reserved by system */
91447636 125#define EV_FLAG0 0x1000 /* filter-specific flag */
55e303ae
A
126#define EV_FLAG1 0x2000 /* filter-specific flag */
127
128/* returned values */
129#define EV_EOF 0x8000 /* EOF detected */
130#define EV_ERROR 0x4000 /* error, data contains errno */
131
132/*
91447636
A
133 * Filter specific flags for EVFILT_READ
134 *
135 * The default behavior for EVFILT_READ is to make the "read" determination
136 * relative to the current file descriptor read pointer. The EV_POLL
137 * flag indicates the determination should be made via poll(2) semantics
138 * (which always returns true for regular files - regardless of the amount
139 * of unread data in the file).
140 *
141 * On input, EV_OOBAND specifies that only OOB data should be looked for.
142 * The returned data count is the number of bytes beyond the current OOB marker.
143 *
144 * On output, EV_OOBAND indicates that OOB data is present
145 * If it was not specified as an input parameter, then the data count is the
146 * number of bytes before the current OOB marker. If at the marker, the
147 * data count indicates the number of bytes available after it. In either
148 * case, it's the amount of data one could expect to receive next.
55e303ae 149 */
91447636
A
150#define EV_POLL EV_FLAG0
151#define EV_OOBAND EV_FLAG1
55e303ae
A
152
153/*
91447636
A
154 * data/hint fflags for EVFILT_{READ|WRITE}, shared with userspace
155 *
156 * The default behavior for EVFILT_READ is to make the determination
157 * realtive to the current file descriptor read pointer.
158 */
159#define NOTE_LOWAT 0x00000001 /* low water mark */
160/*
161 * data/hint fflags for EVFILT_VNODE, shared with userspace
55e303ae 162 */
91447636
A
163#define NOTE_DELETE 0x00000001 /* vnode was removed */
164#define NOTE_WRITE 0x00000002 /* data contents changed */
165#define NOTE_EXTEND 0x00000004 /* size increased */
166#define NOTE_ATTRIB 0x00000008 /* attributes changed */
167#define NOTE_LINK 0x00000010 /* link count changed */
168#define NOTE_RENAME 0x00000020 /* vnode was renamed */
169#define NOTE_REVOKE 0x00000040 /* vnode access was revoked */
55e303ae
A
170
171/*
91447636 172 * data/hint fflags for EVFILT_PROC, shared with userspace
55e303ae
A
173 */
174#define NOTE_EXIT 0x80000000 /* process exited */
175#define NOTE_FORK 0x40000000 /* process forked */
176#define NOTE_EXEC 0x20000000 /* process exec'd */
177#define NOTE_PCTRLMASK 0xf0000000 /* mask for hint bits */
178#define NOTE_PDATAMASK 0x000fffff /* mask for pid */
179
91447636
A
180/*
181 * data/hint fflags for EVFILT_TIMER, shared with userspace.
182 * The default is a (repeating) interval timer with the data
183 * specifying the timeout interval in milliseconds.
184 *
185 * All timeouts are implicitly EV_CLEAR events.
186 */
187#define NOTE_SECONDS 0x00000001 /* data is seconds */
188#define NOTE_USECONDS 0x00000002 /* data is microseconds */
189#define NOTE_NSECONDS 0x00000004 /* data is nanoseconds */
190#define NOTE_ABSOLUTE 0x00000008 /* absolute timeout */
191 /* ... implicit EV_ONESHOT */
192
55e303ae
A
193/* additional flags for EVFILT_PROC */
194#define NOTE_TRACK 0x00000001 /* follow across forks */
195#define NOTE_TRACKERR 0x00000002 /* could not track child */
196#define NOTE_CHILD 0x00000004 /* am a child process */
197
198
55e303ae 199
91447636
A
200#ifndef KERNEL
201/* Temporay solution for BootX to use inode.h till kqueue moves to vfs layer */
202#include <sys/queue.h>
203struct knote;
204SLIST_HEAD(klist, knote);
205#endif
206
207#ifdef KERNEL
208
209#ifdef KERNEL_PRIVATE
55e303ae
A
210#include <sys/queue.h>
211
212#ifdef MALLOC_DECLARE
213MALLOC_DECLARE(M_KQUEUE);
214#endif
215
216/*
217 * Flag indicating hint is a signal. Used by EVFILT_SIGNAL, and also
218 * shared by EVFILT_PROC (all knotes attached to p->p_klist)
219 */
220#define NOTE_SIGNAL 0x08000000
221
91447636
A
222TAILQ_HEAD(kqtailq, knote); /* a list of "queued" events */
223
55e303ae 224struct knote {
91447636
A
225 int kn_inuse; /* inuse count */
226 struct kqtailq *kn_tq; /* pointer to tail queue */
227 TAILQ_ENTRY(knote) kn_tqe; /* linkage for tail queue */
228 struct kqueue *kn_kq; /* which kqueue we are on */
229 SLIST_ENTRY(knote) kn_link; /* linkage for search list */
55e303ae 230 SLIST_ENTRY(knote) kn_selnext; /* klist element chain */
55e303ae 231 union {
91447636 232 struct fileproc *p_fp; /* file data pointer */
55e303ae
A
233 struct proc *p_proc; /* proc pointer */
234 } kn_ptr;
235 struct filterops *kn_fop;
91447636 236 int kn_status; /* status bits */
55e303ae
A
237 int kn_sfflags; /* saved filter flags */
238 struct kevent kn_kevent;
55e303ae 239 caddr_t kn_hook;
91447636
A
240 int kn_hookid;
241 int64_t kn_sdata; /* saved data field */
242
55e303ae
A
243#define KN_ACTIVE 0x01 /* event has been triggered */
244#define KN_QUEUED 0x02 /* event is on queue */
245#define KN_DISABLED 0x04 /* event is disabled */
91447636
A
246#define KN_DROPPING 0x08 /* knote is being dropped */
247#define KN_USEWAIT 0x10 /* wait for knote use */
248#define KN_DROPWAIT 0x20 /* wait for knote drop */
55e303ae
A
249
250#define kn_id kn_kevent.ident
251#define kn_filter kn_kevent.filter
252#define kn_flags kn_kevent.flags
253#define kn_fflags kn_kevent.fflags
254#define kn_data kn_kevent.data
255#define kn_fp kn_ptr.p_fp
256};
257
258struct filterops {
259 int f_isfd; /* true if ident == filedescriptor */
91447636
A
260 int (*f_attach)(struct knote *kn);
261 void (*f_detach)(struct knote *kn);
262 int (*f_event)(struct knote *kn, long hint);
55e303ae
A
263};
264
265struct proc;
266
267SLIST_HEAD(klist, knote);
268extern void klist_init(struct klist *list);
269
270#define KNOTE(list, hint) knote(list, hint)
271#define KNOTE_ATTACH(list, kn) knote_attach(list, kn)
272#define KNOTE_DETACH(list, kn) knote_detach(list, kn)
273
274
275extern void knote(struct klist *list, long hint);
276extern int knote_attach(struct klist *list, struct knote *kn);
277extern int knote_detach(struct klist *list, struct knote *kn);
55e303ae 278extern void knote_fdclose(struct proc *p, int fd);
55e303ae 279
91447636
A
280#endif /* !KERNEL_PRIVATE */
281
282#else /* KERNEL */
55e303ae 283
55e303ae 284
55e303ae
A
285struct timespec;
286
287__BEGIN_DECLS
91447636
A
288int kqueue(void);
289int kevent(int kq, const struct kevent *changelist, int nchanges,
55e303ae 290 struct kevent *eventlist, int nevents,
91447636 291 const struct timespec *timeout);
55e303ae
A
292__END_DECLS
293
55e303ae 294
91447636
A
295#ifdef PRIVATE
296#include <mach/port.h>
55e303ae
A
297
298__BEGIN_DECLS
91447636
A
299mach_port_t kqueue_portset_np(int kq);
300int kqueue_from_portset_np(mach_port_t portset);
55e303ae 301__END_DECLS
91447636
A
302#endif /* PRIVATE */
303
304#endif /* KERNEL */
55e303ae 305
55e303ae
A
306
307#endif /* !_SYS_EVENT_H_ */