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>
50 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
52 asmlinkage
int do_signal(struct pt_regs
*regs
, sigset_t
*oldset
);
55 * Atomically swap in the new signal mask, and wait for a signal.
57 asmlinkage
int do_sigsuspend(struct pt_regs
*regs
)
59 old_sigset_t mask
= regs
->er3
;
60 sigset_t saveset
, blocked
;
62 saveset
= current
->blocked
;
65 siginitset(&blocked
, mask
);
66 set_current_blocked(&blocked
);
70 current
->state
= TASK_INTERRUPTIBLE
;
72 if (do_signal(regs
, &saveset
))
78 do_rt_sigsuspend(struct pt_regs
*regs
)
80 sigset_t
*unewset
= (sigset_t
*)regs
->er1
;
81 size_t sigsetsize
= (size_t)regs
->er2
;
82 sigset_t saveset
, newset
;
84 /* XXX: Don't preclude handling different sized sigset_t's. */
85 if (sigsetsize
!= sizeof(sigset_t
))
88 if (copy_from_user(&newset
, unewset
, sizeof(newset
)))
90 sigdelsetmask(&newset
, ~_BLOCKABLE
);
92 saveset
= current
->blocked
;
93 set_current_blocked(&newset
);
97 current
->state
= TASK_INTERRUPTIBLE
;
99 if (do_signal(regs
, &saveset
))
105 sys_sigaction(int sig
, const struct old_sigaction
*act
,
106 struct old_sigaction
*oact
)
108 struct k_sigaction new_ka
, old_ka
;
113 if (!access_ok(VERIFY_READ
, act
, sizeof(*act
)) ||
114 __get_user(new_ka
.sa
.sa_handler
, &act
->sa_handler
) ||
115 __get_user(new_ka
.sa
.sa_restorer
, &act
->sa_restorer
))
117 __get_user(new_ka
.sa
.sa_flags
, &act
->sa_flags
);
118 __get_user(mask
, &act
->sa_mask
);
119 siginitset(&new_ka
.sa
.sa_mask
, mask
);
122 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
125 if (!access_ok(VERIFY_WRITE
, oact
, sizeof(*oact
)) ||
126 __put_user(old_ka
.sa
.sa_handler
, &oact
->sa_handler
) ||
127 __put_user(old_ka
.sa
.sa_restorer
, &oact
->sa_restorer
))
129 __put_user(old_ka
.sa
.sa_flags
, &oact
->sa_flags
);
130 __put_user(old_ka
.sa
.sa_mask
.sig
[0], &oact
->sa_mask
);
137 sys_sigaltstack(const stack_t
*uss
, stack_t
*uoss
)
139 return do_sigaltstack(uss
, uoss
, rdusp());
144 * Do a signal return; undo the signal stack.
146 * Keep the return code on the stack quadword aligned!
147 * That makes the cache flush below easier.
154 #if defined(CONFIG_CPU_H8S)
159 unsigned char retcode
[8];
160 unsigned long extramask
[_NSIG_WORDS
-1];
161 struct sigcontext sc
;
163 } __attribute__((aligned(2),packed
));
169 #if defined(CONFIG_CPU_H8S)
174 struct siginfo
*pinfo
;
176 unsigned char retcode
[8];
180 } __attribute__((aligned(2),packed
));
183 restore_sigcontext(struct pt_regs
*regs
, struct sigcontext
*usc
,
191 /* Always make any pending restarted system calls return -EINTR */
192 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
194 #define COPY(r) err |= __get_user(regs->r, &usc->sc_##r) /* restore passed registers */
200 ccr
= regs
->ccr
& 0x10;
205 regs
->orig_er0
= -1; /* disable syscall checks */
206 err
|= __get_user(usp
, &usc
->sc_usp
);
209 err
|= __get_user(er0
, &usc
->sc_er0
);
214 asmlinkage
int do_sigreturn(unsigned long __unused
,...)
216 struct pt_regs
*regs
= (struct pt_regs
*) (&__unused
- 1);
217 unsigned long usp
= rdusp();
218 struct sigframe
*frame
= (struct sigframe
*)(usp
- 4);
222 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
224 if (__get_user(set
.sig
[0], &frame
->sc
.sc_mask
) ||
226 __copy_from_user(&set
.sig
[1], &frame
->extramask
,
227 sizeof(frame
->extramask
))))
230 sigdelsetmask(&set
, ~_BLOCKABLE
);
231 set_current_blocked(&set
);
233 if (restore_sigcontext(regs
, &frame
->sc
, &er0
))
238 force_sig(SIGSEGV
, current
);
242 asmlinkage
int do_rt_sigreturn(unsigned long __unused
,...)
244 struct pt_regs
*regs
= (struct pt_regs
*) &__unused
;
245 unsigned long usp
= rdusp();
246 struct rt_sigframe
*frame
= (struct rt_sigframe
*)(usp
- 4);
250 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
252 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
255 sigdelsetmask(&set
, ~_BLOCKABLE
);
256 set_current_blocked(&set
);
258 if (restore_sigcontext(regs
, &frame
->uc
.uc_mcontext
, &er0
))
261 if (do_sigaltstack(&frame
->uc
.uc_stack
, NULL
, usp
) == -EFAULT
)
267 force_sig(SIGSEGV
, current
);
271 static int setup_sigcontext(struct sigcontext __user
*sc
, struct pt_regs
*regs
,
276 err
|= __put_user(regs
->er0
, &sc
->sc_er0
);
277 err
|= __put_user(regs
->er1
, &sc
->sc_er1
);
278 err
|= __put_user(regs
->er2
, &sc
->sc_er2
);
279 err
|= __put_user(regs
->er3
, &sc
->sc_er3
);
280 err
|= __put_user(regs
->er4
, &sc
->sc_er4
);
281 err
|= __put_user(regs
->er5
, &sc
->sc_er5
);
282 err
|= __put_user(regs
->er6
, &sc
->sc_er6
);
283 err
|= __put_user(rdusp(), &sc
->sc_usp
);
284 err
|= __put_user(regs
->pc
, &sc
->sc_pc
);
285 err
|= __put_user(regs
->ccr
, &sc
->sc_ccr
);
286 err
|= __put_user(mask
, &sc
->sc_mask
);
292 get_sigframe(struct k_sigaction
*ka
, struct pt_regs
*regs
, size_t frame_size
)
296 /* Default to using normal stack. */
299 /* This is the X/Open sanctioned signal stack switching. */
300 if (ka
->sa
.sa_flags
& SA_ONSTACK
) {
301 if (!sas_ss_flags(usp
))
302 usp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
304 return (void *)((usp
- frame_size
) & -8UL);
307 static void setup_frame (int sig
, struct k_sigaction
*ka
,
308 sigset_t
*set
, struct pt_regs
*regs
)
310 struct sigframe
*frame
;
315 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
317 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
320 usig
= current_thread_info()->exec_domain
321 && current_thread_info()->exec_domain
->signal_invmap
323 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
326 err
|= __put_user(usig
, &frame
->sig
);
330 err
|= setup_sigcontext(&frame
->sc
, regs
, set
->sig
[0]);
334 if (_NSIG_WORDS
> 1) {
335 err
|= copy_to_user(frame
->extramask
, &set
->sig
[1],
336 sizeof(frame
->extramask
));
341 ret
= frame
->retcode
;
342 if (ka
->sa
.sa_flags
& SA_RESTORER
)
343 ret
= (unsigned char *)(ka
->sa
.sa_restorer
);
345 /* sub.l er0,er0; mov.b #__NR_sigreturn,r0l; trapa #0 */
346 err
|= __put_user(0x1a80f800 + (__NR_sigreturn
& 0xff),
347 (unsigned long *)(frame
->retcode
+ 0));
348 err
|= __put_user(0x5700, (unsigned short *)(frame
->retcode
+ 4));
351 /* Set up to return from userspace. */
352 err
|= __put_user(ret
, &frame
->pretcode
);
357 /* Set up registers for signal handler */
358 wrusp ((unsigned long) frame
);
359 regs
->pc
= (unsigned long) ka
->sa
.sa_handler
;
360 regs
->er0
= (current_thread_info()->exec_domain
361 && current_thread_info()->exec_domain
->signal_invmap
363 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
365 regs
->er1
= (unsigned long)&(frame
->sc
);
366 regs
->er5
= current
->mm
->start_data
; /* GOT base */
371 force_sigsegv(sig
, current
);
374 static void setup_rt_frame (int sig
, struct k_sigaction
*ka
, siginfo_t
*info
,
375 sigset_t
*set
, struct pt_regs
*regs
)
377 struct rt_sigframe
*frame
;
382 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
384 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
387 usig
= current_thread_info()->exec_domain
388 && current_thread_info()->exec_domain
->signal_invmap
390 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
393 err
|= __put_user(usig
, &frame
->sig
);
397 err
|= __put_user(&frame
->info
, &frame
->pinfo
);
398 err
|= __put_user(&frame
->uc
, &frame
->puc
);
399 err
|= copy_siginfo_to_user(&frame
->info
, info
);
403 /* Create the ucontext. */
404 err
|= __put_user(0, &frame
->uc
.uc_flags
);
405 err
|= __put_user(0, &frame
->uc
.uc_link
);
406 err
|= __put_user((void *)current
->sas_ss_sp
,
407 &frame
->uc
.uc_stack
.ss_sp
);
408 err
|= __put_user(sas_ss_flags(rdusp()),
409 &frame
->uc
.uc_stack
.ss_flags
);
410 err
|= __put_user(current
->sas_ss_size
, &frame
->uc
.uc_stack
.ss_size
);
411 err
|= setup_sigcontext(&frame
->uc
.uc_mcontext
, regs
, set
->sig
[0]);
412 err
|= copy_to_user (&frame
->uc
.uc_sigmask
, set
, sizeof(*set
));
416 /* Set up to return from userspace. */
417 ret
= frame
->retcode
;
418 if (ka
->sa
.sa_flags
& SA_RESTORER
)
419 ret
= (unsigned char *)(ka
->sa
.sa_restorer
);
421 /* sub.l er0,er0; mov.b #__NR_sigreturn,r0l; trapa #0 */
422 err
|= __put_user(0x1a80f800 + (__NR_sigreturn
& 0xff),
423 (unsigned long *)(frame
->retcode
+ 0));
424 err
|= __put_user(0x5700, (unsigned short *)(frame
->retcode
+ 4));
426 err
|= __put_user(ret
, &frame
->pretcode
);
431 /* Set up registers for signal handler */
432 wrusp ((unsigned long) frame
);
433 regs
->pc
= (unsigned long) ka
->sa
.sa_handler
;
434 regs
->er0
= (current_thread_info()->exec_domain
435 && current_thread_info()->exec_domain
->signal_invmap
437 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
439 regs
->er1
= (unsigned long)&(frame
->info
);
440 regs
->er2
= (unsigned long)&frame
->uc
;
441 regs
->er5
= current
->mm
->start_data
; /* GOT base */
446 force_sigsegv(sig
, current
);
450 * OK, we're invoking a handler
453 handle_signal(unsigned long sig
, siginfo_t
*info
, struct k_sigaction
*ka
,
454 sigset_t
*oldset
, struct pt_regs
* regs
)
456 /* are we from a system call? */
457 if (regs
->orig_er0
>= 0) {
459 case -ERESTART_RESTARTBLOCK
:
460 case -ERESTARTNOHAND
:
465 if (!(ka
->sa
.sa_flags
& SA_RESTART
)) {
470 case -ERESTARTNOINTR
:
471 regs
->er0
= regs
->orig_er0
;
476 /* set up the stack frame */
477 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
478 setup_rt_frame(sig
, ka
, info
, oldset
, regs
);
480 setup_frame(sig
, ka
, oldset
, regs
);
482 block_sigmask(ka
, sig
);
486 * Note that 'init' is a special process: it doesn't get signals it doesn't
487 * want to handle. Thus you cannot kill init even with a SIGKILL even by
490 asmlinkage
int do_signal(struct pt_regs
*regs
, sigset_t
*oldset
)
494 struct k_sigaction ka
;
497 * We want the common case to go fast, which
498 * is why we may in certain cases get here from
499 * kernel mode. Just return without doing anything
502 if ((regs
->ccr
& 0x10))
508 current
->thread
.esp0
= (unsigned long) regs
;
511 oldset
= ¤t
->blocked
;
513 signr
= get_signal_to_deliver(&info
, &ka
, regs
, NULL
);
515 /* Whee! Actually deliver the signal. */
516 handle_signal(signr
, &info
, &ka
, oldset
, regs
);
520 /* Did we come from a system call? */
521 if (regs
->orig_er0
>= 0) {
522 /* Restart the system call - no handlers present */
523 if (regs
->er0
== -ERESTARTNOHAND
||
524 regs
->er0
== -ERESTARTSYS
||
525 regs
->er0
== -ERESTARTNOINTR
) {
526 regs
->er0
= regs
->orig_er0
;
529 if (regs
->er0
== -ERESTART_RESTARTBLOCK
){
530 regs
->er0
= __NR_restart_syscall
;
537 asmlinkage
void do_notify_resume(struct pt_regs
*regs
, u32 thread_info_flags
)
539 if (thread_info_flags
& (_TIF_SIGPENDING
| _TIF_RESTORE_SIGMASK
))
540 do_signal(regs
, NULL
);
542 if (thread_info_flags
& _TIF_NOTIFY_RESUME
) {
543 clear_thread_flag(TIF_NOTIFY_RESUME
);
544 tracehook_notify_resume(regs
);
545 if (current
->replacement_session_keyring
)
546 key_replace_session_keyring();