Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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 | */ | |
02416dcf | 10 | #include <linux/cache.h> |
1da177e4 LT |
11 | #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 | ||
e50c0a8f | 24 | #include <asm/abi.h> |
1da177e4 LT |
25 | #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> | |
02416dcf | 33 | #include <asm/war.h> |
1da177e4 LT |
34 | |
35 | #include "signal-common.h" | |
36 | ||
37 | #define DEBUG_SIG 0 | |
38 | ||
39 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) | |
40 | ||
c0b9bae9 FBH |
41 | #if ICACHE_REFILLS_WORKAROUND_WAR == 0 |
42 | ||
43 | struct 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 | ||
52 | struct 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 | ||
c3fc4ab3 FBH |
62 | /* |
63 | * Helper routines | |
64 | */ | |
65 | int 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 | ||
108 | int 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 | ||
153 | void __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 | ||
175 | int 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); | |
187 | err |= __put_user(0x0000000c , tramp + 1); | |
188 | 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 | ||
1da177e4 LT |
201 | /* |
202 | * Atomically swap in the new signal mask, and wait for a signal. | |
203 | */ | |
204 | ||
205 | #ifdef CONFIG_TRAD_SIGNALS | |
206 | save_static_function(sys_sigsuspend); | |
207 | __attribute_used__ noinline static int | |
208 | _sys_sigsuspend(nabi_no_regargs struct pt_regs regs) | |
209 | { | |
7b3e2fc8 | 210 | sigset_t newset; |
fe00f943 | 211 | sigset_t __user *uset; |
1da177e4 | 212 | |
fe00f943 | 213 | uset = (sigset_t __user *) regs.regs[4]; |
1da177e4 LT |
214 | if (copy_from_user(&newset, uset, sizeof(sigset_t))) |
215 | return -EFAULT; | |
216 | sigdelsetmask(&newset, ~_BLOCKABLE); | |
217 | ||
218 | spin_lock_irq(¤t->sighand->siglock); | |
7b3e2fc8 | 219 | current->saved_sigmask = current->blocked; |
1da177e4 LT |
220 | current->blocked = newset; |
221 | recalc_sigpending(); | |
222 | spin_unlock_irq(¤t->sighand->siglock); | |
223 | ||
7b3e2fc8 RB |
224 | current->state = TASK_INTERRUPTIBLE; |
225 | schedule(); | |
226 | set_thread_flag(TIF_RESTORE_SIGMASK); | |
227 | return -ERESTARTNOHAND; | |
1da177e4 LT |
228 | } |
229 | #endif | |
230 | ||
231 | save_static_function(sys_rt_sigsuspend); | |
232 | __attribute_used__ noinline static int | |
233 | _sys_rt_sigsuspend(nabi_no_regargs struct pt_regs regs) | |
234 | { | |
7b3e2fc8 | 235 | sigset_t newset; |
fe00f943 | 236 | sigset_t __user *unewset; |
1da177e4 LT |
237 | 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 | ||
fe00f943 | 244 | unewset = (sigset_t __user *) regs.regs[4]; |
1da177e4 LT |
245 | if (copy_from_user(&newset, unewset, sizeof(newset))) |
246 | return -EFAULT; | |
247 | sigdelsetmask(&newset, ~_BLOCKABLE); | |
248 | ||
249 | spin_lock_irq(¤t->sighand->siglock); | |
7b3e2fc8 | 250 | current->saved_sigmask = current->blocked; |
1da177e4 | 251 | current->blocked = newset; |
e0daad44 | 252 | recalc_sigpending(); |
1da177e4 LT |
253 | spin_unlock_irq(¤t->sighand->siglock); |
254 | ||
7b3e2fc8 RB |
255 | current->state = TASK_INTERRUPTIBLE; |
256 | schedule(); | |
257 | set_thread_flag(TIF_RESTORE_SIGMASK); | |
258 | return -ERESTARTNOHAND; | |
1da177e4 LT |
259 | } |
260 | ||
261 | #ifdef CONFIG_TRAD_SIGNALS | |
9c6031cc AN |
262 | asmlinkage int sys_sigaction(int sig, const struct sigaction __user *act, |
263 | struct sigaction __user *oact) | |
1da177e4 LT |
264 | { |
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))) | |
e0daad44 | 287 | return -EFAULT; |
1da177e4 LT |
288 | 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 | ||
302 | asmlinkage int sys_sigaltstack(nabi_no_regargs struct pt_regs regs) | |
303 | { | |
fe00f943 RB |
304 | const stack_t __user *uss = (const stack_t __user *) regs.regs[4]; |
305 | stack_t __user *uoss = (stack_t __user *) regs.regs[5]; | |
1da177e4 LT |
306 | unsigned long usp = regs.regs[29]; |
307 | ||
308 | return do_sigaltstack(uss, uoss, usp); | |
309 | } | |
310 | ||
1da177e4 LT |
311 | #ifdef CONFIG_TRAD_SIGNALS |
312 | save_static_function(sys_sigreturn); | |
313 | __attribute_used__ noinline static void | |
314 | _sys_sigreturn(nabi_no_regargs struct pt_regs regs) | |
315 | { | |
9bbf28a3 | 316 | struct sigframe __user *frame; |
1da177e4 LT |
317 | sigset_t blocked; |
318 | ||
9bbf28a3 | 319 | frame = (struct sigframe __user *) regs.regs[29]; |
1da177e4 LT |
320 | 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(¤t->sighand->siglock); | |
327 | current->blocked = blocked; | |
328 | recalc_sigpending(); | |
329 | spin_unlock_irq(¤t->sighand->siglock); | |
330 | ||
331 | if (restore_sigcontext(®s, &frame->sf_sc)) | |
332 | goto badframe; | |
333 | ||
334 | /* | |
335 | * Don't let your children do this ... | |
336 | */ | |
1da177e4 LT |
337 | __asm__ __volatile__( |
338 | "move\t$29, %0\n\t" | |
339 | "j\tsyscall_exit" | |
340 | :/* no outputs */ | |
341 | :"r" (®s)); | |
342 | /* Unreached */ | |
343 | ||
344 | badframe: | |
345 | force_sig(SIGSEGV, current); | |
346 | } | |
e50c0a8f | 347 | #endif /* CONFIG_TRAD_SIGNALS */ |
1da177e4 LT |
348 | |
349 | save_static_function(sys_rt_sigreturn); | |
350 | __attribute_used__ noinline static void | |
351 | _sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs) | |
352 | { | |
9bbf28a3 | 353 | struct rt_sigframe __user *frame; |
1da177e4 LT |
354 | sigset_t set; |
355 | stack_t st; | |
356 | ||
9bbf28a3 | 357 | frame = (struct rt_sigframe __user *) regs.regs[29]; |
1da177e4 LT |
358 | 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(¤t->sighand->siglock); | |
365 | current->blocked = set; | |
366 | recalc_sigpending(); | |
367 | spin_unlock_irq(¤t->sighand->siglock); | |
368 | ||
369 | if (restore_sigcontext(®s, &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. */ | |
9bbf28a3 | 376 | do_sigaltstack((stack_t __user *)&st, NULL, regs.regs[29]); |
1da177e4 LT |
377 | |
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" (®s)); | |
386 | /* Unreached */ | |
387 | ||
388 | badframe: | |
389 | force_sig(SIGSEGV, current); | |
390 | } | |
391 | ||
392 | #ifdef CONFIG_TRAD_SIGNALS | |
129bc8f7 | 393 | int setup_frame(struct k_sigaction * ka, struct pt_regs *regs, |
1da177e4 LT |
394 | int signr, sigset_t *set) |
395 | { | |
9bbf28a3 | 396 | struct sigframe __user *frame; |
1da177e4 LT |
397 | 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 | ||
02416dcf | 403 | install_sigtramp(frame->sf_code, __NR_sigreturn); |
1da177e4 LT |
404 | |
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 | |
e0daad44 | 432 | return 0; |
1da177e4 LT |
433 | |
434 | give_sigsegv: | |
435 | force_sigsegv(signr, current); | |
7b3e2fc8 | 436 | return -EFAULT; |
1da177e4 LT |
437 | } |
438 | #endif | |
439 | ||
129bc8f7 | 440 | int setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs, |
1da177e4 LT |
441 | int signr, sigset_t *set, siginfo_t *info) |
442 | { | |
9bbf28a3 | 443 | struct rt_sigframe __user *frame; |
1da177e4 LT |
444 | 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 | ||
02416dcf | 450 | install_sigtramp(frame->rs_code, __NR_rt_sigreturn); |
1da177e4 LT |
451 | |
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); | |
5665a0ac | 457 | err |= __put_user(NULL, &frame->rs_uc.uc_link); |
9c6031cc | 458 | err |= __put_user((void __user *)current->sas_ss_sp, |
1da177e4 LT |
459 | &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 | |
7b3e2fc8 | 492 | return 0; |
1da177e4 LT |
493 | |
494 | give_sigsegv: | |
495 | force_sigsegv(signr, current); | |
7b3e2fc8 | 496 | return -EFAULT; |
1da177e4 LT |
497 | } |
498 | ||
129bc8f7 | 499 | static inline int handle_signal(unsigned long sig, siginfo_t *info, |
1da177e4 LT |
500 | struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs) |
501 | { | |
129bc8f7 RB |
502 | int ret; |
503 | ||
1da177e4 LT |
504 | switch(regs->regs[0]) { |
505 | case ERESTART_RESTARTBLOCK: | |
506 | case ERESTARTNOHAND: | |
507 | regs->regs[2] = EINTR; | |
508 | break; | |
509 | case ERESTARTSYS: | |
7b3e2fc8 | 510 | if (!(ka->sa.sa_flags & SA_RESTART)) { |
1da177e4 LT |
511 | 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 | ||
e50c0a8f | 522 | if (sig_uses_siginfo(ka)) |
129bc8f7 | 523 | ret = current->thread.abi->setup_rt_frame(ka, regs, sig, oldset, info); |
1da177e4 | 524 | else |
129bc8f7 | 525 | ret = current->thread.abi->setup_frame(ka, regs, sig, oldset); |
1da177e4 | 526 | |
69be8f18 SR |
527 | spin_lock_irq(¤t->sighand->siglock); |
528 | sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask); | |
529 | if (!(ka->sa.sa_flags & SA_NODEFER)) | |
1da177e4 | 530 | sigaddset(¤t->blocked,sig); |
69be8f18 SR |
531 | recalc_sigpending(); |
532 | spin_unlock_irq(¤t->sighand->siglock); | |
129bc8f7 RB |
533 | |
534 | return ret; | |
1da177e4 LT |
535 | } |
536 | ||
40ac5d47 | 537 | void do_signal(struct pt_regs *regs) |
1da177e4 LT |
538 | { |
539 | struct k_sigaction ka; | |
7b3e2fc8 | 540 | sigset_t *oldset; |
1da177e4 LT |
541 | siginfo_t info; |
542 | int signr; | |
543 | ||
1da177e4 LT |
544 | /* |
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)) | |
40ac5d47 | 550 | return; |
1da177e4 | 551 | |
7b3e2fc8 RB |
552 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) |
553 | oldset = ¤t->saved_sigmask; | |
554 | else | |
1da177e4 LT |
555 | oldset = ¤t->blocked; |
556 | ||
557 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); | |
7b3e2fc8 RB |
558 | 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 | } | |
45887e12 RB |
570 | |
571 | return; | |
7b3e2fc8 | 572 | } |
1da177e4 | 573 | |
1da177e4 LT |
574 | /* |
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 | } | |
13fdd31a | 591 | regs->regs[0] = 0; /* Don't deal with this again. */ |
1da177e4 | 592 | } |
7b3e2fc8 RB |
593 | |
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, ¤t->saved_sigmask, NULL); | |
601 | } | |
1da177e4 LT |
602 | } |
603 | ||
604 | /* | |
605 | * notification of userspace execution resumption | |
7b3e2fc8 | 606 | * - triggered by the TIF_WORK_MASK flags |
1da177e4 | 607 | */ |
7b3e2fc8 | 608 | asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused, |
1da177e4 LT |
609 | __u32 thread_info_flags) |
610 | { | |
611 | /* deal with pending signal delivery */ | |
7b3e2fc8 RB |
612 | if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) |
613 | current->thread.abi->do_signal(regs); | |
1da177e4 | 614 | } |