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