// SPDX-License-Identifier: GPL-2.0 /* arch/sparc64/kernel/signal32.c * * Copyright (C) 1991, 1992 Linus Torvalds * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx) * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be) * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
*/
/* This magic should be in g_upper[0] for all upper parts * to be valid.
*/ #define SIGINFO_EXTRA_V8PLUS_MAGIC 0x130e269 typedefstruct { unsignedint g_upper[8]; unsignedint o_upper[8]; unsignedint asi;
} siginfo_extra_v8plus_t;
/* Checks if the fp is valid. We always build signal frames which are * 16-byte aligned, therefore we can always enforce that the restore * frame has that property as well.
*/ staticbool invalid_frame_pointer(void __user *fp, int fplen)
{ if ((((unsignedlong) fp) & 15) ||
((unsignedlong)fp) > 0x100000000ULL - fplen) returntrue; returnfalse;
}
/* Always make any pending restarted system calls return -EINTR */
current->restart_block.fn = do_no_restart_syscall;
synchronize_user_stack();
regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;
sf = (struct signal_frame32 __user *) regs->u_regs[UREG_FP];
/* 1. Make sure we are not getting garbage from the user */ if (invalid_frame_pointer(sf, sizeof(*sf))) goto segv;
if (get_user(ufp, &sf->info.si_regs.u_regs[UREG_FP])) goto segv;
if (ufp & 0x7) goto segv;
if (__get_user(pc, &sf->info.si_regs.pc) ||
__get_user(npc, &sf->info.si_regs.npc)) goto segv;
if ((pc | npc) & 3) goto segv;
if (test_thread_flag(TIF_32BIT)) {
pc &= 0xffffffff;
npc &= 0xffffffff;
}
regs->tpc = pc;
regs->tnpc = npc;
/* 2. Restore the state */
err = __get_user(regs->y, &sf->info.si_regs.y);
err |= __get_user(psr, &sf->info.si_regs.psr);
for (i = UREG_G1; i <= UREG_I7; i++)
err |= __get_user(regs->u_regs[i], &sf->info.si_regs.u_regs[i]); if ((psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS) {
err |= __get_user(i, &sf->v8plus.g_upper[0]); if (i == SIGINFO_EXTRA_V8PLUS_MAGIC) { unsignedlong asi;
for (i = UREG_G1; i <= UREG_I7; i++)
err |= __get_user(((u32 *)regs->u_regs)[2*i], &sf->v8plus.g_upper[i]);
err |= __get_user(asi, &sf->v8plus.asi);
regs->tstate &= ~TSTATE_ASI;
regs->tstate |= ((asi & 0xffUL) << 24UL);
}
}
/* User can only change condition codes in %tstate. */
regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC);
regs->tstate |= psr_to_tstate_icc(psr);
/* 1. Make sure we are not getting garbage from the user */ if (invalid_frame_pointer(sf, sizeof(*sf))) goto segv;
if (get_user(ufp, &sf->regs.u_regs[UREG_FP])) goto segv;
if (ufp & 0x7) goto segv;
if (__get_user(pc, &sf->regs.pc) ||
__get_user(npc, &sf->regs.npc)) goto segv;
if ((pc | npc) & 3) goto segv;
if (test_thread_flag(TIF_32BIT)) {
pc &= 0xffffffff;
npc &= 0xffffffff;
}
regs->tpc = pc;
regs->tnpc = npc;
/* 2. Restore the state */
err = __get_user(regs->y, &sf->regs.y);
err |= __get_user(psr, &sf->regs.psr);
for (i = UREG_G1; i <= UREG_I7; i++)
err |= __get_user(regs->u_regs[i], &sf->regs.u_regs[i]); if ((psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS) {
err |= __get_user(i, &sf->v8plus.g_upper[0]); if (i == SIGINFO_EXTRA_V8PLUS_MAGIC) { unsignedlong asi;
for (i = UREG_G1; i <= UREG_I7; i++)
err |= __get_user(((u32 *)regs->u_regs)[2*i], &sf->v8plus.g_upper[i]);
err |= __get_user(asi, &sf->v8plus.asi);
regs->tstate &= ~TSTATE_ASI;
regs->tstate |= ((asi & 0xffUL) << 24UL);
}
}
/* User can only change condition codes in %tstate. */
regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC);
regs->tstate |= psr_to_tstate_icc(psr);
/* * 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 - framesize))) return (void __user *) -1L;
/* This is the X/Open sanctioned signal stack switching. */
sp = sigsp(sp, ksig) - framesize;
/* Always align the stack frame. This handles two cases. First, * sigaltstack need not be mindful of platform specific stack * alignment. Second, if we took this signal because the stack * is not aligned properly, we'd like to take the signal cleanly * and report that.
*/
sp &= ~15UL;
return (void __user *) sp;
}
/* The I-cache flush instruction only works in the primary ASI, which * right now is the nucleus, aka. kernel space. * * Therefore we have to kick the instructions out using the kernel * side linear mapping of the physical address backing the user * instructions.
*/ staticvoid flush_signal_insns(unsignedlong address)
{ unsignedlong pstate, paddr;
pte_t *ptep, pte;
pgd_t *pgdp;
p4d_t *p4dp;
pud_t *pudp;
pmd_t *pmdp;
/* Commit all stores of the instructions we are about to flush. */
wmb();
/* Disable cross-call reception. In this way even a very wide * munmap() on another cpu can't tear down the page table * hierarchy from underneath us, since that can't complete * until the IPI tlb flush returns.
*/
/* If these change we need to know - assignments to seta relies on these sizes */
BUILD_BUG_ON(_NSIG_WORDS != 1);
BUILD_BUG_ON(_COMPAT_NSIG_WORDS != 2);
seta.sig[1] = (oldset->sig[0] >> 32);
seta.sig[0] = oldset->sig[0];
staticinlinevoid syscall_restart32(unsignedlong orig_i0, struct pt_regs *regs, struct sigaction *sa)
{ switch (regs->u_regs[UREG_I0]) { case ERESTART_RESTARTBLOCK: case ERESTARTNOHAND:
no_system_call_restart:
regs->u_regs[UREG_I0] = EINTR;
regs->tstate |= TSTATE_ICARRY; break; case ERESTARTSYS: if (!(sa->sa_flags & SA_RESTART)) goto no_system_call_restart;
fallthrough; case ERESTARTNOINTR:
regs->u_regs[UREG_I0] = orig_i0;
regs->tpc -= 4;
regs->tnpc -= 4;
}
}
/* Note that 'init' is a special process: it doesn't get signals it doesn't * want to handle. Thus you cannot kill init even with a SIGKILL even by * mistake.
*/ void do_signal32(struct pt_regs * regs)
{ struct ksignal ksig; unsignedlong orig_i0 = 0; int restart_syscall = 0; bool has_handler = get_signal(&ksig);
/* First see if old state is wanted. */ if (ossptr) { if (put_user(current->sas_ss_sp + current->sas_ss_size,
&ossptr->the_stack) ||
__put_user(on_sig_stack(sp), &ossptr->cur_status)) goto out;
}
/* Now see if we want to update the new state. */ if (ssptr) {
u32 ss_sp;
if (get_user(ss_sp, &ssptr->the_stack)) goto out;
/* If the current stack was set with sigaltstack, don't * swap stacks while we are on it.
*/
ret = -EPERM; if (current->sas_ss_sp && on_sig_stack(sp)) goto out;
/* Since we don't know the extent of the stack, and we don't * track onstack-ness, but rather calculate it, we must * presume a size. Ho hum this interface is lossy.
*/
current->sas_ss_sp = (unsignedlong)ss_sp - SIGSTKSZ;
current->sas_ss_size = SIGSTKSZ;
}
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.