Loading...
1#ifndef _ASM_X86_KPROBES_H
2#define _ASM_X86_KPROBES_H
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>
27#include <asm/insn.h>
28
29#define __ARCH_WANT_KPROBES_INSN_SLOT
30
31struct pt_regs;
32struct kprobe;
33
34typedef u8 kprobe_opcode_t;
35#define BREAKPOINT_INSTRUCTION 0xcc
36#define RELATIVEJUMP_OPCODE 0xe9
37#define RELATIVEJUMP_SIZE 5
38#define RELATIVECALL_OPCODE 0xe8
39#define RELATIVE_ADDR_SIZE 4
40#define MAX_STACK_SIZE 64
41#define MIN_STACK_SIZE(ADDR) \
42 (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
43 THREAD_SIZE - (unsigned long)(ADDR))) \
44 ? (MAX_STACK_SIZE) \
45 : (((unsigned long)current_thread_info()) + \
46 THREAD_SIZE - (unsigned long)(ADDR)))
47
48#define flush_insn_slot(p) do { } while (0)
49
50/* optinsn template addresses */
51extern __visible kprobe_opcode_t optprobe_template_entry;
52extern __visible kprobe_opcode_t optprobe_template_val;
53extern __visible kprobe_opcode_t optprobe_template_call;
54extern __visible kprobe_opcode_t optprobe_template_end;
55#define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + RELATIVE_ADDR_SIZE)
56#define MAX_OPTINSN_SIZE \
57 (((unsigned long)&optprobe_template_end - \
58 (unsigned long)&optprobe_template_entry) + \
59 MAX_OPTIMIZED_LENGTH + RELATIVEJUMP_SIZE)
60
61extern const int kretprobe_blacklist_size;
62
63void arch_remove_kprobe(struct kprobe *p);
64asmlinkage void kretprobe_trampoline(void);
65
66/* Architecture specific copy of original instruction*/
67struct arch_specific_insn {
68 /* copy of the original instruction */
69 kprobe_opcode_t *insn;
70 /*
71 * boostable = -1: This instruction type is not boostable.
72 * boostable = 0: This instruction type is boostable.
73 * boostable = 1: This instruction has been boosted: we have
74 * added a relative jump after the instruction copy in insn,
75 * so no single-step and fixup are needed (unless there's
76 * a post_handler or break_handler).
77 */
78 int boostable;
79 bool if_modifier;
80};
81
82struct arch_optimized_insn {
83 /* copy of the original instructions */
84 kprobe_opcode_t copied_insn[RELATIVE_ADDR_SIZE];
85 /* detour code buffer */
86 kprobe_opcode_t *insn;
87 /* the size of instructions copied to detour code buffer */
88 size_t size;
89};
90
91/* Return true (!0) if optinsn is prepared for optimization. */
92static inline int arch_prepared_optinsn(struct arch_optimized_insn *optinsn)
93{
94 return optinsn->size;
95}
96
97struct prev_kprobe {
98 struct kprobe *kp;
99 unsigned long status;
100 unsigned long old_flags;
101 unsigned long saved_flags;
102};
103
104/* per-cpu kprobe control block */
105struct kprobe_ctlblk {
106 unsigned long kprobe_status;
107 unsigned long kprobe_old_flags;
108 unsigned long kprobe_saved_flags;
109 unsigned long *jprobe_saved_sp;
110 struct pt_regs jprobe_saved_regs;
111 kprobe_opcode_t jprobes_stack[MAX_STACK_SIZE];
112 struct prev_kprobe prev_kprobe;
113};
114
115extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
116extern int kprobe_exceptions_notify(struct notifier_block *self,
117 unsigned long val, void *data);
118extern int kprobe_int3_handler(struct pt_regs *regs);
119extern int kprobe_debug_handler(struct pt_regs *regs);
120#endif /* _ASM_X86_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#ifdef CONFIG_KPROBES
15#include <linux/types.h>
16#include <linux/ptrace.h>
17#include <linux/percpu.h>
18#include <asm/text-patching.h>
19#include <asm/insn.h>
20
21#define __ARCH_WANT_KPROBES_INSN_SLOT
22
23struct pt_regs;
24struct kprobe;
25
26typedef u8 kprobe_opcode_t;
27
28#define MAX_STACK_SIZE 64
29#define CUR_STACK_SIZE(ADDR) \
30 (current_top_of_stack() - (unsigned long)(ADDR))
31#define MIN_STACK_SIZE(ADDR) \
32 (MAX_STACK_SIZE < CUR_STACK_SIZE(ADDR) ? \
33 MAX_STACK_SIZE : CUR_STACK_SIZE(ADDR))
34
35#define flush_insn_slot(p) do { } while (0)
36
37/* optinsn template addresses */
38extern __visible kprobe_opcode_t optprobe_template_entry[];
39extern __visible kprobe_opcode_t optprobe_template_clac[];
40extern __visible kprobe_opcode_t optprobe_template_val[];
41extern __visible kprobe_opcode_t optprobe_template_call[];
42extern __visible kprobe_opcode_t optprobe_template_end[];
43#define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + DISP32_SIZE)
44#define MAX_OPTINSN_SIZE \
45 (((unsigned long)optprobe_template_end - \
46 (unsigned long)optprobe_template_entry) + \
47 MAX_OPTIMIZED_LENGTH + JMP32_INSN_SIZE)
48
49extern const int kretprobe_blacklist_size;
50
51void arch_remove_kprobe(struct kprobe *p);
52
53/* Architecture specific copy of original instruction*/
54struct arch_specific_insn {
55 /* copy of the original instruction */
56 kprobe_opcode_t *insn;
57 /*
58 * boostable = 0: This instruction type is not boostable.
59 * boostable = 1: This instruction has been boosted: we have
60 * added a relative jump after the instruction copy in insn,
61 * so no single-step and fixup are needed (unless there's
62 * a post_handler).
63 */
64 unsigned boostable:1;
65 unsigned char size; /* The size of insn */
66 union {
67 unsigned char opcode;
68 struct {
69 unsigned char type;
70 } jcc;
71 struct {
72 unsigned char type;
73 unsigned char asize;
74 } loop;
75 struct {
76 unsigned char reg;
77 } indirect;
78 };
79 s32 rel32; /* relative offset must be s32, s16, or s8 */
80 void (*emulate_op)(struct kprobe *p, struct pt_regs *regs);
81 /* Number of bytes of text poked */
82 int tp_len;
83};
84
85struct arch_optimized_insn {
86 /* copy of the original instructions */
87 kprobe_opcode_t copied_insn[DISP32_SIZE];
88 /* detour code buffer */
89 kprobe_opcode_t *insn;
90 /* the size of instructions copied to detour code buffer */
91 size_t size;
92};
93
94/* Return true (!0) if optinsn is prepared for optimization. */
95static inline int arch_prepared_optinsn(struct arch_optimized_insn *optinsn)
96{
97 return optinsn->size;
98}
99
100struct prev_kprobe {
101 struct kprobe *kp;
102 unsigned long status;
103 unsigned long old_flags;
104 unsigned long saved_flags;
105};
106
107/* per-cpu kprobe control block */
108struct kprobe_ctlblk {
109 unsigned long kprobe_status;
110 unsigned long kprobe_old_flags;
111 unsigned long kprobe_saved_flags;
112 struct prev_kprobe prev_kprobe;
113};
114
115extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
116extern int kprobe_int3_handler(struct pt_regs *regs);
117
118#else
119
120static inline int kprobe_debug_handler(struct pt_regs *regs) { return 0; }
121
122#endif /* CONFIG_KPROBES */
123#endif /* _ASM_X86_KPROBES_H */