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