stacktrace.h 2.5 KB

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