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 /* Signal frames: the original one (compatible with SunOS):
40 * Set up a signal frame... Make the stack look the way SunOS
41 * expects it to look which is basically:
43 * ---------------------------------- <-- %sp at signal time
46 * Ptr to sigcontext area above
48 * The signal number itself
50 * ---------------------------------- <-- New %sp
52 struct signal_sframe {
53 struct reg_window sig_window;
56 struct sigcontext __user *sig_scptr;
58 struct sigcontext sig_context;
59 unsigned int extramask[_NSIG_WORDS - 1];
63 * And the new one, intended to be used for Linux applications only
64 * (we have enough in there to work with clone).
65 * All the interesting bits are in the info field.
68 struct new_signal_frame {
69 struct sparc_stackf ss;
71 __siginfo_fpu_t __user *fpu_save;
72 unsigned long insns[2] __attribute__ ((aligned (8)));
73 unsigned int extramask[_NSIG_WORDS - 1];
74 unsigned int extra_size; /* Should be 0 */
75 __siginfo_fpu_t fpu_state;
78 struct rt_signal_frame {
79 struct sparc_stackf ss;
83 __siginfo_fpu_t __user *fpu_save;
84 unsigned int insns[2];
86 unsigned int extra_size; /* Should be 0 */
87 __siginfo_fpu_t fpu_state;
91 #define SF_ALIGNEDSZ (((sizeof(struct signal_sframe) + 7) & (~7)))
92 #define NF_ALIGNEDSZ (((sizeof(struct new_signal_frame) + 7) & (~7)))
93 #define RT_ALIGNEDSZ (((sizeof(struct rt_signal_frame) + 7) & (~7)))
95 static int _sigpause_common(old_sigset_t set)
98 spin_lock_irq(¤t->sighand->siglock);
99 current->saved_sigmask = current->blocked;
100 siginitset(¤t->blocked, set);
102 spin_unlock_irq(¤t->sighand->siglock);
104 current->state = TASK_INTERRUPTIBLE;
106 set_thread_flag(TIF_RESTORE_SIGMASK);
108 return -ERESTARTNOHAND;
111 asmlinkage int sys_sigpause(unsigned int set)
113 return _sigpause_common(set);
116 asmlinkage int sys_sigsuspend(old_sigset_t set)
118 return _sigpause_common(set);
122 restore_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
126 if (test_tsk_thread_flag(current, TIF_USEDFPU))
127 regs->psr &= ~PSR_EF;
129 if (current == last_task_used_math) {
130 last_task_used_math = NULL;
131 regs->psr &= ~PSR_EF;
135 clear_tsk_thread_flag(current, TIF_USEDFPU);
137 if (!access_ok(VERIFY_READ, fpu, sizeof(*fpu)))
140 err = __copy_from_user(¤t->thread.float_regs[0], &fpu->si_float_regs[0],
141 (sizeof(unsigned long) * 32));
142 err |= __get_user(current->thread.fsr, &fpu->si_fsr);
143 err |= __get_user(current->thread.fpqdepth, &fpu->si_fpqdepth);
144 if (current->thread.fpqdepth != 0)
145 err |= __copy_from_user(¤t->thread.fpqueue[0],
147 ((sizeof(unsigned long) +
148 (sizeof(unsigned long *)))*16));
152 static inline void do_new_sigreturn (struct pt_regs *regs)
154 struct new_signal_frame __user *sf;
155 unsigned long up_psr, pc, npc;
157 __siginfo_fpu_t __user *fpu_save;
160 sf = (struct new_signal_frame __user *) regs->u_regs[UREG_FP];
162 /* 1. Make sure we are not getting garbage from the user */
163 if (!access_ok(VERIFY_READ, sf, sizeof(*sf)))
166 if (((unsigned long) sf) & 3)
169 err = __get_user(pc, &sf->info.si_regs.pc);
170 err |= __get_user(npc, &sf->info.si_regs.npc);
175 /* 2. Restore the state */
177 err |= __copy_from_user(regs, &sf->info.si_regs, sizeof(struct pt_regs));
179 /* User can only change condition codes and FPU enabling in %psr. */
180 regs->psr = (up_psr & ~(PSR_ICC | PSR_EF))
181 | (regs->psr & (PSR_ICC | PSR_EF));
183 err |= __get_user(fpu_save, &sf->fpu_save);
186 err |= restore_fpu_state(regs, fpu_save);
188 /* This is pretty much atomic, no amount locking would prevent
189 * the races which exist anyways.
191 err |= __get_user(set.sig[0], &sf->info.si_mask);
192 err |= __copy_from_user(&set.sig[1], &sf->extramask,
193 (_NSIG_WORDS-1) * sizeof(unsigned int));
198 sigdelsetmask(&set, ~_BLOCKABLE);
199 spin_lock_irq(¤t->sighand->siglock);
200 current->blocked = set;
202 spin_unlock_irq(¤t->sighand->siglock);
206 force_sig(SIGSEGV, current);
209 asmlinkage void do_sigreturn(struct pt_regs *regs)
211 struct sigcontext __user *scptr;
212 unsigned long pc, npc, psr;
216 /* Always make any pending restarted system calls return -EINTR */
217 current_thread_info()->restart_block.fn = do_no_restart_syscall;
219 synchronize_user_stack();
221 if (current->thread.new_signal) {
222 do_new_sigreturn(regs);
226 scptr = (struct sigcontext __user *) regs->u_regs[UREG_I0];
228 /* Check sanity of the user arg. */
229 if (!access_ok(VERIFY_READ, scptr, sizeof(struct sigcontext)) ||
230 (((unsigned long) scptr) & 3))
233 err = __get_user(pc, &scptr->sigc_pc);
234 err |= __get_user(npc, &scptr->sigc_npc);
239 /* This is pretty much atomic, no amount locking would prevent
240 * the races which exist anyways.
242 err |= __get_user(set.sig[0], &scptr->sigc_mask);
243 /* Note that scptr + 1 points to extramask */
244 err |= __copy_from_user(&set.sig[1], scptr + 1,
245 (_NSIG_WORDS - 1) * sizeof(unsigned int));
250 sigdelsetmask(&set, ~_BLOCKABLE);
251 spin_lock_irq(¤t->sighand->siglock);
252 current->blocked = set;
254 spin_unlock_irq(¤t->sighand->siglock);
259 err = __get_user(regs->u_regs[UREG_FP], &scptr->sigc_sp);
260 err |= __get_user(regs->u_regs[UREG_I0], &scptr->sigc_o0);
261 err |= __get_user(regs->u_regs[UREG_G1], &scptr->sigc_g1);
263 /* User can only change condition codes in %psr. */
264 err |= __get_user(psr, &scptr->sigc_psr);
268 regs->psr &= ~(PSR_ICC);
269 regs->psr |= (psr & PSR_ICC);
273 force_sig(SIGSEGV, current);
276 asmlinkage void do_rt_sigreturn(struct pt_regs *regs)
278 struct rt_signal_frame __user *sf;
279 unsigned int psr, pc, npc;
280 __siginfo_fpu_t __user *fpu_save;
286 synchronize_user_stack();
287 sf = (struct rt_signal_frame __user *) regs->u_regs[UREG_FP];
288 if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) ||
289 (((unsigned long) sf) & 0x03))
292 err = __get_user(pc, &sf->regs.pc);
293 err |= __get_user(npc, &sf->regs.npc);
294 err |= ((pc | npc) & 0x03);
296 err |= __get_user(regs->y, &sf->regs.y);
297 err |= __get_user(psr, &sf->regs.psr);
299 err |= __copy_from_user(®s->u_regs[UREG_G1],
300 &sf->regs.u_regs[UREG_G1], 15 * sizeof(u32));
302 regs->psr = (regs->psr & ~PSR_ICC) | (psr & PSR_ICC);
304 err |= __get_user(fpu_save, &sf->fpu_save);
307 err |= restore_fpu_state(regs, fpu_save);
308 err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t));
310 err |= __copy_from_user(&st, &sf->stack, sizeof(stack_t));
318 /* It is more difficult to avoid calling this function than to
319 * call it and ignore errors.
323 do_sigaltstack((const stack_t __user *) &st, NULL, (unsigned long)sf);
326 sigdelsetmask(&set, ~_BLOCKABLE);
327 spin_lock_irq(¤t->sighand->siglock);
328 current->blocked = set;
330 spin_unlock_irq(¤t->sighand->siglock);
333 force_sig(SIGSEGV, current);
336 /* Checks if the fp is valid */
337 static inline int invalid_frame_pointer(void __user *fp, int fplen)
339 if ((((unsigned long) fp) & 7) ||
340 !__access_ok((unsigned long)fp, fplen) ||
341 ((sparc_cpu_model == sun4 || sparc_cpu_model == sun4c) &&
342 ((unsigned long) fp < 0xe0000000 && (unsigned long) fp >= 0x20000000)))
348 static inline void __user *get_sigframe(struct sigaction *sa, struct pt_regs *regs, unsigned long framesize)
352 sp = regs->u_regs[UREG_FP];
354 /* This is the X/Open sanctioned signal stack switching. */
355 if (sa->sa_flags & SA_ONSTACK) {
356 if (!on_sig_stack(sp) && !((current->sas_ss_sp + current->sas_ss_size) & 7))
357 sp = current->sas_ss_sp + current->sas_ss_size;
359 return (void __user *)(sp - framesize);
363 setup_frame(struct sigaction *sa, struct pt_regs *regs, int signr, sigset_t *oldset, siginfo_t *info)
365 struct signal_sframe __user *sframep;
366 struct sigcontext __user *sc;
368 unsigned long pc = regs->pc;
369 unsigned long npc = regs->npc;
370 struct thread_info *tp = current_thread_info();
371 void __user *sig_address;
374 synchronize_user_stack();
375 sframep = (struct signal_sframe __user *)
376 get_sigframe(sa, regs, SF_ALIGNEDSZ);
377 if (invalid_frame_pointer(sframep, sizeof(*sframep))){
378 /* Don't change signal code and address, so that
379 * post mortem debuggers can have a look.
381 goto sigill_and_return;
384 sc = &sframep->sig_context;
386 /* We've already made sure frame pointer isn't in kernel space... */
387 err = __put_user((sas_ss_flags(regs->u_regs[UREG_FP]) == SS_ONSTACK),
389 err |= __put_user(oldset->sig[0], &sc->sigc_mask);
390 err |= __copy_to_user(sframep->extramask, &oldset->sig[1],
391 (_NSIG_WORDS - 1) * sizeof(unsigned int));
392 err |= __put_user(regs->u_regs[UREG_FP], &sc->sigc_sp);
393 err |= __put_user(pc, &sc->sigc_pc);
394 err |= __put_user(npc, &sc->sigc_npc);
395 err |= __put_user(regs->psr, &sc->sigc_psr);
396 err |= __put_user(regs->u_regs[UREG_G1], &sc->sigc_g1);
397 err |= __put_user(regs->u_regs[UREG_I0], &sc->sigc_o0);
398 err |= __put_user(tp->w_saved, &sc->sigc_oswins);
400 for (window = 0; window < tp->w_saved; window++) {
401 put_user((char *)tp->rwbuf_stkptrs[window],
402 &sc->sigc_spbuf[window]);
403 err |= __copy_to_user(&sc->sigc_wbuf[window],
404 &tp->reg_window[window],
405 sizeof(struct reg_window));
408 err |= __copy_to_user(sframep, (char *) regs->u_regs[UREG_FP],
409 sizeof(struct reg_window));
411 tp->w_saved = 0; /* So process is allowed to execute. */
413 err |= __put_user(signr, &sframep->sig_num);
416 if (SI_FROMKERNEL (info) && (info->si_code & __SI_MASK) == __SI_FAULT) {
417 sig_address = info->si_addr;
420 switch (info->si_code) {
421 case SEGV_MAPERR: sig_code = SUBSIG_NOMAPPING; break;
422 default: sig_code = SUBSIG_PROTECTION; break;
426 switch (info->si_code) {
427 case ILL_ILLOPC: sig_code = SUBSIG_ILLINST; break;
428 case ILL_PRVOPC: sig_code = SUBSIG_PRIVINST; break;
429 case ILL_ILLTRP: sig_code = SUBSIG_BADTRAP(info->si_trapno); break;
430 default: sig_code = SUBSIG_STACK; break;
434 switch (info->si_code) {
435 case FPE_INTDIV: sig_code = SUBSIG_IDIVZERO; break;
436 case FPE_INTOVF: sig_code = SUBSIG_FPINTOVFL; break;
437 case FPE_FLTDIV: sig_code = SUBSIG_FPDIVZERO; break;
438 case FPE_FLTOVF: sig_code = SUBSIG_FPOVFLOW; break;
439 case FPE_FLTUND: sig_code = SUBSIG_FPUNFLOW; break;
440 case FPE_FLTRES: sig_code = SUBSIG_FPINEXACT; break;
441 case FPE_FLTINV: sig_code = SUBSIG_FPOPERROR; break;
442 default: sig_code = SUBSIG_FPERROR; break;
446 switch (info->si_code) {
447 case BUS_ADRALN: sig_code = SUBSIG_ALIGNMENT; break;
448 case BUS_ADRERR: sig_code = SUBSIG_MISCERROR; break;
449 default: sig_code = SUBSIG_BUSTIMEOUT; break;
453 switch (info->si_code) {
454 case EMT_TAGOVF: sig_code = SUBSIG_TAG; break;
458 if (info->si_code == (__SI_FAULT|0x100)) {
459 /* See sys_sunos.c */
460 sig_code = info->si_trapno;
467 err |= __put_user((unsigned long)sig_address, &sframep->sig_address);
468 err |= __put_user(sig_code, &sframep->sig_code);
469 err |= __put_user(sc, &sframep->sig_scptr);
473 regs->u_regs[UREG_FP] = (unsigned long) sframep;
474 regs->pc = (unsigned long) sa->sa_handler;
475 regs->npc = (regs->pc + 4);
481 force_sigsegv(signr, current);
486 save_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
490 if (test_tsk_thread_flag(current, TIF_USEDFPU)) {
491 put_psr(get_psr() | PSR_EF);
492 fpsave(¤t->thread.float_regs[0], ¤t->thread.fsr,
493 ¤t->thread.fpqueue[0], ¤t->thread.fpqdepth);
494 regs->psr &= ~(PSR_EF);
495 clear_tsk_thread_flag(current, TIF_USEDFPU);
498 if (current == last_task_used_math) {
499 put_psr(get_psr() | PSR_EF);
500 fpsave(¤t->thread.float_regs[0], ¤t->thread.fsr,
501 ¤t->thread.fpqueue[0], ¤t->thread.fpqdepth);
502 last_task_used_math = NULL;
503 regs->psr &= ~(PSR_EF);
506 err |= __copy_to_user(&fpu->si_float_regs[0],
507 ¤t->thread.float_regs[0],
508 (sizeof(unsigned long) * 32));
509 err |= __put_user(current->thread.fsr, &fpu->si_fsr);
510 err |= __put_user(current->thread.fpqdepth, &fpu->si_fpqdepth);
511 if (current->thread.fpqdepth != 0)
512 err |= __copy_to_user(&fpu->si_fpqueue[0],
513 ¤t->thread.fpqueue[0],
514 ((sizeof(unsigned long) +
515 (sizeof(unsigned long *)))*16));
521 new_setup_frame(struct k_sigaction *ka, struct pt_regs *regs,
522 int signo, sigset_t *oldset)
524 struct new_signal_frame __user *sf;
525 int sigframe_size, err;
527 /* 1. Make sure everything is clean */
528 synchronize_user_stack();
530 sigframe_size = NF_ALIGNEDSZ;
532 sigframe_size -= sizeof(__siginfo_fpu_t);
534 sf = (struct new_signal_frame __user *)
535 get_sigframe(&ka->sa, regs, sigframe_size);
537 if (invalid_frame_pointer(sf, sigframe_size))
538 goto sigill_and_return;
540 if (current_thread_info()->w_saved != 0)
541 goto sigill_and_return;
543 /* 2. Save the current process state */
544 err = __copy_to_user(&sf->info.si_regs, regs, sizeof(struct pt_regs));
546 err |= __put_user(0, &sf->extra_size);
549 err |= save_fpu_state(regs, &sf->fpu_state);
550 err |= __put_user(&sf->fpu_state, &sf->fpu_save);
552 err |= __put_user(0, &sf->fpu_save);
555 err |= __put_user(oldset->sig[0], &sf->info.si_mask);
556 err |= __copy_to_user(sf->extramask, &oldset->sig[1],
557 (_NSIG_WORDS - 1) * sizeof(unsigned int));
558 err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP],
559 sizeof(struct reg_window));
563 /* 3. signal handler back-trampoline and parameters */
564 regs->u_regs[UREG_FP] = (unsigned long) sf;
565 regs->u_regs[UREG_I0] = signo;
566 regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
567 regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
569 /* 4. signal handler */
570 regs->pc = (unsigned long) ka->sa.sa_handler;
571 regs->npc = (regs->pc + 4);
573 /* 5. return to kernel instructions */
575 regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
577 regs->u_regs[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2);
579 /* mov __NR_sigreturn, %g1 */
580 err |= __put_user(0x821020d8, &sf->insns[0]);
583 err |= __put_user(0x91d02010, &sf->insns[1]);
587 /* Flush instruction space. */
588 flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
595 force_sigsegv(signo, current);
599 new_setup_rt_frame(struct k_sigaction *ka, struct pt_regs *regs,
600 int signo, sigset_t *oldset, siginfo_t *info)
602 struct rt_signal_frame __user *sf;
607 synchronize_user_stack();
608 sigframe_size = RT_ALIGNEDSZ;
610 sigframe_size -= sizeof(__siginfo_fpu_t);
611 sf = (struct rt_signal_frame __user *)
612 get_sigframe(&ka->sa, regs, sigframe_size);
613 if (invalid_frame_pointer(sf, sigframe_size))
615 if (current_thread_info()->w_saved != 0)
618 err = __put_user(regs->pc, &sf->regs.pc);
619 err |= __put_user(regs->npc, &sf->regs.npc);
620 err |= __put_user(regs->y, &sf->regs.y);
624 err |= __put_user(psr, &sf->regs.psr);
625 err |= __copy_to_user(&sf->regs.u_regs, regs->u_regs, sizeof(regs->u_regs));
626 err |= __put_user(0, &sf->extra_size);
629 err |= save_fpu_state(regs, &sf->fpu_state);
630 err |= __put_user(&sf->fpu_state, &sf->fpu_save);
632 err |= __put_user(0, &sf->fpu_save);
634 err |= __copy_to_user(&sf->mask, &oldset->sig[0], sizeof(sigset_t));
636 /* Setup sigaltstack */
637 err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp);
638 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &sf->stack.ss_flags);
639 err |= __put_user(current->sas_ss_size, &sf->stack.ss_size);
641 err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP],
642 sizeof(struct reg_window));
644 err |= copy_siginfo_to_user(&sf->info, info);
649 regs->u_regs[UREG_FP] = (unsigned long) sf;
650 regs->u_regs[UREG_I0] = signo;
651 regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
652 regs->u_regs[UREG_I2] = (unsigned long) &sf->regs;
654 regs->pc = (unsigned long) ka->sa.sa_handler;
655 regs->npc = (regs->pc + 4);
658 regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
660 regs->u_regs[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2);
662 /* mov __NR_sigreturn, %g1 */
663 err |= __put_user(0x821020d8, &sf->insns[0]);
666 err |= __put_user(0x91d02010, &sf->insns[1]);
670 /* Flush instruction space. */
671 flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
678 force_sigsegv(signo, current);
681 /* Setup a Solaris stack frame */
683 setup_svr4_frame(struct sigaction *sa, unsigned long pc, unsigned long npc,
684 struct pt_regs *regs, int signr, sigset_t *oldset)
686 svr4_signal_frame_t __user *sfp;
687 svr4_gregset_t __user *gr;
688 svr4_siginfo_t __user *si;
689 svr4_mcontext_t __user *mc;
690 svr4_gwindows_t __user *gw;
691 svr4_ucontext_t __user *uc;
693 struct thread_info *tp = current_thread_info();
696 synchronize_user_stack();
697 sfp = (svr4_signal_frame_t __user *)
698 get_sigframe(sa, regs, SVR4_SF_ALIGNED + sizeof(struct reg_window));
700 if (invalid_frame_pointer(sfp, sizeof(*sfp)))
701 goto sigill_and_return;
703 /* Start with a clean frame pointer and fill it */
704 err = __clear_user(sfp, sizeof(*sfp));
706 /* Setup convenience variables */
713 /* FIXME: where am I supposed to put this?
714 * sc->sigc_onstack = old_status;
715 * anyways, it does not look like it is used for anything at all.
717 setv.sigbits[0] = oldset->sig[0];
718 setv.sigbits[1] = oldset->sig[1];
719 if (_NSIG_WORDS >= 4) {
720 setv.sigbits[2] = oldset->sig[2];
721 setv.sigbits[3] = oldset->sig[3];
722 err |= __copy_to_user(&uc->sigmask, &setv, sizeof(svr4_sigset_t));
724 err |= __copy_to_user(&uc->sigmask, &setv,
725 2 * sizeof(unsigned int));
727 /* Store registers */
728 err |= __put_user(regs->pc, &((*gr)[SVR4_PC]));
729 err |= __put_user(regs->npc, &((*gr)[SVR4_NPC]));
730 err |= __put_user(regs->psr, &((*gr)[SVR4_PSR]));
731 err |= __put_user(regs->y, &((*gr)[SVR4_Y]));
733 /* Copy g[1..7] and o[0..7] registers */
734 err |= __copy_to_user(&(*gr)[SVR4_G1], ®s->u_regs[UREG_G1],
736 err |= __copy_to_user(&(*gr)[SVR4_O0], ®s->u_regs[UREG_I0],
739 /* Setup sigaltstack */
740 err |= __put_user(current->sas_ss_sp, &uc->stack.sp);
741 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &uc->stack.flags);
742 err |= __put_user(current->sas_ss_size, &uc->stack.size);
744 /* Save the currently window file: */
746 /* 1. Link sfp->uc->gwins to our windows */
747 err |= __put_user(gw, &mc->gwin);
749 /* 2. Number of windows to restore at setcontext(): */
750 err |= __put_user(tp->w_saved, &gw->count);
752 /* 3. Save each valid window
753 * Currently, it makes a copy of the windows from the kernel copy.
754 * David's code for SunOS, makes the copy but keeps the pointer to
755 * the kernel. My version makes the pointer point to a userland
756 * copy of those. Mhm, I wonder if I shouldn't just ignore those
757 * on setcontext and use those that are on the kernel, the signal
758 * handler should not be modyfing those, mhm.
760 * These windows are just used in case synchronize_user_stack failed
761 * to flush the user windows.
763 for (window = 0; window < tp->w_saved; window++) {
764 err |= __put_user((int __user *) &(gw->win[window]), &gw->winptr[window]);
765 err |= __copy_to_user(&gw->win[window],
766 &tp->reg_window[window],
767 sizeof(svr4_rwindow_t));
768 err |= __put_user(0, gw->winptr[window]);
771 /* 4. We just pay attention to the gw->count field on setcontext */
772 tp->w_saved = 0; /* So process is allowed to execute. */
774 /* Setup the signal information. Solaris expects a bunch of
775 * information to be passed to the signal handler, we don't provide
776 * that much currently, should use siginfo.
778 err |= __put_user(signr, &si->siginfo.signo);
779 err |= __put_user(SVR4_SINOINFO, &si->siginfo.code);
783 regs->u_regs[UREG_FP] = (unsigned long) sfp;
784 regs->pc = (unsigned long) sa->sa_handler;
785 regs->npc = (regs->pc + 4);
787 /* Arguments passed to signal handler */
788 if (regs->u_regs[14]){
789 struct reg_window __user *rw = (struct reg_window __user *)
792 err |= __put_user(signr, &rw->ins[0]);
793 err |= __put_user(si, &rw->ins[1]);
794 err |= __put_user(uc, &rw->ins[2]);
795 err |= __put_user(sfp, &rw->ins[6]); /* frame pointer */
799 regs->u_regs[UREG_I0] = signr;
800 regs->u_regs[UREG_I1] = (unsigned long) si;
801 regs->u_regs[UREG_I2] = (unsigned long) uc;
808 force_sigsegv(signr, current);
811 asmlinkage int svr4_getcontext(svr4_ucontext_t __user *uc, struct pt_regs *regs)
813 svr4_gregset_t __user *gr;
814 svr4_mcontext_t __user *mc;
818 synchronize_user_stack();
820 if (current_thread_info()->w_saved)
823 err = clear_user(uc, sizeof(*uc));
827 /* Setup convenience variables */
831 setv.sigbits[0] = current->blocked.sig[0];
832 setv.sigbits[1] = current->blocked.sig[1];
833 if (_NSIG_WORDS >= 4) {
834 setv.sigbits[2] = current->blocked.sig[2];
835 setv.sigbits[3] = current->blocked.sig[3];
836 err |= __copy_to_user(&uc->sigmask, &setv, sizeof(svr4_sigset_t));
838 err |= __copy_to_user(&uc->sigmask, &setv,
839 2 * sizeof(unsigned int));
841 /* Store registers */
842 err |= __put_user(regs->pc, &uc->mcontext.greg[SVR4_PC]);
843 err |= __put_user(regs->npc, &uc->mcontext.greg[SVR4_NPC]);
844 err |= __put_user(regs->psr, &uc->mcontext.greg[SVR4_PSR]);
845 err |= __put_user(regs->y, &uc->mcontext.greg[SVR4_Y]);
847 /* Copy g[1..7] and o[0..7] registers */
848 err |= __copy_to_user(&(*gr)[SVR4_G1], ®s->u_regs[UREG_G1],
850 err |= __copy_to_user(&(*gr)[SVR4_O0], ®s->u_regs[UREG_I0],
853 /* Setup sigaltstack */
854 err |= __put_user(current->sas_ss_sp, &uc->stack.sp);
855 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &uc->stack.flags);
856 err |= __put_user(current->sas_ss_size, &uc->stack.size);
858 /* The register file is not saved
859 * we have already stuffed all of it with sync_user_stack
861 return (err ? -EFAULT : 0);
864 /* Set the context for a svr4 application, this is Solaris way to sigreturn */
865 asmlinkage int svr4_setcontext(svr4_ucontext_t __user *c, struct pt_regs *regs)
867 svr4_gregset_t __user *gr;
868 unsigned long pc, npc, psr;
875 /* Fixme: restore windows, or is this already taken care of in
876 * svr4_setup_frame when sync_user_windows is done?
878 flush_user_windows();
880 if (current_thread_info()->w_saved)
881 goto sigsegv_and_return;
883 if (((unsigned long) c) & 3)
884 goto sigsegv_and_return;
886 if (!__access_ok((unsigned long)c, sizeof(*c)))
887 goto sigsegv_and_return;
889 /* Check for valid PC and nPC */
890 gr = &c->mcontext.greg;
891 err = __get_user(pc, &((*gr)[SVR4_PC]));
892 err |= __get_user(npc, &((*gr)[SVR4_NPC]));
895 goto sigsegv_and_return;
897 /* Retrieve information from passed ucontext */
898 /* note that nPC is ored a 1, this is used to inform entry.S */
899 /* that we don't want it to mess with our PC and nPC */
901 /* This is pretty much atomic, no amount locking would prevent
902 * the races which exist anyways.
904 err |= __copy_from_user(&setv, &c->sigmask, sizeof(svr4_sigset_t));
906 err |= __get_user(st.ss_sp, &c->stack.sp);
907 err |= __get_user(st.ss_flags, &c->stack.flags);
908 err |= __get_user(st.ss_size, &c->stack.size);
911 goto sigsegv_and_return;
913 /* It is more difficult to avoid calling this function than to
914 call it and ignore errors. */
917 do_sigaltstack((const stack_t __user *) &st, NULL,
918 regs->u_regs[UREG_I6]);
921 set.sig[0] = setv.sigbits[0];
922 set.sig[1] = setv.sigbits[1];
923 if (_NSIG_WORDS >= 4) {
924 set.sig[2] = setv.sigbits[2];
925 set.sig[3] = setv.sigbits[3];
927 sigdelsetmask(&set, ~_BLOCKABLE);
928 spin_lock_irq(¤t->sighand->siglock);
929 current->blocked = set;
931 spin_unlock_irq(¤t->sighand->siglock);
934 err |= __get_user(regs->y, &((*gr)[SVR4_Y]));
935 err |= __get_user(psr, &((*gr)[SVR4_PSR]));
936 regs->psr &= ~(PSR_ICC);
937 regs->psr |= (psr & PSR_ICC);
939 /* Restore g[1..7] and o[0..7] registers */
940 err |= __copy_from_user(®s->u_regs[UREG_G1], &(*gr)[SVR4_G1],
942 err |= __copy_from_user(®s->u_regs[UREG_I0], &(*gr)[SVR4_O0],
944 return (err ? -EFAULT : 0);
947 force_sig(SIGSEGV, current);
952 handle_signal(unsigned long signr, struct k_sigaction *ka,
953 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs,
957 setup_svr4_frame(&ka->sa, regs->pc, regs->npc, regs, signr, oldset);
959 if (ka->sa.sa_flags & SA_SIGINFO)
960 new_setup_rt_frame(ka, regs, signr, oldset, info);
961 else if (current->thread.new_signal)
962 new_setup_frame(ka, regs, signr, oldset);
964 setup_frame(&ka->sa, regs, signr, oldset, info);
966 spin_lock_irq(¤t->sighand->siglock);
967 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
968 if (!(ka->sa.sa_flags & SA_NOMASK))
969 sigaddset(¤t->blocked, signr);
971 spin_unlock_irq(¤t->sighand->siglock);
974 static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
975 struct sigaction *sa)
977 switch(regs->u_regs[UREG_I0]) {
978 case ERESTART_RESTARTBLOCK:
980 no_system_call_restart:
981 regs->u_regs[UREG_I0] = EINTR;
985 if (!(sa->sa_flags & SA_RESTART))
986 goto no_system_call_restart;
989 regs->u_regs[UREG_I0] = orig_i0;
995 /* Note that 'init' is a special process: it doesn't get signals it doesn't
996 * want to handle. Thus you cannot kill init even with a SIGKILL even by
999 asmlinkage void do_signal(struct pt_regs * regs, unsigned long orig_i0, int restart_syscall)
1002 struct sparc_deliver_cookie cookie;
1003 struct k_sigaction ka;
1008 * XXX Disable svr4 signal handling until solaris emulation works.
1009 * It is buggy - Anton
1011 #define SVR4_SIGNAL_BROKEN 1
1012 #ifdef SVR4_SIGNAL_BROKEN
1013 int svr4_signal = 0;
1015 int svr4_signal = current->personality == PER_SVR4;
1018 cookie.restart_syscall = restart_syscall;
1019 cookie.orig_i0 = orig_i0;
1021 if (test_thread_flag(TIF_RESTORE_SIGMASK))
1022 oldset = ¤t->saved_sigmask;
1024 oldset = ¤t->blocked;
1026 signr = get_signal_to_deliver(&info, &ka, regs, &cookie);
1028 if (cookie.restart_syscall)
1029 syscall_restart(cookie.orig_i0, regs, &ka.sa);
1030 handle_signal(signr, &ka, &info, oldset,
1032 /* a signal was successfully delivered; the saved
1033 * sigmask will have been stored in the signal frame,
1034 * and will be restored by sigreturn, so we can simply
1035 * clear the TIF_RESTORE_SIGMASK flag.
1037 if (test_thread_flag(TIF_RESTORE_SIGMASK))
1038 clear_thread_flag(TIF_RESTORE_SIGMASK);
1041 if (cookie.restart_syscall &&
1042 (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
1043 regs->u_regs[UREG_I0] == ERESTARTSYS ||
1044 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
1045 /* replay the system call when we are done */
1046 regs->u_regs[UREG_I0] = cookie.orig_i0;
1050 if (cookie.restart_syscall &&
1051 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
1052 regs->u_regs[UREG_G1] = __NR_restart_syscall;
1057 /* if there's no signal to deliver, we just put the saved sigmask
1060 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
1061 clear_thread_flag(TIF_RESTORE_SIGMASK);
1062 sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL);
1067 do_sys_sigstack(struct sigstack __user *ssptr, struct sigstack __user *ossptr,
1072 /* First see if old state is wanted. */
1074 if (put_user(current->sas_ss_sp + current->sas_ss_size,
1075 &ossptr->the_stack) ||
1076 __put_user(on_sig_stack(sp), &ossptr->cur_status))
1080 /* Now see if we want to update the new state. */
1084 if (get_user(ss_sp, &ssptr->the_stack))
1086 /* If the current stack was set with sigaltstack, don't
1087 swap stacks while we are on it. */
1089 if (current->sas_ss_sp && on_sig_stack(sp))
1092 /* Since we don't know the extent of the stack, and we don't
1093 track onstack-ness, but rather calculate it, we must
1094 presume a size. Ho hum this interface is lossy. */
1095 current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ;
1096 current->sas_ss_size = SIGSTKSZ;
1103 void ptrace_signal_deliver(struct pt_regs *regs, void *cookie)
1105 struct sparc_deliver_cookie *cp = cookie;
1107 if (cp->restart_syscall &&
1108 (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
1109 regs->u_regs[UREG_I0] == ERESTARTSYS ||
1110 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
1111 /* replay the system call when we are done */
1112 regs->u_regs[UREG_I0] = cp->orig_i0;
1115 cp->restart_syscall = 0;
1118 if (cp->restart_syscall &&
1119 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
1120 regs->u_regs[UREG_G1] = __NR_restart_syscall;
1123 cp->restart_syscall = 0;