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>
43 #include <asm/setup.h>
44 #include <asm/uaccess.h>
45 #include <asm/pgtable.h>
46 #include <asm/traps.h>
47 #include <asm/ucontext.h>
49 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
51 asmlinkage
int do_signal(struct pt_regs
*regs
, sigset_t
*oldset
);
54 * Atomically swap in the new signal mask, and wait for a signal.
56 asmlinkage
int do_sigsuspend(struct pt_regs
*regs
)
58 old_sigset_t mask
= regs
->er3
;
62 spin_lock_irq(¤t
->sighand
->siglock
);
63 saveset
= current
->blocked
;
64 siginitset(¤t
->blocked
, mask
);
66 spin_unlock_irq(¤t
->sighand
->siglock
);
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 spin_lock_irq(¤t
->sighand
->siglock
);
93 saveset
= current
->blocked
;
94 current
->blocked
= newset
;
96 spin_unlock_irq(¤t
->sighand
->siglock
);
100 current
->state
= TASK_INTERRUPTIBLE
;
102 if (do_signal(regs
, &saveset
))
108 sys_sigaction(int sig
, const struct old_sigaction
*act
,
109 struct old_sigaction
*oact
)
111 struct k_sigaction new_ka
, old_ka
;
116 if (!access_ok(VERIFY_READ
, act
, sizeof(*act
)) ||
117 __get_user(new_ka
.sa
.sa_handler
, &act
->sa_handler
) ||
118 __get_user(new_ka
.sa
.sa_restorer
, &act
->sa_restorer
))
120 __get_user(new_ka
.sa
.sa_flags
, &act
->sa_flags
);
121 __get_user(mask
, &act
->sa_mask
);
122 siginitset(&new_ka
.sa
.sa_mask
, mask
);
125 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
128 if (!access_ok(VERIFY_WRITE
, oact
, sizeof(*oact
)) ||
129 __put_user(old_ka
.sa
.sa_handler
, &oact
->sa_handler
) ||
130 __put_user(old_ka
.sa
.sa_restorer
, &oact
->sa_restorer
))
132 __put_user(old_ka
.sa
.sa_flags
, &oact
->sa_flags
);
133 __put_user(old_ka
.sa
.sa_mask
.sig
[0], &oact
->sa_mask
);
140 sys_sigaltstack(const stack_t
*uss
, stack_t
*uoss
)
142 return do_sigaltstack(uss
, uoss
, rdusp());
147 * Do a signal return; undo the signal stack.
149 * Keep the return code on the stack quadword aligned!
150 * That makes the cache flush below easier.
157 #if defined(CONFIG_CPU_H8S)
162 unsigned char retcode
[8];
163 unsigned long extramask
[_NSIG_WORDS
-1];
164 struct sigcontext sc
;
166 } __attribute__((aligned(2),packed
));
172 #if defined(CONFIG_CPU_H8S)
177 struct siginfo
*pinfo
;
179 unsigned char retcode
[8];
183 } __attribute__((aligned(2),packed
));
186 restore_sigcontext(struct pt_regs
*regs
, struct sigcontext
*usc
,
194 /* Always make any pending restarted system calls return -EINTR */
195 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
197 #define COPY(r) err |= __get_user(regs->r, &usc->sc_##r) /* restore passed registers */
203 ccr
= regs
->ccr
& 0x10;
208 regs
->orig_er0
= -1; /* disable syscall checks */
209 err
|= __get_user(usp
, &usc
->sc_usp
);
212 err
|= __get_user(er0
, &usc
->sc_er0
);
217 asmlinkage
int do_sigreturn(unsigned long __unused
,...)
219 struct pt_regs
*regs
= (struct pt_regs
*) (&__unused
- 1);
220 unsigned long usp
= rdusp();
221 struct sigframe
*frame
= (struct sigframe
*)(usp
- 4);
225 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
227 if (__get_user(set
.sig
[0], &frame
->sc
.sc_mask
) ||
229 __copy_from_user(&set
.sig
[1], &frame
->extramask
,
230 sizeof(frame
->extramask
))))
233 sigdelsetmask(&set
, ~_BLOCKABLE
);
234 spin_lock_irq(¤t
->sighand
->siglock
);
235 current
->blocked
= set
;
237 spin_unlock_irq(¤t
->sighand
->siglock
);
239 if (restore_sigcontext(regs
, &frame
->sc
, &er0
))
244 force_sig(SIGSEGV
, current
);
248 asmlinkage
int do_rt_sigreturn(unsigned long __unused
,...)
250 struct pt_regs
*regs
= (struct pt_regs
*) &__unused
;
251 unsigned long usp
= rdusp();
252 struct rt_sigframe
*frame
= (struct rt_sigframe
*)(usp
- 4);
256 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
258 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
261 sigdelsetmask(&set
, ~_BLOCKABLE
);
262 spin_unlock_irq(¤t
->sighand
->siglock
);
263 current
->blocked
= set
;
265 spin_lock_irq(¤t
->sighand
->siglock
);
267 if (restore_sigcontext(regs
, &frame
->uc
.uc_mcontext
, &er0
))
270 if (do_sigaltstack(&frame
->uc
.uc_stack
, NULL
, usp
) == -EFAULT
)
276 force_sig(SIGSEGV
, current
);
280 static int setup_sigcontext(struct sigcontext __user
*sc
, struct pt_regs
*regs
,
285 err
|= __put_user(regs
->er0
, &sc
->sc_er0
);
286 err
|= __put_user(regs
->er1
, &sc
->sc_er1
);
287 err
|= __put_user(regs
->er2
, &sc
->sc_er2
);
288 err
|= __put_user(regs
->er3
, &sc
->sc_er3
);
289 err
|= __put_user(regs
->er4
, &sc
->sc_er4
);
290 err
|= __put_user(regs
->er5
, &sc
->sc_er5
);
291 err
|= __put_user(regs
->er6
, &sc
->sc_er6
);
292 err
|= __put_user(rdusp(), &sc
->sc_usp
);
293 err
|= __put_user(regs
->pc
, &sc
->sc_pc
);
294 err
|= __put_user(regs
->ccr
, &sc
->sc_ccr
);
295 err
|= __put_user(mask
, &sc
->sc_mask
);
301 get_sigframe(struct k_sigaction
*ka
, struct pt_regs
*regs
, size_t frame_size
)
305 /* Default to using normal stack. */
308 /* This is the X/Open sanctioned signal stack switching. */
309 if (ka
->sa
.sa_flags
& SA_ONSTACK
) {
310 if (!sas_ss_flags(usp
))
311 usp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
313 return (void *)((usp
- frame_size
) & -8UL);
316 static void setup_frame (int sig
, struct k_sigaction
*ka
,
317 sigset_t
*set
, struct pt_regs
*regs
)
319 struct sigframe
*frame
;
324 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
326 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
329 usig
= current_thread_info()->exec_domain
330 && current_thread_info()->exec_domain
->signal_invmap
332 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
335 err
|= __put_user(usig
, &frame
->sig
);
339 err
|= setup_sigcontext(&frame
->sc
, regs
, set
->sig
[0]);
343 if (_NSIG_WORDS
> 1) {
344 err
|= copy_to_user(frame
->extramask
, &set
->sig
[1],
345 sizeof(frame
->extramask
));
350 ret
= frame
->retcode
;
351 if (ka
->sa
.sa_flags
& SA_RESTORER
)
352 ret
= (unsigned char *)(ka
->sa
.sa_restorer
);
354 /* sub.l er0,er0; mov.b #__NR_sigreturn,r0l; trapa #0 */
355 <<<<<<< HEAD
:arch
/h8300
/kernel
/signal
.c
356 err
!= __put_user(0x1a80f800 + (__NR_sigreturn
& 0xff),
358 err
|= __put_user(0x1a80f800 + (__NR_sigreturn
& 0xff),
359 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/h8300
/kernel
/signal
.c
360 (unsigned long *)(frame
->retcode
+ 0));
361 err
|= __put_user(0x5700, (unsigned short *)(frame
->retcode
+ 4));
364 /* Set up to return from userspace. */
365 err
|= __put_user(ret
, &frame
->pretcode
);
370 /* Set up registers for signal handler */
371 wrusp ((unsigned long) frame
);
372 regs
->pc
= (unsigned long) ka
->sa
.sa_handler
;
373 regs
->er0
= (current_thread_info()->exec_domain
374 && current_thread_info()->exec_domain
->signal_invmap
376 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
378 regs
->er1
= (unsigned long)&(frame
->sc
);
379 regs
->er5
= current
->mm
->start_data
; /* GOT base */
384 force_sigsegv(sig
, current
);
387 static void setup_rt_frame (int sig
, struct k_sigaction
*ka
, siginfo_t
*info
,
388 sigset_t
*set
, struct pt_regs
*regs
)
390 struct rt_sigframe
*frame
;
395 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
397 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
400 usig
= current_thread_info()->exec_domain
401 && current_thread_info()->exec_domain
->signal_invmap
403 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
406 err
|= __put_user(usig
, &frame
->sig
);
410 err
|= __put_user(&frame
->info
, &frame
->pinfo
);
411 err
|= __put_user(&frame
->uc
, &frame
->puc
);
412 err
|= copy_siginfo_to_user(&frame
->info
, info
);
416 /* Create the ucontext. */
417 err
|= __put_user(0, &frame
->uc
.uc_flags
);
418 err
|= __put_user(0, &frame
->uc
.uc_link
);
419 err
|= __put_user((void *)current
->sas_ss_sp
,
420 &frame
->uc
.uc_stack
.ss_sp
);
421 err
|= __put_user(sas_ss_flags(rdusp()),
422 &frame
->uc
.uc_stack
.ss_flags
);
423 err
|= __put_user(current
->sas_ss_size
, &frame
->uc
.uc_stack
.ss_size
);
424 err
|= setup_sigcontext(&frame
->uc
.uc_mcontext
, regs
, set
->sig
[0]);
425 err
|= copy_to_user (&frame
->uc
.uc_sigmask
, set
, sizeof(*set
));
429 /* Set up to return from userspace. */
430 ret
= frame
->retcode
;
431 if (ka
->sa
.sa_flags
& SA_RESTORER
)
432 ret
= (unsigned char *)(ka
->sa
.sa_restorer
);
434 /* sub.l er0,er0; mov.b #__NR_sigreturn,r0l; trapa #0 */
435 <<<<<<< HEAD
:arch
/h8300
/kernel
/signal
.c
436 err
!= __put_user(0x1a80f800 + (__NR_sigreturn
& 0xff),
438 err
|= __put_user(0x1a80f800 + (__NR_sigreturn
& 0xff),
439 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/h8300
/kernel
/signal
.c
440 (unsigned long *)(frame
->retcode
+ 0));
441 err
|= __put_user(0x5700, (unsigned short *)(frame
->retcode
+ 4));
443 err
|= __put_user(ret
, &frame
->pretcode
);
448 /* Set up registers for signal handler */
449 wrusp ((unsigned long) frame
);
450 regs
->pc
= (unsigned long) ka
->sa
.sa_handler
;
451 regs
->er0
= (current_thread_info()->exec_domain
452 && current_thread_info()->exec_domain
->signal_invmap
454 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
456 regs
->er1
= (unsigned long)&(frame
->info
);
457 regs
->er2
= (unsigned long)&frame
->uc
;
458 regs
->er5
= current
->mm
->start_data
; /* GOT base */
463 force_sigsegv(sig
, current
);
467 * OK, we're invoking a handler
470 handle_signal(unsigned long sig
, siginfo_t
*info
, struct k_sigaction
*ka
,
471 sigset_t
*oldset
, struct pt_regs
* regs
)
473 /* are we from a system call? */
474 if (regs
->orig_er0
>= 0) {
476 case -ERESTART_RESTARTBLOCK
:
477 case -ERESTARTNOHAND
:
482 if (!(ka
->sa
.sa_flags
& SA_RESTART
)) {
487 case -ERESTARTNOINTR
:
488 regs
->er0
= regs
->orig_er0
;
493 /* set up the stack frame */
494 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
495 setup_rt_frame(sig
, ka
, info
, oldset
, regs
);
497 setup_frame(sig
, ka
, oldset
, regs
);
499 spin_lock_irq(¤t
->sighand
->siglock
);
500 sigorsets(¤t
->blocked
,¤t
->blocked
,&ka
->sa
.sa_mask
);
501 if (!(ka
->sa
.sa_flags
& SA_NODEFER
))
502 sigaddset(¤t
->blocked
,sig
);
504 spin_unlock_irq(¤t
->sighand
->siglock
);
508 * Note that 'init' is a special process: it doesn't get signals it doesn't
509 * want to handle. Thus you cannot kill init even with a SIGKILL even by
512 asmlinkage
int do_signal(struct pt_regs
*regs
, sigset_t
*oldset
)
516 struct k_sigaction ka
;
519 * We want the common case to go fast, which
520 * is why we may in certain cases get here from
521 * kernel mode. Just return without doing anything
524 if ((regs
->ccr
& 0x10))
530 current
->thread
.esp0
= (unsigned long) regs
;
533 oldset
= ¤t
->blocked
;
535 signr
= get_signal_to_deliver(&info
, &ka
, regs
, NULL
);
537 /* Whee! Actually deliver the signal. */
538 handle_signal(signr
, &info
, &ka
, oldset
, regs
);
542 /* Did we come from a system call? */
543 if (regs
->orig_er0
>= 0) {
544 /* Restart the system call - no handlers present */
545 if (regs
->er0
== -ERESTARTNOHAND
||
546 regs
->er0
== -ERESTARTSYS
||
547 regs
->er0
== -ERESTARTNOINTR
) {
548 regs
->er0
= regs
->orig_er0
;
551 if (regs
->er0
== -ERESTART_RESTARTBLOCK
){
552 regs
->er0
= __NR_restart_syscall
;
559 asmlinkage
void do_notify_resume(struct pt_regs
*regs
, u32 thread_info_flags
)
561 if (thread_info_flags
& (_TIF_SIGPENDING
| _TIF_RESTORE_SIGMASK
))
562 do_signal(regs
, NULL
);