1 /*
2  *  linux/arch/arm/kernel/ptrace.c
3  *
4  *  By Ross Biro 1/23/92
5  * edited by Linus Torvalds
6  * ARM modifications Copyright (C) 2000 Russell King
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12 #include <linux/config.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/mm.h>
16 #include <linux/smp.h>
17 #include <linux/smp_lock.h>
18 #include <linux/ptrace.h>
19 #include <linux/user.h>
20 #include <linux/bitops.h>
21 
22 #include <asm/uaccess.h>
23 #include <asm/pgtable.h>
24 #include <asm/system.h>
25 
26 #include "ptrace.h"
27 
28 #define REG_PC	15
29 #define REG_PSR	16
30 /*
31  * does not yet catch signals sent when the child dies.
32  * in exit.c or in signal.c.
33  */
34 
35 /*
36  * Breakpoint SWI instruction: SWI &9F0001
37  */
38 #define BREAKINST_ARM	0xef9f0001
39 /* fill this in later */
40 #define BREAKINST_THUMB	0xdf00
41 
42 /*
43  * Get the address of the live pt_regs for the specified task.
44  * These are saved onto the top kernel stack when the process
45  * is not running.
46  *
47  * Note: if a user thread is execve'd from kernel space, the
48  * kernel stack will not be empty on entry to the kernel, so
49  * ptracing these tasks will fail.
50  */
51 static inline struct pt_regs *
get_user_regs(struct task_struct * task)52 get_user_regs(struct task_struct *task)
53 {
54 	return (struct pt_regs *)
55 		((unsigned long)task + 8192 - 8 - sizeof(struct pt_regs));
56 }
57 
58 /*
59  * this routine will get a word off of the processes privileged stack.
60  * the offset is how far from the base addr as stored in the THREAD.
61  * this routine assumes that all the privileged stacks are in our
62  * data space.
63  */
get_user_reg(struct task_struct * task,int offset)64 static inline long get_user_reg(struct task_struct *task, int offset)
65 {
66 	return get_user_regs(task)->uregs[offset];
67 }
68 
69 /*
70  * this routine will put a word on the processes privileged stack.
71  * the offset is how far from the base addr as stored in the THREAD.
72  * this routine assumes that all the privileged stacks are in our
73  * data space.
74  */
75 static inline int
put_user_reg(struct task_struct * task,int offset,long data)76 put_user_reg(struct task_struct *task, int offset, long data)
77 {
78 	struct pt_regs newregs, *regs = get_user_regs(task);
79 	int ret = -EINVAL;
80 
81 	newregs = *regs;
82 	newregs.uregs[offset] = data;
83 
84 	if (valid_user_regs(&newregs)) {
85 		regs->uregs[offset] = data;
86 		ret = 0;
87 	}
88 
89 	return ret;
90 }
91 
92 static inline int
read_u32(struct task_struct * task,unsigned long addr,u32 * res)93 read_u32(struct task_struct *task, unsigned long addr, u32 *res)
94 {
95 	int ret;
96 
97 	ret = access_process_vm(task, addr, res, sizeof(*res), 0);
98 
99 	return ret == sizeof(*res) ? 0 : -EIO;
100 }
101 
102 static inline int
read_instr(struct task_struct * task,unsigned long addr,u32 * res)103 read_instr(struct task_struct *task, unsigned long addr, u32 *res)
104 {
105 	int ret;
106 
107 	if (addr & 1) {
108 		u16 val;
109 		ret = access_process_vm(task, addr & ~1, &val, sizeof(val), 0);
110 		ret = ret == sizeof(val) ? 0 : -EIO;
111 		*res = val;
112 	} else {
113 		u32 val;
114 		ret = access_process_vm(task, addr & ~3, &val, sizeof(val), 0);
115 		ret = ret == sizeof(val) ? 0 : -EIO;
116 		*res = val;
117 	}
118 	return ret;
119 }
120 
121 /*
122  * Get value of register `rn' (in the instruction)
123  */
124 static unsigned long
ptrace_getrn(struct task_struct * child,unsigned long insn)125 ptrace_getrn(struct task_struct *child, unsigned long insn)
126 {
127 	unsigned int reg = (insn >> 16) & 15;
128 	unsigned long val;
129 
130 	val = get_user_reg(child, reg);
131 	if (reg == 15)
132 		val = pc_pointer(val + 8);
133 
134 	return val;
135 }
136 
137 /*
138  * Get value of operand 2 (in an ALU instruction)
139  */
140 static unsigned long
ptrace_getaluop2(struct task_struct * child,unsigned long insn)141 ptrace_getaluop2(struct task_struct *child, unsigned long insn)
142 {
143 	unsigned long val;
144 	int shift;
145 	int type;
146 
147 	if (insn & 1 << 25) {
148 		val = insn & 255;
149 		shift = (insn >> 8) & 15;
150 		type = 3;
151 	} else {
152 		val = get_user_reg (child, insn & 15);
153 
154 		if (insn & (1 << 4))
155 			shift = (int)get_user_reg (child, (insn >> 8) & 15);
156 		else
157 			shift = (insn >> 7) & 31;
158 
159 		type = (insn >> 5) & 3;
160 	}
161 
162 	switch (type) {
163 	case 0:	val <<= shift;	break;
164 	case 1:	val >>= shift;	break;
165 	case 2:
166 		val = (((signed long)val) >> shift);
167 		break;
168 	case 3:
169  		val = (val >> shift) | (val << (32 - shift));
170 		break;
171 	}
172 	return val;
173 }
174 
175 /*
176  * Get value of operand 2 (in a LDR instruction)
177  */
178 static unsigned long
ptrace_getldrop2(struct task_struct * child,unsigned long insn)179 ptrace_getldrop2(struct task_struct *child, unsigned long insn)
180 {
181 	unsigned long val;
182 	int shift;
183 	int type;
184 
185 	val = get_user_reg(child, insn & 15);
186 	shift = (insn >> 7) & 31;
187 	type = (insn >> 5) & 3;
188 
189 	switch (type) {
190 	case 0:	val <<= shift;	break;
191 	case 1:	val >>= shift;	break;
192 	case 2:
193 		val = (((signed long)val) >> shift);
194 		break;
195 	case 3:
196  		val = (val >> shift) | (val << (32 - shift));
197 		break;
198 	}
199 	return val;
200 }
201 
202 #define OP_MASK	0x01e00000
203 #define OP_AND	0x00000000
204 #define OP_EOR	0x00200000
205 #define OP_SUB	0x00400000
206 #define OP_RSB	0x00600000
207 #define OP_ADD	0x00800000
208 #define OP_ADC	0x00a00000
209 #define OP_SBC	0x00c00000
210 #define OP_RSC	0x00e00000
211 #define OP_ORR	0x01800000
212 #define OP_MOV	0x01a00000
213 #define OP_BIC	0x01c00000
214 #define OP_MVN	0x01e00000
215 
216 static unsigned long
get_branch_address(struct task_struct * child,unsigned long pc,unsigned long insn)217 get_branch_address(struct task_struct *child, unsigned long pc, unsigned long insn)
218 {
219 	u32 alt = 0;
220 
221 	switch (insn & 0x0e000000) {
222 	case 0x00000000:
223 	case 0x02000000: {
224 		/*
225 		 * data processing
226 		 */
227 		long aluop1, aluop2, ccbit;
228 
229 		if ((insn & 0xf000) != 0xf000)
230 			break;
231 
232 		aluop1 = ptrace_getrn(child, insn);
233 		aluop2 = ptrace_getaluop2(child, insn);
234 		ccbit  = get_user_reg(child, REG_PSR) & CC_C_BIT ? 1 : 0;
235 
236 		switch (insn & OP_MASK) {
237 		case OP_AND: alt = aluop1 & aluop2;		break;
238 		case OP_EOR: alt = aluop1 ^ aluop2;		break;
239 		case OP_SUB: alt = aluop1 - aluop2;		break;
240 		case OP_RSB: alt = aluop2 - aluop1;		break;
241 		case OP_ADD: alt = aluop1 + aluop2;		break;
242 		case OP_ADC: alt = aluop1 + aluop2 + ccbit;	break;
243 		case OP_SBC: alt = aluop1 - aluop2 + ccbit;	break;
244 		case OP_RSC: alt = aluop2 - aluop1 + ccbit;	break;
245 		case OP_ORR: alt = aluop1 | aluop2;		break;
246 		case OP_MOV: alt = aluop2;			break;
247 		case OP_BIC: alt = aluop1 & ~aluop2;		break;
248 		case OP_MVN: alt = ~aluop2;			break;
249 		}
250 		break;
251 	}
252 
253 	case 0x04000000:
254 	case 0x06000000:
255 		/*
256 		 * ldr
257 		 */
258 		if ((insn & 0x0010f000) == 0x0010f000) {
259 			unsigned long base;
260 
261 			base = ptrace_getrn(child, insn);
262 			if (insn & 1 << 24) {
263 				long aluop2;
264 
265 				if (insn & 0x02000000)
266 					aluop2 = ptrace_getldrop2(child, insn);
267 				else
268 					aluop2 = insn & 0xfff;
269 
270 				if (insn & 1 << 23)
271 					base += aluop2;
272 				else
273 					base -= aluop2;
274 			}
275 			if (read_u32(child, base, &alt) == 0)
276 				alt = pc_pointer(alt);
277 		}
278 		break;
279 
280 	case 0x08000000:
281 		/*
282 		 * ldm
283 		 */
284 		if ((insn & 0x00108000) == 0x00108000) {
285 			unsigned long base;
286 			unsigned int nr_regs;
287 
288 			if (insn & (1 << 23)) {
289 				nr_regs = hweight16(insn & 65535) << 2;
290 
291 				if (!(insn & (1 << 24)))
292 					nr_regs -= 4;
293 			} else {
294 				if (insn & (1 << 24))
295 					nr_regs = -4;
296 				else
297 					nr_regs = 0;
298 			}
299 
300 			base = ptrace_getrn(child, insn);
301 
302 			if (read_u32(child, base + nr_regs, &alt) == 0)
303 				alt = pc_pointer(alt);
304 			break;
305 		}
306 		break;
307 
308 	case 0x0a000000: {
309 		/*
310 		 * bl or b
311 		 */
312 		signed long displ;
313 		/* It's a branch/branch link: instead of trying to
314 		 * figure out whether the branch will be taken or not,
315 		 * we'll put a breakpoint at both locations.  This is
316 		 * simpler, more reliable, and probably not a whole lot
317 		 * slower than the alternative approach of emulating the
318 		 * branch.
319 		 */
320 		displ = (insn & 0x00ffffff) << 8;
321 		displ = (displ >> 6) + 8;
322 		if (displ != 0 && displ != 4)
323 			alt = pc + displ;
324 	    }
325 	    break;
326 	}
327 
328 	return alt;
329 }
330 
331 static int
swap_insn(struct task_struct * task,unsigned long addr,void * old_insn,void * new_insn,int size)332 swap_insn(struct task_struct *task, unsigned long addr,
333 	  void *old_insn, void *new_insn, int size)
334 {
335 	int ret;
336 
337 	ret = access_process_vm(task, addr, old_insn, size, 0);
338 	if (ret == size)
339 		ret = access_process_vm(task, addr, new_insn, size, 1);
340 	return ret;
341 }
342 
343 static void
add_breakpoint(struct task_struct * task,struct debug_info * dbg,unsigned long addr)344 add_breakpoint(struct task_struct *task, struct debug_info *dbg, unsigned long addr)
345 {
346 	int nr = dbg->nsaved;
347 
348 	if (nr < 2) {
349 		u32 new_insn = BREAKINST_ARM;
350 		int res;
351 
352 		res = swap_insn(task, addr, &dbg->bp[nr].insn, &new_insn, 4);
353 
354 		if (res == 4) {
355 			dbg->bp[nr].address = addr;
356 			dbg->nsaved += 1;
357 		}
358 	} else
359 		printk(KERN_ERR "ptrace: too many breakpoints\n");
360 }
361 
362 /*
363  * Clear one breakpoint in the user program.  We copy what the hardware
364  * does and use bit 0 of the address to indicate whether this is a Thumb
365  * breakpoint or an ARM breakpoint.
366  */
clear_breakpoint(struct task_struct * task,struct debug_entry * bp)367 static void clear_breakpoint(struct task_struct *task, struct debug_entry *bp)
368 {
369 	unsigned long addr = bp->address;
370 	union debug_insn old_insn;
371 	int ret;
372 
373 	if (addr & 1) {
374 		ret = swap_insn(task, addr & ~1, &old_insn.thumb,
375 				&bp->insn.thumb, 2);
376 
377 		if (ret != 2 || old_insn.thumb != BREAKINST_THUMB)
378 			printk(KERN_ERR "%s:%d: corrupted Thumb breakpoint at "
379 				"0x%08lx (0x%04x)\n", task->comm, task->pid,
380 				addr, old_insn.thumb);
381 	} else {
382 		ret = swap_insn(task, addr & ~3, &old_insn.thumb,
383 				&bp->insn.thumb, 4);
384 
385 		if (ret != 4 || old_insn.arm != BREAKINST_ARM)
386 			printk(KERN_ERR "%s:%d: corrupted ARM breakpoint at "
387 				"0x%08lx (0x%08x)\n", task->comm, task->pid,
388 				addr, old_insn.arm);
389 	}
390 }
391 
ptrace_set_bpt(struct task_struct * child)392 void ptrace_set_bpt(struct task_struct *child)
393 {
394 	struct pt_regs *regs;
395 	unsigned long pc;
396 	u32 insn;
397 	int res;
398 
399 	regs = get_user_regs(child);
400 	pc = instruction_pointer(regs);
401 
402 	if (thumb_mode(regs)) {
403 		printk(KERN_WARNING "ptrace: can't handle thumb mode\n");
404 		return;
405 	}
406 
407 	res = read_instr(child, pc, &insn);
408 	if (!res) {
409 		struct debug_info *dbg = &child->thread.debug;
410 		unsigned long alt;
411 
412 		dbg->nsaved = 0;
413 
414 		alt = get_branch_address(child, pc, insn);
415 		if (alt)
416 			add_breakpoint(child, dbg, alt);
417 
418 		/*
419 		 * Note that we ignore the result of setting the above
420 		 * breakpoint since it may fail.  When it does, this is
421 		 * not so much an error, but a forewarning that we may
422 		 * be receiving a prefetch abort shortly.
423 		 *
424 		 * If we don't set this breakpoint here, then we can
425 		 * loose control of the thread during single stepping.
426 		 */
427 		if (!alt || predicate(insn) != PREDICATE_ALWAYS)
428 			add_breakpoint(child, dbg, pc + 4);
429 	}
430 }
431 
432 /*
433  * Ensure no single-step breakpoint is pending.  Returns non-zero
434  * value if child was being single-stepped.
435  */
__ptrace_cancel_bpt(struct task_struct * child)436 void __ptrace_cancel_bpt(struct task_struct *child)
437 {
438 	int i, nsaved = child->thread.debug.nsaved;
439 
440 	child->thread.debug.nsaved = 0;
441 
442 	if (nsaved > 2) {
443 		printk("ptrace_cancel_bpt: bogus nsaved: %d!\n", nsaved);
444 		nsaved = 2;
445 	}
446 
447 	for (i = 0; i < nsaved; i++)
448 		clear_breakpoint(child, &child->thread.debug.bp[i]);
449 }
450 
451 /*
452  * Called by kernel/ptrace.c when detaching..
453  *
454  * Make sure the single step bit is not set.
455  */
ptrace_disable(struct task_struct * child)456 void ptrace_disable(struct task_struct *child)
457 {
458 	__ptrace_cancel_bpt(child);
459 }
460 
461 /*
462  * Handle hitting a breakpoint.  regs points at the instruction.
463  */
ptrace_break(struct task_struct * tsk,struct pt_regs * regs)464 void ptrace_break(struct task_struct *tsk, struct pt_regs *regs)
465 {
466 	siginfo_t info;
467 
468 	/*
469 	 * The PC is pointing at the next instruction.  Fix this.
470 	 */
471 	regs->ARM_pc -= thumb_mode(regs) ? 2 : 4;
472 
473 	__ptrace_cancel_bpt(tsk);
474 
475 	info.si_signo = SIGTRAP;
476 	info.si_errno = 0;
477 	info.si_code  = TRAP_BRKPT;
478 	info.si_addr  = (void *)instruction_pointer(regs);
479 
480 	force_sig_info(SIGTRAP, &info, tsk);
481 }
482 
483 /*
484  * Read the word at offset "off" into the "struct user".  We
485  * actually access the pt_regs stored on the kernel stack.
486  */
ptrace_read_user(struct task_struct * tsk,unsigned long off,unsigned long * ret)487 static int ptrace_read_user(struct task_struct *tsk, unsigned long off,
488 			    unsigned long *ret)
489 {
490 	unsigned long tmp;
491 
492 	if (off & 3 || off >= sizeof(struct user))
493 		return -EIO;
494 
495 	tmp = 0;
496 	if (off < sizeof(struct pt_regs))
497 		tmp = get_user_reg(tsk, off >> 2);
498 
499 	return put_user(tmp, ret);
500 }
501 
502 /*
503  * Write the word at offset "off" into "struct user".  We
504  * actually access the pt_regs stored on the kernel stack.
505  */
ptrace_write_user(struct task_struct * tsk,unsigned long off,unsigned long val)506 static int ptrace_write_user(struct task_struct *tsk, unsigned long off,
507 			     unsigned long val)
508 {
509 	if (off & 3 || off >= sizeof(struct user))
510 		return -EIO;
511 
512 	if (off >= sizeof(struct pt_regs))
513 		return 0;
514 
515 	return put_user_reg(tsk, off >> 2, val);
516 }
517 
518 /*
519  * Get all user integer registers.
520  */
ptrace_getregs(struct task_struct * tsk,void * uregs)521 static int ptrace_getregs(struct task_struct *tsk, void *uregs)
522 {
523 	struct pt_regs *regs = get_user_regs(tsk);
524 
525 	return copy_to_user(uregs, regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
526 }
527 
528 /*
529  * Set all user integer registers.
530  */
ptrace_setregs(struct task_struct * tsk,void * uregs)531 static int ptrace_setregs(struct task_struct *tsk, void *uregs)
532 {
533 	struct pt_regs newregs;
534 	int ret;
535 
536 	ret = -EFAULT;
537 	if (copy_from_user(&newregs, uregs, sizeof(struct pt_regs)) == 0) {
538 		struct pt_regs *regs = get_user_regs(tsk);
539 
540 		ret = -EINVAL;
541 		if (valid_user_regs(&newregs)) {
542 			*regs = newregs;
543 			ret = 0;
544 		}
545 	}
546 
547 	return ret;
548 }
549 
550 /*
551  * Get the child FPU state.
552  */
ptrace_getfpregs(struct task_struct * tsk,void * ufp)553 static int ptrace_getfpregs(struct task_struct *tsk, void *ufp)
554 {
555 	return copy_to_user(ufp, &tsk->thread.fpstate,
556 			    sizeof(struct user_fp)) ? -EFAULT : 0;
557 }
558 
559 /*
560  * Set the child FPU state.
561  */
ptrace_setfpregs(struct task_struct * tsk,void * ufp)562 static int ptrace_setfpregs(struct task_struct *tsk, void *ufp)
563 {
564 	tsk->used_math = 1;
565 	return copy_from_user(&tsk->thread.fpstate, ufp,
566 			      sizeof(struct user_fp)) ? -EFAULT : 0;
567 }
568 
do_ptrace(int request,struct task_struct * child,long addr,long data)569 static int do_ptrace(int request, struct task_struct *child, long addr, long data)
570 {
571 	unsigned long tmp;
572 	int ret;
573 
574 	switch (request) {
575 		/*
576 		 * read word at location "addr" in the child process.
577 		 */
578 		case PTRACE_PEEKTEXT:
579 		case PTRACE_PEEKDATA:
580 			ret = access_process_vm(child, addr, &tmp,
581 						sizeof(unsigned long), 0);
582 			if (ret == sizeof(unsigned long))
583 				ret = put_user(tmp, (unsigned long *) data);
584 			else
585 				ret = -EIO;
586 			break;
587 
588 		case PTRACE_PEEKUSR:
589 			ret = ptrace_read_user(child, addr, (unsigned long *)data);
590 			break;
591 
592 		/*
593 		 * write the word at location addr.
594 		 */
595 		case PTRACE_POKETEXT:
596 		case PTRACE_POKEDATA:
597 			ret = access_process_vm(child, addr, &data,
598 						sizeof(unsigned long), 1);
599 			if (ret == sizeof(unsigned long))
600 				ret = 0;
601 			else
602 				ret = -EIO;
603 			break;
604 
605 		case PTRACE_POKEUSR:
606 			ret = ptrace_write_user(child, addr, data);
607 			break;
608 
609 		/*
610 		 * continue/restart and stop at next (return from) syscall
611 		 */
612 		case PTRACE_SYSCALL:
613 		case PTRACE_CONT:
614 			ret = -EIO;
615 			if ((unsigned long) data > _NSIG)
616 				break;
617 			if (request == PTRACE_SYSCALL)
618 				child->ptrace |= PT_TRACESYS;
619 			else
620 				child->ptrace &= ~PT_TRACESYS;
621 			child->exit_code = data;
622 			/* make sure single-step breakpoint is gone. */
623 			__ptrace_cancel_bpt(child);
624 			wake_up_process(child);
625 			ret = 0;
626 			break;
627 
628 		/*
629 		 * make the child exit.  Best I can do is send it a sigkill.
630 		 * perhaps it should be put in the status that it wants to
631 		 * exit.
632 		 */
633 		case PTRACE_KILL:
634 			/* make sure single-step breakpoint is gone. */
635 			__ptrace_cancel_bpt(child);
636 			if (child->state != TASK_ZOMBIE) {
637 				child->exit_code = SIGKILL;
638 				wake_up_process(child);
639 			}
640 			ret = 0;
641 			break;
642 
643 		/*
644 		 * execute single instruction.
645 		 */
646 		case PTRACE_SINGLESTEP:
647 			ret = -EIO;
648 			if ((unsigned long) data > _NSIG)
649 				break;
650 			child->thread.debug.nsaved = -1;
651 			child->ptrace &= ~PT_TRACESYS;
652 			child->exit_code = data;
653 			/* give it a chance to run. */
654 			wake_up_process(child);
655 			ret = 0;
656 			break;
657 
658 		case PTRACE_DETACH:
659 			ret = ptrace_detach(child, data);
660 			break;
661 
662 		case PTRACE_GETREGS:
663 			ret = ptrace_getregs(child, (void *)data);
664 			break;
665 
666 		case PTRACE_SETREGS:
667 			ret = ptrace_setregs(child, (void *)data);
668 			break;
669 
670 		case PTRACE_GETFPREGS:
671 			ret = ptrace_getfpregs(child, (void *)data);
672 			break;
673 
674 		case PTRACE_SETFPREGS:
675 			ret = ptrace_setfpregs(child, (void *)data);
676 			break;
677 
678 		case PTRACE_SETOPTIONS:
679 			if (data & PTRACE_O_TRACESYSGOOD)
680 				child->ptrace |= PT_TRACESYSGOOD;
681 			else
682 				child->ptrace &= ~PT_TRACESYSGOOD;
683 			ret = 0;
684 			break;
685 
686 		default:
687 			ret = -EIO;
688 			break;
689 	}
690 
691 	return ret;
692 }
693 
sys_ptrace(long request,long pid,long addr,long data)694 asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
695 {
696 	struct task_struct *child;
697 	int ret;
698 
699 	lock_kernel();
700 	ret = -EPERM;
701 	if (request == PTRACE_TRACEME) {
702 		/* are we already being traced? */
703 		if (current->ptrace & PT_PTRACED)
704 			goto out;
705 		/* set the ptrace bit in the process flags. */
706 		current->ptrace |= PT_PTRACED;
707 		ret = 0;
708 		goto out;
709 	}
710 	ret = -ESRCH;
711 	read_lock(&tasklist_lock);
712 	child = find_task_by_pid(pid);
713 	if (child)
714 		get_task_struct(child);
715 	read_unlock(&tasklist_lock);
716 	if (!child)
717 		goto out;
718 
719 	ret = -EPERM;
720 	if (pid == 1)		/* you may not mess with init */
721 		goto out_tsk;
722 
723 	if (request == PTRACE_ATTACH) {
724 		ret = ptrace_attach(child);
725 		goto out_tsk;
726 	}
727 	ret = -ESRCH;
728 	if (!(child->ptrace & PT_PTRACED))
729 		goto out_tsk;
730 	if (child->state != TASK_STOPPED && request != PTRACE_KILL)
731 		goto out_tsk;
732 	if (child->p_pptr != current)
733 		goto out_tsk;
734 
735 	ret = do_ptrace(request, child, addr, data);
736 
737 out_tsk:
738 	free_task_struct(child);
739 out:
740 	unlock_kernel();
741 	return ret;
742 }
743 
syscall_trace(int why,struct pt_regs * regs)744 asmlinkage void syscall_trace(int why, struct pt_regs *regs)
745 {
746 	unsigned long ip;
747 
748 	if ((current->ptrace & (PT_PTRACED|PT_TRACESYS))
749 			!= (PT_PTRACED|PT_TRACESYS))
750 		return;
751 
752 	/*
753 	 * Save IP.  IP is used to denote syscall entry/exit:
754 	 *  IP = 0 -> entry, = 1 -> exit
755 	 */
756 	ip = regs->ARM_ip;
757 	regs->ARM_ip = why;
758 
759 	/* the 0x80 provides a way for the tracing parent to distinguish
760 	   between a syscall stop and SIGTRAP delivery */
761 	current->exit_code = SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
762 					? 0x80 : 0);
763 	current->state = TASK_STOPPED;
764 	notify_parent(current, SIGCHLD);
765 	schedule();
766 	/*
767 	 * this isn't the same as continuing with a signal, but it will do
768 	 * for normal use.  strace only continues with a signal if the
769 	 * stopping signal is not SIGTRAP.  -brl
770 	 */
771 	if (current->exit_code) {
772 		send_sig(current->exit_code, current, 1);
773 		current->exit_code = 0;
774 	}
775 	regs->ARM_ip = ip;
776 }
777