stacktrace.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 1991, 1992 Linus Torvalds
  4. * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
  5. */
  6. #ifndef _ASM_X86_STACKTRACE_H
  7. #define _ASM_X86_STACKTRACE_H
  8. #include <linux/uaccess.h>
  9. #include <linux/ptrace.h>
  10. #include <asm/cpu_entry_area.h>
  11. #include <asm/switch_to.h>
  12. enum stack_type {
  13. STACK_TYPE_UNKNOWN,
  14. STACK_TYPE_TASK,
  15. STACK_TYPE_IRQ,
  16. STACK_TYPE_SOFTIRQ,
  17. STACK_TYPE_ENTRY,
  18. STACK_TYPE_EXCEPTION,
  19. STACK_TYPE_EXCEPTION_LAST = STACK_TYPE_EXCEPTION + N_EXCEPTION_STACKS-1,
  20. };
  21. struct stack_info {
  22. enum stack_type type;
  23. unsigned long *begin, *end, *next_sp;
  24. };
  25. bool in_task_stack(unsigned long *stack, struct task_struct *task,
  26. struct stack_info *info);
  27. bool in_entry_stack(unsigned long *stack, struct stack_info *info);
  28. int get_stack_info(unsigned long *stack, struct task_struct *task,
  29. struct stack_info *info, unsigned long *visit_mask);
  30. bool get_stack_info_noinstr(unsigned long *stack, struct task_struct *task,
  31. struct stack_info *info);
  32. static __always_inline
  33. bool get_stack_guard_info(unsigned long *stack, struct stack_info *info)
  34. {
  35. /* make sure it's not in the stack proper */
  36. if (get_stack_info_noinstr(stack, current, info))
  37. return false;
  38. /* but if it is in the page below it, we hit a guard */
  39. return get_stack_info_noinstr((void *)stack + PAGE_SIZE, current, info);
  40. }
  41. const char *stack_type_name(enum stack_type type);
  42. static inline bool on_stack(struct stack_info *info, void *addr, size_t len)
  43. {
  44. void *begin = info->begin;
  45. void *end = info->end;
  46. return (info->type != STACK_TYPE_UNKNOWN &&
  47. addr >= begin && addr < end &&
  48. addr + len > begin && addr + len <= end);
  49. }
  50. #ifdef CONFIG_X86_32
  51. #define STACKSLOTS_PER_LINE 8
  52. #else
  53. #define STACKSLOTS_PER_LINE 4
  54. #endif
  55. #ifdef CONFIG_FRAME_POINTER
  56. static inline unsigned long *
  57. get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
  58. {
  59. if (regs)
  60. return (unsigned long *)regs->bp;
  61. if (task == current)
  62. return __builtin_frame_address(0);
  63. return &((struct inactive_task_frame *)task->thread.sp)->bp;
  64. }
  65. #else
  66. static inline unsigned long *
  67. get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
  68. {
  69. return NULL;
  70. }
  71. #endif /* CONFIG_FRAME_POINTER */
  72. static inline unsigned long *
  73. get_stack_pointer(struct task_struct *task, struct pt_regs *regs)
  74. {
  75. if (regs)
  76. return (unsigned long *)regs->sp;
  77. if (task == current)
  78. return __builtin_frame_address(0);
  79. return (unsigned long *)task->thread.sp;
  80. }
  81. /* The form of the top of the frame on the stack */
  82. struct stack_frame {
  83. struct stack_frame *next_frame;
  84. unsigned long return_address;
  85. };
  86. struct stack_frame_ia32 {
  87. u32 next_frame;
  88. u32 return_address;
  89. };
  90. void show_opcodes(struct pt_regs *regs, const char *loglvl);
  91. void show_ip(struct pt_regs *regs, const char *loglvl);
  92. #endif /* _ASM_X86_STACKTRACE_H */