unwind.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef _ASM_I386_UNWIND_H
  2. #define _ASM_I386_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/fixmap.h>
  11. #include <asm/ptrace.h>
  12. #include <asm/uaccess.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.eip
  19. #define UNW_SP(frame) (frame)->regs.esp
  20. #ifdef CONFIG_FRAME_POINTER
  21. #define UNW_FP(frame) (frame)->regs.ebp
  22. #define FRAME_RETADDR_OFFSET 4
  23. #define FRAME_LINK_OFFSET 0
  24. #define STACK_BOTTOM(tsk) STACK_LIMIT((tsk)->thread.esp0)
  25. #define STACK_TOP(tsk) ((tsk)->thread.esp0)
  26. #else
  27. #define UNW_FP(frame) ((void)(frame), 0)
  28. #endif
  29. #define STACK_LIMIT(ptr) (((ptr) - 1) & ~(THREAD_SIZE - 1))
  30. #define UNW_REGISTER_INFO \
  31. PTREGS_INFO(eax), \
  32. PTREGS_INFO(ecx), \
  33. PTREGS_INFO(edx), \
  34. PTREGS_INFO(ebx), \
  35. PTREGS_INFO(esp), \
  36. PTREGS_INFO(ebp), \
  37. PTREGS_INFO(esi), \
  38. PTREGS_INFO(edi), \
  39. PTREGS_INFO(eip)
  40. static inline void arch_unw_init_frame_info(struct unwind_frame_info *info,
  41. /*const*/ struct pt_regs *regs)
  42. {
  43. if (user_mode_vm(regs))
  44. info->regs = *regs;
  45. else {
  46. memcpy(&info->regs, regs, offsetof(struct pt_regs, esp));
  47. info->regs.esp = (unsigned long)&regs->esp;
  48. info->regs.xss = __KERNEL_DS;
  49. }
  50. }
  51. static inline void arch_unw_init_blocked(struct unwind_frame_info *info)
  52. {
  53. memset(&info->regs, 0, sizeof(info->regs));
  54. info->regs.eip = info->task->thread.eip;
  55. info->regs.xcs = __KERNEL_CS;
  56. __get_user(info->regs.ebp, (long *)info->task->thread.esp);
  57. info->regs.esp = info->task->thread.esp;
  58. info->regs.xss = __KERNEL_DS;
  59. info->regs.xds = __USER_DS;
  60. info->regs.xes = __USER_DS;
  61. }
  62. extern asmlinkage int arch_unwind_init_running(struct unwind_frame_info *,
  63. asmlinkage int (*callback)(struct unwind_frame_info *,
  64. void *arg),
  65. void *arg);
  66. static inline int arch_unw_user_mode(const struct unwind_frame_info *info)
  67. {
  68. #if 0 /* This can only work when selector register and EFLAGS saves/restores
  69. are properly annotated (and tracked in UNW_REGISTER_INFO). */
  70. return user_mode_vm(&info->regs);
  71. #else
  72. return info->regs.eip < PAGE_OFFSET
  73. || (info->regs.eip >= __fix_to_virt(FIX_VDSO)
  74. && info->regs.eip < __fix_to_virt(FIX_VDSO) + PAGE_SIZE)
  75. || info->regs.esp < PAGE_OFFSET;
  76. #endif
  77. }
  78. #else
  79. #define UNW_PC(frame) ((void)(frame), 0)
  80. #define UNW_SP(frame) ((void)(frame), 0)
  81. #define UNW_FP(frame) ((void)(frame), 0)
  82. static inline int arch_unw_user_mode(const void *info)
  83. {
  84. return 0;
  85. }
  86. #endif
  87. #endif /* _ASM_I386_UNWIND_H */