⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ptrace.c

📁 讲述linux的初始化过程
💻 C
📖 第 1 页 / 共 2 页
字号:
				goto out;			}		pt_succ_return(regs, 0);#ifdef DEBUG_PTRACE		printk ("PC=%lx nPC=%lx o7=%lx\n", cregs->tpc, cregs->tnpc, cregs->u_regs [15]);#endif		goto out;	}	case PTRACE_SETREGS: {		struct pt_regs32 *pregs = (struct pt_regs32 *) addr;		struct pt_regs *cregs = child->thread.kregs;		unsigned int psr, pc, npc, y;		int i;		/* Must be careful, tracing process can only set certain		 * bits in the psr.		 */		if (__get_user(psr, (&pregs->psr)) ||		    __get_user(pc, (&pregs->pc)) ||		    __get_user(npc, (&pregs->npc)) ||		    __get_user(y, (&pregs->y))) {			pt_error_return(regs, EFAULT);			goto out;		}		cregs->tstate &= ~(TSTATE_ICC);		cregs->tstate |= psr_to_tstate_icc(psr);               	if(!((pc | npc) & 3)) {			cregs->tpc = pc;			cregs->tnpc = npc;		}		cregs->y = y;		for(i = 1; i < 16; i++) {			if (__get_user(cregs->u_regs[i], (&pregs->u_regs[i-1]))) {				pt_error_return(regs, EFAULT);				goto out;			}		}		pt_succ_return(regs, 0);		goto out;	}	case PTRACE_SETREGS64: {		struct pt_regs *pregs = (struct pt_regs *) addr;		struct pt_regs *cregs = child->thread.kregs;		unsigned long tstate, tpc, tnpc, y;		int i;		/* Must be careful, tracing process can only set certain		 * bits in the psr.		 */		if (__get_user(tstate, (&pregs->tstate)) ||		    __get_user(tpc, (&pregs->tpc)) ||		    __get_user(tnpc, (&pregs->tnpc)) ||		    __get_user(y, (&pregs->y))) {			pt_error_return(regs, EFAULT);			goto out;		}		tstate &= (TSTATE_ICC | TSTATE_XCC);		cregs->tstate &= ~(TSTATE_ICC | TSTATE_XCC);		cregs->tstate |= tstate;		if(!((tpc | tnpc) & 3)) {			cregs->tpc = tpc;			cregs->tnpc = tnpc;		}		cregs->y = y;		for(i = 1; i < 16; i++) {			if (__get_user(cregs->u_regs[i], (&pregs->u_regs[i-1]))) {				pt_error_return(regs, EFAULT);				goto out;			}		}		pt_succ_return(regs, 0);		goto out;	}	case PTRACE_GETFPREGS: {		struct fps {			unsigned int regs[32];			unsigned int fsr;			unsigned int flags;			unsigned int extra;			unsigned int fpqd;			struct fq {				unsigned int insnaddr;				unsigned int insn;			} fpq[16];		} *fps = (struct fps *) addr;		unsigned long *fpregs = (unsigned long *)(((char *)child) + AOFF_task_fpregs);		if (copy_to_user(&fps->regs[0], fpregs,				 (32 * sizeof(unsigned int))) ||		    __put_user(child->thread.xfsr[0], (&fps->fsr)) ||		    __put_user(0, (&fps->fpqd)) ||		    __put_user(0, (&fps->flags)) ||		    __put_user(0, (&fps->extra)) ||		    clear_user(&fps->fpq[0], 32 * sizeof(unsigned int))) {			pt_error_return(regs, EFAULT);			goto out;		}		pt_succ_return(regs, 0);		goto out;	}	case PTRACE_GETFPREGS64: {		struct fps {			unsigned int regs[64];			unsigned long fsr;		} *fps = (struct fps *) addr;		unsigned long *fpregs = (unsigned long *)(((char *)child) + AOFF_task_fpregs);		if (copy_to_user(&fps->regs[0], fpregs,				 (64 * sizeof(unsigned int))) ||		    __put_user(child->thread.xfsr[0], (&fps->fsr))) {			pt_error_return(regs, EFAULT);			goto out;		}		pt_succ_return(regs, 0);		goto out;	}	case PTRACE_SETFPREGS: {		struct fps {			unsigned int regs[32];			unsigned int fsr;			unsigned int flags;			unsigned int extra;			unsigned int fpqd;			struct fq {				unsigned int insnaddr;				unsigned int insn;			} fpq[16];		} *fps = (struct fps *) addr;		unsigned long *fpregs = (unsigned long *)(((char *)child) + AOFF_task_fpregs);		unsigned fsr;		if (copy_from_user(fpregs, &fps->regs[0],				   (32 * sizeof(unsigned int))) ||		    __get_user(fsr, (&fps->fsr))) {			pt_error_return(regs, EFAULT);			goto out;		}		child->thread.xfsr[0] &= 0xffffffff00000000UL;		child->thread.xfsr[0] |= fsr;		if (!(child->thread.fpsaved[0] & FPRS_FEF))			child->thread.gsr[0] = 0;		child->thread.fpsaved[0] |= (FPRS_FEF | FPRS_DL);		pt_succ_return(regs, 0);		goto out;	}	case PTRACE_SETFPREGS64: {		struct fps {			unsigned int regs[64];			unsigned long fsr;		} *fps = (struct fps *) addr;		unsigned long *fpregs = (unsigned long *)(((char *)child) + AOFF_task_fpregs);		if (copy_from_user(fpregs, &fps->regs[0],				   (64 * sizeof(unsigned int))) ||		    __get_user(child->thread.xfsr[0], (&fps->fsr))) {			pt_error_return(regs, EFAULT);			goto out;		}		if (!(child->thread.fpsaved[0] & FPRS_FEF))			child->thread.gsr[0] = 0;		child->thread.fpsaved[0] |= (FPRS_FEF | FPRS_DL | FPRS_DU);		pt_succ_return(regs, 0);		goto out;	}	case PTRACE_READTEXT:	case PTRACE_READDATA: {		int res = ptrace_readdata(child, addr,					  (void *)addr2, data);		if (res == data) {			pt_succ_return(regs, 0);			goto flush_and_out;		}		if (res >= 0)			res = -EIO;		pt_error_return(regs, -res);		goto flush_and_out;	}	case PTRACE_WRITETEXT:	case PTRACE_WRITEDATA: {		int res = ptrace_writedata(child, (void *) addr2,					   addr, data);		if (res == data) {			pt_succ_return(regs, 0);			goto flush_and_out;		}		if (res >= 0)			res = -EIO;		pt_error_return(regs, -res);		goto flush_and_out;	}	case PTRACE_SYSCALL: /* continue and stop at (return from) syscall */		addr = 1;	case PTRACE_CONT: { /* restart after signal. */		if (data > _NSIG) {			pt_error_return(regs, EIO);			goto out;		}		if (addr != 1) {			if (addr & 3) {				pt_error_return(regs, EINVAL);				goto out;			}#ifdef DEBUG_PTRACE			printk ("Original: %016lx %016lx\n", child->thread.kregs->tpc, child->thread.kregs->tnpc);			printk ("Continuing with %016lx %016lx\n", addr, addr+4);#endif			child->thread.kregs->tpc = addr;			child->thread.kregs->tnpc = addr + 4;		}		if (request == PTRACE_SYSCALL)			child->ptrace |= PT_TRACESYS;		else			child->ptrace &= ~PT_TRACESYS;		child->exit_code = data;#ifdef DEBUG_PTRACE		printk("CONT: %s [%d]: set exit_code = %x %lx %lx\n", child->comm,			child->pid, child->exit_code,			child->thread.kregs->tpc,			child->thread.kregs->tnpc);		       #endif		wake_up_process(child);		pt_succ_return(regs, 0);		goto out;	}/* * 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: {		if (child->state == TASK_ZOMBIE) {	/* already dead */			pt_succ_return(regs, 0);			goto out;		}		child->exit_code = SIGKILL;		wake_up_process(child);		pt_succ_return(regs, 0);		goto out;	}	case PTRACE_SUNDETACH: { /* detach a process that was attached. */		unsigned long flags;		if ((unsigned long) data > _NSIG) {			pt_error_return(regs, EIO);			goto out;		}		child->ptrace &= ~(PT_PTRACED|PT_TRACESYS);		child->exit_code = data;		write_lock_irqsave(&tasklist_lock, flags);		REMOVE_LINKS(child);		child->p_pptr = child->p_opptr;		SET_LINKS(child);		write_unlock_irqrestore(&tasklist_lock, flags);		wake_up_process(child);		pt_succ_return(regs, 0);		goto out;	}	/* PTRACE_DUMPCORE unsupported... */	default:		pt_error_return(regs, EIO);		goto out;	}flush_and_out:	{		unsigned long va;		for(va =  0; va < (PAGE_SIZE << 1); va += 32)			spitfire_put_dcache_tag(va, 0x0);		if (request == PTRACE_PEEKTEXT ||		    request == PTRACE_POKETEXT ||		    request == PTRACE_READTEXT ||		    request == PTRACE_WRITETEXT) {			for(va =  0; va < (PAGE_SIZE << 1); va += 32)				spitfire_put_icache_tag(va, 0x0);			__asm__ __volatile__("flush %g6");		}	}out:	unlock_kernel();}asmlinkage void syscall_trace(void){#ifdef DEBUG_PTRACE	printk("%s [%d]: syscall_trace\n", current->comm, current->pid);#endif	if ((current->ptrace & (PT_PTRACED|PT_TRACESYS))	    != (PT_PTRACED|PT_TRACESYS))		return;	current->exit_code = SIGTRAP;	current->state = TASK_STOPPED;	current->thread.flags ^= MAGIC_CONSTANT;	notify_parent(current, SIGCHLD);	schedule();	/*	 * this isn't the same as continuing with a signal, but it will do	 * for normal use.  strace only continues with a signal if the	 * stopping signal is not SIGTRAP.  -brl	 */#ifdef DEBUG_PTRACE	printk("%s [%d]: syscall_trace exit= %x\n", current->comm,		current->pid, current->exit_code);#endif	if (current->exit_code) {		send_sig (current->exit_code, current, 1);		current->exit_code = 0;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -