struct sigframe {
u32 sf_ass[4]; /* argument save space for o32 */
u32 sf_pad[2]; /* Was: signal trampoline */
/* Matches struct ucontext from its uc_mcontext field onwards */ struct sigcontext sf_sc;
sigset_t sf_mask; unsignedlonglong sf_extcontext[];
};
struct rt_sigframe {
u32 rs_ass[4]; /* argument save space for o32 */
u32 rs_pad[2]; /* Was: signal trampoline */ struct siginfo rs_info; struct ucontext rs_uc;
};
#ifdef CONFIG_MIPS_FP_SUPPORT
/* * Thread saved context copy to/from a signal context presumed to be on the * user stack, and therefore accessed with appropriate macros from uaccess.h.
*/ staticint copy_fp_to_sigcontext(void __user *sc)
{ struct mips_abi *abi = current->thread.abi;
uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
uint32_t __user *csr = sc + abi->off_sc_fpc_csr; int i; int err = 0; int inc = test_thread_flag(TIF_32BIT_FPREGS) ? 2 : 1;
for (i = 0; i < NUM_FPU_REGS; i += inc) {
err |=
__put_user(get_fpr64(¤t->thread.fpu.fpr[i], 0),
&fpregs[i]);
}
err |= __put_user(current->thread.fpu.fcr31, csr);
/* * We can just pretend the sigcontext is always embedded in a struct * ucontext here, because the offset from sigcontext to extended * context is the same in the struct sigframe case.
*/
uc = container_of(sc, struct ucontext, uc_mcontext); return &uc->uc_extcontext;
}
#ifdef CONFIG_CPU_HAS_MSA
staticint save_msa_extcontext(void __user *buf)
{ struct msa_extcontext __user *msa = buf;
uint64_t val; int i, err;
if (!thread_msa_context_live()) return 0;
/* * Ensure that we can't lose the live MSA context between checking * for it & writing it to memory.
*/
preempt_disable();
if (is_msa_enabled()) { /* * There are no EVA versions of the vector register load/store * instructions, so MSA context has to be saved to kernel memory * and then copied to user memory. The save to kernel memory * should already have been done when handling scalar FP * context.
*/
BUG_ON(IS_ENABLED(CONFIG_EVA));
staticint restore_msa_extcontext(void __user *buf, unsignedint size)
{ struct msa_extcontext __user *msa = buf; unsignedlonglong val; unsignedint csr; int i, err;
if (size != sizeof(*msa)) return -EINVAL;
err = get_user(csr, &msa->csr); if (err) return err;
preempt_disable();
if (is_msa_enabled()) { /* * There are no EVA versions of the vector register load/store * instructions, so MSA context has to be copied to kernel * memory and later loaded to registers. The same is true of * scalar FP context, so FPU & MSA should have already been * disabled whilst handling scalar FP context.
*/
BUG_ON(IS_ENABLED(CONFIG_EVA));
used = used_math() ? USED_FP : 0; if (!used) goto fp_done;
if (!test_thread_flag(TIF_32BIT_FPREGS))
used |= USED_FR1; if (test_thread_flag(TIF_HYBRID_FPREGS))
used |= USED_HYBRID_FPRS;
/* * EVA does not have userland equivalents of ldc1 or sdc1, so * save to the kernel FP context & copy that to userland below.
*/ if (IS_ENABLED(CONFIG_EVA))
lose_fpu(1);
while (1) {
lock_fpu_owner(); if (is_fpu_owner()) {
err = save_fp_context(sc);
unlock_fpu_owner();
} else {
unlock_fpu_owner();
err = copy_fp_to_sigcontext(sc);
} if (likely(!err)) break; /* touch the sigcontext and try again */
err = __put_user(0, &fpregs[0]) |
__put_user(0, &fpregs[31]) |
__put_user(0, csr); if (err) return err; /* really bad sigcontext */
}
fp_done:
ext_sz = err = save_extcontext(sc_to_extcontext(sc)); if (err < 0) return err;
used |= ext_sz ? USED_EXTCONTEXT : 0;
/* * The signal handler may have used FPU; give it up if the program * doesn't want it following sigreturn.
*/ if (err || !(used & USED_FP))
lose_fpu(0); if (err) return err; if (!(used & USED_FP)) goto fp_done;
err = sig = fpcsr_pending(csr); if (err < 0) return err;
/* * EVA does not have userland equivalents of ldc1 or sdc1, so we * disable the FPU here such that the code below simply copies to * the kernel FP context.
*/ if (IS_ENABLED(CONFIG_EVA))
lose_fpu(0);
while (1) {
lock_fpu_owner(); if (is_fpu_owner()) {
err = restore_fp_context(sc);
unlock_fpu_owner();
} else {
unlock_fpu_owner();
err = copy_fp_from_sigcontext(sc);
} if (likely(!err)) break; /* touch the sigcontext and try again */
err = __get_user(tmp, &fpregs[0]) |
__get_user(tmp, &fpregs[31]) |
__get_user(tmp, csr); if (err) break; /* really bad sigcontext */
}
fp_done: if (!err && (used & USED_EXTCONTEXT))
err = restore_extcontext(sc_to_extcontext(sc));
return err ?: sig;
}
int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
{ int err = 0; int i;
err |= __put_user(regs->cp0_epc, &sc->sc_pc);
err |= __put_user(0, &sc->sc_regs[0]); for (i = 1; i < 32; i++)
err |= __put_user(regs->regs[i], &sc->sc_regs[i]);
/* * The assumption here is that between this point & the point at which * the extended context is saved the size of the context should only * ever be able to shrink (if the task is preempted), but never grow. * That is, what this function returns is an upper bound on the size of * the extended context for the current task at the current time.
*/
if (thread_msa_context_live())
sz += sizeof(struct msa_extcontext);
/* If any context is saved then we'll append the end marker */ if (sz)
sz += sizeof(((struct extcontext *)NULL)->magic);
return sz;
}
int fpcsr_pending(unsignedint __user *fpcsr)
{ int err, sig = 0; unsignedint csr, enabled;
err = __get_user(csr, fpcsr);
enabled = FPU_CSR_UNI_X | ((csr & FPU_CSR_ALL_E) << 5); /* * If the signal handler set some FPU exceptions, clear it and * send SIGFPE.
*/ if (csr & enabled) {
csr &= ~enabled;
err |= __put_user(csr, fpcsr);
sig = SIGFPE;
} return err ?: sig;
}
int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
{ unsignedlong treg; int err = 0; int i;
/* Always make any pending restarted system calls return -EINTR */
current->restart_block.fn = do_no_restart_syscall;
/* Leave space for potential extended context */
frame_size += extcontext_max_size();
/* Default to using normal stack */
sp = regs->regs[29];
/* * If we are on the alternate signal stack and would overflow it, don't. * Return an always-bogus address instead so we will die with SIGSEGV.
*/ if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size))) return (void __user __force *)(-1UL);
/* * FPU emulator may have its own trampoline active just * above the user stack, 16-bytes before the next lowest * 16 byte boundary. Try to avoid trashing it.
*/
sp -= 32;
regs = current_pt_regs();
frame = (struct sigframe __user *)regs->regs[29]; if (!access_ok(frame, sizeof(*frame))) goto badframe; if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked))) goto badframe;
set_current_blocked(&blocked);
sig = restore_sigcontext(regs, &frame->sf_sc); if (sig < 0) goto badframe; elseif (sig)
force_sig(sig);
/* * Don't let your children do this ...
*/
__asm__ __volatile__( "move\t$29, %0\n\t" "j\tsyscall_exit"
: /* no outputs */
: "r" (regs)); /* Unreached */
regs = current_pt_regs();
frame = (struct rt_sigframe __user *)regs->regs[29]; if (!access_ok(frame, sizeof(*frame))) goto badframe; if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set))) goto badframe;
set_current_blocked(&set);
sig = restore_sigcontext(regs, &frame->rs_uc.uc_mcontext); if (sig < 0) goto badframe; elseif (sig)
force_sig(sig);
if (restore_altstack(&frame->rs_uc.uc_stack)) goto badframe;
/* * Don't let your children do this ...
*/
__asm__ __volatile__( "move\t$29, %0\n\t" "j\tsyscall_exit"
: /* no outputs */
: "r" (regs)); /* Unreached */
/* * If we were emulating a delay slot instruction, exit that frame such * that addresses in the sigframe are as expected for userland and we * don't have a problem if we reuse the thread's frame for an * instruction within the signal handler.
*/
dsemul_thread_rollback(regs);
if (regs->regs[0]) { switch(regs->regs[2]) { case ERESTART_RESTARTBLOCK: case ERESTARTNOHAND:
regs->regs[2] = EINTR; break; case ERESTARTSYS: if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
regs->regs[2] = EINTR; break;
}
fallthrough; case ERESTARTNOINTR:
regs->regs[7] = regs->regs[26];
regs->regs[2] = regs->regs[0];
regs->cp0_epc -= 4;
}
regs->regs[0] = 0; /* Don't deal with this again. */
}
rseq_signal_deliver(ksig, regs);
if (sig_uses_siginfo(&ksig->ka, abi))
ret = abi->setup_rt_frame(vdso + abi->vdso->off_rt_sigreturn,
ksig, regs, oldset); else
ret = abi->setup_frame(vdso + abi->vdso->off_sigreturn,
ksig, regs, oldset);
staticint signal_setup(void)
{ /* * The offset from sigcontext to extended context should be the same * regardless of the type of signal, such that userland can always know * where to look if it wishes to find the extended context structures.
*/
BUILD_BUG_ON((offsetof(struct sigframe, sf_extcontext) -
offsetof(struct sigframe, sf_sc)) !=
(offsetof(struct rt_sigframe, rs_uc.uc_extcontext) -
offsetof(struct rt_sigframe, rs_uc.uc_mcontext)));
#ifdefined(CONFIG_SMP) && defined(CONFIG_MIPS_FP_SUPPORT) /* For now just do the cpu_has_fpu check when the functions are invoked */
save_fp_context = smp_save_fp_context;
restore_fp_context = smp_restore_fp_context; #else if (cpu_has_fpu) {
save_fp_context = save_hw_fp_context;
restore_fp_context = restore_hw_fp_context;
} else {
save_fp_context = copy_fp_to_sigcontext;
restore_fp_context = copy_fp_from_sigcontext;
} #endif/* CONFIG_SMP */
return 0;
}
arch_initcall(signal_setup);
Messung V0.5
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.