1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _ASM_X86_KPROBES_H
3 #define _ASM_X86_KPROBES_H
5 * Kernel Probes (KProbes)
7 * Copyright (C) IBM Corporation, 2002, 2004
9 * See arch/x86/kernel/kprobes.c for x86 kprobes history.
12 #include <asm-generic/kprobes.h>
14 #define BREAKPOINT_INSTRUCTION 0xcc
17 #include <linux/types.h>
18 #include <linux/ptrace.h>
19 #include <linux/percpu.h>
22 #define __ARCH_WANT_KPROBES_INSN_SLOT
27 typedef u8 kprobe_opcode_t
;
28 #define RELATIVEJUMP_OPCODE 0xe9
29 #define RELATIVEJUMP_SIZE 5
30 #define RELATIVECALL_OPCODE 0xe8
31 #define RELATIVE_ADDR_SIZE 4
32 #define MAX_STACK_SIZE 64
33 #define CUR_STACK_SIZE(ADDR) \
34 (current_top_of_stack() - (unsigned long)(ADDR))
35 #define MIN_STACK_SIZE(ADDR) \
36 (MAX_STACK_SIZE < CUR_STACK_SIZE(ADDR) ? \
37 MAX_STACK_SIZE : CUR_STACK_SIZE(ADDR))
39 #define flush_insn_slot(p) do { } while (0)
41 /* optinsn template addresses */
42 extern __visible kprobe_opcode_t optprobe_template_entry
[];
43 extern __visible kprobe_opcode_t optprobe_template_val
[];
44 extern __visible kprobe_opcode_t optprobe_template_call
[];
45 extern __visible kprobe_opcode_t optprobe_template_end
[];
46 #define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + RELATIVE_ADDR_SIZE)
47 #define MAX_OPTINSN_SIZE \
48 (((unsigned long)optprobe_template_end - \
49 (unsigned long)optprobe_template_entry) + \
50 MAX_OPTIMIZED_LENGTH + RELATIVEJUMP_SIZE)
52 extern const int kretprobe_blacklist_size
;
54 void arch_remove_kprobe(struct kprobe
*p
);
55 asmlinkage
void kretprobe_trampoline(void);
57 extern void arch_kprobe_override_function(struct pt_regs
*regs
);
59 /* Architecture specific copy of original instruction*/
60 struct arch_specific_insn
{
61 /* copy of the original instruction */
62 kprobe_opcode_t
*insn
;
64 * boostable = false: This instruction type is not boostable.
65 * boostable = true: This instruction has been boosted: we have
66 * added a relative jump after the instruction copy in insn,
67 * so no single-step and fixup are needed (unless there's
74 struct arch_optimized_insn
{
75 /* copy of the original instructions */
76 kprobe_opcode_t copied_insn
[RELATIVE_ADDR_SIZE
];
77 /* detour code buffer */
78 kprobe_opcode_t
*insn
;
79 /* the size of instructions copied to detour code buffer */
83 /* Return true (!0) if optinsn is prepared for optimization. */
84 static inline int arch_prepared_optinsn(struct arch_optimized_insn
*optinsn
)
92 unsigned long old_flags
;
93 unsigned long saved_flags
;
96 /* per-cpu kprobe control block */
97 struct kprobe_ctlblk
{
98 unsigned long kprobe_status
;
99 unsigned long kprobe_old_flags
;
100 unsigned long kprobe_saved_flags
;
101 struct prev_kprobe prev_kprobe
;
104 extern int kprobe_fault_handler(struct pt_regs
*regs
, int trapnr
);
105 extern int kprobe_exceptions_notify(struct notifier_block
*self
,
106 unsigned long val
, void *data
);
107 extern int kprobe_int3_handler(struct pt_regs
*regs
);
108 extern int kprobe_debug_handler(struct pt_regs
*regs
);
110 #endif /* CONFIG_KPROBES */
111 #endif /* _ASM_X86_KPROBES_H */