hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/arch/x86/include/asm/kprobes.h
....@@ -1,21 +1,8 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 #ifndef _ASM_X86_KPROBES_H
23 #define _ASM_X86_KPROBES_H
34 /*
45 * 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.
196 *
207 * Copyright (C) IBM Corporation, 2002, 2004
218 *
....@@ -24,12 +11,11 @@
2411
2512 #include <asm-generic/kprobes.h>
2613
27
-#define BREAKPOINT_INSTRUCTION 0xcc
28
-
2914 #ifdef CONFIG_KPROBES
3015 #include <linux/types.h>
3116 #include <linux/ptrace.h>
3217 #include <linux/percpu.h>
18
+#include <asm/text-patching.h>
3319 #include <asm/insn.h>
3420
3521 #define __ARCH_WANT_KPROBES_INSN_SLOT
....@@ -38,10 +24,7 @@
3824 struct kprobe;
3925
4026 typedef u8 kprobe_opcode_t;
41
-#define RELATIVEJUMP_OPCODE 0xe9
42
-#define RELATIVEJUMP_SIZE 5
43
-#define RELATIVECALL_OPCODE 0xe8
44
-#define RELATIVE_ADDR_SIZE 4
27
+
4528 #define MAX_STACK_SIZE 64
4629 #define CUR_STACK_SIZE(ADDR) \
4730 (current_top_of_stack() - (unsigned long)(ADDR))
....@@ -53,14 +36,15 @@
5336
5437 /* optinsn template addresses */
5538 extern __visible kprobe_opcode_t optprobe_template_entry[];
39
+extern __visible kprobe_opcode_t optprobe_template_clac[];
5640 extern __visible kprobe_opcode_t optprobe_template_val[];
5741 extern __visible kprobe_opcode_t optprobe_template_call[];
5842 extern __visible kprobe_opcode_t optprobe_template_end[];
59
-#define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + RELATIVE_ADDR_SIZE)
43
+#define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + DISP32_SIZE)
6044 #define MAX_OPTINSN_SIZE \
6145 (((unsigned long)optprobe_template_end - \
6246 (unsigned long)optprobe_template_entry) + \
63
- MAX_OPTIMIZED_LENGTH + RELATIVEJUMP_SIZE)
47
+ MAX_OPTIMIZED_LENGTH + JMP32_INSN_SIZE)
6448
6549 extern const int kretprobe_blacklist_size;
6650
....@@ -74,19 +58,36 @@
7458 /* copy of the original instruction */
7559 kprobe_opcode_t *insn;
7660 /*
77
- * boostable = false: This instruction type is not boostable.
78
- * boostable = true: This instruction has been boosted: we have
61
+ * boostable = 0: This instruction type is not boostable.
62
+ * boostable = 1: This instruction has been boosted: we have
7963 * added a relative jump after the instruction copy in insn,
8064 * so no single-step and fixup are needed (unless there's
8165 * a post_handler).
8266 */
83
- bool boostable;
84
- bool if_modifier;
67
+ unsigned boostable:1;
68
+ unsigned char size; /* The size of insn */
69
+ union {
70
+ unsigned char opcode;
71
+ struct {
72
+ unsigned char type;
73
+ } jcc;
74
+ struct {
75
+ unsigned char type;
76
+ unsigned char asize;
77
+ } loop;
78
+ struct {
79
+ unsigned char reg;
80
+ } indirect;
81
+ };
82
+ s32 rel32; /* relative offset must be s32, s16, or s8 */
83
+ void (*emulate_op)(struct kprobe *p, struct pt_regs *regs);
84
+ /* Number of bytes of text poked */
85
+ int tp_len;
8586 };
8687
8788 struct arch_optimized_insn {
8889 /* copy of the original instructions */
89
- kprobe_opcode_t copied_insn[RELATIVE_ADDR_SIZE];
90
+ kprobe_opcode_t copied_insn[DISP32_SIZE];
9091 /* detour code buffer */
9192 kprobe_opcode_t *insn;
9293 /* the size of instructions copied to detour code buffer */
....@@ -118,7 +119,10 @@
118119 extern int kprobe_exceptions_notify(struct notifier_block *self,
119120 unsigned long val, void *data);
120121 extern int kprobe_int3_handler(struct pt_regs *regs);
121
-extern int kprobe_debug_handler(struct pt_regs *regs);
122
+
123
+#else
124
+
125
+static inline int kprobe_debug_handler(struct pt_regs *regs) { return 0; }
122126
123127 #endif /* CONFIG_KPROBES */
124128 #endif /* _ASM_X86_KPROBES_H */