unwind.h 2.7 KB

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