blob: adbfb95e42d0f80b927b0a216d442fa7ac21dcb0 [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
Ralf Baechle66680582007-02-13 01:31:48 +000037/*
38 * Horribly complicated - with the bloody RM9000 workarounds enabled
39 * the signal trampolines is moving to the end of the structure so we can
40 * increase the alignment without breaking software compatibility.
41 */
Franck Bui-Huuc0b9bae2007-02-05 15:24:21 +010042#if ICACHE_REFILLS_WORKAROUND_WAR == 0
43
Ralf Baechle66680582007-02-13 01:31:48 +000044struct sigframe {
45 u32 sf_ass[4]; /* argument save space for o32 */
46 u32 sf_code[2]; /* signal trampoline */
47 struct sigcontext sf_sc;
48 sigset_t sf_mask;
49};
50
Franck Bui-Huuc0b9bae2007-02-05 15:24:21 +010051struct rt_sigframe {
52 u32 rs_ass[4]; /* argument save space for o32 */
53 u32 rs_code[2]; /* signal trampoline */
54 struct siginfo rs_info;
55 struct ucontext rs_uc;
56};
57
58#else
59
Ralf Baechle66680582007-02-13 01:31:48 +000060struct sigframe {
61 u32 sf_ass[4]; /* argument save space for o32 */
62 u32 sf_pad[2];
63 struct sigcontext sf_sc; /* hw context */
64 sigset_t sf_mask;
65 u32 sf_code[8] ____cacheline_aligned; /* signal trampoline */
66};
67
Franck Bui-Huuc0b9bae2007-02-05 15:24:21 +010068struct rt_sigframe {
69 u32 rs_ass[4]; /* argument save space for o32 */
70 u32 rs_pad[2];
71 struct siginfo rs_info;
72 struct ucontext rs_uc;
73 u32 rs_code[8] ____cacheline_aligned; /* signal trampoline */
74};
75
76#endif
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078/*
Franck Bui-Huuc3fc4ab2007-02-05 15:24:20 +010079 * Helper routines
80 */
81int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
82{
83 int err = 0;
84 int i;
85
86 err |= __put_user(regs->cp0_epc, &sc->sc_pc);
87
88 err |= __put_user(0, &sc->sc_regs[0]);
89 for (i = 1; i < 32; i++)
90 err |= __put_user(regs->regs[i], &sc->sc_regs[i]);
91
92 err |= __put_user(regs->hi, &sc->sc_mdhi);
93 err |= __put_user(regs->lo, &sc->sc_mdlo);
94 if (cpu_has_dsp) {
95 err |= __put_user(mfhi1(), &sc->sc_hi1);
96 err |= __put_user(mflo1(), &sc->sc_lo1);
97 err |= __put_user(mfhi2(), &sc->sc_hi2);
98 err |= __put_user(mflo2(), &sc->sc_lo2);
99 err |= __put_user(mfhi3(), &sc->sc_hi3);
100 err |= __put_user(mflo3(), &sc->sc_lo3);
101 err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
102 }
103
104 err |= __put_user(!!used_math(), &sc->sc_used_math);
105
106 if (used_math()) {
107 /*
108 * Save FPU state to signal context. Signal handler
109 * will "inherit" current FPU state.
110 */
111 preempt_disable();
112
113 if (!is_fpu_owner()) {
114 own_fpu();
115 restore_fp(current);
116 }
117 err |= save_fp_context(sc);
118
119 preempt_enable();
120 }
121 return err;
122}
123
124int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
125{
126 unsigned int used_math;
127 unsigned long treg;
128 int err = 0;
129 int i;
130
131 /* Always make any pending restarted system calls return -EINTR */
132 current_thread_info()->restart_block.fn = do_no_restart_syscall;
133
134 err |= __get_user(regs->cp0_epc, &sc->sc_pc);
135 err |= __get_user(regs->hi, &sc->sc_mdhi);
136 err |= __get_user(regs->lo, &sc->sc_mdlo);
137 if (cpu_has_dsp) {
138 err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
139 err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
140 err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
141 err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
142 err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
143 err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
144 err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
145 }
146
147 for (i = 1; i < 32; i++)
148 err |= __get_user(regs->regs[i], &sc->sc_regs[i]);
149
150 err |= __get_user(used_math, &sc->sc_used_math);
151 conditional_used_math(used_math);
152
153 preempt_disable();
154
155 if (used_math()) {
156 /* restore fpu context if we have used it before */
157 own_fpu();
158 err |= restore_fp_context(sc);
159 } else {
160 /* signal handler may have used FPU. Give it up. */
161 lose_fpu();
162 }
163
164 preempt_enable();
165
166 return err;
167}
168
169void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
170 size_t frame_size)
171{
172 unsigned long sp;
173
174 /* Default to using normal stack */
175 sp = regs->regs[29];
176
177 /*
178 * FPU emulator may have it's own trampoline active just
179 * above the user stack, 16-bytes before the next lowest
180 * 16 byte boundary. Try to avoid trashing it.
181 */
182 sp -= 32;
183
184 /* This is the X/Open sanctioned signal stack switching. */
185 if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
186 sp = current->sas_ss_sp + current->sas_ss_size;
187
188 return (void __user *)((sp - frame_size) & (ICACHE_REFILLS_WORKAROUND_WAR ? ~(cpu_icache_line_size()-1) : ALMASK));
189}
190
191int install_sigtramp(unsigned int __user *tramp, unsigned int syscall)
192{
193 int err;
194
195 /*
196 * Set up the return code ...
197 *
198 * li v0, __NR__foo_sigreturn
199 * syscall
200 */
201
202 err = __put_user(0x24020000 + syscall, tramp + 0);
Franck Bui-Huu601dde42007-02-05 15:24:23 +0100203 err |= __put_user(0x0000000c , tramp + 1);
Franck Bui-Huuc3fc4ab2007-02-05 15:24:20 +0100204 if (ICACHE_REFILLS_WORKAROUND_WAR) {
205 err |= __put_user(0, tramp + 2);
206 err |= __put_user(0, tramp + 3);
207 err |= __put_user(0, tramp + 4);
208 err |= __put_user(0, tramp + 5);
209 err |= __put_user(0, tramp + 6);
210 err |= __put_user(0, tramp + 7);
211 }
212 flush_cache_sigtramp((unsigned long) tramp);
213
214 return err;
215}
216
217/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 * Atomically swap in the new signal mask, and wait for a signal.
219 */
220
221#ifdef CONFIG_TRAD_SIGNALS
Franck Bui-Huuf90080a2007-02-05 15:24:27 +0100222asmlinkage int sys_sigsuspend(nabi_no_regargs struct pt_regs regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000224 sigset_t newset;
Ralf Baechlefe00f942005-03-01 19:22:29 +0000225 sigset_t __user *uset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Ralf Baechlefe00f942005-03-01 19:22:29 +0000227 uset = (sigset_t __user *) regs.regs[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if (copy_from_user(&newset, uset, sizeof(sigset_t)))
229 return -EFAULT;
230 sigdelsetmask(&newset, ~_BLOCKABLE);
231
232 spin_lock_irq(&current->sighand->siglock);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000233 current->saved_sigmask = current->blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 current->blocked = newset;
235 recalc_sigpending();
236 spin_unlock_irq(&current->sighand->siglock);
237
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000238 current->state = TASK_INTERRUPTIBLE;
239 schedule();
240 set_thread_flag(TIF_RESTORE_SIGMASK);
241 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242}
243#endif
244
Franck Bui-Huuf90080a2007-02-05 15:24:27 +0100245asmlinkage int sys_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000247 sigset_t newset;
Ralf Baechlefe00f942005-03-01 19:22:29 +0000248 sigset_t __user *unewset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 size_t sigsetsize;
250
251 /* XXX Don't preclude handling different sized sigset_t's. */
252 sigsetsize = regs.regs[5];
253 if (sigsetsize != sizeof(sigset_t))
254 return -EINVAL;
255
Ralf Baechlefe00f942005-03-01 19:22:29 +0000256 unewset = (sigset_t __user *) regs.regs[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 if (copy_from_user(&newset, unewset, sizeof(newset)))
258 return -EFAULT;
259 sigdelsetmask(&newset, ~_BLOCKABLE);
260
261 spin_lock_irq(&current->sighand->siglock);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000262 current->saved_sigmask = current->blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 current->blocked = newset;
Ralf Baechlee0daad42007-02-05 00:10:11 +0000264 recalc_sigpending();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 spin_unlock_irq(&current->sighand->siglock);
266
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000267 current->state = TASK_INTERRUPTIBLE;
268 schedule();
269 set_thread_flag(TIF_RESTORE_SIGMASK);
270 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271}
272
273#ifdef CONFIG_TRAD_SIGNALS
Atsushi Nemoto9c6031c2006-02-19 23:46:44 +0900274asmlinkage int sys_sigaction(int sig, const struct sigaction __user *act,
275 struct sigaction __user *oact)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
277 struct k_sigaction new_ka, old_ka;
278 int ret;
279 int err = 0;
280
281 if (act) {
282 old_sigset_t mask;
283
284 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
285 return -EFAULT;
286 err |= __get_user(new_ka.sa.sa_handler, &act->sa_handler);
287 err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
288 err |= __get_user(mask, &act->sa_mask.sig[0]);
289 if (err)
290 return -EFAULT;
291
292 siginitset(&new_ka.sa.sa_mask, mask);
293 }
294
295 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
296
297 if (!ret && oact) {
298 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
Ralf Baechlee0daad42007-02-05 00:10:11 +0000299 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
301 err |= __put_user(old_ka.sa.sa_handler, &oact->sa_handler);
302 err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
303 err |= __put_user(0, &oact->sa_mask.sig[1]);
304 err |= __put_user(0, &oact->sa_mask.sig[2]);
305 err |= __put_user(0, &oact->sa_mask.sig[3]);
306 if (err)
307 return -EFAULT;
308 }
309
310 return ret;
311}
312#endif
313
314asmlinkage int sys_sigaltstack(nabi_no_regargs struct pt_regs regs)
315{
Ralf Baechlefe00f942005-03-01 19:22:29 +0000316 const stack_t __user *uss = (const stack_t __user *) regs.regs[4];
317 stack_t __user *uoss = (stack_t __user *) regs.regs[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 unsigned long usp = regs.regs[29];
319
320 return do_sigaltstack(uss, uoss, usp);
321}
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#ifdef CONFIG_TRAD_SIGNALS
Franck Bui-Huuf90080a2007-02-05 15:24:27 +0100324asmlinkage void sys_sigreturn(nabi_no_regargs struct pt_regs regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900326 struct sigframe __user *frame;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 sigset_t blocked;
328
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900329 frame = (struct sigframe __user *) regs.regs[29];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
331 goto badframe;
332 if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked)))
333 goto badframe;
334
335 sigdelsetmask(&blocked, ~_BLOCKABLE);
336 spin_lock_irq(&current->sighand->siglock);
337 current->blocked = blocked;
338 recalc_sigpending();
339 spin_unlock_irq(&current->sighand->siglock);
340
341 if (restore_sigcontext(&regs, &frame->sf_sc))
342 goto badframe;
343
344 /*
345 * Don't let your children do this ...
346 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 __asm__ __volatile__(
348 "move\t$29, %0\n\t"
349 "j\tsyscall_exit"
350 :/* no outputs */
351 :"r" (&regs));
352 /* Unreached */
353
354badframe:
355 force_sig(SIGSEGV, current);
356}
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000357#endif /* CONFIG_TRAD_SIGNALS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Franck Bui-Huuf90080a2007-02-05 15:24:27 +0100359asmlinkage void sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900361 struct rt_sigframe __user *frame;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 sigset_t set;
363 stack_t st;
364
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900365 frame = (struct rt_sigframe __user *) regs.regs[29];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
367 goto badframe;
368 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
369 goto badframe;
370
371 sigdelsetmask(&set, ~_BLOCKABLE);
372 spin_lock_irq(&current->sighand->siglock);
373 current->blocked = set;
374 recalc_sigpending();
375 spin_unlock_irq(&current->sighand->siglock);
376
377 if (restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext))
378 goto badframe;
379
380 if (__copy_from_user(&st, &frame->rs_uc.uc_stack, sizeof(st)))
381 goto badframe;
382 /* It is more difficult to avoid calling this function than to
383 call it and ignore errors. */
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900384 do_sigaltstack((stack_t __user *)&st, NULL, regs.regs[29]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386 /*
387 * Don't let your children do this ...
388 */
389 __asm__ __volatile__(
390 "move\t$29, %0\n\t"
391 "j\tsyscall_exit"
392 :/* no outputs */
393 :"r" (&regs));
394 /* Unreached */
395
396badframe:
397 force_sig(SIGSEGV, current);
398}
399
400#ifdef CONFIG_TRAD_SIGNALS
Ralf Baechle151fd6a2007-02-15 11:40:37 +0000401static int setup_frame(struct k_sigaction * ka, struct pt_regs *regs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 int signr, sigset_t *set)
403{
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900404 struct sigframe __user *frame;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 int err = 0;
406
407 frame = get_sigframe(ka, regs, sizeof(*frame));
408 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
409 goto give_sigsegv;
410
Franck Bui-Huu601dde42007-02-05 15:24:23 +0100411 err |= install_sigtramp(frame->sf_code, __NR_sigreturn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 err |= setup_sigcontext(regs, &frame->sf_sc);
414 err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));
415 if (err)
416 goto give_sigsegv;
417
418 /*
419 * Arguments to signal handler:
420 *
421 * a0 = signal number
422 * a1 = 0 (should be cause)
423 * a2 = pointer to struct sigcontext
424 *
425 * $25 and c0_epc point to the signal handler, $29 points to the
426 * struct sigframe.
427 */
428 regs->regs[ 4] = signr;
429 regs->regs[ 5] = 0;
430 regs->regs[ 6] = (unsigned long) &frame->sf_sc;
431 regs->regs[29] = (unsigned long) frame;
432 regs->regs[31] = (unsigned long) frame->sf_code;
433 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
434
Franck Bui-Huu722bb632007-02-05 15:24:24 +0100435 DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 current->comm, current->pid,
Franck Bui-Huu722bb632007-02-05 15:24:24 +0100437 frame, regs->cp0_epc, regs->regs[31]);
Ralf Baechlee0daad42007-02-05 00:10:11 +0000438 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440give_sigsegv:
441 force_sigsegv(signr, current);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000442 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443}
444#endif
445
Ralf Baechle151fd6a2007-02-15 11:40:37 +0000446static int setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 int signr, sigset_t *set, siginfo_t *info)
448{
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +0900449 struct rt_sigframe __user *frame;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 int err = 0;
451
452 frame = get_sigframe(ka, regs, sizeof(*frame));
453 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
454 goto give_sigsegv;
455
Franck Bui-Huu601dde42007-02-05 15:24:23 +0100456 err |= install_sigtramp(frame->rs_code, __NR_rt_sigreturn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 /* Create siginfo. */
459 err |= copy_siginfo_to_user(&frame->rs_info, info);
460
461 /* Create the ucontext. */
462 err |= __put_user(0, &frame->rs_uc.uc_flags);
Atsushi Nemoto5665a0a2006-02-02 01:26:34 +0900463 err |= __put_user(NULL, &frame->rs_uc.uc_link);
Atsushi Nemoto9c6031c2006-02-19 23:46:44 +0900464 err |= __put_user((void __user *)current->sas_ss_sp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 &frame->rs_uc.uc_stack.ss_sp);
466 err |= __put_user(sas_ss_flags(regs->regs[29]),
467 &frame->rs_uc.uc_stack.ss_flags);
468 err |= __put_user(current->sas_ss_size,
469 &frame->rs_uc.uc_stack.ss_size);
470 err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
471 err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));
472
473 if (err)
474 goto give_sigsegv;
475
476 /*
477 * Arguments to signal handler:
478 *
479 * a0 = signal number
480 * a1 = 0 (should be cause)
481 * a2 = pointer to ucontext
482 *
483 * $25 and c0_epc point to the signal handler, $29 points to
484 * the struct rt_sigframe.
485 */
486 regs->regs[ 4] = signr;
487 regs->regs[ 5] = (unsigned long) &frame->rs_info;
488 regs->regs[ 6] = (unsigned long) &frame->rs_uc;
489 regs->regs[29] = (unsigned long) frame;
490 regs->regs[31] = (unsigned long) frame->rs_code;
491 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
492
Franck Bui-Huu722bb632007-02-05 15:24:24 +0100493 DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 current->comm, current->pid,
495 frame, regs->cp0_epc, regs->regs[31]);
Franck Bui-Huu722bb632007-02-05 15:24:24 +0100496
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000497 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499give_sigsegv:
500 force_sigsegv(signr, current);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000501 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502}
503
Ralf Baechle151fd6a2007-02-15 11:40:37 +0000504struct mips_abi mips_abi = {
505#ifdef CONFIG_TRAD_SIGNALS
506 .setup_frame = setup_frame,
507#endif
508 .setup_rt_frame = setup_rt_frame,
509 .restart = __NR_restart_syscall
510};
511
Franck Bui-Huue692eb32007-02-05 15:24:28 +0100512static int handle_signal(unsigned long sig, siginfo_t *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs)
514{
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000515 int ret;
516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 switch(regs->regs[0]) {
518 case ERESTART_RESTARTBLOCK:
519 case ERESTARTNOHAND:
520 regs->regs[2] = EINTR;
521 break;
522 case ERESTARTSYS:
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000523 if (!(ka->sa.sa_flags & SA_RESTART)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 regs->regs[2] = EINTR;
525 break;
526 }
527 /* fallthrough */
528 case ERESTARTNOINTR: /* Userland will reload $v0. */
529 regs->regs[7] = regs->regs[26];
530 regs->cp0_epc -= 8;
531 }
532
533 regs->regs[0] = 0; /* Don't deal with this again. */
534
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000535 if (sig_uses_siginfo(ka))
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000536 ret = current->thread.abi->setup_rt_frame(ka, regs, sig, oldset, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 else
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000538 ret = current->thread.abi->setup_frame(ka, regs, sig, oldset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Steven Rostedt69be8f12005-08-29 11:44:09 -0400540 spin_lock_irq(&current->sighand->siglock);
541 sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
542 if (!(ka->sa.sa_flags & SA_NODEFER))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 sigaddset(&current->blocked,sig);
Steven Rostedt69be8f12005-08-29 11:44:09 -0400544 recalc_sigpending();
545 spin_unlock_irq(&current->sighand->siglock);
Ralf Baechle129bc8f2005-07-11 20:45:51 +0000546
547 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548}
549
Ralf Baechle151fd6a2007-02-15 11:40:37 +0000550static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551{
552 struct k_sigaction ka;
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000553 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 siginfo_t info;
555 int signr;
556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 /*
558 * We want the common case to go fast, which is why we may in certain
559 * cases get here from kernel mode. Just return without doing anything
560 * if so.
561 */
562 if (!user_mode(regs))
Ralf Baechle40ac5d42006-02-08 13:38:18 +0000563 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000565 if (test_thread_flag(TIF_RESTORE_SIGMASK))
566 oldset = &current->saved_sigmask;
567 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 oldset = &current->blocked;
569
570 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000571 if (signr > 0) {
572 /* Whee! Actually deliver the signal. */
573 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
574 /*
575 * A signal was successfully delivered; the saved
576 * sigmask will have been stored in the signal frame,
577 * and will be restored by sigreturn, so we can simply
578 * clear the TIF_RESTORE_SIGMASK flag.
579 */
580 if (test_thread_flag(TIF_RESTORE_SIGMASK))
581 clear_thread_flag(TIF_RESTORE_SIGMASK);
582 }
Ralf Baechle45887e12006-08-03 21:54:13 +0100583
584 return;
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000585 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 /*
588 * Who's code doesn't conform to the restartable syscall convention
589 * dies here!!! The li instruction, a single machine instruction,
590 * must directly be followed by the syscall instruction.
591 */
592 if (regs->regs[0]) {
593 if (regs->regs[2] == ERESTARTNOHAND ||
594 regs->regs[2] == ERESTARTSYS ||
595 regs->regs[2] == ERESTARTNOINTR) {
596 regs->regs[7] = regs->regs[26];
597 regs->cp0_epc -= 8;
598 }
599 if (regs->regs[2] == ERESTART_RESTARTBLOCK) {
Ralf Baechle151fd6a2007-02-15 11:40:37 +0000600 regs->regs[2] = current->thread.abi->restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 regs->regs[7] = regs->regs[26];
602 regs->cp0_epc -= 4;
603 }
Ralf Baechle13fdd312006-08-08 03:47:01 +0100604 regs->regs[0] = 0; /* Don't deal with this again. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 }
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000606
607 /*
608 * If there's no signal to deliver, we just put the saved sigmask
609 * back
610 */
611 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
612 clear_thread_flag(TIF_RESTORE_SIGMASK);
613 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
614 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615}
616
617/*
618 * notification of userspace execution resumption
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000619 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 */
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000621asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 __u32 thread_info_flags)
623{
624 /* deal with pending signal delivery */
Ralf Baechle7b3e2fc2006-02-08 12:58:41 +0000625 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
Ralf Baechle151fd6a2007-02-15 11:40:37 +0000626 do_signal(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627}