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/tracehook.h>
24 #include <asm/ucontext.h>
25 #include <asm/uaccess.h>
26 #include <asm/cacheflush.h>
30 struct fdpic_func_descriptor
{
36 * Atomically swap in the new signal mask, and wait for a signal.
38 asmlinkage
int sys_sigsuspend(int history0
, int history1
, old_sigset_t mask
)
41 siginitset(&blocked
, mask
);
42 return sigsuspend(&blocked
);
45 asmlinkage
int sys_sigaction(int sig
,
46 const struct old_sigaction __user
*act
,
47 struct old_sigaction __user
*oact
)
49 struct k_sigaction new_ka
, old_ka
;
54 if (!access_ok(VERIFY_READ
, act
, sizeof(*act
)) ||
55 __get_user(new_ka
.sa
.sa_handler
, &act
->sa_handler
) ||
56 __get_user(new_ka
.sa
.sa_restorer
, &act
->sa_restorer
) ||
57 __get_user(new_ka
.sa
.sa_flags
, &act
->sa_flags
) ||
58 __get_user(mask
, &act
->sa_mask
))
60 siginitset(&new_ka
.sa
.sa_mask
, mask
);
63 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
66 if (!access_ok(VERIFY_WRITE
, oact
, sizeof(*oact
)) ||
67 __put_user(old_ka
.sa
.sa_handler
, &oact
->sa_handler
) ||
68 __put_user(old_ka
.sa
.sa_restorer
, &oact
->sa_restorer
) ||
69 __put_user(old_ka
.sa
.sa_flags
, &oact
->sa_flags
) ||
70 __put_user(old_ka
.sa
.sa_mask
.sig
[0], &oact
->sa_mask
))
78 int sys_sigaltstack(const stack_t __user
*uss
, stack_t __user
*uoss
)
80 return do_sigaltstack(uss
, uoss
, __frame
->sp
);
85 * Do a signal return; undo the signal stack.
90 __sigrestore_t pretcode
;
93 unsigned long extramask
[_NSIG_WORDS
-1];
99 __sigrestore_t pretcode
;
101 struct siginfo __user
*pinfo
;
108 static int restore_sigcontext(struct sigcontext __user
*sc
, int *_gr8
)
110 struct user_context
*user
= current
->thread
.user
;
111 unsigned long tbr
, psr
;
113 /* Always make any pending restarted system calls return -EINTR */
114 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
118 if (copy_from_user(user
, &sc
->sc_context
, sizeof(sc
->sc_context
)))
123 restore_user_regs(user
);
125 user
->i
.syscallno
= -1; /* disable syscall checks */
127 *_gr8
= user
->i
.gr
[8];
134 asmlinkage
int sys_sigreturn(void)
136 struct sigframe __user
*frame
= (struct sigframe __user
*) __frame
->sp
;
140 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
142 if (__get_user(set
.sig
[0], &frame
->sc
.sc_oldmask
))
145 if (_NSIG_WORDS
> 1 &&
146 __copy_from_user(&set
.sig
[1], &frame
->extramask
, sizeof(frame
->extramask
)))
149 set_current_blocked(&set
);
151 if (restore_sigcontext(&frame
->sc
, &gr8
))
156 force_sig(SIGSEGV
, current
);
160 asmlinkage
int sys_rt_sigreturn(void)
162 struct rt_sigframe __user
*frame
= (struct rt_sigframe __user
*) __frame
->sp
;
166 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
168 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
171 set_current_blocked(&set
);
173 if (restore_sigcontext(&frame
->uc
.uc_mcontext
, &gr8
))
176 if (do_sigaltstack(&frame
->uc
.uc_stack
, NULL
, __frame
->sp
) == -EFAULT
)
182 force_sig(SIGSEGV
, current
);
187 * Set up a signal frame
189 static int setup_sigcontext(struct sigcontext __user
*sc
, unsigned long mask
)
191 save_user_regs(current
->thread
.user
);
193 if (copy_to_user(&sc
->sc_context
, current
->thread
.user
, sizeof(sc
->sc_context
)) != 0)
196 /* non-iBCS2 extensions.. */
197 if (__put_user(mask
, &sc
->sc_oldmask
) < 0)
206 /*****************************************************************************/
208 * Determine which stack to use..
210 static inline void __user
*get_sigframe(struct k_sigaction
*ka
,
215 /* Default to using normal stack */
218 /* This is the X/Open sanctioned signal stack switching. */
219 if (ka
->sa
.sa_flags
& SA_ONSTACK
) {
220 if (! sas_ss_flags(sp
))
221 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
224 return (void __user
*) ((sp
- frame_size
) & ~7UL);
226 } /* end get_sigframe() */
228 /*****************************************************************************/
232 static int setup_frame(int sig
, struct k_sigaction
*ka
, sigset_t
*set
)
234 struct sigframe __user
*frame
;
239 frame
= get_sigframe(ka
, sizeof(*frame
));
241 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
246 __current_thread_info
->exec_domain
&&
247 __current_thread_info
->exec_domain
->signal_invmap
)
248 rsig
= __current_thread_info
->exec_domain
->signal_invmap
[sig
];
250 if (__put_user(rsig
, &frame
->sig
) < 0)
253 if (setup_sigcontext(&frame
->sc
, set
->sig
[0]))
256 if (_NSIG_WORDS
> 1) {
257 if (__copy_to_user(frame
->extramask
, &set
->sig
[1],
258 sizeof(frame
->extramask
)))
262 /* Set up to return from userspace. If provided, use a stub
263 * already in userspace. */
264 if (ka
->sa
.sa_flags
& SA_RESTORER
) {
265 if (__put_user(ka
->sa
.sa_restorer
, &frame
->pretcode
) < 0)
269 /* Set up the following code on the stack:
270 * setlos #__NR_sigreturn,gr7
273 if (__put_user((__sigrestore_t
)frame
->retcode
, &frame
->pretcode
) ||
274 __put_user(0x8efc0000|__NR_sigreturn
, &frame
->retcode
[0]) ||
275 __put_user(0xc0700000, &frame
->retcode
[1]))
278 flush_icache_range((unsigned long) frame
->retcode
,
279 (unsigned long) (frame
->retcode
+ 2));
282 /* Set up registers for the signal handler */
283 if (current
->personality
& FDPIC_FUNCPTRS
) {
284 struct fdpic_func_descriptor __user
*funcptr
=
285 (struct fdpic_func_descriptor __user
*) ka
->sa
.sa_handler
;
286 struct fdpic_func_descriptor desc
;
287 if (copy_from_user(&desc
, funcptr
, sizeof(desc
)))
289 __frame
->pc
= desc
.text
;
290 __frame
->gr15
= desc
.GOT
;
292 __frame
->pc
= (unsigned long) ka
->sa
.sa_handler
;
296 __frame
->sp
= (unsigned long) frame
;
297 __frame
->lr
= (unsigned long) &frame
->retcode
;
301 printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
302 sig
, current
->comm
, current
->pid
, frame
, __frame
->pc
,
309 force_sigsegv(sig
, current
);
312 } /* end setup_frame() */
314 /*****************************************************************************/
318 static int setup_rt_frame(int sig
, struct k_sigaction
*ka
, siginfo_t
*info
,
321 struct rt_sigframe __user
*frame
;
326 frame
= get_sigframe(ka
, sizeof(*frame
));
328 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
333 __current_thread_info
->exec_domain
&&
334 __current_thread_info
->exec_domain
->signal_invmap
)
335 rsig
= __current_thread_info
->exec_domain
->signal_invmap
[sig
];
337 if (__put_user(rsig
, &frame
->sig
) ||
338 __put_user(&frame
->info
, &frame
->pinfo
) ||
339 __put_user(&frame
->uc
, &frame
->puc
))
342 if (copy_siginfo_to_user(&frame
->info
, info
))
345 /* Create the ucontext. */
346 if (__put_user(0, &frame
->uc
.uc_flags
) ||
347 __put_user(NULL
, &frame
->uc
.uc_link
) ||
348 __put_user((void __user
*)current
->sas_ss_sp
, &frame
->uc
.uc_stack
.ss_sp
) ||
349 __put_user(sas_ss_flags(__frame
->sp
), &frame
->uc
.uc_stack
.ss_flags
) ||
350 __put_user(current
->sas_ss_size
, &frame
->uc
.uc_stack
.ss_size
))
353 if (setup_sigcontext(&frame
->uc
.uc_mcontext
, set
->sig
[0]))
356 if (__copy_to_user(&frame
->uc
.uc_sigmask
, set
, sizeof(*set
)))
359 /* Set up to return from userspace. If provided, use a stub
360 * already in userspace. */
361 if (ka
->sa
.sa_flags
& SA_RESTORER
) {
362 if (__put_user(ka
->sa
.sa_restorer
, &frame
->pretcode
))
366 /* Set up the following code on the stack:
367 * setlos #__NR_sigreturn,gr7
370 if (__put_user((__sigrestore_t
)frame
->retcode
, &frame
->pretcode
) ||
371 __put_user(0x8efc0000|__NR_rt_sigreturn
, &frame
->retcode
[0]) ||
372 __put_user(0xc0700000, &frame
->retcode
[1]))
375 flush_icache_range((unsigned long) frame
->retcode
,
376 (unsigned long) (frame
->retcode
+ 2));
379 /* Set up registers for signal handler */
380 if (current
->personality
& FDPIC_FUNCPTRS
) {
381 struct fdpic_func_descriptor __user
*funcptr
=
382 (struct fdpic_func_descriptor __user
*) ka
->sa
.sa_handler
;
383 struct fdpic_func_descriptor desc
;
384 if (copy_from_user(&desc
, funcptr
, sizeof(desc
)))
386 __frame
->pc
= desc
.text
;
387 __frame
->gr15
= desc
.GOT
;
389 __frame
->pc
= (unsigned long) ka
->sa
.sa_handler
;
393 __frame
->sp
= (unsigned long) frame
;
394 __frame
->lr
= (unsigned long) &frame
->retcode
;
396 __frame
->gr9
= (unsigned long) &frame
->info
;
399 printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
400 sig
, current
->comm
, current
->pid
, frame
, __frame
->pc
,
407 force_sigsegv(sig
, current
);
410 } /* end setup_rt_frame() */
412 /*****************************************************************************/
414 * OK, we're invoking a handler
416 static void handle_signal(unsigned long sig
, siginfo_t
*info
,
417 struct k_sigaction
*ka
)
419 sigset_t
*oldset
= sigmask_to_save();
422 /* Are we from a system call? */
423 if (__frame
->syscallno
!= -1) {
424 /* If so, check system call restarting.. */
425 switch (__frame
->gr8
) {
426 case -ERESTART_RESTARTBLOCK
:
427 case -ERESTARTNOHAND
:
428 __frame
->gr8
= -EINTR
;
432 if (!(ka
->sa
.sa_flags
& SA_RESTART
)) {
433 __frame
->gr8
= -EINTR
;
438 case -ERESTARTNOINTR
:
439 __frame
->gr8
= __frame
->orig_gr8
;
442 __frame
->syscallno
= -1;
445 /* Set up the stack frame */
446 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
447 ret
= setup_rt_frame(sig
, ka
, info
, oldset
);
449 ret
= setup_frame(sig
, ka
, oldset
);
454 signal_delivered(sig
, info
, ka
, __frame
,
455 test_thread_flag(TIF_SINGLESTEP
));
456 } /* end handle_signal() */
458 /*****************************************************************************/
460 * Note that 'init' is a special process: it doesn't get signals it doesn't
461 * want to handle. Thus you cannot kill init even with a SIGKILL even by
464 static void do_signal(void)
466 struct k_sigaction ka
;
470 signr
= get_signal_to_deliver(&info
, &ka
, __frame
, NULL
);
472 handle_signal(signr
, &info
, &ka
);
476 /* Did we come from a system call? */
477 if (__frame
->syscallno
!= -1) {
478 /* Restart the system call - no handlers present */
479 switch (__frame
->gr8
) {
480 case -ERESTARTNOHAND
:
482 case -ERESTARTNOINTR
:
483 __frame
->gr8
= __frame
->orig_gr8
;
487 case -ERESTART_RESTARTBLOCK
:
488 __frame
->gr7
= __NR_restart_syscall
;
492 __frame
->syscallno
= -1;
495 /* if there's no signal to deliver, we just put the saved sigmask
497 restore_saved_sigmask();
498 } /* end do_signal() */
500 /*****************************************************************************/
502 * notification of userspace execution resumption
503 * - triggered by the TIF_WORK_MASK flags
505 asmlinkage
void do_notify_resume(__u32 thread_info_flags
)
507 /* pending single-step? */
508 if (thread_info_flags
& _TIF_SINGLESTEP
)
509 clear_thread_flag(TIF_SINGLESTEP
);
511 /* deal with pending signal delivery */
512 if (thread_info_flags
& _TIF_SIGPENDING
)
515 /* deal with notification on about to resume userspace execution */
516 if (thread_info_flags
& _TIF_NOTIFY_RESUME
) {
517 clear_thread_flag(TIF_NOTIFY_RESUME
);
518 tracehook_notify_resume(__frame
);
521 } /* end do_notify_resume() */