this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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