kprobes.c (bf61c8840efe60fd8f91446860b63338fb424158) kprobes.c (c473b2c6f6c6d012da98416b5de28cc48c4306c9)
1/*
2 * Kernel probes (kprobes) for SuperH
3 *
4 * Copyright (C) 2007 Chris Smith <chris.smith@st.com>
5 * Copyright (C) 2006 Lineo Solutions, Inc.
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive

--- 88 unchanged lines hidden (view full) ---

97 return 0;
98 }
99
100 return 1;
101}
102
103void __kprobes arch_remove_kprobe(struct kprobe *p)
104{
1/*
2 * Kernel probes (kprobes) for SuperH
3 *
4 * Copyright (C) 2007 Chris Smith <chris.smith@st.com>
5 * Copyright (C) 2006 Lineo Solutions, Inc.
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive

--- 88 unchanged lines hidden (view full) ---

97 return 0;
98 }
99
100 return 1;
101}
102
103void __kprobes arch_remove_kprobe(struct kprobe *p)
104{
105 struct kprobe *saved = &__get_cpu_var(saved_next_opcode);
105 struct kprobe *saved = this_cpu_ptr(&saved_next_opcode);
106
107 if (saved->addr) {
108 arch_disarm_kprobe(p);
109 arch_disarm_kprobe(saved);
110
111 saved->addr = NULL;
112 saved->opcode = 0;
113
106
107 if (saved->addr) {
108 arch_disarm_kprobe(p);
109 arch_disarm_kprobe(saved);
110
111 saved->addr = NULL;
112 saved->opcode = 0;
113
114 saved = &__get_cpu_var(saved_next_opcode2);
114 saved = this_cpu_ptr(&saved_next_opcode2);
115 if (saved->addr) {
116 arch_disarm_kprobe(saved);
117
118 saved->addr = NULL;
119 saved->opcode = 0;
120 }
121 }
122}
123
124static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
125{
126 kcb->prev_kprobe.kp = kprobe_running();
127 kcb->prev_kprobe.status = kcb->kprobe_status;
128}
129
130static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
131{
115 if (saved->addr) {
116 arch_disarm_kprobe(saved);
117
118 saved->addr = NULL;
119 saved->opcode = 0;
120 }
121 }
122}
123
124static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
125{
126 kcb->prev_kprobe.kp = kprobe_running();
127 kcb->prev_kprobe.status = kcb->kprobe_status;
128}
129
130static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
131{
132 __get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
132 __this_cpu_write(current_kprobe, kcb->prev_kprobe.kp);
133 kcb->kprobe_status = kcb->prev_kprobe.status;
134}
135
136static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
137 struct kprobe_ctlblk *kcb)
138{
133 kcb->kprobe_status = kcb->prev_kprobe.status;
134}
135
136static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
137 struct kprobe_ctlblk *kcb)
138{
139 __get_cpu_var(current_kprobe) = p;
139 __this_cpu_write(current_kprobe, p);
140}
141
142/*
143 * Singlestep is implemented by disabling the current kprobe and setting one
144 * on the next instruction, following branches. Two probes are set if the
145 * branch is conditional.
146 */
147static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
148{
140}
141
142/*
143 * Singlestep is implemented by disabling the current kprobe and setting one
144 * on the next instruction, following branches. Two probes are set if the
145 * branch is conditional.
146 */
147static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
148{
149 __get_cpu_var(saved_current_opcode).addr = (kprobe_opcode_t *)regs->pc;
149 __this_cpu_write(saved_current_opcode.addr, (kprobe_opcode_t *)regs->pc);
150
151 if (p != NULL) {
152 struct kprobe *op1, *op2;
153
154 arch_disarm_kprobe(p);
155
150
151 if (p != NULL) {
152 struct kprobe *op1, *op2;
153
154 arch_disarm_kprobe(p);
155
156 op1 = &__get_cpu_var(saved_next_opcode);
157 op2 = &__get_cpu_var(saved_next_opcode2);
156 op1 = this_cpu_ptr(&saved_next_opcode);
157 op2 = this_cpu_ptr(&saved_next_opcode2);
158
159 if (OPCODE_JSR(p->opcode) || OPCODE_JMP(p->opcode)) {
160 unsigned int reg_nr = ((p->opcode >> 8) & 0x000F);
161 op1->addr = (kprobe_opcode_t *) regs->regs[reg_nr];
162 } else if (OPCODE_BRA(p->opcode) || OPCODE_BSR(p->opcode)) {
163 unsigned long disp = (p->opcode & 0x0FFF);
164 op1->addr =
165 (kprobe_opcode_t *) (regs->pc + 4 + disp * 2);

--- 78 unchanged lines hidden (view full) ---

244 */
245 save_previous_kprobe(kcb);
246 set_current_kprobe(p, regs, kcb);
247 kprobes_inc_nmissed_count(p);
248 prepare_singlestep(p, regs);
249 kcb->kprobe_status = KPROBE_REENTER;
250 return 1;
251 } else {
158
159 if (OPCODE_JSR(p->opcode) || OPCODE_JMP(p->opcode)) {
160 unsigned int reg_nr = ((p->opcode >> 8) & 0x000F);
161 op1->addr = (kprobe_opcode_t *) regs->regs[reg_nr];
162 } else if (OPCODE_BRA(p->opcode) || OPCODE_BSR(p->opcode)) {
163 unsigned long disp = (p->opcode & 0x0FFF);
164 op1->addr =
165 (kprobe_opcode_t *) (regs->pc + 4 + disp * 2);

--- 78 unchanged lines hidden (view full) ---

244 */
245 save_previous_kprobe(kcb);
246 set_current_kprobe(p, regs, kcb);
247 kprobes_inc_nmissed_count(p);
248 prepare_singlestep(p, regs);
249 kcb->kprobe_status = KPROBE_REENTER;
250 return 1;
251 } else {
252 p = __get_cpu_var(current_kprobe);
252 p = __this_cpu_read(current_kprobe);
253 if (p->break_handler && p->break_handler(p, regs)) {
254 goto ss_probe;
255 }
256 }
257 goto no_kprobe;
258 }
259
260 p = get_kprobe(addr);

--- 70 unchanged lines hidden (view full) ---

331 * kretprobe_trampoline
332 */
333 hlist_for_each_entry_safe(ri, tmp, head, hlist) {
334 if (ri->task != current)
335 /* another task is sharing our hash bucket */
336 continue;
337
338 if (ri->rp && ri->rp->handler) {
253 if (p->break_handler && p->break_handler(p, regs)) {
254 goto ss_probe;
255 }
256 }
257 goto no_kprobe;
258 }
259
260 p = get_kprobe(addr);

--- 70 unchanged lines hidden (view full) ---

331 * kretprobe_trampoline
332 */
333 hlist_for_each_entry_safe(ri, tmp, head, hlist) {
334 if (ri->task != current)
335 /* another task is sharing our hash bucket */
336 continue;
337
338 if (ri->rp && ri->rp->handler) {
339 __get_cpu_var(current_kprobe) = &ri->rp->kp;
339 __this_cpu_write(current_kprobe, &ri->rp->kp);
340 ri->rp->handler(ri, regs);
340 ri->rp->handler(ri, regs);
341 __get_cpu_var(current_kprobe) = NULL;
341 __this_cpu_write(current_kprobe, NULL);
342 }
343
344 orig_ret_address = (unsigned long)ri->ret_addr;
345 recycle_rp_inst(ri, &empty_rp);
346
347 if (orig_ret_address != trampoline_address)
348 /*
349 * This is the real return address. Any other

--- 28 unchanged lines hidden (view full) ---

378 if (!cur)
379 return 0;
380
381 if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
382 kcb->kprobe_status = KPROBE_HIT_SSDONE;
383 cur->post_handler(cur, regs, 0);
384 }
385
342 }
343
344 orig_ret_address = (unsigned long)ri->ret_addr;
345 recycle_rp_inst(ri, &empty_rp);
346
347 if (orig_ret_address != trampoline_address)
348 /*
349 * This is the real return address. Any other

--- 28 unchanged lines hidden (view full) ---

378 if (!cur)
379 return 0;
380
381 if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
382 kcb->kprobe_status = KPROBE_HIT_SSDONE;
383 cur->post_handler(cur, regs, 0);
384 }
385
386 p = &__get_cpu_var(saved_next_opcode);
386 p = this_cpu_ptr(&saved_next_opcode);
387 if (p->addr) {
388 arch_disarm_kprobe(p);
389 p->addr = NULL;
390 p->opcode = 0;
391
387 if (p->addr) {
388 arch_disarm_kprobe(p);
389 p->addr = NULL;
390 p->opcode = 0;
391
392 addr = __get_cpu_var(saved_current_opcode).addr;
393 __get_cpu_var(saved_current_opcode).addr = NULL;
392 addr = __this_cpu_read(saved_current_opcode.addr);
393 __this_cpu_write(saved_current_opcode.addr, NULL);
394
395 p = get_kprobe(addr);
396 arch_arm_kprobe(p);
397
394
395 p = get_kprobe(addr);
396 arch_arm_kprobe(p);
397
398 p = &__get_cpu_var(saved_next_opcode2);
398 p = this_cpu_ptr(&saved_next_opcode2);
399 if (p->addr) {
400 arch_disarm_kprobe(p);
401 p->addr = NULL;
402 p->opcode = 0;
403 }
404 }
405
406 /* Restore back the original saved kprobes variables and continue. */

--- 99 unchanged lines hidden (view full) ---

506 if ((kcb->kprobe_status == KPROBE_HIT_SS) ||
507 (kcb->kprobe_status == KPROBE_REENTER)) {
508 if (post_kprobe_handler(args->regs))
509 ret = NOTIFY_STOP;
510 } else {
511 if (kprobe_handler(args->regs)) {
512 ret = NOTIFY_STOP;
513 } else {
399 if (p->addr) {
400 arch_disarm_kprobe(p);
401 p->addr = NULL;
402 p->opcode = 0;
403 }
404 }
405
406 /* Restore back the original saved kprobes variables and continue. */

--- 99 unchanged lines hidden (view full) ---

506 if ((kcb->kprobe_status == KPROBE_HIT_SS) ||
507 (kcb->kprobe_status == KPROBE_REENTER)) {
508 if (post_kprobe_handler(args->regs))
509 ret = NOTIFY_STOP;
510 } else {
511 if (kprobe_handler(args->regs)) {
512 ret = NOTIFY_STOP;
513 } else {
514 p = __get_cpu_var(current_kprobe);
514 p = __this_cpu_read(current_kprobe);
515 if (p->break_handler &&
516 p->break_handler(p, args->regs))
517 ret = NOTIFY_STOP;
518 }
519 }
520 }
521 }
522

--- 63 unchanged lines hidden ---
515 if (p->break_handler &&
516 p->break_handler(p, args->regs))
517 ret = NOTIFY_STOP;
518 }
519 }
520 }
521 }
522

--- 63 unchanged lines hidden ---