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