Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Kernel Probes (KProbes) |
| 3 | * arch/ia64/kernel/kprobes.c |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | * |
| 19 | * Copyright (C) IBM Corporation, 2002, 2004 |
| 20 | * Copyright (C) Intel Corporation, 2005 |
| 21 | * |
| 22 | * 2005-Apr Rusty Lynch <rusty.lynch@intel.com> and Anil S Keshavamurthy |
| 23 | * <anil.s.keshavamurthy@intel.com> adapted from i386 |
| 24 | */ |
| 25 | |
| 26 | #include <linux/config.h> |
| 27 | #include <linux/kprobes.h> |
| 28 | #include <linux/ptrace.h> |
| 29 | #include <linux/spinlock.h> |
| 30 | #include <linux/string.h> |
| 31 | #include <linux/slab.h> |
| 32 | #include <linux/preempt.h> |
| 33 | #include <linux/moduleloader.h> |
| 34 | |
| 35 | #include <asm/pgtable.h> |
| 36 | #include <asm/kdebug.h> |
Keshavamurthy Anil S | c7b645f | 2005-06-27 15:17:16 -0700 | [diff] [blame] | 37 | #include <asm/sections.h> |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 38 | |
Anil S Keshavamurthy | b2761dc | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 39 | extern void jprobe_inst_return(void); |
| 40 | |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 41 | /* kprobe_status settings */ |
| 42 | #define KPROBE_HIT_ACTIVE 0x00000001 |
| 43 | #define KPROBE_HIT_SS 0x00000002 |
| 44 | |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 45 | static struct kprobe *current_kprobe, *kprobe_prev; |
| 46 | static unsigned long kprobe_status, kprobe_status_prev; |
Anil S Keshavamurthy | b2761dc | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 47 | static struct pt_regs jprobe_saved_regs; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 48 | |
| 49 | enum instruction_type {A, I, M, F, B, L, X, u}; |
| 50 | static enum instruction_type bundle_encoding[32][3] = { |
| 51 | { M, I, I }, /* 00 */ |
| 52 | { M, I, I }, /* 01 */ |
| 53 | { M, I, I }, /* 02 */ |
| 54 | { M, I, I }, /* 03 */ |
| 55 | { M, L, X }, /* 04 */ |
| 56 | { M, L, X }, /* 05 */ |
| 57 | { u, u, u }, /* 06 */ |
| 58 | { u, u, u }, /* 07 */ |
| 59 | { M, M, I }, /* 08 */ |
| 60 | { M, M, I }, /* 09 */ |
| 61 | { M, M, I }, /* 0A */ |
| 62 | { M, M, I }, /* 0B */ |
| 63 | { M, F, I }, /* 0C */ |
| 64 | { M, F, I }, /* 0D */ |
| 65 | { M, M, F }, /* 0E */ |
| 66 | { M, M, F }, /* 0F */ |
| 67 | { M, I, B }, /* 10 */ |
| 68 | { M, I, B }, /* 11 */ |
| 69 | { M, B, B }, /* 12 */ |
| 70 | { M, B, B }, /* 13 */ |
| 71 | { u, u, u }, /* 14 */ |
| 72 | { u, u, u }, /* 15 */ |
| 73 | { B, B, B }, /* 16 */ |
| 74 | { B, B, B }, /* 17 */ |
| 75 | { M, M, B }, /* 18 */ |
| 76 | { M, M, B }, /* 19 */ |
| 77 | { u, u, u }, /* 1A */ |
| 78 | { u, u, u }, /* 1B */ |
| 79 | { M, F, B }, /* 1C */ |
| 80 | { M, F, B }, /* 1D */ |
| 81 | { u, u, u }, /* 1E */ |
| 82 | { u, u, u }, /* 1F */ |
| 83 | }; |
| 84 | |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 85 | /* |
| 86 | * In this function we check to see if the instruction |
| 87 | * is IP relative instruction and update the kprobe |
| 88 | * inst flag accordingly |
| 89 | */ |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 90 | static void __kprobes update_kprobe_inst_flag(uint template, uint slot, |
| 91 | uint major_opcode, |
| 92 | unsigned long kprobe_inst, |
| 93 | struct kprobe *p) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 94 | { |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 95 | p->ainsn.inst_flag = 0; |
| 96 | p->ainsn.target_br_reg = 0; |
| 97 | |
Keshavamurthy Anil S | deac66a | 2005-09-06 15:19:35 -0700 | [diff] [blame] | 98 | /* Check for Break instruction |
| 99 | * Bits 37:40 Major opcode to be zero |
| 100 | * Bits 27:32 X6 to be zero |
| 101 | * Bits 32:35 X3 to be zero |
| 102 | */ |
| 103 | if ((!major_opcode) && (!((kprobe_inst >> 27) & 0x1FF)) ) { |
| 104 | /* is a break instruction */ |
| 105 | p->ainsn.inst_flag |= INST_FLAG_BREAK_INST; |
| 106 | return; |
| 107 | } |
| 108 | |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 109 | if (bundle_encoding[template][slot] == B) { |
| 110 | switch (major_opcode) { |
| 111 | case INDIRECT_CALL_OPCODE: |
| 112 | p->ainsn.inst_flag |= INST_FLAG_FIX_BRANCH_REG; |
| 113 | p->ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7); |
| 114 | break; |
| 115 | case IP_RELATIVE_PREDICT_OPCODE: |
| 116 | case IP_RELATIVE_BRANCH_OPCODE: |
| 117 | p->ainsn.inst_flag |= INST_FLAG_FIX_RELATIVE_IP_ADDR; |
| 118 | break; |
| 119 | case IP_RELATIVE_CALL_OPCODE: |
| 120 | p->ainsn.inst_flag |= INST_FLAG_FIX_RELATIVE_IP_ADDR; |
| 121 | p->ainsn.inst_flag |= INST_FLAG_FIX_BRANCH_REG; |
| 122 | p->ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7); |
| 123 | break; |
| 124 | } |
| 125 | } else if (bundle_encoding[template][slot] == X) { |
| 126 | switch (major_opcode) { |
| 127 | case LONG_CALL_OPCODE: |
| 128 | p->ainsn.inst_flag |= INST_FLAG_FIX_BRANCH_REG; |
| 129 | p->ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7); |
| 130 | break; |
| 131 | } |
| 132 | } |
| 133 | return; |
| 134 | } |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 135 | |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 136 | /* |
Anil S Keshavamurthy | 1674eaf | 2005-06-23 00:09:33 -0700 | [diff] [blame] | 137 | * In this function we check to see if the instruction |
Anil S Keshavamurthy | 708de8f | 2005-06-23 00:09:34 -0700 | [diff] [blame] | 138 | * on which we are inserting kprobe is supported. |
| 139 | * Returns 0 if supported |
| 140 | * Returns -EINVAL if unsupported |
| 141 | */ |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 142 | static int __kprobes unsupported_inst(uint template, uint slot, |
| 143 | uint major_opcode, |
| 144 | unsigned long kprobe_inst, |
| 145 | struct kprobe *p) |
Anil S Keshavamurthy | 708de8f | 2005-06-23 00:09:34 -0700 | [diff] [blame] | 146 | { |
| 147 | unsigned long addr = (unsigned long)p->addr; |
| 148 | |
| 149 | if (bundle_encoding[template][slot] == I) { |
| 150 | switch (major_opcode) { |
| 151 | case 0x0: //I_UNIT_MISC_OPCODE: |
| 152 | /* |
| 153 | * Check for Integer speculation instruction |
| 154 | * - Bit 33-35 to be equal to 0x1 |
| 155 | */ |
| 156 | if (((kprobe_inst >> 33) & 0x7) == 1) { |
| 157 | printk(KERN_WARNING |
| 158 | "Kprobes on speculation inst at <0x%lx> not supported\n", |
| 159 | addr); |
| 160 | return -EINVAL; |
| 161 | } |
| 162 | |
| 163 | /* |
| 164 | * IP relative mov instruction |
| 165 | * - Bit 27-35 to be equal to 0x30 |
| 166 | */ |
| 167 | if (((kprobe_inst >> 27) & 0x1FF) == 0x30) { |
| 168 | printk(KERN_WARNING |
| 169 | "Kprobes on \"mov r1=ip\" at <0x%lx> not supported\n", |
| 170 | addr); |
| 171 | return -EINVAL; |
| 172 | |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | |
| 180 | /* |
| 181 | * In this function we check to see if the instruction |
Anil S Keshavamurthy | 1674eaf | 2005-06-23 00:09:33 -0700 | [diff] [blame] | 182 | * (qp) cmpx.crel.ctype p1,p2=r2,r3 |
| 183 | * on which we are inserting kprobe is cmp instruction |
| 184 | * with ctype as unc. |
| 185 | */ |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 186 | static uint __kprobes is_cmp_ctype_unc_inst(uint template, uint slot, |
| 187 | uint major_opcode, |
| 188 | unsigned long kprobe_inst) |
Anil S Keshavamurthy | 1674eaf | 2005-06-23 00:09:33 -0700 | [diff] [blame] | 189 | { |
| 190 | cmp_inst_t cmp_inst; |
| 191 | uint ctype_unc = 0; |
| 192 | |
| 193 | if (!((bundle_encoding[template][slot] == I) || |
| 194 | (bundle_encoding[template][slot] == M))) |
| 195 | goto out; |
| 196 | |
| 197 | if (!((major_opcode == 0xC) || (major_opcode == 0xD) || |
| 198 | (major_opcode == 0xE))) |
| 199 | goto out; |
| 200 | |
| 201 | cmp_inst.l = kprobe_inst; |
| 202 | if ((cmp_inst.f.x2 == 0) || (cmp_inst.f.x2 == 1)) { |
| 203 | /* Integere compare - Register Register (A6 type)*/ |
| 204 | if ((cmp_inst.f.tb == 0) && (cmp_inst.f.ta == 0) |
| 205 | &&(cmp_inst.f.c == 1)) |
| 206 | ctype_unc = 1; |
| 207 | } else if ((cmp_inst.f.x2 == 2)||(cmp_inst.f.x2 == 3)) { |
| 208 | /* Integere compare - Immediate Register (A8 type)*/ |
| 209 | if ((cmp_inst.f.ta == 0) &&(cmp_inst.f.c == 1)) |
| 210 | ctype_unc = 1; |
| 211 | } |
| 212 | out: |
| 213 | return ctype_unc; |
| 214 | } |
| 215 | |
| 216 | /* |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 217 | * In this function we override the bundle with |
| 218 | * the break instruction at the given slot. |
| 219 | */ |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 220 | static void __kprobes prepare_break_inst(uint template, uint slot, |
| 221 | uint major_opcode, |
| 222 | unsigned long kprobe_inst, |
| 223 | struct kprobe *p) |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 224 | { |
| 225 | unsigned long break_inst = BREAK_INST; |
| 226 | bundle_t *bundle = &p->ainsn.insn.bundle; |
| 227 | |
| 228 | /* |
| 229 | * Copy the original kprobe_inst qualifying predicate(qp) |
Anil S Keshavamurthy | 1674eaf | 2005-06-23 00:09:33 -0700 | [diff] [blame] | 230 | * to the break instruction iff !is_cmp_ctype_unc_inst |
| 231 | * because for cmp instruction with ctype equal to unc, |
| 232 | * which is a special instruction always needs to be |
| 233 | * executed regradless of qp |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 234 | */ |
Anil S Keshavamurthy | 1674eaf | 2005-06-23 00:09:33 -0700 | [diff] [blame] | 235 | if (!is_cmp_ctype_unc_inst(template, slot, major_opcode, kprobe_inst)) |
| 236 | break_inst |= (0x3f & kprobe_inst); |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 237 | |
| 238 | switch (slot) { |
| 239 | case 0: |
| 240 | bundle->quad0.slot0 = break_inst; |
| 241 | break; |
| 242 | case 1: |
| 243 | bundle->quad0.slot1_p0 = break_inst; |
| 244 | bundle->quad1.slot1_p1 = break_inst >> (64-46); |
| 245 | break; |
| 246 | case 2: |
| 247 | bundle->quad1.slot2 = break_inst; |
| 248 | break; |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | * Update the instruction flag, so that we can |
| 253 | * emulate the instruction properly after we |
| 254 | * single step on original instruction |
| 255 | */ |
| 256 | update_kprobe_inst_flag(template, slot, major_opcode, kprobe_inst, p); |
| 257 | } |
| 258 | |
| 259 | static inline void get_kprobe_inst(bundle_t *bundle, uint slot, |
| 260 | unsigned long *kprobe_inst, uint *major_opcode) |
| 261 | { |
| 262 | unsigned long kprobe_inst_p0, kprobe_inst_p1; |
| 263 | unsigned int template; |
| 264 | |
| 265 | template = bundle->quad0.template; |
| 266 | |
| 267 | switch (slot) { |
| 268 | case 0: |
| 269 | *major_opcode = (bundle->quad0.slot0 >> SLOT0_OPCODE_SHIFT); |
| 270 | *kprobe_inst = bundle->quad0.slot0; |
| 271 | break; |
| 272 | case 1: |
| 273 | *major_opcode = (bundle->quad1.slot1_p1 >> SLOT1_p1_OPCODE_SHIFT); |
| 274 | kprobe_inst_p0 = bundle->quad0.slot1_p0; |
| 275 | kprobe_inst_p1 = bundle->quad1.slot1_p1; |
| 276 | *kprobe_inst = kprobe_inst_p0 | (kprobe_inst_p1 << (64-46)); |
| 277 | break; |
| 278 | case 2: |
| 279 | *major_opcode = (bundle->quad1.slot2 >> SLOT2_OPCODE_SHIFT); |
| 280 | *kprobe_inst = bundle->quad1.slot2; |
| 281 | break; |
| 282 | } |
| 283 | } |
| 284 | |
Keshavamurthy Anil S | c7b645f | 2005-06-27 15:17:16 -0700 | [diff] [blame] | 285 | /* Returns non-zero if the addr is in the Interrupt Vector Table */ |
| 286 | static inline int in_ivt_functions(unsigned long addr) |
| 287 | { |
| 288 | return (addr >= (unsigned long)__start_ivt_text |
| 289 | && addr < (unsigned long)__end_ivt_text); |
| 290 | } |
| 291 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 292 | static int __kprobes valid_kprobe_addr(int template, int slot, |
| 293 | unsigned long addr) |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 294 | { |
| 295 | if ((slot > 2) || ((bundle_encoding[template][1] == L) && slot > 1)) { |
Keshavamurthy Anil S | c7b645f | 2005-06-27 15:17:16 -0700 | [diff] [blame] | 296 | printk(KERN_WARNING "Attempting to insert unaligned kprobe " |
| 297 | "at 0x%lx\n", addr); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 298 | return -EINVAL; |
| 299 | } |
Rusty Lynch | a528e21 | 2005-06-27 15:17:15 -0700 | [diff] [blame] | 300 | |
Keshavamurthy Anil S | c7b645f | 2005-06-27 15:17:16 -0700 | [diff] [blame] | 301 | if (in_ivt_functions(addr)) { |
| 302 | printk(KERN_WARNING "Kprobes can't be inserted inside " |
| 303 | "IVT functions at 0x%lx\n", addr); |
| 304 | return -EINVAL; |
| 305 | } |
| 306 | |
Rusty Lynch | a528e21 | 2005-06-27 15:17:15 -0700 | [diff] [blame] | 307 | if (slot == 1 && bundle_encoding[template][1] != L) { |
| 308 | printk(KERN_WARNING "Inserting kprobes on slot #1 " |
| 309 | "is not supported\n"); |
| 310 | return -EINVAL; |
| 311 | } |
| 312 | |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 313 | return 0; |
| 314 | } |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 315 | |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 316 | static inline void save_previous_kprobe(void) |
| 317 | { |
| 318 | kprobe_prev = current_kprobe; |
| 319 | kprobe_status_prev = kprobe_status; |
| 320 | } |
| 321 | |
| 322 | static inline void restore_previous_kprobe(void) |
| 323 | { |
| 324 | current_kprobe = kprobe_prev; |
| 325 | kprobe_status = kprobe_status_prev; |
| 326 | } |
| 327 | |
| 328 | static inline void set_current_kprobe(struct kprobe *p) |
| 329 | { |
| 330 | current_kprobe = p; |
| 331 | } |
| 332 | |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 333 | static void kretprobe_trampoline(void) |
| 334 | { |
| 335 | } |
| 336 | |
| 337 | /* |
| 338 | * At this point the target function has been tricked into |
| 339 | * returning into our trampoline. Lookup the associated instance |
| 340 | * and then: |
| 341 | * - call the handler function |
| 342 | * - cleanup by marking the instance as unused |
| 343 | * - long jump back to the original return address |
| 344 | */ |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 345 | int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs) |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 346 | { |
| 347 | struct kretprobe_instance *ri = NULL; |
| 348 | struct hlist_head *head; |
| 349 | struct hlist_node *node, *tmp; |
| 350 | unsigned long orig_ret_address = 0; |
| 351 | unsigned long trampoline_address = |
| 352 | ((struct fnptr *)kretprobe_trampoline)->ip; |
| 353 | |
| 354 | head = kretprobe_inst_table_head(current); |
| 355 | |
| 356 | /* |
| 357 | * It is possible to have multiple instances associated with a given |
| 358 | * task either because an multiple functions in the call path |
| 359 | * have a return probe installed on them, and/or more then one return |
| 360 | * return probe was registered for a target function. |
| 361 | * |
| 362 | * We can handle this because: |
| 363 | * - instances are always inserted at the head of the list |
| 364 | * - when multiple return probes are registered for the same |
| 365 | * function, the first instance's ret_addr will point to the |
| 366 | * real return address, and all the rest will point to |
| 367 | * kretprobe_trampoline |
| 368 | */ |
| 369 | hlist_for_each_entry_safe(ri, node, tmp, head, hlist) { |
| 370 | if (ri->task != current) |
| 371 | /* another task is sharing our hash bucket */ |
| 372 | continue; |
| 373 | |
| 374 | if (ri->rp && ri->rp->handler) |
| 375 | ri->rp->handler(ri, regs); |
| 376 | |
| 377 | orig_ret_address = (unsigned long)ri->ret_addr; |
| 378 | recycle_rp_inst(ri); |
| 379 | |
| 380 | if (orig_ret_address != trampoline_address) |
| 381 | /* |
| 382 | * This is the real return address. Any other |
| 383 | * instances associated with this task are for |
| 384 | * other calls deeper on the call stack |
| 385 | */ |
| 386 | break; |
| 387 | } |
| 388 | |
| 389 | BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address)); |
| 390 | regs->cr_iip = orig_ret_address; |
| 391 | |
| 392 | unlock_kprobes(); |
| 393 | preempt_enable_no_resched(); |
| 394 | |
| 395 | /* |
| 396 | * By returning a non-zero value, we are telling |
| 397 | * kprobe_handler() that we have handled unlocking |
Ananth N Mavinakayanahalli | 66ff2d0 | 2005-11-07 01:00:07 -0800 | [diff] [blame^] | 398 | * and re-enabling preemption |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 399 | */ |
| 400 | return 1; |
| 401 | } |
| 402 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 403 | void __kprobes arch_prepare_kretprobe(struct kretprobe *rp, |
| 404 | struct pt_regs *regs) |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 405 | { |
| 406 | struct kretprobe_instance *ri; |
| 407 | |
| 408 | if ((ri = get_free_rp_inst(rp)) != NULL) { |
| 409 | ri->rp = rp; |
| 410 | ri->task = current; |
| 411 | ri->ret_addr = (kprobe_opcode_t *)regs->b0; |
| 412 | |
| 413 | /* Replace the return addr with trampoline addr */ |
| 414 | regs->b0 = ((struct fnptr *)kretprobe_trampoline)->ip; |
| 415 | |
| 416 | add_rp_inst(ri); |
| 417 | } else { |
| 418 | rp->nmissed++; |
| 419 | } |
| 420 | } |
| 421 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 422 | int __kprobes arch_prepare_kprobe(struct kprobe *p) |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 423 | { |
| 424 | unsigned long addr = (unsigned long) p->addr; |
| 425 | unsigned long *kprobe_addr = (unsigned long *)(addr & ~0xFULL); |
| 426 | unsigned long kprobe_inst=0; |
| 427 | unsigned int slot = addr & 0xf, template, major_opcode = 0; |
| 428 | bundle_t *bundle = &p->ainsn.insn.bundle; |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 429 | |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 430 | memcpy(&p->opcode.bundle, kprobe_addr, sizeof(bundle_t)); |
| 431 | memcpy(&p->ainsn.insn.bundle, kprobe_addr, sizeof(bundle_t)); |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 432 | |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 433 | template = bundle->quad0.template; |
| 434 | |
| 435 | if(valid_kprobe_addr(template, slot, addr)) |
| 436 | return -EINVAL; |
| 437 | |
| 438 | /* Move to slot 2, if bundle is MLX type and kprobe slot is 1 */ |
| 439 | if (slot == 1 && bundle_encoding[template][1] == L) |
| 440 | slot++; |
| 441 | |
| 442 | /* Get kprobe_inst and major_opcode from the bundle */ |
| 443 | get_kprobe_inst(bundle, slot, &kprobe_inst, &major_opcode); |
| 444 | |
Anil S Keshavamurthy | 708de8f | 2005-06-23 00:09:34 -0700 | [diff] [blame] | 445 | if (unsupported_inst(template, slot, major_opcode, kprobe_inst, p)) |
| 446 | return -EINVAL; |
| 447 | |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 448 | prepare_break_inst(template, slot, major_opcode, kprobe_inst, p); |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 449 | |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 450 | return 0; |
| 451 | } |
| 452 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 453 | void __kprobes arch_arm_kprobe(struct kprobe *p) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 454 | { |
| 455 | unsigned long addr = (unsigned long)p->addr; |
| 456 | unsigned long arm_addr = addr & ~0xFULL; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 457 | |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 458 | memcpy((char *)arm_addr, &p->ainsn.insn.bundle, sizeof(bundle_t)); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 459 | flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t)); |
| 460 | } |
| 461 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 462 | void __kprobes arch_disarm_kprobe(struct kprobe *p) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 463 | { |
| 464 | unsigned long addr = (unsigned long)p->addr; |
| 465 | unsigned long arm_addr = addr & ~0xFULL; |
| 466 | |
| 467 | /* p->opcode contains the original unaltered bundle */ |
| 468 | memcpy((char *) arm_addr, (char *) &p->opcode.bundle, sizeof(bundle_t)); |
| 469 | flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t)); |
| 470 | } |
| 471 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 472 | void __kprobes arch_remove_kprobe(struct kprobe *p) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 473 | { |
| 474 | } |
| 475 | |
| 476 | /* |
| 477 | * We are resuming execution after a single step fault, so the pt_regs |
| 478 | * structure reflects the register state after we executed the instruction |
| 479 | * located in the kprobe (p->ainsn.insn.bundle). We still need to adjust |
Anil S Keshavamurthy | cd2675b | 2005-06-23 00:09:29 -0700 | [diff] [blame] | 480 | * the ip to point back to the original stack address. To set the IP address |
| 481 | * to original stack address, handle the case where we need to fixup the |
| 482 | * relative IP address and/or fixup branch register. |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 483 | */ |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 484 | static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 485 | { |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 486 | unsigned long bundle_addr = ((unsigned long) (&p->opcode.bundle)) & ~0xFULL; |
Anil S Keshavamurthy | cd2675b | 2005-06-23 00:09:29 -0700 | [diff] [blame] | 487 | unsigned long resume_addr = (unsigned long)p->addr & ~0xFULL; |
| 488 | unsigned long template; |
| 489 | int slot = ((unsigned long)p->addr & 0xf); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 490 | |
Anil S Keshavamurthy | cd2675b | 2005-06-23 00:09:29 -0700 | [diff] [blame] | 491 | template = p->opcode.bundle.quad0.template; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 492 | |
Anil S Keshavamurthy | cd2675b | 2005-06-23 00:09:29 -0700 | [diff] [blame] | 493 | if (slot == 1 && bundle_encoding[template][1] == L) |
| 494 | slot = 2; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 495 | |
Anil S Keshavamurthy | cd2675b | 2005-06-23 00:09:29 -0700 | [diff] [blame] | 496 | if (p->ainsn.inst_flag) { |
| 497 | |
| 498 | if (p->ainsn.inst_flag & INST_FLAG_FIX_RELATIVE_IP_ADDR) { |
| 499 | /* Fix relative IP address */ |
| 500 | regs->cr_iip = (regs->cr_iip - bundle_addr) + resume_addr; |
| 501 | } |
| 502 | |
| 503 | if (p->ainsn.inst_flag & INST_FLAG_FIX_BRANCH_REG) { |
| 504 | /* |
| 505 | * Fix target branch register, software convention is |
| 506 | * to use either b0 or b6 or b7, so just checking |
| 507 | * only those registers |
| 508 | */ |
| 509 | switch (p->ainsn.target_br_reg) { |
| 510 | case 0: |
| 511 | if ((regs->b0 == bundle_addr) || |
| 512 | (regs->b0 == bundle_addr + 0x10)) { |
| 513 | regs->b0 = (regs->b0 - bundle_addr) + |
| 514 | resume_addr; |
| 515 | } |
| 516 | break; |
| 517 | case 6: |
| 518 | if ((regs->b6 == bundle_addr) || |
| 519 | (regs->b6 == bundle_addr + 0x10)) { |
| 520 | regs->b6 = (regs->b6 - bundle_addr) + |
| 521 | resume_addr; |
| 522 | } |
| 523 | break; |
| 524 | case 7: |
| 525 | if ((regs->b7 == bundle_addr) || |
| 526 | (regs->b7 == bundle_addr + 0x10)) { |
| 527 | regs->b7 = (regs->b7 - bundle_addr) + |
| 528 | resume_addr; |
| 529 | } |
| 530 | break; |
| 531 | } /* end switch */ |
| 532 | } |
| 533 | goto turn_ss_off; |
| 534 | } |
| 535 | |
| 536 | if (slot == 2) { |
| 537 | if (regs->cr_iip == bundle_addr + 0x10) { |
| 538 | regs->cr_iip = resume_addr + 0x10; |
| 539 | } |
| 540 | } else { |
| 541 | if (regs->cr_iip == bundle_addr) { |
| 542 | regs->cr_iip = resume_addr; |
| 543 | } |
Anil S Keshavamurthy | a540318 | 2005-06-23 00:09:32 -0700 | [diff] [blame] | 544 | } |
Anil S Keshavamurthy | cd2675b | 2005-06-23 00:09:29 -0700 | [diff] [blame] | 545 | |
| 546 | turn_ss_off: |
| 547 | /* Turn off Single Step bit */ |
| 548 | ia64_psr(regs)->ss = 0; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 551 | static void __kprobes prepare_ss(struct kprobe *p, struct pt_regs *regs) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 552 | { |
Rusty Lynch | 8bc7677 | 2005-06-23 00:09:30 -0700 | [diff] [blame] | 553 | unsigned long bundle_addr = (unsigned long) &p->opcode.bundle; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 554 | unsigned long slot = (unsigned long)p->addr & 0xf; |
| 555 | |
Keshavamurthy Anil S | deac66a | 2005-09-06 15:19:35 -0700 | [diff] [blame] | 556 | /* single step inline if break instruction */ |
| 557 | if (p->ainsn.inst_flag == INST_FLAG_BREAK_INST) |
| 558 | regs->cr_iip = (unsigned long)p->addr & ~0xFULL; |
| 559 | else |
| 560 | regs->cr_iip = bundle_addr & ~0xFULL; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 561 | |
| 562 | if (slot > 2) |
| 563 | slot = 0; |
| 564 | |
| 565 | ia64_psr(regs)->ri = slot; |
| 566 | |
| 567 | /* turn on single stepping */ |
| 568 | ia64_psr(regs)->ss = 1; |
| 569 | } |
| 570 | |
Keshavamurthy Anil S | 661e5a3 | 2005-09-06 15:19:32 -0700 | [diff] [blame] | 571 | static int __kprobes is_ia64_break_inst(struct pt_regs *regs) |
| 572 | { |
| 573 | unsigned int slot = ia64_psr(regs)->ri; |
| 574 | unsigned int template, major_opcode; |
| 575 | unsigned long kprobe_inst; |
| 576 | unsigned long *kprobe_addr = (unsigned long *)regs->cr_iip; |
| 577 | bundle_t bundle; |
| 578 | |
| 579 | memcpy(&bundle, kprobe_addr, sizeof(bundle_t)); |
| 580 | template = bundle.quad0.template; |
| 581 | |
| 582 | /* Move to slot 2, if bundle is MLX type and kprobe slot is 1 */ |
| 583 | if (slot == 1 && bundle_encoding[template][1] == L) |
| 584 | slot++; |
| 585 | |
| 586 | /* Get Kprobe probe instruction at given slot*/ |
| 587 | get_kprobe_inst(&bundle, slot, &kprobe_inst, &major_opcode); |
| 588 | |
| 589 | /* For break instruction, |
| 590 | * Bits 37:40 Major opcode to be zero |
| 591 | * Bits 27:32 X6 to be zero |
| 592 | * Bits 32:35 X3 to be zero |
| 593 | */ |
| 594 | if (major_opcode || ((kprobe_inst >> 27) & 0x1FF) ) { |
| 595 | /* Not a break instruction */ |
| 596 | return 0; |
| 597 | } |
| 598 | |
| 599 | /* Is a break instruction */ |
| 600 | return 1; |
| 601 | } |
| 602 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 603 | static int __kprobes pre_kprobes_handler(struct die_args *args) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 604 | { |
| 605 | struct kprobe *p; |
| 606 | int ret = 0; |
Keshavamurthy Anil S | 89cb14c | 2005-06-23 00:09:35 -0700 | [diff] [blame] | 607 | struct pt_regs *regs = args->regs; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 608 | kprobe_opcode_t *addr = (kprobe_opcode_t *)instruction_pointer(regs); |
| 609 | |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 610 | /* Handle recursion cases */ |
| 611 | if (kprobe_running()) { |
| 612 | p = get_kprobe(addr); |
| 613 | if (p) { |
Keshavamurthy Anil S | deac66a | 2005-09-06 15:19:35 -0700 | [diff] [blame] | 614 | if ( (kprobe_status == KPROBE_HIT_SS) && |
| 615 | (p->ainsn.inst_flag == INST_FLAG_BREAK_INST)) { |
| 616 | ia64_psr(regs)->ss = 0; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 617 | unlock_kprobes(); |
| 618 | goto no_kprobe; |
| 619 | } |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 620 | /* We have reentered the pre_kprobe_handler(), since |
| 621 | * another probe was hit while within the handler. |
| 622 | * We here save the original kprobes variables and |
| 623 | * just single step on the instruction of the new probe |
| 624 | * without calling any user handlers. |
| 625 | */ |
| 626 | save_previous_kprobe(); |
| 627 | set_current_kprobe(p); |
| 628 | p->nmissed++; |
| 629 | prepare_ss(p, regs); |
| 630 | kprobe_status = KPROBE_REENTER; |
| 631 | return 1; |
Keshavamurthy Anil S | 89cb14c | 2005-06-23 00:09:35 -0700 | [diff] [blame] | 632 | } else if (args->err == __IA64_BREAK_JPROBE) { |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 633 | /* |
| 634 | * jprobe instrumented function just completed |
| 635 | */ |
| 636 | p = current_kprobe; |
| 637 | if (p->break_handler && p->break_handler(p, regs)) { |
| 638 | goto ss_probe; |
| 639 | } |
Keshavamurthy Anil S | 89cb14c | 2005-06-23 00:09:35 -0700 | [diff] [blame] | 640 | } else { |
| 641 | /* Not our break */ |
| 642 | goto no_kprobe; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | |
| 646 | lock_kprobes(); |
| 647 | p = get_kprobe(addr); |
| 648 | if (!p) { |
| 649 | unlock_kprobes(); |
Keshavamurthy Anil S | 661e5a3 | 2005-09-06 15:19:32 -0700 | [diff] [blame] | 650 | if (!is_ia64_break_inst(regs)) { |
| 651 | /* |
| 652 | * The breakpoint instruction was removed right |
| 653 | * after we hit it. Another cpu has removed |
| 654 | * either a probepoint or a debugger breakpoint |
| 655 | * at this address. In either case, no further |
| 656 | * handling of this interrupt is appropriate. |
| 657 | */ |
| 658 | ret = 1; |
| 659 | |
| 660 | } |
| 661 | |
| 662 | /* Not one of our break, let kernel handle it */ |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 663 | goto no_kprobe; |
| 664 | } |
| 665 | |
Ananth N Mavinakayanahalli | 66ff2d0 | 2005-11-07 01:00:07 -0800 | [diff] [blame^] | 666 | /* |
| 667 | * This preempt_disable() matches the preempt_enable_no_resched() |
| 668 | * in post_kprobes_handler() |
| 669 | */ |
| 670 | preempt_disable(); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 671 | kprobe_status = KPROBE_HIT_ACTIVE; |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 672 | set_current_kprobe(p); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 673 | |
| 674 | if (p->pre_handler && p->pre_handler(p, regs)) |
| 675 | /* |
| 676 | * Our pre-handler is specifically requesting that we just |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 677 | * do a return. This is used for both the jprobe pre-handler |
| 678 | * and the kretprobe trampoline |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 679 | */ |
| 680 | return 1; |
| 681 | |
| 682 | ss_probe: |
| 683 | prepare_ss(p, regs); |
| 684 | kprobe_status = KPROBE_HIT_SS; |
| 685 | return 1; |
| 686 | |
| 687 | no_kprobe: |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 688 | return ret; |
| 689 | } |
| 690 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 691 | static int __kprobes post_kprobes_handler(struct pt_regs *regs) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 692 | { |
| 693 | if (!kprobe_running()) |
| 694 | return 0; |
| 695 | |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 696 | if ((kprobe_status != KPROBE_REENTER) && current_kprobe->post_handler) { |
| 697 | kprobe_status = KPROBE_HIT_SSDONE; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 698 | current_kprobe->post_handler(current_kprobe, regs, 0); |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 699 | } |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 700 | |
| 701 | resume_execution(current_kprobe, regs); |
| 702 | |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 703 | /*Restore back the original saved kprobes variables and continue. */ |
| 704 | if (kprobe_status == KPROBE_REENTER) { |
| 705 | restore_previous_kprobe(); |
| 706 | goto out; |
| 707 | } |
| 708 | |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 709 | unlock_kprobes(); |
Anil S Keshavamurthy | 852cacc | 2005-06-23 00:09:40 -0700 | [diff] [blame] | 710 | |
| 711 | out: |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 712 | preempt_enable_no_resched(); |
| 713 | return 1; |
| 714 | } |
| 715 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 716 | static int __kprobes kprobes_fault_handler(struct pt_regs *regs, int trapnr) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 717 | { |
| 718 | if (!kprobe_running()) |
| 719 | return 0; |
| 720 | |
| 721 | if (current_kprobe->fault_handler && |
| 722 | current_kprobe->fault_handler(current_kprobe, regs, trapnr)) |
| 723 | return 1; |
| 724 | |
| 725 | if (kprobe_status & KPROBE_HIT_SS) { |
| 726 | resume_execution(current_kprobe, regs); |
| 727 | unlock_kprobes(); |
| 728 | preempt_enable_no_resched(); |
| 729 | } |
| 730 | |
| 731 | return 0; |
| 732 | } |
| 733 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 734 | int __kprobes kprobe_exceptions_notify(struct notifier_block *self, |
| 735 | unsigned long val, void *data) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 736 | { |
| 737 | struct die_args *args = (struct die_args *)data; |
Ananth N Mavinakayanahalli | 66ff2d0 | 2005-11-07 01:00:07 -0800 | [diff] [blame^] | 738 | int ret = NOTIFY_DONE; |
| 739 | |
| 740 | preempt_disable(); |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 741 | switch(val) { |
| 742 | case DIE_BREAK: |
Keshavamurthy Anil S | 89cb14c | 2005-06-23 00:09:35 -0700 | [diff] [blame] | 743 | if (pre_kprobes_handler(args)) |
Ananth N Mavinakayanahalli | 66ff2d0 | 2005-11-07 01:00:07 -0800 | [diff] [blame^] | 744 | ret = NOTIFY_STOP; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 745 | break; |
| 746 | case DIE_SS: |
| 747 | if (post_kprobes_handler(args->regs)) |
Ananth N Mavinakayanahalli | 66ff2d0 | 2005-11-07 01:00:07 -0800 | [diff] [blame^] | 748 | ret = NOTIFY_STOP; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 749 | break; |
| 750 | case DIE_PAGE_FAULT: |
| 751 | if (kprobes_fault_handler(args->regs, args->trapnr)) |
Ananth N Mavinakayanahalli | 66ff2d0 | 2005-11-07 01:00:07 -0800 | [diff] [blame^] | 752 | ret = NOTIFY_STOP; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 753 | default: |
| 754 | break; |
| 755 | } |
Ananth N Mavinakayanahalli | 66ff2d0 | 2005-11-07 01:00:07 -0800 | [diff] [blame^] | 756 | preempt_enable(); |
| 757 | return ret; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 760 | int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 761 | { |
Anil S Keshavamurthy | b2761dc | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 762 | struct jprobe *jp = container_of(p, struct jprobe, kp); |
| 763 | unsigned long addr = ((struct fnptr *)(jp->entry))->ip; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 764 | |
Anil S Keshavamurthy | b2761dc | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 765 | /* save architectural state */ |
| 766 | jprobe_saved_regs = *regs; |
| 767 | |
| 768 | /* after rfi, execute the jprobe instrumented function */ |
| 769 | regs->cr_iip = addr & ~0xFULL; |
| 770 | ia64_psr(regs)->ri = addr & 0xf; |
| 771 | regs->r1 = ((struct fnptr *)(jp->entry))->gp; |
| 772 | |
| 773 | /* |
| 774 | * fix the return address to our jprobe_inst_return() function |
| 775 | * in the jprobes.S file |
| 776 | */ |
| 777 | regs->b0 = ((struct fnptr *)(jprobe_inst_return))->ip; |
| 778 | |
| 779 | return 1; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Prasanna S Panchamukhi | 1f7ad57 | 2005-09-06 15:19:30 -0700 | [diff] [blame] | 782 | int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 783 | { |
Anil S Keshavamurthy | b2761dc | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 784 | *regs = jprobe_saved_regs; |
| 785 | return 1; |
Anil S Keshavamurthy | fd7b231 | 2005-06-23 00:09:28 -0700 | [diff] [blame] | 786 | } |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 787 | |
| 788 | static struct kprobe trampoline_p = { |
| 789 | .pre_handler = trampoline_probe_handler |
| 790 | }; |
| 791 | |
Rusty Lynch | 6772926 | 2005-07-05 18:54:50 -0700 | [diff] [blame] | 792 | int __init arch_init_kprobes(void) |
Rusty Lynch | 9508dbf | 2005-06-27 15:17:12 -0700 | [diff] [blame] | 793 | { |
| 794 | trampoline_p.addr = |
| 795 | (kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip; |
| 796 | return register_kprobe(&trampoline_p); |
| 797 | } |