aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Medhurst <tixy@yxit.co.uk>2011-04-19 12:56:58 -0400
committerTixy <tixy@medhuaa1.miniserver.com>2011-07-13 13:32:41 -0400
commit2437170710c4a3dee137a65623960aa7ac82a32e (patch)
treec886353a398a3e60c148bfd3e3eb7c3a42486d88
parentde41984003ed2315dbb7d58168cc3e72e15b075c (diff)
ARM: kprobes: Add Thumb instruction decoding stubs
Extend arch_prepare_kprobe to support probing of Thumb code. For the actual decoding of Thumb instructions, stub functions are added which currently just reject the probe. Signed-off-by: Jon Medhurst <tixy@yxit.co.uk> Acked-by: Nicolas Pitre <nicolas.pitre@linaro.org>
-rw-r--r--arch/arm/kernel/Makefile4
-rw-r--r--arch/arm/kernel/kprobes-thumb.c26
-rw-r--r--arch/arm/kernel/kprobes.c20
-rw-r--r--arch/arm/kernel/kprobes.h13
4 files changed, 61 insertions, 2 deletions
diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
index a22b8f1c7b14..f7887dc53c1f 100644
--- a/arch/arm/kernel/Makefile
+++ b/arch/arm/kernel/Makefile
@@ -38,7 +38,11 @@ obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o
38obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o 38obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o
39obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o 39obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
40obj-$(CONFIG_KPROBES) += kprobes.o kprobes-common.o 40obj-$(CONFIG_KPROBES) += kprobes.o kprobes-common.o
41ifdef CONFIG_THUMB2_KERNEL
42obj-$(CONFIG_KPROBES) += kprobes-thumb.o
43else
41obj-$(CONFIG_KPROBES) += kprobes-arm.o 44obj-$(CONFIG_KPROBES) += kprobes-arm.o
45endif
42obj-$(CONFIG_ATAGS_PROC) += atags.o 46obj-$(CONFIG_ATAGS_PROC) += atags.o
43obj-$(CONFIG_OABI_COMPAT) += sys_oabi-compat.o 47obj-$(CONFIG_OABI_COMPAT) += sys_oabi-compat.o
44obj-$(CONFIG_ARM_THUMBEE) += thumbee.o 48obj-$(CONFIG_ARM_THUMBEE) += thumbee.o
diff --git a/arch/arm/kernel/kprobes-thumb.c b/arch/arm/kernel/kprobes-thumb.c
new file mode 100644
index 000000000000..ac6b2d138ee5
--- /dev/null
+++ b/arch/arm/kernel/kprobes-thumb.c
@@ -0,0 +1,26 @@
1/*
2 * arch/arm/kernel/kprobes-thumb.c
3 *
4 * Copyright (C) 2011 Jon Medhurst <tixy@yxit.co.uk>.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/kernel.h>
12#include <linux/kprobes.h>
13
14#include "kprobes.h"
15
16enum kprobe_insn __kprobes
17thumb16_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
18{
19 return INSN_REJECTED;
20}
21
22enum kprobe_insn __kprobes
23thumb32_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
24{
25 return INSN_REJECTED;
26}
diff --git a/arch/arm/kernel/kprobes.c b/arch/arm/kernel/kprobes.c
index 0e47d3d67427..0df2d6d57c04 100644
--- a/arch/arm/kernel/kprobes.c
+++ b/arch/arm/kernel/kprobes.c
@@ -51,16 +51,32 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
51 kprobe_opcode_t insn; 51 kprobe_opcode_t insn;
52 kprobe_opcode_t tmp_insn[MAX_INSN_SIZE]; 52 kprobe_opcode_t tmp_insn[MAX_INSN_SIZE];
53 unsigned long addr = (unsigned long)p->addr; 53 unsigned long addr = (unsigned long)p->addr;
54 kprobe_decode_insn_t *decode_insn;
54 int is; 55 int is;
55 56
56 if (addr & 0x3 || in_exception_text(addr)) 57 if (in_exception_text(addr))
57 return -EINVAL; 58 return -EINVAL;
58 59
60#ifdef CONFIG_THUMB2_KERNEL
61 addr &= ~1; /* Bit 0 would normally be set to indicate Thumb code */
62 insn = ((u16 *)addr)[0];
63 if (is_wide_instruction(insn)) {
64 insn <<= 16;
65 insn |= ((u16 *)addr)[1];
66 decode_insn = thumb32_kprobe_decode_insn;
67 } else
68 decode_insn = thumb16_kprobe_decode_insn;
69#else /* !CONFIG_THUMB2_KERNEL */
70 if (addr & 0x3)
71 return -EINVAL;
59 insn = *p->addr; 72 insn = *p->addr;
73 decode_insn = arm_kprobe_decode_insn;
74#endif
75
60 p->opcode = insn; 76 p->opcode = insn;
61 p->ainsn.insn = tmp_insn; 77 p->ainsn.insn = tmp_insn;
62 78
63 switch (arm_kprobe_decode_insn(insn, &p->ainsn)) { 79 switch ((*decode_insn)(insn, &p->ainsn)) {
64 case INSN_REJECTED: /* not supported */ 80 case INSN_REJECTED: /* not supported */
65 return -EINVAL; 81 return -EINVAL;
66 82
diff --git a/arch/arm/kernel/kprobes.h b/arch/arm/kernel/kprobes.h
index 406bb2da7fea..86abfabe83f2 100644
--- a/arch/arm/kernel/kprobes.h
+++ b/arch/arm/kernel/kprobes.h
@@ -29,8 +29,21 @@ enum kprobe_insn {
29 INSN_GOOD_NO_SLOT 29 INSN_GOOD_NO_SLOT
30}; 30};
31 31
32typedef enum kprobe_insn (kprobe_decode_insn_t)(kprobe_opcode_t,
33 struct arch_specific_insn *);
34
35#ifdef CONFIG_THUMB2_KERNEL
36
37enum kprobe_insn thumb16_kprobe_decode_insn(kprobe_opcode_t,
38 struct arch_specific_insn *);
39enum kprobe_insn thumb32_kprobe_decode_insn(kprobe_opcode_t,
40 struct arch_specific_insn *);
41
42#else /* !CONFIG_THUMB2_KERNEL */
43
32enum kprobe_insn arm_kprobe_decode_insn(kprobe_opcode_t, 44enum kprobe_insn arm_kprobe_decode_insn(kprobe_opcode_t,
33 struct arch_specific_insn *); 45 struct arch_specific_insn *);
46#endif
34 47
35void __init arm_kprobe_decode_init(void); 48void __init arm_kprobe_decode_init(void);
36 49