]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/backtrace.h
2 * Copyright (c) 2016-2019 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef KERN_BACKTRACE_H
30 #define KERN_BACKTRACE_H
34 #include <sys/cdefs.h>
41 * @abstract backtrace the current thread's kernel stack
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,
50 * @param bt Clients must provide a buffer in which to store the return
53 * @param btlen Along with the buffer, its length (in terms of uintptr_t) must
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
60 * @return The number of return addresses written to bt is returned. The
61 * function cannot return an error.
63 unsigned int backtrace(uintptr_t *bt
, unsigned int btlen
, bool *was_truncated
)
64 __attribute__((noinline
));
67 * @function backtrace_from
69 * @abstract backtrace the current thread's kernel stack from a frame pointer
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
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.
83 unsigned int backtrace_frame(uintptr_t *bt
, unsigned int btlen
, void *startfp
,
85 __attribute__((noinline
, not_tail_called
));
88 * @function backtrace_interrupted
90 * @abstract backtrace the interrupted context
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
98 unsigned int backtrace_interrupted(uintptr_t *bt
, unsigned int btlen
,
102 * @function backtrace_user
104 * @abstract backtrace the current thread's user space stack
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
111 * @param error The precise error code that occurred is stored here, or 0 if no
114 * @param user64 On success, true is stored here if user space was running in
115 * 64-bit mode, and false is stored otherwise.
117 * @param was_truncated true is stored here if the full stack could not be written
120 * @return Returns the number of frames written to bt.
124 unsigned int backtrace_user(uintptr_t *bt
, unsigned int btlen
, int *error
,
125 bool *user64
, bool *was_truncated
);
128 * @function backtrace_thread_user
130 * @abstract backtrace a given thread's user space stack
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.
136 * @param thread The user thread to backtrace is required.
138 * @see backtrace_user
140 unsigned int backtrace_thread_user(void *thread
, uintptr_t *bt
,
141 unsigned int btlen
, int *error
, bool *user64
, bool *was_truncated
,
142 bool faults_permitted
);
146 #endif /* !defined(KERN_BACKTRACE_H) */