Skip to content

Commit

Permalink
openrisc: Use get_signal() signal_setup_done()
Browse files Browse the repository at this point in the history
Use the more generic functions get_signal() signal_setup_done()
for signal delivery.

Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Jonas Bonn <jonas@southpole.se>
  • Loading branch information
Richard Weinberger authored and Jonas Bonn committed Jan 9, 2014
1 parent 10f67db commit 548dafe
Showing 1 changed file with 22 additions and 37 deletions.
59 changes: 22 additions & 37 deletions arch/openrisc/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,21 @@ static inline void __user *get_sigframe(struct k_sigaction *ka,
* trampoline which performs the syscall sigreturn, or a provided
* user-mode trampoline.
*/
static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
sigset_t *set, struct pt_regs *regs)
static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
struct pt_regs *regs)
{
struct rt_sigframe *frame;
unsigned long return_ip;
int err = 0;

frame = get_sigframe(ka, regs, sizeof(*frame));
frame = get_sigframe(&ksig->ka, regs, sizeof(*frame));

if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
goto give_sigsegv;
return -EFAULT;

/* Create siginfo. */
if (ka->sa.sa_flags & SA_SIGINFO)
err |= copy_siginfo_to_user(&frame->info, info);
if (ksig->ka.sa.sa_flags & SA_SIGINFO)
err |= copy_siginfo_to_user(&frame->info, &ksig->info);

/* Create the ucontext. */
err |= __put_user(0, &frame->uc.uc_flags);
Expand All @@ -190,7 +191,7 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));

if (err)
goto give_sigsegv;
return -EFAULT;

/* trampoline - the desired return ip is the retcode itself */
return_ip = (unsigned long)&frame->retcode;
Expand All @@ -204,40 +205,31 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
err |= __put_user(0x15000000, (unsigned long *)(frame->retcode + 8));

if (err)
goto give_sigsegv;
return -EFAULT;

/* TODO what is the current->exec_domain stuff and invmap ? */

/* Set up registers for signal handler */
regs->pc = (unsigned long)ka->sa.sa_handler; /* what we enter NOW */
regs->pc = (unsigned long)ksig->ka.sa.sa_handler; /* what we enter NOW */
regs->gpr[9] = (unsigned long)return_ip; /* what we enter LATER */
regs->gpr[3] = (unsigned long)sig; /* arg 1: signo */
regs->gpr[3] = (unsigned long)ksig->sig; /* arg 1: signo */
regs->gpr[4] = (unsigned long)&frame->info; /* arg 2: (siginfo_t*) */
regs->gpr[5] = (unsigned long)&frame->uc; /* arg 3: ucontext */

/* actually move the usp to reflect the stacked frame */
regs->sp = (unsigned long)frame;

return 0;

give_sigsegv:
force_sigsegv(sig, current);
return -EFAULT;
}

static inline void
handle_signal(unsigned long sig,
siginfo_t *info, struct k_sigaction *ka,
struct pt_regs *regs)
handle_signal(struct ksignal *ksig, struct pt_regs *regs)
{
int ret;

ret = setup_rt_frame(sig, ka, info, sigmask_to_save(), regs);
if (ret)
return;
ret = setup_rt_frame(ksig, sigmask_to_save(), regs);

signal_delivered(sig, info, ka, regs,
test_thread_flag(TIF_SINGLESTEP));
signal_setup_done(ret, ksig, test_thread_flag(TIF_SINGLESTEP));
}

/*
Expand All @@ -254,9 +246,7 @@ handle_signal(unsigned long sig,

int do_signal(struct pt_regs *regs, int syscall)
{
siginfo_t info;
int signr;
struct k_sigaction ka;
struct ksignal ksig;
unsigned long continue_addr = 0;
unsigned long restart_addr = 0;
unsigned long retval = 0;
Expand Down Expand Up @@ -286,28 +276,23 @@ int do_signal(struct pt_regs *regs, int syscall)
}

/*
* Get the signal to deliver. When running under ptrace, at this
* point the debugger may change all our registers ...
* 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.
*/
signr = get_signal_to_deliver(&info, &ka, regs, NULL);
/*
* Depending on the signal settings we may need to revert the
* decision to restart the system call. But skip this if a
* debugger has chosen to restart at a different PC.
*/
if (signr > 0) {
if (get_signal(&ksig)) {
if (unlikely(restart) && regs->pc == restart_addr) {
if (retval == -ERESTARTNOHAND ||
retval == -ERESTART_RESTARTBLOCK
|| (retval == -ERESTARTSYS
&& !(ka.sa.sa_flags & SA_RESTART))) {
&& !(ksig.ka.sa.sa_flags & SA_RESTART))) {
/* No automatic restart */
regs->gpr[11] = -EINTR;
regs->pc = continue_addr;
}
}

handle_signal(signr, &info, &ka, regs);
handle_signal(&ksig, regs);
} else {
/* no handler */
restore_saved_sigmask();
Expand Down

0 comments on commit 548dafe

Please sign in to comment.