powerpc/86xx: Renaming following split of GE Fanuc joint venture
[safe/jmp/linux-2.6] / arch / powerpc / kernel / signal_64.c
index 93ebfb6..2fe6fc6 100644 (file)
@@ -74,7 +74,8 @@ static const char fmt64[] = KERN_INFO \
  */
 
 static long setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
-                int signr, sigset_t *set, unsigned long handler)
+                int signr, sigset_t *set, unsigned long handler,
+                int ctx_has_vsx_region)
 {
        /* When CONFIG_ALTIVEC is set, we _always_ setup v_regs even if the
         * process never used altivec yet (MSR_VEC is zero in pt_regs of
@@ -121,8 +122,8 @@ static long setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
         * then out to userspace.  Update v_regs to point after the
         * VMX data.
         */
-       if (current->thread.used_vsr) {
-               flush_vsx_to_thread(current);
+       if (current->thread.used_vsr && ctx_has_vsx_region) {
+               __giveup_vsx(current);
                v_regs += ELF_NVRREG;
                err |= copy_vsx_to_user(v_regs, current);
                /* set MSR_VSX in the MSR value in the frame to
@@ -235,8 +236,6 @@ static long restore_sigcontext(struct pt_regs *regs, sigset_t *set, int sig,
        else
                for (i = 0; i < 32 ; i++)
                        current->thread.fpr[i][TS_VSRLOWOFFSET] = 0;
-
-#else
 #endif
        return err;
 }
@@ -268,6 +267,13 @@ static long setup_trampoline(unsigned int syscall, unsigned int __user *tramp)
 }
 
 /*
+ * Userspace code may pass a ucontext which doesn't include VSX added
+ * at the end.  We need to check for this case.
+ */
+#define UCONTEXTSIZEWITHOUTVSX \
+               (sizeof(struct ucontext) - 32*sizeof(long))
+
+/*
  * Handle {get,set,swap}_context operations
  */
 int sys_swapcontext(struct ucontext __user *old_ctx,
@@ -276,25 +282,42 @@ int sys_swapcontext(struct ucontext __user *old_ctx,
 {
        unsigned char tmp;
        sigset_t set;
+       unsigned long new_msr = 0;
+       int ctx_has_vsx_region = 0;
 
-       /* Context size is for future use. Right now, we only make sure
-        * we are passed something we understand
+       if (new_ctx &&
+           get_user(new_msr, &new_ctx->uc_mcontext.gp_regs[PT_MSR]))
+               return -EFAULT;
+       /*
+        * Check that the context is not smaller than the original
+        * size (with VMX but without VSX)
+        */
+       if (ctx_size < UCONTEXTSIZEWITHOUTVSX)
+               return -EINVAL;
+       /*
+        * If the new context state sets the MSR VSX bits but
+        * it doesn't provide VSX state.
         */
-       if (ctx_size < sizeof(struct ucontext))
+       if ((ctx_size < sizeof(struct ucontext)) &&
+           (new_msr & MSR_VSX))
                return -EINVAL;
+       /* Does the context have enough room to store VSX data? */
+       if (ctx_size >= sizeof(struct ucontext))
+               ctx_has_vsx_region = 1;
 
        if (old_ctx != NULL) {
-               if (!access_ok(VERIFY_WRITE, old_ctx, sizeof(*old_ctx))
-                   || setup_sigcontext(&old_ctx->uc_mcontext, regs, 0, NULL, 0)
+               if (!access_ok(VERIFY_WRITE, old_ctx, ctx_size)
+                   || setup_sigcontext(&old_ctx->uc_mcontext, regs, 0, NULL, 0,
+                                       ctx_has_vsx_region)
                    || __copy_to_user(&old_ctx->uc_sigmask,
                                      &current->blocked, sizeof(sigset_t)))
                        return -EFAULT;
        }
        if (new_ctx == NULL)
                return 0;
-       if (!access_ok(VERIFY_READ, new_ctx, sizeof(*new_ctx))
+       if (!access_ok(VERIFY_READ, new_ctx, ctx_size)
            || __get_user(tmp, (u8 __user *) new_ctx)
-           || __get_user(tmp, (u8 __user *) (new_ctx + 1) - 1))
+           || __get_user(tmp, (u8 __user *) new_ctx + ctx_size - 1))
                return -EFAULT;
 
        /*
@@ -379,7 +402,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
        unsigned long newsp = 0;
        long err = 0;
 
-       frame = get_sigframe(ka, regs, sizeof(*frame));
+       frame = get_sigframe(ka, regs, sizeof(*frame), 0);
        if (unlikely(frame == NULL))
                goto badframe;
 
@@ -397,7 +420,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
                          &frame->uc.uc_stack.ss_flags);
        err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
        err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, signr, NULL,
-                               (unsigned long)ka->sa.sa_handler);
+                               (unsigned long)ka->sa.sa_handler, 1);
        err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
        if (err)
                goto badframe;