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/tracehook.h>
24 #include <asm/cacheflush.h>
25 #include <asm/ucontext.h>
26 #include <asm/uaccess.h>
31 * Do a signal return; undo the signal stack.
37 struct siginfo __user *pinfo;
41 // struct _fpstate fpstate;
45 restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
50 /* Always make any pending restarted system calls return -EINTR */
51 current->restart_block.fn = do_no_restart_syscall;
53 #define COPY(x) err |= __get_user(regs->x, &sc->sc_##x)
58 /* COPY(r0); Skip r0 */
70 COPY(acc1h); /* ISA_DSP_LEVEL2 only */
71 COPY(acc1l); /* ISA_DSP_LEVEL2 only */
82 regs->syscall_nr = -1; /* disable syscall checks */
83 err |= __get_user(*r0_p, &sc->sc_r0);
89 sys_rt_sigreturn(unsigned long r0, unsigned long r1,
90 unsigned long r2, unsigned long r3, unsigned long r4,
91 unsigned long r5, unsigned long r6, struct pt_regs *regs)
93 struct rt_sigframe __user *frame = (struct rt_sigframe __user *)regs->spu;
97 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
99 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
102 set_current_blocked(&set);
104 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &result))
107 if (restore_altstack(&frame->uc.uc_stack))
113 force_sig(SIGSEGV, current);
118 * Set up a signal frame.
122 setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
127 #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x)
144 COPY(acc1h); /* ISA_DSP_LEVEL2 only */
145 COPY(acc1l); /* ISA_DSP_LEVEL2 only */
156 err |= __put_user(mask, &sc->oldmask);
162 * Determine which stack to use..
164 static inline void __user *
165 get_sigframe(struct ksignal *ksig, unsigned long sp, size_t frame_size)
167 return (void __user *)((sigsp(sp, ksig) - frame_size) & -8ul);
170 static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
171 struct pt_regs *regs)
173 struct rt_sigframe __user *frame;
177 frame = get_sigframe(ksig, regs->spu, sizeof(*frame));
179 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
182 err |= __put_user(sig, &frame->sig);
186 err |= __put_user(&frame->info, &frame->pinfo);
187 err |= __put_user(&frame->uc, &frame->puc);
188 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
192 /* Create the ucontext. */
193 err |= __put_user(0, &frame->uc.uc_flags);
194 err |= __put_user(0, &frame->uc.uc_link);
195 err |= __save_altstack(&frame->uc.uc_stack, regs->spu);
196 err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0]);
197 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
201 /* Set up to return from userspace. */
202 regs->lr = (unsigned long)ksig->ka.sa.sa_restorer;
204 /* Set up registers for signal handler */
205 regs->spu = (unsigned long)frame;
206 regs->r0 = sig; /* Arg for signal handler */
207 regs->r1 = (unsigned long)&frame->info;
208 regs->r2 = (unsigned long)&frame->uc;
209 regs->bpc = (unsigned long)ksig->ka.sa.sa_handler;
212 printk("SIG deliver (%s:%d): sp=%p pc=%p\n",
213 current->comm, current->pid, frame, regs->pc);
219 static int prev_insn(struct pt_regs *regs)
222 if (get_user(inst, (u16 __user *)(regs->bpc - 2)))
224 if ((inst & 0xfff0) == 0x10f0) /* trap ? */
228 regs->syscall_nr = -1;
233 * OK, we're invoking a handler
237 handle_signal(struct ksignal *ksig, struct pt_regs *regs)
241 /* Are we from a system call? */
242 if (regs->syscall_nr >= 0) {
243 /* If so, check system call restarting.. */
245 case -ERESTART_RESTARTBLOCK:
246 case -ERESTARTNOHAND:
251 if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
256 case -ERESTARTNOINTR:
257 regs->r0 = regs->orig_r0;
258 if (prev_insn(regs) < 0)
263 /* Set up the stack frame */
264 ret = setup_rt_frame(ksig, sigmask_to_save(), regs);
266 signal_setup_done(ret, ksig, 0);
270 * Note that 'init' is a special process: it doesn't get signals it doesn't
271 * want to handle. Thus you cannot kill init even with a SIGKILL even by
274 static void do_signal(struct pt_regs *regs)
279 * We want the common case to go fast, which
280 * is why we may in certain cases get here from
281 * kernel mode. Just return without doing anything
284 if (!user_mode(regs))
287 if (get_signal(&ksig)) {
288 /* Re-enable any watchpoints before delivering the
289 * signal to user space. The processor register will
290 * have been cleared if the watchpoint triggered
294 /* Whee! Actually deliver the signal. */
295 handle_signal(&ksig, regs);
300 /* Did we come from a system call? */
301 if (regs->syscall_nr >= 0) {
302 /* Restart the system call - no handlers present */
303 if (regs->r0 == -ERESTARTNOHAND ||
304 regs->r0 == -ERESTARTSYS ||
305 regs->r0 == -ERESTARTNOINTR) {
306 regs->r0 = regs->orig_r0;
308 } else if (regs->r0 == -ERESTART_RESTARTBLOCK){
309 regs->r0 = regs->orig_r0;
310 regs->r7 = __NR_restart_syscall;
314 restore_saved_sigmask();
318 * notification of userspace execution resumption
319 * - triggered by current->work.notify_resume
321 void do_notify_resume(struct pt_regs *regs, __u32 thread_info_flags)
323 /* Pending single-step? */
324 if (thread_info_flags & _TIF_SINGLESTEP)
325 clear_thread_flag(TIF_SINGLESTEP);
327 /* deal with pending signal delivery */
328 if (thread_info_flags & _TIF_SIGPENDING)
331 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
332 clear_thread_flag(TIF_NOTIFY_RESUME);
333 tracehook_notify_resume(regs);