Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Ingo Molnar | 8637c09 | 2006-07-03 00:24:38 -0700 | [diff] [blame] | 2 | #ifndef __LINUX_STACKTRACE_H |
| 3 | #define __LINUX_STACKTRACE_H |
| 4 | |
Joonsoo Kim | 9a92a6c | 2014-12-12 16:55:58 -0800 | [diff] [blame] | 5 | #include <linux/types.h> |
Thomas Gleixner | e9b98e1 | 2019-04-25 11:44:55 +0200 | [diff] [blame] | 6 | #include <asm/errno.h> |
Joonsoo Kim | 9a92a6c | 2014-12-12 16:55:58 -0800 | [diff] [blame] | 7 | |
Andrew Morton | 897312b | 2008-10-03 15:23:41 -0700 | [diff] [blame] | 8 | struct task_struct; |
Soeren Sandmann Pedersen | 9c0729d | 2010-11-05 05:59:39 -0400 | [diff] [blame] | 9 | struct pt_regs; |
Andrew Morton | 897312b | 2008-10-03 15:23:41 -0700 | [diff] [blame] | 10 | |
Ingo Molnar | 8637c09 | 2006-07-03 00:24:38 -0700 | [diff] [blame] | 11 | #ifdef CONFIG_STACKTRACE |
Thomas Gleixner | e9b98e1 | 2019-04-25 11:44:55 +0200 | [diff] [blame] | 12 | void stack_trace_print(unsigned long *trace, unsigned int nr_entries, |
| 13 | int spaces); |
| 14 | int stack_trace_snprint(char *buf, size_t size, unsigned long *entries, |
| 15 | unsigned int nr_entries, int spaces); |
| 16 | unsigned int stack_trace_save(unsigned long *store, unsigned int size, |
| 17 | unsigned int skipnr); |
| 18 | unsigned int stack_trace_save_tsk(struct task_struct *task, |
| 19 | unsigned long *store, unsigned int size, |
| 20 | unsigned int skipnr); |
| 21 | unsigned int stack_trace_save_regs(struct pt_regs *regs, unsigned long *store, |
| 22 | unsigned int size, unsigned int skipnr); |
| 23 | unsigned int stack_trace_save_user(unsigned long *store, unsigned int size); |
| 24 | |
| 25 | /* Internal interfaces. Do not use in generic code */ |
Thomas Gleixner | 214d8ca | 2019-04-25 11:45:21 +0200 | [diff] [blame] | 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 |
| 32 | * @reliable: True when the stack entry is reliable. Required by |
| 33 | * some printk based consumers. |
| 34 | * |
| 35 | * Return: True, if the entry was consumed or skipped |
| 36 | * False, if there is no space left to store |
| 37 | */ |
| 38 | typedef bool (*stack_trace_consume_fn)(void *cookie, unsigned long addr, |
| 39 | bool reliable); |
| 40 | /** |
| 41 | * arch_stack_walk - Architecture specific function to walk the stack |
| 42 | * @consume_entry: Callback which is invoked by the architecture code for |
| 43 | * each entry. |
| 44 | * @cookie: Caller supplied pointer which is handed back to |
| 45 | * @consume_entry |
| 46 | * @task: Pointer to a task struct, can be NULL |
| 47 | * @regs: Pointer to registers, can be NULL |
| 48 | * |
| 49 | * ============ ======= ============================================ |
| 50 | * task regs |
| 51 | * ============ ======= ============================================ |
| 52 | * task NULL Stack trace from task (can be current) |
| 53 | * current regs Stack trace starting on regs->stackpointer |
| 54 | * ============ ======= ============================================ |
| 55 | */ |
| 56 | void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie, |
| 57 | struct task_struct *task, struct pt_regs *regs); |
| 58 | int arch_stack_walk_reliable(stack_trace_consume_fn consume_entry, void *cookie, |
| 59 | struct task_struct *task); |
| 60 | void arch_stack_walk_user(stack_trace_consume_fn consume_entry, void *cookie, |
| 61 | const struct pt_regs *regs); |
| 62 | |
| 63 | #else /* CONFIG_ARCH_STACKWALK */ |
Ingo Molnar | 8637c09 | 2006-07-03 00:24:38 -0700 | [diff] [blame] | 64 | struct stack_trace { |
| 65 | unsigned int nr_entries, max_entries; |
| 66 | unsigned long *entries; |
Andi Kleen | 5a1b399 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 67 | int skip; /* input argument: How many entries to skip */ |
Ingo Molnar | 8637c09 | 2006-07-03 00:24:38 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame] | 70 | extern void save_stack_trace(struct stack_trace *trace); |
Masami Hiramatsu | 3958106 | 2011-06-08 16:09:21 +0900 | [diff] [blame] | 71 | extern void save_stack_trace_regs(struct pt_regs *regs, |
| 72 | struct stack_trace *trace); |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 73 | extern void save_stack_trace_tsk(struct task_struct *tsk, |
| 74 | struct stack_trace *trace); |
Josh Poimboeuf | af085d9 | 2017-02-13 19:42:28 -0600 | [diff] [blame] | 75 | extern int save_stack_trace_tsk_reliable(struct task_struct *tsk, |
| 76 | struct stack_trace *trace); |
Török Edwin | 02b6751 | 2008-11-22 13:28:47 +0200 | [diff] [blame] | 77 | extern void save_stack_trace_user(struct stack_trace *trace); |
Thomas Gleixner | 214d8ca | 2019-04-25 11:45:21 +0200 | [diff] [blame] | 78 | #endif /* !CONFIG_ARCH_STACKWALK */ |
Josh Poimboeuf | af085d9 | 2017-02-13 19:42:28 -0600 | [diff] [blame] | 79 | #endif /* CONFIG_STACKTRACE */ |
Ingo Molnar | 8637c09 | 2006-07-03 00:24:38 -0700 | [diff] [blame] | 80 | |
Thomas Gleixner | e9b98e1 | 2019-04-25 11:44:55 +0200 | [diff] [blame] | 81 | #if defined(CONFIG_STACKTRACE) && defined(CONFIG_HAVE_RELIABLE_STACKTRACE) |
| 82 | int stack_trace_save_tsk_reliable(struct task_struct *tsk, unsigned long *store, |
| 83 | unsigned int size); |
| 84 | #else |
| 85 | static inline int stack_trace_save_tsk_reliable(struct task_struct *tsk, |
| 86 | unsigned long *store, |
| 87 | unsigned int size) |
| 88 | { |
| 89 | return -ENOSYS; |
| 90 | } |
| 91 | #endif |
| 92 | |
Josh Poimboeuf | af085d9 | 2017-02-13 19:42:28 -0600 | [diff] [blame] | 93 | #endif /* __LINUX_STACKTRACE_H */ |