stacktrace.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_STACKTRACE_H
  3. #define __LINUX_STACKTRACE_H
  4. #include <linux/types.h>
  5. #include <asm/errno.h>
  6. struct task_struct;
  7. struct pt_regs;
  8. #ifdef CONFIG_STACKTRACE
  9. void stack_trace_print(const unsigned long *trace, unsigned int nr_entries,
  10. int spaces);
  11. int stack_trace_snprint(char *buf, size_t size, const unsigned long *entries,
  12. unsigned int nr_entries, int spaces);
  13. unsigned int stack_trace_save(unsigned long *store, unsigned int size,
  14. unsigned int skipnr);
  15. unsigned int stack_trace_save_tsk(struct task_struct *task,
  16. unsigned long *store, unsigned int size,
  17. unsigned int skipnr);
  18. unsigned int stack_trace_save_regs(struct pt_regs *regs, unsigned long *store,
  19. unsigned int size, unsigned int skipnr);
  20. unsigned int stack_trace_save_user(unsigned long *store, unsigned int size);
  21. /* Internal interfaces. Do not use in generic code */
  22. #ifdef CONFIG_ARCH_STACKWALK
  23. /**
  24. * stack_trace_consume_fn - Callback for arch_stack_walk()
  25. * @cookie: Caller supplied pointer handed back by arch_stack_walk()
  26. * @addr: The stack entry address to consume
  27. *
  28. * Return: True, if the entry was consumed or skipped
  29. * False, if there is no space left to store
  30. */
  31. typedef bool (*stack_trace_consume_fn)(void *cookie, unsigned long addr);
  32. /**
  33. * arch_stack_walk - Architecture specific function to walk the stack
  34. * @consume_entry: Callback which is invoked by the architecture code for
  35. * each entry.
  36. * @cookie: Caller supplied pointer which is handed back to
  37. * @consume_entry
  38. * @task: Pointer to a task struct, can be NULL
  39. * @regs: Pointer to registers, can be NULL
  40. *
  41. * ============ ======= ============================================
  42. * task regs
  43. * ============ ======= ============================================
  44. * task NULL Stack trace from task (can be current)
  45. * current regs Stack trace starting on regs->stackpointer
  46. * ============ ======= ============================================
  47. */
  48. void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
  49. struct task_struct *task, struct pt_regs *regs);
  50. int arch_stack_walk_reliable(stack_trace_consume_fn consume_entry, void *cookie,
  51. struct task_struct *task);
  52. void arch_stack_walk_user(stack_trace_consume_fn consume_entry, void *cookie,
  53. const struct pt_regs *regs);
  54. #else /* CONFIG_ARCH_STACKWALK */
  55. struct stack_trace {
  56. unsigned int nr_entries, max_entries;
  57. unsigned long *entries;
  58. unsigned int skip; /* input argument: How many entries to skip */
  59. };
  60. extern void save_stack_trace(struct stack_trace *trace);
  61. extern void save_stack_trace_regs(struct pt_regs *regs,
  62. struct stack_trace *trace);
  63. extern void save_stack_trace_tsk(struct task_struct *tsk,
  64. struct stack_trace *trace);
  65. extern int save_stack_trace_tsk_reliable(struct task_struct *tsk,
  66. struct stack_trace *trace);
  67. extern void save_stack_trace_user(struct stack_trace *trace);
  68. #endif /* !CONFIG_ARCH_STACKWALK */
  69. #endif /* CONFIG_STACKTRACE */
  70. #if defined(CONFIG_STACKTRACE) && defined(CONFIG_HAVE_RELIABLE_STACKTRACE)
  71. int stack_trace_save_tsk_reliable(struct task_struct *tsk, unsigned long *store,
  72. unsigned int size);
  73. #else
  74. static inline int stack_trace_save_tsk_reliable(struct task_struct *tsk,
  75. unsigned long *store,
  76. unsigned int size)
  77. {
  78. return -ENOSYS;
  79. }
  80. #endif
  81. #endif /* __LINUX_STACKTRACE_H */