Commit fa019772 authored by Richard Weinberger's avatar Richard Weinberger Committed by Richard Weinberger

cris: Use get_signal() signal_setup_done()

Use the more generic functions get_signal() signal_setup_done()
for signal delivery.
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
parent e19c025b
...@@ -228,33 +228,33 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size) ...@@ -228,33 +228,33 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size)
* user-mode trampoline. * user-mode trampoline.
*/ */
static int setup_frame(int sig, struct k_sigaction *ka, static int setup_frame(struct ksignal *ksig, sigset_t *set,
sigset_t *set, struct pt_regs *regs) struct pt_regs *regs)
{ {
struct sigframe __user *frame; struct sigframe __user *frame;
unsigned long return_ip; unsigned long return_ip;
int err = 0; 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))) if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
goto give_sigsegv; return -EFAULT;
err |= setup_sigcontext(&frame->sc, regs, set->sig[0]); err |= setup_sigcontext(&frame->sc, regs, set->sig[0]);
if (err) if (err)
goto give_sigsegv; return -EFAULT;
if (_NSIG_WORDS > 1) { if (_NSIG_WORDS > 1) {
err |= __copy_to_user(frame->extramask, &set->sig[1], err |= __copy_to_user(frame->extramask, &set->sig[1],
sizeof(frame->extramask)); sizeof(frame->extramask));
} }
if (err) if (err)
goto give_sigsegv; return -EFAULT;
/* Set up to return from userspace. If provided, use a stub /* Set up to return from userspace. If provided, use a stub
already in userspace. */ already in userspace. */
if (ka->sa.sa_flags & SA_RESTORER) { if (ksig->ka.sa.sa_flags & SA_RESTORER) {
return_ip = (unsigned long)ka->sa.sa_restorer; return_ip = (unsigned long)ksig->ka.sa.sa_restorer;
} else { } else {
/* trampoline - the desired return ip is the retcode itself */ /* trampoline - the desired return ip is the retcode itself */
return_ip = (unsigned long)&frame->retcode; return_ip = (unsigned long)&frame->retcode;
...@@ -265,42 +265,38 @@ static int setup_frame(int sig, struct k_sigaction *ka, ...@@ -265,42 +265,38 @@ static int setup_frame(int sig, struct k_sigaction *ka,
} }
if (err) if (err)
goto give_sigsegv; return -EFAULT;
/* Set up registers for signal handler */ /* Set up registers for signal handler */
regs->irp = (unsigned long) ka->sa.sa_handler; /* what we enter NOW */ regs->irp = (unsigned long) ksig->ka.sa.sa_handler; /* what we enter NOW */
regs->srp = return_ip; /* what we enter LATER */ regs->srp = return_ip; /* what we enter LATER */
regs->r10 = sig; /* first argument is signo */ regs->r10 = ksig->sig; /* first argument is signo */
/* actually move the usp to reflect the stacked frame */ /* actually move the usp to reflect the stacked frame */
wrusp((unsigned long)frame); wrusp((unsigned long)frame);
return 0; return 0;
give_sigsegv:
force_sigsegv(sig, current);
return -EFAULT;
} }
static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
sigset_t *set, struct pt_regs *regs) struct pt_regs *regs)
{ {
struct rt_sigframe __user *frame; struct rt_sigframe __user *frame;
unsigned long return_ip; unsigned long return_ip;
int err = 0; 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))) if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
goto give_sigsegv; return -EFAULT;
err |= __put_user(&frame->info, &frame->pinfo); err |= __put_user(&frame->info, &frame->pinfo);
err |= __put_user(&frame->uc, &frame->puc); err |= __put_user(&frame->uc, &frame->puc);
err |= copy_siginfo_to_user(&frame->info, info); err |= copy_siginfo_to_user(&frame->info, &ksig->info);
if (err) if (err)
goto give_sigsegv; return -EFAULT;
/* Clear all the bits of the ucontext we don't use. */ /* Clear all the bits of the ucontext we don't use. */
err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext)); err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext));
...@@ -312,12 +308,12 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -312,12 +308,12 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
err |= __save_altstack(&frame->uc.uc_stack, rdusp()); err |= __save_altstack(&frame->uc.uc_stack, rdusp());
if (err) if (err)
goto give_sigsegv; return -EFAULT;
/* Set up to return from userspace. If provided, use a stub /* Set up to return from userspace. If provided, use a stub
already in userspace. */ already in userspace. */
if (ka->sa.sa_flags & SA_RESTORER) { if (ksig->ka.sa.sa_flags & SA_RESTORER) {
return_ip = (unsigned long)ka->sa.sa_restorer; return_ip = (unsigned long)ksig->ka.sa.sa_restorer;
} else { } else {
/* trampoline - the desired return ip is the retcode itself */ /* trampoline - the desired return ip is the retcode itself */
return_ip = (unsigned long)&frame->retcode; return_ip = (unsigned long)&frame->retcode;
...@@ -329,18 +325,18 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -329,18 +325,18 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
} }
if (err) if (err)
goto give_sigsegv; return -EFAULT;
/* TODO what is the current->exec_domain stuff and invmap ? */ /* TODO what is the current->exec_domain stuff and invmap ? */
/* Set up registers for signal handler */ /* Set up registers for signal handler */
/* What we enter NOW */ /* What we enter NOW */
regs->irp = (unsigned long) ka->sa.sa_handler; regs->irp = (unsigned long) ksig->ka.sa.sa_handler;
/* What we enter LATER */ /* What we enter LATER */
regs->srp = return_ip; regs->srp = return_ip;
/* First argument is signo */ /* First argument is signo */
regs->r10 = sig; regs->r10 = ksig->sig;
/* Second argument is (siginfo_t *) */ /* Second argument is (siginfo_t *) */
regs->r11 = (unsigned long)&frame->info; regs->r11 = (unsigned long)&frame->info;
/* Third argument is unused */ /* Third argument is unused */
...@@ -350,19 +346,14 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -350,19 +346,14 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
wrusp((unsigned long)frame); wrusp((unsigned long)frame);
return 0; return 0;
give_sigsegv:
force_sigsegv(sig, current);
return -EFAULT;
} }
/* /*
* OK, we're invoking a handler * OK, we're invoking a handler
*/ */
static inline void handle_signal(int canrestart, unsigned long sig, static inline void handle_signal(int canrestart, struct ksignal *ksig,
siginfo_t *info, struct k_sigaction *ka, struct pt_regs *regs)
struct pt_regs *regs)
{ {
sigset_t *oldset = sigmask_to_save(); sigset_t *oldset = sigmask_to_save();
int ret; int ret;
...@@ -383,7 +374,7 @@ static inline void handle_signal(int canrestart, unsigned long sig, ...@@ -383,7 +374,7 @@ static inline void handle_signal(int canrestart, unsigned long sig,
/* ERESTARTSYS means to restart the syscall if /* ERESTARTSYS means to restart the syscall if
* there is no handler or the handler was * there is no handler or the handler was
* registered with SA_RESTART */ * registered with SA_RESTART */
if (!(ka->sa.sa_flags & SA_RESTART)) { if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
regs->r10 = -EINTR; regs->r10 = -EINTR;
break; break;
} }
...@@ -396,13 +387,12 @@ static inline void handle_signal(int canrestart, unsigned long sig, ...@@ -396,13 +387,12 @@ static inline void handle_signal(int canrestart, unsigned long sig,
} }
/* Set up the stack frame */ /* Set up the stack frame */
if (ka->sa.sa_flags & SA_SIGINFO) if (ksig->ka.sa.sa_flags & SA_SIGINFO)
ret = setup_rt_frame(sig, ka, info, oldset, regs); ret = setup_rt_frame(ksig, oldset, regs);
else else
ret = setup_frame(sig, ka, oldset, regs); ret = setup_frame(ksig, oldset, regs);
if (ret == 0) signal_setup_done(ret, ksig, 0);
signal_delivered(sig, info, ka, regs, 0);
} }
/* /*
...@@ -419,9 +409,7 @@ static inline void handle_signal(int canrestart, unsigned long sig, ...@@ -419,9 +409,7 @@ static inline void handle_signal(int canrestart, unsigned long sig,
void do_signal(int canrestart, struct pt_regs *regs) void do_signal(int canrestart, struct pt_regs *regs)
{ {
siginfo_t info; struct ksignal ksig;
int signr;
struct k_sigaction ka;
/* /*
* We want the common case to go fast, which * We want the common case to go fast, which
...@@ -432,10 +420,9 @@ void do_signal(int canrestart, struct pt_regs *regs) ...@@ -432,10 +420,9 @@ void do_signal(int canrestart, struct pt_regs *regs)
if (!user_mode(regs)) if (!user_mode(regs))
return; return;
signr = get_signal_to_deliver(&info, &ka, regs, NULL); if (get_signal(&ksig)) {
if (signr > 0) {
/* Whee! Actually deliver the signal. */ /* Whee! Actually deliver the signal. */
handle_signal(canrestart, signr, &info, &ka, regs); handle_signal(canrestart, &ksig, regs);
return; return;
} }
......
...@@ -215,23 +215,22 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size) ...@@ -215,23 +215,22 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
* trampoline. * trampoline.
*/ */
static int static int
setup_frame(int sig, struct k_sigaction *ka, sigset_t *set, setup_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs)
struct pt_regs * regs)
{ {
int err; int err;
unsigned long return_ip; unsigned long return_ip;
struct signal_frame __user *frame; struct signal_frame __user *frame;
err = 0; 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))) if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
goto give_sigsegv; return -EFAULT;
err |= setup_sigcontext(&frame->sc, regs, set->sig[0]); err |= setup_sigcontext(&frame->sc, regs, set->sig[0]);
if (err) if (err)
goto give_sigsegv; return -EFAULT;
if (_NSIG_WORDS > 1) { if (_NSIG_WORDS > 1) {
err |= __copy_to_user(frame->extramask, &set->sig[1], err |= __copy_to_user(frame->extramask, &set->sig[1],
...@@ -239,14 +238,14 @@ setup_frame(int sig, struct k_sigaction *ka, sigset_t *set, ...@@ -239,14 +238,14 @@ setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
} }
if (err) if (err)
goto give_sigsegv; return -EFAULT;
/* /*
* Set up to return from user-space. If provided, use a stub * Set up to return from user-space. If provided, use a stub
* already located in user-space. * already located in user-space.
*/ */
if (ka->sa.sa_flags & SA_RESTORER) { if (ksig->ka.sa.sa_flags & SA_RESTORER) {
return_ip = (unsigned long)ka->sa.sa_restorer; return_ip = (unsigned long)ksig->ka.sa.sa_restorer;
} else { } else {
/* Trampoline - the desired return ip is in the signal return page. */ /* Trampoline - the desired return ip is in the signal return page. */
return_ip = cris_signal_return_page; return_ip = cris_signal_return_page;
...@@ -264,7 +263,7 @@ setup_frame(int sig, struct k_sigaction *ka, sigset_t *set, ...@@ -264,7 +263,7 @@ setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
} }
if (err) if (err)
goto give_sigsegv; return -EFAULT;
/* /*
* Set up registers for signal handler. * Set up registers for signal handler.
...@@ -273,42 +272,37 @@ setup_frame(int sig, struct k_sigaction *ka, sigset_t *set, ...@@ -273,42 +272,37 @@ setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
* Where the code enter later. * Where the code enter later.
* First argument, signo. * First argument, signo.
*/ */
regs->erp = (unsigned long) ka->sa.sa_handler; regs->erp = (unsigned long) ksig->ka.sa.sa_handler;
regs->srp = return_ip; regs->srp = return_ip;
regs->r10 = sig; regs->r10 = ksig->sig;
/* Actually move the USP to reflect the stacked frame. */ /* Actually move the USP to reflect the stacked frame. */
wrusp((unsigned long)frame); wrusp((unsigned long)frame);
return 0; return 0;
give_sigsegv:
force_sigsegv(sig, current);
return -EFAULT;
} }
static int static int
setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs)
sigset_t *set, struct pt_regs * regs)
{ {
int err; int err;
unsigned long return_ip; unsigned long return_ip;
struct rt_signal_frame __user *frame; struct rt_signal_frame __user *frame;
err = 0; 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))) if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
goto give_sigsegv; return -EFAULT;
/* TODO: what is the current->exec_domain stuff and invmap ? */ /* TODO: what is the current->exec_domain stuff and invmap ? */
err |= __put_user(&frame->info, &frame->pinfo); err |= __put_user(&frame->info, &frame->pinfo);
err |= __put_user(&frame->uc, &frame->puc); err |= __put_user(&frame->uc, &frame->puc);
err |= copy_siginfo_to_user(&frame->info, info); err |= copy_siginfo_to_user(&frame->info, &ksig->info);
if (err) if (err)
goto give_sigsegv; return -EFAULT;
/* Clear all the bits of the ucontext we don't use. */ /* Clear all the bits of the ucontext we don't use. */
err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext)); err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext));
...@@ -317,14 +311,14 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -317,14 +311,14 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
err |= __save_altstack(&frame->uc.uc_stack, rdusp()); err |= __save_altstack(&frame->uc.uc_stack, rdusp());
if (err) if (err)
goto give_sigsegv; return -EFAULT;
/* /*
* Set up to return from user-space. If provided, use a stub * Set up to return from user-space. If provided, use a stub
* already located in user-space. * already located in user-space.
*/ */
if (ka->sa.sa_flags & SA_RESTORER) { if (ksig->ka.sa.sa_flags & SA_RESTORER) {
return_ip = (unsigned long) ka->sa.sa_restorer; return_ip = (unsigned long) ksig->ka.sa.sa_restorer;
} else { } else {
/* Trampoline - the desired return ip is in the signal return page. */ /* Trampoline - the desired return ip is in the signal return page. */
return_ip = cris_signal_return_page + 6; return_ip = cris_signal_return_page + 6;
...@@ -345,7 +339,7 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -345,7 +339,7 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
} }
if (err) if (err)
goto give_sigsegv; return -EFAULT;
/* /*
* Set up registers for signal handler. * Set up registers for signal handler.
...@@ -356,9 +350,9 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -356,9 +350,9 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
* Second argument is (siginfo_t *). * Second argument is (siginfo_t *).
* Third argument is unused. * Third argument is unused.
*/ */
regs->erp = (unsigned long) ka->sa.sa_handler; regs->erp = (unsigned long) ksig->ka.sa.sa_handler;
regs->srp = return_ip; regs->srp = return_ip;
regs->r10 = sig; regs->r10 = ksig->sig;
regs->r11 = (unsigned long) &frame->info; regs->r11 = (unsigned long) &frame->info;
regs->r12 = 0; regs->r12 = 0;
...@@ -366,17 +360,11 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, ...@@ -366,17 +360,11 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
wrusp((unsigned long)frame); wrusp((unsigned long)frame);
return 0; return 0;
give_sigsegv:
force_sigsegv(sig, current);
return -EFAULT;
} }
/* Invoke a signal handler to, well, handle the signal. */ /* Invoke a signal handler to, well, handle the signal. */
static inline void static inline void
handle_signal(int canrestart, unsigned long sig, handle_signal(int canrestart, struct ksignal *ksig, struct pt_regs *regs)
siginfo_t *info, struct k_sigaction *ka,
struct pt_regs * regs)
{ {
sigset_t *oldset = sigmask_to_save(); sigset_t *oldset = sigmask_to_save();
int ret; int ret;
...@@ -404,7 +392,7 @@ handle_signal(int canrestart, unsigned long sig, ...@@ -404,7 +392,7 @@ handle_signal(int canrestart, unsigned long sig,
* there is no handler, or the handler * there is no handler, or the handler
* was registered with SA_RESTART. * was registered with SA_RESTART.
*/ */
if (!(ka->sa.sa_flags & SA_RESTART)) { if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
regs->r10 = -EINTR; regs->r10 = -EINTR;
break; break;
} }
...@@ -423,13 +411,12 @@ handle_signal(int canrestart, unsigned long sig, ...@@ -423,13 +411,12 @@ handle_signal(int canrestart, unsigned long sig,
} }
/* Set up the stack frame. */ /* Set up the stack frame. */
if (ka->sa.sa_flags & SA_SIGINFO) if (ksig->ka.sa.sa_flags & SA_SIGINFO)
ret = setup_rt_frame(sig, ka, info, oldset, regs); ret = setup_rt_frame(ksig, oldset, regs);
else else
ret = setup_frame(sig, ka, oldset, regs); ret = setup_frame(ksig, oldset, regs);
if (ret == 0) signal_setup_done(ret, ksig, 0);
signal_delivered(sig, info, ka, regs, 0);
} }
/* /*
...@@ -446,9 +433,7 @@ handle_signal(int canrestart, unsigned long sig, ...@@ -446,9 +433,7 @@ handle_signal(int canrestart, unsigned long sig,
void void
do_signal(int canrestart, struct pt_regs *regs) do_signal(int canrestart, struct pt_regs *regs)
{ {
int signr; struct ksignal ksig;
siginfo_t info;
struct k_sigaction ka;
/* /*
* The common case should go fast, which is why this point is * The common case should go fast, which is why this point is
...@@ -458,11 +443,9 @@ do_signal(int canrestart, struct pt_regs *regs) ...@@ -458,11 +443,9 @@ do_signal(int canrestart, struct pt_regs *regs)
if (!user_mode(regs)) if (!user_mode(regs))
return; return;
signr = get_signal_to_deliver(&info, &ka, regs, NULL); if (get_signal(&ksig)) {
if (signr > 0) {
/* Whee! Actually deliver the signal. */ /* Whee! Actually deliver the signal. */
handle_signal(canrestart, signr, &info, &ka, regs); handle_signal(canrestart, &ksig, regs);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment