Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 #ifndef _ASM_X86_KPROBES_H
0003 #define _ASM_X86_KPROBES_H
0004 /*
0005  *  Kernel Probes (KProbes)
0006  *
0007  * Copyright (C) IBM Corporation, 2002, 2004
0008  *
0009  * See arch/x86/kernel/kprobes.c for x86 kprobes history.
0010  */
0011 
0012 #include <asm-generic/kprobes.h>
0013 
0014 #ifdef CONFIG_KPROBES
0015 #include <linux/types.h>
0016 #include <linux/ptrace.h>
0017 #include <linux/percpu.h>
0018 #include <asm/text-patching.h>
0019 #include <asm/insn.h>
0020 
0021 #define  __ARCH_WANT_KPROBES_INSN_SLOT
0022 
0023 struct pt_regs;
0024 struct kprobe;
0025 
0026 typedef u8 kprobe_opcode_t;
0027 
0028 #define MAX_STACK_SIZE 64
0029 #define CUR_STACK_SIZE(ADDR) \
0030     (current_top_of_stack() - (unsigned long)(ADDR))
0031 #define MIN_STACK_SIZE(ADDR)                \
0032     (MAX_STACK_SIZE < CUR_STACK_SIZE(ADDR) ?    \
0033      MAX_STACK_SIZE : CUR_STACK_SIZE(ADDR))
0034 
0035 #define flush_insn_slot(p)  do { } while (0)
0036 
0037 /* optinsn template addresses */
0038 extern __visible kprobe_opcode_t optprobe_template_entry[];
0039 extern __visible kprobe_opcode_t optprobe_template_clac[];
0040 extern __visible kprobe_opcode_t optprobe_template_val[];
0041 extern __visible kprobe_opcode_t optprobe_template_call[];
0042 extern __visible kprobe_opcode_t optprobe_template_end[];
0043 #define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + DISP32_SIZE)
0044 #define MAX_OPTINSN_SIZE                \
0045     (((unsigned long)optprobe_template_end -    \
0046       (unsigned long)optprobe_template_entry) + \
0047      MAX_OPTIMIZED_LENGTH + JMP32_INSN_SIZE)
0048 
0049 extern const int kretprobe_blacklist_size;
0050 
0051 void arch_remove_kprobe(struct kprobe *p);
0052 
0053 extern void arch_kprobe_override_function(struct pt_regs *regs);
0054 
0055 /* Architecture specific copy of original instruction*/
0056 struct arch_specific_insn {
0057     /* copy of the original instruction */
0058     kprobe_opcode_t *insn;
0059     /*
0060      * boostable = 0: This instruction type is not boostable.
0061      * boostable = 1: This instruction has been boosted: we have
0062      * added a relative jump after the instruction copy in insn,
0063      * so no single-step and fixup are needed (unless there's
0064      * a post_handler).
0065      */
0066     unsigned boostable:1;
0067     unsigned char size; /* The size of insn */
0068     union {
0069         unsigned char opcode;
0070         struct {
0071             unsigned char type;
0072         } jcc;
0073         struct {
0074             unsigned char type;
0075             unsigned char asize;
0076         } loop;
0077         struct {
0078             unsigned char reg;
0079         } indirect;
0080     };
0081     s32 rel32;  /* relative offset must be s32, s16, or s8 */
0082     void (*emulate_op)(struct kprobe *p, struct pt_regs *regs);
0083     /* Number of bytes of text poked */
0084     int tp_len;
0085 };
0086 
0087 struct arch_optimized_insn {
0088     /* copy of the original instructions */
0089     kprobe_opcode_t copied_insn[DISP32_SIZE];
0090     /* detour code buffer */
0091     kprobe_opcode_t *insn;
0092     /* the size of instructions copied to detour code buffer */
0093     size_t size;
0094 };
0095 
0096 /* Return true (!0) if optinsn is prepared for optimization. */
0097 static inline int arch_prepared_optinsn(struct arch_optimized_insn *optinsn)
0098 {
0099     return optinsn->size;
0100 }
0101 
0102 struct prev_kprobe {
0103     struct kprobe *kp;
0104     unsigned long status;
0105     unsigned long old_flags;
0106     unsigned long saved_flags;
0107 };
0108 
0109 /* per-cpu kprobe control block */
0110 struct kprobe_ctlblk {
0111     unsigned long kprobe_status;
0112     unsigned long kprobe_old_flags;
0113     unsigned long kprobe_saved_flags;
0114     struct prev_kprobe prev_kprobe;
0115 };
0116 
0117 extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
0118 extern int kprobe_exceptions_notify(struct notifier_block *self,
0119                     unsigned long val, void *data);
0120 extern int kprobe_int3_handler(struct pt_regs *regs);
0121 
0122 #else
0123 
0124 static inline int kprobe_debug_handler(struct pt_regs *regs) { return 0; }
0125 
0126 #endif /* CONFIG_KPROBES */
0127 #endif /* _ASM_X86_KPROBES_H */