1 #ifndef _ASM_POWERPC_KPROBES_H 2 #define _ASM_POWERPC_KPROBES_H 3 #ifdef __KERNEL__ 4 /* 5 * Kernel Probes (KProbes) 6 * 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. 11 * 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. 16 * 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. 20 * 21 * Copyright (C) IBM Corporation, 2002, 2004 22 * 23 * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel 24 * Probes initial implementation ( includes suggestions from 25 * Rusty Russell). 26 * 2004-Nov Modified for PPC64 by Ananth N Mavinakayanahalli 27 * <ananth@in.ibm.com> 28 */ 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> 35 36 #ifdef CONFIG_KPROBES 37 #define __ARCH_WANT_KPROBES_INSN_SLOT 38 39 struct pt_regs; 40 struct kprobe; 41 42 typedef ppc_opcode_t kprobe_opcode_t; 43 44 extern kprobe_opcode_t optinsn_slot; 45 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[]; 54 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 */ 60 61 #ifdef PPC64_ELF_ABI_v2 62 /* PPC64 ABIv2 needs local entry point */ 63 #define kprobe_lookup_name(name, addr) \ 64 { \ 65 addr = (kprobe_opcode_t *)kallsyms_lookup_name(name); \ 66 if (addr) \ 67 addr = (kprobe_opcode_t *)ppc_function_entry(addr); \ 68 } 69 #elif defined(PPC64_ELF_ABI_v1) 70 /* 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. 74 * 75 * This ensures we always get to the actual symbol and not the descriptor. 76 * Also handle <module:symbol> format. 77 */ 78 #define kprobe_lookup_name(name, addr) \ 79 { \ 80 char dot_name[MODULE_NAME_LEN + 1 + KSYM_NAME_LEN]; \ 81 const char *modsym; \ 82 bool dot_appended = false; \ 83 if ((modsym = strchr(name, ':')) != NULL) { \ 84 modsym++; \ 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; \ 93 } else { \ 94 dot_name[0] = '\0'; \ 95 strncat(dot_name, name, sizeof(dot_name) - 1); \ 96 } \ 97 } else if (name[0] != '.') { \ 98 dot_name[0] = '.'; \ 99 dot_name[1] = '\0'; \ 100 strncat(dot_name, name, KSYM_NAME_LEN - 2); \ 101 dot_appended = true; \ 102 } else { \ 103 dot_name[0] = '\0'; \ 104 strncat(dot_name, name, KSYM_NAME_LEN - 1); \ 105 } \ 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); \ 110 } \ 111 } 112 #endif 113 114 #define flush_insn_slot(p) do { } while (0) 115 #define kretprobe_blacklist_size 0 116 117 void kretprobe_trampoline(void); 118 extern void arch_remove_kprobe(struct kprobe *p); 119 120 /* Architecture specific copy of original instruction */ 121 struct arch_specific_insn { 122 /* copy of original instruction */ 123 kprobe_opcode_t *insn; 124 /* 125 * Set in kprobes code, initially to 0. If the instruction can be 126 * eumulated, this is set to 1, if not, to -1. 127 */ 128 int boostable; 129 }; 130 131 struct prev_kprobe { 132 struct kprobe *kp; 133 unsigned long status; 134 unsigned long saved_msr; 135 }; 136 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; 143 }; 144 145 struct arch_optimized_insn { 146 kprobe_opcode_t copied_insn[1]; 147 /* detour buffer */ 148 kprobe_opcode_t *insn; 149 }; 150 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); 156 #else 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 */ 162