2 * linux/arch/m32r/kernel/signal.c
4 * Copyright (c) 2003 Hitoshi Yamamoto
6 * Taken from i386 version.
7 * Copyright (C) 1991, 1992 Linus Torvalds
9 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
10 * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes
13 #include <linux/config.h>
14 #include <linux/sched.h>
16 #include <linux/smp.h>
17 #include <linux/smp_lock.h>
18 #include <linux/kernel.h>
19 #include <linux/signal.h>
20 #include <linux/errno.h>
21 #include <linux/wait.h>
22 #include <linux/unistd.h>
23 #include <linux/stddef.h>
24 #include <linux/personality.h>
25 #include <linux/suspend.h>
26 #include <asm/cacheflush.h>
27 #include <asm/ucontext.h>
28 #include <asm/uaccess.h>
32 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
34 int do_signal(struct pt_regs *, sigset_t *);
37 * Atomically swap in the new signal mask, and wait for a signal.
40 sys_sigsuspend(old_sigset_t mask, unsigned long r1,
41 unsigned long r2, unsigned long r3, unsigned long r4,
42 unsigned long r5, unsigned long r6, struct pt_regs regs)
47 spin_lock_irq(¤t->sighand->siglock);
48 saveset = current->blocked;
49 siginitset(¤t->blocked, mask);
51 spin_unlock_irq(¤t->sighand->siglock);
55 current->state = TASK_INTERRUPTIBLE;
57 if (do_signal(®s, &saveset))
63 sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize,
64 unsigned long r2, unsigned long r3, unsigned long r4,
65 unsigned long r5, unsigned long r6, struct pt_regs regs)
67 sigset_t saveset, newset;
69 /* XXX: Don't preclude handling different sized sigset_t's. */
70 if (sigsetsize != sizeof(sigset_t))
73 if (copy_from_user(&newset, unewset, sizeof(newset)))
75 sigdelsetmask(&newset, ~_BLOCKABLE);
77 spin_lock_irq(¤t->sighand->siglock);
78 saveset = current->blocked;
79 current->blocked = newset;
81 spin_unlock_irq(¤t->sighand->siglock);
85 current->state = TASK_INTERRUPTIBLE;
87 if (do_signal(®s, &saveset))
93 sys_sigaction(int sig, const struct old_sigaction __user *act,
94 struct old_sigaction __user *oact)
96 struct k_sigaction new_ka, old_ka;
101 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
102 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
103 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
105 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
106 __get_user(mask, &act->sa_mask);
107 siginitset(&new_ka.sa.sa_mask, mask);
110 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
113 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
114 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
115 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
117 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
118 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
125 sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
126 unsigned long r2, unsigned long r3, unsigned long r4,
127 unsigned long r5, unsigned long r6, struct pt_regs regs)
129 return do_sigaltstack(uss, uoss, regs.spu);
134 * Do a signal return; undo the signal stack.
141 struct sigcontext sc;
142 // struct _fpstate fpstate;
143 unsigned long extramask[_NSIG_WORDS-1];
151 struct siginfo *pinfo;
155 // struct _fpstate fpstate;
160 restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
163 unsigned int err = 0;
165 /* Always make any pending restarted system calls return -EINTR */
166 current_thread_info()->restart_block.fn = do_no_restart_syscall;
168 #define COPY(x) err |= __get_user(regs->x, &sc->sc_##x)
173 /* COPY(r0); Skip r0 */
183 #if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
188 #elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
192 #error unknown isa configuration
204 regs->syscall_nr = -1; /* disable syscall checks */
205 err |= __get_user(*r0_p, &sc->sc_r0);
211 sys_sigreturn(unsigned long r0, unsigned long r1,
212 unsigned long r2, unsigned long r3, unsigned long r4,
213 unsigned long r5, unsigned long r6, struct pt_regs regs)
215 struct sigframe __user *frame = (struct sigframe __user *)regs.spu;
219 if (verify_area(VERIFY_READ, frame, sizeof(*frame)))
221 if (__get_user(set.sig[0], &frame->sc.oldmask)
223 && __copy_from_user(&set.sig[1], &frame->extramask,
224 sizeof(frame->extramask))))
227 sigdelsetmask(&set, ~_BLOCKABLE);
228 spin_lock_irq(¤t->sighand->siglock);
229 current->blocked = set;
231 spin_unlock_irq(¤t->sighand->siglock);
233 if (restore_sigcontext(®s, &frame->sc, &result))
238 force_sig(SIGSEGV, current);
243 sys_rt_sigreturn(unsigned long r0, unsigned long r1,
244 unsigned long r2, unsigned long r3, unsigned long r4,
245 unsigned long r5, unsigned long r6, struct pt_regs regs)
247 struct rt_sigframe __user *frame = (struct rt_sigframe __user *)regs.spu;
252 if (verify_area(VERIFY_READ, frame, sizeof(*frame)))
254 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
257 sigdelsetmask(&set, ~_BLOCKABLE);
258 spin_lock_irq(¤t->sighand->siglock);
259 current->blocked = set;
261 spin_unlock_irq(¤t->sighand->siglock);
263 if (restore_sigcontext(®s, &frame->uc.uc_mcontext, &result))
266 if (__copy_from_user(&st, &frame->uc.uc_stack, sizeof(st)))
268 /* It is more difficult to avoid calling this function than to
269 call it and ignore errors. */
270 do_sigaltstack(&st, NULL, regs.spu);
275 force_sig(SIGSEGV, current);
280 * Set up a signal frame.
284 setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
289 #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x)
304 #if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
309 #elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
313 #error unknown isa configuration
325 err |= __put_user(mask, &sc->oldmask);
331 * Determine which stack to use..
333 static inline void __user *
334 get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
336 /* This is the X/Open sanctioned signal stack switching. */
337 if (ka->sa.sa_flags & SA_ONSTACK) {
338 if (sas_ss_flags(sp) == 0)
339 sp = current->sas_ss_sp + current->sas_ss_size;
342 return (void __user *)((sp - frame_size) & -8ul);
345 static void setup_frame(int sig, struct k_sigaction *ka,
346 sigset_t *set, struct pt_regs *regs)
348 struct sigframe __user *frame;
352 frame = get_sigframe(ka, regs->spu, sizeof(*frame));
354 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
357 signal = current_thread_info()->exec_domain
358 && current_thread_info()->exec_domain->signal_invmap
360 ? current_thread_info()->exec_domain->signal_invmap[sig]
363 err |= __put_user(signal, &frame->sig);
367 err |= setup_sigcontext(&frame->sc, regs, set->sig[0]);
371 if (_NSIG_WORDS > 1) {
372 err |= __copy_to_user(frame->extramask, &set->sig[1],
373 sizeof(frame->extramask));
378 if (ka->sa.sa_flags & SA_RESTORER)
379 regs->lr = (unsigned long)ka->sa.sa_restorer;
381 /* This is : ldi r7, #__NR_sigreturn ; trap #2 */
382 unsigned long code = 0x670010f2 | (__NR_sigreturn << 16);
384 regs->lr = (unsigned long)frame->retcode;
385 err |= __put_user(code, (long __user *)(frame->retcode+0));
388 flush_cache_sigtramp((unsigned long)frame->retcode);
391 /* Set up registers for signal handler */
392 regs->spu = (unsigned long)frame;
393 regs->r0 = signal; /* Arg for signal handler */
394 regs->r1 = (unsigned long)&frame->sc;
395 regs->bpc = (unsigned long)ka->sa.sa_handler;
400 printk("SIG deliver (%s:%d): sp=%p pc=%p\n",
401 current->comm, current->pid, frame, regs->pc);
407 force_sigsegv(sig, current);
410 static void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
411 sigset_t *set, struct pt_regs *regs)
413 struct rt_sigframe __user *frame;
417 frame = get_sigframe(ka, regs->spu, sizeof(*frame));
419 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
422 signal = current_thread_info()->exec_domain
423 && current_thread_info()->exec_domain->signal_invmap
425 ? current_thread_info()->exec_domain->signal_invmap[sig]
428 err |= __put_user(signal, &frame->sig);
432 err |= __put_user(&frame->info, &frame->pinfo);
433 err |= __put_user(&frame->uc, &frame->puc);
434 err |= copy_siginfo_to_user(&frame->info, info);
438 /* Create the ucontext. */
439 err |= __put_user(0, &frame->uc.uc_flags);
440 err |= __put_user(0, &frame->uc.uc_link);
441 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
442 err |= __put_user(sas_ss_flags(regs->spu),
443 &frame->uc.uc_stack.ss_flags);
444 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
445 err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0]);
446 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
450 /* Set up to return from userspace. */
451 if (ka->sa.sa_flags & SA_RESTORER)
452 regs->lr = (unsigned long)ka->sa.sa_restorer;
454 /* This is : ldi r7, #__NR_rt_sigreturn ; trap #2 */
455 unsigned long code1 = 0x97f00000 | (__NR_rt_sigreturn);
456 unsigned long code2 = 0x10f2f000;
458 regs->lr = (unsigned long)frame->retcode;
459 err |= __put_user(code1, (long __user *)(frame->retcode+0));
460 err |= __put_user(code2, (long __user *)(frame->retcode+4));
463 flush_cache_sigtramp((unsigned long)frame->retcode);
466 /* Set up registers for signal handler */
467 regs->spu = (unsigned long)frame;
468 regs->r0 = signal; /* Arg for signal handler */
469 regs->r1 = (unsigned long)&frame->info;
470 regs->r2 = (unsigned long)&frame->uc;
471 regs->bpc = (unsigned long)ka->sa.sa_handler;
476 printk("SIG deliver (%s:%d): sp=%p pc=%p\n",
477 current->comm, current->pid, frame, regs->pc);
483 force_sigsegv(sig, current);
487 * OK, we're invoking a handler
491 handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
492 sigset_t *oldset, struct pt_regs *regs)
496 /* Are we from a system call? */
497 if (regs->syscall_nr >= 0) {
498 /* If so, check system call restarting.. */
500 case -ERESTART_RESTARTBLOCK:
501 case -ERESTARTNOHAND:
506 if (!(ka->sa.sa_flags & SA_RESTART)) {
511 case -ERESTARTNOINTR:
512 regs->r0 = regs->orig_r0;
513 inst = *(unsigned short *)(regs->bpc - 2);
514 if ((inst & 0xfff0) == 0x10f0) /* trap ? */
521 /* Set up the stack frame */
522 if (ka->sa.sa_flags & SA_SIGINFO)
523 setup_rt_frame(sig, ka, info, oldset, regs);
525 setup_frame(sig, ka, oldset, regs);
527 if (!(ka->sa.sa_flags & SA_NODEFER)) {
528 spin_lock_irq(¤t->sighand->siglock);
529 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
530 sigaddset(¤t->blocked,sig);
532 spin_unlock_irq(¤t->sighand->siglock);
537 * Note that 'init' is a special process: it doesn't get signals it doesn't
538 * want to handle. Thus you cannot kill init even with a SIGKILL even by
541 int do_signal(struct pt_regs *regs, sigset_t *oldset)
545 struct k_sigaction ka;
549 * We want the common case to go fast, which
550 * is why we may in certain cases get here from
551 * kernel mode. Just return without doing anything
554 if (!user_mode(regs))
557 if (current->flags & PF_FREEZE) {
563 oldset = ¤t->blocked;
565 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
567 /* Reenable any watchpoints before delivering the
568 * signal to user space. The processor register will
569 * have been cleared if the watchpoint triggered
573 /* Whee! Actually deliver the signal. */
574 handle_signal(signr, &ka, &info, oldset, regs);
579 /* Did we come from a system call? */
580 if (regs->syscall_nr >= 0) {
581 /* Restart the system call - no handlers present */
582 if (regs->r0 == -ERESTARTNOHAND ||
583 regs->r0 == -ERESTARTSYS ||
584 regs->r0 == -ERESTARTNOINTR) {
585 regs->r0 = regs->orig_r0;
586 inst = *(unsigned short *)(regs->bpc - 2);
587 if ((inst & 0xfff0) == 0x10f0) /* trap ? */
592 if (regs->r0 == -ERESTART_RESTARTBLOCK){
593 regs->r0 = regs->orig_r0;
594 regs->r7 = __NR_restart_syscall;
595 inst = *(unsigned short *)(regs->bpc - 2);
596 if ((inst & 0xfff0) == 0x10f0) /* trap ? */
606 * notification of userspace execution resumption
607 * - triggered by current->work.notify_resume
609 void do_notify_resume(struct pt_regs *regs, sigset_t *oldset,
610 __u32 thread_info_flags)
612 /* Pending single-step? */
613 if (thread_info_flags & _TIF_SINGLESTEP)
614 clear_thread_flag(TIF_SINGLESTEP);
616 /* deal with pending signal delivery */
617 if (thread_info_flags & _TIF_SIGPENDING)
618 do_signal(regs,oldset);
620 clear_thread_flag(TIF_IRET);