]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/kdebug.h
xnu-3789.41.3.tar.gz
[apple/xnu.git] / bsd / sys / kdebug.h
CommitLineData
1c79356b 1/*
39037602 2 * Copyright (c) 2000-2016 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
3e170ce0 5 *
2d21ac55
A
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.
3e170ce0 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
3e170ce0 17 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
3e170ce0 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28
39037602
A
29/*
30 * kdebug.h - kernel_debug definitions
1c79356b
A
31 */
32
33#ifndef BSD_SYS_KDEBUG_H
34#define BSD_SYS_KDEBUG_H
35
9bccf70c 36#include <sys/appleapiopts.h>
1c79356b
A
37#include <sys/cdefs.h>
38__BEGIN_DECLS
39
9bccf70c
A
40#ifdef __APPLE_API_UNSTABLE
41
1c79356b 42#include <mach/clock_types.h>
55e303ae 43#include <stdint.h>
a1c7dba1
A
44
45#ifndef KERNEL
46#include <Availability.h>
47#endif
1c79356b 48
39037602
A
49#ifdef XNU_KERNEL_PRIVATE
50#include <mach/branch_predicates.h> /* __improbable */
6d2010ae
A
51#endif
52
3e170ce0
A
53/*
54 * Kdebug is a facility for tracing events occurring on a system.
55 *
39037602 56 * All events are tagged with a 32-bit debugid:
3e170ce0
A
57 *
58 * +----------------+----------------+----------------------------+----+
59 * | Class (8) | Subclass (8) | Code (14) |Func|
60 * | | | |(2) |
61 * +----------------+----------------+----------------------------+----+
39037602
A
62 * \_________________________________/
63 * ClassSubclass (CSC)
64 * \________________________________________________________________00_/
65 * Eventid
3e170ce0
A
66 * \___________________________________________________________________/
67 * Debugid
68 *
69 * The eventid is a hierarchical ID, indicating which components an event is
70 * referring to. The debugid includes an eventid and two function qualifier
71 * bits, to determine the structural significance of an event (whether it
39037602 72 * starts or ends an interval).
3e170ce0
A
73 */
74
75#define KDBG_CLASS_MASK (0xff000000)
76#define KDBG_CLASS_OFFSET (24)
77#define KDBG_CLASS_MAX (0xff)
78
79#define KDBG_SUBCLASS_MASK (0x00ff0000)
80#define KDBG_SUBCLASS_OFFSET (16)
81#define KDBG_SUBCLASS_MAX (0xff)
82
83/* class and subclass mask */
84#define KDBG_CSC_MASK (0xffff0000)
85#define KDBG_CSC_OFFSET (KDBG_SUBCLASS_OFFSET)
39037602 86#define KDBG_CSC_MAX (0xffff)
3e170ce0
A
87
88#define KDBG_CODE_MASK (0x0000fffc)
89#define KDBG_CODE_OFFSET (2)
90#define KDBG_CODE_MAX (0x3fff)
91
92#define KDBG_EVENTID_MASK (0xfffffffc)
39037602 93#define KDBG_FUNC_MASK (0x00000003)
3e170ce0
A
94
95/* Generate an eventid corresponding to Class, SubClass, and Code. */
96#define KDBG_EVENTID(Class, SubClass, Code) \
97 ((((Class) & 0xff) << KDBG_CLASS_OFFSET) | \
98 (((SubClass) & 0xff) << KDBG_SUBCLASS_OFFSET) | \
99 (((Code) & 0x3fff) << KDBG_CODE_OFFSET))
100/* Deprecated macro using old naming convention. */
101#define KDBG_CODE(Class, SubClass, Code) \
102 KDBG_EVENTID(Class, SubClass, Code)
103
104/* Extract pieces of the debug code. */
105#define KDBG_EXTRACT_CLASS(Debugid) \
106 ((uint8_t)(((Debugid) & KDBG_CLASS_MASK) >> KDBG_CLASS_OFFSET))
107#define KDBG_EXTRACT_SUBCLASS(Debugid) \
108 ((uint8_t)(((Debugid) & KDBG_SUBCLASS_MASK) >> KDBG_SUBCLASS_OFFSET))
109#define KDBG_EXTRACT_CSC(Debugid) \
110 ((uint16_t)(((Debugid) & KDBG_CSC_MASK) >> KDBG_CSC_OFFSET))
111#define KDBG_EXTRACT_CODE(Debugid) \
112 ((uint16_t)(((Debugid) & KDBG_CODE_MASK) >> KDBG_CODE_OFFSET))
113
39037602
A
114/* function qualifiers */
115#define DBG_FUNC_START 1
116#define DBG_FUNC_END 2
117#define DBG_FUNC_NONE 0
118
119/*
120 * Definitions to support IOP tracing.
121 */
122
a1c7dba1
A
123#ifdef KERNEL_PRIVATE
124
39037602
A
125typedef enum {
126 /* Trace is now enabled; no arguments. */
127 KD_CALLBACK_KDEBUG_ENABLED,
128 /* Trace is now disabled; no arguments. */
129 KD_CALLBACK_KDEBUG_DISABLED,
130 /*
131 * Request the latest entries from the IOP and block until complete; no
132 * arguments.
133 */
134 KD_CALLBACK_SYNC_FLUSH,
135 /*
136 * The typefilter is enabled; a read-only pointer to the typefilter is
137 * provided, valid only while in the callback.
138 */
139 KD_CALLBACK_TYPEFILTER_CHANGED,
39236c6e
A
140} kd_callback_type;
141typedef void (*kd_callback_fn) (void* context, kd_callback_type reason, void* arg);
142
143struct kd_callback {
39037602
A
144 kd_callback_fn func;
145 void *context;
146 /* name of IOP, NUL-terminated */
147 char iop_name[8];
39236c6e
A
148};
149
150typedef struct kd_callback kd_callback_t;
151
152/*
3e170ce0
A
153 * Registers an IOP for participation in tracing.
154 *
155 * The registered callback function will be called with the
156 * supplied context as the first argument, followed by a
157 * kd_callback_type and an associated void* argument.
158 *
159 * The return value is a nonzero coreid that shall be used in
160 * kernel_debug_enter() to refer to your IOP. If the allocation
161 * failed, then 0 will be returned.
162 *
3e170ce0
A
163 * Caveats:
164 * Note that not all callback calls will indicate a change in
165 * state (e.g. disabling trace twice would send two disable
166 * notifications).
39236c6e
A
167 */
168extern int kernel_debug_register_callback(kd_callback_t callback);
169
170extern void kernel_debug_enter(
39037602
A
171 uint32_t coreid,
172 uint32_t debugid,
173 uint64_t timestamp,
174 uintptr_t arg1,
175 uintptr_t arg2,
176 uintptr_t arg3,
177 uintptr_t arg4,
178 uintptr_t threadid
39236c6e
A
179 );
180
a1c7dba1 181#endif /* KERNEL_PRIVATE */
1c79356b 182
1c79356b 183/* The Kernel Debug Classes */
39037602
A
184#define DBG_MACH 1
185#define DBG_NETWORK 2
186#define DBG_FSYSTEM 3
187#define DBG_BSD 4
188#define DBG_IOKIT 5
189#define DBG_DRIVERS 6
190#define DBG_TRACE 7
191#define DBG_DLIL 8
192#define DBG_WORKQUEUE 9
193#define DBG_CORESTORAGE 10
194#define DBG_CG 11
195#define DBG_MISC 20
196#define DBG_SECURITY 30
197#define DBG_DYLD 31
198#define DBG_QT 32
199#define DBG_APPS 33
200#define DBG_LAUNCHD 34
201#define DBG_PERF 37
202#define DBG_IMPORTANCE 38
203#define DBG_BANK 40
204#define DBG_XPC 41
205#define DBG_ATM 42
206#define DBG_ARIADNE 43
207#define DBG_DAEMON 44
208#define DBG_ENERGYTRACE 45
209#define DBG_DISPATCH 46
210#define DBG_IMG 49
211#define DBG_UMALLOC 51
212
213
214#define DBG_MIG 255
1c79356b 215
a1c7dba1 216#ifdef PRIVATE
39037602
A
217
218/*
219 * Private kdebug userspace API
220 */
221#ifndef KERNEL
222#include <stdbool.h>
223
a1c7dba1
A
224/*
225 * OS components can use the full precision of the "code" field
226 * (Class, SubClass, Code) to inject events using kdebug_trace() by
227 * using:
228 *
229 * kdebug_trace(KDBG_CODE(DBG_XPC, 15, 1) | DBG_FUNC_NONE, 1, 2, 3, 4);
230 *
231 * These trace points can be included in production code, since they
232 * use reserved, non-overlapping ranges. The performance impact when
233 * kernel tracing is not enabled is minimal. Classes can be reserved
234 * by filing a Radar in xnu|all.
235 *
236 * 64-bit arguments may be truncated if the system is using a 32-bit
237 * kernel.
238 *
239 * On error, -1 will be returned and errno will indicate the error.
240 */
39037602
A
241extern int kdebug_trace(
242 uint32_t code,
243 uint64_t arg1,
244 uint64_t arg2,
245 uint64_t arg3,
246 uint64_t arg4)
247 __OSX_AVAILABLE(10.10.2) __IOS_AVAILABLE(8.2);
3e170ce0
A
248
249/*!
250 * @function kdebug_trace_string
251 *
252 * @discussion
253 * This function emits strings to kdebug trace along with an ID and allows
254 * for previously-traced strings to be overwritten and invalidated.
255 *
256 * To start tracing a string and generate an ID to use to refer to it:
257 *
258 * string_id = kdebug_trace_string(debugid, 0, "string");
259 *
260 * To replace a string previously traced:
261 *
262 * string_id = kdebug_trace_string(debugid, string_id, "new string");
263 *
264 * To invalidate a string ID:
265 *
266 * string_id = kdebug_trace_string(debugid, string_id, NULL);
267 *
268 * To check for errors:
269 *
270 * if ((int64_t)string_id == -1) { perror("string error") }
271 *
272 * @param debugid
273 * The `debugid` to check if its enabled before tracing and include as
274 * an argument in the event containing the string.
275 *
276 * Some classes or subclasses are reserved for specific uses and are not
277 * allowed to be used with this function. No function qualifiers are
278 * allowed on `debugid`.
279 *
280 * @param str_id
281 * When 0, a new ID will be generated and returned if tracing is
282 * enabled.
283 *
284 * Otherwise `str_id` must contain an ID that was previously generated
285 * with this function. Clents should pass NULL in `str` if `str_id`
286 * is no longer in use. Otherwise, the string previously mapped to
287 * `str_id` will be overwritten with the contents of `str`.
288 *
289 * @param str
290 * A NUL-terminated 'C' string containing the characters that should be
291 * traced alongside `str_id`.
292 *
293 * If necessary, the string will be truncated at an
294 * implementation-defined length. The string must not be the empty
295 * string, but can be NULL if a valid `str_id` is provided.
296 *
297 * @return
298 * 0 if tracing is disabled or `debugid` is being filtered out of trace.
299 * It can also return (int64_t)-1 if an error occured. Otherwise,
300 * it returns the ID to use to refer to the string in future
301 * kdebug_trace(2) calls.
302 *
303 * The errors that can occur are:
304 *
305 * EINVAL
306 * There are function qualifiers on `debugid`, `str` is empty, or
307 * `str_id` was not generated by this function.
308 * EPERM
309 * The `debugid`'s class or subclass is reserved for internal use.
310 * EFAULT
311 * `str` is an invalid address or NULL when `str_id` is 0.
312 */
3e170ce0
A
313extern uint64_t kdebug_trace_string(uint32_t debugid, uint64_t str_id,
314 const char *str)
39037602
A
315 __OSX_AVAILABLE(10.11) __IOS_AVAILABLE(9.0);
316
317/*
318 * Although the performance impact of kdebug_trace() when kernel
319 * tracing is not enabled is minimal, it may require the caller to
320 * perform an expensive calculation/summarization. This cost can be
321 * skipped by checking the kdebug_is_enabled() predicate:
322 *
323 * if (kdebug_is_enabled(KDBG_CODE(DBG_XPC, 15, 1))) {
324 * uint64_t arg1 = ...;
325 * uint64_t arg2 = ...;
326 * kdebug_trace(KDBG_CODE(DBG_XPC, 15, 1) | DBG_FUNC_NONE, arg1, arg2, 0, 0);
327 * }
328 *
329 * If tracing is enabled for the code at the time of the check, 1
330 * will be returned. Otherwise, 0 will be returned.
331 */
332extern bool kdebug_is_enabled(uint32_t code)
333 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
334 __WATCHOS_AVAILABLE(3.0) __TVOS_AVAILABLE(10.0);
335
336/*
337 * Returns a pointer to the userspace typefilter, if one is available.
338 * May return NULL.
339 */
340extern void *kdebug_typefilter(void)
341 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
342 __WATCHOS_AVAILABLE(3.0) __TVOS_AVAILABLE(10.0);
343
344#endif /* !KERNEL (Private kdebug userspace API) */
a1c7dba1
A
345#endif /* PRIVATE */
346
3e170ce0
A
347#ifdef XNU_KERNEL_PRIVATE
348/* Used in early boot to log strings spanning only a single tracepoint. */
39037602
A
349extern void kernel_debug_string_early(const char *message);
350/* Used to trace strings within kdebug tracepoints on arbitrary eventids. */
351extern void kernel_debug_string_simple(uint32_t eventid, const char *str);
352/* Only used by ktrace to reset kdebug. ktrace_lock must be held. */
353extern void kdebug_reset(void);
3e170ce0
A
354#endif /* XNU_KERNEL_PRIVATE */
355
1c79356b 356/* **** The Kernel Debug Sub Classes for Mach (DBG_MACH) **** */
0c530ab8 357#define DBG_MACH_EXCP_KTRAP_x86 0x02 /* Kernel Traps on x86 */
1c79356b
A
358#define DBG_MACH_EXCP_DFLT 0x03 /* Data Translation Fault */
359#define DBG_MACH_EXCP_IFLT 0x04 /* Inst Translation Fault */
360#define DBG_MACH_EXCP_INTR 0x05 /* Interrupts */
361#define DBG_MACH_EXCP_ALNG 0x06 /* Alignment Exception */
0c530ab8 362#define DBG_MACH_EXCP_UTRAP_x86 0x07 /* User Traps on x86 */
1c79356b
A
363#define DBG_MACH_EXCP_FP 0x08 /* FP Unavail */
364#define DBG_MACH_EXCP_DECI 0x09 /* Decrementer Interrupt */
39037602
A
365#define DBG_MACH_CHUD 0x0A /* deprecated name */
366#define DBG_MACH_SIGNPOST 0x0A /* kernel signposts */
1c79356b
A
367#define DBG_MACH_EXCP_SC 0x0C /* System Calls */
368#define DBG_MACH_EXCP_TRACE 0x0D /* Trace exception */
55e303ae 369#define DBG_MACH_EXCP_EMUL 0x0E /* Instruction emulated */
1c79356b
A
370#define DBG_MACH_IHDLR 0x10 /* Interrupt Handlers */
371#define DBG_MACH_IPC 0x20 /* Inter Process Comm */
39037602
A
372#define DBG_MACH_RESOURCE 0x25 /* tracing limits, etc */
373#define DBG_MACH_VM 0x30 /* Virtual Memory */
374#define DBG_MACH_LEAKS 0x31 /* alloc/free */
375#define DBG_MACH_WORKINGSET 0x32 /* private subclass for working set related debugging */
376#define DBG_MACH_SCHED 0x40 /* Scheduler */
377#define DBG_MACH_MSGID_INVALID 0x50 /* Messages - invalid */
91447636 378#define DBG_MACH_LOCKS 0x60 /* new lock APIs */
2d21ac55 379#define DBG_MACH_PMAP 0x70 /* pmap */
3e170ce0 380#define DBG_MACH_CLOCK 0x80 /* clock */
6d2010ae 381#define DBG_MACH_MP 0x90 /* MP related */
39236c6e 382#define DBG_MACH_VM_PRESSURE 0xA0 /* Memory Pressure Events */
39037602
A
383#define DBG_MACH_STACKSHOT 0xA1 /* Stackshot/Microstackshot subsystem */
384#define DBG_MACH_SFI 0xA2 /* Selective Forced Idle (SFI) */
fe8ab488 385#define DBG_MACH_ENERGY_PERF 0xA3 /* Energy/performance resource stats */
3e170ce0 386#define DBG_MACH_SYSDIAGNOSE 0xA4 /* sysdiagnose keychord */
4bd07ac2 387#define DBG_MACH_ZALLOC 0xA5 /* Zone allocator */
1c79356b 388
3e170ce0 389/* Codes for Scheduler (DBG_MACH_SCHED) */
1c79356b
A
390#define MACH_SCHED 0x0 /* Scheduler */
391#define MACH_STACK_ATTACH 0x1 /* stack_attach() */
392#define MACH_STACK_HANDOFF 0x2 /* stack_handoff() */
393#define MACH_CALL_CONT 0x3 /* call_continuation() */
394#define MACH_CALLOUT 0x4 /* callouts */
395#define MACH_STACK_DETACH 0x5
0b4e3aa0 396#define MACH_MAKE_RUNNABLE 0x6 /* make thread runnable */
b0d623f7
A
397#define MACH_PROMOTE 0x7 /* promoted due to resource */
398#define MACH_DEMOTE 0x8 /* promotion undone */
399#define MACH_IDLE 0x9 /* processor idling */
400#define MACH_STACK_DEPTH 0xa /* stack depth at switch */
6d2010ae 401#define MACH_MOVED 0xb /* did not use original scheduling decision */
3e170ce0
A
402/* unused 0xc */
403/* unused 0xd */
316670eb
A
404#define MACH_FAILSAFE 0xe /* tripped fixed-pri/RT failsafe */
405#define MACH_BLOCK 0xf /* thread block */
406#define MACH_WAIT 0x10 /* thread wait assertion */
6d2010ae
A
407#define MACH_GET_URGENCY 0x14 /* Urgency queried by platform */
408#define MACH_URGENCY 0x15 /* Urgency (RT/BG/NORMAL) communicated
316670eb
A
409 * to platform
410 */
6d2010ae
A
411#define MACH_REDISPATCH 0x16 /* "next thread" thread redispatched */
412#define MACH_REMOTE_AST 0x17 /* AST signal issued to remote processor */
39236c6e 413#define MACH_SCHED_CHOOSE_PROCESSOR 0x18 /* Result of choose_processor */
bd504ef0 414#define MACH_DEEP_IDLE 0x19 /* deep idle on master processor */
3e170ce0 415/* unused 0x1a was MACH_SCHED_DECAY_PRIORITY */
39236c6e
A
416#define MACH_CPU_THROTTLE_DISABLE 0x1b /* Global CPU Throttle Disable */
417#define MACH_RW_PROMOTE 0x1c /* promoted due to RW lock promotion */
418#define MACH_RW_DEMOTE 0x1d /* promotion due to RW lock undone */
fe8ab488
A
419#define MACH_SCHED_MAINTENANCE 0x1f /* periodic maintenance thread */
420#define MACH_DISPATCH 0x20 /* context switch completed */
421#define MACH_QUANTUM_HANDOFF 0x21 /* quantum handoff occurred */
422#define MACH_MULTIQ_DEQUEUE 0x22 /* Result of multiq dequeue */
423#define MACH_SCHED_THREAD_SWITCH 0x23 /* attempt direct context switch to hinted thread */
424#define MACH_SCHED_SMT_BALANCE 0x24 /* SMT load balancing ASTs */
3e170ce0
A
425#define MACH_REMOTE_DEFERRED_AST 0x25 /* Deferred AST started against remote processor */
426#define MACH_REMOTE_CANCEL_AST 0x26 /* Canceled deferred AST for remote processor */
427#define MACH_SCHED_CHANGE_PRIORITY 0x27 /* thread sched priority changed */
428#define MACH_SCHED_UPDATE_REC_CORES 0x28 /* Change to recommended processor bitmask */
429#define MACH_STACK_WAIT 0x29 /* Thread could not be switched-to because of kernel stack shortage */
430#define MACH_THREAD_BIND 0x2a /* Thread was bound (or unbound) to a processor */
431#define MACH_WAITQ_PROMOTE 0x2b /* Thread promoted by waitq boost */
432#define MACH_WAITQ_DEMOTE 0x2c /* Thread demoted from waitq boost */
490019cf
A
433#define MACH_SCHED_LOAD 0x2d /* load update */
434#define MACH_REC_CORES_FAILSAFE 0x2e /* recommended processor failsafe kicked in */
435#define MACH_SCHED_QUANTUM_EXPIRED 0x2f /* thread quantum expired */
fe8ab488
A
436
437/* Variants for MACH_MULTIQ_DEQUEUE */
438#define MACH_MULTIQ_BOUND 1
439#define MACH_MULTIQ_GROUP 2
440#define MACH_MULTIQ_GLOBAL 3
39236c6e 441
a1c7dba1
A
442/* Arguments for vm_fault (DBG_MACH_VM) */
443#define DBG_ZERO_FILL_FAULT 1
444#define DBG_PAGEIN_FAULT 2
445#define DBG_COW_FAULT 3
446#define DBG_CACHE_HIT_FAULT 4
447#define DBG_NZF_PAGE_FAULT 5
3e170ce0 448#define DBG_GUARD_FAULT 6
a1c7dba1
A
449#define DBG_PAGEINV_FAULT 7
450#define DBG_PAGEIND_FAULT 8
451#define DBG_COMPRESSOR_FAULT 9
452#define DBG_COMPRESSOR_SWAPIN_FAULT 10
453
39236c6e 454/* Codes for IPC (DBG_MACH_IPC) */
fe8ab488
A
455#define MACH_TASK_SUSPEND 0x0 /* Suspended a task */
456#define MACH_TASK_RESUME 0x1 /* Resumed a task */
457#define MACH_THREAD_SET_VOUCHER 0x2
458#define MACH_IPC_MSG_SEND 0x3 /* mach msg send, uniq msg info */
459#define MACH_IPC_MSG_RECV 0x4 /* mach_msg receive */
460#define MACH_IPC_MSG_RECV_VOUCHER_REFUSED 0x5 /* mach_msg receive, voucher refused */
461#define MACH_IPC_KMSG_FREE 0x6 /* kernel free of kmsg data */
462#define MACH_IPC_VOUCHER_CREATE 0x7 /* Voucher added to global voucher hashtable */
463#define MACH_IPC_VOUCHER_CREATE_ATTR_DATA 0x8 /* Attr data for newly created voucher */
464#define MACH_IPC_VOUCHER_DESTROY 0x9 /* Voucher removed from global voucher hashtable */
39037602
A
465#define MACH_IPC_KMSG_INFO 0xa /* Send/Receive info for a kmsg */
466#define MACH_IPC_KMSG_LINK 0xb /* link a kernel kmsg pointer to user mach_msg_header_t */
2d21ac55 467
3e170ce0 468/* Codes for pmap (DBG_MACH_PMAP) */
2d21ac55
A
469#define PMAP__CREATE 0x0
470#define PMAP__DESTROY 0x1
471#define PMAP__PROTECT 0x2
472#define PMAP__PAGE_PROTECT 0x3
473#define PMAP__ENTER 0x4
474#define PMAP__REMOVE 0x5
475#define PMAP__NEST 0x6
476#define PMAP__UNNEST 0x7
477#define PMAP__FLUSH_TLBS 0x8
478#define PMAP__UPDATE_INTERRUPT 0x9
479#define PMAP__ATTRIBUTE_CLEAR 0xa
39236c6e
A
480#define PMAP__REUSABLE 0xb
481#define PMAP__QUERY_RESIDENT 0xc
482#define PMAP__FLUSH_KERN_TLBS 0xd
483#define PMAP__FLUSH_DELAYED_TLBS 0xe
fe8ab488 484#define PMAP__FLUSH_TLBS_TO 0xf
3e170ce0
A
485#define PMAP__FLUSH_EPT 0x10
486
487/* Codes for clock (DBG_MACH_CLOCK) */
488#define MACH_EPOCH_CHANGE 0x0 /* wake epoch change */
489
39236c6e
A
490
491/* Codes for Stackshot/Microstackshot (DBG_MACH_STACKSHOT) */
492#define MICROSTACKSHOT_RECORD 0x0
493#define MICROSTACKSHOT_GATHER 0x1
1c79356b 494
3e170ce0
A
495/* Codes for sysdiagnose */
496#define SYSDIAGNOSE_NOTIFY_USER 0x0
497
fe8ab488
A
498/* Codes for Selective Forced Idle (DBG_MACH_SFI) */
499#define SFI_SET_WINDOW 0x0
500#define SFI_CANCEL_WINDOW 0x1
04b8595b 501#define SFI_SET_CLASS_OFFTIME 0x2
fe8ab488
A
502#define SFI_CANCEL_CLASS_OFFTIME 0x3
503#define SFI_THREAD_DEFER 0x4
504#define SFI_OFF_TIMER 0x5
505#define SFI_ON_TIMER 0x6
506#define SFI_WAIT_CANCELED 0x7
507#define SFI_PID_SET_MANAGED 0x8
04b8595b
A
508#define SFI_PID_CLEAR_MANAGED 0x9
509#define SFI_GLOBAL_DEFER 0xa
4bd07ac2
A
510
511/* Codes for Zone Allocator (DBG_MACH_ZALLOC) */
512#define ZALLOC_ZCRAM 0x0
513
39037602
A
514/* Codes for Mach resource management (DBG_MACH_RESOURCE) */
515/* _K32A/B codes start at double the low nibble */
516#define RMON_ENABLE_CPUUSAGE_MONITOR 0x001
517#define RMON_CPUUSAGE_VIOLATED 0x002
518#define RMON_CPUUSAGE_SUSPENDED 0x003
519#define RMON_CPUUSAGE_VIOLATED_K32A 0x004
520#define RMON_CPUUSAGE_VIOLATED_K32B 0x005
521#define RMON_CPUUSAGE_RESUMED 0x006
522#define RMON_DISABLE_CPUUSAGE_MONITOR 0x00f
523
524#define RMON_ENABLE_CPUWAKES_MONITOR 0x011
525#define RMON_CPUWAKES_VIOLATED 0x012
526#define RMON_CPUWAKES_VIOLATED_K32A 0x014
527#define RMON_CPUWAKES_VIOLATED_K32B 0x015
528#define RMON_DISABLE_CPUWAKES_MONITOR 0x01f
529
530#define RMON_ENABLE_IO_MONITOR 0x021
531#define RMON_LOGWRITES_VIOLATED 0x022
532#define RMON_PHYSWRITES_VIOLATED 0x023
533#define RMON_LOGWRITES_VIOLATED_K32A 0x024
534#define RMON_LOGWRITES_VIOLATED_K32B 0x025
535#define RMON_DISABLE_IO_MONITOR 0x02f
536
1c79356b
A
537/* **** The Kernel Debug Sub Classes for Network (DBG_NETWORK) **** */
538#define DBG_NETIP 1 /* Internet Protocol */
539#define DBG_NETARP 2 /* Address Resolution Protocol */
540#define DBG_NETUDP 3 /* User Datagram Protocol */
541#define DBG_NETTCP 4 /* Transmission Control Protocol */
542#define DBG_NETICMP 5 /* Internet Control Message Protocol */
543#define DBG_NETIGMP 6 /* Internet Group Management Protocol */
544#define DBG_NETRIP 7 /* Routing Information Protocol */
545#define DBG_NETOSPF 8 /* Open Shortest Path First */
546#define DBG_NETISIS 9 /* Intermediate System to Intermediate System */
547#define DBG_NETSNMP 10 /* Simple Network Management Protocol */
548#define DBG_NETSOCK 11 /* Socket Layer */
549
550/* For Apple talk */
551#define DBG_NETAARP 100 /* Apple ARP */
552#define DBG_NETDDP 101 /* Datagram Delivery Protocol */
553#define DBG_NETNBP 102 /* Name Binding Protocol */
554#define DBG_NETZIP 103 /* Zone Information Protocol */
555#define DBG_NETADSP 104 /* Name Binding Protocol */
556#define DBG_NETATP 105 /* Apple Transaction Protocol */
557#define DBG_NETASP 106 /* Apple Session Protocol */
558#define DBG_NETAFP 107 /* Apple Filing Protocol */
559#define DBG_NETRTMP 108 /* Routing Table Maintenance Protocol */
560#define DBG_NETAURP 109 /* Apple Update Routing Protocol */
fe8ab488 561
55e303ae 562#define DBG_NETIPSEC 128 /* IPsec Protocol */
fe8ab488 563#define DBG_NETVMNET 129 /* VMNet */
1c79356b
A
564
565/* **** The Kernel Debug Sub Classes for IOKIT (DBG_IOKIT) **** */
060df5ea 566#define DBG_IOINTC 0 /* Interrupt controller */
3e170ce0 567#define DBG_IOWORKLOOP 1 /* Work from work loop */
0c530ab8
A
568#define DBG_IOINTES 2 /* Interrupt event source */
569#define DBG_IOCLKES 3 /* Clock event source */
570#define DBG_IOCMDQ 4 /* Command queue latencies */
571#define DBG_IOMCURS 5 /* Memory Cursor */
572#define DBG_IOMDESC 6 /* Memory Descriptors */
573#define DBG_IOPOWER 7 /* Power Managerment */
3e170ce0 574#define DBG_IOSERVICE 8 /* Matching etc. */
743345f9 575#define DBG_IOREGISTRY 9 /* Registry */
0c530ab8 576
b0d623f7 577/* **** 9-32 reserved for internal IOKit usage **** */
0c530ab8
A
578
579#define DBG_IOSTORAGE 32 /* Storage layers */
580#define DBG_IONETWORK 33 /* Network layers */
581#define DBG_IOKEYBOARD 34 /* Keyboard */
6d2010ae
A
582#define DBG_IOHID 35 /* HID Devices */
583#define DBG_IOAUDIO 36 /* Audio */
0c530ab8 584#define DBG_IOSERIAL 37 /* Serial */
6d2010ae
A
585#define DBG_IOTTY 38 /* TTY layers */
586#define DBG_IOSAM 39 /* SCSI Architecture Model layers */
587#define DBG_IOPARALLELATA 40 /* Parallel ATA */
0c530ab8 588#define DBG_IOPARALLELSCSI 41 /* Parallel SCSI */
6d2010ae
A
589#define DBG_IOSATA 42 /* Serial-ATA */
590#define DBG_IOSAS 43 /* SAS */
0c530ab8 591#define DBG_IOFIBRECHANNEL 44 /* FiberChannel */
6d2010ae 592#define DBG_IOUSB 45 /* USB */
0c530ab8
A
593#define DBG_IOBLUETOOTH 46 /* Bluetooth */
594#define DBG_IOFIREWIRE 47 /* FireWire */
595#define DBG_IOINFINIBAND 48 /* Infiniband */
6d2010ae 596#define DBG_IOCPUPM 49 /* CPU Power Management */
593a1d5f 597#define DBG_IOGRAPHICS 50 /* Graphics */
0b4c1975 598#define DBG_HIBERNATE 51 /* hibernation related events */
39236c6e 599#define DBG_IOTHUNDERBOLT 52 /* Thunderbolt */
0c530ab8 600
6d2010ae 601
0c530ab8
A
602/* Backwards compatibility */
603#define DBG_IOPOINTING DBG_IOHID /* OBSOLETE: Use DBG_IOHID instead */
604#define DBG_IODISK DBG_IOSTORAGE /* OBSOLETE: Use DBG_IOSTORAGE instead */
1c79356b
A
605
606/* **** The Kernel Debug Sub Classes for Device Drivers (DBG_DRIVERS) **** */
0c530ab8
A
607#define DBG_DRVSTORAGE 1 /* Storage layers */
608#define DBG_DRVNETWORK 2 /* Network layers */
609#define DBG_DRVKEYBOARD 3 /* Keyboard */
3e170ce0 610#define DBG_DRVHID 4 /* HID Devices */
0c530ab8
A
611#define DBG_DRVAUDIO 5 /* Audio */
612#define DBG_DRVSERIAL 7 /* Serial */
3e170ce0
A
613#define DBG_DRVSAM 8 /* SCSI Architecture Model layers */
614#define DBG_DRVPARALLELATA 9 /* Parallel ATA */
0c530ab8 615#define DBG_DRVPARALLELSCSI 10 /* Parallel SCSI */
3e170ce0
A
616#define DBG_DRVSATA 11 /* Serial ATA */
617#define DBG_DRVSAS 12 /* SAS */
0c530ab8 618#define DBG_DRVFIBRECHANNEL 13 /* FiberChannel */
3e170ce0 619#define DBG_DRVUSB 14 /* USB */
0c530ab8
A
620#define DBG_DRVBLUETOOTH 15 /* Bluetooth */
621#define DBG_DRVFIREWIRE 16 /* FireWire */
622#define DBG_DRVINFINIBAND 17 /* Infiniband */
3e170ce0 623#define DBG_DRVGRAPHICS 18 /* Graphics */
6d2010ae 624#define DBG_DRVSD 19 /* Secure Digital */
316670eb
A
625#define DBG_DRVNAND 20 /* NAND drivers and layers */
626#define DBG_SSD 21 /* SSD */
bd504ef0 627#define DBG_DRVSPI 22 /* SPI */
39037602 628#define DBG_DRVWLAN_802_11 23 /* WLAN 802.11 */
0c530ab8
A
629
630/* Backwards compatibility */
3e170ce0
A
631#define DBG_DRVPOINTING DBG_DRVHID /* OBSOLETE: Use DBG_DRVHID instead */
632#define DBG_DRVDISK DBG_DRVSTORAGE /* OBSOLETE: Use DBG_DRVSTORAGE instead */
1c79356b
A
633
634/* **** The Kernel Debug Sub Classes for the DLIL Layer (DBG_DLIL) **** */
635#define DBG_DLIL_STATIC 1 /* Static DLIL code */
636#define DBG_DLIL_PR_MOD 2 /* DLIL Protocol Module */
637#define DBG_DLIL_IF_MOD 3 /* DLIL Interface Module */
638#define DBG_DLIL_PR_FLT 4 /* DLIL Protocol Filter */
639#define DBG_DLIL_IF_FLT 5 /* DLIL Interface FIlter */
640
6d2010ae 641/* The Kernel Debug Sub Classes for File System (DBG_FSYSTEM) */
39037602
A
642#define DBG_FSRW 0x1 /* reads and writes to the filesystem */
643#define DBG_DKRW 0x2 /* reads and writes to the disk */
644#define DBG_FSVN 0x3 /* vnode operations (inc. locking/unlocking) */
645#define DBG_FSLOOOKUP 0x4 /* namei and other lookup-related operations */
646#define DBG_JOURNAL 0x5 /* journaling operations */
647#define DBG_IOCTL 0x6 /* ioctl to the disk */
648#define DBG_BOOTCACHE 0x7 /* bootcache operations */
649#define DBG_HFS 0x8 /* HFS-specific events; see the hfs project */
650#define DBG_APFS 0x9 /* APFS-specific events; see the apfs project */
651#define DBG_SMB 0xA /* SMB-specific events; see the smb project */
316670eb
A
652#define DBG_EXFAT 0xE /* ExFAT-specific events; see the exfat project */
653#define DBG_MSDOS 0xF /* FAT-specific events; see the msdosfs project */
39236c6e 654#define DBG_ACFS 0x10 /* Xsan-specific events; see the XsanFS project */
3e170ce0 655#define DBG_THROTTLE 0x11 /* I/O Throttling events */
fe8ab488 656#define DBG_CONTENT_PROT 0xCF /* Content Protection Events: see bsd/sys/cprotect.h */
1c79356b 657
a1c7dba1
A
658/*
659 * For Kernel Debug Sub Class DBG_HFS, state bits for hfs_update event
660 */
661#define DBG_HFS_UPDATE_ACCTIME 0x01
662#define DBG_HFS_UPDATE_MODTIME 0x02
663#define DBG_HFS_UPDATE_CHGTIME 0x04
664#define DBG_HFS_UPDATE_MODIFIED 0x08
3e170ce0 665#define DBG_HFS_UPDATE_FORCE 0x10
a1c7dba1 666#define DBG_HFS_UPDATE_DATEADDED 0x20
3e170ce0
A
667#define DBG_HFS_UPDATE_MINOR 0x40
668#define DBG_HFS_UPDATE_SKIPPED 0x80
a1c7dba1 669
1c79356b 670/* The Kernel Debug Sub Classes for BSD */
39037602
A
671#define DBG_BSD_PROC 0x01 /* process/signals related */
672#define DBG_BSD_MEMSTAT 0x02 /* memorystatus / jetsam operations */
673#define DBG_BSD_EXCP_SC 0x0C /* System Calls */
674#define DBG_BSD_AIO 0x0D /* aio (POSIX async IO) */
675#define DBG_BSD_SC_EXTENDED_INFO 0x0E /* System Calls, extended info */
676#define DBG_BSD_SC_EXTENDED_INFO2 0x0F /* System Calls, extended info */
677#define DBG_BSD_KDEBUG_TEST 0xFF /* for testing kdebug */
1c79356b 678
b0d623f7
A
679
680/* The Codes for BSD subcode class DBG_BSD_PROC */
39037602
A
681#define BSD_PROC_EXIT 1 /* process exit */
682#define BSD_PROC_FRCEXIT 2 /* Kernel force termination */
683#define BSD_PROC_EXEC 3 /* process spawn / exec */
684#define BSD_PROC_EXITREASON_CREATE 4 /* exit reason creation */
685#define BSD_PROC_EXITREASON_COMMIT 5 /* exit reason commited to a proc */
6d2010ae 686
39236c6e
A
687/* Codes for BSD subcode class DBG_BSD_MEMSTAT */
688#define BSD_MEMSTAT_SCAN 1 /* memorystatus thread awake */
689#define BSD_MEMSTAT_JETSAM 2 /* LRU jetsam */
690#define BSD_MEMSTAT_JETSAM_HIWAT 3 /* highwater jetsam */
691#define BSD_MEMSTAT_FREEZE 4 /* freeze process */
692#define BSD_MEMSTAT_LATENCY_COALESCE 5 /* delay imposed to coalesce jetsam reports */
3e170ce0 693#define BSD_MEMSTAT_UPDATE 6 /* priority update */
39236c6e
A
694#define BSD_MEMSTAT_IDLE_DEMOTE 7 /* idle demotion fired */
695#define BSD_MEMSTAT_CLEAR_ERRORS 8 /* reset termination error state */
fe8ab488
A
696#define BSD_MEMSTAT_DIRTY_TRACK 9 /* track the process state */
697#define BSD_MEMSTAT_DIRTY_SET 10 /* set the process state */
698#define BSD_MEMSTAT_DIRTY_CLEAR 11 /* clear the process state */
699#ifdef PRIVATE
700#define BSD_MEMSTAT_GRP_SET_PROP 12 /* set group properties */
701#define BSD_MEMSTAT_DO_KILL 13 /* memorystatus kills */
702#endif /* PRIVATE */
39236c6e 703
1c79356b
A
704/* The Kernel Debug Sub Classes for DBG_TRACE */
705#define DBG_TRACE_DATA 0
706#define DBG_TRACE_STRING 1
b0d623f7 707#define DBG_TRACE_INFO 2
1c79356b 708
04b8595b
A
709/* The Kernel Debug events: */
710#define TRACE_DATA_NEWTHREAD (TRACEDBG_CODE(DBG_TRACE_DATA, 1))
711#define TRACE_DATA_EXEC (TRACEDBG_CODE(DBG_TRACE_DATA, 2))
712#define TRACE_DATA_THREAD_TERMINATE (TRACEDBG_CODE(DBG_TRACE_DATA, 3))
39037602 713#define TRACE_DATA_THREAD_TERMINATE_PID (TRACEDBG_CODE(DBG_TRACE_DATA, 4))
3e170ce0 714#define TRACE_STRING_GLOBAL (TRACEDBG_CODE(DBG_TRACE_STRING, 0))
04b8595b
A
715#define TRACE_STRING_NEWTHREAD (TRACEDBG_CODE(DBG_TRACE_STRING, 1))
716#define TRACE_STRING_EXEC (TRACEDBG_CODE(DBG_TRACE_STRING, 2))
39037602
A
717#define TRACE_STRING_PROC_EXIT (TRACEDBG_CODE(DBG_TRACE_STRING, 3))
718#define TRACE_STRING_THREADNAME (TRACEDBG_CODE(DBG_TRACE_STRING, 4))
719#define TRACE_STRING_THREADNAME_PREV (TRACEDBG_CODE(DBG_TRACE_STRING, 5))
04b8595b
A
720#define TRACE_PANIC (TRACEDBG_CODE(DBG_TRACE_INFO, 0))
721#define TRACE_TIMESTAMPS (TRACEDBG_CODE(DBG_TRACE_INFO, 1))
722#define TRACE_LOST_EVENTS (TRACEDBG_CODE(DBG_TRACE_INFO, 2))
723#define TRACE_WRITING_EVENTS (TRACEDBG_CODE(DBG_TRACE_INFO, 3))
724#define TRACE_INFO_STRING (TRACEDBG_CODE(DBG_TRACE_INFO, 4))
fe8ab488 725
6d2010ae
A
726/* The Kernel Debug Sub Classes for DBG_CORESTORAGE */
727#define DBG_CS_IO 0
728
fe8ab488
A
729/* The Kernel Debug Sub Classes for DBG_SECURITY */
730#define DBG_SEC_KERNEL 0 /* raw entropy collected by the kernel */
731
316670eb
A
732/* Sub-class codes for CoreGraphics (DBG_CG) are defined in its component. */
733
0c530ab8
A
734/* The Kernel Debug Sub Classes for DBG_MISC */
735#define DBG_EVENT 0x10
736#define DBG_BUFFER 0x20
737
9bccf70c 738/* The Kernel Debug Sub Classes for DBG_DYLD */
39037602
A
739#define DBG_DYLD_UUID (5)
740
741/* Kernel Debug codes for the DBG_DYLD_UUID subclass */
742#define DBG_DYLD_UUID_MAP_A (0)
743#define DBG_DYLD_UUID_MAP_B (1)
744#define DBG_DYLD_UUID_MAP_32_A (2)
745#define DBG_DYLD_UUID_MAP_32_B (3)
746#define DBG_DYLD_UUID_MAP_32_C (4)
747#define DBG_DYLD_UUID_UNMAP_A (5)
748#define DBG_DYLD_UUID_UNMAP_B (6)
749#define DBG_DYLD_UUID_UNMAP_32_A (7)
750#define DBG_DYLD_UUID_UNMAP_32_B (8)
751#define DBG_DYLD_UUID_UNMAP_32_C (9)
752#define DBG_DYLD_UUID_SHARED_CACHE_A (10)
753#define DBG_DYLD_UUID_SHARED_CACHE_B (11)
754#define DBG_DYLD_UUID_SHARED_CACHE_32_A (12)
755#define DBG_DYLD_UUID_SHARED_CACHE_32_B (13)
756#define DBG_DYLD_UUID_SHARED_CACHE_32_C (14)
9bccf70c
A
757
758/* The Kernel Debug modifiers for the DBG_DKRW sub class */
759#define DKIO_DONE 0x01
760#define DKIO_READ 0x02
761#define DKIO_ASYNC 0x04
762#define DKIO_META 0x08
763#define DKIO_PAGING 0x10
39236c6e 764#define DKIO_THROTTLE 0x20 /* Deprecated, still provided so fs_usage doesn't break */
6d2010ae 765#define DKIO_PASSIVE 0x40
316670eb 766#define DKIO_NOCACHE 0x80
39236c6e
A
767#define DKIO_TIER_MASK 0xF00
768#define DKIO_TIER_SHIFT 8
d190cdc3 769#define DKIO_TIER_UPGRADE 0x1000
9bccf70c 770
db609669
A
771/* Kernel Debug Sub Classes for Applications (DBG_APPS) */
772#define DBG_APP_LOGINWINDOW 0x03
39236c6e 773#define DBG_APP_AUDIO 0x04
39037602
A
774#define DBG_APP_SYSTEMUI 0x05
775#define DBG_APP_SIGNPOST 0x0A
3e170ce0 776#define DBG_APP_APPKIT 0x0C
39037602 777#define DBG_APP_DFR 0x0E
db609669 778#define DBG_APP_SAMBA 0x80
743345f9 779#define DBG_APP_EOSSUPPORT 0x81
0c530ab8 780
39236c6e
A
781/* Kernel Debug codes for Throttling (DBG_THROTTLE) */
782#define OPEN_THROTTLE_WINDOW 0x1
3e170ce0 783#define PROCESS_THROTTLED 0x2
39236c6e
A
784#define IO_THROTTLE_DISABLE 0x3
785
786
787/* Subclasses for MACH Importance Policies (DBG_IMPORTANCE) */
788/* TODO: Split up boost and task policy? */
789#define IMP_ASSERTION 0x10 /* Task takes/drops a boost assertion */
790#define IMP_BOOST 0x11 /* Task boost level changed */
791#define IMP_MSG 0x12 /* boosting message sent by donating task on donating port */
792#define IMP_WATCHPORT 0x13 /* port marked as watchport, and boost was transferred to the watched task */
793#define IMP_TASK_SUPPRESSION 0x17 /* Task changed suppression behaviors */
794#define IMP_TASK_APPTYPE 0x18 /* Task launched with apptype */
795#define IMP_UPDATE 0x19 /* Requested -> effective calculation */
fe8ab488
A
796#define IMP_USYNCH_QOS_OVERRIDE 0x1A /* Userspace synchronization applied QoS override to resource owning thread */
797#define IMP_DONOR_CHANGE 0x1B /* The iit_donor bit changed */
798#define IMP_MAIN_THREAD_QOS 0x1C /* The task's main thread QoS was set */
39236c6e
A
799/* DBG_IMPORTANCE subclasses 0x20 - 0x3F reserved for task policy flavors */
800
801/* Codes for IMP_ASSERTION */
802#define IMP_HOLD 0x2 /* Task holds a boost assertion */
803#define IMP_DROP 0x4 /* Task drops a boost assertion */
804#define IMP_EXTERN 0x8 /* boost assertion moved from kernel to userspace responsibility (externalized) */
805
806/* Codes for IMP_BOOST */
807#define IMP_BOOSTED 0x1
808#define IMP_UNBOOSTED 0x2 /* Task drops a boost assertion */
809
810/* Codes for IMP_MSG */
811#define IMP_MSG_SEND 0x1 /* boosting message sent by donating task on donating port */
812#define IMP_MSG_DELV 0x2 /* boosting message delivered to task */
813
814/* Codes for IMP_UPDATE */
815#define IMP_UPDATE_TASK_CREATE 0x1
316670eb 816
fe8ab488
A
817/* Codes for IMP_USYNCH_QOS_OVERRIDE */
818#define IMP_USYNCH_ADD_OVERRIDE 0x0 /* add override for a contended resource */
819#define IMP_USYNCH_REMOVE_OVERRIDE 0x1 /* remove override for a contended resource */
820
821/* Codes for IMP_DONOR_CHANGE */
822#define IMP_DONOR_UPDATE_LIVE_DONOR_STATE 0x0
823#define IMP_DONOR_INIT_DONOR_STATE 0x1
824
825/* Subclasses for MACH Bank Voucher Attribute Manager (DBG_BANK) */
826#define BANK_ACCOUNT_INFO 0x10 /* Trace points related to bank account struct */
827#define BANK_TASK_INFO 0x11 /* Trace points related to bank task struct */
828
829/* Subclasses for MACH ATM Voucher Attribute Manager (ATM) */
3e170ce0
A
830#define ATM_SUBAID_INFO 0x10
831#define ATM_GETVALUE_INFO 0x20
832#define ATM_UNREGISTER_INFO 0x30
fe8ab488
A
833
834/* Codes for BANK_ACCOUNT_INFO */
835#define BANK_SETTLE_CPU_TIME 0x1 /* Bank ledger(chit) rolled up to tasks. */
490019cf 836#define BANK_SECURE_ORIGINATOR_CHANGED 0x2 /* Secure Originator changed. */
fe8ab488
A
837
838/* Codes for ATM_SUBAID_INFO */
839#define ATM_MIN_CALLED 0x1
3e170ce0 840#define ATM_LINK_LIST_TRIM 0x2
fe8ab488
A
841
842/* Codes for ATM_GETVALUE_INFO */
843#define ATM_VALUE_REPLACED 0x1
844#define ATM_VALUE_ADDED 0x2
845
846/* Codes for ATM_UNREGISTER_INFO */
847#define ATM_VALUE_UNREGISTERED 0x1
848#define ATM_VALUE_DIFF_MAILBOX 0x2
849
3e170ce0
A
850/* Kernel Debug Sub Classes for daemons (DBG_DAEMON) */
851#define DBG_DAEMON_COREDUET 0x1
1c79356b 852
39037602
A
853/* Subclasses for the user space allocator */
854#define DBG_UMALLOC_EXTERNAL 0x1
855#define DBG_UMALLOC_INTERNAL 0x2
3e170ce0 856/**********************************************************************/
1c79356b 857
3e170ce0
A
858#define KDBG_MIGCODE(msgid) ((DBG_MIG << KDBG_CLASS_OFFSET) | \
859 (((msgid) & 0x3fffff) << KDBG_CODE_OFFSET))
1c79356b
A
860
861#define MACHDBG_CODE(SubClass, code) KDBG_CODE(DBG_MACH, SubClass, code)
862#define NETDBG_CODE(SubClass, code) KDBG_CODE(DBG_NETWORK, SubClass, code)
863#define FSDBG_CODE(SubClass, code) KDBG_CODE(DBG_FSYSTEM, SubClass, code)
864#define BSDDBG_CODE(SubClass, code) KDBG_CODE(DBG_BSD, SubClass, code)
865#define IOKDBG_CODE(SubClass, code) KDBG_CODE(DBG_IOKIT, SubClass, code)
866#define DRVDBG_CODE(SubClass, code) KDBG_CODE(DBG_DRIVERS, SubClass, code)
867#define TRACEDBG_CODE(SubClass,code) KDBG_CODE(DBG_TRACE, SubClass, code)
868#define MISCDBG_CODE(SubClass,code) KDBG_CODE(DBG_MISC, SubClass, code)
869#define DLILDBG_CODE(SubClass,code) KDBG_CODE(DBG_DLIL, SubClass, code)
91447636 870#define SECURITYDBG_CODE(SubClass,code) KDBG_CODE(DBG_SECURITY, SubClass, code)
9bccf70c 871#define DYLDDBG_CODE(SubClass,code) KDBG_CODE(DBG_DYLD, SubClass, code)
55e303ae 872#define QTDBG_CODE(SubClass,code) KDBG_CODE(DBG_QT, SubClass, code)
91447636 873#define APPSDBG_CODE(SubClass,code) KDBG_CODE(DBG_APPS, SubClass, code)
a1c7dba1 874#define ARIADNEDBG_CODE(SubClass, code) KDBG_CODE(DBG_ARIADNE, SubClass, code)
3e170ce0 875#define DAEMONDBG_CODE(SubClass, code) KDBG_CODE(DBG_DAEMON, SubClass, code)
0c530ab8 876#define CPUPM_CODE(code) IOKDBG_CODE(DBG_IOCPUPM, code)
1c79356b 877
2d21ac55
A
878#define KMEM_ALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 0)
879#define KMEM_ALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 1)
880#define KMEM_FREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 2)
881#define KMEM_FREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 3)
882#define ZALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 4)
883#define ZALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 5)
884#define ZFREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 6)
885#define ZFREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 7)
886
887#define PMAP_CODE(code) MACHDBG_CODE(DBG_MACH_PMAP, code)
888
316670eb 889
39236c6e 890#define IMPORTANCE_CODE(SubClass, code) KDBG_CODE(DBG_IMPORTANCE, (SubClass), (code))
fe8ab488
A
891#define BANK_CODE(SubClass, code) KDBG_CODE(DBG_BANK, (SubClass), (code))
892#define ATM_CODE(SubClass, code) KDBG_CODE(DBG_ATM, (SubClass), (code))
39236c6e 893
3e170ce0
A
894/* Kernel Debug Macros for specific daemons */
895#define COREDUETDBG_CODE(code) DAEMONDBG_CODE(DBG_DAEMON_COREDUET, code)
896
39037602
A
897/*
898 * To use kdebug in the kernel:
899 *
900 * #include <sys/kdebug.h>
901 *
902 * #define DBG_NETIPINIT NETDBG_CODE(DBG_NETIP, 1)
903 *
904 * void
905 * ip_init(void)
906 * {
907 * KDBG(DBG_NETIPINIT | DBG_FUNC_START, 1, 2, 3, 4);
908 * ...
909 * KDBG(DBG_NETIPINIT);
910 * ...
911 * KDBG(DBG_NETIPINIT | DBG_FUNC_END);
912 * }
913 */
1c79356b 914
39037602
A
915#ifdef KERNEL_PRIVATE
916
917/*
918 * The KDBG{,_DEBUG,_RELEASE,_FILTERED} macros are the preferred method of
919 * making tracepoints.
920 *
921 * Kernel pointers must be unslid or permuted using VM_KERNEL_UNSLIDE_OR_PERM.
922 * Do not trace any sensitive data.
923 */
924
925/*
926 * Traced on debug and development (and release OS X) kernels.
927 */
928#define KDBG(x, ...) KDBG_(, x, ## __VA_ARGS__, 4, 3, 2, 1, 0)
929
930/*
931 * Traced on debug and development (and release OS X) kernels if explicitly
932 * requested. Omitted from tracing without a typefilter.
933 */
934#define KDBG_FILTERED(x, ...) KDBG_(_FILTERED, x, ## __VA_ARGS__, 4, 3, 2, 1, 0)
935
936/*
937 * Traced on debug, development, and release kernels.
938 *
939 * Only use this tracepoint if the events are required for a shipping trace
940 * tool.
941 */
942#define KDBG_RELEASE(x, ...) KDBG_(_RELEASE, x, ## __VA_ARGS__, 4, 3, 2, 1, 0)
943
944/*
945 * Traced only on debug kernels.
946 */
947#define KDBG_DEBUG(x, ...) KDBG_(_DEBUG, x, ## __VA_ARGS__, 4, 3, 2, 1, 0)
948
949#define KDBG_(f, x, a, b, c, d, n, ...) KDBG##n(f, x, a, b, c, d)
950#define KDBG0(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, 0, 0, 0, 0, 0)
951#define KDBG1(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, 0, 0, 0, 0)
952#define KDBG2(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, b, 0, 0, 0)
953#define KDBG3(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, b, c, 0, 0)
954#define KDBG4(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, b, c, d, 0)
955
956#endif /* defined(KERNEL_PRIVATE) */
1c79356b
A
957
958extern unsigned int kdebug_enable;
9bccf70c 959
316670eb 960/*
39037602
A
961 * Bits used by kdebug_enable. These control which events are traced at
962 * runtime.
963 */
964#define KDEBUG_ENABLE_TRACE (1U << 0)
965#define KDEBUG_ENABLE_ENTROPY (1U << 1) /* obsolete */
966#define KDEBUG_ENABLE_CHUD (1U << 2) /* obsolete */
967#define KDEBUG_ENABLE_PPT (1U << 3)
968#define KDEBUG_ENABLE_SERIAL (1U << 4)
969
970#define KDEBUG_TRACE (KDEBUG_ENABLE_TRACE)
971
972/*
973 * Specify KDEBUG_PPT to indicate that the event belongs to the limited PPT set.
974 * PPT is deprecated -- use a typefilter and the PPTDBG class instead.
975 */
976#define KDEBUG_PPT (KDEBUG_ENABLE_PPT)
977#define KDEBUG_COMMON (KDEBUG_ENABLE_TRACE | KDEBUG_ENABLE_PPT)
978
979/*
980 * The kernel debug configuration level. These values control which events are
981 * compiled in under different build configurations.
982 *
983 * Infer the supported kernel debug event level from config option. Use
984 * (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) as a guard to protect unaudited debug
985 * code.
316670eb
A
986 */
987#define KDEBUG_LEVEL_NONE 0
988#define KDEBUG_LEVEL_IST 1
989#define KDEBUG_LEVEL_STANDARD 2
990#define KDEBUG_LEVEL_FULL 3
991
992#if NO_KDEBUG
3e170ce0 993#define KDEBUG_LEVEL KDEBUG_LEVEL_NONE
316670eb
A
994#elif IST_KDEBUG
995#define KDEBUG_LEVEL KDEBUG_LEVEL_IST
3e170ce0 996 // currently configured for the iOS release kernel
316670eb
A
997#elif KDEBUG
998#define KDEBUG_LEVEL KDEBUG_LEVEL_FULL
999#else
1000#define KDEBUG_LEVEL KDEBUG_LEVEL_STANDARD
39037602
A
1001/*
1002 * Currently, all other kernel configurations (development, etc) build with
1003 * KDEBUG_LEVEL_STANDARD. As a result, KERNEL_DEBUG_CONSTANT*() are on by
1004 * default but KERNEL_DEBUG*() are not.
1005 */
316670eb
A
1006#endif
1007
316670eb 1008#ifdef XNU_KERNEL_PRIVATE
39037602
A
1009#define KDBG_IMPROBABLE __improbable
1010#else
1011#define KDBG_IMPROBABLE
1012#endif
fe8ab488 1013
39037602
A
1014/*
1015 * KERNEL_DEBUG_CONSTANT_FILTERED events are omitted from tracing unless they
1016 * are explicitly requested in the typefilter. They are not emitted when
1017 * tracing without a typefilter.
1018 */
1019#if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
1020#define KERNEL_DEBUG_CONSTANT_FILTERED(x, a, b, c, d, ...) \
1021 do { \
1022 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1023 kernel_debug_filtered((x), (uintptr_t)(a), (uintptr_t)(b), \
1024 (uintptr_t)(c), (uintptr_t)(d)); \
1025 } \
1026 } while (0)
1027#else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
1028#define KERNEL_DEBUG_CONSTANT_FILTERED(type, x, a, b, c, d, ...) do {} while (0)
1029#endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
0b4e3aa0 1030
39037602
A
1031#if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
1032#define KERNEL_DEBUG_CONSTANT(x, a, b, c, d, e) \
1033 do { \
1034 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1035 kernel_debug((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \
1036 (uintptr_t)(d),(uintptr_t)(e)); \
1037 } \
1038 } while (0)
fe8ab488 1039
39037602
A
1040/*
1041 * DO NOT USE THIS MACRO -- it breaks fundamental assumptions about ktrace and
1042 * is only meant to be used by the pthread kext and other points in the kernel
1043 * where the thread ID must be provided explicitly.
1044 */
1045#define KERNEL_DEBUG_CONSTANT1(x, a, b, c, d, e) \
1046 do { \
1047 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1048 kernel_debug1((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \
1049 (uintptr_t)(d), (uintptr_t)(e)); \
1050 } \
1051 } while (0)
1052
1053#define KERNEL_DEBUG_EARLY(x, a, b, c, d) \
1054 do { \
1055 kernel_debug_early((uint32_t)(x), (uintptr_t)(a), (uintptr_t)(b), \
1056 (uintptr_t)(c), (uintptr_t)(d)); \
1057 } while (0)
316670eb 1058#else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
39037602
A
1059#define KERNEL_DEBUG_CONSTANT(x, a, b, c, d, e) do {} while (0)
1060#define KERNEL_DEBUG_CONSTANT1(x, a, b, c, d, e) do {} while (0)
1061#define KERNEL_DEBUG_EARLY(x, a, b, c, d) do {} while (0)
316670eb
A
1062#endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
1063
39037602
A
1064/*
1065 * KERNEL_DEBUG_CONSTANT_IST (in-system trace) events provide an audited subset
1066 * of tracepoints for userland system tracing tools. This tracing level was
1067 * created by 8857227 to protect fairplayd and other PT_DENY_ATTACH processes.
1068 * It has two effects: only KERNEL_DEBUG_CONSTANT_IST() traces are emitted and
1069 * any PT_DENY_ATTACH processes will only emit basic traces as defined by the
1070 * kernel_debug_filter() routine.
1071 */
1072#define KERNEL_DEBUG_CONSTANT_RELEASE(x, a, b, c, d, e) \
1073 KERNEL_DEBUG_CONSTANT_IST(~KDEBUG_ENABLE_PPT, x, a, b, c, d, 0)
3e170ce0 1074
39037602
A
1075#if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST)
1076#define KERNEL_DEBUG_CONSTANT_IST(type, x, a, b, c, d, e) \
1077 do { \
1078 if (KDBG_IMPROBABLE(kdebug_enable & (type))) { \
1079 kernel_debug((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \
1080 (uintptr_t)(d), (uintptr_t)(e)); \
1081 } \
1082 } while (0)
1083#else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
1084#define KERNEL_DEBUG_CONSTANT_IST(type, x, a, b, c, d, e) do {} while (0)
1085#endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
3e170ce0 1086
39037602
A
1087#if NO_KDEBUG
1088#define __kdebug_constant_only __unused
1089#endif
3e170ce0
A
1090
1091/*
39037602 1092 * KERNEL_DEBUG events are only traced for DEBUG kernels.
316670eb 1093 */
39037602
A
1094#define KERNEL_DEBUG_CONSTANT_DEBUG(x, a, b, c, d, e) \
1095 KERNEL_DEBUG(x, a, b, c, d, e)
1096
1097#if (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL)
1098#define __kdebug_only
1099
1100#define KERNEL_DEBUG(x, a, b, c, d, e) \
1101 do { \
1102 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1103 kernel_debug((uint32_t)(x), (uintptr_t)(a), (uintptr_t)(b), \
1104 (uintptr_t)(c), (uintptr_t)(d), (uintptr_t)(e)); \
1105 } \
1106 } while (0)
2d21ac55 1107
316670eb 1108/*
39037602 1109 * DO NOT USE THIS MACRO -- see warning above for KERNEL_DEBUG_CONSTANT1.
316670eb 1110 */
39037602
A
1111#define KERNEL_DEBUG1(x, a, b, c, d, e) \
1112 do { \
1113 if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \
1114 kernel_debug1((uint32_t)(x), (uintptr_t)(a), (uintptr_t)(b), \
1115 (uintptr_t)(c), (uintptr_t)(d), (uintptr_t)(e)); \
1116 } \
1117 } while (0)
3e170ce0 1118
39037602
A
1119#else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
1120#define __kdebug_only __unused
1121
1122#define KERNEL_DEBUG(x,a,b,c,d,e) do {} while (0)
1123#define KERNEL_DEBUG1(x,a,b,c,d,e) do {} while (0)
1124#endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
1125
1126
1127extern void kernel_debug(
1128 uint32_t debugid,
1129 uintptr_t arg1,
1130 uintptr_t arg2,
1131 uintptr_t arg3,
1132 uintptr_t arg4,
1133 uintptr_t arg5);
1134
1135extern void kernel_debug1(
1136 uint32_t debugid,
1137 uintptr_t arg1,
1138 uintptr_t arg2,
1139 uintptr_t arg3,
1140 uintptr_t arg4,
1141 uintptr_t arg5);
1142
1143extern void kernel_debug_filtered(
1144 uint32_t debugid,
1145 uintptr_t arg1,
1146 uintptr_t arg2,
1147 uintptr_t arg3,
1148 uintptr_t arg4);
1149
1150extern void kernel_debug_early(
1151 uint32_t debugid,
1152 uintptr_t arg1,
1153 uintptr_t arg2,
1154 uintptr_t arg3,
1155 uintptr_t arg4);
1156
1157/*
1158 * EnergyTracing macros.
1159 */
1160
1161#if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST)
3e170ce0 1162// whether to bother calculating EnergyTracing inputs
39037602 1163// could change in future to see if DBG_ENERGYTRACE is active
3e170ce0
A
1164#define ENTR_SHOULDTRACE kdebug_enable
1165// encode logical EnergyTracing into 32/64 KDebug trace
1166#define ENTR_KDTRACE(component, opcode, lifespan, id, quality, value) \
1167do { \
1168 uint32_t kdcode__; \
1169 uintptr_t highval__, lowval__, mask__ = 0xffffffff; \
1170 kdcode__ = KDBG_CODE(DBG_ENERGYTRACE,component,opcode)|(lifespan); \
1171 highval__ = ((value) >> 32) & mask__; \
1172 lowval__ = (value) & mask__; \
1173 ENTR_KDTRACEFUNC(kdcode__, id, quality, highval__, lowval__); \
1174} while(0)
1175
1176/*
1177 Trace the association of two existing activations.
1178
1179 An association is traced as a modification to the parent activation.
1180 In order to fit the sub-activation's component, activation code, and
1181 activation ID into a kdebug tracepoint, the arguments that would hold
1182 the value are left separate, and one stores the component and opcode
1183 of the sub-activation, while the other stores the pointer-sized
1184 activation ID.
1185
1186 arg2 arg3 arg4
1187 +-----------------+ +~+----+----+--------+ +----------+
1188 |kEnTrModAssociate| | | | | | | |
1189 +-----------------+ +~+----+----+--------+ +----------+
1190 8-bits unused sub-activation ID
1191 8-bit sub-component
1192 16-bit sub-opcode
1193
1194*/
1195#define kEnTrModAssociate (1 << 28)
1196#define ENTR_KDASSOCIATE(par_comp, par_opcode, par_act_id, \
1197 sub_comp, sub_opcode, sub_act_id) \
1198do { \
1199 unsigned sub_compcode = ((unsigned)sub_comp << 16) | sub_opcode; \
1200 ENTR_KDTRACEFUNC(KDBG_CODE(DBG_ENERGYTRACE,par_comp,par_opcode), \
1201 par_act_id, kEnTrModAssociate, sub_compcode, \
1202 sub_act_id); \
1203} while(0)
1204
316670eb 1205#else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
3e170ce0 1206
3e170ce0
A
1207#define ENTR_SHOULDTRACE FALSE
1208#define ENTR_KDTRACE(component, opcode, lifespan, id, quality, value) \
1209 do {} while (0)
1210#define ENTR_KDASSOCIATE(par_comp, par_opcode, par_act_id, \
1211 sub_comp, sub_opcode, sub_act_id) \
1212 do {} while (0)
1213
316670eb
A
1214#endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
1215
3e170ce0
A
1216#ifdef KERNEL_PRIVATE
1217/*
1218 * kernel_debug_string provides the same functionality as the
1219 * kdebug_trace_string syscall as a KPI. str_id is an in/out
1220 * parameter that, if it's pointing to a string ID of 0, will
1221 * receive a generated ID. If it provides a value in str_id,
1222 * then that will be used, instead.
1223 *
1224 * Returns an errno indicating the type of failure.
1225 */
1226extern int
1227kernel_debug_string(uint32_t debugid, uint64_t *str_id, const char *str);
3e170ce0 1228
39037602
A
1229/*
1230 * kernel_debug_disable disables event logging, but leaves any buffers
1231 * intact.
1232 */
1233extern void kernel_debug_disable(void);
1234#endif
1c79356b 1235
39037602
A
1236/*
1237 * Bits set in the comm page for kdebug.
1238 */
1239#define KDEBUG_COMMPAGE_ENABLE_TRACE 0x1
1240#define KDEBUG_COMMPAGE_ENABLE_TYPEFILTER 0x2 /* Forced to false if ENABLE_TRACE is 0 */
3e170ce0
A
1241
1242// for EnergyTracing user space & clients
1243#define kEnTrCompKernel 2
1244
1245/*
1246 EnergyTracing opcodes
1247
1248 Activations use DBG_FUNC_START/END.
1249 Events are DBG_FUNC_NONE.
1250 */
1251
1252/* Socket reads and writes are uniquely identified by the (sanitized)
1253 pointer to the socket struct in question. To associate this address
1254 with the user space file descriptor, we have a socket activation with
1255 the FD as its identifier and the socket struct pointer as its value.
1256*/
1257#define kEnTrActKernSocket 1
1258#define kEnTrActKernSockRead 2
1259#define kEnTrActKernSockWrite 3
1260
1261#define kEnTrActKernPoll 10
1262#define kEnTrActKernSelect 11
1263#define kEnTrActKernKQWait 12
1264
1265// events
1266#define kEnTrEvUnblocked 256
1267
1268// EnergyTracing flags (the low-order 16 bits of 'quality')
1269#define kEnTrFlagNonBlocking 1 << 0
1270#define kEnTrFlagNoWork 1 << 1
1271
1272// and now the internal mechanism
b0d623f7 1273#ifdef KERNEL_PRIVATE
3e170ce0
A
1274
1275// 20452597 requests that the trace macros not take an argument it throws away
1276#define KERNEL_DBG_IST_SANE(x, a, b, c, d) \
1277 KERNEL_DEBUG_CONSTANT_IST(KDEBUG_TRACE, x, a, b, c, d, \
1278 0 /*__unused in kernel_debug()*/)
1279#define ENTR_KDTRACEFUNC KERNEL_DBG_IST_SANE
1280
1281// value is int64_t, quality is uint32_t
1282#define KERNEL_ENERGYTRACE(opcode, lifespan, id, quality, value) \
1283 ENTR_KDTRACE(kEnTrCompKernel, opcode, lifespan, id, \
1284 quality, value)
1285#define KERNEL_ENTR_ASSOCIATE(par_opcode, par_act_id, sub_opcode, sub_act_id) \
1286 ENTR_KDASSOCIATE(kEnTrCompKernel, par_opcode, par_act_id, \
1287 kEnTrCompKernel, sub_opcode, sub_act_id)
1288
1289// end EnergyTracing
1290
1291
6d2010ae 1292#include <mach/boolean.h>
39236c6e
A
1293
1294#define NUMPARMS 23
1295
b0d623f7 1296struct proc;
39236c6e 1297
39037602
A
1298extern boolean_t kdebug_debugid_enabled(uint32_t debugid);
1299extern uint32_t kdebug_commpage_state(void);
39236c6e 1300extern void kdebug_lookup_gen_events(long *dbg_parms, int dbg_namelen, void *dp, boolean_t lookup);
b0d623f7
A
1301extern void kdbg_trace_data(struct proc *proc, long *arg_pid);
1302
1303extern void kdbg_trace_string(struct proc *proc, long *arg1, long *arg2, long *arg3, long *arg4);
1304
1305extern void kdbg_dump_trace_to_file(const char *);
39037602
A
1306void kdebug_boot_trace(unsigned int n_events, char *filterdesc);
1307void kdebug_trace_start(unsigned int n_events, const char *filterdesc, boolean_t need_map);
6d2010ae
A
1308struct task;
1309extern void kdbg_get_task_name(char*, int, struct task *task);
39037602 1310boolean_t disable_wrap(uint32_t *old_slowcheck, uint32_t *old_flags);
6d2010ae
A
1311void enable_wrap(uint32_t old_slowcheck, boolean_t lostevents);
1312void release_storage_unit(int cpu, uint32_t storage_unit);
1313int allocate_storage_unit(int cpu);
1314
3e170ce0
A
1315#define KDBG_CLASS_ENCODE(Class, SubClass) KDBG_EVENTID(Class, SubClass, 0)
1316#define KDBG_CLASS_DECODE(Debugid) (Debugid & KDBG_CSC_MASK)
316670eb 1317
39037602 1318#endif /* KERNEL_PRIVATE */
9bccf70c 1319#endif /* __APPLE_API_UNSTABLE */
1c79356b
A
1320__END_DECLS
1321
39037602 1322#ifdef PRIVATE
9bccf70c 1323#ifdef __APPLE_API_PRIVATE
1c79356b
A
1324/*
1325 * private kernel_debug definitions
1326 */
1327
1328typedef struct {
39037602
A
1329 uint64_t timestamp;
1330 uintptr_t arg1;
1331 uintptr_t arg2;
1332 uintptr_t arg3;
1333 uintptr_t arg4;
1334 uintptr_t arg5; /* the thread ID */
1335 uint32_t debugid;
b0d623f7 1336#if defined(__LP64__)
39037602
A
1337 uint32_t cpuid;
1338 uintptr_t unused;
b0d623f7 1339#endif
1c79356b
A
1340} kd_buf;
1341
b0d623f7 1342#if !defined(__LP64__)
39037602
A
1343#define KDBG_TIMESTAMP_MASK 0x00ffffffffffffffULL
1344#define KDBG_CPU_MASK 0xff00000000000000ULL
1345#define KDBG_CPU_SHIFT 56
b0d623f7
A
1346static inline void
1347kdbg_set_cpu(kd_buf *kp, int cpu)
1348{
3e170ce0 1349 kp->timestamp = (kp->timestamp & KDBG_TIMESTAMP_MASK) |
b0d623f7
A
1350 (((uint64_t) cpu) << KDBG_CPU_SHIFT);
1351}
1352static inline int
1353kdbg_get_cpu(kd_buf *kp)
1354{
1355 return (int) (((kp)->timestamp & KDBG_CPU_MASK) >> KDBG_CPU_SHIFT);
1356}
1357static inline void
6d2010ae 1358kdbg_set_timestamp(kd_buf *kp, uint64_t thetime)
b0d623f7 1359{
6d2010ae 1360 kp->timestamp = thetime & KDBG_TIMESTAMP_MASK;
b0d623f7
A
1361}
1362static inline uint64_t
1363kdbg_get_timestamp(kd_buf *kp)
1364{
1365 return kp->timestamp & KDBG_TIMESTAMP_MASK;
1366}
1367static inline void
6d2010ae 1368kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu)
b0d623f7 1369{
3e170ce0 1370 kp->timestamp = (thetime & KDBG_TIMESTAMP_MASK) |
b0d623f7
A
1371 (((uint64_t) cpu) << KDBG_CPU_SHIFT);
1372}
1373#else
1374#define KDBG_TIMESTAMP_MASK 0xffffffffffffffffULL
1375static inline void
1376kdbg_set_cpu(kd_buf *kp, int cpu)
1377{
1378 kp->cpuid = cpu;
1379}
1380static inline int
1381kdbg_get_cpu(kd_buf *kp)
1382{
1383 return kp->cpuid;
1384}
1385static inline void
6d2010ae 1386kdbg_set_timestamp(kd_buf *kp, uint64_t thetime)
b0d623f7 1387{
6d2010ae 1388 kp->timestamp = thetime;
b0d623f7
A
1389}
1390static inline uint64_t
1391kdbg_get_timestamp(kd_buf *kp)
1392{
1393 return kp->timestamp;
1394}
1395static inline void
6d2010ae 1396kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu)
b0d623f7 1397{
6d2010ae 1398 kdbg_set_timestamp(kp, thetime);
b0d623f7
A
1399 kdbg_set_cpu(kp, cpu);
1400}
1401#endif
1c79356b 1402
39037602
A
1403/*
1404 * 2^16 bits (8 kilobytes), one for each possible class/subclass combination
1405 */
1406#define KDBG_TYPEFILTER_BITMAP_SIZE ((256 * 256) / 8)
1c79356b 1407
39037602
A
1408/*
1409 * Bits for kd_ctrl_page.flags, KERN_KD{D,E}FLAGS.
1410 */
1411#define KDBG_INIT (1U << 0) /* obsolete */
1412/* disable tracing when buffers are full */
1413#define KDBG_NOWRAP (1U << 1)
1414#define KDBG_FREERUN (1U << 2) /* obsolete */
1415/* buffer has wrapped */
1416#define KDBG_WRAPPED (1U << 3)
1417/* flags that are allowed to be set by user space */
1418#define KDBG_USERFLAGS (KDBG_FREERUN | KDBG_NOWRAP | KDBG_INIT)
1419/* only include processes with kdebug bit set in proc */
1420#define KDBG_PIDCHECK (1U << 4)
1421/* thread map is initialized */
1422#define KDBG_MAPINIT (1U << 5)
1423/* exclude processes based on kdebug bit in proc */
1424#define KDBG_PIDEXCLUDE (1U << 6)
1425/* whether the kdebug locks are intialized */
1426#define KDBG_LOCKINIT (1U << 7)
1427/* word size of the kernel */
1428#define KDBG_LP64 (1U << 8)
1429
1430/* bits for kd_ctrl_page.flags and kbufinfo_t.flags */
1431
1432/* only trace events within a range */
1433#define KDBG_RANGECHECK 0x00100000U
1434/* only trace at most 4 types of events, at the code granularity */
1435#define KDBG_VALCHECK 0x00200000U
1436/* check class and subclass against the typefilter */
1437#define KDBG_TYPEFILTER_CHECK 0x00400000U
1438/* kdebug trace buffers are initialized */
1439#define KDBG_BUFINIT 0x80000000U
1440
1441/* bits for the type field of kd_regtype */
1442#define KDBG_CLASSTYPE 0x10000
1443#define KDBG_SUBCLSTYPE 0x20000
1444#define KDBG_RANGETYPE 0x40000
1445#define KDBG_TYPENONE 0x80000
1446#define KDBG_CKTYPES 0xF0000
3e170ce0 1447
39037602
A
1448typedef struct {
1449 unsigned int type;
1450 unsigned int value1;
1451 unsigned int value2;
1452 unsigned int value3;
1453 unsigned int value4;
1c79356b
A
1454} kd_regtype;
1455
39037602
A
1456typedef struct {
1457 /* number of events that can fit in the buffers */
1458 int nkdbufs;
1459 /* set if trace is disabled */
1460 int nolog;
1461 /* kd_ctrl_page.flags */
1462 unsigned int flags;
1463 /* number of threads in thread map */
1464 int nkdthreads;
1465 /* the owning pid */
1466 int bufid;
1c79356b
A
1467} kbufinfo_t;
1468
b0d623f7 1469typedef struct {
39037602
A
1470 /* the thread ID */
1471 uintptr_t thread;
1472 /* 0 for invalid, otherwise the PID (or 1 for kernel_task) */
1473 int valid;
1474 /* the name of the process owning the thread */
1475 char command[20];
1c79356b
A
1476} kd_threadmap;
1477
39236c6e 1478typedef struct {
39037602
A
1479 uint32_t version_no;
1480 uint32_t cpu_count;
39236c6e
A
1481} kd_cpumap_header;
1482
1483/* cpumap flags */
1484#define KDBG_CPUMAP_IS_IOP 0x1
1485
1486typedef struct {
39037602
A
1487 uint32_t cpu_id;
1488 uint32_t flags;
1489 char name[8];
39236c6e
A
1490} kd_cpumap;
1491
1492/*
1493 * TRACE file formats...
1494 *
1495 * RAW_VERSION0
1496 *
1497 * uint32_t #threadmaps
1498 * kd_threadmap[]
1499 * kd_buf[]
1500 *
1501 * RAW_VERSION1
1502 *
1503 * RAW_header, with version_no set to RAW_VERSION1
1504 * kd_threadmap[]
1505 * Empty space to pad alignment to the nearest page boundary.
1506 * kd_buf[]
1507 *
1508 * RAW_VERSION1+
1509 *
1510 * RAW_header, with version_no set to RAW_VERSION1
1511 * kd_threadmap[]
1512 * kd_cpumap_header, with version_no set to RAW_VERSION1
1513 * kd_cpumap[]
1514 * Empty space to pad alignment to the nearest page boundary.
1515 * kd_buf[]
1516 *
1517 * V1+ implementation details...
1518 *
1519 * It would have been nice to add the cpumap data "correctly", but there were
1520 * several obstacles. Existing code attempts to parse both V1 and V0 files.
1521 * Due to the fact that V0 has no versioning or header, the test looks like
1522 * this:
1523 *
1524 * // Read header
1525 * if (header.version_no != RAW_VERSION1) { // Assume V0 }
1526 *
1527 * If we add a VERSION2 file format, all existing code is going to treat that
1528 * as a VERSION0 file when reading it, and crash terribly when trying to read
1529 * RAW_VERSION2 threadmap entries.
1530 *
1531 * To differentiate between a V1 and V1+ file, read as V1 until you reach
1532 * the padding bytes. Then:
1533 *
1534 * boolean_t is_v1plus = FALSE;
1535 * if (padding_bytes >= sizeof(kd_cpumap_header)) {
1536 * kd_cpumap_header header = // read header;
1537 * if (header.version_no == RAW_VERSION1) {
1538 * is_v1plus = TRUE;
1539 * }
1540 * }
1541 *
1542 */
6d2010ae
A
1543
1544typedef struct {
1545 int version_no;
1546 int thread_count;
1547 uint64_t TOD_secs;
1548 uint32_t TOD_usecs;
1549} RAW_header;
1550
3e170ce0
A
1551// Version 3 header
1552// The header chunk has the tag 0x00001000 which also serves as a magic word
1553// that identifies the file as a version 3 trace file. The header payload is
1554// a set of fixed fields followed by a variable number of sub-chunks:
1555/*
1556 ____________________________________________________________________________
1557 | Offset | Size | Field |
1558 ----------------------------------------------------------------------------
1559 | 0 | 4 | Tag (0x00001000) |
1560 | 4 | 4 | Sub-tag. Represents the version of the header. |
1561 | 8 | 8 | Length of header payload (40+8x) |
1562 | 16 | 8 | Time base info. Two 32-bit numbers, numer/denom, |
1563 | | | for converting timestamps to nanoseconds. |
1564 | 24 | 8 | Timestamp of trace start. |
1565 | 32 | 8 | Wall time seconds since Unix epoch. |
1566 | | | As returned by gettimeofday(). |
1567 | 40 | 4 | Wall time microseconds. As returned by gettimeofday(). |
1568 | 44 | 4 | Local time zone offset in minutes. ( " ) |
1569 | 48 | 4 | Type of daylight savings time correction to apply. ( " ) |
1570 | 52 | 4 | Flags. 1 = 64-bit. Remaining bits should be written |
1571 | | | as 0 and ignored when reading. |
1572 | 56 | 8x | Variable number of sub-chunks. None are required. |
1573 | | | Ignore unknown chunks. |
1574 ----------------------------------------------------------------------------
1575*/
1576// NOTE: The header sub-chunks are considered part of the header chunk,
1577// so they must be included in the header chunk’s length field.
1578// The CPU map is an optional sub-chunk of the header chunk. It provides
1579// information about the CPUs that are referenced from the trace events.
1580typedef struct {
39037602
A
1581 uint32_t tag;
1582 uint32_t sub_tag;
1583 uint64_t length;
1584 uint32_t timebase_numer;
1585 uint32_t timebase_denom;
1586 uint64_t timestamp;
1587 uint64_t walltime_secs;
1588 uint32_t walltime_usecs;
1589 uint32_t timezone_minuteswest;
1590 uint32_t timezone_dst;
1591 uint32_t flags;
1592} __attribute__((packed)) kd_header_v3;
3e170ce0
A
1593
1594typedef struct {
1595 uint32_t tag;
1596 uint32_t sub_tag;
1597 uint64_t length;
39037602 1598} __attribute__((packed)) kd_chunk_header_v3;
3e170ce0 1599
6d2010ae
A
1600#define RAW_VERSION0 0x55aa0000
1601#define RAW_VERSION1 0x55aa0101
3e170ce0 1602#define RAW_VERSION2 0x55aa0200 /* Only used by kperf and Instruments */
39037602 1603#define RAW_VERSION3 0x00001000
3e170ce0
A
1604
1605#define V3_CONFIG 0x00001b00
1606#define V3_CPU_MAP 0x00001c00
1607#define V3_THREAD_MAP 0x00001d00
1608#define V3_RAW_EVENTS 0x00001e00
1609#define V3_NULL_CHUNK 0x00002000
1610
1611// The current version of all kernel managed chunks is 1. The
1612// V3_CURRENT_CHUNK_VERSION is added to ease the simple case
1613// when most/all the kernel managed chunks have the same version.
1614
1615#define V3_CURRENT_CHUNK_VERSION 1
1616#define V3_HEADER_VERSION V3_CURRENT_CHUNK_VERSION
1617#define V3_CPUMAP_VERSION V3_CURRENT_CHUNK_VERSION
1618#define V3_THRMAP_VERSION V3_CURRENT_CHUNK_VERSION
1619#define V3_EVENT_DATA_VERSION V3_CURRENT_CHUNK_VERSION
1620
1621// Apis to support writing v3 chunks in the kernel
1622int kdbg_write_v3_chunk_header_to_buffer(void *buffer, uint32_t tag, uint32_t sub_tag, uint64_t length);
1623int kdbg_write_v3_chunk_to_fd(uint32_t tag, uint32_t sub_tag, uint64_t length, void *payload, uint64_t payload_size, int fd);
6d2010ae 1624
04b8595b
A
1625/* VFS lookup events for serial traces */
1626#define VFS_LOOKUP (FSDBG_CODE(DBG_FSRW,36))
1627#define VFS_LOOKUP_DONE (FSDBG_CODE(DBG_FSRW,39))
1628
39037602 1629#if defined(XNU_KERNEL_PRIVATE) && (DEVELOPMENT || DEBUG)
04b8595b
A
1630#define KDEBUG_MOJO_TRACE 1
1631#endif
1632
9bccf70c 1633#endif /* __APPLE_API_PRIVATE */
39037602 1634#endif /* PRIVATE */
1c79356b
A
1635
1636#endif /* !BSD_SYS_KDEBUG_H */