]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - arch/powerpc/kernel/signal_32.c
[PATCH] powerpc: Implement support for setting little-endian mode via prctl
[mirror_ubuntu-zesty-kernel.git] / arch / powerpc / kernel / signal_32.c
index c6d0595da6b5d74755d2eb8be8804672c862eae7..237faeec2ec2634302413d9eb4bb39ede02bc564 100644 (file)
@@ -42,6 +42,7 @@
 
 #include <asm/uaccess.h>
 #include <asm/cacheflush.h>
+#include <asm/syscalls.h>
 #include <asm/sigcontext.h>
 #include <asm/vdso.h>
 #ifdef CONFIG_PPC64
@@ -142,11 +143,7 @@ static inline int get_old_sigaction(struct k_sigaction *new_ka,
        return 0;
 }
 
-static inline compat_uptr_t to_user_ptr(void *kp)
-{
-       return (compat_uptr_t)(u64)kp;
-}
-
+#define to_user_ptr(p)         ptr_to_compat(p)
 #define from_user_ptr(p)       compat_ptr(p)
 
 static inline int save_general_regs(struct pt_regs *regs,
@@ -155,10 +152,7 @@ static inline int save_general_regs(struct pt_regs *regs,
        elf_greg_t64 *gregs = (elf_greg_t64 *)regs;
        int i;
 
-       if (!FULL_REGS(regs)) {
-               set_thread_flag(TIF_SAVE_NVGPRS);
-               current_thread_info()->nvgprs_frame = frame->mc_gregs;
-       }
+       WARN_ON(!FULL_REGS(regs));
 
        for (i = 0; i <= PT_RESULT; i ++) {
                if (i == 14 && !FULL_REGS(regs))
@@ -213,21 +207,13 @@ static inline int get_old_sigaction(struct k_sigaction *new_ka,
        return 0;
 }
 
-#define to_user_ptr(p)         (p)
-#define from_user_ptr(p)       (p)
+#define to_user_ptr(p)         ((unsigned long)(p))
+#define from_user_ptr(p)       ((void __user *)(p))
 
 static inline int save_general_regs(struct pt_regs *regs,
                struct mcontext __user *frame)
 {
-       if (!FULL_REGS(regs)) {
-               /* Zero out the unsaved GPRs to avoid information
-                  leak, and set TIF_SAVE_NVGPRS to ensure that the
-                  registers do actually get saved later. */
-               memset(&regs->gpr[14], 0, 18 * sizeof(unsigned long));
-               current_thread_info()->nvgprs_frame = &frame->mc_gregs;
-               set_thread_flag(TIF_SAVE_NVGPRS);
-       }
-
+       WARN_ON(!FULL_REGS(regs));
        return __copy_to_user(&frame->mc_gregs, regs, GP_REGS_SIZE);
 }
 
@@ -433,9 +419,7 @@ static long restore_user_regs(struct pt_regs *regs,
 {
        long err;
        unsigned int save_r2 = 0;
-#if defined(CONFIG_ALTIVEC) || defined(CONFIG_SPE)
        unsigned long msr;
-#endif
 
        /*
         * restore general registers but not including MSR or SOFTE. Also
@@ -444,11 +428,16 @@ static long restore_user_regs(struct pt_regs *regs,
        if (!sig)
                save_r2 = (unsigned int)regs->gpr[2];
        err = restore_general_regs(regs, sr);
+       err |= __get_user(msr, &sr->mc_gregs[PT_MSR]);
        if (!sig)
                regs->gpr[2] = (unsigned long) save_r2;
        if (err)
                return 1;
 
+       /* if doing signal return, restore the previous little-endian mode */
+       if (sig)
+               regs->msr = (regs->msr & ~MSR_LE) | (msr & MSR_LE);
+
        /*
         * Do this before updating the thread state in
         * current->thread.fpr/vr/evr.  That way, if we get preempted
@@ -469,7 +458,7 @@ static long restore_user_regs(struct pt_regs *regs,
        /* force the process to reload the altivec registers from
           current->thread when it next does altivec instructions */
        regs->msr &= ~MSR_VEC;
-       if (!__get_user(msr, &sr->mc_gregs[PT_MSR]) && (msr & MSR_VEC) != 0) {
+       if (msr & MSR_VEC) {
                /* restore altivec registers from the stack */
                if (__copy_from_user(current->thread.vr, &sr->mc_vregs,
                                     sizeof(sr->mc_vregs)))
@@ -486,7 +475,7 @@ static long restore_user_regs(struct pt_regs *regs,
        /* force the process to reload the spe registers from
           current->thread when it next does spe instructions */
        regs->msr &= ~MSR_SPE;
-       if (!__get_user(msr, &sr->mc_gregs[PT_MSR]) && (msr & MSR_SPE) != 0) {
+       if (msr & MSR_SPE) {
                /* restore spe registers from the stack */
                if (__copy_from_user(current->thread.evr, &sr->mc_vregs,
                                     ELF_NEVRREG * sizeof(u32)))
@@ -526,7 +515,7 @@ long compat_sys_rt_sigaction(int sig, const struct sigaction32 __user *act,
 
        ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
        if (!ret && oact) {
-               ret = put_user((long)old_ka.sa.sa_handler, &oact->sa_handler);
+               ret = put_user(to_user_ptr(old_ka.sa.sa_handler), &oact->sa_handler);
                ret |= put_sigset_t(&oact->sa_mask, &old_ka.sa.sa_mask);
                ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
        }
@@ -675,8 +664,8 @@ long compat_sys_rt_sigqueueinfo(u32 pid, u32 sig, compat_siginfo_t __user *uinfo
 int compat_sys_sigaltstack(u32 __new, u32 __old, int r5,
                      int r6, int r7, int r8, struct pt_regs *regs)
 {
-       stack_32_t __user * newstack = (stack_32_t __user *)(long) __new;
-       stack_32_t __user * oldstack = (stack_32_t __user *)(long) __old;
+       stack_32_t __user * newstack = compat_ptr(__new);
+       stack_32_t __user * oldstack = compat_ptr(__old);
        stack_t uss, uoss;
        int ret;
        mm_segment_t old_fs;
@@ -708,7 +697,7 @@ int compat_sys_sigaltstack(u32 __new, u32 __old, int r5,
        set_fs(old_fs);
        /* Copy the stack information to the user output buffer */
        if (!ret && oldstack  &&
-               (put_user((long)uoss.ss_sp, &oldstack->ss_sp) ||
+               (put_user(ptr_to_compat(uoss.ss_sp), &oldstack->ss_sp) ||
                 __put_user(uoss.ss_flags, &oldstack->ss_flags) ||
                 __put_user(uoss.ss_size, &oldstack->ss_size)))
                return -EFAULT;
@@ -771,10 +760,10 @@ static int handle_rt_signal(unsigned long sig, struct k_sigaction *ka,
 
        /* Save user registers on the stack */
        frame = &rt_sf->uc.uc_mcontext;
-       if (vdso32_rt_sigtramp && current->thread.vdso_base) {
+       if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
                if (save_user_regs(regs, frame, 0))
                        goto badframe;
-               regs->link = current->thread.vdso_base + vdso32_rt_sigtramp;
+               regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
        } else {
                if (save_user_regs(regs, frame, __NR_rt_sigreturn))
                        goto badframe;
@@ -791,6 +780,8 @@ static int handle_rt_signal(unsigned long sig, struct k_sigaction *ka,
        regs->gpr[5] = (unsigned long) &rt_sf->uc;
        regs->gpr[6] = (unsigned long) rt_sf;
        regs->nip = (unsigned long) ka->sa.sa_handler;
+       /* enter the signal handler in big-endian mode */
+       regs->msr &= ~MSR_LE;
        regs->trap = 0;
        return 1;
 
@@ -830,8 +821,8 @@ static int do_setcontext(struct ucontext __user *ucp, struct pt_regs *regs, int
 }
 
 long sys_swapcontext(struct ucontext __user *old_ctx,
-                      struct ucontext __user *new_ctx,
-                      int ctx_size, int r6, int r7, int r8, struct pt_regs *regs)
+                    struct ucontext __user *new_ctx,
+                    int ctx_size, int r6, int r7, int r8, struct pt_regs *regs)
 {
        unsigned char tmp;
 
@@ -1043,10 +1034,10 @@ static int handle_signal(unsigned long sig, struct k_sigaction *ka,
            || __put_user(sig, &sc->signal))
                goto badframe;
 
-       if (vdso32_sigtramp && current->thread.vdso_base) {
+       if (vdso32_sigtramp && current->mm->context.vdso_base) {
                if (save_user_regs(regs, &frame->mctx, 0))
                        goto badframe;
-               regs->link = current->thread.vdso_base + vdso32_sigtramp;
+               regs->link = current->mm->context.vdso_base + vdso32_sigtramp;
        } else {
                if (save_user_regs(regs, &frame->mctx, __NR_sigreturn))
                        goto badframe;
@@ -1061,6 +1052,8 @@ static int handle_signal(unsigned long sig, struct k_sigaction *ka,
        regs->gpr[3] = sig;
        regs->gpr[4] = (unsigned long) sc;
        regs->nip = (unsigned long) ka->sa.sa_handler;
+       /* enter the signal handler in big-endian mode */
+       regs->msr &= ~MSR_LE;
        regs->trap = 0;
 
        return 1;