stacktrace.h 2.4 KB

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