1 #ifndef _SRC_ASM_X86_KPROBES_H
2 #define _SRC_ASM_X86_KPROBES_H
5 * Kernel Probes (KProbes)
6 * include/linux/kprobes.h
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * Copyright (C) IBM Corporation, 2002, 2004
26 * Dynamic Binary Instrumentation Module based on KProbes
27 * modules/kprobe/arch/asm-x86/dbi_kprobes.c
29 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation; either version 2 of the License, or
32 * (at your option) any later version.
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
43 * Copyright (C) Samsung Electronics, 2006-2010
45 * 2008-2009 Alexey Gerenkov <a.gerenkov@samsung.com> User-Space
46 * Probes initial implementation; Support x86/ARM/MIPS for both user and kernel spaces.
47 * 2010 Ekaterina Gorelkina <e.gorelkina@samsung.com>: redesign module for separating core and arch parts
52 #include "dbi_kprobe_deps.h"
53 #include "arch/dbi_kprobes.h"
55 typedef u8 kprobe_opcode_t;
57 #define BREAKPOINT_INSTRUCTION 0xcc
58 #define RELATIVEJUMP_INSTRUCTION 0xe9
60 #define MAX_INSN_SIZE 16
61 #define MAX_STACK_SIZE 64
63 #define MIN_STACK_SIZE(ADDR) (((MAX_STACK_SIZE) < \
64 (((unsigned long)current_thread_info()) \
65 + THREAD_SIZE - (ADDR))) \
67 : (((unsigned long)current_thread_info()) \
68 + THREAD_SIZE - (ADDR)))
70 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
72 #define EREG(rg) e##rg
73 #define XREG(rg) x##rg
74 #define ORIG_EAX_REG orig_eax
80 #define ORIG_EAX_REG orig_ax
82 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) */
84 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
85 #define TF_MASK X86_EFLAGS_TF
86 #define IF_MASK X86_EFLAGS_IF
88 #define UPROBES_TRAMP_LEN (MAX_INSN_SIZE+sizeof(kprobe_opcode_t))
89 #define UPROBES_TRAMP_INSN_IDX 0
90 #define UPROBES_TRAMP_RET_BREAK_IDX MAX_INSN_SIZE
91 #define KPROBES_TRAMP_LEN MAX_INSN_SIZE
92 #define KPROBES_TRAMP_INSN_IDX 0
94 static struct notifier_block kprobe_exceptions_nb = {
95 .notifier_call = kprobe_exceptions_notify,
101 unsigned long status;
102 unsigned long old_eflags;
103 unsigned long saved_eflags;
106 /* per-cpu kprobe control block */
107 struct kprobe_ctlblk {
108 unsigned long kprobe_status;
109 struct prev_kprobe prev_kprobe;
110 struct pt_regs jprobe_saved_regs;
111 unsigned long kprobe_old_eflags;
112 unsigned long kprobe_saved_eflags;
113 unsigned long *jprobe_saved_esp;
114 kprobe_opcode_t jprobes_stack[MAX_STACK_SIZE];
117 extern int kprobe_exceptions_notify (struct notifier_block *self, unsigned long val, void *data);
119 void __kprobes resume_execution
120 (struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb);
122 int __kprobes post_kprobe_handler (struct pt_regs *regs);
125 kprobe_fault_handler (struct pt_regs *regs, int trapnr);
127 void *__kprobes trampoline_probe_handler_x86 (struct pt_regs *regs);
129 DECLARE_MOD_FUNC_DEP(module_alloc, void *, unsigned long size);
130 DECLARE_MOD_FUNC_DEP(module_free, void, struct module *mod, void *module_region);
131 DECLARE_MOD_FUNC_DEP(fixup_exception, int, struct pt_regs * regs);
133 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26))
134 DECLARE_MOD_FUNC_DEP(text_poke, void, void *addr, unsigned char *opcode, int len);
136 DECLARE_MOD_FUNC_DEP(text_poke, void *, void *addr, const void *opcode, size_t len);
138 DECLARE_MOD_FUNC_DEP(show_registers, void, struct pt_regs * regs);
140 /* Architecture specific copy of original instruction */
141 struct arch_specific_insn {
142 /* copy of the original instruction */
143 kprobe_opcode_t *insn;
145 * If this flag is not 0, this kprobe can be boost when its
146 * post_handler and break_handler is not set.
151 typedef kprobe_opcode_t (*entry_point_t) (unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
155 #endif /* _SRC_ASM_X86_KPROBES_H */