Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[cascardo/linux.git] / arch / arm / kernel / signal.c
index c0ba8af..54cdf1a 100644 (file)
@@ -7,12 +7,12 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
-#include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/signal.h>
-#include <linux/ptrace.h>
 #include <linux/personality.h>
+#include <linux/freezer.h>
 
+#include <asm/elf.h>
 #include <asm/cacheflush.h>
 #include <asm/ucontext.h>
 #include <asm/uaccess.h>
@@ -132,18 +132,38 @@ sys_sigaction(int sig, const struct old_sigaction __user *act,
        return ret;
 }
 
-#ifdef CONFIG_IWMMXT
+#ifdef CONFIG_CRUNCH
+static int preserve_crunch_context(struct crunch_sigframe *frame)
+{
+       char kbuf[sizeof(*frame) + 8];
+       struct crunch_sigframe *kframe;
 
-/* iwmmxt_area is 0x98 bytes long, preceeded by 8 bytes of signature */
-#define IWMMXT_STORAGE_SIZE    (0x98 + 8)
-#define IWMMXT_MAGIC0          0x12ef842a
-#define IWMMXT_MAGIC1          0x1c07ca71
+       /* the crunch context must be 64 bit aligned */
+       kframe = (struct crunch_sigframe *)((unsigned long)(kbuf + 8) & ~7);
+       kframe->magic = CRUNCH_MAGIC;
+       kframe->size = CRUNCH_STORAGE_SIZE;
+       crunch_task_copy(current_thread_info(), &kframe->storage);
+       return __copy_to_user(frame, kframe, sizeof(*frame));
+}
 
-struct iwmmxt_sigframe {
-       unsigned long   magic0;
-       unsigned long   magic1;
-       unsigned long   storage[0x98/4];
-};
+static int restore_crunch_context(struct crunch_sigframe *frame)
+{
+       char kbuf[sizeof(*frame) + 8];
+       struct crunch_sigframe *kframe;
+
+       /* the crunch context must be 64 bit aligned */
+       kframe = (struct crunch_sigframe *)((unsigned long)(kbuf + 8) & ~7);
+       if (__copy_from_user(kframe, frame, sizeof(*frame)))
+               return -1;
+       if (kframe->magic != CRUNCH_MAGIC ||
+           kframe->size != CRUNCH_STORAGE_SIZE)
+               return -1;
+       crunch_task_restore(current_thread_info(), &kframe->storage);
+       return 0;
+}
+#endif
+
+#ifdef CONFIG_IWMMXT
 
 static int preserve_iwmmxt_context(struct iwmmxt_sigframe *frame)
 {
@@ -152,8 +172,8 @@ static int preserve_iwmmxt_context(struct iwmmxt_sigframe *frame)
 
        /* the iWMMXt context must be 64 bit aligned */
        kframe = (struct iwmmxt_sigframe *)((unsigned long)(kbuf + 8) & ~7);
-       kframe->magic0 = IWMMXT_MAGIC0;
-       kframe->magic1 = IWMMXT_MAGIC1;
+       kframe->magic = IWMMXT_MAGIC;
+       kframe->size = IWMMXT_STORAGE_SIZE;
        iwmmxt_task_copy(current_thread_info(), &kframe->storage);
        return __copy_to_user(frame, kframe, sizeof(*frame));
 }
@@ -167,8 +187,8 @@ static int restore_iwmmxt_context(struct iwmmxt_sigframe *frame)
        kframe = (struct iwmmxt_sigframe *)((unsigned long)(kbuf + 8) & ~7);
        if (__copy_from_user(kframe, frame, sizeof(*frame)))
                return -1;
-       if (kframe->magic0 != IWMMXT_MAGIC0 ||
-           kframe->magic1 != IWMMXT_MAGIC1)
+       if (kframe->magic != IWMMXT_MAGIC ||
+           kframe->size != IWMMXT_STORAGE_SIZE)
                return -1;
        iwmmxt_task_restore(current_thread_info(), &kframe->storage);
        return 0;
@@ -176,26 +196,12 @@ static int restore_iwmmxt_context(struct iwmmxt_sigframe *frame)
 
 #endif
 
