blob: 54398af2371f9b33d834cfc70b9916fc4337d0d6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
4 * for more details.
5 *
6 * Copyright (C) 1991, 1992 Linus Torvalds
7 * Copyright (C) 1994 - 2000 Ralf Baechle
8 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
9 */
Ralf Baechle02416dc2005-06-15 13:00:12 +000010#include <linux/cache.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/sched.h>
12#include <linux/mm.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>
23
Ralf Baechlee50c0a82005-05-31 11:49:19 +000024#include <asm/abi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/asm.h>
26#include <linux/bitops.h>
27#include <asm/cacheflush.h>
28#include <asm/fpu.h>
29#include <asm/sim.h>
30#include <asm/uaccess.h>
31#include <asm/ucontext.h>
32#include <asm/cpu-features.h>
Ralf Baechle02416dc2005-06-15 13:00:12 +000033#include <asm/war.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35#include "signal-common.h"
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
38
Franck Bui-Huuc0b9bae2007-02-05 15:24:21 +010039#if ICACHE_REFILLS_WORKAROUND_WAR == 0
40
41struct rt_sigframe {
42 u32 rs_ass[4]; /* argument save space for o32 */
43 u32 rs_code[2]; /* signal trampoline */
44 struct siginfo rs_info;
45 struct ucontext rs_uc;
46};
47
48#else
49
50struct rt_sigframe {
51 u32 rs_ass[4]; /* argument save space for o32 */
52 u32 rs_pad[2];
53 struct siginfo rs_info;
54 struct ucontext rs_uc;
55 u32 rs_code[8] ____cacheline_aligned; /* signal trampoline */
56};
57
58#endif
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060/*
Franck Bui-Huuc3fc4ab2007-02-05 15:24:20 +010061 * Helper routines
62 */
63int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
64{
65 int err = 0;
66 int i;
67
68 err |= __put_user(regs->cp0_epc, &sc->sc_pc);
69
70 err |= __put_user(0, &sc->sc_regs[0]);
71 for (i = 1; i < 32; i++)
72 err |= __put_user(regs->regs[i], &sc->sc_regs[i]);
73
74 err |= __put_user(regs->hi, &sc->sc_mdhi);
75 err |= __put_user(regs->lo, &sc->sc_mdlo);
76 if (cpu_has_dsp) {
77 err |= __put_user(mfhi1(), &sc->sc_hi1);
78 err |= __put_user(mflo1(), &sc->sc_lo1);
79 err |= __put_user(mfhi2(), &sc->sc_hi2);
80 err |= __put_user(mflo2(), &sc->sc_lo2);
81 err |= __put_user(mfhi3(), &sc->sc_hi3);
82 err |= __put_user(mflo3(), &sc->sc_lo3);
83 err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
84 }
85
86 err |= __put_user(!!used_math(), &sc->sc_used_math);
87
88 if (used_math()) {
89 /*
90 * Save FPU state to signal context. Signal handler
91 * will "inherit" current FPU state.
92 */
93 preempt_disable();
94
95 if (!is_fpu_owner()) {
96 own_fpu();
97 restore_fp(current);
98 }
99 err |= save_fp_context(sc);
100
101 preempt_enable();
102 }
103 return err;
104}
105
106int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
107{
108 unsigned int used_math;
109 unsigned long treg;
110 int err = 0;
111 int i;
112
113 /* Always make any pending restarted system calls return -EINTR */
114 current_thread_info()->restart_block.fn = do_no_restart_syscall;
115
116 err |= __get_user(regs->cp0_epc, &sc->sc_pc);
117 err |= __get_user(regs->hi, &sc->sc_mdhi);
118 err |= __get_user(regs->lo, &sc->sc_mdlo);
119 if (cpu_has_dsp) {
120 err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
121 err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
122 err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
123 err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
124 err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
125 err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
126 err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
127 }
128
129 for (i = 1; i < 32; i++)
130 err |= __get_user(regs->regs[i], &sc->sc_regs[i]);
131
132 err |= __get_user(used_math, &sc->sc_used_math);
133 conditional_used_math(used_math);
134
135 preempt_disable();
136
137 if (used_math()) {
138 /* restore fpu context if we have used it before */
139 own_fpu();
140 err |= restore_fp_context(sc);
141 } else {
142 /* signal handler may have used FPU. Give it up. */
143 lose_fpu();
144 }
145
146 preempt_enable();
147
148 return err;
149}
150
151void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
152 size_t frame_size)
153{
154 unsigned long sp;
155
156 /* Default to using normal stack */
157 sp = regs->regs[29];
158
159 /*
160 * FPU emulator may have it's own trampoline active just
161 * above the user stack, 16-bytes before the next lowest
162 * 16 byte boundary. Try to avoid trashing it.
163 */
164 sp -= 32;
165
166 /* This is the X/Open sanctioned signal stack switching. */
167 if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
168 sp = current->sas_ss_sp + current->sas_ss_size;
169
170 return (void __user *)((sp - frame_size) & (ICACHE_REFILLS_WORKAROUND_WAR ? ~(cpu_icache_line_size()-1) : ALMASK));
171}
172
173int install_sigtramp(unsigned int __user *tramp, unsigned int syscall)
174{
175 int err;
176
177 /*
178 * Set up the return code ...
179 *
180 * li v0, __NR__foo_sigreturn
181 * syscall
182 */
183
184 err = __put_user(0x24020000 + syscall, tramp + 0);
Franck Bui-Huu601dde42007-02-05 15:24:23 +0100185 err |= __put_user(0x0000000c , tramp + 1);
Franck Bui-Huuc3fc4ab2007-02-05 15:24:20 +0100186 if (ICACHE_REFILLS_WORKAROUND_WAR) {
187 err |= __put_user(0, tramp + 2);
188 err |= __put_user(0, tramp + 3);
189 err |= __put_user(0, tramp + 4);
190 err |= __put_user(0, tramp + 5);
191 err |= __put_user(0, tramp + 6);
192 err |= __put_user(0, tramp + 7);
193 }
194 flush_cache_sigtramp((unsigned long) tramp);
195
196 return err;
197}
198
199/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 * Atomically swap in the new signal mask, and wait for a signal.
201 */
202
203#ifdef CONFIG_TRAD_SIGNALS
Franck Bui-Huuf90080a2007-02-05 15:24:27 +0100204asmlinkage int sys_sigsuspend(nabi_no_regargs struct pt_regs regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000206 sigset_t newset;
Ralf Baechlefe00f942005-03-01 19:22:29 +0000207 sigset_t __user *uset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Ralf Baechlefe00f942005-03-01 19:22:29 +0000209 uset = (sigset_t __user *) regs.regs[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 if (copy_from_user(&newset, uset, sizeof(sigset_t)))
211 return -EFAULT;
212 sigdelsetmask(&newset, ~_BLOCKABLE);
213
214 spin_lock_irq(&current->sighand->siglock);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000215 current->saved_sigmask = current->blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 current->blocked = newset;
217 recalc_sigpending();
218 spin_unlock_irq(&current->sighand->siglock);
219
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000220 current->state = TASK_INTERRUPTIBLE;
221 schedule();
222 set_thread_flag(TIF_RESTORE_SIGMASK);
223 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224}
225#endif
226
Franck Bui-Huuf90080a2007-02-05 15:24:27 +0100227asmlinkage int sys_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000229 sigset_t newset;
Ralf Baechlefe00f942005-03-01 19:22:29 +0000230 sigset_t __user *unewset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 size_t sigsetsize;
232
233 /* XXX Don't preclude handling different sized sigset_t's. */
234 sigsetsize = regs.regs[5];
235 if (sigsetsize != sizeof(sigset_t))
236 return -EINVAL;
237
Ralf Baechlefe00f942005-03-01 19:22:29 +0000238 unewset = (sigset_t __user *) regs.regs[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 if (copy_from_user(&newset, unewset, sizeof(newset)))
240 return -EFAULT;
241 sigdelsetmask(&newset, ~_BLOCKABLE);
242
243 spin_lock_irq(&current->sighand->siglock);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000244 current->saved_sigmask = current->blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 current->blocked = newset;
Ralf Baechlee0daad42007-02-05 00:10:11 +0000246 recalc_sigpending();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 spin_unlock_irq(&current->sighand->siglock);
248
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000249 current->state = TASK_INTERRUPTIBLE;
250 schedule();
251 set_thread_flag(TIF_RESTORE_SIGMASK);
252 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}
254
255#ifdef CONFIG_TRAD_SIGNALS
Atsushi Nemoto9c6031c2006-02-19 23:46:44 +0900256asmlinkage int sys_sigaction(int sig, const struct sigaction __user *act,
257 struct sigaction __user *oact)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
259 struct k_sigaction new_ka, old_ka;
260 int ret;
261 int err = 0;
262
263 if (act) {
264 old_sigset_t mask;
265
266 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
267 return -EFAULT;
268 err |= __get_user(new_ka.sa.sa_handler, &act->sa_handler);
269 err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
270 err |= __get_user(mask, &act->sa_mask.sig[0]);
271 if (err)
272 return -EFAULT;
273
274 siginitset(&new_ka.sa.sa_mask, mask);
275 }
276
277 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
278
279 if (!ret && oact) {
280 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
Ralf Baechlee0daad42007-02-05 00:10:11 +0000281 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
283 err |= __put_user(old_ka.sa.sa_handler, &oact->sa_handler);
284 err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
285 err |= __put_user(0, &oact->sa_mask.sig[1]);
286 err |= __put_user(0, &oact->sa_mask.sig[2]);
287 err |= __put_user(0, &oact->sa_mask.sig[3]);
288 if (err)
289 return -EFAULT;
290 }
291
292 return ret;
293}
294#endif
295
296asmlinkage int sys_sigaltstack(nabi_no_regargs struct pt_regs regs)
297{
Ralf Baechlefe00f942005-03-01 19:22:29 +0000298 const stack_t __user *uss = (const stack_t __user *) regs.regs[4];
299 stack_t __user *uoss = (stack_t __user *) regs.regs[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 unsigned long usp = regs.regs[29];
301
302 return do_sigaltstack(uss, uoss, usp);
303}
304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305#ifdef CONFIG_TRAD_SIGNALS
Franck Bui-Huuf90080a2007-02-05 15:24:27 +0100306asmlinkage void sys_sigreturn(nabi_no_regargs struct pt_regs regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900308 struct sigframe __user *frame;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 sigset_t blocked;
310
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900311 frame = (struct sigframe __user *) regs.regs[29];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
313 goto badframe;
314 if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked)))
315 goto badframe;
316
317 sigdelsetmask(&blocked, ~_BLOCKABLE);
318 spin_lock_irq(&current->sighand->siglock);
319 current->blocked = blocked;
320 recalc_sigpending();
321 spin_unlock_irq(&current->sighand->siglock);
322
323 if (restore_sigcontext(&regs, &frame->sf_sc))
324 goto badframe;
325
326 /*
327 * Don't let your children do this ...
328 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 __asm__ __volatile__(
330 "move\t$29, %0\n\t"
331 "j\tsyscall_exit"
332 :/* no outputs */
333 :"r" (&regs));
334 /* Unreached */
335
336badframe:
337 force_sig(SIGSEGV, current);
338}
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000339#endif /* CONFIG_TRAD_SIGNALS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Franck Bui-Huuf90080a2007-02-05 15:24:27 +0100341asmlinkage void sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900343 struct rt_sigframe __user *frame;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 sigset_t set;
345 stack_t st;
346
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900347 frame = (struct rt_sigframe __user *) regs.regs[29];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
349 goto badframe;
350 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
351 goto badframe;
352
353 sigdelsetmask(&set, ~_BLOCKABLE);
354 spin_lock_irq(&current->sighand->siglock);
355 current->blocked = set;
356 recalc_sigpending();
357 spin_unlock_irq(&current->sighand->siglock);
358
359 if (restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext))
360 goto badframe;
361
362 if (__copy_from_user(&st, &frame->rs_uc.uc_stack, sizeof(st)))
363 goto badframe;
364 /* It is more difficult to avoid calling this function than to
365 call it and ignore errors. */
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900366 do_sigaltstack((stack_t __user *)&st, NULL, regs.regs[29]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 /*
369 * Don't let your children do this ...
370 */
371 __asm__ __volatile__(
372 "move\t$29, %0\n\t"
373 "j\tsyscall_exit"
374 :/* no outputs */
375 :"r" (&regs));
376 /* Unreached */
377
378badframe:
379 force_sig(SIGSEGV, current);
380}
381
382#ifdef CONFIG_TRAD_SIGNALS
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000383int setup_frame(struct k_sigaction * ka, struct pt_regs *regs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 int signr, sigset_t *set)
385{
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900386 struct sigframe __user *frame;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 int err = 0;
388
389 frame = get_sigframe(ka, regs, sizeof(*frame));
390 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
391 goto give_sigsegv;
392
Franck Bui-Huu601dde42007-02-05 15:24:23 +0100393 err |= install_sigtramp(frame->sf_code, __NR_sigreturn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395 err |= setup_sigcontext(regs, &frame->sf_sc);
396 err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));
397 if (err)
398 goto give_sigsegv;
399
400 /*
401 * Arguments to signal handler:
402 *
403 * a0 = signal number
404 * a1 = 0 (should be cause)
405 * a2 = pointer to struct sigcontext
406 *
407 * $25 and c0_epc point to the signal handler, $29 points to the
408 * struct sigframe.
409 */
410 regs->regs[ 4] = signr;
411 regs->regs[ 5] = 0;
412 regs->regs[ 6] = (unsigned long) &frame->sf_sc;
413 regs->regs[29] = (unsigned long) frame;
414 regs->regs[31] = (unsigned long) frame->sf_code;
415 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
416
Franck Bui-Huu722bb632007-02-05 15:24:24 +0100417 DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 current->comm, current->pid,
Franck Bui-Huu722bb632007-02-05 15:24:24 +0100419 frame, regs->cp0_epc, regs->regs[31]);
Ralf Baechlee0daad42007-02-05 00:10:11 +0000420 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422give_sigsegv:
423 force_sigsegv(signr, current);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000424 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
426#endif
427
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000428int setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 int signr, sigset_t *set, siginfo_t *info)
430{
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900431 struct rt_sigframe __user *frame;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 int err = 0;
433
434 frame = get_sigframe(ka, regs, sizeof(*frame));
435 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
436 goto give_sigsegv;
437
Franck Bui-Huu601dde42007-02-05 15:24:23 +0100438 err |= install_sigtramp(frame->rs_code, __NR_rt_sigreturn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 /* Create siginfo. */
441 err |= copy_siginfo_to_user(&frame->rs_info, info);
442
443 /* Create the ucontext. */
444 err |= __put_user(0, &frame->rs_uc.uc_flags);
Atsushi Nemoto5665a0a2006-02-02 01:26:34 +0900445 err |= __put_user(NULL, &frame->rs_uc.uc_link);
Atsushi Nemoto9c6031c2006-02-19 23:46:44 +0900446 err |= __put_user((void __user *)current->sas_ss_sp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 &frame->rs_uc.uc_stack.ss_sp);
448 err |= __put_user(sas_ss_flags(regs->regs[29]),
449 &frame->rs_uc.uc_stack.ss_flags);
450 err |= __put_user(current->sas_ss_size,
451 &frame->rs_uc.uc_stack.ss_size);
452 err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
453 err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));
454
455 if (err)
456 goto give_sigsegv;
457
458 /*
459 * Arguments to signal handler:
460 *
461 * a0 = signal number
462 * a1 = 0 (should be cause)
463 * a2 = pointer to ucontext
464 *
465 * $25 and c0_epc point to the signal handler, $29 points to
466 * the struct rt_sigframe.
467 */
468 regs->regs[ 4] = signr;
469 regs->regs[ 5] = (unsigned long) &frame->rs_info;
470 regs->regs[ 6] = (unsigned long) &frame->rs_uc;
471 regs->regs[29] = (unsigned long) frame;
472 regs->regs[31] = (unsigned long) frame->rs_code;
473 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
474
Franck Bui-Huu722bb632007-02-05 15:24:24 +0100475 DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 current->comm, current->pid,
477 frame, regs->cp0_epc, regs->regs[31]);
Franck Bui-Huu722bb632007-02-05 15:24:24 +0100478
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000479 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
481give_sigsegv:
482 force_sigsegv(signr, current);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000483 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484}
485
Franck Bui-Huue692eb32007-02-05 15:24:28 +0100486static int handle_signal(unsigned long sig, siginfo_t *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs)
488{
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000489 int ret;
490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 switch(regs->regs[0]) {
492 case ERESTART_RESTARTBLOCK:
493 case ERESTARTNOHAND:
494 regs->regs[2] = EINTR;
495 break;
496 case ERESTARTSYS:
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000497 if (!(ka->sa.sa_flags & SA_RESTART)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 regs->regs[2] = EINTR;
499 break;
500 }
501 /* fallthrough */
502 case ERESTARTNOINTR: /* Userland will reload $v0. */
503 regs->regs[7] = regs->regs[26];
504 regs->cp0_epc -= 8;
505 }
506
507 regs->regs[0] = 0; /* Don't deal with this again. */
508
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000509 if (sig_uses_siginfo(ka))
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000510 ret = current->thread.abi->setup_rt_frame(ka, regs, sig, oldset, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 else
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000512 ret = current->thread.abi->setup_frame(ka, regs, sig, oldset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Steven Rostedt69be8f12005-08-29 11:44:09 -0400514 spin_lock_irq(&current->sighand->siglock);
515 sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
516 if (!(ka->sa.sa_flags & SA_NODEFER))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 sigaddset(&current->blocked,sig);
Steven Rostedt69be8f12005-08-29 11:44:09 -0400518 recalc_sigpending();
519 spin_unlock_irq(&current->sighand->siglock);
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000520
521 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522}
523
Ralf Baechle40ac5d42006-02-08 13:38:18 +0000524void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
526 struct k_sigaction ka;
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000527 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 siginfo_t info;
529 int signr;
530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 /*
532 * We want the common case to go fast, which is why we may in certain
533 * cases get here from kernel mode. Just return without doing anything
534 * if so.
535 */
536 if (!user_mode(regs))
Ralf Baechle40ac5d42006-02-08 13:38:18 +0000537 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000539 if (test_thread_flag(TIF_RESTORE_SIGMASK))
540 oldset = &current->saved_sigmask;
541 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 oldset = &current->blocked;
543
544 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000545 if (signr > 0) {
546 /* Whee! Actually deliver the signal. */
547 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
548 /*
549 * A signal was successfully delivered; the saved
550 * sigmask will have been stored in the signal frame,
551 * and will be restored by sigreturn, so we can simply
552 * clear the TIF_RESTORE_SIGMASK flag.
553 */
554 if (test_thread_flag(TIF_RESTORE_SIGMASK))
555 clear_thread_flag(TIF_RESTORE_SIGMASK);
556 }
Ralf Baechle45887e12006-08-03 21:54:13 +0100557
558 return;
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 /*
562 * Who's code doesn't conform to the restartable syscall convention
563 * dies here!!! The li instruction, a single machine instruction,
564 * must directly be followed by the syscall instruction.
565 */
566 if (regs->regs[0]) {
567 if (regs->regs[2] == ERESTARTNOHAND ||
568 regs->regs[2] == ERESTARTSYS ||
569 regs->regs[2] == ERESTARTNOINTR) {
570 regs->regs[7] = regs->regs[26];
571 regs->cp0_epc -= 8;
572 }
573 if (regs->regs[2] == ERESTART_RESTARTBLOCK) {
574 regs->regs[2] = __NR_restart_syscall;
575 regs->regs[7] = regs->regs[26];
576 regs->cp0_epc -= 4;
577 }
Ralf Baechle13fdd312006-08-08 03:47:01 +0100578 regs->regs[0] = 0; /* Don't deal with this again. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000580
581 /*
582 * If there's no signal to deliver, we just put the saved sigmask
583 * back
584 */
585 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
586 clear_thread_flag(TIF_RESTORE_SIGMASK);
587 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
588 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589}
590
591/*
592 * notification of userspace execution resumption
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000593 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 */
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000595asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 __u32 thread_info_flags)
597{
598 /* deal with pending signal delivery */
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000599 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
600 current->thread.abi->do_signal(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601}