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> | |
1da177e4 LT |
15 | #include <linux/kernel.h> |
16 | #include <linux/signal.h> | |
17 | #include <linux/errno.h> | |
18 | #include <linux/wait.h> | |
19 | #include <linux/ptrace.h> | |
20 | #include <linux/unistd.h> | |
21 | #include <linux/compiler.h> | |
dbda6ac0 | 22 | #include <linux/syscalls.h> |
faea6234 | 23 | #include <linux/uaccess.h> |
733e5e4b | 24 | #include <linux/tracehook.h> |
1da177e4 | 25 | |
e50c0a8f | 26 | #include <asm/abi.h> |
1da177e4 LT |
27 | #include <asm/asm.h> |
28 | #include <linux/bitops.h> | |
29 | #include <asm/cacheflush.h> | |
30 | #include <asm/fpu.h> | |
31 | #include <asm/sim.h> | |
1da177e4 LT |
32 | #include <asm/ucontext.h> |
33 | #include <asm/cpu-features.h> | |
02416dcf | 34 | #include <asm/war.h> |
d814c28c | 35 | #include <asm/vdso.h> |
1da177e4 LT |
36 | |
37 | #include "signal-common.h" | |
38 | ||
137f6f3e RB |
39 | static int (*save_fp_context)(struct sigcontext __user *sc); |
40 | static int (*restore_fp_context)(struct sigcontext __user *sc); | |
41 | ||
42 | extern asmlinkage int _save_fp_context(struct sigcontext __user *sc); | |
43 | extern asmlinkage int _restore_fp_context(struct sigcontext __user *sc); | |
44 | ||
45 | extern asmlinkage int fpu_emulator_save_context(struct sigcontext __user *sc); | |
46 | extern asmlinkage int fpu_emulator_restore_context(struct sigcontext __user *sc); | |
47 | ||
66680583 RB |
48 | struct sigframe { |
49 | u32 sf_ass[4]; /* argument save space for o32 */ | |
d814c28c | 50 | u32 sf_pad[2]; /* Was: signal trampoline */ |
66680583 RB |
51 | struct sigcontext sf_sc; |
52 | sigset_t sf_mask; | |
53 | }; | |
54 | ||
c0b9bae9 FBH |
55 | struct rt_sigframe { |
56 | u32 rs_ass[4]; /* argument save space for o32 */ | |
d814c28c | 57 | u32 rs_pad[2]; /* Was: signal trampoline */ |
c0b9bae9 FBH |
58 | struct siginfo rs_info; |
59 | struct ucontext rs_uc; | |
60 | }; | |
61 | ||
c3fc4ab3 FBH |
62 | /* |
63 | * Helper routines | |
64 | */ | |
faea6234 AN |
65 | static int protected_save_fp_context(struct sigcontext __user *sc) |
66 | { | |
67 | int err; | |
68 | while (1) { | |
69 | lock_fpu_owner(); | |
70 | own_fpu_inatomic(1); | |
71 | err = save_fp_context(sc); /* this might fail */ | |
72 | unlock_fpu_owner(); | |
73 | if (likely(!err)) | |
74 | break; | |
75 | /* touch the sigcontext and try again */ | |
76 | err = __put_user(0, &sc->sc_fpregs[0]) | | |
77 | __put_user(0, &sc->sc_fpregs[31]) | | |
78 | __put_user(0, &sc->sc_fpc_csr); | |
79 | if (err) | |
80 | break; /* really bad sigcontext */ | |
81 | } | |
82 | return err; | |
83 | } | |
84 | ||
85 | static int protected_restore_fp_context(struct sigcontext __user *sc) | |
86 | { | |
87 | int err, tmp; | |
88 | while (1) { | |
89 | lock_fpu_owner(); | |
90 | own_fpu_inatomic(0); | |
91 | err = restore_fp_context(sc); /* this might fail */ | |
92 | unlock_fpu_owner(); | |
93 | if (likely(!err)) | |
94 | break; | |
95 | /* touch the sigcontext and try again */ | |
96 | err = __get_user(tmp, &sc->sc_fpregs[0]) | | |
97 | __get_user(tmp, &sc->sc_fpregs[31]) | | |
98 | __get_user(tmp, &sc->sc_fpc_csr); | |
99 | if (err) | |
100 | break; /* really bad sigcontext */ | |
101 | } | |
102 | return err; | |
103 | } | |
104 | ||
c3fc4ab3 FBH |
105 | int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc) |
106 | { | |
107 | int err = 0; | |
108 | int i; | |
53dc8028 | 109 | unsigned int used_math; |
c3fc4ab3 FBH |
110 | |
111 | err |= __put_user(regs->cp0_epc, &sc->sc_pc); | |
112 | ||
113 | err |= __put_user(0, &sc->sc_regs[0]); | |
114 | for (i = 1; i < 32; i++) | |
115 | err |= __put_user(regs->regs[i], &sc->sc_regs[i]); | |
116 | ||
9693a853 FBH |
117 | #ifdef CONFIG_CPU_HAS_SMARTMIPS |
118 | err |= __put_user(regs->acx, &sc->sc_acx); | |
119 | #endif | |
c3fc4ab3 FBH |
120 | err |= __put_user(regs->hi, &sc->sc_mdhi); |
121 | err |= __put_user(regs->lo, &sc->sc_mdlo); | |
122 | if (cpu_has_dsp) { | |
123 | err |= __put_user(mfhi1(), &sc->sc_hi1); | |
124 | err |= __put_user(mflo1(), &sc->sc_lo1); | |
125 | err |= __put_user(mfhi2(), &sc->sc_hi2); | |
126 | err |= __put_user(mflo2(), &sc->sc_lo2); | |
127 | err |= __put_user(mfhi3(), &sc->sc_hi3); | |
128 | err |= __put_user(mflo3(), &sc->sc_lo3); | |
129 | err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp); | |
130 | } | |
131 | ||
53dc8028 AN |
132 | used_math = !!used_math(); |
133 | err |= __put_user(used_math, &sc->sc_used_math); | |
c3fc4ab3 | 134 | |
53dc8028 | 135 | if (used_math) { |
c3fc4ab3 FBH |
136 | /* |
137 | * Save FPU state to signal context. Signal handler | |
138 | * will "inherit" current FPU state. | |
139 | */ | |
faea6234 | 140 | err |= protected_save_fp_context(sc); |
c3fc4ab3 FBH |
141 | } |
142 | return err; | |
143 | } | |
144 | ||
c6a2f467 AN |
145 | int fpcsr_pending(unsigned int __user *fpcsr) |
146 | { | |
147 | int err, sig = 0; | |
148 | unsigned int csr, enabled; | |
149 | ||
150 | err = __get_user(csr, fpcsr); | |
151 | enabled = FPU_CSR_UNI_X | ((csr & FPU_CSR_ALL_E) << 5); | |
152 | /* | |
153 | * If the signal handler set some FPU exceptions, clear it and | |
154 | * send SIGFPE. | |
155 | */ | |
156 | if (csr & enabled) { | |
157 | csr &= ~enabled; | |
158 | err |= __put_user(csr, fpcsr); | |
159 | sig = SIGFPE; | |
160 | } | |
161 | return err ?: sig; | |
162 | } | |
163 | ||
164 | static int | |
165 | check_and_restore_fp_context(struct sigcontext __user *sc) | |
166 | { | |
167 | int err, sig; | |
168 | ||
169 | err = sig = fpcsr_pending(&sc->sc_fpc_csr); | |
170 | if (err > 0) | |
171 | err = 0; | |
faea6234 | 172 | err |= protected_restore_fp_context(sc); |
c6a2f467 AN |
173 | return err ?: sig; |
174 | } | |
175 | ||
c3fc4ab3 FBH |
176 | int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc) |
177 | { | |
178 | unsigned int used_math; | |
179 | unsigned long treg; | |
180 | int err = 0; | |
181 | int i; | |
182 | ||
183 | /* Always make any pending restarted system calls return -EINTR */ | |
184 | current_thread_info()->restart_block.fn = do_no_restart_syscall; | |
185 | ||
186 | err |= __get_user(regs->cp0_epc, &sc->sc_pc); | |
9693a853 FBH |
187 | |
188 | #ifdef CONFIG_CPU_HAS_SMARTMIPS | |
189 | err |= __get_user(regs->acx, &sc->sc_acx); | |
190 | #endif | |
c3fc4ab3 FBH |
191 | err |= __get_user(regs->hi, &sc->sc_mdhi); |
192 | err |= __get_user(regs->lo, &sc->sc_mdlo); | |
193 | if (cpu_has_dsp) { | |
194 | err |= __get_user(treg, &sc->sc_hi1); mthi1(treg); | |
195 | err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg); | |
196 | err |= __get_user(treg, &sc->sc_hi2); mthi2(treg); | |
197 | err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg); | |
198 | err |= __get_user(treg, &sc->sc_hi3); mthi3(treg); | |
199 | err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg); | |
200 | err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK); | |
201 | } | |
202 | ||
203 | for (i = 1; i < 32; i++) | |
204 | err |= __get_user(regs->regs[i], &sc->sc_regs[i]); | |
205 | ||
206 | err |= __get_user(used_math, &sc->sc_used_math); | |
207 | conditional_used_math(used_math); | |
208 | ||
53dc8028 | 209 | if (used_math) { |
c3fc4ab3 | 210 | /* restore fpu context if we have used it before */ |
c6a2f467 AN |
211 | if (!err) |
212 | err = check_and_restore_fp_context(sc); | |
c3fc4ab3 FBH |
213 | } else { |
214 | /* signal handler may have used FPU. Give it up. */ | |
53dc8028 | 215 | lose_fpu(0); |
c3fc4ab3 FBH |
216 | } |
217 | ||
c3fc4ab3 FBH |
218 | return err; |
219 | } | |
220 | ||
221 | void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, | |
222 | size_t frame_size) | |
223 | { | |
224 | unsigned long sp; | |
225 | ||
226 | /* Default to using normal stack */ | |
227 | sp = regs->regs[29]; | |
228 | ||
229 | /* | |
230 | * FPU emulator may have it's own trampoline active just | |
231 | * above the user stack, 16-bytes before the next lowest | |
232 | * 16 byte boundary. Try to avoid trashing it. | |
233 | */ | |
234 | sp -= 32; | |
235 | ||
236 | /* This is the X/Open sanctioned signal stack switching. */ | |
237 | if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0)) | |
238 | sp = current->sas_ss_sp + current->sas_ss_size; | |
239 | ||
240 | return (void __user *)((sp - frame_size) & (ICACHE_REFILLS_WORKAROUND_WAR ? ~(cpu_icache_line_size()-1) : ALMASK)); | |
241 | } | |
242 | ||
1da177e4 LT |
243 | /* |
244 | * Atomically swap in the new signal mask, and wait for a signal. | |
245 | */ | |
246 | ||
247 | #ifdef CONFIG_TRAD_SIGNALS | |
f90080a0 | 248 | asmlinkage int sys_sigsuspend(nabi_no_regargs struct pt_regs regs) |
1da177e4 | 249 | { |
7b3e2fc8 | 250 | sigset_t newset; |
fe00f943 | 251 | sigset_t __user *uset; |
1da177e4 | 252 | |
fe00f943 | 253 | uset = (sigset_t __user *) regs.regs[4]; |
1da177e4 LT |
254 | if (copy_from_user(&newset, uset, sizeof(sigset_t))) |
255 | return -EFAULT; | |
256 | sigdelsetmask(&newset, ~_BLOCKABLE); | |
257 | ||
258 | spin_lock_irq(¤t->sighand->siglock); | |
7b3e2fc8 | 259 | current->saved_sigmask = current->blocked; |
1da177e4 LT |
260 | current->blocked = newset; |
261 | recalc_sigpending(); | |
262 | spin_unlock_irq(¤t->sighand->siglock); | |
263 | ||
7b3e2fc8 RB |
264 | current->state = TASK_INTERRUPTIBLE; |
265 | schedule(); | |
266 | set_thread_flag(TIF_RESTORE_SIGMASK); | |
267 | return -ERESTARTNOHAND; | |
1da177e4 LT |
268 | } |
269 | #endif | |
270 | ||
f90080a0 | 271 | asmlinkage int sys_rt_sigsuspend(nabi_no_regargs struct pt_regs regs) |
1da177e4 | 272 | { |
7b3e2fc8 | 273 | sigset_t newset; |
fe00f943 | 274 | sigset_t __user *unewset; |
1da177e4 LT |
275 | size_t sigsetsize; |
276 | ||
277 | /* XXX Don't preclude handling different sized sigset_t's. */ | |
278 | sigsetsize = regs.regs[5]; | |
279 | if (sigsetsize != sizeof(sigset_t)) | |
280 | return -EINVAL; | |
281 | ||
fe00f943 | 282 | unewset = (sigset_t __user *) regs.regs[4]; |
1da177e4 LT |
283 | if (copy_from_user(&newset, unewset, sizeof(newset))) |
284 | return -EFAULT; | |
285 | sigdelsetmask(&newset, ~_BLOCKABLE); | |
286 | ||
287 | spin_lock_irq(¤t->sighand->siglock); | |
7b3e2fc8 | 288 | current->saved_sigmask = current->blocked; |
1da177e4 | 289 | current->blocked = newset; |
e0daad44 | 290 | recalc_sigpending(); |
1da177e4 LT |
291 | spin_unlock_irq(¤t->sighand->siglock); |
292 | ||
7b3e2fc8 RB |
293 | current->state = TASK_INTERRUPTIBLE; |
294 | schedule(); | |
295 | set_thread_flag(TIF_RESTORE_SIGMASK); | |
296 | return -ERESTARTNOHAND; | |
1da177e4 LT |
297 | } |
298 | ||
299 | #ifdef CONFIG_TRAD_SIGNALS | |
dbda6ac0 RB |
300 | SYSCALL_DEFINE3(sigaction, int, sig, const struct sigaction __user *, act, |
301 | struct sigaction __user *, oact) | |
1da177e4 LT |
302 | { |
303 | struct k_sigaction new_ka, old_ka; | |
304 | int ret; | |
305 | int err = 0; | |
306 | ||
307 | if (act) { | |
308 | old_sigset_t mask; | |
309 | ||
310 | if (!access_ok(VERIFY_READ, act, sizeof(*act))) | |
311 | return -EFAULT; | |
312 | err |= __get_user(new_ka.sa.sa_handler, &act->sa_handler); | |
313 | err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags); | |
314 | err |= __get_user(mask, &act->sa_mask.sig[0]); | |
315 | if (err) | |
316 | return -EFAULT; | |
317 | ||
318 | siginitset(&new_ka.sa.sa_mask, mask); | |
319 | } | |
320 | ||
321 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); | |
322 | ||
323 | if (!ret && oact) { | |
324 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact))) | |
e0daad44 | 325 | return -EFAULT; |
1da177e4 LT |
326 | err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags); |
327 | err |= __put_user(old_ka.sa.sa_handler, &oact->sa_handler); | |
328 | err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig); | |
329 | err |= __put_user(0, &oact->sa_mask.sig[1]); | |
330 | err |= __put_user(0, &oact->sa_mask.sig[2]); | |
331 | err |= __put_user(0, &oact->sa_mask.sig[3]); | |
332 | if (err) | |
333 | return -EFAULT; | |
334 | } | |
335 | ||
336 | return ret; | |
337 | } | |
338 | #endif | |
339 | ||
340 | asmlinkage int sys_sigaltstack(nabi_no_regargs struct pt_regs regs) | |
341 | { | |
fe00f943 RB |
342 | const stack_t __user *uss = (const stack_t __user *) regs.regs[4]; |
343 | stack_t __user *uoss = (stack_t __user *) regs.regs[5]; | |
1da177e4 LT |
344 | unsigned long usp = regs.regs[29]; |
345 | ||
346 | return do_sigaltstack(uss, uoss, usp); | |
347 | } | |
348 | ||
1da177e4 | 349 | #ifdef CONFIG_TRAD_SIGNALS |
f90080a0 | 350 | asmlinkage void sys_sigreturn(nabi_no_regargs struct pt_regs regs) |
1da177e4 | 351 | { |
9bbf28a3 | 352 | struct sigframe __user *frame; |
1da177e4 | 353 | sigset_t blocked; |
c6a2f467 | 354 | int sig; |
1da177e4 | 355 | |
9bbf28a3 | 356 | frame = (struct sigframe __user *) regs.regs[29]; |
1da177e4 LT |
357 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
358 | goto badframe; | |
359 | if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked))) | |
360 | goto badframe; | |
361 | ||
362 | sigdelsetmask(&blocked, ~_BLOCKABLE); | |
363 | spin_lock_irq(¤t->sighand->siglock); | |
364 | current->blocked = blocked; | |
365 | recalc_sigpending(); | |
366 | spin_unlock_irq(¤t->sighand->siglock); | |
367 | ||
c6a2f467 AN |
368 | sig = restore_sigcontext(®s, &frame->sf_sc); |
369 | if (sig < 0) | |
1da177e4 | 370 | goto badframe; |
c6a2f467 AN |
371 | else if (sig) |
372 | force_sig(sig, current); | |
1da177e4 LT |
373 | |
374 | /* | |
375 | * Don't let your children do this ... | |
376 | */ | |
1da177e4 LT |
377 | __asm__ __volatile__( |
378 | "move\t$29, %0\n\t" | |
379 | "j\tsyscall_exit" | |
380 | :/* no outputs */ | |
381 | :"r" (®s)); | |
382 | /* Unreached */ | |
383 | ||
384 | badframe: | |
385 | force_sig(SIGSEGV, current); | |
386 | } | |
e50c0a8f | 387 | #endif /* CONFIG_TRAD_SIGNALS */ |
1da177e4 | 388 | |
f90080a0 | 389 | asmlinkage void sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs) |
1da177e4 | 390 | { |
9bbf28a3 | 391 | struct rt_sigframe __user *frame; |
1da177e4 LT |
392 | sigset_t set; |
393 | stack_t st; | |
c6a2f467 | 394 | int sig; |
1da177e4 | 395 | |
9bbf28a3 | 396 | frame = (struct rt_sigframe __user *) regs.regs[29]; |
1da177e4 LT |
397 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
398 | goto badframe; | |
399 | if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set))) | |
400 | goto badframe; | |
401 | ||
402 | sigdelsetmask(&set, ~_BLOCKABLE); | |
403 | spin_lock_irq(¤t->sighand->siglock); | |
404 | current->blocked = set; | |
405 | recalc_sigpending(); | |
406 | spin_unlock_irq(¤t->sighand->siglock); | |
407 | ||
c6a2f467 AN |
408 | sig = restore_sigcontext(®s, &frame->rs_uc.uc_mcontext); |
409 | if (sig < 0) | |
1da177e4 | 410 | goto badframe; |
c6a2f467 AN |
411 | else if (sig) |
412 | force_sig(sig, current); | |
1da177e4 LT |
413 | |
414 | if (__copy_from_user(&st, &frame->rs_uc.uc_stack, sizeof(st))) | |
415 | goto badframe; | |
416 | /* It is more difficult to avoid calling this function than to | |
417 | call it and ignore errors. */ | |
9bbf28a3 | 418 | do_sigaltstack((stack_t __user *)&st, NULL, regs.regs[29]); |
1da177e4 LT |
419 | |
420 | /* | |
421 | * Don't let your children do this ... | |
422 | */ | |
423 | __asm__ __volatile__( | |
424 | "move\t$29, %0\n\t" | |
425 | "j\tsyscall_exit" | |
426 | :/* no outputs */ | |
427 | :"r" (®s)); | |
428 | /* Unreached */ | |
429 | ||
430 | badframe: | |
431 | force_sig(SIGSEGV, current); | |
432 | } | |
433 | ||
434 | #ifdef CONFIG_TRAD_SIGNALS | |
d814c28c DD |
435 | static int setup_frame(void *sig_return, struct k_sigaction *ka, |
436 | struct pt_regs *regs, int signr, sigset_t *set) | |
1da177e4 | 437 | { |
9bbf28a3 | 438 | struct sigframe __user *frame; |
1da177e4 LT |
439 | int err = 0; |
440 | ||
441 | frame = get_sigframe(ka, regs, sizeof(*frame)); | |
442 | if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame))) | |
443 | goto give_sigsegv; | |
444 | ||
1da177e4 LT |
445 | err |= setup_sigcontext(regs, &frame->sf_sc); |
446 | err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set)); | |
447 | if (err) | |
448 | goto give_sigsegv; | |
449 | ||
450 | /* | |
451 | * Arguments to signal handler: | |
452 | * | |
453 | * a0 = signal number | |
454 | * a1 = 0 (should be cause) | |
455 | * a2 = pointer to struct sigcontext | |
456 | * | |
457 | * $25 and c0_epc point to the signal handler, $29 points to the | |
458 | * struct sigframe. | |
459 | */ | |
460 | regs->regs[ 4] = signr; | |
461 | regs->regs[ 5] = 0; | |
462 | regs->regs[ 6] = (unsigned long) &frame->sf_sc; | |
463 | regs->regs[29] = (unsigned long) frame; | |
d814c28c | 464 | regs->regs[31] = (unsigned long) sig_return; |
1da177e4 LT |
465 | regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler; |
466 | ||
722bb63d | 467 | DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n", |
1da177e4 | 468 | current->comm, current->pid, |
722bb63d | 469 | frame, regs->cp0_epc, regs->regs[31]); |
e0daad44 | 470 | return 0; |
1da177e4 LT |
471 | |
472 | give_sigsegv: | |
473 | force_sigsegv(signr, current); | |
7b3e2fc8 | 474 | return -EFAULT; |
1da177e4 LT |
475 | } |
476 | #endif | |
477 | ||
d814c28c DD |
478 | static int setup_rt_frame(void *sig_return, struct k_sigaction *ka, |
479 | struct pt_regs *regs, int signr, sigset_t *set, | |
480 | siginfo_t *info) | |
1da177e4 | 481 | { |
9bbf28a3 | 482 | struct rt_sigframe __user *frame; |
1da177e4 LT |
483 | int err = 0; |
484 | ||
485 | frame = get_sigframe(ka, regs, sizeof(*frame)); | |
486 | if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame))) | |
487 | goto give_sigsegv; | |
488 | ||
1da177e4 LT |
489 | /* Create siginfo. */ |
490 | err |= copy_siginfo_to_user(&frame->rs_info, info); | |
491 | ||
492 | /* Create the ucontext. */ | |
493 | err |= __put_user(0, &frame->rs_uc.uc_flags); | |
5665a0ac | 494 | err |= __put_user(NULL, &frame->rs_uc.uc_link); |
9c6031cc | 495 | err |= __put_user((void __user *)current->sas_ss_sp, |
1da177e4 LT |
496 | &frame->rs_uc.uc_stack.ss_sp); |
497 | err |= __put_user(sas_ss_flags(regs->regs[29]), | |
498 | &frame->rs_uc.uc_stack.ss_flags); | |
499 | err |= __put_user(current->sas_ss_size, | |
500 | &frame->rs_uc.uc_stack.ss_size); | |
501 | err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext); | |
502 | err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set)); | |
503 | ||
504 | if (err) | |
505 | goto give_sigsegv; | |
506 | ||
507 | /* | |
508 | * Arguments to signal handler: | |
509 | * | |
510 | * a0 = signal number | |
511 | * a1 = 0 (should be cause) | |
512 | * a2 = pointer to ucontext | |
513 | * | |
514 | * $25 and c0_epc point to the signal handler, $29 points to | |
515 | * the struct rt_sigframe. | |
516 | */ | |
517 | regs->regs[ 4] = signr; | |
518 | regs->regs[ 5] = (unsigned long) &frame->rs_info; | |
519 | regs->regs[ 6] = (unsigned long) &frame->rs_uc; | |
520 | regs->regs[29] = (unsigned long) frame; | |
d814c28c | 521 | regs->regs[31] = (unsigned long) sig_return; |
1da177e4 LT |
522 | regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler; |
523 | ||
722bb63d | 524 | DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n", |
1da177e4 LT |
525 | current->comm, current->pid, |
526 | frame, regs->cp0_epc, regs->regs[31]); | |
722bb63d | 527 | |
7b3e2fc8 | 528 | return 0; |
1da177e4 LT |
529 | |
530 | give_sigsegv: | |
531 | force_sigsegv(signr, current); | |
7b3e2fc8 | 532 | return -EFAULT; |
1da177e4 LT |
533 | } |
534 | ||
151fd6ac RB |
535 | struct mips_abi mips_abi = { |
536 | #ifdef CONFIG_TRAD_SIGNALS | |
537 | .setup_frame = setup_frame, | |
d814c28c | 538 | .signal_return_offset = offsetof(struct mips_vdso, signal_trampoline), |
151fd6ac RB |
539 | #endif |
540 | .setup_rt_frame = setup_rt_frame, | |
d814c28c DD |
541 | .rt_signal_return_offset = |
542 | offsetof(struct mips_vdso, rt_signal_trampoline), | |
151fd6ac RB |
543 | .restart = __NR_restart_syscall |
544 | }; | |
545 | ||
e692eb30 | 546 | static int handle_signal(unsigned long sig, siginfo_t *info, |
1da177e4 LT |
547 | struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs) |
548 | { | |
129bc8f7 | 549 | int ret; |
d814c28c DD |
550 | struct mips_abi *abi = current->thread.abi; |
551 | void *vdso = current->mm->context.vdso; | |
129bc8f7 | 552 | |
1da177e4 LT |
553 | switch(regs->regs[0]) { |
554 | case ERESTART_RESTARTBLOCK: | |
555 | case ERESTARTNOHAND: | |
556 | regs->regs[2] = EINTR; | |
557 | break; | |
558 | case ERESTARTSYS: | |
7b3e2fc8 | 559 | if (!(ka->sa.sa_flags & SA_RESTART)) { |
1da177e4 LT |
560 | regs->regs[2] = EINTR; |
561 | break; | |
562 | } | |
563 | /* fallthrough */ | |
564 | case ERESTARTNOINTR: /* Userland will reload $v0. */ | |
565 | regs->regs[7] = regs->regs[26]; | |
566 | regs->cp0_epc -= 8; | |
567 | } | |
568 | ||
569 | regs->regs[0] = 0; /* Don't deal with this again. */ | |
570 | ||
e50c0a8f | 571 | if (sig_uses_siginfo(ka)) |
d814c28c DD |
572 | ret = abi->setup_rt_frame(vdso + abi->rt_signal_return_offset, |
573 | ka, regs, sig, oldset, info); | |
1da177e4 | 574 | else |
d814c28c DD |
575 | ret = abi->setup_frame(vdso + abi->signal_return_offset, |
576 | ka, regs, sig, oldset); | |
1da177e4 | 577 | |
69be8f18 | 578 | spin_lock_irq(¤t->sighand->siglock); |
21a151d8 | 579 | sigorsets(¤t->blocked, ¤t->blocked, &ka->sa.sa_mask); |
69be8f18 | 580 | if (!(ka->sa.sa_flags & SA_NODEFER)) |
21a151d8 | 581 | sigaddset(¤t->blocked, sig); |
69be8f18 SR |
582 | recalc_sigpending(); |
583 | spin_unlock_irq(¤t->sighand->siglock); | |
129bc8f7 RB |
584 | |
585 | return ret; | |
1da177e4 LT |
586 | } |
587 | ||
151fd6ac | 588 | static void do_signal(struct pt_regs *regs) |
1da177e4 LT |
589 | { |
590 | struct k_sigaction ka; | |
7b3e2fc8 | 591 | sigset_t *oldset; |
1da177e4 LT |
592 | siginfo_t info; |
593 | int signr; | |
594 | ||
1da177e4 LT |
595 | /* |
596 | * We want the common case to go fast, which is why we may in certain | |
597 | * cases get here from kernel mode. Just return without doing anything | |
598 | * if so. | |
599 | */ | |
600 | if (!user_mode(regs)) | |
40ac5d47 | 601 | return; |
1da177e4 | 602 | |
7b3e2fc8 RB |
603 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) |
604 | oldset = ¤t->saved_sigmask; | |
605 | else | |
1da177e4 LT |
606 | oldset = ¤t->blocked; |
607 | ||
608 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); | |
7b3e2fc8 RB |
609 | if (signr > 0) { |
610 | /* Whee! Actually deliver the signal. */ | |
611 | if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { | |
612 | /* | |
613 | * A signal was successfully delivered; the saved | |
614 | * sigmask will have been stored in the signal frame, | |
615 | * and will be restored by sigreturn, so we can simply | |
616 | * clear the TIF_RESTORE_SIGMASK flag. | |
617 | */ | |
618 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) | |
619 | clear_thread_flag(TIF_RESTORE_SIGMASK); | |
620 | } | |
45887e12 RB |
621 | |
622 | return; | |
7b3e2fc8 | 623 | } |
1da177e4 | 624 | |
1da177e4 LT |
625 | /* |
626 | * Who's code doesn't conform to the restartable syscall convention | |
627 | * dies here!!! The li instruction, a single machine instruction, | |
628 | * must directly be followed by the syscall instruction. | |
629 | */ | |
630 | if (regs->regs[0]) { | |
631 | if (regs->regs[2] == ERESTARTNOHAND || | |
632 | regs->regs[2] == ERESTARTSYS || | |
633 | regs->regs[2] == ERESTARTNOINTR) { | |
634 | regs->regs[7] = regs->regs[26]; | |
635 | regs->cp0_epc -= 8; | |
636 | } | |
637 | if (regs->regs[2] == ERESTART_RESTARTBLOCK) { | |
151fd6ac | 638 | regs->regs[2] = current->thread.abi->restart; |
1da177e4 LT |
639 | regs->regs[7] = regs->regs[26]; |
640 | regs->cp0_epc -= 4; | |
641 | } | |
13fdd31a | 642 | regs->regs[0] = 0; /* Don't deal with this again. */ |
1da177e4 | 643 | } |
7b3e2fc8 RB |
644 | |
645 | /* | |
646 | * If there's no signal to deliver, we just put the saved sigmask | |
647 | * back | |
648 | */ | |
649 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) { | |
650 | clear_thread_flag(TIF_RESTORE_SIGMASK); | |
651 | sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); | |
652 | } | |
1da177e4 LT |
653 | } |
654 | ||
655 | /* | |
656 | * notification of userspace execution resumption | |
7b3e2fc8 | 657 | * - triggered by the TIF_WORK_MASK flags |
1da177e4 | 658 | */ |
7b3e2fc8 | 659 | asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused, |
1da177e4 LT |
660 | __u32 thread_info_flags) |
661 | { | |
662 | /* deal with pending signal delivery */ | |
7b3e2fc8 | 663 | if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) |
151fd6ac | 664 | do_signal(regs); |
d0420c83 DH |
665 | |
666 | if (thread_info_flags & _TIF_NOTIFY_RESUME) { | |
667 | clear_thread_flag(TIF_NOTIFY_RESUME); | |
668 | tracehook_notify_resume(regs); | |
ee18d64c DH |
669 | if (current->replacement_session_keyring) |
670 | key_replace_session_keyring(); | |
d0420c83 | 671 | } |
1da177e4 | 672 | } |
137f6f3e RB |
673 | |
674 | #ifdef CONFIG_SMP | |
675 | static int smp_save_fp_context(struct sigcontext __user *sc) | |
676 | { | |
677 | return raw_cpu_has_fpu | |
678 | ? _save_fp_context(sc) | |
679 | : fpu_emulator_save_context(sc); | |
680 | } | |
681 | ||
682 | static int smp_restore_fp_context(struct sigcontext __user *sc) | |
683 | { | |
684 | return raw_cpu_has_fpu | |
685 | ? _restore_fp_context(sc) | |
686 | : fpu_emulator_restore_context(sc); | |
687 | } | |
688 | #endif | |
689 | ||
690 | static int signal_setup(void) | |
691 | { | |
692 | #ifdef CONFIG_SMP | |
693 | /* For now just do the cpu_has_fpu check when the functions are invoked */ | |
694 | save_fp_context = smp_save_fp_context; | |
695 | restore_fp_context = smp_restore_fp_context; | |
696 | #else | |
697 | if (cpu_has_fpu) { | |
698 | save_fp_context = _save_fp_context; | |
699 | restore_fp_context = _restore_fp_context; | |
700 | } else { | |
701 | save_fp_context = fpu_emulator_save_context; | |
702 | restore_fp_context = fpu_emulator_restore_context; | |
703 | } | |
704 | #endif | |
705 | ||
706 | return 0; | |
707 | } | |
708 | ||
709 | arch_initcall(signal_setup); |