// SPDX-License-Identifier: GPL-2.0-or-later /* * OpenRISC signal.c * * Linux architectural port borrowing liberally from similar works of * others. All original copyrights apply as per the original source * declaration. * * Modifications for the OpenRISC architecture: * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
*/
/* TODO: the other ports use regs->orig_XX to disable syscall checks * after this completes, but we don't use that mechanism. maybe we can * use it now ?
*/
/* * Since we stacked the signal on a dword boundary, * then frame should be dword aligned here. If it's * not, then the user is trying to mess with us.
*/ if (((unsignedlong)frame) & 3) goto badframe;
if (!access_ok(frame, sizeof(*frame))) goto badframe; if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) goto badframe;
set_current_blocked(&set);
if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) goto badframe;
if (restore_altstack(&frame->uc.uc_stack)) goto badframe;
/* copy the regs */ /* There should be no need to save callee-saved registers here... * ...but we save them anyway. Revisit this
*/
err |= __copy_to_user(sc->regs.gpr, regs, 32 * sizeof(unsignedlong));
err |= __copy_to_user(&sc->regs.pc, ®s->pc, sizeof(unsignedlong));
err |= __copy_to_user(&sc->regs.sr, ®s->sr, sizeof(unsignedlong));
err |= save_fp_state(sc);
/* grab and setup a signal frame. * * basically we stack a lot of state info, and arrange for the * user-mode program to return to the kernel using either a * trampoline which performs the syscall sigreturn, or a provided * user-mode trampoline.
*/ staticint setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs)
{ struct rt_sigframe __user *frame; unsignedlong return_ip; int err = 0;
frame = get_sigframe(ksig, regs, sizeof(*frame));
if (!access_ok(frame, sizeof(*frame))) return -EFAULT;
/* trampoline - the desired return ip is the retcode itself */
return_ip = (unsignedlong)&frame->retcode; /* This is: l.ori r11,r0,__NR_sigreturn l.sys 1
*/
err |= __put_user(0xa960, (short __user *)(frame->retcode + 0));
err |= __put_user(__NR_rt_sigreturn, (short __user *)(frame->retcode + 2));
err |= __put_user(0x20000001, (unsignedlong __user *)(frame->retcode + 4));
err |= __put_user(0x15000000, (unsignedlong __user *)(frame->retcode + 8));
if (err) return -EFAULT;
/* Set up registers for signal handler */
regs->pc = (unsignedlong)ksig->ka.sa.sa_handler; /* what we enter NOW */
regs->gpr[9] = (unsignedlong)return_ip; /* what we enter LATER */
regs->gpr[3] = (unsignedlong)ksig->sig; /* arg 1: signo */
regs->gpr[4] = (unsignedlong)&frame->info; /* arg 2: (siginfo_t*) */
regs->gpr[5] = (unsignedlong)&frame->uc; /* arg 3: ucontext */
/* actually move the usp to reflect the stacked frame */
regs->sp = (unsignedlong)frame;
return 0;
}
staticinlinevoid
handle_signal(struct ksignal *ksig, struct pt_regs *regs)
{ int ret;
rseq_signal_deliver(ksig, regs);
ret = setup_rt_frame(ksig, sigmask_to_save(), regs);
/* * 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. * * Also note that the regs structure given here as an argument, is the latest * pushed pt_regs. It may or may not be the same as the first pushed registers * when the initial usermode->kernelmode transition took place. Therefore * we can use user_mode(regs) to see if we came directly from kernel or user * mode below.
*/
/* * Setup syscall restart here so that a debugger will * see the already changed PC.
*/ switch (retval) { case -ERESTART_RESTARTBLOCK:
restart = -2;
fallthrough; case -ERESTARTNOHAND: case -ERESTARTSYS: case -ERESTARTNOINTR:
restart++;
regs->gpr[11] = regs->orig_gpr11;
regs->pc = restart_addr; break;
}
}
/* * Get the signal to deliver. During the call to get_signal the * debugger may change all our registers so we may need to revert * the decision to restart the syscall; specifically, if the PC is * changed, don't restart the syscall.
*/ if (get_signal(&ksig)) { if (unlikely(restart) && regs->pc == restart_addr) { if (retval == -ERESTARTNOHAND ||
retval == -ERESTART_RESTARTBLOCK
|| (retval == -ERESTARTSYS
&& !(ksig.ka.sa.sa_flags & SA_RESTART))) { /* No automatic restart */
regs->gpr[11] = -EINTR;
regs->pc = continue_addr;
}
}
handle_signal(&ksig, regs);
} else { /* no handler */
restore_saved_sigmask(); /* * Restore pt_regs PC as syscall restart will be handled by * kernel without return to userspace
*/ if (unlikely(restart) && regs->pc == restart_addr) {
regs->pc = continue_addr; return restart;
}
}
return 0;
}
asmlinkage int
do_work_pending(struct pt_regs *regs, unsignedint thread_flags, int syscall)
{ do { if (likely(thread_flags & _TIF_NEED_RESCHED)) {
schedule();
} else { if (unlikely(!user_mode(regs))) return 0;
local_irq_enable(); if (thread_flags & (_TIF_SIGPENDING|_TIF_NOTIFY_SIGNAL)) { int restart = do_signal(regs, syscall); if (unlikely(restart)) { /* * Restart without handlers. * Deal with it without leaving * the kernel space.
*/ return restart;
}
syscall = 0;
} else {
resume_user_mode_work(regs);
}
}
local_irq_disable();
thread_flags = read_thread_flags();
} while (thread_flags & _TIF_WORK_MASK); return 0;
}
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.