]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/kdebug.h
xnu-2422.1.72.tar.gz
[apple/xnu.git] / bsd / sys / kdebug.h
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 typedef enum
56 {
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.
61 } kd_callback_type;
62 typedef void (*kd_callback_fn) (void* context, kd_callback_type reason, void* arg);
63
64 struct kd_callback {
65 kd_callback_fn func;
66 void* context;
67 char iop_name[8]; // null-terminated string with name of core.
68 };
69
70 typedef struct kd_callback kd_callback_t;
71
72 /*
73 * Registers an IOP for participation in tracing.
74 *
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.
78 *
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.
82 *
83 *
84 * Caveats:
85 * Note that not all callback calls will indicate a change in
86 * state (e.g. disabling trace twice would send two disable
87 * notifications).
88 *
89 */
90 extern int kernel_debug_register_callback(kd_callback_t callback);
91
92 extern void kernel_debug_enter(
93 uint32_t coreid,
94 uint32_t debugid,
95 uint64_t timestamp,
96 uintptr_t arg1,
97 uintptr_t arg2,
98 uintptr_t arg3,
99 uintptr_t arg4,
100 uintptr_t threadid
101 );
102
103
104 /*
105 * state bits for hfs_update event
106 */
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
113
114
115 /*
116 * types of faults that vm_fault handles
117 * and creates trace entries for
118 */
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
129
130
131 /* The debug code consists of the following
132 *
133 * ----------------------------------------------------------------------
134 *| | | |Func |
135 *| Class (8) | SubClass (8) | Code (14) |Qual(2)|
136 * ----------------------------------------------------------------------
137 * The class specifies the higher level
138 */
139
140 /* The Function qualifiers */
141 #define DBG_FUNC_START 1
142 #define DBG_FUNC_END 2
143 #define DBG_FUNC_NONE 0
144
145
146 /* The Kernel Debug Classes */
147 #define DBG_MACH 1
148 #define DBG_NETWORK 2
149 #define DBG_FSYSTEM 3
150 #define DBG_BSD 4
151 #define DBG_IOKIT 5
152 #define DBG_DRIVERS 6
153 #define DBG_TRACE 7
154 #define DBG_DLIL 8
155 #define DBG_SECURITY 9
156 #define DBG_CORESTORAGE 10
157 #define DBG_CG 11
158 #define DBG_MISC 20
159 #define DBG_DYLD 31
160 #define DBG_QT 32
161 #define DBG_APPS 33
162 #define DBG_LAUNCHD 34
163 #define DBG_PERF 37
164 #define DBG_IMPORTANCE 38
165 #define DBG_MIG 255
166
167 /* **** The Kernel Debug Sub Classes for Mach (DBG_MACH) **** */
168 #define DBG_MACH_EXCP_KTRAP_x86 0x02 /* Kernel Traps on x86 */
169 #define DBG_MACH_EXCP_DFLT 0x03 /* Data Translation Fault */
170 #define DBG_MACH_EXCP_IFLT 0x04 /* Inst Translation Fault */
171 #define DBG_MACH_EXCP_INTR 0x05 /* Interrupts */
172 #define DBG_MACH_EXCP_ALNG 0x06 /* Alignment Exception */
173 #define DBG_MACH_EXCP_UTRAP_x86 0x07 /* User Traps on x86 */
174 #define DBG_MACH_EXCP_FP 0x08 /* FP Unavail */
175 #define DBG_MACH_EXCP_DECI 0x09 /* Decrementer Interrupt */
176 #define DBG_MACH_CHUD 0x0A /* CHUD */
177 #define DBG_MACH_EXCP_SC 0x0C /* System Calls */
178 #define DBG_MACH_EXCP_TRACE 0x0D /* Trace exception */
179 #define DBG_MACH_EXCP_EMUL 0x0E /* Instruction emulated */
180 #define DBG_MACH_IHDLR 0x10 /* Interrupt Handlers */
181 #define DBG_MACH_IPC 0x20 /* Inter Process Comm */
182 #define DBG_MACH_VM 0x30 /* Virtual Memory */
183 #define DBG_MACH_LEAKS 0x31 /* alloc/free */
184 #define DBG_MACH_SCHED 0x40 /* Scheduler */
185 #define DBG_MACH_MSGID_INVALID 0x50 /* Messages - invalid */
186 #define DBG_MACH_LOCKS 0x60 /* new lock APIs */
187 #define DBG_MACH_PMAP 0x70 /* pmap */
188 #define DBG_MACH_MP 0x90 /* MP related */
189 #define DBG_MACH_VM_PRESSURE 0xA0 /* Memory Pressure Events */
190 #define DBG_MACH_STACKSHOT 0xA1 /* Stackshot/Microstackshot subsystem */
191
192 /* Codes for Scheduler (DBG_MACH_SCHED) */
193 #define MACH_SCHED 0x0 /* Scheduler */
194 #define MACH_STACK_ATTACH 0x1 /* stack_attach() */
195 #define MACH_STACK_HANDOFF 0x2 /* stack_handoff() */
196 #define MACH_CALL_CONT 0x3 /* call_continuation() */
197 #define MACH_CALLOUT 0x4 /* callouts */
198 #define MACH_STACK_DETACH 0x5
199 #define MACH_MAKE_RUNNABLE 0x6 /* make thread runnable */
200 #define MACH_PROMOTE 0x7 /* promoted due to resource */
201 #define MACH_DEMOTE 0x8 /* promotion undone */
202 #define MACH_IDLE 0x9 /* processor idling */
203 #define MACH_STACK_DEPTH 0xa /* stack depth at switch */
204 #define MACH_MOVED 0xb /* did not use original scheduling decision */
205 #define MACH_FAIRSHARE_ENTER 0xc /* move to fairshare band */
206 #define MACH_FAIRSHARE_EXIT 0xd /* exit fairshare band */
207 #define MACH_FAILSAFE 0xe /* tripped fixed-pri/RT failsafe */
208 #define MACH_BLOCK 0xf /* thread block */
209 #define MACH_WAIT 0x10 /* thread wait assertion */
210 #define MACH_GET_URGENCY 0x14 /* Urgency queried by platform */
211 #define MACH_URGENCY 0x15 /* Urgency (RT/BG/NORMAL) communicated
212 * to platform
213 */
214 #define MACH_REDISPATCH 0x16 /* "next thread" thread redispatched */
215 #define MACH_REMOTE_AST 0x17 /* AST signal issued to remote processor */
216
217 #define MACH_SCHED_CHOOSE_PROCESSOR 0x18 /* Result of choose_processor */
218 #define MACH_DEEP_IDLE 0x19 /* deep idle on master processor */
219 #define MACH_SCHED_DECAY_PRIORITY 0x1a /* timeshare thread priority decayed/restored */
220 #define MACH_CPU_THROTTLE_DISABLE 0x1b /* Global CPU Throttle Disable */
221 #define MACH_RW_PROMOTE 0x1c /* promoted due to RW lock promotion */
222 #define MACH_RW_DEMOTE 0x1d /* promotion due to RW lock undone */
223
224 /* Codes for IPC (DBG_MACH_IPC) */
225 #define MACH_TASK_SUSPEND 0x0 /* Suspended a task */
226 #define MACH_TASK_RESUME 0x1 /* Resumed a task */
227
228 /* Codes for pmap (DBG_MACH_PMAP) */
229 #define PMAP__CREATE 0x0
230 #define PMAP__DESTROY 0x1
231 #define PMAP__PROTECT 0x2
232 #define PMAP__PAGE_PROTECT 0x3
233 #define PMAP__ENTER 0x4
234 #define PMAP__REMOVE 0x5
235 #define PMAP__NEST 0x6
236 #define PMAP__UNNEST 0x7
237 #define PMAP__FLUSH_TLBS 0x8
238 #define PMAP__UPDATE_INTERRUPT 0x9
239 #define PMAP__ATTRIBUTE_CLEAR 0xa
240 #define PMAP__REUSABLE 0xb
241 #define PMAP__QUERY_RESIDENT 0xc
242 #define PMAP__FLUSH_KERN_TLBS 0xd
243 #define PMAP__FLUSH_DELAYED_TLBS 0xe
244
245 /* Codes for Stackshot/Microstackshot (DBG_MACH_STACKSHOT) */
246 #define MICROSTACKSHOT_RECORD 0x0
247 #define MICROSTACKSHOT_GATHER 0x1
248
249 /* **** The Kernel Debug Sub Classes for Network (DBG_NETWORK) **** */
250 #define DBG_NETIP 1 /* Internet Protocol */
251 #define DBG_NETARP 2 /* Address Resolution Protocol */
252 #define DBG_NETUDP 3 /* User Datagram Protocol */
253 #define DBG_NETTCP 4 /* Transmission Control Protocol */
254 #define DBG_NETICMP 5 /* Internet Control Message Protocol */
255 #define DBG_NETIGMP 6 /* Internet Group Management Protocol */
256 #define DBG_NETRIP 7 /* Routing Information Protocol */
257 #define DBG_NETOSPF 8 /* Open Shortest Path First */
258 #define DBG_NETISIS 9 /* Intermediate System to Intermediate System */
259 #define DBG_NETSNMP 10 /* Simple Network Management Protocol */
260 #define DBG_NETSOCK 11 /* Socket Layer */
261
262 /* For Apple talk */
263 #define DBG_NETAARP 100 /* Apple ARP */
264 #define DBG_NETDDP 101 /* Datagram Delivery Protocol */
265 #define DBG_NETNBP 102 /* Name Binding Protocol */
266 #define DBG_NETZIP 103 /* Zone Information Protocol */
267 #define DBG_NETADSP 104 /* Name Binding Protocol */
268 #define DBG_NETATP 105 /* Apple Transaction Protocol */
269 #define DBG_NETASP 106 /* Apple Session Protocol */
270 #define DBG_NETAFP 107 /* Apple Filing Protocol */
271 #define DBG_NETRTMP 108 /* Routing Table Maintenance Protocol */
272 #define DBG_NETAURP 109 /* Apple Update Routing Protocol */
273 #define DBG_NETIPSEC 128 /* IPsec Protocol */
274
275 /* **** The Kernel Debug Sub Classes for IOKIT (DBG_IOKIT) **** */
276 #define DBG_IOINTC 0 /* Interrupt controller */
277 #define DBG_IOWORKLOOP 1 /* Work from work loop */
278 #define DBG_IOINTES 2 /* Interrupt event source */
279 #define DBG_IOCLKES 3 /* Clock event source */
280 #define DBG_IOCMDQ 4 /* Command queue latencies */
281 #define DBG_IOMCURS 5 /* Memory Cursor */
282 #define DBG_IOMDESC 6 /* Memory Descriptors */
283 #define DBG_IOPOWER 7 /* Power Managerment */
284 #define DBG_IOSERVICE 8 /* Matching etc. */
285
286 /* **** 9-32 reserved for internal IOKit usage **** */
287
288 #define DBG_IOSTORAGE 32 /* Storage layers */
289 #define DBG_IONETWORK 33 /* Network layers */
290 #define DBG_IOKEYBOARD 34 /* Keyboard */
291 #define DBG_IOHID 35 /* HID Devices */
292 #define DBG_IOAUDIO 36 /* Audio */
293 #define DBG_IOSERIAL 37 /* Serial */
294 #define DBG_IOTTY 38 /* TTY layers */
295 #define DBG_IOSAM 39 /* SCSI Architecture Model layers */
296 #define DBG_IOPARALLELATA 40 /* Parallel ATA */
297 #define DBG_IOPARALLELSCSI 41 /* Parallel SCSI */
298 #define DBG_IOSATA 42 /* Serial-ATA */
299 #define DBG_IOSAS 43 /* SAS */
300 #define DBG_IOFIBRECHANNEL 44 /* FiberChannel */
301 #define DBG_IOUSB 45 /* USB */
302 #define DBG_IOBLUETOOTH 46 /* Bluetooth */
303 #define DBG_IOFIREWIRE 47 /* FireWire */
304 #define DBG_IOINFINIBAND 48 /* Infiniband */
305 #define DBG_IOCPUPM 49 /* CPU Power Management */
306 #define DBG_IOGRAPHICS 50 /* Graphics */
307 #define DBG_HIBERNATE 51 /* hibernation related events */
308 #define DBG_IOTHUNDERBOLT 52 /* Thunderbolt */
309
310
311 /* Backwards compatibility */
312 #define DBG_IOPOINTING DBG_IOHID /* OBSOLETE: Use DBG_IOHID instead */
313 #define DBG_IODISK DBG_IOSTORAGE /* OBSOLETE: Use DBG_IOSTORAGE instead */
314
315 /* **** The Kernel Debug Sub Classes for Device Drivers (DBG_DRIVERS) **** */
316 #define DBG_DRVSTORAGE 1 /* Storage layers */
317 #define DBG_DRVNETWORK 2 /* Network layers */
318 #define DBG_DRVKEYBOARD 3 /* Keyboard */
319 #define DBG_DRVHID 4 /* HID Devices */
320 #define DBG_DRVAUDIO 5 /* Audio */
321 #define DBG_DRVSERIAL 7 /* Serial */
322 #define DBG_DRVSAM 8 /* SCSI Architecture Model layers */
323 #define DBG_DRVPARALLELATA 9 /* Parallel ATA */
324 #define DBG_DRVPARALLELSCSI 10 /* Parallel SCSI */
325 #define DBG_DRVSATA 11 /* Serial ATA */
326 #define DBG_DRVSAS 12 /* SAS */
327 #define DBG_DRVFIBRECHANNEL 13 /* FiberChannel */
328 #define DBG_DRVUSB 14 /* USB */
329 #define DBG_DRVBLUETOOTH 15 /* Bluetooth */
330 #define DBG_DRVFIREWIRE 16 /* FireWire */
331 #define DBG_DRVINFINIBAND 17 /* Infiniband */
332 #define DBG_DRVGRAPHICS 18 /* Graphics */
333 #define DBG_DRVSD 19 /* Secure Digital */
334 #define DBG_DRVNAND 20 /* NAND drivers and layers */
335 #define DBG_SSD 21 /* SSD */
336 #define DBG_DRVSPI 22 /* SPI */
337
338 /* Backwards compatibility */
339 #define DBG_DRVPOINTING DBG_DRVHID /* OBSOLETE: Use DBG_DRVHID instead */
340 #define DBG_DRVDISK DBG_DRVSTORAGE /* OBSOLETE: Use DBG_DRVSTORAGE instead */
341
342 /* **** The Kernel Debug Sub Classes for the DLIL Layer (DBG_DLIL) **** */
343 #define DBG_DLIL_STATIC 1 /* Static DLIL code */
344 #define DBG_DLIL_PR_MOD 2 /* DLIL Protocol Module */
345 #define DBG_DLIL_IF_MOD 3 /* DLIL Interface Module */
346 #define DBG_DLIL_PR_FLT 4 /* DLIL Protocol Filter */
347 #define DBG_DLIL_IF_FLT 5 /* DLIL Interface FIlter */
348
349 /* The Kernel Debug Sub Classes for File System (DBG_FSYSTEM) */
350 #define DBG_FSRW 1 /* reads and writes to the filesystem */
351 #define DBG_DKRW 2 /* reads and writes to the disk */
352 #define DBG_FSVN 3 /* vnode operations (inc. locking/unlocking) */
353 #define DBG_FSLOOOKUP 4 /* namei and other lookup-related operations */
354 #define DBG_JOURNAL 5 /* journaling operations */
355 #define DBG_IOCTL 6 /* ioctl to the disk */
356 #define DBG_BOOTCACHE 7 /* bootcache operations */
357 #define DBG_HFS 8 /* HFS-specific events; see bsd/hfs/hfs_kdebug.h */
358 #define DBG_EXFAT 0xE /* ExFAT-specific events; see the exfat project */
359 #define DBG_MSDOS 0xF /* FAT-specific events; see the msdosfs project */
360 #define DBG_ACFS 0x10 /* Xsan-specific events; see the XsanFS project */
361 #define DBG_THROTTLE 0x11 /* I/O Throttling events */
362
363 /* The Kernel Debug Sub Classes for BSD */
364 #define DBG_BSD_PROC 0x01 /* process/signals related */
365 #define DBG_BSD_MEMSTAT 0x02 /* memorystatus / jetsam operations */
366 #define DBG_BSD_EXCP_SC 0x0C /* System Calls */
367 #define DBG_BSD_AIO 0x0D /* aio (POSIX async IO) */
368 #define DBG_BSD_SC_EXTENDED_INFO 0x0E /* System Calls, extended info */
369 #define DBG_BSD_SC_EXTENDED_INFO2 0x0F /* System Calls, extended info */
370
371
372 /* The Codes for BSD subcode class DBG_BSD_PROC */
373 #define BSD_PROC_EXIT 1 /* process exit */
374 #define BSD_PROC_FRCEXIT 2 /* Kernel force termination */
375
376 /* Codes for BSD subcode class DBG_BSD_MEMSTAT */
377 #define BSD_MEMSTAT_SCAN 1 /* memorystatus thread awake */
378 #define BSD_MEMSTAT_JETSAM 2 /* LRU jetsam */
379 #define BSD_MEMSTAT_JETSAM_HIWAT 3 /* highwater jetsam */
380 #define BSD_MEMSTAT_FREEZE 4 /* freeze process */
381 #define BSD_MEMSTAT_LATENCY_COALESCE 5 /* delay imposed to coalesce jetsam reports */
382 #define BSD_MEMSTAT_UPDATE 6 /* priority update */
383 #define BSD_MEMSTAT_IDLE_DEMOTE 7 /* idle demotion fired */
384 #define BSD_MEMSTAT_CLEAR_ERRORS 8 /* reset termination error state */
385
386 /* The Kernel Debug Sub Classes for DBG_TRACE */
387 #define DBG_TRACE_DATA 0
388 #define DBG_TRACE_STRING 1
389 #define DBG_TRACE_INFO 2
390
391 /* The Kernel Debug Sub Classes for DBG_CORESTORAGE */
392 #define DBG_CS_IO 0
393
394 /* Sub-class codes for CoreGraphics (DBG_CG) are defined in its component. */
395
396 /* The Kernel Debug Sub Classes for DBG_MISC */
397 #define DBG_EVENT 0x10
398 #define DBG_BUFFER 0x20
399
400 /* The Kernel Debug Sub Classes for DBG_DYLD */
401 #define DBG_DYLD_STRING 5
402
403 /* The Kernel Debug modifiers for the DBG_DKRW sub class */
404 #define DKIO_DONE 0x01
405 #define DKIO_READ 0x02
406 #define DKIO_ASYNC 0x04
407 #define DKIO_META 0x08
408 #define DKIO_PAGING 0x10
409 #define DKIO_THROTTLE 0x20 /* Deprecated, still provided so fs_usage doesn't break */
410 #define DKIO_PASSIVE 0x40
411 #define DKIO_NOCACHE 0x80
412 #define DKIO_TIER_MASK 0xF00
413 #define DKIO_TIER_SHIFT 8
414
415 /* Kernel Debug Sub Classes for Applications (DBG_APPS) */
416 #define DBG_APP_LOGINWINDOW 0x03
417 #define DBG_APP_AUDIO 0x04
418 #define DBG_APP_SAMBA 0x80
419
420 /* Kernel Debug codes for Throttling (DBG_THROTTLE) */
421 #define OPEN_THROTTLE_WINDOW 0x1
422 #define PROCESS_THROTTLED 0x2
423 #define IO_THROTTLE_DISABLE 0x3
424
425
426 /* Subclasses for MACH Importance Policies (DBG_IMPORTANCE) */
427 /* TODO: Split up boost and task policy? */
428 #define IMP_ASSERTION 0x10 /* Task takes/drops a boost assertion */
429 #define IMP_BOOST 0x11 /* Task boost level changed */
430 #define IMP_MSG 0x12 /* boosting message sent by donating task on donating port */
431 #define IMP_WATCHPORT 0x13 /* port marked as watchport, and boost was transferred to the watched task */
432 #define IMP_TASK_SUPPRESSION 0x17 /* Task changed suppression behaviors */
433 #define IMP_TASK_APPTYPE 0x18 /* Task launched with apptype */
434 #define IMP_UPDATE 0x19 /* Requested -> effective calculation */
435 /* DBG_IMPORTANCE subclasses 0x20 - 0x3F reserved for task policy flavors */
436
437 /* Codes for IMP_ASSERTION */
438 #define IMP_HOLD 0x2 /* Task holds a boost assertion */
439 #define IMP_DROP 0x4 /* Task drops a boost assertion */
440 #define IMP_EXTERN 0x8 /* boost assertion moved from kernel to userspace responsibility (externalized) */
441
442 /* Codes for IMP_BOOST */
443 #define IMP_BOOSTED 0x1
444 #define IMP_UNBOOSTED 0x2 /* Task drops a boost assertion */
445
446 /* Codes for IMP_MSG */
447 #define IMP_MSG_SEND 0x1 /* boosting message sent by donating task on donating port */
448 #define IMP_MSG_DELV 0x2 /* boosting message delivered to task */
449
450 /* Codes for IMP_UPDATE */
451 #define IMP_UPDATE_TASK_CREATE 0x1
452
453 /**********************************************************************/
454
455 #define KDBG_CODE(Class, SubClass, code) (((Class & 0xff) << 24) | ((SubClass & 0xff) << 16) | ((code & 0x3fff) << 2))
456
457 #define KDBG_MIGCODE(msgid) ((DBG_MIG << 24) | (((msgid) & 0x3fffff) << 2))
458
459 #define MACHDBG_CODE(SubClass, code) KDBG_CODE(DBG_MACH, SubClass, code)
460 #define NETDBG_CODE(SubClass, code) KDBG_CODE(DBG_NETWORK, SubClass, code)
461 #define FSDBG_CODE(SubClass, code) KDBG_CODE(DBG_FSYSTEM, SubClass, code)
462 #define BSDDBG_CODE(SubClass, code) KDBG_CODE(DBG_BSD, SubClass, code)
463 #define IOKDBG_CODE(SubClass, code) KDBG_CODE(DBG_IOKIT, SubClass, code)
464 #define DRVDBG_CODE(SubClass, code) KDBG_CODE(DBG_DRIVERS, SubClass, code)
465 #define TRACEDBG_CODE(SubClass,code) KDBG_CODE(DBG_TRACE, SubClass, code)
466 #define MISCDBG_CODE(SubClass,code) KDBG_CODE(DBG_MISC, SubClass, code)
467 #define DLILDBG_CODE(SubClass,code) KDBG_CODE(DBG_DLIL, SubClass, code)
468 #define SECURITYDBG_CODE(SubClass,code) KDBG_CODE(DBG_SECURITY, SubClass, code)
469 #define DYLDDBG_CODE(SubClass,code) KDBG_CODE(DBG_DYLD, SubClass, code)
470 #define QTDBG_CODE(SubClass,code) KDBG_CODE(DBG_QT, SubClass, code)
471 #define APPSDBG_CODE(SubClass,code) KDBG_CODE(DBG_APPS, SubClass, code)
472 #define CPUPM_CODE(code) IOKDBG_CODE(DBG_IOCPUPM, code)
473
474 #define KMEM_ALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 0)
475 #define KMEM_ALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 1)
476 #define KMEM_FREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 2)
477 #define KMEM_FREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 3)
478 #define ZALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 4)
479 #define ZALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 5)
480 #define ZFREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 6)
481 #define ZFREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 7)
482
483 #define PMAP_CODE(code) MACHDBG_CODE(DBG_MACH_PMAP, code)
484
485
486 #define IMPORTANCE_CODE(SubClass, code) KDBG_CODE(DBG_IMPORTANCE, (SubClass), (code))
487
488 /* Usage:
489 * kernel_debug((KDBG_CODE(DBG_NETWORK, DNET_PROTOCOL, 51) | DBG_FUNC_START),
490 * offset, 0, 0, 0,0)
491 *
492 * For ex,
493 *
494 * #include <sys/kdebug.h>
495 *
496 * #define DBG_NETIPINIT NETDBG_CODE(DBG_NETIP,1)
497 *
498 *
499 * void
500 * ip_init()
501 * {
502 * register struct protosw *pr;
503 * register int i;
504 *
505 * KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_START, 0,0,0,0,0)
506 * --------
507 * KERNEL_DEBUG(DBG_NETIPINIT, 0,0,0,0,0)
508 * --------
509 * KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_END, 0,0,0,0,0)
510 * }
511 *
512
513 */
514
515 extern unsigned int kdebug_enable;
516 #define KDEBUG_ENABLE_TRACE 0x1
517 #define KDEBUG_ENABLE_ENTROPY 0x2
518 #define KDEBUG_ENABLE_CHUD 0x4
519 #define KDEBUG_ENABLE_PPT 0x8
520
521 /*
522 * Infer the supported kernel debug event level from config option.
523 * Use (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) as a guard to protect
524 * unaudited debug code.
525 */
526 #define KDEBUG_LEVEL_NONE 0
527 #define KDEBUG_LEVEL_IST 1
528 #define KDEBUG_LEVEL_STANDARD 2
529 #define KDEBUG_LEVEL_FULL 3
530
531 #if NO_KDEBUG
532 #define KDEBUG_LEVEL KDEBUG_LEVEL_NONE
533 #elif IST_KDEBUG
534 #define KDEBUG_LEVEL KDEBUG_LEVEL_IST
535 #elif KDEBUG
536 #define KDEBUG_LEVEL KDEBUG_LEVEL_FULL
537 #else
538 #define KDEBUG_LEVEL KDEBUG_LEVEL_STANDARD
539 #endif
540
541 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
542 #ifdef XNU_KERNEL_PRIVATE
543 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \
544 do { \
545 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
546 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
547 (uintptr_t)d,(uintptr_t)e); \
548 } while(0)
549
550 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \
551 do { \
552 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
553 kernel_debug1(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
554 (uintptr_t)d,(uintptr_t)e); \
555 } while(0)
556 #else /* XNU_KERNEL_PRIVATE */
557 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \
558 do { \
559 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
560 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
561 (uintptr_t)d,(uintptr_t)e); \
562 } while(0)
563
564 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \
565 do { \
566 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
567 kernel_debug1(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
568 (uintptr_t)d,(uintptr_t)e); \
569 } while(0)
570 #endif /* XNU_KERNEL_PRIVATE */
571 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
572 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) do { } while(0)
573 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) do { } while(0)
574 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
575
576 /*
577 * Specify KDEBUG_PPT to indicate that the event belongs to the
578 * limited PPT set.
579 */
580 #define KDEBUG_COMMON (KDEBUG_ENABLE_TRACE|KDEBUG_ENABLE_ENTROPY|KDEBUG_ENABLE_CHUD|KDEBUG_ENABLE_PPT)
581 #define KDEBUG_TRACE (KDEBUG_ENABLE_TRACE|KDEBUG_ENABLE_ENTROPY|KDEBUG_ENABLE_CHUD)
582 #define KDEBUG_PPT (KDEBUG_ENABLE_PPT)
583
584 /*
585 * KERNEL_DEBUG_CONSTANT_IST events provide an audited subset of
586 * tracepoints for userland system tracing tools.
587 */
588 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST)
589 #ifdef XNU_KERNEL_PRIVATE
590 #define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) \
591 do { \
592 if (__improbable(kdebug_enable & type)) \
593 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
594 (uintptr_t)d,(uintptr_t)e); \
595 } while(0)
596 #else /* XNU_KERNEL_PRIVATE */
597 #define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) \
598 do { \
599 if (kdebug_enable & type) \
600 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
601 (uintptr_t)d,(uintptr_t)e); \
602 } while(0)
603 #endif /* XNU_KERNEL_PRIVATE */
604 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
605 #define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) do { } while(0)
606 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
607
608 #if NO_KDEBUG
609 #define __kdebug_constant_only __unused
610 #endif
611
612 extern void kernel_debug(
613 uint32_t debugid,
614 uintptr_t arg1,
615 uintptr_t arg2,
616 uintptr_t arg3,
617 uintptr_t arg4,
618 uintptr_t arg5);
619
620 extern void kernel_debug1(
621 uint32_t debugid,
622 uintptr_t arg1,
623 uintptr_t arg2,
624 uintptr_t arg3,
625 uintptr_t arg4,
626 uintptr_t arg5);
627
628
629 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL)
630 #ifdef XNU_KERNEL_PRIVATE
631 #define KERNEL_DEBUG(x,a,b,c,d,e) \
632 do { \
633 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
634 kernel_debug((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
635 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
636 } while(0)
637
638 #define KERNEL_DEBUG1(x,a,b,c,d,e) \
639 do { \
640 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
641 kernel_debug1((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
642 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
643 } while(0)
644
645 #define __kdebug_only
646 #else /* !XNU_KERNEL_PRIVATE */
647 #define KERNEL_DEBUG(x,a,b,c,d,e) \
648 do { \
649 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
650 kernel_debug((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
651 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
652 } while(0)
653
654 #define KERNEL_DEBUG1(x,a,b,c,d,e) \
655 do { \
656 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
657 kernel_debug1((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
658 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
659 } while(0)
660 #endif /* XNU_KERNEL_PRIVATE */
661 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
662 #define KERNEL_DEBUG(x,a,b,c,d,e) do {} while (0)
663 #define KERNEL_DEBUG1(x,a,b,c,d,e) do {} while (0)
664
665 #define __kdebug_only __unused
666 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
667
668 #ifdef KERNEL_PRIVATE
669 #include <mach/boolean.h>
670
671 #define NUMPARMS 23
672
673 struct proc;
674
675 extern void kdebug_lookup_gen_events(long *dbg_parms, int dbg_namelen, void *dp, boolean_t lookup);
676 extern void kdbg_trace_data(struct proc *proc, long *arg_pid);
677
678 extern void kdbg_trace_string(struct proc *proc, long *arg1, long *arg2, long *arg3, long *arg4);
679
680 extern void kdbg_dump_trace_to_file(const char *);
681 void start_kern_tracing(unsigned int, boolean_t);
682 struct task;
683 extern void kdbg_get_task_name(char*, int, struct task *task);
684 void disable_wrap(uint32_t *old_slowcheck, uint32_t *old_flags);
685 void enable_wrap(uint32_t old_slowcheck, boolean_t lostevents);
686 void release_storage_unit(int cpu, uint32_t storage_unit);
687 int allocate_storage_unit(int cpu);
688
689 #define KDBG_CLASS_ENCODE(Class, SubClass) (((Class & 0xff) << 24) | ((SubClass & 0xff) << 16))
690 #define KDBG_CLASS_DECODE(Debugid) (Debugid & 0xFFFF0000)
691
692
693 #endif /* KERNEL_PRIVATE */
694
695
696 #endif /* __APPLE_API_UNSTABLE */
697 __END_DECLS
698
699
700 #ifdef PRIVATE
701 #ifdef __APPLE_API_PRIVATE
702 /*
703 * private kernel_debug definitions
704 */
705
706 typedef struct {
707 uint64_t timestamp;
708 uintptr_t arg1;
709 uintptr_t arg2;
710 uintptr_t arg3;
711 uintptr_t arg4;
712 uintptr_t arg5; /* will hold current thread */
713 uint32_t debugid;
714 #if defined(__LP64__)
715 uint32_t cpuid;
716 uintptr_t unused;
717 #endif
718 } kd_buf;
719
720 #if !defined(__LP64__)
721 #define KDBG_TIMESTAMP_MASK 0x00ffffffffffffffULL
722 #define KDBG_CPU_MASK 0xff00000000000000ULL
723 #define KDBG_CPU_SHIFT 56
724 static inline void
725 kdbg_set_cpu(kd_buf *kp, int cpu)
726 {
727 kp->timestamp = (kp->timestamp & KDBG_TIMESTAMP_MASK) |
728 (((uint64_t) cpu) << KDBG_CPU_SHIFT);
729 }
730 static inline int
731 kdbg_get_cpu(kd_buf *kp)
732 {
733 return (int) (((kp)->timestamp & KDBG_CPU_MASK) >> KDBG_CPU_SHIFT);
734 }
735 static inline void
736 kdbg_set_timestamp(kd_buf *kp, uint64_t thetime)
737 {
738 kp->timestamp = thetime & KDBG_TIMESTAMP_MASK;
739 }
740 static inline uint64_t
741 kdbg_get_timestamp(kd_buf *kp)
742 {
743 return kp->timestamp & KDBG_TIMESTAMP_MASK;
744 }
745 static inline void
746 kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu)
747 {
748 kp->timestamp = (thetime & KDBG_TIMESTAMP_MASK) |
749 (((uint64_t) cpu) << KDBG_CPU_SHIFT);
750 }
751 #else
752 #define KDBG_TIMESTAMP_MASK 0xffffffffffffffffULL
753 static inline void
754 kdbg_set_cpu(kd_buf *kp, int cpu)
755 {
756 kp->cpuid = cpu;
757 }
758 static inline int
759 kdbg_get_cpu(kd_buf *kp)
760 {
761 return kp->cpuid;
762 }
763 static inline void
764 kdbg_set_timestamp(kd_buf *kp, uint64_t thetime)
765 {
766 kp->timestamp = thetime;
767 }
768 static inline uint64_t
769 kdbg_get_timestamp(kd_buf *kp)
770 {
771 return kp->timestamp;
772 }
773 static inline void
774 kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu)
775 {
776 kdbg_set_timestamp(kp, thetime);
777 kdbg_set_cpu(kp, cpu);
778 }
779 #endif
780
781 /* 2^16 bits (8 kilobytes), one for each possible class/subclass combination */
782 #define KDBG_TYPEFILTER_BITMAP_SIZE ( (256 * 256) / 8 )
783
784 /* Debug Flags */
785 #define KDBG_INIT 0x001
786 #define KDBG_NOWRAP 0x002
787 #define KDBG_FREERUN 0x004
788 #define KDBG_WRAPPED 0x008
789 #define KDBG_USERFLAGS (KDBG_FREERUN|KDBG_NOWRAP|KDBG_INIT)
790 #define KDBG_PIDCHECK 0x010
791 #define KDBG_MAPINIT 0x020
792 #define KDBG_PIDEXCLUDE 0x040
793 #define KDBG_LOCKINIT 0x080
794 #define KDBG_LP64 0x100
795
796 typedef struct {
797 unsigned int type;
798 unsigned int value1;
799 unsigned int value2;
800 unsigned int value3;
801 unsigned int value4;
802
803 } kd_regtype;
804
805 typedef struct
806 {
807 int nkdbufs;
808 int nolog;
809 int flags;
810 int nkdthreads;
811 int bufid;
812 } kbufinfo_t;
813
814 typedef struct {
815 uintptr_t thread;
816 int valid;
817 char command[20];
818 } kd_threadmap;
819
820 typedef struct {
821 uint32_t version_no;
822 uint32_t cpu_count;
823 } kd_cpumap_header;
824
825 /* cpumap flags */
826 #define KDBG_CPUMAP_IS_IOP 0x1
827
828 typedef struct {
829 uint32_t cpu_id;
830 uint32_t flags;
831 char name[8];
832 } kd_cpumap;
833
834 /*
835 * TRACE file formats...
836 *
837 * RAW_VERSION0
838 *
839 * uint32_t #threadmaps
840 * kd_threadmap[]
841 * kd_buf[]
842 *
843 * RAW_VERSION1
844 *
845 * RAW_header, with version_no set to RAW_VERSION1
846 * kd_threadmap[]
847 * Empty space to pad alignment to the nearest page boundary.
848 * kd_buf[]
849 *
850 * RAW_VERSION1+
851 *
852 * RAW_header, with version_no set to RAW_VERSION1
853 * kd_threadmap[]
854 * kd_cpumap_header, with version_no set to RAW_VERSION1
855 * kd_cpumap[]
856 * Empty space to pad alignment to the nearest page boundary.
857 * kd_buf[]
858 *
859 * V1+ implementation details...
860 *
861 * It would have been nice to add the cpumap data "correctly", but there were
862 * several obstacles. Existing code attempts to parse both V1 and V0 files.
863 * Due to the fact that V0 has no versioning or header, the test looks like
864 * this:
865 *
866 * // Read header
867 * if (header.version_no != RAW_VERSION1) { // Assume V0 }
868 *
869 * If we add a VERSION2 file format, all existing code is going to treat that
870 * as a VERSION0 file when reading it, and crash terribly when trying to read
871 * RAW_VERSION2 threadmap entries.
872 *
873 * To differentiate between a V1 and V1+ file, read as V1 until you reach
874 * the padding bytes. Then:
875 *
876 * boolean_t is_v1plus = FALSE;
877 * if (padding_bytes >= sizeof(kd_cpumap_header)) {
878 * kd_cpumap_header header = // read header;
879 * if (header.version_no == RAW_VERSION1) {
880 * is_v1plus = TRUE;
881 * }
882 * }
883 *
884 */
885
886 typedef struct {
887 int version_no;
888 int thread_count;
889 uint64_t TOD_secs;
890 uint32_t TOD_usecs;
891 } RAW_header;
892
893 #define RAW_VERSION0 0x55aa0000
894 #define RAW_VERSION1 0x55aa0101
895
896 #define KDBG_CLASSTYPE 0x10000
897 #define KDBG_SUBCLSTYPE 0x20000
898 #define KDBG_RANGETYPE 0x40000
899 #define KDBG_TYPENONE 0x80000
900 #define KDBG_CKTYPES 0xF0000
901
902 #define KDBG_RANGECHECK 0x100000
903 #define KDBG_VALCHECK 0x200000 /* Check up to 4 individual values */
904
905 #define KDBG_TYPEFILTER_CHECK ((uint32_t) 0x400000) /* Check class and subclass against a bitmap */
906
907 #define KDBG_BUFINIT 0x80000000
908
909 /* Minimum value allowed when setting decrementer ticks */
910 #define KDBG_MINRTCDEC 2500
911
912 #endif /* __APPLE_API_PRIVATE */
913 #endif /* PRIVATE */
914
915 #endif /* !BSD_SYS_KDEBUG_H */