]>
Commit | Line | Data |
---|---|---|
39037602 | 1 | /* |
cb323159 | 2 | * Copyright (c) 2016-2019 Apple Inc. All rights reserved. |
39037602 A |
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 | ||
cb323159 A |
29 | #ifndef KERN_BACKTRACE_H |
30 | #define KERN_BACKTRACE_H | |
39037602 A |
31 | |
32 | #include <stdbool.h> | |
33 | #include <stdint.h> | |
34 | #include <sys/cdefs.h> | |
35 | ||
36 | __BEGIN_DECLS | |
37 | ||
cb323159 A |
38 | /*! |
39 | * @function backtrace | |
40 | * | |
41 | * @abstract backtrace the current thread's kernel stack | |
42 | * | |
43 | * @discussion Backtrace the kernel stack of the current thread, storing up | |
44 | * to btlen return addresses in bt. Returns the number of return addresses | |
45 | * stored and sets was_truncated to true if it is non-NULL and the backtrace was | |
46 | * truncated to fit in the provided space. The backtrace starts at the calling | |
47 | * function. A zero will be stored after the return addresses in the buffer, | |
48 | * if space allows. | |
49 | * | |
50 | * @param bt Clients must provide a buffer in which to store the return | |
51 | * addresses. | |
52 | * | |
53 | * @param btlen Along with the buffer, its length (in terms of uintptr_t) must | |
54 | * also be provided. | |
55 | * | |
56 | * @param was_truncated Optionally, clients can provide a boolean out-parameter | |
57 | * that will be set to true if the backtrace was truncated due to a lack of | |
58 | * buffer space. | |
59 | * | |
60 | * @return The number of return addresses written to bt is returned. The | |
61 | * function cannot return an error. | |
39037602 | 62 | */ |
cb323159 | 63 | unsigned int backtrace(uintptr_t *bt, unsigned int btlen, bool *was_truncated) |
0a7de745 | 64 | __attribute__((noinline)); |
39037602 | 65 | |
cb323159 A |
66 | /*! |
67 | * @function backtrace_from | |
68 | * | |
69 | * @abstract backtrace the current thread's kernel stack from a frame pointer | |
70 | * | |
71 | * @discussion Backtrace the kernel stack of the current thread from the given | |
72 | * frame pointer startfp, storing up to btlen return addresses in bt. Returns | |
73 | * the number of return addresses written and sets trunc to true if trunc is | |
74 | * non-NULL and the backtrace was truncated to fit in the provided space. The | |
75 | * frame pointer provided must point to a valid frame on the current thread's | |
76 | * stack. | |
77 | * | |
78 | * @param startfp The frame pointer to start backtracing from is required, and | |
79 | * must be point to a valid frame on the current thread's stack. | |
80 | * | |
81 | * @seealso backtrace | |
39037602 | 82 | */ |
cb323159 A |
83 | unsigned int backtrace_frame(uintptr_t *bt, unsigned int btlen, void *startfp, |
84 | bool *was_truncated) | |
0a7de745 | 85 | __attribute__((noinline, not_tail_called)); |
39037602 | 86 | |
cb323159 A |
87 | /*! |
88 | * @function backtrace_interrupted | |
89 | * | |
90 | * @abstract backtrace the interrupted context | |
91 | * | |
92 | * @discussion Backtrace the kernel stack of the interrupted thread, storing up | |
93 | * to btlen return addresses in bt. This function must be called from interrupt | |
94 | * context. | |
39037602 | 95 | * |
cb323159 | 96 | * @seealso backtrace |
39037602 | 97 | */ |
cb323159 A |
98 | unsigned int backtrace_interrupted(uintptr_t *bt, unsigned int btlen, |
99 | bool *was_truncated); | |
39037602 | 100 | |
cb323159 A |
101 | /*! |
102 | * @function backtrace_user | |
103 | * | |
104 | * @abstract backtrace the current thread's user space stack | |
105 | * | |
106 | * @discussion Backtrace the user stack of the current thread, storing up to | |
107 | * btlen return addresses in bt. This function cannot be called on a kernel | |
108 | * thread, nor can it be called from interrupt context or with interrupts | |
109 | * disabled. | |
39037602 | 110 | * |
ea3f0419 A |
111 | * @param error The precise error code that occurred is stored here, or 0 if no |
112 | * error occurred. | |
cb323159 A |
113 | * |
114 | * @param user64 On success, true is stored here if user space was running in | |
115 | * 64-bit mode, and false is stored otherwise. | |
116 | * | |
ea3f0419 A |
117 | * @param was_truncated true is stored here if the full stack could not be written |
118 | * to bt. | |
119 | * | |
120 | * @return Returns the number of frames written to bt. | |
cb323159 A |
121 | * |
122 | * @seealso backtrace | |
39037602 | 123 | */ |
ea3f0419 | 124 | unsigned int backtrace_user(uintptr_t *bt, unsigned int btlen, int *error, |
cb323159 | 125 | bool *user64, bool *was_truncated); |
39037602 A |
126 | |
127 | /* | |
cb323159 A |
128 | * @function backtrace_thread_user |
129 | * | |
130 | * @abstract backtrace a given thread's user space stack | |
131 | * | |
132 | * @discussion Backtrace the user stack of the given thread, storing up to btlen | |
133 | * return addresses in bt. This function cannot be called on a kernel thread, | |
134 | * nor can it be called from interrupt context or with interrupts disabled. | |
135 | * | |
136 | * @param thread The user thread to backtrace is required. | |
39037602 | 137 | * |
cb323159 | 138 | * @see backtrace_user |
39037602 | 139 | */ |
ea3f0419 | 140 | unsigned int backtrace_thread_user(void *thread, uintptr_t *bt, |
f427ee49 A |
141 | unsigned int btlen, int *error, bool *user64, bool *was_truncated, |
142 | bool faults_permitted); | |
39037602 A |
143 | |
144 | __END_DECLS | |
145 | ||
cb323159 | 146 | #endif /* !defined(KERN_BACKTRACE_H) */ |