unwind.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. };
  18. #define UNW_PC(frame) (frame)->regs.rip
  19. #define UNW_SP(frame) (frame)->regs.rsp
  20. #ifdef CONFIG_FRAME_POINTER
  21. #define UNW_FP(frame) (frame)->regs.rbp
  22. #define FRAME_RETADDR_OFFSET 8
  23. #define FRAME_LINK_OFFSET 0
  24. #define STACK_BOTTOM(tsk) (((tsk)->thread.rsp0 - 1) & ~(THREAD_SIZE - 1))
  25. #define STACK_TOP(tsk) ((tsk)->thread.rsp0)
  26. #endif
  27. /* Might need to account for the special exception and interrupt handling
  28. stacks here, since normally
  29. EXCEPTION_STACK_ORDER < THREAD_ORDER < IRQSTACK_ORDER,
  30. but the construct is needed only for getting across the stack switch to
  31. the interrupt stack - thus considering the IRQ stack itself is unnecessary,
  32. and the overhead of comparing against all exception handling stacks seems
  33. not desirable. */
  34. #define STACK_LIMIT(ptr) (((ptr) - 1) & ~(THREAD_SIZE - 1))
  35. #define UNW_REGISTER_INFO \
  36. PTREGS_INFO(rax), \
  37. PTREGS_INFO(rdx), \
  38. PTREGS_INFO(rcx), \
  39. PTREGS_INFO(rbx), \
  40. PTREGS_INFO(rsi), \
  41. PTREGS_INFO(rdi), \
  42. PTREGS_INFO(rbp), \
  43. PTREGS_INFO(rsp), \
  44. PTREGS_INFO(r8), \
  45. PTREGS_INFO(r9), \
  46. PTREGS_INFO(r10), \
  47. PTREGS_INFO(r11), \
  48. PTREGS_INFO(r12), \
  49. PTREGS_INFO(r13), \
  50. PTREGS_INFO(r14), \
  51. PTREGS_INFO(r15), \
  52. PTREGS_INFO(rip)
  53. static inline void arch_unw_init_frame_info(struct unwind_frame_info *info,
  54. /*const*/ struct pt_regs *regs)
  55. {
  56. info->regs = *regs;
  57. }
  58. static inline void arch_unw_init_blocked(struct unwind_frame_info *info)
  59. {
  60. extern const char thread_return[];
  61. memset(&info->regs, 0, sizeof(info->regs));
  62. info->regs.rip = (unsigned long)thread_return;
  63. info->regs.cs = __KERNEL_CS;
  64. __get_user(info->regs.rbp, (unsigned long *)info->task->thread.rsp);
  65. info->regs.rsp = info->task->thread.rsp;
  66. info->regs.ss = __KERNEL_DS;
  67. }
  68. extern int arch_unwind_init_running(struct unwind_frame_info *,
  69. int (*callback)(struct unwind_frame_info *,
  70. void *arg),
  71. void *arg);
  72. static inline int arch_unw_user_mode(const struct unwind_frame_info *info)
  73. {
  74. #if 0 /* This can only work when selector register saves/restores
  75. are properly annotated (and tracked in UNW_REGISTER_INFO). */
  76. return user_mode(&info->regs);
  77. #else
  78. return (long)info->regs.rip >= 0
  79. || (info->regs.rip >= VSYSCALL_START && info->regs.rip < VSYSCALL_END)
  80. || (long)info->regs.rsp >= 0;
  81. #endif
  82. }
  83. #else
  84. #define UNW_PC(frame) ((void)(frame), 0)
  85. static inline int arch_unw_user_mode(const void *info)
  86. {
  87. return 0;
  88. }
  89. #endif
  90. #endif /* _ASM_X86_64_UNWIND_H */