static int regs_set(struct task_struct *target, const struct user_regset *regset, unsigned int pos, unsigned int count, const void *kbuf, const void __user *ubuf) { int r; int ret; struct user_regs_struct regs; long *reg; /* build user regs in buffer */ BUILD_BUG_ON(sizeof(regs) % sizeof(long) != 0); for (reg = (long *)®s, r = 0; r < sizeof(regs) / sizeof(long); r++) *reg++ = h8300_get_reg(target, r); ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, ®s, 0, sizeof(regs)); if (ret) return ret; /* write back to pt_regs */ for (reg = (long *)®s, r = 0; r < sizeof(regs) / sizeof(long); r++) h8300_put_reg(target, r, *reg++); return 0; }
long arch_ptrace(struct task_struct *child, long request, long addr, long data) { int ret; switch (request) { case PTRACE_PEEKTEXT: /* read word at location addr. */ case PTRACE_PEEKDATA: { unsigned long tmp; ret = read_long(child, addr, &tmp); if (ret < 0) 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 = 0; if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) { ret = -EIO; break ; } ret = 0; /* Default return condition */ addr = addr >> 2; /* temporary hack. */ if (addr < H8300_REGS_NO) tmp = h8300_get_reg(child, addr); else { switch(addr) { case 49: tmp = child->mm->start_code; break ; case 50: tmp = child->mm->start_data; break ; case 51: tmp = child->mm->end_code; break ; case 52: tmp = child->mm->end_data; break ; default: ret = -EIO; } } if (!ret) 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 */ if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) { ret = -EIO; break ; } addr = addr >> 2; /* temporary hack. */ if (addr == PT_ORIG_ER0) { ret = -EIO; break ; } if (addr < H8300_REGS_NO) { ret = h8300_put_reg(child, addr, data); break ; } ret = -EIO; break ; case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ case PTRACE_CONT: { /* restart after signal. */ ret = -EIO; if ((unsigned long) data >= _NSIG) 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); /* make sure the single step bit is not set. */ h8300_disable_trace(child); ret = 0; } /* * 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; h8300_disable_trace(child); wake_up_process(child); break; } case PTRACE_SINGLESTEP: { /* set the trap flag. */ ret = -EIO; if ((unsigned long) data > _NSIG) break; clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); child->exit_code = data; h8300_enable_trace(child); wake_up_process(child); ret = 0; break; } case PTRACE_DETACH: /* detach a process that was attached. */ ret = ptrace_detach(child, data); break; case PTRACE_GETREGS: { /* Get all gp regs from the child. */ int i; unsigned long tmp; for (i = 0; i < H8300_REGS_NO; i++) { tmp = h8300_get_reg(child, i); if (put_user(tmp, (unsigned long *) data)) { ret = -EFAULT; break; } data += sizeof(long); } ret = 0; break; } case PTRACE_SETREGS: { /* Set all gp regs in the child. */ int i; unsigned long tmp; for (i = 0; i < H8300_REGS_NO; i++) { if (get_user(tmp, (unsigned long *) data)) { ret = -EFAULT; break; } h8300_put_reg(child, i, tmp); data += sizeof(long); } ret = 0; break; } default: ret = -EIO; break; } return ret; }
long arch_ptrace(struct task_struct *child, long request, unsigned long addr, unsigned long data) { int ret; int regno = addr >> 2; unsigned long __user *datap = (unsigned long __user *) data; switch (request) { /* read the word at location addr in the USER area. */ case PTRACE_PEEKUSR: { unsigned long tmp = 0; if ((addr & 3) || addr >= sizeof(struct user)) { ret = -EIO; break ; } ret = 0; /* Default return condition */ if (regno < H8300_REGS_NO) tmp = h8300_get_reg(child, regno); else { switch (regno) { case 49: tmp = child->mm->start_code; break ; case 50: tmp = child->mm->start_data; break ; case 51: tmp = child->mm->end_code; break ; case 52: tmp = child->mm->end_data; break ; default: ret = -EIO; } } if (!ret) ret = put_user(tmp, datap); break ; } /* when I and D space are separate, this will have to be fixed. */ case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ if ((addr & 3) || addr >= sizeof(struct user)) { ret = -EIO; break ; } if (regno == PT_ORIG_ER0) { ret = -EIO; break ; } if (regno < H8300_REGS_NO) { ret = h8300_put_reg(child, regno, data); break ; } ret = -EIO; break ; case PTRACE_GETREGS: { /* Get all gp regs from the child. */ int i; unsigned long tmp; for (i = 0; i < H8300_REGS_NO; i++) { tmp = h8300_get_reg(child, i); if (put_user(tmp, datap)) { ret = -EFAULT; break; } datap++; } ret = 0; break; } case PTRACE_SETREGS: { /* Set all gp regs in the child. */ int i; unsigned long tmp; for (i = 0; i < H8300_REGS_NO; i++) { if (get_user(tmp, datap)) { ret = -EFAULT; break; } h8300_put_reg(child, i, tmp); datap++; } ret = 0; break; } default: ret = ptrace_request(child, request, addr, data); break; } return ret; }
asmlinkage int sys_ptrace(long request, long pid, long addr, long data) { struct task_struct *child; int ret; lock_kernel(); 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 = -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: /* read word at location addr. */ case PTRACE_PEEKDATA: { unsigned long tmp; ret = -EIO; if (access_process_vm(child, addr, &tmp, sizeof(tmp), 0) != sizeof(tmp)) break; ret = verify_area(VERIFY_WRITE, (void *) data, sizeof(long)); if (!ret) put_user(tmp, (unsigned long *) data); break ; } /* read the word at location addr in the USER area. */ case PTRACE_PEEKUSR: { unsigned long tmp; if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) ret = -EIO; ret = verify_area(VERIFY_WRITE, (void *) data, sizeof(long)); if (ret) break ; tmp = 0; /* Default return condition */ addr = addr >> 2; /* temporary hack. */ if (addr < H8300_REGS_NO) tmp = h8300_get_reg(child, addr); else { switch(addr) { case 49: tmp = child->mm->start_code; break ; case 50: tmp = child->mm->start_data; break ; case 51: tmp = child->mm->end_code; break ; case 52: tmp = child->mm->end_data; break ; default: ret = -EIO; } } if (!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 */ if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) { ret = -EIO; break ; } addr = addr >> 2; /* temporary hack. */ if (addr == PT_ORIG_ER0) { ret = -EIO; break ; } if (addr < H8300_REGS_NO) { ret = h8300_put_reg(child, addr, data); break ; } ret = -EIO; break ; case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ case PTRACE_CONT: { /* restart after signal. */ ret = -EIO; if ((unsigned long) data >= _NSIG) break ; if (request == PTRACE_SYSCALL) child->flags |= PT_TRACESYS; else child->flags &= ~PT_TRACESYS; child->exit_code = data; wake_up_process(child); /* make sure the single step bit is not set. */ h8300_disable_trace(child); ret = 0; } /* * 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->state == TASK_ZOMBIE) /* already dead */ break; child->exit_code = SIGKILL; h8300_disable_trace(child); wake_up_process(child); break; } case PTRACE_SINGLESTEP: { /* set the trap flag. */ ret = -EIO; if ((unsigned long) data > _NSIG) break; child->ptrace &= ~PT_TRACESYS; child->exit_code = data; h8300_enable_trace(child); wake_up_process(child); ret = 0; break; } case PTRACE_DETACH: /* detach a process that was attached. */ ret = ptrace_detach(child, data); break; case PTRACE_GETREGS: { /* Get all gp regs from the child. */ int i; unsigned long tmp; for (i = 0; i < H8300_REGS_NO; i++) { tmp = h8300_get_reg(child, i); if (put_user(tmp, (unsigned long *) data)) { ret = -EFAULT; break; } data += sizeof(long); } ret = 0; break; } case PTRACE_SETREGS: { /* Set all gp regs in the child. */ int i; unsigned long tmp; for (i = 0; i < H8300_REGS_NO; i++) { if (get_user(tmp, (unsigned long *) data)) { ret = -EFAULT; break; } h8300_put_reg(child, i, tmp); data += sizeof(long); } ret = 0; break; } default: ret = -EIO; break; } out_tsk: free_task_struct(child); out: unlock_kernel(); return ret; }