int sys_ptrace(long request, long pid, long addr, long data) 
long sys_ptrace(long request, long pid, long addr, long data) 
int sys_ptrace(long request, long pid, long addr, long data){	struct task_struct *child;	int rval;	lock_kernel();	if (request == PTRACE_TRACEME) {		/* are we already being traced? */		if (current->ptrace & PT_PTRACED) {			rval = -EPERM;			goto out;		}		/* set the ptrace bit in the process flags. */		current->ptrace |= PT_PTRACED;		rval = 0;		goto out;	}	rval = -ESRCH;	read_lock(&tasklist_lock);	child = find_task_by_pid(pid);	if (child)		get_task_struct(child);	read_unlock(&tasklist_lock);	if (!child)		goto out;	rval = -EPERM;	if (pid == 1)		/* you may not mess with init */		goto out_tsk;	if (request == PTRACE_ATTACH) {		rval = ptrace_attach(child);		goto out_tsk;	}	rval = ptrace_check_attach(child, request == PTRACE_KILL);	if (rval < 0)		goto out_tsk;	switch (request) {		unsigned long val, copied;	case PTRACE_PEEKTEXT: /* read word at location addr. */	case PTRACE_PEEKDATA:		copied = access_process_vm(child, addr, &val, sizeof(val), 0);		rval = -EIO;		if (copied != sizeof(val))			break;		rval = put_user(val, (unsigned long *)data);		goto out;	case PTRACE_POKETEXT: /* write the word at location addr. */	case PTRACE_POKEDATA:		rval = 0;		if (access_process_vm(child, addr, &data, sizeof(data), 1)		    == sizeof(data))			break;		rval = -EIO;		goto out;	/* Read/write the word at location ADDR in the registers.  */	case PTRACE_PEEKUSR:	case PTRACE_POKEUSR:		rval = 0;		if (addr >= PT_SIZE && request == PTRACE_PEEKUSR) {			/* Special requests that don't actually correspond			   to offsets in struct pt_regs.  */			if (addr == PT_TEXT_ADDR)				val = child->mm->start_code;			else if (addr == PT_DATA_ADDR)				val = child->mm->start_data;			else if (addr == PT_TEXT_LEN)				val = child->mm->end_code					- child->mm->start_code;			else				rval = -EIO;		} else if (addr >= 0 && addr < PT_SIZE && (addr & 0x3) == 0) {			v850_reg_t *reg_addr = reg_save_addr(addr, child);			if (request == PTRACE_PEEKUSR)				val = *reg_addr;			else				*reg_addr = data;		} else			rval = -EIO;		if (rval == 0 && request == PTRACE_PEEKUSR)			rval = put_user (val, (unsigned long *)data);		goto out;	/* Continue and stop at next (return from) syscall */	case PTRACE_SYSCALL:	/* Restart after a signal.  */	case PTRACE_CONT:	/* Execute a single instruction. */	case PTRACE_SINGLESTEP:		rval = -EIO;		if (!valid_signal(data))			break;		/* Turn CHILD's single-step flag on or off.  */		if (! set_single_step (child, request == PTRACE_SINGLESTEP))			break;		if (request == PTRACE_SYSCALL)			set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);		else			clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);		child->exit_code = data;		wake_up_process(child);		rval = 0;		break;	/*	 * make the child exit.  Best I can do is send it a sigkill.	 * perhaps it should be put in the status that it wants to	 * exit.	 */	case PTRACE_KILL:		rval = 0;		if (child->exit_state == EXIT_ZOMBIE)	/* already dead */			break;		child->exit_code = SIGKILL;		wake_up_process(child);		break;	case PTRACE_DETACH: /* detach a process that was attached. */		set_single_step (child, 0);  /* Clear single-step flag */		rval = ptrace_detach(child, data);		break;	default:		rval = -EIO;		goto out;	}out_tsk:	put_task_struct(child);out:	unlock_kernel();	return rval;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/dfb7dac3af623a68262536437af008ed6aba4d88/ptrace.c/buggy/arch/v850/kernel/ptrace.c