xref: /OK3568_Linux_fs/kernel/arch/arm/include/asm/kprobes.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * arch/arm/include/asm/kprobes.h
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2006, 2007 Motorola Inc.
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef _ARM_KPROBES_H
9*4882a593Smuzhiyun #define _ARM_KPROBES_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <asm-generic/kprobes.h>
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #ifdef CONFIG_KPROBES
14*4882a593Smuzhiyun #include <linux/types.h>
15*4882a593Smuzhiyun #include <linux/ptrace.h>
16*4882a593Smuzhiyun #include <linux/notifier.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #define __ARCH_WANT_KPROBES_INSN_SLOT
19*4882a593Smuzhiyun #define MAX_INSN_SIZE			2
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #define flush_insn_slot(p)		do { } while (0)
22*4882a593Smuzhiyun #define kretprobe_blacklist_size	0
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun typedef u32 kprobe_opcode_t;
25*4882a593Smuzhiyun struct kprobe;
26*4882a593Smuzhiyun #include <asm/probes.h>
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #define	arch_specific_insn	arch_probes_insn
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun struct prev_kprobe {
31*4882a593Smuzhiyun 	struct kprobe *kp;
32*4882a593Smuzhiyun 	unsigned int status;
33*4882a593Smuzhiyun };
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun /* per-cpu kprobe control block */
36*4882a593Smuzhiyun struct kprobe_ctlblk {
37*4882a593Smuzhiyun 	unsigned int kprobe_status;
38*4882a593Smuzhiyun 	struct prev_kprobe prev_kprobe;
39*4882a593Smuzhiyun };
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun void arch_remove_kprobe(struct kprobe *);
42*4882a593Smuzhiyun int kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr);
43*4882a593Smuzhiyun int kprobe_exceptions_notify(struct notifier_block *self,
44*4882a593Smuzhiyun 			     unsigned long val, void *data);
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /* optinsn template addresses */
47*4882a593Smuzhiyun extern __visible kprobe_opcode_t optprobe_template_entry[];
48*4882a593Smuzhiyun extern __visible kprobe_opcode_t optprobe_template_val[];
49*4882a593Smuzhiyun extern __visible kprobe_opcode_t optprobe_template_call[];
50*4882a593Smuzhiyun extern __visible kprobe_opcode_t optprobe_template_end[];
51*4882a593Smuzhiyun extern __visible kprobe_opcode_t optprobe_template_sub_sp[];
52*4882a593Smuzhiyun extern __visible kprobe_opcode_t optprobe_template_add_sp[];
53*4882a593Smuzhiyun extern __visible kprobe_opcode_t optprobe_template_restore_begin[];
54*4882a593Smuzhiyun extern __visible kprobe_opcode_t optprobe_template_restore_orig_insn[];
55*4882a593Smuzhiyun extern __visible kprobe_opcode_t optprobe_template_restore_end[];
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun #define MAX_OPTIMIZED_LENGTH	4
58*4882a593Smuzhiyun #define MAX_OPTINSN_SIZE				\
59*4882a593Smuzhiyun 	((unsigned long)optprobe_template_end -	\
60*4882a593Smuzhiyun 	 (unsigned long)optprobe_template_entry)
61*4882a593Smuzhiyun #define RELATIVEJUMP_SIZE	4
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun struct arch_optimized_insn {
64*4882a593Smuzhiyun 	/*
65*4882a593Smuzhiyun 	 * copy of the original instructions.
66*4882a593Smuzhiyun 	 * Different from x86, ARM kprobe_opcode_t is u32.
67*4882a593Smuzhiyun 	 */
68*4882a593Smuzhiyun #define MAX_COPIED_INSN	DIV_ROUND_UP(RELATIVEJUMP_SIZE, sizeof(kprobe_opcode_t))
69*4882a593Smuzhiyun 	kprobe_opcode_t copied_insn[MAX_COPIED_INSN];
70*4882a593Smuzhiyun 	/* detour code buffer */
71*4882a593Smuzhiyun 	kprobe_opcode_t *insn;
72*4882a593Smuzhiyun 	/*
73*4882a593Smuzhiyun 	 * We always copy one instruction on ARM,
74*4882a593Smuzhiyun 	 * so size will always be 4, and unlike x86, there is no
75*4882a593Smuzhiyun 	 * need for a size field.
76*4882a593Smuzhiyun 	 */
77*4882a593Smuzhiyun };
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun #endif /* CONFIG_KPROBES */
80*4882a593Smuzhiyun #endif /* _ARM_KPROBES_H */
81