2 * Copyright (c) 2000-2014 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 /* Copyright (c) 1997 Apple Computer, Inc. All rights reserved.
31 * kdebug.h - kernel_debug definitions
35 #ifndef BSD_SYS_KDEBUG_H
36 #define BSD_SYS_KDEBUG_H
38 #include <sys/appleapiopts.h>
39 #include <sys/cdefs.h>
42 #ifdef __APPLE_API_UNSTABLE
44 #include <mach/clock_types.h>
46 #if defined(KERNEL_BUILD)
48 #endif /* KERNEL_BUILD */
50 #ifdef XNU_KERNEL_PRIVATE
52 #include <mach/branch_predicates.h>
57 KD_CALLBACK_KDEBUG_ENABLED
, // Trace is now enabled. No arguments
58 KD_CALLBACK_KDEBUG_DISABLED
, // Trace is now disabled. No arguments
59 KD_CALLBACK_SYNC_FLUSH
, // Request the latest entries from the IOP, and block until complete. No arguments
60 KD_CALLBACK_TYPEFILTER_CHANGED
, // Typefilter is enabled. A read-only pointer to the typefilter is provided, but is only valid while in the callback.
62 typedef void (*kd_callback_fn
) (void* context
, kd_callback_type reason
, void* arg
);
67 char iop_name
[8]; // null-terminated string with name of core.
70 typedef struct kd_callback kd_callback_t
;
73 * Registers an IOP for participation in tracing.
75 * The registered callback function will be called with the
76 * supplied context as the first argument, followed by a
77 * kd_callback_type and an associated void* argument.
79 * The return value is a nonzero coreid that shall be used in
80 * kernel_debug_enter() to refer to your IOP. If the allocation
81 * failed, then 0 will be returned.
85 * Note that not all callback calls will indicate a change in
86 * state (e.g. disabling trace twice would send two disable
90 extern int kernel_debug_register_callback(kd_callback_t callback
);
92 extern void kernel_debug_enter(
105 * state bits for hfs_update event
107 #define DBG_HFS_UPDATE_ACCTIME 0x01
108 #define DBG_HFS_UPDATE_MODTIME 0x02
109 #define DBG_HFS_UPDATE_CHGTIME 0x04
110 #define DBG_HFS_UPDATE_MODIFIED 0x08
111 #define DBG_HFS_UPDATE_FORCE 0x10
112 #define DBG_HFS_UPDATE_DATEADDED 0x20
116 * types of faults that vm_fault handles
117 * and creates trace entries for
119 #define DBG_ZERO_FILL_FAULT 1
120 #define DBG_PAGEIN_FAULT 2
121 #define DBG_COW_FAULT 3
122 #define DBG_CACHE_HIT_FAULT 4
123 #define DBG_NZF_PAGE_FAULT 5
124 #define DBG_GUARD_FAULT 6
125 #define DBG_PAGEINV_FAULT 7
126 #define DBG_PAGEIND_FAULT 8
127 #define DBG_COMPRESSOR_FAULT 9
128 #define DBG_COMPRESSOR_SWAPIN_FAULT 10
131 /* The debug code consists of the following
133 * ----------------------------------------------------------------------
135 *| Class (8) | SubClass (8) | Code (14) |Qual(2)|
136 * ----------------------------------------------------------------------
137 * The class specifies the higher level
140 /* The Function qualifiers */
141 #define DBG_FUNC_START 1
142 #define DBG_FUNC_END 2
143 #define DBG_FUNC_NONE 0
146 /* The Kernel Debug Classes */
148 #define DBG_NETWORK 2
149 #define DBG_FSYSTEM 3
152 #define DBG_DRIVERS 6
155 #define DBG_WORKQUEUE 9
156 #define DBG_CORESTORAGE 10
159 #define DBG_SECURITY 30
163 #define DBG_LAUNCHD 34
165 #define DBG_IMPORTANCE 38
172 /* **** The Kernel Debug Sub Classes for Mach (DBG_MACH) **** */
173 #define DBG_MACH_EXCP_KTRAP_x86 0x02 /* Kernel Traps on x86 */
174 #define DBG_MACH_EXCP_DFLT 0x03 /* Data Translation Fault */
175 #define DBG_MACH_EXCP_IFLT 0x04 /* Inst Translation Fault */
176 #define DBG_MACH_EXCP_INTR 0x05 /* Interrupts */
177 #define DBG_MACH_EXCP_ALNG 0x06 /* Alignment Exception */
178 #define DBG_MACH_EXCP_UTRAP_x86 0x07 /* User Traps on x86 */
179 #define DBG_MACH_EXCP_FP 0x08 /* FP Unavail */
180 #define DBG_MACH_EXCP_DECI 0x09 /* Decrementer Interrupt */
181 #define DBG_MACH_CHUD 0x0A /* CHUD */
182 #define DBG_MACH_EXCP_SC 0x0C /* System Calls */
183 #define DBG_MACH_EXCP_TRACE 0x0D /* Trace exception */
184 #define DBG_MACH_EXCP_EMUL 0x0E /* Instruction emulated */
185 #define DBG_MACH_IHDLR 0x10 /* Interrupt Handlers */
186 #define DBG_MACH_IPC 0x20 /* Inter Process Comm */
187 #define DBG_MACH_VM 0x30 /* Virtual Memory */
188 #define DBG_MACH_LEAKS 0x31 /* alloc/free */
189 #define DBG_MACH_SCHED 0x40 /* Scheduler */
190 #define DBG_MACH_MSGID_INVALID 0x50 /* Messages - invalid */
191 #define DBG_MACH_LOCKS 0x60 /* new lock APIs */
192 #define DBG_MACH_PMAP 0x70 /* pmap */
193 /* #define unused 0x80 */
194 #define DBG_MACH_MP 0x90 /* MP related */
195 #define DBG_MACH_VM_PRESSURE 0xA0 /* Memory Pressure Events */
196 #define DBG_MACH_STACKSHOT 0xA1 /* Stackshot/Microstackshot subsystem */
197 #define DBG_MACH_SFI 0xA2 /* Selective Forced Idle (SFI) */
198 #define DBG_MACH_ENERGY_PERF 0xA3 /* Energy/performance resource stats */
200 /* Codes for Scheduler (DBG_MACH_SCHED) */
201 #define MACH_SCHED 0x0 /* Scheduler */
202 #define MACH_STACK_ATTACH 0x1 /* stack_attach() */
203 #define MACH_STACK_HANDOFF 0x2 /* stack_handoff() */
204 #define MACH_CALL_CONT 0x3 /* call_continuation() */
205 #define MACH_CALLOUT 0x4 /* callouts */
206 #define MACH_STACK_DETACH 0x5
207 #define MACH_MAKE_RUNNABLE 0x6 /* make thread runnable */
208 #define MACH_PROMOTE 0x7 /* promoted due to resource */
209 #define MACH_DEMOTE 0x8 /* promotion undone */
210 #define MACH_IDLE 0x9 /* processor idling */
211 #define MACH_STACK_DEPTH 0xa /* stack depth at switch */
212 #define MACH_MOVED 0xb /* did not use original scheduling decision */
213 #define MACH_FAIRSHARE_ENTER 0xc /* move to fairshare band */
214 #define MACH_FAIRSHARE_EXIT 0xd /* exit fairshare band */
215 #define MACH_FAILSAFE 0xe /* tripped fixed-pri/RT failsafe */
216 #define MACH_BLOCK 0xf /* thread block */
217 #define MACH_WAIT 0x10 /* thread wait assertion */
218 #define MACH_GET_URGENCY 0x14 /* Urgency queried by platform */
219 #define MACH_URGENCY 0x15 /* Urgency (RT/BG/NORMAL) communicated
222 #define MACH_REDISPATCH 0x16 /* "next thread" thread redispatched */
223 #define MACH_REMOTE_AST 0x17 /* AST signal issued to remote processor */
225 #define MACH_SCHED_CHOOSE_PROCESSOR 0x18 /* Result of choose_processor */
226 #define MACH_DEEP_IDLE 0x19 /* deep idle on master processor */
227 #define MACH_SCHED_DECAY_PRIORITY 0x1a /* timeshare thread priority decayed/restored */
228 #define MACH_CPU_THROTTLE_DISABLE 0x1b /* Global CPU Throttle Disable */
229 #define MACH_RW_PROMOTE 0x1c /* promoted due to RW lock promotion */
230 #define MACH_RW_DEMOTE 0x1d /* promotion due to RW lock undone */
231 #define MACH_SCHED_MAINTENANCE 0x1f /* periodic maintenance thread */
232 #define MACH_DISPATCH 0x20 /* context switch completed */
233 #define MACH_QUANTUM_HANDOFF 0x21 /* quantum handoff occurred */
234 #define MACH_MULTIQ_DEQUEUE 0x22 /* Result of multiq dequeue */
235 #define MACH_SCHED_THREAD_SWITCH 0x23 /* attempt direct context switch to hinted thread */
236 #define MACH_SCHED_SMT_BALANCE 0x24 /* SMT load balancing ASTs */
238 /* Variants for MACH_MULTIQ_DEQUEUE */
239 #define MACH_MULTIQ_BOUND 1
240 #define MACH_MULTIQ_GROUP 2
241 #define MACH_MULTIQ_GLOBAL 3
243 /* Codes for IPC (DBG_MACH_IPC) */
244 #define MACH_TASK_SUSPEND 0x0 /* Suspended a task */
245 #define MACH_TASK_RESUME 0x1 /* Resumed a task */
246 #define MACH_THREAD_SET_VOUCHER 0x2
247 #define MACH_IPC_MSG_SEND 0x3 /* mach msg send, uniq msg info */
248 #define MACH_IPC_MSG_RECV 0x4 /* mach_msg receive */
249 #define MACH_IPC_MSG_RECV_VOUCHER_REFUSED 0x5 /* mach_msg receive, voucher refused */
250 #define MACH_IPC_KMSG_FREE 0x6 /* kernel free of kmsg data */
251 #define MACH_IPC_VOUCHER_CREATE 0x7 /* Voucher added to global voucher hashtable */
252 #define MACH_IPC_VOUCHER_CREATE_ATTR_DATA 0x8 /* Attr data for newly created voucher */
253 #define MACH_IPC_VOUCHER_DESTROY 0x9 /* Voucher removed from global voucher hashtable */
255 /* Codes for pmap (DBG_MACH_PMAP) */
256 #define PMAP__CREATE 0x0
257 #define PMAP__DESTROY 0x1
258 #define PMAP__PROTECT 0x2
259 #define PMAP__PAGE_PROTECT 0x3
260 #define PMAP__ENTER 0x4
261 #define PMAP__REMOVE 0x5
262 #define PMAP__NEST 0x6
263 #define PMAP__UNNEST 0x7
264 #define PMAP__FLUSH_TLBS 0x8
265 #define PMAP__UPDATE_INTERRUPT 0x9
266 #define PMAP__ATTRIBUTE_CLEAR 0xa
267 #define PMAP__REUSABLE 0xb
268 #define PMAP__QUERY_RESIDENT 0xc
269 #define PMAP__FLUSH_KERN_TLBS 0xd
270 #define PMAP__FLUSH_DELAYED_TLBS 0xe
271 #define PMAP__FLUSH_TLBS_TO 0xf
273 /* Codes for Stackshot/Microstackshot (DBG_MACH_STACKSHOT) */
274 #define MICROSTACKSHOT_RECORD 0x0
275 #define MICROSTACKSHOT_GATHER 0x1
277 /* Codes for Selective Forced Idle (DBG_MACH_SFI) */
278 #define SFI_SET_WINDOW 0x0
279 #define SFI_CANCEL_WINDOW 0x1
280 #define SFI_SET_CLASS_OFFTIME 0x2
281 #define SFI_CANCEL_CLASS_OFFTIME 0x3
282 #define SFI_THREAD_DEFER 0x4
283 #define SFI_OFF_TIMER 0x5
284 #define SFI_ON_TIMER 0x6
285 #define SFI_WAIT_CANCELED 0x7
286 #define SFI_PID_SET_MANAGED 0x8
287 #define SFI_PID_CLEAR_MANAGED 0x9
289 /* **** The Kernel Debug Sub Classes for Network (DBG_NETWORK) **** */
290 #define DBG_NETIP 1 /* Internet Protocol */
291 #define DBG_NETARP 2 /* Address Resolution Protocol */
292 #define DBG_NETUDP 3 /* User Datagram Protocol */
293 #define DBG_NETTCP 4 /* Transmission Control Protocol */
294 #define DBG_NETICMP 5 /* Internet Control Message Protocol */
295 #define DBG_NETIGMP 6 /* Internet Group Management Protocol */
296 #define DBG_NETRIP 7 /* Routing Information Protocol */
297 #define DBG_NETOSPF 8 /* Open Shortest Path First */
298 #define DBG_NETISIS 9 /* Intermediate System to Intermediate System */
299 #define DBG_NETSNMP 10 /* Simple Network Management Protocol */
300 #define DBG_NETSOCK 11 /* Socket Layer */
303 #define DBG_NETAARP 100 /* Apple ARP */
304 #define DBG_NETDDP 101 /* Datagram Delivery Protocol */
305 #define DBG_NETNBP 102 /* Name Binding Protocol */
306 #define DBG_NETZIP 103 /* Zone Information Protocol */
307 #define DBG_NETADSP 104 /* Name Binding Protocol */
308 #define DBG_NETATP 105 /* Apple Transaction Protocol */
309 #define DBG_NETASP 106 /* Apple Session Protocol */
310 #define DBG_NETAFP 107 /* Apple Filing Protocol */
311 #define DBG_NETRTMP 108 /* Routing Table Maintenance Protocol */
312 #define DBG_NETAURP 109 /* Apple Update Routing Protocol */
314 #define DBG_NETIPSEC 128 /* IPsec Protocol */
315 #define DBG_NETVMNET 129 /* VMNet */
317 /* **** The Kernel Debug Sub Classes for IOKIT (DBG_IOKIT) **** */
318 #define DBG_IOINTC 0 /* Interrupt controller */
319 #define DBG_IOWORKLOOP 1 /* Work from work loop */
320 #define DBG_IOINTES 2 /* Interrupt event source */
321 #define DBG_IOCLKES 3 /* Clock event source */
322 #define DBG_IOCMDQ 4 /* Command queue latencies */
323 #define DBG_IOMCURS 5 /* Memory Cursor */
324 #define DBG_IOMDESC 6 /* Memory Descriptors */
325 #define DBG_IOPOWER 7 /* Power Managerment */
326 #define DBG_IOSERVICE 8 /* Matching etc. */
328 /* **** 9-32 reserved for internal IOKit usage **** */
330 #define DBG_IOSTORAGE 32 /* Storage layers */
331 #define DBG_IONETWORK 33 /* Network layers */
332 #define DBG_IOKEYBOARD 34 /* Keyboard */
333 #define DBG_IOHID 35 /* HID Devices */
334 #define DBG_IOAUDIO 36 /* Audio */
335 #define DBG_IOSERIAL 37 /* Serial */
336 #define DBG_IOTTY 38 /* TTY layers */
337 #define DBG_IOSAM 39 /* SCSI Architecture Model layers */
338 #define DBG_IOPARALLELATA 40 /* Parallel ATA */
339 #define DBG_IOPARALLELSCSI 41 /* Parallel SCSI */
340 #define DBG_IOSATA 42 /* Serial-ATA */
341 #define DBG_IOSAS 43 /* SAS */
342 #define DBG_IOFIBRECHANNEL 44 /* FiberChannel */
343 #define DBG_IOUSB 45 /* USB */
344 #define DBG_IOBLUETOOTH 46 /* Bluetooth */
345 #define DBG_IOFIREWIRE 47 /* FireWire */
346 #define DBG_IOINFINIBAND 48 /* Infiniband */
347 #define DBG_IOCPUPM 49 /* CPU Power Management */
348 #define DBG_IOGRAPHICS 50 /* Graphics */
349 #define DBG_HIBERNATE 51 /* hibernation related events */
350 #define DBG_IOTHUNDERBOLT 52 /* Thunderbolt */
353 /* Backwards compatibility */
354 #define DBG_IOPOINTING DBG_IOHID /* OBSOLETE: Use DBG_IOHID instead */
355 #define DBG_IODISK DBG_IOSTORAGE /* OBSOLETE: Use DBG_IOSTORAGE instead */
357 /* **** The Kernel Debug Sub Classes for Device Drivers (DBG_DRIVERS) **** */
358 #define DBG_DRVSTORAGE 1 /* Storage layers */
359 #define DBG_DRVNETWORK 2 /* Network layers */
360 #define DBG_DRVKEYBOARD 3 /* Keyboard */
361 #define DBG_DRVHID 4 /* HID Devices */
362 #define DBG_DRVAUDIO 5 /* Audio */
363 #define DBG_DRVSERIAL 7 /* Serial */
364 #define DBG_DRVSAM 8 /* SCSI Architecture Model layers */
365 #define DBG_DRVPARALLELATA 9 /* Parallel ATA */
366 #define DBG_DRVPARALLELSCSI 10 /* Parallel SCSI */
367 #define DBG_DRVSATA 11 /* Serial ATA */
368 #define DBG_DRVSAS 12 /* SAS */
369 #define DBG_DRVFIBRECHANNEL 13 /* FiberChannel */
370 #define DBG_DRVUSB 14 /* USB */
371 #define DBG_DRVBLUETOOTH 15 /* Bluetooth */
372 #define DBG_DRVFIREWIRE 16 /* FireWire */
373 #define DBG_DRVINFINIBAND 17 /* Infiniband */
374 #define DBG_DRVGRAPHICS 18 /* Graphics */
375 #define DBG_DRVSD 19 /* Secure Digital */
376 #define DBG_DRVNAND 20 /* NAND drivers and layers */
377 #define DBG_SSD 21 /* SSD */
378 #define DBG_DRVSPI 22 /* SPI */
380 /* Backwards compatibility */
381 #define DBG_DRVPOINTING DBG_DRVHID /* OBSOLETE: Use DBG_DRVHID instead */
382 #define DBG_DRVDISK DBG_DRVSTORAGE /* OBSOLETE: Use DBG_DRVSTORAGE instead */
384 /* **** The Kernel Debug Sub Classes for the DLIL Layer (DBG_DLIL) **** */
385 #define DBG_DLIL_STATIC 1 /* Static DLIL code */
386 #define DBG_DLIL_PR_MOD 2 /* DLIL Protocol Module */
387 #define DBG_DLIL_IF_MOD 3 /* DLIL Interface Module */
388 #define DBG_DLIL_PR_FLT 4 /* DLIL Protocol Filter */
389 #define DBG_DLIL_IF_FLT 5 /* DLIL Interface FIlter */
391 /* The Kernel Debug Sub Classes for File System (DBG_FSYSTEM) */
392 #define DBG_FSRW 1 /* reads and writes to the filesystem */
393 #define DBG_DKRW 2 /* reads and writes to the disk */
394 #define DBG_FSVN 3 /* vnode operations (inc. locking/unlocking) */
395 #define DBG_FSLOOOKUP 4 /* namei and other lookup-related operations */
396 #define DBG_JOURNAL 5 /* journaling operations */
397 #define DBG_IOCTL 6 /* ioctl to the disk */
398 #define DBG_BOOTCACHE 7 /* bootcache operations */
399 #define DBG_HFS 8 /* HFS-specific events; see bsd/hfs/hfs_kdebug.h */
400 #define DBG_EXFAT 0xE /* ExFAT-specific events; see the exfat project */
401 #define DBG_MSDOS 0xF /* FAT-specific events; see the msdosfs project */
402 #define DBG_ACFS 0x10 /* Xsan-specific events; see the XsanFS project */
403 #define DBG_THROTTLE 0x11 /* I/O Throttling events */
404 #define DBG_CONTENT_PROT 0xCF /* Content Protection Events: see bsd/sys/cprotect.h */
406 /* The Kernel Debug Sub Classes for BSD */
407 #define DBG_BSD_PROC 0x01 /* process/signals related */
408 #define DBG_BSD_MEMSTAT 0x02 /* memorystatus / jetsam operations */
409 #define DBG_BSD_EXCP_SC 0x0C /* System Calls */
410 #define DBG_BSD_AIO 0x0D /* aio (POSIX async IO) */
411 #define DBG_BSD_SC_EXTENDED_INFO 0x0E /* System Calls, extended info */
412 #define DBG_BSD_SC_EXTENDED_INFO2 0x0F /* System Calls, extended info */
415 /* The Codes for BSD subcode class DBG_BSD_PROC */
416 #define BSD_PROC_EXIT 1 /* process exit */
417 #define BSD_PROC_FRCEXIT 2 /* Kernel force termination */
419 /* Codes for BSD subcode class DBG_BSD_MEMSTAT */
420 #define BSD_MEMSTAT_SCAN 1 /* memorystatus thread awake */
421 #define BSD_MEMSTAT_JETSAM 2 /* LRU jetsam */
422 #define BSD_MEMSTAT_JETSAM_HIWAT 3 /* highwater jetsam */
423 #define BSD_MEMSTAT_FREEZE 4 /* freeze process */
424 #define BSD_MEMSTAT_LATENCY_COALESCE 5 /* delay imposed to coalesce jetsam reports */
425 #define BSD_MEMSTAT_UPDATE 6 /* priority update */
426 #define BSD_MEMSTAT_IDLE_DEMOTE 7 /* idle demotion fired */
427 #define BSD_MEMSTAT_CLEAR_ERRORS 8 /* reset termination error state */
428 #define BSD_MEMSTAT_DIRTY_TRACK 9 /* track the process state */
429 #define BSD_MEMSTAT_DIRTY_SET 10 /* set the process state */
430 #define BSD_MEMSTAT_DIRTY_CLEAR 11 /* clear the process state */
432 #define BSD_MEMSTAT_GRP_SET_PROP 12 /* set group properties */
433 #define BSD_MEMSTAT_DO_KILL 13 /* memorystatus kills */
436 /* The Kernel Debug Sub Classes for DBG_TRACE */
437 #define DBG_TRACE_DATA 0
438 #define DBG_TRACE_STRING 1
439 #define DBG_TRACE_INFO 2
442 * TRACE_DATA_NEWTHREAD 0x1
443 * TRACE_DATA_EXEC 0x2
445 #define TRACE_DATA_THREAD_TERMINATE 0x3 /* thread has been queued for deallocation and can no longer run */
447 /* The Kernel Debug Sub Classes for DBG_CORESTORAGE */
450 /* The Kernel Debug Sub Classes for DBG_SECURITY */
451 #define DBG_SEC_KERNEL 0 /* raw entropy collected by the kernel */
453 /* Sub-class codes for CoreGraphics (DBG_CG) are defined in its component. */
455 /* The Kernel Debug Sub Classes for DBG_MISC */
456 #define DBG_EVENT 0x10
457 #define DBG_BUFFER 0x20
459 /* The Kernel Debug Sub Classes for DBG_DYLD */
460 #define DBG_DYLD_STRING 5
462 /* The Kernel Debug modifiers for the DBG_DKRW sub class */
463 #define DKIO_DONE 0x01
464 #define DKIO_READ 0x02
465 #define DKIO_ASYNC 0x04
466 #define DKIO_META 0x08
467 #define DKIO_PAGING 0x10
468 #define DKIO_THROTTLE 0x20 /* Deprecated, still provided so fs_usage doesn't break */
469 #define DKIO_PASSIVE 0x40
470 #define DKIO_NOCACHE 0x80
471 #define DKIO_TIER_MASK 0xF00
472 #define DKIO_TIER_SHIFT 8
474 /* Kernel Debug Sub Classes for Applications (DBG_APPS) */
475 #define DBG_APP_LOGINWINDOW 0x03
476 #define DBG_APP_AUDIO 0x04
477 #define DBG_APP_SAMBA 0x80
479 /* Kernel Debug codes for Throttling (DBG_THROTTLE) */
480 #define OPEN_THROTTLE_WINDOW 0x1
481 #define PROCESS_THROTTLED 0x2
482 #define IO_THROTTLE_DISABLE 0x3
485 /* Subclasses for MACH Importance Policies (DBG_IMPORTANCE) */
486 /* TODO: Split up boost and task policy? */
487 #define IMP_ASSERTION 0x10 /* Task takes/drops a boost assertion */
488 #define IMP_BOOST 0x11 /* Task boost level changed */
489 #define IMP_MSG 0x12 /* boosting message sent by donating task on donating port */
490 #define IMP_WATCHPORT 0x13 /* port marked as watchport, and boost was transferred to the watched task */
491 #define IMP_TASK_SUPPRESSION 0x17 /* Task changed suppression behaviors */
492 #define IMP_TASK_APPTYPE 0x18 /* Task launched with apptype */
493 #define IMP_UPDATE 0x19 /* Requested -> effective calculation */
494 #define IMP_USYNCH_QOS_OVERRIDE 0x1A /* Userspace synchronization applied QoS override to resource owning thread */
495 #define IMP_DONOR_CHANGE 0x1B /* The iit_donor bit changed */
496 #define IMP_MAIN_THREAD_QOS 0x1C /* The task's main thread QoS was set */
497 /* DBG_IMPORTANCE subclasses 0x20 - 0x3F reserved for task policy flavors */
499 /* Codes for IMP_ASSERTION */
500 #define IMP_HOLD 0x2 /* Task holds a boost assertion */
501 #define IMP_DROP 0x4 /* Task drops a boost assertion */
502 #define IMP_EXTERN 0x8 /* boost assertion moved from kernel to userspace responsibility (externalized) */
504 /* Codes for IMP_BOOST */
505 #define IMP_BOOSTED 0x1
506 #define IMP_UNBOOSTED 0x2 /* Task drops a boost assertion */
508 /* Codes for IMP_MSG */
509 #define IMP_MSG_SEND 0x1 /* boosting message sent by donating task on donating port */
510 #define IMP_MSG_DELV 0x2 /* boosting message delivered to task */
512 /* Codes for IMP_UPDATE */
513 #define IMP_UPDATE_TASK_CREATE 0x1
515 /* Codes for IMP_USYNCH_QOS_OVERRIDE */
516 #define IMP_USYNCH_ADD_OVERRIDE 0x0 /* add override for a contended resource */
517 #define IMP_USYNCH_REMOVE_OVERRIDE 0x1 /* remove override for a contended resource */
519 /* Codes for IMP_DONOR_CHANGE */
520 #define IMP_DONOR_UPDATE_LIVE_DONOR_STATE 0x0
521 #define IMP_DONOR_INIT_DONOR_STATE 0x1
523 /* Subclasses for MACH Bank Voucher Attribute Manager (DBG_BANK) */
524 #define BANK_ACCOUNT_INFO 0x10 /* Trace points related to bank account struct */
525 #define BANK_TASK_INFO 0x11 /* Trace points related to bank task struct */
527 /* Subclasses for MACH ATM Voucher Attribute Manager (ATM) */
528 #define ATM_SUBAID_INFO 0x10
529 #define ATM_GETVALUE_INFO 0x20
530 #define ATM_UNREGISTER_INFO 0x30
532 /* Codes for BANK_ACCOUNT_INFO */
533 #define BANK_SETTLE_CPU_TIME 0x1 /* Bank ledger(chit) rolled up to tasks. */
535 /* Codes for ATM_SUBAID_INFO */
536 #define ATM_MIN_CALLED 0x1
537 #define ATM_MIN_LINK_LIST 0x2
539 /* Codes for ATM_GETVALUE_INFO */
540 #define ATM_VALUE_REPLACED 0x1
541 #define ATM_VALUE_ADDED 0x2
543 /* Codes for ATM_UNREGISTER_INFO */
544 #define ATM_VALUE_UNREGISTERED 0x1
545 #define ATM_VALUE_DIFF_MAILBOX 0x2
547 /**********************************************************************/
549 #define KDBG_CODE(Class, SubClass, code) (((Class & 0xff) << 24) | ((SubClass & 0xff) << 16) | ((code & 0x3fff) << 2))
551 #define KDBG_MIGCODE(msgid) ((DBG_MIG << 24) | (((msgid) & 0x3fffff) << 2))
553 #define MACHDBG_CODE(SubClass, code) KDBG_CODE(DBG_MACH, SubClass, code)
554 #define NETDBG_CODE(SubClass, code) KDBG_CODE(DBG_NETWORK, SubClass, code)
555 #define FSDBG_CODE(SubClass, code) KDBG_CODE(DBG_FSYSTEM, SubClass, code)
556 #define BSDDBG_CODE(SubClass, code) KDBG_CODE(DBG_BSD, SubClass, code)
557 #define IOKDBG_CODE(SubClass, code) KDBG_CODE(DBG_IOKIT, SubClass, code)
558 #define DRVDBG_CODE(SubClass, code) KDBG_CODE(DBG_DRIVERS, SubClass, code)
559 #define TRACEDBG_CODE(SubClass,code) KDBG_CODE(DBG_TRACE, SubClass, code)
560 #define MISCDBG_CODE(SubClass,code) KDBG_CODE(DBG_MISC, SubClass, code)
561 #define DLILDBG_CODE(SubClass,code) KDBG_CODE(DBG_DLIL, SubClass, code)
562 #define SECURITYDBG_CODE(SubClass,code) KDBG_CODE(DBG_SECURITY, SubClass, code)
563 #define DYLDDBG_CODE(SubClass,code) KDBG_CODE(DBG_DYLD, SubClass, code)
564 #define QTDBG_CODE(SubClass,code) KDBG_CODE(DBG_QT, SubClass, code)
565 #define APPSDBG_CODE(SubClass,code) KDBG_CODE(DBG_APPS, SubClass, code)
566 #define CPUPM_CODE(code) IOKDBG_CODE(DBG_IOCPUPM, code)
568 #define KMEM_ALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 0)
569 #define KMEM_ALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 1)
570 #define KMEM_FREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 2)
571 #define KMEM_FREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 3)
572 #define ZALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 4)
573 #define ZALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 5)
574 #define ZFREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 6)
575 #define ZFREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 7)
577 #define PMAP_CODE(code) MACHDBG_CODE(DBG_MACH_PMAP, code)
580 #define IMPORTANCE_CODE(SubClass, code) KDBG_CODE(DBG_IMPORTANCE, (SubClass), (code))
581 #define BANK_CODE(SubClass, code) KDBG_CODE(DBG_BANK, (SubClass), (code))
582 #define ATM_CODE(SubClass, code) KDBG_CODE(DBG_ATM, (SubClass), (code))
585 * kernel_debug((KDBG_CODE(DBG_NETWORK, DNET_PROTOCOL, 51) | DBG_FUNC_START),
590 * #include <sys/kdebug.h>
592 * #define DBG_NETIPINIT NETDBG_CODE(DBG_NETIP,1)
598 * register struct protosw *pr;
601 * KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_START, 0,0,0,0,0)
603 * KERNEL_DEBUG(DBG_NETIPINIT, 0,0,0,0,0)
605 * KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_END, 0,0,0,0,0)
611 extern unsigned int kdebug_enable
;
612 #define KDEBUG_ENABLE_TRACE 0x1
613 #define KDEBUG_ENABLE_ENTROPY 0x2 /* Obsolescent */
614 #define KDEBUG_ENABLE_CHUD 0x4
615 #define KDEBUG_ENABLE_PPT 0x8
618 * Infer the supported kernel debug event level from config option.
619 * Use (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) as a guard to protect
620 * unaudited debug code.
622 #define KDEBUG_LEVEL_NONE 0
623 #define KDEBUG_LEVEL_IST 1
624 #define KDEBUG_LEVEL_STANDARD 2
625 #define KDEBUG_LEVEL_FULL 3
628 #define KDEBUG_LEVEL KDEBUG_LEVEL_NONE
630 #define KDEBUG_LEVEL KDEBUG_LEVEL_IST
632 #define KDEBUG_LEVEL KDEBUG_LEVEL_FULL
634 #define KDEBUG_LEVEL KDEBUG_LEVEL_STANDARD
637 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
638 #ifdef XNU_KERNEL_PRIVATE
639 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \
641 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
642 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
643 (uintptr_t)d,(uintptr_t)e); \
646 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \
648 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
649 kernel_debug1(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
650 (uintptr_t)d,(uintptr_t)e); \
653 #define KERNEL_DEBUG_EARLY(x,a,b,c,d) \
655 kernel_debug_early((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
656 (uintptr_t)c, (uintptr_t)d); \
658 #else /* XNU_KERNEL_PRIVATE */
659 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \
661 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
662 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
663 (uintptr_t)d,(uintptr_t)e); \
666 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \
668 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
669 kernel_debug1(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
670 (uintptr_t)d,(uintptr_t)e); \
673 #define KERNEL_DEBUG_EARLY(x,a,b,c,d) \
675 kernel_debug_early((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
676 (uintptr_t)c, (uintptr_t)d); \
678 #endif /* XNU_KERNEL_PRIVATE */
679 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
680 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) do { } while(0)
681 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) do { } while(0)
682 #define KERNEL_DEBUG_EARLY(x,a,b,c,d) do { } while(0)
683 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
686 * Specify KDEBUG_PPT to indicate that the event belongs to the
689 #define KDEBUG_COMMON (KDEBUG_ENABLE_TRACE|KDEBUG_ENABLE_CHUD|KDEBUG_ENABLE_PPT)
690 #define KDEBUG_TRACE (KDEBUG_ENABLE_TRACE|KDEBUG_ENABLE_CHUD)
691 #define KDEBUG_PPT (KDEBUG_ENABLE_PPT)
694 * KERNEL_DEBUG_CONSTANT_IST events provide an audited subset of
695 * tracepoints for userland system tracing tools.
697 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST)
698 #ifdef XNU_KERNEL_PRIVATE
699 #define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) \
701 if (__improbable(kdebug_enable & type)) \
702 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
703 (uintptr_t)d,(uintptr_t)e); \
705 #else /* XNU_KERNEL_PRIVATE */
706 #define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) \
708 if (kdebug_enable & type) \
709 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
710 (uintptr_t)d,(uintptr_t)e); \
712 #endif /* XNU_KERNEL_PRIVATE */
713 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
714 #define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) do { } while(0)
715 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
718 #define __kdebug_constant_only __unused
721 extern void kernel_debug(
729 extern void kernel_debug1(
737 extern void kernel_debug_early(
744 extern void kernel_debug_string(
745 const char *message
);
747 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL)
748 #ifdef XNU_KERNEL_PRIVATE
749 #define KERNEL_DEBUG(x,a,b,c,d,e) \
751 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
752 kernel_debug((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
753 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
756 #define KERNEL_DEBUG1(x,a,b,c,d,e) \
758 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
759 kernel_debug1((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
760 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
763 #define __kdebug_only
764 #else /* !XNU_KERNEL_PRIVATE */
765 #define KERNEL_DEBUG(x,a,b,c,d,e) \
767 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
768 kernel_debug((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
769 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
772 #define KERNEL_DEBUG1(x,a,b,c,d,e) \
774 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
775 kernel_debug1((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
776 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
778 #endif /* XNU_KERNEL_PRIVATE */
779 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
780 #define KERNEL_DEBUG(x,a,b,c,d,e) do {} while (0)
781 #define KERNEL_DEBUG1(x,a,b,c,d,e) do {} while (0)
783 #define __kdebug_only __unused
784 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
786 #ifdef KERNEL_PRIVATE
787 #include <mach/boolean.h>
793 extern void kdebug_lookup_gen_events(long *dbg_parms
, int dbg_namelen
, void *dp
, boolean_t lookup
);
794 extern void kdbg_trace_data(struct proc
*proc
, long *arg_pid
);
796 extern void kdbg_trace_string(struct proc
*proc
, long *arg1
, long *arg2
, long *arg3
, long *arg4
);
798 extern void kdbg_dump_trace_to_file(const char *);
799 void start_kern_tracing(unsigned int, boolean_t
);
800 void start_kern_tracing_with_typefilter(unsigned int, boolean_t
, unsigned int);
802 extern void kdbg_get_task_name(char*, int, struct task
*task
);
803 void disable_wrap(uint32_t *old_slowcheck
, uint32_t *old_flags
);
804 void enable_wrap(uint32_t old_slowcheck
, boolean_t lostevents
);
805 void release_storage_unit(int cpu
, uint32_t storage_unit
);
806 int allocate_storage_unit(int cpu
);
808 #define KDBG_CLASS_ENCODE(Class, SubClass) (((Class & 0xff) << 24) | ((SubClass & 0xff) << 16))
809 #define KDBG_CLASS_DECODE(Debugid) (Debugid & 0xFFFF0000)
812 #endif /* KERNEL_PRIVATE */
815 #endif /* __APPLE_API_UNSTABLE */
820 #ifdef __APPLE_API_PRIVATE
822 * private kernel_debug definitions
831 uintptr_t arg5
; /* will hold current thread */
833 #if defined(__LP64__)
839 #if !defined(__LP64__)
840 #define KDBG_TIMESTAMP_MASK 0x00ffffffffffffffULL
841 #define KDBG_CPU_MASK 0xff00000000000000ULL
842 #define KDBG_CPU_SHIFT 56
844 kdbg_set_cpu(kd_buf
*kp
, int cpu
)
846 kp
->timestamp
= (kp
->timestamp
& KDBG_TIMESTAMP_MASK
) |
847 (((uint64_t) cpu
) << KDBG_CPU_SHIFT
);
850 kdbg_get_cpu(kd_buf
*kp
)
852 return (int) (((kp
)->timestamp
& KDBG_CPU_MASK
) >> KDBG_CPU_SHIFT
);
855 kdbg_set_timestamp(kd_buf
*kp
, uint64_t thetime
)
857 kp
->timestamp
= thetime
& KDBG_TIMESTAMP_MASK
;
859 static inline uint64_t
860 kdbg_get_timestamp(kd_buf
*kp
)
862 return kp
->timestamp
& KDBG_TIMESTAMP_MASK
;
865 kdbg_set_timestamp_and_cpu(kd_buf
*kp
, uint64_t thetime
, int cpu
)
867 kp
->timestamp
= (thetime
& KDBG_TIMESTAMP_MASK
) |
868 (((uint64_t) cpu
) << KDBG_CPU_SHIFT
);
871 #define KDBG_TIMESTAMP_MASK 0xffffffffffffffffULL
873 kdbg_set_cpu(kd_buf
*kp
, int cpu
)
878 kdbg_get_cpu(kd_buf
*kp
)
883 kdbg_set_timestamp(kd_buf
*kp
, uint64_t thetime
)
885 kp
->timestamp
= thetime
;
887 static inline uint64_t
888 kdbg_get_timestamp(kd_buf
*kp
)
890 return kp
->timestamp
;
893 kdbg_set_timestamp_and_cpu(kd_buf
*kp
, uint64_t thetime
, int cpu
)
895 kdbg_set_timestamp(kp
, thetime
);
896 kdbg_set_cpu(kp
, cpu
);
900 /* 2^16 bits (8 kilobytes), one for each possible class/subclass combination */
901 #define KDBG_TYPEFILTER_BITMAP_SIZE ( (256 * 256) / 8 )
904 #define KDBG_INIT 0x001
905 #define KDBG_NOWRAP 0x002
906 #define KDBG_FREERUN 0x004
907 #define KDBG_WRAPPED 0x008
908 #define KDBG_USERFLAGS (KDBG_FREERUN|KDBG_NOWRAP|KDBG_INIT)
909 #define KDBG_PIDCHECK 0x010
910 #define KDBG_MAPINIT 0x020
911 #define KDBG_PIDEXCLUDE 0x040
912 #define KDBG_LOCKINIT 0x080
913 #define KDBG_LP64 0x100
945 #define KDBG_CPUMAP_IS_IOP 0x1
954 * TRACE file formats...
958 * uint32_t #threadmaps
964 * RAW_header, with version_no set to RAW_VERSION1
966 * Empty space to pad alignment to the nearest page boundary.
971 * RAW_header, with version_no set to RAW_VERSION1
973 * kd_cpumap_header, with version_no set to RAW_VERSION1
975 * Empty space to pad alignment to the nearest page boundary.
978 * V1+ implementation details...
980 * It would have been nice to add the cpumap data "correctly", but there were
981 * several obstacles. Existing code attempts to parse both V1 and V0 files.
982 * Due to the fact that V0 has no versioning or header, the test looks like
986 * if (header.version_no != RAW_VERSION1) { // Assume V0 }
988 * If we add a VERSION2 file format, all existing code is going to treat that
989 * as a VERSION0 file when reading it, and crash terribly when trying to read
990 * RAW_VERSION2 threadmap entries.
992 * To differentiate between a V1 and V1+ file, read as V1 until you reach
993 * the padding bytes. Then:
995 * boolean_t is_v1plus = FALSE;
996 * if (padding_bytes >= sizeof(kd_cpumap_header)) {
997 * kd_cpumap_header header = // read header;
998 * if (header.version_no == RAW_VERSION1) {
1012 #define RAW_VERSION0 0x55aa0000
1013 #define RAW_VERSION1 0x55aa0101
1015 #define KDBG_CLASSTYPE 0x10000
1016 #define KDBG_SUBCLSTYPE 0x20000
1017 #define KDBG_RANGETYPE 0x40000
1018 #define KDBG_TYPENONE 0x80000
1019 #define KDBG_CKTYPES 0xF0000
1021 #define KDBG_RANGECHECK 0x100000
1022 #define KDBG_VALCHECK 0x200000 /* Check up to 4 individual values */
1024 #define KDBG_TYPEFILTER_CHECK ((uint32_t) 0x400000) /* Check class and subclass against a bitmap */
1026 #define KDBG_BUFINIT 0x80000000
1028 /* Minimum value allowed when setting decrementer ticks */
1029 #define KDBG_MINRTCDEC 2500
1031 #endif /* __APPLE_API_PRIVATE */
1032 #endif /* PRIVATE */
1034 #endif /* !BSD_SYS_KDEBUG_H */