sysctl: remove "struct file *" argument of ->proc_handler
[safe/jmp/linux-2.6] / arch / x86 / kernel / ptrace.c
index adbb243..7b058a2 100644 (file)
@@ -21,7 +21,6 @@
 #include <linux/audit.h>
 #include <linux/seccomp.h>
 #include <linux/signal.h>
-#include <linux/ftrace.h>
 #include <linux/workqueue.h>
 
 #include <asm/uaccess.h>
@@ -38,6 +37,9 @@
 
 #include "tls.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
+
 enum x86_regset {
        REGSET_GENERAL,
        REGSET_FP,
@@ -323,16 +325,6 @@ static int putreg(struct task_struct *child,
                return set_flags(child, value);
 
 #ifdef CONFIG_X86_64
-       /*
-        * Orig_ax is really just a flag with small positive and
-        * negative values, so make sure to always sign-extend it
-        * from 32 bits so that it works correctly regardless of
-        * whether we come from a 32-bit environment or not.
-        */
-       case offsetof(struct user_regs_struct, orig_ax):
-               value = (long) (s32) value;
-               break;
-
        case offsetof(struct user_regs_struct,fs_base):
                if (value >= TASK_SIZE_OF(child))
                        return -EIO;
@@ -616,17 +608,28 @@ struct bts_context {
        struct work_struct      work;
 };
 
-static inline void alloc_bts_buffer(struct bts_context *context,
-                                   unsigned int size)
+static int alloc_bts_buffer(struct bts_context *context, unsigned int size)
 {
-       void *buffer;
+       void *buffer = NULL;
+       int err = -ENOMEM;
 
-       buffer = alloc_locked_buffer(size);
-       if (buffer) {
-               context->buffer = buffer;
-               context->size = size;
-               context->mm = get_task_mm(current);
-       }
+       err = account_locked_memory(current->mm, current->signal->rlim, size);
+       if (err < 0)
+               return err;
+
+       buffer = kzalloc(size, GFP_KERNEL);
+       if (!buffer)
+               goto out_refund;
+
+       context->buffer = buffer;
+       context->size = size;
+       context->mm = get_task_mm(current);
+
+       return 0;
+
+ out_refund:
+       refund_locked_memory(current->mm, size);
+       return err;
 }
 
 static inline void free_bts_buffer(struct bts_context *context)
@@ -637,7 +640,7 @@ static inline void free_bts_buffer(struct bts_context *context)
        kfree(context->buffer);
        context->buffer = NULL;
 
-       refund_locked_buffer_memory(context->mm, context->size);
+       refund_locked_memory(context->mm, context->size);
        context->size = 0;
 
        mmput(context->mm);
@@ -785,13 +788,15 @@ static int ptrace_bts_config(struct task_struct *child,
        context->tracer = NULL;
 
        if ((cfg.flags & PTRACE_BTS_O_ALLOC) && (cfg.size != context->size)) {
+               int err;
+
                free_bts_buffer(context);
                if (!cfg.size)
                        return 0;
 
-               alloc_bts_buffer(context, cfg.size);
-               if (!context->buffer)
-                       return -ENOMEM;
+               err = alloc_bts_buffer(context, cfg.size);
+               if (err < 0)
+                       return err;
        }
 
        if (cfg.flags & PTRACE_BTS_O_TRACE)
@@ -887,37 +892,19 @@ static int ptrace_bts_size(struct task_struct *child)
        return (trace->ds.top - trace->ds.begin) / trace->ds.size;
 }
 
-static inline void ptrace_bts_fork(struct task_struct *tsk)
-{
-       tsk->bts = NULL;
-}
-
 /*
  * Called from __ptrace_unlink() after the child has been moved back
  * to its original parent.
  */
-static inline void ptrace_bts_untrace(struct task_struct *child)
+void ptrace_bts_untrace(struct task_struct *child)
 {
        if (unlikely(child->bts)) {
                free_bts_context(child->bts);
                child->bts = NULL;
        }
 }
-#else
-static inline void ptrace_bts_fork(struct task_struct *tsk) {}
-static inline void ptrace_bts_untrace(struct task_struct *child) {}
 #endif /* CONFIG_X86_PTRACE_BTS */
 
-void x86_ptrace_fork(struct task_struct *child, unsigned long clone_flags)
-{
-       ptrace_bts_fork(child);
-}
-
-void x86_ptrace_untrace(struct task_struct *child)
-{
-       ptrace_bts_untrace(child);
-}
-
 /*
  * Called by kernel/ptrace.c when detaching..
  *
@@ -1129,10 +1116,15 @@ static int putreg32(struct task_struct *child, unsigned regno, u32 value)
 
        case offsetof(struct user32, regs.orig_eax):
                /*
-                * Sign-extend the value so that orig_eax = -1
-                * causes (long)orig_ax < 0 tests to fire correctly.
+                * A 32-bit debugger setting orig_eax means to restore
+                * the state of the task restarting a 32-bit syscall.
+                * Make sure we interpret the -ERESTART* codes correctly
+                * in case the task is not actually still sitting at the
+                * exit from a 32-bit syscall with TS_COMPAT still set.
                 */
-               regs->orig_ax = (long) (s32) value;
+               regs->orig_ax = value;
+               if (syscall_get_nr(child, regs) >= 0)
+                       task_thread_info(child)->status |= TS_COMPAT;
                break;
 
        case offsetof(struct user32, regs.eflags):
@@ -1501,8 +1493,8 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs)
            tracehook_report_syscall_entry(regs))
                ret = -1L;
 
-       if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
-               ftrace_syscall_enter(regs);
+       if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
+               trace_sys_enter(regs, regs->orig_ax);
 
        if (unlikely(current->audit_context)) {
                if (IS_IA32)
@@ -1527,8 +1519,8 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs)
        if (unlikely(current->audit_context))
                audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
 
-       if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
-               ftrace_syscall_exit(regs);
+       if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
+               trace_sys_exit(regs, regs->ax);
 
        if (test_thread_flag(TIF_SYSCALL_TRACE))
                tracehook_report_syscall_exit(regs, 0);