vserver 2.0 rc7
[linux-2.6.git] / arch / ppc64 / kernel / signal.c
index 8323d73..bf78227 100644 (file)
@@ -26,7 +26,9 @@
 #include <linux/unistd.h>
 #include <linux/stddef.h>
 #include <linux/elf.h>
-#include <asm/ppc32.h>
+#include <linux/ptrace.h>
+#include <linux/module.h>
+
 #include <asm/sigcontext.h>
 #include <asm/ucontext.h>
 #include <asm/uaccess.h>
 #include <asm/ppcdebug.h>
 #include <asm/unistd.h>
 #include <asm/cacheflush.h>
+#include <asm/vdso.h>
 
 #define DEBUG_SIG 0
 
 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
 
-#ifndef MIN
-#define MIN(a,b) (((a) < (b)) ? (a) : (b))
-#endif
-
-#define GP_REGS_SIZE   MIN(sizeof(elf_gregset_t), sizeof(struct pt_regs))
+#define GP_REGS_SIZE   min(sizeof(elf_gregset_t), sizeof(struct pt_regs))
 #define FP_REGS_SIZE   sizeof(elf_fpregset_t)
 
 #define TRAMP_TRACEBACK        3
@@ -67,7 +66,7 @@ struct rt_sigframe {
        struct siginfo info;
        /* 64 bit ABI allows for 288 bytes below sp before decrementing it. */
        char abigap[288];
-};
+} __attribute__ ((aligned (16)));
 
 
 /*
@@ -99,7 +98,7 @@ long sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize, int p3, int
                current->state = TASK_INTERRUPTIBLE;
                schedule();
                if (do_signal(&saveset, regs))
-                       return regs->gpr[3];
+                       return 0;
        }
 }
 
@@ -127,7 +126,7 @@ static long setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
         * v_regs pointer or not
         */
 #ifdef CONFIG_ALTIVEC
-       elf_vrreg_t __user *v_regs = (elf_vrreg_t __user *)(((unsigned long)sc->vmx_reserve) & ~0xful);
+       elf_vrreg_t __user *v_regs = (elf_vrreg_t __user *)(((unsigned long)sc->vmx_reserve + 15) & ~0xful);
 #endif
        long err = 0;
 
