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 set_current_blocked(&set
);
114 if (restore_sigcontext(regs
, &frame
->uc
.uc_mcontext
, &result
))
117 if (do_sigaltstack(&frame
->uc
.uc_stack
, NULL
, regs
->spu
) == -EFAULT
)
123 force_sig(SIGSEGV
, current
);
128 * Set up a signal frame.
132 setup_sigcontext(struct sigcontext __user
*sc
, struct pt_regs
*regs
,
137 #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x)
154 COPY(acc1h
); /* ISA_DSP_LEVEL2 only */
155 COPY(acc1l
); /* ISA_DSP_LEVEL2 only */
166 err
|= __put_user(mask
, &sc
->oldmask
);
172 * Determine which stack to use..
174 static inline void __user
*
175 get_sigframe(struct k_sigaction
*ka
, unsigned long sp
, size_t frame_size
)
177 /* This is the X/Open sanctioned signal stack switching. */
178 if (ka
->sa
.sa_flags
& SA_ONSTACK
) {
179 if (sas_ss_flags(sp
) == 0)
180 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
183 return (void __user
*)((sp
- frame_size
) & -8ul);
186 static int setup_rt_frame(int sig
, struct k_sigaction
*ka
, siginfo_t
*info
,
187 sigset_t
*set
, struct pt_regs
*regs
)
189 struct rt_sigframe __user
*frame
;
193 frame
= get_sigframe(ka
, regs
->spu
, sizeof(*frame
));
195 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
198 signal
= current_thread_info()->exec_domain
199 && current_thread_info()->exec_domain
->signal_invmap
201 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
204 err
|= __put_user(signal
, &frame
->sig
);
208 err
|= __put_user(&frame
->info
, &frame
->pinfo
);
209 err
|= __put_user(&frame
->uc
, &frame
->puc
);
210 err
|= copy_siginfo_to_user(&frame
->info
, info
);
214 /* Create the ucontext. */
215 err
|= __put_user(0, &frame
->uc
.uc_flags
);
216 err
|= __put_user(0, &frame
->uc
.uc_link
);
217 err
|= __put_user(current
->sas_ss_sp
, &frame
->uc
.uc_stack
.ss_sp
);
218 err
|= __put_user(sas_ss_flags(regs
->spu
),
219 &frame
->uc
.uc_stack
.ss_flags
);
220 err
|= __put_user(current
->sas_ss_size
, &frame
->uc
.uc_stack
.ss_size
);
221 err
|= setup_sigcontext(&frame
->uc
.uc_mcontext
, regs
, set
->sig
[0]);
222 err
|= __copy_to_user(&frame
->uc
.uc_sigmask
, set
, sizeof(*set
));
226 /* Set up to return from userspace. */
227 regs
->lr
= (unsigned long)ka
->sa
.sa_restorer
;
229 /* Set up registers for signal handler */
230 regs
->spu
= (unsigned long)frame
;
231 regs
->r0
= signal
; /* Arg for signal handler */
232 regs
->r1
= (unsigned long)&frame
->info
;
233 regs
->r2
= (unsigned long)&frame
->uc
;
234 regs
->bpc
= (unsigned long)ka
->sa
.sa_handler
;
239 printk("SIG deliver (%s:%d): sp=%p pc=%p\n",
240 current
->comm
, current
->pid
, frame
, regs
->pc
);
246 force_sigsegv(sig
, current
);
250 static int prev_insn(struct pt_regs
*regs
)
253 if (get_user(inst
, (u16 __user
*)(regs
->bpc
- 2)))
255 if ((inst
& 0xfff0) == 0x10f0) /* trap ? */
259 regs
->syscall_nr
= -1;
264 * OK, we're invoking a handler
268 handle_signal(unsigned long sig
, struct k_sigaction
*ka
, siginfo_t
*info
,
269 struct pt_regs
*regs
)
271 /* Are we from a system call? */
272 if (regs
->syscall_nr
>= 0) {
273 /* If so, check system call restarting.. */
275 case -ERESTART_RESTARTBLOCK
:
276 case -ERESTARTNOHAND
:
281 if (!(ka
->sa
.sa_flags
& SA_RESTART
)) {
286 case -ERESTARTNOINTR
:
287 regs
->r0
= regs
->orig_r0
;
288 if (prev_insn(regs
) < 0)
293 /* Set up the stack frame */
294 if (setup_rt_frame(sig
, ka
, info
, sigmask_to_save(), regs
))
297 signal_delivered(sig
, info
, ka
, regs
, 0);
301 * Note that 'init' is a special process: it doesn't get signals it doesn't
302 * want to handle. Thus you cannot kill init even with a SIGKILL even by
305 static void do_signal(struct pt_regs
*regs
)
309 struct k_sigaction ka
;
312 * We want the common case to go fast, which
313 * is why we may in certain cases get here from
314 * kernel mode. Just return without doing anything
317 if (!user_mode(regs
))
320 signr
= get_signal_to_deliver(&info
, &ka
, regs
, NULL
);
322 /* Re-enable any watchpoints before delivering the
323 * signal to user space. The processor register will
324 * have been cleared if the watchpoint triggered
328 /* Whee! Actually deliver the signal. */
329 handle_signal(signr
, &ka
, &info
, regs
);
334 /* Did we come from a system call? */
335 if (regs
->syscall_nr
>= 0) {
336 /* Restart the system call - no handlers present */
337 if (regs
->r0
== -ERESTARTNOHAND
||
338 regs
->r0
== -ERESTARTSYS
||
339 regs
->r0
== -ERESTARTNOINTR
) {
340 regs
->r0
= regs
->orig_r0
;
342 } else if (regs
->r0
== -ERESTART_RESTARTBLOCK
){
343 regs
->r0
= regs
->orig_r0
;
344 regs
->r7
= __NR_restart_syscall
;
348 restore_saved_sigmask();
352 * notification of userspace execution resumption
353 * - triggered by current->work.notify_resume
355 void do_notify_resume(struct pt_regs
*regs
, __u32 thread_info_flags
)
357 /* Pending single-step? */
358 if (thread_info_flags
& _TIF_SINGLESTEP
)
359 clear_thread_flag(TIF_SINGLESTEP
);
361 /* deal with pending signal delivery */
362 if (thread_info_flags
& _TIF_SIGPENDING
)
365 if (thread_info_flags
& _TIF_NOTIFY_RESUME
) {
366 clear_thread_flag(TIF_NOTIFY_RESUME
);
367 tracehook_notify_resume(regs
);
370 clear_thread_flag(TIF_IRET
);