Home | History | Annotate | Line # | Download | only in vax
      1 /*	$NetBSD: compat_13_machdep.c,v 1.6 2018/12/29 11:30:12 maxv Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
      5  * All rights reserved.
      6  *
      7  * Changed for the VAX port (and for readability) /IC
      8  *
      9  * This code is derived from software contributed to Berkeley by the Systems
     10  * Programming Group of the University of Utah Computer Science Department.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  * from: Utah Hdr: machdep.c 1.63 91/04/24
     37  *
     38  * @(#)machdep.c	7.16 (Berkeley) 6/3/91
     39  */
     40 
     41 /*
     42  * Copyright (c) 2002, Hugh Graham.
     43  * Copyright (c) 1994, 1998 Ludd, University of Lule}, Sweden.
     44  * Copyright (c) 1993 Adam Glass
     45  * Copyright (c) 1988 University of Utah.
     46  *
     47  * Changed for the VAX port (and for readability) /IC
     48  *
     49  * This code is derived from software contributed to Berkeley by the Systems
     50  * Programming Group of the University of Utah Computer Science Department.
     51  *
     52  * Redistribution and use in source and binary forms, with or without
     53  * modification, are permitted provided that the following conditions
     54  * are met:
     55  * 1. Redistributions of source code must retain the above copyright
     56  *    notice, this list of conditions and the following disclaimer.
     57  * 2. Redistributions in binary form must reproduce the above copyright
     58  *    notice, this list of conditions and the following disclaimer in the
     59  *    documentation and/or other materials provided with the distribution.
     60  * 3. All advertising materials mentioning features or use of this software
     61  *    must display the following acknowledgement:
     62  *	This product includes software developed by the University of
     63  *	California, Berkeley and its contributors.
     64  * 4. Neither the name of the University nor the names of its contributors
     65  *    may be used to endorse or promote products derived from this software
     66  *    without specific prior written permission.
     67  *
     68  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     69  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     70  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     71  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     72  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     73  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     74  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     75  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     76  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     77  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     78  * SUCH DAMAGE.
     79  *
     80  * from: Utah Hdr: machdep.c 1.63 91/04/24
     81  *
     82  * @(#)machdep.c	7.16 (Berkeley) 6/3/91
     83  */
     84 
     85 #include <sys/cdefs.h>
     86 __KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.6 2018/12/29 11:30:12 maxv Exp $");
     87 
     88 #ifdef _KERNEL_OPT
     89 #include "opt_compat_netbsd.h"
     90 #include "opt_compat_ultrix.h"
     91 #include "opt_multiprocessor.h"
     92 #include "opt_lockdebug.h"
     93 #endif
     94 
     95 #include <sys/param.h>
     96 #include <sys/systm.h>
     97 #include <sys/cpu.h>
     98 #include <sys/device.h>
     99 #include <sys/extent.h>
    100 #include <sys/proc.h>
    101 #include <sys/signal.h>
    102 #include <sys/syscallargs.h>
    103 #include <sys/sysctl.h>
    104 #include <sys/time.h>
    105 
    106 #include <dev/cons.h>
    107 
    108 #include <compat/sys/signal.h>
    109 #include <compat/sys/signalvar.h>
    110 
    111 #include <machine/macros.h>
    112 #include <machine/reg.h>
    113 #include <vax/vax/gencons.h>
    114 
    115 /*
    116  * This code was moved here from sys/arch/vax/vax/sig_machdep.c
    117  */
    118 
    119 int
    120 compat_13_sys_sigreturn(struct lwp *l, const struct compat_13_sys_sigreturn_args *uap, register_t *retval)
    121 {
    122 	/* {
    123 		syscallarg(struct sigcontext13 *) sigcntxp;
    124 	} */
    125 	struct proc * const p = l->l_proc;
    126 	struct trapframe * const tf = l->l_md.md_utf;
    127 	struct sigcontext13 *ucntx;
    128 	struct sigcontext13 ksc;
    129 	sigset_t mask;
    130 
    131 	ucntx = SCARG(uap, sigcntxp);
    132 	if (copyin((void *)ucntx, (void *)&ksc, sizeof(struct sigcontext)))
    133 		return EINVAL;
    134 
    135 	/* Compatibility mode? */
    136 	if ((ksc.sc_ps & (PSL_IPL | PSL_IS)) ||
    137 	    ((ksc.sc_ps & (PSL_U | PSL_PREVU)) != (PSL_U | PSL_PREVU)) ||
    138 	    (ksc.sc_ps & PSL_CM)) {
    139 		return (EINVAL);
    140 	}
    141 
    142 	mutex_enter(p->p_lock);
    143 	if (ksc.sc_onstack & SS_ONSTACK)
    144 		l->l_sigstk.ss_flags |= SS_ONSTACK;
    145 	else
    146 		l->l_sigstk.ss_flags &= ~SS_ONSTACK;
    147 
    148 	native_sigset13_to_sigset(&ksc.sc_mask, &mask);
    149 	(void) sigprocmask1(l, SIG_SETMASK, &mask, 0);
    150 	mutex_exit(p->p_lock);
    151 
    152 	tf->tf_fp = ksc.sc_fp;
    153 	tf->tf_ap = ksc.sc_ap;
    154 	tf->tf_pc = ksc.sc_pc;
    155 	tf->tf_sp = ksc.sc_sp;
    156 	tf->tf_psl = ksc.sc_ps;
    157 	return (EJUSTRETURN);
    158 }
    159 
    160 vaddr_t
    161 setupstack_oldsigcontext(const struct ksiginfo *ksi, const sigset_t *mask,
    162 	int vers, struct lwp *l, struct trapframe *tf, vaddr_t sp, int onstack,
    163 	vaddr_t handler)
    164 {
    165 	struct sigcontext sigctx;
    166 	struct otrampframe tramp;
    167 	struct proc * const p = l->l_proc;
    168 	bool error;
    169 
    170 	sigctx.sc_pc = tf->tf_pc;
    171 	sigctx.sc_ps = tf->tf_psl;
    172 	sigctx.sc_ap = tf->tf_ap;
    173 	sigctx.sc_fp = tf->tf_fp;
    174 	sigctx.sc_sp = tf->tf_sp;
    175 	sigctx.sc_onstack = onstack ? SS_ONSTACK : 0;
    176 	sigctx.sc_mask = *mask;
    177 	sp -= sizeof(struct sigcontext);
    178 
    179 	native_sigset_to_sigset13(mask, &sigctx.__sc_mask13);
    180 
    181 	tramp.sig = ksi->ksi_signo;
    182 	tramp.code = (register_t)ksi->ksi_addr;
    183 	/* Set up positions for structs on stack */
    184 	tramp.scp = sp;
    185 	/* r0..r5 are saved by the popr in the sigcode snippet but we need
    186 	   to zero them anyway.  */
    187 	tramp.r0 = tramp.r1 = tramp.r2 = tramp.r3 = tramp.r4 = tramp.r5 = 0;
    188 	tramp.pc = (register_t)handler;
    189 	tramp.arg = sp;
    190 	sendsig_reset(l, ksi->ksi_signo);
    191 	mutex_exit(p->p_lock);
    192 
    193 	/* Point stack pointer at pc in trampoline.  */
    194 	sp =- 8;
    195 
    196 	error = copyout(&tramp, (char *)tramp.scp - sizeof(tramp), sizeof(tramp)) != 0 ||
    197 	    copyout(&sigctx, (void *)tramp.scp, sizeof(sigctx)) != 0;
    198 
    199 	mutex_enter(p->p_lock);
    200 	if (error)
    201 		return 0;
    202 
    203 	return sp;
    204 }
    205