]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/event.h
xnu-4570.1.46.tar.gz
[apple/xnu.git] / bsd / sys / event.h
1 /*
2 * Copyright (c) 2003-2017 Apple 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 /*
64 * Filter types
65 */
66 #define EVFILT_READ (-1)
67 #define EVFILT_WRITE (-2)
68 #define EVFILT_AIO (-3) /* attached to aio requests */
69 #define EVFILT_VNODE (-4) /* attached to vnodes */
70 #define EVFILT_PROC (-5) /* attached to struct proc */
71 #define EVFILT_SIGNAL (-6) /* attached to struct proc */
72 #define EVFILT_TIMER (-7) /* timers */
73 #define EVFILT_MACHPORT (-8) /* Mach portsets */
74 #define EVFILT_FS (-9) /* Filesystem events */
75 #define EVFILT_USER (-10) /* User events */
76 /* (-11) unused */
77 #define EVFILT_VM (-12) /* Virtual memory events */
78
79 #ifdef PRIVATE
80 #define EVFILT_SOCK (-13) /* Socket events */
81 #define EVFILT_MEMORYSTATUS (-14) /* Memorystatus events */
82 #endif /* PRIVATE */
83 #define EVFILT_EXCEPT (-15) /* Exception events */
84 #ifdef PRIVATE
85 #define EVFILT_WORKLOOP (-17) /* Workloop events */
86 #endif /* PRIVATE */
87
88 #define EVFILT_SYSCOUNT 17
89 #define EVFILT_THREADMARKER EVFILT_SYSCOUNT /* Internal use only */
90
91 #pragma pack(4)
92
93 struct kevent {
94 uintptr_t ident; /* identifier for this event */
95 int16_t filter; /* filter for event */
96 uint16_t flags; /* general flags */
97 uint32_t fflags; /* filter-specific flags */
98 intptr_t data; /* filter-specific data */
99 void *udata; /* opaque user data identifier */
100 };
101
102 #ifdef KERNEL_PRIVATE
103
104 struct user64_kevent {
105 uint64_t ident; /* identifier for this event */
106 int16_t filter; /* filter for event */
107 uint16_t flags; /* general flags */
108 uint32_t fflags; /* filter-specific flags */
109 int64_t data; /* filter-specific data */
110 user_addr_t udata; /* opaque user data identifier */
111 };
112
113 struct user32_kevent {
114 uint32_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 int32_t data; /* filter-specific data */
119 user32_addr_t udata; /* opaque user data identifier */
120 };
121
122 struct kevent_internal_s {
123 uint64_t ident; /* identifier for this event */
124 int16_t filter; /* filter for event */
125 uint16_t flags; /* general flags */
126 int32_t qos; /* quality of service */
127 uint32_t fflags; /* filter-specific flags */
128 // uint32_t xflags; /* extra filter-specific flags */
129 int64_t data; /* filter-specific data */
130 uint64_t udata; /* opaque user data identifier */
131 uint64_t ext[4]; /* filter-specific extensions */
132 };
133
134 #endif /* KERNEL_PRIVATE */
135
136 #pragma pack()
137
138 struct kevent64_s {
139 uint64_t ident; /* identifier for this event */
140 int16_t filter; /* filter for event */
141 uint16_t flags; /* general flags */
142 uint32_t fflags; /* filter-specific flags */
143 int64_t data; /* filter-specific data */
144 uint64_t udata; /* opaque user data identifier */
145 uint64_t ext[2]; /* filter-specific extensions */
146 };
147
148 #ifdef PRIVATE
149 struct kevent_qos_s {
150 uint64_t ident; /* identifier for this event */
151 int16_t filter; /* filter for event */
152 uint16_t flags; /* general flags */
153 int32_t qos; /* quality of service */
154 uint64_t udata; /* opaque user data identifier */
155 uint32_t fflags; /* filter-specific flags */
156 uint32_t xflags; /* extra filter-specific flags */
157 int64_t data; /* filter-specific data */
158 uint64_t ext[4]; /* filter-specific extensions */
159 };
160
161 /*
162 * Type definition for names/ids of dynamically allocated kqueues.
163 */
164 typedef uint64_t kqueue_id_t;
165
166 #endif /* PRIVATE */
167
168 #define EV_SET(kevp, a, b, c, d, e, f) do { \
169 struct kevent *__kevp__ = (kevp); \
170 __kevp__->ident = (a); \
171 __kevp__->filter = (b); \
172 __kevp__->flags = (c); \
173 __kevp__->fflags = (d); \
174 __kevp__->data = (e); \
175 __kevp__->udata = (f); \
176 } while(0)
177
178 #define EV_SET64(kevp, a, b, c, d, e, f, g, h) do { \
179 struct kevent64_s *__kevp__ = (kevp); \
180 __kevp__->ident = (a); \
181 __kevp__->filter = (b); \
182 __kevp__->flags = (c); \
183 __kevp__->fflags = (d); \
184 __kevp__->data = (e); \
185 __kevp__->udata = (f); \
186 __kevp__->ext[0] = (g); \
187 __kevp__->ext[1] = (h); \
188 } while(0)
189
190
191 /* kevent system call flags */
192 #define KEVENT_FLAG_NONE 0x000 /* no flag value */
193 #define KEVENT_FLAG_IMMEDIATE 0x001 /* immediate timeout */
194 #define KEVENT_FLAG_ERROR_EVENTS 0x002 /* output events only include change errors */
195
196 #ifdef PRIVATE
197
198 /*
199 * Rather than provide an EV_SET_QOS macro for kevent_qos_t structure
200 * initialization, we encourage use of named field initialization support
201 * instead.
202 */
203
204 #define KEVENT_FLAG_STACK_EVENTS 0x004 /* output events treated as stack (grows down) */
205 #define KEVENT_FLAG_STACK_DATA 0x008 /* output data allocated as stack (grows down) */
206 #define KEVENT_FLAG_UNBIND_CHECK_FLAGS 0x010 /* check the flags passed to kevent_qos_internal_unbind */
207 #define KEVENT_FLAG_WORKQ 0x020 /* interact with the default workq kq */
208 #define KEVENT_FLAG_WORKQ_MANAGER 0x200 /* current thread is the workq manager */
209 #define KEVENT_FLAG_WORKLOOP 0x400 /* interact with the specified workloop kq */
210 #define KEVENT_FLAG_SYNCHRONOUS_BIND 0x800 /* synchronous bind callback */
211
212 #define KEVENT_FLAG_WORKLOOP_SERVICER_ATTACH 0x8000 /* attach current thread to workloop */
213 #define KEVENT_FLAG_WORKLOOP_SERVICER_DETACH 0x10000 /* unbind current thread from workloop */
214 #define KEVENT_FLAG_DYNAMIC_KQ_MUST_EXIST 0x20000 /* kq lookup by id must exist */
215 #define KEVENT_FLAG_DYNAMIC_KQ_MUST_NOT_EXIST 0x40000 /* kq lookup by id must not exist */
216 #define KEVENT_FLAG_WORKLOOP_NO_WQ_THREAD 0x80000 /* do not create workqueue threads for this worloop */
217
218 #ifdef XNU_KERNEL_PRIVATE
219
220 #define KEVENT_FLAG_LEGACY32 0x040 /* event data in legacy 32-bit format */
221 #define KEVENT_FLAG_LEGACY64 0x080 /* event data in legacy 64-bit format */
222 #define KEVENT_FLAG_KERNEL 0x1000 /* caller is in-kernel */
223 #define KEVENT_FLAG_DYNAMIC_KQUEUE 0x2000 /* kqueue is dynamically allocated */
224 #define KEVENT_FLAG_WORKLOOP_CANCELED 0x4000 /* workloop bind was cancelled */
225
226 #define KEVENT_FLAG_USER (KEVENT_FLAG_IMMEDIATE | KEVENT_FLAG_ERROR_EVENTS | \
227 KEVENT_FLAG_STACK_EVENTS | KEVENT_FLAG_STACK_DATA | \
228 KEVENT_FLAG_WORKQ | KEVENT_FLAG_WORKLOOP | \
229 KEVENT_FLAG_WORKLOOP_SERVICER_ATTACH | KEVENT_FLAG_WORKLOOP_SERVICER_DETACH | \
230 KEVENT_FLAG_DYNAMIC_KQ_MUST_EXIST | KEVENT_FLAG_DYNAMIC_KQ_MUST_NOT_EXIST | \
231 KEVENT_FLAG_WORKLOOP_NO_WQ_THREAD)
232
233 /*
234 * Since some filter ops are not part of the standard sysfilt_ops, we use
235 * kn_filtid starting from EVFILT_SYSCOUNT to identify these cases. This is to
236 * let kn_fops() get the correct fops for all cases.
237 */
238 #define EVFILTID_KQREAD (EVFILT_SYSCOUNT)
239 #define EVFILTID_PIPE_R (EVFILT_SYSCOUNT + 1)
240 #define EVFILTID_PIPE_W (EVFILT_SYSCOUNT + 2)
241 #define EVFILTID_PTSD (EVFILT_SYSCOUNT + 3)
242 #define EVFILTID_SOREAD (EVFILT_SYSCOUNT + 4)
243 #define EVFILTID_SOWRITE (EVFILT_SYSCOUNT + 5)
244 #define EVFILTID_SCK (EVFILT_SYSCOUNT + 6)
245 #define EVFILTID_SOEXCEPT (EVFILT_SYSCOUNT + 7)
246 #define EVFILTID_SPEC (EVFILT_SYSCOUNT + 8)
247 #define EVFILTID_BPFREAD (EVFILT_SYSCOUNT + 9)
248 #define EVFILTID_NECP_FD (EVFILT_SYSCOUNT + 10)
249 #define EVFILTID_FSEVENT (EVFILT_SYSCOUNT + 13)
250 #define EVFILTID_VN (EVFILT_SYSCOUNT + 14)
251 #define EVFILTID_TTY (EVFILT_SYSCOUNT + 16)
252
253 #define EVFILTID_MAX (EVFILT_SYSCOUNT + 17)
254
255 #endif /* defined(XNU_KERNEL_PRIVATE) */
256
257 #define EV_SET_QOS 0
258
259 #endif /* PRIVATE */
260
261 /* actions */
262 #define EV_ADD 0x0001 /* add event to kq (implies enable) */
263 #define EV_DELETE 0x0002 /* delete event from kq */
264 #define EV_ENABLE 0x0004 /* enable event */
265 #define EV_DISABLE 0x0008 /* disable event (not reported) */
266
267 /* flags */
268 #define EV_ONESHOT 0x0010 /* only report one occurrence */
269 #define EV_CLEAR 0x0020 /* clear event state after reporting */
270 #define EV_RECEIPT 0x0040 /* force immediate event output */
271 /* ... with or without EV_ERROR */
272 /* ... use KEVENT_FLAG_ERROR_EVENTS */
273 /* on syscalls supporting flags */
274
275 #define EV_DISPATCH 0x0080 /* disable event after reporting */
276 #define EV_UDATA_SPECIFIC 0x0100 /* unique kevent per udata value */
277
278 #define EV_DISPATCH2 (EV_DISPATCH | EV_UDATA_SPECIFIC)
279 /* ... in combination with EV_DELETE */
280 /* will defer delete until udata-specific */
281 /* event enabled. EINPROGRESS will be */
282 /* returned to indicate the deferral */
283
284 #define EV_VANISHED 0x0200 /* report that source has vanished */
285 /* ... only valid with EV_DISPATCH2 */
286
287 #define EV_SYSFLAGS 0xF000 /* reserved by system */
288 #define EV_FLAG0 0x1000 /* filter-specific flag */
289 #define EV_FLAG1 0x2000 /* filter-specific flag */
290
291 /* returned values */
292 #define EV_EOF 0x8000 /* EOF detected */
293 #define EV_ERROR 0x4000 /* error, data contains errno */
294
295 /*
296 * Filter specific flags for EVFILT_READ
297 *
298 * The default behavior for EVFILT_READ is to make the "read" determination
299 * relative to the current file descriptor read pointer.
300 *
301 * The EV_POLL flag indicates the determination should be made via poll(2)
302 * semantics. These semantics dictate always returning true for regular files,
303 * regardless of the amount of unread data in the file.
304 *
305 * On input, EV_OOBAND specifies that filter should actively return in the
306 * presence of OOB on the descriptor. It implies that filter will return
307 * if there is OOB data available to read OR when any other condition
308 * for the read are met (for example number of bytes regular data becomes >=
309 * low-watermark).
310 * If EV_OOBAND is not set on input, it implies that the filter should not actively
311 * return for out of band data on the descriptor. The filter will then only return
312 * when some other condition for read is met (ex: when number of regular data bytes
313 * >=low-watermark OR when socket can't receive more data (SS_CANTRCVMORE)).
314 *
315 * On output, EV_OOBAND indicates the presence of OOB data on the descriptor.
316 * If it was not specified as an input parameter, then the data count is the
317 * number of bytes before the current OOB marker, else data count is the number
318 * of bytes beyond OOB marker.
319 */
320 #define EV_POLL EV_FLAG0
321 #define EV_OOBAND EV_FLAG1
322
323 /*
324 * data/hint fflags for EVFILT_USER, shared with userspace
325 */
326
327 /*
328 * On input, NOTE_TRIGGER causes the event to be triggered for output.
329 */
330 #define NOTE_TRIGGER 0x01000000
331
332 /*
333 * On input, the top two bits of fflags specifies how the lower twenty four
334 * bits should be applied to the stored value of fflags.
335 *
336 * On output, the top two bits will always be set to NOTE_FFNOP and the
337 * remaining twenty four bits will contain the stored fflags value.
338 */
339 #define NOTE_FFNOP 0x00000000 /* ignore input fflags */
340 #define NOTE_FFAND 0x40000000 /* and fflags */
341 #define NOTE_FFOR 0x80000000 /* or fflags */
342 #define NOTE_FFCOPY 0xc0000000 /* copy fflags */
343 #define NOTE_FFCTRLMASK 0xc0000000 /* mask for operations */
344 #define NOTE_FFLAGSMASK 0x00ffffff
345
346 #ifdef PRIVATE
347 /*
348 * data/hint fflags for EVFILT_WORKLOOP, shared with userspace
349 *
350 * The ident for thread requests should be the dynamic ID of the workloop
351 * The ident for each sync waiter must be unique to that waiter [for this workloop]
352 *
353 *
354 * Commands:
355 *
356 * @const NOTE_WL_THREAD_REQUEST [in/out]
357 * The kevent represents asynchronous userspace work and its associated QoS.
358 * There can only be a single knote with this flag set per workloop.
359 *
360 * @const NOTE_WL_SYNC_WAIT [in/out]
361 * This bit is set when the caller is waiting to become the owner of a workloop.
362 * If the NOTE_WL_SYNC_WAKE bit is already set then the caller is not blocked,
363 * else it blocks until it is set.
364 *
365 * The QoS field of the knote is used to push on other owners or servicers.
366 *
367 * @const NOTE_WL_SYNC_WAKE [in/out]
368 * Marks the waiter knote as being eligible to become an owner
369 * This bit can only be set once, trying it again will fail with EALREADY.
370 *
371 *
372 * Flags/Modifiers:
373 *
374 * @const NOTE_WL_UPDATE_QOS [in] (only NOTE_WL_THREAD_REQUEST)
375 * For successful updates (EV_ADD only), learn the new userspace async QoS from
376 * the kevent qos field.
377 *
378 * @const NOTE_WL_END_OWNERSHIP [in]
379 * If the update is successful (including deletions) or returns ESTALE, and
380 * the caller thread or the "suspended" thread is currently owning the workloop,
381 * then ownership is forgotten.
382 *
383 * @const NOTE_WL_DISCOVER_OWNER [in]
384 * If the update is successful (including deletions), learn the owner identity
385 * from the loaded value during debounce. This requires an address to have been
386 * filled in the EV_EXTIDX_WL_ADDR ext field, but doesn't require a mask to have
387 * been set in the EV_EXTIDX_WL_MASK.
388 *
389 * @const NOTE_WL_IGNORE_ESTALE [in]
390 * If the operation would fail with ESTALE, mask the error and pretend the
391 * update was successful. However the operation itself didn't happen, meaning
392 * that:
393 * - attaching a new knote will not happen
394 * - dropping an existing knote will not happen
395 * - NOTE_WL_UPDATE_QOS or NOTE_WL_DISCOVER_OWNER will have no effect
396 *
397 * This modifier doesn't affect NOTE_WL_END_OWNERSHIP.
398 */
399 #define NOTE_WL_THREAD_REQUEST 0x00000001
400 #define NOTE_WL_SYNC_WAIT 0x00000004
401 #define NOTE_WL_SYNC_WAKE 0x00000008
402 #define NOTE_WL_COMMANDS_MASK 0x0000000f /* Mask of all the [in] commands above */
403
404 #define NOTE_WL_UPDATE_QOS 0x00000010
405 #define NOTE_WL_END_OWNERSHIP 0x00000020
406 #define NOTE_WL_UPDATE_OWNER 0 /* ... compatibility define ... */
407 #define NOTE_WL_DISCOVER_OWNER 0x00000080
408 #define NOTE_WL_IGNORE_ESTALE 0x00000100
409 #define NOTE_WL_UPDATES_MASK 0x000001f0 /* Mask of all the [in] updates above */
410
411 /*
412 * EVFILT_WORKLOOP ext[] array indexes/meanings.
413 */
414 #define EV_EXTIDX_WL_LANE 0 /* lane identifier [in: sync waiter]
415 [out: thread request] */
416 #define EV_EXTIDX_WL_ADDR 1 /* debounce address [in: NULL==no debounce] */
417 #define EV_EXTIDX_WL_MASK 2 /* debounce mask [in] */
418 #define EV_EXTIDX_WL_VALUE 3 /* debounce value [in: not current->ESTALE]
419 [out: new/debounce value] */
420 #endif /* PRIVATE */
421
422 /*
423 * data/hint fflags for EVFILT_{READ|WRITE}, shared with userspace
424 *
425 * The default behavior for EVFILT_READ is to make the determination
426 * realtive to the current file descriptor read pointer.
427 */
428 #define NOTE_LOWAT 0x00000001 /* low water mark */
429
430 /* data/hint flags for EVFILT_EXCEPT, shared with userspace */
431 #define NOTE_OOB 0x00000002 /* OOB data */
432
433 /*
434 * data/hint fflags for EVFILT_VNODE, shared with userspace
435 */
436 #define NOTE_DELETE 0x00000001 /* vnode was removed */
437 #define NOTE_WRITE 0x00000002 /* data contents changed */
438 #define NOTE_EXTEND 0x00000004 /* size increased */
439 #define NOTE_ATTRIB 0x00000008 /* attributes changed */
440 #define NOTE_LINK 0x00000010 /* link count changed */
441 #define NOTE_RENAME 0x00000020 /* vnode was renamed */
442 #define NOTE_REVOKE 0x00000040 /* vnode access was revoked */
443 #define NOTE_NONE 0x00000080 /* No specific vnode event: to test for EVFILT_READ activation*/
444 #define NOTE_FUNLOCK 0x00000100 /* vnode was unlocked by flock(2) */
445
446 /*
447 * data/hint fflags for EVFILT_PROC, shared with userspace
448 *
449 * Please note that EVFILT_PROC and EVFILT_SIGNAL share the same knote list
450 * that hangs off the proc structure. They also both play games with the hint
451 * passed to KNOTE(). If NOTE_SIGNAL is passed as a hint, then the lower bits
452 * of the hint contain the signal. IF NOTE_FORK is passed, then the lower bits
453 * contain the PID of the child (but the pid does not get passed through in
454 * the actual kevent).
455 */
456 enum {
457 eNoteReapDeprecated __deprecated_enum_msg("This kqueue(2) EVFILT_PROC flag is deprecated") = 0x10000000
458 };
459
460 #define NOTE_EXIT 0x80000000 /* process exited */
461 #define NOTE_FORK 0x40000000 /* process forked */
462 #define NOTE_EXEC 0x20000000 /* process exec'd */
463 #define NOTE_REAP ((unsigned int)eNoteReapDeprecated /* 0x10000000 */) /* process reaped */
464 #define NOTE_SIGNAL 0x08000000 /* shared with EVFILT_SIGNAL */
465 #define NOTE_EXITSTATUS 0x04000000 /* exit status to be returned, valid for child process only */
466 #define NOTE_EXIT_DETAIL 0x02000000 /* provide details on reasons for exit */
467
468 #define NOTE_PDATAMASK 0x000fffff /* mask for signal & exit status */
469 #define NOTE_PCTRLMASK (~NOTE_PDATAMASK)
470
471 /*
472 * If NOTE_EXITSTATUS is present, provide additional info about exiting process.
473 */
474 enum {
475 eNoteExitReparentedDeprecated __deprecated_enum_msg("This kqueue(2) EVFILT_PROC flag is no longer sent") = 0x00080000
476 };
477 #define NOTE_EXIT_REPARENTED ((unsigned int)eNoteExitReparentedDeprecated) /* exited while reparented */
478
479 /*
480 * If NOTE_EXIT_DETAIL is present, these bits indicate specific reasons for exiting.
481 */
482 #define NOTE_EXIT_DETAIL_MASK 0x00070000
483 #define NOTE_EXIT_DECRYPTFAIL 0x00010000
484 #define NOTE_EXIT_MEMORY 0x00020000
485 #define NOTE_EXIT_CSERROR 0x00040000
486
487 #ifdef PRIVATE
488
489 /*
490 * If NOTE_EXIT_MEMORY is present, these bits indicate specific jetsam condition.
491 */
492 #define NOTE_EXIT_MEMORY_DETAIL_MASK 0xfe000000
493 #define NOTE_EXIT_MEMORY_VMPAGESHORTAGE 0x80000000 /* jetsam condition: lowest jetsam priority proc killed due to vm page shortage */
494 #define NOTE_EXIT_MEMORY_VMTHRASHING 0x40000000 /* jetsam condition: lowest jetsam priority proc killed due to vm thrashing */
495 #define NOTE_EXIT_MEMORY_HIWAT 0x20000000 /* jetsam condition: process reached its high water mark */
496 #define NOTE_EXIT_MEMORY_PID 0x10000000 /* jetsam condition: special pid kill requested */
497 #define NOTE_EXIT_MEMORY_IDLE 0x08000000 /* jetsam condition: idle process cleaned up */
498 #define NOTE_EXIT_MEMORY_VNODE 0X04000000 /* jetsam condition: virtual node kill */
499 #define NOTE_EXIT_MEMORY_FCTHRASHING 0x02000000 /* jetsam condition: lowest jetsam priority proc killed due to filecache thrashing */
500
501 #endif
502
503 /*
504 * data/hint fflags for EVFILT_VM, shared with userspace.
505 */
506 #define NOTE_VM_PRESSURE 0x80000000 /* will react on memory pressure */
507 #define NOTE_VM_PRESSURE_TERMINATE 0x40000000 /* will quit on memory pressure, possibly after cleaning up dirty state */
508 #define NOTE_VM_PRESSURE_SUDDEN_TERMINATE 0x20000000 /* will quit immediately on memory pressure */
509 #define NOTE_VM_ERROR 0x10000000 /* there was an error */
510
511 #ifdef PRIVATE
512
513 /*
514 * data/hint fflags for EVFILT_MEMORYSTATUS, shared with userspace.
515 */
516 #define NOTE_MEMORYSTATUS_PRESSURE_NORMAL 0x00000001 /* system memory pressure has returned to normal */
517 #define NOTE_MEMORYSTATUS_PRESSURE_WARN 0x00000002 /* system memory pressure has changed to the warning state */
518 #define NOTE_MEMORYSTATUS_PRESSURE_CRITICAL 0x00000004 /* system memory pressure has changed to the critical state */
519 #define NOTE_MEMORYSTATUS_LOW_SWAP 0x00000008 /* system is in a low-swap state */
520 #define NOTE_MEMORYSTATUS_PROC_LIMIT_WARN 0x00000010 /* process memory limit has hit a warning state */
521 #define NOTE_MEMORYSTATUS_PROC_LIMIT_CRITICAL 0x00000020 /* process memory limit has hit a critical state - soft limit */
522 #define NOTE_MEMORYSTATUS_MSL_STATUS 0xf0000000 /* bits used to request change to process MSL status */
523
524 #ifdef KERNEL_PRIVATE
525 /*
526 * data/hint fflags for EVFILT_MEMORYSTATUS, but not shared with userspace.
527 */
528 #define NOTE_MEMORYSTATUS_PROC_LIMIT_WARN_ACTIVE 0x00000040 /* Used to restrict sending a warn event only once, per active limit, soft limits only */
529 #define NOTE_MEMORYSTATUS_PROC_LIMIT_WARN_INACTIVE 0x00000080 /* Used to restrict sending a warn event only once, per inactive limit, soft limit only */
530 #define NOTE_MEMORYSTATUS_PROC_LIMIT_CRITICAL_ACTIVE 0x00000100 /* Used to restrict sending a critical event only once per active limit, soft limit only */
531 #define NOTE_MEMORYSTATUS_PROC_LIMIT_CRITICAL_INACTIVE 0x00000200 /* Used to restrict sending a critical event only once per inactive limit, soft limit only */
532
533 /*
534 * Use this mask to protect the kernel private flags.
535 */
536 #define EVFILT_MEMORYSTATUS_ALL_MASK \
537 (NOTE_MEMORYSTATUS_PRESSURE_NORMAL | NOTE_MEMORYSTATUS_PRESSURE_WARN | NOTE_MEMORYSTATUS_PRESSURE_CRITICAL | NOTE_MEMORYSTATUS_LOW_SWAP | \
538 NOTE_MEMORYSTATUS_PROC_LIMIT_WARN | NOTE_MEMORYSTATUS_PROC_LIMIT_CRITICAL | NOTE_MEMORYSTATUS_MSL_STATUS)
539
540 #endif /* KERNEL_PRIVATE */
541
542 typedef enum vm_pressure_level {
543 kVMPressureNormal = 0,
544 kVMPressureWarning = 1,
545 kVMPressureUrgent = 2,
546 kVMPressureCritical = 3,
547 } vm_pressure_level_t;
548
549 #endif /* PRIVATE */
550
551 /*
552 * data/hint fflags for EVFILT_TIMER, shared with userspace.
553 * The default is a (repeating) interval timer with the data
554 * specifying the timeout interval in milliseconds.
555 *
556 * All timeouts are implicitly EV_CLEAR events.
557 */
558 #define NOTE_SECONDS 0x00000001 /* data is seconds */
559 #define NOTE_USECONDS 0x00000002 /* data is microseconds */
560 #define NOTE_NSECONDS 0x00000004 /* data is nanoseconds */
561 #define NOTE_ABSOLUTE 0x00000008 /* absolute timeout */
562 /* ... implicit EV_ONESHOT, timeout uses the gettimeofday epoch */
563 #define NOTE_LEEWAY 0x00000010 /* ext[1] holds leeway for power aware timers */
564 #define NOTE_CRITICAL 0x00000020 /* system does minimal timer coalescing */
565 #define NOTE_BACKGROUND 0x00000040 /* system does maximum timer coalescing */
566 #define NOTE_MACH_CONTINUOUS_TIME 0x00000080
567 /*
568 * NOTE_MACH_CONTINUOUS_TIME:
569 * with NOTE_ABSOLUTE: causes the timer to continue to tick across sleep,
570 * still uses gettimeofday epoch
571 * with NOTE_MACHTIME and NOTE_ABSOLUTE: uses mach continuous time epoch
572 * without NOTE_ABSOLUTE (interval timer mode): continues to tick across sleep
573 */
574 #define NOTE_MACHTIME 0x00000100 /* data is mach absolute time units */
575 /* timeout uses the mach absolute time epoch */
576
577 #ifdef PRIVATE
578 /*
579 * data/hint fflags for EVFILT_SOCK, shared with userspace.
580 *
581 */
582 #define NOTE_CONNRESET 0x00000001 /* Received RST */
583 #define NOTE_READCLOSED 0x00000002 /* Read side is shutdown */
584 #define NOTE_WRITECLOSED 0x00000004 /* Write side is shutdown */
585 #define NOTE_TIMEOUT 0x00000008 /* timeout: rexmt, keep-alive or persist */
586 #define NOTE_NOSRCADDR 0x00000010 /* source address not available */
587 #define NOTE_IFDENIED 0x00000020 /* interface denied connection */
588 #define NOTE_SUSPEND 0x00000040 /* output queue suspended */
589 #define NOTE_RESUME 0x00000080 /* output queue resumed */
590 #define NOTE_KEEPALIVE 0x00000100 /* TCP Keepalive received */
591 #define NOTE_ADAPTIVE_WTIMO 0x00000200 /* TCP adaptive write timeout */
592 #define NOTE_ADAPTIVE_RTIMO 0x00000400 /* TCP adaptive read timeout */
593 #define NOTE_CONNECTED 0x00000800 /* socket is connected */
594 #define NOTE_DISCONNECTED 0x00001000 /* socket is disconnected */
595 #define NOTE_CONNINFO_UPDATED 0x00002000 /* connection info was updated */
596 #define NOTE_NOTIFY_ACK 0x00004000 /* notify acknowledgement */
597
598 #define EVFILT_SOCK_LEVEL_TRIGGER_MASK \
599 (NOTE_READCLOSED | NOTE_WRITECLOSED | NOTE_SUSPEND | NOTE_RESUME | NOTE_CONNECTED | NOTE_DISCONNECTED)
600
601 #define EVFILT_SOCK_ALL_MASK \
602 (NOTE_CONNRESET | NOTE_READCLOSED | NOTE_WRITECLOSED | NOTE_TIMEOUT | NOTE_NOSRCADDR | NOTE_IFDENIED | NOTE_SUSPEND | NOTE_RESUME | NOTE_KEEPALIVE | NOTE_ADAPTIVE_WTIMO | NOTE_ADAPTIVE_RTIMO | NOTE_CONNECTED | NOTE_DISCONNECTED | NOTE_CONNINFO_UPDATED | NOTE_NOTIFY_ACK)
603
604 #endif /* PRIVATE */
605
606 /*
607 * data/hint fflags for EVFILT_MACHPORT, shared with userspace.
608 *
609 * Only portsets are supported at this time.
610 *
611 * The fflags field can optionally contain the MACH_RCV_MSG, MACH_RCV_LARGE,
612 * and related trailer receive options as defined in <mach/message.h>.
613 * The presence of these flags directs the kevent64() call to attempt to receive
614 * the message during kevent delivery, rather than just indicate that a message exists.
615 * On setup, The ext[0] field contains the receive buffer pointer and ext[1] contains
616 * the receive buffer length. Upon event delivery, the actual received message size
617 * is returned in ext[1]. As with mach_msg(), the buffer must be large enough to
618 * receive the message and the requested (or default) message trailers. In addition,
619 * the fflags field contains the return code normally returned by mach_msg().
620 *
621 * If MACH_RCV_MSG is specified, and the ext[1] field specifies a zero length, the
622 * system call argument specifying an ouput area (kevent_qos) will be consulted. If
623 * the system call specified an output data area, the user-space address
624 * of the received message is carved from that provided output data area (if enough
625 * space remains there). The address and length of each received message is
626 * returned in the ext[0] and ext[1] fields (respectively) of the corresponding kevent.
627 *
628 * IF_MACH_RCV_VOUCHER_CONTENT is specified, the contents of the message voucher is
629 * extracted (as specified in the xflags field) and stored in ext[2] up to ext[3]
630 * length. If the input length is zero, and the system call provided a data area,
631 * the space for the voucher content is carved from the provided space and its
632 * address and length is returned in ext[2] and ext[3] respectively.
633 *
634 * If no message receipt options were provided in the fflags field on setup, no
635 * message is received by this call. Instead, on output, the data field simply
636 * contains the name of the actual port detected with a message waiting.
637 */
638
639 /*
640 * DEPRECATED!!!!!!!!!
641 * NOTE_TRACK, NOTE_TRACKERR, and NOTE_CHILD are no longer supported as of 10.5
642 */
643 /* additional flags for EVFILT_PROC */
644 #define NOTE_TRACK 0x00000001 /* follow across forks */
645 #define NOTE_TRACKERR 0x00000002 /* could not track child */
646 #define NOTE_CHILD 0x00000004 /* am a child process */
647
648
649 #ifdef PRIVATE
650 #endif /* PRIVATE */
651
652 #ifndef KERNEL
653 /* Temporay solution for BootX to use inode.h till kqueue moves to vfs layer */
654 #include <sys/queue.h>
655 struct knote;
656 SLIST_HEAD(klist, knote);
657 #endif
658
659 #ifdef KERNEL
660
661 #ifdef XNU_KERNEL_PRIVATE
662 #include <sys/queue.h>
663 #include <kern/kern_types.h>
664 #include <sys/fcntl.h> /* FREAD, FWRITE */
665 #include <kern/debug.h> /* panic */
666
667 #ifdef MALLOC_DECLARE
668 MALLOC_DECLARE(M_KQUEUE);
669 #endif
670
671 TAILQ_HEAD(kqtailq, knote); /* a list of "queued" events */
672
673 /* Bit size for packed field within knote */
674 #define KNOTE_KQ_BITSIZE 40
675
676
677 /* index into various kq queues */
678 typedef uint8_t kq_index_t;
679 typedef uint16_t kn_status_t;
680
681 #define KN_ACTIVE 0x0001 /* event has been triggered */
682 #define KN_QUEUED 0x0002 /* event is on queue */
683 #define KN_DISABLED 0x0004 /* event is disabled */
684 #define KN_DROPPING 0x0008 /* knote is being dropped */
685 #define KN_USEWAIT 0x0010 /* wait for knote use */
686 #define KN_ATTACHING 0x0020 /* event is pending attach */
687 #define KN_STAYACTIVE 0x0040 /* force event to stay active */
688 #define KN_DEFERDELETE 0x0080 /* defer delete until re-enabled */
689 #define KN_ATTACHED 0x0100 /* currently attached to source */
690 #define KN_DISPATCH 0x0200 /* disables as part of deliver */
691 #define KN_UDATA_SPECIFIC 0x0400 /* udata is part of matching */
692 #define KN_SUPPRESSED 0x0800 /* event is suppressed during delivery */
693 #define KN_STOLENDROP 0x1000 /* someone stole the drop privilege */
694 #define KN_REQVANISH 0x2000 /* requested EV_VANISH */
695 #define KN_VANISHED 0x4000 /* has vanished */
696
697 #define KN_DISPATCH2 (KN_DISPATCH | KN_UDATA_SPECIFIC)
698 /* combination defines deferred-delete mode enabled */
699
700 struct knote {
701 TAILQ_ENTRY(knote) kn_tqe; /* linkage for tail queue */
702 SLIST_ENTRY(knote) kn_link; /* linkage for search list */
703 SLIST_ENTRY(knote) kn_selnext; /* klist element chain */
704 union {
705 struct fileproc *p_fp; /* file data pointer */
706 struct proc *p_proc; /* proc pointer */
707 struct ipc_mqueue *p_mqueue; /* pset pointer */
708 } kn_ptr;
709 uint64_t kn_req_index:3, /* requested qos index */
710 kn_qos_index:3, /* in-use qos index */
711 kn_qos_override:3, /* qos override index */
712 kn_qos_sync_override:3, /* qos sync override index */
713 kn_vnode_kqok:1,
714 kn_vnode_use_ofst:1,
715 kn_qos_override_is_sync:1, /* qos override index is a sync override */
716 kn_reserved:1, /* reserved bits */
717 kn_filtid:8, /* filter id to index filter ops */
718 kn_kq_packed:KNOTE_KQ_BITSIZE; /* packed pointer for kq */
719
720 union {
721 void *kn_hook;
722 uint64_t kn_hook_data;
723 };
724 int64_t kn_sdata; /* saved data field */
725 struct kevent_internal_s kn_kevent;
726 int kn_sfflags; /* saved filter flags */
727 int kn_hookid;
728 uint16_t kn_inuse; /* inuse count */
729 kn_status_t kn_status; /* status bits */
730
731 #define kn_id kn_kevent.ident
732 #define kn_filter kn_kevent.filter
733 #define kn_flags kn_kevent.flags
734 #define kn_qos kn_kevent.qos
735 #define kn_udata kn_kevent.udata
736 #define kn_fflags kn_kevent.fflags
737 #define kn_xflags kn_kevent.xflags
738 #define kn_data kn_kevent.data
739 #define kn_ext kn_kevent.ext
740 #define kn_fp kn_ptr.p_fp
741 };
742
743 static inline struct kqueue *knote_get_kq(struct knote *kn)
744 {
745 if (!(kn->kn_kq_packed))
746 return 0;
747 else
748 return (struct kqueue *)((uintptr_t)(kn->kn_kq_packed) + (uintptr_t)VM_MIN_KERNEL_AND_KEXT_ADDRESS);
749 }
750
751 static inline void knote_set_kq(struct knote *kn, void *kq)
752 {
753 if (!kq)
754 kn->kn_kq_packed = 0;
755 else {
756 uint64_t offset = ((uintptr_t)kq - (uintptr_t)VM_MIN_KERNEL_AND_KEXT_ADDRESS);
757 kn->kn_kq_packed = offset;
758 }
759 }
760
761 static inline int knote_get_seltype(struct knote *kn)
762 {
763 switch (kn->kn_filter) {
764 case EVFILT_READ:
765 return FREAD;
766 case EVFILT_WRITE:
767 return FWRITE;
768 default:
769 panic("%s(%p): invalid filter %d\n",
770 __func__, kn, kn->kn_filter);
771 return 0;
772 }
773 }
774
775 static inline void knote_set_error(struct knote *kn, int error)
776 {
777 kn->kn_flags |= EV_ERROR;
778 kn->kn_data = error;
779 }
780
781 struct filt_process_s {
782 int fp_fd;
783 unsigned int fp_flags;
784 user_addr_t fp_data_out;
785 user_size_t fp_data_size;
786 user_size_t fp_data_resid;
787 };
788 typedef struct filt_process_s *filt_process_data_t;
789
790 /*
791 * Filter operators
792 *
793 * These routines, provided by each filter, are called to attach, detach, deliver events,
794 * change/update filter registration and process/deliver events. They are called with the
795 * with a use-count referenced knote, with the kq unlocked. Here are more details:
796 *
797 * f_isfd -
798 * identifies if the "ident" field in the kevent structure is a file-descriptor.
799 *
800 * If so, the knote is associated with the file descriptor prior to attach and
801 * auto-removed when the file descriptor is closed (this latter behavior may change
802 * for EV_DISPATCH2 kevent types to allow delivery of events identifying unintended
803 * closes).
804 *
805 * Otherwise the knote is hashed by the ident and has no auto-close behavior.
806 *
807 * f_adjusts_qos -
808 * identifies if the filter can adjust its QoS during its lifetime.
809 *
810 * Currently, EVFILT_MAACHPORT is the only filter using this facility.
811 *
812 * f_needs_boost -
813 * [OPTIONAL] used by filters to communicate they need to hold a boost
814 * while holding a usecount on this knote. This is called with the kqlock
815 * held.
816 *
817 * This is only used by EVFILT_WORKLOOP currently.
818 *
819 * f_attach -
820 * called to attach the knote to the underlying object that will be delivering events
821 * through it when EV_ADD is supplied and no existing matching event is found
822 *
823 * provided a knote that is pre-attached to the fd or hashed (see above) but is
824 * specially marked to avoid concurrent access until the attach is complete. The
825 * kevent structure embedded in this knote has been filled in with a sanitized
826 * version of the user-supplied kevent data. However, the user-supplied filter-specific
827 * flags (fflags) and data fields have been moved into the knote's kn_sfflags and kn_sdata
828 * fields respectively. These are usually interpretted as a set of "interest" flags and
829 * data by each filter - to be matched against delivered events.
830 *
831 * The attach operator indicated errors by setting the EV_ERROR flog in the flags field
832 * embedded in the knote's kevent structure - with the specific error indicated in the
833 * corresponding data field.
834 *
835 * The return value indicates if the knote should already be considered "activated" at
836 * the time of attach (one or more of the interest events has already occured).
837 *
838 * f_post_attach -
839 * [OPTIONAL] called after a successful attach, with the kqueue lock held,
840 * returns lock held, may drop and re-acquire
841 *
842 * If this function is non-null, then it indicates that the filter wants
843 * to perform an action after a successful ATTACH of a knote.
844 *
845 * Currently, EVFILT_WORKLOOP is the only filter using this facility.
846 *
847 * The return value indicates an error to report to userland.
848 *
849 *
850 * f_detach -
851 * called to disassociate the knote from the underlying object delivering events
852 * the filter should not attempt to deliver events through this knote after this
853 * operation returns control to the kq system.
854 *
855 * f_event -
856 * if the knote() function (or KNOTE() macro) is called against a list of knotes,
857 * this operator will be called on each knote in the list.
858 *
859 * The "hint" parameter is completely filter-specific, but usually indicates an
860 * event or set of events that have occured against the source object associated
861 * with the list.
862 *
863 * The return value indicates if the knote should already be considered "activated" at
864 * the time of attach (one or more of the interest events has already occured).
865 *
866 * f_drop_and_unlock -
867 * [OPTIONAL] called with the kqueue locked, and has to unlock
868 *
869 * If this function is non-null, then it indicates that the filter
870 * wants to handle EV_DELETE events. This is necessary if a particular
871 * filter needs to synchronize knote deletion with its own filter lock.
872 * Currently, EVFILT_WORKLOOP is the only filter using this facility.
873 *
874 * The return value indicates an error during the knote drop, i.e., the
875 * knote still exists and user space should re-drive the EV_DELETE.
876 *
877 * If the return value is ERESTART, kevent_register() is called from
878 * scratch again (useful to wait for usecounts to drop and then
879 * reevaluate the relevance of that drop)
880 *
881 *
882 * f_process -
883 * called when attempting to deliver triggered events to user-space.
884 *
885 * If the knote was previously activated, this operator will be called when a
886 * thread is trying to deliver events to user-space. The filter gets one last
887 * chance to determine if the event/events are still interesting for this knote
888 * (are the conditions still right to deliver an event). If so, the filter
889 * fills in the output kevent structure with the information to be delivered.
890 *
891 * The input context/data parameter is used during event delivery. Some
892 * filters allow additional data delivery as part of event delivery. This
893 * context field indicates if space was made available for these additional
894 * items and how that space is to be allocated/carved-out.
895 *
896 * The filter may set EV_CLEAR or EV_ONESHOT in the output flags field to indicate
897 * special post-delivery dispositions for the knote.
898 *
899 * EV_CLEAR - indicates that all matching events have been delivered. Even
900 * though there were events to deliver now, there will not be any
901 * more until some additional events are delivered to the knote
902 * via the f_event operator, or the interest set is changed via
903 * the f_touch operator. The knote can remain deactivated after
904 * processing this event delivery.
905 *
906 * EV_ONESHOT - indicates that this is the last event to be delivered via
907 * this knote. It will automatically be deleted upon delivery
908 * (or if in dispatch-mode, upon re-enablement after this delivery).
909 *
910 * The return value indicates if the knote has delivered an output event.
911 * Unless one of the special output flags was set in the output kevent, a non-
912 * zero return value ALSO indicates that the knote should be re-activated
913 * for future event processing (in case it delivers level-based or a multi-edge
914 * type events like message queues that already exist).
915 *
916 * NOTE: In the future, the boolean may change to an enum that allows more
917 * explicit indication of just delivering a current event vs delivering
918 * an event with more events still pending.
919 *
920 * f_touch -
921 * called to update the knote with new state from the user during EVFILT_ADD/ENABLE/DISABLE
922 * on an already-attached knote.
923 *
924 * f_touch should copy relevant new data from the kevent into the knote.
925 * (if KN_UDATA_SPECIFIC is not set, you may need to update the udata too)
926 *
927 * operator must lock against concurrent f_event and f_process operations.
928 *
929 * A return value of 1 indicates that the knote should now be considered 'activated'.
930 *
931 * f_touch can set EV_ERROR with specific error in the data field to return an error to the client.
932 * You should return 1 to indicate that the kevent needs to be activated and processed.
933 *
934 * f_peek -
935 * For knotes marked KN_STAYACTIVE, indicate if the knote is truly active at
936 * the moment (not used for event delivery, but for status checks).
937 */
938
939 struct filterops {
940 bool f_isfd; /* true if ident == filedescriptor */
941 bool f_adjusts_qos; /* true if the filter can override the knote */
942 bool (*f_needs_boost)(struct kevent_internal_s *kev);
943 int (*f_attach)(struct knote *kn, struct kevent_internal_s *kev);
944 int (*f_post_attach)(struct knote *kn, struct kevent_internal_s *kev);
945 void (*f_detach)(struct knote *kn);
946 int (*f_event)(struct knote *kn, long hint);
947 int (*f_touch)(struct knote *kn, struct kevent_internal_s *kev);
948 int (*f_drop_and_unlock)(struct knote *kn, struct kevent_internal_s *kev);
949 int (*f_process)(struct knote *kn, struct filt_process_s *data, struct kevent_internal_s *kev);
950 unsigned (*f_peek)(struct knote *kn);
951 };
952
953 struct proc;
954 struct waitq;
955
956 SLIST_HEAD(klist, knote);
957 extern void knote_init(void);
958 extern void klist_init(struct klist *list);
959
960 #define KNOTE(list, hint) knote(list, hint)
961 #define KNOTE_ATTACH(list, kn) knote_attach(list, kn)
962 #define KNOTE_DETACH(list, kn) knote_detach(list, kn)
963
964 extern void knote(struct klist *list, long hint);
965 extern int knote_attach(struct klist *list, struct knote *kn);
966 extern int knote_detach(struct klist *list, struct knote *kn);
967 extern void knote_vanish(struct klist *list);
968 extern int knote_link_waitq(struct knote *kn, struct waitq *wq, uint64_t *reserved_link);
969 extern int knote_unlink_waitq(struct knote *kn, struct waitq *wq);
970 extern void knote_fdclose(struct proc *p, int fd, int force);
971 extern void knote_markstayactive(struct knote *kn);
972 extern void knote_clearstayactive(struct knote *kn);
973 extern void knote_adjust_qos(struct knote *kn, int qos, int override, kq_index_t sync_override_index);
974 extern void knote_adjust_sync_qos(struct knote *kn, kq_index_t sync_qos, boolean_t lock_kq);
975 extern const struct filterops *knote_fops(struct knote *kn);
976 extern void knote_set_error(struct knote *kn, int error);
977
978 int kevent_exit_on_workloop_ownership_leak(thread_t thread);
979 int kevent_proc_copy_uptrs(void *proc, uint64_t *buf, int bufsize);
980 int kevent_copyout_proc_dynkqids(void *proc, user_addr_t ubuf,
981 uint32_t ubufsize, int32_t *nkqueues_out);
982 int kevent_copyout_dynkqinfo(void *proc, kqueue_id_t kq_id, user_addr_t ubuf,
983 uint32_t ubufsize, int32_t *size_out);
984 int kevent_copyout_dynkqextinfo(void *proc, kqueue_id_t kq_id, user_addr_t ubuf,
985 uint32_t ubufsize, int32_t *nknotes_out);
986
987 #elif defined(KERNEL_PRIVATE) /* !XNU_KERNEL_PRIVATE: kexts still need a klist structure definition */
988
989 #include <sys/queue.h>
990 struct proc;
991 struct knote;
992 SLIST_HEAD(klist, knote);
993
994 #endif /* !XNU_KERNEL_PRIVATE && KERNEL_PRIVATE */
995
996 #ifdef KERNEL_PRIVATE
997 #ifdef PRIVATE
998
999 /* make these private functions available to the pthread kext */
1000 extern int kevent_qos_internal(struct proc *p, int fd,
1001 user_addr_t changelist, int nchanges,
1002 user_addr_t eventlist, int nevents,
1003 user_addr_t data_out, user_size_t *data_available,
1004 unsigned int flags, int32_t *retval);
1005
1006 extern int kevent_qos_internal_bind(struct proc *p,
1007 int qos, thread_t thread, unsigned int flags);
1008 extern int kevent_qos_internal_unbind(struct proc *p,
1009 int qos, thread_t thread, unsigned int flags);
1010
1011 extern int kevent_id_internal(struct proc *p, kqueue_id_t *id,
1012 user_addr_t changelist, int nchanges,
1013 user_addr_t eventlist, int nevents,
1014 user_addr_t data_out, user_size_t *data_available,
1015 unsigned int flags, int32_t *retval);
1016
1017 #endif /* PRIVATE */
1018 #endif /* KERNEL_PRIVATE */
1019
1020 #else /* KERNEL */
1021
1022 #include <sys/types.h>
1023
1024 struct timespec;
1025
1026 __BEGIN_DECLS
1027 int kqueue(void);
1028 int kevent(int kq,
1029 const struct kevent *changelist, int nchanges,
1030 struct kevent *eventlist, int nevents,
1031 const struct timespec *timeout);
1032 int kevent64(int kq,
1033 const struct kevent64_s *changelist, int nchanges,
1034 struct kevent64_s *eventlist, int nevents,
1035 unsigned int flags,
1036 const struct timespec *timeout);
1037
1038 #ifdef PRIVATE
1039 int kevent_qos(int kq,
1040 const struct kevent_qos_s *changelist, int nchanges,
1041 struct kevent_qos_s *eventlist, int nevents,
1042 void *data_out, size_t *data_available,
1043 unsigned int flags);
1044
1045 int kevent_id(kqueue_id_t id,
1046 const struct kevent_qos_s *changelist, int nchanges,
1047 struct kevent_qos_s *eventlist, int nevents,
1048 void *data_out, size_t *data_available,
1049 unsigned int flags);
1050 #endif /* PRIVATE */
1051
1052 __END_DECLS
1053
1054
1055 #endif /* KERNEL */
1056
1057 #ifdef PRIVATE
1058
1059 /* Flags for pending events notified by kernel via return-to-kernel ast */
1060 #define R2K_WORKLOOP_PENDING_EVENTS 0x1
1061 #define R2K_WORKQ_PENDING_EVENTS 0x2
1062
1063 #endif /* PRIVATE */
1064
1065
1066 #endif /* !_SYS_EVENT_H_ */