uprobes.h 5.8 KB
Newer Older
1 2 3
#ifndef _LINUX_UPROBES_H
#define _LINUX_UPROBES_H
/*
4
 * User-space Probes (UProbes)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
I
Ingo Molnar 已提交
20
 * Copyright (C) IBM Corporation, 2008-2012
21 22 23
 * Authors:
 *	Srikar Dronamraju
 *	Jim Keniston
I
Ingo Molnar 已提交
24
 * Copyright (C) 2011-2012 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com>
25 26 27 28
 */

#include <linux/errno.h>
#include <linux/rbtree.h>
29
#include <linux/types.h>
30 31

struct vm_area_struct;
32 33
struct mm_struct;
struct inode;
34
struct notifier_block;
35
struct page;
36

37 38 39
#define UPROBE_HANDLER_REMOVE		1
#define UPROBE_HANDLER_MASK		1

40 41
#define MAX_URETPROBE_DEPTH		64

42 43 44 45 46 47
enum uprobe_filter_ctx {
	UPROBE_FILTER_REGISTER,
	UPROBE_FILTER_UNREGISTER,
	UPROBE_FILTER_MMAP,
};

48 49
struct uprobe_consumer {
	int (*handler)(struct uprobe_consumer *self, struct pt_regs *regs);
50 51 52
	int (*ret_handler)(struct uprobe_consumer *self,
				unsigned long func,
				struct pt_regs *regs);
53 54 55
	bool (*filter)(struct uprobe_consumer *self,
				enum uprobe_filter_ctx ctx,
				struct mm_struct *mm);
56 57 58 59 60

	struct uprobe_consumer *next;
};

#ifdef CONFIG_UPROBES
61 62
#include <asm/uprobes.h>

63 64 65 66 67 68 69 70 71 72 73 74 75
enum uprobe_task_state {
	UTASK_RUNNING,
	UTASK_SSTEP,
	UTASK_SSTEP_ACK,
	UTASK_SSTEP_TRAPPED,
};

/*
 * uprobe_task: Metadata of a task while it singlesteps.
 */
struct uprobe_task {
	enum uprobe_task_state		state;

76 77 78 79 80 81 82 83 84 85 86
	union {
		struct {
			struct arch_uprobe_task	autask;
			unsigned long		vaddr;
		};

		struct {
			struct callback_head	dup_xol_work;
			unsigned long		dup_xol_addr;
		};
	};
87

88
	struct uprobe			*active_uprobe;
89
	unsigned long			xol_vaddr;
90 91 92

	struct return_instance		*return_instances;
	unsigned int			depth;
93 94
};

95
struct xol_area;
96 97 98 99

struct uprobes_state {
	struct xol_area		*xol_area;
};
100

101 102 103 104 105
extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
extern bool is_swbp_insn(uprobe_opcode_t *insn);
extern bool is_trap_insn(uprobe_opcode_t *insn);
extern unsigned long uprobe_get_swbp_addr(struct pt_regs *regs);
106
extern unsigned long uprobe_get_trap_addr(struct pt_regs *regs);
107
extern int uprobe_write_opcode(struct mm_struct *mm, unsigned long vaddr, uprobe_opcode_t);
108
extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
109
extern int uprobe_apply(struct inode *inode, loff_t offset, struct uprobe_consumer *uc, bool);
110
extern void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
111
extern int uprobe_mmap(struct vm_area_struct *vma);
112
extern void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end);
113 114
extern void uprobe_start_dup_mmap(void);
extern void uprobe_end_dup_mmap(void);
115
extern void uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm);
116
extern void uprobe_free_utask(struct task_struct *t);
117
extern void uprobe_copy_process(struct task_struct *t, unsigned long flags);
118 119 120 121
extern int uprobe_post_sstep_notifier(struct pt_regs *regs);
extern int uprobe_pre_sstep_notifier(struct pt_regs *regs);
extern void uprobe_notify_resume(struct pt_regs *regs);
extern bool uprobe_deny_signal(void);
122
extern bool arch_uprobe_skip_sstep(struct arch_uprobe *aup, struct pt_regs *regs);
123
extern void uprobe_clear_state(struct mm_struct *mm);
124 125 126 127 128 129 130
extern int  arch_uprobe_analyze_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long addr);
extern int  arch_uprobe_pre_xol(struct arch_uprobe *aup, struct pt_regs *regs);
extern int  arch_uprobe_post_xol(struct arch_uprobe *aup, struct pt_regs *regs);
extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);
extern int  arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val, void *data);
extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs);
extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs);
131 132
extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
133
					 void *src, unsigned long len);
134
#else /* !CONFIG_UPROBES */
135 136
struct uprobes_state {
};
137 138 139

#define uprobe_get_trap_addr(regs)	instruction_pointer(regs)

140
static inline int
141
uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
142 143 144
{
	return -ENOSYS;
}
145 146 147 148 149
static inline int
uprobe_apply(struct inode *inode, loff_t offset, struct uprobe_consumer *uc, bool add)
{
	return -ENOSYS;
}
150
static inline void
151
uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
152 153
{
}
154
static inline int uprobe_mmap(struct vm_area_struct *vma)
155 156 157
{
	return 0;
}
158 159
static inline void
uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end)
160 161
{
}
162 163 164 165 166 167
static inline void uprobe_start_dup_mmap(void)
{
}
static inline void uprobe_end_dup_mmap(void)
{
}
168 169 170 171
static inline void
uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm)
{
}
172 173 174 175 176 177 178 179 180 181
static inline void uprobe_notify_resume(struct pt_regs *regs)
{
}
static inline bool uprobe_deny_signal(void)
{
	return false;
}
static inline void uprobe_free_utask(struct task_struct *t)
{
}
182
static inline void uprobe_copy_process(struct task_struct *t, unsigned long flags)
183 184
{
}
185 186 187
static inline void uprobe_clear_state(struct mm_struct *mm)
{
}
188
#endif /* !CONFIG_UPROBES */
189
#endif	/* _LINUX_UPROBES_H */