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/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/unistd.h>
21 #include <linux/stddef.h>
22 #include <linux/personality.h>
23 #include <linux/freezer.h>
24 #include <linux/tracehook.h>
25 #include <asm/cacheflush.h>
26 #include <asm/ucontext.h>
27 #include <asm/uaccess.h>
32 sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
33 unsigned long r2, unsigned long r3, unsigned long r4,
34 unsigned long r5, unsigned long r6, struct pt_regs *regs)
36 return do_sigaltstack(uss, uoss, regs->spu);
41 * Do a signal return; undo the signal stack.
47 struct siginfo __user *pinfo;
51 // struct _fpstate fpstate;
55 restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
60 /* Always make any pending restarted system calls return -EINTR */
61 current_thread_info()->restart_block.fn = do_no_restart_syscall;
63 #define COPY(x) err |= __get_user(regs->x, &sc->sc_##x)
68 /* COPY(r0); Skip r0 */
80 COPY(acc1h); /* ISA_DSP_LEVEL2 only */
81 COPY(acc1l); /* ISA_DSP_LEVEL2 only */
92 regs->syscall_nr = -1; /* disable syscall checks */
93 err |= __get_user(*r0_p, &sc->sc_r0);
99 sys_rt_sigreturn(unsigned long r0, unsigned long r1,
100 unsigned long r2, unsigned long r3, unsigned long r4,
101 unsigned long r5, unsigned long r6, struct pt_regs *regs)
103 struct rt_sigframe __user *frame = (struct rt_sigframe __user *)regs->spu;
107 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
109 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
112 sigdelsetmask(&set, ~_BLOCKABLE);
113 spin_lock_irq(¤t->sighand->siglock);
114 current->blocked = set;
116 spin_unlock_irq(¤t->sighand->siglock);
118 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &result))
121 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->spu) == -EFAULT)
127 force_sig(SIGSEGV, current);
132 * Set up a signal frame.
136 setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
141 #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x)
158 COPY(acc1h); /* ISA_DSP_LEVEL2 only */
159 COPY(acc1l); /* ISA_DSP_LEVEL2 only */
170 err |= __put_user(mask, &sc->oldmask);
176 * Determine which stack to use..
178 static inline void __user *
179 get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
181 /* This is the X/Open sanctioned signal stack switching. */
182 if (ka->sa.sa_flags & SA_ONSTACK) {
183 if (sas_ss_flags(sp) == 0)
184 sp = current->sas_ss_sp + current->sas_ss_size;
187 return (void __user *)((sp - frame_size) & -8ul);
190 static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
191 sigset_t *set, struct pt_regs *regs)
193 struct rt_sigframe __user *frame;
197 frame = get_sigframe(ka, regs->spu, sizeof(*frame));
199 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
202 signal = current_thread_info()->exec_domain
203 && current_thread_info()->exec_domain->signal_invmap
205 ? current_thread_info()->exec_domain->signal_invmap[sig]
208 err |= __put_user(signal, &frame->sig);
212 err |= __put_user(&frame->info, &frame->pinfo);
213 err |= __put_user(&frame->uc, &frame->puc);
214 err |= copy_siginfo_to_user(&frame->info, info);
218 /* Create the ucontext. */
219 err |= __put_user(0, &frame->uc.uc_flags);
220 err |= __put_user(0, &frame->uc.uc_link);
221 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
222 err |= __put_user(sas_ss_flags(regs->spu),
223 &frame->uc.uc_stack.ss_flags);
224 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
225 err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0]);
226 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
230 /* Set up to return from userspace. */
231 regs->lr = (unsigned long)ka->sa.sa_restorer;
233 /* Set up registers for signal handler */
234 regs->spu = (unsigned long)frame;
235 regs->r0 = signal; /* Arg for signal handler */
236 regs->r1 = (unsigned long)&frame->info;
237 regs->r2 = (unsigned long)&frame->uc;
238 regs->bpc = (unsigned long)ka->sa.sa_handler;
243 printk("SIG deliver (%s:%d): sp=%p pc=%p\n",
244 current->comm, current->pid, frame, regs->pc);
250 force_sigsegv(sig, current);
254 static int prev_insn(struct pt_regs *regs)
257 if (get_user(&inst, (u16 __user *)(regs->bpc - 2)))
259 if ((inst & 0xfff0) == 0x10f0) /* trap ? */
263 regs->syscall_nr = -1;
268 * OK, we're invoking a handler
272 handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
273 sigset_t *oldset, struct pt_regs *regs)
275 /* Are we from a system call? */
276 if (regs->syscall_nr >= 0) {
277 /* If so, check system call restarting.. */
279 case -ERESTART_RESTARTBLOCK:
280 case -ERESTARTNOHAND:
285 if (!(ka->sa.sa_flags & SA_RESTART)) {
290 case -ERESTARTNOINTR:
291 regs->r0 = regs->orig_r0;
292 if (prev_insn(regs) < 0)
297 /* Set up the stack frame */
298 if (setup_rt_frame(sig, ka, info, oldset, regs))
301 spin_lock_irq(¤t->sighand->siglock);
302 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
303 if (!(ka->sa.sa_flags & SA_NODEFER))
304 sigaddset(¤t->blocked,sig);
306 spin_unlock_irq(¤t->sighand->siglock);
311 * Note that 'init' is a special process: it doesn't get signals it doesn't
312 * want to handle. Thus you cannot kill init even with a SIGKILL even by
315 static void do_signal(struct pt_regs *regs)
319 struct k_sigaction ka;
323 * We want the common case to go fast, which
324 * is why we may in certain cases get here from
325 * kernel mode. Just return without doing anything
328 if (!user_mode(regs))
334 if (test_thread_flag(TIF_RESTORE_SIGMASK))
335 oldset = ¤t->saved_sigmask;
337 oldset = ¤t->blocked;
339 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
341 /* Re-enable any watchpoints before delivering the
342 * signal to user space. The processor register will
343 * have been cleared if the watchpoint triggered
347 /* Whee! Actually deliver the signal. */
348 if (handle_signal(signr, &ka, &info, oldset, regs) == 0)
349 clear_thread_flag(TIF_RESTORE_SIGMASK);
355 /* Did we come from a system call? */
356 if (regs->syscall_nr >= 0) {
357 /* Restart the system call - no handlers present */
358 if (regs->r0 == -ERESTARTNOHAND ||
359 regs->r0 == -ERESTARTSYS ||
360 regs->r0 == -ERESTARTNOINTR) {
361 regs->r0 = regs->orig_r0;
363 } else if (regs->r0 == -ERESTART_RESTARTBLOCK){
364 regs->r0 = regs->orig_r0;
365 regs->r7 = __NR_restart_syscall;
369 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
370 clear_thread_flag(TIF_RESTORE_SIGMASK);
371 sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL);
376 * notification of userspace execution resumption
377 * - triggered by current->work.notify_resume
379 void do_notify_resume(struct pt_regs *regs, __u32 thread_info_flags)
381 /* Pending single-step? */
382 if (thread_info_flags & _TIF_SINGLESTEP)
383 clear_thread_flag(TIF_SINGLESTEP);
385 /* deal with pending signal delivery */
386 if (thread_info_flags & _TIF_SIGPENDING)
389 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
390 clear_thread_flag(TIF_NOTIFY_RESUME);
391 tracehook_notify_resume(regs);
392 if (current->replacement_session_keyring)
393 key_replace_session_keyring();
396 clear_thread_flag(TIF_IRET);