[PATCH] acpiphp: fix acpi_path_name
[linux/fpc-iii.git] / arch / mips / kernel / signal32.c
blobf32a22997c3d68d1754f745564b9dbac4e3928d2
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/sched.h>
12 #include <linux/mm.h>
13 #include <linux/smp.h>
14 #include <linux/smp_lock.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/compat.h>
22 #include <linux/suspend.h>
23 #include <linux/compiler.h>
25 #include <asm/abi.h>
26 #include <asm/asm.h>
27 #include <linux/bitops.h>
28 #include <asm/cacheflush.h>
29 #include <asm/sim.h>
30 #include <asm/uaccess.h>
31 #include <asm/ucontext.h>
32 #include <asm/system.h>
33 #include <asm/fpu.h>
34 #include <asm/war.h>
36 #define SI_PAD_SIZE32 ((SI_MAX_SIZE/sizeof(int)) - 3)
38 typedef struct compat_siginfo {
39 int si_signo;
40 int si_code;
41 int si_errno;
43 union {
44 int _pad[SI_PAD_SIZE32];
46 /* kill() */
47 struct {
48 compat_pid_t _pid; /* sender's pid */
49 compat_uid_t _uid; /* sender's uid */
50 } _kill;
52 /* SIGCHLD */
53 struct {
54 compat_pid_t _pid; /* which child */
55 compat_uid_t _uid; /* sender's uid */
56 int _status; /* exit code */
57 compat_clock_t _utime;
58 compat_clock_t _stime;
59 } _sigchld;
61 /* IRIX SIGCHLD */
62 struct {
63 compat_pid_t _pid; /* which child */
64 compat_clock_t _utime;
65 int _status; /* exit code */
66 compat_clock_t _stime;
67 } _irix_sigchld;
69 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
70 struct {
71 s32 _addr; /* faulting insn/memory ref. */
72 } _sigfault;
74 /* SIGPOLL, SIGXFSZ (To do ...) */
75 struct {
76 int _band; /* POLL_IN, POLL_OUT, POLL_MSG */
77 int _fd;
78 } _sigpoll;
80 /* POSIX.1b timers */
81 struct {
82 timer_t _tid; /* timer id */
83 int _overrun; /* overrun count */
84 compat_sigval_t _sigval;/* same as below */
85 int _sys_private; /* not to be passed to user */
86 } _timer;
88 /* POSIX.1b signals */
89 struct {
90 compat_pid_t _pid; /* sender's pid */
91 compat_uid_t _uid; /* sender's uid */
92 compat_sigval_t _sigval;
93 } _rt;
95 } _sifields;
96 } compat_siginfo_t;
99 * Including <asm/unistd.h> would give use the 64-bit syscall numbers ...
101 #define __NR_O32_sigreturn 4119
102 #define __NR_O32_rt_sigreturn 4193
103 #define __NR_O32_restart_syscall 4253
105 #define DEBUG_SIG 0
107 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
109 /* 32-bit compatibility types */
111 #define _NSIG_BPW32 32
112 #define _NSIG_WORDS32 (_NSIG / _NSIG_BPW32)
114 typedef struct {
115 unsigned int sig[_NSIG_WORDS32];
116 } sigset_t32;
118 typedef unsigned int __sighandler32_t;
119 typedef void (*vfptr_t)(void);
121 struct sigaction32 {
122 unsigned int sa_flags;
123 __sighandler32_t sa_handler;
124 compat_sigset_t sa_mask;
127 /* IRIX compatible stack_t */
128 typedef struct sigaltstack32 {
129 s32 ss_sp;
130 compat_size_t ss_size;
131 int ss_flags;
132 } stack32_t;
134 struct ucontext32 {
135 u32 uc_flags;
136 s32 uc_link;
137 stack32_t uc_stack;
138 struct sigcontext32 uc_mcontext;
139 sigset_t32 uc_sigmask; /* mask last for extensibility */
142 extern void __put_sigset_unknown_nsig(void);
143 extern void __get_sigset_unknown_nsig(void);
145 static inline int put_sigset(const sigset_t *kbuf, compat_sigset_t __user *ubuf)
147 int err = 0;
149 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)))
150 return -EFAULT;
152 switch (_NSIG_WORDS) {
153 default:
154 __put_sigset_unknown_nsig();
155 case 2:
156 err |= __put_user (kbuf->sig[1] >> 32, &ubuf->sig[3]);
157 err |= __put_user (kbuf->sig[1] & 0xffffffff, &ubuf->sig[2]);
158 case 1:
159 err |= __put_user (kbuf->sig[0] >> 32, &ubuf->sig[1]);
160 err |= __put_user (kbuf->sig[0] & 0xffffffff, &ubuf->sig[0]);
163 return err;
166 static inline int get_sigset(sigset_t *kbuf, const compat_sigset_t __user *ubuf)
168 int err = 0;
169 unsigned long sig[4];
171 if (!access_ok(VERIFY_READ, ubuf, sizeof(*ubuf)))
172 return -EFAULT;
174 switch (_NSIG_WORDS) {
175 default:
176 __get_sigset_unknown_nsig();
177 case 2:
178 err |= __get_user (sig[3], &ubuf->sig[3]);
179 err |= __get_user (sig[2], &ubuf->sig[2]);
180 kbuf->sig[1] = sig[2] | (sig[3] << 32);
181 case 1:
182 err |= __get_user (sig[1], &ubuf->sig[1]);
183 err |= __get_user (sig[0], &ubuf->sig[0]);
184 kbuf->sig[0] = sig[0] | (sig[1] << 32);
187 return err;
191 * Atomically swap in the new signal mask, and wait for a signal.
194 save_static_function(sys32_sigsuspend);
195 __attribute_used__ noinline static int
196 _sys32_sigsuspend(nabi_no_regargs struct pt_regs regs)
198 compat_sigset_t __user *uset;
199 sigset_t newset;
201 uset = (compat_sigset_t __user *) regs.regs[4];
202 if (get_sigset(&newset, uset))
203 return -EFAULT;
204 sigdelsetmask(&newset, ~_BLOCKABLE);
206 spin_lock_irq(&current->sighand->siglock);
207 current->saved_sigmask = current->blocked;
208 current->blocked = newset;
209 recalc_sigpending();
210 spin_unlock_irq(&current->sighand->siglock);
212 current->state = TASK_INTERRUPTIBLE;
213 schedule();
214 set_thread_flag(TIF_RESTORE_SIGMASK);
215 return -ERESTARTNOHAND;
218 save_static_function(sys32_rt_sigsuspend);
219 __attribute_used__ noinline static int
220 _sys32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
222 compat_sigset_t __user *uset;
223 sigset_t newset;
224 size_t sigsetsize;
226 /* XXX Don't preclude handling different sized sigset_t's. */
227 sigsetsize = regs.regs[5];
228 if (sigsetsize != sizeof(compat_sigset_t))
229 return -EINVAL;
231 uset = (compat_sigset_t __user *) regs.regs[4];
232 if (get_sigset(&newset, uset))
233 return -EFAULT;
234 sigdelsetmask(&newset, ~_BLOCKABLE);
236 spin_lock_irq(&current->sighand->siglock);
237 current->saved_sigmask = current->blocked;
238 current->blocked = newset;
239 recalc_sigpending();
240 spin_unlock_irq(&current->sighand->siglock);
242 current->state = TASK_INTERRUPTIBLE;
243 schedule();
244 set_thread_flag(TIF_RESTORE_SIGMASK);
245 return -ERESTARTNOHAND;
248 asmlinkage int sys32_sigaction(int sig, const struct sigaction32 __user *act,
249 struct sigaction32 __user *oact)
251 struct k_sigaction new_ka, old_ka;
252 int ret;
253 int err = 0;
255 if (act) {
256 old_sigset_t mask;
257 s32 handler;
259 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
260 return -EFAULT;
261 err |= __get_user(handler, &act->sa_handler);
262 new_ka.sa.sa_handler = (void __user *)(s64)handler;
263 err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
264 err |= __get_user(mask, &act->sa_mask.sig[0]);
265 if (err)
266 return -EFAULT;
268 siginitset(&new_ka.sa.sa_mask, mask);
271 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
273 if (!ret && oact) {
274 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
275 return -EFAULT;
276 err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
277 err |= __put_user((u32)(u64)old_ka.sa.sa_handler,
278 &oact->sa_handler);
279 err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
280 err |= __put_user(0, &oact->sa_mask.sig[1]);
281 err |= __put_user(0, &oact->sa_mask.sig[2]);
282 err |= __put_user(0, &oact->sa_mask.sig[3]);
283 if (err)
284 return -EFAULT;
287 return ret;
290 asmlinkage int sys32_sigaltstack(nabi_no_regargs struct pt_regs regs)
292 const stack32_t __user *uss = (const stack32_t __user *) regs.regs[4];
293 stack32_t __user *uoss = (stack32_t __user *) regs.regs[5];
294 unsigned long usp = regs.regs[29];
295 stack_t kss, koss;
296 int ret, err = 0;
297 mm_segment_t old_fs = get_fs();
298 s32 sp;
300 if (uss) {
301 if (!access_ok(VERIFY_READ, uss, sizeof(*uss)))
302 return -EFAULT;
303 err |= __get_user(sp, &uss->ss_sp);
304 kss.ss_sp = (void __user *) (long) sp;
305 err |= __get_user(kss.ss_size, &uss->ss_size);
306 err |= __get_user(kss.ss_flags, &uss->ss_flags);
307 if (err)
308 return -EFAULT;
311 set_fs (KERNEL_DS);
312 ret = do_sigaltstack(uss ? (stack_t __user *)&kss : NULL,
313 uoss ? (stack_t __user *)&koss : NULL, usp);
314 set_fs (old_fs);
316 if (!ret && uoss) {
317 if (!access_ok(VERIFY_WRITE, uoss, sizeof(*uoss)))
318 return -EFAULT;
319 sp = (int) (unsigned long) koss.ss_sp;
320 err |= __put_user(sp, &uoss->ss_sp);
321 err |= __put_user(koss.ss_size, &uoss->ss_size);
322 err |= __put_user(koss.ss_flags, &uoss->ss_flags);
323 if (err)
324 return -EFAULT;
326 return ret;
329 static int restore_sigcontext32(struct pt_regs *regs, struct sigcontext32 __user *sc)
331 u32 used_math;
332 int err = 0;
333 s32 treg;
335 /* Always make any pending restarted system calls return -EINTR */
336 current_thread_info()->restart_block.fn = do_no_restart_syscall;
338 err |= __get_user(regs->cp0_epc, &sc->sc_pc);
339 err |= __get_user(regs->hi, &sc->sc_mdhi);
340 err |= __get_user(regs->lo, &sc->sc_mdlo);
341 if (cpu_has_dsp) {
342 err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
343 err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
344 err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
345 err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
346 err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
347 err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
348 err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
351 #define restore_gp_reg(i) do { \
352 err |= __get_user(regs->regs[i], &sc->sc_regs[i]); \
353 } while(0)
354 restore_gp_reg( 1); restore_gp_reg( 2); restore_gp_reg( 3);
355 restore_gp_reg( 4); restore_gp_reg( 5); restore_gp_reg( 6);
356 restore_gp_reg( 7); restore_gp_reg( 8); restore_gp_reg( 9);
357 restore_gp_reg(10); restore_gp_reg(11); restore_gp_reg(12);
358 restore_gp_reg(13); restore_gp_reg(14); restore_gp_reg(15);
359 restore_gp_reg(16); restore_gp_reg(17); restore_gp_reg(18);
360 restore_gp_reg(19); restore_gp_reg(20); restore_gp_reg(21);
361 restore_gp_reg(22); restore_gp_reg(23); restore_gp_reg(24);
362 restore_gp_reg(25); restore_gp_reg(26); restore_gp_reg(27);
363 restore_gp_reg(28); restore_gp_reg(29); restore_gp_reg(30);
364 restore_gp_reg(31);
365 #undef restore_gp_reg
367 err |= __get_user(used_math, &sc->sc_used_math);
368 conditional_used_math(used_math);
370 preempt_disable();
372 if (used_math()) {
373 /* restore fpu context if we have used it before */
374 own_fpu();
375 err |= restore_fp_context32(sc);
376 } else {
377 /* signal handler may have used FPU. Give it up. */
378 lose_fpu();
381 preempt_enable();
383 return err;
386 struct sigframe {
387 u32 sf_ass[4]; /* argument save space for o32 */
388 #if ICACHE_REFILLS_WORKAROUND_WAR
389 u32 sf_pad[2];
390 #else
391 u32 sf_code[2]; /* signal trampoline */
392 #endif
393 struct sigcontext32 sf_sc;
394 sigset_t sf_mask;
395 #if ICACHE_REFILLS_WORKAROUND_WAR
396 u32 sf_code[8] ____cacheline_aligned; /* signal trampoline */
397 #endif
400 struct rt_sigframe32 {
401 u32 rs_ass[4]; /* argument save space for o32 */
402 #if ICACHE_REFILLS_WORKAROUND_WAR
403 u32 rs_pad[2];
404 #else
405 u32 rs_code[2]; /* signal trampoline */
406 #endif
407 compat_siginfo_t rs_info;
408 struct ucontext32 rs_uc;
409 #if ICACHE_REFILLS_WORKAROUND_WAR
410 u32 rs_code[8] __attribute__((aligned(32))); /* signal trampoline */
411 #endif
414 int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
416 int err;
418 if (!access_ok (VERIFY_WRITE, to, sizeof(compat_siginfo_t)))
419 return -EFAULT;
421 /* If you change siginfo_t structure, please be sure
422 this code is fixed accordingly.
423 It should never copy any pad contained in the structure
424 to avoid security leaks, but must copy the generic
425 3 ints plus the relevant union member.
426 This routine must convert siginfo from 64bit to 32bit as well
427 at the same time. */
428 err = __put_user(from->si_signo, &to->si_signo);
429 err |= __put_user(from->si_errno, &to->si_errno);
430 err |= __put_user((short)from->si_code, &to->si_code);
431 if (from->si_code < 0)
432 err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
433 else {
434 switch (from->si_code >> 16) {
435 case __SI_TIMER >> 16:
436 err |= __put_user(from->si_tid, &to->si_tid);
437 err |= __put_user(from->si_overrun, &to->si_overrun);
438 err |= __put_user(from->si_int, &to->si_int);
439 break;
440 case __SI_CHLD >> 16:
441 err |= __put_user(from->si_utime, &to->si_utime);
442 err |= __put_user(from->si_stime, &to->si_stime);
443 err |= __put_user(from->si_status, &to->si_status);
444 default:
445 err |= __put_user(from->si_pid, &to->si_pid);
446 err |= __put_user(from->si_uid, &to->si_uid);
447 break;
448 case __SI_FAULT >> 16:
449 err |= __put_user((unsigned long)from->si_addr, &to->si_addr);
450 break;
451 case __SI_POLL >> 16:
452 err |= __put_user(from->si_band, &to->si_band);
453 err |= __put_user(from->si_fd, &to->si_fd);
454 break;
455 case __SI_RT >> 16: /* This is not generated by the kernel as of now. */
456 case __SI_MESGQ >> 16:
457 err |= __put_user(from->si_pid, &to->si_pid);
458 err |= __put_user(from->si_uid, &to->si_uid);
459 err |= __put_user(from->si_int, &to->si_int);
460 break;
463 return err;
466 save_static_function(sys32_sigreturn);
467 __attribute_used__ noinline static void
468 _sys32_sigreturn(nabi_no_regargs struct pt_regs regs)
470 struct sigframe __user *frame;
471 sigset_t blocked;
473 frame = (struct sigframe __user *) regs.regs[29];
474 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
475 goto badframe;
476 if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked)))
477 goto badframe;
479 sigdelsetmask(&blocked, ~_BLOCKABLE);
480 spin_lock_irq(&current->sighand->siglock);
481 current->blocked = blocked;
482 recalc_sigpending();
483 spin_unlock_irq(&current->sighand->siglock);
485 if (restore_sigcontext32(&regs, &frame->sf_sc))
486 goto badframe;
489 * Don't let your children do this ...
491 __asm__ __volatile__(
492 "move\t$29, %0\n\t"
493 "j\tsyscall_exit"
494 :/* no outputs */
495 :"r" (&regs));
496 /* Unreached */
498 badframe:
499 force_sig(SIGSEGV, current);
502 save_static_function(sys32_rt_sigreturn);
503 __attribute_used__ noinline static void
504 _sys32_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
506 struct rt_sigframe32 __user *frame;
507 mm_segment_t old_fs;
508 sigset_t set;
509 stack_t st;
510 s32 sp;
512 frame = (struct rt_sigframe32 __user *) regs.regs[29];
513 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
514 goto badframe;
515 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
516 goto badframe;
518 sigdelsetmask(&set, ~_BLOCKABLE);
519 spin_lock_irq(&current->sighand->siglock);
520 current->blocked = set;
521 recalc_sigpending();
522 spin_unlock_irq(&current->sighand->siglock);
524 if (restore_sigcontext32(&regs, &frame->rs_uc.uc_mcontext))
525 goto badframe;
527 /* The ucontext contains a stack32_t, so we must convert! */
528 if (__get_user(sp, &frame->rs_uc.uc_stack.ss_sp))
529 goto badframe;
530 st.ss_sp = (void __user *)(long) sp;
531 if (__get_user(st.ss_size, &frame->rs_uc.uc_stack.ss_size))
532 goto badframe;
533 if (__get_user(st.ss_flags, &frame->rs_uc.uc_stack.ss_flags))
534 goto badframe;
536 /* It is more difficult to avoid calling this function than to
537 call it and ignore errors. */
538 old_fs = get_fs();
539 set_fs (KERNEL_DS);
540 do_sigaltstack((stack_t __user *)&st, NULL, regs.regs[29]);
541 set_fs (old_fs);
544 * Don't let your children do this ...
546 __asm__ __volatile__(
547 "move\t$29, %0\n\t"
548 "j\tsyscall_exit"
549 :/* no outputs */
550 :"r" (&regs));
551 /* Unreached */
553 badframe:
554 force_sig(SIGSEGV, current);
557 static inline int setup_sigcontext32(struct pt_regs *regs,
558 struct sigcontext32 __user *sc)
560 int err = 0;
562 err |= __put_user(regs->cp0_epc, &sc->sc_pc);
563 err |= __put_user(regs->cp0_status, &sc->sc_status);
565 #define save_gp_reg(i) { \
566 err |= __put_user(regs->regs[i], &sc->sc_regs[i]); \
567 } while(0)
568 __put_user(0, &sc->sc_regs[0]); save_gp_reg(1); save_gp_reg(2);
569 save_gp_reg(3); save_gp_reg(4); save_gp_reg(5); save_gp_reg(6);
570 save_gp_reg(7); save_gp_reg(8); save_gp_reg(9); save_gp_reg(10);
571 save_gp_reg(11); save_gp_reg(12); save_gp_reg(13); save_gp_reg(14);
572 save_gp_reg(15); save_gp_reg(16); save_gp_reg(17); save_gp_reg(18);
573 save_gp_reg(19); save_gp_reg(20); save_gp_reg(21); save_gp_reg(22);
574 save_gp_reg(23); save_gp_reg(24); save_gp_reg(25); save_gp_reg(26);
575 save_gp_reg(27); save_gp_reg(28); save_gp_reg(29); save_gp_reg(30);
576 save_gp_reg(31);
577 #undef save_gp_reg
579 err |= __put_user(regs->hi, &sc->sc_mdhi);
580 err |= __put_user(regs->lo, &sc->sc_mdlo);
581 if (cpu_has_dsp) {
582 err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
583 err |= __put_user(mfhi1(), &sc->sc_hi1);
584 err |= __put_user(mflo1(), &sc->sc_lo1);
585 err |= __put_user(mfhi2(), &sc->sc_hi2);
586 err |= __put_user(mflo2(), &sc->sc_lo2);
587 err |= __put_user(mfhi3(), &sc->sc_hi3);
588 err |= __put_user(mflo3(), &sc->sc_lo3);
591 err |= __put_user(!!used_math(), &sc->sc_used_math);
593 if (!used_math())
594 goto out;
597 * Save FPU state to signal context. Signal handler will "inherit"
598 * current FPU state.
600 preempt_disable();
602 if (!is_fpu_owner()) {
603 own_fpu();
604 restore_fp(current);
606 err |= save_fp_context32(sc);
608 preempt_enable();
610 out:
611 return err;
615 * Determine which stack to use..
617 static inline void __user *get_sigframe(struct k_sigaction *ka,
618 struct pt_regs *regs,
619 size_t frame_size)
621 unsigned long sp;
623 /* Default to using normal stack */
624 sp = regs->regs[29];
627 * FPU emulator may have it's own trampoline active just
628 * above the user stack, 16-bytes before the next lowest
629 * 16 byte boundary. Try to avoid trashing it.
631 sp -= 32;
633 /* This is the X/Open sanctioned signal stack switching. */
634 if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
635 sp = current->sas_ss_sp + current->sas_ss_size;
637 return (void __user *)((sp - frame_size) & ALMASK);
640 int setup_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
641 int signr, sigset_t *set)
643 struct sigframe __user *frame;
644 int err = 0;
646 frame = get_sigframe(ka, regs, sizeof(*frame));
647 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
648 goto give_sigsegv;
651 * Set up the return code ...
653 * li v0, __NR_O32_sigreturn
654 * syscall
656 err |= __put_user(0x24020000 + __NR_O32_sigreturn, frame->sf_code + 0);
657 err |= __put_user(0x0000000c , frame->sf_code + 1);
658 flush_cache_sigtramp((unsigned long) frame->sf_code);
660 err |= setup_sigcontext32(regs, &frame->sf_sc);
661 err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));
662 if (err)
663 goto give_sigsegv;
666 * Arguments to signal handler:
668 * a0 = signal number
669 * a1 = 0 (should be cause)
670 * a2 = pointer to struct sigcontext
672 * $25 and c0_epc point to the signal handler, $29 points to the
673 * struct sigframe.
675 regs->regs[ 4] = signr;
676 regs->regs[ 5] = 0;
677 regs->regs[ 6] = (unsigned long) &frame->sf_sc;
678 regs->regs[29] = (unsigned long) frame;
679 regs->regs[31] = (unsigned long) frame->sf_code;
680 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
682 #if DEBUG_SIG
683 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
684 current->comm, current->pid,
685 frame, regs->cp0_epc, frame->sf_code);
686 #endif
687 return 0;
689 give_sigsegv:
690 force_sigsegv(signr, current);
691 return -EFAULT;
694 int setup_rt_frame_32(struct k_sigaction * ka, struct pt_regs *regs,
695 int signr, sigset_t *set, siginfo_t *info)
697 struct rt_sigframe32 __user *frame;
698 int err = 0;
699 s32 sp;
701 frame = get_sigframe(ka, regs, sizeof(*frame));
702 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
703 goto give_sigsegv;
705 /* Set up to return from userspace. If provided, use a stub already
706 in userspace. */
708 * Set up the return code ...
710 * li v0, __NR_O32_rt_sigreturn
711 * syscall
713 err |= __put_user(0x24020000 + __NR_O32_rt_sigreturn, frame->rs_code + 0);
714 err |= __put_user(0x0000000c , frame->rs_code + 1);
715 flush_cache_sigtramp((unsigned long) frame->rs_code);
717 /* Convert (siginfo_t -> compat_siginfo_t) and copy to user. */
718 err |= copy_siginfo_to_user32(&frame->rs_info, info);
720 /* Create the ucontext. */
721 err |= __put_user(0, &frame->rs_uc.uc_flags);
722 err |= __put_user(0, &frame->rs_uc.uc_link);
723 sp = (int) (long) current->sas_ss_sp;
724 err |= __put_user(sp,
725 &frame->rs_uc.uc_stack.ss_sp);
726 err |= __put_user(sas_ss_flags(regs->regs[29]),
727 &frame->rs_uc.uc_stack.ss_flags);
728 err |= __put_user(current->sas_ss_size,
729 &frame->rs_uc.uc_stack.ss_size);
730 err |= setup_sigcontext32(regs, &frame->rs_uc.uc_mcontext);
731 err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));
733 if (err)
734 goto give_sigsegv;
737 * Arguments to signal handler:
739 * a0 = signal number
740 * a1 = 0 (should be cause)
741 * a2 = pointer to ucontext
743 * $25 and c0_epc point to the signal handler, $29 points to
744 * the struct rt_sigframe32.
746 regs->regs[ 4] = signr;
747 regs->regs[ 5] = (unsigned long) &frame->rs_info;
748 regs->regs[ 6] = (unsigned long) &frame->rs_uc;
749 regs->regs[29] = (unsigned long) frame;
750 regs->regs[31] = (unsigned long) frame->rs_code;
751 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
753 #if DEBUG_SIG
754 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
755 current->comm, current->pid,
756 frame, regs->cp0_epc, frame->rs_code);
757 #endif
758 return 0;
760 give_sigsegv:
761 force_sigsegv(signr, current);
762 return -EFAULT;
765 static inline int handle_signal(unsigned long sig, siginfo_t *info,
766 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs * regs)
768 int ret;
770 switch (regs->regs[0]) {
771 case ERESTART_RESTARTBLOCK:
772 case ERESTARTNOHAND:
773 regs->regs[2] = EINTR;
774 break;
775 case ERESTARTSYS:
776 if (!(ka->sa.sa_flags & SA_RESTART)) {
777 regs->regs[2] = EINTR;
778 break;
780 /* fallthrough */
781 case ERESTARTNOINTR: /* Userland will reload $v0. */
782 regs->regs[7] = regs->regs[26];
783 regs->cp0_epc -= 8;
786 regs->regs[0] = 0; /* Don't deal with this again. */
788 if (ka->sa.sa_flags & SA_SIGINFO)
789 ret = current->thread.abi->setup_rt_frame(ka, regs, sig, oldset, info);
790 else
791 ret = current->thread.abi->setup_frame(ka, regs, sig, oldset);
793 spin_lock_irq(&current->sighand->siglock);
794 sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
795 if (!(ka->sa.sa_flags & SA_NODEFER))
796 sigaddset(&current->blocked,sig);
797 recalc_sigpending();
798 spin_unlock_irq(&current->sighand->siglock);
800 return ret;
803 void do_signal32(struct pt_regs *regs)
805 struct k_sigaction ka;
806 sigset_t *oldset;
807 siginfo_t info;
808 int signr;
811 * We want the common case to go fast, which is why we may in certain
812 * cases get here from kernel mode. Just return without doing anything
813 * if so.
815 if (!user_mode(regs))
816 return;
818 if (try_to_freeze())
819 goto no_signal;
821 if (test_thread_flag(TIF_RESTORE_SIGMASK))
822 oldset = &current->saved_sigmask;
823 else
824 oldset = &current->blocked;
826 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
827 if (signr > 0) {
828 /* Whee! Actually deliver the signal. */
829 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
831 * A signal was successfully delivered; the saved
832 * sigmask will have been stored in the signal frame,
833 * and will be restored by sigreturn, so we can simply
834 * clear the TIF_RESTORE_SIGMASK flag.
836 if (test_thread_flag(TIF_RESTORE_SIGMASK))
837 clear_thread_flag(TIF_RESTORE_SIGMASK);
841 no_signal:
843 * Who's code doesn't conform to the restartable syscall convention
844 * dies here!!! The li instruction, a single machine instruction,
845 * must directly be followed by the syscall instruction.
847 if (regs->regs[0]) {
848 if (regs->regs[2] == ERESTARTNOHAND ||
849 regs->regs[2] == ERESTARTSYS ||
850 regs->regs[2] == ERESTARTNOINTR) {
851 regs->regs[7] = regs->regs[26];
852 regs->cp0_epc -= 8;
854 if (regs->regs[2] == ERESTART_RESTARTBLOCK) {
855 regs->regs[2] = __NR_O32_restart_syscall;
856 regs->regs[7] = regs->regs[26];
857 regs->cp0_epc -= 4;
862 * If there's no signal to deliver, we just put the saved sigmask
863 * back
865 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
866 clear_thread_flag(TIF_RESTORE_SIGMASK);
867 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
871 asmlinkage int sys32_rt_sigaction(int sig, const struct sigaction32 __user *act,
872 struct sigaction32 __user *oact,
873 unsigned int sigsetsize)
875 struct k_sigaction new_sa, old_sa;
876 int ret = -EINVAL;
878 /* XXX: Don't preclude handling different sized sigset_t's. */
879 if (sigsetsize != sizeof(sigset_t))
880 goto out;
882 if (act) {
883 s32 handler;
884 int err = 0;
886 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
887 return -EFAULT;
888 err |= __get_user(handler, &act->sa_handler);
889 new_sa.sa.sa_handler = (void __user *)(s64)handler;
890 err |= __get_user(new_sa.sa.sa_flags, &act->sa_flags);
891 err |= get_sigset(&new_sa.sa.sa_mask, &act->sa_mask);
892 if (err)
893 return -EFAULT;
896 ret = do_sigaction(sig, act ? &new_sa : NULL, oact ? &old_sa : NULL);
898 if (!ret && oact) {
899 int err = 0;
901 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
902 return -EFAULT;
904 err |= __put_user((u32)(u64)old_sa.sa.sa_handler,
905 &oact->sa_handler);
906 err |= __put_user(old_sa.sa.sa_flags, &oact->sa_flags);
907 err |= put_sigset(&old_sa.sa.sa_mask, &oact->sa_mask);
908 if (err)
909 return -EFAULT;
911 out:
912 return ret;
915 asmlinkage int sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
916 compat_sigset_t __user *oset, unsigned int sigsetsize)
918 sigset_t old_set, new_set;
919 int ret;
920 mm_segment_t old_fs = get_fs();
922 if (set && get_sigset(&new_set, set))
923 return -EFAULT;
925 set_fs (KERNEL_DS);
926 ret = sys_rt_sigprocmask(how, set ? (sigset_t __user *)&new_set : NULL,
927 oset ? (sigset_t __user *)&old_set : NULL,
928 sigsetsize);
929 set_fs (old_fs);
931 if (!ret && oset && put_sigset(&old_set, oset))
932 return -EFAULT;
934 return ret;
937 asmlinkage int sys32_rt_sigpending(compat_sigset_t __user *uset,
938 unsigned int sigsetsize)
940 int ret;
941 sigset_t set;
942 mm_segment_t old_fs = get_fs();
944 set_fs (KERNEL_DS);
945 ret = sys_rt_sigpending((sigset_t __user *)&set, sigsetsize);
946 set_fs (old_fs);
948 if (!ret && put_sigset(&set, uset))
949 return -EFAULT;
951 return ret;
954 asmlinkage int sys32_rt_sigqueueinfo(int pid, int sig, compat_siginfo_t __user *uinfo)
956 siginfo_t info;
957 int ret;
958 mm_segment_t old_fs = get_fs();
960 if (copy_from_user (&info, uinfo, 3*sizeof(int)) ||
961 copy_from_user (info._sifields._pad, uinfo->_sifields._pad, SI_PAD_SIZE))
962 return -EFAULT;
963 set_fs (KERNEL_DS);
964 ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
965 set_fs (old_fs);
966 return ret;
969 asmlinkage long
970 sys32_waitid(int which, compat_pid_t pid,
971 compat_siginfo_t __user *uinfo, int options,
972 struct compat_rusage __user *uru)
974 siginfo_t info;
975 struct rusage ru;
976 long ret;
977 mm_segment_t old_fs = get_fs();
979 info.si_signo = 0;
980 set_fs (KERNEL_DS);
981 ret = sys_waitid(which, pid, (siginfo_t __user *) &info, options,
982 uru ? (struct rusage __user *) &ru : NULL);
983 set_fs (old_fs);
985 if (ret < 0 || info.si_signo == 0)
986 return ret;
988 if (uru && (ret = put_compat_rusage(&ru, uru)))
989 return ret;
991 BUG_ON(info.si_code & __SI_MASK);
992 info.si_code |= __SI_CHLD;
993 return copy_siginfo_to_user32(uinfo, &info);