diff options
author | Jon Medhurst <tixy@yxit.co.uk> | 2011-04-19 12:56:58 -0400 |
---|---|---|
committer | Tixy <tixy@medhuaa1.miniserver.com> | 2011-07-13 13:32:41 -0400 |
commit | 2437170710c4a3dee137a65623960aa7ac82a32e (patch) | |
tree | c886353a398a3e60c148bfd3e3eb7c3a42486d88 | |
parent | de41984003ed2315dbb7d58168cc3e72e15b075c (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/Makefile | 4 | ||||
-rw-r--r-- | arch/arm/kernel/kprobes-thumb.c | 26 | ||||
-rw-r--r-- | arch/arm/kernel/kprobes.c | 20 | ||||
-rw-r--r-- | arch/arm/kernel/kprobes.h | 13 |
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 | |||
38 | obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o | 38 | obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o |
39 | obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o | 39 | obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o |
40 | obj-$(CONFIG_KPROBES) += kprobes.o kprobes-common.o | 40 | obj-$(CONFIG_KPROBES) += kprobes.o kprobes-common.o |
41 | ifdef CONFIG_THUMB2_KERNEL | ||
42 | obj-$(CONFIG_KPROBES) += kprobes-thumb.o | ||
43 | else | ||
41 | obj-$(CONFIG_KPROBES) += kprobes-arm.o | 44 | obj-$(CONFIG_KPROBES) += kprobes-arm.o |
45 | endif | ||
42 | obj-$(CONFIG_ATAGS_PROC) += atags.o | 46 | obj-$(CONFIG_ATAGS_PROC) += atags.o |
43 | obj-$(CONFIG_OABI_COMPAT) += sys_oabi-compat.o | 47 | obj-$(CONFIG_OABI_COMPAT) += sys_oabi-compat.o |
44 | obj-$(CONFIG_ARM_THUMBEE) += thumbee.o | 48 | obj-$(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 | |||
16 | enum kprobe_insn __kprobes | ||
17 | thumb16_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi) | ||
18 | { | ||
19 | return INSN_REJECTED; | ||
20 | } | ||
21 | |||
22 | enum kprobe_insn __kprobes | ||
23 | thumb32_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 | ||
32 | typedef enum kprobe_insn (kprobe_decode_insn_t)(kprobe_opcode_t, | ||
33 | struct arch_specific_insn *); | ||
34 | |||
35 | #ifdef CONFIG_THUMB2_KERNEL | ||
36 | |||
37 | enum kprobe_insn thumb16_kprobe_decode_insn(kprobe_opcode_t, | ||
38 | struct arch_specific_insn *); | ||
39 | enum kprobe_insn thumb32_kprobe_decode_insn(kprobe_opcode_t, | ||
40 | struct arch_specific_insn *); | ||
41 | |||
42 | #else /* !CONFIG_THUMB2_KERNEL */ | ||
43 | |||
32 | enum kprobe_insn arm_kprobe_decode_insn(kprobe_opcode_t, | 44 | enum kprobe_insn arm_kprobe_decode_insn(kprobe_opcode_t, |
33 | struct arch_specific_insn *); | 45 | struct arch_specific_insn *); |
46 | #endif | ||
34 | 47 | ||
35 | void __init arm_kprobe_decode_init(void); | 48 | void __init arm_kprobe_decode_init(void); |
36 | 49 | ||