unwind.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. unsigned call_frame:1;
  18. };
  19. #define UNW_PC(frame) (frame)->regs.eip
  20. #define UNW_SP(frame) (frame)->regs.esp
  21. #ifdef CONFIG_FRAME_POINTER
  22. #define UNW_FP(frame) (frame)->regs.ebp
  23. #define FRAME_RETADDR_OFFSET 4
  24. #define FRAME_LINK_OFFSET 0
  25. #define STACK_BOTTOM(tsk) STACK_LIMIT((tsk)->thread.esp0)
  26. #define STACK_TOP(tsk) ((tsk)->thread.esp0)
  27. #else
  28. #define UNW_FP(frame) ((void)(frame), 0)
  29. #endif
  30. #define STACK_LIMIT(ptr) (((ptr) - 1) & ~(THREAD_SIZE - 1))
  31. #define UNW_REGISTER_INFO \
  32. PTREGS_INFO(eax), \
  33. PTREGS_INFO(ecx), \
  34. PTREGS_INFO(edx), \
  35. PTREGS_INFO(ebx), \
  36. PTREGS_INFO(esp), \
  37. PTREGS_INFO(ebp), \
  38. PTREGS_INFO(esi), \
  39. PTREGS_INFO(edi), \
  40. PTREGS_INFO(eip)
  41. #define UNW_DEFAULT_RA(raItem, dataAlign) \
  42. ((raItem).where == Memory && \
  43. !((raItem).value * (dataAlign) + 4))
  44. static inline void arch_unw_init_frame_info(struct unwind_frame_info *info,
  45. /*const*/ struct pt_regs *regs)
  46. {
  47. if (user_mode_vm(regs))
  48. info->regs = *regs;
  49. else {
  50. memcpy(&info->regs, regs, offsetof(struct pt_regs, esp));
  51. info->regs.esp = (unsigned long)&regs->esp;
  52. info->regs.xss = __KERNEL_DS;
  53. }
  54. }
  55. static inline void arch_unw_init_blocked(struct unwind_frame_info *info)
  56. {
  57. memset(&info->regs, 0, sizeof(info->regs));
  58. info->regs.eip = info->task->thread.eip;
  59. info->regs.xcs = __KERNEL_CS;
  60. __get_user(info->regs.ebp, (long *)info->task->thread.esp);
  61. info->regs.esp = info->task->thread.esp;
  62. info->regs.xss = __KERNEL_DS;
  63. info->regs.xds = __USER_DS;
  64. info->regs.xes = __USER_DS;
  65. info->regs.xgs = __KERNEL_PDA;
  66. }
  67. extern asmlinkage int arch_unwind_init_running(struct unwind_frame_info *,
  68. asmlinkage int (*callback)(struct unwind_frame_info *,
  69. void *arg),
  70. void *arg);
  71. static inline int arch_unw_user_mode(/*const*/ struct unwind_frame_info *info)
  72. {
  73. return user_mode_vm(&info->regs)
  74. || info->regs.eip < PAGE_OFFSET
  75. || (info->regs.eip >= __fix_to_virt(FIX_VDSO)
  76. && info->regs.eip < __fix_to_virt(FIX_VDSO) + PAGE_SIZE)
  77. || info->regs.esp < PAGE_OFFSET;
  78. }
  79. #else
  80. #define UNW_PC(frame) ((void)(frame), 0)
  81. #define UNW_SP(frame) ((void)(frame), 0)
  82. #define UNW_FP(frame) ((void)(frame), 0)
  83. static inline int arch_unw_user_mode(const void *info)
  84. {
  85. return 0;
  86. }
  87. #endif
  88. #endif /* _ASM_I386_UNWIND_H */