@@ -178,8 +177,11 @@ static long restore_sigcontext(struct pt_regs *regs, sigset_t *set, int sig,
        elf_vrreg_t __user *v_regs;
 #endif
        unsigned long err = 0;
-       unsigned long save_r13;
+       unsigned long save_r13 = 0;
        elf_greg_t *gregs = (elf_greg_t *)regs;
+#ifdef CONFIG_ALTIVEC
+       unsigned long msr;
+#endif
        int i;
 
        /* If this is not a signal return, we preserve the TLS in r13 */
@@ -205,13 +207,15 @@ static long restore_sigcontext(struct pt_regs *regs, sigset_t *set, int sig,
 
 #ifdef CONFIG_ALTIVEC
        err |= __get_user(v_regs, &sc->v_regs);
+       err |= __get_user(msr, &sc->gp_regs[PT_MSR]);
        if (err)
                return err;
        /* Copy 33 vec registers (vr0..31 and vscr) from the stack */
-       if (v_regs != 0 && (regs->msr & MSR_VEC) != 0)
-               err |= __copy_from_user(current->thread.vr, v_regs, 33 * sizeof(vector128));
+       if (v_regs != 0 && (msr & MSR_VEC) != 0)
+               err |= __copy_from_user(current->thread.vr, v_regs,
+                                       33 * sizeof(vector128));
        else if (current->thread.used_vr)
-               memset(&current->thread.vr, 0, 33);
+               memset(current->thread.vr, 0, 33 * sizeof(vector128));
        /* Always get VRSAVE back */
        if (v_regs != 0)
                err |= __get_user(current->thread.vrsave, (u32 __user *)&v_regs[33]);
@@ -219,6 +223,14 @@ static long restore_sigcontext(struct pt_regs *regs, sigset_t *set, int sig,
                current->thread.vrsave = 0;
 #endif /* CONFIG_ALTIVEC */
 
+#ifndef CONFIG_SMP
+       preempt_disable();
+       if (last_task_used_math == current)
+               last_task_used_math = NULL;
+       if (last_task_used_altivec == current)
+               last_task_used_altivec = NULL;
+       preempt_enable();
+#endif
        /* Force reload of FP/VEC */
        regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1 | MSR_VEC);
 
@@ -241,7 +253,7 @@ static inline void __user * get_sigframe(struct k_sigaction *ka, struct pt_regs
                        newsp = (current->sas_ss_sp + current->sas_ss_size);
        }
 
-        return (void __user *)((newsp - frame_size) & -8ul);
+        return (void __user *)((newsp - frame_size) & -16ul);
 }
 
 /*
@@ -300,7 +312,7 @@ int sys_swapcontext(struct ucontext __user *old_ctx,
                return -EINVAL;
 
        if (old_ctx != NULL) {
-               if (verify_area(VERIFY_WRITE, old_ctx, sizeof(*old_ctx))
+               if (!access_ok(VERIFY_WRITE, old_ctx, sizeof(*old_ctx))
                    || setup_sigcontext(&old_ctx->uc_mcontext, regs, 0, NULL, 0)
                    || __copy_to_user(&old_ctx->uc_sigmask,
                                      &current->blocked, sizeof(sigset_t)))
@@ -308,7 +320,7 @@ int sys_swapcontext(struct ucontext __user *old_ctx,
        }
        if (new_ctx == NULL)
                return 0;
-       if (verify_area(VERIFY_READ, new_ctx, sizeof(*new_ctx))
+       if (!access_ok(VERIFY_READ, new_ctx, sizeof(*new_ctx))
            || __get_user(tmp, (u8 __user *) new_ctx)
            || __get_user(tmp, (u8 __user *) (new_ctx + 1) - 1))
                return -EFAULT;
@@ -318,7 +330,7 @@ int sys_swapcontext(struct ucontext __user *old_ctx,
         * image of the user's registers, we can't just return -EFAULT
         * because the user's registers will be corrupted.  For instance
         * the NIP value may have been updated but not some of the
-        * other registers.  Given that we have done the verify_area
+        * other registers.  Given that we have done the access_ok
         * and successfully read the first and last bytes of the region
         * above, this should only happen in an out-of-memory situation
         * or if another thread unmaps the region containing the context.
@@ -350,7 +362,7 @@ int sys_rt_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5,
        /* Always make any pending restarted system calls return -EINTR */
        current_thread_info()->restart_block.fn = do_no_restart_syscall;
 
-       if (verify_area(VERIFY_READ, uc, sizeof(*uc)))
+       if (!access_ok(VERIFY_READ, uc, sizeof(*uc)))
                goto badframe;
 
        if (__copy_from_user(&set, &uc->uc_sigmask, sizeof(set)))
@@ -371,10 +383,11 @@ badframe:
        printk("badframe in sys_rt_sigreturn, regs=%p uc=%p &uc->uc_mcontext=%p\n",
               regs, uc, &uc->uc_mcontext);
 #endif
-       do_exit(SIGSEGV);
+       force_sig(SIGSEGV, current);
+       return 0;
 }
 
