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 <asm/ptrace.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
22 #include <linux/file.h>
23 #include <linux/signal.h>
24 #include <linux/utime.h>
25 #include <linux/resource.h>
26 #include <linux/times.h>
27 #include <linux/utsname.h>
28 #include <linux/timex.h>
29 #include <linux/smp.h>
30 #include <linux/smp_lock.h>
31 #include <linux/sem.h>
32 #include <linux/msg.h>
33 #include <linux/shm.h>
34 #include <linux/slab.h>
35 #include <linux/uio.h>
36 #include <linux/nfs_fs.h>
37 #include <linux/smb_fs.h>
38 #include <linux/smb_mount.h>
39 #include <linux/ncp_fs.h>
40 #include <linux/quota.h>
41 #include <linux/module.h>
42 #include <linux/poll.h>
43 #include <linux/personality.h>
44 #include <linux/stat.h>
45 #include <linux/filter.h>
46 #include <asm/types.h>
48 #include <asm/uaccess.h>
49 #include <linux/elf.h>
50 #include <asm/ppc32.h>
51 #include <asm/ppcdebug.h>
52 #include <asm/unistd.h>
53 #include <asm/ucontext.h>
55 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
57 * These are the flags in the MSR that the user is allowed to change
58 * by modifying the saved value of the MSR on the stack. SE and BE
59 * should not be in this list since gdb may want to change these. I.e,
60 * you should be able to step out of a signal handler to see what
61 * instruction executes next after the signal handler completes.
62 * Alternately, if you stepped into a signal handler, you should be
63 * able to continue 'til the next breakpoint from within the signal
64 * handler, even if the handler returns.
66 #define MSR_USERCHANGE (MSR_FE0 | MSR_FE1)
75 * the gp_regs array is 32 bit representation of the pt_regs
76 * structure that was stored on the kernle stack during the
77 * system call that was interrupted for the signal.
79 * Note that the entire pt_regs regs structure will fit in
80 * the gp_regs structure because the ELF_NREG value is 48 for
81 * PPC and the pt_regs structure contains 44 registers
83 elf_gregset_t32 gp_regs;
84 double fp_regs[ELF_NFPREG];
85 unsigned int tramp[2];
87 * Programs using the rs6000/xcoff abi can save up to 19 gp
88 * regs and 18 fp regs below sp before decrementing it.
94 struct rt_sigframe_32 {
96 * Unused space at start of frame to allow for storing of
99 unsigned long _unused;
101 * This is a 32 bit pointer in user address space
102 * it is a pointer to the siginfo stucture in the rt stack frame
106 * This is a 32 bit pointer in user address space
107 * it is a pointer to the user context in the rt stack frame
110 struct siginfo32 info;
111 struct ucontext32 uc;
118 extern asmlinkage long sys_wait4(pid_t pid,unsigned int * stat_addr, int options, struct rusage * ru);
121 /****************************************************************************/
122 /* Start of nonRT signal support */
124 /* sigset_t is 32 bits for non-rt signals */
127 /* sigaction sys32_sigaction */
128 /* sigpending sys32_sigpending */
129 /* sigprocmask sys32_sigprocmask */
130 /* sigreturn sys32_sigreturn */
132 /* Note sigsuspend has no special 32 bit routine - uses the 64 bit routine */
137 /****************************************************************************/
140 asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 *act, struct old_sigaction32 *oact)
142 struct k_sigaction new_ka, old_ka;
145 PPCDBG(PPCDBG_SYS32, "sys32_sigaction - entered - pid=%ld current=%lx comm=%s\n", current->pid, current, current->comm);
153 ret = get_user((long)new_ka.sa.sa_handler, &act->sa_handler);
154 ret |= __get_user((long)new_ka.sa.sa_restorer, &act->sa_restorer);
155 ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
156 ret |= __get_user(mask, &act->sa_mask);
159 PPCDBG(PPCDBG_SIGNAL, "sys32_sigaction flags =%lx \n", new_ka.sa.sa_flags);
161 siginitset(&new_ka.sa.sa_mask, mask);
164 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
168 ret = put_user((long)old_ka.sa.sa_handler, &oact->sa_handler);
169 ret |= __put_user((long)old_ka.sa.sa_restorer, &oact->sa_restorer);
170 ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
171 ret |= __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
175 PPCDBG(PPCDBG_SYS32, "sys32_sigaction - exited - pid=%ld current=%lx comm=%s\n", current->pid, current, current->comm);
183 extern asmlinkage long sys_sigpending(old_sigset_t *set);
185 asmlinkage long sys32_sigpending(old_sigset_t32 *set)
189 mm_segment_t old_fs = get_fs();
191 PPCDBG(PPCDBG_SYS32, "sys32_sigpending - entered - pid=%ld current=%lx comm=%s\n", current->pid, current, current->comm);
194 ret = sys_sigpending(&s);
196 if (put_user (s, set)) return -EFAULT;
198 PPCDBG(PPCDBG_SYS32, "sys32_sigpending - exited - pid=%ld current=%lx comm=%s\n", current->pid, current, current->comm);
206 extern asmlinkage long sys_sigprocmask(int how, old_sigset_t *set, old_sigset_t *oset);
208 /* Note: it is necessary to treat how as an unsigned int,
209 * with the corresponding cast to a signed int to insure that the
210 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
211 * and the register representation of a signed int (msr in 64-bit mode) is performed.
213 asmlinkage long sys32_sigprocmask(u32 how, old_sigset_t32 *set, old_sigset_t32 *oset)
217 mm_segment_t old_fs = get_fs();
219 PPCDBG(PPCDBG_SYS32, "sys32_sigprocmask - entered - pid=%ld current=%lx comm=%s\n", current->pid, current, current->comm);
221 if (set && get_user(s, set))
224 ret = sys_sigprocmask((int)how, set ? &s : NULL, oset ? &s : NULL);
227 PPCDBG(PPCDBG_SYS32, "sys32_sigprocmask - exited - pid=%ld current=%lx comm=%s\n", current->pid, current, current->comm);
231 if (oset && put_user (s, oset))
239 * When we have signals to deliver, we set up on the
240 * user stack, going down from the original stack pointer:
242 * one or more sigcontext structs
243 * a gap of __SIGNAL_FRAMESIZE32 bytes
245 * Each of these things must be a multiple of 16 bytes in size.
251 * Do a signal return; undo the signal stack.
253 long sys32_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5,
254 unsigned long r6, unsigned long r7, unsigned long r8,
255 struct pt_regs *regs)
257 struct sigcontext32 *sc, sigctx;
258 struct sigregs32 *sr;
260 elf_gregset_t32 saved_regs; /* an array of ELF_NGREG unsigned ints (32 bits) */
265 PPCDBG(PPCDBG_SIGNAL, "sys32_sigreturn - entered - pid=%ld current=%lx comm=%s \n", current->pid, current, current->comm);
267 sc = (struct sigcontext32 *)(regs->gpr[1] + __SIGNAL_FRAMESIZE32);
268 if (copy_from_user(&sigctx, sc, sizeof(sigctx)))
272 * Note that PPC32 puts the upper 32 bits of the sigmask in the
273 * unused part of the signal stackframe
275 set.sig[0] = sigctx.oldmask + ((long)(sigctx._unused[3])<< 32);
276 sigdelsetmask(&set, ~_BLOCKABLE);
277 spin_lock_irq(¤t->sigmask_lock);
278 current->blocked = set;
279 recalc_sigpending(current);
280 spin_unlock_irq(¤t->sigmask_lock);
282 sc++; /* Look at next sigcontext */
283 /* If the next sigcontext is actually the sigregs (frame) */
284 /* - then no more sigcontexts on the user stack */
285 if (sc == (struct sigcontext32*)(u64)sigctx.regs)
287 /* Last stacked signal - restore registers */
288 sr = (struct sigregs32*)(u64)sigctx.regs;
289 if (regs->msr & MSR_FP )
292 * Copy the 32 bit register values off the user stack
293 * into the 32 bit register area
295 if (copy_from_user(saved_regs, &sr->gp_regs,sizeof(sr->gp_regs)))
298 * The saved reg structure in the frame is an elf_grepset_t32,
299 * it is a 32 bit register save of the registers in the
300 * pt_regs structure that was stored on the kernel stack
301 * during the system call when the system call was interrupted
302 * for the signal. Only 32 bits are saved because the
303 * sigcontext contains a pointer to the regs and the sig
304 * context address is passed as a pointer to the signal
307 * The entries in the elf_grepset have the same index as the
308 * elements in the pt_regs structure.
310 saved_regs[PT_MSR] = (regs->msr & ~MSR_USERCHANGE)
311 | (saved_regs[PT_MSR] & MSR_USERCHANGE);
313 * Register 2 is the kernel toc - should be reset on
314 * any calls into the kernel
316 for (i = 0; i < 32; i++)
317 regs->gpr[i] = (u64)(saved_regs[i]) & 0xFFFFFFFF;
320 * restore the non gpr registers
322 regs->msr = (u64)(saved_regs[PT_MSR]) & 0xFFFFFFFF;
324 * Insure that the interrupt mode is 64 bit, during 32 bit
325 * execution. (This is necessary because we only saved
326 * lower 32 bits of msr.)
328 regs->msr = regs->msr | MSR_ISF;
330 regs->nip = (u64)(saved_regs[PT_NIP]) & 0xFFFFFFFF;
331 regs->orig_gpr3 = (u64)(saved_regs[PT_ORIG_R3]) & 0xFFFFFFFF;
332 regs->ctr = (u64)(saved_regs[PT_CTR]) & 0xFFFFFFFF;
333 regs->link = (u64)(saved_regs[PT_LNK]) & 0xFFFFFFFF;
334 regs->xer = (u64)(saved_regs[PT_XER]) & 0xFFFFFFFF;
335 regs->ccr = (u64)(saved_regs[PT_CCR]) & 0xFFFFFFFF;
336 /* regs->softe is left unchanged (like the MSR.EE bit) */
337 /******************************************************/
338 /* the DAR and the DSISR are only relevant during a */
339 /* data or instruction storage interrupt. The value */
340 /* will be set to zero. */
341 /******************************************************/
344 regs->result = (u64)(saved_regs[PT_RESULT]) & 0xFFFFFFFF;
346 if (copy_from_user(current->thread.fpr, &sr->fp_regs, sizeof(sr->fp_regs)))
351 /* More signals to go */
352 regs->gpr[1] = (unsigned long)sc - __SIGNAL_FRAMESIZE32;
353 if (copy_from_user(&sigctx, sc, sizeof(sigctx)))
355 sr = (struct sigregs32*)(u64)sigctx.regs;
356 regs->gpr[3] = ret = sigctx.signal;
357 regs->gpr[4] = (unsigned long) sc;
358 regs->link = (unsigned long) &sr->tramp;
359 regs->nip = sigctx.handler;
361 if (get_user(prevsp, &sr->gp_regs[PT_R1])
362 || put_user(prevsp, (unsigned int*) regs->gpr[1]))
364 current->thread.fpscr = 0;
367 PPCDBG(PPCDBG_SIGNAL, "sys32_sigreturn - normal exit returning %ld - pid=%ld current=%lx comm=%s \n", ret, current->pid, current, current->comm);
371 PPCDBG(PPCDBG_SYS32NI, "sys32_sigreturn - badframe - pid=%ld current=%lx comm=%s \n", current->pid, current, current->comm);
376 * Set up a signal frame.
379 setup_frame32(struct pt_regs *regs, struct sigregs32 *frame,
382 struct sigcontext32 *sc = (struct sigcontext32 *)(u64)newsp;
385 if (verify_area(VERIFY_WRITE, frame, sizeof(*frame)))
387 if (regs->msr & MSR_FP)
391 * Copy the register contents for the pt_regs structure on the
392 * kernel stack to the elf_gregset_t32 structure on the user
393 * stack. This is a copy of 64 bit register values to 32 bit
394 * register values. The high order 32 bits of the 64 bit
395 * registers are not needed since a 32 bit application is
396 * running and the saved registers are the contents of the
397 * user registers at the time of a system call.
399 * The values saved on the user stack will be restored into
400 * the registers during the signal return processing
402 * Note the +1 is needed in order to get the lower 32 bits
405 for (i = 0; i < 32; i++) {
406 if (__copy_to_user(&frame->gp_regs[i], (u32*)(®s->gpr[i])+1, sizeof(u32)))
411 * Copy the non gpr registers to the user stack
413 if (__copy_to_user(&frame->gp_regs[PT_NIP], (u32*)(®s->gpr[PT_NIP])+1, sizeof(u32))
414 || __copy_to_user(&frame->gp_regs[PT_MSR], (u32*)(®s->gpr[PT_MSR])+1, sizeof(u32))
415 || __copy_to_user(&frame->gp_regs[PT_ORIG_R3], (u32*)(®s->gpr[PT_ORIG_R3])+1,
417 || __copy_to_user(&frame->gp_regs[PT_CTR], (u32*)(®s->gpr[PT_CTR])+1, sizeof(u32))
418 || __copy_to_user(&frame->gp_regs[PT_LNK], (u32*)(®s->gpr[PT_LNK])+1, sizeof(u32))
419 || __copy_to_user(&frame->gp_regs[PT_XER], (u32*)(®s->gpr[PT_XER])+1, sizeof(u32))
420 || __copy_to_user(&frame->gp_regs[PT_CCR], (u32*)(®s->gpr[PT_CCR])+1, sizeof(u32))
422 || __copy_to_user(&frame->gp_regs[PT_MQ], (u32*)(®s->gpr[PT_MQ])+1, sizeof(u32))
424 || __copy_to_user(&frame->gp_regs[PT_RESULT], (u32*)(®s->gpr[PT_RESULT])+1,
429 * Now copy the floating point registers onto the user stack
431 * Also set up so on the completion of the signal handler, the
432 * sys_sigreturn will get control to reset the stack
434 if (__copy_to_user(&frame->fp_regs, current->thread.fpr,
435 ELF_NFPREG * sizeof(double))
436 /* li r0, __NR_sigreturn */
437 || __put_user(0x38000000U + __NR_sigreturn, &frame->tramp[0])
439 || __put_user(0x44000002U, &frame->tramp[1]))
442 flush_icache_range((unsigned long) &frame->tramp[0],
443 (unsigned long) &frame->tramp[2]);
444 current->thread.fpscr = 0; /* turn off all fp exceptions */
446 newsp -= __SIGNAL_FRAMESIZE32;
447 if (put_user(regs->gpr[1], (u32*)(u64)newsp)
448 || get_user(regs->nip, &sc->handler)
449 || get_user(regs->gpr[3], &sc->signal))
452 regs->gpr[1] = newsp & 0xFFFFFFFF;
454 * first parameter to the signal handler is the signal number
455 * - the value is in gpr3
456 * second parameter to the signal handler is the sigcontext
457 * - set the value into gpr4
459 regs->gpr[4] = (unsigned long) sc;
460 regs->link = (unsigned long) frame->tramp;
464 udbg_printf("setup_frame32 - badframe in setup_frame, regs=%p frame=%p newsp=%lx\n", regs, frame, newsp); PPCDBG_ENTER_DEBUGGER();
466 printk("badframe in setup_frame32, regs=%p frame=%p newsp=%lx\n",
474 * Start of RT signal support
476 * sigset_t is 64 bits for rt signals
479 * sigaction sys32_rt_sigaction
480 * sigpending sys32_rt_sigpending
481 * sigprocmask sys32_rt_sigprocmask
482 * sigreturn sys32_rt_sigreturn
483 * sigtimedwait sys32_rt_sigtimedwait
484 * sigqueueinfo sys32_rt_sigqueueinfo
485 * sigsuspend sys32_rt_sigsuspend
489 * copy_siginfo_to_user32
495 * This code executes after the rt signal handler in 32 bit mode has
496 * completed and returned
498 long sys32_rt_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5,
499 unsigned long r6, unsigned long r7, unsigned long r8,
500 struct pt_regs * regs)
502 struct rt_sigframe_32 *rt_stack_frame;
503 struct sigcontext32 sigctx;
504 struct sigregs32 *signalregs;
507 elf_gregset_t32 saved_regs; /* an array of 32 bit register values */
510 unsigned int previous_stack;
513 /* Adjust the inputted reg1 to point to the first rt signal frame */
514 rt_stack_frame = (struct rt_sigframe_32 *)(regs->gpr[1] + __SIGNAL_FRAMESIZE32);
515 /* Copy the information from the user stack */
516 if (copy_from_user(&sigctx, &rt_stack_frame->uc.uc_mcontext,sizeof(sigctx))
517 || copy_from_user(&signal_set, &rt_stack_frame->uc.uc_sigmask,sizeof(signal_set))
518 || copy_from_user(&stack,&rt_stack_frame->uc.uc_stack,sizeof(stack)))
519 /* unable to copy from user storage */
523 * Unblock the signal that was processed
524 * After a signal handler runs -
525 * if the signal is blockable - the signal will be unblocked
526 * ( sigkill and sigstop are not blockable)
528 sigdelsetmask(&signal_set, ~_BLOCKABLE);
529 /* update the current based on the sigmask found in the rt_stackframe */
530 spin_lock_irq(¤t->sigmask_lock);
531 current->blocked = signal_set;
532 recalc_sigpending(current);
533 spin_unlock_irq(¤t->sigmask_lock);
535 /* Set to point to the next rt_sigframe - this is used to determine whether this
536 * is the last signal to process
540 if (rt_stack_frame == (struct rt_sigframe_32 *)(u64)(sigctx.regs)) {
541 signalregs = (struct sigregs32 *) (u64)sigctx.regs;
542 /* If currently owning the floating point - give them up */
543 if (regs->msr & MSR_FP)
546 if (copy_from_user(saved_regs,&signalregs->gp_regs,sizeof(signalregs->gp_regs)))
550 * The saved reg structure in the frame is an elf_grepset_t32,
551 * it is a 32 bit register save of the registers in the
552 * pt_regs structure that was stored on the kernel stack
553 * during the system call when the system call was interrupted
554 * for the signal. Only 32 bits are saved because the
555 * sigcontext contains a pointer to the regs and the sig
556 * context address is passed as a pointer to the signal handler
558 * The entries in the elf_grepset have the same index as
559 * the elements in the pt_regs structure.
561 saved_regs[PT_MSR] = (regs->msr & ~MSR_USERCHANGE)
562 | (saved_regs[PT_MSR] & MSR_USERCHANGE);
564 * Register 2 is the kernel toc - should be reset on any
565 * calls into the kernel
567 for (i = 0; i < 32; i++)
568 regs->gpr[i] = (u64)(saved_regs[i]) & 0xFFFFFFFF;
570 * restore the non gpr registers
572 regs->msr = (u64)(saved_regs[PT_MSR]) & 0xFFFFFFFF;
573 regs->nip = (u64)(saved_regs[PT_NIP]) & 0xFFFFFFFF;
574 regs->orig_gpr3 = (u64)(saved_regs[PT_ORIG_R3]) & 0xFFFFFFFF;
575 regs->ctr = (u64)(saved_regs[PT_CTR]) & 0xFFFFFFFF;
576 regs->link = (u64)(saved_regs[PT_LNK]) & 0xFFFFFFFF;
577 regs->xer = (u64)(saved_regs[PT_XER]) & 0xFFFFFFFF;
578 regs->ccr = (u64)(saved_regs[PT_CCR]) & 0xFFFFFFFF;
579 /* regs->softe is left unchanged (like MSR.EE) */
581 * the DAR and the DSISR are only relevant during a
582 * data or instruction storage interrupt. The value
583 * will be set to zero.
587 regs->result = (u64)(saved_regs[PT_RESULT]) & 0xFFFFFFFF;
589 if (copy_from_user(current->thread.fpr, &signalregs->fp_regs, sizeof(signalregs->fp_regs)))
594 else /* more signals to go */
596 regs->gpr[1] = (u64)rt_stack_frame - __SIGNAL_FRAMESIZE32;
597 if (copy_from_user(&sigctx, &rt_stack_frame->uc.uc_mcontext,sizeof(sigctx)))
601 signalregs = (struct sigregs32 *) (u64)sigctx.regs;
602 /* first parm to signal handler is the signal number */
603 regs->gpr[3] = ret = sigctx.signal;
604 /* second parm is a pointer to sig info */
605 get_user(regs->gpr[4], &rt_stack_frame->pinfo);
606 /* third parm is a pointer to the ucontext */
607 get_user(regs->gpr[5], &rt_stack_frame->puc);
608 /* fourth parm is the stack frame */
609 regs->gpr[6] = (u64)rt_stack_frame;
610 /* Set up link register to return to sigreturn when the */
611 /* signal handler completes */
612 regs->link = (u64)&signalregs->tramp;
613 /* Set next instruction to the start fo the signal handler */
614 regs->nip = sigctx.handler;
615 /* Set the reg1 to look like a call to the signal handler */
616 if (get_user(previous_stack,&signalregs->gp_regs[PT_R1])
617 || put_user(previous_stack, (unsigned long *)regs->gpr[1]))
621 current->thread.fpscr = 0;
633 asmlinkage long sys32_rt_sigaction(int sig, const struct sigaction32 *act, struct sigaction32 *oact, size_t sigsetsize)
635 struct k_sigaction new_ka, old_ka;
639 PPCDBG(PPCDBG_SIGNAL, "sys32_rt_sigaction - entered - sig=%x \n", sig);
641 /* XXX: Don't preclude handling different sized sigset_t's. */
642 if (sigsetsize != sizeof(sigset32_t))
646 ret = get_user((long)new_ka.sa.sa_handler, &act->sa_handler);
647 ret |= __copy_from_user(&set32, &act->sa_mask,
649 switch (_NSIG_WORDS) {
650 case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]
651 | (((long)set32.sig[7]) << 32);
652 case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]
653 | (((long)set32.sig[5]) << 32);
654 case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]
655 | (((long)set32.sig[3]) << 32);
656 case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]
657 | (((long)set32.sig[1]) << 32);
660 ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
666 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
669 switch (_NSIG_WORDS) {
671 set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
672 set32.sig[6] = old_ka.sa.sa_mask.sig[3];
674 set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
675 set32.sig[4] = old_ka.sa.sa_mask.sig[2];
677 set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
678 set32.sig[2] = old_ka.sa.sa_mask.sig[1];
680 set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
681 set32.sig[0] = old_ka.sa.sa_mask.sig[0];
683 ret = put_user((long)old_ka.sa.sa_handler, &oact->sa_handler);
684 ret |= __copy_to_user(&oact->sa_mask, &set32,
686 ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
690 PPCDBG(PPCDBG_SIGNAL, "sys32_rt_sigaction - exiting - sig=%x \n", sig);
695 extern asmlinkage long sys_rt_sigprocmask(int how, sigset_t *set, sigset_t *oset,
699 * Note: it is necessary to treat how as an unsigned int, with the
700 * corresponding cast to a signed int to insure that the proper
701 * conversion (sign extension) between the register representation
702 * of a signed int (msr in 32-bit mode) and the register representation
703 * of a signed int (msr in 64-bit mode) is performed.
705 asmlinkage long sys32_rt_sigprocmask(u32 how, sigset32_t *set, sigset32_t *oset, size_t sigsetsize)
710 mm_segment_t old_fs = get_fs();
712 PPCDBG(PPCDBG_SIGNAL, "sys32_rt_sigprocmask - entered how=%x \n", (int)how);
715 if (copy_from_user (&s32, set, sizeof(sigset32_t)))
718 switch (_NSIG_WORDS) {
719 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
720 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
721 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
722 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
727 ret = sys_rt_sigprocmask((int)how, set ? &s : NULL, oset ? &s : NULL,
733 switch (_NSIG_WORDS) {
734 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
735 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
736 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
737 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
739 if (copy_to_user (oset, &s32, sizeof(sigset32_t)))
746 extern asmlinkage long sys_rt_sigpending(sigset_t *set, size_t sigsetsize);
750 asmlinkage long sys32_rt_sigpending(sigset32_t *set, __kernel_size_t32 sigsetsize)
756 mm_segment_t old_fs = get_fs();
759 ret = sys_rt_sigpending(&s, sigsetsize);
762 switch (_NSIG_WORDS) {
763 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
764 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
765 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
766 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
768 if (copy_to_user (set, &s32, sizeof(sigset32_t)))
777 siginfo64to32(siginfo_t32 *d, siginfo_t *s)
779 memset (d, 0, sizeof(siginfo_t32));
780 d->si_signo = s->si_signo;
781 d->si_errno = s->si_errno;
782 d->si_code = s->si_code & 0xffff;
783 if (s->si_signo >= SIGRTMIN) {
784 d->si_pid = s->si_pid;
785 d->si_uid = s->si_uid;
787 d->si_int = s->si_int;
788 } else switch (s->si_signo) {
789 /* XXX: What about POSIX1.b timers */
791 d->si_pid = s->si_pid;
792 d->si_status = s->si_status;
793 d->si_utime = s->si_utime;
794 d->si_stime = s->si_stime;
800 d->si_addr = (long)(s->si_addr);
803 d->si_band = s->si_band;
807 d->si_pid = s->si_pid;
808 d->si_uid = s->si_uid;
814 extern asmlinkage long
815 sys_rt_sigtimedwait(const sigset_t *uthese, siginfo_t *uinfo,
816 const struct timespec *uts, size_t sigsetsize);
819 sys32_rt_sigtimedwait(sigset32_t *uthese, siginfo_t32 *uinfo,
820 struct timespec32 *uts, __kernel_size_t32 sigsetsize)
826 mm_segment_t old_fs = get_fs();
830 if (copy_from_user (&s32, uthese, sizeof(sigset32_t)))
832 switch (_NSIG_WORDS) {
833 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
834 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
835 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
836 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
839 ret = get_user (t.tv_sec, &uts->tv_sec);
840 ret |= __get_user (t.tv_nsec, &uts->tv_nsec);
846 ret = sys_rt_sigtimedwait(&s, &info, &t, sigsetsize);
848 ret = sys_rt_sigtimedwait(&s, &info, (struct timespec *)uts,
851 if (ret >= 0 && uinfo) {
852 if (copy_to_user (uinfo, siginfo64to32(&info32, &info),
853 sizeof(siginfo_t32)))
862 siginfo32to64(siginfo_t *d, siginfo_t32 *s)
864 d->si_signo = s->si_signo;
865 d->si_errno = s->si_errno;
866 d->si_code = s->si_code;
867 if (s->si_signo >= SIGRTMIN) {
868 d->si_pid = s->si_pid;
869 d->si_uid = s->si_uid;
870 d->si_int = s->si_int;
872 } else switch (s->si_signo) {
873 /* XXX: What about POSIX1.b timers */
875 d->si_pid = s->si_pid;
876 d->si_status = s->si_status;
877 d->si_utime = s->si_utime;
878 d->si_stime = s->si_stime;
884 d->si_addr = (void *)A(s->si_addr);
887 d->si_band = s->si_band;
891 d->si_pid = s->si_pid;
892 d->si_uid = s->si_uid;
899 extern asmlinkage long sys_rt_sigqueueinfo(int pid, int sig, siginfo_t *uinfo);
902 * Note: it is necessary to treat pid and sig as unsigned ints, with the
903 * corresponding cast to a signed int to insure that the proper conversion
904 * (sign extension) between the register representation of a signed int
905 * (msr in 32-bit mode) and the register representation of a signed int
906 * (msr in 64-bit mode) is performed.
908 asmlinkage long sys32_rt_sigqueueinfo(u32 pid, u32 sig, siginfo_t32 *uinfo)
913 mm_segment_t old_fs = get_fs();
915 if (copy_from_user (&info32, uinfo, sizeof(siginfo_t32)))
917 /* XXX: Is this correct? */
918 siginfo32to64(&info, &info32);
921 ret = sys_rt_sigqueueinfo((int)pid, (int)sig, &info);
927 int do_signal(sigset_t *oldset, struct pt_regs *regs);
928 int sys32_rt_sigsuspend(sigset32_t* unewset, size_t sigsetsize, int p3, int p4, int p6, int p7, struct pt_regs *regs)
930 sigset_t saveset, newset;
934 /* XXX: Don't preclude handling different sized sigset_t's. */
935 if (sigsetsize != sizeof(sigset_t))
938 if (copy_from_user(&s32, unewset, sizeof(s32)))
942 * Swap the 2 words of the 64-bit sigset_t (they are stored
943 * in the "wrong" endian in 32-bit user storage).
945 switch (_NSIG_WORDS) {
946 case 4: newset.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
947 case 3: newset.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
948 case 2: newset.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
949 case 1: newset.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
952 sigdelsetmask(&newset, ~_BLOCKABLE);
954 spin_lock_irq(¤t->sigmask_lock);
955 saveset = current->blocked;
956 current->blocked = newset;
957 recalc_sigpending(current);
958 spin_unlock_irq(¤t->sigmask_lock);
960 regs->result = -EINTR;
961 regs->gpr[3] = EINTR;
962 regs->ccr |= 0x10000000;
964 current->state = TASK_INTERRUPTIBLE;
966 if (do_signal(&saveset, regs))
968 * If a signal handler needs to be called,
969 * do_signal() has set R3 to the signal number (the
970 * first argument of the signal handler), so don't
971 * overwrite that with EINTR !
972 * In the other cases, do_signal() doesn't touch
973 * R3, so it's still set to -EINTR (see above).
981 * Set up a rt signal frame.
984 setup_rt_frame32(struct pt_regs *regs, struct sigregs32 *frame,
987 unsigned int copyreg4,copyreg5;
988 struct rt_sigframe_32 * rt_sf = (struct rt_sigframe_32 *) (u64)newsp;
991 if (verify_area(VERIFY_WRITE, frame, sizeof(*frame)))
993 if (regs->msr & MSR_FP)
997 * Copy the register contents for the pt_regs structure on the
998 * kernel stack to the elf_gregset_t32 structure on the user
999 * stack. This is a copy of 64 bit register values to 32 bit
1000 * register values. The high order 32 bits of the 64 bit
1001 * registers are not needed since a 32 bit application is
1002 * running and the saved registers are the contents of the
1003 * user registers at the time of a system call.
1005 * The values saved on the user stack will be restored into
1006 * the registers during the signal return processing.
1008 * Note the +1 is needed in order to get the lower 32 bits
1009 * of 64 bit register
1011 for (i = 0; i < 32; i++) {
1012 if (__copy_to_user(&frame->gp_regs[i], (u32*)(®s->gpr[i])+1, sizeof(u32)))
1017 * Copy the non gpr registers to the user stack
1019 if (__copy_to_user(&frame->gp_regs[PT_NIP], (u32*)(®s->gpr[PT_NIP])+1, sizeof(u32))
1020 || __copy_to_user(&frame->gp_regs[PT_MSR], (u32*)(®s->gpr[PT_MSR])+1, sizeof(u32))
1021 || __copy_to_user(&frame->gp_regs[PT_ORIG_R3], (u32*)(®s->gpr[PT_ORIG_R3])+1,
1023 || __copy_to_user(&frame->gp_regs[PT_CTR], (u32*)(®s->gpr[PT_CTR])+1, sizeof(u32))
1024 || __copy_to_user(&frame->gp_regs[PT_LNK], (u32*)(®s->gpr[PT_LNK])+1, sizeof(u32))
1025 || __copy_to_user(&frame->gp_regs[PT_XER], (u32*)(®s->gpr[PT_XER])+1, sizeof(u32))
1026 || __copy_to_user(&frame->gp_regs[PT_CCR], (u32*)(®s->gpr[PT_CCR])+1, sizeof(u32))
1027 || __copy_to_user(&frame->gp_regs[PT_RESULT], (u32*)(®s->gpr[PT_RESULT])+1,
1033 * Now copy the floating point registers onto the user stack
1035 * Also set up so on the completion of the signal handler, the
1036 * sys_sigreturn will get control to reset the stack
1038 if (__copy_to_user(&frame->fp_regs, current->thread.fpr,
1039 ELF_NFPREG * sizeof(double))
1040 || __put_user(0x38000000U + __NR_rt_sigreturn, &frame->tramp[0]) /* li r0, __NR_rt_sigreturn */
1041 || __put_user(0x44000002U, &frame->tramp[1])) /* sc */
1044 flush_icache_range((unsigned long) &frame->tramp[0],
1045 (unsigned long) &frame->tramp[2]);
1046 current->thread.fpscr = 0; /* turn off all fp exceptions */
1049 * Retrieve rt_sigframe from stack and
1050 * set up registers for signal handler
1052 newsp -= __SIGNAL_FRAMESIZE32;
1055 if (put_user((u32)(regs->gpr[1]), (unsigned int *)(u64)newsp)
1056 || get_user(regs->nip, &rt_sf->uc.uc_mcontext.handler)
1057 || get_user(regs->gpr[3], &rt_sf->uc.uc_mcontext.signal)
1058 || get_user(copyreg4, &rt_sf->pinfo)
1059 || get_user(copyreg5, &rt_sf->puc))
1062 regs->gpr[4] = copyreg4;
1063 regs->gpr[5] = copyreg5;
1064 regs->gpr[1] = newsp;
1065 regs->gpr[6] = (unsigned long) rt_sf;
1066 regs->link = (unsigned long) frame->tramp;
1071 udbg_printf("setup_frame32 - badframe in setup_frame, regs=%p frame=%p newsp=%lx\n", regs, frame, newsp); PPCDBG_ENTER_DEBUGGER();
1073 printk("badframe in setup_frame32, regs=%p frame=%p newsp=%lx\n",
1074 regs, frame, newsp);
1081 * OK, we're invoking a handler
1084 handle_signal32(unsigned long sig, struct k_sigaction *ka,
1085 siginfo_t *info, sigset_t *oldset, struct pt_regs * regs,
1086 unsigned int *newspp, unsigned int frame)
1088 struct sigcontext32 *sc;
1089 struct rt_sigframe_32 *rt_stack_frame;
1090 siginfo_t32 siginfo32bit;
1092 if (regs->trap == 0x0C00 /* System Call! */
1093 && ((int)regs->result == -ERESTARTNOHAND ||
1094 ((int)regs->result == -ERESTARTSYS &&
1095 !(ka->sa.sa_flags & SA_RESTART))))
1096 regs->result = -EINTR;
1098 /* Set up the signal frame */
1099 /* Determine if an real time frame - siginfo required */
1100 if (ka->sa.sa_flags & SA_SIGINFO)
1102 siginfo64to32(&siginfo32bit,info);
1103 *newspp -= sizeof(*rt_stack_frame);
1104 rt_stack_frame = (struct rt_sigframe_32 *) (u64)(*newspp) ;
1106 if (verify_area(VERIFY_WRITE, rt_stack_frame, sizeof(*rt_stack_frame)))
1110 if (__put_user((u32)(u64)ka->sa.sa_handler, &rt_stack_frame->uc.uc_mcontext.handler)
1111 || __put_user((u32)(u64)&rt_stack_frame->info, &rt_stack_frame->pinfo)
1112 || __put_user((u32)(u64)&rt_stack_frame->uc, &rt_stack_frame->puc)
1113 /* put the siginfo on the user stack */
1114 || __copy_to_user(&rt_stack_frame->info,&siginfo32bit,sizeof(siginfo32bit))
1115 /* set the ucontext on the user stack */
1116 || __put_user(0,&rt_stack_frame->uc.uc_flags)
1117 || __put_user(0,&rt_stack_frame->uc.uc_link)
1118 || __put_user(current->sas_ss_sp, &rt_stack_frame->uc.uc_stack.ss_sp)
1119 || __put_user(sas_ss_flags(regs->gpr[1]),
1120 &rt_stack_frame->uc.uc_stack.ss_flags)
1121 || __put_user(current->sas_ss_size, &rt_stack_frame->uc.uc_stack.ss_size)
1122 || __copy_to_user(&rt_stack_frame->uc.uc_sigmask, oldset,sizeof(*oldset))
1123 /* point the mcontext.regs to the pramble register frame */
1124 || __put_user(frame, &rt_stack_frame->uc.uc_mcontext.regs)
1125 || __put_user(sig,&rt_stack_frame->uc.uc_mcontext.signal))
1130 /* Put a sigcontext on the stack */
1131 *newspp -= sizeof(*sc);
1132 sc = (struct sigcontext32 *)(u64)*newspp;
1133 if (verify_area(VERIFY_WRITE, sc, sizeof(*sc)))
1136 * Note the upper 32 bits of the signal mask are stored
1137 * in the unused part of the signal stack frame
1139 if (__put_user((u32)(u64)ka->sa.sa_handler, &sc->handler)
1140 || __put_user(oldset->sig[0], &sc->oldmask)
1141 || __put_user((oldset->sig[0] >> 32), &sc->_unused[3])
1142 || __put_user((unsigned int)frame, &sc->regs)
1143 || __put_user(sig, &sc->signal))
1147 if (ka->sa.sa_flags & SA_ONESHOT)
1148 ka->sa.sa_handler = SIG_DFL;
1150 if (!(ka->sa.sa_flags & SA_NODEFER)) {
1151 spin_lock_irq(¤t->sigmask_lock);
1152 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
1153 sigaddset(¤t->blocked,sig);
1154 recalc_sigpending(current);
1155 spin_unlock_irq(¤t->sigmask_lock);
1162 printk("badframe in handle_signal32, regs=%p frame=%lx newsp=%lx\n",
1163 regs, frame, *newspp);
1164 printk("sc=%p sig=%d ka=%p info=%p oldset=%p\n", sc, sig, ka, info, oldset);
1171 * Start Alternate signal stack support
1174 * sigaltatck sys32_sigaltstack
1178 asmlinkage int sys32_sigaltstack(u32 newstack, u32 oldstack, int p3, int p4, int p6,
1179 int p7, struct pt_regs *regs)
1183 mm_segment_t old_fs;
1187 * set sp to the user stack on entry to the system call
1188 * the system call router sets R9 to the saved registers
1192 /* Put new stack info in local 64 bit stack struct */
1193 if (newstack && (get_user((long)uss.ss_sp, &((stack_32_t *)(long)newstack)->ss_sp) ||
1194 __get_user(uss.ss_flags, &((stack_32_t *)(long)newstack)->ss_flags) ||
1195 __get_user(uss.ss_size, &((stack_32_t *)(long)newstack)->ss_size)))
1201 ret = do_sigaltstack(newstack ? &uss : NULL, oldstack ? &uoss : NULL, sp);
1203 /* Copy the stack information to the user output buffer */
1204 if (!ret && oldstack && (put_user((long)uoss.ss_sp, &((stack_32_t *)(long)oldstack)->ss_sp) ||
1205 __put_user(uoss.ss_flags, &((stack_32_t *)(long)oldstack)->ss_flags) ||
1206 __put_user(uoss.ss_size, &((stack_32_t *)(long)oldstack)->ss_size)))
1214 * Start of do_signal32 routine
1216 * This routine gets control when a pending signal needs to be processed
1217 * in the 32 bit target thread -
1219 * It handles both rt and non-rt signals
1223 * Note that 'init' is a special process: it doesn't get signals it doesn't
1224 * want to handle. Thus you cannot kill init even with a SIGKILL even by
1228 int do_signal32(sigset_t *oldset, struct pt_regs *regs)
1231 struct k_sigaction *ka;
1232 unsigned int frame, newsp;
1235 oldset = ¤t->blocked;
1240 unsigned long signr;
1242 spin_lock_irq(¤t->sigmask_lock);
1243 signr = dequeue_signal(¤t->blocked, &info);
1244 spin_unlock_irq(¤t->sigmask_lock);
1245 ifppcdebug(PPCDBG_SYS32) {
1247 udbg_printf("do_signal32 - processing signal=%2lx - pid=%ld, comm=%s \n", signr, current->pid, current->comm);
1253 if ((current->ptrace & PT_PTRACED) && signr != SIGKILL) {
1254 /* Let the debugger run. */
1255 current->exit_code = signr;
1256 current->state = TASK_STOPPED;
1257 notify_parent(current, SIGCHLD);
1260 /* We're back. Did the debugger cancel the sig? */
1261 if (!(signr = current->exit_code))
1263 current->exit_code = 0;
1265 /* The debugger continued. Ignore SIGSTOP. */
1266 if (signr == SIGSTOP)
1269 /* Update the siginfo structure. Is this good? */
1270 if (signr != info.si_signo) {
1271 info.si_signo = signr;
1273 info.si_code = SI_USER;
1274 info.si_pid = current->p_pptr->pid;
1275 info.si_uid = current->p_pptr->uid;
1278 /* If the (new) signal is now blocked, requeue it. */
1279 if (sigismember(¤t->blocked, signr)) {
1280 send_sig_info(signr, &info, current);
1285 ka = ¤t->sig->action[signr-1];
1287 if (ka->sa.sa_handler == SIG_IGN) {
1288 if (signr != SIGCHLD)
1290 /* Check for SIGCHLD: it's special. */
1291 while (sys_wait4(-1, NULL, WNOHANG, NULL) > 0)
1296 if (ka->sa.sa_handler == SIG_DFL) {
1297 int exit_code = signr;
1299 /* Init gets no signals it doesn't want. */
1300 if (current->pid == 1)
1304 case SIGCONT: case SIGCHLD: case SIGWINCH: case SIGURG:
1307 case SIGTSTP: case SIGTTIN: case SIGTTOU:
1308 if (is_orphaned_pgrp(current->pgrp))
1313 current->state = TASK_STOPPED;
1314 current->exit_code = signr;
1315 if (!(current->p_pptr->sig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDSTOP))
1316 notify_parent(current, SIGCHLD);
1320 case SIGQUIT: case SIGILL: case SIGTRAP:
1321 case SIGABRT: case SIGFPE: case SIGSEGV:
1322 case SIGBUS: case SIGSYS: case SIGXCPU: case SIGXFSZ:
1323 if (do_coredump(signr, regs))
1328 sig_exit(signr, exit_code, &info);
1333 PPCDBG(PPCDBG_SIGNAL, " do signal :sigaction flags = %lx \n" ,ka->sa.sa_flags);
1334 PPCDBG(PPCDBG_SIGNAL, " do signal :on sig stack = %lx \n" ,on_sig_stack(regs->gpr[1]));
1335 PPCDBG(PPCDBG_SIGNAL, " do signal :reg1 = %lx \n" ,regs->gpr[1]);
1336 PPCDBG(PPCDBG_SIGNAL, " do signal :alt stack = %lx \n" ,current->sas_ss_sp);
1337 PPCDBG(PPCDBG_SIGNAL, " do signal :alt stack size = %lx \n" ,current->sas_ss_size);
1341 if ( (ka->sa.sa_flags & SA_ONSTACK)
1342 && (! on_sig_stack(regs->gpr[1])))
1343 newsp = (current->sas_ss_sp + current->sas_ss_size);
1345 newsp = regs->gpr[1];
1346 newsp = frame = newsp - sizeof(struct sigregs32);
1348 /* Whee! Actually deliver the signal. */
1349 handle_signal32(signr, ka, &info, oldset, regs, &newsp, frame);
1353 if (regs->trap == 0x0C00 /* System Call! */ &&
1354 ((int)regs->result == -ERESTARTNOHAND ||
1355 (int)regs->result == -ERESTARTSYS ||
1356 (int)regs->result == -ERESTARTNOINTR)) {
1357 regs->gpr[3] = regs->orig_gpr3;
1358 regs->nip -= 4; /* Back up & retry system call */
1363 return 0; /* no signals delivered */
1365 /* Invoke correct stack setup routine */
1366 if (ka->sa.sa_flags & SA_SIGINFO)
1367 setup_rt_frame32(regs, (struct sigregs32*)(u64)frame, newsp);
1369 setup_frame32(regs, (struct sigregs32*)(u64)frame, newsp);