ptrace.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (C) 1999, 2000 Niibe Yutaka
  3. */
  4. #ifndef __ASM_SH_PTRACE_H
  5. #define __ASM_SH_PTRACE_H
  6. #include <linux/stringify.h>
  7. #include <linux/stddef.h>
  8. #include <linux/thread_info.h>
  9. #include <asm/addrspace.h>
  10. #include <asm/page.h>
  11. #include <uapi/asm/ptrace.h>
  12. #define user_mode(regs) (((regs)->sr & 0x40000000)==0)
  13. #define kernel_stack_pointer(_regs) ((unsigned long)(_regs)->regs[15])
  14. #define GET_FP(regs) ((regs)->regs[14])
  15. #define GET_USP(regs) ((regs)->regs[15])
  16. #define arch_has_single_step() (1)
  17. /*
  18. * kprobe-based event tracer support
  19. */
  20. struct pt_regs_offset {
  21. const char *name;
  22. int offset;
  23. };
  24. #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
  25. #define REGS_OFFSET_NAME(num) \
  26. {.name = __stringify(r##num), .offset = offsetof(struct pt_regs, regs[num])}
  27. #define TREGS_OFFSET_NAME(num) \
  28. {.name = __stringify(tr##num), .offset = offsetof(struct pt_regs, tregs[num])}
  29. #define REG_OFFSET_END {.name = NULL, .offset = 0}
  30. /* Query offset/name of register from its name/offset */
  31. extern int regs_query_register_offset(const char *name);
  32. extern const char *regs_query_register_name(unsigned int offset);
  33. extern const struct pt_regs_offset regoffset_table[];
  34. /**
  35. * regs_get_register() - get register value from its offset
  36. * @regs: pt_regs from which register value is gotten.
  37. * @offset: offset number of the register.
  38. *
  39. * regs_get_register returns the value of a register. The @offset is the
  40. * offset of the register in struct pt_regs address which specified by @regs.
  41. * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
  42. */
  43. static inline unsigned long regs_get_register(struct pt_regs *regs,
  44. unsigned int offset)
  45. {
  46. if (unlikely(offset > MAX_REG_OFFSET))
  47. return 0;
  48. return *(unsigned long *)((unsigned long)regs + offset);
  49. }
  50. /**
  51. * regs_within_kernel_stack() - check the address in the stack
  52. * @regs: pt_regs which contains kernel stack pointer.
  53. * @addr: address which is checked.
  54. *
  55. * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
  56. * If @addr is within the kernel stack, it returns true. If not, returns false.
  57. */
  58. static inline int regs_within_kernel_stack(struct pt_regs *regs,
  59. unsigned long addr)
  60. {
  61. return ((addr & ~(THREAD_SIZE - 1)) ==
  62. (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
  63. }
  64. /**
  65. * regs_get_kernel_stack_nth() - get Nth entry of the stack
  66. * @regs: pt_regs which contains kernel stack pointer.
  67. * @n: stack entry number.
  68. *
  69. * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
  70. * is specified by @regs. If the @n th entry is NOT in the kernel stack,
  71. * this returns 0.
  72. */
  73. static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
  74. unsigned int n)
  75. {
  76. unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
  77. addr += n;
  78. if (regs_within_kernel_stack(regs, (unsigned long)addr))
  79. return *addr;
  80. else
  81. return 0;
  82. }
  83. struct perf_event;
  84. struct perf_sample_data;
  85. extern void ptrace_triggered(struct perf_event *bp,
  86. struct perf_sample_data *data, struct pt_regs *regs);
  87. #define task_pt_regs(task) \
  88. ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE) - 1)
  89. static inline unsigned long profile_pc(struct pt_regs *regs)
  90. {
  91. unsigned long pc = regs->pc;
  92. if (virt_addr_uncached(pc))
  93. return CAC_ADDR(pc);
  94. return pc;
  95. }
  96. #define profile_pc profile_pc
  97. #include <asm-generic/ptrace.h>
  98. #endif /* __ASM_SH_PTRACE_H */