2 * linux/arch/h8300/kernel/signal.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
12 * uClinux H8/300 support by Yoshinori Sato <ysato@users.sourceforge.jp>
13 * and David McCullough <davidm@snapgear.com>
16 * Linux/m68k by Hamish Macdonald
20 * ++roman (07/09/96): implemented signal stacks (specially for tosemu on
21 * Atari :-) Current limitation: Only one sigstack can be active at one time.
22 * If a second signal with SA_ONSTACK set arrives while working on a sigstack,
23 * SA_ONSTACK is ignored. This behaviour avoids lots of trouble with nested
27 #include <linux/sched.h>
29 #include <linux/kernel.h>
30 #include <linux/signal.h>
31 #include <linux/syscalls.h>
32 #include <linux/errno.h>
33 #include <linux/wait.h>
34 #include <linux/ptrace.h>
35 #include <linux/unistd.h>
36 #include <linux/stddef.h>
37 #include <linux/highuid.h>
38 #include <linux/personality.h>
39 #include <linux/tty.h>
40 #include <linux/binfmts.h>
41 #include <linux/freezer.h>
42 #include <linux/tracehook.h>
44 #include <asm/setup.h>
45 #include <asm/uaccess.h>
46 #include <asm/pgtable.h>
47 #include <asm/traps.h>
48 #include <asm/ucontext.h>
51 * Atomically swap in the new signal mask, and wait for a signal.
54 sys_sigsuspend(int unused1
, int unused2
, old_sigset_t mask
)
57 siginitset(&blocked
, mask
);
58 return sigsuspend(&blocked
);
62 sys_sigaction(int sig
, const struct old_sigaction
*act
,
63 struct old_sigaction
*oact
)
65 struct k_sigaction new_ka
, old_ka
;
70 if (!access_ok(VERIFY_READ
, act
, sizeof(*act
)) ||
71 __get_user(new_ka
.sa
.sa_handler
, &act
->sa_handler
) ||
72 __get_user(new_ka
.sa
.sa_restorer
, &act
->sa_restorer
) ||
73 __get_user(new_ka
.sa
.sa_flags
, &act
->sa_flags
) ||
74 __get_user(mask
, &act
->sa_mask
))
76 siginitset(&new_ka
.sa
.sa_mask
, mask
);
79 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
82 if (!access_ok(VERIFY_WRITE
, oact
, sizeof(*oact
)) ||
83 __put_user(old_ka
.sa
.sa_handler
, &oact
->sa_handler
) ||
84 __put_user(old_ka
.sa
.sa_restorer
, &oact
->sa_restorer
) ||
85 __put_user(old_ka
.sa
.sa_flags
, &oact
->sa_flags
) ||
86 __put_user(old_ka
.sa
.sa_mask
.sig
[0], &oact
->sa_mask
))
94 sys_sigaltstack(const stack_t
*uss
, stack_t
*uoss
)
96 return do_sigaltstack(uss
, uoss
, rdusp());
101 * Do a signal return; undo the signal stack.
103 * Keep the return code on the stack quadword aligned!
104 * That makes the cache flush below easier.
111 #if defined(CONFIG_CPU_H8S)
116 unsigned char retcode
[8];
117 unsigned long extramask
[_NSIG_WORDS
-1];
118 struct sigcontext sc
;
120 } __attribute__((aligned(2),packed
));
126 #if defined(CONFIG_CPU_H8S)
131 struct siginfo
*pinfo
;
133 unsigned char retcode
[8];
137 } __attribute__((aligned(2),packed
));
140 restore_sigcontext(struct pt_regs
*regs
, struct sigcontext
*usc
,
148 /* Always make any pending restarted system calls return -EINTR */
149 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
151 #define COPY(r) err |= __get_user(regs->r, &usc->sc_##r) /* restore passed registers */
157 ccr
= regs
->ccr
& 0x10;
162 regs
->orig_er0
= -1; /* disable syscall checks */
163 err
|= __get_user(usp
, &usc
->sc_usp
);
166 err
|= __get_user(er0
, &usc
->sc_er0
);
171 asmlinkage
int do_sigreturn(unsigned long __unused
,...)
173 struct pt_regs
*regs
= (struct pt_regs
*) (&__unused
- 1);
174 unsigned long usp
= rdusp();
175 struct sigframe
*frame
= (struct sigframe
*)(usp
- 4);
179 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
181 if (__get_user(set
.sig
[0], &frame
->sc
.sc_mask
) ||
183 __copy_from_user(&set
.sig
[1], &frame
->extramask
,
184 sizeof(frame
->extramask
))))
187 set_current_blocked(&set
);
189 if (restore_sigcontext(regs
, &frame
->sc
, &er0
))
194 force_sig(SIGSEGV
, current
);
198 asmlinkage
int do_rt_sigreturn(unsigned long __unused
,...)
200 struct pt_regs
*regs
= (struct pt_regs
*) &__unused
;
201 unsigned long usp
= rdusp();
202 struct rt_sigframe
*frame
= (struct rt_sigframe
*)(usp
- 4);
206 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
208 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
211 set_current_blocked(&set
);
213 if (restore_sigcontext(regs
, &frame
->uc
.uc_mcontext
, &er0
))
216 if (do_sigaltstack(&frame
->uc
.uc_stack
, NULL
, usp
) == -EFAULT
)
222 force_sig(SIGSEGV
, current
);
226 static int setup_sigcontext(struct sigcontext __user
*sc
, struct pt_regs
*regs
,
231 err
|= __put_user(regs
->er0
, &sc
->sc_er0
);
232 err
|= __put_user(regs
->er1
, &sc
->sc_er1
);
233 err
|= __put_user(regs
->er2
, &sc
->sc_er2
);
234 err
|= __put_user(regs
->er3
, &sc
->sc_er3
);
235 err
|= __put_user(regs
->er4
, &sc
->sc_er4
);
236 err
|= __put_user(regs
->er5
, &sc
->sc_er5
);
237 err
|= __put_user(regs
->er6
, &sc
->sc_er6
);
238 err
|= __put_user(rdusp(), &sc
->sc_usp
);
239 err
|= __put_user(regs
->pc
, &sc
->sc_pc
);
240 err
|= __put_user(regs
->ccr
, &sc
->sc_ccr
);
241 err
|= __put_user(mask
, &sc
->sc_mask
);
247 get_sigframe(struct k_sigaction
*ka
, struct pt_regs
*regs
, size_t frame_size
)
251 /* Default to using normal stack. */
254 /* This is the X/Open sanctioned signal stack switching. */
255 if (ka
->sa
.sa_flags
& SA_ONSTACK
) {
256 if (!sas_ss_flags(usp
))
257 usp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
259 return (void *)((usp
- frame_size
) & -8UL);
262 static int setup_frame (int sig
, struct k_sigaction
*ka
,
263 sigset_t
*set
, struct pt_regs
*regs
)
265 struct sigframe
*frame
;
270 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
272 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
275 usig
= current_thread_info()->exec_domain
276 && current_thread_info()->exec_domain
->signal_invmap
278 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
281 err
|= __put_user(usig
, &frame
->sig
);
285 err
|= setup_sigcontext(&frame
->sc
, regs
, set
->sig
[0]);
289 if (_NSIG_WORDS
> 1) {
290 err
|= copy_to_user(frame
->extramask
, &set
->sig
[1],
291 sizeof(frame
->extramask
));
296 ret
= frame
->retcode
;
297 if (ka
->sa
.sa_flags
& SA_RESTORER
)
298 ret
= (unsigned char *)(ka
->sa
.sa_restorer
);
300 /* sub.l er0,er0; mov.b #__NR_sigreturn,r0l; trapa #0 */
301 err
|= __put_user(0x1a80f800 + (__NR_sigreturn
& 0xff),
302 (unsigned long *)(frame
->retcode
+ 0));
303 err
|= __put_user(0x5700, (unsigned short *)(frame
->retcode
+ 4));
306 /* Set up to return from userspace. */
307 err
|= __put_user(ret
, &frame
->pretcode
);
312 /* Set up registers for signal handler */
313 wrusp ((unsigned long) frame
);
314 regs
->pc
= (unsigned long) ka
->sa
.sa_handler
;
315 regs
->er0
= (current_thread_info()->exec_domain
316 && current_thread_info()->exec_domain
->signal_invmap
318 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
320 regs
->er1
= (unsigned long)&(frame
->sc
);
321 regs
->er5
= current
->mm
->start_data
; /* GOT base */
326 force_sigsegv(sig
, current
);
330 static int setup_rt_frame (int sig
, struct k_sigaction
*ka
, siginfo_t
*info
,
331 sigset_t
*set
, struct pt_regs
*regs
)
333 struct rt_sigframe
*frame
;
338 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
340 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
343 usig
= current_thread_info()->exec_domain
344 && current_thread_info()->exec_domain
->signal_invmap
346 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
349 err
|= __put_user(usig
, &frame
->sig
);
353 err
|= __put_user(&frame
->info
, &frame
->pinfo
);
354 err
|= __put_user(&frame
->uc
, &frame
->puc
);
355 err
|= copy_siginfo_to_user(&frame
->info
, info
);
359 /* Create the ucontext. */
360 err
|= __put_user(0, &frame
->uc
.uc_flags
);
361 err
|= __put_user(0, &frame
->uc
.uc_link
);
362 err
|= __put_user((void *)current
->sas_ss_sp
,
363 &frame
->uc
.uc_stack
.ss_sp
);
364 err
|= __put_user(sas_ss_flags(rdusp()),
365 &frame
->uc
.uc_stack
.ss_flags
);
366 err
|= __put_user(current
->sas_ss_size
, &frame
->uc
.uc_stack
.ss_size
);
367 err
|= setup_sigcontext(&frame
->uc
.uc_mcontext
, regs
, set
->sig
[0]);
368 err
|= copy_to_user (&frame
->uc
.uc_sigmask
, set
, sizeof(*set
));
372 /* Set up to return from userspace. */
373 ret
= frame
->retcode
;
374 if (ka
->sa
.sa_flags
& SA_RESTORER
)
375 ret
= (unsigned char *)(ka
->sa
.sa_restorer
);
377 /* sub.l er0,er0; mov.b #__NR_sigreturn,r0l; trapa #0 */
378 err
|= __put_user(0x1a80f800 + (__NR_sigreturn
& 0xff),
379 (unsigned long *)(frame
->retcode
+ 0));
380 err
|= __put_user(0x5700, (unsigned short *)(frame
->retcode
+ 4));
382 err
|= __put_user(ret
, &frame
->pretcode
);
387 /* Set up registers for signal handler */
388 wrusp ((unsigned long) frame
);
389 regs
->pc
= (unsigned long) ka
->sa
.sa_handler
;
390 regs
->er0
= (current_thread_info()->exec_domain
391 && current_thread_info()->exec_domain
->signal_invmap
393 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
395 regs
->er1
= (unsigned long)&(frame
->info
);
396 regs
->er2
= (unsigned long)&frame
->uc
;
397 regs
->er5
= current
->mm
->start_data
; /* GOT base */
402 force_sigsegv(sig
, current
);
407 * OK, we're invoking a handler
410 handle_signal(unsigned long sig
, siginfo_t
*info
, struct k_sigaction
*ka
,
411 struct pt_regs
* regs
)
413 sigset_t
*oldset
= sigmask_to_save();
415 /* are we from a system call? */
416 if (regs
->orig_er0
>= 0) {
418 case -ERESTART_RESTARTBLOCK
:
419 case -ERESTARTNOHAND
:
424 if (!(ka
->sa
.sa_flags
& SA_RESTART
)) {
429 case -ERESTARTNOINTR
:
430 regs
->er0
= regs
->orig_er0
;
435 /* set up the stack frame */
436 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
437 ret
= setup_rt_frame(sig
, ka
, info
, oldset
, regs
);
439 ret
= setup_frame(sig
, ka
, oldset
, regs
);
442 signal_delivered(sig
, info
, ka
, regs
, 0);
446 * Note that 'init' is a special process: it doesn't get signals it doesn't
447 * want to handle. Thus you cannot kill init even with a SIGKILL even by
450 static void do_signal(struct pt_regs
*regs
)
454 struct k_sigaction ka
;
457 * We want the common case to go fast, which
458 * is why we may in certain cases get here from
459 * kernel mode. Just return without doing anything
462 if ((regs
->ccr
& 0x10))
465 current
->thread
.esp0
= (unsigned long) regs
;
467 signr
= get_signal_to_deliver(&info
, &ka
, regs
, NULL
);
469 /* Whee! Actually deliver the signal. */
470 handle_signal(signr
, &info
, &ka
, regs
);
473 /* Did we come from a system call? */
474 if (regs
->orig_er0
>= 0) {
475 /* Restart the system call - no handlers present */
476 if (regs
->er0
== -ERESTARTNOHAND
||
477 regs
->er0
== -ERESTARTSYS
||
478 regs
->er0
== -ERESTARTNOINTR
) {
479 regs
->er0
= regs
->orig_er0
;
482 if (regs
->er0
== -ERESTART_RESTARTBLOCK
){
483 regs
->er0
= __NR_restart_syscall
;
488 /* If there's no signal to deliver, we just restore the saved mask. */
489 restore_saved_sigmask();
492 asmlinkage
void do_notify_resume(struct pt_regs
*regs
, u32 thread_info_flags
)
494 if (thread_info_flags
& _TIF_SIGPENDING
)
497 if (thread_info_flags
& _TIF_NOTIFY_RESUME
) {
498 clear_thread_flag(TIF_NOTIFY_RESUME
);
499 tracehook_notify_resume(regs
);