-static void setup_rt_frame(int signr, struct k_sigaction *ka, siginfo_t *info,
+static int setup_rt_frame(int signr, struct k_sigaction *ka, siginfo_t *info,
                sigset_t *set, struct pt_regs *regs)
 {
        /* Handler is *really* a pointer to the function descriptor for
@@ -389,7 +402,7 @@ static void setup_rt_frame(int signr, struct k_sigaction *ka, siginfo_t *info,
 
        frame = get_sigframe(ka, regs, sizeof(*frame));
 
-       if (verify_area(VERIFY_WRITE, frame, sizeof(*frame)))
+       if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
                goto badframe;
 
        err |= __put_user(&frame->info, &frame->pinfo);
@@ -412,19 +425,22 @@ static void setup_rt_frame(int signr, struct k_sigaction *ka, siginfo_t *info,
                goto badframe;
 
        /* Set up to return from userspace. */
-       err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
-       if (err)
-               goto badframe;
-
+       if (vdso64_rt_sigtramp && current->thread.vdso_base) {
+               regs->link = current->thread.vdso_base + vdso64_rt_sigtramp;
+       } else {
+               err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
+               if (err)
+                       goto badframe;
+               regs->link = (unsigned long) &frame->tramp[0];
+       }
        funct_desc_ptr = (func_descr_t __user *) ka->sa.sa_handler;
 
        /* Allocate a dummy caller frame for the signal handler. */
        newsp = (unsigned long)frame - __SIGNAL_FRAMESIZE;
-       err |= put_user(0, (unsigned long __user *)newsp);
+       err |= put_user(regs->gpr[1], (unsigned long __user *)newsp);
 
        /* Set up "regs" so we "return" to the signal handler. */
        err |= get_user(regs->nip, &funct_desc_ptr->entry);
-       regs->link = (unsigned long) &frame->tramp[0];
        regs->gpr[1] = newsp;
        err |= get_user(regs->gpr[2], &funct_desc_ptr->toc);
        regs->gpr[3] = signr;
@@ -439,37 +455,41 @@ static void setup_rt_frame(int signr, struct k_sigaction *ka, siginfo_t *info,
        if (err)
                goto badframe;
 
-       return;
+       if (test_thread_flag(TIF_SINGLESTEP))
+               ptrace_notify(SIGTRAP);
+
+       return 1;
 
 badframe:
 #if DEBUG_SIG
        printk("badframe in setup_rt_frame, regs=%p frame=%p newsp=%lx\n",
               regs, frame, newsp);
 #endif
-       do_exit(SIGSEGV);
+       force_sigsegv(signr, current);
+       return 0;
 }
 
 
 /*
  * OK, we're invoking a handler
  */
-static void handle_signal(unsigned long sig, struct k_sigaction *ka,
-                         siginfo_t *info, sigset_t *oldset, struct pt_regs *regs)
+static int handle_signal(unsigned long sig, struct k_sigaction *ka,
+                        siginfo_t *info, sigset_t *oldset, struct pt_regs *regs)
 {
-       /* Set up Signal Frame */
-       setup_rt_frame(sig, ka, info, oldset, regs);
+       int ret;
 
-       if (ka->sa.sa_flags & SA_ONESHOT)
-               ka->sa.sa_handler = SIG_DFL;
+       /* Set up Signal Frame */
+       ret = setup_rt_frame(sig, ka, info, oldset, regs);
 
-       if (!(ka->sa.sa_flags & SA_NODEFER)) {
+       if (ret && !(ka->sa.sa_flags & SA_NODEFER)) {
                spin_lock_irq(&current->sighand->siglock);
-               sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
+               sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
                sigaddset(&current->blocked,sig);
                recalc_sigpending();
                spin_unlock_irq(&current->sighand->siglock);
        }
-       return;
+
+       return ret;
 }
 
 static inline void syscall_restart(struct pt_regs *regs, struct k_sigaction *ka)
@@ -512,6 +532,7 @@ int do_signal(sigset_t *oldset, struct pt_regs *regs)
 {
        siginfo_t info;
        int signr;
+       struct k_sigaction ka;
 
        /*
         * If the current thread is 32 bit - invoke the
@@ -523,15 +544,12 @@ int do_signal(sigset_t *oldset, struct pt_regs *regs)
        if (!oldset)
                oldset = &current->blocked;
 
-       signr = get_signal_to_deliver(&info, regs, NULL);
+       signr = get_signal_to_deliver(&info, &ka, regs, NULL);
        if (signr > 0) {
-               struct k_sigaction *ka = &current->sighand->action[signr-1];
-
                /* Whee!  Actually deliver the signal.  */
                if (TRAP(regs) == 0x0C00)
-                       syscall_restart(regs, ka);
-               handle_signal(signr, ka, &info, oldset, regs);
-               return 1;
+                       syscall_restart(regs, &ka);
+               return handle_signal(signr, &ka, &info, oldset, regs);
        }
 
        if (TRAP(regs) == 0x0C00) {     /* System Call! */
@@ -550,6 +568,4 @@ int do_signal(sigset_t *oldset, struct pt_regs *regs)
 
        return 0;
 }
-
-
-
+EXPORT_SYMBOL(do_signal);