1 /* signal.c: FRV specific bits of signal handling
3 * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 * - Derived from arch/m68k/kernel/signal.c
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
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/ptrace.h>
21 #include <linux/unistd.h>
22 #include <linux/personality.h>
23 #include <linux/freezer.h>
24 #include <linux/tracehook.h>
25 #include <asm/ucontext.h>
26 #include <asm/uaccess.h>
27 #include <asm/cacheflush.h>
31 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
33 struct fdpic_func_descriptor
{
39 * Atomically swap in the new signal mask, and wait for a signal.
41 asmlinkage
int sys_sigsuspend(int history0
, int history1
, old_sigset_t mask
)
44 siginitset(&blocked
, mask
);
45 return sigsuspend(&blocked
);
48 asmlinkage
int sys_sigaction(int sig
,
49 const struct old_sigaction __user
*act
,
50 struct old_sigaction __user
*oact
)
52 struct k_sigaction new_ka
, old_ka
;
57 if (!access_ok(VERIFY_READ
, act
, sizeof(*act
)) ||
58 __get_user(new_ka
.sa
.sa_handler
, &act
->sa_handler
) ||
59 __get_user(new_ka
.sa
.sa_restorer
, &act
->sa_restorer
) ||
60 __get_user(new_ka
.sa
.sa_flags
, &act
->sa_flags
) ||
61 __get_user(mask
, &act
->sa_mask
))
63 siginitset(&new_ka
.sa
.sa_mask
, mask
);
66 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
69 if (!access_ok(VERIFY_WRITE
, oact
, sizeof(*oact
)) ||
70 __put_user(old_ka
.sa
.sa_handler
, &oact
->sa_handler
) ||
71 __put_user(old_ka
.sa
.sa_restorer
, &oact
->sa_restorer
) ||
72 __put_user(old_ka
.sa
.sa_flags
, &oact
->sa_flags
) ||
73 __put_user(old_ka
.sa
.sa_mask
.sig
[0], &oact
->sa_mask
))
81 int sys_sigaltstack(const stack_t __user
*uss
, stack_t __user
*uoss
)
83 return do_sigaltstack(uss
, uoss
, __frame
->sp
);
88 * Do a signal return; undo the signal stack.
93 __sigrestore_t pretcode
;
96 unsigned long extramask
[_NSIG_WORDS
-1];
102 __sigrestore_t pretcode
;
104 struct siginfo __user
*pinfo
;
111 static int restore_sigcontext(struct sigcontext __user
*sc
, int *_gr8
)
113 struct user_context
*user
= current
->thread
.user
;
114 unsigned long tbr
, psr
;
116 /* Always make any pending restarted system calls return -EINTR */
117 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
121 if (copy_from_user(user
, &sc
->sc_context
, sizeof(sc
->sc_context
)))
126 restore_user_regs(user
);
128 user
->i
.syscallno
= -1; /* disable syscall checks */
130 *_gr8
= user
->i
.gr
[8];
137 asmlinkage
int sys_sigreturn(void)
139 struct sigframe __user
*frame
= (struct sigframe __user
*) __frame
->sp
;
143 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
145 if (__get_user(set
.sig
[0], &frame
->sc
.sc_oldmask
))
148 if (_NSIG_WORDS
> 1 &&
149 __copy_from_user(&set
.sig
[1], &frame
->extramask
, sizeof(frame
->extramask
)))
152 sigdelsetmask(&set
, ~_BLOCKABLE
);
153 set_current_blocked(&set
);
155 if (restore_sigcontext(&frame
->sc
, &gr8
))
160 force_sig(SIGSEGV
, current
);
164 asmlinkage
int sys_rt_sigreturn(void)
166 struct rt_sigframe __user
*frame
= (struct rt_sigframe __user
*) __frame
->sp
;
170 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
172 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
175 sigdelsetmask(&set
, ~_BLOCKABLE
);
176 set_current_blocked(&set
);
178 if (restore_sigcontext(&frame
->uc
.uc_mcontext
, &gr8
))
181 if (do_sigaltstack(&frame
->uc
.uc_stack
, NULL
, __frame
->sp
) == -EFAULT
)
187 force_sig(SIGSEGV
, current
);
192 * Set up a signal frame
194 static int setup_sigcontext(struct sigcontext __user
*sc
, unsigned long mask
)
196 save_user_regs(current
->thread
.user
);
198 if (copy_to_user(&sc
->sc_context
, current
->thread
.user
, sizeof(sc
->sc_context
)) != 0)
201 /* non-iBCS2 extensions.. */
202 if (__put_user(mask
, &sc
->sc_oldmask
) < 0)
211 /*****************************************************************************/
213 * Determine which stack to use..
215 static inline void __user
*get_sigframe(struct k_sigaction
*ka
,
220 /* Default to using normal stack */
223 /* This is the X/Open sanctioned signal stack switching. */
224 if (ka
->sa
.sa_flags
& SA_ONSTACK
) {
225 if (! sas_ss_flags(sp
))
226 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
229 return (void __user
*) ((sp
- frame_size
) & ~7UL);
231 } /* end get_sigframe() */
233 /*****************************************************************************/
237 static int setup_frame(int sig
, struct k_sigaction
*ka
, sigset_t
*set
)
239 struct sigframe __user
*frame
;
244 frame
= get_sigframe(ka
, sizeof(*frame
));
246 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
251 __current_thread_info
->exec_domain
&&
252 __current_thread_info
->exec_domain
->signal_invmap
)
253 rsig
= __current_thread_info
->exec_domain
->signal_invmap
[sig
];
255 if (__put_user(rsig
, &frame
->sig
) < 0)
258 if (setup_sigcontext(&frame
->sc
, set
->sig
[0]))
261 if (_NSIG_WORDS
> 1) {
262 if (__copy_to_user(frame
->extramask
, &set
->sig
[1],
263 sizeof(frame
->extramask
)))
267 /* Set up to return from userspace. If provided, use a stub
268 * already in userspace. */
269 if (ka
->sa
.sa_flags
& SA_RESTORER
) {
270 if (__put_user(ka
->sa
.sa_restorer
, &frame
->pretcode
) < 0)
274 /* Set up the following code on the stack:
275 * setlos #__NR_sigreturn,gr7
278 if (__put_user((__sigrestore_t
)frame
->retcode
, &frame
->pretcode
) ||
279 __put_user(0x8efc0000|__NR_sigreturn
, &frame
->retcode
[0]) ||
280 __put_user(0xc0700000, &frame
->retcode
[1]))
283 flush_icache_range((unsigned long) frame
->retcode
,
284 (unsigned long) (frame
->retcode
+ 2));
287 /* Set up registers for the signal handler */
288 if (current
->personality
& FDPIC_FUNCPTRS
) {
289 struct fdpic_func_descriptor __user
*funcptr
=
290 (struct fdpic_func_descriptor __user
*) ka
->sa
.sa_handler
;
291 struct fdpic_func_descriptor desc
;
292 if (copy_from_user(&desc
, funcptr
, sizeof(desc
)))
294 __frame
->pc
= desc
.text
;
295 __frame
->gr15
= desc
.GOT
;
297 __frame
->pc
= (unsigned long) ka
->sa
.sa_handler
;
301 __frame
->sp
= (unsigned long) frame
;
302 __frame
->lr
= (unsigned long) &frame
->retcode
;
305 /* the tracer may want to single-step inside the handler */
306 if (test_thread_flag(TIF_SINGLESTEP
))
307 ptrace_notify(SIGTRAP
);
310 printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
311 sig
, current
->comm
, current
->pid
, frame
, __frame
->pc
,
318 force_sigsegv(sig
, current
);
321 } /* end setup_frame() */
323 /*****************************************************************************/
327 static int setup_rt_frame(int sig
, struct k_sigaction
*ka
, siginfo_t
*info
,
330 struct rt_sigframe __user
*frame
;
335 frame
= get_sigframe(ka
, sizeof(*frame
));
337 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
342 __current_thread_info
->exec_domain
&&
343 __current_thread_info
->exec_domain
->signal_invmap
)
344 rsig
= __current_thread_info
->exec_domain
->signal_invmap
[sig
];
346 if (__put_user(rsig
, &frame
->sig
) ||
347 __put_user(&frame
->info
, &frame
->pinfo
) ||
348 __put_user(&frame
->uc
, &frame
->puc
))
351 if (copy_siginfo_to_user(&frame
->info
, info
))
354 /* Create the ucontext. */
355 if (__put_user(0, &frame
->uc
.uc_flags
) ||
356 __put_user(NULL
, &frame
->uc
.uc_link
) ||
357 __put_user((void __user
*)current
->sas_ss_sp
, &frame
->uc
.uc_stack
.ss_sp
) ||
358 __put_user(sas_ss_flags(__frame
->sp
), &frame
->uc
.uc_stack
.ss_flags
) ||
359 __put_user(current
->sas_ss_size
, &frame
->uc
.uc_stack
.ss_size
))
362 if (setup_sigcontext(&frame
->uc
.uc_mcontext
, set
->sig
[0]))
365 if (__copy_to_user(&frame
->uc
.uc_sigmask
, set
, sizeof(*set
)))
368 /* Set up to return from userspace. If provided, use a stub
369 * already in userspace. */
370 if (ka
->sa
.sa_flags
& SA_RESTORER
) {
371 if (__put_user(ka
->sa
.sa_restorer
, &frame
->pretcode
))
375 /* Set up the following code on the stack:
376 * setlos #__NR_sigreturn,gr7
379 if (__put_user((__sigrestore_t
)frame
->retcode
, &frame
->pretcode
) ||
380 __put_user(0x8efc0000|__NR_rt_sigreturn
, &frame
->retcode
[0]) ||
381 __put_user(0xc0700000, &frame
->retcode
[1]))
384 flush_icache_range((unsigned long) frame
->retcode
,
385 (unsigned long) (frame
->retcode
+ 2));
388 /* Set up registers for signal handler */
389 if (current
->personality
& FDPIC_FUNCPTRS
) {
390 struct fdpic_func_descriptor __user
*funcptr
=
391 (struct fdpic_func_descriptor __user
*) ka
->sa
.sa_handler
;
392 struct fdpic_func_descriptor desc
;
393 if (copy_from_user(&desc
, funcptr
, sizeof(desc
)))
395 __frame
->pc
= desc
.text
;
396 __frame
->gr15
= desc
.GOT
;
398 __frame
->pc
= (unsigned long) ka
->sa
.sa_handler
;
402 __frame
->sp
= (unsigned long) frame
;
403 __frame
->lr
= (unsigned long) &frame
->retcode
;
405 __frame
->gr9
= (unsigned long) &frame
->info
;
407 /* the tracer may want to single-step inside the handler */
408 if (test_thread_flag(TIF_SINGLESTEP
))
409 ptrace_notify(SIGTRAP
);
412 printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
413 sig
, current
->comm
, current
->pid
, frame
, __frame
->pc
,
420 force_sigsegv(sig
, current
);
423 } /* end setup_rt_frame() */
425 /*****************************************************************************/
427 * OK, we're invoking a handler
429 static int handle_signal(unsigned long sig
, siginfo_t
*info
,
430 struct k_sigaction
*ka
)
432 sigset_t
*oldset
= sigmask_to_save();
435 /* Are we from a system call? */
436 if (__frame
->syscallno
!= -1) {
437 /* If so, check system call restarting.. */
438 switch (__frame
->gr8
) {
439 case -ERESTART_RESTARTBLOCK
:
440 case -ERESTARTNOHAND
:
441 __frame
->gr8
= -EINTR
;
445 if (!(ka
->sa
.sa_flags
& SA_RESTART
)) {
446 __frame
->gr8
= -EINTR
;
451 case -ERESTARTNOINTR
:
452 __frame
->gr8
= __frame
->orig_gr8
;
455 __frame
->syscallno
= -1;
458 /* Set up the stack frame */
459 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
460 ret
= setup_rt_frame(sig
, ka
, info
, oldset
);
462 ret
= setup_frame(sig
, ka
, oldset
);
465 block_sigmask(ka
, sig
);
469 } /* end handle_signal() */
471 /*****************************************************************************/
473 * Note that 'init' is a special process: it doesn't get signals it doesn't
474 * want to handle. Thus you cannot kill init even with a SIGKILL even by
477 static void do_signal(void)
479 struct k_sigaction ka
;
485 * We want the common case to go fast, which
486 * is why we may in certain cases get here from
487 * kernel mode. Just return without doing anything
490 if (!user_mode(__frame
))
496 signr
= get_signal_to_deliver(&info
, &ka
, __frame
, NULL
);
498 if (handle_signal(signr
, &info
, &ka
) == 0) {
499 /* a signal was successfully delivered; the saved
500 * sigmask will have been stored in the signal frame,
501 * and will be restored by sigreturn, so we can simply
502 * clear the TIF_RESTORE_SIGMASK flag */
503 if (test_thread_flag(TIF_RESTORE_SIGMASK
))
504 clear_thread_flag(TIF_RESTORE_SIGMASK
);
506 tracehook_signal_handler(signr
, &info
, &ka
, __frame
,
507 test_thread_flag(TIF_SINGLESTEP
));
514 /* Did we come from a system call? */
515 if (__frame
->syscallno
!= -1) {
516 /* Restart the system call - no handlers present */
517 switch (__frame
->gr8
) {
518 case -ERESTARTNOHAND
:
520 case -ERESTARTNOINTR
:
521 __frame
->gr8
= __frame
->orig_gr8
;
525 case -ERESTART_RESTARTBLOCK
:
526 __frame
->gr7
= __NR_restart_syscall
;
530 __frame
->syscallno
= -1;
533 /* if there's no signal to deliver, we just put the saved sigmask
535 restore_saved_sigmask();
536 } /* end do_signal() */
538 /*****************************************************************************/
540 * notification of userspace execution resumption
541 * - triggered by the TIF_WORK_MASK flags
543 asmlinkage
void do_notify_resume(__u32 thread_info_flags
)
545 /* pending single-step? */
546 if (thread_info_flags
& _TIF_SINGLESTEP
)
547 clear_thread_flag(TIF_SINGLESTEP
);
549 /* deal with pending signal delivery */
550 if (thread_info_flags
& (_TIF_SIGPENDING
| _TIF_RESTORE_SIGMASK
))
553 /* deal with notification on about to resume userspace execution */
554 if (thread_info_flags
& _TIF_NOTIFY_RESUME
) {
555 clear_thread_flag(TIF_NOTIFY_RESUME
);
556 tracehook_notify_resume(__frame
);
559 } /* end do_notify_resume() */