2 * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 * kdebug.h - kernel_debug definitions
33 #ifndef BSD_SYS_KDEBUG_H
34 #define BSD_SYS_KDEBUG_H
36 #include <sys/appleapiopts.h>
37 #include <sys/cdefs.h>
41 #ifdef __APPLE_API_UNSTABLE
43 #include <mach/clock_types.h>
47 #include <Availability.h>
51 * Kdebug is a facility for tracing events occurring on a system.
53 * All events are tagged with a 32-bit debugid:
55 * +----------------+----------------+----------------------------+----+
56 * | Class (8) | Subclass (8) | Code (14) |Func|
58 * +----------------+----------------+----------------------------+----+
59 * \_________________________________/
61 * \________________________________________________________________00_/
63 * \___________________________________________________________________/
66 * The eventid is a hierarchical ID, indicating which components an event is
67 * referring to. The debugid includes an eventid and two function qualifier
68 * bits, to determine the structural significance of an event (whether it
69 * starts or ends an interval).
72 #define KDBG_CLASS_MASK (0xff000000)
73 #define KDBG_CLASS_OFFSET (24)
74 #define KDBG_CLASS_MAX (0xff)
76 #define KDBG_SUBCLASS_MASK (0x00ff0000)
77 #define KDBG_SUBCLASS_OFFSET (16)
78 #define KDBG_SUBCLASS_MAX (0xff)
80 /* class and subclass mask */
81 #define KDBG_CSC_MASK (0xffff0000)
82 #define KDBG_CSC_OFFSET (KDBG_SUBCLASS_OFFSET)
83 #define KDBG_CSC_MAX (0xffff)
85 #define KDBG_CODE_MASK (0x0000fffc)
86 #define KDBG_CODE_OFFSET (2)
87 #define KDBG_CODE_MAX (0x3fff)
89 #define KDBG_EVENTID_MASK (0xfffffffc)
90 #define KDBG_FUNC_MASK (0x00000003)
92 /* Generate an eventid corresponding to Class, SubClass, and Code. */
93 #define KDBG_EVENTID(Class, SubClass, Code) \
94 ((((Class) & 0xff) << KDBG_CLASS_OFFSET) | \
95 (((SubClass) & 0xff) << KDBG_SUBCLASS_OFFSET) | \
96 (((Code) & 0x3fff) << KDBG_CODE_OFFSET))
97 /* Deprecated macro using old naming convention. */
98 #define KDBG_CODE(Class, SubClass, Code) \
99 KDBG_EVENTID(Class, SubClass, Code)
101 /* Extract pieces of the debug code. */
102 #define KDBG_EXTRACT_CLASS(Debugid) \
103 ((uint8_t)(((Debugid) & KDBG_CLASS_MASK) >> KDBG_CLASS_OFFSET))
104 #define KDBG_EXTRACT_SUBCLASS(Debugid) \
105 ((uint8_t)(((Debugid) & KDBG_SUBCLASS_MASK) >> KDBG_SUBCLASS_OFFSET))
106 #define KDBG_EXTRACT_CSC(Debugid) \
107 ((uint16_t)(((Debugid) & KDBG_CSC_MASK) >> KDBG_CSC_OFFSET))
108 #define KDBG_EXTRACT_CODE(Debugid) \
109 ((uint16_t)(((Debugid) & KDBG_CODE_MASK) >> KDBG_CODE_OFFSET))
111 /* function qualifiers */
112 #define DBG_FUNC_START 1
113 #define DBG_FUNC_END 2
114 #define DBG_FUNC_NONE 0
117 * Definitions to support IOP tracing.
120 #ifdef KERNEL_PRIVATE
123 /* Trace is now enabled; no arguments. */
124 KD_CALLBACK_KDEBUG_ENABLED
,
125 /* Trace is now disabled; no arguments. */
126 KD_CALLBACK_KDEBUG_DISABLED
,
128 * Request the latest entries from the IOP and block until complete; no
131 KD_CALLBACK_SYNC_FLUSH
,
133 * The typefilter is enabled; a read-only pointer to the typefilter is
134 * provided, valid only while in the callback.
136 KD_CALLBACK_TYPEFILTER_CHANGED
,
138 typedef void (*kd_callback_fn
) (void* context
, kd_callback_type reason
, void* arg
);
143 /* name of IOP, NUL-terminated */
147 typedef struct kd_callback kd_callback_t
;
150 * Registers an IOP for participation in tracing.
152 * The registered callback function will be called with the
153 * supplied context as the first argument, followed by a
154 * kd_callback_type and an associated void* argument.
156 * The return value is a nonzero coreid that shall be used in
157 * kernel_debug_enter() to refer to your IOP. If the allocation
158 * failed, then 0 will be returned.
161 * Note that not all callback calls will indicate a change in
162 * state (e.g. disabling trace twice would send two disable
165 extern int kernel_debug_register_callback(kd_callback_t callback
);
167 extern void kernel_debug_enter(
178 #endif /* KERNEL_PRIVATE */
180 /* The Kernel Debug Classes */
182 #define DBG_NETWORK 2
183 #define DBG_FSYSTEM 3
186 #define DBG_DRIVERS 6
189 #define DBG_PTHREAD 9
190 #define DBG_CORESTORAGE 10
192 #define DBG_MONOTONIC 12
194 #define DBG_SECURITY 30
198 #define DBG_LAUNCHD 34
200 #define DBG_IMPORTANCE 38
204 #define DBG_ARIADNE 43
205 #define DBG_DAEMON 44
206 #define DBG_ENERGYTRACE 45
207 #define DBG_DISPATCH 46
209 #define DBG_UMALLOC 51
210 #define DBG_TURNSTILE 53
218 * Private kdebug userspace API
224 * OS components can use the full precision of the "code" field
225 * (Class, SubClass, Code) to inject events using kdebug_trace() by
228 * kdebug_trace(KDBG_CODE(DBG_XPC, 15, 1) | DBG_FUNC_NONE, 1, 2, 3, 4);
230 * These trace points can be included in production code, since they
231 * use reserved, non-overlapping ranges. The performance impact when
232 * kernel tracing is not enabled is minimal. Classes can be reserved
233 * by filing a Radar in xnu|all.
235 * 64-bit arguments may be truncated if the system is using a 32-bit
238 * On error, -1 will be returned and errno will indicate the error.
240 extern int kdebug_trace(
246 __OSX_AVAILABLE(10.10.2) __IOS_AVAILABLE(8.2);
249 * @function kdebug_trace_string
252 * This function emits strings to kdebug trace along with an ID and allows
253 * for previously-traced strings to be overwritten and invalidated.
255 * To start tracing a string and generate an ID to use to refer to it:
257 * string_id = kdebug_trace_string(debugid, 0, "string");
259 * To replace a string previously traced:
261 * string_id = kdebug_trace_string(debugid, string_id, "new string");
263 * To invalidate a string ID:
265 * string_id = kdebug_trace_string(debugid, string_id, NULL);
267 * To check for errors:
269 * if ((int64_t)string_id == -1) { perror("string error") }
272 * The `debugid` to check if its enabled before tracing and include as
273 * an argument in the event containing the string.
275 * Some classes or subclasses are reserved for specific uses and are not
276 * allowed to be used with this function. No function qualifiers are
277 * allowed on `debugid`.
280 * When 0, a new ID will be generated and returned if tracing is
283 * Otherwise `str_id` must contain an ID that was previously generated
284 * with this function. Clents should pass NULL in `str` if `str_id`
285 * is no longer in use. Otherwise, the string previously mapped to
286 * `str_id` will be overwritten with the contents of `str`.
289 * A NUL-terminated 'C' string containing the characters that should be
290 * traced alongside `str_id`.
292 * If necessary, the string will be truncated at an
293 * implementation-defined length. The string must not be the empty
294 * string, but can be NULL if a valid `str_id` is provided.
297 * 0 if tracing is disabled or `debugid` is being filtered out of trace.
298 * It can also return (int64_t)-1 if an error occured. Otherwise,
299 * it returns the ID to use to refer to the string in future
300 * kdebug_trace(2) calls.
302 * The errors that can occur are:
305 * There are function qualifiers on `debugid`, `str` is empty, or
306 * `str_id` was not generated by this function.
308 * The `debugid`'s class or subclass is reserved for internal use.
310 * `str` is an invalid address or NULL when `str_id` is 0.
312 extern uint64_t kdebug_trace_string(uint32_t debugid
, uint64_t str_id
,
314 __OSX_AVAILABLE(10.11) __IOS_AVAILABLE(9.0);
317 * Although the performance impact of kdebug_trace() when kernel
318 * tracing is not enabled is minimal, it may require the caller to
319 * perform an expensive calculation/summarization. This cost can be
320 * skipped by checking the kdebug_is_enabled() predicate:
322 * if (kdebug_is_enabled(KDBG_CODE(DBG_XPC, 15, 1))) {
323 * uint64_t arg1 = ...;
324 * uint64_t arg2 = ...;
325 * kdebug_trace(KDBG_CODE(DBG_XPC, 15, 1) | DBG_FUNC_NONE, arg1, arg2, 0, 0);
328 * If tracing is enabled for the code at the time of the check, 1
329 * will be returned. Otherwise, 0 will be returned.
331 extern bool kdebug_is_enabled(uint32_t code
)
332 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
333 __WATCHOS_AVAILABLE(3.0) __TVOS_AVAILABLE(10.0);
336 * Returns a pointer to the userspace typefilter, if one is available.
339 extern void *kdebug_typefilter(void)
340 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
341 __WATCHOS_AVAILABLE(3.0) __TVOS_AVAILABLE(10.0);
343 #endif /* !KERNEL (Private kdebug userspace API) */
346 #ifdef XNU_KERNEL_PRIVATE
347 /* Used in early boot to log strings spanning only a single tracepoint. */
348 extern void kernel_debug_string_early(const char *message
);
349 /* Used to trace strings within kdebug tracepoints on arbitrary eventids. */
350 extern void kernel_debug_string_simple(uint32_t eventid
, const char *str
);
351 /* Only used by ktrace to reset kdebug. ktrace_lock must be held. */
352 extern void kdebug_reset(void);
353 #endif /* XNU_KERNEL_PRIVATE */
355 /* **** The Kernel Debug Sub Classes for Mach (DBG_MACH) **** */
356 #define DBG_MACH_EXCP_KTRAP_x86 0x02 /* Kernel Traps on x86 */
357 #define DBG_MACH_EXCP_DFLT 0x03 /* Data Translation Fault */
358 #define DBG_MACH_EXCP_IFLT 0x04 /* Inst Translation Fault */
359 #define DBG_MACH_EXCP_INTR 0x05 /* Interrupts */
360 #define DBG_MACH_EXCP_ALNG 0x06 /* Alignment Exception */
361 #define DBG_MACH_EXCP_UTRAP_x86 0x07 /* User Traps on x86 */
362 #define DBG_MACH_EXCP_FP 0x08 /* FP Unavail */
363 #define DBG_MACH_EXCP_DECI 0x09 /* Decrementer Interrupt */
364 #define DBG_MACH_CHUD 0x0A /* deprecated name */
365 #define DBG_MACH_SIGNPOST 0x0A /* kernel signposts */
366 #define DBG_MACH_EXCP_SC 0x0C /* System Calls */
367 #define DBG_MACH_EXCP_TRACE 0x0D /* Trace exception */
368 #define DBG_MACH_EXCP_EMUL 0x0E /* Instruction emulated */
369 #define DBG_MACH_IHDLR 0x10 /* Interrupt Handlers */
370 #define DBG_MACH_IPC 0x20 /* Inter Process Comm */
371 #define DBG_MACH_RESOURCE 0x25 /* tracing limits, etc */
372 #define DBG_MACH_VM 0x30 /* Virtual Memory */
373 #define DBG_MACH_LEAKS 0x31 /* alloc/free */
374 #define DBG_MACH_WORKINGSET 0x32 /* private subclass for working set related debugging */
375 #define DBG_MACH_SCHED 0x40 /* Scheduler */
376 #define DBG_MACH_MSGID_INVALID 0x50 /* Messages - invalid */
377 #define DBG_MACH_LOCKS 0x60 /* new lock APIs */
378 #define DBG_MACH_PMAP 0x70 /* pmap */
379 #define DBG_MACH_CLOCK 0x80 /* clock */
380 #define DBG_MACH_MP 0x90 /* MP related */
381 #define DBG_MACH_VM_PRESSURE 0xA0 /* Memory Pressure Events */
382 #define DBG_MACH_STACKSHOT 0xA1 /* Stackshot/Microstackshot subsystem */
383 #define DBG_MACH_SFI 0xA2 /* Selective Forced Idle (SFI) */
384 #define DBG_MACH_ENERGY_PERF 0xA3 /* Energy/performance resource stats */
385 #define DBG_MACH_SYSDIAGNOSE 0xA4 /* sysdiagnose */
386 #define DBG_MACH_ZALLOC 0xA5 /* Zone allocator */
387 #define DBG_MACH_THREAD_GROUP 0xA6 /* Thread groups */
388 #define DBG_MACH_COALITION 0xA7 /* Coalitions */
389 #define DBG_MACH_SHAREDREGION 0xA8 /* Shared region */
390 #define DBG_MACH_IO 0xAA /* I/O */
392 /* Codes for DBG_MACH_IO */
393 #define DBC_MACH_IO_MMIO_READ 0x1
394 #define DBC_MACH_IO_MMIO_WRITE 0x2
395 #define DBC_MACH_IO_PHYS_READ 0x3
396 #define DBC_MACH_IO_PHYS_WRITE 0x4
397 #define DBC_MACH_IO_PORTIO_READ 0x5
398 #define DBC_MACH_IO_PORTIO_WRITE 0x6
400 /* Interrupt type bits for DBG_MACH_EXCP_INTR */
401 #define DBG_INTR_TYPE_UNKNOWN 0x0 /* default/unknown interrupt */
402 #define DBG_INTR_TYPE_IPI 0x1 /* interprocessor interrupt */
403 #define DBG_INTR_TYPE_TIMER 0x2 /* timer interrupt */
404 #define DBG_INTR_TYPE_OTHER 0x3 /* other (usually external) interrupt */
405 #define DBG_INTR_TYPE_PMI 0x4 /* performance monitor interrupt */
407 /* Codes for Scheduler (DBG_MACH_SCHED) */
408 #define MACH_SCHED 0x0 /* Scheduler */
409 #define MACH_STACK_ATTACH 0x1 /* stack_attach() */
410 #define MACH_STACK_HANDOFF 0x2 /* stack_handoff() */
411 #define MACH_CALL_CONT 0x3 /* call_continuation() */
412 #define MACH_CALLOUT 0x4 /* callouts */
413 #define MACH_STACK_DETACH 0x5
414 #define MACH_MAKE_RUNNABLE 0x6 /* make thread runnable */
415 #define MACH_PROMOTE 0x7 /* promoted due to resource (replaced by MACH_PROMOTED) */
416 #define MACH_DEMOTE 0x8 /* promotion undone (replaced by MACH_UNPROMOTED) */
417 #define MACH_IDLE 0x9 /* processor idling */
418 #define MACH_STACK_DEPTH 0xa /* stack depth at switch */
419 #define MACH_MOVED 0xb /* did not use original scheduling decision */
420 #define MACH_PSET_LOAD_AVERAGE 0xc
421 #define MACH_AMP_DEBUG 0xd
422 #define MACH_FAILSAFE 0xe /* tripped fixed-pri/RT failsafe */
423 #define MACH_BLOCK 0xf /* thread block */
424 #define MACH_WAIT 0x10 /* thread wait assertion */
425 #define MACH_GET_URGENCY 0x14 /* Urgency queried by platform */
426 #define MACH_URGENCY 0x15 /* Urgency (RT/BG/NORMAL) communicated
429 #define MACH_REDISPATCH 0x16 /* "next thread" thread redispatched */
430 #define MACH_REMOTE_AST 0x17 /* AST signal issued to remote processor */
431 #define MACH_SCHED_CHOOSE_PROCESSOR 0x18 /* Result of choose_processor */
432 #define MACH_DEEP_IDLE 0x19 /* deep idle on master processor */
433 /* unused 0x1a was MACH_SCHED_DECAY_PRIORITY */
434 #define MACH_CPU_THROTTLE_DISABLE 0x1b /* Global CPU Throttle Disable */
435 #define MACH_RW_PROMOTE 0x1c /* promoted due to RW lock promotion */
436 #define MACH_RW_DEMOTE 0x1d /* promotion due to RW lock undone */
437 #define MACH_SCHED_MAINTENANCE 0x1f /* periodic maintenance thread */
438 #define MACH_DISPATCH 0x20 /* context switch completed */
439 #define MACH_QUANTUM_HANDOFF 0x21 /* quantum handoff occurred */
440 #define MACH_MULTIQ_DEQUEUE 0x22 /* Result of multiq dequeue */
441 #define MACH_SCHED_THREAD_SWITCH 0x23 /* attempt direct context switch to hinted thread */
442 #define MACH_SCHED_SMT_BALANCE 0x24 /* SMT load balancing ASTs */
443 #define MACH_REMOTE_DEFERRED_AST 0x25 /* Deferred AST started against remote processor */
444 #define MACH_REMOTE_CANCEL_AST 0x26 /* Canceled deferred AST for remote processor */
445 #define MACH_SCHED_CHANGE_PRIORITY 0x27 /* thread sched priority changed */
446 #define MACH_SCHED_UPDATE_REC_CORES 0x28 /* Change to recommended processor bitmask */
447 #define MACH_STACK_WAIT 0x29 /* Thread could not be switched-to because of kernel stack shortage */
448 #define MACH_THREAD_BIND 0x2a /* Thread was bound (or unbound) to a processor */
449 #define MACH_WAITQ_PROMOTE 0x2b /* Thread promoted by waitq boost */
450 #define MACH_WAITQ_DEMOTE 0x2c /* Thread demoted from waitq boost */
451 #define MACH_SCHED_LOAD 0x2d /* load update */
452 #define MACH_REC_CORES_FAILSAFE 0x2e /* recommended processor failsafe kicked in */
453 #define MACH_SCHED_QUANTUM_EXPIRED 0x2f /* thread quantum expired */
454 #define MACH_EXEC_PROMOTE 0x30 /* Thread promoted by exec boost */
455 #define MACH_EXEC_DEMOTE 0x31 /* Thread demoted from exec boost */
456 #define MACH_AMP_SIGNAL_SPILL 0x32 /* AMP spill signal sent to cpuid */
457 #define MACH_AMP_STEAL 0x33 /* AMP thread stolen or spilled */
458 #define MACH_SCHED_LOAD_EFFECTIVE 0x34 /* Effective scheduler load */
459 #define MACH_PROMOTED 0x35 /* thread promoted due to mutex priority promotion */
460 #define MACH_UNPROMOTED 0x36 /* thread unpromoted due to mutex priority promotion */
461 #define MACH_PROMOTED_UPDATE 0x37 /* thread already promoted, but promotion priority changed */
462 #define MACH_QUIESCENT_COUNTER 0x38 /* quiescent counter tick */
464 /* Variants for MACH_MULTIQ_DEQUEUE */
465 #define MACH_MULTIQ_BOUND 1
466 #define MACH_MULTIQ_GROUP 2
467 #define MACH_MULTIQ_GLOBAL 3
469 /* Arguments for vm_fault (DBG_MACH_VM) */
470 #define DBG_ZERO_FILL_FAULT 1
471 #define DBG_PAGEIN_FAULT 2
472 #define DBG_COW_FAULT 3
473 #define DBG_CACHE_HIT_FAULT 4
474 #define DBG_NZF_PAGE_FAULT 5
475 #define DBG_GUARD_FAULT 6
476 #define DBG_PAGEINV_FAULT 7
477 #define DBG_PAGEIND_FAULT 8
478 #define DBG_COMPRESSOR_FAULT 9
479 #define DBG_COMPRESSOR_SWAPIN_FAULT 10
481 /* Codes for IPC (DBG_MACH_IPC) */
482 #define MACH_TASK_SUSPEND 0x0 /* Suspended a task */
483 #define MACH_TASK_RESUME 0x1 /* Resumed a task */
484 #define MACH_THREAD_SET_VOUCHER 0x2
485 #define MACH_IPC_MSG_SEND 0x3 /* mach msg send, uniq msg info */
486 #define MACH_IPC_MSG_RECV 0x4 /* mach_msg receive */
487 #define MACH_IPC_MSG_RECV_VOUCHER_REFUSED 0x5 /* mach_msg receive, voucher refused */
488 #define MACH_IPC_KMSG_FREE 0x6 /* kernel free of kmsg data */
489 #define MACH_IPC_VOUCHER_CREATE 0x7 /* Voucher added to global voucher hashtable */
490 #define MACH_IPC_VOUCHER_CREATE_ATTR_DATA 0x8 /* Attr data for newly created voucher */
491 #define MACH_IPC_VOUCHER_DESTROY 0x9 /* Voucher removed from global voucher hashtable */
492 #define MACH_IPC_KMSG_INFO 0xa /* Send/Receive info for a kmsg */
493 #define MACH_IPC_KMSG_LINK 0xb /* link a kernel kmsg pointer to user mach_msg_header_t */
494 #define MACH_IPC_PORT_ENTRY_MODIFY 0xc /* A port space gained or lost a port right (reference) */
496 /* Codes for thread groups (DBG_MACH_THREAD_GROUP) */
497 #define MACH_THREAD_GROUP_NEW 0x0
498 #define MACH_THREAD_GROUP_FREE 0x1
499 #define MACH_THREAD_GROUP_SET 0x2
500 #define MACH_THREAD_GROUP_NAME 0x3
501 #define MACH_THREAD_GROUP_NAME_FREE 0x4
502 #define MACH_THREAD_GROUP_FLAGS 0x5
504 /* Codes for coalitions (DBG_MACH_COALITION) */
505 #define MACH_COALITION_NEW 0x0
506 #define MACH_COALITION_FREE 0x1
507 #define MACH_COALITION_ADOPT 0x2
508 #define MACH_COALITION_REMOVE 0x3
509 #define MACH_COALITION_THREAD_GROUP_SET 0x4
511 /* Codes for pmap (DBG_MACH_PMAP) */
512 #define PMAP__CREATE 0x0
513 #define PMAP__DESTROY 0x1
514 #define PMAP__PROTECT 0x2
515 #define PMAP__PAGE_PROTECT 0x3
516 #define PMAP__ENTER 0x4
517 #define PMAP__REMOVE 0x5
518 #define PMAP__NEST 0x6
519 #define PMAP__UNNEST 0x7
520 #define PMAP__FLUSH_TLBS 0x8
521 #define PMAP__UPDATE_INTERRUPT 0x9
522 #define PMAP__ATTRIBUTE_CLEAR 0xa
523 #define PMAP__REUSABLE 0xb /* This appears to be unused */
524 #define PMAP__QUERY_RESIDENT 0xc
525 #define PMAP__FLUSH_KERN_TLBS 0xd
526 #define PMAP__FLUSH_DELAYED_TLBS 0xe
527 #define PMAP__FLUSH_TLBS_TO 0xf
528 #define PMAP__FLUSH_EPT 0x10
529 #define PMAP__FAST_FAULT 0x11
530 #define PMAP__SWITCH 0x12
531 #define PMAP__TTE 0x13
532 #define PMAP__SWITCH_USER_TTB 0x14
534 /* Codes for clock (DBG_MACH_CLOCK) */
535 #define MACH_EPOCH_CHANGE 0x0 /* wake epoch change */
536 #define MACH_BRIDGE_RCV_TS 0x1 /* receive timestamp pair from interrupt handler */
537 #define MACH_BRIDGE_REMOTE_TIME 0x2 /* calculate remote timestamp */
538 #define MACH_BRIDGE_RESET_TS 0x3 /* reset timestamp conversion parameters */
539 #define MACH_BRIDGE_TS_PARAMS 0x4 /* recompute timestamp conversion parameters */
540 #define MACH_BRIDGE_SKIP_TS 0x5 /* skip timestamp */
541 #define MACH_BRIDGE_TS_MISMATCH 0x6 /* mismatch between predicted and received remote timestamp */
542 #define MACH_BRIDGE_OBSV_RATE 0x7 /* out of range observed rates */
544 /* Codes for Stackshot/Microstackshot (DBG_MACH_STACKSHOT) */
545 #define MICROSTACKSHOT_RECORD 0x0
546 #define MICROSTACKSHOT_GATHER 0x1
548 /* Codes for sysdiagnose (DBG_MACH_SYSDIAGNOSE) */
549 #define SYSDIAGNOSE_NOTIFY_USER 0x0
550 #define SYSDIAGNOSE_FULL 0x1
551 #define SYSDIAGNOSE_STACKSHOT 0x2
552 #define SYSDIAGNOSE_TAILSPIN 0x3
554 /* Codes for Selective Forced Idle (DBG_MACH_SFI) */
555 #define SFI_SET_WINDOW 0x0
556 #define SFI_CANCEL_WINDOW 0x1
557 #define SFI_SET_CLASS_OFFTIME 0x2
558 #define SFI_CANCEL_CLASS_OFFTIME 0x3
559 #define SFI_THREAD_DEFER 0x4
560 #define SFI_OFF_TIMER 0x5
561 #define SFI_ON_TIMER 0x6
562 #define SFI_WAIT_CANCELED 0x7
563 #define SFI_PID_SET_MANAGED 0x8
564 #define SFI_PID_CLEAR_MANAGED 0x9
565 #define SFI_GLOBAL_DEFER 0xa
567 /* Codes for Zone Allocator (DBG_MACH_ZALLOC) */
568 #define ZALLOC_ZCRAM 0x0
570 /* Codes for Mach resource management (DBG_MACH_RESOURCE) */
571 /* _K32A/B codes start at double the low nibble */
572 #define RMON_ENABLE_CPUUSAGE_MONITOR 0x001
573 #define RMON_CPUUSAGE_VIOLATED 0x002
574 #define RMON_CPUUSAGE_SUSPENDED 0x003
575 #define RMON_CPUUSAGE_VIOLATED_K32A 0x004
576 #define RMON_CPUUSAGE_VIOLATED_K32B 0x005
577 #define RMON_CPUUSAGE_RESUMED 0x006
578 #define RMON_DISABLE_CPUUSAGE_MONITOR 0x00f
580 #define RMON_ENABLE_CPUWAKES_MONITOR 0x011
581 #define RMON_CPUWAKES_VIOLATED 0x012
582 #define RMON_CPUWAKES_VIOLATED_K32A 0x014
583 #define RMON_CPUWAKES_VIOLATED_K32B 0x015
584 #define RMON_DISABLE_CPUWAKES_MONITOR 0x01f
586 #define RMON_ENABLE_IO_MONITOR 0x021
587 #define RMON_LOGWRITES_VIOLATED 0x022
588 #define RMON_PHYSWRITES_VIOLATED 0x023
589 #define RMON_LOGWRITES_VIOLATED_K32A 0x024
590 #define RMON_LOGWRITES_VIOLATED_K32B 0x025
591 #define RMON_DISABLE_IO_MONITOR 0x02f
593 /* **** The Kernel Debug Sub Classes for Network (DBG_NETWORK) **** */
594 #define DBG_NETIP 1 /* Internet Protocol */
595 #define DBG_NETARP 2 /* Address Resolution Protocol */
596 #define DBG_NETUDP 3 /* User Datagram Protocol */
597 #define DBG_NETTCP 4 /* Transmission Control Protocol */
598 #define DBG_NETICMP 5 /* Internet Control Message Protocol */
599 #define DBG_NETIGMP 6 /* Internet Group Management Protocol */
600 #define DBG_NETRIP 7 /* Routing Information Protocol */
601 #define DBG_NETOSPF 8 /* Open Shortest Path First */
602 #define DBG_NETISIS 9 /* Intermediate System to Intermediate System */
603 #define DBG_NETSNMP 10 /* Simple Network Management Protocol */
604 #define DBG_NETSOCK 11 /* Socket Layer */
607 #define DBG_NETAARP 100 /* Apple ARP */
608 #define DBG_NETDDP 101 /* Datagram Delivery Protocol */
609 #define DBG_NETNBP 102 /* Name Binding Protocol */
610 #define DBG_NETZIP 103 /* Zone Information Protocol */
611 #define DBG_NETADSP 104 /* Name Binding Protocol */
612 #define DBG_NETATP 105 /* Apple Transaction Protocol */
613 #define DBG_NETASP 106 /* Apple Session Protocol */
614 #define DBG_NETAFP 107 /* Apple Filing Protocol */
615 #define DBG_NETRTMP 108 /* Routing Table Maintenance Protocol */
616 #define DBG_NETAURP 109 /* Apple Update Routing Protocol */
618 #define DBG_NETIPSEC 128 /* IPsec Protocol */
619 #define DBG_NETVMNET 129 /* VMNet */
621 /* **** The Kernel Debug Sub Classes for IOKIT (DBG_IOKIT) **** */
622 #define DBG_IOINTC 0 /* Interrupt controller */
623 #define DBG_IOWORKLOOP 1 /* Work from work loop */
624 #define DBG_IOINTES 2 /* Interrupt event source */
625 #define DBG_IOCLKES 3 /* Clock event source */
626 #define DBG_IOCMDQ 4 /* Command queue latencies */
627 #define DBG_IOMCURS 5 /* Memory Cursor */
628 #define DBG_IOMDESC 6 /* Memory Descriptors */
629 #define DBG_IOPOWER 7 /* Power Managerment */
630 #define DBG_IOSERVICE 8 /* Matching etc. */
631 #define DBG_IOREGISTRY 9 /* Registry */
633 /* **** 9-32 reserved for internal IOKit usage **** */
635 #define DBG_IOSTORAGE 32 /* Storage layers */
636 #define DBG_IONETWORK 33 /* Network layers */
637 #define DBG_IOKEYBOARD 34 /* Keyboard */
638 #define DBG_IOHID 35 /* HID Devices */
639 #define DBG_IOAUDIO 36 /* Audio */
640 #define DBG_IOSERIAL 37 /* Serial */
641 #define DBG_IOTTY 38 /* TTY layers */
642 #define DBG_IOSAM 39 /* SCSI Architecture Model layers */
643 #define DBG_IOPARALLELATA 40 /* Parallel ATA */
644 #define DBG_IOPARALLELSCSI 41 /* Parallel SCSI */
645 #define DBG_IOSATA 42 /* Serial-ATA */
646 #define DBG_IOSAS 43 /* SAS */
647 #define DBG_IOFIBRECHANNEL 44 /* FiberChannel */
648 #define DBG_IOUSB 45 /* USB */
649 #define DBG_IOBLUETOOTH 46 /* Bluetooth */
650 #define DBG_IOFIREWIRE 47 /* FireWire */
651 #define DBG_IOINFINIBAND 48 /* Infiniband */
652 #define DBG_IOCPUPM 49 /* CPU Power Management */
653 #define DBG_IOGRAPHICS 50 /* Graphics */
654 #define DBG_HIBERNATE 51 /* hibernation related events */
655 #define DBG_IOTHUNDERBOLT 52 /* Thunderbolt */
656 #define DBG_BOOTER 53 /* booter related events */
658 /* Backwards compatibility */
659 #define DBG_IOPOINTING DBG_IOHID /* OBSOLETE: Use DBG_IOHID instead */
660 #define DBG_IODISK DBG_IOSTORAGE /* OBSOLETE: Use DBG_IOSTORAGE instead */
662 /* **** The Kernel Debug Sub Classes for Device Drivers (DBG_DRIVERS) **** */
663 #define DBG_DRVSTORAGE 1 /* Storage layers */
664 #define DBG_DRVNETWORK 2 /* Network layers */
665 #define DBG_DRVKEYBOARD 3 /* Keyboard */
666 #define DBG_DRVHID 4 /* HID Devices */
667 #define DBG_DRVAUDIO 5 /* Audio */
668 #define DBG_DRVSERIAL 7 /* Serial */
669 #define DBG_DRVSAM 8 /* SCSI Architecture Model layers */
670 #define DBG_DRVPARALLELATA 9 /* Parallel ATA */
671 #define DBG_DRVPARALLELSCSI 10 /* Parallel SCSI */
672 #define DBG_DRVSATA 11 /* Serial ATA */
673 #define DBG_DRVSAS 12 /* SAS */
674 #define DBG_DRVFIBRECHANNEL 13 /* FiberChannel */
675 #define DBG_DRVUSB 14 /* USB */
676 #define DBG_DRVBLUETOOTH 15 /* Bluetooth */
677 #define DBG_DRVFIREWIRE 16 /* FireWire */
678 #define DBG_DRVINFINIBAND 17 /* Infiniband */
679 #define DBG_DRVGRAPHICS 18 /* Graphics */
680 #define DBG_DRVSD 19 /* Secure Digital */
681 #define DBG_DRVNAND 20 /* NAND drivers and layers */
682 #define DBG_SSD 21 /* SSD */
683 #define DBG_DRVSPI 22 /* SPI */
684 #define DBG_DRVWLAN_802_11 23 /* WLAN 802.11 */
685 #define DBG_DRVSSM 24 /* System State Manager(AppleSSM) */
686 #define DBG_DRVSMC 25 /* System Management Controller */
687 #define DBG_DRVMACEFIMANAGER 26 /* Mac EFI Manager */
688 #define DBG_DRVANE 27 /* ANE */
690 /* Backwards compatibility */
691 #define DBG_DRVPOINTING DBG_DRVHID /* OBSOLETE: Use DBG_DRVHID instead */
692 #define DBG_DRVDISK DBG_DRVSTORAGE /* OBSOLETE: Use DBG_DRVSTORAGE instead */
694 /* **** The Kernel Debug Sub Classes for the DLIL Layer (DBG_DLIL) **** */
695 #define DBG_DLIL_STATIC 1 /* Static DLIL code */
696 #define DBG_DLIL_PR_MOD 2 /* DLIL Protocol Module */
697 #define DBG_DLIL_IF_MOD 3 /* DLIL Interface Module */
698 #define DBG_DLIL_PR_FLT 4 /* DLIL Protocol Filter */
699 #define DBG_DLIL_IF_FLT 5 /* DLIL Interface FIlter */
703 * The Kernel Debug Sub Classes for File System (DBG_FSYSTEM)
705 * Please NOTE: sub class values 0xC and 0xD are currently unused.
707 #define DBG_FSRW 0x1 /* reads and writes to the filesystem */
708 #define DBG_DKRW 0x2 /* reads and writes to the disk */
709 #define DBG_FSVN 0x3 /* vnode operations (inc. locking/unlocking) */
710 #define DBG_FSLOOOKUP 0x4 /* namei and other lookup-related operations */
711 #define DBG_JOURNAL 0x5 /* journaling operations */
712 #define DBG_IOCTL 0x6 /* ioctl to the disk */
713 #define DBG_BOOTCACHE 0x7 /* bootcache operations */
714 #define DBG_HFS 0x8 /* HFS-specific events; see the hfs project */
715 #define DBG_APFS 0x9 /* APFS-specific events; see the apfs project */
716 #define DBG_SMB 0xA /* SMB-specific events; see the smb project */
717 #define DBG_MOUNT 0xB /* Mounting/unmounting operations */
718 #define DBG_EXFAT 0xE /* ExFAT-specific events; see the exfat project */
719 #define DBG_MSDOS 0xF /* FAT-specific events; see the msdosfs project */
720 #define DBG_ACFS 0x10 /* Xsan-specific events; see the XsanFS project */
721 #define DBG_THROTTLE 0x11 /* I/O Throttling events */
722 #define DBG_DECMP 0x12 /* Decmpfs-specific events */
723 #define DBG_CONTENT_PROT 0xCF /* Content Protection Events: see bsd/sys/cprotect.h */
726 * For Kernel Debug Sub Class DBG_HFS, state bits for hfs_update event
728 #define DBG_HFS_UPDATE_ACCTIME 0x01
729 #define DBG_HFS_UPDATE_MODTIME 0x02
730 #define DBG_HFS_UPDATE_CHGTIME 0x04
731 #define DBG_HFS_UPDATE_MODIFIED 0x08
732 #define DBG_HFS_UPDATE_FORCE 0x10
733 #define DBG_HFS_UPDATE_DATEADDED 0x20
734 #define DBG_HFS_UPDATE_MINOR 0x40
735 #define DBG_HFS_UPDATE_SKIPPED 0x80
737 /* The Kernel Debug Sub Classes for BSD */
738 #define DBG_BSD_PROC 0x01 /* process/signals related */
739 #define DBG_BSD_MEMSTAT 0x02 /* memorystatus / jetsam operations */
740 #define DBG_BSD_KEVENT 0x03 /* kqueue / kevent related */
741 #define DBG_BSD_EXCP_SC 0x0C /* System Calls */
742 #define DBG_BSD_AIO 0x0D /* aio (POSIX async IO) */
743 #define DBG_BSD_SC_EXTENDED_INFO 0x0E /* System Calls, extended info */
744 #define DBG_BSD_SC_EXTENDED_INFO2 0x0F /* System Calls, extended info */
745 #define DBG_BSD_KDEBUG_TEST 0xFF /* for testing kdebug */
747 /* The Codes for BSD subcode class DBG_BSD_PROC */
748 #define BSD_PROC_EXIT 1 /* process exit */
749 #define BSD_PROC_FRCEXIT 2 /* Kernel force termination */
750 #define BSD_PROC_EXEC 3 /* process spawn / exec */
751 #define BSD_PROC_EXITREASON_CREATE 4 /* exit reason creation */
752 #define BSD_PROC_EXITREASON_COMMIT 5 /* exit reason commited to a proc */
754 /* Codes for BSD subcode class DBG_BSD_MEMSTAT */
755 #define BSD_MEMSTAT_SCAN 1 /* memorystatus thread awake */
756 #define BSD_MEMSTAT_JETSAM 2 /* LRU jetsam */
757 #define BSD_MEMSTAT_JETSAM_HIWAT 3 /* highwater jetsam */
758 #define BSD_MEMSTAT_FREEZE 4 /* freeze process */
759 #define BSD_MEMSTAT_LATENCY_COALESCE 5 /* delay imposed to coalesce jetsam reports */
760 #define BSD_MEMSTAT_UPDATE 6 /* priority update */
761 #define BSD_MEMSTAT_IDLE_DEMOTE 7 /* idle demotion fired */
762 #define BSD_MEMSTAT_CLEAR_ERRORS 8 /* reset termination error state */
763 #define BSD_MEMSTAT_DIRTY_TRACK 9 /* track the process state */
764 #define BSD_MEMSTAT_DIRTY_SET 10 /* set the process state */
765 #define BSD_MEMSTAT_DIRTY_CLEAR 11 /* clear the process state */
767 #define BSD_MEMSTAT_GRP_SET_PROP 12 /* set group properties */
768 #define BSD_MEMSTAT_DO_KILL 13 /* memorystatus kills */
769 #define BSD_MEMSTAT_CHANGE_PRIORITY 14 /* priority changed */
771 #define BSD_MEMSTAT_FAST_JETSAM 15 /* Aggressive jetsam ("clear-the-deck") */
773 /* Codes for BSD subcode class DBG_BSD_KEVENT */
774 #define BSD_KEVENT_KQ_PROCESS_BEGIN 1
775 #define BSD_KEVENT_KQ_PROCESS_END 2
776 #define BSD_KEVENT_KQWQ_PROCESS_BEGIN 3
777 #define BSD_KEVENT_KQWQ_PROCESS_END 4
778 #define BSD_KEVENT_KQWQ_BIND 5
779 #define BSD_KEVENT_KQWQ_UNBIND 6
780 #define BSD_KEVENT_KQWQ_THREQUEST 7
781 #define BSD_KEVENT_KQWL_PROCESS_BEGIN 8
782 #define BSD_KEVENT_KQWL_PROCESS_END 9
783 #define BSD_KEVENT_KQWL_THREQUEST 10
784 #define BSD_KEVENT_KQWL_THADJUST 11
785 #define BSD_KEVENT_KQ_REGISTER 12
786 #define BSD_KEVENT_KQWQ_REGISTER 13
787 #define BSD_KEVENT_KQWL_REGISTER 14
788 #define BSD_KEVENT_KNOTE_ACTIVATE 15
789 #define BSD_KEVENT_KQ_PROCESS 16
790 #define BSD_KEVENT_KQWQ_PROCESS 17
791 #define BSD_KEVENT_KQWL_PROCESS 18
792 #define BSD_KEVENT_KQWL_BIND 19
793 #define BSD_KEVENT_KQWL_UNBIND 20
794 #define BSD_KEVENT_KNOTE_ENABLE 21
795 #define BSD_KEVENT_KNOTE_VANISHED 22
797 /* The Kernel Debug Sub Classes for DBG_TRACE */
798 #define DBG_TRACE_DATA 0
799 #define DBG_TRACE_STRING 1
800 #define DBG_TRACE_INFO 2
802 /* The Kernel Debug events: */
803 #define TRACE_DATA_NEWTHREAD (TRACEDBG_CODE(DBG_TRACE_DATA, 1))
804 #define TRACE_DATA_EXEC (TRACEDBG_CODE(DBG_TRACE_DATA, 2))
805 #define TRACE_DATA_THREAD_TERMINATE (TRACEDBG_CODE(DBG_TRACE_DATA, 3))
806 #define TRACE_DATA_THREAD_TERMINATE_PID (TRACEDBG_CODE(DBG_TRACE_DATA, 4))
807 #define TRACE_STRING_GLOBAL (TRACEDBG_CODE(DBG_TRACE_STRING, 0))
808 #define TRACE_STRING_NEWTHREAD (TRACEDBG_CODE(DBG_TRACE_STRING, 1))
809 #define TRACE_STRING_EXEC (TRACEDBG_CODE(DBG_TRACE_STRING, 2))
810 #define TRACE_STRING_PROC_EXIT (TRACEDBG_CODE(DBG_TRACE_STRING, 3))
811 #define TRACE_STRING_THREADNAME (TRACEDBG_CODE(DBG_TRACE_STRING, 4))
812 #define TRACE_STRING_THREADNAME_PREV (TRACEDBG_CODE(DBG_TRACE_STRING, 5))
813 #define TRACE_PANIC (TRACEDBG_CODE(DBG_TRACE_INFO, 0))
814 #define TRACE_TIMESTAMPS (TRACEDBG_CODE(DBG_TRACE_INFO, 1))
815 #define TRACE_LOST_EVENTS (TRACEDBG_CODE(DBG_TRACE_INFO, 2))
816 #define TRACE_WRITING_EVENTS (TRACEDBG_CODE(DBG_TRACE_INFO, 3))
817 #define TRACE_INFO_STRING (TRACEDBG_CODE(DBG_TRACE_INFO, 4))
818 #define TRACE_RETROGRADE_EVENTS (TRACEDBG_CODE(DBG_TRACE_INFO, 5))
820 /* The Kernel Debug Sub Classes for DBG_CORESTORAGE */
823 /* The Kernel Debug Sub Classes for DBG_SECURITY */
824 #define DBG_SEC_KERNEL 0 /* raw entropy collected by the kernel */
825 #define DBG_SEC_SANDBOX 1
827 /* Sub-class codes for CoreGraphics (DBG_CG) are defined in its component. */
829 /* The Kernel Debug Sub Classes for DBG_MONOTONIC */
830 #define DBG_MT_INSTRS_CYCLES 1
831 #define DBG_MT_DEBUG 2
832 #define DBG_MT_TMPTH 0xfe
833 #define DBG_MT_TMPCPU 0xff
835 /* The Kernel Debug Sub Classes for DBG_MISC */
836 #define DBG_EVENT 0x10
837 #define DBG_MISC_LAYOUT 0x1a
838 #define DBG_BUFFER 0x20
840 /* The Kernel Debug Sub Classes for DBG_DYLD */
841 #define DBG_DYLD_UUID (5)
843 /* Kernel Debug codes for the DBG_DYLD_UUID subclass */
844 #define DBG_DYLD_UUID_MAP_A (0)
845 #define DBG_DYLD_UUID_MAP_B (1)
846 #define DBG_DYLD_UUID_MAP_32_A (2)
847 #define DBG_DYLD_UUID_MAP_32_B (3)
848 #define DBG_DYLD_UUID_MAP_32_C (4)
849 #define DBG_DYLD_UUID_UNMAP_A (5)
850 #define DBG_DYLD_UUID_UNMAP_B (6)
851 #define DBG_DYLD_UUID_UNMAP_32_A (7)
852 #define DBG_DYLD_UUID_UNMAP_32_B (8)
853 #define DBG_DYLD_UUID_UNMAP_32_C (9)
854 #define DBG_DYLD_UUID_SHARED_CACHE_A (10)
855 #define DBG_DYLD_UUID_SHARED_CACHE_B (11)
856 #define DBG_DYLD_UUID_SHARED_CACHE_32_A (12)
857 #define DBG_DYLD_UUID_SHARED_CACHE_32_B (13)
858 #define DBG_DYLD_UUID_SHARED_CACHE_32_C (14)
860 /* The Kernel Debug modifiers for the DBG_DKRW sub class */
861 #define DKIO_DONE 0x01
862 #define DKIO_READ 0x02
863 #define DKIO_ASYNC 0x04
864 #define DKIO_META 0x08
865 #define DKIO_PAGING 0x10
866 #define DKIO_THROTTLE 0x20 /* Deprecated, still provided so fs_usage doesn't break */
867 #define DKIO_PASSIVE 0x40
868 #define DKIO_NOCACHE 0x80
869 #define DKIO_TIER_MASK 0xF00
870 #define DKIO_TIER_SHIFT 8
871 #define DKIO_TIER_UPGRADE 0x1000
873 /* Kernel Debug Sub Classes for Applications (DBG_APPS) */
874 #define DBG_APP_LOGINWINDOW 0x03
875 #define DBG_APP_AUDIO 0x04
876 #define DBG_APP_SYSTEMUI 0x05
877 #define DBG_APP_SIGNPOST 0x0A
878 #define DBG_APP_APPKIT 0x0C
879 #define DBG_APP_UIKIT 0x0D
880 #define DBG_APP_DFR 0x0E
881 #define DBG_APP_LAYOUT 0x0F
882 #define DBG_APP_COREDATA 0x10
883 #define DBG_APP_SAMBA 0x80
884 #define DBG_APP_EOSSUPPORT 0x81
885 #define DBG_APP_MACEFIMANAGER 0x82
887 /* Kernel Debug codes for Throttling (DBG_THROTTLE) */
888 #define OPEN_THROTTLE_WINDOW 0x1
889 #define PROCESS_THROTTLED 0x2
890 #define IO_THROTTLE_DISABLE 0x3
891 #define IO_TIER_UPL_MISMATCH 0x4
894 /* Subclasses for MACH Importance Policies (DBG_IMPORTANCE) */
895 /* TODO: Split up boost and task policy? */
896 #define IMP_ASSERTION 0x10 /* Task takes/drops a boost assertion */
897 #define IMP_BOOST 0x11 /* Task boost level changed */
898 #define IMP_MSG 0x12 /* boosting message sent by donating task on donating port */
899 #define IMP_WATCHPORT 0x13 /* port marked as watchport, and boost was transferred to the watched task */
900 #define IMP_TASK_SUPPRESSION 0x17 /* Task changed suppression behaviors */
901 #define IMP_TASK_APPTYPE 0x18 /* Task launched with apptype */
902 #define IMP_UPDATE 0x19 /* Requested -> effective calculation */
903 #define IMP_USYNCH_QOS_OVERRIDE 0x1A /* Userspace synchronization applied QoS override to resource owning thread */
904 #define IMP_DONOR_CHANGE 0x1B /* The iit_donor bit changed */
905 #define IMP_MAIN_THREAD_QOS 0x1C /* The task's main thread QoS was set */
906 #define IMP_SYNC_IPC_QOS 0x1D /* Sync IPC QOS override */
907 /* DBG_IMPORTANCE subclasses 0x20 - 0x3F reserved for task policy flavors */
909 /* Codes for IMP_ASSERTION */
910 #define IMP_HOLD 0x2 /* Task holds a boost assertion */
911 #define IMP_DROP 0x4 /* Task drops a boost assertion */
912 #define IMP_EXTERN 0x8 /* boost assertion moved from kernel to userspace responsibility (externalized) */
914 /* Codes for IMP_BOOST */
915 #define IMP_BOOSTED 0x1
916 #define IMP_UNBOOSTED 0x2 /* Task drops a boost assertion */
918 /* Codes for IMP_MSG */
919 #define IMP_MSG_SEND 0x1 /* boosting message sent by donating task on donating port */
920 #define IMP_MSG_DELV 0x2 /* boosting message delivered to task */
922 /* Codes for IMP_UPDATE */
923 #define IMP_UPDATE_TASK_CREATE 0x1
925 /* Codes for IMP_USYNCH_QOS_OVERRIDE */
926 #define IMP_USYNCH_ADD_OVERRIDE 0x0 /* add override for a contended resource */
927 #define IMP_USYNCH_REMOVE_OVERRIDE 0x1 /* remove override for a contended resource */
929 /* Codes for IMP_DONOR_CHANGE */
930 #define IMP_DONOR_UPDATE_LIVE_DONOR_STATE 0x0
931 #define IMP_DONOR_INIT_DONOR_STATE 0x1
933 /* Code for IMP_SYNC_IPC_QOS */
934 #define IMP_SYNC_IPC_QOS_APPLIED 0x0
935 #define IMP_SYNC_IPC_QOS_REMOVED 0x1
936 #define IMP_SYNC_IPC_QOS_OVERFLOW 0x2
937 #define IMP_SYNC_IPC_QOS_UNDERFLOW 0x3
939 /* Subclasses for Turnstiles (DBG_TURNSTILE) */
940 #define TURNSTILE_HEAP_OPERATIONS 0x10
941 #define TURNSTILE_PRIORITY_OPERATIONS 0x20
942 #define TURNSTILE_FREELIST_OPERATIONS 0x30
944 /* Codes for TURNSTILE_HEAP_OPERATIONS */
945 #define THREAD_ADDED_TO_TURNSTILE_WAITQ 0x1
946 #define THREAD_REMOVED_FROM_TURNSTILE_WAITQ 0x2
947 #define THREAD_MOVED_IN_TURNSTILE_WAITQ 0x3
948 #define TURNSTILE_ADDED_TO_TURNSTILE_HEAP 0x4
949 #define TURNSTILE_REMOVED_FROM_TURNSTILE_HEAP 0x5
950 #define TURNSTILE_MOVED_IN_TURNSTILE_HEAP 0x6
951 #define TURNSTILE_ADDED_TO_THREAD_HEAP 0x7
952 #define TURNSTILE_REMOVED_FROM_THREAD_HEAP 0x8
953 #define TURNSTILE_MOVED_IN_THREAD_HEAP 0x9
954 #define TURNSTILE_UPDATE_STOPPED_BY_LIMIT 0xa
955 #define THREAD_NOT_WAITING_ON_TURNSTILE 0xb
957 /* Codes for TURNSTILE_PRIORITY_OPERATIONS */
958 #define TURNSTILE_PRIORITY_CHANGE 0x1
959 #define THREAD_USER_PROMOTION_CHANGE 0x2
961 /* Codes for TURNSTILE_FREELIST_OPERATIONS */
962 #define TURNSTILE_PREPARE 0x1
963 #define TURNSTILE_COMPLETE 0x2
965 /* Subclasses for MACH Bank Voucher Attribute Manager (DBG_BANK) */
966 #define BANK_ACCOUNT_INFO 0x10 /* Trace points related to bank account struct */
967 #define BANK_TASK_INFO 0x11 /* Trace points related to bank task struct */
969 /* Subclasses for MACH ATM Voucher Attribute Manager (ATM) */
970 #define ATM_SUBAID_INFO 0x10
971 #define ATM_GETVALUE_INFO 0x20
972 #define ATM_UNREGISTER_INFO 0x30
974 /* Codes for BANK_ACCOUNT_INFO */
975 #define BANK_SETTLE_CPU_TIME 0x1 /* Bank ledger(chit) rolled up to tasks. */
976 #define BANK_SECURE_ORIGINATOR_CHANGED 0x2 /* Secure Originator changed. */
977 #define BANK_SETTLE_ENERGY 0x3 /* Bank ledger(energy field) rolled up to tasks. */
979 /* Codes for ATM_SUBAID_INFO */
980 #define ATM_MIN_CALLED 0x1
981 #define ATM_LINK_LIST_TRIM 0x2
983 /* Codes for ATM_GETVALUE_INFO */
984 #define ATM_VALUE_REPLACED 0x1
985 #define ATM_VALUE_ADDED 0x2
987 /* Codes for ATM_UNREGISTER_INFO */
988 #define ATM_VALUE_UNREGISTERED 0x1
989 #define ATM_VALUE_DIFF_MAILBOX 0x2
991 /* Kernel Debug Sub Classes for daemons (DBG_DAEMON) */
992 #define DBG_DAEMON_COREDUET 0x1
993 #define DBG_DAEMON_POWERD 0x2
995 /* Subclasses for the user space allocator */
996 #define DBG_UMALLOC_EXTERNAL 0x1
997 #define DBG_UMALLOC_INTERNAL 0x2
999 /**********************************************************************/
1001 #define KDBG_MIGCODE(msgid) ((DBG_MIG << KDBG_CLASS_OFFSET) | \
1002 (((msgid) & 0x3fffff) << KDBG_CODE_OFFSET))
1004 #define MACHDBG_CODE(SubClass, code) KDBG_CODE(DBG_MACH, SubClass, code)
1005 #define NETDBG_CODE(SubClass, code) KDBG_CODE(DBG_NETWORK, SubClass, code)
1006 #define FSDBG_CODE(SubClass, code) KDBG_CODE(DBG_FSYSTEM, SubClass, code)
1007 #define BSDDBG_CODE(SubClass, code) KDBG_CODE(DBG_BSD, SubClass, code)
1008 #define IOKDBG_CODE(SubClass, code) KDBG_CODE(DBG_IOKIT, SubClass, code)
1009 #define DRVDBG_CODE(SubClass, code) KDBG_CODE(DBG_DRIVERS, SubClass, code)
1010 #define TRACEDBG_CODE(SubClass, code) KDBG_CODE(DBG_TRACE, SubClass, code)
1011 #define MISCDBG_CODE(SubClass, code) KDBG_CODE(DBG_MISC, SubClass, code)
1012 #define DLILDBG_CODE(SubClass, code) KDBG_CODE(DBG_DLIL, SubClass, code)
1013 #define SECURITYDBG_CODE(SubClass, code) KDBG_CODE(DBG_SECURITY, SubClass, code)
1014 #define DYLDDBG_CODE(SubClass, code) KDBG_CODE(DBG_DYLD, SubClass, code)
1015 #define QTDBG_CODE(SubClass, code) KDBG_CODE(DBG_QT, SubClass, code)
1016 #define APPSDBG_CODE(SubClass, code) KDBG_CODE(DBG_APPS, SubClass, code)
1017 #define ARIADNEDBG_CODE(SubClass, code) KDBG_CODE(DBG_ARIADNE, SubClass, code)
1018 #define DAEMONDBG_CODE(SubClass, code) KDBG_CODE(DBG_DAEMON, SubClass, code)
1019 #define CPUPM_CODE(code) IOKDBG_CODE(DBG_IOCPUPM, code)
1021 #define KMEM_ALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 0)
1022 #define KMEM_ALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 1)
1023 #define KMEM_FREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 2)
1024 #define KMEM_FREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 3)
1025 #define ZALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 4)
1026 #define ZALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 5)
1027 #define ZFREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 6)
1028 #define ZFREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 7)
1030 #define PMAP_CODE(code) MACHDBG_CODE(DBG_MACH_PMAP, code)
1033 #define IMPORTANCE_CODE(SubClass, code) KDBG_CODE(DBG_IMPORTANCE, (SubClass), (code))
1034 #define BANK_CODE(SubClass, code) KDBG_CODE(DBG_BANK, (SubClass), (code))
1035 #define ATM_CODE(SubClass, code) KDBG_CODE(DBG_ATM, (SubClass), (code))
1036 #define TURNSTILE_CODE(SubClass, code) KDBG_CODE(DBG_TURNSTILE, (SubClass), (code))
1038 /* Kernel Debug Macros for specific daemons */
1039 #define COREDUETDBG_CODE(code) DAEMONDBG_CODE(DBG_DAEMON_COREDUET, code)
1040 #define POWERDDBG_CODE(code) DAEMONDBG_CODE(DBG_DAEMON_POWERD, code)
1043 * To use kdebug in the kernel:
1045 * #include <sys/kdebug.h>
1047 * #define DBG_NETIPINIT NETDBG_CODE(DBG_NETIP, 1)
1052 * KDBG(DBG_NETIPINIT | DBG_FUNC_START, 1, 2, 3, 4);
1054 * KDBG(DBG_NETIPINIT);
1056 * KDBG(DBG_NETIPINIT | DBG_FUNC_END);
1060 #ifdef KERNEL_PRIVATE
1063 * The KDBG{,_DEBUG,_RELEASE,_FILTERED} macros are the preferred method of
1064 * making tracepoints.
1066 * Kernel pointers must be unslid or permuted using VM_KERNEL_UNSLIDE_OR_PERM.
1067 * Do not trace any sensitive data.
1071 * Traced on debug and development (and release macOS) kernels.
1073 #define KDBG(x, ...) KDBG_(, x, ## __VA_ARGS__, 4, 3, 2, 1, 0)
1076 * Traced on debug and development (and release macOS) kernels if explicitly
1077 * requested. Omitted from tracing without a typefilter.
1079 #define KDBG_FILTERED(x, ...) KDBG_(_FILTERED, x, ## __VA_ARGS__, 4, 3, 2, 1, 0)
1082 * Traced on debug and development (and release macOS) kernels, even if the
1083 * process filter would reject it.
1085 #define KDBG_RELEASE_NOPROCFILT(x, ...) \
1086 KDBG_(_RELEASE_NOPROCFILT, x, ## __VA_ARGS__, 4, 3, 2, 1, 0)
1089 * Traced on debug, development, and release kernels.
1091 * Only use this tracepoint if the events are required for a shipping trace
1094 #define KDBG_RELEASE(x, ...) KDBG_(_RELEASE, x, ## __VA_ARGS__, 4, 3, 2, 1, 0)
1097 * Traced only on debug kernels.
1099 #define KDBG_DEBUG(x, ...) KDBG_(_DEBUG, x, ## __VA_ARGS__, 4, 3, 2, 1, 0)
1101 #define KDBG_(f, x, a, b, c, d, n, ...) KDBG##n(f, x, a, b, c, d)
1102 #define KDBG0(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, 0, 0, 0, 0, 0)
1103 #define KDBG1(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, 0, 0, 0, 0)
1104 #define KDBG2(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, b, 0, 0, 0)
1105 #define KDBG3(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, b, c, 0, 0)
1106 #define KDBG4(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, b, c, d, 0)
1108 #endif /* defined(KERNEL_PRIVATE) */
1110 extern unsigned int kdebug_enable
;
1113 * Bits used by kdebug_enable. These control which events are traced at
1116 #define KDEBUG_ENABLE_TRACE (1U << 0)
1117 #define KDEBUG_ENABLE_ENTROPY (1U << 1) /* obsolete */
1118 #define KDEBUG_ENABLE_CHUD (1U << 2) /* obsolete */
1119 #define KDEBUG_ENABLE_PPT (1U << 3)
1120 #define KDEBUG_ENABLE_SERIAL (1U << 4)
1122 #define KDEBUG_TRACE (KDEBUG_ENABLE_TRACE)
1125 * Specify KDEBUG_PPT to indicate that the event belongs to the limited PPT set.
1126 * PPT is deprecated -- use a typefilter and the PPTDBG class instead.
1128 #define KDEBUG_PPT (KDEBUG_ENABLE_PPT)
1129 #define KDEBUG_COMMON (KDEBUG_ENABLE_TRACE | KDEBUG_ENABLE_PPT)
1132 * The kernel debug configuration level. These values control which events are
1133 * compiled in under different build configurations.
1135 * Infer the supported kernel debug event level from config option. Use
1136 * (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) as a guard to protect unaudited debug
1139 #define KDEBUG_LEVEL_NONE 0
1140 #define KDEBUG_LEVEL_IST 1
1141 #define KDEBUG_LEVEL_STANDARD 2
1142 #define KDEBUG_LEVEL_FULL 3
1145 #define KDEBUG_LEVEL KDEBUG_LEVEL_NONE
1147 #define KDEBUG_LEVEL KDEBUG_LEVEL_IST
1148 // currently configured for the iOS release kernel
1150 #define KDEBUG_LEVEL KDEBUG_LEVEL_FULL
1152 #define KDEBUG_LEVEL KDEBUG_LEVEL_STANDARD
1154 * Currently, all other kernel configurations (development, etc) build with
1155 * KDEBUG_LEVEL_STANDARD. As a result, KERNEL_DEBUG_CONSTANT*() are on by
1156 * default but KERNEL_DEBUG*() are not.
1160 #ifdef XNU_KERNEL_PRIVATE
1161 #define KDBG_IMPROBABLE __improbable
1163 #define KDBG_IMPROBABLE
1167 * KERNEL_DEBUG_CONSTANT_FILTERED events are omitted from tracing unless they
1168 * are explicitly requested in the typefilter. They are not emitted when
1169 * tracing without a typefilter.
1171 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
1172 #define KERNEL_DEBUG_CONSTANT_FILTERED(x, a, b, c, d, ...) \
1174 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1175 kernel_debug_filtered((x), (uintptr_t)(a), (uintptr_t)(b), \
1176 (uintptr_t)(c), (uintptr_t)(d)); \
1179 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
1180 #define KERNEL_DEBUG_CONSTANT_FILTERED(type, x, a, b, c, d, ...) do {} while (0)
1181 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
1183 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST)
1184 #define KERNEL_DEBUG_CONSTANT_RELEASE_NOPROCFILT(x, a, b, c, d, ...) \
1186 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1187 kernel_debug_flags((x), (uintptr_t)(a), (uintptr_t)(b), \
1188 (uintptr_t)(c), (uintptr_t)(d), KDBG_FLAG_NOPROCFILT); \
1191 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
1192 #define KERNEL_DEBUG_CONSTANT_RELEASE_NOPROCFILT(x, a, b, c, d, ...) \
1194 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
1197 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
1198 #define KERNEL_DEBUG_CONSTANT(x, a, b, c, d, e) \
1200 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1201 kernel_debug((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \
1202 (uintptr_t)(d),(uintptr_t)(e)); \
1207 * DO NOT USE THIS MACRO -- it breaks fundamental assumptions about ktrace and
1208 * is only meant to be used by the pthread kext and other points in the kernel
1209 * where the thread ID must be provided explicitly.
1211 #define KERNEL_DEBUG_CONSTANT1(x, a, b, c, d, e) \
1213 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1214 kernel_debug1((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \
1215 (uintptr_t)(d), (uintptr_t)(e)); \
1219 #define KERNEL_DEBUG_EARLY(x, a, b, c, d) \
1221 kernel_debug_early((uint32_t)(x), (uintptr_t)(a), (uintptr_t)(b), \
1222 (uintptr_t)(c), (uintptr_t)(d)); \
1224 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
1225 #define KERNEL_DEBUG_CONSTANT(x, a, b, c, d, e) do {} while (0)
1226 #define KERNEL_DEBUG_CONSTANT1(x, a, b, c, d, e) do {} while (0)
1227 #define KERNEL_DEBUG_EARLY(x, a, b, c, d) do {} while (0)
1228 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
1231 * KERNEL_DEBUG_CONSTANT_IST (in-system trace) events provide an audited subset
1232 * of tracepoints for userland system tracing tools. This tracing level was
1233 * created by 8857227 to protect fairplayd and other PT_DENY_ATTACH processes.
1234 * It has two effects: only KERNEL_DEBUG_CONSTANT_IST() traces are emitted and
1235 * any PT_DENY_ATTACH processes will only emit basic traces as defined by the
1236 * kernel_debug_filter() routine.
1238 #define KERNEL_DEBUG_CONSTANT_RELEASE(x, a, b, c, d, e) \
1239 KERNEL_DEBUG_CONSTANT_IST(~KDEBUG_ENABLE_PPT, x, a, b, c, d, 0)
1241 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST)
1242 #define KERNEL_DEBUG_CONSTANT_IST(type, x, a, b, c, d, e) \
1244 if (KDBG_IMPROBABLE(kdebug_enable & (type))) { \
1245 kernel_debug((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \
1246 (uintptr_t)(d), 0); \
1249 #define KERNEL_DEBUG_CONSTANT_IST1(x, a, b, c, d, e) \
1251 if (KDBG_IMPROBABLE(kdebug_enable)) { \
1252 kernel_debug1((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \
1253 (uintptr_t)(d), (uintptr_t)(e)); \
1256 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
1257 #define KERNEL_DEBUG_CONSTANT_IST(type, x, a, b, c, d, e) do {} while (0)
1258 #define KERNEL_DEBUG_CONSTANT_IST1(x, a, b, c, d, e) do {} while (0)
1259 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
1262 #define __kdebug_constant_only __unused
1266 * KERNEL_DEBUG events are only traced for DEBUG kernels.
1268 #define KERNEL_DEBUG_CONSTANT_DEBUG(x, a, b, c, d, e) \
1269 KERNEL_DEBUG(x, a, b, c, d, e)
1271 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL)
1272 #define __kdebug_only
1274 #define KERNEL_DEBUG(x, a, b, c, d, e) \
1276 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1277 kernel_debug((uint32_t)(x), (uintptr_t)(a), (uintptr_t)(b), \
1278 (uintptr_t)(c), (uintptr_t)(d), (uintptr_t)(e)); \
1283 * DO NOT USE THIS MACRO -- see warning above for KERNEL_DEBUG_CONSTANT1.
1285 #define KERNEL_DEBUG1(x, a, b, c, d, e) \
1287 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1288 kernel_debug1((uint32_t)(x), (uintptr_t)(a), (uintptr_t)(b), \
1289 (uintptr_t)(c), (uintptr_t)(d), (uintptr_t)(e)); \
1293 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
1294 #define __kdebug_only __unused
1296 #define KERNEL_DEBUG(x, a, b, c, d, e) do {} while (0)
1297 #define KERNEL_DEBUG1(x, a, b, c, d, e) do {} while (0)
1298 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
1301 extern void kernel_debug(
1309 extern void kernel_debug1(
1317 #define KDBG_FLAG_FILTERED 0x01
1318 #define KDBG_FLAG_NOPROCFILT 0x02
1320 extern void kernel_debug_flags(
1328 extern void kernel_debug_filtered(
1335 extern void kernel_debug_early(
1343 * EnergyTracing macros.
1346 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST)
1347 // whether to bother calculating EnergyTracing inputs
1348 // could change in future to see if DBG_ENERGYTRACE is active
1349 #define ENTR_SHOULDTRACE kdebug_enable
1350 // encode logical EnergyTracing into 32/64 KDebug trace
1351 #define ENTR_KDTRACE(component, opcode, lifespan, id, quality, value) \
1353 uint32_t kdcode__; \
1354 uintptr_t highval__, lowval__, mask__ = 0xffffffff; \
1355 kdcode__ = KDBG_CODE(DBG_ENERGYTRACE,component,opcode)|(lifespan); \
1356 highval__ = ((value) >> 32) & mask__; \
1357 lowval__ = (value) & mask__; \
1358 ENTR_KDTRACEFUNC(kdcode__, id, quality, highval__, lowval__); \
1362 * Trace the association of two existing activations.
1364 * An association is traced as a modification to the parent activation.
1365 * In order to fit the sub-activation's component, activation code, and
1366 * activation ID into a kdebug tracepoint, the arguments that would hold
1367 * the value are left separate, and one stores the component and opcode
1368 * of the sub-activation, while the other stores the pointer-sized
1372 +-----------------+ +~+----+----+--------+ +----------+
1373 |kEnTrModAssociate| | | | | | | |
1374 +-----------------+ +~+----+----+--------+ +----------+
1375 * 8-bits unused sub-activation ID
1376 * 8-bit sub-component
1380 #define kEnTrModAssociate (1 << 28)
1381 #define ENTR_KDASSOCIATE(par_comp, par_opcode, par_act_id, \
1382 sub_comp, sub_opcode, sub_act_id) \
1384 unsigned sub_compcode = ((unsigned)sub_comp << 16) | sub_opcode; \
1385 ENTR_KDTRACEFUNC(KDBG_CODE(DBG_ENERGYTRACE,par_comp,par_opcode), \
1386 par_act_id, kEnTrModAssociate, sub_compcode, \
1390 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
1392 #define ENTR_SHOULDTRACE FALSE
1393 #define ENTR_KDTRACE(component, opcode, lifespan, id, quality, value) \
1395 #define ENTR_KDASSOCIATE(par_comp, par_opcode, par_act_id, \
1396 sub_comp, sub_opcode, sub_act_id) \
1399 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
1401 #ifdef KERNEL_PRIVATE
1403 * kernel_debug_string provides the same functionality as the
1404 * kdebug_trace_string syscall as a KPI. str_id is an in/out
1405 * parameter that, if it's pointing to a string ID of 0, will
1406 * receive a generated ID. If it provides a value in str_id,
1407 * then that will be used, instead.
1409 * Returns an errno indicating the type of failure.
1412 kernel_debug_string(uint32_t debugid
, uint64_t *str_id
, const char *str
);
1415 * kernel_debug_disable disables event logging, but leaves any buffers
1418 extern void kernel_debug_disable(void);
1422 * Bits set in the comm page for kdebug.
1424 #define KDEBUG_COMMPAGE_ENABLE_TRACE 0x1
1425 #define KDEBUG_COMMPAGE_ENABLE_TYPEFILTER 0x2 /* Forced to false if ENABLE_TRACE is 0 */
1427 // for EnergyTracing user space & clients
1428 #define kEnTrCompKernel 2
1431 * EnergyTracing opcodes
1433 * Activations use DBG_FUNC_START/END.
1434 * Events are DBG_FUNC_NONE.
1437 /* Socket reads and writes are uniquely identified by the (sanitized)
1438 * pointer to the socket struct in question. To associate this address
1439 * with the user space file descriptor, we have a socket activation with
1440 * the FD as its identifier and the socket struct pointer as its value.
1442 #define kEnTrActKernSocket 1
1443 #define kEnTrActKernSockRead 2
1444 #define kEnTrActKernSockWrite 3
1446 #define kEnTrActKernPoll 10
1447 #define kEnTrActKernSelect 11
1448 #define kEnTrActKernKQWait 12
1451 #define kEnTrEvUnblocked 256
1453 // EnergyTracing flags (the low-order 16 bits of 'quality')
1454 #define kEnTrFlagNonBlocking 1 << 0
1455 #define kEnTrFlagNoWork 1 << 1
1457 // and now the internal mechanism
1458 #ifdef KERNEL_PRIVATE
1460 // 20452597 requests that the trace macros not take an argument it throws away
1461 #define KERNEL_DBG_IST_SANE(x, a, b, c, d) \
1462 KERNEL_DEBUG_CONSTANT_IST(KDEBUG_TRACE, x, a, b, c, d, \
1463 0 /*__unused in kernel_debug()*/ )
1464 #define ENTR_KDTRACEFUNC KERNEL_DBG_IST_SANE
1466 // value is int64_t, quality is uint32_t
1467 #define KERNEL_ENERGYTRACE(opcode, lifespan, id, quality, value) \
1468 ENTR_KDTRACE(kEnTrCompKernel, opcode, lifespan, id, \
1470 #define KERNEL_ENTR_ASSOCIATE(par_opcode, par_act_id, sub_opcode, sub_act_id) \
1471 ENTR_KDASSOCIATE(kEnTrCompKernel, par_opcode, par_act_id, \
1472 kEnTrCompKernel, sub_opcode, sub_act_id)
1474 // end EnergyTracing
1477 #include <mach/boolean.h>
1484 * Returns false if the debugid is disabled by filters, and true if the
1485 * debugid is allowed to be traced. A debugid may not be traced if the
1486 * typefilter disables its class and subclass, it's outside a range
1487 * check, or if it's not an allowed debugid in a value check. Trace
1488 * system events bypass this check.
1490 boolean_t
kdebug_debugid_enabled(uint32_t debugid
);
1493 * Returns true only if the debugid is explicitly enabled by filters. Returns
1494 * false otherwise, including when no filters are active.
1496 boolean_t
kdebug_debugid_explicitly_enabled(uint32_t debugid
);
1498 uint32_t kdebug_commpage_state(void);
1500 #define KDBG_VFS_LOOKUP_FLAG_LOOKUP 0x01
1501 #define KDBG_VFS_LOOKUP_FLAG_NOPROCFILT 0x02
1502 void kdebug_vfs_lookup(long *dbg_parms
, int dbg_namelen
, void *dp
,
1505 void kdebug_lookup_gen_events(long *dbg_parms
, int dbg_namelen
, void *dp
,
1508 void kdbg_trace_data(struct proc
*proc
, long *arg_pid
, long *arg_uniqueid
);
1510 void kdbg_trace_string(struct proc
*proc
, long *arg1
, long *arg2
, long *arg3
, long *arg4
);
1512 void kdbg_dump_trace_to_file(const char *);
1513 void kdebug_init(unsigned int n_events
, char *filterdesc
, boolean_t wrapping
);
1514 void kdebug_trace_start(unsigned int n_events
, const char *filterdesc
,
1515 boolean_t wrapping
, boolean_t at_wake
);
1516 void kdebug_free_early_buf(void);
1518 void release_storage_unit(int cpu
, uint32_t storage_unit
);
1519 int allocate_storage_unit(int cpu
);
1521 #define KDBG_CLASS_ENCODE(Class, SubClass) KDBG_EVENTID(Class, SubClass, 0)
1522 #define KDBG_CLASS_DECODE(Debugid) (Debugid & KDBG_CSC_MASK)
1524 #endif /* KERNEL_PRIVATE */
1525 #endif /* __APPLE_API_UNSTABLE */
1529 #ifdef __APPLE_API_PRIVATE
1531 * private kernel_debug definitions
1535 * Ensure that both LP32 and LP64 variants of arm64 use the same kd_buf
1538 #if defined(__arm64__)
1539 typedef uint64_t kd_buf_argtype
;
1541 typedef uintptr_t kd_buf_argtype
;
1546 kd_buf_argtype arg1
;
1547 kd_buf_argtype arg2
;
1548 kd_buf_argtype arg3
;
1549 kd_buf_argtype arg4
;
1550 kd_buf_argtype arg5
; /* the thread ID */
1553 * Ensure that both LP32 and LP64 variants of arm64 use the same kd_buf
1556 #if defined(__LP64__) || defined(__arm64__)
1558 kd_buf_argtype unused
;
1562 #if defined(__LP64__) || defined(__arm64__)
1563 #define KDBG_TIMESTAMP_MASK 0xffffffffffffffffULL
1565 kdbg_set_cpu(kd_buf
*kp
, int cpu
)
1567 kp
->cpuid
= (unsigned int)cpu
;
1570 kdbg_get_cpu(kd_buf
*kp
)
1572 return (int)kp
->cpuid
;
1575 kdbg_set_timestamp(kd_buf
*kp
, uint64_t thetime
)
1577 kp
->timestamp
= thetime
;
1579 static inline uint64_t
1580 kdbg_get_timestamp(kd_buf
*kp
)
1582 return kp
->timestamp
;
1585 kdbg_set_timestamp_and_cpu(kd_buf
*kp
, uint64_t thetime
, int cpu
)
1587 kdbg_set_timestamp(kp
, thetime
);
1588 kdbg_set_cpu(kp
, cpu
);
1591 #define KDBG_TIMESTAMP_MASK 0x00ffffffffffffffULL
1592 #define KDBG_CPU_MASK 0xff00000000000000ULL
1593 #define KDBG_CPU_SHIFT 56
1595 kdbg_set_cpu(kd_buf
*kp
, int cpu
)
1597 kp
->timestamp
= (kp
->timestamp
& KDBG_TIMESTAMP_MASK
) |
1598 (((uint64_t) cpu
) << KDBG_CPU_SHIFT
);
1601 kdbg_get_cpu(kd_buf
*kp
)
1603 return (int) (((kp
)->timestamp
& KDBG_CPU_MASK
) >> KDBG_CPU_SHIFT
);
1606 kdbg_set_timestamp(kd_buf
*kp
, uint64_t thetime
)
1608 kp
->timestamp
= thetime
& KDBG_TIMESTAMP_MASK
;
1610 static inline uint64_t
1611 kdbg_get_timestamp(kd_buf
*kp
)
1613 return kp
->timestamp
& KDBG_TIMESTAMP_MASK
;
1616 kdbg_set_timestamp_and_cpu(kd_buf
*kp
, uint64_t thetime
, int cpu
)
1618 kp
->timestamp
= (thetime
& KDBG_TIMESTAMP_MASK
) |
1619 (((uint64_t) cpu
) << KDBG_CPU_SHIFT
);
1624 * 2^16 bits (8 kilobytes), one for each possible class/subclass combination
1626 #define KDBG_TYPEFILTER_BITMAP_SIZE ((256 * 256) / 8)
1629 * Bits for kd_ctrl_page.flags, KERN_KD{D,E}FLAGS.
1631 #define KDBG_INIT (1U << 0) /* obsolete */
1632 /* disable tracing when buffers are full */
1633 #define KDBG_NOWRAP (1U << 1)
1634 #define KDBG_FREERUN (1U << 2) /* obsolete */
1635 /* buffer has wrapped */
1636 #define KDBG_WRAPPED (1U << 3)
1637 /* flags that are allowed to be set by user space */
1638 #define KDBG_USERFLAGS (KDBG_FREERUN | KDBG_NOWRAP | KDBG_INIT)
1639 /* only include processes with kdebug bit set in proc */
1640 #define KDBG_PIDCHECK (1U << 4)
1641 /* thread map is initialized */
1642 #define KDBG_MAPINIT (1U << 5)
1643 /* exclude processes based on kdebug bit in proc */
1644 #define KDBG_PIDEXCLUDE (1U << 6)
1645 /* whether the kdebug locks are intialized */
1646 #define KDBG_LOCKINIT (1U << 7)
1647 /* word size of the kernel */
1648 #define KDBG_LP64 (1U << 8)
1650 /* bits for kd_ctrl_page.flags and kbufinfo_t.flags */
1652 /* only trace events within a range */
1653 #define KDBG_RANGECHECK 0x00100000U
1654 /* only trace at most 4 types of events, at the code granularity */
1655 #define KDBG_VALCHECK 0x00200000U
1656 /* check class and subclass against the typefilter */
1657 #define KDBG_TYPEFILTER_CHECK 0x00400000U
1658 /* kdebug trace buffers are initialized */
1659 #define KDBG_BUFINIT 0x80000000U
1661 /* bits for the type field of kd_regtype */
1662 #define KDBG_CLASSTYPE 0x10000
1663 #define KDBG_SUBCLSTYPE 0x20000
1664 #define KDBG_RANGETYPE 0x40000
1665 #define KDBG_TYPENONE 0x80000
1666 #define KDBG_CKTYPES 0xF0000
1670 unsigned int value1
;
1671 unsigned int value2
;
1672 unsigned int value3
;
1673 unsigned int value4
;
1677 /* number of events that can fit in the buffers */
1679 /* set if trace is disabled */
1681 /* kd_ctrl_page.flags */
1683 /* number of threads in thread map */
1685 /* the owning pid */
1691 #if defined(__arm64__)
1696 /* 0 for invalid, otherwise the PID (or 1 for kernel_task) */
1698 /* the name of the process owning the thread */
1703 uint32_t version_no
;
1708 #define KDBG_CPUMAP_IS_IOP 0x1
1717 * TRACE file formats...
1721 * uint32_t #threadmaps
1727 * RAW_header, with version_no set to RAW_VERSION1
1729 * Empty space to pad alignment to the nearest page boundary.
1734 * RAW_header, with version_no set to RAW_VERSION1
1736 * kd_cpumap_header, with version_no set to RAW_VERSION1
1738 * Empty space to pad alignment to the nearest page boundary.
1741 * V1+ implementation details...
1743 * It would have been nice to add the cpumap data "correctly", but there were
1744 * several obstacles. Existing code attempts to parse both V1 and V0 files.
1745 * Due to the fact that V0 has no versioning or header, the test looks like
1749 * if (header.version_no != RAW_VERSION1) { // Assume V0 }
1751 * If we add a VERSION2 file format, all existing code is going to treat that
1752 * as a VERSION0 file when reading it, and crash terribly when trying to read
1753 * RAW_VERSION2 threadmap entries.
1755 * To differentiate between a V1 and V1+ file, read as V1 until you reach
1756 * the padding bytes. Then:
1758 * boolean_t is_v1plus = FALSE;
1759 * if (padding_bytes >= sizeof(kd_cpumap_header)) {
1760 * kd_cpumap_header header = // read header;
1761 * if (header.version_no == RAW_VERSION1) {
1776 // The header chunk has the tag 0x00001000 which also serves as a magic word
1777 // that identifies the file as a version 3 trace file. The header payload is
1778 // a set of fixed fields followed by a variable number of sub-chunks:
1780 * ____________________________________________________________________________
1781 | Offset | Size | Field |
1782 | ----------------------------------------------------------------------------
1783 | 0 | 4 | Tag (0x00001000) |
1784 | 4 | 4 | Sub-tag. Represents the version of the header. |
1785 | 8 | 8 | Length of header payload (40+8x) |
1786 | 16 | 8 | Time base info. Two 32-bit numbers, numer/denom, |
1787 | | | for converting timestamps to nanoseconds. |
1788 | 24 | 8 | Timestamp of trace start. |
1789 | 32 | 8 | Wall time seconds since Unix epoch. |
1790 | | | As returned by gettimeofday(). |
1791 | 40 | 4 | Wall time microseconds. As returned by gettimeofday(). |
1792 | 44 | 4 | Local time zone offset in minutes. ( " ) |
1793 | 48 | 4 | Type of daylight savings time correction to apply. ( " ) |
1794 | 52 | 4 | Flags. 1 = 64-bit. Remaining bits should be written |
1795 | | | as 0 and ignored when reading. |
1796 | 56 | 8x | Variable number of sub-chunks. None are required. |
1797 | | | Ignore unknown chunks. |
1798 | ----------------------------------------------------------------------------
1800 // NOTE: The header sub-chunks are considered part of the header chunk,
1801 // so they must be included in the header chunk’s length field.
1802 // The CPU map is an optional sub-chunk of the header chunk. It provides
1803 // information about the CPUs that are referenced from the trace events.
1808 uint32_t timebase_numer
;
1809 uint32_t timebase_denom
;
1811 uint64_t walltime_secs
;
1812 uint32_t walltime_usecs
;
1813 uint32_t timezone_minuteswest
;
1814 uint32_t timezone_dst
;
1816 } __attribute__((packed
)) kd_header_v3
;
1822 } __attribute__((packed
)) kd_chunk_header_v3
;
1824 #define RAW_VERSION0 0x55aa0000
1825 #define RAW_VERSION1 0x55aa0101
1826 #define RAW_VERSION2 0x55aa0200 /* Only used by kperf and Instruments */
1827 #define RAW_VERSION3 0x00001000
1829 #define V3_CONFIG 0x00001b00
1830 #define V3_CPU_MAP 0x00001c00
1831 #define V3_THREAD_MAP 0x00001d00
1832 #define V3_RAW_EVENTS 0x00001e00
1833 #define V3_NULL_CHUNK 0x00002000
1835 // The current version of all kernel managed chunks is 1. The
1836 // V3_CURRENT_CHUNK_VERSION is added to ease the simple case
1837 // when most/all the kernel managed chunks have the same version.
1839 #define V3_CURRENT_CHUNK_VERSION 1
1840 #define V3_HEADER_VERSION V3_CURRENT_CHUNK_VERSION
1841 #define V3_CPUMAP_VERSION V3_CURRENT_CHUNK_VERSION
1842 #define V3_THRMAP_VERSION V3_CURRENT_CHUNK_VERSION
1843 #define V3_EVENT_DATA_VERSION V3_CURRENT_CHUNK_VERSION
1845 // Apis to support writing v3 chunks in the kernel
1846 int kdbg_write_v3_chunk_header_to_buffer(void *buffer
, uint32_t tag
, uint32_t sub_tag
, uint64_t length
);
1847 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
);
1849 /* VFS lookup events for serial traces */
1850 #define VFS_LOOKUP (FSDBG_CODE(DBG_FSRW,36))
1851 #define VFS_LOOKUP_DONE (FSDBG_CODE(DBG_FSRW,39))
1853 #if !CONFIG_EMBEDDED
1854 #if defined(XNU_KERNEL_PRIVATE) && (DEVELOPMENT || DEBUG)
1855 #define KDEBUG_MOJO_TRACE 1
1859 #endif /* __APPLE_API_PRIVATE */
1860 #endif /* PRIVATE */
1862 #endif /* !BSD_SYS_KDEBUG_H */