fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / arch / sh64 / kernel / ptrace.c
index c48bc4a..4e95e18 100644 (file)
@@ -17,7 +17,6 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/rwsem.h>
 #include <linux/sched.h>
@@ -27,6 +26,8 @@
 #include <linux/errno.h>
 #include <linux/ptrace.h>
 #include <linux/user.h>
+#include <linux/signal.h>
+#include <linux/syscalls.h>
 
 #include <asm/io.h>
 #include <asm/uaccess.h>
@@ -63,7 +64,7 @@ get_fpu_long(struct task_struct *task, unsigned long addr)
        struct pt_regs *regs;
        regs = (struct pt_regs*)((unsigned char *)task + THREAD_SIZE) - 1;
 
-       if (!task->used_math) {
+       if (!tsk_used_math(task)) {
                if (addr == offsetof(struct user_fpu_struct, fpscr)) {
                        tmp = FPSCR_INIT;
                } else {
@@ -105,9 +106,9 @@ put_fpu_long(struct task_struct *task, unsigned long addr, unsigned long data)
 
        regs = (struct pt_regs*)((unsigned char *)task + THREAD_SIZE) - 1;
 
-       if (!task->used_math) {
+       if (!tsk_used_math(task)) {
                fpinit(&task->thread.fpu.hard);
-               task->used_math = 1;
+               set_stopped_child_used_math(task);
        } else if (last_task_used_math == task) {
                grab_fpu();
                fpsave(&task->thread.fpu.hard);
@@ -120,44 +121,11 @@ put_fpu_long(struct task_struct *task, unsigned long addr, unsigned long data)
        return 0;
 }
 
-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) {
-               /* 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 = ptrace_check_attach(child, request == PTRACE_KILL);
-       if (ret < 0)
-               goto out_tsk;
-
        switch (request) {
        /* when I and D space are separate, these will need to be fixed. */
        case PTRACE_PEEKTEXT: /* read word at location addr. */
@@ -187,7 +155,7 @@ asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
                         (addr <  offsetof(struct user, u_fpvalid))) {
                        tmp = get_fpu_long(child, addr - offsetof(struct user, fpu));
                } else if (addr == offsetof(struct user, u_fpvalid)) {
-                       tmp = child->used_math;
+                       tmp = !!tsk_used_math(child);
                } else {
                        break;
                }
@@ -238,7 +206,7 @@ asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
        case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
        case PTRACE_CONT: { /* restart after signal. */
                ret = -EIO;
-               if ((unsigned long) data > _NSIG)
+               if (!valid_signal(data))
                        break;
                if (request == PTRACE_SYSCALL)
                        set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
@@ -257,7 +225,7 @@ asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
  */
        case PTRACE_KILL: {
                ret = 0;
-               if (child->state == TASK_ZOMBIE)        /* already dead */
+               if (child->exit_state == EXIT_ZOMBIE)   /* already dead */
                        break;
                child->exit_code = SIGKILL;
                wake_up_process(child);
@@ -268,7 +236,7 @@ asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
                struct pt_regs *regs;
 
                ret = -EIO;
-               if ((unsigned long) data > _NSIG)
+               if (!valid_signal(data))
                        break;
                clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
                if ((child->ptrace & PT_DTRACE) == 0) {
@@ -295,13 +263,33 @@ asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
                ret = ptrace_request(child, request, addr, data);
                break;
        }
-out_tsk:
-       put_task_struct(child);
-out:
-       unlock_kernel();
        return ret;
 }
 
+asmlinkage int sh64_ptrace(long request, long pid, long addr, long data)
+{
+       extern void poke_real_address_q(unsigned long long addr, unsigned long long data);
+#define WPC_DBRMODE 0x0d104008
+       static int first_call = 1;
+
+       lock_kernel();
+       if (first_call) {
+               /* Set WPC.DBRMODE to 0.  This makes all debug events get
+                * delivered through RESVEC, i.e. into the handlers in entry.S.
+                * (If the kernel was downloaded using a remote gdb, WPC.DBRMODE
+                * would normally be left set to 1, which makes debug events get
+                * delivered through DBRVEC, i.e. into the remote gdb's
+                * handlers.  This prevents ptrace getting them, and confuses
+                * the remote gdb.) */
+               printk("DBRMODE set to 0 to permit native debugging\n");
+               poke_real_address_q(WPC_DBRMODE, 0);
+               first_call = 0;
+       }
+       unlock_kernel();
+
+       return sys_ptrace(request, pid, addr, data);
+}
+
 asmlinkage void syscall_trace(void)
 {
        struct task_struct *tsk = current;