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/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>
25 #include <linux/bitops.h>
26 #include <asm/cacheflush.h>
29 #include <asm/uaccess.h>
30 #include <asm/ucontext.h>
31 #include <asm/cpu-features.h>
33 #include "signal-common.h"
37 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
39 static int do_signal(sigset_t *oldset, struct pt_regs *regs);
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)
50 sigset_t saveset, newset;
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 saveset = current->blocked;
60 current->blocked = newset;
62 spin_unlock_irq(¤t->sighand->siglock);
67 current->state = TASK_INTERRUPTIBLE;
69 if (do_signal(&saveset, ®s))
75 save_static_function(sys_rt_sigsuspend);
76 __attribute_used__ noinline static int
77 _sys_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
79 sigset_t saveset, newset;
80 sigset_t __user *unewset;
83 /* XXX Don't preclude handling different sized sigset_t's. */
84 sigsetsize = regs.regs[5];
85 if (sigsetsize != sizeof(sigset_t))
88 unewset = (sigset_t __user *) regs.regs[4];
89 if (copy_from_user(&newset, unewset, sizeof(newset)))
91 sigdelsetmask(&newset, ~_BLOCKABLE);
93 spin_lock_irq(¤t->sighand->siglock);
94 saveset = current->blocked;
95 current->blocked = newset;
97 spin_unlock_irq(¤t->sighand->siglock);
102 current->state = TASK_INTERRUPTIBLE;
104 if (do_signal(&saveset, ®s))
109 #ifdef CONFIG_TRAD_SIGNALS
110 asmlinkage int sys_sigaction(int sig, const struct sigaction *act,
111 struct sigaction *oact)
113 struct k_sigaction new_ka, old_ka;
120 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
122 err |= __get_user(new_ka.sa.sa_handler, &act->sa_handler);
123 err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
124 err |= __get_user(mask, &act->sa_mask.sig[0]);
128 siginitset(&new_ka.sa.sa_mask, mask);
131 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
134 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
136 err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
137 err |= __put_user(old_ka.sa.sa_handler, &oact->sa_handler);
138 err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
139 err |= __put_user(0, &oact->sa_mask.sig[1]);
140 err |= __put_user(0, &oact->sa_mask.sig[2]);
141 err |= __put_user(0, &oact->sa_mask.sig[3]);
150 asmlinkage int sys_sigaltstack(nabi_no_regargs struct pt_regs regs)
152 const stack_t __user *uss = (const stack_t __user *) regs.regs[4];
153 stack_t __user *uoss = (stack_t __user *) regs.regs[5];
154 unsigned long usp = regs.regs[29];
156 return do_sigaltstack(uss, uoss, usp);
159 #if PLAT_TRAMPOLINE_STUFF_LINE
160 #define __tramp __attribute__((aligned(PLAT_TRAMPOLINE_STUFF_LINE)))
165 #ifdef CONFIG_TRAD_SIGNALS
167 u32 sf_ass[4]; /* argument save space for o32 */
168 u32 sf_code[2] __tramp; /* signal trampoline */
169 struct sigcontext sf_sc __tramp;
175 u32 rs_ass[4]; /* argument save space for o32 */
176 u32 rs_code[2] __tramp; /* signal trampoline */
177 struct siginfo rs_info __tramp;
178 struct ucontext rs_uc;
181 #ifdef CONFIG_TRAD_SIGNALS
182 save_static_function(sys_sigreturn);
183 __attribute_used__ noinline static void
184 _sys_sigreturn(nabi_no_regargs struct pt_regs regs)
186 struct sigframe *frame;
189 frame = (struct sigframe *) regs.regs[29];
190 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
192 if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked)))
195 sigdelsetmask(&blocked, ~_BLOCKABLE);
196 spin_lock_irq(¤t->sighand->siglock);
197 current->blocked = blocked;
199 spin_unlock_irq(¤t->sighand->siglock);
201 if (restore_sigcontext(®s, &frame->sf_sc))
205 * Don't let your children do this ...
207 if (current_thread_info()->flags & TIF_SYSCALL_TRACE)
208 do_syscall_trace(®s, 1);
209 __asm__ __volatile__(
217 force_sig(SIGSEGV, current);
221 save_static_function(sys_rt_sigreturn);
222 __attribute_used__ noinline static void
223 _sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
225 struct rt_sigframe *frame;
229 frame = (struct rt_sigframe *) regs.regs[29];
230 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
232 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
235 sigdelsetmask(&set, ~_BLOCKABLE);
236 spin_lock_irq(¤t->sighand->siglock);
237 current->blocked = set;
239 spin_unlock_irq(¤t->sighand->siglock);
241 if (restore_sigcontext(®s, &frame->rs_uc.uc_mcontext))
244 if (__copy_from_user(&st, &frame->rs_uc.uc_stack, sizeof(st)))
246 /* It is more difficult to avoid calling this function than to
247 call it and ignore errors. */
248 do_sigaltstack(&st, NULL, regs.regs[29]);
251 * Don't let your children do this ...
253 __asm__ __volatile__(
261 force_sig(SIGSEGV, current);
264 #ifdef CONFIG_TRAD_SIGNALS
265 static void inline setup_frame(struct k_sigaction * ka, struct pt_regs *regs,
266 int signr, sigset_t *set)
268 struct sigframe *frame;
271 frame = get_sigframe(ka, regs, sizeof(*frame));
272 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
276 * Set up the return code ...
278 * li v0, __NR_sigreturn
281 if (PLAT_TRAMPOLINE_STUFF_LINE)
282 __clear_user(frame->sf_code, PLAT_TRAMPOLINE_STUFF_LINE);
283 err |= __put_user(0x24020000 + __NR_sigreturn, frame->sf_code + 0);
284 err |= __put_user(0x0000000c , frame->sf_code + 1);
285 flush_cache_sigtramp((unsigned long) frame->sf_code);
287 err |= setup_sigcontext(regs, &frame->sf_sc);
288 err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));
293 * Arguments to signal handler:
296 * a1 = 0 (should be cause)
297 * a2 = pointer to struct sigcontext
299 * $25 and c0_epc point to the signal handler, $29 points to the
302 regs->regs[ 4] = signr;
304 regs->regs[ 6] = (unsigned long) &frame->sf_sc;
305 regs->regs[29] = (unsigned long) frame;
306 regs->regs[31] = (unsigned long) frame->sf_code;
307 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
310 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
311 current->comm, current->pid,
312 frame, regs->cp0_epc, frame->regs[31]);
317 force_sigsegv(signr, current);
321 static void inline setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
322 int signr, sigset_t *set, siginfo_t *info)
324 struct rt_sigframe *frame;
327 frame = get_sigframe(ka, regs, sizeof(*frame));
328 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
332 * Set up the return code ...
334 * li v0, __NR_rt_sigreturn
337 if (PLAT_TRAMPOLINE_STUFF_LINE)
338 __clear_user(frame->rs_code, PLAT_TRAMPOLINE_STUFF_LINE);
339 err |= __put_user(0x24020000 + __NR_rt_sigreturn, frame->rs_code + 0);
340 err |= __put_user(0x0000000c , frame->rs_code + 1);
341 flush_cache_sigtramp((unsigned long) frame->rs_code);
343 /* Create siginfo. */
344 err |= copy_siginfo_to_user(&frame->rs_info, info);
346 /* Create the ucontext. */
347 err |= __put_user(0, &frame->rs_uc.uc_flags);
348 err |= __put_user(0, &frame->rs_uc.uc_link);
349 err |= __put_user((void *)current->sas_ss_sp,
350 &frame->rs_uc.uc_stack.ss_sp);
351 err |= __put_user(sas_ss_flags(regs->regs[29]),
352 &frame->rs_uc.uc_stack.ss_flags);
353 err |= __put_user(current->sas_ss_size,
354 &frame->rs_uc.uc_stack.ss_size);
355 err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
356 err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));
362 * Arguments to signal handler:
365 * a1 = 0 (should be cause)
366 * a2 = pointer to ucontext
368 * $25 and c0_epc point to the signal handler, $29 points to
369 * the struct rt_sigframe.
371 regs->regs[ 4] = signr;
372 regs->regs[ 5] = (unsigned long) &frame->rs_info;
373 regs->regs[ 6] = (unsigned long) &frame->rs_uc;
374 regs->regs[29] = (unsigned long) frame;
375 regs->regs[31] = (unsigned long) frame->rs_code;
376 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
379 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
380 current->comm, current->pid,
381 frame, regs->cp0_epc, regs->regs[31]);
386 force_sigsegv(signr, current);
389 extern void setup_rt_frame_n32(struct k_sigaction * ka,
390 struct pt_regs *regs, int signr, sigset_t *set, siginfo_t *info);
392 static inline void handle_signal(unsigned long sig, siginfo_t *info,
393 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs)
395 switch(regs->regs[0]) {
396 case ERESTART_RESTARTBLOCK:
398 regs->regs[2] = EINTR;
401 if(!(ka->sa.sa_flags & SA_RESTART)) {
402 regs->regs[2] = EINTR;
406 case ERESTARTNOINTR: /* Userland will reload $v0. */
407 regs->regs[7] = regs->regs[26];
411 regs->regs[0] = 0; /* Don't deal with this again. */
413 #ifdef CONFIG_TRAD_SIGNALS
414 if (ka->sa.sa_flags & SA_SIGINFO) {
418 #ifdef CONFIG_MIPS32_N32
419 if ((current->thread.mflags & MF_ABI_MASK) == MF_N32)
420 setup_rt_frame_n32 (ka, regs, sig, oldset, info);
423 setup_rt_frame(ka, regs, sig, oldset, info);
425 #ifdef CONFIG_TRAD_SIGNALS
427 setup_frame(ka, regs, sig, oldset);
430 spin_lock_irq(¤t->sighand->siglock);
431 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
432 if (!(ka->sa.sa_flags & SA_NODEFER))
433 sigaddset(¤t->blocked,sig);
435 spin_unlock_irq(¤t->sighand->siglock);
438 extern int do_signal32(sigset_t *oldset, struct pt_regs *regs);
439 extern int do_irix_signal(sigset_t *oldset, struct pt_regs *regs);
441 static int do_signal(sigset_t *oldset, struct pt_regs *regs)
443 struct k_sigaction ka;
447 #ifdef CONFIG_BINFMT_ELF32
448 if ((current->thread.mflags & MF_ABI_MASK) == MF_O32) {
449 return do_signal32(oldset, regs);
454 * We want the common case to go fast, which is why we may in certain
455 * cases get here from kernel mode. Just return without doing anything
458 if (!user_mode(regs))
465 oldset = ¤t->blocked;
467 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
469 handle_signal(signr, &info, &ka, oldset, regs);
475 * Who's code doesn't conform to the restartable syscall convention
476 * dies here!!! The li instruction, a single machine instruction,
477 * must directly be followed by the syscall instruction.
480 if (regs->regs[2] == ERESTARTNOHAND ||
481 regs->regs[2] == ERESTARTSYS ||
482 regs->regs[2] == ERESTARTNOINTR) {
483 regs->regs[7] = regs->regs[26];
486 if (regs->regs[2] == ERESTART_RESTARTBLOCK) {
487 regs->regs[2] = __NR_restart_syscall;
488 regs->regs[7] = regs->regs[26];
496 * notification of userspace execution resumption
497 * - triggered by current->work.notify_resume
499 asmlinkage void do_notify_resume(struct pt_regs *regs, sigset_t *oldset,
500 __u32 thread_info_flags)
502 /* deal with pending signal delivery */
503 if (thread_info_flags & _TIF_SIGPENDING) {
504 #ifdef CONFIG_BINFMT_ELF32
505 if (likely((current->thread.mflags & MF_ABI_MASK) == MF_O32)) {
506 do_signal32(oldset, regs);
510 #ifdef CONFIG_BINFMT_IRIX
511 if (unlikely(current->personality != PER_LINUX)) {
512 do_irix_signal(oldset, regs);
516 do_signal(oldset, regs);