add 'swap_ksyms' module
[kernel/swap-modules.git] / kprobe / arch / dbi_kprobes.c
1 /*
2  *  Kernel Probes (KProbes)
3  *  arch/<arch>/kernel/kprobes.c
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Copyright (C) IBM Corporation, 2002, 2004
20  */
21
22 /*
23  *  Dynamic Binary Instrumentation Module based on KProbes
24  *  modules/kprobe/arch/dbi_kprobes.c
25  *
26  * This program is free software; you can redistribute it and/or modify
27  * it under the terms of the GNU General Public License as published by
28  * the Free Software Foundation; either version 2 of the License, or
29  * (at your option) any later version.
30  *
31  * This program is distributed in the hope that it will be useful,
32  * but WITHOUT ANY WARRANTY; without even the implied warranty of
33  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34  * GNU General Public License for more details.
35  *
36  * You should have received a copy of the GNU General Public License
37  * along with this program; if not, write to the Free Software
38  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
39  *
40  * Copyright (C) Samsung Electronics, 2006-2010
41  *
42  * 2006-2007    Ekaterina Gorelkina <e.gorelkina@samsung.com>: initial implementation for ARM and MIPS
43  * 2008-2009    Alexey Gerenkov <a.gerenkov@samsung.com> User-Space
44  *              Probes initial implementation; Support x86/ARM/MIPS for both user and kernel spaces.
45  * 2010         Ekaterina Gorelkina <e.gorelkina@samsung.com>: redesign module for separating core and arch parts
46  *
47
48  */
49
50 #include "dbi_kprobes.h"
51 #include "../dbi_kprobes.h"
52 #include "asm/dbi_kprobes.h"
53
54 #include "../dbi_kdebug.h"
55 #include "../dbi_insn_slots.h"
56 #include "../dbi_kprobes_deps.h"
57
58 #include <linux/module.h>
59 #include <ksyms.h>
60
61
62 extern unsigned long sched_addr;
63 extern unsigned long fork_addr;
64
65 extern struct hlist_head kprobe_insn_pages;
66 extern struct hlist_head uprobe_insn_pages;
67
68
69 void arch_remove_kprobe (struct kprobe *p, struct task_struct *task)
70 {
71         // TODO: check boostable for x86 and MIPS
72         if (p->tgid) {
73 #ifdef CONFIG_ARM
74                 free_insn_slot(&uprobe_insn_pages, task, p->ainsn.insn_arm);
75                 free_insn_slot(&uprobe_insn_pages, task, p->ainsn.insn_thumb);
76 #else /* CONFIG_ARM */
77                 free_insn_slot(&uprobe_insn_pages, task, p->ainsn.insn);
78 #endif /* CONFIG_ARM */
79         } else {
80                 free_insn_slot(&kprobe_insn_pages, NULL, p->ainsn.insn);
81         }
82 }
83
84 void arch_arm_uprobe (struct kprobe *p, struct task_struct *tsk)
85 {
86         kprobe_opcode_t insn = BREAKPOINT_INSTRUCTION;
87
88         if (!write_proc_vm_atomic (tsk, (unsigned long) p->addr, &insn, sizeof (insn)))
89                 panic ("failed to write memory %p!\n", p->addr);
90 }
91
92 void arch_arm_uretprobe (struct kretprobe *p, struct task_struct *tsk)
93 {
94 }
95
96 void arch_disarm_uprobe (struct kprobe *p, struct task_struct *tsk)
97 {
98         if (!write_proc_vm_atomic (tsk, (unsigned long) p->addr, &p->opcode, sizeof (p->opcode))) {
99                 panic ("failed to write memory: tgid=%u, addr=%p!\n", tsk->tgid, p->addr);
100         }
101 }
102 EXPORT_SYMBOL_GPL(arch_disarm_uprobe);
103
104 void arch_disarm_uretprobe (struct kretprobe *p, struct task_struct *tsk)
105 {
106 }
107
108 int arch_init_module_dependencies()
109 {
110         sched_addr = swap_ksyms("__switch_to");
111         fork_addr = swap_ksyms("do_fork");
112
113         init_module_dependencies();
114
115         return asm_init_module_dependencies();
116 }