]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - arch/x86/include/asm/kprobes.h
Merge tag 'v5.2-rc2-smb3-fixes' of git://git.samba.org/sfrench/cifs-2.6
[mirror_ubuntu-jammy-kernel.git] / arch / x86 / include / asm / kprobes.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _ASM_X86_KPROBES_H
3 #define _ASM_X86_KPROBES_H
4 /*
5 * Kernel Probes (KProbes)
6 *
7 * Copyright (C) IBM Corporation, 2002, 2004
8 *
9 * See arch/x86/kernel/kprobes.c for x86 kprobes history.
10 */
11
12 #include <asm-generic/kprobes.h>
13
14 #define BREAKPOINT_INSTRUCTION 0xcc
15
16 #ifdef CONFIG_KPROBES
17 #include <linux/types.h>
18 #include <linux/ptrace.h>
19 #include <linux/percpu.h>
20 #include <asm/insn.h>
21
22 #define __ARCH_WANT_KPROBES_INSN_SLOT
23
24 struct pt_regs;
25 struct kprobe;
26
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))
38
39 #define flush_insn_slot(p) do { } while (0)
40
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)
51
52 extern const int kretprobe_blacklist_size;
53
54 void arch_remove_kprobe(struct kprobe *p);
55 asmlinkage void kretprobe_trampoline(void);
56
57 extern void arch_kprobe_override_function(struct pt_regs *regs);
58
59 /* Architecture specific copy of original instruction*/
60 struct arch_specific_insn {
61 /* copy of the original instruction */
62 kprobe_opcode_t *insn;
63 /*
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
68 * a post_handler).
69 */
70 bool boostable;
71 bool if_modifier;
72 };
73
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 */
80 size_t size;
81 };
82
83 /* Return true (!0) if optinsn is prepared for optimization. */
84 static inline int arch_prepared_optinsn(struct arch_optimized_insn *optinsn)
85 {
86 return optinsn->size;
87 }
88
89 struct prev_kprobe {
90 struct kprobe *kp;
91 unsigned long status;
92 unsigned long old_flags;
93 unsigned long saved_flags;
94 };
95
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;
102 };
103
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);
109
110 #endif /* CONFIG_KPROBES */
111 #endif /* _ASM_X86_KPROBES_H */