1 /* signal.c: FRV specific bits of signal handling
3 * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 * - Derived from arch/m68k/kernel/signal.c
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 #include <linux/sched.h>
15 #include <linux/smp.h>
16 #include <linux/kernel.h>
17 #include <linux/signal.h>
18 #include <linux/errno.h>
19 #include <linux/wait.h>
20 #include <linux/ptrace.h>
21 #include <linux/unistd.h>
22 #include <linux/personality.h>
23 #include <linux/freezer.h>
24 #include <linux/tracehook.h>
25 #include <asm/ucontext.h>
26 #include <asm/uaccess.h>
27 #include <asm/cacheflush.h>
31 struct fdpic_func_descriptor {
37 * Atomically swap in the new signal mask, and wait for a signal.
39 asmlinkage int sys_sigsuspend(int history0, int history1, old_sigset_t mask)
42 siginitset(&blocked, mask);
43 return sigsuspend(&blocked);
46 asmlinkage int sys_sigaction(int sig,
47 const struct old_sigaction __user *act,
48 struct old_sigaction __user *oact)
50 struct k_sigaction new_ka, old_ka;
55 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
56 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
57 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) ||
58 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
59 __get_user(mask, &act->sa_mask))
61 siginitset(&new_ka.sa.sa_mask, mask);
64 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
67 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
68 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
69 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) ||
70 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
71 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
79 int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss)
81 return do_sigaltstack(uss, uoss, __frame->sp);
86 * Do a signal return; undo the signal stack.
91 __sigrestore_t pretcode;
94 unsigned long extramask[_NSIG_WORDS-1];
100 __sigrestore_t pretcode;
102 struct siginfo __user *pinfo;
109 static int restore_sigcontext(struct sigcontext __user *sc, int *_gr8)
111 struct user_context *user = current->thread.user;
112 unsigned long tbr, psr;
114 /* Always make any pending restarted system calls return -EINTR */
115 current_thread_info()->restart_block.fn = do_no_restart_syscall;
119 if (copy_from_user(user, &sc->sc_context, sizeof(sc->sc_context)))
124 restore_user_regs(user);
126 user->i.syscallno = -1; /* disable syscall checks */
128 *_gr8 = user->i.gr[8];
135 asmlinkage int sys_sigreturn(void)
137 struct sigframe __user *frame = (struct sigframe __user *) __frame->sp;
141 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
143 if (__get_user(set.sig[0], &frame->sc.sc_oldmask))
146 if (_NSIG_WORDS > 1 &&
147 __copy_from_user(&set.sig[1], &frame->extramask, sizeof(frame->extramask)))
150 set_current_blocked(&set);
152 if (restore_sigcontext(&frame->sc, &gr8))
157 force_sig(SIGSEGV, current);
161 asmlinkage int sys_rt_sigreturn(void)
163 struct rt_sigframe __user *frame = (struct rt_sigframe __user *) __frame->sp;
167 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
169 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
172 set_current_blocked(&set);
174 if (restore_sigcontext(&frame->uc.uc_mcontext, &gr8))
177 if (do_sigaltstack(&frame->uc.uc_stack, NULL, __frame->sp) == -EFAULT)
183 force_sig(SIGSEGV, current);
188 * Set up a signal frame
190 static int setup_sigcontext(struct sigcontext __user *sc, unsigned long mask)
192 save_user_regs(current->thread.user);
194 if (copy_to_user(&sc->sc_context, current->thread.user, sizeof(sc->sc_context)) != 0)
197 /* non-iBCS2 extensions.. */
198 if (__put_user(mask, &sc->sc_oldmask) < 0)
207 /*****************************************************************************/
209 * Determine which stack to use..
211 static inline void __user *get_sigframe(struct k_sigaction *ka,
216 /* Default to using normal stack */
219 /* This is the X/Open sanctioned signal stack switching. */
220 if (ka->sa.sa_flags & SA_ONSTACK) {
221 if (! sas_ss_flags(sp))
222 sp = current->sas_ss_sp + current->sas_ss_size;
225 return (void __user *) ((sp - frame_size) & ~7UL);
227 } /* end get_sigframe() */
229 /*****************************************************************************/
233 static int setup_frame(int sig, struct k_sigaction *ka, sigset_t *set)
235 struct sigframe __user *frame;
240 frame = get_sigframe(ka, sizeof(*frame));
242 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
247 __current_thread_info->exec_domain &&
248 __current_thread_info->exec_domain->signal_invmap)
249 rsig = __current_thread_info->exec_domain->signal_invmap[sig];
251 if (__put_user(rsig, &frame->sig) < 0)
254 if (setup_sigcontext(&frame->sc, set->sig[0]))
257 if (_NSIG_WORDS > 1) {
258 if (__copy_to_user(frame->extramask, &set->sig[1],
259 sizeof(frame->extramask)))
263 /* Set up to return from userspace. If provided, use a stub
264 * already in userspace. */
265 if (ka->sa.sa_flags & SA_RESTORER) {
266 if (__put_user(ka->sa.sa_restorer, &frame->pretcode) < 0)
270 /* Set up the following code on the stack:
271 * setlos #__NR_sigreturn,gr7
274 if (__put_user((__sigrestore_t)frame->retcode, &frame->pretcode) ||
275 __put_user(0x8efc0000|__NR_sigreturn, &frame->retcode[0]) ||
276 __put_user(0xc0700000, &frame->retcode[1]))
279 flush_icache_range((unsigned long) frame->retcode,
280 (unsigned long) (frame->retcode + 2));
283 /* Set up registers for the signal handler */
284 if (current->personality & FDPIC_FUNCPTRS) {
285 struct fdpic_func_descriptor __user *funcptr =
286 (struct fdpic_func_descriptor __user *) ka->sa.sa_handler;
287 struct fdpic_func_descriptor desc;
288 if (copy_from_user(&desc, funcptr, sizeof(desc)))
290 __frame->pc = desc.text;
291 __frame->gr15 = desc.GOT;
293 __frame->pc = (unsigned long) ka->sa.sa_handler;
297 __frame->sp = (unsigned long) frame;
298 __frame->lr = (unsigned long) &frame->retcode;
301 /* the tracer may want to single-step inside the handler */
302 if (test_thread_flag(TIF_SINGLESTEP))
303 ptrace_notify(SIGTRAP);
306 printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
307 sig, current->comm, current->pid, frame, __frame->pc,
314 force_sigsegv(sig, current);
317 } /* end setup_frame() */
319 /*****************************************************************************/
323 static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
326 struct rt_sigframe __user *frame;
331 frame = get_sigframe(ka, sizeof(*frame));
333 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
338 __current_thread_info->exec_domain &&
339 __current_thread_info->exec_domain->signal_invmap)
340 rsig = __current_thread_info->exec_domain->signal_invmap[sig];
342 if (__put_user(rsig, &frame->sig) ||
343 __put_user(&frame->info, &frame->pinfo) ||
344 __put_user(&frame->uc, &frame->puc))
347 if (copy_siginfo_to_user(&frame->info, info))
350 /* Create the ucontext. */
351 if (__put_user(0, &frame->uc.uc_flags) ||
352 __put_user(NULL, &frame->uc.uc_link) ||
353 __put_user((void __user *)current->sas_ss_sp, &frame->uc.uc_stack.ss_sp) ||
354 __put_user(sas_ss_flags(__frame->sp), &frame->uc.uc_stack.ss_flags) ||
355 __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size))
358 if (setup_sigcontext(&frame->uc.uc_mcontext, set->sig[0]))
361 if (__copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)))
364 /* Set up to return from userspace. If provided, use a stub
365 * already in userspace. */
366 if (ka->sa.sa_flags & SA_RESTORER) {
367 if (__put_user(ka->sa.sa_restorer, &frame->pretcode))
371 /* Set up the following code on the stack:
372 * setlos #__NR_sigreturn,gr7
375 if (__put_user((__sigrestore_t)frame->retcode, &frame->pretcode) ||
376 __put_user(0x8efc0000|__NR_rt_sigreturn, &frame->retcode[0]) ||
377 __put_user(0xc0700000, &frame->retcode[1]))
380 flush_icache_range((unsigned long) frame->retcode,
381 (unsigned long) (frame->retcode + 2));
384 /* Set up registers for signal handler */
385 if (current->personality & FDPIC_FUNCPTRS) {
386 struct fdpic_func_descriptor __user *funcptr =
387 (struct fdpic_func_descriptor __user *) ka->sa.sa_handler;
388 struct fdpic_func_descriptor desc;
389 if (copy_from_user(&desc, funcptr, sizeof(desc)))
391 __frame->pc = desc.text;
392 __frame->gr15 = desc.GOT;
394 __frame->pc = (unsigned long) ka->sa.sa_handler;
398 __frame->sp = (unsigned long) frame;
399 __frame->lr = (unsigned long) &frame->retcode;
401 __frame->gr9 = (unsigned long) &frame->info;
403 /* the tracer may want to single-step inside the handler */
404 if (test_thread_flag(TIF_SINGLESTEP))
405 ptrace_notify(SIGTRAP);
408 printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
409 sig, current->comm, current->pid, frame, __frame->pc,
416 force_sigsegv(sig, current);
419 } /* end setup_rt_frame() */
421 /*****************************************************************************/
423 * OK, we're invoking a handler
425 static void handle_signal(unsigned long sig, siginfo_t *info,
426 struct k_sigaction *ka)
428 sigset_t *oldset = sigmask_to_save();
431 /* Are we from a system call? */
432 if (__frame->syscallno != -1) {
433 /* If so, check system call restarting.. */
434 switch (__frame->gr8) {
435 case -ERESTART_RESTARTBLOCK:
436 case -ERESTARTNOHAND:
437 __frame->gr8 = -EINTR;
441 if (!(ka->sa.sa_flags & SA_RESTART)) {
442 __frame->gr8 = -EINTR;
447 case -ERESTARTNOINTR:
448 __frame->gr8 = __frame->orig_gr8;
451 __frame->syscallno = -1;
454 /* Set up the stack frame */
455 if (ka->sa.sa_flags & SA_SIGINFO)
456 ret = setup_rt_frame(sig, ka, info, oldset);
458 ret = setup_frame(sig, ka, oldset);
463 signal_delivered(sig, info, ka, __frame,
464 test_thread_flag(TIF_SINGLESTEP));
465 } /* end handle_signal() */
467 /*****************************************************************************/
469 * Note that 'init' is a special process: it doesn't get signals it doesn't
470 * want to handle. Thus you cannot kill init even with a SIGKILL even by
473 static void do_signal(void)
475 struct k_sigaction ka;
479 signr = get_signal_to_deliver(&info, &ka, __frame, NULL);
481 handle_signal(signr, &info, &ka);
485 /* Did we come from a system call? */
486 if (__frame->syscallno != -1) {
487 /* Restart the system call - no handlers present */
488 switch (__frame->gr8) {
489 case -ERESTARTNOHAND:
491 case -ERESTARTNOINTR:
492 __frame->gr8 = __frame->orig_gr8;
496 case -ERESTART_RESTARTBLOCK:
497 __frame->gr7 = __NR_restart_syscall;
501 __frame->syscallno = -1;
504 /* if there's no signal to deliver, we just put the saved sigmask
506 restore_saved_sigmask();
507 } /* end do_signal() */
509 /*****************************************************************************/
511 * notification of userspace execution resumption
512 * - triggered by the TIF_WORK_MASK flags
514 asmlinkage void do_notify_resume(__u32 thread_info_flags)
516 /* pending single-step? */
517 if (thread_info_flags & _TIF_SINGLESTEP)
518 clear_thread_flag(TIF_SINGLESTEP);
520 /* deal with pending signal delivery */
521 if (thread_info_flags & _TIF_SIGPENDING))
524 /* deal with notification on about to resume userspace execution */
525 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
526 clear_thread_flag(TIF_NOTIFY_RESUME);
527 tracehook_notify_resume(__frame);
530 } /* end do_notify_resume() */