2 * Kernel Probes (KProbes)
3 * arch/<arch>/kernel/kprobes.c
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.
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.
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.
19 * Copyright (C) IBM Corporation, 2002, 2004
23 * Dynamic Binary Instrumentation Module based on KProbes
24 * modules/kprobe/arch/dbi_kprobes.c
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.
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.
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.
40 * Copyright (C) Samsung Electronics, 2006-2010
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
50 #include "dbi_kprobes.h"
51 #include "../dbi_kprobes.h"
52 #include "asm/dbi_kprobes.h"
54 #include "../dbi_kdebug.h"
55 #include "../dbi_insn_slots.h"
56 #include "../dbi_kprobes_deps.h"
58 #include <linux/module.h>
60 extern unsigned int *sched_addr;
61 extern unsigned int *fork_addr;
63 extern struct hlist_head kprobe_insn_pages;
64 extern struct hlist_head uprobe_insn_pages;
66 static int ksyms = INVALID_VALUE;
67 module_param (ksyms, int, 0);
69 extern unsigned long (*kallsyms_search) (const char *name);
71 void arch_remove_kprobe (struct kprobe *p, struct task_struct *task)
74 free_insn_slot (&uprobe_insn_pages, task, \
75 p->ainsn.insn, (p->ainsn.boostable == 1));
77 free_insn_slot (&kprobe_insn_pages, NULL, \
78 p->ainsn.insn, (p->ainsn.boostable == 1));
81 void arch_arm_uprobe (struct kprobe *p, struct task_struct *tsk)
83 kprobe_opcode_t insn = BREAKPOINT_INSTRUCTION;
85 if (!write_proc_vm_atomic (tsk, (unsigned long) p->addr, &insn, sizeof (insn)))
86 panic ("failed to write memory %p!\n", p->addr);
89 void arch_arm_uretprobe (struct kretprobe *p, struct task_struct *tsk)
93 void arch_disarm_uprobe (struct kprobe *p, struct task_struct *tsk)
95 if (!write_proc_vm_atomic (tsk, (unsigned long) p->addr, &p->opcode, sizeof (p->opcode)))
96 panic ("failed to write memory %p!\n", p->addr);
99 void arch_disarm_uretprobe (struct kretprobe *p, struct task_struct *tsk)
103 int arch_init_module_dependencies()
106 kallsyms_search = (void *) ksyms;
107 DBPRINTF ("kallsyms=0x%08x\n", ksyms);
109 sched_addr = (unsigned int *)kallsyms_search("__switch_to");//"schedule");
110 fork_addr = (unsigned int *)kallsyms_search("do_fork");
112 init_module_dependencies();
114 return asm_init_module_dependencies();