2 * signal32.c: Support 32bit signal syscalls.
4 * Copyright (C) 2001 IBM
5 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
8 * These routines maintain argument size conversion between 32bit and 64bit
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
17 #include <linux/config.h>
18 #include <linux/sched.h>
20 #include <linux/smp.h>
21 #include <linux/smp_lock.h>
22 #include <linux/kernel.h>
23 #include <linux/signal.h>
24 #include <linux/syscalls.h>
25 #include <linux/errno.h>
26 #include <linux/elf.h>
27 #include <linux/compat.h>
28 #include <asm/ppc32.h>
29 #include <asm/uaccess.h>
30 #include <asm/ppcdebug.h>
31 #include <asm/unistd.h>
32 #include <asm/cacheflush.h>
36 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
38 #define GP_REGS_SIZE32 min(sizeof(elf_gregset_t32), sizeof(struct pt_regs32))
41 * When we have signals to deliver, we set up on the
42 * user stack, going down from the original stack pointer:
44 * a sigcontext32 struct
45 * a gap of __SIGNAL_FRAMESIZE32 bytes
47 * Each of these things must be a multiple of 16 bytes in size.
51 struct mcontext32 mctx; /* all the register values */
53 * Programs using the rs6000/xcoff abi can save up to 19 gp
54 * regs and 18 fp regs below sp before decrementing it.
59 /* We use the mc_pad field for the signal return trampoline. */
63 * When we have rt signals to deliver, we set up on the
64 * user stack, going down from the original stack pointer:
65 * one rt_sigframe32 struct (siginfo + ucontext + ABI gap)
66 * a gap of __SIGNAL_FRAMESIZE32+16 bytes
67 * (the +16 is to get the siginfo and ucontext32 in the same
68 * positions as in older kernels).
70 * Each of these things must be a multiple of 16 bytes in size.
73 struct rt_sigframe32 {
74 struct compat_siginfo info;
77 * Programs using the rs6000/xcoff abi can save up to 19 gp
78 * regs and 18 fp regs below sp before decrementing it.
85 * Common utility functions used by signal and context support
90 * Restore the user process's signal mask
91 * (implemented in signal.c)
93 extern void restore_sigmask(sigset_t *set);
96 * Functions for flipping sigsets (thanks to brain dead generic
97 * implementation that makes things simple for little endian only
99 static inline void compat_from_sigset(compat_sigset_t *compat, sigset_t *set)
101 switch (_NSIG_WORDS) {
102 case 4: compat->sig[5] = set->sig[3] & 0xffffffffull ;
103 compat->sig[7] = set->sig[3] >> 32;
104 case 3: compat->sig[4] = set->sig[2] & 0xffffffffull ;
105 compat->sig[5] = set->sig[2] >> 32;
106 case 2: compat->sig[2] = set->sig[1] & 0xffffffffull ;
107 compat->sig[3] = set->sig[1] >> 32;
108 case 1: compat->sig[0] = set->sig[0] & 0xffffffffull ;
109 compat->sig[1] = set->sig[0] >> 32;
113 static inline void sigset_from_compat(sigset_t *set, compat_sigset_t *compat)
115 switch (_NSIG_WORDS) {
116 case 4: set->sig[3] = compat->sig[6] | (((long)compat->sig[7]) << 32);
117 case 3: set->sig[2] = compat->sig[4] | (((long)compat->sig[5]) << 32);
118 case 2: set->sig[1] = compat->sig[2] | (((long)compat->sig[3]) << 32);
119 case 1: set->sig[0] = compat->sig[0] | (((long)compat->sig[1]) << 32);
125 * Save the current user registers on the user stack.
126 * We only save the altivec registers if the process has used
127 * altivec instructions at some point.
129 static int save_user_regs(struct pt_regs *regs, struct mcontext32 *frame, int sigret)
131 elf_greg_t64 *gregs = (elf_greg_t64 *)regs;
134 /* Make sure floating point registers are stored in regs */
135 if (regs->msr & MSR_FP)
138 /* save general and floating-point registers */
139 for (i = 0; i <= PT_RESULT; i ++)
140 err |= __put_user((unsigned int)gregs[i], &frame->mc_gregs[i]);
141 err |= __copy_to_user(&frame->mc_fregs, current->thread.fpr,
142 ELF_NFPREG * sizeof(double));
146 current->thread.fpscr = 0; /* turn off all fp exceptions */
148 #ifdef CONFIG_ALTIVEC
149 /* save altivec registers */
150 if (current->thread.used_vr) {
151 if (regs->msr & MSR_VEC)
152 giveup_altivec(current);
153 if (__copy_to_user(&frame->mc_vregs, current->thread.vr,
154 ELF_NVRREG32 * sizeof(vector128)))
156 /* set MSR_VEC in the saved MSR value to indicate that
157 frame->mc_vregs contains valid data */
158 if (__put_user(regs->msr | MSR_VEC, &frame->mc_gregs[PT_MSR]))
161 /* else assert((regs->msr & MSR_VEC) == 0) */
163 /* We always copy to/from vrsave, it's 0 if we don't have or don't
164 * use altivec. Since VSCR only contains 32 bits saved in the least
165 * significant bits of a vector, we "cheat" and stuff VRSAVE in the
166 * most significant bits of that same vector. --BenH
168 if (__put_user(current->thread.vrsave, (u32 *)&frame->mc_vregs[32]))
170 #endif /* CONFIG_ALTIVEC */
173 /* Set up the sigreturn trampoline: li r0,sigret; sc */
174 if (__put_user(0x38000000UL + sigret, &frame->tramp[0])
175 || __put_user(0x44000002UL, &frame->tramp[1]))
177 flush_icache_range((unsigned long) &frame->tramp[0],
178 (unsigned long) &frame->tramp[2]);
185 * Restore the current user register values from the user stack,
188 static long restore_user_regs(struct pt_regs *regs,
189 struct mcontext32 __user *sr, int sig)
191 elf_greg_t64 *gregs = (elf_greg_t64 *)regs;
194 unsigned int save_r2;
195 #ifdef CONFIG_ALTIVEC
200 * restore general registers but not including MSR or SOFTE. Also
201 * take care of keeping r2 (TLS) intact if not a signal
204 save_r2 = (unsigned int)regs->gpr[2];
205 for (i = 0; i <= PT_RESULT; i++) {
206 if ((i == PT_MSR) || (i == PT_SOFTE))
208 err |= __get_user(gregs[i], &sr->mc_gregs[i]);
211 regs->gpr[2] = (unsigned long) save_r2;
215 /* force the process to reload the FP registers from
216 current->thread when it next does FP instructions */
217 regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1);
218 if (__copy_from_user(current->thread.fpr, &sr->mc_fregs,
219 sizeof(sr->mc_fregs)))
222 #ifdef CONFIG_ALTIVEC
223 /* force the process to reload the altivec registers from
224 current->thread when it next does altivec instructions */
225 regs->msr &= ~MSR_VEC;
226 if (!__get_user(msr, &sr->mc_gregs[PT_MSR]) && (msr & MSR_VEC) != 0) {
227 /* restore altivec registers from the stack */
228 if (__copy_from_user(current->thread.vr, &sr->mc_vregs,
229 sizeof(sr->mc_vregs)))
231 } else if (current->thread.used_vr)
232 memset(¤t->thread.vr, 0, ELF_NVRREG32 * sizeof(vector128));
234 /* Always get VRSAVE back */
235 if (__get_user(current->thread.vrsave, (u32 *)&sr->mc_vregs[32]))
237 #endif /* CONFIG_ALTIVEC */
244 * Start of nonRT signal support
246 * sigset_t is 32 bits for non-rt signals
249 * sigaction sys32_sigaction
250 * sigreturn sys32_sigreturn
252 * Note sigsuspend has no special 32 bit routine - uses the 64 bit routine
259 * Atomically swap in the new signal mask, and wait for a signal.
261 long sys32_sigsuspend(old_sigset_t mask, int p2, int p3, int p4, int p6, int p7,
262 struct pt_regs *regs)
267 spin_lock_irq(¤t->sighand->siglock);
268 saveset = current->blocked;
269 siginitset(¤t->blocked, mask);
271 spin_unlock_irq(¤t->sighand->siglock);
273 regs->result = -EINTR;
274 regs->gpr[3] = EINTR;
275 regs->ccr |= 0x10000000;
277 current->state = TASK_INTERRUPTIBLE;
279 if (do_signal32(&saveset, regs))
281 * If a signal handler needs to be called,
282 * do_signal32() has set R3 to the signal number (the
283 * first argument of the signal handler), so don't
284 * overwrite that with EINTR !
285 * In the other cases, do_signal32() doesn't touch
286 * R3, so it's still set to -EINTR (see above).
292 long sys32_sigaction(int sig, struct old_sigaction32 *act,
293 struct old_sigaction32 *oact)
295 struct k_sigaction new_ka, old_ka;
302 compat_old_sigset_t mask;
304 if (get_user((long)new_ka.sa.sa_handler, &act->sa_handler) ||
305 __get_user((long)new_ka.sa.sa_restorer, &act->sa_restorer) ||
306 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
307 __get_user(mask, &act->sa_mask))
309 siginitset(&new_ka.sa.sa_mask, mask);
312 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
314 if (put_user((long)old_ka.sa.sa_handler, &oact->sa_handler) ||
315 __put_user((long)old_ka.sa.sa_restorer, &oact->sa_restorer) ||
316 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
317 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
327 * Start of RT signal support
329 * sigset_t is 64 bits for rt signals
332 * sigaction sys32_rt_sigaction
333 * sigpending sys32_rt_sigpending
334 * sigprocmask sys32_rt_sigprocmask
335 * sigreturn sys32_rt_sigreturn
336 * sigtimedwait sys32_rt_sigtimedwait
337 * sigqueueinfo sys32_rt_sigqueueinfo
338 * sigsuspend sys32_rt_sigsuspend
342 * copy_siginfo_to_user32
347 long sys32_rt_sigaction(int sig, const struct sigaction32 *act,
348 struct sigaction32 *oact, size_t sigsetsize)
350 struct k_sigaction new_ka, old_ka;
352 compat_sigset_t set32;
354 /* XXX: Don't preclude handling different sized sigset_t's. */
355 if (sigsetsize != sizeof(compat_sigset_t))
359 ret = get_user((long)new_ka.sa.sa_handler, &act->sa_handler);
360 ret |= __copy_from_user(&set32, &act->sa_mask,
361 sizeof(compat_sigset_t));
362 sigset_from_compat(&new_ka.sa.sa_mask, &set32);
363 ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
368 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
370 compat_from_sigset(&set32, &old_ka.sa.sa_mask);
371 ret = put_user((long)old_ka.sa.sa_handler, &oact->sa_handler);
372 ret |= __copy_to_user(&oact->sa_mask, &set32,
373 sizeof(compat_sigset_t));
374 ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
380 * Note: it is necessary to treat how as an unsigned int, with the
381 * corresponding cast to a signed int to insure that the proper
382 * conversion (sign extension) between the register representation
383 * of a signed int (msr in 32-bit mode) and the register representation
384 * of a signed int (msr in 64-bit mode) is performed.
386 long sys32_rt_sigprocmask(u32 how, compat_sigset_t *set,
387 compat_sigset_t *oset, size_t sigsetsize)
392 mm_segment_t old_fs = get_fs();
395 if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
397 sigset_from_compat(&s, &s32);
401 ret = sys_rt_sigprocmask((int)how, set ? &s : NULL, oset ? &s : NULL,
407 compat_from_sigset(&s32, &s);
408 if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
414 long sys32_rt_sigpending(compat_sigset_t *set, compat_size_t sigsetsize)
419 mm_segment_t old_fs = get_fs();
422 ret = sys_rt_sigpending(&s, sigsetsize);
425 compat_from_sigset(&s32, &s);
426 if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
433 static long copy_siginfo_to_user32(compat_siginfo_t *d, siginfo_t *s)
437 if (!access_ok (VERIFY_WRITE, d, sizeof(*d)))
440 /* If you change siginfo_t structure, please be sure
441 * this code is fixed accordingly.
442 * It should never copy any pad contained in the structure
443 * to avoid security leaks, but must copy the generic
444 * 3 ints plus the relevant union member.
445 * This routine must convert siginfo from 64bit to 32bit as well
448 err = __put_user(s->si_signo, &d->si_signo);
449 err |= __put_user(s->si_errno, &d->si_errno);
450 err |= __put_user((short)s->si_code, &d->si_code);
452 err |= __copy_to_user(&d->_sifields._pad, &s->_sifields._pad,
454 else switch(s->si_code >> 16) {
455 case __SI_CHLD >> 16:
456 err |= __put_user(s->si_pid, &d->si_pid);
457 err |= __put_user(s->si_uid, &d->si_uid);
458 err |= __put_user(s->si_utime, &d->si_utime);
459 err |= __put_user(s->si_stime, &d->si_stime);
460 err |= __put_user(s->si_status, &d->si_status);
462 case __SI_FAULT >> 16:
463 err |= __put_user((unsigned int)(unsigned long)s->si_addr,
466 case __SI_POLL >> 16:
467 case __SI_TIMER >> 16:
468 err |= __put_user(s->si_band, &d->si_band);
469 err |= __put_user(s->si_fd, &d->si_fd);
471 case __SI_RT >> 16: /* This is not generated by the kernel as of now. */
472 case __SI_MESGQ >> 16:
473 err |= __put_user(s->si_int, &d->si_int);
475 case __SI_KILL >> 16:
477 err |= __put_user(s->si_pid, &d->si_pid);
478 err |= __put_user(s->si_uid, &d->si_uid);
484 long sys32_rt_sigtimedwait(compat_sigset_t *uthese, compat_siginfo_t *uinfo,
485 struct compat_timespec *uts, compat_size_t sigsetsize)
491 mm_segment_t old_fs = get_fs();
494 if (copy_from_user(&s32, uthese, sizeof(compat_sigset_t)))
496 sigset_from_compat(&s, &s32);
497 if (uts && get_compat_timespec(&t, uts))
500 ret = sys_rt_sigtimedwait(&s, uinfo ? &info : NULL, uts ? &t : NULL,
503 if (ret >= 0 && uinfo) {
504 if (copy_siginfo_to_user32(uinfo, &info))
511 * Note: it is necessary to treat pid and sig as unsigned ints, with the
512 * corresponding cast to a signed int to insure that the proper conversion
513 * (sign extension) between the register representation of a signed int
514 * (msr in 32-bit mode) and the register representation of a signed int
515 * (msr in 64-bit mode) is performed.
517 long sys32_rt_sigqueueinfo(u32 pid, u32 sig, compat_siginfo_t *uinfo)
521 mm_segment_t old_fs = get_fs();
523 if (copy_from_user (&info, uinfo, 3*sizeof(int)) ||
524 copy_from_user (info._sifields._pad, uinfo->_sifields._pad, SI_PAD_SIZE32))
527 ret = sys_rt_sigqueueinfo((int)pid, (int)sig, &info);
532 int sys32_rt_sigsuspend(compat_sigset_t* unewset, size_t sigsetsize, int p3,
533 int p4, int p6, int p7, struct pt_regs *regs)
535 sigset_t saveset, newset;
538 /* XXX: Don't preclude handling different sized sigset_t's. */
539 if (sigsetsize != sizeof(sigset_t))
542 if (copy_from_user(&s32, unewset, sizeof(s32)))
546 * Swap the 2 words of the 64-bit sigset_t (they are stored
547 * in the "wrong" endian in 32-bit user storage).
549 sigset_from_compat(&newset, &s32);
551 sigdelsetmask(&newset, ~_BLOCKABLE);
552 spin_lock_irq(¤t->sighand->siglock);
553 saveset = current->blocked;
554 current->blocked = newset;
556 spin_unlock_irq(¤t->sighand->siglock);
558 regs->result = -EINTR;
559 regs->gpr[3] = EINTR;
560 regs->ccr |= 0x10000000;
562 current->state = TASK_INTERRUPTIBLE;
564 if (do_signal32(&saveset, regs))
566 * If a signal handler needs to be called,
567 * do_signal32() has set R3 to the signal number (the
568 * first argument of the signal handler), so don't
569 * overwrite that with EINTR !
570 * In the other cases, do_signal32() doesn't touch
571 * R3, so it's still set to -EINTR (see above).
578 * Start Alternate signal stack support
581 * sigaltatck sys32_sigaltstack
584 int sys32_sigaltstack(u32 newstack, u32 oldstack, int r5,
585 int r6, int r7, int r8, struct pt_regs *regs)
593 * set sp to the user stack on entry to the system call
594 * the system call router sets R9 to the saved registers
598 /* Put new stack info in local 64 bit stack struct */
600 (get_user((long)uss.ss_sp,
601 &((stack_32_t *)(long)newstack)->ss_sp) ||
602 __get_user(uss.ss_flags,
603 &((stack_32_t *)(long)newstack)->ss_flags) ||
604 __get_user(uss.ss_size,
605 &((stack_32_t *)(long)newstack)->ss_size)))
610 ret = do_sigaltstack(newstack ? &uss : NULL, oldstack ? &uoss : NULL,
613 /* Copy the stack information to the user output buffer */
614 if (!ret && oldstack &&
615 (put_user((long)uoss.ss_sp,
616 &((stack_32_t *)(long)oldstack)->ss_sp) ||
617 __put_user(uoss.ss_flags,
618 &((stack_32_t *)(long)oldstack)->ss_flags) ||
619 __put_user(uoss.ss_size,
620 &((stack_32_t *)(long)oldstack)->ss_size)))
627 * Set up a signal frame for a "real-time" signal handler
628 * (one which gets siginfo).
630 static void handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
631 siginfo_t *info, sigset_t *oldset,
632 struct pt_regs * regs, unsigned long newsp)
634 struct rt_sigframe32 __user *rt_sf;
635 struct mcontext32 __user *frame;
636 unsigned long origsp = newsp;
637 compat_sigset_t c_oldset;
639 /* Set up Signal Frame */
640 /* Put a Real Time Context onto stack */
641 newsp -= sizeof(*rt_sf);
642 rt_sf = (struct rt_sigframe32 __user *)newsp;
644 /* create a stack frame for the caller of the handler */
645 newsp -= __SIGNAL_FRAMESIZE32 + 16;
647 if (verify_area(VERIFY_WRITE, (void __user *)newsp, origsp - newsp))
650 compat_from_sigset(&c_oldset, oldset);
652 /* Put the siginfo & fill in most of the ucontext */
653 if (copy_siginfo_to_user32(&rt_sf->info, info)
654 || __put_user(0, &rt_sf->uc.uc_flags)
655 || __put_user(0, &rt_sf->uc.uc_link)
656 || __put_user(current->sas_ss_sp, &rt_sf->uc.uc_stack.ss_sp)
657 || __put_user(sas_ss_flags(regs->gpr[1]),
658 &rt_sf->uc.uc_stack.ss_flags)
659 || __put_user(current->sas_ss_size, &rt_sf->uc.uc_stack.ss_size)
660 || __put_user((u32)(u64)&rt_sf->uc.uc_mcontext, &rt_sf->uc.uc_regs)
661 || __copy_to_user(&rt_sf->uc.uc_sigmask, &c_oldset, sizeof(c_oldset)))
664 /* Save user registers on the stack */
665 frame = &rt_sf->uc.uc_mcontext;
666 if (save_user_regs(regs, frame, __NR_rt_sigreturn))
669 if (put_user(regs->gpr[1], (unsigned long __user *)newsp))
671 regs->gpr[1] = (unsigned long) newsp;
673 regs->gpr[4] = (unsigned long) &rt_sf->info;
674 regs->gpr[5] = (unsigned long) &rt_sf->uc;
675 regs->gpr[6] = (unsigned long) rt_sf;
676 regs->nip = (unsigned long) ka->sa.sa_handler;
677 regs->link = (unsigned long) frame->tramp;
685 printk("badframe in handle_rt_signal, regs=%p frame=%p newsp=%lx\n",
689 ka->sa.sa_handler = SIG_DFL;
690 force_sig(SIGSEGV, current);
693 static long do_setcontext32(struct ucontext32 __user *ucp, struct pt_regs *regs, int sig)
695 compat_sigset_t c_set;
699 if (__copy_from_user(&c_set, &ucp->uc_sigmask, sizeof(c_set))
700 || __get_user(mcp, &ucp->uc_regs))
702 sigset_from_compat(&set, &c_set);
703 restore_sigmask(&set);
704 if (restore_user_regs(regs, (struct mcontext32 *)(u64)mcp, sig))
711 * Handle {get,set,swap}_context operations for 32 bits processes
714 long sys32_swapcontext(struct ucontext32 __user *old_ctx,
715 struct ucontext32 __user *new_ctx,
716 int ctx_size, int r6, int r7, int r8, struct pt_regs *regs)
719 compat_sigset_t c_set;
721 /* Context size is for future use. Right now, we only make sure
722 * we are passed something we understand
724 if (ctx_size < sizeof(struct ucontext32))
727 if (old_ctx != NULL) {
728 compat_from_sigset(&c_set, ¤t->blocked);
729 if (verify_area(VERIFY_WRITE, old_ctx, sizeof(*old_ctx))
730 || save_user_regs(regs, &old_ctx->uc_mcontext, 0)
731 || __copy_to_user(&old_ctx->uc_sigmask, &c_set, sizeof(c_set))
732 || __put_user((u32)(u64)&old_ctx->uc_mcontext, &old_ctx->uc_regs))
737 if (verify_area(VERIFY_READ, new_ctx, sizeof(*new_ctx))
738 || __get_user(tmp, (u8 *) new_ctx)
739 || __get_user(tmp, (u8 *) (new_ctx + 1) - 1))
743 * If we get a fault copying the context into the kernel's
744 * image of the user's registers, we can't just return -EFAULT
745 * because the user's registers will be corrupted. For instance
746 * the NIP value may have been updated but not some of the
747 * other registers. Given that we have done the verify_area
748 * and successfully read the first and last bytes of the region
749 * above, this should only happen in an out-of-memory situation
750 * or if another thread unmaps the region containing the context.
751 * We kill the task with a SIGSEGV in this situation.
753 if (do_setcontext32(new_ctx, regs, 0))
759 long sys32_rt_sigreturn(int r3, int r4, int r5, int r6, int r7, int r8,
760 struct pt_regs *regs)
762 struct rt_sigframe32 __user *rt_sf;
766 /* Always make any pending restarted system calls return -EINTR */
767 current_thread_info()->restart_block.fn = do_no_restart_syscall;
769 rt_sf = (struct rt_sigframe32 __user *)
770 (regs->gpr[1] + __SIGNAL_FRAMESIZE32 + 16);
771 if (verify_area(VERIFY_READ, rt_sf, sizeof(*rt_sf)))
773 if (do_setcontext32(&rt_sf->uc, regs, 1))
777 * It's not clear whether or why it is desirable to save the
778 * sigaltstack setting on signal delivery and restore it on
779 * signal return. But other architectures do this and we have
780 * always done it up until now so it is probably better not to
781 * change it. -- paulus
782 * We use the sys32_ version that does the 32/64 bits conversion
783 * and takes userland pointer directly. What about error checking ?
786 sys32_sigaltstack((u32)(u64)&rt_sf->uc.uc_stack, 0, 0, 0, 0, 0, regs);
793 force_sig(SIGSEGV, current);
799 * OK, we're invoking a handler
801 static void handle_signal32(unsigned long sig, struct k_sigaction *ka,
802 siginfo_t *info, sigset_t *oldset,
803 struct pt_regs * regs, unsigned long newsp)
805 struct sigcontext32 __user *sc;
806 struct sigregs32 __user *frame;
807 unsigned long origsp = newsp;
809 /* Set up Signal Frame */
810 newsp -= sizeof(struct sigregs32);
811 frame = (struct sigregs32 __user *) newsp;
813 /* Put a sigcontext on the stack */
814 newsp -= sizeof(*sc);
815 sc = (struct sigcontext32 __user *) newsp;
817 /* create a stack frame for the caller of the handler */
818 newsp -= __SIGNAL_FRAMESIZE32;
820 if (verify_area(VERIFY_WRITE, (void *) newsp, origsp - newsp))
824 #error "Please adjust handle_signal32()"
826 if (__put_user((u32)(u64)ka->sa.sa_handler, &sc->handler)
827 || __put_user(oldset->sig[0], &sc->oldmask)
828 || __put_user((oldset->sig[0] >> 32), &sc->_unused[3])
829 || __put_user((u32)(u64)frame, &sc->regs)
830 || __put_user(sig, &sc->signal))
833 if (save_user_regs(regs, &frame->mctx, __NR_sigreturn))
836 if (put_user(regs->gpr[1], (unsigned long __user *)newsp))
838 regs->gpr[1] = (unsigned long) newsp;
840 regs->gpr[4] = (unsigned long) sc;
841 regs->nip = (unsigned long) ka->sa.sa_handler;
842 regs->link = (unsigned long) frame->mctx.tramp;
850 printk("badframe in handle_signal, regs=%p frame=%x newsp=%x\n",
851 regs, frame, *newspp);
854 ka->sa.sa_handler = SIG_DFL;
855 force_sig(SIGSEGV, current);
859 * Do a signal return; undo the signal stack.
861 long sys32_sigreturn(int r3, int r4, int r5, int r6, int r7, int r8,
862 struct pt_regs *regs)
864 struct sigcontext32 __user *sc;
865 struct sigcontext32 sigctx;
866 struct mcontext32 __user *sr;
870 /* Always make any pending restarted system calls return -EINTR */
871 current_thread_info()->restart_block.fn = do_no_restart_syscall;
873 sc = (struct sigcontext32 __user *)(regs->gpr[1] + __SIGNAL_FRAMESIZE32);
874 if (copy_from_user(&sigctx, sc, sizeof(sigctx)))
878 * Note that PPC32 puts the upper 32 bits of the sigmask in the
879 * unused part of the signal stackframe
881 set.sig[0] = sigctx.oldmask + ((long)(sigctx._unused[3]) << 32);
882 restore_sigmask(&set);
884 sr = (struct mcontext32 *)(u64)sigctx.regs;
885 if (verify_area(VERIFY_READ, sr, sizeof(*sr))
886 || restore_user_regs(regs, sr, 1))
893 force_sig(SIGSEGV, current);
900 * Start of do_signal32 routine
902 * This routine gets control when a pending signal needs to be processed
903 * in the 32 bit target thread -
905 * It handles both rt and non-rt signals
909 * Note that 'init' is a special process: it doesn't get signals it doesn't
910 * want to handle. Thus you cannot kill init even with a SIGKILL even by
914 int do_signal32(sigset_t *oldset, struct pt_regs *regs)
917 struct k_sigaction *ka;
918 unsigned int frame, newsp;
922 oldset = ¤t->blocked;
926 signr = get_signal_to_deliver(&info, regs, NULL);
928 ka = (signr == 0)? NULL: ¤t->sighand->action[signr-1];
930 if (regs->trap == 0x0C00 /* System Call! */
931 && regs->ccr & 0x10000000 /* error signalled */
932 && ((ret = regs->gpr[3]) == ERESTARTSYS
933 || ret == ERESTARTNOHAND || ret == ERESTARTNOINTR
934 || ret == ERESTART_RESTARTBLOCK)) {
937 && (ret == ERESTARTNOHAND || ret == ERESTART_RESTARTBLOCK
938 || (ret == ERESTARTSYS
939 && !(ka->sa.sa_flags & SA_RESTART)))) {
940 /* make the system call return an EINTR error */
941 regs->result = -EINTR;
942 regs->gpr[3] = EINTR;
943 /* note that the cr0.SO bit is already set */
945 regs->nip -= 4; /* Back up & retry system call */
948 if (ret == ERESTART_RESTARTBLOCK)
949 regs->gpr[0] = __NR_restart_syscall;
951 regs->gpr[3] = regs->orig_gpr3;
956 return 0; /* no signals delivered */
958 if ((ka->sa.sa_flags & SA_ONSTACK) && current->sas_ss_size
959 && (!on_sig_stack(regs->gpr[1])))
960 newsp = (current->sas_ss_sp + current->sas_ss_size);
962 newsp = regs->gpr[1];
965 /* Whee! Actually deliver the signal. */
966 if (ka->sa.sa_flags & SA_SIGINFO)
967 handle_rt_signal32(signr, ka, &info, oldset, regs, newsp);
969 handle_signal32(signr, ka, &info, oldset, regs, newsp);
971 if (ka->sa.sa_flags & SA_ONESHOT)
972 ka->sa.sa_handler = SIG_DFL;
974 if (!(ka->sa.sa_flags & SA_NODEFER)) {
975 spin_lock_irq(¤t->sighand->siglock);
976 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
977 sigaddset(¤t->blocked, signr);
979 spin_unlock_irq(¤t->sighand->siglock);