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/sched.h>
11 #include <linux/kernel.h>
12 #include <linux/signal.h>
13 #include <linux/errno.h>
14 #include <linux/wait.h>
15 #include <linux/ptrace.h>
16 #include <linux/unistd.h>
18 #include <linux/tty.h>
19 #include <linux/smp.h>
20 #include <linux/binfmts.h> /* do_coredum */
21 #include <linux/bitops.h>
23 #include <asm/uaccess.h>
24 #include <asm/ptrace.h>
26 #include <asm/pgalloc.h>
27 #include <asm/pgtable.h>
28 #include <asm/cacheflush.h> /* flush_sig_insns */
30 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
32 extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
33 void *fpqueue, unsigned long *fpqdepth);
34 extern void fpload(unsigned long *fpregs, unsigned long *fsr);
36 /* Signal frames: the original one (compatible with SunOS):
38 * Set up a signal frame... Make the stack look the way SunOS
39 * expects it to look which is basically:
41 * ---------------------------------- <-- %sp at signal time
44 * Ptr to sigcontext area above
46 * The signal number itself
48 * ---------------------------------- <-- New %sp
50 struct signal_sframe {
51 struct reg_window sig_window;
54 struct sigcontext __user *sig_scptr;
56 struct sigcontext sig_context;
57 unsigned int extramask[_NSIG_WORDS - 1];
61 * And the new one, intended to be used for Linux applications only
62 * (we have enough in there to work with clone).
63 * All the interesting bits are in the info field.
66 struct new_signal_frame {
67 struct sparc_stackf ss;
69 __siginfo_fpu_t __user *fpu_save;
70 unsigned long insns[2] __attribute__ ((aligned (8)));
71 unsigned int extramask[_NSIG_WORDS - 1];
72 unsigned int extra_size; /* Should be 0 */
73 __siginfo_fpu_t fpu_state;
76 struct rt_signal_frame {
77 struct sparc_stackf ss;
81 __siginfo_fpu_t __user *fpu_save;
82 unsigned int insns[2];
84 unsigned int extra_size; /* Should be 0 */
85 __siginfo_fpu_t fpu_state;
89 #define SF_ALIGNEDSZ (((sizeof(struct signal_sframe) + 7) & (~7)))
90 #define NF_ALIGNEDSZ (((sizeof(struct new_signal_frame) + 7) & (~7)))
91 #define RT_ALIGNEDSZ (((sizeof(struct rt_signal_frame) + 7) & (~7)))
93 static int _sigpause_common(old_sigset_t set)
96 spin_lock_irq(¤t->sighand->siglock);
97 current->saved_sigmask = current->blocked;
98 siginitset(¤t->blocked, set);
100 spin_unlock_irq(¤t->sighand->siglock);
102 current->state = TASK_INTERRUPTIBLE;
104 set_thread_flag(TIF_RESTORE_SIGMASK);
106 return -ERESTARTNOHAND;
109 asmlinkage int sys_sigpause(unsigned int set)
111 return _sigpause_common(set);
114 asmlinkage int sys_sigsuspend(old_sigset_t set)
116 return _sigpause_common(set);
120 restore_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
124 if (test_tsk_thread_flag(current, TIF_USEDFPU))
125 regs->psr &= ~PSR_EF;
127 if (current == last_task_used_math) {
128 last_task_used_math = NULL;
129 regs->psr &= ~PSR_EF;
133 clear_tsk_thread_flag(current, TIF_USEDFPU);
135 if (!access_ok(VERIFY_READ, fpu, sizeof(*fpu)))
138 err = __copy_from_user(¤t->thread.float_regs[0], &fpu->si_float_regs[0],
139 (sizeof(unsigned long) * 32));
140 err |= __get_user(current->thread.fsr, &fpu->si_fsr);
141 err |= __get_user(current->thread.fpqdepth, &fpu->si_fpqdepth);
142 if (current->thread.fpqdepth != 0)
143 err |= __copy_from_user(¤t->thread.fpqueue[0],
145 ((sizeof(unsigned long) +
146 (sizeof(unsigned long *)))*16));
150 static inline void do_new_sigreturn (struct pt_regs *regs)
152 struct new_signal_frame __user *sf;
153 unsigned long up_psr, pc, npc;
155 __siginfo_fpu_t __user *fpu_save;
158 sf = (struct new_signal_frame __user *) regs->u_regs[UREG_FP];
160 /* 1. Make sure we are not getting garbage from the user */
161 if (!access_ok(VERIFY_READ, sf, sizeof(*sf)))
164 if (((unsigned long) sf) & 3)
167 err = __get_user(pc, &sf->info.si_regs.pc);
168 err |= __get_user(npc, &sf->info.si_regs.npc);
173 /* 2. Restore the state */
175 err |= __copy_from_user(regs, &sf->info.si_regs, sizeof(struct pt_regs));
177 /* User can only change condition codes and FPU enabling in %psr. */
178 regs->psr = (up_psr & ~(PSR_ICC | PSR_EF))
179 | (regs->psr & (PSR_ICC | PSR_EF));
181 err |= __get_user(fpu_save, &sf->fpu_save);
184 err |= restore_fpu_state(regs, fpu_save);
186 /* This is pretty much atomic, no amount locking would prevent
187 * the races which exist anyways.
189 err |= __get_user(set.sig[0], &sf->info.si_mask);
190 err |= __copy_from_user(&set.sig[1], &sf->extramask,
191 (_NSIG_WORDS-1) * sizeof(unsigned int));
196 sigdelsetmask(&set, ~_BLOCKABLE);
197 spin_lock_irq(¤t->sighand->siglock);
198 current->blocked = set;
200 spin_unlock_irq(¤t->sighand->siglock);
204 force_sig(SIGSEGV, current);
207 asmlinkage void do_sigreturn(struct pt_regs *regs)
209 struct sigcontext __user *scptr;
210 unsigned long pc, npc, psr;
214 /* Always make any pending restarted system calls return -EINTR */
215 current_thread_info()->restart_block.fn = do_no_restart_syscall;
217 synchronize_user_stack();
219 if (current->thread.new_signal) {
220 do_new_sigreturn(regs);
224 scptr = (struct sigcontext __user *) regs->u_regs[UREG_I0];
226 /* Check sanity of the user arg. */
227 if (!access_ok(VERIFY_READ, scptr, sizeof(struct sigcontext)) ||
228 (((unsigned long) scptr) & 3))
231 err = __get_user(pc, &scptr->sigc_pc);
232 err |= __get_user(npc, &scptr->sigc_npc);
237 /* This is pretty much atomic, no amount locking would prevent
238 * the races which exist anyways.
240 err |= __get_user(set.sig[0], &scptr->sigc_mask);
241 /* Note that scptr + 1 points to extramask */
242 err |= __copy_from_user(&set.sig[1], scptr + 1,
243 (_NSIG_WORDS - 1) * sizeof(unsigned int));
248 sigdelsetmask(&set, ~_BLOCKABLE);
249 spin_lock_irq(¤t->sighand->siglock);
250 current->blocked = set;
252 spin_unlock_irq(¤t->sighand->siglock);
257 err = __get_user(regs->u_regs[UREG_FP], &scptr->sigc_sp);
258 err |= __get_user(regs->u_regs[UREG_I0], &scptr->sigc_o0);
259 err |= __get_user(regs->u_regs[UREG_G1], &scptr->sigc_g1);
261 /* User can only change condition codes in %psr. */
262 err |= __get_user(psr, &scptr->sigc_psr);
266 regs->psr &= ~(PSR_ICC);
267 regs->psr |= (psr & PSR_ICC);
271 force_sig(SIGSEGV, current);
274 asmlinkage void do_rt_sigreturn(struct pt_regs *regs)
276 struct rt_signal_frame __user *sf;
277 unsigned int psr, pc, npc;
278 __siginfo_fpu_t __user *fpu_save;
284 synchronize_user_stack();
285 sf = (struct rt_signal_frame __user *) regs->u_regs[UREG_FP];
286 if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) ||
287 (((unsigned long) sf) & 0x03))
290 err = __get_user(pc, &sf->regs.pc);
291 err |= __get_user(npc, &sf->regs.npc);
292 err |= ((pc | npc) & 0x03);
294 err |= __get_user(regs->y, &sf->regs.y);
295 err |= __get_user(psr, &sf->regs.psr);
297 err |= __copy_from_user(®s->u_regs[UREG_G1],
298 &sf->regs.u_regs[UREG_G1], 15 * sizeof(u32));
300 regs->psr = (regs->psr & ~PSR_ICC) | (psr & PSR_ICC);
302 err |= __get_user(fpu_save, &sf->fpu_save);
305 err |= restore_fpu_state(regs, fpu_save);
306 err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t));
308 err |= __copy_from_user(&st, &sf->stack, sizeof(stack_t));
316 /* It is more difficult to avoid calling this function than to
317 * call it and ignore errors.
321 do_sigaltstack((const stack_t __user *) &st, NULL, (unsigned long)sf);
324 sigdelsetmask(&set, ~_BLOCKABLE);
325 spin_lock_irq(¤t->sighand->siglock);
326 current->blocked = set;
328 spin_unlock_irq(¤t->sighand->siglock);
331 force_sig(SIGSEGV, current);
334 /* Checks if the fp is valid */
335 static inline int invalid_frame_pointer(void __user *fp, int fplen)
337 if ((((unsigned long) fp) & 7) ||
338 !__access_ok((unsigned long)fp, fplen) ||
339 ((sparc_cpu_model == sun4 || sparc_cpu_model == sun4c) &&
340 ((unsigned long) fp < 0xe0000000 && (unsigned long) fp >= 0x20000000)))
346 static inline void __user *get_sigframe(struct sigaction *sa, struct pt_regs *regs, unsigned long framesize)
350 sp = regs->u_regs[UREG_FP];
352 /* This is the X/Open sanctioned signal stack switching. */
353 if (sa->sa_flags & SA_ONSTACK) {
354 if (!on_sig_stack(sp) && !((current->sas_ss_sp + current->sas_ss_size) & 7))
355 sp = current->sas_ss_sp + current->sas_ss_size;
357 return (void __user *)(sp - framesize);
361 setup_frame(struct sigaction *sa, struct pt_regs *regs, int signr, sigset_t *oldset, siginfo_t *info)
363 struct signal_sframe __user *sframep;
364 struct sigcontext __user *sc;
366 unsigned long pc = regs->pc;
367 unsigned long npc = regs->npc;
368 struct thread_info *tp = current_thread_info();
369 void __user *sig_address;
372 synchronize_user_stack();
373 sframep = (struct signal_sframe __user *)
374 get_sigframe(sa, regs, SF_ALIGNEDSZ);
375 if (invalid_frame_pointer(sframep, sizeof(*sframep))){
376 /* Don't change signal code and address, so that
377 * post mortem debuggers can have a look.
379 goto sigill_and_return;
382 sc = &sframep->sig_context;
384 /* We've already made sure frame pointer isn't in kernel space... */
385 err = __put_user((sas_ss_flags(regs->u_regs[UREG_FP]) == SS_ONSTACK),
387 err |= __put_user(oldset->sig[0], &sc->sigc_mask);
388 err |= __copy_to_user(sframep->extramask, &oldset->sig[1],
389 (_NSIG_WORDS - 1) * sizeof(unsigned int));
390 err |= __put_user(regs->u_regs[UREG_FP], &sc->sigc_sp);
391 err |= __put_user(pc, &sc->sigc_pc);
392 err |= __put_user(npc, &sc->sigc_npc);
393 err |= __put_user(regs->psr, &sc->sigc_psr);
394 err |= __put_user(regs->u_regs[UREG_G1], &sc->sigc_g1);
395 err |= __put_user(regs->u_regs[UREG_I0], &sc->sigc_o0);
396 err |= __put_user(tp->w_saved, &sc->sigc_oswins);
398 for (window = 0; window < tp->w_saved; window++) {
399 put_user((char *)tp->rwbuf_stkptrs[window],
400 &sc->sigc_spbuf[window]);
401 err |= __copy_to_user(&sc->sigc_wbuf[window],
402 &tp->reg_window[window],
403 sizeof(struct reg_window));
406 err |= __copy_to_user(sframep, (char *) regs->u_regs[UREG_FP],
407 sizeof(struct reg_window));
409 tp->w_saved = 0; /* So process is allowed to execute. */
411 err |= __put_user(signr, &sframep->sig_num);
414 if (SI_FROMKERNEL (info) && (info->si_code & __SI_MASK) == __SI_FAULT) {
415 sig_address = info->si_addr;
418 switch (info->si_code) {
419 case SEGV_MAPERR: sig_code = SUBSIG_NOMAPPING; break;
420 default: sig_code = SUBSIG_PROTECTION; break;
424 switch (info->si_code) {
425 case ILL_ILLOPC: sig_code = SUBSIG_ILLINST; break;
426 case ILL_PRVOPC: sig_code = SUBSIG_PRIVINST; break;
427 case ILL_ILLTRP: sig_code = SUBSIG_BADTRAP(info->si_trapno); break;
428 default: sig_code = SUBSIG_STACK; break;
432 switch (info->si_code) {
433 case FPE_INTDIV: sig_code = SUBSIG_IDIVZERO; break;
434 case FPE_INTOVF: sig_code = SUBSIG_FPINTOVFL; break;
435 case FPE_FLTDIV: sig_code = SUBSIG_FPDIVZERO; break;
436 case FPE_FLTOVF: sig_code = SUBSIG_FPOVFLOW; break;
437 case FPE_FLTUND: sig_code = SUBSIG_FPUNFLOW; break;
438 case FPE_FLTRES: sig_code = SUBSIG_FPINEXACT; break;
439 case FPE_FLTINV: sig_code = SUBSIG_FPOPERROR; break;
440 default: sig_code = SUBSIG_FPERROR; break;
444 switch (info->si_code) {
445 case BUS_ADRALN: sig_code = SUBSIG_ALIGNMENT; break;
446 case BUS_ADRERR: sig_code = SUBSIG_MISCERROR; break;
447 default: sig_code = SUBSIG_BUSTIMEOUT; break;
451 switch (info->si_code) {
452 case EMT_TAGOVF: sig_code = SUBSIG_TAG; break;
456 if (info->si_code == (__SI_FAULT|0x100)) {
457 /* See sys_sunos.c */
458 sig_code = info->si_trapno;
465 err |= __put_user((unsigned long)sig_address, &sframep->sig_address);
466 err |= __put_user(sig_code, &sframep->sig_code);
467 err |= __put_user(sc, &sframep->sig_scptr);
471 regs->u_regs[UREG_FP] = (unsigned long) sframep;
472 regs->pc = (unsigned long) sa->sa_handler;
473 regs->npc = (regs->pc + 4);
479 force_sigsegv(signr, current);
484 save_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
488 if (test_tsk_thread_flag(current, TIF_USEDFPU)) {
489 put_psr(get_psr() | PSR_EF);
490 fpsave(¤t->thread.float_regs[0], ¤t->thread.fsr,
491 ¤t->thread.fpqueue[0], ¤t->thread.fpqdepth);
492 regs->psr &= ~(PSR_EF);
493 clear_tsk_thread_flag(current, TIF_USEDFPU);
496 if (current == last_task_used_math) {
497 put_psr(get_psr() | PSR_EF);
498 fpsave(¤t->thread.float_regs[0], ¤t->thread.fsr,
499 ¤t->thread.fpqueue[0], ¤t->thread.fpqdepth);
500 last_task_used_math = NULL;
501 regs->psr &= ~(PSR_EF);
504 err |= __copy_to_user(&fpu->si_float_regs[0],
505 ¤t->thread.float_regs[0],
506 (sizeof(unsigned long) * 32));
507 err |= __put_user(current->thread.fsr, &fpu->si_fsr);
508 err |= __put_user(current->thread.fpqdepth, &fpu->si_fpqdepth);
509 if (current->thread.fpqdepth != 0)
510 err |= __copy_to_user(&fpu->si_fpqueue[0],
511 ¤t->thread.fpqueue[0],
512 ((sizeof(unsigned long) +
513 (sizeof(unsigned long *)))*16));
519 new_setup_frame(struct k_sigaction *ka, struct pt_regs *regs,
520 int signo, sigset_t *oldset)
522 struct new_signal_frame __user *sf;
523 int sigframe_size, err;
525 /* 1. Make sure everything is clean */
526 synchronize_user_stack();
528 sigframe_size = NF_ALIGNEDSZ;
530 sigframe_size -= sizeof(__siginfo_fpu_t);
532 sf = (struct new_signal_frame __user *)
533 get_sigframe(&ka->sa, regs, sigframe_size);
535 if (invalid_frame_pointer(sf, sigframe_size))
536 goto sigill_and_return;
538 if (current_thread_info()->w_saved != 0)
539 goto sigill_and_return;
541 /* 2. Save the current process state */
542 err = __copy_to_user(&sf->info.si_regs, regs, sizeof(struct pt_regs));
544 err |= __put_user(0, &sf->extra_size);
547 err |= save_fpu_state(regs, &sf->fpu_state);
548 err |= __put_user(&sf->fpu_state, &sf->fpu_save);
550 err |= __put_user(0, &sf->fpu_save);
553 err |= __put_user(oldset->sig[0], &sf->info.si_mask);
554 err |= __copy_to_user(sf->extramask, &oldset->sig[1],
555 (_NSIG_WORDS - 1) * sizeof(unsigned int));
556 err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP],
557 sizeof(struct reg_window));
561 /* 3. signal handler back-trampoline and parameters */
562 regs->u_regs[UREG_FP] = (unsigned long) sf;
563 regs->u_regs[UREG_I0] = signo;
564 regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
565 regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
567 /* 4. signal handler */
568 regs->pc = (unsigned long) ka->sa.sa_handler;
569 regs->npc = (regs->pc + 4);
571 /* 5. return to kernel instructions */
573 regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
575 regs->u_regs[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2);
577 /* mov __NR_sigreturn, %g1 */
578 err |= __put_user(0x821020d8, &sf->insns[0]);
581 err |= __put_user(0x91d02010, &sf->insns[1]);
585 /* Flush instruction space. */
586 flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
593 force_sigsegv(signo, current);
597 new_setup_rt_frame(struct k_sigaction *ka, struct pt_regs *regs,
598 int signo, sigset_t *oldset, siginfo_t *info)
600 struct rt_signal_frame __user *sf;
605 synchronize_user_stack();
606 sigframe_size = RT_ALIGNEDSZ;
608 sigframe_size -= sizeof(__siginfo_fpu_t);
609 sf = (struct rt_signal_frame __user *)
610 get_sigframe(&ka->sa, regs, sigframe_size);
611 if (invalid_frame_pointer(sf, sigframe_size))
613 if (current_thread_info()->w_saved != 0)
616 err = __put_user(regs->pc, &sf->regs.pc);
617 err |= __put_user(regs->npc, &sf->regs.npc);
618 err |= __put_user(regs->y, &sf->regs.y);
622 err |= __put_user(psr, &sf->regs.psr);
623 err |= __copy_to_user(&sf->regs.u_regs, regs->u_regs, sizeof(regs->u_regs));
624 err |= __put_user(0, &sf->extra_size);
627 err |= save_fpu_state(regs, &sf->fpu_state);
628 err |= __put_user(&sf->fpu_state, &sf->fpu_save);
630 err |= __put_user(0, &sf->fpu_save);
632 err |= __copy_to_user(&sf->mask, &oldset->sig[0], sizeof(sigset_t));
634 /* Setup sigaltstack */
635 err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp);
636 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &sf->stack.ss_flags);
637 err |= __put_user(current->sas_ss_size, &sf->stack.ss_size);
639 err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP],
640 sizeof(struct reg_window));
642 err |= copy_siginfo_to_user(&sf->info, info);
647 regs->u_regs[UREG_FP] = (unsigned long) sf;
648 regs->u_regs[UREG_I0] = signo;
649 regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
650 regs->u_regs[UREG_I2] = (unsigned long) &sf->regs;
652 regs->pc = (unsigned long) ka->sa.sa_handler;
653 regs->npc = (regs->pc + 4);
656 regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
658 regs->u_regs[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2);
660 /* mov __NR_sigreturn, %g1 */
661 err |= __put_user(0x821020d8, &sf->insns[0]);
664 err |= __put_user(0x91d02010, &sf->insns[1]);
668 /* Flush instruction space. */
669 flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
676 force_sigsegv(signo, current);
679 /* Setup a Solaris stack frame */
681 setup_svr4_frame(struct sigaction *sa, unsigned long pc, unsigned long npc,
682 struct pt_regs *regs, int signr, sigset_t *oldset)
684 svr4_signal_frame_t __user *sfp;
685 svr4_gregset_t __user *gr;
686 svr4_siginfo_t __user *si;
687 svr4_mcontext_t __user *mc;
688 svr4_gwindows_t __user *gw;
689 svr4_ucontext_t __user *uc;
691 struct thread_info *tp = current_thread_info();
694 synchronize_user_stack();
695 sfp = (svr4_signal_frame_t __user *)
696 get_sigframe(sa, regs, SVR4_SF_ALIGNED + sizeof(struct reg_window));
698 if (invalid_frame_pointer(sfp, sizeof(*sfp)))
699 goto sigill_and_return;
701 /* Start with a clean frame pointer and fill it */
702 err = __clear_user(sfp, sizeof(*sfp));
704 /* Setup convenience variables */
711 /* FIXME: where am I supposed to put this?
712 * sc->sigc_onstack = old_status;
713 * anyways, it does not look like it is used for anything at all.
715 setv.sigbits[0] = oldset->sig[0];
716 setv.sigbits[1] = oldset->sig[1];
717 if (_NSIG_WORDS >= 4) {
718 setv.sigbits[2] = oldset->sig[2];
719 setv.sigbits[3] = oldset->sig[3];
720 err |= __copy_to_user(&uc->sigmask, &setv, sizeof(svr4_sigset_t));
722 err |= __copy_to_user(&uc->sigmask, &setv,
723 2 * sizeof(unsigned int));
725 /* Store registers */
726 err |= __put_user(regs->pc, &((*gr)[SVR4_PC]));
727 err |= __put_user(regs->npc, &((*gr)[SVR4_NPC]));
728 err |= __put_user(regs->psr, &((*gr)[SVR4_PSR]));
729 err |= __put_user(regs->y, &((*gr)[SVR4_Y]));
731 /* Copy g[1..7] and o[0..7] registers */
732 err |= __copy_to_user(&(*gr)[SVR4_G1], ®s->u_regs[UREG_G1],
734 err |= __copy_to_user(&(*gr)[SVR4_O0], ®s->u_regs[UREG_I0],
737 /* Setup sigaltstack */
738 err |= __put_user(current->sas_ss_sp, &uc->stack.sp);
739 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &uc->stack.flags);
740 err |= __put_user(current->sas_ss_size, &uc->stack.size);
742 /* Save the currently window file: */
744 /* 1. Link sfp->uc->gwins to our windows */
745 err |= __put_user(gw, &mc->gwin);
747 /* 2. Number of windows to restore at setcontext(): */
748 err |= __put_user(tp->w_saved, &gw->count);
750 /* 3. Save each valid window
751 * Currently, it makes a copy of the windows from the kernel copy.
752 * David's code for SunOS, makes the copy but keeps the pointer to
753 * the kernel. My version makes the pointer point to a userland
754 * copy of those. Mhm, I wonder if I shouldn't just ignore those
755 * on setcontext and use those that are on the kernel, the signal
756 * handler should not be modyfing those, mhm.
758 * These windows are just used in case synchronize_user_stack failed
759 * to flush the user windows.
761 for (window = 0; window < tp->w_saved; window++) {
762 err |= __put_user((int __user *) &(gw->win[window]), &gw->winptr[window]);
763 err |= __copy_to_user(&gw->win[window],
764 &tp->reg_window[window],
765 sizeof(svr4_rwindow_t));
766 err |= __put_user(0, gw->winptr[window]);
769 /* 4. We just pay attention to the gw->count field on setcontext */
770 tp->w_saved = 0; /* So process is allowed to execute. */
772 /* Setup the signal information. Solaris expects a bunch of
773 * information to be passed to the signal handler, we don't provide
774 * that much currently, should use siginfo.
776 err |= __put_user(signr, &si->siginfo.signo);
777 err |= __put_user(SVR4_SINOINFO, &si->siginfo.code);
781 regs->u_regs[UREG_FP] = (unsigned long) sfp;
782 regs->pc = (unsigned long) sa->sa_handler;
783 regs->npc = (regs->pc + 4);
785 /* Arguments passed to signal handler */
786 if (regs->u_regs[14]){
787 struct reg_window __user *rw = (struct reg_window __user *)
790 err |= __put_user(signr, &rw->ins[0]);
791 err |= __put_user(si, &rw->ins[1]);
792 err |= __put_user(uc, &rw->ins[2]);
793 err |= __put_user(sfp, &rw->ins[6]); /* frame pointer */
797 regs->u_regs[UREG_I0] = signr;
798 regs->u_regs[UREG_I1] = (unsigned long) si;
799 regs->u_regs[UREG_I2] = (unsigned long) uc;
806 force_sigsegv(signr, current);
809 asmlinkage int svr4_getcontext(svr4_ucontext_t __user *uc, struct pt_regs *regs)
811 svr4_gregset_t __user *gr;
812 svr4_mcontext_t __user *mc;
816 synchronize_user_stack();
818 if (current_thread_info()->w_saved)
821 err = clear_user(uc, sizeof(*uc));
825 /* Setup convenience variables */
829 setv.sigbits[0] = current->blocked.sig[0];
830 setv.sigbits[1] = current->blocked.sig[1];
831 if (_NSIG_WORDS >= 4) {
832 setv.sigbits[2] = current->blocked.sig[2];
833 setv.sigbits[3] = current->blocked.sig[3];
834 err |= __copy_to_user(&uc->sigmask, &setv, sizeof(svr4_sigset_t));
836 err |= __copy_to_user(&uc->sigmask, &setv,
837 2 * sizeof(unsigned int));
839 /* Store registers */
840 err |= __put_user(regs->pc, &uc->mcontext.greg[SVR4_PC]);
841 err |= __put_user(regs->npc, &uc->mcontext.greg[SVR4_NPC]);
842 err |= __put_user(regs->psr, &uc->mcontext.greg[SVR4_PSR]);
843 err |= __put_user(regs->y, &uc->mcontext.greg[SVR4_Y]);
845 /* Copy g[1..7] and o[0..7] registers */
846 err |= __copy_to_user(&(*gr)[SVR4_G1], ®s->u_regs[UREG_G1],
848 err |= __copy_to_user(&(*gr)[SVR4_O0], ®s->u_regs[UREG_I0],
851 /* Setup sigaltstack */
852 err |= __put_user(current->sas_ss_sp, &uc->stack.sp);
853 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &uc->stack.flags);
854 err |= __put_user(current->sas_ss_size, &uc->stack.size);
856 /* The register file is not saved
857 * we have already stuffed all of it with sync_user_stack
859 return (err ? -EFAULT : 0);
862 /* Set the context for a svr4 application, this is Solaris way to sigreturn */
863 asmlinkage int svr4_setcontext(svr4_ucontext_t __user *c, struct pt_regs *regs)
865 svr4_gregset_t __user *gr;
866 unsigned long pc, npc, psr;
873 /* Fixme: restore windows, or is this already taken care of in
874 * svr4_setup_frame when sync_user_windows is done?
876 flush_user_windows();
878 if (current_thread_info()->w_saved)
879 goto sigsegv_and_return;
881 if (((unsigned long) c) & 3)
882 goto sigsegv_and_return;
884 if (!__access_ok((unsigned long)c, sizeof(*c)))
885 goto sigsegv_and_return;
887 /* Check for valid PC and nPC */
888 gr = &c->mcontext.greg;
889 err = __get_user(pc, &((*gr)[SVR4_PC]));
890 err |= __get_user(npc, &((*gr)[SVR4_NPC]));
893 goto sigsegv_and_return;
895 /* Retrieve information from passed ucontext */
896 /* note that nPC is ored a 1, this is used to inform entry.S */
897 /* that we don't want it to mess with our PC and nPC */
899 /* This is pretty much atomic, no amount locking would prevent
900 * the races which exist anyways.
902 err |= __copy_from_user(&setv, &c->sigmask, sizeof(svr4_sigset_t));
904 err |= __get_user(st.ss_sp, &c->stack.sp);
905 err |= __get_user(st.ss_flags, &c->stack.flags);
906 err |= __get_user(st.ss_size, &c->stack.size);
909 goto sigsegv_and_return;
911 /* It is more difficult to avoid calling this function than to
912 call it and ignore errors. */
915 do_sigaltstack((const stack_t __user *) &st, NULL,
916 regs->u_regs[UREG_I6]);
919 set.sig[0] = setv.sigbits[0];
920 set.sig[1] = setv.sigbits[1];
921 if (_NSIG_WORDS >= 4) {
922 set.sig[2] = setv.sigbits[2];
923 set.sig[3] = setv.sigbits[3];
925 sigdelsetmask(&set, ~_BLOCKABLE);
926 spin_lock_irq(¤t->sighand->siglock);
927 current->blocked = set;
929 spin_unlock_irq(¤t->sighand->siglock);
932 err |= __get_user(regs->y, &((*gr)[SVR4_Y]));
933 err |= __get_user(psr, &((*gr)[SVR4_PSR]));
934 regs->psr &= ~(PSR_ICC);
935 regs->psr |= (psr & PSR_ICC);
937 /* Restore g[1..7] and o[0..7] registers */
938 err |= __copy_from_user(®s->u_regs[UREG_G1], &(*gr)[SVR4_G1],
940 err |= __copy_from_user(®s->u_regs[UREG_I0], &(*gr)[SVR4_O0],
942 return (err ? -EFAULT : 0);
945 force_sig(SIGSEGV, current);
950 handle_signal(unsigned long signr, struct k_sigaction *ka,
951 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs,
955 setup_svr4_frame(&ka->sa, regs->pc, regs->npc, regs, signr, oldset);
957 if (ka->sa.sa_flags & SA_SIGINFO)
958 new_setup_rt_frame(ka, regs, signr, oldset, info);
959 else if (current->thread.new_signal)
960 new_setup_frame(ka, regs, signr, oldset);
962 setup_frame(&ka->sa, regs, signr, oldset, info);
964 spin_lock_irq(¤t->sighand->siglock);
965 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
966 if (!(ka->sa.sa_flags & SA_NOMASK))
967 sigaddset(¤t->blocked, signr);
969 spin_unlock_irq(¤t->sighand->siglock);
972 static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
973 struct sigaction *sa)
975 switch(regs->u_regs[UREG_I0]) {
976 case ERESTART_RESTARTBLOCK:
978 no_system_call_restart:
979 regs->u_regs[UREG_I0] = EINTR;
983 if (!(sa->sa_flags & SA_RESTART))
984 goto no_system_call_restart;
987 regs->u_regs[UREG_I0] = orig_i0;
993 /* Note that 'init' is a special process: it doesn't get signals it doesn't
994 * want to handle. Thus you cannot kill init even with a SIGKILL even by
997 asmlinkage void do_signal(struct pt_regs * regs, unsigned long orig_i0, int restart_syscall)
1000 struct sparc_deliver_cookie cookie;
1001 struct k_sigaction ka;
1006 * XXX Disable svr4 signal handling until solaris emulation works.
1007 * It is buggy - Anton
1009 #define SVR4_SIGNAL_BROKEN 1
1010 #ifdef SVR4_SIGNAL_BROKEN
1011 int svr4_signal = 0;
1013 int svr4_signal = current->personality == PER_SVR4;
1016 cookie.restart_syscall = restart_syscall;
1017 cookie.orig_i0 = orig_i0;
1019 if (test_thread_flag(TIF_RESTORE_SIGMASK))
1020 oldset = ¤t->saved_sigmask;
1022 oldset = ¤t->blocked;
1024 signr = get_signal_to_deliver(&info, &ka, regs, &cookie);
1026 if (cookie.restart_syscall)
1027 syscall_restart(cookie.orig_i0, regs, &ka.sa);
1028 handle_signal(signr, &ka, &info, oldset,
1030 /* a signal was successfully delivered; the saved
1031 * sigmask will have been stored in the signal frame,
1032 * and will be restored by sigreturn, so we can simply
1033 * clear the TIF_RESTORE_SIGMASK flag.
1035 if (test_thread_flag(TIF_RESTORE_SIGMASK))
1036 clear_thread_flag(TIF_RESTORE_SIGMASK);
1039 if (cookie.restart_syscall &&
1040 (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
1041 regs->u_regs[UREG_I0] == ERESTARTSYS ||
1042 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
1043 /* replay the system call when we are done */
1044 regs->u_regs[UREG_I0] = cookie.orig_i0;
1048 if (cookie.restart_syscall &&
1049 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
1050 regs->u_regs[UREG_G1] = __NR_restart_syscall;
1055 /* if there's no signal to deliver, we just put the saved sigmask
1058 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
1059 clear_thread_flag(TIF_RESTORE_SIGMASK);
1060 sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL);
1065 do_sys_sigstack(struct sigstack __user *ssptr, struct sigstack __user *ossptr,
1070 /* First see if old state is wanted. */
1072 if (put_user(current->sas_ss_sp + current->sas_ss_size,
1073 &ossptr->the_stack) ||
1074 __put_user(on_sig_stack(sp), &ossptr->cur_status))
1078 /* Now see if we want to update the new state. */
1082 if (get_user(ss_sp, &ssptr->the_stack))
1084 /* If the current stack was set with sigaltstack, don't
1085 swap stacks while we are on it. */
1087 if (current->sas_ss_sp && on_sig_stack(sp))
1090 /* Since we don't know the extent of the stack, and we don't
1091 track onstack-ness, but rather calculate it, we must
1092 presume a size. Ho hum this interface is lossy. */
1093 current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ;
1094 current->sas_ss_size = SIGSTKSZ;
1101 void ptrace_signal_deliver(struct pt_regs *regs, void *cookie)
1103 struct sparc_deliver_cookie *cp = cookie;
1105 if (cp->restart_syscall &&
1106 (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
1107 regs->u_regs[UREG_I0] == ERESTARTSYS ||
1108 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
1109 /* replay the system call when we are done */
1110 regs->u_regs[UREG_I0] = cp->orig_i0;
1113 cp->restart_syscall = 0;
1116 if (cp->restart_syscall &&
1117 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
1118 regs->u_regs[UREG_G1] = __NR_restart_syscall;
1121 cp->restart_syscall = 0;