blob: d676805a34ba053ef7b88fe6eb5fdd977ec2219c [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
37#define DEBUG_SIG 0
38
39#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
40
Franck Bui-Huuc0b9bae2007-02-05 15:24:21 +010041#if ICACHE_REFILLS_WORKAROUND_WAR == 0
42
43struct rt_sigframe {
44 u32 rs_ass[4]; /* argument save space for o32 */
45 u32 rs_code[2]; /* signal trampoline */
46 struct siginfo rs_info;
47 struct ucontext rs_uc;
48};
49
50#else
51
52struct rt_sigframe {
53 u32 rs_ass[4]; /* argument save space for o32 */
54 u32 rs_pad[2];
55 struct siginfo rs_info;
56 struct ucontext rs_uc;
57 u32 rs_code[8] ____cacheline_aligned; /* signal trampoline */
58};
59
60#endif
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/*
Franck Bui-Huuc3fc4ab2007-02-05 15:24:20 +010063 * Helper routines
64 */
65int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
66{
67 int err = 0;
68 int i;
69
70 err |= __put_user(regs->cp0_epc, &sc->sc_pc);
71
72 err |= __put_user(0, &sc->sc_regs[0]);
73 for (i = 1; i < 32; i++)
74 err |= __put_user(regs->regs[i], &sc->sc_regs[i]);
75
76 err |= __put_user(regs->hi, &sc->sc_mdhi);
77 err |= __put_user(regs->lo, &sc->sc_mdlo);
78 if (cpu_has_dsp) {
79 err |= __put_user(mfhi1(), &sc->sc_hi1);
80 err |= __put_user(mflo1(), &sc->sc_lo1);
81 err |= __put_user(mfhi2(), &sc->sc_hi2);
82 err |= __put_user(mflo2(), &sc->sc_lo2);
83 err |= __put_user(mfhi3(), &sc->sc_hi3);
84 err |= __put_user(mflo3(), &sc->sc_lo3);
85 err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
86 }
87
88 err |= __put_user(!!used_math(), &sc->sc_used_math);
89
90 if (used_math()) {
91 /*
92 * Save FPU state to signal context. Signal handler
93 * will "inherit" current FPU state.
94 */
95 preempt_disable();
96
97 if (!is_fpu_owner()) {
98 own_fpu();
99 restore_fp(current);
100 }
101 err |= save_fp_context(sc);
102
103 preempt_enable();
104 }
105 return err;
106}
107
108int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
109{
110 unsigned int used_math;
111 unsigned long treg;
112 int err = 0;
113 int i;
114
115 /* Always make any pending restarted system calls return -EINTR */
116 current_thread_info()->restart_block.fn = do_no_restart_syscall;
117
118 err |= __get_user(regs->cp0_epc, &sc->sc_pc);
119 err |= __get_user(regs->hi, &sc->sc_mdhi);
120 err |= __get_user(regs->lo, &sc->sc_mdlo);
121 if (cpu_has_dsp) {
122 err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
123 err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
124 err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
125 err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
126 err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
127 err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
128 err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
129 }
130
131 for (i = 1; i < 32; i++)
132 err |= __get_user(regs->regs[i], &sc->sc_regs[i]);
133
134 err |= __get_user(used_math, &sc->sc_used_math);
135 conditional_used_math(used_math);
136
137 preempt_disable();
138
139 if (used_math()) {
140 /* restore fpu context if we have used it before */
141 own_fpu();
142 err |= restore_fp_context(sc);
143 } else {
144 /* signal handler may have used FPU. Give it up. */
145 lose_fpu();
146 }
147
148 preempt_enable();
149
150 return err;
151}
152
153void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
154 size_t frame_size)
155{
156 unsigned long sp;
157
158 /* Default to using normal stack */
159 sp = regs->regs[29];
160
161 /*
162 * FPU emulator may have it's own trampoline active just
163 * above the user stack, 16-bytes before the next lowest
164 * 16 byte boundary. Try to avoid trashing it.
165 */
166 sp -= 32;
167
168 /* This is the X/Open sanctioned signal stack switching. */
169 if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
170 sp = current->sas_ss_sp + current->sas_ss_size;
171
172 return (void __user *)((sp - frame_size) & (ICACHE_REFILLS_WORKAROUND_WAR ? ~(cpu_icache_line_size()-1) : ALMASK));
173}
174
175int install_sigtramp(unsigned int __user *tramp, unsigned int syscall)
176{
177 int err;
178
179 /*
180 * Set up the return code ...
181 *
182 * li v0, __NR__foo_sigreturn
183 * syscall
184 */
185
186 err = __put_user(0x24020000 + syscall, tramp + 0);
Franck Bui-Huu601dde42007-02-05 15:24:23 +0100187 err |= __put_user(0x0000000c , tramp + 1);
Franck Bui-Huuc3fc4ab2007-02-05 15:24:20 +0100188 if (ICACHE_REFILLS_WORKAROUND_WAR) {
189 err |= __put_user(0, tramp + 2);
190 err |= __put_user(0, tramp + 3);
191 err |= __put_user(0, tramp + 4);
192 err |= __put_user(0, tramp + 5);
193 err |= __put_user(0, tramp + 6);
194 err |= __put_user(0, tramp + 7);
195 }
196 flush_cache_sigtramp((unsigned long) tramp);
197
198 return err;
199}
200
201/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 * Atomically swap in the new signal mask, and wait for a signal.
203 */
204
205#ifdef CONFIG_TRAD_SIGNALS
206save_static_function(sys_sigsuspend);
207__attribute_used__ noinline static int
208_sys_sigsuspend(nabi_no_regargs struct pt_regs regs)
209{
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000210 sigset_t newset;
Ralf Baechlefe00f942005-03-01 19:22:29 +0000211 sigset_t __user *uset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Ralf Baechlefe00f942005-03-01 19:22:29 +0000213 uset = (sigset_t __user *) regs.regs[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 if (copy_from_user(&newset, uset, sizeof(sigset_t)))
215 return -EFAULT;
216 sigdelsetmask(&newset, ~_BLOCKABLE);
217
218 spin_lock_irq(&current->sighand->siglock);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000219 current->saved_sigmask = current->blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 current->blocked = newset;
221 recalc_sigpending();
222 spin_unlock_irq(&current->sighand->siglock);
223
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000224 current->state = TASK_INTERRUPTIBLE;
225 schedule();
226 set_thread_flag(TIF_RESTORE_SIGMASK);
227 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228}
229#endif
230
231save_static_function(sys_rt_sigsuspend);
232__attribute_used__ noinline static int
233_sys_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
234{
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000235 sigset_t newset;
Ralf Baechlefe00f942005-03-01 19:22:29 +0000236 sigset_t __user *unewset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 size_t sigsetsize;
238
239 /* XXX Don't preclude handling different sized sigset_t's. */
240 sigsetsize = regs.regs[5];
241 if (sigsetsize != sizeof(sigset_t))
242 return -EINVAL;
243
Ralf Baechlefe00f942005-03-01 19:22:29 +0000244 unewset = (sigset_t __user *) regs.regs[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 if (copy_from_user(&newset, unewset, sizeof(newset)))
246 return -EFAULT;
247 sigdelsetmask(&newset, ~_BLOCKABLE);
248
249 spin_lock_irq(&current->sighand->siglock);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000250 current->saved_sigmask = current->blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 current->blocked = newset;
Ralf Baechlee0daad42007-02-05 00:10:11 +0000252 recalc_sigpending();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 spin_unlock_irq(&current->sighand->siglock);
254
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000255 current->state = TASK_INTERRUPTIBLE;
256 schedule();
257 set_thread_flag(TIF_RESTORE_SIGMASK);
258 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259}
260
261#ifdef CONFIG_TRAD_SIGNALS
Atsushi Nemoto9c6031c2006-02-19 23:46:44 +0900262asmlinkage int sys_sigaction(int sig, const struct sigaction __user *act,
263 struct sigaction __user *oact)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
265 struct k_sigaction new_ka, old_ka;
266 int ret;
267 int err = 0;
268
269 if (act) {
270 old_sigset_t mask;
271
272 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
273 return -EFAULT;
274 err |= __get_user(new_ka.sa.sa_handler, &act->sa_handler);
275 err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
276 err |= __get_user(mask, &act->sa_mask.sig[0]);
277 if (err)
278 return -EFAULT;
279
280 siginitset(&new_ka.sa.sa_mask, mask);
281 }
282
283 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
284
285 if (!ret && oact) {
286 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
Ralf Baechlee0daad42007-02-05 00:10:11 +0000287 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
289 err |= __put_user(old_ka.sa.sa_handler, &oact->sa_handler);
290 err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
291 err |= __put_user(0, &oact->sa_mask.sig[1]);
292 err |= __put_user(0, &oact->sa_mask.sig[2]);
293 err |= __put_user(0, &oact->sa_mask.sig[3]);
294 if (err)
295 return -EFAULT;
296 }
297
298 return ret;
299}
300#endif
301
302asmlinkage int sys_sigaltstack(nabi_no_regargs struct pt_regs regs)
303{
Ralf Baechlefe00f942005-03-01 19:22:29 +0000304 const stack_t __user *uss = (const stack_t __user *) regs.regs[4];
305 stack_t __user *uoss = (stack_t __user *) regs.regs[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 unsigned long usp = regs.regs[29];
307
308 return do_sigaltstack(uss, uoss, usp);
309}
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311#ifdef CONFIG_TRAD_SIGNALS
312save_static_function(sys_sigreturn);
313__attribute_used__ noinline static void
314_sys_sigreturn(nabi_no_regargs struct pt_regs regs)
315{
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900316 struct sigframe __user *frame;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 sigset_t blocked;
318
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900319 frame = (struct sigframe __user *) regs.regs[29];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
321 goto badframe;
322 if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked)))
323 goto badframe;
324
325 sigdelsetmask(&blocked, ~_BLOCKABLE);
326 spin_lock_irq(&current->sighand->siglock);
327 current->blocked = blocked;
328 recalc_sigpending();
329 spin_unlock_irq(&current->sighand->siglock);
330
331 if (restore_sigcontext(&regs, &frame->sf_sc))
332 goto badframe;
333
334 /*
335 * Don't let your children do this ...
336 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 __asm__ __volatile__(
338 "move\t$29, %0\n\t"
339 "j\tsyscall_exit"
340 :/* no outputs */
341 :"r" (&regs));
342 /* Unreached */
343
344badframe:
345 force_sig(SIGSEGV, current);
346}
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000347#endif /* CONFIG_TRAD_SIGNALS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349save_static_function(sys_rt_sigreturn);
350__attribute_used__ noinline static void
351_sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
352{
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900353 struct rt_sigframe __user *frame;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 sigset_t set;
355 stack_t st;
356
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900357 frame = (struct rt_sigframe __user *) regs.regs[29];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
359 goto badframe;
360 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
361 goto badframe;
362
363 sigdelsetmask(&set, ~_BLOCKABLE);
364 spin_lock_irq(&current->sighand->siglock);
365 current->blocked = set;
366 recalc_sigpending();
367 spin_unlock_irq(&current->sighand->siglock);
368
369 if (restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext))
370 goto badframe;
371
372 if (__copy_from_user(&st, &frame->rs_uc.uc_stack, sizeof(st)))
373 goto badframe;
374 /* It is more difficult to avoid calling this function than to
375 call it and ignore errors. */
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900376 do_sigaltstack((stack_t __user *)&st, NULL, regs.regs[29]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378 /*
379 * Don't let your children do this ...
380 */
381 __asm__ __volatile__(
382 "move\t$29, %0\n\t"
383 "j\tsyscall_exit"
384 :/* no outputs */
385 :"r" (&regs));
386 /* Unreached */
387
388badframe:
389 force_sig(SIGSEGV, current);
390}
391
392#ifdef CONFIG_TRAD_SIGNALS
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000393int setup_frame(struct k_sigaction * ka, struct pt_regs *regs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 int signr, sigset_t *set)
395{
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900396 struct sigframe __user *frame;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 int err = 0;
398
399 frame = get_sigframe(ka, regs, sizeof(*frame));
400 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
401 goto give_sigsegv;
402
Franck Bui-Huu601dde42007-02-05 15:24:23 +0100403 err |= install_sigtramp(frame->sf_code, __NR_sigreturn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 err |= setup_sigcontext(regs, &frame->sf_sc);
406 err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));
407 if (err)
408 goto give_sigsegv;
409
410 /*
411 * Arguments to signal handler:
412 *
413 * a0 = signal number
414 * a1 = 0 (should be cause)
415 * a2 = pointer to struct sigcontext
416 *
417 * $25 and c0_epc point to the signal handler, $29 points to the
418 * struct sigframe.
419 */
420 regs->regs[ 4] = signr;
421 regs->regs[ 5] = 0;
422 regs->regs[ 6] = (unsigned long) &frame->sf_sc;
423 regs->regs[29] = (unsigned long) frame;
424 regs->regs[31] = (unsigned long) frame->sf_code;
425 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
426
427#if DEBUG_SIG
428 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
429 current->comm, current->pid,
430 frame, regs->cp0_epc, frame->regs[31]);
431#endif
Ralf Baechlee0daad42007-02-05 00:10:11 +0000432 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
434give_sigsegv:
435 force_sigsegv(signr, current);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000436 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438#endif
439
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000440int setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 int signr, sigset_t *set, siginfo_t *info)
442{
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900443 struct rt_sigframe __user *frame;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 int err = 0;
445
446 frame = get_sigframe(ka, regs, sizeof(*frame));
447 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
448 goto give_sigsegv;
449
Franck Bui-Huu601dde42007-02-05 15:24:23 +0100450 err |= install_sigtramp(frame->rs_code, __NR_rt_sigreturn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452 /* Create siginfo. */
453 err |= copy_siginfo_to_user(&frame->rs_info, info);
454
455 /* Create the ucontext. */
456 err |= __put_user(0, &frame->rs_uc.uc_flags);
Atsushi Nemoto5665a0a2006-02-02 01:26:34 +0900457 err |= __put_user(NULL, &frame->rs_uc.uc_link);
Atsushi Nemoto9c6031c2006-02-19 23:46:44 +0900458 err |= __put_user((void __user *)current->sas_ss_sp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 &frame->rs_uc.uc_stack.ss_sp);
460 err |= __put_user(sas_ss_flags(regs->regs[29]),
461 &frame->rs_uc.uc_stack.ss_flags);
462 err |= __put_user(current->sas_ss_size,
463 &frame->rs_uc.uc_stack.ss_size);
464 err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
465 err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));
466
467 if (err)
468 goto give_sigsegv;
469
470 /*
471 * Arguments to signal handler:
472 *
473 * a0 = signal number
474 * a1 = 0 (should be cause)
475 * a2 = pointer to ucontext
476 *
477 * $25 and c0_epc point to the signal handler, $29 points to
478 * the struct rt_sigframe.
479 */
480 regs->regs[ 4] = signr;
481 regs->regs[ 5] = (unsigned long) &frame->rs_info;
482 regs->regs[ 6] = (unsigned long) &frame->rs_uc;
483 regs->regs[29] = (unsigned long) frame;
484 regs->regs[31] = (unsigned long) frame->rs_code;
485 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
486
487#if DEBUG_SIG
488 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
489 current->comm, current->pid,
490 frame, regs->cp0_epc, regs->regs[31]);
491#endif
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000492 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494give_sigsegv:
495 force_sigsegv(signr, current);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000496 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497}
498
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000499static inline int handle_signal(unsigned long sig, siginfo_t *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs)
501{
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000502 int ret;
503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 switch(regs->regs[0]) {
505 case ERESTART_RESTARTBLOCK:
506 case ERESTARTNOHAND:
507 regs->regs[2] = EINTR;
508 break;
509 case ERESTARTSYS:
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000510 if (!(ka->sa.sa_flags & SA_RESTART)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 regs->regs[2] = EINTR;
512 break;
513 }
514 /* fallthrough */
515 case ERESTARTNOINTR: /* Userland will reload $v0. */
516 regs->regs[7] = regs->regs[26];
517 regs->cp0_epc -= 8;
518 }
519
520 regs->regs[0] = 0; /* Don't deal with this again. */
521
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000522 if (sig_uses_siginfo(ka))
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000523 ret = current->thread.abi->setup_rt_frame(ka, regs, sig, oldset, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 else
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000525 ret = current->thread.abi->setup_frame(ka, regs, sig, oldset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Steven Rostedt69be8f12005-08-29 11:44:09 -0400527 spin_lock_irq(&current->sighand->siglock);
528 sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
529 if (!(ka->sa.sa_flags & SA_NODEFER))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 sigaddset(&current->blocked,sig);
Steven Rostedt69be8f12005-08-29 11:44:09 -0400531 recalc_sigpending();
532 spin_unlock_irq(&current->sighand->siglock);
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000533
534 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535}
536
Ralf Baechle40ac5d42006-02-08 13:38:18 +0000537void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
539 struct k_sigaction ka;
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000540 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 siginfo_t info;
542 int signr;
543
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 /*
545 * We want the common case to go fast, which is why we may in certain
546 * cases get here from kernel mode. Just return without doing anything
547 * if so.
548 */
549 if (!user_mode(regs))
Ralf Baechle40ac5d42006-02-08 13:38:18 +0000550 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000552 if (test_thread_flag(TIF_RESTORE_SIGMASK))
553 oldset = &current->saved_sigmask;
554 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 oldset = &current->blocked;
556
557 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000558 if (signr > 0) {
559 /* Whee! Actually deliver the signal. */
560 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
561 /*
562 * A signal was successfully delivered; the saved
563 * sigmask will have been stored in the signal frame,
564 * and will be restored by sigreturn, so we can simply
565 * clear the TIF_RESTORE_SIGMASK flag.
566 */
567 if (test_thread_flag(TIF_RESTORE_SIGMASK))
568 clear_thread_flag(TIF_RESTORE_SIGMASK);
569 }
Ralf Baechle45887e12006-08-03 21:54:13 +0100570
571 return;
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000572 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 /*
575 * Who's code doesn't conform to the restartable syscall convention
576 * dies here!!! The li instruction, a single machine instruction,
577 * must directly be followed by the syscall instruction.
578 */
579 if (regs->regs[0]) {
580 if (regs->regs[2] == ERESTARTNOHAND ||
581 regs->regs[2] == ERESTARTSYS ||
582 regs->regs[2] == ERESTARTNOINTR) {
583 regs->regs[7] = regs->regs[26];
584 regs->cp0_epc -= 8;
585 }
586 if (regs->regs[2] == ERESTART_RESTARTBLOCK) {
587 regs->regs[2] = __NR_restart_syscall;
588 regs->regs[7] = regs->regs[26];
589 regs->cp0_epc -= 4;
590 }
Ralf Baechle13fdd312006-08-08 03:47:01 +0100591 regs->regs[0] = 0; /* Don't deal with this again. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000593
594 /*
595 * If there's no signal to deliver, we just put the saved sigmask
596 * back
597 */
598 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
599 clear_thread_flag(TIF_RESTORE_SIGMASK);
600 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
601 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602}
603
604/*
605 * notification of userspace execution resumption
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000606 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 */
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000608asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 __u32 thread_info_flags)
610{
611 /* deal with pending signal delivery */
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000612 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
613 current->thread.abi->do_signal(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614}