]>
Commit | Line | Data |
---|---|---|
39037602 A |
1 | /* |
2 | * Copyright (c) 2016 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | ||
29 | #ifndef BACKTRACE_H | |
30 | #define BACKTRACE_H | |
31 | ||
32 | #include <stdbool.h> | |
33 | #include <stdint.h> | |
34 | #include <sys/cdefs.h> | |
35 | ||
36 | __BEGIN_DECLS | |
37 | ||
38 | /* | |
39 | * Backtrace the current thread, storing up to max_frames return addresses in | |
40 | * bt. Returns the number of return addresses stored. | |
41 | */ | |
42 | uint32_t backtrace(uintptr_t *bt, uint32_t max_frames) | |
43 | __attribute__((noinline)); | |
44 | ||
45 | /* | |
46 | * Backtrace the current thread starting at the frame pointer start_fp, storing | |
47 | * up to max_frames return addresses in bt. Returns the number of return | |
48 | * addresses stored. | |
49 | */ | |
50 | uint32_t backtrace_frame(uintptr_t *bt, uint32_t max_frames, void *start_frame) | |
51 | __attribute__((noinline,not_tail_called)); | |
52 | ||
53 | /* | |
54 | * Backtrace the kernel stack of the context that was interrupted, storing up | |
55 | * to max_frames return addresses in bt. Returns 0 on success, and non-zero | |
56 | * otherwise. On success, the number of frames written is stored at the value | |
57 | * pointed to by frames_out. | |
58 | * | |
59 | * Must be called from interrupt context. | |
60 | */ | |
61 | uint32_t backtrace_interrupted(uintptr_t *bt, uint32_t max_frames); | |
62 | ||
63 | /* | |
64 | * Backtrace the user stack of the current thread, storing up to max_frames | |
65 | * return addresses in bt. Returns 0 on success, and non-zero otherwise. On | |
66 | * success, the number of frames written is stored at the value pointed to by | |
67 | * frames_out and the value pointed to by user_64_out is set true if the user | |
68 | * space thread was running in 64-bit mode, and false otherwise. | |
69 | * | |
70 | * Must not be called from interrupt context or with interrupts disabled. | |
71 | */ | |
72 | int backtrace_user(uintptr_t *bt, uint32_t max_frames, uint32_t *frames_out, | |
73 | bool *user_64_out); | |
74 | ||
75 | /* | |
76 | * Backtrace the user stack of the given thread, storing up to max_frames return | |
77 | * addresses in bt. Returns 0 on success, and non-zero otherwise. On success, | |
78 | * the number of frames written is stored at the value pointed to by frames_out | |
79 | * and the value pointed to by user_64_out is set true if the user space thread | |
80 | * was running in 64-bit mode, and false otherwise. | |
81 | * | |
82 | * Must not be called from interrupt context or with interrupts disabled. | |
83 | */ | |
84 | int backtrace_thread_user(void *thread, uintptr_t *bt, uint32_t max_frames, | |
85 | uint32_t *frames_out, bool *user_64_out); | |
86 | ||
87 | __END_DECLS | |
88 | ||
89 | #endif /* !defined(BACKTRACE_H) */ |