]>
Commit | Line | Data |
---|---|---|
1965aae3 PA |
1 | #ifndef _ASM_X86_KPROBES_H |
2 | #define _ASM_X86_KPROBES_H | |
d6be29b8 MH |
3 | /* |
4 | * Kernel Probes (KProbes) | |
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 as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
19 | * | |
20 | * Copyright (C) IBM Corporation, 2002, 2004 | |
21 | * | |
22 | * See arch/x86/kernel/kprobes.c for x86 kprobes history. | |
23 | */ | |
7d134b2c LR |
24 | |
25 | #include <asm-generic/kprobes.h> | |
26 | ||
27 | #define BREAKPOINT_INSTRUCTION 0xcc | |
28 | ||
29 | #ifdef CONFIG_KPROBES | |
d6be29b8 MH |
30 | #include <linux/types.h> |
31 | #include <linux/ptrace.h> | |
32 | #include <linux/percpu.h> | |
30a813ae | 33 | #include <asm/insn.h> |
d6be29b8 MH |
34 | |
35 | #define __ARCH_WANT_KPROBES_INSN_SLOT | |
36 | ||
37 | struct pt_regs; | |
38 | struct kprobe; | |
39 | ||
40 | typedef u8 kprobe_opcode_t; | |
d498f763 | 41 | #define RELATIVEJUMP_OPCODE 0xe9 |
c0f7ac3a MH |
42 | #define RELATIVEJUMP_SIZE 5 |
43 | #define RELATIVECALL_OPCODE 0xe8 | |
44 | #define RELATIVE_ADDR_SIZE 4 | |
d6be29b8 | 45 | #define MAX_STACK_SIZE 64 |
aca9c293 LT |
46 | #define CUR_STACK_SIZE(ADDR) \ |
47 | (current_top_of_stack() - (unsigned long)(ADDR)) | |
48 | #define MIN_STACK_SIZE(ADDR) \ | |
49 | (MAX_STACK_SIZE < CUR_STACK_SIZE(ADDR) ? \ | |
50 | MAX_STACK_SIZE : CUR_STACK_SIZE(ADDR)) | |
d6be29b8 | 51 | |
d6be29b8 MH |
52 | #define flush_insn_slot(p) do { } while (0) |
53 | ||
c0f7ac3a | 54 | /* optinsn template addresses */ |
54a7d50b LT |
55 | extern __visible kprobe_opcode_t optprobe_template_entry[]; |
56 | extern __visible kprobe_opcode_t optprobe_template_val[]; | |
57 | extern __visible kprobe_opcode_t optprobe_template_call[]; | |
58 | extern __visible kprobe_opcode_t optprobe_template_end[]; | |
c0f7ac3a MH |
59 | #define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + RELATIVE_ADDR_SIZE) |
60 | #define MAX_OPTINSN_SIZE \ | |
a8976fc8 MH |
61 | (((unsigned long)optprobe_template_end - \ |
62 | (unsigned long)optprobe_template_entry) + \ | |
c0f7ac3a MH |
63 | MAX_OPTIMIZED_LENGTH + RELATIVEJUMP_SIZE) |
64 | ||
d6be29b8 MH |
65 | extern const int kretprobe_blacklist_size; |
66 | ||
67 | void arch_remove_kprobe(struct kprobe *p); | |
04bb591c | 68 | asmlinkage void kretprobe_trampoline(void); |
d6be29b8 | 69 | |
b4da3340 | 70 | extern void arch_kprobe_override_function(struct pt_regs *regs); |
9802d865 | 71 | |
d6be29b8 MH |
72 | /* Architecture specific copy of original instruction*/ |
73 | struct arch_specific_insn { | |
74 | /* copy of the original instruction */ | |
75 | kprobe_opcode_t *insn; | |
76 | /* | |
490154bc MH |
77 | * boostable = false: This instruction type is not boostable. |
78 | * boostable = true: This instruction has been boosted: we have | |
d6be29b8 MH |
79 | * added a relative jump after the instruction copy in insn, |
80 | * so no single-step and fixup are needed (unless there's | |
e704e34c | 81 | * a post_handler). |
d6be29b8 | 82 | */ |
490154bc | 83 | bool boostable; |
9a556ab9 | 84 | bool if_modifier; |
d6be29b8 MH |
85 | }; |
86 | ||
c0f7ac3a MH |
87 | struct arch_optimized_insn { |
88 | /* copy of the original instructions */ | |
89 | kprobe_opcode_t copied_insn[RELATIVE_ADDR_SIZE]; | |
90 | /* detour code buffer */ | |
91 | kprobe_opcode_t *insn; | |
92 | /* the size of instructions copied to detour code buffer */ | |
93 | size_t size; | |
94 | }; | |
95 | ||
96 | /* Return true (!0) if optinsn is prepared for optimization. */ | |
97 | static inline int arch_prepared_optinsn(struct arch_optimized_insn *optinsn) | |
98 | { | |
99 | return optinsn->size; | |
100 | } | |
101 | ||
d6be29b8 MH |
102 | struct prev_kprobe { |
103 | struct kprobe *kp; | |
104 | unsigned long status; | |
105 | unsigned long old_flags; | |
106 | unsigned long saved_flags; | |
107 | }; | |
108 | ||
109 | /* per-cpu kprobe control block */ | |
110 | struct kprobe_ctlblk { | |
111 | unsigned long kprobe_status; | |
112 | unsigned long kprobe_old_flags; | |
113 | unsigned long kprobe_saved_flags; | |
d6be29b8 MH |
114 | struct prev_kprobe prev_kprobe; |
115 | }; | |
116 | ||
d6be29b8 MH |
117 | extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr); |
118 | extern int kprobe_exceptions_notify(struct notifier_block *self, | |
119 | unsigned long val, void *data); | |
6f6343f5 MH |
120 | extern int kprobe_int3_handler(struct pt_regs *regs); |
121 | extern int kprobe_debug_handler(struct pt_regs *regs); | |
7d134b2c LR |
122 | |
123 | #endif /* CONFIG_KPROBES */ | |
1965aae3 | 124 | #endif /* _ASM_X86_KPROBES_H */ |