#include <linux/errno.h>
#include <linux/ptrace.h>
#include <linux/user.h>
+#include <linux/signal.h>
+#include <linux/security.h>
#include <asm/uaccess.h>
#include <asm/page.h>
*/
#define DCCR_MASK 0x0000001f /* XNZVC */
-extern inline long get_reg(struct task_struct *, unsigned int);
-extern inline long put_reg(struct task_struct *, unsigned int, unsigned long);
+/*
+ * Get contents of register REGNO in task TASK.
+ */
+inline long get_reg(struct task_struct *task, unsigned int regno)
+{
+ /* USP is a special case, it's not in the pt_regs struct but
+ * in the tasks thread struct
+ */
+
+ if (regno == PT_USP)
+ return task->thread.usp;
+ else if (regno < PT_MAX)
+ return ((unsigned long *)task_pt_regs(task))[regno];
+ else
+ return 0;
+}
+
+/*
+ * Write contents of register REGNO in task TASK.
+ */
+inline int put_reg(struct task_struct *task, unsigned int regno,
+ unsigned long data)
+{
+ if (regno == PT_USP)
+ task->thread.usp = data;
+ else if (regno < PT_MAX)
+ ((unsigned long *)task_pt_regs(task))[regno] = data;
+ else
+ return -1;
+ return 0;
+}
/*
* Called by kernel/ptrace.c when detaching.
* (in user space) where the result of the ptrace call is written (instead of
* being returned).
*/
-asmlinkage int
-sys_ptrace(long request, long pid, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request, long addr, long data)
{
- struct task_struct *child;
int ret;
-
- lock_kernel();
- ret = -EPERM;
-
- if (request == PTRACE_TRACEME) {
- 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) /* Leave the init process alone! */
- 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->parent != current)
- goto out_tsk;
+ unsigned long __user *datap = (unsigned long __user *)data;
switch (request) {
/* Read word at location address. */
if (copied != sizeof(tmp))
break;
- ret = put_user(tmp,(unsigned long *) data);
+ ret = put_user(tmp,datap);
break;
}
/* Read the word at location address in the USER area. */
case PTRACE_PEEKUSR: {
unsigned long tmp;
-
+
ret = -EIO;
- if ((addr & 3) || addr < 0 || addr >= sizeof(struct user))
+ if ((addr & 3) || addr < 0 || addr > PT_MAX << 2)
break;
-
- tmp = 0; /* Default return condition */
- ret = -EIO;
-
- if (addr < sizeof(struct pt_regs)) {
- tmp = get_reg(child, addr >> 2);
- ret = put_user(tmp, (unsigned long *)data);
- }
-
+
+ tmp = get_reg(child, addr >> 2);
+ ret = put_user(tmp, datap);
break;
}
/* Write the word at location address in the USER area. */
case PTRACE_POKEUSR:
ret = -EIO;
-
- if ((addr & 3) || addr < 0 || addr >= sizeof(struct user))
+ if ((addr & 3) || addr < 0 || addr > PT_MAX << 2)
break;
- if (addr < sizeof(struct pt_regs)) {
- addr >>= 2;
+ addr >>= 2;
- if (addr == PT_DCCR) {
- /*
- * Don't allow the tracing process to
- * change stuff like interrupt enable,
- * kernel/user bit, etc.
- */
- data &= DCCR_MASK;
- data |= get_reg(child, PT_DCCR) & ~DCCR_MASK;
- }
-
- if (put_reg(child, addr, data))
- break;
-
- ret = 0;
+ if (addr == PT_DCCR) {
+ /* don't allow the tracing process to change stuff like
+ * interrupt enable, kernel/user bit, dma enables etc.
+ */
+ data &= DCCR_MASK;
+ data |= get_reg(child, PT_DCCR) & ~DCCR_MASK;
}
+ if (put_reg(child, addr, data))
+ break;
+ ret = 0;
break;
case PTRACE_SYSCALL:
case PTRACE_CONT:
ret = -EIO;
- if ((unsigned long) data > _NSIG)
+ if (!valid_signal(data))
break;
if (request == PTRACE_SYSCALL) {
case PTRACE_KILL:
ret = 0;
- if (child->state == TASK_ZOMBIE)
+ if (child->exit_state == EXIT_ZOMBIE)
break;
child->exit_code = SIGKILL;
case PTRACE_SINGLESTEP:
ret = -EIO;
- if ((unsigned long) data > _NSIG)
+ if (!valid_signal(data))
break;
clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
int i;
unsigned long tmp;
+ ret = 0;
for (i = 0; i <= PT_MAX; i++) {
tmp = get_reg(child, i);
- if (put_user(tmp, (unsigned long *) data)) {
+ if (put_user(tmp, datap)) {
ret = -EFAULT;
break;
}
data += sizeof(long);
}
- ret = 0;
break;
}
int i;
unsigned long tmp;
+ ret = 0;
for (i = 0; i <= PT_MAX; i++) {
- if (get_user(tmp, (unsigned long *) data)) {
+ if (get_user(tmp, datap)) {
ret = -EFAULT;
break;
}
data += sizeof(long);
}
- ret = 0;
break;
}
ret = ptrace_request(child, request, addr, data);
break;
}
-out_tsk:
- put_task_struct(child);
-out:
- unlock_kernel();
+
return ret;
}
if (!(current->ptrace & PT_PTRACED))
return;
- current->exit_code = SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
- ? 0x80 : 0);
-
- current->state = TASK_STOPPED;
- notify_parent(current, SIGCHLD);
- schedule();
+ /* the 0x80 provides a way for the tracing parent to distinguish
+ between a syscall stop and SIGTRAP delivery */
+ ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
+ ? 0x80 : 0));
/*
* This isn't the same as continuing with a signal, but it will do for