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 *uset, saveset, newset;
52 uset = (sigset_t *) regs.regs[4];
53 if (copy_from_user(&newset, uset, sizeof(sigset_t)))
55 sigdelsetmask(&newset, ~_BLOCKABLE);
57 spin_lock_irq(¤t->sighand->siglock);
58 saveset = current->blocked;
59 current->blocked = newset;
61 spin_unlock_irq(¤t->sighand->siglock);
66 current->state = TASK_INTERRUPTIBLE;
68 if (do_signal(&saveset, ®s))
74 save_static_function(sys_rt_sigsuspend);
75 __attribute_used__ noinline static int
76 _sys_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
78 sigset_t *unewset, saveset, newset;
81 /* XXX Don't preclude handling different sized sigset_t's. */
82 sigsetsize = regs.regs[5];
83 if (sigsetsize != sizeof(sigset_t))
86 unewset = (sigset_t *) regs.regs[4];
87 if (copy_from_user(&newset, unewset, sizeof(newset)))
89 sigdelsetmask(&newset, ~_BLOCKABLE);
91 spin_lock_irq(¤t->sighand->siglock);
92 saveset = current->blocked;
93 current->blocked = newset;
95 spin_unlock_irq(¤t->sighand->siglock);
100 current->state = TASK_INTERRUPTIBLE;
102 if (do_signal(&saveset, ®s))
107 #ifdef CONFIG_TRAD_SIGNALS
108 asmlinkage int sys_sigaction(int sig, const struct sigaction *act,
109 struct sigaction *oact)
111 struct k_sigaction new_ka, old_ka;
118 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
120 err |= __get_user(new_ka.sa.sa_handler, &act->sa_handler);
121 err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
122 err |= __get_user(mask, &act->sa_mask.sig[0]);
126 siginitset(&new_ka.sa.sa_mask, mask);
129 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
132 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
134 err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
135 err |= __put_user(old_ka.sa.sa_handler, &oact->sa_handler);
136 err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
137 err |= __put_user(0, &oact->sa_mask.sig[1]);
138 err |= __put_user(0, &oact->sa_mask.sig[2]);
139 err |= __put_user(0, &oact->sa_mask.sig[3]);
148 asmlinkage int sys_sigaltstack(nabi_no_regargs struct pt_regs regs)
150 const stack_t *uss = (const stack_t *) regs.regs[4];
151 stack_t *uoss = (stack_t *) regs.regs[5];
152 unsigned long usp = regs.regs[29];
154 return do_sigaltstack(uss, uoss, usp);
157 #if PLAT_TRAMPOLINE_STUFF_LINE
158 #define __tramp __attribute__((aligned(PLAT_TRAMPOLINE_STUFF_LINE)))
163 #ifdef CONFIG_TRAD_SIGNALS
165 u32 sf_ass[4]; /* argument save space for o32 */
166 u32 sf_code[2] __tramp; /* signal trampoline */
167 struct sigcontext sf_sc __tramp;
173 u32 rs_ass[4]; /* argument save space for o32 */
174 u32 rs_code[2] __tramp; /* signal trampoline */
175 struct siginfo rs_info __tramp;
176 struct ucontext rs_uc;
179 #ifdef CONFIG_TRAD_SIGNALS
180 save_static_function(sys_sigreturn);
181 __attribute_used__ noinline static void
182 _sys_sigreturn(nabi_no_regargs struct pt_regs regs)
184 struct sigframe *frame;
187 frame = (struct sigframe *) regs.regs[29];
188 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
190 if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked)))
193 sigdelsetmask(&blocked, ~_BLOCKABLE);
194 spin_lock_irq(¤t->sighand->siglock);
195 current->blocked = blocked;
197 spin_unlock_irq(¤t->sighand->siglock);
199 if (restore_sigcontext(®s, &frame->sf_sc))
203 * Don't let your children do this ...
205 if (current_thread_info()->flags & TIF_SYSCALL_TRACE)
206 do_syscall_trace(®s, 1);
207 __asm__ __volatile__(
215 force_sig(SIGSEGV, current);
219 save_static_function(sys_rt_sigreturn);
220 __attribute_used__ noinline static void
221 _sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
223 struct rt_sigframe *frame;
227 frame = (struct rt_sigframe *) regs.regs[29];
228 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
230 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
233 sigdelsetmask(&set, ~_BLOCKABLE);
234 spin_lock_irq(¤t->sighand->siglock);
235 current->blocked = set;
237 spin_unlock_irq(¤t->sighand->siglock);
239 if (restore_sigcontext(®s, &frame->rs_uc.uc_mcontext))
242 if (__copy_from_user(&st, &frame->rs_uc.uc_stack, sizeof(st)))
244 /* It is more difficult to avoid calling this function than to
245 call it and ignore errors. */
246 do_sigaltstack(&st, NULL, regs.regs[29]);
249 * Don't let your children do this ...
251 __asm__ __volatile__(
259 force_sig(SIGSEGV, current);
262 #ifdef CONFIG_TRAD_SIGNALS
263 static void inline setup_frame(struct k_sigaction * ka, struct pt_regs *regs,
264 int signr, sigset_t *set)
266 struct sigframe *frame;
269 frame = get_sigframe(ka, regs, sizeof(*frame));
270 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
274 * Set up the return code ...
276 * li v0, __NR_sigreturn
279 if (PLAT_TRAMPOLINE_STUFF_LINE)
280 __clear_user(frame->sf_code, PLAT_TRAMPOLINE_STUFF_LINE);
281 err |= __put_user(0x24020000 + __NR_sigreturn, frame->sf_code + 0);
282 err |= __put_user(0x0000000c , frame->sf_code + 1);
283 flush_cache_sigtramp((unsigned long) frame->sf_code);
285 err |= setup_sigcontext(regs, &frame->sf_sc);
286 err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));
291 * Arguments to signal handler:
294 * a1 = 0 (should be cause)
295 * a2 = pointer to struct sigcontext
297 * $25 and c0_epc point to the signal handler, $29 points to the
300 regs->regs[ 4] = signr;
302 regs->regs[ 6] = (unsigned long) &frame->sf_sc;
303 regs->regs[29] = (unsigned long) frame;
304 regs->regs[31] = (unsigned long) frame->sf_code;
305 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
308 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
309 current->comm, current->pid,
310 frame, regs->cp0_epc, frame->regs[31]);
315 force_sigsegv(signr, current);
319 static void inline setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
320 int signr, sigset_t *set, siginfo_t *info)
322 struct rt_sigframe *frame;
325 frame = get_sigframe(ka, regs, sizeof(*frame));
326 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
330 * Set up the return code ...
332 * li v0, __NR_rt_sigreturn
335 if (PLAT_TRAMPOLINE_STUFF_LINE)
336 __clear_user(frame->rs_code, PLAT_TRAMPOLINE_STUFF_LINE);
337 err |= __put_user(0x24020000 + __NR_rt_sigreturn, frame->rs_code + 0);
338 err |= __put_user(0x0000000c , frame->rs_code + 1);
339 flush_cache_sigtramp((unsigned long) frame->rs_code);
341 /* Create siginfo. */
342 err |= copy_siginfo_to_user(&frame->rs_info, info);
344 /* Create the ucontext. */
345 err |= __put_user(0, &frame->rs_uc.uc_flags);
346 err |= __put_user(0, &frame->rs_uc.uc_link);
347 err |= __put_user((void *)current->sas_ss_sp,
348 &frame->rs_uc.uc_stack.ss_sp);
349 err |= __put_user(sas_ss_flags(regs->regs[29]),
350 &frame->rs_uc.uc_stack.ss_flags);
351 err |= __put_user(current->sas_ss_size,
352 &frame->rs_uc.uc_stack.ss_size);
353 err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
354 err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));
360 * Arguments to signal handler:
363 * a1 = 0 (should be cause)
364 * a2 = pointer to ucontext
366 * $25 and c0_epc point to the signal handler, $29 points to
367 * the struct rt_sigframe.
369 regs->regs[ 4] = signr;
370 regs->regs[ 5] = (unsigned long) &frame->rs_info;
371 regs->regs[ 6] = (unsigned long) &frame->rs_uc;
372 regs->regs[29] = (unsigned long) frame;
373 regs->regs[31] = (unsigned long) frame->rs_code;
374 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
377 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
378 current->comm, current->pid,
379 frame, regs->cp0_epc, regs->regs[31]);
384 force_sigsegv(signr, current);
387 extern void setup_rt_frame_n32(struct k_sigaction * ka,
388 struct pt_regs *regs, int signr, sigset_t *set, siginfo_t *info);
390 static inline void handle_signal(unsigned long sig, siginfo_t *info,
391 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs)
393 switch(regs->regs[0]) {
394 case ERESTART_RESTARTBLOCK:
396 regs->regs[2] = EINTR;
399 if(!(ka->sa.sa_flags & SA_RESTART)) {
400 regs->regs[2] = EINTR;
404 case ERESTARTNOINTR: /* Userland will reload $v0. */
405 regs->regs[7] = regs->regs[26];
409 regs->regs[0] = 0; /* Don't deal with this again. */
411 #ifdef CONFIG_TRAD_SIGNALS
412 if (ka->sa.sa_flags & SA_SIGINFO) {
416 #ifdef CONFIG_MIPS32_N32
417 if ((current->thread.mflags & MF_ABI_MASK) == MF_N32)
418 setup_rt_frame_n32 (ka, regs, sig, oldset, info);
421 setup_rt_frame(ka, regs, sig, oldset, info);
423 #ifdef CONFIG_TRAD_SIGNALS
425 setup_frame(ka, regs, sig, oldset);
428 if (!(ka->sa.sa_flags & SA_NODEFER)) {
429 spin_lock_irq(¤t->sighand->siglock);
430 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
431 sigaddset(¤t->blocked,sig);
433 spin_unlock_irq(¤t->sighand->siglock);
437 extern int do_signal32(sigset_t *oldset, struct pt_regs *regs);
438 extern int do_irix_signal(sigset_t *oldset, struct pt_regs *regs);
440 static int do_signal(sigset_t *oldset, struct pt_regs *regs)
442 struct k_sigaction ka;
446 #ifdef CONFIG_BINFMT_ELF32
447 if ((current->thread.mflags & MF_ABI_MASK) == MF_O32) {
448 return do_signal32(oldset, regs);
453 * We want the common case to go fast, which is why we may in certain
454 * cases get here from kernel mode. Just return without doing anything
457 if (!user_mode(regs))
464 oldset = ¤t->blocked;
466 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
468 handle_signal(signr, &info, &ka, oldset, regs);
474 * Who's code doesn't conform to the restartable syscall convention
475 * dies here!!! The li instruction, a single machine instruction,
476 * must directly be followed by the syscall instruction.
479 if (regs->regs[2] == ERESTARTNOHAND ||
480 regs->regs[2] == ERESTARTSYS ||
481 regs->regs[2] == ERESTARTNOINTR) {
482 regs->regs[7] = regs->regs[26];
485 if (regs->regs[2] == ERESTART_RESTARTBLOCK) {
486 regs->regs[2] = __NR_restart_syscall;
487 regs->regs[7] = regs->regs[26];
495 * notification of userspace execution resumption
496 * - triggered by current->work.notify_resume
498 asmlinkage void do_notify_resume(struct pt_regs *regs, sigset_t *oldset,
499 __u32 thread_info_flags)
501 /* deal with pending signal delivery */
502 if (thread_info_flags & _TIF_SIGPENDING) {
503 #ifdef CONFIG_BINFMT_ELF32
504 if (likely((current->thread.mflags & MF_ABI_MASK) == MF_O32)) {
505 do_signal32(oldset, regs);
509 #ifdef CONFIG_BINFMT_IRIX
510 if (unlikely(current->personality != PER_LINUX)) {
511 do_irix_signal(oldset, regs);
515 do_signal(oldset, regs);