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/cache.h>
11 #include <linux/sched.h>
13 #include <linux/personality.h>
14 #include <linux/smp.h>
15 #include <linux/smp_lock.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/compiler.h>
26 #include <linux/bitops.h>
27 #include <asm/cacheflush.h>
30 #include <asm/uaccess.h>
31 #include <asm/ucontext.h>
32 #include <asm/cpu-features.h>
35 #include "signal-common.h"
39 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
42 * Atomically swap in the new signal mask, and wait for a signal.
45 #ifdef CONFIG_TRAD_SIGNALS
46 save_static_function(sys_sigsuspend);
47 __attribute_used__ noinline static int
48 _sys_sigsuspend(nabi_no_regargs struct pt_regs regs)
51 sigset_t __user *uset;
53 uset = (sigset_t __user *) regs.regs[4];
54 if (copy_from_user(&newset, uset, sizeof(sigset_t)))
56 sigdelsetmask(&newset, ~_BLOCKABLE);
58 spin_lock_irq(¤t->sighand->siglock);
59 current->saved_sigmask = current->blocked;
60 current->blocked = newset;
62 spin_unlock_irq(¤t->sighand->siglock);
64 current->state = TASK_INTERRUPTIBLE;
66 set_thread_flag(TIF_RESTORE_SIGMASK);
67 return -ERESTARTNOHAND;
71 save_static_function(sys_rt_sigsuspend);
72 __attribute_used__ noinline static int
73 _sys_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
76 sigset_t __user *unewset;
79 /* XXX Don't preclude handling different sized sigset_t's. */
80 sigsetsize = regs.regs[5];
81 if (sigsetsize != sizeof(sigset_t))
84 unewset = (sigset_t __user *) regs.regs[4];
85 if (copy_from_user(&newset, unewset, sizeof(newset)))
87 sigdelsetmask(&newset, ~_BLOCKABLE);
89 spin_lock_irq(¤t->sighand->siglock);
90 current->saved_sigmask = current->blocked;
91 current->blocked = newset;
93 spin_unlock_irq(¤t->sighand->siglock);
95 current->state = TASK_INTERRUPTIBLE;
97 set_thread_flag(TIF_RESTORE_SIGMASK);
98 return -ERESTARTNOHAND;
101 #ifdef CONFIG_TRAD_SIGNALS
102 asmlinkage int sys_sigaction(int sig, const struct sigaction __user *act,
103 struct sigaction __user *oact)
105 struct k_sigaction new_ka, old_ka;
112 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
114 err |= __get_user(new_ka.sa.sa_handler, &act->sa_handler);
115 err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
116 err |= __get_user(mask, &act->sa_mask.sig[0]);
120 siginitset(&new_ka.sa.sa_mask, mask);
123 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
126 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
128 err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
129 err |= __put_user(old_ka.sa.sa_handler, &oact->sa_handler);
130 err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
131 err |= __put_user(0, &oact->sa_mask.sig[1]);
132 err |= __put_user(0, &oact->sa_mask.sig[2]);
133 err |= __put_user(0, &oact->sa_mask.sig[3]);
142 asmlinkage int sys_sigaltstack(nabi_no_regargs struct pt_regs regs)
144 const stack_t __user *uss = (const stack_t __user *) regs.regs[4];
145 stack_t __user *uoss = (stack_t __user *) regs.regs[5];
146 unsigned long usp = regs.regs[29];
148 return do_sigaltstack(uss, uoss, usp);
152 * Horribly complicated - with the bloody RM9000 workarounds enabled
153 * the signal trampolines is moving to the end of the structure so we can
154 * increase the alignment without breaking software compatibility.
156 #ifdef CONFIG_TRAD_SIGNALS
158 u32 sf_ass[4]; /* argument save space for o32 */
159 #if ICACHE_REFILLS_WORKAROUND_WAR
162 u32 sf_code[2]; /* signal trampoline */
164 struct sigcontext sf_sc;
166 #if ICACHE_REFILLS_WORKAROUND_WAR
167 u32 sf_code[8] ____cacheline_aligned; /* signal trampoline */
173 u32 rs_ass[4]; /* argument save space for o32 */
174 #if ICACHE_REFILLS_WORKAROUND_WAR
177 u32 rs_code[2]; /* signal trampoline */
179 struct siginfo rs_info;
180 struct ucontext rs_uc;
181 #if ICACHE_REFILLS_WORKAROUND_WAR
182 u32 rs_code[8] ____cacheline_aligned; /* signal trampoline */
186 #ifdef CONFIG_TRAD_SIGNALS
187 save_static_function(sys_sigreturn);
188 __attribute_used__ noinline static void
189 _sys_sigreturn(nabi_no_regargs struct pt_regs regs)
191 struct sigframe __user *frame;
194 frame = (struct sigframe __user *) regs.regs[29];
195 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
197 if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked)))
200 sigdelsetmask(&blocked, ~_BLOCKABLE);
201 spin_lock_irq(¤t->sighand->siglock);
202 current->blocked = blocked;
204 spin_unlock_irq(¤t->sighand->siglock);
206 if (restore_sigcontext(®s, &frame->sf_sc))
210 * Don't let your children do this ...
212 __asm__ __volatile__(
220 force_sig(SIGSEGV, current);
222 #endif /* CONFIG_TRAD_SIGNALS */
224 save_static_function(sys_rt_sigreturn);
225 __attribute_used__ noinline static void
226 _sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
228 struct rt_sigframe __user *frame;
232 frame = (struct rt_sigframe __user *) regs.regs[29];
233 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
235 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
238 sigdelsetmask(&set, ~_BLOCKABLE);
239 spin_lock_irq(¤t->sighand->siglock);
240 current->blocked = set;
242 spin_unlock_irq(¤t->sighand->siglock);
244 if (restore_sigcontext(®s, &frame->rs_uc.uc_mcontext))
247 if (__copy_from_user(&st, &frame->rs_uc.uc_stack, sizeof(st)))
249 /* It is more difficult to avoid calling this function than to
250 call it and ignore errors. */
251 do_sigaltstack((stack_t __user *)&st, NULL, regs.regs[29]);
254 * Don't let your children do this ...
256 __asm__ __volatile__(
264 force_sig(SIGSEGV, current);
267 #ifdef CONFIG_TRAD_SIGNALS
268 int setup_frame(struct k_sigaction * ka, struct pt_regs *regs,
269 int signr, sigset_t *set)
271 struct sigframe __user *frame;
274 frame = get_sigframe(ka, regs, sizeof(*frame));
275 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
278 install_sigtramp(frame->sf_code, __NR_sigreturn);
280 err |= setup_sigcontext(regs, &frame->sf_sc);
281 err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));
286 * Arguments to signal handler:
289 * a1 = 0 (should be cause)
290 * a2 = pointer to struct sigcontext
292 * $25 and c0_epc point to the signal handler, $29 points to the
295 regs->regs[ 4] = signr;
297 regs->regs[ 6] = (unsigned long) &frame->sf_sc;
298 regs->regs[29] = (unsigned long) frame;
299 regs->regs[31] = (unsigned long) frame->sf_code;
300 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
303 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
304 current->comm, current->pid,
305 frame, regs->cp0_epc, frame->regs[31]);
310 force_sigsegv(signr, current);
315 int setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
316 int signr, sigset_t *set, siginfo_t *info)
318 struct rt_sigframe __user *frame;
321 frame = get_sigframe(ka, regs, sizeof(*frame));
322 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
325 install_sigtramp(frame->rs_code, __NR_rt_sigreturn);
327 /* Create siginfo. */
328 err |= copy_siginfo_to_user(&frame->rs_info, info);
330 /* Create the ucontext. */
331 err |= __put_user(0, &frame->rs_uc.uc_flags);
332 err |= __put_user(NULL, &frame->rs_uc.uc_link);
333 err |= __put_user((void __user *)current->sas_ss_sp,
334 &frame->rs_uc.uc_stack.ss_sp);
335 err |= __put_user(sas_ss_flags(regs->regs[29]),
336 &frame->rs_uc.uc_stack.ss_flags);
337 err |= __put_user(current->sas_ss_size,
338 &frame->rs_uc.uc_stack.ss_size);
339 err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
340 err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));
346 * Arguments to signal handler:
349 * a1 = 0 (should be cause)
350 * a2 = pointer to ucontext
352 * $25 and c0_epc point to the signal handler, $29 points to
353 * the struct rt_sigframe.
355 regs->regs[ 4] = signr;
356 regs->regs[ 5] = (unsigned long) &frame->rs_info;
357 regs->regs[ 6] = (unsigned long) &frame->rs_uc;
358 regs->regs[29] = (unsigned long) frame;
359 regs->regs[31] = (unsigned long) frame->rs_code;
360 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
363 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
364 current->comm, current->pid,
365 frame, regs->cp0_epc, regs->regs[31]);
370 force_sigsegv(signr, current);
374 static inline int handle_signal(unsigned long sig, siginfo_t *info,
375 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs)
379 switch(regs->regs[0]) {
380 case ERESTART_RESTARTBLOCK:
382 regs->regs[2] = EINTR;
385 if (!(ka->sa.sa_flags & SA_RESTART)) {
386 regs->regs[2] = EINTR;
390 case ERESTARTNOINTR: /* Userland will reload $v0. */
391 regs->regs[7] = regs->regs[26];
395 regs->regs[0] = 0; /* Don't deal with this again. */
397 if (sig_uses_siginfo(ka))
398 ret = current->thread.abi->setup_rt_frame(ka, regs, sig, oldset, info);
400 ret = current->thread.abi->setup_frame(ka, regs, sig, oldset);
402 spin_lock_irq(¤t->sighand->siglock);
403 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
404 if (!(ka->sa.sa_flags & SA_NODEFER))
405 sigaddset(¤t->blocked,sig);
407 spin_unlock_irq(¤t->sighand->siglock);
412 void do_signal(struct pt_regs *regs)
414 struct k_sigaction ka;
420 * We want the common case to go fast, which is why we may in certain
421 * cases get here from kernel mode. Just return without doing anything
424 if (!user_mode(regs))
430 if (test_thread_flag(TIF_RESTORE_SIGMASK))
431 oldset = ¤t->saved_sigmask;
433 oldset = ¤t->blocked;
436 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
438 /* Whee! Actually deliver the signal. */
439 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
441 * A signal was successfully delivered; the saved
442 * sigmask will have been stored in the signal frame,
443 * and will be restored by sigreturn, so we can simply
444 * clear the TIF_RESTORE_SIGMASK flag.
446 if (test_thread_flag(TIF_RESTORE_SIGMASK))
447 clear_thread_flag(TIF_RESTORE_SIGMASK);
453 * Who's code doesn't conform to the restartable syscall convention
454 * dies here!!! The li instruction, a single machine instruction,
455 * must directly be followed by the syscall instruction.
458 if (regs->regs[2] == ERESTARTNOHAND ||
459 regs->regs[2] == ERESTARTSYS ||
460 regs->regs[2] == ERESTARTNOINTR) {
461 regs->regs[7] = regs->regs[26];
464 if (regs->regs[2] == ERESTART_RESTARTBLOCK) {
465 regs->regs[2] = __NR_restart_syscall;
466 regs->regs[7] = regs->regs[26];
472 * If there's no signal to deliver, we just put the saved sigmask
475 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
476 clear_thread_flag(TIF_RESTORE_SIGMASK);
477 sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL);
482 * notification of userspace execution resumption
483 * - triggered by the TIF_WORK_MASK flags
485 asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
486 __u32 thread_info_flags)
488 /* deal with pending signal delivery */
489 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
490 current->thread.abi->do_signal(regs);