Home | History | Annotate | Line # | Download | only in alpha
compat_13_machdep.c revision 1.18.4.1
      1  1.18.4.1     rmind /* $NetBSD: compat_13_machdep.c,v 1.18.4.1 2011/06/12 00:23:51 rmind Exp $ */
      2       1.1   thorpej 
      3       1.1   thorpej /*
      4       1.1   thorpej  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
      5       1.1   thorpej  * All rights reserved.
      6       1.1   thorpej  *
      7       1.1   thorpej  * Author: Chris G. Demetriou
      8       1.1   thorpej  *
      9       1.1   thorpej  * Permission to use, copy, modify and distribute this software and
     10       1.1   thorpej  * its documentation is hereby granted, provided that both the copyright
     11       1.1   thorpej  * notice and this permission notice appear in all copies of the
     12       1.1   thorpej  * software, derivative works or modified versions, and any portions
     13       1.1   thorpej  * thereof, and that both notices appear in supporting documentation.
     14       1.1   thorpej  *
     15       1.1   thorpej  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16       1.1   thorpej  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17       1.1   thorpej  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18       1.1   thorpej  *
     19       1.1   thorpej  * Carnegie Mellon requests users of this software to return to
     20       1.1   thorpej  *
     21       1.1   thorpej  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22       1.1   thorpej  *  School of Computer Science
     23       1.1   thorpej  *  Carnegie Mellon University
     24       1.1   thorpej  *  Pittsburgh PA 15213-3890
     25       1.1   thorpej  *
     26       1.1   thorpej  * any improvements or extensions that they make and grant Carnegie the
     27       1.1   thorpej  * rights to redistribute these changes.
     28       1.1   thorpej  */
     29       1.1   thorpej 
     30       1.1   thorpej #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     31       1.1   thorpej 
     32  1.18.4.1     rmind __KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.18.4.1 2011/06/12 00:23:51 rmind Exp $");
     33       1.1   thorpej 
     34       1.1   thorpej #include <sys/param.h>
     35       1.1   thorpej #include <sys/systm.h>
     36       1.1   thorpej #include <sys/signalvar.h>
     37       1.1   thorpej #include <sys/kernel.h>
     38       1.1   thorpej #include <sys/proc.h>
     39       1.1   thorpej #include <sys/mount.h>
     40       1.1   thorpej #include <sys/syscallargs.h>
     41       1.1   thorpej 
     42      1.12    martin #include <compat/sys/signal.h>
     43      1.12    martin #include <compat/sys/signalvar.h>
     44      1.12    martin 
     45       1.1   thorpej #include <machine/cpu.h>
     46       1.1   thorpej #include <machine/reg.h>
     47       1.3      ross #include <machine/alpha.h>
     48       1.4   thorpej 
     49       1.1   thorpej /*
     50       1.1   thorpej  * System call to cleanup state after a signal
     51       1.1   thorpej  * has been taken.  Reset signal mask and
     52       1.1   thorpej  * stack state from context left by sendsig (above).
     53       1.1   thorpej  * Return to previous pc and psl as specified by
     54       1.1   thorpej  * context left by sendsig. Check carefully to
     55       1.1   thorpej  * make sure that the user has not modified the
     56       1.6    simonb  * psl to gain improper privileges or to cause
     57       1.1   thorpej  * a machine fault.
     58       1.1   thorpej  */
     59       1.1   thorpej /* ARGSUSED */
     60       1.1   thorpej int
     61      1.16       dsl compat_13_sys_sigreturn(struct lwp *l, const struct compat_13_sys_sigreturn_args *uap, register_t *retval)
     62       1.1   thorpej {
     63      1.16       dsl 	/* {
     64       1.1   thorpej 		syscallarg(struct sigcontext13 *) sigcntxp;
     65      1.16       dsl 	} */
     66       1.1   thorpej 	struct sigcontext13 *scp, ksc;
     67      1.14        ad 	struct proc *p = l->l_proc;
     68      1.18     rmind 	struct pcb *pcb;
     69       1.1   thorpej 	sigset13_t mask13;
     70       1.1   thorpej 	sigset_t mask;
     71       1.1   thorpej 
     72       1.1   thorpej 	/*
     73       1.1   thorpej 	 * The trampoline code hands us the context.
     74       1.1   thorpej 	 * It is unsafe to keep track of it ourselves, in the event that a
     75       1.1   thorpej 	 * program jumps out of a signal handler.
     76       1.1   thorpej 	 */
     77       1.1   thorpej 	scp = SCARG(uap, sigcntxp);
     78       1.1   thorpej 	if (ALIGN(scp) != (u_int64_t)scp)
     79       1.1   thorpej 		return (EINVAL);
     80       1.1   thorpej 
     81      1.15  christos 	if (copyin((void *)scp, &ksc, sizeof(ksc)) != 0)
     82       1.1   thorpej 		return (EFAULT);
     83       1.1   thorpej 
     84       1.1   thorpej 	if (ksc.sc_regs[R_ZERO] != 0xACEDBADE)		/* magic number */
     85       1.1   thorpej 		return (EINVAL);
     86       1.1   thorpej 
     87       1.1   thorpej 	/* Restore register context. */
     88      1.11   thorpej 	l->l_md.md_tf->tf_regs[FRAME_PC] = ksc.sc_pc;
     89      1.11   thorpej 	l->l_md.md_tf->tf_regs[FRAME_PS] =
     90       1.1   thorpej 	    (ksc.sc_ps | ALPHA_PSL_USERSET) & ~ALPHA_PSL_USERCLR;
     91       1.1   thorpej 
     92      1.11   thorpej 	regtoframe((struct reg *)ksc.sc_regs, l->l_md.md_tf);
     93       1.1   thorpej 	alpha_pal_wrusp(ksc.sc_regs[R_SP]);
     94       1.1   thorpej 
     95       1.1   thorpej 	/* XXX ksc.sc_ownedfp ? */
     96      1.18     rmind 	pcb = lwp_getpcb(l);
     97  1.18.4.1     rmind 	fpu_discard();
     98      1.18     rmind 	memcpy(&pcb->pcb_fp, (struct fpreg *)ksc.sc_fpregs,
     99       1.1   thorpej 	    sizeof(struct fpreg));
    100       1.1   thorpej 	/* XXX ksc.sc_fp_control ? */
    101       1.1   thorpej 
    102      1.17        ad 	mutex_enter(p->p_lock);
    103       1.1   thorpej 	/* Restore signal stack. */
    104       1.1   thorpej 	if (ksc.sc_onstack & SS_ONSTACK)
    105      1.14        ad 		l->l_sigstk.ss_flags |= SS_ONSTACK;
    106       1.1   thorpej 	else
    107      1.14        ad 		l->l_sigstk.ss_flags &= ~SS_ONSTACK;
    108       1.1   thorpej 	/*
    109       1.1   thorpej 	 * Restore signal mask.  Note the mask is a "long" in the stack
    110       1.1   thorpej 	 * frame.
    111       1.1   thorpej 	 */
    112       1.1   thorpej 	mask13 = ksc.sc_mask;
    113       1.1   thorpej 	native_sigset13_to_sigset(&mask13, &mask);
    114      1.14        ad 	(void) sigprocmask1(l, SIG_SETMASK, &mask, 0);
    115      1.17        ad 	mutex_exit(p->p_lock);
    116       1.1   thorpej 
    117       1.1   thorpej 	return (EJUSTRETURN);
    118       1.1   thorpej }
    119