unwind.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef _ASM_X86_64_UNWIND_H
  2. #define _ASM_X86_64_UNWIND_H
  3. /*
  4. * Copyright (C) 2002-2006 Novell, Inc.
  5. * Jan Beulich <jbeulich@novell.com>
  6. * This code is released under version 2 of the GNU GPL.
  7. */
  8. #ifdef CONFIG_STACK_UNWIND
  9. #include <linux/sched.h>
  10. #include <asm/ptrace.h>
  11. #include <asm/uaccess.h>
  12. #include <asm/vsyscall.h>
  13. struct unwind_frame_info
  14. {
  15. struct pt_regs regs;
  16. struct task_struct *task;
  17. unsigned call_frame:1;
  18. };
  19. #define UNW_PC(frame) (frame)->regs.rip
  20. #define UNW_SP(frame) (frame)->regs.rsp
  21. #ifdef CONFIG_FRAME_POINTER
  22. #define UNW_FP(frame) (frame)->regs.rbp
  23. #define FRAME_RETADDR_OFFSET 8
  24. #define FRAME_LINK_OFFSET 0
  25. #define STACK_BOTTOM(tsk) (((tsk)->thread.rsp0 - 1) & ~(THREAD_SIZE - 1))
  26. #define STACK_TOP(tsk) ((tsk)->thread.rsp0)
  27. #endif
  28. /* Might need to account for the special exception and interrupt handling
  29. stacks here, since normally
  30. EXCEPTION_STACK_ORDER < THREAD_ORDER < IRQSTACK_ORDER,
  31. but the construct is needed only for getting across the stack switch to
  32. the interrupt stack - thus considering the IRQ stack itself is unnecessary,
  33. and the overhead of comparing against all exception handling stacks seems
  34. not desirable. */
  35. #define STACK_LIMIT(ptr) (((ptr) - 1) & ~(THREAD_SIZE - 1))
  36. #define UNW_REGISTER_INFO \
  37. PTREGS_INFO(rax), \
  38. PTREGS_INFO(rdx), \
  39. PTREGS_INFO(rcx), \
  40. PTREGS_INFO(rbx), \
  41. PTREGS_INFO(rsi), \
  42. PTREGS_INFO(rdi), \
  43. PTREGS_INFO(rbp), \
  44. PTREGS_INFO(rsp), \
  45. PTREGS_INFO(r8), \
  46. PTREGS_INFO(r9), \
  47. PTREGS_INFO(r10), \
  48. PTREGS_INFO(r11), \
  49. PTREGS_INFO(r12), \
  50. PTREGS_INFO(r13), \
  51. PTREGS_INFO(r14), \
  52. PTREGS_INFO(r15), \
  53. PTREGS_INFO(rip)
  54. #define UNW_DEFAULT_RA(raItem, dataAlign) \
  55. ((raItem).where == Memory && \
  56. !((raItem).value * (dataAlign) + 8))
  57. static inline void arch_unw_init_frame_info(struct unwind_frame_info *info,
  58. /*const*/ struct pt_regs *regs)
  59. {
  60. info->regs = *regs;
  61. }
  62. static inline void arch_unw_init_blocked(struct unwind_frame_info *info)
  63. {
  64. extern const char thread_return[];
  65. memset(&info->regs, 0, sizeof(info->regs));
  66. info->regs.rip = (unsigned long)thread_return;
  67. info->regs.cs = __KERNEL_CS;
  68. __get_user(info->regs.rbp, (unsigned long *)info->task->thread.rsp);
  69. info->regs.rsp = info->task->thread.rsp;
  70. info->regs.ss = __KERNEL_DS;
  71. }
  72. extern int arch_unwind_init_running(struct unwind_frame_info *,
  73. int (*callback)(struct unwind_frame_info *,
  74. void *arg),
  75. void *arg);
  76. static inline int arch_unw_user_mode(const struct unwind_frame_info *info)
  77. {
  78. #if 0 /* This can only work when selector register saves/restores
  79. are properly annotated (and tracked in UNW_REGISTER_INFO). */
  80. return user_mode(&info->regs);
  81. #else
  82. return (long)info->regs.rip >= 0
  83. || (info->regs.rip >= VSYSCALL_START && info->regs.rip < VSYSCALL_END)
  84. || (long)info->regs.rsp >= 0;
  85. #endif
  86. }
  87. #else
  88. #define UNW_PC(frame) ((void)(frame), 0UL)
  89. #define UNW_SP(frame) ((void)(frame), 0UL)
  90. static inline int arch_unw_user_mode(const void *info)
  91. {
  92. return 0;
  93. }
  94. #endif
  95. #endif /* _ASM_X86_64_UNWIND_H */