Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[powerpc.git] / arch / arm / kernel / signal.c
index e5802bf..f38a60a 100644 (file)
@@ -7,11 +7,11 @@
  * 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/cacheflush.h>
 #include <asm/ucontext.h>
@@ -132,6 +132,37 @@ sys_sigaction(int sig, const struct old_sigaction __user *act,
        return ret;
 }
 
+#ifdef CONFIG_CRUNCH
+static int preserve_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);
+       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));
+}
+
+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)
@@ -214,6 +245,10 @@ 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(&aux->iwmmxt);
@@ -333,6 +368,10 @@ 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(&aux->iwmmxt);
@@ -622,17 +661,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]);
 
@@ -640,6 +695,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 ||