]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/cris/arch-v10/kernel/signal.c
2 * linux/arch/cris/kernel/signal.c
4 * Based on arch/i386/kernel/signal.c by
5 * Copyright (C) 1991, 1992 Linus Torvalds
6 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson *
8 * Ideas also taken from arch/arm.
10 * Copyright (C) 2000-2007 Axis Communications AB
12 * Authors: Bjorn Wesen (bjornw@axis.com)
16 #include <linux/sched.h>
18 #include <linux/smp.h>
19 #include <linux/kernel.h>
20 #include <linux/signal.h>
21 #include <linux/errno.h>
22 #include <linux/wait.h>
23 #include <linux/ptrace.h>
24 #include <linux/unistd.h>
25 #include <linux/stddef.h>
27 #include <asm/processor.h>
28 #include <asm/ucontext.h>
29 #include <asm/uaccess.h>
30 #include <arch/system.h>
34 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
36 /* a syscall in Linux/CRIS is a break 13 instruction which is 2 bytes */
37 /* manipulate regs so that upon return, it will be re-executed */
39 /* We rely on that pc points to the instruction after "break 13", so the
40 * library must never do strange things like putting it in a delay slot.
42 #define RESTART_CRIS_SYS(regs) regs->r10 = regs->orig_r10; regs->irp -= 2;
44 void do_signal(int canrestart
, struct pt_regs
*regs
);
47 * Atomically swap in the new signal mask, and wait for a signal. Define
48 * dummy arguments to be able to reach the regs argument. (Note that this
49 * arrangement relies on old_sigset_t occupying one register.)
51 int sys_sigsuspend(old_sigset_t mask
, long r11
, long r12
, long r13
, long mof
,
52 long srp
, struct pt_regs
*regs
)
55 spin_lock_irq(¤t
->sighand
->siglock
);
56 current
->saved_sigmask
= current
->blocked
;
57 siginitset(¤t
->blocked
, mask
);
59 spin_unlock_irq(¤t
->sighand
->siglock
);
60 current
->state
= TASK_INTERRUPTIBLE
;
62 set_thread_flag(TIF_RESTORE_SIGMASK
);
63 return -ERESTARTNOHAND
;
66 int sys_sigaction(int sig
, const struct old_sigaction __user
*act
,
67 struct old_sigaction
*oact
)
69 struct k_sigaction new_ka
, old_ka
;
74 if (!access_ok(VERIFY_READ
, act
, sizeof(*act
)) ||
75 __get_user(new_ka
.sa
.sa_handler
, &act
->sa_handler
) ||
76 __get_user(new_ka
.sa
.sa_restorer
, &act
->sa_restorer
))
78 __get_user(new_ka
.sa
.sa_flags
, &act
->sa_flags
);
79 __get_user(mask
, &act
->sa_mask
);
80 siginitset(&new_ka
.sa
.sa_mask
, mask
);
83 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
86 if (!access_ok(VERIFY_WRITE
, oact
, sizeof(*oact
)) ||
87 __put_user(old_ka
.sa
.sa_handler
, &oact
->sa_handler
) ||
88 __put_user(old_ka
.sa
.sa_restorer
, &oact
->sa_restorer
))
90 __put_user(old_ka
.sa
.sa_flags
, &oact
->sa_flags
);
91 __put_user(old_ka
.sa
.sa_mask
.sig
[0], &oact
->sa_mask
);
97 int sys_sigaltstack(const stack_t
*uss
, stack_t __user
*uoss
)
99 return do_sigaltstack(uss
, uoss
, rdusp());
104 * Do a signal return; undo the signal stack.
108 struct sigcontext sc
;
109 unsigned long extramask
[_NSIG_WORDS
-1];
110 unsigned char retcode
[8]; /* trampoline code */
114 struct siginfo
*pinfo
;
118 unsigned char retcode
[8]; /* trampoline code */
123 restore_sigcontext(struct pt_regs
*regs
, struct sigcontext __user
*sc
)
125 unsigned int err
= 0;
126 unsigned long old_usp
;
128 /* Always make any pending restarted system calls return -EINTR */
129 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
131 /* restore the regs from &sc->regs (same as sc, since regs is first)
132 * (sc is already checked for VERIFY_READ since the sigframe was
133 * checked in sys_sigreturn previously)
136 if (__copy_from_user(regs
, sc
, sizeof(struct pt_regs
)))
139 /* make sure the U-flag is set so user-mode cannot fool us */
141 regs
->dccr
|= 1 << 8;
143 /* restore the old USP as it was before we stacked the sc etc.
144 * (we cannot just pop the sigcontext since we aligned the sp and
145 * stuff after pushing it)
148 err
|= __get_user(old_usp
, &sc
->usp
);
152 /* TODO: the other ports use regs->orig_XX to disable syscall checks
153 * after this completes, but we don't use that mechanism. maybe we can
163 /* Define dummy arguments to be able to reach the regs argument. */
165 asmlinkage
int sys_sigreturn(long r10
, long r11
, long r12
, long r13
, long mof
,
166 long srp
, struct pt_regs
*regs
)
168 struct sigframe __user
*frame
= (struct sigframe
*)rdusp();
172 * Since we stacked the signal on a dword boundary,
173 * then frame should be dword aligned here. If it's
174 * not, then the user is trying to mess with us.
176 if (((long)frame
) & 3)
179 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
181 if (__get_user(set
.sig
[0], &frame
->sc
.oldmask
)
183 && __copy_from_user(&set
.sig
[1], frame
->extramask
,
184 sizeof(frame
->extramask
))))
187 sigdelsetmask(&set
, ~_BLOCKABLE
);
188 spin_lock_irq(¤t
->sighand
->siglock
);
189 current
->blocked
= set
;
191 spin_unlock_irq(¤t
->sighand
->siglock
);
193 if (restore_sigcontext(regs
, &frame
->sc
))
196 /* TODO: SIGTRAP when single-stepping as in arm ? */
201 force_sig(SIGSEGV
, current
);
205 /* Define dummy arguments to be able to reach the regs argument. */
207 asmlinkage
int sys_rt_sigreturn(long r10
, long r11
, long r12
, long r13
,
208 long mof
, long srp
, struct pt_regs
*regs
)
210 struct rt_sigframe __user
*frame
= (struct rt_sigframe
*)rdusp();
214 * Since we stacked the signal on a dword boundary,
215 * then frame should be dword aligned here. If it's
216 * not, then the user is trying to mess with us.
218 if (((long)frame
) & 3)
221 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
223 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
226 sigdelsetmask(&set
, ~_BLOCKABLE
);
227 spin_lock_irq(¤t
->sighand
->siglock
);
228 current
->blocked
= set
;
230 spin_unlock_irq(¤t
->sighand
->siglock
);
232 if (restore_sigcontext(regs
, &frame
->uc
.uc_mcontext
))
235 if (do_sigaltstack(&frame
->uc
.uc_stack
, NULL
, rdusp()) == -EFAULT
)
241 force_sig(SIGSEGV
, current
);
246 * Set up a signal frame.
249 static int setup_sigcontext(struct sigcontext __user
*sc
,
250 struct pt_regs
*regs
, unsigned long mask
)
253 unsigned long usp
= rdusp();
255 /* copy the regs. they are first in sc so we can use sc directly */
257 err
|= __copy_to_user(sc
, regs
, sizeof(struct pt_regs
));
259 /* Set the frametype to CRIS_FRAME_NORMAL for the execution of
260 the signal handler. The frametype will be restored to its previous
261 value in restore_sigcontext. */
262 regs
->frametype
= CRIS_FRAME_NORMAL
;
264 /* then some other stuff */
266 err
|= __put_user(mask
, &sc
->oldmask
);
268 err
|= __put_user(usp
, &sc
->usp
);
273 /* Figure out where we want to put the new signal frame
274 * - usually on the stack. */
276 static inline void __user
*
277 get_sigframe(struct k_sigaction
*ka
, struct pt_regs
*regs
, size_t frame_size
)
279 unsigned long sp
= rdusp();
281 /* This is the X/Open sanctioned signal stack switching. */
282 if (ka
->sa
.sa_flags
& SA_ONSTACK
) {
283 if (! on_sig_stack(sp
))
284 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
287 /* make sure the frame is dword-aligned */
291 return (void __user
*)(sp
- frame_size
);
294 /* grab and setup a signal frame.
296 * basically we stack a lot of state info, and arrange for the
297 * user-mode program to return to the kernel using either a
298 * trampoline which performs the syscall sigreturn, or a provided
299 * user-mode trampoline.
302 static int setup_frame(int sig
, struct k_sigaction
*ka
,
303 sigset_t
*set
, struct pt_regs
*regs
)
305 struct sigframe __user
*frame
;
306 unsigned long return_ip
;
309 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
311 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
314 err
|= setup_sigcontext(&frame
->sc
, regs
, set
->sig
[0]);
318 if (_NSIG_WORDS
> 1) {
319 err
|= __copy_to_user(frame
->extramask
, &set
->sig
[1],
320 sizeof(frame
->extramask
));
325 /* Set up to return from userspace. If provided, use a stub
326 already in userspace. */
327 if (ka
->sa
.sa_flags
& SA_RESTORER
) {
328 return_ip
= (unsigned long)ka
->sa
.sa_restorer
;
330 /* trampoline - the desired return ip is the retcode itself */
331 return_ip
= (unsigned long)&frame
->retcode
;
332 /* This is movu.w __NR_sigreturn, r9; break 13; */
333 err
|= __put_user(0x9c5f, (short __user
*)(frame
->retcode
+0));
334 err
|= __put_user(__NR_sigreturn
, (short __user
*)(frame
->retcode
+2));
335 err
|= __put_user(0xe93d, (short __user
*)(frame
->retcode
+4));
341 /* Set up registers for signal handler */
343 regs
->irp
= (unsigned long) ka
->sa
.sa_handler
; /* what we enter NOW */
344 regs
->srp
= return_ip
; /* what we enter LATER */
345 regs
->r10
= sig
; /* first argument is signo */
347 /* actually move the usp to reflect the stacked frame */
349 wrusp((unsigned long)frame
);
354 force_sigsegv(sig
, current
);
358 static int setup_rt_frame(int sig
, struct k_sigaction
*ka
, siginfo_t
*info
,
359 sigset_t
*set
, struct pt_regs
*regs
)
361 struct rt_sigframe __user
*frame
;
362 unsigned long return_ip
;
365 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
367 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
370 err
|= __put_user(&frame
->info
, &frame
->pinfo
);
371 err
|= __put_user(&frame
->uc
, &frame
->puc
);
372 err
|= copy_siginfo_to_user(&frame
->info
, info
);
376 /* Clear all the bits of the ucontext we don't use. */
377 err
|= __clear_user(&frame
->uc
, offsetof(struct ucontext
, uc_mcontext
));
379 err
|= setup_sigcontext(&frame
->uc
.uc_mcontext
, regs
, set
->sig
[0]);
381 err
|= __copy_to_user(&frame
->uc
.uc_sigmask
, set
, sizeof(*set
));
386 /* Set up to return from userspace. If provided, use a stub
387 already in userspace. */
388 if (ka
->sa
.sa_flags
& SA_RESTORER
) {
389 return_ip
= (unsigned long)ka
->sa
.sa_restorer
;
391 /* trampoline - the desired return ip is the retcode itself */
392 return_ip
= (unsigned long)&frame
->retcode
;
393 /* This is movu.w __NR_rt_sigreturn, r9; break 13; */
394 err
|= __put_user(0x9c5f, (short __user
*)(frame
->retcode
+0));
395 err
|= __put_user(__NR_rt_sigreturn
,
396 (short __user
*)(frame
->retcode
+2));
397 err
|= __put_user(0xe93d, (short __user
*)(frame
->retcode
+4));
403 /* TODO what is the current->exec_domain stuff and invmap ? */
405 /* Set up registers for signal handler */
407 /* What we enter NOW */
408 regs
->irp
= (unsigned long) ka
->sa
.sa_handler
;
409 /* What we enter LATER */
410 regs
->srp
= return_ip
;
411 /* First argument is signo */
413 /* Second argument is (siginfo_t *) */
414 regs
->r11
= (unsigned long)&frame
->info
;
415 /* Third argument is unused */
418 /* Actually move the usp to reflect the stacked frame */
419 wrusp((unsigned long)frame
);
424 force_sigsegv(sig
, current
);
429 * OK, we're invoking a handler
432 static inline int handle_signal(int canrestart
, unsigned long sig
,
433 siginfo_t
*info
, struct k_sigaction
*ka
,
434 sigset_t
*oldset
, struct pt_regs
*regs
)
438 /* Are we from a system call? */
440 /* If so, check system call restarting.. */
442 case -ERESTART_RESTARTBLOCK
:
443 case -ERESTARTNOHAND
:
444 /* ERESTARTNOHAND means that the syscall should
445 * only be restarted if there was no handler for
446 * the signal, and since we only get here if there
447 * is a handler, we don't restart */
451 /* ERESTARTSYS means to restart the syscall if
452 * there is no handler or the handler was
453 * registered with SA_RESTART */
454 if (!(ka
->sa
.sa_flags
& SA_RESTART
)) {
459 case -ERESTARTNOINTR
:
460 /* ERESTARTNOINTR means that the syscall should
461 * be called again after the signal handler returns. */
462 RESTART_CRIS_SYS(regs
);
466 /* Set up the stack frame */
467 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
468 ret
= setup_rt_frame(sig
, ka
, info
, oldset
, regs
);
470 ret
= setup_frame(sig
, ka
, oldset
, regs
);
473 spin_lock_irq(¤t
->sighand
->siglock
);
474 sigorsets(¤t
->blocked
, ¤t
->blocked
,
476 if (!(ka
->sa
.sa_flags
& SA_NODEFER
))
477 sigaddset(¤t
->blocked
, sig
);
479 spin_unlock_irq(¤t
->sighand
->siglock
);
485 * Note that 'init' is a special process: it doesn't get signals it doesn't
486 * want to handle. Thus you cannot kill init even with a SIGKILL even by
489 * Also note that the regs structure given here as an argument, is the latest
490 * pushed pt_regs. It may or may not be the same as the first pushed registers
491 * when the initial usermode->kernelmode transition took place. Therefore
492 * we can use user_mode(regs) to see if we came directly from kernel or user
496 void do_signal(int canrestart
, struct pt_regs
*regs
)
500 struct k_sigaction ka
;
504 * We want the common case to go fast, which
505 * is why we may in certain cases get here from
506 * kernel mode. Just return without doing anything
509 if (!user_mode(regs
))
512 if (test_thread_flag(TIF_RESTORE_SIGMASK
))
513 oldset
= ¤t
->saved_sigmask
;
515 oldset
= ¤t
->blocked
;
517 signr
= get_signal_to_deliver(&info
, &ka
, regs
, NULL
);
519 /* Whee! Actually deliver the signal. */
520 if (handle_signal(canrestart
, signr
, &info
, &ka
,
522 /* a signal was successfully delivered; the saved
523 * sigmask will have been stored in the signal frame,
524 * and will be restored by sigreturn, so we can simply
525 * clear the TIF_RESTORE_SIGMASK flag */
526 if (test_thread_flag(TIF_RESTORE_SIGMASK
))
527 clear_thread_flag(TIF_RESTORE_SIGMASK
);
532 /* Did we come from a system call? */
534 /* Restart the system call - no handlers present */
535 if (regs
->r10
== -ERESTARTNOHAND
||
536 regs
->r10
== -ERESTARTSYS
||
537 regs
->r10
== -ERESTARTNOINTR
) {
538 RESTART_CRIS_SYS(regs
);
540 if (regs
->r10
== -ERESTART_RESTARTBLOCK
) {
541 regs
->r9
= __NR_restart_syscall
;
546 /* if there's no signal to deliver, we just put the saved sigmask
548 if (test_thread_flag(TIF_RESTORE_SIGMASK
)) {
549 clear_thread_flag(TIF_RESTORE_SIGMASK
);
550 sigprocmask(SIG_SETMASK
, ¤t
->saved_sigmask
, NULL
);