blob: d1d1e5094c2844d31ff7d2028c950bd42e396312 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_KPROBES_H
2#define _ASM_X86_KPROBES_H
Masami Hiramatsud6be29b2008-01-30 13:31:21 +01003/*
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 */
24#include <linux/types.h>
25#include <linux/ptrace.h>
26#include <linux/percpu.h>
Peter Zijlstra30a813a2010-03-04 13:49:21 +010027#include <asm/insn.h>
Masami Hiramatsud6be29b2008-01-30 13:31:21 +010028
29#define __ARCH_WANT_KPROBES_INSN_SLOT
30
31struct pt_regs;
32struct kprobe;
33
34typedef u8 kprobe_opcode_t;
35#define BREAKPOINT_INSTRUCTION 0xcc
Masami Hiramatsud498f762010-02-25 08:33:49 -050036#define RELATIVEJUMP_OPCODE 0xe9
Masami Hiramatsuc0f7ac32010-02-25 08:34:46 -050037#define RELATIVEJUMP_SIZE 5
38#define RELATIVECALL_OPCODE 0xe8
39#define RELATIVE_ADDR_SIZE 4
Masami Hiramatsud6be29b2008-01-30 13:31:21 +010040#define MAX_STACK_SIZE 64
Linus Torvaldsaca9c292016-06-24 16:55:53 -070041#define CUR_STACK_SIZE(ADDR) \
42 (current_top_of_stack() - (unsigned long)(ADDR))
43#define MIN_STACK_SIZE(ADDR) \
44 (MAX_STACK_SIZE < CUR_STACK_SIZE(ADDR) ? \
45 MAX_STACK_SIZE : CUR_STACK_SIZE(ADDR))
Masami Hiramatsud6be29b2008-01-30 13:31:21 +010046
Masami Hiramatsud6be29b2008-01-30 13:31:21 +010047#define flush_insn_slot(p) do { } while (0)
48
Masami Hiramatsuc0f7ac32010-02-25 08:34:46 -050049/* optinsn template addresses */
Andi Kleen04bb5912013-08-05 15:02:41 -070050extern __visible kprobe_opcode_t optprobe_template_entry;
51extern __visible kprobe_opcode_t optprobe_template_val;
52extern __visible kprobe_opcode_t optprobe_template_call;
53extern __visible kprobe_opcode_t optprobe_template_end;
Masami Hiramatsuc0f7ac32010-02-25 08:34:46 -050054#define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + RELATIVE_ADDR_SIZE)
55#define MAX_OPTINSN_SIZE \
56 (((unsigned long)&optprobe_template_end - \
57 (unsigned long)&optprobe_template_entry) + \
58 MAX_OPTIMIZED_LENGTH + RELATIVEJUMP_SIZE)
59
Masami Hiramatsud6be29b2008-01-30 13:31:21 +010060extern const int kretprobe_blacklist_size;
61
62void arch_remove_kprobe(struct kprobe *p);
Andi Kleen04bb5912013-08-05 15:02:41 -070063asmlinkage void kretprobe_trampoline(void);
Masami Hiramatsud6be29b2008-01-30 13:31:21 +010064
65/* Architecture specific copy of original instruction*/
66struct arch_specific_insn {
67 /* copy of the original instruction */
68 kprobe_opcode_t *insn;
69 /*
70 * boostable = -1: This instruction type is not boostable.
71 * boostable = 0: This instruction type is boostable.
72 * boostable = 1: This instruction has been boosted: we have
73 * added a relative jump after the instruction copy in insn,
74 * so no single-step and fixup are needed (unless there's
75 * a post_handler or break_handler).
76 */
77 int boostable;
Masami Hiramatsu9a556ab2013-03-14 20:52:43 +090078 bool if_modifier;
Masami Hiramatsud6be29b2008-01-30 13:31:21 +010079};
80
Masami Hiramatsuc0f7ac32010-02-25 08:34:46 -050081struct arch_optimized_insn {
82 /* copy of the original instructions */
83 kprobe_opcode_t copied_insn[RELATIVE_ADDR_SIZE];
84 /* detour code buffer */
85 kprobe_opcode_t *insn;
86 /* the size of instructions copied to detour code buffer */
87 size_t size;
88};
89
90/* Return true (!0) if optinsn is prepared for optimization. */
91static inline int arch_prepared_optinsn(struct arch_optimized_insn *optinsn)
92{
93 return optinsn->size;
94}
95
Masami Hiramatsud6be29b2008-01-30 13:31:21 +010096struct prev_kprobe {
97 struct kprobe *kp;
98 unsigned long status;
99 unsigned long old_flags;
100 unsigned long saved_flags;
101};
102
103/* per-cpu kprobe control block */
104struct kprobe_ctlblk {
105 unsigned long kprobe_status;
106 unsigned long kprobe_old_flags;
107 unsigned long kprobe_saved_flags;
108 unsigned long *jprobe_saved_sp;
109 struct pt_regs jprobe_saved_regs;
110 kprobe_opcode_t jprobes_stack[MAX_STACK_SIZE];
111 struct prev_kprobe prev_kprobe;
112};
113
Masami Hiramatsud6be29b2008-01-30 13:31:21 +0100114extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
115extern int kprobe_exceptions_notify(struct notifier_block *self,
116 unsigned long val, void *data);
Masami Hiramatsu6f6343f2014-04-17 17:17:33 +0900117extern int kprobe_int3_handler(struct pt_regs *regs);
118extern int kprobe_debug_handler(struct pt_regs *regs);
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700119#endif /* _ASM_X86_KPROBES_H */