2 * Copyright (c) 2000-2014 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@
29 /* Copyright (c) 1997 Apple Computer, Inc. All rights reserved.
31 * kdebug.h - kernel_debug definitions
35 #ifndef BSD_SYS_KDEBUG_H
36 #define BSD_SYS_KDEBUG_H
38 #include <sys/appleapiopts.h>
39 #include <sys/cdefs.h>
42 #ifdef __APPLE_API_UNSTABLE
44 #include <mach/clock_types.h>
48 #include <Availability.h>
51 #ifdef XNU_KERNEL_PRIVATE
53 #include <mach/branch_predicates.h>
57 * Kdebug is a facility for tracing events occurring on a system.
59 * All events are tagged with a debugid, consisting of the following:
61 * +----------------+----------------+----------------------------+----+
62 * | Class (8) | Subclass (8) | Code (14) |Func|
64 * +----------------+----------------+----------------------------+----+
65 * \______________________________________________________________/
67 * \___________________________________________________________________/
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 a series of grouped events).
76 #define KDBG_CLASS_MASK (0xff000000)
77 #define KDBG_CLASS_OFFSET (24)
78 #define KDBG_CLASS_MAX (0xff)
80 #define KDBG_SUBCLASS_MASK (0x00ff0000)
81 #define KDBG_SUBCLASS_OFFSET (16)
82 #define KDBG_SUBCLASS_MAX (0xff)
84 /* class and subclass mask */
85 #define KDBG_CSC_MASK (0xffff0000)
86 #define KDBG_CSC_OFFSET (KDBG_SUBCLASS_OFFSET)
88 #define KDBG_CODE_MASK (0x0000fffc)
89 #define KDBG_CODE_OFFSET (2)
90 #define KDBG_CODE_MAX (0x3fff)
92 #define KDBG_EVENTID_MASK (0xfffffffc)
94 /* Generate an eventid corresponding to Class, SubClass, and Code. */
95 #define KDBG_EVENTID(Class, SubClass, Code) \
96 ((((Class) & 0xff) << KDBG_CLASS_OFFSET) | \
97 (((SubClass) & 0xff) << KDBG_SUBCLASS_OFFSET) | \
98 (((Code) & 0x3fff) << KDBG_CODE_OFFSET))
99 /* Deprecated macro using old naming convention. */
100 #define KDBG_CODE(Class, SubClass, Code) \
101 KDBG_EVENTID(Class, SubClass, Code)
103 /* Extract pieces of the debug code. */
104 #define KDBG_EXTRACT_CLASS(Debugid) \
105 ((uint8_t)(((Debugid) & KDBG_CLASS_MASK) >> KDBG_CLASS_OFFSET))
106 #define KDBG_EXTRACT_SUBCLASS(Debugid) \
107 ((uint8_t)(((Debugid) & KDBG_SUBCLASS_MASK) >> KDBG_SUBCLASS_OFFSET))
108 #define KDBG_EXTRACT_CSC(Debugid) \
109 ((uint16_t)(((Debugid) & KDBG_CSC_MASK) >> KDBG_CSC_OFFSET))
110 #define KDBG_EXTRACT_CODE(Debugid) \
111 ((uint16_t)(((Debugid) & KDBG_CODE_MASK) >> KDBG_CODE_OFFSET))
113 #ifdef KERNEL_PRIVATE
117 KD_CALLBACK_KDEBUG_ENABLED
, // Trace is now enabled. No arguments
118 KD_CALLBACK_KDEBUG_DISABLED
, // Trace is now disabled. No arguments
119 KD_CALLBACK_SYNC_FLUSH
, // Request the latest entries from the IOP, and block until complete. No arguments
120 KD_CALLBACK_TYPEFILTER_CHANGED
, // Typefilter is enabled. A read-only pointer to the typefilter is provided, but is only valid while in the callback.
122 typedef void (*kd_callback_fn
) (void* context
, kd_callback_type reason
, void* arg
);
127 char iop_name
[8]; // null-terminated string with name of core.
130 typedef struct kd_callback kd_callback_t
;
133 * Registers an IOP for participation in tracing.
135 * The registered callback function will be called with the
136 * supplied context as the first argument, followed by a
137 * kd_callback_type and an associated void* argument.
139 * The return value is a nonzero coreid that shall be used in
140 * kernel_debug_enter() to refer to your IOP. If the allocation
141 * failed, then 0 will be returned.
145 * Note that not all callback calls will indicate a change in
146 * state (e.g. disabling trace twice would send two disable
150 extern int kernel_debug_register_callback(kd_callback_t callback
);
152 extern void kernel_debug_enter(
163 #endif /* KERNEL_PRIVATE */
165 /* The Function qualifiers */
166 #define DBG_FUNC_START 1
167 #define DBG_FUNC_END 2
168 #define DBG_FUNC_NONE 0
170 /* The Kernel Debug Classes */
172 #define DBG_NETWORK 2
173 #define DBG_FSYSTEM 3
176 #define DBG_DRIVERS 6
179 #define DBG_WORKQUEUE 9
180 #define DBG_CORESTORAGE 10
183 #define DBG_SECURITY 30
187 #define DBG_LAUNCHD 34
189 #define DBG_IMPORTANCE 38
193 #define DBG_ARIADNE 43
194 #define DBG_DAEMON 44
195 #define DBG_ENERGYTRACE 45
202 * OS components can use the full precision of the "code" field
203 * (Class, SubClass, Code) to inject events using kdebug_trace() by
206 * kdebug_trace(KDBG_CODE(DBG_XPC, 15, 1) | DBG_FUNC_NONE, 1, 2, 3, 4);
208 * These trace points can be included in production code, since they
209 * use reserved, non-overlapping ranges. The performance impact when
210 * kernel tracing is not enabled is minimal. Classes can be reserved
211 * by filing a Radar in xnu|all.
213 * 64-bit arguments may be truncated if the system is using a 32-bit
216 * On error, -1 will be returned and errno will indicate the error.
219 extern int kdebug_trace(uint32_t code
, uint64_t arg1
, uint64_t arg2
, uint64_t arg3
, uint64_t arg4
) __OSX_AVAILABLE_STARTING(__MAC_10_10_2
, __IPHONE_8_2
);
223 * @function kdebug_trace_string
226 * This function emits strings to kdebug trace along with an ID and allows
227 * for previously-traced strings to be overwritten and invalidated.
229 * To start tracing a string and generate an ID to use to refer to it:
231 * string_id = kdebug_trace_string(debugid, 0, "string");
233 * To replace a string previously traced:
235 * string_id = kdebug_trace_string(debugid, string_id, "new string");
237 * To invalidate a string ID:
239 * string_id = kdebug_trace_string(debugid, string_id, NULL);
241 * To check for errors:
243 * if ((int64_t)string_id == -1) { perror("string error") }
246 * The `debugid` to check if its enabled before tracing and include as
247 * an argument in the event containing the string.
249 * Some classes or subclasses are reserved for specific uses and are not
250 * allowed to be used with this function. No function qualifiers are
251 * allowed on `debugid`.
254 * When 0, a new ID will be generated and returned if tracing is
257 * Otherwise `str_id` must contain an ID that was previously generated
258 * with this function. Clents should pass NULL in `str` if `str_id`
259 * is no longer in use. Otherwise, the string previously mapped to
260 * `str_id` will be overwritten with the contents of `str`.
263 * A NUL-terminated 'C' string containing the characters that should be
264 * traced alongside `str_id`.
266 * If necessary, the string will be truncated at an
267 * implementation-defined length. The string must not be the empty
268 * string, but can be NULL if a valid `str_id` is provided.
271 * 0 if tracing is disabled or `debugid` is being filtered out of trace.
272 * It can also return (int64_t)-1 if an error occured. Otherwise,
273 * it returns the ID to use to refer to the string in future
274 * kdebug_trace(2) calls.
276 * The errors that can occur are:
279 * There are function qualifiers on `debugid`, `str` is empty, or
280 * `str_id` was not generated by this function.
282 * The `debugid`'s class or subclass is reserved for internal use.
284 * `str` is an invalid address or NULL when `str_id` is 0.
287 extern uint64_t kdebug_trace_string(uint32_t debugid
, uint64_t str_id
,
289 __OSX_AVAILABLE_STARTING(__MAC_10_11
, __IPHONE_9_0
);
293 #ifdef XNU_KERNEL_PRIVATE
294 /* Used in early boot to log strings spanning only a single tracepoint. */
295 extern void kernel_debug_string_simple(const char *message
);
296 #endif /* XNU_KERNEL_PRIVATE */
298 /* **** The Kernel Debug Sub Classes for Mach (DBG_MACH) **** */
299 #define DBG_MACH_EXCP_KTRAP_x86 0x02 /* Kernel Traps on x86 */
300 #define DBG_MACH_EXCP_DFLT 0x03 /* Data Translation Fault */
301 #define DBG_MACH_EXCP_IFLT 0x04 /* Inst Translation Fault */
302 #define DBG_MACH_EXCP_INTR 0x05 /* Interrupts */
303 #define DBG_MACH_EXCP_ALNG 0x06 /* Alignment Exception */
304 #define DBG_MACH_EXCP_UTRAP_x86 0x07 /* User Traps on x86 */
305 #define DBG_MACH_EXCP_FP 0x08 /* FP Unavail */
306 #define DBG_MACH_EXCP_DECI 0x09 /* Decrementer Interrupt */
307 #define DBG_MACH_CHUD 0x0A /* CHUD */
308 #define DBG_MACH_EXCP_SC 0x0C /* System Calls */
309 #define DBG_MACH_EXCP_TRACE 0x0D /* Trace exception */
310 #define DBG_MACH_EXCP_EMUL 0x0E /* Instruction emulated */
311 #define DBG_MACH_IHDLR 0x10 /* Interrupt Handlers */
312 #define DBG_MACH_IPC 0x20 /* Inter Process Comm */
313 #define DBG_MACH_VM 0x30 /* Virtual Memory */
314 #define DBG_MACH_LEAKS 0x31 /* alloc/free */
315 #define DBG_MACH_SCHED 0x40 /* Scheduler */
316 #define DBG_MACH_MSGID_INVALID 0x50 /* Messages - invalid */
317 #define DBG_MACH_LOCKS 0x60 /* new lock APIs */
318 #define DBG_MACH_PMAP 0x70 /* pmap */
319 #define DBG_MACH_CLOCK 0x80 /* clock */
320 #define DBG_MACH_MP 0x90 /* MP related */
321 #define DBG_MACH_VM_PRESSURE 0xA0 /* Memory Pressure Events */
322 #define DBG_MACH_STACKSHOT 0xA1 /* Stackshot/Microstackshot subsystem */
323 #define DBG_MACH_SFI 0xA2 /* Selective Forced Idle (SFI) */
324 #define DBG_MACH_ENERGY_PERF 0xA3 /* Energy/performance resource stats */
325 #define DBG_MACH_SYSDIAGNOSE 0xA4 /* sysdiagnose keychord */
326 #define DBG_MACH_ZALLOC 0xA5 /* Zone allocator */
328 /* Codes for Scheduler (DBG_MACH_SCHED) */
329 #define MACH_SCHED 0x0 /* Scheduler */
330 #define MACH_STACK_ATTACH 0x1 /* stack_attach() */
331 #define MACH_STACK_HANDOFF 0x2 /* stack_handoff() */
332 #define MACH_CALL_CONT 0x3 /* call_continuation() */
333 #define MACH_CALLOUT 0x4 /* callouts */
334 #define MACH_STACK_DETACH 0x5
335 #define MACH_MAKE_RUNNABLE 0x6 /* make thread runnable */
336 #define MACH_PROMOTE 0x7 /* promoted due to resource */
337 #define MACH_DEMOTE 0x8 /* promotion undone */
338 #define MACH_IDLE 0x9 /* processor idling */
339 #define MACH_STACK_DEPTH 0xa /* stack depth at switch */
340 #define MACH_MOVED 0xb /* did not use original scheduling decision */
343 #define MACH_FAILSAFE 0xe /* tripped fixed-pri/RT failsafe */
344 #define MACH_BLOCK 0xf /* thread block */
345 #define MACH_WAIT 0x10 /* thread wait assertion */
346 #define MACH_GET_URGENCY 0x14 /* Urgency queried by platform */
347 #define MACH_URGENCY 0x15 /* Urgency (RT/BG/NORMAL) communicated
350 #define MACH_REDISPATCH 0x16 /* "next thread" thread redispatched */
351 #define MACH_REMOTE_AST 0x17 /* AST signal issued to remote processor */
352 #define MACH_SCHED_CHOOSE_PROCESSOR 0x18 /* Result of choose_processor */
353 #define MACH_DEEP_IDLE 0x19 /* deep idle on master processor */
354 /* unused 0x1a was MACH_SCHED_DECAY_PRIORITY */
355 #define MACH_CPU_THROTTLE_DISABLE 0x1b /* Global CPU Throttle Disable */
356 #define MACH_RW_PROMOTE 0x1c /* promoted due to RW lock promotion */
357 #define MACH_RW_DEMOTE 0x1d /* promotion due to RW lock undone */
358 #define MACH_SCHED_MAINTENANCE 0x1f /* periodic maintenance thread */
359 #define MACH_DISPATCH 0x20 /* context switch completed */
360 #define MACH_QUANTUM_HANDOFF 0x21 /* quantum handoff occurred */
361 #define MACH_MULTIQ_DEQUEUE 0x22 /* Result of multiq dequeue */
362 #define MACH_SCHED_THREAD_SWITCH 0x23 /* attempt direct context switch to hinted thread */
363 #define MACH_SCHED_SMT_BALANCE 0x24 /* SMT load balancing ASTs */
364 #define MACH_REMOTE_DEFERRED_AST 0x25 /* Deferred AST started against remote processor */
365 #define MACH_REMOTE_CANCEL_AST 0x26 /* Canceled deferred AST for remote processor */
366 #define MACH_SCHED_CHANGE_PRIORITY 0x27 /* thread sched priority changed */
367 #define MACH_SCHED_UPDATE_REC_CORES 0x28 /* Change to recommended processor bitmask */
368 #define MACH_STACK_WAIT 0x29 /* Thread could not be switched-to because of kernel stack shortage */
369 #define MACH_THREAD_BIND 0x2a /* Thread was bound (or unbound) to a processor */
370 #define MACH_WAITQ_PROMOTE 0x2b /* Thread promoted by waitq boost */
371 #define MACH_WAITQ_DEMOTE 0x2c /* Thread demoted from waitq boost */
373 /* Variants for MACH_MULTIQ_DEQUEUE */
374 #define MACH_MULTIQ_BOUND 1
375 #define MACH_MULTIQ_GROUP 2
376 #define MACH_MULTIQ_GLOBAL 3
378 /* Arguments for vm_fault (DBG_MACH_VM) */
379 #define DBG_ZERO_FILL_FAULT 1
380 #define DBG_PAGEIN_FAULT 2
381 #define DBG_COW_FAULT 3
382 #define DBG_CACHE_HIT_FAULT 4
383 #define DBG_NZF_PAGE_FAULT 5
384 #define DBG_GUARD_FAULT 6
385 #define DBG_PAGEINV_FAULT 7
386 #define DBG_PAGEIND_FAULT 8
387 #define DBG_COMPRESSOR_FAULT 9
388 #define DBG_COMPRESSOR_SWAPIN_FAULT 10
390 /* Codes for IPC (DBG_MACH_IPC) */
391 #define MACH_TASK_SUSPEND 0x0 /* Suspended a task */
392 #define MACH_TASK_RESUME 0x1 /* Resumed a task */
393 #define MACH_THREAD_SET_VOUCHER 0x2
394 #define MACH_IPC_MSG_SEND 0x3 /* mach msg send, uniq msg info */
395 #define MACH_IPC_MSG_RECV 0x4 /* mach_msg receive */
396 #define MACH_IPC_MSG_RECV_VOUCHER_REFUSED 0x5 /* mach_msg receive, voucher refused */
397 #define MACH_IPC_KMSG_FREE 0x6 /* kernel free of kmsg data */
398 #define MACH_IPC_VOUCHER_CREATE 0x7 /* Voucher added to global voucher hashtable */
399 #define MACH_IPC_VOUCHER_CREATE_ATTR_DATA 0x8 /* Attr data for newly created voucher */
400 #define MACH_IPC_VOUCHER_DESTROY 0x9 /* Voucher removed from global voucher hashtable */
402 /* Codes for pmap (DBG_MACH_PMAP) */
403 #define PMAP__CREATE 0x0
404 #define PMAP__DESTROY 0x1
405 #define PMAP__PROTECT 0x2
406 #define PMAP__PAGE_PROTECT 0x3
407 #define PMAP__ENTER 0x4
408 #define PMAP__REMOVE 0x5
409 #define PMAP__NEST 0x6
410 #define PMAP__UNNEST 0x7
411 #define PMAP__FLUSH_TLBS 0x8
412 #define PMAP__UPDATE_INTERRUPT 0x9
413 #define PMAP__ATTRIBUTE_CLEAR 0xa
414 #define PMAP__REUSABLE 0xb
415 #define PMAP__QUERY_RESIDENT 0xc
416 #define PMAP__FLUSH_KERN_TLBS 0xd
417 #define PMAP__FLUSH_DELAYED_TLBS 0xe
418 #define PMAP__FLUSH_TLBS_TO 0xf
419 #define PMAP__FLUSH_EPT 0x10
421 /* Codes for clock (DBG_MACH_CLOCK) */
422 #define MACH_EPOCH_CHANGE 0x0 /* wake epoch change */
425 /* Codes for Stackshot/Microstackshot (DBG_MACH_STACKSHOT) */
426 #define MICROSTACKSHOT_RECORD 0x0
427 #define MICROSTACKSHOT_GATHER 0x1
429 /* Codes for sysdiagnose */
430 #define SYSDIAGNOSE_NOTIFY_USER 0x0
432 /* Codes for Selective Forced Idle (DBG_MACH_SFI) */
433 #define SFI_SET_WINDOW 0x0
434 #define SFI_CANCEL_WINDOW 0x1
435 #define SFI_SET_CLASS_OFFTIME 0x2
436 #define SFI_CANCEL_CLASS_OFFTIME 0x3
437 #define SFI_THREAD_DEFER 0x4
438 #define SFI_OFF_TIMER 0x5
439 #define SFI_ON_TIMER 0x6
440 #define SFI_WAIT_CANCELED 0x7
441 #define SFI_PID_SET_MANAGED 0x8
442 #define SFI_PID_CLEAR_MANAGED 0x9
443 #define SFI_GLOBAL_DEFER 0xa
445 /* Codes for Zone Allocator (DBG_MACH_ZALLOC) */
446 #define ZALLOC_ZCRAM 0x0
448 /* **** The Kernel Debug Sub Classes for Network (DBG_NETWORK) **** */
449 #define DBG_NETIP 1 /* Internet Protocol */
450 #define DBG_NETARP 2 /* Address Resolution Protocol */
451 #define DBG_NETUDP 3 /* User Datagram Protocol */
452 #define DBG_NETTCP 4 /* Transmission Control Protocol */
453 #define DBG_NETICMP 5 /* Internet Control Message Protocol */
454 #define DBG_NETIGMP 6 /* Internet Group Management Protocol */
455 #define DBG_NETRIP 7 /* Routing Information Protocol */
456 #define DBG_NETOSPF 8 /* Open Shortest Path First */
457 #define DBG_NETISIS 9 /* Intermediate System to Intermediate System */
458 #define DBG_NETSNMP 10 /* Simple Network Management Protocol */
459 #define DBG_NETSOCK 11 /* Socket Layer */
462 #define DBG_NETAARP 100 /* Apple ARP */
463 #define DBG_NETDDP 101 /* Datagram Delivery Protocol */
464 #define DBG_NETNBP 102 /* Name Binding Protocol */
465 #define DBG_NETZIP 103 /* Zone Information Protocol */
466 #define DBG_NETADSP 104 /* Name Binding Protocol */
467 #define DBG_NETATP 105 /* Apple Transaction Protocol */
468 #define DBG_NETASP 106 /* Apple Session Protocol */
469 #define DBG_NETAFP 107 /* Apple Filing Protocol */
470 #define DBG_NETRTMP 108 /* Routing Table Maintenance Protocol */
471 #define DBG_NETAURP 109 /* Apple Update Routing Protocol */
473 #define DBG_NETIPSEC 128 /* IPsec Protocol */
474 #define DBG_NETVMNET 129 /* VMNet */
476 /* **** The Kernel Debug Sub Classes for IOKIT (DBG_IOKIT) **** */
477 #define DBG_IOINTC 0 /* Interrupt controller */
478 #define DBG_IOWORKLOOP 1 /* Work from work loop */
479 #define DBG_IOINTES 2 /* Interrupt event source */
480 #define DBG_IOCLKES 3 /* Clock event source */
481 #define DBG_IOCMDQ 4 /* Command queue latencies */
482 #define DBG_IOMCURS 5 /* Memory Cursor */
483 #define DBG_IOMDESC 6 /* Memory Descriptors */
484 #define DBG_IOPOWER 7 /* Power Managerment */
485 #define DBG_IOSERVICE 8 /* Matching etc. */
487 /* **** 9-32 reserved for internal IOKit usage **** */
489 #define DBG_IOSTORAGE 32 /* Storage layers */
490 #define DBG_IONETWORK 33 /* Network layers */
491 #define DBG_IOKEYBOARD 34 /* Keyboard */
492 #define DBG_IOHID 35 /* HID Devices */
493 #define DBG_IOAUDIO 36 /* Audio */
494 #define DBG_IOSERIAL 37 /* Serial */
495 #define DBG_IOTTY 38 /* TTY layers */
496 #define DBG_IOSAM 39 /* SCSI Architecture Model layers */
497 #define DBG_IOPARALLELATA 40 /* Parallel ATA */
498 #define DBG_IOPARALLELSCSI 41 /* Parallel SCSI */
499 #define DBG_IOSATA 42 /* Serial-ATA */
500 #define DBG_IOSAS 43 /* SAS */
501 #define DBG_IOFIBRECHANNEL 44 /* FiberChannel */
502 #define DBG_IOUSB 45 /* USB */
503 #define DBG_IOBLUETOOTH 46 /* Bluetooth */
504 #define DBG_IOFIREWIRE 47 /* FireWire */
505 #define DBG_IOINFINIBAND 48 /* Infiniband */
506 #define DBG_IOCPUPM 49 /* CPU Power Management */
507 #define DBG_IOGRAPHICS 50 /* Graphics */
508 #define DBG_HIBERNATE 51 /* hibernation related events */
509 #define DBG_IOTHUNDERBOLT 52 /* Thunderbolt */
512 /* Backwards compatibility */
513 #define DBG_IOPOINTING DBG_IOHID /* OBSOLETE: Use DBG_IOHID instead */
514 #define DBG_IODISK DBG_IOSTORAGE /* OBSOLETE: Use DBG_IOSTORAGE instead */
516 /* **** The Kernel Debug Sub Classes for Device Drivers (DBG_DRIVERS) **** */
517 #define DBG_DRVSTORAGE 1 /* Storage layers */
518 #define DBG_DRVNETWORK 2 /* Network layers */
519 #define DBG_DRVKEYBOARD 3 /* Keyboard */
520 #define DBG_DRVHID 4 /* HID Devices */
521 #define DBG_DRVAUDIO 5 /* Audio */
522 #define DBG_DRVSERIAL 7 /* Serial */
523 #define DBG_DRVSAM 8 /* SCSI Architecture Model layers */
524 #define DBG_DRVPARALLELATA 9 /* Parallel ATA */
525 #define DBG_DRVPARALLELSCSI 10 /* Parallel SCSI */
526 #define DBG_DRVSATA 11 /* Serial ATA */
527 #define DBG_DRVSAS 12 /* SAS */
528 #define DBG_DRVFIBRECHANNEL 13 /* FiberChannel */
529 #define DBG_DRVUSB 14 /* USB */
530 #define DBG_DRVBLUETOOTH 15 /* Bluetooth */
531 #define DBG_DRVFIREWIRE 16 /* FireWire */
532 #define DBG_DRVINFINIBAND 17 /* Infiniband */
533 #define DBG_DRVGRAPHICS 18 /* Graphics */
534 #define DBG_DRVSD 19 /* Secure Digital */
535 #define DBG_DRVNAND 20 /* NAND drivers and layers */
536 #define DBG_SSD 21 /* SSD */
537 #define DBG_DRVSPI 22 /* SPI */
539 /* Backwards compatibility */
540 #define DBG_DRVPOINTING DBG_DRVHID /* OBSOLETE: Use DBG_DRVHID instead */
541 #define DBG_DRVDISK DBG_DRVSTORAGE /* OBSOLETE: Use DBG_DRVSTORAGE instead */
543 /* **** The Kernel Debug Sub Classes for the DLIL Layer (DBG_DLIL) **** */
544 #define DBG_DLIL_STATIC 1 /* Static DLIL code */
545 #define DBG_DLIL_PR_MOD 2 /* DLIL Protocol Module */
546 #define DBG_DLIL_IF_MOD 3 /* DLIL Interface Module */
547 #define DBG_DLIL_PR_FLT 4 /* DLIL Protocol Filter */
548 #define DBG_DLIL_IF_FLT 5 /* DLIL Interface FIlter */
550 /* The Kernel Debug Sub Classes for File System (DBG_FSYSTEM) */
551 #define DBG_FSRW 1 /* reads and writes to the filesystem */
552 #define DBG_DKRW 2 /* reads and writes to the disk */
553 #define DBG_FSVN 3 /* vnode operations (inc. locking/unlocking) */
554 #define DBG_FSLOOOKUP 4 /* namei and other lookup-related operations */
555 #define DBG_JOURNAL 5 /* journaling operations */
556 #define DBG_IOCTL 6 /* ioctl to the disk */
557 #define DBG_BOOTCACHE 7 /* bootcache operations */
558 #define DBG_HFS 8 /* HFS-specific events; see bsd/hfs/hfs_kdebug.h */
559 #define DBG_EXFAT 0xE /* ExFAT-specific events; see the exfat project */
560 #define DBG_MSDOS 0xF /* FAT-specific events; see the msdosfs project */
561 #define DBG_ACFS 0x10 /* Xsan-specific events; see the XsanFS project */
562 #define DBG_THROTTLE 0x11 /* I/O Throttling events */
563 #define DBG_CONTENT_PROT 0xCF /* Content Protection Events: see bsd/sys/cprotect.h */
566 * For Kernel Debug Sub Class DBG_HFS, state bits for hfs_update event
568 #define DBG_HFS_UPDATE_ACCTIME 0x01
569 #define DBG_HFS_UPDATE_MODTIME 0x02
570 #define DBG_HFS_UPDATE_CHGTIME 0x04
571 #define DBG_HFS_UPDATE_MODIFIED 0x08
572 #define DBG_HFS_UPDATE_FORCE 0x10
573 #define DBG_HFS_UPDATE_DATEADDED 0x20
574 #define DBG_HFS_UPDATE_MINOR 0x40
575 #define DBG_HFS_UPDATE_SKIPPED 0x80
577 /* The Kernel Debug Sub Classes for BSD */
578 #define DBG_BSD_PROC 0x01 /* process/signals related */
579 #define DBG_BSD_MEMSTAT 0x02 /* memorystatus / jetsam operations */
580 #define DBG_BSD_EXCP_SC 0x0C /* System Calls */
581 #define DBG_BSD_AIO 0x0D /* aio (POSIX async IO) */
582 #define DBG_BSD_SC_EXTENDED_INFO 0x0E /* System Calls, extended info */
583 #define DBG_BSD_SC_EXTENDED_INFO2 0x0F /* System Calls, extended info */
586 /* The Codes for BSD subcode class DBG_BSD_PROC */
587 #define BSD_PROC_EXIT 1 /* process exit */
588 #define BSD_PROC_FRCEXIT 2 /* Kernel force termination */
590 /* Codes for BSD subcode class DBG_BSD_MEMSTAT */
591 #define BSD_MEMSTAT_SCAN 1 /* memorystatus thread awake */
592 #define BSD_MEMSTAT_JETSAM 2 /* LRU jetsam */
593 #define BSD_MEMSTAT_JETSAM_HIWAT 3 /* highwater jetsam */
594 #define BSD_MEMSTAT_FREEZE 4 /* freeze process */
595 #define BSD_MEMSTAT_LATENCY_COALESCE 5 /* delay imposed to coalesce jetsam reports */
596 #define BSD_MEMSTAT_UPDATE 6 /* priority update */
597 #define BSD_MEMSTAT_IDLE_DEMOTE 7 /* idle demotion fired */
598 #define BSD_MEMSTAT_CLEAR_ERRORS 8 /* reset termination error state */
599 #define BSD_MEMSTAT_DIRTY_TRACK 9 /* track the process state */
600 #define BSD_MEMSTAT_DIRTY_SET 10 /* set the process state */
601 #define BSD_MEMSTAT_DIRTY_CLEAR 11 /* clear the process state */
603 #define BSD_MEMSTAT_GRP_SET_PROP 12 /* set group properties */
604 #define BSD_MEMSTAT_DO_KILL 13 /* memorystatus kills */
607 /* The Kernel Debug Sub Classes for DBG_TRACE */
608 #define DBG_TRACE_DATA 0
609 #define DBG_TRACE_STRING 1
610 #define DBG_TRACE_INFO 2
612 /* The Kernel Debug events: */
613 #define TRACE_DATA_NEWTHREAD (TRACEDBG_CODE(DBG_TRACE_DATA, 1))
614 #define TRACE_DATA_EXEC (TRACEDBG_CODE(DBG_TRACE_DATA, 2))
615 #define TRACE_DATA_THREAD_TERMINATE (TRACEDBG_CODE(DBG_TRACE_DATA, 3))
616 #define TRACE_STRING_GLOBAL (TRACEDBG_CODE(DBG_TRACE_STRING, 0))
617 #define TRACE_STRING_NEWTHREAD (TRACEDBG_CODE(DBG_TRACE_STRING, 1))
618 #define TRACE_STRING_EXEC (TRACEDBG_CODE(DBG_TRACE_STRING, 2))
619 #define TRACE_PANIC (TRACEDBG_CODE(DBG_TRACE_INFO, 0))
620 #define TRACE_TIMESTAMPS (TRACEDBG_CODE(DBG_TRACE_INFO, 1))
621 #define TRACE_LOST_EVENTS (TRACEDBG_CODE(DBG_TRACE_INFO, 2))
622 #define TRACE_WRITING_EVENTS (TRACEDBG_CODE(DBG_TRACE_INFO, 3))
623 #define TRACE_INFO_STRING (TRACEDBG_CODE(DBG_TRACE_INFO, 4))
625 /* The Kernel Debug Sub Classes for DBG_CORESTORAGE */
628 /* The Kernel Debug Sub Classes for DBG_SECURITY */
629 #define DBG_SEC_KERNEL 0 /* raw entropy collected by the kernel */
631 /* Sub-class codes for CoreGraphics (DBG_CG) are defined in its component. */
633 /* The Kernel Debug Sub Classes for DBG_MISC */
634 #define DBG_EVENT 0x10
635 #define DBG_BUFFER 0x20
637 /* The Kernel Debug Sub Classes for DBG_DYLD */
638 #define DBG_DYLD_STRING 5
640 /* The Kernel Debug modifiers for the DBG_DKRW sub class */
641 #define DKIO_DONE 0x01
642 #define DKIO_READ 0x02
643 #define DKIO_ASYNC 0x04
644 #define DKIO_META 0x08
645 #define DKIO_PAGING 0x10
646 #define DKIO_THROTTLE 0x20 /* Deprecated, still provided so fs_usage doesn't break */
647 #define DKIO_PASSIVE 0x40
648 #define DKIO_NOCACHE 0x80
649 #define DKIO_TIER_MASK 0xF00
650 #define DKIO_TIER_SHIFT 8
652 /* Kernel Debug Sub Classes for Applications (DBG_APPS) */
653 #define DBG_APP_LOGINWINDOW 0x03
654 #define DBG_APP_AUDIO 0x04
655 #define DBG_APP_SIGPOST 0x0A
656 #define DBG_APP_APPKIT 0x0C
657 #define DBG_APP_SAMBA 0x80
659 /* Kernel Debug codes for Throttling (DBG_THROTTLE) */
660 #define OPEN_THROTTLE_WINDOW 0x1
661 #define PROCESS_THROTTLED 0x2
662 #define IO_THROTTLE_DISABLE 0x3
665 /* Subclasses for MACH Importance Policies (DBG_IMPORTANCE) */
666 /* TODO: Split up boost and task policy? */
667 #define IMP_ASSERTION 0x10 /* Task takes/drops a boost assertion */
668 #define IMP_BOOST 0x11 /* Task boost level changed */
669 #define IMP_MSG 0x12 /* boosting message sent by donating task on donating port */
670 #define IMP_WATCHPORT 0x13 /* port marked as watchport, and boost was transferred to the watched task */
671 #define IMP_TASK_SUPPRESSION 0x17 /* Task changed suppression behaviors */
672 #define IMP_TASK_APPTYPE 0x18 /* Task launched with apptype */
673 #define IMP_UPDATE 0x19 /* Requested -> effective calculation */
674 #define IMP_USYNCH_QOS_OVERRIDE 0x1A /* Userspace synchronization applied QoS override to resource owning thread */
675 #define IMP_DONOR_CHANGE 0x1B /* The iit_donor bit changed */
676 #define IMP_MAIN_THREAD_QOS 0x1C /* The task's main thread QoS was set */
677 /* DBG_IMPORTANCE subclasses 0x20 - 0x3F reserved for task policy flavors */
679 /* Codes for IMP_ASSERTION */
680 #define IMP_HOLD 0x2 /* Task holds a boost assertion */
681 #define IMP_DROP 0x4 /* Task drops a boost assertion */
682 #define IMP_EXTERN 0x8 /* boost assertion moved from kernel to userspace responsibility (externalized) */
684 /* Codes for IMP_BOOST */
685 #define IMP_BOOSTED 0x1
686 #define IMP_UNBOOSTED 0x2 /* Task drops a boost assertion */
688 /* Codes for IMP_MSG */
689 #define IMP_MSG_SEND 0x1 /* boosting message sent by donating task on donating port */
690 #define IMP_MSG_DELV 0x2 /* boosting message delivered to task */
692 /* Codes for IMP_UPDATE */
693 #define IMP_UPDATE_TASK_CREATE 0x1
695 /* Codes for IMP_USYNCH_QOS_OVERRIDE */
696 #define IMP_USYNCH_ADD_OVERRIDE 0x0 /* add override for a contended resource */
697 #define IMP_USYNCH_REMOVE_OVERRIDE 0x1 /* remove override for a contended resource */
699 /* Codes for IMP_DONOR_CHANGE */
700 #define IMP_DONOR_UPDATE_LIVE_DONOR_STATE 0x0
701 #define IMP_DONOR_INIT_DONOR_STATE 0x1
703 /* Subclasses for MACH Bank Voucher Attribute Manager (DBG_BANK) */
704 #define BANK_ACCOUNT_INFO 0x10 /* Trace points related to bank account struct */
705 #define BANK_TASK_INFO 0x11 /* Trace points related to bank task struct */
707 /* Subclasses for MACH ATM Voucher Attribute Manager (ATM) */
708 #define ATM_SUBAID_INFO 0x10
709 #define ATM_GETVALUE_INFO 0x20
710 #define ATM_UNREGISTER_INFO 0x30
712 /* Codes for BANK_ACCOUNT_INFO */
713 #define BANK_SETTLE_CPU_TIME 0x1 /* Bank ledger(chit) rolled up to tasks. */
715 /* Codes for ATM_SUBAID_INFO */
716 #define ATM_MIN_CALLED 0x1
717 #define ATM_LINK_LIST_TRIM 0x2
719 /* Codes for ATM_GETVALUE_INFO */
720 #define ATM_VALUE_REPLACED 0x1
721 #define ATM_VALUE_ADDED 0x2
723 /* Codes for ATM_UNREGISTER_INFO */
724 #define ATM_VALUE_UNREGISTERED 0x1
725 #define ATM_VALUE_DIFF_MAILBOX 0x2
727 /* Kernel Debug Sub Classes for daemons (DBG_DAEMON) */
728 #define DBG_DAEMON_COREDUET 0x1
730 /**********************************************************************/
732 #define KDBG_MIGCODE(msgid) ((DBG_MIG << KDBG_CLASS_OFFSET) | \
733 (((msgid) & 0x3fffff) << KDBG_CODE_OFFSET))
735 #define MACHDBG_CODE(SubClass, code) KDBG_CODE(DBG_MACH, SubClass, code)
736 #define NETDBG_CODE(SubClass, code) KDBG_CODE(DBG_NETWORK, SubClass, code)
737 #define FSDBG_CODE(SubClass, code) KDBG_CODE(DBG_FSYSTEM, SubClass, code)
738 #define BSDDBG_CODE(SubClass, code) KDBG_CODE(DBG_BSD, SubClass, code)
739 #define IOKDBG_CODE(SubClass, code) KDBG_CODE(DBG_IOKIT, SubClass, code)
740 #define DRVDBG_CODE(SubClass, code) KDBG_CODE(DBG_DRIVERS, SubClass, code)
741 #define TRACEDBG_CODE(SubClass,code) KDBG_CODE(DBG_TRACE, SubClass, code)
742 #define MISCDBG_CODE(SubClass,code) KDBG_CODE(DBG_MISC, SubClass, code)
743 #define DLILDBG_CODE(SubClass,code) KDBG_CODE(DBG_DLIL, SubClass, code)
744 #define SECURITYDBG_CODE(SubClass,code) KDBG_CODE(DBG_SECURITY, SubClass, code)
745 #define DYLDDBG_CODE(SubClass,code) KDBG_CODE(DBG_DYLD, SubClass, code)
746 #define QTDBG_CODE(SubClass,code) KDBG_CODE(DBG_QT, SubClass, code)
747 #define APPSDBG_CODE(SubClass,code) KDBG_CODE(DBG_APPS, SubClass, code)
748 #define ARIADNEDBG_CODE(SubClass, code) KDBG_CODE(DBG_ARIADNE, SubClass, code)
749 #define DAEMONDBG_CODE(SubClass, code) KDBG_CODE(DBG_DAEMON, SubClass, code)
750 #define CPUPM_CODE(code) IOKDBG_CODE(DBG_IOCPUPM, code)
752 #define KMEM_ALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 0)
753 #define KMEM_ALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 1)
754 #define KMEM_FREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 2)
755 #define KMEM_FREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 3)
756 #define ZALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 4)
757 #define ZALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 5)
758 #define ZFREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 6)
759 #define ZFREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 7)
761 #define PMAP_CODE(code) MACHDBG_CODE(DBG_MACH_PMAP, code)
764 #define IMPORTANCE_CODE(SubClass, code) KDBG_CODE(DBG_IMPORTANCE, (SubClass), (code))
765 #define BANK_CODE(SubClass, code) KDBG_CODE(DBG_BANK, (SubClass), (code))
766 #define ATM_CODE(SubClass, code) KDBG_CODE(DBG_ATM, (SubClass), (code))
768 /* Kernel Debug Macros for specific daemons */
769 #define COREDUETDBG_CODE(code) DAEMONDBG_CODE(DBG_DAEMON_COREDUET, code)
772 * kernel_debug((KDBG_CODE(DBG_NETWORK, DNET_PROTOCOL, 51) | DBG_FUNC_START),
777 * #include <sys/kdebug.h>
779 * #define DBG_NETIPINIT NETDBG_CODE(DBG_NETIP,1)
785 * register struct protosw *pr;
788 * KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_START, 0,0,0,0,0)
790 * KERNEL_DEBUG(DBG_NETIPINIT, 0,0,0,0,0)
792 * KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_END, 0,0,0,0,0)
798 extern unsigned int kdebug_enable
;
799 #define KDEBUG_ENABLE_TRACE 0x1
800 #define KDEBUG_ENABLE_ENTROPY 0x2 /* Obsolescent */
801 #define KDEBUG_ENABLE_CHUD 0x4
802 #define KDEBUG_ENABLE_PPT 0x8
803 #define KDEBUG_ENABLE_SERIAL 0x10
806 * Infer the supported kernel debug event level from config option.
807 * Use (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) as a guard to protect
808 * unaudited debug code.
810 #define KDEBUG_LEVEL_NONE 0
811 #define KDEBUG_LEVEL_IST 1
812 #define KDEBUG_LEVEL_STANDARD 2
813 #define KDEBUG_LEVEL_FULL 3
816 #define KDEBUG_LEVEL KDEBUG_LEVEL_NONE
818 #define KDEBUG_LEVEL KDEBUG_LEVEL_IST
819 // currently configured for the iOS release kernel
821 #define KDEBUG_LEVEL KDEBUG_LEVEL_FULL
823 #define KDEBUG_LEVEL KDEBUG_LEVEL_STANDARD
824 /* Currently, all other kernel configurations (development, etc)
825 build with KDEBUG_LEVEL_STANDARD. As a result, KERNEL_DEBUG_CONSTANT*()
826 are on by default but KERNEL_DEBUG*() are not.
830 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
831 #ifdef XNU_KERNEL_PRIVATE
832 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \
834 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
835 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
836 (uintptr_t)d,(uintptr_t)e); \
839 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \
841 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
842 kernel_debug1(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
843 (uintptr_t)d,(uintptr_t)e); \
846 #define KERNEL_DEBUG_EARLY(x,a,b,c,d) \
848 kernel_debug_early((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
849 (uintptr_t)c, (uintptr_t)d); \
851 #else /* XNU_KERNEL_PRIVATE */
852 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \
854 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
855 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
856 (uintptr_t)d,(uintptr_t)e); \
859 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \
861 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
862 kernel_debug1(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
863 (uintptr_t)d,(uintptr_t)e); \
866 #define KERNEL_DEBUG_EARLY(x,a,b,c,d) \
868 kernel_debug_early((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
869 (uintptr_t)c, (uintptr_t)d); \
871 #endif /* XNU_KERNEL_PRIVATE */
872 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
873 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) do { } while(0)
874 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) do { } while(0)
875 #define KERNEL_DEBUG_EARLY(x,a,b,c,d) do { } while(0)
876 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
878 #ifdef KERNEL_PRIVATE
880 // Abbreviated version of above
881 #define KDBG(x, ...) KDBG_(x, ## __VA_ARGS__, 5, 4, 3, 2, 1, 0)
882 #define KDBG_(x, a, b, c, d, e, n, ...) KDBG##n(x, a, b, c, d, e)
883 #define KDBG0(x, a, b, c, d, e) KERNEL_DEBUG_CONSTANT(x, 0, 0, 0, 0, 0)
884 #define KDBG1(x, a, b, c, d, e) KERNEL_DEBUG_CONSTANT(x, a, 0, 0, 0, 0)
885 #define KDBG2(x, a, b, c, d, e) KERNEL_DEBUG_CONSTANT(x, a, b, 0, 0, 0)
886 #define KDBG3(x, a, b, c, d, e) KERNEL_DEBUG_CONSTANT(x, a, b, c, 0, 0)
887 #define KDBG4(x, a, b, c, d, e) KERNEL_DEBUG_CONSTANT(x, a, b, c, d, 0)
888 #define KDBG5(x, a, b, c, d, e) KERNEL_DEBUG_CONSTANT(x, a, b, c, d, e)
890 #endif // KERNEL_PRIVATE
893 * Specify KDEBUG_PPT to indicate that the event belongs to the
896 #define KDEBUG_COMMON (KDEBUG_ENABLE_TRACE|KDEBUG_ENABLE_CHUD|KDEBUG_ENABLE_PPT)
897 #define KDEBUG_TRACE (KDEBUG_ENABLE_TRACE|KDEBUG_ENABLE_CHUD)
898 #define KDEBUG_PPT (KDEBUG_ENABLE_PPT)
901 KERNEL_DEBUG_CONSTANT_IST events provide an audited subset of
902 tracepoints for userland system tracing tools. This tracing level was
903 created by 8857227 to protect fairplayd and other PT_DENY_ATTACH
904 processes. It has two effects: only KERNEL_DEBUG_CONSTANT_IST() traces
905 are emitted and any PT_DENY_ATTACH processes will only emit basic
906 traces as defined by the kernel_debug_filter() routine.
908 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST)
909 #ifdef XNU_KERNEL_PRIVATE
910 #define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) \
912 if (__improbable(kdebug_enable & type)) \
913 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
914 (uintptr_t)d,(uintptr_t)e); \
916 #else /* XNU_KERNEL_PRIVATE */
917 #define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) \
919 if (kdebug_enable & type) \
920 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
921 (uintptr_t)d,(uintptr_t)e); \
923 #endif /* XNU_KERNEL_PRIVATE */
925 // whether to bother calculating EnergyTracing inputs
926 // could chnage in future to see if DBG_ENERGYTRACE is active
927 #define ENTR_SHOULDTRACE kdebug_enable
928 // encode logical EnergyTracing into 32/64 KDebug trace
929 #define ENTR_KDTRACE(component, opcode, lifespan, id, quality, value) \
932 uintptr_t highval__, lowval__, mask__ = 0xffffffff; \
933 kdcode__ = KDBG_CODE(DBG_ENERGYTRACE,component,opcode)|(lifespan); \
934 highval__ = ((value) >> 32) & mask__; \
935 lowval__ = (value) & mask__; \
936 ENTR_KDTRACEFUNC(kdcode__, id, quality, highval__, lowval__); \
940 Trace the association of two existing activations.
942 An association is traced as a modification to the parent activation.
943 In order to fit the sub-activation's component, activation code, and
944 activation ID into a kdebug tracepoint, the arguments that would hold
945 the value are left separate, and one stores the component and opcode
946 of the sub-activation, while the other stores the pointer-sized
950 +-----------------+ +~+----+----+--------+ +----------+
951 |kEnTrModAssociate| | | | | | | |
952 +-----------------+ +~+----+----+--------+ +----------+
953 8-bits unused sub-activation ID
958 #define kEnTrModAssociate (1 << 28)
959 #define ENTR_KDASSOCIATE(par_comp, par_opcode, par_act_id, \
960 sub_comp, sub_opcode, sub_act_id) \
962 unsigned sub_compcode = ((unsigned)sub_comp << 16) | sub_opcode; \
963 ENTR_KDTRACEFUNC(KDBG_CODE(DBG_ENERGYTRACE,par_comp,par_opcode), \
964 par_act_id, kEnTrModAssociate, sub_compcode, \
968 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
970 #define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) do { } while(0)
971 #define ENTR_SHOULDTRACE FALSE
972 #define ENTR_KDTRACE(component, opcode, lifespan, id, quality, value) \
974 #define ENTR_KDASSOCIATE(par_comp, par_opcode, par_act_id, \
975 sub_comp, sub_opcode, sub_act_id) \
978 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
981 #define __kdebug_constant_only __unused
984 extern void kernel_debug(
992 extern void kernel_debug1(
1000 extern void kernel_debug_early(
1007 #ifdef KERNEL_PRIVATE
1009 * kernel_debug_string provides the same functionality as the
1010 * kdebug_trace_string syscall as a KPI. str_id is an in/out
1011 * parameter that, if it's pointing to a string ID of 0, will
1012 * receive a generated ID. If it provides a value in str_id,
1013 * then that will be used, instead.
1015 * Returns an errno indicating the type of failure.
1018 kernel_debug_string(uint32_t debugid
, uint64_t *str_id
, const char *str
);
1021 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL)
1022 #ifdef XNU_KERNEL_PRIVATE
1023 #define KERNEL_DEBUG(x,a,b,c,d,e) \
1025 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
1026 kernel_debug((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
1027 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
1030 #define KERNEL_DEBUG1(x,a,b,c,d,e) \
1032 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
1033 kernel_debug1((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
1034 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
1037 #define __kdebug_only
1038 #else /* !XNU_KERNEL_PRIVATE */
1039 #define KERNEL_DEBUG(x,a,b,c,d,e) \
1041 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
1042 kernel_debug((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
1043 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
1046 #define KERNEL_DEBUG1(x,a,b,c,d,e) \
1048 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
1049 kernel_debug1((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
1050 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
1052 #endif /* XNU_KERNEL_PRIVATE */
1054 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
1056 #define KERNEL_DEBUG(x,a,b,c,d,e) do {} while (0)
1057 #define KERNEL_DEBUG1(x,a,b,c,d,e) do {} while (0)
1059 #define __kdebug_only __unused
1060 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
1063 // for EnergyTracing user space & clients
1064 #define kEnTrCompKernel 2
1067 EnergyTracing opcodes
1069 Activations use DBG_FUNC_START/END.
1070 Events are DBG_FUNC_NONE.
1073 /* Socket reads and writes are uniquely identified by the (sanitized)
1074 pointer to the socket struct in question. To associate this address
1075 with the user space file descriptor, we have a socket activation with
1076 the FD as its identifier and the socket struct pointer as its value.
1078 #define kEnTrActKernSocket 1
1079 #define kEnTrActKernSockRead 2
1080 #define kEnTrActKernSockWrite 3
1082 #define kEnTrActKernPoll 10
1083 #define kEnTrActKernSelect 11
1084 #define kEnTrActKernKQWait 12
1087 #define kEnTrEvUnblocked 256
1089 // EnergyTracing flags (the low-order 16 bits of 'quality')
1090 #define kEnTrFlagNonBlocking 1 << 0
1091 #define kEnTrFlagNoWork 1 << 1
1093 // and now the internal mechanism
1094 #ifdef KERNEL_PRIVATE
1096 // 20452597 requests that the trace macros not take an argument it throws away
1097 #define KERNEL_DBG_IST_SANE(x, a, b, c, d) \
1098 KERNEL_DEBUG_CONSTANT_IST(KDEBUG_TRACE, x, a, b, c, d, \
1099 0 /*__unused in kernel_debug()*/)
1100 #define ENTR_KDTRACEFUNC KERNEL_DBG_IST_SANE
1102 // value is int64_t, quality is uint32_t
1103 #define KERNEL_ENERGYTRACE(opcode, lifespan, id, quality, value) \
1104 ENTR_KDTRACE(kEnTrCompKernel, opcode, lifespan, id, \
1106 #define KERNEL_ENTR_ASSOCIATE(par_opcode, par_act_id, sub_opcode, sub_act_id) \
1107 ENTR_KDASSOCIATE(kEnTrCompKernel, par_opcode, par_act_id, \
1108 kEnTrCompKernel, sub_opcode, sub_act_id)
1110 // end EnergyTracing
1113 #include <mach/boolean.h>
1119 extern void kdebug_lookup_gen_events(long *dbg_parms
, int dbg_namelen
, void *dp
, boolean_t lookup
);
1120 extern void kdbg_trace_data(struct proc
*proc
, long *arg_pid
);
1122 extern void kdbg_trace_string(struct proc
*proc
, long *arg1
, long *arg2
, long *arg3
, long *arg4
);
1124 extern void kdbg_dump_trace_to_file(const char *);
1125 void start_kern_tracing(unsigned int, boolean_t
);
1126 void start_kern_tracing_with_typefilter(unsigned int, boolean_t
, unsigned int);
1128 extern void kdbg_get_task_name(char*, int, struct task
*task
);
1129 void disable_wrap(uint32_t *old_slowcheck
, uint32_t *old_flags
);
1130 void enable_wrap(uint32_t old_slowcheck
, boolean_t lostevents
);
1131 void release_storage_unit(int cpu
, uint32_t storage_unit
);
1132 int allocate_storage_unit(int cpu
);
1134 #define KDBG_CLASS_ENCODE(Class, SubClass) KDBG_EVENTID(Class, SubClass, 0)
1135 #define KDBG_CLASS_DECODE(Debugid) (Debugid & KDBG_CSC_MASK)
1138 #endif /* KERNEL_PRIVATE */
1141 #endif /* __APPLE_API_UNSTABLE */
1146 #ifdef __APPLE_API_PRIVATE
1148 * private kernel_debug definitions
1157 uintptr_t arg5
; /* will hold current thread */
1159 #if defined(__LP64__)
1165 #if !defined(__LP64__)
1166 #define KDBG_TIMESTAMP_MASK 0x00ffffffffffffffULL
1167 #define KDBG_CPU_MASK 0xff00000000000000ULL
1168 #define KDBG_CPU_SHIFT 56
1170 kdbg_set_cpu(kd_buf
*kp
, int cpu
)
1172 kp
->timestamp
= (kp
->timestamp
& KDBG_TIMESTAMP_MASK
) |
1173 (((uint64_t) cpu
) << KDBG_CPU_SHIFT
);
1176 kdbg_get_cpu(kd_buf
*kp
)
1178 return (int) (((kp
)->timestamp
& KDBG_CPU_MASK
) >> KDBG_CPU_SHIFT
);
1181 kdbg_set_timestamp(kd_buf
*kp
, uint64_t thetime
)
1183 kp
->timestamp
= thetime
& KDBG_TIMESTAMP_MASK
;
1185 static inline uint64_t
1186 kdbg_get_timestamp(kd_buf
*kp
)
1188 return kp
->timestamp
& KDBG_TIMESTAMP_MASK
;
1191 kdbg_set_timestamp_and_cpu(kd_buf
*kp
, uint64_t thetime
, int cpu
)
1193 kp
->timestamp
= (thetime
& KDBG_TIMESTAMP_MASK
) |
1194 (((uint64_t) cpu
) << KDBG_CPU_SHIFT
);
1197 #define KDBG_TIMESTAMP_MASK 0xffffffffffffffffULL
1199 kdbg_set_cpu(kd_buf
*kp
, int cpu
)
1204 kdbg_get_cpu(kd_buf
*kp
)
1209 kdbg_set_timestamp(kd_buf
*kp
, uint64_t thetime
)
1211 kp
->timestamp
= thetime
;
1213 static inline uint64_t
1214 kdbg_get_timestamp(kd_buf
*kp
)
1216 return kp
->timestamp
;
1219 kdbg_set_timestamp_and_cpu(kd_buf
*kp
, uint64_t thetime
, int cpu
)
1221 kdbg_set_timestamp(kp
, thetime
);
1222 kdbg_set_cpu(kp
, cpu
);
1226 /* 2^16 bits (8 kilobytes), one for each possible class/subclass combination */
1227 #define KDBG_TYPEFILTER_BITMAP_SIZE ( (256 * 256) / 8 )
1230 #define KDBG_INIT 0x001
1231 #define KDBG_NOWRAP 0x002
1232 #define KDBG_FREERUN 0x004
1233 #define KDBG_WRAPPED 0x008
1234 #define KDBG_USERFLAGS (KDBG_FREERUN|KDBG_NOWRAP|KDBG_INIT)
1235 #define KDBG_PIDCHECK 0x010
1236 #define KDBG_MAPINIT 0x020
1237 #define KDBG_PIDEXCLUDE 0x040
1238 #define KDBG_LOCKINIT 0x080
1239 #define KDBG_LP64 0x100
1243 unsigned int value1
;
1244 unsigned int value2
;
1245 unsigned int value3
;
1246 unsigned int value4
;
1266 uint32_t version_no
;
1271 #define KDBG_CPUMAP_IS_IOP 0x1
1280 * TRACE file formats...
1284 * uint32_t #threadmaps
1290 * RAW_header, with version_no set to RAW_VERSION1
1292 * Empty space to pad alignment to the nearest page boundary.
1297 * RAW_header, with version_no set to RAW_VERSION1
1299 * kd_cpumap_header, with version_no set to RAW_VERSION1
1301 * Empty space to pad alignment to the nearest page boundary.
1304 * V1+ implementation details...
1306 * It would have been nice to add the cpumap data "correctly", but there were
1307 * several obstacles. Existing code attempts to parse both V1 and V0 files.
1308 * Due to the fact that V0 has no versioning or header, the test looks like
1312 * if (header.version_no != RAW_VERSION1) { // Assume V0 }
1314 * If we add a VERSION2 file format, all existing code is going to treat that
1315 * as a VERSION0 file when reading it, and crash terribly when trying to read
1316 * RAW_VERSION2 threadmap entries.
1318 * To differentiate between a V1 and V1+ file, read as V1 until you reach
1319 * the padding bytes. Then:
1321 * boolean_t is_v1plus = FALSE;
1322 * if (padding_bytes >= sizeof(kd_cpumap_header)) {
1323 * kd_cpumap_header header = // read header;
1324 * if (header.version_no == RAW_VERSION1) {
1339 // The header chunk has the tag 0x00001000 which also serves as a magic word
1340 // that identifies the file as a version 3 trace file. The header payload is
1341 // a set of fixed fields followed by a variable number of sub-chunks:
1343 ____________________________________________________________________________
1344 | Offset | Size | Field |
1345 ----------------------------------------------------------------------------
1346 | 0 | 4 | Tag (0x00001000) |
1347 | 4 | 4 | Sub-tag. Represents the version of the header. |
1348 | 8 | 8 | Length of header payload (40+8x) |
1349 | 16 | 8 | Time base info. Two 32-bit numbers, numer/denom, |
1350 | | | for converting timestamps to nanoseconds. |
1351 | 24 | 8 | Timestamp of trace start. |
1352 | 32 | 8 | Wall time seconds since Unix epoch. |
1353 | | | As returned by gettimeofday(). |
1354 | 40 | 4 | Wall time microseconds. As returned by gettimeofday(). |
1355 | 44 | 4 | Local time zone offset in minutes. ( " ) |
1356 | 48 | 4 | Type of daylight savings time correction to apply. ( " ) |
1357 | 52 | 4 | Flags. 1 = 64-bit. Remaining bits should be written |
1358 | | | as 0 and ignored when reading. |
1359 | 56 | 8x | Variable number of sub-chunks. None are required. |
1360 | | | Ignore unknown chunks. |
1361 ----------------------------------------------------------------------------
1363 // NOTE: The header sub-chunks are considered part of the header chunk,
1364 // so they must be included in the header chunk’s length field.
1365 // The CPU map is an optional sub-chunk of the header chunk. It provides
1366 // information about the CPUs that are referenced from the trace events.
1371 uint32_t timebase_numer
;
1372 uint32_t timebase_denom
;
1374 uint64_t walltime_secs
;
1375 uint32_t walltime_usecs
;
1376 uint32_t timezone_minuteswest
;
1377 uint32_t timezone_dst
;
1385 } kd_chunk_header_v3
;
1387 #define RAW_VERSION0 0x55aa0000
1388 #define RAW_VERSION1 0x55aa0101
1389 #define RAW_VERSION2 0x55aa0200 /* Only used by kperf and Instruments */
1390 #define RAW_VERSION3 0x00001000
1392 #define V3_CONFIG 0x00001b00
1393 #define V3_CPU_MAP 0x00001c00
1394 #define V3_THREAD_MAP 0x00001d00
1395 #define V3_RAW_EVENTS 0x00001e00
1396 #define V3_NULL_CHUNK 0x00002000
1398 // The current version of all kernel managed chunks is 1. The
1399 // V3_CURRENT_CHUNK_VERSION is added to ease the simple case
1400 // when most/all the kernel managed chunks have the same version.
1402 #define V3_CURRENT_CHUNK_VERSION 1
1403 #define V3_HEADER_VERSION V3_CURRENT_CHUNK_VERSION
1404 #define V3_CPUMAP_VERSION V3_CURRENT_CHUNK_VERSION
1405 #define V3_THRMAP_VERSION V3_CURRENT_CHUNK_VERSION
1406 #define V3_EVENT_DATA_VERSION V3_CURRENT_CHUNK_VERSION
1408 // Apis to support writing v3 chunks in the kernel
1409 int kdbg_write_v3_chunk_header_to_buffer(void *buffer
, uint32_t tag
, uint32_t sub_tag
, uint64_t length
);
1410 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
);
1412 #define KDBG_CLASSTYPE 0x10000
1413 #define KDBG_SUBCLSTYPE 0x20000
1414 #define KDBG_RANGETYPE 0x40000
1415 #define KDBG_TYPENONE 0x80000
1416 #define KDBG_CKTYPES 0xF0000
1418 #define KDBG_RANGECHECK 0x100000
1419 #define KDBG_VALCHECK 0x200000 /* Check up to 4 individual values */
1421 #define KDBG_TYPEFILTER_CHECK ((uint32_t) 0x400000) /* Check class and subclass against a bitmap */
1423 #define KDBG_BUFINIT 0x80000000
1425 /* Minimum value allowed when setting decrementer ticks */
1426 #define KDBG_MINRTCDEC 2500
1428 /* VFS lookup events for serial traces */
1429 #define VFS_LOOKUP (FSDBG_CODE(DBG_FSRW,36))
1430 #define VFS_LOOKUP_DONE (FSDBG_CODE(DBG_FSRW,39))
1432 #ifdef XNU_KERNEL_PRIVATE
1433 #if (DEVELOPMENT || DEBUG)
1434 #define KDEBUG_MOJO_TRACE 1
1438 #endif /* __APPLE_API_PRIVATE */
1439 #endif /* PRIVATE */
1441 #endif /* !BSD_SYS_KDEBUG_H */