Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __LINUX_STACKTRACE_H
0003 #define __LINUX_STACKTRACE_H
0004 
0005 #include <linux/types.h>
0006 #include <asm/errno.h>
0007 
0008 struct task_struct;
0009 struct pt_regs;
0010 
0011 #ifdef CONFIG_ARCH_STACKWALK
0012 
0013 /**
0014  * stack_trace_consume_fn - Callback for arch_stack_walk()
0015  * @cookie: Caller supplied pointer handed back by arch_stack_walk()
0016  * @addr:   The stack entry address to consume
0017  *
0018  * Return:  True, if the entry was consumed or skipped
0019  *      False, if there is no space left to store
0020  */
0021 typedef bool (*stack_trace_consume_fn)(void *cookie, unsigned long addr);
0022 /**
0023  * arch_stack_walk - Architecture specific function to walk the stack
0024  * @consume_entry:  Callback which is invoked by the architecture code for
0025  *          each entry.
0026  * @cookie:     Caller supplied pointer which is handed back to
0027  *          @consume_entry
0028  * @task:       Pointer to a task struct, can be NULL
0029  * @regs:       Pointer to registers, can be NULL
0030  *
0031  * ============ ======= ============================================
0032  * task         regs
0033  * ============ ======= ============================================
0034  * task     NULL    Stack trace from task (can be current)
0035  * current  regs    Stack trace starting on regs->stackpointer
0036  * ============ ======= ============================================
0037  */
0038 void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
0039              struct task_struct *task, struct pt_regs *regs);
0040 
0041 /**
0042  * arch_stack_walk_reliable - Architecture specific function to walk the
0043  *                stack reliably
0044  *
0045  * @consume_entry:  Callback which is invoked by the architecture code for
0046  *          each entry.
0047  * @cookie:     Caller supplied pointer which is handed back to
0048  *          @consume_entry
0049  * @task:       Pointer to a task struct, can be NULL
0050  *
0051  * This function returns an error if it detects any unreliable
0052  * features of the stack. Otherwise it guarantees that the stack
0053  * trace is reliable.
0054  *
0055  * If the task is not 'current', the caller *must* ensure the task is
0056  * inactive and its stack is pinned.
0057  */
0058 int arch_stack_walk_reliable(stack_trace_consume_fn consume_entry, void *cookie,
0059                  struct task_struct *task);
0060 
0061 void arch_stack_walk_user(stack_trace_consume_fn consume_entry, void *cookie,
0062               const struct pt_regs *regs);
0063 #endif /* CONFIG_ARCH_STACKWALK */
0064 
0065 #ifdef CONFIG_STACKTRACE
0066 void stack_trace_print(const unsigned long *trace, unsigned int nr_entries,
0067                int spaces);
0068 int stack_trace_snprint(char *buf, size_t size, const unsigned long *entries,
0069             unsigned int nr_entries, int spaces);
0070 unsigned int stack_trace_save(unsigned long *store, unsigned int size,
0071                   unsigned int skipnr);
0072 unsigned int stack_trace_save_tsk(struct task_struct *task,
0073                   unsigned long *store, unsigned int size,
0074                   unsigned int skipnr);
0075 unsigned int stack_trace_save_regs(struct pt_regs *regs, unsigned long *store,
0076                    unsigned int size, unsigned int skipnr);
0077 unsigned int stack_trace_save_user(unsigned long *store, unsigned int size);
0078 unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_entries);
0079 
0080 #ifndef CONFIG_ARCH_STACKWALK
0081 /* Internal interfaces. Do not use in generic code */
0082 struct stack_trace {
0083     unsigned int nr_entries, max_entries;
0084     unsigned long *entries;
0085     unsigned int skip;  /* input argument: How many entries to skip */
0086 };
0087 
0088 extern void save_stack_trace(struct stack_trace *trace);
0089 extern void save_stack_trace_regs(struct pt_regs *regs,
0090                   struct stack_trace *trace);
0091 extern void save_stack_trace_tsk(struct task_struct *tsk,
0092                 struct stack_trace *trace);
0093 extern int save_stack_trace_tsk_reliable(struct task_struct *tsk,
0094                      struct stack_trace *trace);
0095 extern void save_stack_trace_user(struct stack_trace *trace);
0096 #endif /* !CONFIG_ARCH_STACKWALK */
0097 #endif /* CONFIG_STACKTRACE */
0098 
0099 #if defined(CONFIG_STACKTRACE) && defined(CONFIG_HAVE_RELIABLE_STACKTRACE)
0100 int stack_trace_save_tsk_reliable(struct task_struct *tsk, unsigned long *store,
0101                   unsigned int size);
0102 #else
0103 static inline int stack_trace_save_tsk_reliable(struct task_struct *tsk,
0104                         unsigned long *store,
0105                         unsigned int size)
0106 {
0107     return -ENOSYS;
0108 }
0109 #endif
0110 
0111 #endif /* __LINUX_STACKTRACE_H */