Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 #ifndef _LINUX_UPROBES_H
0003 #define _LINUX_UPROBES_H
0004 /*
0005  * User-space Probes (UProbes)
0006  *
0007  * Copyright (C) IBM Corporation, 2008-2012
0008  * Authors:
0009  *  Srikar Dronamraju
0010  *  Jim Keniston
0011  * Copyright (C) 2011-2012 Red Hat, Inc., Peter Zijlstra
0012  */
0013 
0014 #include <linux/errno.h>
0015 #include <linux/rbtree.h>
0016 #include <linux/types.h>
0017 #include <linux/wait.h>
0018 
0019 struct vm_area_struct;
0020 struct mm_struct;
0021 struct inode;
0022 struct notifier_block;
0023 struct page;
0024 
0025 #define UPROBE_HANDLER_REMOVE       1
0026 #define UPROBE_HANDLER_MASK     1
0027 
0028 #define MAX_URETPROBE_DEPTH     64
0029 
0030 enum uprobe_filter_ctx {
0031     UPROBE_FILTER_REGISTER,
0032     UPROBE_FILTER_UNREGISTER,
0033     UPROBE_FILTER_MMAP,
0034 };
0035 
0036 struct uprobe_consumer {
0037     int (*handler)(struct uprobe_consumer *self, struct pt_regs *regs);
0038     int (*ret_handler)(struct uprobe_consumer *self,
0039                 unsigned long func,
0040                 struct pt_regs *regs);
0041     bool (*filter)(struct uprobe_consumer *self,
0042                 enum uprobe_filter_ctx ctx,
0043                 struct mm_struct *mm);
0044 
0045     struct uprobe_consumer *next;
0046 };
0047 
0048 #ifdef CONFIG_UPROBES
0049 #include <asm/uprobes.h>
0050 
0051 enum uprobe_task_state {
0052     UTASK_RUNNING,
0053     UTASK_SSTEP,
0054     UTASK_SSTEP_ACK,
0055     UTASK_SSTEP_TRAPPED,
0056 };
0057 
0058 /*
0059  * uprobe_task: Metadata of a task while it singlesteps.
0060  */
0061 struct uprobe_task {
0062     enum uprobe_task_state      state;
0063 
0064     union {
0065         struct {
0066             struct arch_uprobe_task autask;
0067             unsigned long       vaddr;
0068         };
0069 
0070         struct {
0071             struct callback_head    dup_xol_work;
0072             unsigned long       dup_xol_addr;
0073         };
0074     };
0075 
0076     struct uprobe           *active_uprobe;
0077     unsigned long           xol_vaddr;
0078 
0079     struct return_instance      *return_instances;
0080     unsigned int            depth;
0081 };
0082 
0083 struct return_instance {
0084     struct uprobe       *uprobe;
0085     unsigned long       func;
0086     unsigned long       stack;      /* stack pointer */
0087     unsigned long       orig_ret_vaddr; /* original return address */
0088     bool            chained;    /* true, if instance is nested */
0089 
0090     struct return_instance  *next;      /* keep as stack */
0091 };
0092 
0093 enum rp_check {
0094     RP_CHECK_CALL,
0095     RP_CHECK_CHAIN_CALL,
0096     RP_CHECK_RET,
0097 };
0098 
0099 struct xol_area;
0100 
0101 struct uprobes_state {
0102     struct xol_area     *xol_area;
0103 };
0104 
0105 extern void __init uprobes_init(void);
0106 extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
0107 extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
0108 extern bool is_swbp_insn(uprobe_opcode_t *insn);
0109 extern bool is_trap_insn(uprobe_opcode_t *insn);
0110 extern unsigned long uprobe_get_swbp_addr(struct pt_regs *regs);
0111 extern unsigned long uprobe_get_trap_addr(struct pt_regs *regs);
0112 extern int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned long vaddr, uprobe_opcode_t);
0113 extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
0114 extern int uprobe_register_refctr(struct inode *inode, loff_t offset, loff_t ref_ctr_offset, struct uprobe_consumer *uc);
0115 extern int uprobe_apply(struct inode *inode, loff_t offset, struct uprobe_consumer *uc, bool);
0116 extern void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
0117 extern int uprobe_mmap(struct vm_area_struct *vma);
0118 extern void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end);
0119 extern void uprobe_start_dup_mmap(void);
0120 extern void uprobe_end_dup_mmap(void);
0121 extern void uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm);
0122 extern void uprobe_free_utask(struct task_struct *t);
0123 extern void uprobe_copy_process(struct task_struct *t, unsigned long flags);
0124 extern int uprobe_post_sstep_notifier(struct pt_regs *regs);
0125 extern int uprobe_pre_sstep_notifier(struct pt_regs *regs);
0126 extern void uprobe_notify_resume(struct pt_regs *regs);
0127 extern bool uprobe_deny_signal(void);
0128 extern bool arch_uprobe_skip_sstep(struct arch_uprobe *aup, struct pt_regs *regs);
0129 extern void uprobe_clear_state(struct mm_struct *mm);
0130 extern int  arch_uprobe_analyze_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long addr);
0131 extern int  arch_uprobe_pre_xol(struct arch_uprobe *aup, struct pt_regs *regs);
0132 extern int  arch_uprobe_post_xol(struct arch_uprobe *aup, struct pt_regs *regs);
0133 extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);
0134 extern int  arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val, void *data);
0135 extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs);
0136 extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs);
0137 extern bool arch_uretprobe_is_alive(struct return_instance *ret, enum rp_check ctx, struct pt_regs *regs);
0138 extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
0139 extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
0140                      void *src, unsigned long len);
0141 #else /* !CONFIG_UPROBES */
0142 struct uprobes_state {
0143 };
0144 
0145 static inline void uprobes_init(void)
0146 {
0147 }
0148 
0149 #define uprobe_get_trap_addr(regs)  instruction_pointer(regs)
0150 
0151 static inline int
0152 uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
0153 {
0154     return -ENOSYS;
0155 }
0156 static inline int uprobe_register_refctr(struct inode *inode, loff_t offset, loff_t ref_ctr_offset, struct uprobe_consumer *uc)
0157 {
0158     return -ENOSYS;
0159 }
0160 static inline int
0161 uprobe_apply(struct inode *inode, loff_t offset, struct uprobe_consumer *uc, bool add)
0162 {
0163     return -ENOSYS;
0164 }
0165 static inline void
0166 uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
0167 {
0168 }
0169 static inline int uprobe_mmap(struct vm_area_struct *vma)
0170 {
0171     return 0;
0172 }
0173 static inline void
0174 uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end)
0175 {
0176 }
0177 static inline void uprobe_start_dup_mmap(void)
0178 {
0179 }
0180 static inline void uprobe_end_dup_mmap(void)
0181 {
0182 }
0183 static inline void
0184 uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm)
0185 {
0186 }
0187 static inline void uprobe_notify_resume(struct pt_regs *regs)
0188 {
0189 }
0190 static inline bool uprobe_deny_signal(void)
0191 {
0192     return false;
0193 }
0194 static inline void uprobe_free_utask(struct task_struct *t)
0195 {
0196 }
0197 static inline void uprobe_copy_process(struct task_struct *t, unsigned long flags)
0198 {
0199 }
0200 static inline void uprobe_clear_state(struct mm_struct *mm)
0201 {
0202 }
0203 #endif /* !CONFIG_UPROBES */
0204 #endif  /* _LINUX_UPROBES_H */