asmlinkage int sys_ptrace(long request, long pid, long addr, long data) 
asmlinkage long sys_ptrace(long request, long pid, long addr, long data) 
asmlinkage int sys_ptrace(long request, long pid, long addr, long data){	struct task_struct *child;	extern void poke_real_address_q(unsigned long long addr, unsigned long long data);#define WPC_DBRMODE 0x0d104008	static int first_call = 1;	int ret;	lock_kernel();	if (first_call) {		/* Set WPC.DBRMODE to 0.  This makes all debug events get		 * delivered through RESVEC, i.e. into the handlers in entry.S.		 * (If the kernel was downloaded using a remote gdb, WPC.DBRMODE		 * would normally be left set to 1, which makes debug events get		 * delivered through DBRVEC, i.e. into the remote gdb's		 * handlers.  This prevents ptrace getting them, and confuses		 * the remote gdb.) */		printk("DBRMODE set to 0 to permit native debugging\n");		poke_real_address_q(WPC_DBRMODE, 0);		first_call = 0;	}	ret = -EPERM;	if (request == PTRACE_TRACEME) {		/* are we already being traced? */		if (current->ptrace & PT_PTRACED)			goto out;		/* set the ptrace bit in the process flags. */		current->ptrace |= PT_PTRACED;		ret = 0;		goto out;	}	ret = -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;	ret = -EPERM;	if (pid == 1)		/* you may not mess with init */		goto out_tsk;	if (request == PTRACE_ATTACH) {		ret = ptrace_attach(child);			goto out_tsk;		}	ret = ptrace_check_attach(child, request == PTRACE_KILL);	if (ret < 0)		goto out_tsk;	switch (request) {	/* when I and D space are separate, these will need to be fixed. */	case PTRACE_PEEKTEXT: /* read word at location addr. */	case PTRACE_PEEKDATA: {		unsigned long tmp;		int copied;		copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);		ret = -EIO;		if (copied != sizeof(tmp))			break;		ret = put_user(tmp,(unsigned long *) data);		break;	}	/* read the word at location addr in the USER area. */	case PTRACE_PEEKUSR: {		unsigned long tmp;		ret = -EIO;		if ((addr & 3) || addr < 0)			break;		if (addr < sizeof(struct pt_regs))			tmp = get_stack_long(child, addr);		else if ((addr >= offsetof(struct user, fpu)) &&			 (addr <  offsetof(struct user, u_fpvalid))) {			tmp = get_fpu_long(child, addr - offsetof(struct user, fpu));		} else if (addr == offsetof(struct user, u_fpvalid)) {			tmp = !!tsk_used_math(child);		} else {			break;		}		ret = put_user(tmp, (unsigned long *)data);		break;	}	/* when I and D space are separate, this will have to be fixed. */	case PTRACE_POKETEXT: /* write the word at location addr. */	case PTRACE_POKEDATA:		ret = 0;		if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))			break;		ret = -EIO;		break;	case PTRACE_POKEUSR:                /* write the word at location addr in the USER area. We must                   disallow any changes to certain SR bits or u_fpvalid, since                   this could crash the kernel or result in a security                   loophole. */		ret = -EIO;		if ((addr & 3) || addr < 0)			break;		if (addr < sizeof(struct pt_regs)) {			/* Ignore change of top 32 bits of SR */			if (addr == offsetof (struct pt_regs, sr)+4)			{				ret = 0;				break;			}			/* If lower 32 bits of SR, ignore non-user bits */			if (addr == offsetof (struct pt_regs, sr))			{				long cursr = get_stack_long(child, addr);				data &= ~(SR_MASK);				data |= (cursr & SR_MASK);			}			ret = put_stack_long(child, addr, data);		}		else if ((addr >= offsetof(struct user, fpu)) &&			 (addr <  offsetof(struct user, u_fpvalid))) {			ret = put_fpu_long(child, addr - offsetof(struct user, fpu), data);		}		break;	case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */	case PTRACE_CONT: { /* restart after signal. */		ret = -EIO;		if (!valid_signal(data))			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);		ret = 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: {		ret = 0;		if (child->exit_state == EXIT_ZOMBIE)	/* already dead */			break;		child->exit_code = SIGKILL;		wake_up_process(child);		break;	}	case PTRACE_SINGLESTEP: {  /* set the trap flag. */		struct pt_regs *regs;		ret = -EIO;		if (!valid_signal(data))			break;		clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);		if ((child->ptrace & PT_DTRACE) == 0) {			/* Spurious delayed TF traps may occur */			child->ptrace |= PT_DTRACE;		}		regs = child->thread.uregs;		regs->sr |= SR_SSTEP;	/* auto-resetting upon exception */		child->exit_code = data;		/* give it a chance to run. */		wake_up_process(child);		ret = 0;		break;	}	case PTRACE_DETACH: /* detach a process that was attached. */		ret = ptrace_detach(child, data);		break;	default:		ret = ptrace_request(child, request, addr, data);		break;	}out_tsk:	put_task_struct(child);out:	unlock_kernel();	return ret;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/dfb7dac3af623a68262536437af008ed6aba4d88/ptrace.c/buggy/arch/sh64/kernel/ptrace.c