sh: Use get_signal() signal_setup_done()

Use the more generic functions get_signal() signal_setup_done()
for signal delivery.

Signed-off-by: Richard Weinberger <richard@nod.at>
This commit is contained in:
Richard Weinberger 2013-10-07 14:51:14 +02:00 committed by Richard Weinberger
parent 2bb12b773f
commit b46e848768
2 changed files with 64 additions and 97 deletions

View File

@ -262,17 +262,17 @@ get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
extern void __kernel_sigreturn(void); extern void __kernel_sigreturn(void);
extern void __kernel_rt_sigreturn(void); extern void __kernel_rt_sigreturn(void);
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;
int err = 0; int err = 0, sig = ksig->sig;
int signal; int signal;
frame = get_sigframe(ka, regs->regs[15], sizeof(*frame)); frame = get_sigframe(&ksig->ka, regs->regs[15], sizeof(*frame));
if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
goto give_sigsegv; return -EFAULT;
signal = current_thread_info()->exec_domain signal = current_thread_info()->exec_domain
&& current_thread_info()->exec_domain->signal_invmap && current_thread_info()->exec_domain->signal_invmap
@ -288,8 +288,8 @@ static int setup_frame(int sig, struct k_sigaction *ka,
/* 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) {
regs->pr = (unsigned long) ka->sa.sa_restorer; regs->pr = (unsigned long) ksig->ka.sa.sa_restorer;
#ifdef CONFIG_VSYSCALL #ifdef CONFIG_VSYSCALL
} else if (likely(current->mm->context.vdso)) { } else if (likely(current->mm->context.vdso)) {
regs->pr = VDSO_SYM(&__kernel_sigreturn); regs->pr = VDSO_SYM(&__kernel_sigreturn);
@ -309,7 +309,7 @@ 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->regs[15] = (unsigned long) frame; regs->regs[15] = (unsigned long) frame;
@ -319,15 +319,15 @@ static int setup_frame(int sig, struct k_sigaction *ka,
if (current->personality & FDPIC_FUNCPTRS) { if (current->personality & FDPIC_FUNCPTRS) {
struct fdpic_func_descriptor __user *funcptr = struct fdpic_func_descriptor __user *funcptr =
(struct fdpic_func_descriptor __user *)ka->sa.sa_handler; (struct fdpic_func_descriptor __user *)ksig->ka.sa.sa_handler;
err |= __get_user(regs->pc, &funcptr->text); err |= __get_user(regs->pc, &funcptr->text);
err |= __get_user(regs->regs[12], &funcptr->GOT); err |= __get_user(regs->regs[12], &funcptr->GOT);
} else } else
regs->pc = (unsigned long)ka->sa.sa_handler; regs->pc = (unsigned long)ksig->ka.sa.sa_handler;
if (err) if (err)
goto give_sigsegv; return -EFAULT;
set_fs(USER_DS); set_fs(USER_DS);
@ -335,23 +335,19 @@ static int setup_frame(int sig, struct k_sigaction *ka,
current->comm, task_pid_nr(current), frame, regs->pc, regs->pr); current->comm, task_pid_nr(current), frame, regs->pc, regs->pr);
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;
int err = 0; int err = 0, sig = ksig->sig;
int signal; int signal;
frame = get_sigframe(ka, regs->regs[15], sizeof(*frame)); frame = get_sigframe(&ksig->ka, regs->regs[15], sizeof(*frame));
if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
goto give_sigsegv; return -EFAULT;
signal = current_thread_info()->exec_domain signal = current_thread_info()->exec_domain
&& current_thread_info()->exec_domain->signal_invmap && current_thread_info()->exec_domain->signal_invmap
@ -359,7 +355,7 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
? current_thread_info()->exec_domain->signal_invmap[sig] ? current_thread_info()->exec_domain->signal_invmap[sig]
: sig; : sig;
err |= copy_siginfo_to_user(&frame->info, info); err |= copy_siginfo_to_user(&frame->info, &ksig->info);
/* Create the ucontext. */ /* Create the ucontext. */
err |= __put_user(0, &frame->uc.uc_flags); err |= __put_user(0, &frame->uc.uc_flags);
@ -371,8 +367,8 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
/* 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) {
regs->pr = (unsigned long) ka->sa.sa_restorer; regs->pr = (unsigned long) ksig->ka.sa.sa_restorer;
#ifdef CONFIG_VSYSCALL #ifdef CONFIG_VSYSCALL
} else if (likely(current->mm->context.vdso)) { } else if (likely(current->mm->context.vdso)) {
regs->pr = VDSO_SYM(&__kernel_rt_sigreturn); regs->pr = VDSO_SYM(&__kernel_rt_sigreturn);
@ -392,7 +388,7 @@ static int 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 */
regs->regs[15] = (unsigned long) frame; regs->regs[15] = (unsigned long) frame;
@ -402,15 +398,15 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
if (current->personality & FDPIC_FUNCPTRS) { if (current->personality & FDPIC_FUNCPTRS) {
struct fdpic_func_descriptor __user *funcptr = struct fdpic_func_descriptor __user *funcptr =
(struct fdpic_func_descriptor __user *)ka->sa.sa_handler; (struct fdpic_func_descriptor __user *)ksig->ka.sa.sa_handler;
err |= __get_user(regs->pc, &funcptr->text); err |= __get_user(regs->pc, &funcptr->text);
err |= __get_user(regs->regs[12], &funcptr->GOT); err |= __get_user(regs->regs[12], &funcptr->GOT);
} else } else
regs->pc = (unsigned long)ka->sa.sa_handler; regs->pc = (unsigned long)ksig->ka.sa.sa_handler;
if (err) if (err)
goto give_sigsegv; return -EFAULT;
set_fs(USER_DS); set_fs(USER_DS);
@ -418,10 +414,6 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
current->comm, task_pid_nr(current), frame, regs->pc, regs->pr); current->comm, task_pid_nr(current), frame, regs->pc, regs->pr);
return 0; return 0;
give_sigsegv:
force_sigsegv(sig, current);
return -EFAULT;
} }
static inline void static inline void
@ -455,22 +447,18 @@ handle_syscall_restart(unsigned long save_r0, struct pt_regs *regs,
* OK, we're invoking a handler * OK, we're invoking a handler
*/ */
static void static void
handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info, handle_signal(struct ksignal *ksig, struct pt_regs *regs, unsigned int save_r0)
struct pt_regs *regs, unsigned int save_r0)
{ {
sigset_t *oldset = sigmask_to_save(); sigset_t *oldset = sigmask_to_save();
int ret; int ret;
/* 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) signal_setup_done(ret, ksig, test_thread_flag(TIF_SINGLESTEP));
return;
signal_delivered(sig, info, ka, regs,
test_thread_flag(TIF_SINGLESTEP));
} }
/* /*
@ -484,9 +472,7 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
*/ */
static void do_signal(struct pt_regs *regs, unsigned int save_r0) static void do_signal(struct pt_regs *regs, unsigned int save_r0)
{ {
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
@ -497,12 +483,11 @@ static void do_signal(struct pt_regs *regs, unsigned int save_r0)
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) { handle_syscall_restart(save_r0, regs, &ksig.ka.sa);
handle_syscall_restart(save_r0, regs, &ka.sa);
/* Whee! Actually deliver the signal. */ /* Whee! Actually deliver the signal. */
handle_signal(signr, &ka, &info, regs, save_r0); handle_signal(&ksig, regs, save_r0);
return; return;
} }

View File

@ -41,8 +41,7 @@
#define DEBUG_SIG 0 #define DEBUG_SIG 0
static void static void
handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, handle_signal(struct ksignal *ksig, struct pt_regs *regs);
struct pt_regs * regs);
static inline void static inline void
handle_syscall_restart(struct pt_regs *regs, struct sigaction *sa) handle_syscall_restart(struct pt_regs *regs, struct sigaction *sa)
@ -82,9 +81,7 @@ handle_syscall_restart(struct pt_regs *regs, struct sigaction *sa)
*/ */
static void do_signal(struct pt_regs *regs) static void do_signal(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
@ -95,12 +92,11 @@ static void do_signal(struct pt_regs *regs)
if (!user_mode(regs)) if (!user_mode(regs))
return; return;
signr = get_signal_to_deliver(&info, &ka, regs, 0); if (get_signal(&ksig)) {
if (signr > 0) { handle_syscall_restart(regs, &ksig.ka.sa);
handle_syscall_restart(regs, &ka.sa);
/* Whee! Actually deliver the signal. */ /* Whee! Actually deliver the signal. */
handle_signal(signr, &info, &ka, regs); handle_signal(&ksig, regs);
return; return;
} }
@ -378,17 +374,16 @@ get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
void sa_default_restorer(void); /* See comments below */ void sa_default_restorer(void); /* See comments below */
void sa_default_rt_restorer(void); /* See comments below */ void sa_default_rt_restorer(void); /* See comments below */
static int setup_frame(int sig, struct k_sigaction *ka, static int setup_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs)
sigset_t *set, struct pt_regs *regs)
{ {
struct sigframe __user *frame; struct sigframe __user *frame;
int err = 0; int err = 0, sig = ksig->sig;
int signal; int signal;
frame = get_sigframe(ka, regs->regs[REG_SP], sizeof(*frame)); frame = get_sigframe(&ksig->ka, regs->regs[REG_SP], sizeof(*frame));
if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
goto give_sigsegv; return -EFAULT;
signal = current_thread_info()->exec_domain signal = current_thread_info()->exec_domain
&& current_thread_info()->exec_domain->signal_invmap && current_thread_info()->exec_domain->signal_invmap
@ -400,7 +395,7 @@ static int setup_frame(int sig, struct k_sigaction *ka,
/* Give up earlier as i386, in case */ /* Give up earlier as i386, in case */
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],
@ -408,16 +403,16 @@ static int setup_frame(int sig, struct k_sigaction *ka,
/* Give up earlier as i386, in case */ /* Give up earlier as i386, in case */
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) {
/* /*
* On SH5 all edited pointers are subject to NEFF * On SH5 all edited pointers are subject to NEFF
*/ */
DEREF_REG_PR = neff_sign_extend((unsigned long) DEREF_REG_PR = neff_sign_extend((unsigned long)
ka->sa.sa_restorer | 0x1); ksig->ka->sa.sa_restorer | 0x1);
} else { } else {
/* /*
* Different approach on SH5. * Different approach on SH5.
@ -435,7 +430,7 @@ static int setup_frame(int sig, struct k_sigaction *ka,
if (__copy_to_user(frame->retcode, if (__copy_to_user(frame->retcode,
(void *)((unsigned long)sa_default_restorer & (~1)), 16) != 0) (void *)((unsigned long)sa_default_restorer & (~1)), 16) != 0)
goto give_sigsegv; return -EFAULT;
/* Cohere the trampoline with the I-cache. */ /* Cohere the trampoline with the I-cache. */
flush_cache_sigtramp(DEREF_REG_PR-1); flush_cache_sigtramp(DEREF_REG_PR-1);
@ -460,7 +455,7 @@ static int setup_frame(int sig, struct k_sigaction *ka,
regs->regs[REG_ARG2] = (unsigned long long)(unsigned long)(signed long)&frame->sc; regs->regs[REG_ARG2] = (unsigned long long)(unsigned long)(signed long)&frame->sc;
regs->regs[REG_ARG3] = (unsigned long long)(unsigned long)(signed long)&frame->sc; regs->regs[REG_ARG3] = (unsigned long long)(unsigned long)(signed long)&frame->sc;
regs->pc = neff_sign_extend((unsigned long)ka->sa.sa_handler); regs->pc = neff_sign_extend((unsigned long)ksig->ka.sa.sa_handler);
set_fs(USER_DS); set_fs(USER_DS);
@ -471,23 +466,19 @@ static int setup_frame(int sig, struct k_sigaction *ka,
DEREF_REG_PR >> 32, DEREF_REG_PR & 0xffffffff); DEREF_REG_PR >> 32, DEREF_REG_PR & 0xffffffff);
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 *kig, sigset_t *set,
sigset_t *set, struct pt_regs *regs) struct pt_regs *regs)
{ {
struct rt_sigframe __user *frame; struct rt_sigframe __user *frame;
int err = 0; int err = 0, sig = ksig->sig;
int signal; int signal;
frame = get_sigframe(ka, regs->regs[REG_SP], sizeof(*frame)); frame = get_sigframe(&ksig->ka, regs->regs[REG_SP], sizeof(*frame));
if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
goto give_sigsegv; return -EFAULT;
signal = current_thread_info()->exec_domain signal = current_thread_info()->exec_domain
&& current_thread_info()->exec_domain->signal_invmap && current_thread_info()->exec_domain->signal_invmap
@ -497,11 +488,11 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
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);
/* Give up earlier as i386, in case */ /* Give up earlier as i386, in case */
if (err) if (err)
goto give_sigsegv; return -EFAULT;
/* Create the ucontext. */ /* Create the ucontext. */
err |= __put_user(0, &frame->uc.uc_flags); err |= __put_user(0, &frame->uc.uc_flags);
@ -513,16 +504,16 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
/* Give up earlier as i386, in case */ /* Give up earlier as i386, in case */
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) {
/* /*
* On SH5 all edited pointers are subject to NEFF * On SH5 all edited pointers are subject to NEFF
*/ */
DEREF_REG_PR = neff_sign_extend((unsigned long) DEREF_REG_PR = neff_sign_extend((unsigned long)
ka->sa.sa_restorer | 0x1); ksig->ka.sa.sa_restorer | 0x1);
} else { } else {
/* /*
* Different approach on SH5. * Different approach on SH5.
@ -540,7 +531,7 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
if (__copy_to_user(frame->retcode, if (__copy_to_user(frame->retcode,
(void *)((unsigned long)sa_default_rt_restorer & (~1)), 16) != 0) (void *)((unsigned long)sa_default_rt_restorer & (~1)), 16) != 0)
goto give_sigsegv; return -EFAULT;
/* Cohere the trampoline with the I-cache. */ /* Cohere the trampoline with the I-cache. */
flush_icache_range(DEREF_REG_PR-1, DEREF_REG_PR-1+15); flush_icache_range(DEREF_REG_PR-1, DEREF_REG_PR-1+15);
@ -554,7 +545,7 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
regs->regs[REG_ARG1] = signal; /* Arg for signal handler */ regs->regs[REG_ARG1] = signal; /* Arg for signal handler */
regs->regs[REG_ARG2] = (unsigned long long)(unsigned long)(signed long)&frame->info; regs->regs[REG_ARG2] = (unsigned long long)(unsigned long)(signed long)&frame->info;
regs->regs[REG_ARG3] = (unsigned long long)(unsigned long)(signed long)&frame->uc.uc_mcontext; regs->regs[REG_ARG3] = (unsigned long long)(unsigned long)(signed long)&frame->uc.uc_mcontext;
regs->pc = neff_sign_extend((unsigned long)ka->sa.sa_handler); regs->pc = neff_sign_extend((unsigned long)ksig->ka.sa.sa_handler);
set_fs(USER_DS); set_fs(USER_DS);
@ -564,33 +555,24 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
DEREF_REG_PR >> 32, DEREF_REG_PR & 0xffffffff); DEREF_REG_PR >> 32, DEREF_REG_PR & 0xffffffff);
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 void static void
handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, handle_signal(struct ksignal *ksig, struct pt_regs *regs)
struct pt_regs * regs)
{ {
sigset_t *oldset = sigmask_to_save(); sigset_t *oldset = sigmask_to_save();
int ret; int ret;
/* 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) signal_setup_done(ret, ksig, test_thread_flag(TIF_SINGLESTEP));
return;
signal_delivered(sig, info, ka, regs,
test_thread_flag(TIF_SINGLESTEP));
} }
asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags) asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)