1 #ifndef _ASM_POWERPC_KPROBES_H
2 #define _ASM_POWERPC_KPROBES_H
5 * Kernel Probes (KProbes)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Copyright (C) IBM Corporation, 2002, 2004
23 * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
24 * Probes initial implementation ( includes suggestions from
26 * 2004-Nov Modified for PPC64 by Ananth N Mavinakayanahalli
29 #include <linux/types.h>
30 #include <linux/ptrace.h>
31 #include <linux/percpu.h>
32 #include <linux/module.h>
33 #include <asm/probes.h>
34 #include <asm/code-patching.h>
37 #define __ARCH_WANT_KPROBES_INSN_SLOT
42 typedef ppc_opcode_t kprobe_opcode_t
;
44 extern kprobe_opcode_t optinsn_slot
;
46 /* Optinsn template address */
47 extern kprobe_opcode_t optprobe_template_entry
[];
48 extern kprobe_opcode_t optprobe_template_op_address
[];
49 extern kprobe_opcode_t optprobe_template_call_handler
[];
50 extern kprobe_opcode_t optprobe_template_insn
[];
51 extern kprobe_opcode_t optprobe_template_call_emulate
[];
52 extern kprobe_opcode_t optprobe_template_ret
[];
53 extern kprobe_opcode_t optprobe_template_end
[];
55 /* Fixed instruction size for powerpc */
56 #define MAX_INSN_SIZE 1
57 #define MAX_OPTIMIZED_LENGTH sizeof(kprobe_opcode_t) /* 4 bytes */
58 #define MAX_OPTINSN_SIZE (optprobe_template_end - optprobe_template_entry)
59 #define RELATIVEJUMP_SIZE sizeof(kprobe_opcode_t) /* 4 bytes */
61 #ifdef PPC64_ELF_ABI_v2
62 /* PPC64 ABIv2 needs local entry point */
63 #define kprobe_lookup_name(name, addr) \
65 addr = (kprobe_opcode_t *)kallsyms_lookup_name(name); \
67 addr = (kprobe_opcode_t *)ppc_function_entry(addr); \
69 #elif defined(PPC64_ELF_ABI_v1)
71 * 64bit powerpc ABIv1 uses function descriptors:
72 * - Check for the dot variant of the symbol first.
73 * - If that fails, try looking up the symbol provided.
75 * This ensures we always get to the actual symbol and not the descriptor.
76 * Also handle <module:symbol> format.
78 #define kprobe_lookup_name(name, addr) \
80 char dot_name[MODULE_NAME_LEN + 1 + KSYM_NAME_LEN]; \
82 bool dot_appended = false; \
83 if ((modsym = strchr(name, ':')) != NULL) { \
85 if (*modsym != '\0' && *modsym != '.') { \
86 /* Convert to <module:.symbol> */ \
87 strncpy(dot_name, name, modsym - name); \
88 dot_name[modsym - name] = '.'; \
89 dot_name[modsym - name + 1] = '\0'; \
90 strncat(dot_name, modsym, \
91 sizeof(dot_name) - (modsym - name) - 2);\
92 dot_appended = true; \
95 strncat(dot_name, name, sizeof(dot_name) - 1); \
97 } else if (name[0] != '.') { \
100 strncat(dot_name, name, KSYM_NAME_LEN - 2); \
101 dot_appended = true; \
103 dot_name[0] = '\0'; \
104 strncat(dot_name, name, KSYM_NAME_LEN - 1); \
106 addr = (kprobe_opcode_t *)kallsyms_lookup_name(dot_name); \
107 if (!addr && dot_appended) { \
108 /* Let's try the original non-dot symbol lookup */ \
109 addr = (kprobe_opcode_t *)kallsyms_lookup_name(name); \
114 #define flush_insn_slot(p) do { } while (0)
115 #define kretprobe_blacklist_size 0
117 void kretprobe_trampoline(void);
118 extern void arch_remove_kprobe(struct kprobe
*p
);
120 /* Architecture specific copy of original instruction */
121 struct arch_specific_insn
{
122 /* copy of original instruction */
123 kprobe_opcode_t
*insn
;
125 * Set in kprobes code, initially to 0. If the instruction can be
126 * eumulated, this is set to 1, if not, to -1.
133 unsigned long status
;
134 unsigned long saved_msr
;
137 /* per-cpu kprobe control block */
138 struct kprobe_ctlblk
{
139 unsigned long kprobe_status
;
140 unsigned long kprobe_saved_msr
;
141 struct pt_regs jprobe_saved_regs
;
142 struct prev_kprobe prev_kprobe
;
145 struct arch_optimized_insn
{
146 kprobe_opcode_t copied_insn
[1];
148 kprobe_opcode_t
*insn
;
151 extern int kprobe_exceptions_notify(struct notifier_block
*self
,
152 unsigned long val
, void *data
);
153 extern int kprobe_fault_handler(struct pt_regs
*regs
, int trapnr
);
154 extern int kprobe_handler(struct pt_regs
*regs
);
155 extern int kprobe_post_handler(struct pt_regs
*regs
);
157 static inline int kprobe_handler(struct pt_regs
*regs
) { return 0; }
158 static inline int kprobe_post_handler(struct pt_regs
*regs
) { return 0; }
159 #endif /* CONFIG_KPROBES */
160 #endif /* __KERNEL__ */
161 #endif /* _ASM_POWERPC_KPROBES_H */