Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[linux-2.6-block.git] / include / linux / stacktrace.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
8637c099
IM
2#ifndef __LINUX_STACKTRACE_H
3#define __LINUX_STACKTRACE_H
4
9a92a6ce 5#include <linux/types.h>
e9b98e16 6#include <asm/errno.h>
9a92a6ce 7
897312bd 8struct task_struct;
9c0729dc 9struct pt_regs;
897312bd 10
8637c099 11#ifdef CONFIG_STACKTRACE
a2970421 12void stack_trace_print(const unsigned long *trace, unsigned int nr_entries,
e9b98e16 13 int spaces);
a2970421 14int stack_trace_snprint(char *buf, size_t size, const unsigned long *entries,
e9b98e16
TG
15 unsigned int nr_entries, int spaces);
16unsigned int stack_trace_save(unsigned long *store, unsigned int size,
17 unsigned int skipnr);
18unsigned int stack_trace_save_tsk(struct task_struct *task,
19 unsigned long *store, unsigned int size,
20 unsigned int skipnr);
21unsigned int stack_trace_save_regs(struct pt_regs *regs, unsigned long *store,
22 unsigned int size, unsigned int skipnr);
23unsigned int stack_trace_save_user(unsigned long *store, unsigned int size);
24
25/* Internal interfaces. Do not use in generic code */
214d8ca6
TG
26#ifdef CONFIG_ARCH_STACKWALK
27
28/**
29 * stack_trace_consume_fn - Callback for arch_stack_walk()
30 * @cookie: Caller supplied pointer handed back by arch_stack_walk()
31 * @addr: The stack entry address to consume
214d8ca6
TG
32 *
33 * Return: True, if the entry was consumed or skipped
34 * False, if there is no space left to store
35 */
264c03a2 36typedef bool (*stack_trace_consume_fn)(void *cookie, unsigned long addr);
214d8ca6
TG
37/**
38 * arch_stack_walk - Architecture specific function to walk the stack
39 * @consume_entry: Callback which is invoked by the architecture code for
40 * each entry.
41 * @cookie: Caller supplied pointer which is handed back to
42 * @consume_entry
43 * @task: Pointer to a task struct, can be NULL
44 * @regs: Pointer to registers, can be NULL
45 *
46 * ============ ======= ============================================
47 * task regs
48 * ============ ======= ============================================
49 * task NULL Stack trace from task (can be current)
50 * current regs Stack trace starting on regs->stackpointer
51 * ============ ======= ============================================
52 */
53void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
54 struct task_struct *task, struct pt_regs *regs);
b18adee4
MB
55
56/**
57 * arch_stack_walk_reliable - Architecture specific function to walk the
58 * stack reliably
59 *
60 * @consume_entry: Callback which is invoked by the architecture code for
61 * each entry.
62 * @cookie: Caller supplied pointer which is handed back to
63 * @consume_entry
64 * @task: Pointer to a task struct, can be NULL
65 *
66 * This function returns an error if it detects any unreliable
67 * features of the stack. Otherwise it guarantees that the stack
68 * trace is reliable.
69 *
70 * If the task is not 'current', the caller *must* ensure the task is
71 * inactive and its stack is pinned.
72 */
214d8ca6
TG
73int arch_stack_walk_reliable(stack_trace_consume_fn consume_entry, void *cookie,
74 struct task_struct *task);
b18adee4 75
214d8ca6
TG
76void arch_stack_walk_user(stack_trace_consume_fn consume_entry, void *cookie,
77 const struct pt_regs *regs);
78
79#else /* CONFIG_ARCH_STACKWALK */
8637c099
IM
80struct stack_trace {
81 unsigned int nr_entries, max_entries;
82 unsigned long *entries;
2c34f6f7 83 unsigned int skip; /* input argument: How many entries to skip */
8637c099
IM
84};
85
ab1b6f03 86extern void save_stack_trace(struct stack_trace *trace);
39581062
MH
87extern void save_stack_trace_regs(struct pt_regs *regs,
88 struct stack_trace *trace);
9745512c
AV
89extern void save_stack_trace_tsk(struct task_struct *tsk,
90 struct stack_trace *trace);
af085d90
JP
91extern int save_stack_trace_tsk_reliable(struct task_struct *tsk,
92 struct stack_trace *trace);
02b67518 93extern void save_stack_trace_user(struct stack_trace *trace);
214d8ca6 94#endif /* !CONFIG_ARCH_STACKWALK */
af085d90 95#endif /* CONFIG_STACKTRACE */
8637c099 96
e9b98e16
TG
97#if defined(CONFIG_STACKTRACE) && defined(CONFIG_HAVE_RELIABLE_STACKTRACE)
98int stack_trace_save_tsk_reliable(struct task_struct *tsk, unsigned long *store,
99 unsigned int size);
100#else
101static inline int stack_trace_save_tsk_reliable(struct task_struct *tsk,
102 unsigned long *store,
103 unsigned int size)
104{
105 return -ENOSYS;
106}
107#endif
108
af085d90 109#endif /* __LINUX_STACKTRACE_H */