this repo has no description
1
fork

Configure Feed

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

at vchroot 736 lines 25 kB view raw
1/* 2 * Copyright (c) 2000-2010 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#ifdef XNU_KERNEL_PRIVATE 51#include <stdint.h> 52#include <mach/branch_predicates.h> 53#endif 54 55/* 56 * types of faults that vm_fault handles 57 * and creates trace entries for 58 */ 59#define DBG_ZERO_FILL_FAULT 1 60#define DBG_PAGEIN_FAULT 2 61#define DBG_COW_FAULT 3 62#define DBG_CACHE_HIT_FAULT 4 63#define DBG_NZF_PAGE_FAULT 5 64#define DBG_GUARD_FAULT 6 65#define DBG_PAGEINV_FAULT 7 66#define DBG_PAGEIND_FAULT 8 67 68 69/* The debug code consists of the following 70* 71* ---------------------------------------------------------------------- 72*| | | |Func | 73*| Class (8) | SubClass (8) | Code (14) |Qual(2)| 74* ---------------------------------------------------------------------- 75* The class specifies the higher level 76*/ 77 78/* The Function qualifiers */ 79#define DBG_FUNC_START 1 80#define DBG_FUNC_END 2 81#define DBG_FUNC_NONE 0 82 83 84/* The Kernel Debug Classes */ 85#define DBG_MACH 1 86#define DBG_NETWORK 2 87#define DBG_FSYSTEM 3 88#define DBG_BSD 4 89#define DBG_IOKIT 5 90#define DBG_DRIVERS 6 91#define DBG_TRACE 7 92#define DBG_DLIL 8 93#define DBG_SECURITY 9 94#define DBG_CORESTORAGE 10 95#define DBG_CG 11 96#define DBG_MISC 20 97#define DBG_DYLD 31 98#define DBG_QT 32 99#define DBG_APPS 33 100#define DBG_LAUNCHD 34 101#define DBG_PERF 37 102#define DBG_ARIADNE 43 103#define DBG_MIG 255 104 105/* **** The Kernel Debug Sub Classes for Mach (DBG_MACH) **** */ 106#define DBG_MACH_EXCP_KTRAP_x86 0x02 /* Kernel Traps on x86 */ 107#define DBG_MACH_EXCP_DFLT 0x03 /* Data Translation Fault */ 108#define DBG_MACH_EXCP_IFLT 0x04 /* Inst Translation Fault */ 109#define DBG_MACH_EXCP_INTR 0x05 /* Interrupts */ 110#define DBG_MACH_EXCP_ALNG 0x06 /* Alignment Exception */ 111#define DBG_MACH_EXCP_UTRAP_x86 0x07 /* User Traps on x86 */ 112#define DBG_MACH_EXCP_FP 0x08 /* FP Unavail */ 113#define DBG_MACH_EXCP_DECI 0x09 /* Decrementer Interrupt */ 114#define DBG_MACH_CHUD 0x0A /* CHUD */ 115#define DBG_MACH_EXCP_SC 0x0C /* System Calls */ 116#define DBG_MACH_EXCP_TRACE 0x0D /* Trace exception */ 117#define DBG_MACH_EXCP_EMUL 0x0E /* Instruction emulated */ 118#define DBG_MACH_IHDLR 0x10 /* Interrupt Handlers */ 119#define DBG_MACH_IPC 0x20 /* Inter Process Comm */ 120#define DBG_MACH_VM 0x30 /* Virtual Memory */ 121#define DBG_MACH_LEAKS 0x31 /* alloc/free */ 122#define DBG_MACH_SCHED 0x40 /* Scheduler */ 123#define DBG_MACH_MSGID_INVALID 0x50 /* Messages - invalid */ 124#define DBG_MACH_LOCKS 0x60 /* new lock APIs */ 125#define DBG_MACH_PMAP 0x70 /* pmap */ 126#define DBG_MACH_MP 0x90 /* MP related */ 127 128/* Codes for Scheduler (DBG_MACH_SCHED) */ 129#define MACH_SCHED 0x0 /* Scheduler */ 130#define MACH_STACK_ATTACH 0x1 /* stack_attach() */ 131#define MACH_STACK_HANDOFF 0x2 /* stack_handoff() */ 132#define MACH_CALL_CONT 0x3 /* call_continuation() */ 133#define MACH_CALLOUT 0x4 /* callouts */ 134#define MACH_STACK_DETACH 0x5 135#define MACH_MAKE_RUNNABLE 0x6 /* make thread runnable */ 136#define MACH_PROMOTE 0x7 /* promoted due to resource */ 137#define MACH_DEMOTE 0x8 /* promotion undone */ 138#define MACH_IDLE 0x9 /* processor idling */ 139#define MACH_STACK_DEPTH 0xa /* stack depth at switch */ 140#define MACH_MOVED 0xb /* did not use original scheduling decision */ 141#define MACH_FAIRSHARE_ENTER 0xc /* move to fairshare band */ 142#define MACH_FAIRSHARE_EXIT 0xd /* exit fairshare band */ 143#define MACH_FAILSAFE 0xe /* tripped fixed-pri/RT failsafe */ 144#define MACH_BLOCK 0xf /* thread block */ 145#define MACH_WAIT 0x10 /* thread wait assertion */ 146#define MACH_GET_URGENCY 0x14 /* Urgency queried by platform */ 147#define MACH_URGENCY 0x15 /* Urgency (RT/BG/NORMAL) communicated 148 * to platform 149 */ 150#define MACH_REDISPATCH 0x16 /* "next thread" thread redispatched */ 151#define MACH_REMOTE_AST 0x17 /* AST signal issued to remote processor */ 152 153#define MACH_SCHED_LPA_BROKEN 0x18 /* last_processor affinity broken in choose_processor */ 154 155/* Codes for pmap (DBG_MACH_PMAP) */ 156#define PMAP__CREATE 0x0 157#define PMAP__DESTROY 0x1 158#define PMAP__PROTECT 0x2 159#define PMAP__PAGE_PROTECT 0x3 160#define PMAP__ENTER 0x4 161#define PMAP__REMOVE 0x5 162#define PMAP__NEST 0x6 163#define PMAP__UNNEST 0x7 164#define PMAP__FLUSH_TLBS 0x8 165#define PMAP__UPDATE_INTERRUPT 0x9 166#define PMAP__ATTRIBUTE_CLEAR 0xa 167 168/* **** The Kernel Debug Sub Classes for Network (DBG_NETWORK) **** */ 169#define DBG_NETIP 1 /* Internet Protocol */ 170#define DBG_NETARP 2 /* Address Resolution Protocol */ 171#define DBG_NETUDP 3 /* User Datagram Protocol */ 172#define DBG_NETTCP 4 /* Transmission Control Protocol */ 173#define DBG_NETICMP 5 /* Internet Control Message Protocol */ 174#define DBG_NETIGMP 6 /* Internet Group Management Protocol */ 175#define DBG_NETRIP 7 /* Routing Information Protocol */ 176#define DBG_NETOSPF 8 /* Open Shortest Path First */ 177#define DBG_NETISIS 9 /* Intermediate System to Intermediate System */ 178#define DBG_NETSNMP 10 /* Simple Network Management Protocol */ 179#define DBG_NETSOCK 11 /* Socket Layer */ 180 181/* For Apple talk */ 182#define DBG_NETAARP 100 /* Apple ARP */ 183#define DBG_NETDDP 101 /* Datagram Delivery Protocol */ 184#define DBG_NETNBP 102 /* Name Binding Protocol */ 185#define DBG_NETZIP 103 /* Zone Information Protocol */ 186#define DBG_NETADSP 104 /* Name Binding Protocol */ 187#define DBG_NETATP 105 /* Apple Transaction Protocol */ 188#define DBG_NETASP 106 /* Apple Session Protocol */ 189#define DBG_NETAFP 107 /* Apple Filing Protocol */ 190#define DBG_NETRTMP 108 /* Routing Table Maintenance Protocol */ 191#define DBG_NETAURP 109 /* Apple Update Routing Protocol */ 192#define DBG_NETIPSEC 128 /* IPsec Protocol */ 193 194/* **** The Kernel Debug Sub Classes for IOKIT (DBG_IOKIT) **** */ 195#define DBG_IOINTC 0 /* Interrupt controller */ 196#define DBG_IOWORKLOOP 1 /* Work from work loop */ 197#define DBG_IOINTES 2 /* Interrupt event source */ 198#define DBG_IOCLKES 3 /* Clock event source */ 199#define DBG_IOCMDQ 4 /* Command queue latencies */ 200#define DBG_IOMCURS 5 /* Memory Cursor */ 201#define DBG_IOMDESC 6 /* Memory Descriptors */ 202#define DBG_IOPOWER 7 /* Power Managerment */ 203#define DBG_IOSERVICE 8 /* Matching etc. */ 204 205/* **** 9-32 reserved for internal IOKit usage **** */ 206 207#define DBG_IOSTORAGE 32 /* Storage layers */ 208#define DBG_IONETWORK 33 /* Network layers */ 209#define DBG_IOKEYBOARD 34 /* Keyboard */ 210#define DBG_IOHID 35 /* HID Devices */ 211#define DBG_IOAUDIO 36 /* Audio */ 212#define DBG_IOSERIAL 37 /* Serial */ 213#define DBG_IOTTY 38 /* TTY layers */ 214#define DBG_IOSAM 39 /* SCSI Architecture Model layers */ 215#define DBG_IOPARALLELATA 40 /* Parallel ATA */ 216#define DBG_IOPARALLELSCSI 41 /* Parallel SCSI */ 217#define DBG_IOSATA 42 /* Serial-ATA */ 218#define DBG_IOSAS 43 /* SAS */ 219#define DBG_IOFIBRECHANNEL 44 /* FiberChannel */ 220#define DBG_IOUSB 45 /* USB */ 221#define DBG_IOBLUETOOTH 46 /* Bluetooth */ 222#define DBG_IOFIREWIRE 47 /* FireWire */ 223#define DBG_IOINFINIBAND 48 /* Infiniband */ 224#define DBG_IOCPUPM 49 /* CPU Power Management */ 225#define DBG_IOGRAPHICS 50 /* Graphics */ 226#define DBG_HIBERNATE 51 /* hibernation related events */ 227 228 229/* Backwards compatibility */ 230#define DBG_IOPOINTING DBG_IOHID /* OBSOLETE: Use DBG_IOHID instead */ 231#define DBG_IODISK DBG_IOSTORAGE /* OBSOLETE: Use DBG_IOSTORAGE instead */ 232 233/* **** The Kernel Debug Sub Classes for Device Drivers (DBG_DRIVERS) **** */ 234#define DBG_DRVSTORAGE 1 /* Storage layers */ 235#define DBG_DRVNETWORK 2 /* Network layers */ 236#define DBG_DRVKEYBOARD 3 /* Keyboard */ 237#define DBG_DRVHID 4 /* HID Devices */ 238#define DBG_DRVAUDIO 5 /* Audio */ 239#define DBG_DRVSERIAL 7 /* Serial */ 240#define DBG_DRVSAM 8 /* SCSI Architecture Model layers */ 241#define DBG_DRVPARALLELATA 9 /* Parallel ATA */ 242#define DBG_DRVPARALLELSCSI 10 /* Parallel SCSI */ 243#define DBG_DRVSATA 11 /* Serial ATA */ 244#define DBG_DRVSAS 12 /* SAS */ 245#define DBG_DRVFIBRECHANNEL 13 /* FiberChannel */ 246#define DBG_DRVUSB 14 /* USB */ 247#define DBG_DRVBLUETOOTH 15 /* Bluetooth */ 248#define DBG_DRVFIREWIRE 16 /* FireWire */ 249#define DBG_DRVINFINIBAND 17 /* Infiniband */ 250#define DBG_DRVGRAPHICS 18 /* Graphics */ 251#define DBG_DRVSD 19 /* Secure Digital */ 252#define DBG_DRVNAND 20 /* NAND drivers and layers */ 253#define DBG_SSD 21 /* SSD */ 254 255/* Backwards compatibility */ 256#define DBG_DRVPOINTING DBG_DRVHID /* OBSOLETE: Use DBG_DRVHID instead */ 257#define DBG_DRVDISK DBG_DRVSTORAGE /* OBSOLETE: Use DBG_DRVSTORAGE instead */ 258 259/* **** The Kernel Debug Sub Classes for the DLIL Layer (DBG_DLIL) **** */ 260#define DBG_DLIL_STATIC 1 /* Static DLIL code */ 261#define DBG_DLIL_PR_MOD 2 /* DLIL Protocol Module */ 262#define DBG_DLIL_IF_MOD 3 /* DLIL Interface Module */ 263#define DBG_DLIL_PR_FLT 4 /* DLIL Protocol Filter */ 264#define DBG_DLIL_IF_FLT 5 /* DLIL Interface FIlter */ 265 266/* The Kernel Debug Sub Classes for File System (DBG_FSYSTEM) */ 267#define DBG_FSRW 1 /* reads and writes to the filesystem */ 268#define DBG_DKRW 2 /* reads and writes to the disk */ 269#define DBG_FSVN 3 /* vnode operations (inc. locking/unlocking) */ 270#define DBG_FSLOOOKUP 4 /* namei and other lookup-related operations */ 271#define DBG_JOURNAL 5 /* journaling operations */ 272#define DBG_IOCTL 6 /* ioctl to the disk */ 273#define DBG_BOOTCACHE 7 /* bootcache operations */ 274#define DBG_HFS 8 /* HFS-specific events; see bsd/hfs/hfs_kdebug.h */ 275#define DBG_EXFAT 0xE /* ExFAT-specific events; see the exfat project */ 276#define DBG_MSDOS 0xF /* FAT-specific events; see the msdosfs project */ 277 278/* The Kernel Debug Sub Classes for BSD */ 279#define DBG_BSD_PROC 0x01 /* process/signals related */ 280#define DBG_BSD_EXCP_SC 0x0C /* System Calls */ 281#define DBG_BSD_AIO 0x0D /* aio (POSIX async IO) */ 282#define DBG_BSD_SC_EXTENDED_INFO 0x0E /* System Calls, extended info */ 283#define DBG_BSD_SC_EXTENDED_INFO2 0x0F /* System Calls, extended info */ 284 285 286/* The Codes for BSD subcode class DBG_BSD_PROC */ 287#define BSD_PROC_EXIT 1 /* process exit */ 288#define BSD_PROC_FRCEXIT 2 /* Kernel force termination */ 289 290/* The Kernel Debug Sub Classes for DBG_TRACE */ 291#define DBG_TRACE_DATA 0 292#define DBG_TRACE_STRING 1 293#define DBG_TRACE_INFO 2 294 295/* The Kernel Debug Sub Classes for DBG_CORESTORAGE */ 296#define DBG_CS_IO 0 297 298/* Sub-class codes for CoreGraphics (DBG_CG) are defined in its component. */ 299 300/* The Kernel Debug Sub Classes for DBG_MISC */ 301#define DBG_EVENT 0x10 302#define DBG_BUFFER 0x20 303 304/* The Kernel Debug Sub Classes for DBG_DYLD */ 305#define DBG_DYLD_STRING 5 306 307/* The Kernel Debug modifiers for the DBG_DKRW sub class */ 308#define DKIO_DONE 0x01 309#define DKIO_READ 0x02 310#define DKIO_ASYNC 0x04 311#define DKIO_META 0x08 312#define DKIO_PAGING 0x10 313#define DKIO_THROTTLE 0x20 314#define DKIO_PASSIVE 0x40 315#define DKIO_NOCACHE 0x80 316 317/* Codes for Application Sub Classes */ 318#define DBG_APP_SAMBA 128 319 320 321/**********************************************************************/ 322 323#define KDBG_CODE(Class, SubClass, code) (((Class & 0xff) << 24) | ((SubClass & 0xff) << 16) | ((code & 0x3fff) << 2)) 324 325#define KDBG_MIGCODE(msgid) ((DBG_MIG << 24) | (((msgid) & 0x3fffff) << 2)) 326 327#define MACHDBG_CODE(SubClass, code) KDBG_CODE(DBG_MACH, SubClass, code) 328#define NETDBG_CODE(SubClass, code) KDBG_CODE(DBG_NETWORK, SubClass, code) 329#define FSDBG_CODE(SubClass, code) KDBG_CODE(DBG_FSYSTEM, SubClass, code) 330#define BSDDBG_CODE(SubClass, code) KDBG_CODE(DBG_BSD, SubClass, code) 331#define IOKDBG_CODE(SubClass, code) KDBG_CODE(DBG_IOKIT, SubClass, code) 332#define DRVDBG_CODE(SubClass, code) KDBG_CODE(DBG_DRIVERS, SubClass, code) 333#define TRACEDBG_CODE(SubClass,code) KDBG_CODE(DBG_TRACE, SubClass, code) 334#define MISCDBG_CODE(SubClass,code) KDBG_CODE(DBG_MISC, SubClass, code) 335#define DLILDBG_CODE(SubClass,code) KDBG_CODE(DBG_DLIL, SubClass, code) 336#define SECURITYDBG_CODE(SubClass,code) KDBG_CODE(DBG_SECURITY, SubClass, code) 337#define DYLDDBG_CODE(SubClass,code) KDBG_CODE(DBG_DYLD, SubClass, code) 338#define QTDBG_CODE(SubClass,code) KDBG_CODE(DBG_QT, SubClass, code) 339#define APPSDBG_CODE(SubClass,code) KDBG_CODE(DBG_APPS, SubClass, code) 340#define CPUPM_CODE(code) IOKDBG_CODE(DBG_IOCPUPM, code) 341#define ARIADNEDBG_CODE(SubClass, code) KDBG_CODE(DBG_ARIADNE, SubClass, code) 342 343#define KMEM_ALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 0) 344#define KMEM_ALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 1) 345#define KMEM_FREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 2) 346#define KMEM_FREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 3) 347#define ZALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 4) 348#define ZALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 5) 349#define ZFREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 6) 350#define ZFREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 7) 351 352#define PMAP_CODE(code) MACHDBG_CODE(DBG_MACH_PMAP, code) 353 354 355/* Usage: 356* kernel_debug((KDBG_CODE(DBG_NETWORK, DNET_PROTOCOL, 51) | DBG_FUNC_START), 357* offset, 0, 0, 0,0) 358* 359* For ex, 360* 361* #include <sys/kdebug.h> 362* 363* #define DBG_NETIPINIT NETDBG_CODE(DBG_NETIP,1) 364* 365* 366* void 367* ip_init() 368* { 369* register struct protosw *pr; 370* register int i; 371* 372* KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_START, 0,0,0,0,0) 373* -------- 374* KERNEL_DEBUG(DBG_NETIPINIT, 0,0,0,0,0) 375* -------- 376* KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_END, 0,0,0,0,0) 377* } 378* 379 380*/ 381 382extern unsigned int kdebug_enable; 383#define KDEBUG_ENABLE_TRACE 0x1 384#define KDEBUG_ENABLE_ENTROPY 0x2 385#define KDEBUG_ENABLE_CHUD 0x4 386#define KDEBUG_ENABLE_PPT 0x8 387 388/* 389 * Infer the supported kernel debug event level from config option. 390 * Use (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) as a guard to protect 391 * unaudited debug code. 392 */ 393#define KDEBUG_LEVEL_NONE 0 394#define KDEBUG_LEVEL_IST 1 395#define KDEBUG_LEVEL_STANDARD 2 396#define KDEBUG_LEVEL_FULL 3 397 398#if NO_KDEBUG 399#define KDEBUG_LEVEL KDEBUG_LEVEL_NONE 400#elif IST_KDEBUG 401#define KDEBUG_LEVEL KDEBUG_LEVEL_IST 402#elif KDEBUG 403#define KDEBUG_LEVEL KDEBUG_LEVEL_FULL 404#else 405#define KDEBUG_LEVEL KDEBUG_LEVEL_STANDARD 406#endif 407 408#if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) 409#ifdef XNU_KERNEL_PRIVATE 410#define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \ 411do { \ 412 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \ 413 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \ 414 (uintptr_t)d,(uintptr_t)e); \ 415} while(0) 416 417#define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \ 418do { \ 419 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \ 420 kernel_debug1(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \ 421 (uintptr_t)d,(uintptr_t)e); \ 422} while(0) 423#else /* XNU_KERNEL_PRIVATE */ 424#define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \ 425do { \ 426 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \ 427 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \ 428 (uintptr_t)d,(uintptr_t)e); \ 429} while(0) 430 431#define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \ 432do { \ 433 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \ 434 kernel_debug1(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \ 435 (uintptr_t)d,(uintptr_t)e); \ 436} while(0) 437#endif /* XNU_KERNEL_PRIVATE */ 438#else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */ 439#define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) do { } while(0) 440#define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) do { } while(0) 441#endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */ 442 443/* 444 * Specify KDEBUG_PPT to indicate that the event belongs to the 445 * limited PPT set. 446 */ 447#define KDEBUG_COMMON (KDEBUG_ENABLE_TRACE|KDEBUG_ENABLE_ENTROPY|KDEBUG_ENABLE_CHUD|KDEBUG_ENABLE_PPT) 448#define KDEBUG_TRACE (KDEBUG_ENABLE_TRACE|KDEBUG_ENABLE_ENTROPY|KDEBUG_ENABLE_CHUD) 449#define KDEBUG_PPT (KDEBUG_ENABLE_PPT) 450 451/* 452 * KERNEL_DEBUG_CONSTANT_IST events provide an audited subset of 453 * tracepoints for userland system tracing tools. 454 */ 455#if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) 456#ifdef XNU_KERNEL_PRIVATE 457#define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) \ 458do { \ 459 if (__improbable(kdebug_enable & type)) \ 460 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \ 461 (uintptr_t)d,(uintptr_t)e); \ 462} while(0) 463#else /* XNU_KERNEL_PRIVATE */ 464#define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) \ 465do { \ 466 if (kdebug_enable & type) \ 467 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \ 468 (uintptr_t)d,(uintptr_t)e); \ 469} while(0) 470#endif /* XNU_KERNEL_PRIVATE */ 471#else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */ 472#define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) do { } while(0) 473#endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */ 474 475#if NO_KDEBUG 476#define __kdebug_constant_only __unused 477#endif 478 479extern void kernel_debug( 480 uint32_t debugid, 481 uintptr_t arg1, 482 uintptr_t arg2, 483 uintptr_t arg3, 484 uintptr_t arg4, 485 uintptr_t arg5); 486 487extern void kernel_debug1( 488 uint32_t debugid, 489 uintptr_t arg1, 490 uintptr_t arg2, 491 uintptr_t arg3, 492 uintptr_t arg4, 493 uintptr_t arg5); 494 495 496#if (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) 497#ifdef XNU_KERNEL_PRIVATE 498#define KERNEL_DEBUG(x,a,b,c,d,e) \ 499do { \ 500 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \ 501 kernel_debug((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \ 502 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \ 503} while(0) 504 505#define KERNEL_DEBUG1(x,a,b,c,d,e) \ 506do { \ 507 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \ 508 kernel_debug1((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \ 509 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \ 510} while(0) 511 512#define __kdebug_only 513#else /* !XNU_KERNEL_PRIVATE */ 514#define KERNEL_DEBUG(x,a,b,c,d,e) \ 515do { \ 516 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \ 517 kernel_debug((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \ 518 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \ 519} while(0) 520 521#define KERNEL_DEBUG1(x,a,b,c,d,e) \ 522do { \ 523 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \ 524 kernel_debug1((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \ 525 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \ 526} while(0) 527#endif /* XNU_KERNEL_PRIVATE */ 528#else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */ 529#define KERNEL_DEBUG(x,a,b,c,d,e) do {} while (0) 530#define KERNEL_DEBUG1(x,a,b,c,d,e) do {} while (0) 531 532#define __kdebug_only __unused 533#endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */ 534 535#ifdef KERNEL_PRIVATE 536#include <mach/boolean.h> 537struct proc; 538extern void kdbg_trace_data(struct proc *proc, long *arg_pid); 539 540extern void kdbg_trace_string(struct proc *proc, long *arg1, long *arg2, long *arg3, long *arg4); 541 542extern void kdbg_dump_trace_to_file(const char *); 543void start_kern_tracing(unsigned int); 544struct task; 545extern void kdbg_get_task_name(char*, int, struct task *task); 546void disable_wrap(uint32_t *old_slowcheck, uint32_t *old_flags); 547void enable_wrap(uint32_t old_slowcheck, boolean_t lostevents); 548void release_storage_unit(int cpu, uint32_t storage_unit); 549int allocate_storage_unit(int cpu); 550 551void trace_handler_map_ctrl_page(uintptr_t addr, unsigned long ctrl_page_size, unsigned long storage_size, unsigned long kds_ptr_size); 552void trace_handler_map_bufinfo(uintptr_t addr, unsigned long size); 553void trace_handler_unmap_bufinfo(void); 554void trace_handler_map_buffer(int index, uintptr_t addr, unsigned long size); 555void trace_handler_unmap_buffer(int index); 556void trace_set_timebases(uint64_t tsc, uint64_t ns); 557 558 559#endif /* KERNEL_PRIVATE */ 560 561 562#endif /* __APPLE_API_UNSTABLE */ 563__END_DECLS 564 565 566#ifdef PRIVATE 567#ifdef __APPLE_API_PRIVATE 568/* 569 * private kernel_debug definitions 570 */ 571 572typedef struct { 573 uint64_t timestamp; 574 uintptr_t arg1; 575 uintptr_t arg2; 576 uintptr_t arg3; 577 uintptr_t arg4; 578 uintptr_t arg5; /* will hold current thread */ 579 uint32_t debugid; 580#if defined(__LP64__) 581 uint32_t cpuid; 582 uintptr_t unused; 583#endif 584} kd_buf; 585 586#if !defined(__LP64__) 587#define KDBG_TIMESTAMP_MASK 0x00ffffffffffffffULL 588#define KDBG_CPU_MASK 0xff00000000000000ULL 589#define KDBG_CPU_SHIFT 56 590static inline void 591kdbg_set_cpu(kd_buf *kp, int cpu) 592{ 593 kp->timestamp = (kp->timestamp & KDBG_TIMESTAMP_MASK) | 594 (((uint64_t) cpu) << KDBG_CPU_SHIFT); 595} 596static inline int 597kdbg_get_cpu(kd_buf *kp) 598{ 599 return (int) (((kp)->timestamp & KDBG_CPU_MASK) >> KDBG_CPU_SHIFT); 600} 601static inline void 602kdbg_set_timestamp(kd_buf *kp, uint64_t thetime) 603{ 604 kp->timestamp = thetime & KDBG_TIMESTAMP_MASK; 605} 606static inline uint64_t 607kdbg_get_timestamp(kd_buf *kp) 608{ 609 return kp->timestamp & KDBG_TIMESTAMP_MASK; 610} 611static inline void 612kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu) 613{ 614 kp->timestamp = (thetime & KDBG_TIMESTAMP_MASK) | 615 (((uint64_t) cpu) << KDBG_CPU_SHIFT); 616} 617#else 618#define KDBG_TIMESTAMP_MASK 0xffffffffffffffffULL 619static inline void 620kdbg_set_cpu(kd_buf *kp, int cpu) 621{ 622 kp->cpuid = cpu; 623} 624static inline int 625kdbg_get_cpu(kd_buf *kp) 626{ 627 return kp->cpuid; 628} 629static inline void 630kdbg_set_timestamp(kd_buf *kp, uint64_t thetime) 631{ 632 kp->timestamp = thetime; 633} 634static inline uint64_t 635kdbg_get_timestamp(kd_buf *kp) 636{ 637 return kp->timestamp; 638} 639static inline void 640kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu) 641{ 642 kdbg_set_timestamp(kp, thetime); 643 kdbg_set_cpu(kp, cpu); 644} 645#endif 646 647/* 2^16 bits (8 kilobytes), one for each possible class/subclass combination */ 648#define KDBG_TYPEFILTER_BITMAP_SIZE ( (256 * 256) / 8 ) 649 650/* Debug Flags */ 651#define KDBG_INIT 0x001 652#define KDBG_NOWRAP 0x002 653#define KDBG_FREERUN 0x004 654#define KDBG_WRAPPED 0x008 655#define KDBG_USERFLAGS (KDBG_FREERUN|KDBG_NOWRAP|KDBG_INIT) 656#define KDBG_PIDCHECK 0x010 657#define KDBG_MAPINIT 0x020 658#define KDBG_PIDEXCLUDE 0x040 659#define KDBG_LOCKINIT 0x080 660#define KDBG_LP64 0x100 661 662typedef struct { 663 unsigned int type; 664 unsigned int value1; 665 unsigned int value2; 666 unsigned int value3; 667 unsigned int value4; 668 669} kd_regtype; 670 671typedef struct 672{ 673 int nkdbufs; 674 int nolog; 675 int flags; 676 int nkdthreads; 677 int bufid; 678} kbufinfo_t; 679 680typedef struct { 681 uintptr_t thread; 682 int valid; 683 char command[20]; 684} kd_threadmap; 685 686 687typedef struct { 688 int version_no; 689 int thread_count; 690 uint64_t TOD_secs; 691 uint32_t TOD_usecs; 692} RAW_header; 693 694#define RAW_VERSION0 0x55aa0000 695#define RAW_VERSION1 0x55aa0101 696 697 698#define KDBG_CLASSTYPE 0x10000 699#define KDBG_SUBCLSTYPE 0x20000 700#define KDBG_RANGETYPE 0x40000 701#define KDBG_TYPENONE 0x80000 702#define KDBG_CKTYPES 0xF0000 703 704#define KDBG_RANGECHECK 0x100000 705#define KDBG_VALCHECK 0x200000 /* Check up to 4 individual values */ 706 707#define KDBG_TYPEFILTER_CHECK ((uint32_t) 0x400000) /* Check class and subclass against a bitmap */ 708 709#define KDBG_BUFINIT 0x80000000 710 711/* Control operations */ 712#define KDBG_EFLAGS 1 713#define KDBG_DFLAGS 2 714#define KDBG_ENABLE 3 715#define KDBG_SETNUMBUF 4 716#define KDBG_GETNUMBUF 5 717#define KDBG_SETUP 6 718#define KDBG_REMOVE 7 719#define KDBG_SETREGCODE 8 720#define KDBG_GETREGCODE 9 721#define KDBG_READTRACE 10 722#define KDBG_PIDTR 11 723#define KDBG_THRMAP 12 724#define KDBG_PIDEX 14 725#define KDBG_SETRTCDEC 15 726#define KDBG_KDGETENTROPY 16 727 728/* Minimum value allowed when setting decrementer ticks */ 729#define KDBG_MINRTCDEC 2500 730 731#endif /* __APPLE_API_PRIVATE */ 732#endif /* PRIVATE */ 733 734int kdebug_trace(int code, int arg1, int arg2, int arg3, int arg4); 735 736#endif /* !BSD_SYS_KDEBUG_H */