H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_KPROBES_H |
| 2 | #define _ASM_X86_KPROBES_H |
Masami Hiramatsu | d6be29b | 2008-01-30 13:31:21 +0100 | [diff] [blame] | 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 | */ |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/ptrace.h> |
| 26 | #include <linux/percpu.h> |
Peter Zijlstra | 30a813a | 2010-03-04 13:49:21 +0100 | [diff] [blame] | 27 | #include <asm/insn.h> |
Masami Hiramatsu | d6be29b | 2008-01-30 13:31:21 +0100 | [diff] [blame] | 28 | |
| 29 | #define __ARCH_WANT_KPROBES_INSN_SLOT |
Masami Hiramatsu | e525389 | 2012-06-05 19:28:38 +0900 | [diff] [blame] | 30 | #define ARCH_SUPPORTS_KPROBES_ON_FTRACE |
Masami Hiramatsu | d6be29b | 2008-01-30 13:31:21 +0100 | [diff] [blame] | 31 | |
| 32 | struct pt_regs; |
| 33 | struct kprobe; |
| 34 | |
| 35 | typedef u8 kprobe_opcode_t; |
| 36 | #define BREAKPOINT_INSTRUCTION 0xcc |
Masami Hiramatsu | d498f76 | 2010-02-25 08:33:49 -0500 | [diff] [blame] | 37 | #define RELATIVEJUMP_OPCODE 0xe9 |
Masami Hiramatsu | c0f7ac3 | 2010-02-25 08:34:46 -0500 | [diff] [blame] | 38 | #define RELATIVEJUMP_SIZE 5 |
| 39 | #define RELATIVECALL_OPCODE 0xe8 |
| 40 | #define RELATIVE_ADDR_SIZE 4 |
Masami Hiramatsu | d6be29b | 2008-01-30 13:31:21 +0100 | [diff] [blame] | 41 | #define MAX_STACK_SIZE 64 |
Joe Perches | 864dfa1 | 2008-03-23 01:02:33 -0700 | [diff] [blame] | 42 | #define MIN_STACK_SIZE(ADDR) \ |
| 43 | (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \ |
| 44 | THREAD_SIZE - (unsigned long)(ADDR))) \ |
| 45 | ? (MAX_STACK_SIZE) \ |
| 46 | : (((unsigned long)current_thread_info()) + \ |
| 47 | THREAD_SIZE - (unsigned long)(ADDR))) |
Masami Hiramatsu | d6be29b | 2008-01-30 13:31:21 +0100 | [diff] [blame] | 48 | |
Masami Hiramatsu | d6be29b | 2008-01-30 13:31:21 +0100 | [diff] [blame] | 49 | #define flush_insn_slot(p) do { } while (0) |
| 50 | |
Masami Hiramatsu | c0f7ac3 | 2010-02-25 08:34:46 -0500 | [diff] [blame] | 51 | /* optinsn template addresses */ |
Andi Kleen | 04bb591 | 2013-08-05 15:02:41 -0700 | [diff] [blame] | 52 | extern __visible kprobe_opcode_t optprobe_template_entry; |
| 53 | extern __visible kprobe_opcode_t optprobe_template_val; |
| 54 | extern __visible kprobe_opcode_t optprobe_template_call; |
| 55 | extern __visible kprobe_opcode_t optprobe_template_end; |
Masami Hiramatsu | c0f7ac3 | 2010-02-25 08:34:46 -0500 | [diff] [blame] | 56 | #define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + RELATIVE_ADDR_SIZE) |
| 57 | #define MAX_OPTINSN_SIZE \ |
| 58 | (((unsigned long)&optprobe_template_end - \ |
| 59 | (unsigned long)&optprobe_template_entry) + \ |
| 60 | MAX_OPTIMIZED_LENGTH + RELATIVEJUMP_SIZE) |
| 61 | |
Masami Hiramatsu | d6be29b | 2008-01-30 13:31:21 +0100 | [diff] [blame] | 62 | extern const int kretprobe_blacklist_size; |
| 63 | |
| 64 | void arch_remove_kprobe(struct kprobe *p); |
Andi Kleen | 04bb591 | 2013-08-05 15:02:41 -0700 | [diff] [blame] | 65 | asmlinkage void kretprobe_trampoline(void); |
Masami Hiramatsu | d6be29b | 2008-01-30 13:31:21 +0100 | [diff] [blame] | 66 | |
| 67 | /* Architecture specific copy of original instruction*/ |
| 68 | struct arch_specific_insn { |
| 69 | /* copy of the original instruction */ |
| 70 | kprobe_opcode_t *insn; |
| 71 | /* |
| 72 | * boostable = -1: This instruction type is not boostable. |
| 73 | * boostable = 0: This instruction type is boostable. |
| 74 | * boostable = 1: This instruction has been boosted: we have |
| 75 | * added a relative jump after the instruction copy in insn, |
| 76 | * so no single-step and fixup are needed (unless there's |
| 77 | * a post_handler or break_handler). |
| 78 | */ |
| 79 | int boostable; |
Masami Hiramatsu | 9a556ab | 2013-03-14 20:52:43 +0900 | [diff] [blame] | 80 | bool if_modifier; |
Masami Hiramatsu | d6be29b | 2008-01-30 13:31:21 +0100 | [diff] [blame] | 81 | }; |
| 82 | |
Masami Hiramatsu | c0f7ac3 | 2010-02-25 08:34:46 -0500 | [diff] [blame] | 83 | struct arch_optimized_insn { |
| 84 | /* copy of the original instructions */ |
| 85 | kprobe_opcode_t copied_insn[RELATIVE_ADDR_SIZE]; |
| 86 | /* detour code buffer */ |
| 87 | kprobe_opcode_t *insn; |
| 88 | /* the size of instructions copied to detour code buffer */ |
| 89 | size_t size; |
| 90 | }; |
| 91 | |
| 92 | /* Return true (!0) if optinsn is prepared for optimization. */ |
| 93 | static inline int arch_prepared_optinsn(struct arch_optimized_insn *optinsn) |
| 94 | { |
| 95 | return optinsn->size; |
| 96 | } |
| 97 | |
Masami Hiramatsu | d6be29b | 2008-01-30 13:31:21 +0100 | [diff] [blame] | 98 | struct prev_kprobe { |
| 99 | struct kprobe *kp; |
| 100 | unsigned long status; |
| 101 | unsigned long old_flags; |
| 102 | unsigned long saved_flags; |
| 103 | }; |
| 104 | |
| 105 | /* per-cpu kprobe control block */ |
| 106 | struct kprobe_ctlblk { |
| 107 | unsigned long kprobe_status; |
| 108 | unsigned long kprobe_old_flags; |
| 109 | unsigned long kprobe_saved_flags; |
| 110 | unsigned long *jprobe_saved_sp; |
| 111 | struct pt_regs jprobe_saved_regs; |
| 112 | kprobe_opcode_t jprobes_stack[MAX_STACK_SIZE]; |
| 113 | struct prev_kprobe prev_kprobe; |
| 114 | }; |
| 115 | |
Masami Hiramatsu | d6be29b | 2008-01-30 13:31:21 +0100 | [diff] [blame] | 116 | extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr); |
| 117 | extern int kprobe_exceptions_notify(struct notifier_block *self, |
| 118 | unsigned long val, void *data); |
Masami Hiramatsu | 6f6343f | 2014-04-17 17:17:33 +0900 | [diff] [blame^] | 119 | extern int kprobe_int3_handler(struct pt_regs *regs); |
| 120 | extern int kprobe_debug_handler(struct pt_regs *regs); |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 121 | #endif /* _ASM_X86_KPROBES_H */ |