1 /* $Id: signal.c,v 1.110 2002/02/08 03:57:14 davem Exp $
2 * linux/arch/sparc/kernel/signal.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
7 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
10 #include <linux/config.h>
11 #include <linux/sched.h>
12 #include <linux/kernel.h>
13 #include <linux/signal.h>
14 #include <linux/errno.h>
15 #include <linux/wait.h>
16 #include <linux/ptrace.h>
17 #include <linux/unistd.h>
19 #include <linux/tty.h>
20 #include <linux/smp.h>
21 #include <linux/smp_lock.h>
22 #include <linux/binfmts.h> /* do_coredum */
23 #include <linux/bitops.h>
25 #include <asm/uaccess.h>
26 #include <asm/ptrace.h>
28 #include <asm/pgalloc.h>
29 #include <asm/pgtable.h>
30 #include <asm/cacheflush.h> /* flush_sig_insns */
32 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
34 extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
35 void *fpqueue, unsigned long *fpqdepth);
36 extern void fpload(unsigned long *fpregs, unsigned long *fsr);
38 asmlinkage int do_signal(sigset_t *oldset, struct pt_regs * regs,
39 unsigned long orig_o0, int restart_syscall);
41 /* Signal frames: the original one (compatible with SunOS):
43 * Set up a signal frame... Make the stack look the way SunOS
44 * expects it to look which is basically:
46 * ---------------------------------- <-- %sp at signal time
49 * Ptr to sigcontext area above
51 * The signal number itself
53 * ---------------------------------- <-- New %sp
55 struct signal_sframe {
56 struct reg_window sig_window;
59 struct sigcontext __user *sig_scptr;
61 struct sigcontext sig_context;
62 unsigned int extramask[_NSIG_WORDS - 1];
66 * And the new one, intended to be used for Linux applications only
67 * (we have enough in there to work with clone).
68 * All the interesting bits are in the info field.
71 struct new_signal_frame {
72 struct sparc_stackf ss;
74 __siginfo_fpu_t __user *fpu_save;
75 unsigned long insns[2] __attribute__ ((aligned (8)));
76 unsigned int extramask[_NSIG_WORDS - 1];
77 unsigned int extra_size; /* Should be 0 */
78 __siginfo_fpu_t fpu_state;
81 struct rt_signal_frame {
82 struct sparc_stackf ss;
86 __siginfo_fpu_t __user *fpu_save;
87 unsigned int insns[2];
89 unsigned int extra_size; /* Should be 0 */
90 __siginfo_fpu_t fpu_state;
94 #define SF_ALIGNEDSZ (((sizeof(struct signal_sframe) + 7) & (~7)))
95 #define NF_ALIGNEDSZ (((sizeof(struct new_signal_frame) + 7) & (~7)))
96 #define RT_ALIGNEDSZ (((sizeof(struct rt_signal_frame) + 7) & (~7)))
99 * atomically swap in the new signal mask, and wait for a signal.
100 * This is really tricky on the Sparc, watch out...
102 asmlinkage void _sigpause_common(old_sigset_t set, struct pt_regs *regs)
107 spin_lock_irq(¤t->sighand->siglock);
108 saveset = current->blocked;
109 siginitset(¤t->blocked, set);
111 spin_unlock_irq(¤t->sighand->siglock);
113 regs->pc = regs->npc;
116 /* Condition codes and return value where set here for sigpause,
117 * and so got used by setup_frame, which again causes sigreturn()
121 current->state = TASK_INTERRUPTIBLE;
124 * Return -EINTR and set condition code here,
125 * so the interrupted system call actually returns
129 regs->u_regs[UREG_I0] = EINTR;
130 if (do_signal(&saveset, regs, 0, 0))
135 asmlinkage void do_sigpause(unsigned int set, struct pt_regs *regs)
137 _sigpause_common(set, regs);
140 asmlinkage void do_sigsuspend (struct pt_regs *regs)
142 _sigpause_common(regs->u_regs[UREG_I0], regs);
145 asmlinkage void do_rt_sigsuspend(sigset_t __user *uset, size_t sigsetsize,
146 struct pt_regs *regs)
148 sigset_t oldset, set;
150 /* XXX: Don't preclude handling different sized sigset_t's. */
151 if (sigsetsize != sizeof(sigset_t)) {
153 regs->u_regs[UREG_I0] = EINVAL;
157 if (copy_from_user(&set, uset, sizeof(set))) {
159 regs->u_regs[UREG_I0] = EFAULT;
163 sigdelsetmask(&set, ~_BLOCKABLE);
164 spin_lock_irq(¤t->sighand->siglock);
165 oldset = current->blocked;
166 current->blocked = set;
168 spin_unlock_irq(¤t->sighand->siglock);
170 regs->pc = regs->npc;
173 /* Condition codes and return value where set here for sigpause,
174 * and so got used by setup_frame, which again causes sigreturn()
178 current->state = TASK_INTERRUPTIBLE;
181 * Return -EINTR and set condition code here,
182 * so the interrupted system call actually returns
186 regs->u_regs[UREG_I0] = EINTR;
187 if (do_signal(&oldset, regs, 0, 0))
193 restore_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
197 if (test_tsk_thread_flag(current, TIF_USEDFPU))
198 regs->psr &= ~PSR_EF;
200 if (current == last_task_used_math) {
201 last_task_used_math = NULL;
202 regs->psr &= ~PSR_EF;
206 clear_tsk_thread_flag(current, TIF_USEDFPU);
208 if (!access_ok(VERIFY_READ, fpu, sizeof(*fpu)))
211 err = __copy_from_user(¤t->thread.float_regs[0], &fpu->si_float_regs[0],
212 (sizeof(unsigned long) * 32));
213 err |= __get_user(current->thread.fsr, &fpu->si_fsr);
214 err |= __get_user(current->thread.fpqdepth, &fpu->si_fpqdepth);
215 if (current->thread.fpqdepth != 0)
216 err |= __copy_from_user(¤t->thread.fpqueue[0],
218 ((sizeof(unsigned long) +
219 (sizeof(unsigned long *)))*16));
223 static inline void do_new_sigreturn (struct pt_regs *regs)
225 struct new_signal_frame __user *sf;
226 unsigned long up_psr, pc, npc;
228 __siginfo_fpu_t __user *fpu_save;
231 sf = (struct new_signal_frame __user *) regs->u_regs[UREG_FP];
233 /* 1. Make sure we are not getting garbage from the user */
234 if (!access_ok(VERIFY_READ, sf, sizeof(*sf)))
237 if (((unsigned long) sf) & 3)
240 err = __get_user(pc, &sf->info.si_regs.pc);
241 err |= __get_user(npc, &sf->info.si_regs.npc);
246 /* 2. Restore the state */
248 err |= __copy_from_user(regs, &sf->info.si_regs, sizeof(struct pt_regs));
250 /* User can only change condition codes and FPU enabling in %psr. */
251 regs->psr = (up_psr & ~(PSR_ICC | PSR_EF))
252 | (regs->psr & (PSR_ICC | PSR_EF));
254 err |= __get_user(fpu_save, &sf->fpu_save);
257 err |= restore_fpu_state(regs, fpu_save);
259 /* This is pretty much atomic, no amount locking would prevent
260 * the races which exist anyways.
262 err |= __get_user(set.sig[0], &sf->info.si_mask);
263 err |= __copy_from_user(&set.sig[1], &sf->extramask,
264 (_NSIG_WORDS-1) * sizeof(unsigned int));
269 sigdelsetmask(&set, ~_BLOCKABLE);
270 spin_lock_irq(¤t->sighand->siglock);
271 current->blocked = set;
273 spin_unlock_irq(¤t->sighand->siglock);
277 force_sig(SIGSEGV, current);
280 asmlinkage void do_sigreturn(struct pt_regs *regs)
282 struct sigcontext __user *scptr;
283 unsigned long pc, npc, psr;
287 /* Always make any pending restarted system calls return -EINTR */
288 current_thread_info()->restart_block.fn = do_no_restart_syscall;
290 synchronize_user_stack();
292 if (current->thread.new_signal) {
293 do_new_sigreturn(regs);
297 scptr = (struct sigcontext __user *) regs->u_regs[UREG_I0];
299 /* Check sanity of the user arg. */
300 if (!access_ok(VERIFY_READ, scptr, sizeof(struct sigcontext)) ||
301 (((unsigned long) scptr) & 3))
304 err = __get_user(pc, &scptr->sigc_pc);
305 err |= __get_user(npc, &scptr->sigc_npc);
310 /* This is pretty much atomic, no amount locking would prevent
311 * the races which exist anyways.
313 err |= __get_user(set.sig[0], &scptr->sigc_mask);
314 /* Note that scptr + 1 points to extramask */
315 err |= __copy_from_user(&set.sig[1], scptr + 1,
316 (_NSIG_WORDS - 1) * sizeof(unsigned int));
321 sigdelsetmask(&set, ~_BLOCKABLE);
322 spin_lock_irq(¤t->sighand->siglock);
323 current->blocked = set;
325 spin_unlock_irq(¤t->sighand->siglock);
330 err = __get_user(regs->u_regs[UREG_FP], &scptr->sigc_sp);
331 err |= __get_user(regs->u_regs[UREG_I0], &scptr->sigc_o0);
332 err |= __get_user(regs->u_regs[UREG_G1], &scptr->sigc_g1);
334 /* User can only change condition codes in %psr. */
335 err |= __get_user(psr, &scptr->sigc_psr);
339 regs->psr &= ~(PSR_ICC);
340 regs->psr |= (psr & PSR_ICC);
344 force_sig(SIGSEGV, current);
347 asmlinkage void do_rt_sigreturn(struct pt_regs *regs)
349 struct rt_signal_frame __user *sf;
350 unsigned int psr, pc, npc;
351 __siginfo_fpu_t __user *fpu_save;
357 synchronize_user_stack();
358 sf = (struct rt_signal_frame __user *) regs->u_regs[UREG_FP];
359 if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) ||
360 (((unsigned long) sf) & 0x03))
363 err = __get_user(pc, &sf->regs.pc);
364 err |= __get_user(npc, &sf->regs.npc);
365 err |= ((pc | npc) & 0x03);
367 err |= __get_user(regs->y, &sf->regs.y);
368 err |= __get_user(psr, &sf->regs.psr);
370 err |= __copy_from_user(®s->u_regs[UREG_G1],
371 &sf->regs.u_regs[UREG_G1], 15 * sizeof(u32));
373 regs->psr = (regs->psr & ~PSR_ICC) | (psr & PSR_ICC);
375 err |= __get_user(fpu_save, &sf->fpu_save);
378 err |= restore_fpu_state(regs, fpu_save);
379 err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t));
381 err |= __copy_from_user(&st, &sf->stack, sizeof(stack_t));
389 /* It is more difficult to avoid calling this function than to
390 * call it and ignore errors.
394 do_sigaltstack((const stack_t __user *) &st, NULL, (unsigned long)sf);
397 sigdelsetmask(&set, ~_BLOCKABLE);
398 spin_lock_irq(¤t->sighand->siglock);
399 current->blocked = set;
401 spin_unlock_irq(¤t->sighand->siglock);
404 force_sig(SIGSEGV, current);
407 /* Checks if the fp is valid */
408 static inline int invalid_frame_pointer(void __user *fp, int fplen)
410 if ((((unsigned long) fp) & 7) ||
411 !__access_ok((unsigned long)fp, fplen) ||
412 ((sparc_cpu_model == sun4 || sparc_cpu_model == sun4c) &&
413 ((unsigned long) fp < 0xe0000000 && (unsigned long) fp >= 0x20000000)))
419 static inline void __user *get_sigframe(struct sigaction *sa, struct pt_regs *regs, unsigned long framesize)
423 sp = regs->u_regs[UREG_FP];
425 /* This is the X/Open sanctioned signal stack switching. */
426 if (sa->sa_flags & SA_ONSTACK) {
427 if (!on_sig_stack(sp) && !((current->sas_ss_sp + current->sas_ss_size) & 7))
428 sp = current->sas_ss_sp + current->sas_ss_size;
430 return (void __user *)(sp - framesize);
434 setup_frame(struct sigaction *sa, struct pt_regs *regs, int signr, sigset_t *oldset, siginfo_t *info)
436 struct signal_sframe __user *sframep;
437 struct sigcontext __user *sc;
439 unsigned long pc = regs->pc;
440 unsigned long npc = regs->npc;
441 struct thread_info *tp = current_thread_info();
442 void __user *sig_address;
445 synchronize_user_stack();
446 sframep = (struct signal_sframe __user *)
447 get_sigframe(sa, regs, SF_ALIGNEDSZ);
448 if (invalid_frame_pointer(sframep, sizeof(*sframep))){
449 /* Don't change signal code and address, so that
450 * post mortem debuggers can have a look.
452 goto sigill_and_return;
455 sc = &sframep->sig_context;
457 /* We've already made sure frame pointer isn't in kernel space... */
458 err = __put_user((sas_ss_flags(regs->u_regs[UREG_FP]) == SS_ONSTACK),
460 err |= __put_user(oldset->sig[0], &sc->sigc_mask);
461 err |= __copy_to_user(sframep->extramask, &oldset->sig[1],
462 (_NSIG_WORDS - 1) * sizeof(unsigned int));
463 err |= __put_user(regs->u_regs[UREG_FP], &sc->sigc_sp);
464 err |= __put_user(pc, &sc->sigc_pc);
465 err |= __put_user(npc, &sc->sigc_npc);
466 err |= __put_user(regs->psr, &sc->sigc_psr);
467 err |= __put_user(regs->u_regs[UREG_G1], &sc->sigc_g1);
468 err |= __put_user(regs->u_regs[UREG_I0], &sc->sigc_o0);
469 err |= __put_user(tp->w_saved, &sc->sigc_oswins);
471 for (window = 0; window < tp->w_saved; window++) {
472 put_user((char *)tp->rwbuf_stkptrs[window],
473 &sc->sigc_spbuf[window]);
474 err |= __copy_to_user(&sc->sigc_wbuf[window],
475 &tp->reg_window[window],
476 sizeof(struct reg_window));
479 err |= __copy_to_user(sframep, (char *) regs->u_regs[UREG_FP],
480 sizeof(struct reg_window));
482 tp->w_saved = 0; /* So process is allowed to execute. */
484 err |= __put_user(signr, &sframep->sig_num);
487 if (SI_FROMKERNEL (info) && (info->si_code & __SI_MASK) == __SI_FAULT) {
488 sig_address = info->si_addr;
491 switch (info->si_code) {
492 case SEGV_MAPERR: sig_code = SUBSIG_NOMAPPING; break;
493 default: sig_code = SUBSIG_PROTECTION; break;
497 switch (info->si_code) {
498 case ILL_ILLOPC: sig_code = SUBSIG_ILLINST; break;
499 case ILL_PRVOPC: sig_code = SUBSIG_PRIVINST; break;
500 case ILL_ILLTRP: sig_code = SUBSIG_BADTRAP(info->si_trapno); break;
501 default: sig_code = SUBSIG_STACK; break;
505 switch (info->si_code) {
506 case FPE_INTDIV: sig_code = SUBSIG_IDIVZERO; break;
507 case FPE_INTOVF: sig_code = SUBSIG_FPINTOVFL; break;
508 case FPE_FLTDIV: sig_code = SUBSIG_FPDIVZERO; break;
509 case FPE_FLTOVF: sig_code = SUBSIG_FPOVFLOW; break;
510 case FPE_FLTUND: sig_code = SUBSIG_FPUNFLOW; break;
511 case FPE_FLTRES: sig_code = SUBSIG_FPINEXACT; break;
512 case FPE_FLTINV: sig_code = SUBSIG_FPOPERROR; break;
513 default: sig_code = SUBSIG_FPERROR; break;
517 switch (info->si_code) {
518 case BUS_ADRALN: sig_code = SUBSIG_ALIGNMENT; break;
519 case BUS_ADRERR: sig_code = SUBSIG_MISCERROR; break;
520 default: sig_code = SUBSIG_BUSTIMEOUT; break;
524 switch (info->si_code) {
525 case EMT_TAGOVF: sig_code = SUBSIG_TAG; break;
529 if (info->si_code == (__SI_FAULT|0x100)) {
530 /* See sys_sunos.c */
531 sig_code = info->si_trapno;
538 err |= __put_user((unsigned long)sig_address, &sframep->sig_address);
539 err |= __put_user(sig_code, &sframep->sig_code);
540 err |= __put_user(sc, &sframep->sig_scptr);
544 regs->u_regs[UREG_FP] = (unsigned long) sframep;
545 regs->pc = (unsigned long) sa->sa_handler;
546 regs->npc = (regs->pc + 4);
552 force_sigsegv(signr, current);
557 save_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
561 if (test_tsk_thread_flag(current, TIF_USEDFPU)) {
562 put_psr(get_psr() | PSR_EF);
563 fpsave(¤t->thread.float_regs[0], ¤t->thread.fsr,
564 ¤t->thread.fpqueue[0], ¤t->thread.fpqdepth);
565 regs->psr &= ~(PSR_EF);
566 clear_tsk_thread_flag(current, TIF_USEDFPU);
569 if (current == last_task_used_math) {
570 put_psr(get_psr() | PSR_EF);
571 fpsave(¤t->thread.float_regs[0], ¤t->thread.fsr,
572 ¤t->thread.fpqueue[0], ¤t->thread.fpqdepth);
573 last_task_used_math = NULL;
574 regs->psr &= ~(PSR_EF);
577 err |= __copy_to_user(&fpu->si_float_regs[0],
578 ¤t->thread.float_regs[0],
579 (sizeof(unsigned long) * 32));
580 err |= __put_user(current->thread.fsr, &fpu->si_fsr);
581 err |= __put_user(current->thread.fpqdepth, &fpu->si_fpqdepth);
582 if (current->thread.fpqdepth != 0)
583 err |= __copy_to_user(&fpu->si_fpqueue[0],
584 ¤t->thread.fpqueue[0],
585 ((sizeof(unsigned long) +
586 (sizeof(unsigned long *)))*16));
592 new_setup_frame(struct k_sigaction *ka, struct pt_regs *regs,
593 int signo, sigset_t *oldset)
595 struct new_signal_frame __user *sf;
596 int sigframe_size, err;
598 /* 1. Make sure everything is clean */
599 synchronize_user_stack();
601 sigframe_size = NF_ALIGNEDSZ;
603 sigframe_size -= sizeof(__siginfo_fpu_t);
605 sf = (struct new_signal_frame __user *)
606 get_sigframe(&ka->sa, regs, sigframe_size);
608 if (invalid_frame_pointer(sf, sigframe_size))
609 goto sigill_and_return;
611 if (current_thread_info()->w_saved != 0)
612 goto sigill_and_return;
614 /* 2. Save the current process state */
615 err = __copy_to_user(&sf->info.si_regs, regs, sizeof(struct pt_regs));
617 err |= __put_user(0, &sf->extra_size);
620 err |= save_fpu_state(regs, &sf->fpu_state);
621 err |= __put_user(&sf->fpu_state, &sf->fpu_save);
623 err |= __put_user(0, &sf->fpu_save);
626 err |= __put_user(oldset->sig[0], &sf->info.si_mask);
627 err |= __copy_to_user(sf->extramask, &oldset->sig[1],
628 (_NSIG_WORDS - 1) * sizeof(unsigned int));
629 err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP],
630 sizeof(struct reg_window));
634 /* 3. signal handler back-trampoline and parameters */
635 regs->u_regs[UREG_FP] = (unsigned long) sf;
636 regs->u_regs[UREG_I0] = signo;
637 regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
638 regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
640 /* 4. signal handler */
641 regs->pc = (unsigned long) ka->sa.sa_handler;
642 regs->npc = (regs->pc + 4);
644 /* 5. return to kernel instructions */
646 regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
648 regs->u_regs[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2);
650 /* mov __NR_sigreturn, %g1 */
651 err |= __put_user(0x821020d8, &sf->insns[0]);
654 err |= __put_user(0x91d02010, &sf->insns[1]);
658 /* Flush instruction space. */
659 flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
666 force_sigsegv(signo, current);
670 new_setup_rt_frame(struct k_sigaction *ka, struct pt_regs *regs,
671 int signo, sigset_t *oldset, siginfo_t *info)
673 struct rt_signal_frame __user *sf;
678 synchronize_user_stack();
679 sigframe_size = RT_ALIGNEDSZ;
681 sigframe_size -= sizeof(__siginfo_fpu_t);
682 sf = (struct rt_signal_frame __user *)
683 get_sigframe(&ka->sa, regs, sigframe_size);
684 if (invalid_frame_pointer(sf, sigframe_size))
686 if (current_thread_info()->w_saved != 0)
689 err = __put_user(regs->pc, &sf->regs.pc);
690 err |= __put_user(regs->npc, &sf->regs.npc);
691 err |= __put_user(regs->y, &sf->regs.y);
695 err |= __put_user(psr, &sf->regs.psr);
696 err |= __copy_to_user(&sf->regs.u_regs, regs->u_regs, sizeof(regs->u_regs));
697 err |= __put_user(0, &sf->extra_size);
700 err |= save_fpu_state(regs, &sf->fpu_state);
701 err |= __put_user(&sf->fpu_state, &sf->fpu_save);
703 err |= __put_user(0, &sf->fpu_save);
705 err |= __copy_to_user(&sf->mask, &oldset->sig[0], sizeof(sigset_t));
707 /* Setup sigaltstack */
708 err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp);
709 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &sf->stack.ss_flags);
710 err |= __put_user(current->sas_ss_size, &sf->stack.ss_size);
712 err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP],
713 sizeof(struct reg_window));
715 err |= copy_siginfo_to_user(&sf->info, info);
720 regs->u_regs[UREG_FP] = (unsigned long) sf;
721 regs->u_regs[UREG_I0] = signo;
722 regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
723 regs->u_regs[UREG_I2] = (unsigned long) &sf->regs;
725 regs->pc = (unsigned long) ka->sa.sa_handler;
726 regs->npc = (regs->pc + 4);
729 regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
731 regs->u_regs[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2);
733 /* mov __NR_sigreturn, %g1 */
734 err |= __put_user(0x821020d8, &sf->insns[0]);
737 err |= __put_user(0x91d02010, &sf->insns[1]);
741 /* Flush instruction space. */
742 flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
749 force_sigsegv(signo, current);
752 /* Setup a Solaris stack frame */
754 setup_svr4_frame(struct sigaction *sa, unsigned long pc, unsigned long npc,
755 struct pt_regs *regs, int signr, sigset_t *oldset)
757 svr4_signal_frame_t __user *sfp;
758 svr4_gregset_t __user *gr;
759 svr4_siginfo_t __user *si;
760 svr4_mcontext_t __user *mc;
761 svr4_gwindows_t __user *gw;
762 svr4_ucontext_t __user *uc;
764 struct thread_info *tp = current_thread_info();
767 synchronize_user_stack();
768 sfp = (svr4_signal_frame_t __user *)
769 get_sigframe(sa, regs, SVR4_SF_ALIGNED + sizeof(struct reg_window));
771 if (invalid_frame_pointer(sfp, sizeof(*sfp)))
772 goto sigill_and_return;
774 /* Start with a clean frame pointer and fill it */
775 err = __clear_user(sfp, sizeof(*sfp));
777 /* Setup convenience variables */
784 /* FIXME: where am I supposed to put this?
785 * sc->sigc_onstack = old_status;
786 * anyways, it does not look like it is used for anything at all.
788 setv.sigbits[0] = oldset->sig[0];
789 setv.sigbits[1] = oldset->sig[1];
790 if (_NSIG_WORDS >= 4) {
791 setv.sigbits[2] = oldset->sig[2];
792 setv.sigbits[3] = oldset->sig[3];
793 err |= __copy_to_user(&uc->sigmask, &setv, sizeof(svr4_sigset_t));
795 err |= __copy_to_user(&uc->sigmask, &setv,
796 2 * sizeof(unsigned int));
798 /* Store registers */
799 err |= __put_user(regs->pc, &((*gr)[SVR4_PC]));
800 err |= __put_user(regs->npc, &((*gr)[SVR4_NPC]));
801 err |= __put_user(regs->psr, &((*gr)[SVR4_PSR]));
802 err |= __put_user(regs->y, &((*gr)[SVR4_Y]));
804 /* Copy g[1..7] and o[0..7] registers */
805 err |= __copy_to_user(&(*gr)[SVR4_G1], ®s->u_regs[UREG_G1],
807 err |= __copy_to_user(&(*gr)[SVR4_O0], ®s->u_regs[UREG_I0],
810 /* Setup sigaltstack */
811 err |= __put_user(current->sas_ss_sp, &uc->stack.sp);
812 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &uc->stack.flags);
813 err |= __put_user(current->sas_ss_size, &uc->stack.size);
815 /* Save the currently window file: */
817 /* 1. Link sfp->uc->gwins to our windows */
818 err |= __put_user(gw, &mc->gwin);
820 /* 2. Number of windows to restore at setcontext(): */
821 err |= __put_user(tp->w_saved, &gw->count);
823 /* 3. Save each valid window
824 * Currently, it makes a copy of the windows from the kernel copy.
825 * David's code for SunOS, makes the copy but keeps the pointer to
826 * the kernel. My version makes the pointer point to a userland
827 * copy of those. Mhm, I wonder if I shouldn't just ignore those
828 * on setcontext and use those that are on the kernel, the signal
829 * handler should not be modyfing those, mhm.
831 * These windows are just used in case synchronize_user_stack failed
832 * to flush the user windows.
834 for (window = 0; window < tp->w_saved; window++) {
835 err |= __put_user((int __user *) &(gw->win[window]), &gw->winptr[window]);
836 err |= __copy_to_user(&gw->win[window],
837 &tp->reg_window[window],
838 sizeof(svr4_rwindow_t));
839 err |= __put_user(0, gw->winptr[window]);
842 /* 4. We just pay attention to the gw->count field on setcontext */
843 tp->w_saved = 0; /* So process is allowed to execute. */
845 /* Setup the signal information. Solaris expects a bunch of
846 * information to be passed to the signal handler, we don't provide
847 * that much currently, should use siginfo.
849 err |= __put_user(signr, &si->siginfo.signo);
850 err |= __put_user(SVR4_SINOINFO, &si->siginfo.code);
854 regs->u_regs[UREG_FP] = (unsigned long) sfp;
855 regs->pc = (unsigned long) sa->sa_handler;
856 regs->npc = (regs->pc + 4);
858 /* Arguments passed to signal handler */
859 if (regs->u_regs[14]){
860 struct reg_window __user *rw = (struct reg_window __user *)
863 err |= __put_user(signr, &rw->ins[0]);
864 err |= __put_user(si, &rw->ins[1]);
865 err |= __put_user(uc, &rw->ins[2]);
866 err |= __put_user(sfp, &rw->ins[6]); /* frame pointer */
870 regs->u_regs[UREG_I0] = signr;
871 regs->u_regs[UREG_I1] = (unsigned long) si;
872 regs->u_regs[UREG_I2] = (unsigned long) uc;
879 force_sigsegv(signr, current);
882 asmlinkage int svr4_getcontext(svr4_ucontext_t __user *uc, struct pt_regs *regs)
884 svr4_gregset_t __user *gr;
885 svr4_mcontext_t __user *mc;
889 synchronize_user_stack();
891 if (current_thread_info()->w_saved)
894 err = clear_user(uc, sizeof(*uc));
898 /* Setup convenience variables */
902 setv.sigbits[0] = current->blocked.sig[0];
903 setv.sigbits[1] = current->blocked.sig[1];
904 if (_NSIG_WORDS >= 4) {
905 setv.sigbits[2] = current->blocked.sig[2];
906 setv.sigbits[3] = current->blocked.sig[3];
907 err |= __copy_to_user(&uc->sigmask, &setv, sizeof(svr4_sigset_t));
909 err |= __copy_to_user(&uc->sigmask, &setv,
910 2 * sizeof(unsigned int));
912 /* Store registers */
913 err |= __put_user(regs->pc, &uc->mcontext.greg[SVR4_PC]);
914 err |= __put_user(regs->npc, &uc->mcontext.greg[SVR4_NPC]);
915 err |= __put_user(regs->psr, &uc->mcontext.greg[SVR4_PSR]);
916 err |= __put_user(regs->y, &uc->mcontext.greg[SVR4_Y]);
918 /* Copy g[1..7] and o[0..7] registers */
919 err |= __copy_to_user(&(*gr)[SVR4_G1], ®s->u_regs[UREG_G1],
921 err |= __copy_to_user(&(*gr)[SVR4_O0], ®s->u_regs[UREG_I0],
924 /* Setup sigaltstack */
925 err |= __put_user(current->sas_ss_sp, &uc->stack.sp);
926 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &uc->stack.flags);
927 err |= __put_user(current->sas_ss_size, &uc->stack.size);
929 /* The register file is not saved
930 * we have already stuffed all of it with sync_user_stack
932 return (err ? -EFAULT : 0);
935 /* Set the context for a svr4 application, this is Solaris way to sigreturn */
936 asmlinkage int svr4_setcontext(svr4_ucontext_t __user *c, struct pt_regs *regs)
938 svr4_gregset_t __user *gr;
939 unsigned long pc, npc, psr;
946 /* Fixme: restore windows, or is this already taken care of in
947 * svr4_setup_frame when sync_user_windows is done?
949 flush_user_windows();
951 if (current_thread_info()->w_saved)
952 goto sigsegv_and_return;
954 if (((unsigned long) c) & 3)
955 goto sigsegv_and_return;
957 if (!__access_ok((unsigned long)c, sizeof(*c)))
958 goto sigsegv_and_return;
960 /* Check for valid PC and nPC */
961 gr = &c->mcontext.greg;
962 err = __get_user(pc, &((*gr)[SVR4_PC]));
963 err |= __get_user(npc, &((*gr)[SVR4_NPC]));
966 goto sigsegv_and_return;
968 /* Retrieve information from passed ucontext */
969 /* note that nPC is ored a 1, this is used to inform entry.S */
970 /* that we don't want it to mess with our PC and nPC */
972 /* This is pretty much atomic, no amount locking would prevent
973 * the races which exist anyways.
975 err |= __copy_from_user(&setv, &c->sigmask, sizeof(svr4_sigset_t));
977 err |= __get_user(st.ss_sp, &c->stack.sp);
978 err |= __get_user(st.ss_flags, &c->stack.flags);
979 err |= __get_user(st.ss_size, &c->stack.size);
982 goto sigsegv_and_return;
984 /* It is more difficult to avoid calling this function than to
985 call it and ignore errors. */
988 do_sigaltstack((const stack_t __user *) &st, NULL,
989 regs->u_regs[UREG_I6]);
992 set.sig[0] = setv.sigbits[0];
993 set.sig[1] = setv.sigbits[1];
994 if (_NSIG_WORDS >= 4) {
995 set.sig[2] = setv.sigbits[2];
996 set.sig[3] = setv.sigbits[3];
998 sigdelsetmask(&set, ~_BLOCKABLE);
999 spin_lock_irq(¤t->sighand->siglock);
1000 current->blocked = set;
1001 recalc_sigpending();
1002 spin_unlock_irq(¤t->sighand->siglock);
1004 regs->npc = npc | 1;
1005 err |= __get_user(regs->y, &((*gr)[SVR4_Y]));
1006 err |= __get_user(psr, &((*gr)[SVR4_PSR]));
1007 regs->psr &= ~(PSR_ICC);
1008 regs->psr |= (psr & PSR_ICC);
1010 /* Restore g[1..7] and o[0..7] registers */
1011 err |= __copy_from_user(®s->u_regs[UREG_G1], &(*gr)[SVR4_G1],
1013 err |= __copy_from_user(®s->u_regs[UREG_I0], &(*gr)[SVR4_O0],
1015 return (err ? -EFAULT : 0);
1018 force_sig(SIGSEGV, current);
1023 handle_signal(unsigned long signr, struct k_sigaction *ka,
1024 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs,
1028 setup_svr4_frame(&ka->sa, regs->pc, regs->npc, regs, signr, oldset);
1030 if (ka->sa.sa_flags & SA_SIGINFO)
1031 new_setup_rt_frame(ka, regs, signr, oldset, info);
1032 else if (current->thread.new_signal)
1033 new_setup_frame(ka, regs, signr, oldset);
1035 setup_frame(&ka->sa, regs, signr, oldset, info);
1037 spin_lock_irq(¤t->sighand->siglock);
1038 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
1039 if (!(ka->sa.sa_flags & SA_NOMASK))
1040 sigaddset(¤t->blocked, signr);
1041 recalc_sigpending();
1042 spin_unlock_irq(¤t->sighand->siglock);
1045 static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
1046 struct sigaction *sa)
1048 switch(regs->u_regs[UREG_I0]) {
1049 case ERESTART_RESTARTBLOCK:
1050 case ERESTARTNOHAND:
1051 no_system_call_restart:
1052 regs->u_regs[UREG_I0] = EINTR;
1056 if (!(sa->sa_flags & SA_RESTART))
1057 goto no_system_call_restart;
1059 case ERESTARTNOINTR:
1060 regs->u_regs[UREG_I0] = orig_i0;
1066 /* Note that 'init' is a special process: it doesn't get signals it doesn't
1067 * want to handle. Thus you cannot kill init even with a SIGKILL even by
1070 asmlinkage int do_signal(sigset_t *oldset, struct pt_regs * regs,
1071 unsigned long orig_i0, int restart_syscall)
1074 struct sparc_deliver_cookie cookie;
1075 struct k_sigaction ka;
1079 * XXX Disable svr4 signal handling until solaris emulation works.
1080 * It is buggy - Anton
1082 #define SVR4_SIGNAL_BROKEN 1
1083 #ifdef SVR4_SIGNAL_BROKEN
1084 int svr4_signal = 0;
1086 int svr4_signal = current->personality == PER_SVR4;
1089 cookie.restart_syscall = restart_syscall;
1090 cookie.orig_i0 = orig_i0;
1093 oldset = ¤t->blocked;
1095 signr = get_signal_to_deliver(&info, &ka, regs, &cookie);
1097 if (cookie.restart_syscall)
1098 syscall_restart(cookie.orig_i0, regs, &ka.sa);
1099 handle_signal(signr, &ka, &info, oldset,
1103 if (cookie.restart_syscall &&
1104 (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
1105 regs->u_regs[UREG_I0] == ERESTARTSYS ||
1106 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
1107 /* replay the system call when we are done */
1108 regs->u_regs[UREG_I0] = cookie.orig_i0;
1112 if (cookie.restart_syscall &&
1113 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
1114 regs->u_regs[UREG_G1] = __NR_restart_syscall;
1122 do_sys_sigstack(struct sigstack __user *ssptr, struct sigstack __user *ossptr,
1127 /* First see if old state is wanted. */
1129 if (put_user(current->sas_ss_sp + current->sas_ss_size,
1130 &ossptr->the_stack) ||
1131 __put_user(on_sig_stack(sp), &ossptr->cur_status))
1135 /* Now see if we want to update the new state. */
1139 if (get_user(ss_sp, &ssptr->the_stack))
1141 /* If the current stack was set with sigaltstack, don't
1142 swap stacks while we are on it. */
1144 if (current->sas_ss_sp && on_sig_stack(sp))
1147 /* Since we don't know the extent of the stack, and we don't
1148 track onstack-ness, but rather calculate it, we must
1149 presume a size. Ho hum this interface is lossy. */
1150 current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ;
1151 current->sas_ss_size = SIGSTKSZ;
1158 void ptrace_signal_deliver(struct pt_regs *regs, void *cookie)
1160 struct sparc_deliver_cookie *cp = cookie;
1162 if (cp->restart_syscall &&
1163 (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
1164 regs->u_regs[UREG_I0] == ERESTARTSYS ||
1165 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
1166 /* replay the system call when we are done */
1167 regs->u_regs[UREG_I0] = cp->orig_i0;
1170 cp->restart_syscall = 0;
1173 if (cp->restart_syscall &&
1174 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
1175 regs->u_regs[UREG_G1] = __NR_restart_syscall;
1178 cp->restart_syscall = 0;