Add linux-next specific files for 20110831
[linux-2.6/next.git] / arch / mips / kernel / signal32.c
blob902a889c0c9fea9033d727b91fa9fc4be07b7712
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.
6 * Copyright (C) 1991, 1992 Linus Torvalds
7 * Copyright (C) 1994 - 2000, 2006 Ralf Baechle
8 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
9 */
10 #include <linux/cache.h>
11 #include <linux/compat.h>
12 #include <linux/sched.h>
13 #include <linux/mm.h>
14 #include <linux/smp.h>
15 #include <linux/kernel.h>
16 #include <linux/signal.h>
17 #include <linux/syscalls.h>
18 #include <linux/errno.h>
19 #include <linux/wait.h>
20 #include <linux/ptrace.h>
21 #include <linux/suspend.h>
22 #include <linux/compiler.h>
23 #include <linux/uaccess.h>
25 #include <asm/abi.h>
26 #include <asm/asm.h>
27 #include <asm/compat-signal.h>
28 #include <linux/bitops.h>
29 #include <asm/cacheflush.h>
30 #include <asm/sim.h>
31 #include <asm/ucontext.h>
32 #include <asm/system.h>
33 #include <asm/fpu.h>
34 #include <asm/war.h>
35 #include <asm/vdso.h>
37 #include "signal-common.h"
39 static int (*save_fp_context32)(struct sigcontext32 __user *sc);
40 static int (*restore_fp_context32)(struct sigcontext32 __user *sc);
42 extern asmlinkage int _save_fp_context32(struct sigcontext32 __user *sc);
43 extern asmlinkage int _restore_fp_context32(struct sigcontext32 __user *sc);
45 extern asmlinkage int fpu_emulator_save_context32(struct sigcontext32 __user *sc);
46 extern asmlinkage int fpu_emulator_restore_context32(struct sigcontext32 __user *sc);
49 * Including <asm/unistd.h> would give use the 64-bit syscall numbers ...
51 #define __NR_O32_restart_syscall 4253
53 /* 32-bit compatibility types */
55 typedef unsigned int __sighandler32_t;
56 typedef void (*vfptr_t)(void);
58 struct sigaction32 {
59 unsigned int sa_flags;
60 __sighandler32_t sa_handler;
61 compat_sigset_t sa_mask;
64 /* IRIX compatible stack_t */
65 typedef struct sigaltstack32 {
66 s32 ss_sp;
67 compat_size_t ss_size;
68 int ss_flags;
69 } stack32_t;
71 struct ucontext32 {
72 u32 uc_flags;
73 s32 uc_link;
74 stack32_t uc_stack;
75 struct sigcontext32 uc_mcontext;
76 compat_sigset_t uc_sigmask; /* mask last for extensibility */
79 struct sigframe32 {
80 u32 sf_ass[4]; /* argument save space for o32 */
81 u32 sf_pad[2]; /* Was: signal trampoline */
82 struct sigcontext32 sf_sc;
83 compat_sigset_t sf_mask;
86 struct rt_sigframe32 {
87 u32 rs_ass[4]; /* argument save space for o32 */
88 u32 rs_pad[2]; /* Was: signal trampoline */
89 compat_siginfo_t rs_info;
90 struct ucontext32 rs_uc;
94 * sigcontext handlers
96 static int protected_save_fp_context32(struct sigcontext32 __user *sc)
98 int err;
99 while (1) {
100 lock_fpu_owner();
101 own_fpu_inatomic(1);
102 err = save_fp_context32(sc); /* this might fail */
103 unlock_fpu_owner();
104 if (likely(!err))
105 break;
106 /* touch the sigcontext and try again */
107 err = __put_user(0, &sc->sc_fpregs[0]) |
108 __put_user(0, &sc->sc_fpregs[31]) |
109 __put_user(0, &sc->sc_fpc_csr);
110 if (err)
111 break; /* really bad sigcontext */
113 return err;
116 static int protected_restore_fp_context32(struct sigcontext32 __user *sc)
118 int err, tmp __maybe_unused;
119 while (1) {
120 lock_fpu_owner();
121 own_fpu_inatomic(0);
122 err = restore_fp_context32(sc); /* this might fail */
123 unlock_fpu_owner();
124 if (likely(!err))
125 break;
126 /* touch the sigcontext and try again */
127 err = __get_user(tmp, &sc->sc_fpregs[0]) |
128 __get_user(tmp, &sc->sc_fpregs[31]) |
129 __get_user(tmp, &sc->sc_fpc_csr);
130 if (err)
131 break; /* really bad sigcontext */
133 return err;
136 static int setup_sigcontext32(struct pt_regs *regs,
137 struct sigcontext32 __user *sc)
139 int err = 0;
140 int i;
141 u32 used_math;
143 err |= __put_user(regs->cp0_epc, &sc->sc_pc);
145 err |= __put_user(0, &sc->sc_regs[0]);
146 for (i = 1; i < 32; i++)
147 err |= __put_user(regs->regs[i], &sc->sc_regs[i]);
149 err |= __put_user(regs->hi, &sc->sc_mdhi);
150 err |= __put_user(regs->lo, &sc->sc_mdlo);
151 if (cpu_has_dsp) {
152 err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
153 err |= __put_user(mfhi1(), &sc->sc_hi1);
154 err |= __put_user(mflo1(), &sc->sc_lo1);
155 err |= __put_user(mfhi2(), &sc->sc_hi2);
156 err |= __put_user(mflo2(), &sc->sc_lo2);
157 err |= __put_user(mfhi3(), &sc->sc_hi3);
158 err |= __put_user(mflo3(), &sc->sc_lo3);
161 used_math = !!used_math();
162 err |= __put_user(used_math, &sc->sc_used_math);
164 if (used_math) {
166 * Save FPU state to signal context. Signal handler
167 * will "inherit" current FPU state.
169 err |= protected_save_fp_context32(sc);
171 return err;
174 static int
175 check_and_restore_fp_context32(struct sigcontext32 __user *sc)
177 int err, sig;
179 err = sig = fpcsr_pending(&sc->sc_fpc_csr);
180 if (err > 0)
181 err = 0;
182 err |= protected_restore_fp_context32(sc);
183 return err ?: sig;
186 static int restore_sigcontext32(struct pt_regs *regs,
187 struct sigcontext32 __user *sc)
189 u32 used_math;
190 int err = 0;
191 s32 treg;
192 int i;
194 /* Always make any pending restarted system calls return -EINTR */
195 current_thread_info()->restart_block.fn = do_no_restart_syscall;
197 err |= __get_user(regs->cp0_epc, &sc->sc_pc);
198 err |= __get_user(regs->hi, &sc->sc_mdhi);
199 err |= __get_user(regs->lo, &sc->sc_mdlo);
200 if (cpu_has_dsp) {
201 err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
202 err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
203 err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
204 err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
205 err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
206 err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
207 err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
210 for (i = 1; i < 32; i++)
211 err |= __get_user(regs->regs[i], &sc->sc_regs[i]);
213 err |= __get_user(used_math, &sc->sc_used_math);
214 conditional_used_math(used_math);
216 if (used_math) {
217 /* restore fpu context if we have used it before */
218 if (!err)
219 err = check_and_restore_fp_context32(sc);
220 } else {
221 /* signal handler may have used FPU. Give it up. */
222 lose_fpu(0);
225 return err;
231 extern void __put_sigset_unknown_nsig(void);
232 extern void __get_sigset_unknown_nsig(void);
234 static inline int put_sigset(const sigset_t *kbuf, compat_sigset_t __user *ubuf)
236 int err = 0;
238 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)))
239 return -EFAULT;
241 switch (_NSIG_WORDS) {
242 default:
243 __put_sigset_unknown_nsig();
244 case 2:
245 err |= __put_user(kbuf->sig[1] >> 32, &ubuf->sig[3]);
246 err |= __put_user(kbuf->sig[1] & 0xffffffff, &ubuf->sig[2]);
247 case 1:
248 err |= __put_user(kbuf->sig[0] >> 32, &ubuf->sig[1]);
249 err |= __put_user(kbuf->sig[0] & 0xffffffff, &ubuf->sig[0]);
252 return err;
255 static inline int get_sigset(sigset_t *kbuf, const compat_sigset_t __user *ubuf)
257 int err = 0;
258 unsigned long sig[4];
260 if (!access_ok(VERIFY_READ, ubuf, sizeof(*ubuf)))
261 return -EFAULT;
263 switch (_NSIG_WORDS) {
264 default:
265 __get_sigset_unknown_nsig();
266 case 2:
267 err |= __get_user(sig[3], &ubuf->sig[3]);
268 err |= __get_user(sig[2], &ubuf->sig[2]);
269 kbuf->sig[1] = sig[2] | (sig[3] << 32);
270 case 1:
271 err |= __get_user(sig[1], &ubuf->sig[1]);
272 err |= __get_user(sig[0], &ubuf->sig[0]);
273 kbuf->sig[0] = sig[0] | (sig[1] << 32);
276 return err;
280 * Atomically swap in the new signal mask, and wait for a signal.
283 asmlinkage int sys32_sigsuspend(nabi_no_regargs struct pt_regs regs)
285 compat_sigset_t __user *uset;
286 sigset_t newset;
288 uset = (compat_sigset_t __user *) regs.regs[4];
289 if (get_sigset(&newset, uset))
290 return -EFAULT;
291 sigdelsetmask(&newset, ~_BLOCKABLE);
293 current->saved_sigmask = current->blocked;
294 set_current_blocked(&newset);
296 current->state = TASK_INTERRUPTIBLE;
297 schedule();
298 set_thread_flag(TIF_RESTORE_SIGMASK);
299 return -ERESTARTNOHAND;
302 asmlinkage int sys32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
304 compat_sigset_t __user *uset;
305 sigset_t newset;
306 size_t sigsetsize;
308 /* XXX Don't preclude handling different sized sigset_t's. */
309 sigsetsize = regs.regs[5];
310 if (sigsetsize != sizeof(compat_sigset_t))
311 return -EINVAL;
313 uset = (compat_sigset_t __user *) regs.regs[4];
314 if (get_sigset(&newset, uset))
315 return -EFAULT;
316 sigdelsetmask(&newset, ~_BLOCKABLE);
318 current->saved_sigmask = current->blocked;
319 set_current_blocked(&newset);
321 current->state = TASK_INTERRUPTIBLE;
322 schedule();
323 set_thread_flag(TIF_RESTORE_SIGMASK);
324 return -ERESTARTNOHAND;
327 SYSCALL_DEFINE3(32_sigaction, long, sig, const struct sigaction32 __user *, act,
328 struct sigaction32 __user *, oact)
330 struct k_sigaction new_ka, old_ka;
331 int ret;
332 int err = 0;
334 if (act) {
335 old_sigset_t mask;
336 s32 handler;
338 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
339 return -EFAULT;
340 err |= __get_user(handler, &act->sa_handler);
341 new_ka.sa.sa_handler = (void __user *)(s64)handler;
342 err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
343 err |= __get_user(mask, &act->sa_mask.sig[0]);
344 if (err)
345 return -EFAULT;
347 siginitset(&new_ka.sa.sa_mask, mask);
350 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
352 if (!ret && oact) {
353 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
354 return -EFAULT;
355 err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
356 err |= __put_user((u32)(u64)old_ka.sa.sa_handler,
357 &oact->sa_handler);
358 err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
359 err |= __put_user(0, &oact->sa_mask.sig[1]);
360 err |= __put_user(0, &oact->sa_mask.sig[2]);
361 err |= __put_user(0, &oact->sa_mask.sig[3]);
362 if (err)
363 return -EFAULT;
366 return ret;
369 asmlinkage int sys32_sigaltstack(nabi_no_regargs struct pt_regs regs)
371 const stack32_t __user *uss = (const stack32_t __user *) regs.regs[4];
372 stack32_t __user *uoss = (stack32_t __user *) regs.regs[5];
373 unsigned long usp = regs.regs[29];
374 stack_t kss, koss;
375 int ret, err = 0;
376 mm_segment_t old_fs = get_fs();
377 s32 sp;
379 if (uss) {
380 if (!access_ok(VERIFY_READ, uss, sizeof(*uss)))
381 return -EFAULT;
382 err |= __get_user(sp, &uss->ss_sp);
383 kss.ss_sp = (void __user *) (long) sp;
384 err |= __get_user(kss.ss_size, &uss->ss_size);
385 err |= __get_user(kss.ss_flags, &uss->ss_flags);
386 if (err)
387 return -EFAULT;
390 set_fs(KERNEL_DS);
391 ret = do_sigaltstack(uss ? (stack_t __user *)&kss : NULL,
392 uoss ? (stack_t __user *)&koss : NULL, usp);
393 set_fs(old_fs);
395 if (!ret && uoss) {
396 if (!access_ok(VERIFY_WRITE, uoss, sizeof(*uoss)))
397 return -EFAULT;
398 sp = (int) (unsigned long) koss.ss_sp;
399 err |= __put_user(sp, &uoss->ss_sp);
400 err |= __put_user(koss.ss_size, &uoss->ss_size);
401 err |= __put_user(koss.ss_flags, &uoss->ss_flags);
402 if (err)
403 return -EFAULT;
405 return ret;
408 int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
410 int err;
412 if (!access_ok (VERIFY_WRITE, to, sizeof(compat_siginfo_t)))
413 return -EFAULT;
415 /* If you change siginfo_t structure, please be sure
416 this code is fixed accordingly.
417 It should never copy any pad contained in the structure
418 to avoid security leaks, but must copy the generic
419 3 ints plus the relevant union member.
420 This routine must convert siginfo from 64bit to 32bit as well
421 at the same time. */
422 err = __put_user(from->si_signo, &to->si_signo);
423 err |= __put_user(from->si_errno, &to->si_errno);
424 err |= __put_user((short)from->si_code, &to->si_code);
425 if (from->si_code < 0)
426 err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
427 else {
428 switch (from->si_code >> 16) {
429 case __SI_TIMER >> 16:
430 err |= __put_user(from->si_tid, &to->si_tid);
431 err |= __put_user(from->si_overrun, &to->si_overrun);
432 err |= __put_user(from->si_int, &to->si_int);
433 break;
434 case __SI_CHLD >> 16:
435 err |= __put_user(from->si_utime, &to->si_utime);
436 err |= __put_user(from->si_stime, &to->si_stime);
437 err |= __put_user(from->si_status, &to->si_status);
438 default:
439 err |= __put_user(from->si_pid, &to->si_pid);
440 err |= __put_user(from->si_uid, &to->si_uid);
441 break;
442 case __SI_FAULT >> 16:
443 err |= __put_user((unsigned long)from->si_addr, &to->si_addr);
444 break;
445 case __SI_POLL >> 16:
446 err |= __put_user(from->si_band, &to->si_band);
447 err |= __put_user(from->si_fd, &to->si_fd);
448 break;
449 case __SI_RT >> 16: /* This is not generated by the kernel as of now. */
450 case __SI_MESGQ >> 16:
451 err |= __put_user(from->si_pid, &to->si_pid);
452 err |= __put_user(from->si_uid, &to->si_uid);
453 err |= __put_user(from->si_int, &to->si_int);
454 break;
457 return err;
460 int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
462 memset(to, 0, sizeof *to);
464 if (copy_from_user(to, from, 3*sizeof(int)) ||
465 copy_from_user(to->_sifields._pad,
466 from->_sifields._pad, SI_PAD_SIZE32))
467 return -EFAULT;
469 return 0;
472 asmlinkage void sys32_sigreturn(nabi_no_regargs struct pt_regs regs)
474 struct sigframe32 __user *frame;
475 sigset_t blocked;
476 int sig;
478 frame = (struct sigframe32 __user *) regs.regs[29];
479 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
480 goto badframe;
481 if (__copy_conv_sigset_from_user(&blocked, &frame->sf_mask))
482 goto badframe;
484 sigdelsetmask(&blocked, ~_BLOCKABLE);
485 set_current_blocked(&blocked);
487 sig = restore_sigcontext32(&regs, &frame->sf_sc);
488 if (sig < 0)
489 goto badframe;
490 else if (sig)
491 force_sig(sig, current);
494 * Don't let your children do this ...
496 __asm__ __volatile__(
497 "move\t$29, %0\n\t"
498 "j\tsyscall_exit"
499 :/* no outputs */
500 :"r" (&regs));
501 /* Unreached */
503 badframe:
504 force_sig(SIGSEGV, current);
507 asmlinkage void sys32_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
509 struct rt_sigframe32 __user *frame;
510 mm_segment_t old_fs;
511 sigset_t set;
512 stack_t st;
513 s32 sp;
514 int sig;
516 frame = (struct rt_sigframe32 __user *) regs.regs[29];
517 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
518 goto badframe;
519 if (__copy_conv_sigset_from_user(&set, &frame->rs_uc.uc_sigmask))
520 goto badframe;
522 sigdelsetmask(&set, ~_BLOCKABLE);
523 set_current_blocked(&set);
525 sig = restore_sigcontext32(&regs, &frame->rs_uc.uc_mcontext);
526 if (sig < 0)
527 goto badframe;
528 else if (sig)
529 force_sig(sig, current);
531 /* The ucontext contains a stack32_t, so we must convert! */
532 if (__get_user(sp, &frame->rs_uc.uc_stack.ss_sp))
533 goto badframe;
534 st.ss_sp = (void __user *)(long) sp;
535 if (__get_user(st.ss_size, &frame->rs_uc.uc_stack.ss_size))
536 goto badframe;
537 if (__get_user(st.ss_flags, &frame->rs_uc.uc_stack.ss_flags))
538 goto badframe;
540 /* It is more difficult to avoid calling this function than to
541 call it and ignore errors. */
542 old_fs = get_fs();
543 set_fs(KERNEL_DS);
544 do_sigaltstack((stack_t __user *)&st, NULL, regs.regs[29]);
545 set_fs(old_fs);
548 * Don't let your children do this ...
550 __asm__ __volatile__(
551 "move\t$29, %0\n\t"
552 "j\tsyscall_exit"
553 :/* no outputs */
554 :"r" (&regs));
555 /* Unreached */
557 badframe:
558 force_sig(SIGSEGV, current);
561 static int setup_frame_32(void *sig_return, struct k_sigaction *ka,
562 struct pt_regs *regs, int signr, sigset_t *set)
564 struct sigframe32 __user *frame;
565 int err = 0;
567 frame = get_sigframe(ka, regs, sizeof(*frame));
568 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
569 goto give_sigsegv;
571 err |= setup_sigcontext32(regs, &frame->sf_sc);
572 err |= __copy_conv_sigset_to_user(&frame->sf_mask, set);
574 if (err)
575 goto give_sigsegv;
578 * Arguments to signal handler:
580 * a0 = signal number
581 * a1 = 0 (should be cause)
582 * a2 = pointer to struct sigcontext
584 * $25 and c0_epc point to the signal handler, $29 points to the
585 * struct sigframe.
587 regs->regs[ 4] = signr;
588 regs->regs[ 5] = 0;
589 regs->regs[ 6] = (unsigned long) &frame->sf_sc;
590 regs->regs[29] = (unsigned long) frame;
591 regs->regs[31] = (unsigned long) sig_return;
592 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
594 DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
595 current->comm, current->pid,
596 frame, regs->cp0_epc, regs->regs[31]);
598 return 0;
600 give_sigsegv:
601 force_sigsegv(signr, current);
602 return -EFAULT;
605 static int setup_rt_frame_32(void *sig_return, struct k_sigaction *ka,
606 struct pt_regs *regs, int signr, sigset_t *set,
607 siginfo_t *info)
609 struct rt_sigframe32 __user *frame;
610 int err = 0;
611 s32 sp;
613 frame = get_sigframe(ka, regs, sizeof(*frame));
614 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
615 goto give_sigsegv;
617 /* Convert (siginfo_t -> compat_siginfo_t) and copy to user. */
618 err |= copy_siginfo_to_user32(&frame->rs_info, info);
620 /* Create the ucontext. */
621 err |= __put_user(0, &frame->rs_uc.uc_flags);
622 err |= __put_user(0, &frame->rs_uc.uc_link);
623 sp = (int) (long) current->sas_ss_sp;
624 err |= __put_user(sp,
625 &frame->rs_uc.uc_stack.ss_sp);
626 err |= __put_user(sas_ss_flags(regs->regs[29]),
627 &frame->rs_uc.uc_stack.ss_flags);
628 err |= __put_user(current->sas_ss_size,
629 &frame->rs_uc.uc_stack.ss_size);
630 err |= setup_sigcontext32(regs, &frame->rs_uc.uc_mcontext);
631 err |= __copy_conv_sigset_to_user(&frame->rs_uc.uc_sigmask, set);
633 if (err)
634 goto give_sigsegv;
637 * Arguments to signal handler:
639 * a0 = signal number
640 * a1 = 0 (should be cause)
641 * a2 = pointer to ucontext
643 * $25 and c0_epc point to the signal handler, $29 points to
644 * the struct rt_sigframe32.
646 regs->regs[ 4] = signr;
647 regs->regs[ 5] = (unsigned long) &frame->rs_info;
648 regs->regs[ 6] = (unsigned long) &frame->rs_uc;
649 regs->regs[29] = (unsigned long) frame;
650 regs->regs[31] = (unsigned long) sig_return;
651 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
653 DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
654 current->comm, current->pid,
655 frame, regs->cp0_epc, regs->regs[31]);
657 return 0;
659 give_sigsegv:
660 force_sigsegv(signr, current);
661 return -EFAULT;
665 * o32 compatibility on 64-bit kernels, without DSP ASE
667 struct mips_abi mips_abi_32 = {
668 .setup_frame = setup_frame_32,
669 .signal_return_offset =
670 offsetof(struct mips_vdso, o32_signal_trampoline),
671 .setup_rt_frame = setup_rt_frame_32,
672 .rt_signal_return_offset =
673 offsetof(struct mips_vdso, o32_rt_signal_trampoline),
674 .restart = __NR_O32_restart_syscall
677 SYSCALL_DEFINE4(32_rt_sigaction, int, sig,
678 const struct sigaction32 __user *, act,
679 struct sigaction32 __user *, oact, unsigned int, sigsetsize)
681 struct k_sigaction new_sa, old_sa;
682 int ret = -EINVAL;
684 /* XXX: Don't preclude handling different sized sigset_t's. */
685 if (sigsetsize != sizeof(sigset_t))
686 goto out;
688 if (act) {
689 s32 handler;
690 int err = 0;
692 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
693 return -EFAULT;
694 err |= __get_user(handler, &act->sa_handler);
695 new_sa.sa.sa_handler = (void __user *)(s64)handler;
696 err |= __get_user(new_sa.sa.sa_flags, &act->sa_flags);
697 err |= get_sigset(&new_sa.sa.sa_mask, &act->sa_mask);
698 if (err)
699 return -EFAULT;
702 ret = do_sigaction(sig, act ? &new_sa : NULL, oact ? &old_sa : NULL);
704 if (!ret && oact) {
705 int err = 0;
707 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
708 return -EFAULT;
710 err |= __put_user((u32)(u64)old_sa.sa.sa_handler,
711 &oact->sa_handler);
712 err |= __put_user(old_sa.sa.sa_flags, &oact->sa_flags);
713 err |= put_sigset(&old_sa.sa.sa_mask, &oact->sa_mask);
714 if (err)
715 return -EFAULT;
717 out:
718 return ret;
721 SYSCALL_DEFINE4(32_rt_sigprocmask, int, how, compat_sigset_t __user *, set,
722 compat_sigset_t __user *, oset, unsigned int, sigsetsize)
724 sigset_t old_set, new_set;
725 int ret;
726 mm_segment_t old_fs = get_fs();
728 if (set && get_sigset(&new_set, set))
729 return -EFAULT;
731 set_fs(KERNEL_DS);
732 ret = sys_rt_sigprocmask(how, set ? (sigset_t __user *)&new_set : NULL,
733 oset ? (sigset_t __user *)&old_set : NULL,
734 sigsetsize);
735 set_fs(old_fs);
737 if (!ret && oset && put_sigset(&old_set, oset))
738 return -EFAULT;
740 return ret;
743 SYSCALL_DEFINE2(32_rt_sigpending, compat_sigset_t __user *, uset,
744 unsigned int, sigsetsize)
746 int ret;
747 sigset_t set;
748 mm_segment_t old_fs = get_fs();
750 set_fs(KERNEL_DS);
751 ret = sys_rt_sigpending((sigset_t __user *)&set, sigsetsize);
752 set_fs(old_fs);
754 if (!ret && put_sigset(&set, uset))
755 return -EFAULT;
757 return ret;
760 SYSCALL_DEFINE3(32_rt_sigqueueinfo, int, pid, int, sig,
761 compat_siginfo_t __user *, uinfo)
763 siginfo_t info;
764 int ret;
765 mm_segment_t old_fs = get_fs();
767 if (copy_from_user(&info, uinfo, 3*sizeof(int)) ||
768 copy_from_user(info._sifields._pad, uinfo->_sifields._pad, SI_PAD_SIZE))
769 return -EFAULT;
770 set_fs(KERNEL_DS);
771 ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
772 set_fs(old_fs);
773 return ret;
776 SYSCALL_DEFINE5(32_waitid, int, which, compat_pid_t, pid,
777 compat_siginfo_t __user *, uinfo, int, options,
778 struct compat_rusage __user *, uru)
780 siginfo_t info;
781 struct rusage ru;
782 long ret;
783 mm_segment_t old_fs = get_fs();
785 info.si_signo = 0;
786 set_fs(KERNEL_DS);
787 ret = sys_waitid(which, pid, (siginfo_t __user *) &info, options,
788 uru ? (struct rusage __user *) &ru : NULL);
789 set_fs(old_fs);
791 if (ret < 0 || info.si_signo == 0)
792 return ret;
794 if (uru && (ret = put_compat_rusage(&ru, uru)))
795 return ret;
797 BUG_ON(info.si_code & __SI_MASK);
798 info.si_code |= __SI_CHLD;
799 return copy_siginfo_to_user32(uinfo, &info);
802 static int signal32_init(void)
804 if (cpu_has_fpu) {
805 save_fp_context32 = _save_fp_context32;
806 restore_fp_context32 = _restore_fp_context32;
807 } else {
808 save_fp_context32 = fpu_emulator_save_context32;
809 restore_fp_context32 = fpu_emulator_restore_context32;
812 return 0;
815 arch_initcall(signal32_init);