kstack.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef _KSTACK_H
  2. #define _KSTACK_H
  3. #include <linux/thread_info.h>
  4. #include <linux/sched.h>
  5. #include <asm/ptrace.h>
  6. #include <asm/irq.h>
  7. /* SP must be STACK_BIAS adjusted already. */
  8. static inline bool kstack_valid(struct thread_info *tp, unsigned long sp)
  9. {
  10. unsigned long base = (unsigned long) tp;
  11. if (sp >= (base + sizeof(struct thread_info)) &&
  12. sp <= (base + THREAD_SIZE - sizeof(struct sparc_stackf)))
  13. return true;
  14. if (hardirq_stack[tp->cpu]) {
  15. base = (unsigned long) hardirq_stack[tp->cpu];
  16. if (sp >= base &&
  17. sp <= (base + THREAD_SIZE - sizeof(struct sparc_stackf)))
  18. return true;
  19. base = (unsigned long) softirq_stack[tp->cpu];
  20. if (sp >= base &&
  21. sp <= (base + THREAD_SIZE - sizeof(struct sparc_stackf)))
  22. return true;
  23. }
  24. return false;
  25. }
  26. /* Does "regs" point to a valid pt_regs trap frame? */
  27. static inline bool kstack_is_trap_frame(struct thread_info *tp, struct pt_regs *regs)
  28. {
  29. unsigned long base = (unsigned long) tp;
  30. unsigned long addr = (unsigned long) regs;
  31. if (addr >= base &&
  32. addr <= (base + THREAD_SIZE - sizeof(*regs)))
  33. goto check_magic;
  34. if (hardirq_stack[tp->cpu]) {
  35. base = (unsigned long) hardirq_stack[tp->cpu];
  36. if (addr >= base &&
  37. addr <= (base + THREAD_SIZE - sizeof(*regs)))
  38. goto check_magic;
  39. base = (unsigned long) softirq_stack[tp->cpu];
  40. if (addr >= base &&
  41. addr <= (base + THREAD_SIZE - sizeof(*regs)))
  42. goto check_magic;
  43. }
  44. return false;
  45. check_magic:
  46. if ((regs->magic & ~0x1ff) == PT_REGS_MAGIC)
  47. return true;
  48. return false;
  49. }
  50. #endif /* _KSTACK_H */