static int setup_return(struct pt_regs *regs, struct ksignal *ksig, unsigned long __user *rc, void __user *frame) { unsigned long handler = (unsigned long)ksig->ka.sa.sa_handler; unsigned long retcode; int thumb = 0; unsigned long cpsr = regs->ARM_cpsr & ~(PSR_f | PSR_E_BIT); cpsr |= PSR_ENDSTATE; /* * Maybe we need to deliver a 32-bit signal to a 26-bit task. */ if (ksig->ka.sa.sa_flags & SA_THIRTYTWO) cpsr = (cpsr & ~MODE_MASK) | USR_MODE; #ifdef CONFIG_ARM_THUMB if (elf_hwcap & HWCAP_THUMB) { /* * The LSB of the handler determines if we're going to * be using THUMB or ARM mode for this signal handler. */ thumb = handler & 1; #if __LINUX_ARM_ARCH__ >= 6 /* * Clear the If-Then Thumb-2 execution state. ARM spec * requires this to be all 000s in ARM mode. Snapdragon * S4/Krait misbehaves on a Thumb=>ARM signal transition * without this. * * We must do this whenever we are running on a Thumb-2 * capable CPU, which includes ARMv6T2. However, we elect * to do this whenever we're on an ARMv6 or later CPU for * simplicity. */ cpsr &= ~PSR_IT_MASK; #endif if (thumb) { cpsr |= PSR_T_BIT; } else cpsr &= ~PSR_T_BIT; } #endif if (ksig->ka.sa.sa_flags & SA_RESTORER) { retcode = (unsigned long)ksig->ka.sa.sa_restorer; } else { unsigned int idx = thumb << 1; if (ksig->ka.sa.sa_flags & SA_SIGINFO) idx += 3; /* * Put the sigreturn code on the stack no matter which return * mechanism we use in order to remain ABI compliant */ if (__put_user(sigreturn_codes[idx], rc) || __put_user(sigreturn_codes[idx+1], rc+1)) return 1; #ifdef CONFIG_MMU if (cpsr & MODE32_BIT) { struct mm_struct *mm = current->mm; /* * 32-bit code can use the signal return page * except when the MPU has protected the vectors * page from PL0 */ retcode = mm->context.sigpage + signal_return_offset + (idx << 2) + thumb; } else #endif { /* * Ensure that the instruction cache sees * the return code written onto the stack. */ flush_icache_range((unsigned long)rc, (unsigned long)(rc + 2)); retcode = ((unsigned long)rc) + thumb; } } regs->ARM_r0 = map_sig(ksig->sig); regs->ARM_sp = (unsigned long)frame; regs->ARM_lr = retcode; regs->ARM_pc = handler; regs->ARM_cpsr = cpsr; return 0; }
static int setup_rt_frame(int signo, struct k_sigaction *ka, siginfo_t *info, sigset_t *set, struct pt_regs *regs) { struct rt_sigframe __user *sf; unsigned int magic = 0; int err = 0; sf = get_sigframe(ka, regs, sizeof(struct rt_sigframe)); if (!sf) return 1; /* * w/o SA_SIGINFO, struct ucontext is partially populated (only * uc_mcontext/uc_sigmask) for kernel's normal user state preservation * during signal handler execution. This works for SA_SIGINFO as well * although the semantics are now overloaded (the same reg state can be * inspected by userland: but are they allowed to fiddle with it ? */ err |= stash_usr_regs(sf, regs, set); /* * SA_SIGINFO requires 3 args to signal handler: * #1: sig-no (common to any handler) * #2: struct siginfo * #3: struct ucontext (completely populated) */ if (unlikely(ka->sa.sa_flags & SA_SIGINFO)) { err |= copy_siginfo_to_user(&sf->info, info); err |= __put_user(0, &sf->uc.uc_flags); err |= __put_user(NULL, &sf->uc.uc_link); err |= __save_altstack(&sf->uc.uc_stack, regs->sp); /* setup args 2 and 3 for user mode handler */ regs->r1 = (unsigned long)&sf->info; regs->r2 = (unsigned long)&sf->uc; /* * small optim to avoid unconditonally calling do_sigaltstack * in sigreturn path, now that we only have rt_sigreturn */ magic = MAGIC_SIGALTSTK; } err |= __put_user(magic, &sf->sigret_magic); if (err) return err; /* #1 arg to the user Signal handler */ regs->r0 = map_sig(signo); /* setup PC of user space signal handler */ regs->ret = (unsigned long)ka->sa.sa_handler; /* * handler returns using sigreturn stub provided already by userpsace */ BUG_ON(!(ka->sa.sa_flags & SA_RESTORER)); regs->blink = (unsigned long)ka->sa.sa_restorer; /* User Stack for signal handler will be above the frame just carved */ regs->sp = (unsigned long)sf; /* * Bug 94183, Clear the DE bit, so that when signal handler * starts to run, it doesn't use BTA */ regs->status32 &= ~STATUS_DE_MASK; regs->status32 |= STATUS_L_MASK; return err; }
static int setup_return(struct pt_regs *regs, struct ksignal *ksig, unsigned long __user *rc, void __user *frame) { unsigned long handler = (unsigned long)ksig->ka.sa.sa_handler; unsigned long retcode; int thumb = 0; unsigned long cpsr = regs->ARM_cpsr & ~(PSR_f | PSR_E_BIT); cpsr |= PSR_ENDSTATE; /* * Maybe we need to deliver a 32-bit signal to a 26-bit task. */ if (ksig->ka.sa.sa_flags & SA_THIRTYTWO) cpsr = (cpsr & ~MODE_MASK) | USR_MODE; #ifdef CONFIG_ARM_THUMB if (elf_hwcap & HWCAP_THUMB) { /* * The LSB of the handler determines if we're going to * be using THUMB or ARM mode for this signal handler. */ thumb = handler & 1; if (thumb) { cpsr |= PSR_T_BIT; #if __LINUX_ARM_ARCH__ >= 7 /* clear the If-Then Thumb-2 execution state */ cpsr &= ~PSR_IT_MASK; #endif } else cpsr &= ~PSR_T_BIT; } #endif if (ksig->ka.sa.sa_flags & SA_RESTORER) { retcode = (unsigned long)ksig->ka.sa.sa_restorer; } else { unsigned int idx = thumb << 1; if (ksig->ka.sa.sa_flags & SA_SIGINFO) idx += 3; if (__put_user(sigreturn_codes[idx], rc) || __put_user(sigreturn_codes[idx+1], rc+1)) return 1; #ifdef CONFIG_MMU if (cpsr & MODE32_BIT) { struct mm_struct *mm = current->mm; /* * 32-bit code can use the signal return page * except when the MPU has protected the vectors * page from PL0 */ retcode = mm->context.sigpage + signal_return_offset + (idx << 2) + thumb; } else #endif { /* * Ensure that the instruction cache sees * the return code written onto the stack. */ flush_icache_range((unsigned long)rc, (unsigned long)(rc + 2)); retcode = ((unsigned long)rc) + thumb; } } regs->ARM_r0 = map_sig(ksig->sig); regs->ARM_sp = (unsigned long)frame; regs->ARM_lr = retcode; regs->ARM_pc = handler; regs->ARM_cpsr = cpsr; return 0; }