vserver 1.9.5.x5
[linux-2.6.git] / arch / cris / arch-v10 / kernel / ptrace.c
index c83eba5..da15db8 100644 (file)
  */
 #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 *)user_regs(task->thread_info))[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 *)user_regs(task->thread_info))[regno] = data;
+       else
+               return -1;
+       return 0;
+}
 
 /*
  * Called by kernel/ptrace.c when detaching.
@@ -50,6 +79,7 @@ sys_ptrace(long request, long pid, long addr, long data)
 {
        struct task_struct *child;
        int ret;
+       unsigned long __user *datap = (unsigned long __user *)data;
 
        lock_kernel();
        ret = -EPERM;
@@ -85,17 +115,8 @@ sys_ptrace(long request, long pid, long addr, long data)
                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)
+       ret = ptrace_check_attach(child, request == PTRACE_KILL);
+       if (ret < 0)
                goto out_tsk;
 
        switch (request) {
@@ -111,26 +132,20 @@ sys_ptrace(long request, long pid, long addr, long data)
                        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;
                }
                
@@ -148,28 +163,21 @@ sys_ptrace(long request, long pid, long addr, long data)
                /* 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:
@@ -235,9 +243,9 @@ sys_ptrace(long request, long pid, long addr, long data)
                        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;
+                                       goto out_tsk;
                                }
                                
                                data += sizeof(long);
@@ -253,9 +261,9 @@ sys_ptrace(long request, long pid, long addr, long data)
                        unsigned long tmp;
                        
                        for (i = 0; i <= PT_MAX; i++) {
-                               if (get_user(tmp, (unsigned long *) data)) {
+                               if (get_user(tmp, datap)) {
                                        ret = -EFAULT;
-                                       break;
+                                       goto out_tsk;
                                }
                                
                                if (i == PT_DCCR) {
@@ -290,12 +298,10 @@ void do_syscall_trace(void)
        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