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