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>
31 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
34 sys_sigaltstack(const stack_t __user
*uss
, stack_t __user
*uoss
,
35 unsigned long r2
, unsigned long r3
, unsigned long r4
,
36 unsigned long r5
, unsigned long r6
, struct pt_regs
*regs
)
38 return do_sigaltstack(uss
, uoss
, regs
->spu
);
43 * Do a signal return; undo the signal stack.
49 struct siginfo __user
*pinfo
;
53 // struct _fpstate fpstate;
57 restore_sigcontext(struct pt_regs
*regs
, struct sigcontext __user
*sc
,
62 /* Always make any pending restarted system calls return -EINTR */
63 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
65 #define COPY(x) err |= __get_user(regs->x, &sc->sc_##x)
70 /* COPY(r0); Skip r0 */
82 COPY(acc1h
); /* ISA_DSP_LEVEL2 only */
83 COPY(acc1l
); /* ISA_DSP_LEVEL2 only */
94 regs
->syscall_nr
= -1; /* disable syscall checks */
95 err
|= __get_user(*r0_p
, &sc
->sc_r0
);
101 sys_rt_sigreturn(unsigned long r0
, unsigned long r1
,
102 unsigned long r2
, unsigned long r3
, unsigned long r4
,
103 unsigned long r5
, unsigned long r6
, struct pt_regs
*regs
)
105 struct rt_sigframe __user
*frame
= (struct rt_sigframe __user
*)regs
->spu
;
109 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
111 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
114 sigdelsetmask(&set
, ~_BLOCKABLE
);
115 set_current_blocked(&set
);
117 if (restore_sigcontext(regs
, &frame
->uc
.uc_mcontext
, &result
))
120 if (do_sigaltstack(&frame
->uc
.uc_stack
, NULL
, regs
->spu
) == -EFAULT
)
126 force_sig(SIGSEGV
, current
);
131 * Set up a signal frame.
135 setup_sigcontext(struct sigcontext __user
*sc
, struct pt_regs
*regs
,
140 #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x)
157 COPY(acc1h
); /* ISA_DSP_LEVEL2 only */
158 COPY(acc1l
); /* ISA_DSP_LEVEL2 only */
169 err
|= __put_user(mask
, &sc
->oldmask
);
175 * Determine which stack to use..
177 static inline void __user
*
178 get_sigframe(struct k_sigaction
*ka
, unsigned long sp
, size_t frame_size
)
180 /* This is the X/Open sanctioned signal stack switching. */
181 if (ka
->sa
.sa_flags
& SA_ONSTACK
) {
182 if (sas_ss_flags(sp
) == 0)
183 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
186 return (void __user
*)((sp
- frame_size
) & -8ul);
189 static int setup_rt_frame(int sig
, struct k_sigaction
*ka
, siginfo_t
*info
,
190 sigset_t
*set
, struct pt_regs
*regs
)
192 struct rt_sigframe __user
*frame
;
196 frame
= get_sigframe(ka
, regs
->spu
, sizeof(*frame
));
198 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
201 signal
= current_thread_info()->exec_domain
202 && current_thread_info()->exec_domain
->signal_invmap
204 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
207 err
|= __put_user(signal
, &frame
->sig
);
211 err
|= __put_user(&frame
->info
, &frame
->pinfo
);
212 err
|= __put_user(&frame
->uc
, &frame
->puc
);
213 err
|= copy_siginfo_to_user(&frame
->info
, info
);
217 /* Create the ucontext. */
218 err
|= __put_user(0, &frame
->uc
.uc_flags
);
219 err
|= __put_user(0, &frame
->uc
.uc_link
);
220 err
|= __put_user(current
->sas_ss_sp
, &frame
->uc
.uc_stack
.ss_sp
);
221 err
|= __put_user(sas_ss_flags(regs
->spu
),
222 &frame
->uc
.uc_stack
.ss_flags
);
223 err
|= __put_user(current
->sas_ss_size
, &frame
->uc
.uc_stack
.ss_size
);
224 err
|= setup_sigcontext(&frame
->uc
.uc_mcontext
, regs
, set
->sig
[0]);
225 err
|= __copy_to_user(&frame
->uc
.uc_sigmask
, set
, sizeof(*set
));
229 /* Set up to return from userspace. */
230 regs
->lr
= (unsigned long)ka
->sa
.sa_restorer
;
232 /* Set up registers for signal handler */
233 regs
->spu
= (unsigned long)frame
;
234 regs
->r0
= signal
; /* Arg for signal handler */
235 regs
->r1
= (unsigned long)&frame
->info
;
236 regs
->r2
= (unsigned long)&frame
->uc
;
237 regs
->bpc
= (unsigned long)ka
->sa
.sa_handler
;
242 printk("SIG deliver (%s:%d): sp=%p pc=%p\n",
243 current
->comm
, current
->pid
, frame
, regs
->pc
);
249 force_sigsegv(sig
, current
);
253 static int prev_insn(struct pt_regs
*regs
)
256 if (get_user(inst
, (u16 __user
*)(regs
->bpc
- 2)))
258 if ((inst
& 0xfff0) == 0x10f0) /* trap ? */
262 regs
->syscall_nr
= -1;
267 * OK, we're invoking a handler
271 handle_signal(unsigned long sig
, struct k_sigaction
*ka
, siginfo_t
*info
,
272 sigset_t
*oldset
, struct pt_regs
*regs
)
274 /* Are we from a system call? */
275 if (regs
->syscall_nr
>= 0) {
276 /* If so, check system call restarting.. */
278 case -ERESTART_RESTARTBLOCK
:
279 case -ERESTARTNOHAND
:
284 if (!(ka
->sa
.sa_flags
& SA_RESTART
)) {
289 case -ERESTARTNOINTR
:
290 regs
->r0
= regs
->orig_r0
;
291 if (prev_insn(regs
) < 0)
296 /* Set up the stack frame */
297 if (setup_rt_frame(sig
, ka
, info
, oldset
, regs
))
300 block_sigmask(ka
, sig
);
305 * Note that 'init' is a special process: it doesn't get signals it doesn't
306 * want to handle. Thus you cannot kill init even with a SIGKILL even by
309 static void do_signal(struct pt_regs
*regs
)
313 struct k_sigaction ka
;
317 * We want the common case to go fast, which
318 * is why we may in certain cases get here from
319 * kernel mode. Just return without doing anything
322 if (!user_mode(regs
))
328 if (test_thread_flag(TIF_RESTORE_SIGMASK
))
329 oldset
= ¤t
->saved_sigmask
;
331 oldset
= ¤t
->blocked
;
333 signr
= get_signal_to_deliver(&info
, &ka
, regs
, NULL
);
335 /* Re-enable any watchpoints before delivering the
336 * signal to user space. The processor register will
337 * have been cleared if the watchpoint triggered
341 /* Whee! Actually deliver the signal. */
342 if (handle_signal(signr
, &ka
, &info
, oldset
, regs
) == 0)
343 clear_thread_flag(TIF_RESTORE_SIGMASK
);
349 /* Did we come from a system call? */
350 if (regs
->syscall_nr
>= 0) {
351 /* Restart the system call - no handlers present */
352 if (regs
->r0
== -ERESTARTNOHAND
||
353 regs
->r0
== -ERESTARTSYS
||
354 regs
->r0
== -ERESTARTNOINTR
) {
355 regs
->r0
= regs
->orig_r0
;
357 } else if (regs
->r0
== -ERESTART_RESTARTBLOCK
){
358 regs
->r0
= regs
->orig_r0
;
359 regs
->r7
= __NR_restart_syscall
;
363 if (test_thread_flag(TIF_RESTORE_SIGMASK
)) {
364 clear_thread_flag(TIF_RESTORE_SIGMASK
);
365 sigprocmask(SIG_SETMASK
, ¤t
->saved_sigmask
, NULL
);
370 * notification of userspace execution resumption
371 * - triggered by current->work.notify_resume
373 void do_notify_resume(struct pt_regs
*regs
, __u32 thread_info_flags
)
375 /* Pending single-step? */
376 if (thread_info_flags
& _TIF_SINGLESTEP
)
377 clear_thread_flag(TIF_SINGLESTEP
);
379 /* deal with pending signal delivery */
380 if (thread_info_flags
& _TIF_SIGPENDING
)
383 if (thread_info_flags
& _TIF_NOTIFY_RESUME
) {
384 clear_thread_flag(TIF_NOTIFY_RESUME
);
385 tracehook_notify_resume(regs
);
386 if (current
->replacement_session_keyring
)
387 key_replace_session_keyring();
390 clear_thread_flag(TIF_IRET
);