2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1991, 1992 Linus Torvalds
7 * Copyright (C) 1994 - 2000 Ralf Baechle
8 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
10 #include <linux/config.h>
11 #include <linux/cache.h>
12 #include <linux/sched.h>
14 #include <linux/personality.h>
15 #include <linux/smp.h>
16 #include <linux/smp_lock.h>
17 #include <linux/kernel.h>
18 #include <linux/signal.h>
19 #include <linux/errno.h>
20 #include <linux/wait.h>
21 #include <linux/ptrace.h>
22 #include <linux/unistd.h>
23 #include <linux/compiler.h>
27 #include <linux/bitops.h>
28 #include <asm/cacheflush.h>
31 #include <asm/uaccess.h>
32 #include <asm/ucontext.h>
33 #include <asm/cpu-features.h>
36 #include "signal-common.h"
40 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
43 * Atomically swap in the new signal mask, and wait for a signal.
46 #ifdef CONFIG_TRAD_SIGNALS
47 save_static_function(sys_sigsuspend
);
48 __attribute_used__ noinline
static int
49 _sys_sigsuspend(nabi_no_regargs
struct pt_regs regs
)
52 sigset_t __user
*uset
;
54 uset
= (sigset_t __user
*) regs
.regs
[4];
55 if (copy_from_user(&newset
, uset
, sizeof(sigset_t
)))
57 sigdelsetmask(&newset
, ~_BLOCKABLE
);
59 spin_lock_irq(¤t
->sighand
->siglock
);
60 current
->saved_sigmask
= current
->blocked
;
61 current
->blocked
= newset
;
63 spin_unlock_irq(¤t
->sighand
->siglock
);
65 current
->state
= TASK_INTERRUPTIBLE
;
67 set_thread_flag(TIF_RESTORE_SIGMASK
);
68 return -ERESTARTNOHAND
;
72 save_static_function(sys_rt_sigsuspend
);
73 __attribute_used__ noinline
static int
74 _sys_rt_sigsuspend(nabi_no_regargs
struct pt_regs regs
)
77 sigset_t __user
*unewset
;
80 /* XXX Don't preclude handling different sized sigset_t's. */
81 sigsetsize
= regs
.regs
[5];
82 if (sigsetsize
!= sizeof(sigset_t
))
85 unewset
= (sigset_t __user
*) regs
.regs
[4];
86 if (copy_from_user(&newset
, unewset
, sizeof(newset
)))
88 sigdelsetmask(&newset
, ~_BLOCKABLE
);
90 spin_lock_irq(¤t
->sighand
->siglock
);
91 current
->saved_sigmask
= current
->blocked
;
92 current
->blocked
= newset
;
94 spin_unlock_irq(¤t
->sighand
->siglock
);
96 current
->state
= TASK_INTERRUPTIBLE
;
98 set_thread_flag(TIF_RESTORE_SIGMASK
);
99 return -ERESTARTNOHAND
;
102 #ifdef CONFIG_TRAD_SIGNALS
103 asmlinkage
int sys_sigaction(int sig
, const struct sigaction __user
*act
,
104 struct sigaction __user
*oact
)
106 struct k_sigaction new_ka
, old_ka
;
113 if (!access_ok(VERIFY_READ
, act
, sizeof(*act
)))
115 err
|= __get_user(new_ka
.sa
.sa_handler
, &act
->sa_handler
);
116 err
|= __get_user(new_ka
.sa
.sa_flags
, &act
->sa_flags
);
117 err
|= __get_user(mask
, &act
->sa_mask
.sig
[0]);
121 siginitset(&new_ka
.sa
.sa_mask
, mask
);
124 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
127 if (!access_ok(VERIFY_WRITE
, oact
, sizeof(*oact
)))
129 err
|= __put_user(old_ka
.sa
.sa_flags
, &oact
->sa_flags
);
130 err
|= __put_user(old_ka
.sa
.sa_handler
, &oact
->sa_handler
);
131 err
|= __put_user(old_ka
.sa
.sa_mask
.sig
[0], oact
->sa_mask
.sig
);
132 err
|= __put_user(0, &oact
->sa_mask
.sig
[1]);
133 err
|= __put_user(0, &oact
->sa_mask
.sig
[2]);
134 err
|= __put_user(0, &oact
->sa_mask
.sig
[3]);
143 asmlinkage
int sys_sigaltstack(nabi_no_regargs
struct pt_regs regs
)
145 const stack_t __user
*uss
= (const stack_t __user
*) regs
.regs
[4];
146 stack_t __user
*uoss
= (stack_t __user
*) regs
.regs
[5];
147 unsigned long usp
= regs
.regs
[29];
149 return do_sigaltstack(uss
, uoss
, usp
);
153 * Horribly complicated - with the bloody RM9000 workarounds enabled
154 * the signal trampolines is moving to the end of the structure so we can
155 * increase the alignment without breaking software compatibility.
157 #ifdef CONFIG_TRAD_SIGNALS
159 u32 sf_ass
[4]; /* argument save space for o32 */
160 #if ICACHE_REFILLS_WORKAROUND_WAR
163 u32 sf_code
[2]; /* signal trampoline */
165 struct sigcontext sf_sc
;
167 #if ICACHE_REFILLS_WORKAROUND_WAR
168 u32 sf_code
[8] ____cacheline_aligned
; /* signal trampoline */
174 u32 rs_ass
[4]; /* argument save space for o32 */
175 #if ICACHE_REFILLS_WORKAROUND_WAR
178 u32 rs_code
[2]; /* signal trampoline */
180 struct siginfo rs_info
;
181 struct ucontext rs_uc
;
182 #if ICACHE_REFILLS_WORKAROUND_WAR
183 u32 rs_code
[8] ____cacheline_aligned
; /* signal trampoline */
187 #ifdef CONFIG_TRAD_SIGNALS
188 save_static_function(sys_sigreturn
);
189 __attribute_used__ noinline
static void
190 _sys_sigreturn(nabi_no_regargs
struct pt_regs regs
)
192 struct sigframe __user
*frame
;
195 frame
= (struct sigframe __user
*) regs
.regs
[29];
196 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
198 if (__copy_from_user(&blocked
, &frame
->sf_mask
, sizeof(blocked
)))
201 sigdelsetmask(&blocked
, ~_BLOCKABLE
);
202 spin_lock_irq(¤t
->sighand
->siglock
);
203 current
->blocked
= blocked
;
205 spin_unlock_irq(¤t
->sighand
->siglock
);
207 if (restore_sigcontext(®s
, &frame
->sf_sc
))
211 * Don't let your children do this ...
213 __asm__
__volatile__(
221 force_sig(SIGSEGV
, current
);
223 #endif /* CONFIG_TRAD_SIGNALS */
225 save_static_function(sys_rt_sigreturn
);
226 __attribute_used__ noinline
static void
227 _sys_rt_sigreturn(nabi_no_regargs
struct pt_regs regs
)
229 struct rt_sigframe __user
*frame
;
233 frame
= (struct rt_sigframe __user
*) regs
.regs
[29];
234 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
236 if (__copy_from_user(&set
, &frame
->rs_uc
.uc_sigmask
, sizeof(set
)))
239 sigdelsetmask(&set
, ~_BLOCKABLE
);
240 spin_lock_irq(¤t
->sighand
->siglock
);
241 current
->blocked
= set
;
243 spin_unlock_irq(¤t
->sighand
->siglock
);
245 if (restore_sigcontext(®s
, &frame
->rs_uc
.uc_mcontext
))
248 if (__copy_from_user(&st
, &frame
->rs_uc
.uc_stack
, sizeof(st
)))
250 /* It is more difficult to avoid calling this function than to
251 call it and ignore errors. */
252 do_sigaltstack((stack_t __user
*)&st
, NULL
, regs
.regs
[29]);
255 * Don't let your children do this ...
257 __asm__
__volatile__(
265 force_sig(SIGSEGV
, current
);
268 #ifdef CONFIG_TRAD_SIGNALS
269 int setup_frame(struct k_sigaction
* ka
, struct pt_regs
*regs
,
270 int signr
, sigset_t
*set
)
272 struct sigframe __user
*frame
;
275 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
276 if (!access_ok(VERIFY_WRITE
, frame
, sizeof (*frame
)))
279 install_sigtramp(frame
->sf_code
, __NR_sigreturn
);
281 err
|= setup_sigcontext(regs
, &frame
->sf_sc
);
282 err
|= __copy_to_user(&frame
->sf_mask
, set
, sizeof(*set
));
287 * Arguments to signal handler:
290 * a1 = 0 (should be cause)
291 * a2 = pointer to struct sigcontext
293 * $25 and c0_epc point to the signal handler, $29 points to the
296 regs
->regs
[ 4] = signr
;
298 regs
->regs
[ 6] = (unsigned long) &frame
->sf_sc
;
299 regs
->regs
[29] = (unsigned long) frame
;
300 regs
->regs
[31] = (unsigned long) frame
->sf_code
;
301 regs
->cp0_epc
= regs
->regs
[25] = (unsigned long) ka
->sa
.sa_handler
;
304 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
305 current
->comm
, current
->pid
,
306 frame
, regs
->cp0_epc
, frame
->regs
[31]);
311 force_sigsegv(signr
, current
);
316 int setup_rt_frame(struct k_sigaction
* ka
, struct pt_regs
*regs
,
317 int signr
, sigset_t
*set
, siginfo_t
*info
)
319 struct rt_sigframe __user
*frame
;
322 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
323 if (!access_ok(VERIFY_WRITE
, frame
, sizeof (*frame
)))
326 install_sigtramp(frame
->rs_code
, __NR_rt_sigreturn
);
328 /* Create siginfo. */
329 err
|= copy_siginfo_to_user(&frame
->rs_info
, info
);
331 /* Create the ucontext. */
332 err
|= __put_user(0, &frame
->rs_uc
.uc_flags
);
333 err
|= __put_user(NULL
, &frame
->rs_uc
.uc_link
);
334 err
|= __put_user((void __user
*)current
->sas_ss_sp
,
335 &frame
->rs_uc
.uc_stack
.ss_sp
);
336 err
|= __put_user(sas_ss_flags(regs
->regs
[29]),
337 &frame
->rs_uc
.uc_stack
.ss_flags
);
338 err
|= __put_user(current
->sas_ss_size
,
339 &frame
->rs_uc
.uc_stack
.ss_size
);
340 err
|= setup_sigcontext(regs
, &frame
->rs_uc
.uc_mcontext
);
341 err
|= __copy_to_user(&frame
->rs_uc
.uc_sigmask
, set
, sizeof(*set
));
347 * Arguments to signal handler:
350 * a1 = 0 (should be cause)
351 * a2 = pointer to ucontext
353 * $25 and c0_epc point to the signal handler, $29 points to
354 * the struct rt_sigframe.
356 regs
->regs
[ 4] = signr
;
357 regs
->regs
[ 5] = (unsigned long) &frame
->rs_info
;
358 regs
->regs
[ 6] = (unsigned long) &frame
->rs_uc
;
359 regs
->regs
[29] = (unsigned long) frame
;
360 regs
->regs
[31] = (unsigned long) frame
->rs_code
;
361 regs
->cp0_epc
= regs
->regs
[25] = (unsigned long) ka
->sa
.sa_handler
;
364 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
365 current
->comm
, current
->pid
,
366 frame
, regs
->cp0_epc
, regs
->regs
[31]);
371 force_sigsegv(signr
, current
);
375 static inline int handle_signal(unsigned long sig
, siginfo_t
*info
,
376 struct k_sigaction
*ka
, sigset_t
*oldset
, struct pt_regs
*regs
)
380 switch(regs
->regs
[0]) {
381 case ERESTART_RESTARTBLOCK
:
383 regs
->regs
[2] = EINTR
;
386 if (!(ka
->sa
.sa_flags
& SA_RESTART
)) {
387 regs
->regs
[2] = EINTR
;
391 case ERESTARTNOINTR
: /* Userland will reload $v0. */
392 regs
->regs
[7] = regs
->regs
[26];
396 regs
->regs
[0] = 0; /* Don't deal with this again. */
398 if (sig_uses_siginfo(ka
))
399 ret
= current
->thread
.abi
->setup_rt_frame(ka
, regs
, sig
, oldset
, info
);
401 ret
= current
->thread
.abi
->setup_frame(ka
, regs
, sig
, oldset
);
403 spin_lock_irq(¤t
->sighand
->siglock
);
404 sigorsets(¤t
->blocked
,¤t
->blocked
,&ka
->sa
.sa_mask
);
405 if (!(ka
->sa
.sa_flags
& SA_NODEFER
))
406 sigaddset(¤t
->blocked
,sig
);
408 spin_unlock_irq(¤t
->sighand
->siglock
);
413 void do_signal(struct pt_regs
*regs
)
415 struct k_sigaction ka
;
421 * We want the common case to go fast, which is why we may in certain
422 * cases get here from kernel mode. Just return without doing anything
425 if (!user_mode(regs
))
431 if (test_thread_flag(TIF_RESTORE_SIGMASK
))
432 oldset
= ¤t
->saved_sigmask
;
434 oldset
= ¤t
->blocked
;
437 signr
= get_signal_to_deliver(&info
, &ka
, regs
, NULL
);
439 /* Whee! Actually deliver the signal. */
440 if (handle_signal(signr
, &info
, &ka
, oldset
, regs
) == 0) {
442 * A signal was successfully delivered; the saved
443 * sigmask will have been stored in the signal frame,
444 * and will be restored by sigreturn, so we can simply
445 * clear the TIF_RESTORE_SIGMASK flag.
447 if (test_thread_flag(TIF_RESTORE_SIGMASK
))
448 clear_thread_flag(TIF_RESTORE_SIGMASK
);
454 * Who's code doesn't conform to the restartable syscall convention
455 * dies here!!! The li instruction, a single machine instruction,
456 * must directly be followed by the syscall instruction.
459 if (regs
->regs
[2] == ERESTARTNOHAND
||
460 regs
->regs
[2] == ERESTARTSYS
||
461 regs
->regs
[2] == ERESTARTNOINTR
) {
462 regs
->regs
[7] = regs
->regs
[26];
465 if (regs
->regs
[2] == ERESTART_RESTARTBLOCK
) {
466 regs
->regs
[2] = __NR_restart_syscall
;
467 regs
->regs
[7] = regs
->regs
[26];
473 * If there's no signal to deliver, we just put the saved sigmask
476 if (test_thread_flag(TIF_RESTORE_SIGMASK
)) {
477 clear_thread_flag(TIF_RESTORE_SIGMASK
);
478 sigprocmask(SIG_SETMASK
, ¤t
->saved_sigmask
, NULL
);
483 * notification of userspace execution resumption
484 * - triggered by the TIF_WORK_MASK flags
486 asmlinkage
void do_notify_resume(struct pt_regs
*regs
, void *unused
,
487 __u32 thread_info_flags
)
489 /* deal with pending signal delivery */
490 if (thread_info_flags
& (_TIF_SIGPENDING
| _TIF_RESTORE_SIGMASK
))
491 current
->thread
.abi
->do_signal(regs
);