ptrace.h 3.4 KB

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