Skip to content

Commit

Permalink
metag: 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.

[James Hogan: avoid reordering get_signal() and restart check.]

Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: James Hogan <james.hogan@imgtec.com>
  • Loading branch information
Richard Weinberger authored and James Hogan committed Mar 18, 2014
1 parent cca7c66 commit d3c7e51
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions arch/metag/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,18 @@ static void __user *get_sigframe(struct k_sigaction *ka, unsigned long sp,
return (void __user *)sp;
}

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 __user *frame;
int err = -EFAULT;
int err;
unsigned long code;

frame = get_sigframe(ka, regs->REG_SP, sizeof(*frame));
frame = get_sigframe(&ksig->ka, regs->REG_SP, sizeof(*frame));
if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
goto out;
return -EFAULT;

err = copy_siginfo_to_user(&frame->info, info);
err = copy_siginfo_to_user(&frame->info, &ksig->info);

/* Create the ucontext. */
err |= __put_user(0, &frame->uc.uc_flags);
Expand All @@ -174,7 +174,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 out;
return -EFAULT;

/* Set up to return from userspace. */

Expand All @@ -187,15 +187,15 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
err |= __put_user(code, (unsigned long __user *)(&frame->retcode[1]));

if (err)
goto out;
return -EFAULT;

/* Set up registers for signal handler */
regs->REG_RTP = (unsigned long) frame->retcode;
regs->REG_SP = (unsigned long) frame + sizeof(*frame);
regs->REG_ARG1 = sig;
regs->REG_ARG1 = ksig->sig;
regs->REG_ARG2 = (unsigned long) &frame->info;
regs->REG_ARG3 = (unsigned long) &frame->uc;
regs->REG_PC = (unsigned long) ka->sa.sa_handler;
regs->REG_PC = (unsigned long) ksig->ka.sa.sa_handler;

pr_debug("SIG deliver (%s:%d): sp=%p pc=%08x pr=%08x\n",
current->comm, current->pid, frame, regs->REG_PC,
Expand All @@ -205,24 +205,19 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
* effective cache flush - directed rather than 'full flush'.
*/
flush_cache_sigtramp(regs->REG_RTP, sizeof(frame->retcode));
out:
if (err) {
force_sigsegv(sig, current);
return -EFAULT;
}

return 0;
}

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

/* Set up the stack frame */
if (setup_rt_frame(sig, ka, info, oldset, regs))
return;
ret = setup_rt_frame(ksig, oldset, regs);

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

/*
Expand All @@ -235,10 +230,8 @@ static void handle_signal(unsigned long sig, siginfo_t *info,
static int do_signal(struct pt_regs *regs, int syscall)
{
unsigned int retval = 0, continue_addr = 0, restart_addr = 0;
struct k_sigaction ka;
siginfo_t info;
int signr;
int restart = 0;
struct ksignal ksig;

/*
* By the end of rt_sigreturn the context describes the point that the
Expand Down Expand Up @@ -275,27 +268,28 @@ static 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 ...
*/
signr = get_signal_to_deliver(&info, &ka, regs, NULL);
get_signal(&ksig);

/*
* 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 (regs->REG_PC != restart_addr)
restart = 0;
if (signr > 0) {
if (ksig.sig > 0) {
if (unlikely(restart)) {
if (retval == -ERESTARTNOHAND
|| retval == -ERESTART_RESTARTBLOCK
|| (retval == -ERESTARTSYS
&& !(ka.sa.sa_flags & SA_RESTART))) {
&& !(ksig.ka.sa.sa_flags & SA_RESTART))) {
regs->REG_RETVAL = -EINTR;
regs->REG_PC = continue_addr;
}
}

/* Whee! Actually deliver the signal. */
handle_signal(signr, &info, &ka, regs);
handle_signal(&ksig, regs);
return 0;
}

Expand Down

0 comments on commit d3c7e51

Please sign in to comment.