uprobes.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef _LINUX_UPROBES_H
  3. #define _LINUX_UPROBES_H
  4. /*
  5. * User-space Probes (UProbes)
  6. *
  7. * Copyright (C) IBM Corporation, 2008-2012
  8. * Authors:
  9. * Srikar Dronamraju
  10. * Jim Keniston
  11. * Copyright (C) 2011-2012 Red Hat, Inc., Peter Zijlstra
  12. */
  13. #include <linux/errno.h>
  14. #include <linux/rbtree.h>
  15. #include <linux/types.h>
  16. #include <linux/wait.h>
  17. struct vm_area_struct;
  18. struct mm_struct;
  19. struct inode;
  20. struct notifier_block;
  21. struct page;
  22. #define UPROBE_HANDLER_REMOVE 1
  23. #define UPROBE_HANDLER_MASK 1
  24. #define MAX_URETPROBE_DEPTH 64
  25. enum uprobe_filter_ctx {
  26. UPROBE_FILTER_REGISTER,
  27. UPROBE_FILTER_UNREGISTER,
  28. UPROBE_FILTER_MMAP,
  29. };
  30. struct uprobe_consumer {
  31. int (*handler)(struct uprobe_consumer *self, struct pt_regs *regs);
  32. int (*ret_handler)(struct uprobe_consumer *self,
  33. unsigned long func,
  34. struct pt_regs *regs);
  35. bool (*filter)(struct uprobe_consumer *self,
  36. enum uprobe_filter_ctx ctx,
  37. struct mm_struct *mm);
  38. struct uprobe_consumer *next;
  39. };
  40. #ifdef CONFIG_UPROBES
  41. #include <asm/uprobes.h>
  42. enum uprobe_task_state {
  43. UTASK_RUNNING,
  44. UTASK_SSTEP,
  45. UTASK_SSTEP_ACK,
  46. UTASK_SSTEP_TRAPPED,
  47. };
  48. /*
  49. * uprobe_task: Metadata of a task while it singlesteps.
  50. */
  51. struct uprobe_task {
  52. enum uprobe_task_state state;
  53. union {
  54. struct {
  55. struct arch_uprobe_task autask;
  56. unsigned long vaddr;
  57. };
  58. struct {
  59. struct callback_head dup_xol_work;
  60. unsigned long dup_xol_addr;
  61. };
  62. };
  63. struct uprobe *active_uprobe;
  64. unsigned long xol_vaddr;
  65. struct return_instance *return_instances;
  66. unsigned int depth;
  67. };
  68. struct return_instance {
  69. struct uprobe *uprobe;
  70. unsigned long func;
  71. unsigned long stack; /* stack pointer */
  72. unsigned long orig_ret_vaddr; /* original return address */
  73. bool chained; /* true, if instance is nested */
  74. struct return_instance *next; /* keep as stack */
  75. };
  76. enum rp_check {
  77. RP_CHECK_CALL,
  78. RP_CHECK_CHAIN_CALL,
  79. RP_CHECK_RET,
  80. };
  81. struct xol_area;
  82. struct uprobes_state {
  83. struct xol_area *xol_area;
  84. };
  85. extern void __init uprobes_init(void);
  86. extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
  87. extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
  88. extern bool is_swbp_insn(uprobe_opcode_t *insn);
  89. extern bool is_trap_insn(uprobe_opcode_t *insn);
  90. extern unsigned long uprobe_get_swbp_addr(struct pt_regs *regs);
  91. extern unsigned long uprobe_get_trap_addr(struct pt_regs *regs);
  92. extern int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned long vaddr, uprobe_opcode_t);
  93. extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
  94. extern int uprobe_register_refctr(struct inode *inode, loff_t offset, loff_t ref_ctr_offset, struct uprobe_consumer *uc);
  95. extern int uprobe_apply(struct inode *inode, loff_t offset, struct uprobe_consumer *uc, bool);
  96. extern void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
  97. extern int uprobe_mmap(struct vm_area_struct *vma);
  98. extern void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end);
  99. extern void uprobe_start_dup_mmap(void);
  100. extern void uprobe_end_dup_mmap(void);
  101. extern void uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm);
  102. extern void uprobe_free_utask(struct task_struct *t);
  103. extern void uprobe_copy_process(struct task_struct *t, unsigned long flags);
  104. extern int uprobe_post_sstep_notifier(struct pt_regs *regs);
  105. extern int uprobe_pre_sstep_notifier(struct pt_regs *regs);
  106. extern void uprobe_notify_resume(struct pt_regs *regs);
  107. extern bool uprobe_deny_signal(void);
  108. extern bool arch_uprobe_skip_sstep(struct arch_uprobe *aup, struct pt_regs *regs);
  109. extern void uprobe_clear_state(struct mm_struct *mm);
  110. extern int arch_uprobe_analyze_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long addr);
  111. extern int arch_uprobe_pre_xol(struct arch_uprobe *aup, struct pt_regs *regs);
  112. extern int arch_uprobe_post_xol(struct arch_uprobe *aup, struct pt_regs *regs);
  113. extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);
  114. extern int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val, void *data);
  115. extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs);
  116. extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs);
  117. extern bool arch_uretprobe_is_alive(struct return_instance *ret, enum rp_check ctx, struct pt_regs *regs);
  118. extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
  119. extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
  120. void *src, unsigned long len);
  121. #else /* !CONFIG_UPROBES */
  122. struct uprobes_state {
  123. };
  124. static inline void uprobes_init(void)
  125. {
  126. }
  127. #define uprobe_get_trap_addr(regs) instruction_pointer(regs)
  128. static inline int
  129. uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
  130. {
  131. return -ENOSYS;
  132. }
  133. static inline int uprobe_register_refctr(struct inode *inode, loff_t offset, loff_t ref_ctr_offset, struct uprobe_consumer *uc)
  134. {
  135. return -ENOSYS;
  136. }
  137. static inline int
  138. uprobe_apply(struct inode *inode, loff_t offset, struct uprobe_consumer *uc, bool add)
  139. {
  140. return -ENOSYS;
  141. }
  142. static inline void
  143. uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
  144. {
  145. }
  146. static inline int uprobe_mmap(struct vm_area_struct *vma)
  147. {
  148. return 0;
  149. }
  150. static inline void
  151. uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  152. {
  153. }
  154. static inline void uprobe_start_dup_mmap(void)
  155. {
  156. }
  157. static inline void uprobe_end_dup_mmap(void)
  158. {
  159. }
  160. static inline void
  161. uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm)
  162. {
  163. }
  164. static inline void uprobe_notify_resume(struct pt_regs *regs)
  165. {
  166. }
  167. static inline bool uprobe_deny_signal(void)
  168. {
  169. return false;
  170. }
  171. static inline void uprobe_free_utask(struct task_struct *t)
  172. {
  173. }
  174. static inline void uprobe_copy_process(struct task_struct *t, unsigned long flags)
  175. {
  176. }
  177. static inline void uprobe_clear_state(struct mm_struct *mm)
  178. {
  179. }
  180. #endif /* !CONFIG_UPROBES */
  181. #endif /* _LINUX_UPROBES_H */