stacktrace.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/switch_to.h>
  11. enum stack_type {
  12. STACK_TYPE_UNKNOWN,
  13. STACK_TYPE_TASK,
  14. STACK_TYPE_IRQ,
  15. STACK_TYPE_SOFTIRQ,
  16. STACK_TYPE_ENTRY,
  17. STACK_TYPE_EXCEPTION,
  18. STACK_TYPE_EXCEPTION_LAST = STACK_TYPE_EXCEPTION + N_EXCEPTION_STACKS-1,
  19. };
  20. struct stack_info {
  21. enum stack_type type;
  22. unsigned long *begin, *end, *next_sp;
  23. };
  24. bool in_task_stack(unsigned long *stack, struct task_struct *task,
  25. struct stack_info *info);
  26. bool in_entry_stack(unsigned long *stack, struct stack_info *info);
  27. int get_stack_info(unsigned long *stack, struct task_struct *task,
  28. struct stack_info *info, unsigned long *visit_mask);
  29. const char *stack_type_name(enum stack_type type);
  30. static inline bool on_stack(struct stack_info *info, void *addr, size_t len)
  31. {
  32. void *begin = info->begin;
  33. void *end = info->end;
  34. return (info->type != STACK_TYPE_UNKNOWN &&
  35. addr >= begin && addr < end &&
  36. addr + len > begin && addr + len <= end);
  37. }
  38. #ifdef CONFIG_X86_32
  39. #define STACKSLOTS_PER_LINE 8
  40. #else
  41. #define STACKSLOTS_PER_LINE 4
  42. #endif
  43. #ifdef CONFIG_FRAME_POINTER
  44. static inline unsigned long *
  45. get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
  46. {
  47. if (regs)
  48. return (unsigned long *)regs->bp;
  49. if (task == current)
  50. return __builtin_frame_address(0);
  51. return &((struct inactive_task_frame *)task->thread.sp)->bp;
  52. }
  53. #else
  54. static inline unsigned long *
  55. get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
  56. {
  57. return NULL;
  58. }
  59. #endif /* CONFIG_FRAME_POINTER */
  60. static inline unsigned long *
  61. get_stack_pointer(struct task_struct *task, struct pt_regs *regs)
  62. {
  63. if (regs)
  64. return (unsigned long *)kernel_stack_pointer(regs);
  65. if (task == current)
  66. return __builtin_frame_address(0);
  67. return (unsigned long *)task->thread.sp;
  68. }
  69. void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
  70. unsigned long *stack, char *log_lvl);
  71. extern unsigned int code_bytes;
  72. /* The form of the top of the frame on the stack */
  73. struct stack_frame {
  74. struct stack_frame *next_frame;
  75. unsigned long return_address;
  76. };
  77. struct stack_frame_ia32 {
  78. u32 next_frame;
  79. u32 return_address;
  80. };
  81. static inline unsigned long caller_frame_pointer(void)
  82. {
  83. struct stack_frame *frame;
  84. frame = __builtin_frame_address(0);
  85. #ifdef CONFIG_FRAME_POINTER
  86. frame = frame->next_frame;
  87. #endif
  88. return (unsigned long)frame;
  89. }
  90. #endif /* _ASM_X86_STACKTRACE_H */