fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / arch / parisc / kernel / signal.c
index b220bb2..ee6653e 100644 (file)
 #include <linux/stddef.h>
 #include <linux/compat.h>
 #include <linux/elf.h>
-#include <linux/personality.h>
 #include <asm/ucontext.h>
 #include <asm/rt_sigframe.h>
 #include <asm/uaccess.h>
 #include <asm/pgalloc.h>
 #include <asm/cacheflush.h>
+#include <asm/asm-offsets.h>
 
 #ifdef CONFIG_COMPAT
 #include <linux/compat.h>
@@ -69,17 +69,17 @@ int do_signal(sigset_t *oldset, struct pt_regs *regs, int in_syscall);
 #endif
 
 asmlinkage int
-sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize, struct pt_regs *regs)
+sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize, struct pt_regs *regs)
 {
        sigset_t saveset, newset;
 #ifdef __LP64__
        compat_sigset_t newset32;
 
-       if(personality(current->personality) == PER_LINUX32){
+       if (is_compat_task()) {
                /* XXX: Don't preclude handling different sized sigset_t's.  */
                if (sigsetsize != sizeof(compat_sigset_t))
                        return -EINVAL;
-               if (copy_from_user(&newset32, (compat_sigset_t *)unewset, sizeof(newset32)))
+               if (copy_from_user(&newset32, (compat_sigset_t __user *)unewset, sizeof(newset32)))
                        return -EFAULT;
                sigset_32to64(&newset,&newset32);
                
@@ -125,7 +125,7 @@ sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize, struct pt_regs *regs)
 #define INSN_DIE_HORRIBLY 0x68000ccc /* stw %r0,0x666(%sr0,%r0) */
 
 static long
-restore_sigcontext(struct sigcontext *sc, struct pt_regs *regs)
+restore_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs)
 {
        long err = 0;
 
@@ -143,29 +143,29 @@ restore_sigcontext(struct sigcontext *sc, struct pt_regs *regs)
 void
 sys_rt_sigreturn(struct pt_regs *regs, int in_syscall)
 {
-       struct rt_sigframe *frame;
+       struct rt_sigframe __user *frame;
        struct siginfo si;
        sigset_t set;
        unsigned long usp = (regs->gr[30] & ~(0x01UL));
        unsigned long sigframe_size = PARISC_RT_SIGFRAME_SIZE;
 #ifdef __LP64__
        compat_sigset_t compat_set;
-       struct compat_rt_sigframe * compat_frame;
+       struct compat_rt_sigframe __user * compat_frame;
        
-       if(personality(current->personality) == PER_LINUX32)
+       if (is_compat_task())
                sigframe_size = PARISC_RT_SIGFRAME_SIZE32;
 #endif
 
 
        /* Unwind the user stack to get the rt_sigframe structure. */
-       frame = (struct rt_sigframe *)
+       frame = (struct rt_sigframe __user *)
                (usp - sigframe_size);
        DBG(2,"sys_rt_sigreturn: frame is %p\n", frame);
 
 #ifdef __LP64__
-       compat_frame = (struct compat_rt_sigframe *)frame;
+       compat_frame = (struct compat_rt_sigframe __user *)frame;
        
-       if(personality(current->personality) == PER_LINUX32){
+       if (is_compat_task()) {
                DBG(2,"sys_rt_sigreturn: ELF32 process.\n");
                if (__copy_from_user(&compat_set, &compat_frame->uc.uc_sigmask, sizeof(compat_set)))
                        goto give_sigsegv;
@@ -185,7 +185,7 @@ sys_rt_sigreturn(struct pt_regs *regs, int in_syscall)
 
        /* Good thing we saved the old gr[30], eh? */
 #ifdef __LP64__
-       if(personality(current->personality) == PER_LINUX32){
+       if (is_compat_task()) {
                DBG(1,"sys_rt_sigreturn: compat_frame->uc.uc_mcontext 0x%p\n",
                                &compat_frame->uc.uc_mcontext);
 // FIXME: Load upper half from register file
@@ -238,7 +238,7 @@ give_sigsegv:
  * Set up a signal frame.
  */
 
-static inline void *
+static inline void __user *
 get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
 {
        /*FIXME: ELF32 vs. ELF64 has different frame_size, but since we
@@ -247,15 +247,15 @@ get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
        DBG(1,"get_sigframe: ka = %#lx, sp = %#lx, frame_size = %#lx\n",
                        (unsigned long)ka, sp, frame_size);
        
-       if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! on_sig_stack(sp))
+       if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! sas_ss_flags(sp))
                sp = current->sas_ss_sp; /* Stacks grow up! */
 
        DBG(1,"get_sigframe: Returning sp = %#lx\n", (unsigned long)sp);
-       return (void *) sp; /* Stacks grow up.  Fun. */
+       return (void __user *) sp; /* Stacks grow up.  Fun. */
 }
 
 static long
-setup_sigcontext(struct sigcontext *sc, struct pt_regs *regs, int in_syscall)
+setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, int in_syscall)
                 
 {
        unsigned long flags = 0;
@@ -292,14 +292,13 @@ static long
 setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
               sigset_t *set, struct pt_regs *regs, int in_syscall)
 {
-       struct rt_sigframe *frame;
+       struct rt_sigframe __user *frame;
        unsigned long rp, usp;
        unsigned long haddr, sigframe_size;
-       struct siginfo si;
        int err = 0;
 #ifdef __LP64__
        compat_int_t compat_val;
-       struct compat_rt_sigframe * compat_frame;
+       struct compat_rt_sigframe __user * compat_frame;
        compat_sigset_t compat_set;
 #endif
        
@@ -313,11 +312,11 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
        
 #ifdef __LP64__
 
-       compat_frame = (struct compat_rt_sigframe *)frame;
+       compat_frame = (struct compat_rt_sigframe __user *)frame;
        
-       if(personality(current->personality) == PER_LINUX32) {
+       if (is_compat_task()) {
                DBG(1,"setup_rt_frame: frame->info = 0x%p\n", &compat_frame->info);
-               err |= compat_copy_siginfo_to_user(&compat_frame->info, info);
+               err |= copy_siginfo_to_user32(&compat_frame->info, info);
                DBG(1,"SETUP_RT_FRAME: 1\n");
                compat_val = (compat_int_t)current->sas_ss_sp;
                err |= __put_user(compat_val, &compat_frame->uc.uc_stack.ss_sp);
@@ -392,11 +391,11 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
        haddr = A(ka->sa.sa_handler);
        /* The sa_handler may be a pointer to a function descriptor */
 #ifdef __LP64__
-       if(personality(current->personality) == PER_LINUX32) {
+       if (is_compat_task()) {
 #endif
                if (haddr & PA_PLABEL_FDESC) {
                        Elf32_Fdesc fdesc;
-                       Elf32_Fdesc *ufdesc = (Elf32_Fdesc *)A(haddr & ~3);
+                       Elf32_Fdesc __user *ufdesc = (Elf32_Fdesc __user *)A(haddr & ~3);
 
                        err = __copy_from_user(&fdesc, ufdesc, sizeof(fdesc));
 
@@ -409,7 +408,7 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
 #ifdef __LP64__
        } else {
                Elf64_Fdesc fdesc;
-               Elf64_Fdesc *ufdesc = (Elf64_Fdesc *)A(haddr & ~3);
+               Elf64_Fdesc __user *ufdesc = (Elf64_Fdesc __user *)A(haddr & ~3);
                
                err = __copy_from_user(&fdesc, ufdesc, sizeof(fdesc));
                
@@ -427,22 +426,34 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
         */
        sigframe_size = PARISC_RT_SIGFRAME_SIZE;
 #ifdef __LP64__
-       if(personality(current->personality) == PER_LINUX32)
+       if (is_compat_task())
                sigframe_size = PARISC_RT_SIGFRAME_SIZE32;
 #endif
        if (in_syscall) {
                regs->gr[31] = haddr;
 #ifdef __LP64__
-               if(personality(current->personality) == PER_LINUX)
+               if (!test_thread_flag(TIF_32BIT))
                        sigframe_size |= 1;
 #endif
        } else {
                unsigned long psw = USER_PSW;
 #ifdef __LP64__
-               if(personality(current->personality) == PER_LINUX)
+               if (!test_thread_flag(TIF_32BIT))
                        psw |= PSW_W;
 #endif
 
+               /* If we are singlestepping, arrange a trap to be delivered
+                  when we return to userspace. Note the semantics -- we
+                  should trap before the first insn in the handler is
+                  executed. Ref:
+                       http://sources.redhat.com/ml/gdb/2004-11/msg00245.html
+                */
+               if (pa_psw(current)->r) {
+                       pa_psw(current)->r = 0;
+                       psw |= PSW_R;
+                       mtctl(-1, 0);
+               }
+
                regs->gr[0] = psw;
                regs->iaoq[0] = haddr | 3;
                regs->iaoq[1] = regs->iaoq[0] + 4;
@@ -452,7 +463,7 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
        regs->gr[26] = sig;               /* signal number */
        
 #ifdef __LP64__
-       if(personality(current->personality) == PER_LINUX32){
+       if (is_compat_task()) {
                regs->gr[25] = A(&compat_frame->info); /* siginfo pointer */
                regs->gr[24] = A(&compat_frame->uc);   /* ucontext pointer */
        } else
@@ -477,15 +488,7 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
 
 give_sigsegv:
        DBG(1,"setup_rt_frame: sending SIGSEGV\n");
-       if (sig == SIGSEGV)
-               ka->sa.sa_handler = SIG_DFL;
-       si.si_signo = SIGSEGV;
-       si.si_errno = 0;
-       si.si_code = SI_KERNEL;
-       si.si_pid = current->pid;
-       si.si_uid = current->uid;
-       si.si_addr = frame;
-       force_sig_info(SIGSEGV, &si, current);
+       force_sigsegv(sig, current);
        return 0;
 }
 
@@ -494,11 +497,9 @@ give_sigsegv:
  */    
 
 static long
-handle_signal(unsigned long sig, siginfo_t *info, sigset_t *oldset,
-             struct pt_regs *regs, int in_syscall)
+handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
+               sigset_t *oldset, struct pt_regs *regs, int in_syscall)
 {
-       struct k_sigaction *ka = &current->sighand->action[sig-1];
-
        DBG(1,"handle_signal: sig=%ld, ka=%p, info=%p, oldset=%p, regs=%p\n",
               sig, ka, info, oldset, regs);
        
@@ -506,16 +507,12 @@ handle_signal(unsigned long sig, siginfo_t *info, sigset_t *oldset,
        if (!setup_rt_frame(sig, ka, info, oldset, regs, in_syscall))
                return 0;
 
-       if (ka->sa.sa_flags & SA_ONESHOT)
-               ka->sa.sa_handler = SIG_DFL;
-
-       if (!(ka->sa.sa_flags & SA_NODEFER)) {
-               spin_lock_irq(&current->sighand->siglock);
-               sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
+       spin_lock_irq(&current->sighand->siglock);
+       sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
+       if (!(ka->sa.sa_flags & SA_NODEFER))
                sigaddset(&current->blocked,sig);
-               recalc_sigpending();
-               spin_unlock_irq(&current->sighand->siglock);
-       }
+       recalc_sigpending();
+       spin_unlock_irq(&current->sighand->siglock);
        return 1;
 }
 
@@ -535,7 +532,7 @@ asmlinkage int
 do_signal(sigset_t *oldset, struct pt_regs *regs, int in_syscall)
 {
        siginfo_t info;
-       struct k_sigaction *ka;
+       struct k_sigaction ka;
        int signr;
 
        DBG(1,"\ndo_signal: oldset=0x%p, regs=0x%p, sr7 %#lx, in_syscall=%d\n",
@@ -553,10 +550,15 @@ do_signal(sigset_t *oldset, struct pt_regs *regs, int in_syscall)
                oldset->sig[0], oldset->sig[1]);
 
 
-       signr = get_signal_to_deliver(&info, regs, NULL);
-       DBG(3,"do_signal: signr = %d, regs->gr[28] = %ld\n", signr, regs->gr[28]); 
+       /* May need to force signal if handle_signal failed to deliver */
+       while (1) {
+         
+               signr = get_signal_to_deliver(&info, &ka, regs, NULL);
+               DBG(3,"do_signal: signr = %d, regs->gr[28] = %ld\n", signr, regs->gr[28]); 
        
-       if (signr > 0) {
+               if (signr <= 0)
+                 break;
+               
                /* Restart a system call if necessary. */
                if (in_syscall) {
                        /* Check the return code */
@@ -569,8 +571,7 @@ do_signal(sigset_t *oldset, struct pt_regs *regs, int in_syscall)
                                break;
 
                        case -ERESTARTSYS:
-                               ka = &current->sighand->action[signr-1];
-                               if (!(ka->sa.sa_flags & SA_RESTART)) {
+                               if (!(ka.sa.sa_flags & SA_RESTART)) {
                                        DBG(1,"ERESTARTSYS: putting -EINTR\n");
                                        regs->gr[28] = -EINTR;
                                        break;
@@ -578,8 +579,7 @@ do_signal(sigset_t *oldset, struct pt_regs *regs, int in_syscall)
                        /* fallthrough */
                        case -ERESTARTNOINTR:
                                /* A syscall is just a branch, so all
-                                   we have to do is fiddle the return
-                                   pointer. */
+                                  we have to do is fiddle the return pointer. */
                                regs->gr[31] -= 8; /* delayed branching */
                                /* Preserve original r28. */
                                regs->gr[28] = regs->orig_r28;
@@ -589,12 +589,13 @@ do_signal(sigset_t *oldset, struct pt_regs *regs, int in_syscall)
                /* Whee!  Actually deliver the signal.  If the
                   delivery failed, we need to continue to iterate in
                   this loop so we can deliver the SIGSEGV... */
-               if (handle_signal(signr, &info, oldset, regs, in_syscall)) {
+               if (handle_signal(signr, &info, &ka, oldset, regs, in_syscall)) {
                        DBG(1,KERN_DEBUG "do_signal: Exit (success), regs->gr[28] = %ld\n",
                                regs->gr[28]);
                        return 1;
                }
        }
+       /* end of while(1) looping forever if we can't force a signal */
 
        /* Did we come from a system call? */
        if (in_syscall) {
@@ -622,10 +623,14 @@ do_signal(sigset_t *oldset, struct pt_regs *regs, int in_syscall)
                        put_user(0xe0008200, &usp[3]);
                        put_user(0x34140000, &usp[4]);
 
-                       /* Stack is 64-byte aligned, and we only 
-                        * need to flush 1 cache line */
-                       asm("fdc 0(%%sr3, %0)\n"
-                           "fic 0(%%sr3, %0)\n"
+                       /* Stack is 64-byte aligned, and we only need
+                        * to flush 1 cache line.
+                        * Flushing one cacheline is cheap.
+                        * "sync" on bigger (> 4 way) boxes is not.
+                        */
+                       asm("fdc %%r0(%%sr3, %0)\n"
+                           "sync\n"
+                           "fic %%r0(%%sr3, %0)\n"
                            "sync\n"
                            : : "r"(regs->gr[30]));