stacktrace.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_STACKTRACE_H
  3. #define __ASM_STACKTRACE_H
  4. #include <asm/ptrace.h>
  5. #include <linux/llist.h>
  6. struct stackframe {
  7. /*
  8. * FP member should hold R7 when CONFIG_THUMB2_KERNEL is enabled
  9. * and R11 otherwise.
  10. */
  11. unsigned long fp;
  12. unsigned long sp;
  13. unsigned long lr;
  14. unsigned long pc;
  15. /* address of the LR value on the stack */
  16. unsigned long *lr_addr;
  17. #ifdef CONFIG_KRETPROBES
  18. struct llist_node *kr_cur;
  19. struct task_struct *tsk;
  20. #endif
  21. #ifdef CONFIG_UNWINDER_FRAME_POINTER
  22. bool ex_frame;
  23. #endif
  24. };
  25. static inline bool on_thread_stack(void)
  26. {
  27. unsigned long delta = current_stack_pointer ^ (unsigned long)current->stack;
  28. return delta < THREAD_SIZE;
  29. }
  30. static __always_inline
  31. void arm_get_current_stackframe(struct pt_regs *regs, struct stackframe *frame)
  32. {
  33. frame->fp = frame_pointer(regs);
  34. frame->sp = regs->ARM_sp;
  35. frame->lr = regs->ARM_lr;
  36. frame->pc = regs->ARM_pc;
  37. #ifdef CONFIG_KRETPROBES
  38. frame->kr_cur = NULL;
  39. frame->tsk = current;
  40. #endif
  41. #ifdef CONFIG_UNWINDER_FRAME_POINTER
  42. frame->ex_frame = in_entry_text(frame->pc);
  43. #endif
  44. }
  45. extern int unwind_frame(struct stackframe *frame);
  46. extern void walk_stackframe(struct stackframe *frame,
  47. bool (*fn)(void *, unsigned long), void *data);
  48. extern void dump_mem(const char *lvl, const char *str, unsigned long bottom,
  49. unsigned long top);
  50. extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk,
  51. const char *loglvl);
  52. #endif /* __ASM_STACKTRACE_H */