sh: Add ftrace syscall tracing support
[safe/jmp/linux-2.6] / arch / sh / kernel / ptrace_32.c
index 0f44f2b..c198ece 100644 (file)
@@ -32,6 +32,9 @@
 #include <asm/processor.h>
 #include <asm/mmu_context.h>
 #include <asm/syscalls.h>
+#include <asm/fpu.h>
+
+#include <trace/syscall.h>
 
 /*
  * This routine will get a word off of the process kernel stack.
@@ -145,13 +148,62 @@ static int genregs_set(struct task_struct *target,
        return ret;
 }
 
+#ifdef CONFIG_SH_FPU
+int fpregs_get(struct task_struct *target,
+              const struct user_regset *regset,
+              unsigned int pos, unsigned int count,
+              void *kbuf, void __user *ubuf)
+{
+       int ret;
+
+       ret = init_fpu(target);
+       if (ret)
+               return ret;
+
+       if ((boot_cpu_data.flags & CPU_HAS_FPU))
+               return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+                                          &target->thread.fpu.hard, 0, -1);
+
+       return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+                                  &target->thread.fpu.soft, 0, -1);
+}
+
+static int fpregs_set(struct task_struct *target,
+                      const struct user_regset *regset,
+                      unsigned int pos, unsigned int count,
+                      const void *kbuf, const void __user *ubuf)
+{
+       int ret;
+
+       ret = init_fpu(target);
+       if (ret)
+               return ret;
+
+       set_stopped_child_used_math(target);
+
+       if ((boot_cpu_data.flags & CPU_HAS_FPU))
+               return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
+                                         &target->thread.fpu.hard, 0, -1);
+
+       return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
+                                 &target->thread.fpu.soft, 0, -1);
+}
+
+static int fpregs_active(struct task_struct *target,
+                        const struct user_regset *regset)
+{
+       return tsk_used_math(target) ? regset->n : 0;
+}
+#endif
+
 #ifdef CONFIG_SH_DSP
 static int dspregs_get(struct task_struct *target,
                       const struct user_regset *regset,
                       unsigned int pos, unsigned int count,
                       void *kbuf, void __user *ubuf)
 {
-       const struct pt_dspregs *regs = task_pt_dspregs(target);
+       const struct pt_dspregs *regs =
+               (struct pt_dspregs *)&target->thread.dsp_status.dsp_regs;
        int ret;
 
        ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, regs,
@@ -168,7 +220,8 @@ static int dspregs_set(struct task_struct *target,
                       unsigned int pos, unsigned int count,
                       const void *kbuf, const void __user *ubuf)
 {
-       struct pt_dspregs *regs = task_pt_dspregs(target);
+       struct pt_dspregs *regs =
+               (struct pt_dspregs *)&target->thread.dsp_status.dsp_regs;
        int ret;
 
        ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, regs,
@@ -194,6 +247,9 @@ static int dspregs_active(struct task_struct *target,
  */
 enum sh_regset {
        REGSET_GENERAL,
+#ifdef CONFIG_SH_FPU
+       REGSET_FPU,
+#endif
 #ifdef CONFIG_SH_DSP
        REGSET_DSP,
 #endif
@@ -214,6 +270,18 @@ static const struct user_regset sh_regsets[] = {
                .set            = genregs_set,
        },
 
+#ifdef CONFIG_SH_FPU
+       [REGSET_FPU] = {
+               .core_note_type = NT_PRFPREG,
+               .n              = sizeof(struct user_fpu_struct) / sizeof(long),
+               .size           = sizeof(long),
+               .align          = sizeof(long),
+               .get            = fpregs_get,
+               .set            = fpregs_set,
+               .active         = fpregs_active,
+       },
+#endif
+
 #ifdef CONFIG_SH_DSP
        [REGSET_DSP] = {
                .n              = sizeof(struct pt_dspregs) / sizeof(long),
@@ -268,6 +336,14 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                                        [(addr - (long)&dummy->fpu) >> 2];
                } else if (addr == (long) &dummy->u_fpvalid)
                        tmp = !!tsk_used_math(child);
+               else if (addr == PT_TEXT_ADDR)
+                       tmp = child->mm->start_code;
+               else if (addr == PT_DATA_ADDR)
+                       tmp = child->mm->start_data;
+               else if (addr == PT_TEXT_END_ADDR)
+                       tmp = child->mm->end_code;
+               else if (addr == PT_TEXT_LEN)
+                       tmp = child->mm->end_code - child->mm->start_code;
                else
                        tmp = 0;
                ret = put_user(tmp, datap);
@@ -304,6 +380,18 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                                             REGSET_GENERAL,
                                             0, sizeof(struct pt_regs),
                                             (const void __user *)data);
+#ifdef CONFIG_SH_FPU
+       case PTRACE_GETFPREGS:
+               return copy_regset_to_user(child, &user_sh_native_view,
+                                          REGSET_FPU,
+                                          0, sizeof(struct user_fpu_struct),
+                                          (void __user *)data);
+       case PTRACE_SETFPREGS:
+               return copy_regset_from_user(child, &user_sh_native_view,
+                                            REGSET_FPU,
+                                            0, sizeof(struct user_fpu_struct),
+                                            (const void __user *)data);
+#endif
 #ifdef CONFIG_SH_DSP
        case PTRACE_GETDSPREGS:
                return copy_regset_to_user(child, &user_sh_native_view,
@@ -373,6 +461,9 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
                 */
                ret = -1L;
 
+       if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
+               ftrace_syscall_enter(regs);
+
        if (unlikely(current->audit_context))
                audit_syscall_entry(audit_arch(), regs->regs[3],
                                    regs->regs[4], regs->regs[5],
@@ -389,6 +480,9 @@ asmlinkage void do_syscall_trace_leave(struct pt_regs *regs)
                audit_syscall_exit(AUDITSC_RESULT(regs->regs[0]),
                                   regs->regs[0]);
 
+       if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
+               ftrace_syscall_exit(regs);
+
        step = test_thread_flag(TIF_SINGLESTEP);
        if (step || test_thread_flag(TIF_SYSCALL_TRACE))
                tracehook_report_syscall_exit(regs, step);