uprobes.h 4.6 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 29 30
 */

#include <linux/errno.h>
#include <linux/rbtree.h>

struct vm_area_struct;
31 32
struct mm_struct;
struct inode;
33

34
#ifdef CONFIG_ARCH_SUPPORTS_UPROBES
35
# include <asm/uprobes.h>
36 37 38 39 40 41 42 43 44
#endif

struct uprobe_consumer {
	int (*handler)(struct uprobe_consumer *self, struct pt_regs *regs);

	struct uprobe_consumer *next;
};

#ifdef CONFIG_UPROBES
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
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;
	struct arch_uprobe_task		autask;

	struct uprobe			*active_uprobe;

	unsigned long			xol_vaddr;
	unsigned long			vaddr;
};

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
/*
 * On a breakpoint hit, thread contests for a slot.  It frees the
 * slot after singlestep. Currently a fixed number of slots are
 * allocated.
 */
struct xol_area {
	wait_queue_head_t 	wq;		/* if all slots are busy */
	atomic_t 		slot_count;	/* number of in-use slots */
	unsigned long 		*bitmap;	/* 0 = free slot */
	struct page 		*page;

	/*
	 * We keep the vma's vm_start rather than a pointer to the vma
	 * itself.  The probed process or a naughty kernel module could make
	 * the vma go away, and we must handle that reasonably gracefully.
	 */
	unsigned long 		vaddr;		/* Page(s) of instruction slots */
};

struct uprobes_state {
	struct xol_area		*xol_area;
};
87

88
extern int __weak set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
89
extern int __weak set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
90
extern bool __weak is_swbp_insn(uprobe_opcode_t *insn);
91 92
extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
extern void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
93
extern int uprobe_mmap(struct vm_area_struct *vma);
94
extern void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end);
95 96
extern void uprobe_start_dup_mmap(void);
extern void uprobe_end_dup_mmap(void);
97
extern void uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm);
98 99 100 101 102 103 104 105
extern void uprobe_free_utask(struct task_struct *t);
extern void uprobe_copy_process(struct task_struct *t);
extern unsigned long __weak uprobe_get_swbp_addr(struct pt_regs *regs);
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);
extern bool __weak arch_uprobe_skip_sstep(struct arch_uprobe *aup, struct pt_regs *regs);
106
extern void uprobe_clear_state(struct mm_struct *mm);
107
#else /* !CONFIG_UPROBES */
108 109
struct uprobes_state {
};
110
static inline int
111
uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
112 113 114
{
	return -ENOSYS;
}
115
static inline void
116
uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
117 118
{
}
119
static inline int uprobe_mmap(struct vm_area_struct *vma)
120 121 122
{
	return 0;
}
123 124
static inline void
uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end)
125 126
{
}
127 128 129 130 131 132
static inline void uprobe_start_dup_mmap(void)
{
}
static inline void uprobe_end_dup_mmap(void)
{
}
133 134 135 136
static inline void
uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm)
{
}
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
static inline void uprobe_notify_resume(struct pt_regs *regs)
{
}
static inline bool uprobe_deny_signal(void)
{
	return false;
}
static inline unsigned long uprobe_get_swbp_addr(struct pt_regs *regs)
{
	return 0;
}
static inline void uprobe_free_utask(struct task_struct *t)
{
}
static inline void uprobe_copy_process(struct task_struct *t)
{
}
154 155 156
static inline void uprobe_clear_state(struct mm_struct *mm)
{
}
157
#endif /* !CONFIG_UPROBES */
158
#endif	/* _LINUX_UPROBES_H */