]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/kdebug.h
xnu-4570.61.1.tar.gz
[apple/xnu.git] / bsd / sys / kdebug.h
1 /*
2 * Copyright (c) 2000-2016 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 /*
30 * kdebug.h - kernel_debug definitions
31 */
32
33 #ifndef BSD_SYS_KDEBUG_H
34 #define BSD_SYS_KDEBUG_H
35
36 #include <sys/appleapiopts.h>
37 #include <sys/cdefs.h>
38
39 __BEGIN_DECLS
40
41 #ifdef __APPLE_API_UNSTABLE
42
43 #include <mach/clock_types.h>
44 #include <stdint.h>
45
46 #ifndef KERNEL
47 #include <Availability.h>
48 #endif
49
50 #ifdef XNU_KERNEL_PRIVATE
51 #include <mach/branch_predicates.h> /* __improbable */
52 #endif
53
54 /*
55 * Kdebug is a facility for tracing events occurring on a system.
56 *
57 * All events are tagged with a 32-bit debugid:
58 *
59 * +----------------+----------------+----------------------------+----+
60 * | Class (8) | Subclass (8) | Code (14) |Func|
61 * | | | |(2) |
62 * +----------------+----------------+----------------------------+----+
63 * \_________________________________/
64 * ClassSubclass (CSC)
65 * \________________________________________________________________00_/
66 * Eventid
67 * \___________________________________________________________________/
68 * Debugid
69 *
70 * The eventid is a hierarchical ID, indicating which components an event is
71 * referring to. The debugid includes an eventid and two function qualifier
72 * bits, to determine the structural significance of an event (whether it
73 * starts or ends an interval).
74 */
75
76 #define KDBG_CLASS_MASK (0xff000000)
77 #define KDBG_CLASS_OFFSET (24)
78 #define KDBG_CLASS_MAX (0xff)
79
80 #define KDBG_SUBCLASS_MASK (0x00ff0000)
81 #define KDBG_SUBCLASS_OFFSET (16)
82 #define KDBG_SUBCLASS_MAX (0xff)
83
84 /* class and subclass mask */
85 #define KDBG_CSC_MASK (0xffff0000)
86 #define KDBG_CSC_OFFSET (KDBG_SUBCLASS_OFFSET)
87 #define KDBG_CSC_MAX (0xffff)
88
89 #define KDBG_CODE_MASK (0x0000fffc)
90 #define KDBG_CODE_OFFSET (2)
91 #define KDBG_CODE_MAX (0x3fff)
92
93 #define KDBG_EVENTID_MASK (0xfffffffc)
94 #define KDBG_FUNC_MASK (0x00000003)
95
96 /* Generate an eventid corresponding to Class, SubClass, and Code. */
97 #define KDBG_EVENTID(Class, SubClass, Code) \
98 ((((Class) & 0xff) << KDBG_CLASS_OFFSET) | \
99 (((SubClass) & 0xff) << KDBG_SUBCLASS_OFFSET) | \
100 (((Code) & 0x3fff) << KDBG_CODE_OFFSET))
101 /* Deprecated macro using old naming convention. */
102 #define KDBG_CODE(Class, SubClass, Code) \
103 KDBG_EVENTID(Class, SubClass, Code)
104
105 /* Extract pieces of the debug code. */
106 #define KDBG_EXTRACT_CLASS(Debugid) \
107 ((uint8_t)(((Debugid) & KDBG_CLASS_MASK) >> KDBG_CLASS_OFFSET))
108 #define KDBG_EXTRACT_SUBCLASS(Debugid) \
109 ((uint8_t)(((Debugid) & KDBG_SUBCLASS_MASK) >> KDBG_SUBCLASS_OFFSET))
110 #define KDBG_EXTRACT_CSC(Debugid) \
111 ((uint16_t)(((Debugid) & KDBG_CSC_MASK) >> KDBG_CSC_OFFSET))
112 #define KDBG_EXTRACT_CODE(Debugid) \
113 ((uint16_t)(((Debugid) & KDBG_CODE_MASK) >> KDBG_CODE_OFFSET))
114
115 /* function qualifiers */
116 #define DBG_FUNC_START 1
117 #define DBG_FUNC_END 2
118 #define DBG_FUNC_NONE 0
119
120 /*
121 * Definitions to support IOP tracing.
122 */
123
124 #ifdef KERNEL_PRIVATE
125
126 typedef enum {
127 /* Trace is now enabled; no arguments. */
128 KD_CALLBACK_KDEBUG_ENABLED,
129 /* Trace is now disabled; no arguments. */
130 KD_CALLBACK_KDEBUG_DISABLED,
131 /*
132 * Request the latest entries from the IOP and block until complete; no
133 * arguments.
134 */
135 KD_CALLBACK_SYNC_FLUSH,
136 /*
137 * The typefilter is enabled; a read-only pointer to the typefilter is
138 * provided, valid only while in the callback.
139 */
140 KD_CALLBACK_TYPEFILTER_CHANGED,
141 } kd_callback_type;
142 typedef void (*kd_callback_fn) (void* context, kd_callback_type reason, void* arg);
143
144 struct kd_callback {
145 kd_callback_fn func;
146 void *context;
147 /* name of IOP, NUL-terminated */
148 char iop_name[8];
149 };
150
151 typedef struct kd_callback kd_callback_t;
152
153 /*
154 * Registers an IOP for participation in tracing.
155 *
156 * The registered callback function will be called with the
157 * supplied context as the first argument, followed by a
158 * kd_callback_type and an associated void* argument.
159 *
160 * The return value is a nonzero coreid that shall be used in
161 * kernel_debug_enter() to refer to your IOP. If the allocation
162 * failed, then 0 will be returned.
163 *
164 * Caveats:
165 * Note that not all callback calls will indicate a change in
166 * state (e.g. disabling trace twice would send two disable
167 * notifications).
168 */
169 extern int kernel_debug_register_callback(kd_callback_t callback);
170
171 extern void kernel_debug_enter(
172 uint32_t coreid,
173 uint32_t debugid,
174 uint64_t timestamp,
175 uintptr_t arg1,
176 uintptr_t arg2,
177 uintptr_t arg3,
178 uintptr_t arg4,
179 uintptr_t threadid
180 );
181
182 #endif /* KERNEL_PRIVATE */
183
184 /* The Kernel Debug Classes */
185 #define DBG_MACH 1
186 #define DBG_NETWORK 2
187 #define DBG_FSYSTEM 3
188 #define DBG_BSD 4
189 #define DBG_IOKIT 5
190 #define DBG_DRIVERS 6
191 #define DBG_TRACE 7
192 #define DBG_DLIL 8
193 #define DBG_WORKQUEUE 9
194 #define DBG_CORESTORAGE 10
195 #define DBG_CG 11
196 #define DBG_MONOTONIC 12
197 #define DBG_MISC 20
198 #define DBG_SECURITY 30
199 #define DBG_DYLD 31
200 #define DBG_QT 32
201 #define DBG_APPS 33
202 #define DBG_LAUNCHD 34
203 #define DBG_PERF 37
204 #define DBG_IMPORTANCE 38
205 #define DBG_BANK 40
206 #define DBG_XPC 41
207 #define DBG_ATM 42
208 #define DBG_ARIADNE 43
209 #define DBG_DAEMON 44
210 #define DBG_ENERGYTRACE 45
211 #define DBG_DISPATCH 46
212 #define DBG_IMG 49
213 #define DBG_UMALLOC 51
214
215
216 #define DBG_MIG 255
217
218 #ifdef PRIVATE
219
220 /*
221 * Private kdebug userspace API
222 */
223 #ifndef KERNEL
224 #include <stdbool.h>
225
226 /*
227 * OS components can use the full precision of the "code" field
228 * (Class, SubClass, Code) to inject events using kdebug_trace() by
229 * using:
230 *
231 * kdebug_trace(KDBG_CODE(DBG_XPC, 15, 1) | DBG_FUNC_NONE, 1, 2, 3, 4);
232 *
233 * These trace points can be included in production code, since they
234 * use reserved, non-overlapping ranges. The performance impact when
235 * kernel tracing is not enabled is minimal. Classes can be reserved
236 * by filing a Radar in xnu|all.
237 *
238 * 64-bit arguments may be truncated if the system is using a 32-bit
239 * kernel.
240 *
241 * On error, -1 will be returned and errno will indicate the error.
242 */
243 extern int kdebug_trace(
244 uint32_t code,
245 uint64_t arg1,
246 uint64_t arg2,
247 uint64_t arg3,
248 uint64_t arg4)
249 __OSX_AVAILABLE(10.10.2) __IOS_AVAILABLE(8.2);
250
251 /*!
252 * @function kdebug_trace_string
253 *
254 * @discussion
255 * This function emits strings to kdebug trace along with an ID and allows
256 * for previously-traced strings to be overwritten and invalidated.
257 *
258 * To start tracing a string and generate an ID to use to refer to it:
259 *
260 * string_id = kdebug_trace_string(debugid, 0, "string");
261 *
262 * To replace a string previously traced:
263 *
264 * string_id = kdebug_trace_string(debugid, string_id, "new string");
265 *
266 * To invalidate a string ID:
267 *
268 * string_id = kdebug_trace_string(debugid, string_id, NULL);
269 *
270 * To check for errors:
271 *
272 * if ((int64_t)string_id == -1) { perror("string error") }
273 *
274 * @param debugid
275 * The `debugid` to check if its enabled before tracing and include as
276 * an argument in the event containing the string.
277 *
278 * Some classes or subclasses are reserved for specific uses and are not
279 * allowed to be used with this function. No function qualifiers are
280 * allowed on `debugid`.
281 *
282 * @param str_id
283 * When 0, a new ID will be generated and returned if tracing is
284 * enabled.
285 *
286 * Otherwise `str_id` must contain an ID that was previously generated
287 * with this function. Clents should pass NULL in `str` if `str_id`
288 * is no longer in use. Otherwise, the string previously mapped to
289 * `str_id` will be overwritten with the contents of `str`.
290 *
291 * @param str
292 * A NUL-terminated 'C' string containing the characters that should be
293 * traced alongside `str_id`.
294 *
295 * If necessary, the string will be truncated at an
296 * implementation-defined length. The string must not be the empty
297 * string, but can be NULL if a valid `str_id` is provided.
298 *
299 * @return
300 * 0 if tracing is disabled or `debugid` is being filtered out of trace.
301 * It can also return (int64_t)-1 if an error occured. Otherwise,
302 * it returns the ID to use to refer to the string in future
303 * kdebug_trace(2) calls.
304 *
305 * The errors that can occur are:
306 *
307 * EINVAL
308 * There are function qualifiers on `debugid`, `str` is empty, or
309 * `str_id` was not generated by this function.
310 * EPERM
311 * The `debugid`'s class or subclass is reserved for internal use.
312 * EFAULT
313 * `str` is an invalid address or NULL when `str_id` is 0.
314 */
315 extern uint64_t kdebug_trace_string(uint32_t debugid, uint64_t str_id,
316 const char *str)
317 __OSX_AVAILABLE(10.11) __IOS_AVAILABLE(9.0);
318
319 /*
320 * Although the performance impact of kdebug_trace() when kernel
321 * tracing is not enabled is minimal, it may require the caller to
322 * perform an expensive calculation/summarization. This cost can be
323 * skipped by checking the kdebug_is_enabled() predicate:
324 *
325 * if (kdebug_is_enabled(KDBG_CODE(DBG_XPC, 15, 1))) {
326 * uint64_t arg1 = ...;
327 * uint64_t arg2 = ...;
328 * kdebug_trace(KDBG_CODE(DBG_XPC, 15, 1) | DBG_FUNC_NONE, arg1, arg2, 0, 0);
329 * }
330 *
331 * If tracing is enabled for the code at the time of the check, 1
332 * will be returned. Otherwise, 0 will be returned.
333 */
334 extern bool kdebug_is_enabled(uint32_t code)
335 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
336 __WATCHOS_AVAILABLE(3.0) __TVOS_AVAILABLE(10.0);
337
338 /*
339 * Returns a pointer to the userspace typefilter, if one is available.
340 * May return NULL.
341 */
342 extern void *kdebug_typefilter(void)
343 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
344 __WATCHOS_AVAILABLE(3.0) __TVOS_AVAILABLE(10.0);
345
346 #endif /* !KERNEL (Private kdebug userspace API) */
347 #endif /* PRIVATE */
348
349 #ifdef XNU_KERNEL_PRIVATE
350 /* Used in early boot to log strings spanning only a single tracepoint. */
351 extern void kernel_debug_string_early(const char *message);
352 /* Used to trace strings within kdebug tracepoints on arbitrary eventids. */
353 extern void kernel_debug_string_simple(uint32_t eventid, const char *str);
354 /* Only used by ktrace to reset kdebug. ktrace_lock must be held. */
355 extern void kdebug_reset(void);
356 #endif /* XNU_KERNEL_PRIVATE */
357
358 /* **** The Kernel Debug Sub Classes for Mach (DBG_MACH) **** */
359 #define DBG_MACH_EXCP_KTRAP_x86 0x02 /* Kernel Traps on x86 */
360 #define DBG_MACH_EXCP_DFLT 0x03 /* Data Translation Fault */
361 #define DBG_MACH_EXCP_IFLT 0x04 /* Inst Translation Fault */
362 #define DBG_MACH_EXCP_INTR 0x05 /* Interrupts */
363 #define DBG_MACH_EXCP_ALNG 0x06 /* Alignment Exception */
364 #define DBG_MACH_EXCP_UTRAP_x86 0x07 /* User Traps on x86 */
365 #define DBG_MACH_EXCP_FP 0x08 /* FP Unavail */
366 #define DBG_MACH_EXCP_DECI 0x09 /* Decrementer Interrupt */
367 #define DBG_MACH_CHUD 0x0A /* deprecated name */
368 #define DBG_MACH_SIGNPOST 0x0A /* kernel signposts */
369 #define DBG_MACH_EXCP_SC 0x0C /* System Calls */
370 #define DBG_MACH_EXCP_TRACE 0x0D /* Trace exception */
371 #define DBG_MACH_EXCP_EMUL 0x0E /* Instruction emulated */
372 #define DBG_MACH_IHDLR 0x10 /* Interrupt Handlers */
373 #define DBG_MACH_IPC 0x20 /* Inter Process Comm */
374 #define DBG_MACH_RESOURCE 0x25 /* tracing limits, etc */
375 #define DBG_MACH_VM 0x30 /* Virtual Memory */
376 #define DBG_MACH_LEAKS 0x31 /* alloc/free */
377 #define DBG_MACH_WORKINGSET 0x32 /* private subclass for working set related debugging */
378 #define DBG_MACH_SCHED 0x40 /* Scheduler */
379 #define DBG_MACH_MSGID_INVALID 0x50 /* Messages - invalid */
380 #define DBG_MACH_LOCKS 0x60 /* new lock APIs */
381 #define DBG_MACH_PMAP 0x70 /* pmap */
382 #define DBG_MACH_CLOCK 0x80 /* clock */
383 #define DBG_MACH_MP 0x90 /* MP related */
384 #define DBG_MACH_VM_PRESSURE 0xA0 /* Memory Pressure Events */
385 #define DBG_MACH_STACKSHOT 0xA1 /* Stackshot/Microstackshot subsystem */
386 #define DBG_MACH_SFI 0xA2 /* Selective Forced Idle (SFI) */
387 #define DBG_MACH_ENERGY_PERF 0xA3 /* Energy/performance resource stats */
388 #define DBG_MACH_SYSDIAGNOSE 0xA4 /* sysdiagnose */
389 #define DBG_MACH_ZALLOC 0xA5 /* Zone allocator */
390 #define DBG_MACH_THREAD_GROUP 0xA6 /* Thread groups */
391 #define DBG_MACH_COALITION 0xA7 /* Coalitions */
392
393 /* Interrupt type bits for DBG_MACH_EXCP_INTR */
394 #define DBG_INTR_TYPE_UNKNOWN 0x0 /* default/unknown interrupt */
395 #define DBG_INTR_TYPE_IPI 0x1 /* interprocessor interrupt */
396 #define DBG_INTR_TYPE_TIMER 0x2 /* timer interrupt */
397 #define DBG_INTR_TYPE_OTHER 0x3 /* other (usually external) interrupt */
398
399 /* Codes for Scheduler (DBG_MACH_SCHED) */
400 #define MACH_SCHED 0x0 /* Scheduler */
401 #define MACH_STACK_ATTACH 0x1 /* stack_attach() */
402 #define MACH_STACK_HANDOFF 0x2 /* stack_handoff() */
403 #define MACH_CALL_CONT 0x3 /* call_continuation() */
404 #define MACH_CALLOUT 0x4 /* callouts */
405 #define MACH_STACK_DETACH 0x5
406 #define MACH_MAKE_RUNNABLE 0x6 /* make thread runnable */
407 #define MACH_PROMOTE 0x7 /* promoted due to resource */
408 #define MACH_DEMOTE 0x8 /* promotion undone */
409 #define MACH_IDLE 0x9 /* processor idling */
410 #define MACH_STACK_DEPTH 0xa /* stack depth at switch */
411 #define MACH_MOVED 0xb /* did not use original scheduling decision */
412 #define MACH_PSET_LOAD_AVERAGE 0xc
413 #define MACH_AMP_DEBUG 0xd
414 #define MACH_FAILSAFE 0xe /* tripped fixed-pri/RT failsafe */
415 #define MACH_BLOCK 0xf /* thread block */
416 #define MACH_WAIT 0x10 /* thread wait assertion */
417 #define MACH_GET_URGENCY 0x14 /* Urgency queried by platform */
418 #define MACH_URGENCY 0x15 /* Urgency (RT/BG/NORMAL) communicated
419 * to platform
420 */
421 #define MACH_REDISPATCH 0x16 /* "next thread" thread redispatched */
422 #define MACH_REMOTE_AST 0x17 /* AST signal issued to remote processor */
423 #define MACH_SCHED_CHOOSE_PROCESSOR 0x18 /* Result of choose_processor */
424 #define MACH_DEEP_IDLE 0x19 /* deep idle on master processor */
425 /* unused 0x1a was MACH_SCHED_DECAY_PRIORITY */
426 #define MACH_CPU_THROTTLE_DISABLE 0x1b /* Global CPU Throttle Disable */
427 #define MACH_RW_PROMOTE 0x1c /* promoted due to RW lock promotion */
428 #define MACH_RW_DEMOTE 0x1d /* promotion due to RW lock undone */
429 #define MACH_SCHED_MAINTENANCE 0x1f /* periodic maintenance thread */
430 #define MACH_DISPATCH 0x20 /* context switch completed */
431 #define MACH_QUANTUM_HANDOFF 0x21 /* quantum handoff occurred */
432 #define MACH_MULTIQ_DEQUEUE 0x22 /* Result of multiq dequeue */
433 #define MACH_SCHED_THREAD_SWITCH 0x23 /* attempt direct context switch to hinted thread */
434 #define MACH_SCHED_SMT_BALANCE 0x24 /* SMT load balancing ASTs */
435 #define MACH_REMOTE_DEFERRED_AST 0x25 /* Deferred AST started against remote processor */
436 #define MACH_REMOTE_CANCEL_AST 0x26 /* Canceled deferred AST for remote processor */
437 #define MACH_SCHED_CHANGE_PRIORITY 0x27 /* thread sched priority changed */
438 #define MACH_SCHED_UPDATE_REC_CORES 0x28 /* Change to recommended processor bitmask */
439 #define MACH_STACK_WAIT 0x29 /* Thread could not be switched-to because of kernel stack shortage */
440 #define MACH_THREAD_BIND 0x2a /* Thread was bound (or unbound) to a processor */
441 #define MACH_WAITQ_PROMOTE 0x2b /* Thread promoted by waitq boost */
442 #define MACH_WAITQ_DEMOTE 0x2c /* Thread demoted from waitq boost */
443 #define MACH_SCHED_LOAD 0x2d /* load update */
444 #define MACH_REC_CORES_FAILSAFE 0x2e /* recommended processor failsafe kicked in */
445 #define MACH_SCHED_QUANTUM_EXPIRED 0x2f /* thread quantum expired */
446 #define MACH_EXEC_PROMOTE 0x30 /* Thread promoted by exec boost */
447 #define MACH_EXEC_DEMOTE 0x31 /* Thread demoted from exec boost */
448 #define MACH_AMP_SIGNAL_SPILL 0x32 /* AMP spill signal sent to cpuid */
449 #define MACH_AMP_STEAL 0x33 /* AMP thread stolen or spilled */
450
451 /* Variants for MACH_MULTIQ_DEQUEUE */
452 #define MACH_MULTIQ_BOUND 1
453 #define MACH_MULTIQ_GROUP 2
454 #define MACH_MULTIQ_GLOBAL 3
455
456 /* Arguments for vm_fault (DBG_MACH_VM) */
457 #define DBG_ZERO_FILL_FAULT 1
458 #define DBG_PAGEIN_FAULT 2
459 #define DBG_COW_FAULT 3
460 #define DBG_CACHE_HIT_FAULT 4
461 #define DBG_NZF_PAGE_FAULT 5
462 #define DBG_GUARD_FAULT 6
463 #define DBG_PAGEINV_FAULT 7
464 #define DBG_PAGEIND_FAULT 8
465 #define DBG_COMPRESSOR_FAULT 9
466 #define DBG_COMPRESSOR_SWAPIN_FAULT 10
467
468 /* Codes for IPC (DBG_MACH_IPC) */
469 #define MACH_TASK_SUSPEND 0x0 /* Suspended a task */
470 #define MACH_TASK_RESUME 0x1 /* Resumed a task */
471 #define MACH_THREAD_SET_VOUCHER 0x2
472 #define MACH_IPC_MSG_SEND 0x3 /* mach msg send, uniq msg info */
473 #define MACH_IPC_MSG_RECV 0x4 /* mach_msg receive */
474 #define MACH_IPC_MSG_RECV_VOUCHER_REFUSED 0x5 /* mach_msg receive, voucher refused */
475 #define MACH_IPC_KMSG_FREE 0x6 /* kernel free of kmsg data */
476 #define MACH_IPC_VOUCHER_CREATE 0x7 /* Voucher added to global voucher hashtable */
477 #define MACH_IPC_VOUCHER_CREATE_ATTR_DATA 0x8 /* Attr data for newly created voucher */
478 #define MACH_IPC_VOUCHER_DESTROY 0x9 /* Voucher removed from global voucher hashtable */
479 #define MACH_IPC_KMSG_INFO 0xa /* Send/Receive info for a kmsg */
480 #define MACH_IPC_KMSG_LINK 0xb /* link a kernel kmsg pointer to user mach_msg_header_t */
481
482 /* Codes for thread groups (DBG_MACH_THREAD_GROUP) */
483 #define MACH_THREAD_GROUP_NEW 0x0
484 #define MACH_THREAD_GROUP_FREE 0x1
485 #define MACH_THREAD_GROUP_SET 0x2
486 #define MACH_THREAD_GROUP_NAME 0x3
487 #define MACH_THREAD_GROUP_NAME_FREE 0x4
488 #define MACH_THREAD_GROUP_FLAGS 0x5
489
490 /* Codes for coalitions (DBG_MACH_COALITION) */
491 #define MACH_COALITION_NEW 0x0
492 #define MACH_COALITION_FREE 0x1
493 #define MACH_COALITION_ADOPT 0x2
494 #define MACH_COALITION_REMOVE 0x3
495 #define MACH_COALITION_THREAD_GROUP_SET 0x4
496
497 /* Codes for pmap (DBG_MACH_PMAP) */
498 #define PMAP__CREATE 0x0
499 #define PMAP__DESTROY 0x1
500 #define PMAP__PROTECT 0x2
501 #define PMAP__PAGE_PROTECT 0x3
502 #define PMAP__ENTER 0x4
503 #define PMAP__REMOVE 0x5
504 #define PMAP__NEST 0x6
505 #define PMAP__UNNEST 0x7
506 #define PMAP__FLUSH_TLBS 0x8
507 #define PMAP__UPDATE_INTERRUPT 0x9
508 #define PMAP__ATTRIBUTE_CLEAR 0xa
509 #define PMAP__REUSABLE 0xb /* This appears to be unused */
510 #define PMAP__QUERY_RESIDENT 0xc
511 #define PMAP__FLUSH_KERN_TLBS 0xd
512 #define PMAP__FLUSH_DELAYED_TLBS 0xe
513 #define PMAP__FLUSH_TLBS_TO 0xf
514 #define PMAP__FLUSH_EPT 0x10
515 #define PMAP__FAST_FAULT 0x11
516
517 /* Codes for clock (DBG_MACH_CLOCK) */
518 #define MACH_EPOCH_CHANGE 0x0 /* wake epoch change */
519
520 /* Codes for Stackshot/Microstackshot (DBG_MACH_STACKSHOT) */
521 #define MICROSTACKSHOT_RECORD 0x0
522 #define MICROSTACKSHOT_GATHER 0x1
523
524 /* Codes for sysdiagnose (DBG_MACH_SYSDIAGNOSE) */
525 #define SYSDIAGNOSE_NOTIFY_USER 0x0
526 #define SYSDIAGNOSE_FULL 0x1
527 #define SYSDIAGNOSE_STACKSHOT 0x2
528 #define SYSDIAGNOSE_TAILSPIN 0x3
529
530 /* Codes for Selective Forced Idle (DBG_MACH_SFI) */
531 #define SFI_SET_WINDOW 0x0
532 #define SFI_CANCEL_WINDOW 0x1
533 #define SFI_SET_CLASS_OFFTIME 0x2
534 #define SFI_CANCEL_CLASS_OFFTIME 0x3
535 #define SFI_THREAD_DEFER 0x4
536 #define SFI_OFF_TIMER 0x5
537 #define SFI_ON_TIMER 0x6
538 #define SFI_WAIT_CANCELED 0x7
539 #define SFI_PID_SET_MANAGED 0x8
540 #define SFI_PID_CLEAR_MANAGED 0x9
541 #define SFI_GLOBAL_DEFER 0xa
542
543 /* Codes for Zone Allocator (DBG_MACH_ZALLOC) */
544 #define ZALLOC_ZCRAM 0x0
545
546 /* Codes for Mach resource management (DBG_MACH_RESOURCE) */
547 /* _K32A/B codes start at double the low nibble */
548 #define RMON_ENABLE_CPUUSAGE_MONITOR 0x001
549 #define RMON_CPUUSAGE_VIOLATED 0x002
550 #define RMON_CPUUSAGE_SUSPENDED 0x003
551 #define RMON_CPUUSAGE_VIOLATED_K32A 0x004
552 #define RMON_CPUUSAGE_VIOLATED_K32B 0x005
553 #define RMON_CPUUSAGE_RESUMED 0x006
554 #define RMON_DISABLE_CPUUSAGE_MONITOR 0x00f
555
556 #define RMON_ENABLE_CPUWAKES_MONITOR 0x011
557 #define RMON_CPUWAKES_VIOLATED 0x012
558 #define RMON_CPUWAKES_VIOLATED_K32A 0x014
559 #define RMON_CPUWAKES_VIOLATED_K32B 0x015
560 #define RMON_DISABLE_CPUWAKES_MONITOR 0x01f
561
562 #define RMON_ENABLE_IO_MONITOR 0x021
563 #define RMON_LOGWRITES_VIOLATED 0x022
564 #define RMON_PHYSWRITES_VIOLATED 0x023
565 #define RMON_LOGWRITES_VIOLATED_K32A 0x024
566 #define RMON_LOGWRITES_VIOLATED_K32B 0x025
567 #define RMON_DISABLE_IO_MONITOR 0x02f
568
569 /* **** The Kernel Debug Sub Classes for Network (DBG_NETWORK) **** */
570 #define DBG_NETIP 1 /* Internet Protocol */
571 #define DBG_NETARP 2 /* Address Resolution Protocol */
572 #define DBG_NETUDP 3 /* User Datagram Protocol */
573 #define DBG_NETTCP 4 /* Transmission Control Protocol */
574 #define DBG_NETICMP 5 /* Internet Control Message Protocol */
575 #define DBG_NETIGMP 6 /* Internet Group Management Protocol */
576 #define DBG_NETRIP 7 /* Routing Information Protocol */
577 #define DBG_NETOSPF 8 /* Open Shortest Path First */
578 #define DBG_NETISIS 9 /* Intermediate System to Intermediate System */
579 #define DBG_NETSNMP 10 /* Simple Network Management Protocol */
580 #define DBG_NETSOCK 11 /* Socket Layer */
581
582 /* For Apple talk */
583 #define DBG_NETAARP 100 /* Apple ARP */
584 #define DBG_NETDDP 101 /* Datagram Delivery Protocol */
585 #define DBG_NETNBP 102 /* Name Binding Protocol */
586 #define DBG_NETZIP 103 /* Zone Information Protocol */
587 #define DBG_NETADSP 104 /* Name Binding Protocol */
588 #define DBG_NETATP 105 /* Apple Transaction Protocol */
589 #define DBG_NETASP 106 /* Apple Session Protocol */
590 #define DBG_NETAFP 107 /* Apple Filing Protocol */
591 #define DBG_NETRTMP 108 /* Routing Table Maintenance Protocol */
592 #define DBG_NETAURP 109 /* Apple Update Routing Protocol */
593
594 #define DBG_NETIPSEC 128 /* IPsec Protocol */
595 #define DBG_NETVMNET 129 /* VMNet */
596
597 /* **** The Kernel Debug Sub Classes for IOKIT (DBG_IOKIT) **** */
598 #define DBG_IOINTC 0 /* Interrupt controller */
599 #define DBG_IOWORKLOOP 1 /* Work from work loop */
600 #define DBG_IOINTES 2 /* Interrupt event source */
601 #define DBG_IOCLKES 3 /* Clock event source */
602 #define DBG_IOCMDQ 4 /* Command queue latencies */
603 #define DBG_IOMCURS 5 /* Memory Cursor */
604 #define DBG_IOMDESC 6 /* Memory Descriptors */
605 #define DBG_IOPOWER 7 /* Power Managerment */
606 #define DBG_IOSERVICE 8 /* Matching etc. */
607 #define DBG_IOREGISTRY 9 /* Registry */
608
609 /* **** 9-32 reserved for internal IOKit usage **** */
610
611 #define DBG_IOSTORAGE 32 /* Storage layers */
612 #define DBG_IONETWORK 33 /* Network layers */
613 #define DBG_IOKEYBOARD 34 /* Keyboard */
614 #define DBG_IOHID 35 /* HID Devices */
615 #define DBG_IOAUDIO 36 /* Audio */
616 #define DBG_IOSERIAL 37 /* Serial */
617 #define DBG_IOTTY 38 /* TTY layers */
618 #define DBG_IOSAM 39 /* SCSI Architecture Model layers */
619 #define DBG_IOPARALLELATA 40 /* Parallel ATA */
620 #define DBG_IOPARALLELSCSI 41 /* Parallel SCSI */
621 #define DBG_IOSATA 42 /* Serial-ATA */
622 #define DBG_IOSAS 43 /* SAS */
623 #define DBG_IOFIBRECHANNEL 44 /* FiberChannel */
624 #define DBG_IOUSB 45 /* USB */
625 #define DBG_IOBLUETOOTH 46 /* Bluetooth */
626 #define DBG_IOFIREWIRE 47 /* FireWire */
627 #define DBG_IOINFINIBAND 48 /* Infiniband */
628 #define DBG_IOCPUPM 49 /* CPU Power Management */
629 #define DBG_IOGRAPHICS 50 /* Graphics */
630 #define DBG_HIBERNATE 51 /* hibernation related events */
631 #define DBG_IOTHUNDERBOLT 52 /* Thunderbolt */
632 #define DBG_BOOTER 53 /* booter related events */
633
634 /* Backwards compatibility */
635 #define DBG_IOPOINTING DBG_IOHID /* OBSOLETE: Use DBG_IOHID instead */
636 #define DBG_IODISK DBG_IOSTORAGE /* OBSOLETE: Use DBG_IOSTORAGE instead */
637
638 /* **** The Kernel Debug Sub Classes for Device Drivers (DBG_DRIVERS) **** */
639 #define DBG_DRVSTORAGE 1 /* Storage layers */
640 #define DBG_DRVNETWORK 2 /* Network layers */
641 #define DBG_DRVKEYBOARD 3 /* Keyboard */
642 #define DBG_DRVHID 4 /* HID Devices */
643 #define DBG_DRVAUDIO 5 /* Audio */
644 #define DBG_DRVSERIAL 7 /* Serial */
645 #define DBG_DRVSAM 8 /* SCSI Architecture Model layers */
646 #define DBG_DRVPARALLELATA 9 /* Parallel ATA */
647 #define DBG_DRVPARALLELSCSI 10 /* Parallel SCSI */
648 #define DBG_DRVSATA 11 /* Serial ATA */
649 #define DBG_DRVSAS 12 /* SAS */
650 #define DBG_DRVFIBRECHANNEL 13 /* FiberChannel */
651 #define DBG_DRVUSB 14 /* USB */
652 #define DBG_DRVBLUETOOTH 15 /* Bluetooth */
653 #define DBG_DRVFIREWIRE 16 /* FireWire */
654 #define DBG_DRVINFINIBAND 17 /* Infiniband */
655 #define DBG_DRVGRAPHICS 18 /* Graphics */
656 #define DBG_DRVSD 19 /* Secure Digital */
657 #define DBG_DRVNAND 20 /* NAND drivers and layers */
658 #define DBG_SSD 21 /* SSD */
659 #define DBG_DRVSPI 22 /* SPI */
660 #define DBG_DRVWLAN_802_11 23 /* WLAN 802.11 */
661 #define DBG_DRVSSM 24 /* System State Manager(AppleSSM) */
662 #define DBG_DRVSMC 25 /* System Management Controller */
663 #define DBG_DRVMACEFIMANAGER 26 /* Mac EFI Manager */
664
665 /* Backwards compatibility */
666 #define DBG_DRVPOINTING DBG_DRVHID /* OBSOLETE: Use DBG_DRVHID instead */
667 #define DBG_DRVDISK DBG_DRVSTORAGE /* OBSOLETE: Use DBG_DRVSTORAGE instead */
668
669 /* **** The Kernel Debug Sub Classes for the DLIL Layer (DBG_DLIL) **** */
670 #define DBG_DLIL_STATIC 1 /* Static DLIL code */
671 #define DBG_DLIL_PR_MOD 2 /* DLIL Protocol Module */
672 #define DBG_DLIL_IF_MOD 3 /* DLIL Interface Module */
673 #define DBG_DLIL_PR_FLT 4 /* DLIL Protocol Filter */
674 #define DBG_DLIL_IF_FLT 5 /* DLIL Interface FIlter */
675
676
677 /* The Kernel Debug Sub Classes for File System (DBG_FSYSTEM) */
678 #define DBG_FSRW 0x1 /* reads and writes to the filesystem */
679 #define DBG_DKRW 0x2 /* reads and writes to the disk */
680 #define DBG_FSVN 0x3 /* vnode operations (inc. locking/unlocking) */
681 #define DBG_FSLOOOKUP 0x4 /* namei and other lookup-related operations */
682 #define DBG_JOURNAL 0x5 /* journaling operations */
683 #define DBG_IOCTL 0x6 /* ioctl to the disk */
684 #define DBG_BOOTCACHE 0x7 /* bootcache operations */
685 #define DBG_HFS 0x8 /* HFS-specific events; see the hfs project */
686 #define DBG_APFS 0x9 /* APFS-specific events; see the apfs project */
687 #define DBG_SMB 0xA /* SMB-specific events; see the smb project */
688 #define DBG_MOUNT 0xB /* Mounting/unmounting operations */
689 #define DBG_EXFAT 0xE /* ExFAT-specific events; see the exfat project */
690 #define DBG_MSDOS 0xF /* FAT-specific events; see the msdosfs project */
691 #define DBG_ACFS 0x10 /* Xsan-specific events; see the XsanFS project */
692 #define DBG_THROTTLE 0x11 /* I/O Throttling events */
693 #define DBG_CONTENT_PROT 0xCF /* Content Protection Events: see bsd/sys/cprotect.h */
694
695 /*
696 * For Kernel Debug Sub Class DBG_HFS, state bits for hfs_update event
697 */
698 #define DBG_HFS_UPDATE_ACCTIME 0x01
699 #define DBG_HFS_UPDATE_MODTIME 0x02
700 #define DBG_HFS_UPDATE_CHGTIME 0x04
701 #define DBG_HFS_UPDATE_MODIFIED 0x08
702 #define DBG_HFS_UPDATE_FORCE 0x10
703 #define DBG_HFS_UPDATE_DATEADDED 0x20
704 #define DBG_HFS_UPDATE_MINOR 0x40
705 #define DBG_HFS_UPDATE_SKIPPED 0x80
706
707 /* The Kernel Debug Sub Classes for BSD */
708 #define DBG_BSD_PROC 0x01 /* process/signals related */
709 #define DBG_BSD_MEMSTAT 0x02 /* memorystatus / jetsam operations */
710 #define DBG_BSD_KEVENT 0x03 /* kqueue / kevent related */
711 #define DBG_BSD_EXCP_SC 0x0C /* System Calls */
712 #define DBG_BSD_AIO 0x0D /* aio (POSIX async IO) */
713 #define DBG_BSD_SC_EXTENDED_INFO 0x0E /* System Calls, extended info */
714 #define DBG_BSD_SC_EXTENDED_INFO2 0x0F /* System Calls, extended info */
715 #define DBG_BSD_KDEBUG_TEST 0xFF /* for testing kdebug */
716
717 /* The Codes for BSD subcode class DBG_BSD_PROC */
718 #define BSD_PROC_EXIT 1 /* process exit */
719 #define BSD_PROC_FRCEXIT 2 /* Kernel force termination */
720 #define BSD_PROC_EXEC 3 /* process spawn / exec */
721 #define BSD_PROC_EXITREASON_CREATE 4 /* exit reason creation */
722 #define BSD_PROC_EXITREASON_COMMIT 5 /* exit reason commited to a proc */
723
724 /* Codes for BSD subcode class DBG_BSD_MEMSTAT */
725 #define BSD_MEMSTAT_SCAN 1 /* memorystatus thread awake */
726 #define BSD_MEMSTAT_JETSAM 2 /* LRU jetsam */
727 #define BSD_MEMSTAT_JETSAM_HIWAT 3 /* highwater jetsam */
728 #define BSD_MEMSTAT_FREEZE 4 /* freeze process */
729 #define BSD_MEMSTAT_LATENCY_COALESCE 5 /* delay imposed to coalesce jetsam reports */
730 #define BSD_MEMSTAT_UPDATE 6 /* priority update */
731 #define BSD_MEMSTAT_IDLE_DEMOTE 7 /* idle demotion fired */
732 #define BSD_MEMSTAT_CLEAR_ERRORS 8 /* reset termination error state */
733 #define BSD_MEMSTAT_DIRTY_TRACK 9 /* track the process state */
734 #define BSD_MEMSTAT_DIRTY_SET 10 /* set the process state */
735 #define BSD_MEMSTAT_DIRTY_CLEAR 11 /* clear the process state */
736 #ifdef PRIVATE
737 #define BSD_MEMSTAT_GRP_SET_PROP 12 /* set group properties */
738 #define BSD_MEMSTAT_DO_KILL 13 /* memorystatus kills */
739 #endif /* PRIVATE */
740
741 /* Codes for BSD subcode class DBG_BSD_KEVENT */
742 #define BSD_KEVENT_KQ_PROCESS_BEGIN 1
743 #define BSD_KEVENT_KQ_PROCESS_END 2
744 #define BSD_KEVENT_KQWQ_PROCESS_BEGIN 3
745 #define BSD_KEVENT_KQWQ_PROCESS_END 4
746 #define BSD_KEVENT_KQWQ_BIND 5
747 #define BSD_KEVENT_KQWQ_UNBIND 6
748 #define BSD_KEVENT_KQWQ_THREQUEST 7
749 #define BSD_KEVENT_KQWL_PROCESS_BEGIN 8
750 #define BSD_KEVENT_KQWL_PROCESS_END 9
751 #define BSD_KEVENT_KQWL_THREQUEST 10
752 #define BSD_KEVENT_KQWL_THADJUST 11
753 #define BSD_KEVENT_KQ_REGISTER 12
754 #define BSD_KEVENT_KQWQ_REGISTER 13
755 #define BSD_KEVENT_KQWL_REGISTER 14
756 #define BSD_KEVENT_KNOTE_ACTIVATE 15
757 #define BSD_KEVENT_KQ_PROCESS 16
758 #define BSD_KEVENT_KQWQ_PROCESS 17
759 #define BSD_KEVENT_KQWL_PROCESS 18
760 #define BSD_KEVENT_KQWL_BIND 19
761 #define BSD_KEVENT_KQWL_UNBIND 20
762 #define BSD_KEVENT_KNOTE_ENABLE 21
763
764 /* The Kernel Debug Sub Classes for DBG_TRACE */
765 #define DBG_TRACE_DATA 0
766 #define DBG_TRACE_STRING 1
767 #define DBG_TRACE_INFO 2
768
769 /* The Kernel Debug events: */
770 #define TRACE_DATA_NEWTHREAD (TRACEDBG_CODE(DBG_TRACE_DATA, 1))
771 #define TRACE_DATA_EXEC (TRACEDBG_CODE(DBG_TRACE_DATA, 2))
772 #define TRACE_DATA_THREAD_TERMINATE (TRACEDBG_CODE(DBG_TRACE_DATA, 3))
773 #define TRACE_DATA_THREAD_TERMINATE_PID (TRACEDBG_CODE(DBG_TRACE_DATA, 4))
774 #define TRACE_STRING_GLOBAL (TRACEDBG_CODE(DBG_TRACE_STRING, 0))
775 #define TRACE_STRING_NEWTHREAD (TRACEDBG_CODE(DBG_TRACE_STRING, 1))
776 #define TRACE_STRING_EXEC (TRACEDBG_CODE(DBG_TRACE_STRING, 2))
777 #define TRACE_STRING_PROC_EXIT (TRACEDBG_CODE(DBG_TRACE_STRING, 3))
778 #define TRACE_STRING_THREADNAME (TRACEDBG_CODE(DBG_TRACE_STRING, 4))
779 #define TRACE_STRING_THREADNAME_PREV (TRACEDBG_CODE(DBG_TRACE_STRING, 5))
780 #define TRACE_PANIC (TRACEDBG_CODE(DBG_TRACE_INFO, 0))
781 #define TRACE_TIMESTAMPS (TRACEDBG_CODE(DBG_TRACE_INFO, 1))
782 #define TRACE_LOST_EVENTS (TRACEDBG_CODE(DBG_TRACE_INFO, 2))
783 #define TRACE_WRITING_EVENTS (TRACEDBG_CODE(DBG_TRACE_INFO, 3))
784 #define TRACE_INFO_STRING (TRACEDBG_CODE(DBG_TRACE_INFO, 4))
785 #define TRACE_RETROGRADE_EVENTS (TRACEDBG_CODE(DBG_TRACE_INFO, 5))
786
787 /* The Kernel Debug Sub Classes for DBG_CORESTORAGE */
788 #define DBG_CS_IO 0
789
790 /* The Kernel Debug Sub Classes for DBG_SECURITY */
791 #define DBG_SEC_KERNEL 0 /* raw entropy collected by the kernel */
792 #define DBG_SEC_SANDBOX 1
793
794 /* Sub-class codes for CoreGraphics (DBG_CG) are defined in its component. */
795
796 /* The Kernel Debug Sub Classes for DBG_MONOTONIC */
797 #define DBG_MT_INSTRS_CYCLES 1
798 #define DBG_MT_TMPTH 0xfe
799 #define DBG_MT_TMPCPU 0xff
800
801 /* The Kernel Debug Sub Classes for DBG_MISC */
802 #define DBG_EVENT 0x10
803 #define DBG_BUFFER 0x20
804
805 /* The Kernel Debug Sub Classes for DBG_DYLD */
806 #define DBG_DYLD_UUID (5)
807
808 /* Kernel Debug codes for the DBG_DYLD_UUID subclass */
809 #define DBG_DYLD_UUID_MAP_A (0)
810 #define DBG_DYLD_UUID_MAP_B (1)
811 #define DBG_DYLD_UUID_MAP_32_A (2)
812 #define DBG_DYLD_UUID_MAP_32_B (3)
813 #define DBG_DYLD_UUID_MAP_32_C (4)
814 #define DBG_DYLD_UUID_UNMAP_A (5)
815 #define DBG_DYLD_UUID_UNMAP_B (6)
816 #define DBG_DYLD_UUID_UNMAP_32_A (7)
817 #define DBG_DYLD_UUID_UNMAP_32_B (8)
818 #define DBG_DYLD_UUID_UNMAP_32_C (9)
819 #define DBG_DYLD_UUID_SHARED_CACHE_A (10)
820 #define DBG_DYLD_UUID_SHARED_CACHE_B (11)
821 #define DBG_DYLD_UUID_SHARED_CACHE_32_A (12)
822 #define DBG_DYLD_UUID_SHARED_CACHE_32_B (13)
823 #define DBG_DYLD_UUID_SHARED_CACHE_32_C (14)
824
825 /* The Kernel Debug modifiers for the DBG_DKRW sub class */
826 #define DKIO_DONE 0x01
827 #define DKIO_READ 0x02
828 #define DKIO_ASYNC 0x04
829 #define DKIO_META 0x08
830 #define DKIO_PAGING 0x10
831 #define DKIO_THROTTLE 0x20 /* Deprecated, still provided so fs_usage doesn't break */
832 #define DKIO_PASSIVE 0x40
833 #define DKIO_NOCACHE 0x80
834 #define DKIO_TIER_MASK 0xF00
835 #define DKIO_TIER_SHIFT 8
836 #define DKIO_TIER_UPGRADE 0x1000
837
838 /* Kernel Debug Sub Classes for Applications (DBG_APPS) */
839 #define DBG_APP_LOGINWINDOW 0x03
840 #define DBG_APP_AUDIO 0x04
841 #define DBG_APP_SYSTEMUI 0x05
842 #define DBG_APP_SIGNPOST 0x0A
843 #define DBG_APP_APPKIT 0x0C
844 #define DBG_APP_DFR 0x0E
845 #define DBG_APP_SAMBA 0x80
846 #define DBG_APP_EOSSUPPORT 0x81
847 #define DBG_APP_MACEFIMANAGER 0x82
848
849 /* Kernel Debug codes for Throttling (DBG_THROTTLE) */
850 #define OPEN_THROTTLE_WINDOW 0x1
851 #define PROCESS_THROTTLED 0x2
852 #define IO_THROTTLE_DISABLE 0x3
853 #define IO_TIER_UPL_MISMATCH 0x4
854
855
856 /* Subclasses for MACH Importance Policies (DBG_IMPORTANCE) */
857 /* TODO: Split up boost and task policy? */
858 #define IMP_ASSERTION 0x10 /* Task takes/drops a boost assertion */
859 #define IMP_BOOST 0x11 /* Task boost level changed */
860 #define IMP_MSG 0x12 /* boosting message sent by donating task on donating port */
861 #define IMP_WATCHPORT 0x13 /* port marked as watchport, and boost was transferred to the watched task */
862 #define IMP_TASK_SUPPRESSION 0x17 /* Task changed suppression behaviors */
863 #define IMP_TASK_APPTYPE 0x18 /* Task launched with apptype */
864 #define IMP_UPDATE 0x19 /* Requested -> effective calculation */
865 #define IMP_USYNCH_QOS_OVERRIDE 0x1A /* Userspace synchronization applied QoS override to resource owning thread */
866 #define IMP_DONOR_CHANGE 0x1B /* The iit_donor bit changed */
867 #define IMP_MAIN_THREAD_QOS 0x1C /* The task's main thread QoS was set */
868 #define IMP_SYNC_IPC_QOS 0x1D /* Sync IPC QOS override */
869 /* DBG_IMPORTANCE subclasses 0x20 - 0x3F reserved for task policy flavors */
870
871 /* Codes for IMP_ASSERTION */
872 #define IMP_HOLD 0x2 /* Task holds a boost assertion */
873 #define IMP_DROP 0x4 /* Task drops a boost assertion */
874 #define IMP_EXTERN 0x8 /* boost assertion moved from kernel to userspace responsibility (externalized) */
875
876 /* Codes for IMP_BOOST */
877 #define IMP_BOOSTED 0x1
878 #define IMP_UNBOOSTED 0x2 /* Task drops a boost assertion */
879
880 /* Codes for IMP_MSG */
881 #define IMP_MSG_SEND 0x1 /* boosting message sent by donating task on donating port */
882 #define IMP_MSG_DELV 0x2 /* boosting message delivered to task */
883
884 /* Codes for IMP_UPDATE */
885 #define IMP_UPDATE_TASK_CREATE 0x1
886
887 /* Codes for IMP_USYNCH_QOS_OVERRIDE */
888 #define IMP_USYNCH_ADD_OVERRIDE 0x0 /* add override for a contended resource */
889 #define IMP_USYNCH_REMOVE_OVERRIDE 0x1 /* remove override for a contended resource */
890
891 /* Codes for IMP_DONOR_CHANGE */
892 #define IMP_DONOR_UPDATE_LIVE_DONOR_STATE 0x0
893 #define IMP_DONOR_INIT_DONOR_STATE 0x1
894
895 /* Code for IMP_SYNC_IPC_QOS */
896 #define IMP_SYNC_IPC_QOS_APPLIED 0x0
897 #define IMP_SYNC_IPC_QOS_REMOVED 0x1
898 #define IMP_SYNC_IPC_QOS_OVERFLOW 0x2
899 #define IMP_SYNC_IPC_QOS_UNDERFLOW 0x3
900
901 /* Subclasses for MACH Bank Voucher Attribute Manager (DBG_BANK) */
902 #define BANK_ACCOUNT_INFO 0x10 /* Trace points related to bank account struct */
903 #define BANK_TASK_INFO 0x11 /* Trace points related to bank task struct */
904
905 /* Subclasses for MACH ATM Voucher Attribute Manager (ATM) */
906 #define ATM_SUBAID_INFO 0x10
907 #define ATM_GETVALUE_INFO 0x20
908 #define ATM_UNREGISTER_INFO 0x30
909
910 /* Codes for BANK_ACCOUNT_INFO */
911 #define BANK_SETTLE_CPU_TIME 0x1 /* Bank ledger(chit) rolled up to tasks. */
912 #define BANK_SECURE_ORIGINATOR_CHANGED 0x2 /* Secure Originator changed. */
913 #define BANK_SETTLE_ENERGY 0x3 /* Bank ledger(energy field) rolled up to tasks. */
914
915 /* Codes for ATM_SUBAID_INFO */
916 #define ATM_MIN_CALLED 0x1
917 #define ATM_LINK_LIST_TRIM 0x2
918
919 /* Codes for ATM_GETVALUE_INFO */
920 #define ATM_VALUE_REPLACED 0x1
921 #define ATM_VALUE_ADDED 0x2
922
923 /* Codes for ATM_UNREGISTER_INFO */
924 #define ATM_VALUE_UNREGISTERED 0x1
925 #define ATM_VALUE_DIFF_MAILBOX 0x2
926
927 /* Kernel Debug Sub Classes for daemons (DBG_DAEMON) */
928 #define DBG_DAEMON_COREDUET 0x1
929 #define DBG_DAEMON_POWERD 0x2
930
931 /* Subclasses for the user space allocator */
932 #define DBG_UMALLOC_EXTERNAL 0x1
933 #define DBG_UMALLOC_INTERNAL 0x2
934 /**********************************************************************/
935
936 #define KDBG_MIGCODE(msgid) ((DBG_MIG << KDBG_CLASS_OFFSET) | \
937 (((msgid) & 0x3fffff) << KDBG_CODE_OFFSET))
938
939 #define MACHDBG_CODE(SubClass, code) KDBG_CODE(DBG_MACH, SubClass, code)
940 #define NETDBG_CODE(SubClass, code) KDBG_CODE(DBG_NETWORK, SubClass, code)
941 #define FSDBG_CODE(SubClass, code) KDBG_CODE(DBG_FSYSTEM, SubClass, code)
942 #define BSDDBG_CODE(SubClass, code) KDBG_CODE(DBG_BSD, SubClass, code)
943 #define IOKDBG_CODE(SubClass, code) KDBG_CODE(DBG_IOKIT, SubClass, code)
944 #define DRVDBG_CODE(SubClass, code) KDBG_CODE(DBG_DRIVERS, SubClass, code)
945 #define TRACEDBG_CODE(SubClass,code) KDBG_CODE(DBG_TRACE, SubClass, code)
946 #define MISCDBG_CODE(SubClass,code) KDBG_CODE(DBG_MISC, SubClass, code)
947 #define DLILDBG_CODE(SubClass,code) KDBG_CODE(DBG_DLIL, SubClass, code)
948 #define SECURITYDBG_CODE(SubClass,code) KDBG_CODE(DBG_SECURITY, SubClass, code)
949 #define DYLDDBG_CODE(SubClass,code) KDBG_CODE(DBG_DYLD, SubClass, code)
950 #define QTDBG_CODE(SubClass,code) KDBG_CODE(DBG_QT, SubClass, code)
951 #define APPSDBG_CODE(SubClass,code) KDBG_CODE(DBG_APPS, SubClass, code)
952 #define ARIADNEDBG_CODE(SubClass, code) KDBG_CODE(DBG_ARIADNE, SubClass, code)
953 #define DAEMONDBG_CODE(SubClass, code) KDBG_CODE(DBG_DAEMON, SubClass, code)
954 #define CPUPM_CODE(code) IOKDBG_CODE(DBG_IOCPUPM, code)
955
956 #define KMEM_ALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 0)
957 #define KMEM_ALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 1)
958 #define KMEM_FREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 2)
959 #define KMEM_FREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 3)
960 #define ZALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 4)
961 #define ZALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 5)
962 #define ZFREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 6)
963 #define ZFREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 7)
964
965 #define PMAP_CODE(code) MACHDBG_CODE(DBG_MACH_PMAP, code)
966
967
968 #define IMPORTANCE_CODE(SubClass, code) KDBG_CODE(DBG_IMPORTANCE, (SubClass), (code))
969 #define BANK_CODE(SubClass, code) KDBG_CODE(DBG_BANK, (SubClass), (code))
970 #define ATM_CODE(SubClass, code) KDBG_CODE(DBG_ATM, (SubClass), (code))
971
972 /* Kernel Debug Macros for specific daemons */
973 #define COREDUETDBG_CODE(code) DAEMONDBG_CODE(DBG_DAEMON_COREDUET, code)
974 #define POWERDDBG_CODE(code) DAEMONDBG_CODE(DBG_DAEMON_POWERD, code)
975
976 /*
977 * To use kdebug in the kernel:
978 *
979 * #include <sys/kdebug.h>
980 *
981 * #define DBG_NETIPINIT NETDBG_CODE(DBG_NETIP, 1)
982 *
983 * void
984 * ip_init(void)
985 * {
986 * KDBG(DBG_NETIPINIT | DBG_FUNC_START, 1, 2, 3, 4);
987 * ...
988 * KDBG(DBG_NETIPINIT);
989 * ...
990 * KDBG(DBG_NETIPINIT | DBG_FUNC_END);
991 * }
992 */
993
994 #ifdef KERNEL_PRIVATE
995
996 /*
997 * The KDBG{,_DEBUG,_RELEASE,_FILTERED} macros are the preferred method of
998 * making tracepoints.
999 *
1000 * Kernel pointers must be unslid or permuted using VM_KERNEL_UNSLIDE_OR_PERM.
1001 * Do not trace any sensitive data.
1002 */
1003
1004 /*
1005 * Traced on debug and development (and release OS X) kernels.
1006 */
1007 #define KDBG(x, ...) KDBG_(, x, ## __VA_ARGS__, 4, 3, 2, 1, 0)
1008
1009 /*
1010 * Traced on debug and development (and release OS X) kernels if explicitly
1011 * requested. Omitted from tracing without a typefilter.
1012 */
1013 #define KDBG_FILTERED(x, ...) KDBG_(_FILTERED, x, ## __VA_ARGS__, 4, 3, 2, 1, 0)
1014
1015 /*
1016 * Traced on debug, development, and release kernels.
1017 *
1018 * Only use this tracepoint if the events are required for a shipping trace
1019 * tool.
1020 */
1021 #define KDBG_RELEASE(x, ...) KDBG_(_RELEASE, x, ## __VA_ARGS__, 4, 3, 2, 1, 0)
1022
1023 /*
1024 * Traced only on debug kernels.
1025 */
1026 #define KDBG_DEBUG(x, ...) KDBG_(_DEBUG, x, ## __VA_ARGS__, 4, 3, 2, 1, 0)
1027
1028 #define KDBG_(f, x, a, b, c, d, n, ...) KDBG##n(f, x, a, b, c, d)
1029 #define KDBG0(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, 0, 0, 0, 0, 0)
1030 #define KDBG1(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, 0, 0, 0, 0)
1031 #define KDBG2(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, b, 0, 0, 0)
1032 #define KDBG3(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, b, c, 0, 0)
1033 #define KDBG4(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, b, c, d, 0)
1034
1035 #endif /* defined(KERNEL_PRIVATE) */
1036
1037 extern unsigned int kdebug_enable;
1038
1039 /*
1040 * Bits used by kdebug_enable. These control which events are traced at
1041 * runtime.
1042 */
1043 #define KDEBUG_ENABLE_TRACE (1U << 0)
1044 #define KDEBUG_ENABLE_ENTROPY (1U << 1) /* obsolete */
1045 #define KDEBUG_ENABLE_CHUD (1U << 2) /* obsolete */
1046 #define KDEBUG_ENABLE_PPT (1U << 3)
1047 #define KDEBUG_ENABLE_SERIAL (1U << 4)
1048
1049 #define KDEBUG_TRACE (KDEBUG_ENABLE_TRACE)
1050
1051 /*
1052 * Specify KDEBUG_PPT to indicate that the event belongs to the limited PPT set.
1053 * PPT is deprecated -- use a typefilter and the PPTDBG class instead.
1054 */
1055 #define KDEBUG_PPT (KDEBUG_ENABLE_PPT)
1056 #define KDEBUG_COMMON (KDEBUG_ENABLE_TRACE | KDEBUG_ENABLE_PPT)
1057
1058 /*
1059 * The kernel debug configuration level. These values control which events are
1060 * compiled in under different build configurations.
1061 *
1062 * Infer the supported kernel debug event level from config option. Use
1063 * (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) as a guard to protect unaudited debug
1064 * code.
1065 */
1066 #define KDEBUG_LEVEL_NONE 0
1067 #define KDEBUG_LEVEL_IST 1
1068 #define KDEBUG_LEVEL_STANDARD 2
1069 #define KDEBUG_LEVEL_FULL 3
1070
1071 #if NO_KDEBUG
1072 #define KDEBUG_LEVEL KDEBUG_LEVEL_NONE
1073 #elif IST_KDEBUG
1074 #define KDEBUG_LEVEL KDEBUG_LEVEL_IST
1075 // currently configured for the iOS release kernel
1076 #elif KDEBUG
1077 #define KDEBUG_LEVEL KDEBUG_LEVEL_FULL
1078 #else
1079 #define KDEBUG_LEVEL KDEBUG_LEVEL_STANDARD
1080 /*
1081 * Currently, all other kernel configurations (development, etc) build with
1082 * KDEBUG_LEVEL_STANDARD. As a result, KERNEL_DEBUG_CONSTANT*() are on by
1083 * default but KERNEL_DEBUG*() are not.
1084 */
1085 #endif
1086
1087 #ifdef XNU_KERNEL_PRIVATE
1088 #define KDBG_IMPROBABLE __improbable
1089 #else
1090 #define KDBG_IMPROBABLE
1091 #endif
1092
1093 /*
1094 * KERNEL_DEBUG_CONSTANT_FILTERED events are omitted from tracing unless they
1095 * are explicitly requested in the typefilter. They are not emitted when
1096 * tracing without a typefilter.
1097 */
1098 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
1099 #define KERNEL_DEBUG_CONSTANT_FILTERED(x, a, b, c, d, ...) \
1100 do { \
1101 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1102 kernel_debug_filtered((x), (uintptr_t)(a), (uintptr_t)(b), \
1103 (uintptr_t)(c), (uintptr_t)(d)); \
1104 } \
1105 } while (0)
1106 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
1107 #define KERNEL_DEBUG_CONSTANT_FILTERED(type, x, a, b, c, d, ...) do {} while (0)
1108 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
1109
1110 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
1111 #define KERNEL_DEBUG_CONSTANT(x, a, b, c, d, e) \
1112 do { \
1113 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1114 kernel_debug((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \
1115 (uintptr_t)(d),(uintptr_t)(e)); \
1116 } \
1117 } while (0)
1118
1119 /*
1120 * DO NOT USE THIS MACRO -- it breaks fundamental assumptions about ktrace and
1121 * is only meant to be used by the pthread kext and other points in the kernel
1122 * where the thread ID must be provided explicitly.
1123 */
1124 #define KERNEL_DEBUG_CONSTANT1(x, a, b, c, d, e) \
1125 do { \
1126 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1127 kernel_debug1((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \
1128 (uintptr_t)(d), (uintptr_t)(e)); \
1129 } \
1130 } while (0)
1131
1132 #define KERNEL_DEBUG_EARLY(x, a, b, c, d) \
1133 do { \
1134 kernel_debug_early((uint32_t)(x), (uintptr_t)(a), (uintptr_t)(b), \
1135 (uintptr_t)(c), (uintptr_t)(d)); \
1136 } while (0)
1137 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
1138 #define KERNEL_DEBUG_CONSTANT(x, a, b, c, d, e) do {} while (0)
1139 #define KERNEL_DEBUG_CONSTANT1(x, a, b, c, d, e) do {} while (0)
1140 #define KERNEL_DEBUG_EARLY(x, a, b, c, d) do {} while (0)
1141 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
1142
1143 /*
1144 * KERNEL_DEBUG_CONSTANT_IST (in-system trace) events provide an audited subset
1145 * of tracepoints for userland system tracing tools. This tracing level was
1146 * created by 8857227 to protect fairplayd and other PT_DENY_ATTACH processes.
1147 * It has two effects: only KERNEL_DEBUG_CONSTANT_IST() traces are emitted and
1148 * any PT_DENY_ATTACH processes will only emit basic traces as defined by the
1149 * kernel_debug_filter() routine.
1150 */
1151 #define KERNEL_DEBUG_CONSTANT_RELEASE(x, a, b, c, d, e) \
1152 KERNEL_DEBUG_CONSTANT_IST(~KDEBUG_ENABLE_PPT, x, a, b, c, d, 0)
1153
1154 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST)
1155 #define KERNEL_DEBUG_CONSTANT_IST(type, x, a, b, c, d, e) \
1156 do { \
1157 if (KDBG_IMPROBABLE(kdebug_enable & (type))) { \
1158 kernel_debug((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \
1159 (uintptr_t)(d), 0); \
1160 } \
1161 } while (0)
1162 #define KERNEL_DEBUG_CONSTANT_IST1(x, a, b, c, d, e) \
1163 do { \
1164 if (KDBG_IMPROBABLE(kdebug_enable)) { \
1165 kernel_debug1((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \
1166 (uintptr_t)(d), (uintptr_t)(e)); \
1167 } \
1168 } while (0)
1169 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
1170 #define KERNEL_DEBUG_CONSTANT_IST(type, x, a, b, c, d, e) do {} while (0)
1171 #define KERNEL_DEBUG_CONSTANT_IST1(x, a, b, c, d, e) do {} while (0)
1172 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
1173
1174 #if NO_KDEBUG
1175 #define __kdebug_constant_only __unused
1176 #endif
1177
1178 /*
1179 * KERNEL_DEBUG events are only traced for DEBUG kernels.
1180 */
1181 #define KERNEL_DEBUG_CONSTANT_DEBUG(x, a, b, c, d, e) \
1182 KERNEL_DEBUG(x, a, b, c, d, e)
1183
1184 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL)
1185 #define __kdebug_only
1186
1187 #define KERNEL_DEBUG(x, a, b, c, d, e) \
1188 do { \
1189 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1190 kernel_debug((uint32_t)(x), (uintptr_t)(a), (uintptr_t)(b), \
1191 (uintptr_t)(c), (uintptr_t)(d), (uintptr_t)(e)); \
1192 } \
1193 } while (0)
1194
1195 /*
1196 * DO NOT USE THIS MACRO -- see warning above for KERNEL_DEBUG_CONSTANT1.
1197 */
1198 #define KERNEL_DEBUG1(x, a, b, c, d, e) \
1199 do { \
1200 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1201 kernel_debug1((uint32_t)(x), (uintptr_t)(a), (uintptr_t)(b), \
1202 (uintptr_t)(c), (uintptr_t)(d), (uintptr_t)(e)); \
1203 } \
1204 } while (0)
1205
1206 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
1207 #define __kdebug_only __unused
1208
1209 #define KERNEL_DEBUG(x,a,b,c,d,e) do {} while (0)
1210 #define KERNEL_DEBUG1(x,a,b,c,d,e) do {} while (0)
1211 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
1212
1213
1214 extern void kernel_debug(
1215 uint32_t debugid,
1216 uintptr_t arg1,
1217 uintptr_t arg2,
1218 uintptr_t arg3,
1219 uintptr_t arg4,
1220 uintptr_t arg5);
1221
1222 extern void kernel_debug1(
1223 uint32_t debugid,
1224 uintptr_t arg1,
1225 uintptr_t arg2,
1226 uintptr_t arg3,
1227 uintptr_t arg4,
1228 uintptr_t arg5);
1229
1230 extern void kernel_debug_filtered(
1231 uint32_t debugid,
1232 uintptr_t arg1,
1233 uintptr_t arg2,
1234 uintptr_t arg3,
1235 uintptr_t arg4);
1236
1237 extern void kernel_debug_early(
1238 uint32_t debugid,
1239 uintptr_t arg1,
1240 uintptr_t arg2,
1241 uintptr_t arg3,
1242 uintptr_t arg4);
1243
1244 /*
1245 * EnergyTracing macros.
1246 */
1247
1248 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST)
1249 // whether to bother calculating EnergyTracing inputs
1250 // could change in future to see if DBG_ENERGYTRACE is active
1251 #define ENTR_SHOULDTRACE kdebug_enable
1252 // encode logical EnergyTracing into 32/64 KDebug trace
1253 #define ENTR_KDTRACE(component, opcode, lifespan, id, quality, value) \
1254 do { \
1255 uint32_t kdcode__; \
1256 uintptr_t highval__, lowval__, mask__ = 0xffffffff; \
1257 kdcode__ = KDBG_CODE(DBG_ENERGYTRACE,component,opcode)|(lifespan); \
1258 highval__ = ((value) >> 32) & mask__; \
1259 lowval__ = (value) & mask__; \
1260 ENTR_KDTRACEFUNC(kdcode__, id, quality, highval__, lowval__); \
1261 } while(0)
1262
1263 /*
1264 Trace the association of two existing activations.
1265
1266 An association is traced as a modification to the parent activation.
1267 In order to fit the sub-activation's component, activation code, and
1268 activation ID into a kdebug tracepoint, the arguments that would hold
1269 the value are left separate, and one stores the component and opcode
1270 of the sub-activation, while the other stores the pointer-sized
1271 activation ID.
1272
1273 arg2 arg3 arg4
1274 +-----------------+ +~+----+----+--------+ +----------+
1275 |kEnTrModAssociate| | | | | | | |
1276 +-----------------+ +~+----+----+--------+ +----------+
1277 8-bits unused sub-activation ID
1278 8-bit sub-component
1279 16-bit sub-opcode
1280
1281 */
1282 #define kEnTrModAssociate (1 << 28)
1283 #define ENTR_KDASSOCIATE(par_comp, par_opcode, par_act_id, \
1284 sub_comp, sub_opcode, sub_act_id) \
1285 do { \
1286 unsigned sub_compcode = ((unsigned)sub_comp << 16) | sub_opcode; \
1287 ENTR_KDTRACEFUNC(KDBG_CODE(DBG_ENERGYTRACE,par_comp,par_opcode), \
1288 par_act_id, kEnTrModAssociate, sub_compcode, \
1289 sub_act_id); \
1290 } while(0)
1291
1292 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
1293
1294 #define ENTR_SHOULDTRACE FALSE
1295 #define ENTR_KDTRACE(component, opcode, lifespan, id, quality, value) \
1296 do {} while (0)
1297 #define ENTR_KDASSOCIATE(par_comp, par_opcode, par_act_id, \
1298 sub_comp, sub_opcode, sub_act_id) \
1299 do {} while (0)
1300
1301 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
1302
1303 #ifdef KERNEL_PRIVATE
1304 /*
1305 * kernel_debug_string provides the same functionality as the
1306 * kdebug_trace_string syscall as a KPI. str_id is an in/out
1307 * parameter that, if it's pointing to a string ID of 0, will
1308 * receive a generated ID. If it provides a value in str_id,
1309 * then that will be used, instead.
1310 *
1311 * Returns an errno indicating the type of failure.
1312 */
1313 extern int
1314 kernel_debug_string(uint32_t debugid, uint64_t *str_id, const char *str);
1315
1316 /*
1317 * kernel_debug_disable disables event logging, but leaves any buffers
1318 * intact.
1319 */
1320 extern void kernel_debug_disable(void);
1321 #endif
1322
1323 /*
1324 * Bits set in the comm page for kdebug.
1325 */
1326 #define KDEBUG_COMMPAGE_ENABLE_TRACE 0x1
1327 #define KDEBUG_COMMPAGE_ENABLE_TYPEFILTER 0x2 /* Forced to false if ENABLE_TRACE is 0 */
1328
1329 // for EnergyTracing user space & clients
1330 #define kEnTrCompKernel 2
1331
1332 /*
1333 EnergyTracing opcodes
1334
1335 Activations use DBG_FUNC_START/END.
1336 Events are DBG_FUNC_NONE.
1337 */
1338
1339 /* Socket reads and writes are uniquely identified by the (sanitized)
1340 pointer to the socket struct in question. To associate this address
1341 with the user space file descriptor, we have a socket activation with
1342 the FD as its identifier and the socket struct pointer as its value.
1343 */
1344 #define kEnTrActKernSocket 1
1345 #define kEnTrActKernSockRead 2
1346 #define kEnTrActKernSockWrite 3
1347
1348 #define kEnTrActKernPoll 10
1349 #define kEnTrActKernSelect 11
1350 #define kEnTrActKernKQWait 12
1351
1352 // events
1353 #define kEnTrEvUnblocked 256
1354
1355 // EnergyTracing flags (the low-order 16 bits of 'quality')
1356 #define kEnTrFlagNonBlocking 1 << 0
1357 #define kEnTrFlagNoWork 1 << 1
1358
1359 // and now the internal mechanism
1360 #ifdef KERNEL_PRIVATE
1361
1362 // 20452597 requests that the trace macros not take an argument it throws away
1363 #define KERNEL_DBG_IST_SANE(x, a, b, c, d) \
1364 KERNEL_DEBUG_CONSTANT_IST(KDEBUG_TRACE, x, a, b, c, d, \
1365 0 /*__unused in kernel_debug()*/)
1366 #define ENTR_KDTRACEFUNC KERNEL_DBG_IST_SANE
1367
1368 // value is int64_t, quality is uint32_t
1369 #define KERNEL_ENERGYTRACE(opcode, lifespan, id, quality, value) \
1370 ENTR_KDTRACE(kEnTrCompKernel, opcode, lifespan, id, \
1371 quality, value)
1372 #define KERNEL_ENTR_ASSOCIATE(par_opcode, par_act_id, sub_opcode, sub_act_id) \
1373 ENTR_KDASSOCIATE(kEnTrCompKernel, par_opcode, par_act_id, \
1374 kEnTrCompKernel, sub_opcode, sub_act_id)
1375
1376 // end EnergyTracing
1377
1378
1379 #include <mach/boolean.h>
1380
1381 #define NUMPARMS 23
1382
1383 struct proc;
1384
1385 /*
1386 * Returns false if the debugid is disabled by filters, and true if the
1387 * debugid is allowed to be traced. A debugid may not be traced if the
1388 * typefilter disables its class and subclass, it's outside a range
1389 * check, or if it's not an allowed debugid in a value check. Trace
1390 * system events bypass this check.
1391 */
1392 boolean_t kdebug_debugid_enabled(uint32_t debugid);
1393
1394 /*
1395 * Returns true only if the debugid is explicitly enabled by filters. Returns
1396 * false otherwise, including when no filters are active.
1397 */
1398 boolean_t kdebug_debugid_explicitly_enabled(uint32_t debugid);
1399
1400 uint32_t kdebug_commpage_state(void);
1401 void kdebug_lookup_gen_events(long *dbg_parms, int dbg_namelen, void *dp, boolean_t lookup);
1402 void kdbg_trace_data(struct proc *proc, long *arg_pid, long *arg_uniqueid);
1403
1404 void kdbg_trace_string(struct proc *proc, long *arg1, long *arg2, long *arg3, long *arg4);
1405
1406 void kdbg_dump_trace_to_file(const char *);
1407 void kdebug_init(unsigned int n_events, char *filterdesc, boolean_t wrapping);
1408 void kdebug_trace_start(unsigned int n_events, const char *filterdesc,
1409 boolean_t wrapping, boolean_t at_wake);
1410 void kdebug_free_early_buf(void);
1411 struct task;
1412 boolean_t disable_wrap(uint32_t *old_slowcheck, uint32_t *old_flags);
1413 void enable_wrap(uint32_t old_slowcheck, boolean_t lostevents);
1414 void release_storage_unit(int cpu, uint32_t storage_unit);
1415 int allocate_storage_unit(int cpu);
1416
1417 #define KDBG_CLASS_ENCODE(Class, SubClass) KDBG_EVENTID(Class, SubClass, 0)
1418 #define KDBG_CLASS_DECODE(Debugid) (Debugid & KDBG_CSC_MASK)
1419
1420 #endif /* KERNEL_PRIVATE */
1421 #endif /* __APPLE_API_UNSTABLE */
1422 __END_DECLS
1423
1424 #ifdef PRIVATE
1425 #ifdef __APPLE_API_PRIVATE
1426 /*
1427 * private kernel_debug definitions
1428 */
1429
1430 typedef struct {
1431 uint64_t timestamp;
1432 uintptr_t arg1;
1433 uintptr_t arg2;
1434 uintptr_t arg3;
1435 uintptr_t arg4;
1436 uintptr_t arg5; /* the thread ID */
1437 uint32_t debugid;
1438 #if defined(__LP64__)
1439 uint32_t cpuid;
1440 uintptr_t unused;
1441 #endif
1442 } kd_buf;
1443
1444 #if !defined(__LP64__)
1445 #define KDBG_TIMESTAMP_MASK 0x00ffffffffffffffULL
1446 #define KDBG_CPU_MASK 0xff00000000000000ULL
1447 #define KDBG_CPU_SHIFT 56
1448 static inline void
1449 kdbg_set_cpu(kd_buf *kp, int cpu)
1450 {
1451 kp->timestamp = (kp->timestamp & KDBG_TIMESTAMP_MASK) |
1452 (((uint64_t) cpu) << KDBG_CPU_SHIFT);
1453 }
1454 static inline int
1455 kdbg_get_cpu(kd_buf *kp)
1456 {
1457 return (int) (((kp)->timestamp & KDBG_CPU_MASK) >> KDBG_CPU_SHIFT);
1458 }
1459 static inline void
1460 kdbg_set_timestamp(kd_buf *kp, uint64_t thetime)
1461 {
1462 kp->timestamp = thetime & KDBG_TIMESTAMP_MASK;
1463 }
1464 static inline uint64_t
1465 kdbg_get_timestamp(kd_buf *kp)
1466 {
1467 return kp->timestamp & KDBG_TIMESTAMP_MASK;
1468 }
1469 static inline void
1470 kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu)
1471 {
1472 kp->timestamp = (thetime & KDBG_TIMESTAMP_MASK) |
1473 (((uint64_t) cpu) << KDBG_CPU_SHIFT);
1474 }
1475 #else
1476 #define KDBG_TIMESTAMP_MASK 0xffffffffffffffffULL
1477 static inline void
1478 kdbg_set_cpu(kd_buf *kp, int cpu)
1479 {
1480 kp->cpuid = (unsigned int)cpu;
1481 }
1482 static inline int
1483 kdbg_get_cpu(kd_buf *kp)
1484 {
1485 return (int)kp->cpuid;
1486 }
1487 static inline void
1488 kdbg_set_timestamp(kd_buf *kp, uint64_t thetime)
1489 {
1490 kp->timestamp = thetime;
1491 }
1492 static inline uint64_t
1493 kdbg_get_timestamp(kd_buf *kp)
1494 {
1495 return kp->timestamp;
1496 }
1497 static inline void
1498 kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu)
1499 {
1500 kdbg_set_timestamp(kp, thetime);
1501 kdbg_set_cpu(kp, cpu);
1502 }
1503 #endif
1504
1505 /*
1506 * 2^16 bits (8 kilobytes), one for each possible class/subclass combination
1507 */
1508 #define KDBG_TYPEFILTER_BITMAP_SIZE ((256 * 256) / 8)
1509
1510 /*
1511 * Bits for kd_ctrl_page.flags, KERN_KD{D,E}FLAGS.
1512 */
1513 #define KDBG_INIT (1U << 0) /* obsolete */
1514 /* disable tracing when buffers are full */
1515 #define KDBG_NOWRAP (1U << 1)
1516 #define KDBG_FREERUN (1U << 2) /* obsolete */
1517 /* buffer has wrapped */
1518 #define KDBG_WRAPPED (1U << 3)
1519 /* flags that are allowed to be set by user space */
1520 #define KDBG_USERFLAGS (KDBG_FREERUN | KDBG_NOWRAP | KDBG_INIT)
1521 /* only include processes with kdebug bit set in proc */
1522 #define KDBG_PIDCHECK (1U << 4)
1523 /* thread map is initialized */
1524 #define KDBG_MAPINIT (1U << 5)
1525 /* exclude processes based on kdebug bit in proc */
1526 #define KDBG_PIDEXCLUDE (1U << 6)
1527 /* whether the kdebug locks are intialized */
1528 #define KDBG_LOCKINIT (1U << 7)
1529 /* word size of the kernel */
1530 #define KDBG_LP64 (1U << 8)
1531
1532 /* bits for kd_ctrl_page.flags and kbufinfo_t.flags */
1533
1534 /* only trace events within a range */
1535 #define KDBG_RANGECHECK 0x00100000U
1536 /* only trace at most 4 types of events, at the code granularity */
1537 #define KDBG_VALCHECK 0x00200000U
1538 /* check class and subclass against the typefilter */
1539 #define KDBG_TYPEFILTER_CHECK 0x00400000U
1540 /* kdebug trace buffers are initialized */
1541 #define KDBG_BUFINIT 0x80000000U
1542
1543 /* bits for the type field of kd_regtype */
1544 #define KDBG_CLASSTYPE 0x10000
1545 #define KDBG_SUBCLSTYPE 0x20000
1546 #define KDBG_RANGETYPE 0x40000
1547 #define KDBG_TYPENONE 0x80000
1548 #define KDBG_CKTYPES 0xF0000
1549
1550 typedef struct {
1551 unsigned int type;
1552 unsigned int value1;
1553 unsigned int value2;
1554 unsigned int value3;
1555 unsigned int value4;
1556 } kd_regtype;
1557
1558 typedef struct {
1559 /* number of events that can fit in the buffers */
1560 int nkdbufs;
1561 /* set if trace is disabled */
1562 int nolog;
1563 /* kd_ctrl_page.flags */
1564 unsigned int flags;
1565 /* number of threads in thread map */
1566 int nkdthreads;
1567 /* the owning pid */
1568 int bufid;
1569 } kbufinfo_t;
1570
1571 typedef struct {
1572 /* the thread ID */
1573 uintptr_t thread;
1574 /* 0 for invalid, otherwise the PID (or 1 for kernel_task) */
1575 int valid;
1576 /* the name of the process owning the thread */
1577 char command[20];
1578 } kd_threadmap;
1579
1580 typedef struct {
1581 uint32_t version_no;
1582 uint32_t cpu_count;
1583 } kd_cpumap_header;
1584
1585 /* cpumap flags */
1586 #define KDBG_CPUMAP_IS_IOP 0x1
1587
1588 typedef struct {
1589 uint32_t cpu_id;
1590 uint32_t flags;
1591 char name[8];
1592 } kd_cpumap;
1593
1594 /*
1595 * TRACE file formats...
1596 *
1597 * RAW_VERSION0
1598 *
1599 * uint32_t #threadmaps
1600 * kd_threadmap[]
1601 * kd_buf[]
1602 *
1603 * RAW_VERSION1
1604 *
1605 * RAW_header, with version_no set to RAW_VERSION1
1606 * kd_threadmap[]
1607 * Empty space to pad alignment to the nearest page boundary.
1608 * kd_buf[]
1609 *
1610 * RAW_VERSION1+
1611 *
1612 * RAW_header, with version_no set to RAW_VERSION1
1613 * kd_threadmap[]
1614 * kd_cpumap_header, with version_no set to RAW_VERSION1
1615 * kd_cpumap[]
1616 * Empty space to pad alignment to the nearest page boundary.
1617 * kd_buf[]
1618 *
1619 * V1+ implementation details...
1620 *
1621 * It would have been nice to add the cpumap data "correctly", but there were
1622 * several obstacles. Existing code attempts to parse both V1 and V0 files.
1623 * Due to the fact that V0 has no versioning or header, the test looks like
1624 * this:
1625 *
1626 * // Read header
1627 * if (header.version_no != RAW_VERSION1) { // Assume V0 }
1628 *
1629 * If we add a VERSION2 file format, all existing code is going to treat that
1630 * as a VERSION0 file when reading it, and crash terribly when trying to read
1631 * RAW_VERSION2 threadmap entries.
1632 *
1633 * To differentiate between a V1 and V1+ file, read as V1 until you reach
1634 * the padding bytes. Then:
1635 *
1636 * boolean_t is_v1plus = FALSE;
1637 * if (padding_bytes >= sizeof(kd_cpumap_header)) {
1638 * kd_cpumap_header header = // read header;
1639 * if (header.version_no == RAW_VERSION1) {
1640 * is_v1plus = TRUE;
1641 * }
1642 * }
1643 *
1644 */
1645
1646 typedef struct {
1647 int version_no;
1648 int thread_count;
1649 uint64_t TOD_secs;
1650 uint32_t TOD_usecs;
1651 } RAW_header;
1652
1653 // Version 3 header
1654 // The header chunk has the tag 0x00001000 which also serves as a magic word
1655 // that identifies the file as a version 3 trace file. The header payload is
1656 // a set of fixed fields followed by a variable number of sub-chunks:
1657 /*
1658 ____________________________________________________________________________
1659 | Offset | Size | Field |
1660 ----------------------------------------------------------------------------
1661 | 0 | 4 | Tag (0x00001000) |
1662 | 4 | 4 | Sub-tag. Represents the version of the header. |
1663 | 8 | 8 | Length of header payload (40+8x) |
1664 | 16 | 8 | Time base info. Two 32-bit numbers, numer/denom, |
1665 | | | for converting timestamps to nanoseconds. |
1666 | 24 | 8 | Timestamp of trace start. |
1667 | 32 | 8 | Wall time seconds since Unix epoch. |
1668 | | | As returned by gettimeofday(). |
1669 | 40 | 4 | Wall time microseconds. As returned by gettimeofday(). |
1670 | 44 | 4 | Local time zone offset in minutes. ( " ) |
1671 | 48 | 4 | Type of daylight savings time correction to apply. ( " ) |
1672 | 52 | 4 | Flags. 1 = 64-bit. Remaining bits should be written |
1673 | | | as 0 and ignored when reading. |
1674 | 56 | 8x | Variable number of sub-chunks. None are required. |
1675 | | | Ignore unknown chunks. |
1676 ----------------------------------------------------------------------------
1677 */
1678 // NOTE: The header sub-chunks are considered part of the header chunk,
1679 // so they must be included in the header chunk’s length field.
1680 // The CPU map is an optional sub-chunk of the header chunk. It provides
1681 // information about the CPUs that are referenced from the trace events.
1682 typedef struct {
1683 uint32_t tag;
1684 uint32_t sub_tag;
1685 uint64_t length;
1686 uint32_t timebase_numer;
1687 uint32_t timebase_denom;
1688 uint64_t timestamp;
1689 uint64_t walltime_secs;
1690 uint32_t walltime_usecs;
1691 uint32_t timezone_minuteswest;
1692 uint32_t timezone_dst;
1693 uint32_t flags;
1694 } __attribute__((packed)) kd_header_v3;
1695
1696 typedef struct {
1697 uint32_t tag;
1698 uint32_t sub_tag;
1699 uint64_t length;
1700 } __attribute__((packed)) kd_chunk_header_v3;
1701
1702 #define RAW_VERSION0 0x55aa0000
1703 #define RAW_VERSION1 0x55aa0101
1704 #define RAW_VERSION2 0x55aa0200 /* Only used by kperf and Instruments */
1705 #define RAW_VERSION3 0x00001000
1706
1707 #define V3_CONFIG 0x00001b00
1708 #define V3_CPU_MAP 0x00001c00
1709 #define V3_THREAD_MAP 0x00001d00
1710 #define V3_RAW_EVENTS 0x00001e00
1711 #define V3_NULL_CHUNK 0x00002000
1712
1713 // The current version of all kernel managed chunks is 1. The
1714 // V3_CURRENT_CHUNK_VERSION is added to ease the simple case
1715 // when most/all the kernel managed chunks have the same version.
1716
1717 #define V3_CURRENT_CHUNK_VERSION 1
1718 #define V3_HEADER_VERSION V3_CURRENT_CHUNK_VERSION
1719 #define V3_CPUMAP_VERSION V3_CURRENT_CHUNK_VERSION
1720 #define V3_THRMAP_VERSION V3_CURRENT_CHUNK_VERSION
1721 #define V3_EVENT_DATA_VERSION V3_CURRENT_CHUNK_VERSION
1722
1723 // Apis to support writing v3 chunks in the kernel
1724 int kdbg_write_v3_chunk_header_to_buffer(void *buffer, uint32_t tag, uint32_t sub_tag, uint64_t length);
1725 int kdbg_write_v3_chunk_to_fd(uint32_t tag, uint32_t sub_tag, uint64_t length, void *payload, uint64_t payload_size, int fd);
1726
1727 /* VFS lookup events for serial traces */
1728 #define VFS_LOOKUP (FSDBG_CODE(DBG_FSRW,36))
1729 #define VFS_LOOKUP_DONE (FSDBG_CODE(DBG_FSRW,39))
1730
1731 #if !CONFIG_EMBEDDED
1732 #if defined(XNU_KERNEL_PRIVATE) && (DEVELOPMENT || DEBUG)
1733 #define KDEBUG_MOJO_TRACE 1
1734 #endif
1735 #endif
1736
1737 #endif /* __APPLE_API_PRIVATE */
1738 #endif /* PRIVATE */
1739
1740 #endif /* !BSD_SYS_KDEBUG_H */