-/*
- * Auxiliary signal frame.  This saves stuff like FP state.
- * The layout of this structure is not part of the user ABI.
- */
-struct aux_sigframe {
-#ifdef CONFIG_IWMMXT
-       struct iwmmxt_sigframe  iwmmxt;
-#endif
-#ifdef CONFIG_VFP
-       union vfp_state         vfp;
-#endif
-};
-
 /*
  * Do a signal return; undo the signal stack.  These are aligned to 64-bit.
  */
 struct sigframe {
        struct ucontext uc;
        unsigned long retcode[2];
-       struct aux_sigframe aux __attribute__((aligned(8)));
 };
 
 struct rt_sigframe {
@@ -205,6 +211,7 @@ struct rt_sigframe {
 
 static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf)
 {
+       struct aux_sigframe __user *aux;
        sigset_t set;
        int err;
 
@@ -237,9 +244,14 @@ static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf)
 
        err |= !valid_user_regs(regs);
 
+       aux = (struct aux_sigframe __user *) sf->uc.uc_regspace;
+#ifdef CONFIG_CRUNCH
+       if (err == 0)
+               err |= restore_crunch_context(&aux->crunch);
+#endif
 #ifdef CONFIG_IWMMXT
        if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
-               err |= restore_iwmmxt_context(&sf->aux.iwmmxt);
+               err |= restore_iwmmxt_context(&aux->iwmmxt);
 #endif
 #ifdef CONFIG_VFP
 //     if (err == 0)
@@ -272,11 +284,7 @@ asmlinkage int sys_sigreturn(struct pt_regs *regs)
        if (restore_sigframe(regs, frame))
                goto badframe;
 
-       /* Send SIGTRAP if we're single-stepping */
-       if (current->ptrace & PT_SINGLESTEP) {
-               ptrace_cancel_bpt(current);
-               send_sig(SIGTRAP, current, 1);
-       }
+       single_step_trap(current);
 
        return regs->ARM_r0;
 
@@ -311,11 +319,7 @@ asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
        if (do_sigaltstack(&frame->sig.uc.uc_stack, NULL, regs->ARM_sp) == -EFAULT)
                goto badframe;
 
-       /* Send SIGTRAP if we're single-stepping */
-       if (current->ptrace & PT_SINGLESTEP) {
-               ptrace_cancel_bpt(current);
-               send_sig(SIGTRAP, current, 1);
-       }
+       single_step_trap(current);
 
        return regs->ARM_r0;
 
@@ -327,6 +331,7 @@ badframe:
 static int
 setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set)
 {
+       struct aux_sigframe __user *aux;
        int err = 0;
 
        __put_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err);
@@ -354,14 +359,20 @@ setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set)
 
        err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set));
 
+       aux = (struct aux_sigframe __user *) sf->uc.uc_regspace;
+#ifdef CONFIG_CRUNCH
+       if (err == 0)
+               err |= preserve_crunch_context(&aux->crunch);
+#endif
 #ifdef CONFIG_IWMMXT
        if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
-               err |= preserve_iwmmxt_context(&sf->aux.iwmmxt);
+               err |= preserve_iwmmxt_context(&aux->iwmmxt);
 #endif
 #ifdef CONFIG_VFP
 //     if (err == 0)
 //             err |= vfp_save_state(&sf->aux.vfp);
 #endif
+       __put_user_error(0, &aux->end_magic, err);
 
        return err;
 }
@@ -624,14 +635,12 @@ static int do_signal(sigset_t *oldset, struct pt_regs *regs, int syscall)
        if (try_to_freeze())
                goto no_signal;
 
-       if (current->ptrace & PT_SINGLESTEP)
-               ptrace_cancel_bpt(current);
+       single_step_clear(current);
 
        signr = get_signal_to_deliver(&info, &ka, regs, NULL);
        if (signr > 0) {
                handle_signal(signr, &ka, &info, oldset, regs, syscall);
-               if (current->ptrace & PT_SINGLESTEP)
-                       ptrace_set_bpt(current);
+               single_step_set(current);
                return 1;
        }
 
@@ -642,17 +651,33 @@ static int do_signal(sigset_t *oldset, struct pt_regs *regs, int syscall)
        if (syscall) {
                if (regs->ARM_r0 == -ERESTART_RESTARTBLOCK) {
                        if (thumb_mode(regs)) {
-                               regs->ARM_r7 = __NR_restart_syscall;
+                               regs->ARM_r7 = __NR_restart_syscall - __NR_SYSCALL_BASE;
                                regs->ARM_pc -= 2;
                        } else {
+#if defined(CONFIG_AEABI) && !defined(CONFIG_OABI_COMPAT)
+                               regs->ARM_r7 = __NR_restart_syscall;
+                               regs->ARM_pc -= 4;
+#else
                                u32 __user *usp;
+                               u32 swival = __NR_restart_syscall;
 
                                regs->ARM_sp -= 12;
                                usp = (u32 __user *)regs->ARM_sp;
 
+                               /*
+                                * Either we supports OABI only, or we have
+                                * EABI with the OABI compat layer enabled.
+                                * In the later case we don't know if user
+                                * space is EABI or not, and if not we must
+                                * not clobber r7.  Always using the OABI
+                                * syscall solves that issue and works for
+                                * all those cases.
+                                */
+                               swival = swival - __NR_SYSCALL_BASE + __NR_OABI_SYSCALL_BASE;
+
                                put_user(regs->ARM_pc, &usp[0]);
                                /* swi __NR_restart_syscall */
-                               put_user(0xef000000 | __NR_restart_syscall, &usp[1]);
+                               put_user(0xef000000 | swival, &usp[1]);
                                /* ldr  pc, [sp], #12 */
                                put_user(0xe49df00c, &usp[2]);
 
@@ -660,6 +685,7 @@ static int do_signal(sigset_t *oldset, struct pt_regs *regs, int syscall)
                                                   (unsigned long)(usp + 3));
 
                                regs->ARM_pc = regs->ARM_sp + 4;
+#endif
                        }
                }
                if (regs->ARM_r0 == -ERESTARTNOHAND ||
@@ -668,8 +694,7 @@ static int do_signal(sigset_t *oldset, struct pt_regs *regs, int syscall)
                        restart_syscall(regs);
                }
        }
-       if (current->ptrace & PT_SINGLESTEP)
-               ptrace_set_bpt(current);
+       single_step_set(current);
        return 0;
 }