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