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/tracehook.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>
50 * Do a signal return; undo the signal stack.
52 * Keep the return code on the stack quadword aligned!
53 * That makes the cache flush below easier.
60 #if defined(CONFIG_CPU_H8S)
65 unsigned char retcode
[8];
66 unsigned long extramask
[_NSIG_WORDS
-1];
69 } __attribute__((aligned(2),packed
));
75 #if defined(CONFIG_CPU_H8S)
80 struct siginfo
*pinfo
;
82 unsigned char retcode
[8];
86 } __attribute__((aligned(2),packed
));
89 restore_sigcontext(struct sigcontext
*usc
, int *pd0
)
91 struct pt_regs
*regs
= current_pt_regs();
97 /* Always make any pending restarted system calls return -EINTR */
98 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
100 #define COPY(r) err |= __get_user(regs->r, &usc->sc_##r) /* restore passed registers */
106 ccr
= regs
->ccr
& 0x10;
111 regs
->orig_er0
= -1; /* disable syscall checks */
112 err
|= __get_user(usp
, &usc
->sc_usp
);
115 err
|= __get_user(er0
, &usc
->sc_er0
);
120 asmlinkage
int sys_sigreturn(void)
122 unsigned long usp
= rdusp();
123 struct sigframe
*frame
= (struct sigframe
*)(usp
- 4);
127 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
129 if (__get_user(set
.sig
[0], &frame
->sc
.sc_mask
) ||
131 __copy_from_user(&set
.sig
[1], &frame
->extramask
,
132 sizeof(frame
->extramask
))))
135 set_current_blocked(&set
);
137 if (restore_sigcontext(&frame
->sc
, &er0
))
142 force_sig(SIGSEGV
, current
);
146 asmlinkage
int sys_rt_sigreturn(void)
148 unsigned long usp
= rdusp();
149 struct rt_sigframe
*frame
= (struct rt_sigframe
*)(usp
- 4);
153 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
155 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
158 set_current_blocked(&set
);
160 if (restore_sigcontext(&frame
->uc
.uc_mcontext
, &er0
))
163 if (restore_altstack(&frame
->uc
.uc_stack
))
169 force_sig(SIGSEGV
, current
);
173 static int setup_sigcontext(struct sigcontext __user
*sc
, struct pt_regs
*regs
,
178 err
|= __put_user(regs
->er0
, &sc
->sc_er0
);
179 err
|= __put_user(regs
->er1
, &sc
->sc_er1
);
180 err
|= __put_user(regs
->er2
, &sc
->sc_er2
);
181 err
|= __put_user(regs
->er3
, &sc
->sc_er3
);
182 err
|= __put_user(regs
->er4
, &sc
->sc_er4
);
183 err
|= __put_user(regs
->er5
, &sc
->sc_er5
);
184 err
|= __put_user(regs
->er6
, &sc
->sc_er6
);
185 err
|= __put_user(rdusp(), &sc
->sc_usp
);
186 err
|= __put_user(regs
->pc
, &sc
->sc_pc
);
187 err
|= __put_user(regs
->ccr
, &sc
->sc_ccr
);
188 err
|= __put_user(mask
, &sc
->sc_mask
);
194 get_sigframe(struct k_sigaction
*ka
, struct pt_regs
*regs
, size_t frame_size
)
198 /* Default to using normal stack. */
201 /* This is the X/Open sanctioned signal stack switching. */
202 if (ka
->sa
.sa_flags
& SA_ONSTACK
) {
203 if (!sas_ss_flags(usp
))
204 usp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
206 return (void *)((usp
- frame_size
) & -8UL);
209 static int setup_frame (int sig
, struct k_sigaction
*ka
,
210 sigset_t
*set
, struct pt_regs
*regs
)
212 struct sigframe
*frame
;
217 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
219 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
222 usig
= current_thread_info()->exec_domain
223 && current_thread_info()->exec_domain
->signal_invmap
225 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
228 err
|= __put_user(usig
, &frame
->sig
);
232 err
|= setup_sigcontext(&frame
->sc
, regs
, set
->sig
[0]);
236 if (_NSIG_WORDS
> 1) {
237 err
|= copy_to_user(frame
->extramask
, &set
->sig
[1],
238 sizeof(frame
->extramask
));
243 ret
= frame
->retcode
;
244 if (ka
->sa
.sa_flags
& SA_RESTORER
)
245 ret
= (unsigned char *)(ka
->sa
.sa_restorer
);
247 /* sub.l er0,er0; mov.b #__NR_sigreturn,r0l; trapa #0 */
248 err
|= __put_user(0x1a80f800 + (__NR_sigreturn
& 0xff),
249 (unsigned long *)(frame
->retcode
+ 0));
250 err
|= __put_user(0x5700, (unsigned short *)(frame
->retcode
+ 4));
253 /* Set up to return from userspace. */
254 err
|= __put_user(ret
, &frame
->pretcode
);
259 /* Set up registers for signal handler */
260 wrusp ((unsigned long) frame
);
261 regs
->pc
= (unsigned long) ka
->sa
.sa_handler
;
262 regs
->er0
= (current_thread_info()->exec_domain
263 && current_thread_info()->exec_domain
->signal_invmap
265 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
267 regs
->er1
= (unsigned long)&(frame
->sc
);
268 regs
->er5
= current
->mm
->start_data
; /* GOT base */
273 force_sigsegv(sig
, current
);
277 static int setup_rt_frame (int sig
, struct k_sigaction
*ka
, siginfo_t
*info
,
278 sigset_t
*set
, struct pt_regs
*regs
)
280 struct rt_sigframe
*frame
;
285 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
287 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
290 usig
= current_thread_info()->exec_domain
291 && current_thread_info()->exec_domain
->signal_invmap
293 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
296 err
|= __put_user(usig
, &frame
->sig
);
300 err
|= __put_user(&frame
->info
, &frame
->pinfo
);
301 err
|= __put_user(&frame
->uc
, &frame
->puc
);
302 err
|= copy_siginfo_to_user(&frame
->info
, info
);
306 /* Create the ucontext. */
307 err
|= __put_user(0, &frame
->uc
.uc_flags
);
308 err
|= __put_user(0, &frame
->uc
.uc_link
);
309 err
|= __save_altstack(&frame
->uc
.uc_stack
, rdusp());
310 err
|= setup_sigcontext(&frame
->uc
.uc_mcontext
, regs
, set
->sig
[0]);
311 err
|= copy_to_user (&frame
->uc
.uc_sigmask
, set
, sizeof(*set
));
315 /* Set up to return from userspace. */
316 ret
= frame
->retcode
;
317 if (ka
->sa
.sa_flags
& SA_RESTORER
)
318 ret
= (unsigned char *)(ka
->sa
.sa_restorer
);
320 /* sub.l er0,er0; mov.b #__NR_sigreturn,r0l; trapa #0 */
321 err
|= __put_user(0x1a80f800 + (__NR_sigreturn
& 0xff),
322 (unsigned long *)(frame
->retcode
+ 0));
323 err
|= __put_user(0x5700, (unsigned short *)(frame
->retcode
+ 4));
325 err
|= __put_user(ret
, &frame
->pretcode
);
330 /* Set up registers for signal handler */
331 wrusp ((unsigned long) frame
);
332 regs
->pc
= (unsigned long) ka
->sa
.sa_handler
;
333 regs
->er0
= (current_thread_info()->exec_domain
334 && current_thread_info()->exec_domain
->signal_invmap
336 ? current_thread_info()->exec_domain
->signal_invmap
[sig
]
338 regs
->er1
= (unsigned long)&(frame
->info
);
339 regs
->er2
= (unsigned long)&frame
->uc
;
340 regs
->er5
= current
->mm
->start_data
; /* GOT base */
345 force_sigsegv(sig
, current
);
350 * OK, we're invoking a handler
353 handle_signal(unsigned long sig
, siginfo_t
*info
, struct k_sigaction
*ka
,
354 struct pt_regs
* regs
)
356 sigset_t
*oldset
= sigmask_to_save();
358 /* are we from a system call? */
359 if (regs
->orig_er0
>= 0) {
361 case -ERESTART_RESTARTBLOCK
:
362 case -ERESTARTNOHAND
:
367 if (!(ka
->sa
.sa_flags
& SA_RESTART
)) {
372 case -ERESTARTNOINTR
:
373 regs
->er0
= regs
->orig_er0
;
378 /* set up the stack frame */
379 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
380 ret
= setup_rt_frame(sig
, ka
, info
, oldset
, regs
);
382 ret
= setup_frame(sig
, ka
, oldset
, regs
);
385 signal_delivered(sig
, info
, ka
, regs
, 0);
389 * Note that 'init' is a special process: it doesn't get signals it doesn't
390 * want to handle. Thus you cannot kill init even with a SIGKILL even by
393 static void do_signal(struct pt_regs
*regs
)
397 struct k_sigaction ka
;
400 * We want the common case to go fast, which
401 * is why we may in certain cases get here from
402 * kernel mode. Just return without doing anything
405 if ((regs
->ccr
& 0x10))
408 current
->thread
.esp0
= (unsigned long) regs
;
410 signr
= get_signal_to_deliver(&info
, &ka
, regs
, NULL
);
412 /* Whee! Actually deliver the signal. */
413 handle_signal(signr
, &info
, &ka
, regs
);
416 /* Did we come from a system call? */
417 if (regs
->orig_er0
>= 0) {
418 /* Restart the system call - no handlers present */
419 if (regs
->er0
== -ERESTARTNOHAND
||
420 regs
->er0
== -ERESTARTSYS
||
421 regs
->er0
== -ERESTARTNOINTR
) {
422 regs
->er0
= regs
->orig_er0
;
425 if (regs
->er0
== -ERESTART_RESTARTBLOCK
){
426 regs
->er0
= __NR_restart_syscall
;
431 /* If there's no signal to deliver, we just restore the saved mask. */
432 restore_saved_sigmask();
435 asmlinkage
void do_notify_resume(struct pt_regs
*regs
, u32 thread_info_flags
)
437 if (thread_info_flags
& _TIF_SIGPENDING
)
440 if (thread_info_flags
& _TIF_NOTIFY_RESUME
) {
441 clear_thread_flag(TIF_NOTIFY_RESUME
);
442 tracehook_notify_resume(regs
);