]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 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. | |
8f6c56a5 | 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. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b | 27 | */ |
9bccf70c | 28 | |
1c79356b A |
29 | #ifndef _KERN_DEBUG_H_ |
30 | #define _KERN_DEBUG_H_ | |
31 | ||
91447636 | 32 | #include <sys/cdefs.h> |
2d21ac55 | 33 | #include <stdint.h> |
39236c6e A |
34 | #include <uuid/uuid.h> |
35 | ||
36 | #ifndef XNU_KERNEL_PRIVATE | |
37 | #include <TargetConditionals.h> | |
38 | #endif | |
9bccf70c | 39 | |
b0d623f7 A |
40 | #ifdef __APPLE_API_PRIVATE |
41 | #ifdef __APPLE_API_UNSTABLE | |
42 | ||
43 | struct thread_snapshot { | |
44 | uint32_t snapshot_magic; | |
45 | uint32_t nkern_frames; | |
46 | uint32_t nuser_frames; | |
b0d623f7 | 47 | uint64_t wait_event; |
6d2010ae | 48 | uint64_t continuation; |
b0d623f7 | 49 | uint64_t thread_id; |
6d2010ae A |
50 | uint64_t user_time; |
51 | uint64_t system_time; | |
b0d623f7 | 52 | int32_t state; |
39236c6e | 53 | int32_t priority; // static priority |
316670eb A |
54 | int32_t sched_pri; // scheduled (current) priority |
55 | int32_t sched_flags; // scheduler flags | |
b0d623f7 | 56 | char ss_flags; |
b7266188 A |
57 | } __attribute__ ((packed)); |
58 | ||
59 | struct task_snapshot { | |
60 | uint32_t snapshot_magic; | |
61 | int32_t pid; | |
39236c6e | 62 | uint64_t uniqueid; |
6d2010ae A |
63 | uint64_t user_time_in_terminated_threads; |
64 | uint64_t system_time_in_terminated_threads; | |
39236c6e A |
65 | uint8_t shared_cache_identifier[16]; |
66 | uint64_t shared_cache_slide; | |
67 | uint32_t nloadinfos; | |
6d2010ae A |
68 | int suspend_count; |
69 | int task_size; // pages | |
70 | int faults; // number of page faults | |
71 | int pageins; // number of actual pageins | |
72 | int cow_faults; // number of copy-on-write faults | |
39236c6e | 73 | uint32_t ss_flags; |
b0d623f7 A |
74 | /* We restrict ourselves to a statically defined |
75 | * (current as of 2009) length for the | |
76 | * p_comm string, due to scoping issues (osfmk/bsd and user/kernel | |
77 | * binary compatibility). | |
78 | */ | |
79 | char p_comm[17]; | |
39236c6e A |
80 | uint32_t was_throttled; |
81 | uint32_t did_throttle; | |
82 | uint32_t latency_qos; | |
b0d623f7 A |
83 | } __attribute__ ((packed)); |
84 | ||
39236c6e A |
85 | struct micro_snapshot { |
86 | uint32_t snapshot_magic; | |
87 | uint32_t ms_cpu; /* cpu number this snapshot was recorded on */ | |
88 | uint64_t ms_time; /* time at sample (seconds) */ | |
89 | uint64_t ms_time_microsecs; | |
90 | uint8_t ms_flags; | |
91 | uint16_t ms_opaque_flags; /* managed by external entity, e.g. fdrmicrod */ | |
92 | } __attribute__ ((packed)); | |
6d2010ae | 93 | |
316670eb | 94 | struct mem_and_io_snapshot { |
6d2010ae A |
95 | uint32_t snapshot_magic; |
96 | uint32_t free_pages; | |
97 | uint32_t active_pages; | |
98 | uint32_t inactive_pages; | |
99 | uint32_t purgeable_pages; | |
100 | uint32_t wired_pages; | |
101 | uint32_t speculative_pages; | |
102 | uint32_t throttled_pages; | |
39236c6e A |
103 | uint32_t filebacked_pages; |
104 | uint32_t compressions; | |
105 | uint32_t decompressions; | |
106 | uint32_t compressor_size; | |
316670eb A |
107 | int busy_buffer_count; |
108 | uint32_t pages_wanted; | |
109 | uint32_t pages_reclaimed; | |
110 | uint8_t pages_wanted_reclaimed_valid; // did mach_vm_pressure_monitor succeed? | |
6d2010ae A |
111 | } __attribute__((packed)); |
112 | ||
39236c6e A |
113 | struct stack_snapshot_frame32 { |
114 | uint32_t lr; | |
115 | uint32_t sp; | |
116 | }; | |
316670eb | 117 | |
39236c6e A |
118 | struct stack_snapshot_frame64 { |
119 | uint64_t lr; | |
120 | uint64_t sp; | |
121 | }; | |
122 | ||
123 | struct _dyld_cache_header | |
124 | { | |
125 | char magic[16]; // e.g. "dyld_v0 i386" | |
126 | uint32_t mappingOffset; // file offset to first dyld_cache_mapping_info | |
127 | uint32_t mappingCount; // number of dyld_cache_mapping_info entries | |
128 | uint32_t imagesOffset; // file offset to first dyld_cache_image_info | |
129 | uint32_t imagesCount; // number of dyld_cache_image_info entries | |
130 | uint64_t dyldBaseAddress; // base address of dyld when cache was built | |
131 | uint64_t codeSignatureOffset; // file offset of code signature blob | |
132 | uint64_t codeSignatureSize; // size of code signature blob (zero means to end of file) | |
133 | uint64_t slideInfoOffset; // file offset of kernel slid info | |
134 | uint64_t slideInfoSize; // size of kernel slid info | |
135 | uint64_t localSymbolsOffset; // file offset of where local symbols are stored | |
136 | uint64_t localSymbolsSize; // size of local symbols information | |
137 | uint8_t uuid[16]; // unique value for each shared cache file | |
138 | }; | |
139 | ||
140 | struct dyld_uuid_info_32 { | |
141 | uint32_t imageLoadAddress; /* base address image is mapped at */ | |
142 | uuid_t imageUUID; | |
143 | }; | |
144 | ||
145 | struct dyld_uuid_info_64 { | |
146 | uint64_t imageLoadAddress; /* base address image is mapped at */ | |
147 | uuid_t imageUUID; | |
148 | }; | |
149 | ||
150 | enum micro_snapshot_flags { | |
151 | kInterruptRecord = 0x1, | |
152 | kTimerArmingRecord = 0x2, | |
153 | kUserMode = 0x4, /* interrupted usermode, or armed by usermode */ | |
154 | }; | |
155 | ||
156 | /* | |
157 | * Flags used in the following assortment of snapshots. | |
158 | */ | |
159 | enum generic_snapshot_flags { | |
160 | kUser64_p = 0x1, | |
161 | kKernel64_p = 0x2 | |
162 | }; | |
163 | ||
164 | enum task_snapshot_flags { | |
165 | kTaskRsrcFlagged = 0x4, // In the EXC_RESOURCE danger zone? | |
166 | kTerminatedSnapshot = 0x8, | |
167 | kPidSuspended = 0x10, // true for suspended task | |
168 | kFrozen = 0x20, // true for hibernated task (along with pidsuspended) | |
169 | kTaskDarwinBG = 0x40, | |
170 | kTaskExtDarwinBG = 0x80, | |
171 | kTaskVisVisible = 0x100, | |
172 | kTaskVisNonvisible = 0x200, | |
173 | kTaskIsForeground = 0x400, | |
174 | kTaskIsBoosted = 0x800, | |
175 | kTaskIsSuppressed = 0x1000, | |
176 | kTaskIsTimerThrottled = 0x2000 /* deprecated */ | |
177 | }; | |
178 | ||
179 | enum thread_snapshot_flags { | |
180 | kHasDispatchSerial = 0x4, | |
181 | kStacksPCOnly = 0x8, /* Stack traces have no frame pointers. */ | |
182 | kThreadDarwinBG = 0x10 /* Thread is darwinbg */ | |
b0d623f7 A |
183 | }; |
184 | ||
316670eb A |
185 | #define VM_PRESSURE_TIME_WINDOW 5 /* seconds */ |
186 | ||
b7266188 | 187 | enum { |
39236c6e A |
188 | STACKSHOT_GET_DQ = 0x01, |
189 | STACKSHOT_SAVE_LOADINFO = 0x02, | |
190 | STACKSHOT_GET_GLOBAL_MEM_STATS = 0x04, | |
191 | STACKSHOT_SAVE_KEXT_LOADINFO = 0x08, | |
192 | STACKSHOT_GET_MICROSTACKSHOT = 0x10, | |
193 | STACKSHOT_GLOBAL_MICROSTACKSHOT_ENABLE = 0x20, | |
194 | STACKSHOT_GLOBAL_MICROSTACKSHOT_DISABLE = 0x40, | |
195 | STACKSHOT_SET_MICROSTACKSHOT_MARK = 0x80, | |
196 | STACKSHOT_SAVE_KERNEL_FRAMES_ONLY = 0x100, | |
197 | STACKSHOT_GET_BOOT_PROFILE = 0x200, | |
b7266188 A |
198 | }; |
199 | ||
316670eb A |
200 | #define STACKSHOT_THREAD_SNAPSHOT_MAGIC 0xfeedface |
201 | #define STACKSHOT_TASK_SNAPSHOT_MAGIC 0xdecafbad | |
202 | #define STACKSHOT_MEM_AND_IO_SNAPSHOT_MAGIC 0xbfcabcde | |
39236c6e | 203 | #define STACKSHOT_MICRO_SNAPSHOT_MAGIC 0x31c54011 |
b0d623f7 A |
204 | |
205 | #endif /* __APPLE_API_UNSTABLE */ | |
206 | #endif /* __APPLE_API_PRIVATE */ | |
207 | ||
91447636 | 208 | #ifdef KERNEL_PRIVATE |
1c79356b A |
209 | |
210 | extern unsigned int systemLogDiags; | |
593a1d5f | 211 | extern char debug_buf[]; |
b7266188 | 212 | extern unsigned int debug_boot_arg; |
39236c6e A |
213 | extern unsigned char *kernel_uuid; |
214 | extern char kernel_uuid_string[]; | |
1c79356b A |
215 | |
216 | #ifdef MACH_KERNEL_PRIVATE | |
217 | ||
218 | extern unsigned int halt_in_debugger; | |
219 | ||
220 | extern unsigned int switch_debugger; | |
221 | ||
222 | extern unsigned int current_debugger; | |
223 | #define NO_CUR_DB 0x0 | |
224 | #define KDP_CUR_DB 0x1 | |
225 | #define KDB_CUR_DB 0x2 | |
226 | ||
6d2010ae | 227 | extern unsigned int active_debugger; |
1c79356b | 228 | extern unsigned int debug_mode; |
593a1d5f | 229 | extern unsigned int disable_debug_output; |
9bccf70c | 230 | |
6d2010ae A |
231 | extern unsigned int panicDebugging; |
232 | extern unsigned int logPanicDataToScreen; | |
1c79356b A |
233 | |
234 | extern int db_run_mode; | |
235 | ||
236 | /* modes the system may be running in */ | |
237 | ||
238 | #define STEP_NONE 0 | |
239 | #define STEP_ONCE 1 | |
240 | #define STEP_RETURN 2 | |
241 | #define STEP_CALLT 3 | |
242 | #define STEP_CONTINUE 4 | |
243 | #define STEP_INVISIBLE 5 | |
244 | #define STEP_COUNT 6 | |
245 | #define STEP_TRACE 7 /* Show all calls to functions and returns */ | |
246 | ||
91447636 A |
247 | extern const char *panicstr; |
248 | extern volatile unsigned int nestedpanic; | |
2d21ac55 | 249 | extern int unsigned long panic_caller; |
1c79356b | 250 | |
9bccf70c A |
251 | extern char *debug_buf_ptr; |
252 | extern unsigned int debug_buf_size; | |
253 | ||
254 | extern void debug_log_init(void); | |
255 | extern void debug_putc(char); | |
256 | ||
91447636 A |
257 | extern void panic_init(void); |
258 | ||
2d21ac55 A |
259 | int packA(char *inbuf, uint32_t length, uint32_t buflen); |
260 | void unpackA(char *inbuf, uint32_t length); | |
261 | ||
262 | void panic_display_system_configuration(void); | |
c910b4d9 | 263 | void panic_display_zprint(void); |
39236c6e | 264 | void panic_display_kernel_aslr(void); |
6d2010ae A |
265 | #if CONFIG_ZLEAKS |
266 | void panic_display_ztrace(void); | |
267 | #endif /* CONFIG_ZLEAKS */ | |
1c79356b A |
268 | #endif /* MACH_KERNEL_PRIVATE */ |
269 | ||
270 | #define DB_HALT 0x1 | |
271 | #define DB_PRT 0x2 | |
272 | #define DB_NMI 0x4 | |
273 | #define DB_KPRT 0x8 | |
274 | #define DB_KDB 0x10 | |
275 | #define DB_SLOG 0x20 | |
9bccf70c A |
276 | #define DB_ARP 0x40 |
277 | #define DB_KDP_BP_DIS 0x80 | |
278 | #define DB_LOG_PI_SCRN 0x100 | |
55e303ae | 279 | #define DB_KDP_GETC_ENA 0x200 |
9bccf70c | 280 | |
b0d623f7 A |
281 | #define DB_KERN_DUMP_ON_PANIC 0x400 /* Trigger core dump on panic*/ |
282 | #define DB_KERN_DUMP_ON_NMI 0x800 /* Trigger core dump on NMI */ | |
283 | #define DB_DBG_POST_CORE 0x1000 /*Wait in debugger after NMI core */ | |
284 | #define DB_PANICLOG_DUMP 0x2000 /* Send paniclog on panic,not core*/ | |
285 | #define DB_REBOOT_POST_CORE 0x4000 /* Attempt to reboot after | |
286 | * post-panic crashdump/paniclog | |
287 | * dump. | |
288 | */ | |
39236c6e | 289 | #define DB_NMI_BTN_ENA 0x8000 /* Enable button to directly trigger NMI */ |
91447636 | 290 | |
b0d623f7 A |
291 | #if DEBUG |
292 | /* | |
293 | * For the DEBUG kernel, support the following: | |
294 | * sysctl -w debug.kprint_syscall=<syscall_mask> | |
295 | * sysctl -w debug.kprint_syscall_process=<p_comm> | |
296 | * <syscall_mask> should be an OR of the masks below | |
297 | * for UNIX, MACH, MDEP, or IPC. This debugging aid | |
298 | * assumes the task/process is locked/wired and will | |
299 | * not go away during evaluation. If no process is | |
300 | * specified, all processes will be traced | |
301 | */ | |
302 | extern int debug_kprint_syscall; | |
303 | extern int debug_kprint_current_process(const char **namep); | |
304 | #define DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, namep) \ | |
305 | ( (debug_kprint_syscall & (mask)) && debug_kprint_current_process(namep) ) | |
306 | #define DEBUG_KPRINT_SYSCALL_MASK(mask, fmt, args...) do { \ | |
307 | const char *dks_name = NULL; \ | |
308 | if (DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, &dks_name)) { \ | |
309 | kprintf("[%s%s%p]" fmt, dks_name ? dks_name : "", \ | |
310 | dks_name ? "@" : "", current_thread(), args); \ | |
311 | } \ | |
312 | } while (0) | |
313 | #else /* !DEBUG */ | |
314 | #define DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, namep) (0) | |
316670eb | 315 | #define DEBUG_KPRINT_SYSCALL_MASK(mask, fmt, args...) do { } while (0) /* kprintf(fmt, args) */ |
b0d623f7 A |
316 | #endif /* !DEBUG */ |
317 | ||
318 | enum { | |
319 | DEBUG_KPRINT_SYSCALL_UNIX_MASK = 1 << 0, | |
320 | DEBUG_KPRINT_SYSCALL_MACH_MASK = 1 << 1, | |
321 | DEBUG_KPRINT_SYSCALL_MDEP_MASK = 1 << 2, | |
322 | DEBUG_KPRINT_SYSCALL_IPC_MASK = 1 << 3 | |
323 | }; | |
324 | ||
325 | #define DEBUG_KPRINT_SYSCALL_PREDICATE(mask) \ | |
326 | DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, NULL) | |
327 | #define DEBUG_KPRINT_SYSCALL_UNIX(fmt, args...) \ | |
328 | DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_UNIX_MASK,fmt,args) | |
329 | #define DEBUG_KPRINT_SYSCALL_MACH(fmt, args...) \ | |
330 | DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_MACH_MASK,fmt,args) | |
331 | #define DEBUG_KPRINT_SYSCALL_MDEP(fmt, args...) \ | |
332 | DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_MDEP_MASK,fmt,args) | |
333 | #define DEBUG_KPRINT_SYSCALL_IPC(fmt, args...) \ | |
334 | DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_IPC_MASK,fmt,args) | |
593a1d5f | 335 | |
91447636 A |
336 | #endif /* KERNEL_PRIVATE */ |
337 | ||
338 | __BEGIN_DECLS | |
339 | ||
2d21ac55 | 340 | extern void panic(const char *string, ...) __printflike(1,2); |
b0d623f7 A |
341 | |
342 | #if KERNEL_PRIVATE | |
343 | void _consume_panic_args(int, ...); | |
316670eb | 344 | void panic_context(unsigned int reason, void *ctx, const char *string, ...); |
b0d623f7 A |
345 | #endif |
346 | ||
2d21ac55 | 347 | #if CONFIG_NO_PANIC_STRINGS |
b0d623f7 A |
348 | #if KERNEL_PRIVATE |
349 | #define panic_plain(x, ...) _consume_panic_args( 0, ## __VA_ARGS__ ) | |
350 | #define panic(x, ...) _consume_panic_args( 0, ## __VA_ARGS__ ) | |
351 | #else | |
2d21ac55 A |
352 | #define panic_plain(...) (panic)((char *)0) |
353 | #define panic(...) (panic)((char *)0) | |
b0d623f7 | 354 | #endif |
2d21ac55 A |
355 | #else /* CONFIGS_NO_PANIC_STRINGS */ |
356 | #define panic_plain(ex, ...) \ | |
357 | (panic)(ex, ## __VA_ARGS__) | |
358 | #define __STRINGIFY(x) #x | |
359 | #define LINE_NUMBER(x) __STRINGIFY(x) | |
360 | #define PANIC_LOCATION __FILE__ ":" LINE_NUMBER(__LINE__) | |
361 | #define panic(ex, ...) \ | |
362 | (panic)(# ex "@" PANIC_LOCATION, ## __VA_ARGS__) | |
363 | #endif /* CONFIGS_NO_PANIC_STRINGS */ | |
364 | ||
365 | void populate_model_name(char *); | |
366 | unsigned panic_active(void); | |
91447636 | 367 | __END_DECLS |
1c79356b A |
368 | |
369 | #endif /* _KERN_DEBUG_H_ */ |