1 /* 2 * Copyright (c) 2000-2014 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 /* Copyright (c) 1997 Apple Computer, Inc. All rights reserved. 30 * 31 * kdebug.h - kernel_debug definitions 32 * 33 */ 34 35 #ifndef BSD_SYS_KDEBUG_H 36 #define BSD_SYS_KDEBUG_H 37 38 #include <sys/appleapiopts.h> 39 #include <sys/cdefs.h> 40 __BEGIN_DECLS 41 42 #ifdef __APPLE_API_UNSTABLE 43 44 #include <mach/clock_types.h> 45 #include <stdint.h> 46 #if defined(KERNEL_BUILD) 47 #include <kdebug.h> 48 #endif /* KERNEL_BUILD */ 49 50 51 typedef enum 52 { 53 KD_CALLBACK_KDEBUG_ENABLED, // Trace is now enabled. No arguments 54 KD_CALLBACK_KDEBUG_DISABLED, // Trace is now disabled. No arguments 55 KD_CALLBACK_SYNC_FLUSH, // Request the latest entries from the IOP, and block until complete. No arguments 56 KD_CALLBACK_TYPEFILTER_CHANGED, // Typefilter is enabled. A read-only pointer to the typefilter is provided, but is only valid while in the callback. 57 } kd_callback_type; 58 typedef void (*kd_callback_fn) (void* context, kd_callback_type reason, void* arg); 59 60 struct kd_callback { 61 kd_callback_fn func; 62 void* context; 63 char iop_name[8]; // null-terminated string with name of core. 64 }; 65 66 typedef struct kd_callback kd_callback_t; 67 68 /* 69 * Registers an IOP for participation in tracing. 70 * 71 * The registered callback function will be called with the 72 * supplied context as the first argument, followed by a 73 * kd_callback_type and an associated void* argument. 74 * 75 * The return value is a nonzero coreid that shall be used in 76 * kernel_debug_enter() to refer to your IOP. If the allocation 77 * failed, then 0 will be returned. 78 * 79 * 80 * Caveats: 81 * Note that not all callback calls will indicate a change in 82 * state (e.g. disabling trace twice would send two disable 83 * notifications). 84 * 85 */ 86 extern int kernel_debug_register_callback(kd_callback_t callback); 87 88 extern void kernel_debug_enter( 89 uint32_t coreid, 90 uint32_t debugid, 91 uint64_t timestamp, 92 uintptr_t arg1, 93 uintptr_t arg2, 94 uintptr_t arg3, 95 uintptr_t arg4, 96 uintptr_t threadid 97 ); 98 99 100 /* 101 * state bits for hfs_update event 102 */ 103 #define DBG_HFS_UPDATE_ACCTIME 0x01 104 #define DBG_HFS_UPDATE_MODTIME 0x02 105 #define DBG_HFS_UPDATE_CHGTIME 0x04 106 #define DBG_HFS_UPDATE_MODIFIED 0x08 107 #define DBG_HFS_UPDATE_FORCE 0x10 108 #define DBG_HFS_UPDATE_DATEADDED 0x20 109 110 111 /* 112 * types of faults that vm_fault handles 113 * and creates trace entries for 114 */ 115 #define DBG_ZERO_FILL_FAULT 1 116 #define DBG_PAGEIN_FAULT 2 117 #define DBG_COW_FAULT 3 118 #define DBG_CACHE_HIT_FAULT 4 119 #define DBG_NZF_PAGE_FAULT 5 120 #define DBG_GUARD_FAULT 6 121 #define DBG_PAGEINV_FAULT 7 122 #define DBG_PAGEIND_FAULT 8 123 #define DBG_COMPRESSOR_FAULT 9 124 #define DBG_COMPRESSOR_SWAPIN_FAULT 10 125 126 127 /* The debug code consists of the following 128 * 129 * ---------------------------------------------------------------------- 130 *| | | |Func | 131 *| Class (8) | SubClass (8) | Code (14) |Qual(2)| 132 * ---------------------------------------------------------------------- 133 * The class specifies the higher level 134 */ 135 136 /* The Function qualifiers */ 137 #define DBG_FUNC_START 1 138 #define DBG_FUNC_END 2 139 #define DBG_FUNC_NONE 0 140 141 142 /* The Kernel Debug Classes */ 143 #define DBG_MACH 1 144 #define DBG_NETWORK 2 145 #define DBG_FSYSTEM 3 146 #define DBG_BSD 4 147 #define DBG_IOKIT 5 148 #define DBG_DRIVERS 6 149 #define DBG_TRACE 7 150 #define DBG_DLIL 8 151 #define DBG_WORKQUEUE 9 152 #define DBG_CORESTORAGE 10 153 #define DBG_CG 11 154 #define DBG_MISC 20 155 #define DBG_SECURITY 30 156 #define DBG_DYLD 31 157 #define DBG_QT 32 158 #define DBG_APPS 33 159 #define DBG_LAUNCHD 34 160 #define DBG_PERF 37 161 #define DBG_IMPORTANCE 38 162 #define DBG_BANK 40 163 #define DBG_XPC 41 164 #define DBG_ATM 42 165 166 #define DBG_MIG 255 167 168 /* **** The Kernel Debug Sub Classes for Mach (DBG_MACH) **** */ 169 #define DBG_MACH_EXCP_KTRAP_x86 0x02 /* Kernel Traps on x86 */ 170 #define DBG_MACH_EXCP_DFLT 0x03 /* Data Translation Fault */ 171 #define DBG_MACH_EXCP_IFLT 0x04 /* Inst Translation Fault */ 172 #define DBG_MACH_EXCP_INTR 0x05 /* Interrupts */ 173 #define DBG_MACH_EXCP_ALNG 0x06 /* Alignment Exception */ 174 #define DBG_MACH_EXCP_UTRAP_x86 0x07 /* User Traps on x86 */ 175 #define DBG_MACH_EXCP_FP 0x08 /* FP Unavail */ 176 #define DBG_MACH_EXCP_DECI 0x09 /* Decrementer Interrupt */ 177 #define DBG_MACH_CHUD 0x0A /* CHUD */ 178 #define DBG_MACH_EXCP_SC 0x0C /* System Calls */ 179 #define DBG_MACH_EXCP_TRACE 0x0D /* Trace exception */ 180 #define DBG_MACH_EXCP_EMUL 0x0E /* Instruction emulated */ 181 #define DBG_MACH_IHDLR 0x10 /* Interrupt Handlers */ 182 #define DBG_MACH_IPC 0x20 /* Inter Process Comm */ 183 #define DBG_MACH_VM 0x30 /* Virtual Memory */ 184 #define DBG_MACH_LEAKS 0x31 /* alloc/free */ 185 #define DBG_MACH_SCHED 0x40 /* Scheduler */ 186 #define DBG_MACH_MSGID_INVALID 0x50 /* Messages - invalid */ 187 #define DBG_MACH_LOCKS 0x60 /* new lock APIs */ 188 #define DBG_MACH_PMAP 0x70 /* pmap */ 189 /* #define unused 0x80 */ 190 #define DBG_MACH_MP 0x90 /* MP related */ 191 #define DBG_MACH_VM_PRESSURE 0xA0 /* Memory Pressure Events */ 192 #define DBG_MACH_STACKSHOT 0xA1 /* Stackshot/Microstackshot subsystem */ 193 #define DBG_MACH_SFI 0xA2 /* Selective Forced Idle (SFI) */ 194 #define DBG_MACH_ENERGY_PERF 0xA3 /* Energy/performance resource stats */ 195 196 /* Codes for Scheduler (DBG_MACH_SCHED) */ 197 #define MACH_SCHED 0x0 /* Scheduler */ 198 #define MACH_STACK_ATTACH 0x1 /* stack_attach() */ 199 #define MACH_STACK_HANDOFF 0x2 /* stack_handoff() */ 200 #define MACH_CALL_CONT 0x3 /* call_continuation() */ 201 #define MACH_CALLOUT 0x4 /* callouts */ 202 #define MACH_STACK_DETACH 0x5 203 #define MACH_MAKE_RUNNABLE 0x6 /* make thread runnable */ 204 #define MACH_PROMOTE 0x7 /* promoted due to resource */ 205 #define MACH_DEMOTE 0x8 /* promotion undone */ 206 #define MACH_IDLE 0x9 /* processor idling */ 207 #define MACH_STACK_DEPTH 0xa /* stack depth at switch */ 208 #define MACH_MOVED 0xb /* did not use original scheduling decision */ 209 #define MACH_FAIRSHARE_ENTER 0xc /* move to fairshare band */ 210 #define MACH_FAIRSHARE_EXIT 0xd /* exit fairshare band */ 211 #define MACH_FAILSAFE 0xe /* tripped fixed-pri/RT failsafe */ 212 #define MACH_BLOCK 0xf /* thread block */ 213 #define MACH_WAIT 0x10 /* thread wait assertion */ 214 #define MACH_GET_URGENCY 0x14 /* Urgency queried by platform */ 215 #define MACH_URGENCY 0x15 /* Urgency (RT/BG/NORMAL) communicated 216 * to platform 217 */ 218 #define MACH_REDISPATCH 0x16 /* "next thread" thread redispatched */ 219 #define MACH_REMOTE_AST 0x17 /* AST signal issued to remote processor */ 220 221 #define MACH_SCHED_CHOOSE_PROCESSOR 0x18 /* Result of choose_processor */ 222 #define MACH_DEEP_IDLE 0x19 /* deep idle on master processor */ 223 #define MACH_SCHED_DECAY_PRIORITY 0x1a /* timeshare thread priority decayed/restored */ 224 #define MACH_CPU_THROTTLE_DISABLE 0x1b /* Global CPU Throttle Disable */ 225 #define MACH_RW_PROMOTE 0x1c /* promoted due to RW lock promotion */ 226 #define MACH_RW_DEMOTE 0x1d /* promotion due to RW lock undone */ 227 #define MACH_SCHED_MAINTENANCE 0x1f /* periodic maintenance thread */ 228 #define MACH_DISPATCH 0x20 /* context switch completed */ 229 #define MACH_QUANTUM_HANDOFF 0x21 /* quantum handoff occurred */ 230 #define MACH_MULTIQ_DEQUEUE 0x22 /* Result of multiq dequeue */ 231 #define MACH_SCHED_THREAD_SWITCH 0x23 /* attempt direct context switch to hinted thread */ 232 #define MACH_SCHED_SMT_BALANCE 0x24 /* SMT load balancing ASTs */ 233 234 /* Variants for MACH_MULTIQ_DEQUEUE */ 235 #define MACH_MULTIQ_BOUND 1 236 #define MACH_MULTIQ_GROUP 2 237 #define MACH_MULTIQ_GLOBAL 3 238 239 /* Codes for IPC (DBG_MACH_IPC) */ 240 #define MACH_TASK_SUSPEND 0x0 /* Suspended a task */ 241 #define MACH_TASK_RESUME 0x1 /* Resumed a task */ 242 #define MACH_THREAD_SET_VOUCHER 0x2 243 #define MACH_IPC_MSG_SEND 0x3 /* mach msg send, uniq msg info */ 244 #define MACH_IPC_MSG_RECV 0x4 /* mach_msg receive */ 245 #define MACH_IPC_MSG_RECV_VOUCHER_REFUSED 0x5 /* mach_msg receive, voucher refused */ 246 #define MACH_IPC_KMSG_FREE 0x6 /* kernel free of kmsg data */ 247 #define MACH_IPC_VOUCHER_CREATE 0x7 /* Voucher added to global voucher hashtable */ 248 #define MACH_IPC_VOUCHER_CREATE_ATTR_DATA 0x8 /* Attr data for newly created voucher */ 249 #define MACH_IPC_VOUCHER_DESTROY 0x9 /* Voucher removed from global voucher hashtable */ 250 251 /* Codes for pmap (DBG_MACH_PMAP) */ 252 #define PMAP__CREATE 0x0 253 #define PMAP__DESTROY 0x1 254 #define PMAP__PROTECT 0x2 255 #define PMAP__PAGE_PROTECT 0x3 256 #define PMAP__ENTER 0x4 257 #define PMAP__REMOVE 0x5 258 #define PMAP__NEST 0x6 259 #define PMAP__UNNEST 0x7 260 #define PMAP__FLUSH_TLBS 0x8 261 #define PMAP__UPDATE_INTERRUPT 0x9 262 #define PMAP__ATTRIBUTE_CLEAR 0xa 263 #define PMAP__REUSABLE 0xb 264 #define PMAP__QUERY_RESIDENT 0xc 265 #define PMAP__FLUSH_KERN_TLBS 0xd 266 #define PMAP__FLUSH_DELAYED_TLBS 0xe 267 #define PMAP__FLUSH_TLBS_TO 0xf 268 269 /* Codes for Stackshot/Microstackshot (DBG_MACH_STACKSHOT) */ 270 #define MICROSTACKSHOT_RECORD 0x0 271 #define MICROSTACKSHOT_GATHER 0x1 272 273 /* Codes for Selective Forced Idle (DBG_MACH_SFI) */ 274 #define SFI_SET_WINDOW 0x0 275 #define SFI_CANCEL_WINDOW 0x1 276 #define SFI_SET_CLASS_OFFTIME 0x2 277 #define SFI_CANCEL_CLASS_OFFTIME 0x3 278 #define SFI_THREAD_DEFER 0x4 279 #define SFI_OFF_TIMER 0x5 280 #define SFI_ON_TIMER 0x6 281 #define SFI_WAIT_CANCELED 0x7 282 #define SFI_PID_SET_MANAGED 0x8 283 #define SFI_PID_CLEAR_MANAGED 0x9 284 285 /* **** The Kernel Debug Sub Classes for Network (DBG_NETWORK) **** */ 286 #define DBG_NETIP 1 /* Internet Protocol */ 287 #define DBG_NETARP 2 /* Address Resolution Protocol */ 288 #define DBG_NETUDP 3 /* User Datagram Protocol */ 289 #define DBG_NETTCP 4 /* Transmission Control Protocol */ 290 #define DBG_NETICMP 5 /* Internet Control Message Protocol */ 291 #define DBG_NETIGMP 6 /* Internet Group Management Protocol */ 292 #define DBG_NETRIP 7 /* Routing Information Protocol */ 293 #define DBG_NETOSPF 8 /* Open Shortest Path First */ 294 #define DBG_NETISIS 9 /* Intermediate System to Intermediate System */ 295 #define DBG_NETSNMP 10 /* Simple Network Management Protocol */ 296 #define DBG_NETSOCK 11 /* Socket Layer */ 297 298 /* For Apple talk */ 299 #define DBG_NETAARP 100 /* Apple ARP */ 300 #define DBG_NETDDP 101 /* Datagram Delivery Protocol */ 301 #define DBG_NETNBP 102 /* Name Binding Protocol */ 302 #define DBG_NETZIP 103 /* Zone Information Protocol */ 303 #define DBG_NETADSP 104 /* Name Binding Protocol */ 304 #define DBG_NETATP 105 /* Apple Transaction Protocol */ 305 #define DBG_NETASP 106 /* Apple Session Protocol */ 306 #define DBG_NETAFP 107 /* Apple Filing Protocol */ 307 #define DBG_NETRTMP 108 /* Routing Table Maintenance Protocol */ 308 #define DBG_NETAURP 109 /* Apple Update Routing Protocol */ 309 310 #define DBG_NETIPSEC 128 /* IPsec Protocol */ 311 #define DBG_NETVMNET 129 /* VMNet */ 312 313 /* **** The Kernel Debug Sub Classes for IOKIT (DBG_IOKIT) **** */ 314 #define DBG_IOINTC 0 /* Interrupt controller */ 315 #define DBG_IOWORKLOOP 1 /* Work from work loop */ 316 #define DBG_IOINTES 2 /* Interrupt event source */ 317 #define DBG_IOCLKES 3 /* Clock event source */ 318 #define DBG_IOCMDQ 4 /* Command queue latencies */ 319 #define DBG_IOMCURS 5 /* Memory Cursor */ 320 #define DBG_IOMDESC 6 /* Memory Descriptors */ 321 #define DBG_IOPOWER 7 /* Power Managerment */ 322 #define DBG_IOSERVICE 8 /* Matching etc. */ 323 324 /* **** 9-32 reserved for internal IOKit usage **** */ 325 326 #define DBG_IOSTORAGE 32 /* Storage layers */ 327 #define DBG_IONETWORK 33 /* Network layers */ 328 #define DBG_IOKEYBOARD 34 /* Keyboard */ 329 #define DBG_IOHID 35 /* HID Devices */ 330 #define DBG_IOAUDIO 36 /* Audio */ 331 #define DBG_IOSERIAL 37 /* Serial */ 332 #define DBG_IOTTY 38 /* TTY layers */ 333 #define DBG_IOSAM 39 /* SCSI Architecture Model layers */ 334 #define DBG_IOPARALLELATA 40 /* Parallel ATA */ 335 #define DBG_IOPARALLELSCSI 41 /* Parallel SCSI */ 336 #define DBG_IOSATA 42 /* Serial-ATA */ 337 #define DBG_IOSAS 43 /* SAS */ 338 #define DBG_IOFIBRECHANNEL 44 /* FiberChannel */ 339 #define DBG_IOUSB 45 /* USB */ 340 #define DBG_IOBLUETOOTH 46 /* Bluetooth */ 341 #define DBG_IOFIREWIRE 47 /* FireWire */ 342 #define DBG_IOINFINIBAND 48 /* Infiniband */ 343 #define DBG_IOCPUPM 49 /* CPU Power Management */ 344 #define DBG_IOGRAPHICS 50 /* Graphics */ 345 #define DBG_HIBERNATE 51 /* hibernation related events */ 346 #define DBG_IOTHUNDERBOLT 52 /* Thunderbolt */ 347 348 349 /* Backwards compatibility */ 350 #define DBG_IOPOINTING DBG_IOHID /* OBSOLETE: Use DBG_IOHID instead */ 351 #define DBG_IODISK DBG_IOSTORAGE /* OBSOLETE: Use DBG_IOSTORAGE instead */ 352 353 /* **** The Kernel Debug Sub Classes for Device Drivers (DBG_DRIVERS) **** */ 354 #define DBG_DRVSTORAGE 1 /* Storage layers */ 355 #define DBG_DRVNETWORK 2 /* Network layers */ 356 #define DBG_DRVKEYBOARD 3 /* Keyboard */ 357 #define DBG_DRVHID 4 /* HID Devices */ 358 #define DBG_DRVAUDIO 5 /* Audio */ 359 #define DBG_DRVSERIAL 7 /* Serial */ 360 #define DBG_DRVSAM 8 /* SCSI Architecture Model layers */ 361 #define DBG_DRVPARALLELATA 9 /* Parallel ATA */ 362 #define DBG_DRVPARALLELSCSI 10 /* Parallel SCSI */ 363 #define DBG_DRVSATA 11 /* Serial ATA */ 364 #define DBG_DRVSAS 12 /* SAS */ 365 #define DBG_DRVFIBRECHANNEL 13 /* FiberChannel */ 366 #define DBG_DRVUSB 14 /* USB */ 367 #define DBG_DRVBLUETOOTH 15 /* Bluetooth */ 368 #define DBG_DRVFIREWIRE 16 /* FireWire */ 369 #define DBG_DRVINFINIBAND 17 /* Infiniband */ 370 #define DBG_DRVGRAPHICS 18 /* Graphics */ 371 #define DBG_DRVSD 19 /* Secure Digital */ 372 #define DBG_DRVNAND 20 /* NAND drivers and layers */ 373 #define DBG_SSD 21 /* SSD */ 374 #define DBG_DRVSPI 22 /* SPI */ 375 376 /* Backwards compatibility */ 377 #define DBG_DRVPOINTING DBG_DRVHID /* OBSOLETE: Use DBG_DRVHID instead */ 378 #define DBG_DRVDISK DBG_DRVSTORAGE /* OBSOLETE: Use DBG_DRVSTORAGE instead */ 379 380 /* **** The Kernel Debug Sub Classes for the DLIL Layer (DBG_DLIL) **** */ 381 #define DBG_DLIL_STATIC 1 /* Static DLIL code */ 382 #define DBG_DLIL_PR_MOD 2 /* DLIL Protocol Module */ 383 #define DBG_DLIL_IF_MOD 3 /* DLIL Interface Module */ 384 #define DBG_DLIL_PR_FLT 4 /* DLIL Protocol Filter */ 385 #define DBG_DLIL_IF_FLT 5 /* DLIL Interface FIlter */ 386 387 /* The Kernel Debug Sub Classes for File System (DBG_FSYSTEM) */ 388 #define DBG_FSRW 1 /* reads and writes to the filesystem */ 389 #define DBG_DKRW 2 /* reads and writes to the disk */ 390 #define DBG_FSVN 3 /* vnode operations (inc. locking/unlocking) */ 391 #define DBG_FSLOOOKUP 4 /* namei and other lookup-related operations */ 392 #define DBG_JOURNAL 5 /* journaling operations */ 393 #define DBG_IOCTL 6 /* ioctl to the disk */ 394 #define DBG_BOOTCACHE 7 /* bootcache operations */ 395 #define DBG_HFS 8 /* HFS-specific events; see bsd/hfs/hfs_kdebug.h */ 396 #define DBG_EXFAT 0xE /* ExFAT-specific events; see the exfat project */ 397 #define DBG_MSDOS 0xF /* FAT-specific events; see the msdosfs project */ 398 #define DBG_ACFS 0x10 /* Xsan-specific events; see the XsanFS project */ 399 #define DBG_THROTTLE 0x11 /* I/O Throttling events */ 400 #define DBG_CONTENT_PROT 0xCF /* Content Protection Events: see bsd/sys/cprotect.h */ 401 402 /* The Kernel Debug Sub Classes for BSD */ 403 #define DBG_BSD_PROC 0x01 /* process/signals related */ 404 #define DBG_BSD_MEMSTAT 0x02 /* memorystatus / jetsam operations */ 405 #define DBG_BSD_EXCP_SC 0x0C /* System Calls */ 406 #define DBG_BSD_AIO 0x0D /* aio (POSIX async IO) */ 407 #define DBG_BSD_SC_EXTENDED_INFO 0x0E /* System Calls, extended info */ 408 #define DBG_BSD_SC_EXTENDED_INFO2 0x0F /* System Calls, extended info */ 409 410 411 /* The Codes for BSD subcode class DBG_BSD_PROC */ 412 #define BSD_PROC_EXIT 1 /* process exit */ 413 #define BSD_PROC_FRCEXIT 2 /* Kernel force termination */ 414 415 /* Codes for BSD subcode class DBG_BSD_MEMSTAT */ 416 #define BSD_MEMSTAT_SCAN 1 /* memorystatus thread awake */ 417 #define BSD_MEMSTAT_JETSAM 2 /* LRU jetsam */ 418 #define BSD_MEMSTAT_JETSAM_HIWAT 3 /* highwater jetsam */ 419 #define BSD_MEMSTAT_FREEZE 4 /* freeze process */ 420 #define BSD_MEMSTAT_LATENCY_COALESCE 5 /* delay imposed to coalesce jetsam reports */ 421 #define BSD_MEMSTAT_UPDATE 6 /* priority update */ 422 #define BSD_MEMSTAT_IDLE_DEMOTE 7 /* idle demotion fired */ 423 #define BSD_MEMSTAT_CLEAR_ERRORS 8 /* reset termination error state */ 424 #define BSD_MEMSTAT_DIRTY_TRACK 9 /* track the process state */ 425 #define BSD_MEMSTAT_DIRTY_SET 10 /* set the process state */ 426 #define BSD_MEMSTAT_DIRTY_CLEAR 11 /* clear the process state */ 427 428 /* The Kernel Debug Sub Classes for DBG_TRACE */ 429 #define DBG_TRACE_DATA 0 430 #define DBG_TRACE_STRING 1 431 #define DBG_TRACE_INFO 2 432 433 /* 434 * TRACE_DATA_NEWTHREAD 0x1 435 * TRACE_DATA_EXEC 0x2 436 */ 437 #define TRACE_DATA_THREAD_TERMINATE 0x3 /* thread has been queued for deallocation and can no longer run */ 438 439 /* The Kernel Debug Sub Classes for DBG_CORESTORAGE */ 440 #define DBG_CS_IO 0 441 442 /* The Kernel Debug Sub Classes for DBG_SECURITY */ 443 #define DBG_SEC_KERNEL 0 /* raw entropy collected by the kernel */ 444 445 /* Sub-class codes for CoreGraphics (DBG_CG) are defined in its component. */ 446 447 /* The Kernel Debug Sub Classes for DBG_MISC */ 448 #define DBG_EVENT 0x10 449 #define DBG_BUFFER 0x20 450 451 /* The Kernel Debug Sub Classes for DBG_DYLD */ 452 #define DBG_DYLD_STRING 5 453 454 /* The Kernel Debug modifiers for the DBG_DKRW sub class */ 455 #define DKIO_DONE 0x01 456 #define DKIO_READ 0x02 457 #define DKIO_ASYNC 0x04 458 #define DKIO_META 0x08 459 #define DKIO_PAGING 0x10 460 #define DKIO_THROTTLE 0x20 /* Deprecated, still provided so fs_usage doesn't break */ 461 #define DKIO_PASSIVE 0x40 462 #define DKIO_NOCACHE 0x80 463 #define DKIO_TIER_MASK 0xF00 464 #define DKIO_TIER_SHIFT 8 465 466 /* Kernel Debug Sub Classes for Applications (DBG_APPS) */ 467 #define DBG_APP_LOGINWINDOW 0x03 468 #define DBG_APP_AUDIO 0x04 469 #define DBG_APP_SAMBA 0x80 470 471 /* Kernel Debug codes for Throttling (DBG_THROTTLE) */ 472 #define OPEN_THROTTLE_WINDOW 0x1 473 #define PROCESS_THROTTLED 0x2 474 #define IO_THROTTLE_DISABLE 0x3 475 476 477 /* Subclasses for MACH Importance Policies (DBG_IMPORTANCE) */ 478 /* TODO: Split up boost and task policy? */ 479 #define IMP_ASSERTION 0x10 /* Task takes/drops a boost assertion */ 480 #define IMP_BOOST 0x11 /* Task boost level changed */ 481 #define IMP_MSG 0x12 /* boosting message sent by donating task on donating port */ 482 #define IMP_WATCHPORT 0x13 /* port marked as watchport, and boost was transferred to the watched task */ 483 #define IMP_TASK_SUPPRESSION 0x17 /* Task changed suppression behaviors */ 484 #define IMP_TASK_APPTYPE 0x18 /* Task launched with apptype */ 485 #define IMP_UPDATE 0x19 /* Requested -> effective calculation */ 486 #define IMP_USYNCH_QOS_OVERRIDE 0x1A /* Userspace synchronization applied QoS override to resource owning thread */ 487 #define IMP_DONOR_CHANGE 0x1B /* The iit_donor bit changed */ 488 #define IMP_MAIN_THREAD_QOS 0x1C /* The task's main thread QoS was set */ 489 /* DBG_IMPORTANCE subclasses 0x20 - 0x3F reserved for task policy flavors */ 490 491 /* Codes for IMP_ASSERTION */ 492 #define IMP_HOLD 0x2 /* Task holds a boost assertion */ 493 #define IMP_DROP 0x4 /* Task drops a boost assertion */ 494 #define IMP_EXTERN 0x8 /* boost assertion moved from kernel to userspace responsibility (externalized) */ 495 496 /* Codes for IMP_BOOST */ 497 #define IMP_BOOSTED 0x1 498 #define IMP_UNBOOSTED 0x2 /* Task drops a boost assertion */ 499 500 /* Codes for IMP_MSG */ 501 #define IMP_MSG_SEND 0x1 /* boosting message sent by donating task on donating port */ 502 #define IMP_MSG_DELV 0x2 /* boosting message delivered to task */ 503 504 /* Codes for IMP_UPDATE */ 505 #define IMP_UPDATE_TASK_CREATE 0x1 506 507 /* Codes for IMP_USYNCH_QOS_OVERRIDE */ 508 #define IMP_USYNCH_ADD_OVERRIDE 0x0 /* add override for a contended resource */ 509 #define IMP_USYNCH_REMOVE_OVERRIDE 0x1 /* remove override for a contended resource */ 510 511 /* Codes for IMP_DONOR_CHANGE */ 512 #define IMP_DONOR_UPDATE_LIVE_DONOR_STATE 0x0 513 #define IMP_DONOR_INIT_DONOR_STATE 0x1 514 515 /* Subclasses for MACH Bank Voucher Attribute Manager (DBG_BANK) */ 516 #define BANK_ACCOUNT_INFO 0x10 /* Trace points related to bank account struct */ 517 #define BANK_TASK_INFO 0x11 /* Trace points related to bank task struct */ 518 519 /* Subclasses for MACH ATM Voucher Attribute Manager (ATM) */ 520 #define ATM_SUBAID_INFO 0x10 521 #define ATM_GETVALUE_INFO 0x20 522 #define ATM_UNREGISTER_INFO 0x30 523 524 /* Codes for BANK_ACCOUNT_INFO */ 525 #define BANK_SETTLE_CPU_TIME 0x1 /* Bank ledger(chit) rolled up to tasks. */ 526 527 /* Codes for ATM_SUBAID_INFO */ 528 #define ATM_MIN_CALLED 0x1 529 #define ATM_MIN_LINK_LIST 0x2 530 531 /* Codes for ATM_GETVALUE_INFO */ 532 #define ATM_VALUE_REPLACED 0x1 533 #define ATM_VALUE_ADDED 0x2 534 535 /* Codes for ATM_UNREGISTER_INFO */ 536 #define ATM_VALUE_UNREGISTERED 0x1 537 #define ATM_VALUE_DIFF_MAILBOX 0x2 538 539 /**********************************************************************/ 540 541 #define KDBG_CODE(Class, SubClass, code) (((Class & 0xff) << 24) | ((SubClass & 0xff) << 16) | ((code & 0x3fff) << 2)) 542 543 #define KDBG_MIGCODE(msgid) ((DBG_MIG << 24) | (((msgid) & 0x3fffff) << 2)) 544 545 #define MACHDBG_CODE(SubClass, code) KDBG_CODE(DBG_MACH, SubClass, code) 546 #define NETDBG_CODE(SubClass, code) KDBG_CODE(DBG_NETWORK, SubClass, code) 547 #define FSDBG_CODE(SubClass, code) KDBG_CODE(DBG_FSYSTEM, SubClass, code) 548 #define BSDDBG_CODE(SubClass, code) KDBG_CODE(DBG_BSD, SubClass, code) 549 #define IOKDBG_CODE(SubClass, code) KDBG_CODE(DBG_IOKIT, SubClass, code) 550 #define DRVDBG_CODE(SubClass, code) KDBG_CODE(DBG_DRIVERS, SubClass, code) 551 #define TRACEDBG_CODE(SubClass,code) KDBG_CODE(DBG_TRACE, SubClass, code) 552 #define MISCDBG_CODE(SubClass,code) KDBG_CODE(DBG_MISC, SubClass, code) 553 #define DLILDBG_CODE(SubClass,code) KDBG_CODE(DBG_DLIL, SubClass, code) 554 #define SECURITYDBG_CODE(SubClass,code) KDBG_CODE(DBG_SECURITY, SubClass, code) 555 #define DYLDDBG_CODE(SubClass,code) KDBG_CODE(DBG_DYLD, SubClass, code) 556 #define QTDBG_CODE(SubClass,code) KDBG_CODE(DBG_QT, SubClass, code) 557 #define APPSDBG_CODE(SubClass,code) KDBG_CODE(DBG_APPS, SubClass, code) 558 #define CPUPM_CODE(code) IOKDBG_CODE(DBG_IOCPUPM, code) 559 560 #define KMEM_ALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 0) 561 #define KMEM_ALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 1) 562 #define KMEM_FREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 2) 563 #define KMEM_FREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 3) 564 #define ZALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 4) 565 #define ZALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 5) 566 #define ZFREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 6) 567 #define ZFREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 7) 568 569 #define PMAP_CODE(code) MACHDBG_CODE(DBG_MACH_PMAP, code) 570 571 572 #define IMPORTANCE_CODE(SubClass, code) KDBG_CODE(DBG_IMPORTANCE, (SubClass), (code)) 573 #define BANK_CODE(SubClass, code) KDBG_CODE(DBG_BANK, (SubClass), (code)) 574 #define ATM_CODE(SubClass, code) KDBG_CODE(DBG_ATM, (SubClass), (code)) 575 576 /* Usage: 577 * kernel_debug((KDBG_CODE(DBG_NETWORK, DNET_PROTOCOL, 51) | DBG_FUNC_START), 578 * offset, 0, 0, 0,0) 579 * 580 * For ex, 581 * 582 * #include <sys/kdebug.h> 583 * 584 * #define DBG_NETIPINIT NETDBG_CODE(DBG_NETIP,1) 585 * 586 * 587 * void 588 * ip_init() 589 * { 590 * register struct protosw *pr; 591 * register int i; 592 * 593 * KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_START, 0,0,0,0,0) 594 * -------- 595 * KERNEL_DEBUG(DBG_NETIPINIT, 0,0,0,0,0) 596 * -------- 597 * KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_END, 0,0,0,0,0) 598 * } 599 * 600 601 */ 602 603 extern unsigned int kdebug_enable; 604 #define KDEBUG_ENABLE_TRACE 0x1 605 #define KDEBUG_ENABLE_ENTROPY 0x2 /* Obsolescent */ 606 #define KDEBUG_ENABLE_CHUD 0x4 607 #define KDEBUG_ENABLE_PPT 0x8 608 609 /* 610 * Infer the supported kernel debug event level from config option. 611 * Use (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) as a guard to protect 612 * unaudited debug code. 613 */ 614 #define KDEBUG_LEVEL_NONE 0 615 #define KDEBUG_LEVEL_IST 1 616 #define KDEBUG_LEVEL_STANDARD 2 617 #define KDEBUG_LEVEL_FULL 3 618 619 #if NO_KDEBUG 620 #define KDEBUG_LEVEL KDEBUG_LEVEL_NONE 621 #elif IST_KDEBUG 622 #define KDEBUG_LEVEL KDEBUG_LEVEL_IST 623 #elif KDEBUG 624 #define KDEBUG_LEVEL KDEBUG_LEVEL_FULL 625 #else 626 #define KDEBUG_LEVEL KDEBUG_LEVEL_STANDARD 627 #endif 628 629 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) 630 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \ 631 do { \ 632 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \ 633 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \ 634 (uintptr_t)d,(uintptr_t)e); \ 635 } while(0) 636 637 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \ 638 do { \ 639 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \ 640 kernel_debug1(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \ 641 (uintptr_t)d,(uintptr_t)e); \ 642 } while(0) 643 644 #define KERNEL_DEBUG_EARLY(x,a,b,c,d) \ 645 do { \ 646 kernel_debug_early((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \ 647 (uintptr_t)c, (uintptr_t)d); \ 648 } while(0) 649 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */ 650 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) do { } while(0) 651 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) do { } while(0) 652 #define KERNEL_DEBUG_EARLY(x,a,b,c,d) do { } while(0) 653 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */ 654 655 /* 656 * Specify KDEBUG_PPT to indicate that the event belongs to the 657 * limited PPT set. 658 */ 659 #define KDEBUG_COMMON (KDEBUG_ENABLE_TRACE|KDEBUG_ENABLE_CHUD|KDEBUG_ENABLE_PPT) 660 #define KDEBUG_TRACE (KDEBUG_ENABLE_TRACE|KDEBUG_ENABLE_CHUD) 661 #define KDEBUG_PPT (KDEBUG_ENABLE_PPT) 662 663 /* 664 * KERNEL_DEBUG_CONSTANT_IST events provide an audited subset of 665 * tracepoints for userland system tracing tools. 666 */ 667 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) 668 #define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) \ 669 do { \ 670 if (kdebug_enable & type) \ 671 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \ 672 (uintptr_t)d,(uintptr_t)e); \ 673 } while(0) 674 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */ 675 #define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) do { } while(0) 676 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */ 677 678 #if NO_KDEBUG 679 #define __kdebug_constant_only __unused 680 #endif 681 682 extern void kernel_debug( 683 uint32_t debugid, 684 uintptr_t arg1, 685 uintptr_t arg2, 686 uintptr_t arg3, 687 uintptr_t arg4, 688 uintptr_t arg5); 689 690 extern void kernel_debug1( 691 uint32_t debugid, 692 uintptr_t arg1, 693 uintptr_t arg2, 694 uintptr_t arg3, 695 uintptr_t arg4, 696 uintptr_t arg5); 697 698 extern void kernel_debug_early( 699 uint32_t debugid, 700 uintptr_t arg1, 701 uintptr_t arg2, 702 uintptr_t arg3, 703 uintptr_t arg4); 704 705 extern void kernel_debug_string( 706 const char *message); 707 708 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) 709 #define KERNEL_DEBUG(x,a,b,c,d,e) \ 710 do { \ 711 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \ 712 kernel_debug((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \ 713 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \ 714 } while(0) 715 716 #define KERNEL_DEBUG1(x,a,b,c,d,e) \ 717 do { \ 718 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \ 719 kernel_debug1((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \ 720 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \ 721 } while(0) 722 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */ 723 #define KERNEL_DEBUG(x,a,b,c,d,e) do {} while (0) 724 #define KERNEL_DEBUG1(x,a,b,c,d,e) do {} while (0) 725 726 #define __kdebug_only __unused 727 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */ 728 729 730 731 #endif /* __APPLE_API_UNSTABLE */ 732 __END_DECLS 733 734 735 736 #endif /* !BSD_SYS_KDEBUG_H */ 737