📄 ptrace.c
字号:
return -1; if (addr < PT_F127+16) { /* accessing fph */ if (write_access) ia64_sync_fph(child); else ia64_flush_fph(child); ptr = (unsigned long *) ((unsigned long) &child->thread.fph + addr); } else if (addr < PT_F9+16) { /* accessing switch_stack or pt_regs: */ pt = ia64_task_regs(child); sw = (struct switch_stack *) pt - 1; switch (addr) { case PT_NAT_BITS: if (write_access) ia64_put_nat_bits(pt, sw, *data); else *data = ia64_get_nat_bits(pt, sw); return 0; case PT_AR_BSP: if (write_access) /* FIXME? Account for lack of ``cover'' in the syscall case */ return sync_kernel_register_backing_store(child, *data, 1); else { rbs = (unsigned long *) child + IA64_RBS_OFFSET/8; bspstore = (unsigned long *) pt->ar_bspstore; ndirty = ia64_rse_num_regs(rbs, rbs + (pt->loadrs >> 19)); /* * If we're in a system call, no ``cover'' was done. So to * make things uniform, we'll add the appropriate displacement * onto bsp if we're in a system call. */ if (!(pt->cr_ifs & (1UL << 63))) ndirty += sw->ar_pfs & 0x7f; *data = (unsigned long) ia64_rse_skip_regs(bspstore, ndirty); return 0; } case PT_CFM: if (write_access) { if (pt->cr_ifs & (1UL << 63)) pt->cr_ifs = ((pt->cr_ifs & ~0x3fffffffffUL) | (*data & 0x3fffffffffUL)); else sw->ar_pfs = ((sw->ar_pfs & ~0x3fffffffffUL) | (*data & 0x3fffffffffUL)); return 0; } else { if ((pt->cr_ifs & (1UL << 63)) == 0) *data = sw->ar_pfs; else /* return only the CFM */ *data = pt->cr_ifs & 0x3fffffffffUL; return 0; } case PT_CR_IPSR: if (write_access) pt->cr_ipsr = ((*data & IPSR_WRITE_MASK) | (pt->cr_ipsr & ~IPSR_WRITE_MASK)); else *data = (pt->cr_ipsr & IPSR_READ_MASK); return 0; case PT_AR_EC: if (write_access) sw->ar_pfs = (((*data & 0x3f) << 52) | (sw->ar_pfs & ~(0x3fUL << 52))); else *data = (sw->ar_pfs >> 52) & 0x3f; break; case PT_R1: case PT_R2: case PT_R3: case PT_R4: case PT_R5: case PT_R6: case PT_R7: case PT_R8: case PT_R9: case PT_R10: case PT_R11: case PT_R12: case PT_R13: case PT_R14: case PT_R15: case PT_R16: case PT_R17: case PT_R18: case PT_R19: case PT_R20: case PT_R21: case PT_R22: case PT_R23: case PT_R24: case PT_R25: case PT_R26: case PT_R27: case PT_R28: case PT_R29: case PT_R30: case PT_R31: case PT_B0: case PT_B1: case PT_B2: case PT_B3: case PT_B4: case PT_B5: case PT_B6: case PT_B7: case PT_F2: case PT_F2+8: case PT_F3: case PT_F3+8: case PT_F4: case PT_F4+8: case PT_F5: case PT_F5+8: case PT_F6: case PT_F6+8: case PT_F7: case PT_F7+8: case PT_F8: case PT_F8+8: case PT_F9: case PT_F9+8: case PT_F10: case PT_F10+8: case PT_F11: case PT_F11+8: case PT_F12: case PT_F12+8: case PT_F13: case PT_F13+8: case PT_F14: case PT_F14+8: case PT_F15: case PT_F15+8: case PT_F16: case PT_F16+8: case PT_F17: case PT_F17+8: case PT_F18: case PT_F18+8: case PT_F19: case PT_F19+8: case PT_F20: case PT_F20+8: case PT_F21: case PT_F21+8: case PT_F22: case PT_F22+8: case PT_F23: case PT_F23+8: case PT_F24: case PT_F24+8: case PT_F25: case PT_F25+8: case PT_F26: case PT_F26+8: case PT_F27: case PT_F27+8: case PT_F28: case PT_F28+8: case PT_F29: case PT_F29+8: case PT_F30: case PT_F30+8: case PT_F31: case PT_F31+8: case PT_AR_BSPSTORE: case PT_AR_RSC: case PT_AR_UNAT: case PT_AR_PFS: case PT_AR_RNAT: case PT_AR_CCV: case PT_AR_FPSR: case PT_CR_IIP: case PT_PR: case PT_AR_LC: ptr = (unsigned long *) ((long) sw + addr - PT_NAT_BITS); break; default: /* disallow accessing anything else... */ return -1; } } else { /* access debug registers */ if (!(child->thread.flags & IA64_THREAD_DBG_VALID)) { child->thread.flags |= IA64_THREAD_DBG_VALID; memset(child->thread.dbr, 0, sizeof child->thread.dbr); memset(child->thread.ibr, 0, sizeof child->thread.ibr); } if (addr >= PT_IBR) { regnum = (addr - PT_IBR) >> 3; ptr = &child->thread.ibr[0]; } else { regnum = (addr - PT_DBR) >> 3; ptr = &child->thread.dbr[0]; } if (regnum >= 8) return -1; ptr += regnum; if (write_access) /* don't let the user set kernel-level breakpoints... */ *ptr = *data & ~(7UL << 56); else *data = *ptr; return 0; } if (write_access) *ptr = *data; else *data = *ptr; return 0;}#endif /* !CONFIG_IA64_NEW_UNWIND */asmlinkage longsys_ptrace (long request, pid_t pid, unsigned long addr, unsigned long data, long arg4, long arg5, long arg6, long arg7, long stack){ struct pt_regs *regs = (struct pt_regs *) &stack; struct task_struct *child; unsigned long flags; long ret; lock_kernel(); ret = -EPERM; if (request == PTRACE_TRACEME) { /* are we already being traced? */ if (current->ptrace & PT_PTRACED) goto out; 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) /* no messing around with init! */ goto out_tsk; if (request == PTRACE_ATTACH) { if (child == current) goto out_tsk; if ((!child->dumpable || (current->uid != child->euid) || (current->uid != child->suid) || (current->uid != child->uid) || (current->gid != child->egid) || (current->gid != child->sgid) || (!cap_issubset(child->cap_permitted, current->cap_permitted)) || (current->gid != child->gid)) && !capable(CAP_SYS_PTRACE)) goto out_tsk; /* the same process cannot be attached many times */ if (child->ptrace & PT_PTRACED) goto out_tsk; child->ptrace |= PT_PTRACED; if (child->p_pptr != current) { unsigned long flags; write_lock_irqsave(&tasklist_lock, flags); REMOVE_LINKS(child); child->p_pptr = current; SET_LINKS(child); write_unlock_irqrestore(&tasklist_lock, flags); } send_sig(SIGSTOP, child, 1); ret = 0; goto out_tsk; } ret = -ESRCH; if (!(child->ptrace & PT_PTRACED)) goto out_tsk; if (child->state != TASK_STOPPED) { if (request != PTRACE_KILL) goto out_tsk; } if (child->p_pptr != current) goto out_tsk; switch (request) { case PTRACE_PEEKTEXT: case PTRACE_PEEKDATA: /* read word at location addr */ if (!(child->thread.flags & IA64_THREAD_KRBS_SYNCED)) { struct mm_struct *mm; long do_sync; task_lock(child); { mm = child->mm; do_sync = mm && (atomic_read(&mm->mm_users) > 1); } task_unlock(child); if (do_sync) sync_thread_rbs(child, mm, 0); } ret = ia64_peek(regs, child, addr, &data); if (ret == 0) { ret = data; regs->r8 = 0; /* ensure "ret" is not mistaken as an error code */ } goto out_tsk; case PTRACE_POKETEXT: case PTRACE_POKEDATA: /* write the word at location addr */ if (!(child->thread.flags & IA64_THREAD_KRBS_SYNCED)) { struct mm_struct *mm; long do_sync; task_lock(child); { mm = child->mm; do_sync = mm && (atomic_read(&child->mm->mm_users) > 1); } task_unlock(child); if (do_sync) sync_thread_rbs(child, mm, 1); } ret = ia64_poke(regs, child, addr, data); goto out_tsk; case PTRACE_PEEKUSR: /* read the word at addr in the USER area */ if (access_uarea(child, addr, &data, 0) < 0) { ret = -EIO; goto out_tsk; } ret = data; regs->r8 = 0; /* ensure "ret" is not mistaken as an error code */ goto out_tsk; case PTRACE_POKEUSR: /* write the word at addr in the USER area */ if (access_uarea(child, addr, &data, 1) < 0) { ret = -EIO; goto out_tsk; } ret = 0; goto out_tsk; case PTRACE_GETSIGINFO: ret = -EIO; if (!access_ok(VERIFY_WRITE, data, sizeof (siginfo_t)) || child->thread.siginfo == 0) goto out_tsk; copy_to_user((siginfo_t *) data, child->thread.siginfo, sizeof (siginfo_t)); ret = 0; goto out_tsk; break; case PTRACE_SETSIGINFO: ret = -EIO; if (!access_ok(VERIFY_READ, data, sizeof (siginfo_t)) || child->thread.siginfo == 0) goto out_tsk; copy_from_user(child->thread.siginfo, (siginfo_t *) data, sizeof (siginfo_t)); ret = 0; goto out_tsk; case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ case PTRACE_CONT: /* restart after signal. */ ret = -EIO; if (data > _NSIG) goto out_tsk; if (request == PTRACE_SYSCALL) child->ptrace |= PT_TRACESYS; else child->ptrace &= ~PT_TRACESYS; child->exit_code = data; /* make sure the single step/take-branch tra bits are not set: */ ia64_psr(ia64_task_regs(child))->ss = 0; ia64_psr(ia64_task_regs(child))->tb = 0; /* Turn off flag indicating that the KRBS is sync'd with child's VM: */ child->thread.flags &= ~IA64_THREAD_KRBS_SYNCED; wake_up_process(child); ret = 0; goto out_tsk; case PTRACE_KILL: /* * 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. */ if (child->state == TASK_ZOMBIE) /* already dead */ goto out_tsk; child->exit_code = SIGKILL; /* make sure the single step/take-branch tra bits are not set: */ ia64_psr(ia64_task_regs(child))->ss = 0; ia64_psr(ia64_task_regs(child))->tb = 0; /* Turn off flag indicating that the KRBS is sync'd with child's VM: */ child->thread.flags &= ~IA64_THREAD_KRBS_SYNCED; wake_up_process(child); ret = 0; goto out_tsk; case PTRACE_SINGLESTEP: /* let child execute for one instruction */ case PTRACE_SINGLEBLOCK: ret = -EIO; if (data > _NSIG) goto out_tsk; child->ptrace &= ~PT_TRACESYS; if (request == PTRACE_SINGLESTEP) { ia64_psr(ia64_task_regs(child))->ss = 1; } else { ia64_psr(ia64_task_regs(child))->tb = 1; } child->exit_code = data; /* Turn off flag indicating that the KRBS is sync'd with child's VM: */ child->thread.flags &= ~IA64_THREAD_KRBS_SYNCED; /* give it a chance to run. */ wake_up_process(child); ret = 0; goto out_tsk; case PTRACE_DETACH: /* detach a process that was attached. */ ret = -EIO; if (data > _NSIG) goto out_tsk; 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); /* make sure the single step/take-branch tra bits are not set: */ ia64_psr(ia64_task_regs(child))->ss = 0; ia64_psr(ia64_task_regs(child))->tb = 0; /* Turn off flag indicating that the KRBS is sync'd with child's VM: */ child->thread.flags &= ~IA64_THREAD_KRBS_SYNCED; wake_up_process(child); ret = 0; goto out_tsk; default: ret = -EIO; goto out_tsk; } out_tsk: free_task_struct(child); out: unlock_kernel(); return ret;}voidsyscall_trace (void){ if ((current->ptrace & (PT_PTRACED|PT_TRACESYS)) != (PT_PTRACED|PT_TRACESYS)) return; current->exit_code = SIGTRAP; set_current_state(TASK_STOPPED); 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 */ 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 + -