1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
22d7c11bfSCatalin Marinas #ifndef __ASM_STACKTRACE_H
32d7c11bfSCatalin Marinas #define __ASM_STACKTRACE_H
42d7c11bfSCatalin Marinas
59865f1d4SNikolay Borisov #include <asm/ptrace.h>
6fed240d9SMasami Hiramatsu #include <linux/llist.h>
79865f1d4SNikolay Borisov
82d7c11bfSCatalin Marinas struct stackframe {
99865f1d4SNikolay Borisov /*
109865f1d4SNikolay Borisov * FP member should hold R7 when CONFIG_THUMB2_KERNEL is enabled
119865f1d4SNikolay Borisov * and R11 otherwise.
129865f1d4SNikolay Borisov */
132d7c11bfSCatalin Marinas unsigned long fp;
142d7c11bfSCatalin Marinas unsigned long sp;
152d7c11bfSCatalin Marinas unsigned long lr;
162d7c11bfSCatalin Marinas unsigned long pc;
17538b9265SArd Biesheuvel
18538b9265SArd Biesheuvel /* address of the LR value on the stack */
19538b9265SArd Biesheuvel unsigned long *lr_addr;
20fed240d9SMasami Hiramatsu #ifdef CONFIG_KRETPROBES
21fed240d9SMasami Hiramatsu struct llist_node *kr_cur;
22fed240d9SMasami Hiramatsu struct task_struct *tsk;
23fed240d9SMasami Hiramatsu #endif
24752ec621SLi Huafei #ifdef CONFIG_UNWINDER_FRAME_POINTER
25752ec621SLi Huafei bool ex_frame;
26752ec621SLi Huafei #endif
272d7c11bfSCatalin Marinas };
282d7c11bfSCatalin Marinas
on_thread_stack(void)29*2335c9cbSJinjie Ruan static inline bool on_thread_stack(void)
30*2335c9cbSJinjie Ruan {
31*2335c9cbSJinjie Ruan unsigned long delta = current_stack_pointer ^ (unsigned long)current->stack;
32*2335c9cbSJinjie Ruan
33*2335c9cbSJinjie Ruan return delta < THREAD_SIZE;
34*2335c9cbSJinjie Ruan }
35*2335c9cbSJinjie Ruan
369865f1d4SNikolay Borisov static __always_inline
arm_get_current_stackframe(struct pt_regs * regs,struct stackframe * frame)379865f1d4SNikolay Borisov void arm_get_current_stackframe(struct pt_regs *regs, struct stackframe *frame)
389865f1d4SNikolay Borisov {
399865f1d4SNikolay Borisov frame->fp = frame_pointer(regs);
409865f1d4SNikolay Borisov frame->sp = regs->ARM_sp;
419865f1d4SNikolay Borisov frame->lr = regs->ARM_lr;
429865f1d4SNikolay Borisov frame->pc = regs->ARM_pc;
43fed240d9SMasami Hiramatsu #ifdef CONFIG_KRETPROBES
44fed240d9SMasami Hiramatsu frame->kr_cur = NULL;
45fed240d9SMasami Hiramatsu frame->tsk = current;
46fed240d9SMasami Hiramatsu #endif
47752ec621SLi Huafei #ifdef CONFIG_UNWINDER_FRAME_POINTER
48752ec621SLi Huafei frame->ex_frame = in_entry_text(frame->pc);
49752ec621SLi Huafei #endif
509865f1d4SNikolay Borisov }
519865f1d4SNikolay Borisov
522d7c11bfSCatalin Marinas extern int unwind_frame(struct stackframe *frame);
532d7c11bfSCatalin Marinas extern void walk_stackframe(struct stackframe *frame,
5470ccc7c0SLi Huafei bool (*fn)(void *, unsigned long), void *data);
558cdfdf7fSArd Biesheuvel extern void dump_mem(const char *lvl, const char *str, unsigned long bottom,
568cdfdf7fSArd Biesheuvel unsigned long top);
5709cffecaSZhen Lei extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk,
5809cffecaSZhen Lei const char *loglvl);
592d7c11bfSCatalin Marinas
602d7c11bfSCatalin Marinas #endif /* __ASM_STACKTRACE_H */
61