Home | History | Annotate | Line # | Download | only in ultrix
ultrix_misc.c revision 1.38
      1  1.38  jonathan /*	$NetBSD: ultrix_misc.c,v 1.38 1997/10/19 00:15:31 jonathan Exp $	*/
      2   1.5       cgd 
      3   1.1     glass /*
      4  1.30  jonathan  * Copyright (c) 1995, 1997 Jonathan Stone (hereinafter referred to as the author)
      5  1.30  jonathan  * All rights reserved.
      6  1.23  jonathan  *
      7  1.23  jonathan  * Redistribution and use in source and binary forms, with or without
      8  1.23  jonathan  * modification, are permitted provided that the following conditions
      9  1.23  jonathan  * are met:
     10  1.23  jonathan  * 1. Redistributions of source code must retain the above copyright
     11  1.23  jonathan  *    notice, this list of conditions and the following disclaimer.
     12  1.23  jonathan  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.23  jonathan  *    notice, this list of conditions and the following disclaimer in the
     14  1.23  jonathan  *    documentation and/or other materials provided with the distribution.
     15  1.28  jonathan  * 3. All advertising materials mentioning features or use of this software
     16  1.28  jonathan  *    must display the following acknowledgement:
     17  1.37  jonathan  *      This product includes software developed by Jonathan Stone for
     18  1.28  jonathan  *      the NetBSD Project.
     19  1.28  jonathan  * 4. The name of the author may not be used to endorse or promote products
     20  1.23  jonathan  *    derived from this software without specific prior written permission.
     21  1.23  jonathan  *
     22  1.23  jonathan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
     23  1.23  jonathan  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.23  jonathan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.23  jonathan  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
     26  1.23  jonathan  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.23  jonathan  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.23  jonathan  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.23  jonathan  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.23  jonathan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.23  jonathan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.23  jonathan  * SUCH DAMAGE.
     33  1.23  jonathan  */
     34  1.23  jonathan 
     35  1.23  jonathan /*
     36   1.1     glass  * Copyright (c) 1992, 1993
     37   1.1     glass  *	The Regents of the University of California.  All rights reserved.
     38   1.1     glass  *
     39   1.1     glass  * This software was developed by the Computer Systems Engineering group
     40   1.1     glass  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     41   1.1     glass  * contributed to Berkeley.
     42   1.1     glass  *
     43   1.1     glass  * All advertising materials mentioning features or use of this software
     44   1.1     glass  * must display the following acknowledgement:
     45   1.1     glass  *	This product includes software developed by the University of
     46   1.1     glass  *	California, Lawrence Berkeley Laboratory.
     47   1.1     glass  *
     48   1.1     glass  * Redistribution and use in source and binary forms, with or without
     49   1.1     glass  * modification, are permitted provided that the following conditions
     50   1.1     glass  * are met:
     51   1.1     glass  * 1. Redistributions of source code must retain the above copyright
     52   1.1     glass  *    notice, this list of conditions and the following disclaimer.
     53   1.1     glass  * 2. Redistributions in binary form must reproduce the above copyright
     54   1.1     glass  *    notice, this list of conditions and the following disclaimer in the
     55   1.1     glass  *    documentation and/or other materials provided with the distribution.
     56   1.1     glass  * 3. All advertising materials mentioning features or use of this software
     57   1.1     glass  *    must display the following acknowledgement:
     58   1.1     glass  *	This product includes software developed by the University of
     59   1.1     glass  *	California, Berkeley and its contributors.
     60   1.1     glass  * 4. Neither the name of the University nor the names of its contributors
     61   1.1     glass  *    may be used to endorse or promote products derived from this software
     62   1.1     glass  *    without specific prior written permission.
     63   1.1     glass  *
     64   1.1     glass  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     65   1.1     glass  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     66   1.1     glass  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     67   1.1     glass  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     68   1.1     glass  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     69   1.1     glass  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     70   1.1     glass  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     71   1.1     glass  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     72   1.1     glass  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     73   1.1     glass  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     74   1.1     glass  * SUCH DAMAGE.
     75   1.1     glass  *
     76   1.5       cgd  *
     77   1.1     glass  *	@(#)sun_misc.c	8.1 (Berkeley) 6/18/93
     78   1.1     glass  *
     79   1.1     glass  * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
     80   1.1     glass  */
     81   1.1     glass 
     82  1.38  jonathan #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     83  1.38  jonathan 
     84  1.38  jonathan __KERNEL_RCSID(0, "$NetBSD: ultrix_misc.c,v 1.38 1997/10/19 00:15:31 jonathan Exp $");
     85  1.38  jonathan 
     86   1.1     glass /*
     87   1.1     glass  * SunOS compatibility module.
     88   1.1     glass  *
     89   1.1     glass  * SunOS system calls that are implemented differently in BSD are
     90   1.1     glass  * handled here.
     91   1.1     glass  */
     92   1.1     glass 
     93   1.1     glass #include <sys/param.h>
     94   1.1     glass #include <sys/systm.h>
     95   1.1     glass #include <sys/namei.h>
     96  1.25   mycroft #include <sys/dirent.h>
     97   1.1     glass #include <sys/proc.h>
     98   1.1     glass #include <sys/file.h>
     99   1.1     glass #include <sys/filedesc.h>
    100  1.20  jonathan /*#include <sys/stat.h>*/
    101  1.20  jonathan /*#include <sys/ioctl.h>*/
    102   1.1     glass #include <sys/kernel.h>
    103   1.1     glass #include <sys/exec.h>
    104   1.1     glass #include <sys/malloc.h>
    105   1.1     glass #include <sys/mbuf.h>
    106   1.1     glass #include <sys/mman.h>
    107   1.1     glass #include <sys/mount.h>
    108   1.1     glass #include <sys/resource.h>
    109   1.1     glass #include <sys/resourcevar.h>
    110   1.1     glass #include <sys/signal.h>
    111   1.1     glass #include <sys/signalvar.h>
    112   1.1     glass #include <sys/socket.h>
    113   1.1     glass #include <sys/vnode.h>
    114   1.1     glass #include <sys/uio.h>
    115   1.1     glass #include <sys/wait.h>
    116   1.1     glass #include <sys/utsname.h>
    117   1.1     glass #include <sys/unistd.h>
    118  1.30  jonathan #include <sys/ipc.h>
    119  1.20  jonathan 
    120  1.16   mycroft #include <sys/syscallargs.h>
    121  1.16   mycroft 
    122  1.16   mycroft #include <compat/ultrix/ultrix_syscall.h>
    123  1.16   mycroft #include <compat/ultrix/ultrix_syscallargs.h>
    124  1.30  jonathan #include <compat/common/compat_util.h>
    125   1.1     glass 
    126   1.1     glass #include <netinet/in.h>
    127   1.1     glass 
    128   1.1     glass #include <miscfs/specfs/specdev.h>
    129   1.1     glass 
    130   1.3     glass #include <nfs/rpcv2.h>
    131  1.21        pk #include <nfs/nfsproto.h>
    132   1.3     glass #include <nfs/nfs.h>
    133   1.3     glass 
    134  1.35  jonathan #include <vm/vm.h>					/* pmap declarations */
    135  1.11  christos 
    136  1.23  jonathan #include <sys/conf.h>					/* iszerodev() */
    137  1.23  jonathan #include <sys/socketvar.h>				/* sosetopt() */
    138  1.23  jonathan 
    139  1.35  jonathan 
    140  1.11  christos extern struct sysent ultrix_sysent[];
    141  1.11  christos extern char *ultrix_syscallnames[];
    142  1.22  jonathan 
    143  1.35  jonathan 
    144  1.22  jonathan /*
    145  1.22  jonathan  * Select the appropriate setregs callback for the target architecture.
    146  1.22  jonathan  */
    147  1.22  jonathan #ifdef mips
    148  1.33  jonathan #include <machine/ecoff_machdep.h>
    149  1.22  jonathan #define ULTRIX_EXEC_SETREGS cpu_exec_ecoff_setregs
    150  1.22  jonathan #endif /* mips */
    151  1.22  jonathan 
    152  1.22  jonathan #ifdef vax
    153  1.22  jonathan #define ULTRIX_EXEC_SETREGS setregs
    154  1.22  jonathan #endif /* mips */
    155  1.22  jonathan 
    156  1.22  jonathan 
    157  1.22  jonathan extern void ULTRIX_EXEC_SETREGS __P((struct proc *, struct exec_package *,
    158  1.36    mhitch 					u_long));
    159  1.19  jonathan extern char sigcode[], esigcode[];
    160  1.19  jonathan 
    161  1.11  christos struct emul emul_ultrix = {
    162  1.11  christos 	"ultrix",
    163  1.11  christos 	NULL,
    164  1.11  christos 	sendsig,
    165  1.11  christos 	ULTRIX_SYS_syscall,
    166  1.11  christos 	ULTRIX_SYS_MAXSYSCALL,
    167  1.11  christos 	ultrix_sysent,
    168  1.11  christos 	ultrix_syscallnames,
    169  1.11  christos 	0,
    170  1.11  christos 	copyargs,
    171  1.22  jonathan 	ULTRIX_EXEC_SETREGS,
    172  1.19  jonathan 	sigcode,
    173  1.19  jonathan 	esigcode,
    174  1.11  christos };
    175   1.1     glass 
    176   1.6     glass #define GSI_PROG_ENV 1
    177   1.6     glass 
    178  1.23  jonathan int
    179  1.16   mycroft ultrix_sys_getsysinfo(p, v, retval)
    180   1.6     glass 	struct proc *p;
    181  1.15   thorpej 	void *v;
    182  1.16   mycroft 	register_t *retval;
    183   1.6     glass {
    184  1.16   mycroft 	struct ultrix_sys_getsysinfo_args *uap = v;
    185   1.6     glass 	static short progenv = 0;
    186   1.6     glass 
    187  1.16   mycroft 	switch (SCARG(uap, op)) {
    188   1.6     glass 		/* operations implemented: */
    189   1.6     glass 	case GSI_PROG_ENV:
    190  1.16   mycroft 		if (SCARG(uap, nbytes) < sizeof(short))
    191   1.6     glass 			return EINVAL;
    192   1.6     glass 		*retval = 1;
    193  1.16   mycroft 		return (copyout(&progenv, SCARG(uap, buffer), sizeof(short)));
    194   1.6     glass 	default:
    195   1.6     glass 		*retval = 0; /* info unavail */
    196   1.6     glass 		return 0;
    197   1.6     glass 	}
    198   1.6     glass }
    199   1.6     glass 
    200  1.23  jonathan int
    201  1.16   mycroft ultrix_sys_setsysinfo(p, v, retval)
    202   1.6     glass 	struct proc *p;
    203  1.15   thorpej 	void *v;
    204  1.16   mycroft 	register_t *retval;
    205   1.6     glass {
    206  1.23  jonathan 
    207  1.23  jonathan #ifdef notyet
    208  1.16   mycroft 	struct ultrix_sys_setsysinfo_args *uap = v;
    209  1.23  jonathan #endif
    210  1.23  jonathan 
    211   1.6     glass 	*retval = 0;
    212   1.6     glass 	return 0;
    213   1.6     glass }
    214   1.6     glass 
    215  1.23  jonathan int
    216  1.16   mycroft ultrix_sys_waitpid(p, v, retval)
    217   1.1     glass 	struct proc *p;
    218  1.15   thorpej 	void *v;
    219   1.7       cgd 	register_t *retval;
    220   1.1     glass {
    221  1.16   mycroft 	struct ultrix_sys_waitpid_args *uap = v;
    222  1.16   mycroft 	struct sys_wait4_args ua;
    223   1.1     glass 
    224  1.16   mycroft 	SCARG(&ua, pid) = SCARG(uap, pid);
    225  1.16   mycroft 	SCARG(&ua, status) = SCARG(uap, status);
    226  1.16   mycroft 	SCARG(&ua, options) = SCARG(uap, options);
    227  1.16   mycroft 	SCARG(&ua, rusage) = 0;
    228   1.1     glass 
    229  1.16   mycroft 	return (sys_wait4(p, &ua, retval));
    230   1.2     glass }
    231   1.2     glass 
    232  1.23  jonathan int
    233  1.16   mycroft ultrix_sys_wait3(p, v, retval)
    234   1.2     glass 	struct proc *p;
    235  1.15   thorpej 	void *v;
    236   1.7       cgd 	register_t *retval;
    237   1.2     glass {
    238  1.16   mycroft 	struct ultrix_sys_wait3_args *uap = v;
    239  1.16   mycroft 	struct sys_wait4_args ua;
    240   1.2     glass 
    241  1.16   mycroft 	SCARG(&ua, pid) = -1;
    242  1.16   mycroft 	SCARG(&ua, status) = SCARG(uap, status);
    243  1.16   mycroft 	SCARG(&ua, options) = SCARG(uap, options);
    244  1.16   mycroft 	SCARG(&ua, rusage) = SCARG(uap, rusage);
    245   1.1     glass 
    246  1.16   mycroft 	return (sys_wait4(p, &ua, retval));
    247   1.1     glass }
    248   1.1     glass 
    249  1.20  jonathan /*
    250  1.20  jonathan  * Ultrix binaries pass in FD_MAX as the first arg to select().
    251  1.23  jonathan  * On Ultrix, FD_MAX is 4096, which is more than the NetBSD sys_select()
    252  1.20  jonathan  * can handle.
    253  1.23  jonathan  * Since we can't have more than the (native) FD_MAX descriptors open,
    254  1.23  jonathan  * limit nfds to at most FD_MAX.
    255  1.20  jonathan  */
    256  1.23  jonathan int
    257  1.18  jonathan ultrix_sys_select(p, v, retval)
    258  1.18  jonathan 	struct proc *p;
    259  1.18  jonathan 	void *v;
    260  1.18  jonathan 	register_t *retval;
    261  1.18  jonathan {
    262  1.18  jonathan 	struct sys_select_args *uap = v;
    263  1.23  jonathan 	struct timeval atv;
    264  1.18  jonathan 	int error;
    265  1.18  jonathan 
    266  1.18  jonathan 	/* Limit number of FDs selected on to the native maximum */
    267  1.18  jonathan 
    268  1.18  jonathan 	if (SCARG(uap, nd) > FD_SETSIZE)
    269  1.18  jonathan 		SCARG(uap, nd) = FD_SETSIZE;
    270  1.18  jonathan 
    271  1.18  jonathan 	/* Check for negative timeval */
    272  1.18  jonathan 	if (SCARG(uap, tv)) {
    273  1.18  jonathan 		error = copyin((caddr_t)SCARG(uap, tv), (caddr_t)&atv,
    274  1.18  jonathan 			       sizeof(atv));
    275  1.18  jonathan 		if (error)
    276  1.18  jonathan 			goto done;
    277  1.18  jonathan #ifdef DEBUG
    278  1.18  jonathan 		/* Ultrix clients sometimes give negative timeouts? */
    279  1.18  jonathan 		if (atv.tv_sec < 0 || atv.tv_usec < 0)
    280  1.27  christos 			printf("ultrix select( %ld, %ld): negative timeout\n",
    281  1.26  christos 			    atv.tv_sec, atv.tv_usec);
    282  1.18  jonathan 		/*tvp = (timeval *)STACKGAPBASE;*/
    283  1.18  jonathan #endif
    284  1.18  jonathan 
    285  1.18  jonathan 	}
    286  1.18  jonathan 	error = sys_select(p, (void*) uap, retval);
    287  1.18  jonathan 	if (error == EINVAL)
    288  1.27  christos 		printf("ultrix select: bad args?\n");
    289  1.18  jonathan 
    290  1.18  jonathan done:
    291  1.18  jonathan 	return error;
    292   1.1     glass }
    293   1.1     glass 
    294  1.29   thorpej #if defined(NFS)
    295  1.23  jonathan int
    296  1.16   mycroft async_daemon(p, v, retval)
    297   1.1     glass 	struct proc *p;
    298  1.15   thorpej 	void *v;
    299   1.7       cgd 	register_t *retval;
    300   1.1     glass {
    301  1.16   mycroft 	struct sys_nfssvc_args ouap;
    302   1.1     glass 
    303  1.16   mycroft 	SCARG(&ouap, flag) = NFSSVC_BIOD;
    304  1.16   mycroft 	SCARG(&ouap, argp) = NULL;
    305   1.3     glass 
    306  1.16   mycroft 	return (sys_nfssvc(p, &ouap, retval));
    307   1.3     glass }
    308  1.29   thorpej #endif /* NFS */
    309   1.3     glass 
    310   1.1     glass 
    311   1.1     glass #define	SUN__MAP_NEW	0x80000000	/* if not, old mmap & cannot handle */
    312   1.1     glass 
    313  1.20  jonathan int
    314  1.16   mycroft ultrix_sys_mmap(p, v, retval)
    315   1.1     glass 	register struct proc *p;
    316  1.15   thorpej 	void *v;
    317   1.7       cgd 	register_t *retval;
    318   1.1     glass {
    319  1.16   mycroft 	register struct ultrix_sys_mmap_args *uap = v;
    320  1.16   mycroft 	struct sys_mmap_args ouap;
    321   1.1     glass 	register struct filedesc *fdp;
    322   1.1     glass 	register struct file *fp;
    323   1.1     glass 	register struct vnode *vp;
    324   1.1     glass 
    325   1.1     glass 	/*
    326   1.1     glass 	 * Verify the arguments.
    327   1.1     glass 	 */
    328  1.16   mycroft 	if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
    329   1.1     glass 		return (EINVAL);			/* XXX still needed? */
    330   1.1     glass 
    331  1.16   mycroft 	if ((SCARG(uap, flags) & SUN__MAP_NEW) == 0)
    332   1.1     glass 		return (EINVAL);
    333   1.1     glass 
    334  1.16   mycroft 	SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUN__MAP_NEW;
    335  1.16   mycroft 	SCARG(&ouap, addr) = SCARG(uap, addr);
    336  1.16   mycroft 
    337  1.16   mycroft 	if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 &&
    338  1.16   mycroft 	    SCARG(&ouap, addr) != 0 &&
    339  1.38  jonathan 	    SCARG(&ouap, addr) < (void *)round_page(p->p_vmspace->vm_daddr+MAXDSIZ))
    340  1.38  jonathan 		SCARG(&ouap, addr) = (void *)round_page(p->p_vmspace->vm_daddr+MAXDSIZ);
    341  1.16   mycroft 
    342  1.16   mycroft 	SCARG(&ouap, len) = SCARG(uap, len);
    343  1.16   mycroft 	SCARG(&ouap, prot) = SCARG(uap, prot);
    344  1.16   mycroft 	SCARG(&ouap, fd) = SCARG(uap, fd);
    345  1.16   mycroft 	SCARG(&ouap, pos) = SCARG(uap, pos);
    346   1.1     glass 
    347   1.1     glass 	/*
    348   1.1     glass 	 * Special case: if fd refers to /dev/zero, map as MAP_ANON.  (XXX)
    349   1.1     glass 	 */
    350   1.1     glass 	fdp = p->p_fd;
    351  1.16   mycroft 	if ((unsigned)SCARG(&ouap, fd) < fdp->fd_nfiles &&		/*XXX*/
    352  1.16   mycroft 	    (fp = fdp->fd_ofiles[SCARG(&ouap, fd)]) != NULL &&		/*XXX*/
    353   1.1     glass 	    fp->f_type == DTYPE_VNODE &&				/*XXX*/
    354   1.1     glass 	    (vp = (struct vnode *)fp->f_data)->v_type == VCHR &&	/*XXX*/
    355   1.1     glass 	    iszerodev(vp->v_rdev)) {					/*XXX*/
    356  1.16   mycroft 		SCARG(&ouap, flags) |= MAP_ANON;
    357  1.16   mycroft 		SCARG(&ouap, fd) = -1;
    358   1.1     glass 	}
    359   1.1     glass 
    360  1.16   mycroft 	return (sys_mmap(p, &ouap, retval));
    361   1.1     glass }
    362   1.1     glass 
    363  1.23  jonathan int
    364  1.16   mycroft ultrix_sys_setsockopt(p, v, retval)
    365   1.1     glass 	struct proc *p;
    366  1.15   thorpej 	void *v;
    367   1.7       cgd 	register_t *retval;
    368   1.1     glass {
    369  1.16   mycroft 	register struct ultrix_sys_setsockopt_args *uap = v;
    370   1.1     glass 	struct file *fp;
    371   1.1     glass 	struct mbuf *m = NULL;
    372   1.1     glass 	int error;
    373   1.1     glass 
    374  1.23  jonathan 	if ((error = getsock(p->p_fd, SCARG(uap, s), &fp))  != 0)
    375   1.1     glass 		return (error);
    376   1.1     glass #define	SO_DONTLINGER (~SO_LINGER)
    377  1.16   mycroft 	if (SCARG(uap, name) == SO_DONTLINGER) {
    378   1.1     glass 		m = m_get(M_WAIT, MT_SOOPTS);
    379   1.1     glass 		mtod(m, struct linger *)->l_onoff = 0;
    380   1.1     glass 		m->m_len = sizeof(struct linger);
    381  1.16   mycroft 		return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    382   1.1     glass 		    SO_LINGER, m));
    383   1.1     glass 	}
    384  1.30  jonathan 	if (SCARG(uap, level) == IPPROTO_IP) {
    385  1.30  jonathan #define		EMUL_IP_MULTICAST_IF		2
    386  1.30  jonathan #define		EMUL_IP_MULTICAST_TTL		3
    387  1.30  jonathan #define		EMUL_IP_MULTICAST_LOOP		4
    388  1.30  jonathan #define		EMUL_IP_ADD_MEMBERSHIP		5
    389  1.30  jonathan #define		EMUL_IP_DROP_MEMBERSHIP	6
    390  1.30  jonathan 		static int ipoptxlat[] = {
    391  1.30  jonathan 			IP_MULTICAST_IF,
    392  1.30  jonathan 			IP_MULTICAST_TTL,
    393  1.30  jonathan 			IP_MULTICAST_LOOP,
    394  1.30  jonathan 			IP_ADD_MEMBERSHIP,
    395  1.30  jonathan 			IP_DROP_MEMBERSHIP
    396  1.30  jonathan 		};
    397  1.30  jonathan 		if (SCARG(uap, name) >= EMUL_IP_MULTICAST_IF &&
    398  1.30  jonathan 		    SCARG(uap, name) <= EMUL_IP_DROP_MEMBERSHIP) {
    399  1.30  jonathan 			SCARG(uap, name) =
    400  1.30  jonathan 			    ipoptxlat[SCARG(uap, name) - EMUL_IP_MULTICAST_IF];
    401  1.30  jonathan 		}
    402  1.30  jonathan 	}
    403  1.16   mycroft 	if (SCARG(uap, valsize) > MLEN)
    404   1.1     glass 		return (EINVAL);
    405  1.16   mycroft 	if (SCARG(uap, val)) {
    406   1.1     glass 		m = m_get(M_WAIT, MT_SOOPTS);
    407  1.30  jonathan 		error = copyin(SCARG(uap, val), mtod(m, caddr_t),
    408  1.30  jonathan 		    (u_int)SCARG(uap, valsize));
    409  1.30  jonathan 		if (error) {
    410   1.1     glass 			(void) m_free(m);
    411   1.1     glass 			return (error);
    412   1.1     glass 		}
    413  1.16   mycroft 		m->m_len = SCARG(uap, valsize);
    414   1.1     glass 	}
    415  1.16   mycroft 	return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    416  1.16   mycroft 	    SCARG(uap, name), m));
    417   1.1     glass }
    418   1.1     glass 
    419  1.16   mycroft struct ultrix_utsname {
    420   1.1     glass 	char    sysname[9];
    421   1.1     glass 	char    nodename[9];
    422   1.1     glass 	char    nodeext[65-9];
    423   1.1     glass 	char    release[9];
    424   1.1     glass 	char    version[9];
    425   1.1     glass 	char    machine[9];
    426   1.1     glass };
    427   1.1     glass 
    428  1.20  jonathan int
    429  1.16   mycroft ultrix_sys_uname(p, v, retval)
    430   1.1     glass 	struct proc *p;
    431  1.15   thorpej 	void *v;
    432   1.7       cgd 	register_t *retval;
    433   1.1     glass {
    434  1.16   mycroft 	struct ultrix_sys_uname_args *uap = v;
    435  1.16   mycroft 	struct ultrix_utsname sut;
    436   1.1     glass 	extern char ostype[], machine[], osrelease[];
    437   1.1     glass 
    438   1.1     glass 	bzero(&sut, sizeof(sut));
    439   1.1     glass 
    440   1.1     glass 	bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1);
    441   1.1     glass 	bcopy(hostname, sut.nodename, sizeof(sut.nodename));
    442   1.1     glass 	sut.nodename[sizeof(sut.nodename)-1] = '\0';
    443   1.1     glass 	bcopy(osrelease, sut.release, sizeof(sut.release) - 1);
    444   1.1     glass 	bcopy("1", sut.version, sizeof(sut.version) - 1);
    445   1.1     glass 	bcopy(machine, sut.machine, sizeof(sut.machine) - 1);
    446   1.1     glass 
    447  1.16   mycroft 	return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
    448  1.16   mycroft 	    sizeof(struct ultrix_utsname));
    449   1.1     glass }
    450   1.1     glass 
    451   1.1     glass int
    452  1.16   mycroft ultrix_sys_setpgrp(p, v, retval)
    453   1.1     glass 	struct proc *p;
    454  1.15   thorpej 	void *v;
    455   1.7       cgd 	register_t *retval;
    456   1.1     glass {
    457  1.16   mycroft 	struct ultrix_sys_setpgrp_args *uap = v;
    458  1.15   thorpej 
    459   1.1     glass 	/*
    460   1.1     glass 	 * difference to our setpgid call is to include backwards
    461   1.1     glass 	 * compatibility to pre-setsid() binaries. Do setsid()
    462   1.1     glass 	 * instead of setpgid() in those cases where the process
    463   1.1     glass 	 * tries to create a new session the old way.
    464   1.1     glass 	 */
    465  1.16   mycroft 	if (!SCARG(uap, pgid) &&
    466  1.16   mycroft 	    (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
    467  1.16   mycroft 		return sys_setsid(p, uap, retval);
    468   1.1     glass 	else
    469  1.16   mycroft 		return sys_setpgid(p, uap, retval);
    470   1.1     glass }
    471   1.1     glass 
    472   1.1     glass #if defined (NFSSERVER)
    473  1.20  jonathan int
    474  1.16   mycroft ultrix_sys_nfssvc(p, v, retval)
    475   1.1     glass 	struct proc *p;
    476  1.15   thorpej 	void *v;
    477   1.7       cgd 	register_t *retval;
    478   1.1     glass {
    479  1.23  jonathan 
    480  1.23  jonathan #if 0	/* XXX */
    481  1.16   mycroft 	struct ultrix_sys_nfssvc_args *uap = v;
    482  1.16   mycroft 	struct emul *e = p->p_emul;
    483  1.16   mycroft 	struct sys_nfssvc_args outuap;
    484   1.1     glass 	struct sockaddr sa;
    485   1.1     glass 	int error;
    486   1.1     glass 
    487   1.1     glass 	bzero(&outuap, sizeof outuap);
    488  1.16   mycroft 	SCARG(&outuap, fd) = SCARG(uap, fd);
    489  1.16   mycroft 	SCARG(&outuap, mskval) = STACKGAPBASE;
    490  1.16   mycroft 	SCARG(&outuap, msklen) = sizeof sa;
    491  1.16   mycroft 	SCARG(&outuap, mtchval) = outuap.mskval + sizeof sa;
    492  1.16   mycroft 	SCARG(&outuap, mtchlen) = sizeof sa;
    493   1.1     glass 
    494   1.1     glass 	bzero(&sa, sizeof sa);
    495  1.16   mycroft 	if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
    496   1.1     glass 		return (error);
    497  1.16   mycroft 	if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
    498   1.1     glass 		return (error);
    499   1.1     glass 
    500   1.1     glass 	return nfssvc(p, &outuap, retval);
    501  1.16   mycroft #else
    502  1.16   mycroft 	return (ENOSYS);
    503  1.16   mycroft #endif
    504   1.1     glass }
    505   1.1     glass #endif /* NFSSERVER */
    506   1.1     glass 
    507  1.16   mycroft struct ultrix_ustat {
    508   1.1     glass 	daddr_t	f_tfree;	/* total free */
    509   1.1     glass 	ino_t	f_tinode;	/* total inodes free */
    510   1.1     glass 	char	f_fname[6];	/* filsys name */
    511   1.1     glass 	char	f_fpack[6];	/* filsys pack name */
    512   1.1     glass };
    513  1.16   mycroft 
    514  1.20  jonathan int
    515  1.16   mycroft ultrix_sys_ustat(p, v, retval)
    516   1.1     glass 	struct proc *p;
    517  1.15   thorpej 	void *v;
    518   1.7       cgd 	register_t *retval;
    519   1.1     glass {
    520  1.16   mycroft 	struct ultrix_sys_ustat_args *uap = v;
    521  1.16   mycroft 	struct ultrix_ustat us;
    522   1.1     glass 	int error;
    523   1.1     glass 
    524   1.1     glass 	bzero(&us, sizeof us);
    525   1.1     glass 
    526   1.1     glass 	/*
    527   1.1     glass 	 * XXX: should set f_tfree and f_tinode at least
    528  1.16   mycroft 	 * How do we translate dev -> fstat? (and then to ultrix_ustat)
    529   1.1     glass 	 */
    530   1.1     glass 
    531  1.23  jonathan 	if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
    532   1.1     glass 		return (error);
    533   1.1     glass 	return 0;
    534   1.1     glass }
    535   1.1     glass 
    536  1.20  jonathan int
    537  1.16   mycroft ultrix_sys_quotactl(p, v, retval)
    538   1.1     glass 	struct proc *p;
    539  1.15   thorpej 	void *v;
    540   1.7       cgd 	register_t *retval;
    541   1.1     glass {
    542  1.23  jonathan 
    543  1.23  jonathan #ifdef notyet
    544  1.16   mycroft 	struct ultrix_sys_quotactl_args *uap = v;
    545  1.23  jonathan #endif
    546  1.15   thorpej 
    547   1.1     glass 	return EINVAL;
    548   1.1     glass }
    549   1.1     glass 
    550  1.20  jonathan int
    551  1.16   mycroft ultrix_sys_vhangup(p, v, retval)
    552   1.1     glass 	struct proc *p;
    553  1.16   mycroft 	void *v;
    554   1.7       cgd 	register_t *retval;
    555   1.1     glass {
    556  1.16   mycroft 
    557   1.1     glass 	return 0;
    558   1.1     glass }
    559  1.35  jonathan 
    560  1.35  jonathan 
    561  1.35  jonathan /*
    562  1.35  jonathan  * RISC Ultrix cache control syscalls
    563  1.35  jonathan  */
    564  1.35  jonathan #ifdef __mips
    565  1.35  jonathan int
    566  1.35  jonathan ultrix_sys_cacheflush(p, v, retval)
    567  1.35  jonathan 	register struct proc *p;
    568  1.35  jonathan 	void *v;
    569  1.35  jonathan 	register_t *retval;
    570  1.35  jonathan {
    571  1.35  jonathan 	register struct ultrix_sys_cacheflush_args /* {
    572  1.35  jonathan 		syscallarg(void *) addr;
    573  1.35  jonathan 		syscallarg(int) nbytes;
    574  1.35  jonathan 		syscallarg(int) flag;
    575  1.35  jonathan 	} */ *uap = v;
    576  1.35  jonathan 	register vm_offset_t va  = (vm_offset_t)SCARG(uap, addr);
    577  1.35  jonathan 	register int nbytes     = SCARG(uap, nbytes);
    578  1.35  jonathan 	register int whichcache = SCARG(uap, whichcache);
    579  1.35  jonathan 
    580  1.35  jonathan 	return (mips_user_cacheflush(p, va, nbytes, whichcache));
    581  1.35  jonathan }
    582  1.35  jonathan 
    583  1.35  jonathan 
    584  1.35  jonathan int
    585  1.35  jonathan ultrix_sys_cachectl(p, v, retval)
    586  1.35  jonathan 	register struct proc *p;
    587  1.35  jonathan 	void *v;
    588  1.35  jonathan 	register_t *retval;
    589  1.35  jonathan {
    590  1.35  jonathan 	register struct ultrix_sys_cachectl_args /* {
    591  1.35  jonathan 		syscallarg(void *) addr;
    592  1.35  jonathan 		syscallarg(int) nbytes;
    593  1.35  jonathan 		syscallarg(int) cacheop;
    594  1.35  jonathan 	} */ *uap = v;
    595  1.35  jonathan 	register vm_offset_t va  = (vm_offset_t)SCARG(uap, addr);
    596  1.35  jonathan 	register int nbytes  = SCARG(uap, nbytes);
    597  1.35  jonathan 	register int cacheop = SCARG(uap, cacheop);
    598  1.35  jonathan 
    599  1.35  jonathan 	return mips_user_cachectl(p, va, nbytes, cacheop);
    600  1.35  jonathan }
    601  1.35  jonathan 
    602  1.35  jonathan #endif	/* __mips */
    603  1.35  jonathan 
    604   1.1     glass 
    605  1.20  jonathan int
    606  1.16   mycroft ultrix_sys_exportfs(p, v, retval)
    607   1.1     glass 	struct proc *p;
    608  1.15   thorpej 	void *v;
    609   1.7       cgd 	register_t *retval;
    610   1.1     glass {
    611  1.23  jonathan #ifdef notyet
    612  1.16   mycroft 	struct ultrix_sys_exportfs_args *uap = v;
    613  1.23  jonathan #endif
    614  1.15   thorpej 
    615   1.1     glass 	/*
    616   1.1     glass 	 * XXX: should perhaps translate into a mount(2)
    617   1.1     glass 	 * with MOUNT_EXPORT?
    618   1.1     glass 	 */
    619   1.1     glass 	return 0;
    620   1.1     glass }
    621   1.1     glass 
    622  1.16   mycroft int
    623  1.19  jonathan ultrix_sys_sigpending(p, v, retval)
    624  1.19  jonathan 	struct proc *p;
    625  1.19  jonathan 	void *v;
    626  1.19  jonathan 	register_t *retval;
    627  1.19  jonathan {
    628  1.19  jonathan 	struct ultrix_sys_sigpending_args *uap = v;
    629  1.19  jonathan 	int mask = p->p_siglist & p->p_sigmask;
    630  1.19  jonathan 
    631  1.19  jonathan 	return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
    632  1.19  jonathan }
    633  1.19  jonathan 
    634  1.19  jonathan int
    635  1.16   mycroft ultrix_sys_sigcleanup(p, v, retval)
    636  1.13    mellon 	struct proc *p;
    637  1.15   thorpej 	void *v;
    638  1.13    mellon 	register_t *retval;
    639  1.13    mellon {
    640  1.16   mycroft 	struct ultrix_sys_sigcleanup_args *uap = v;
    641  1.15   thorpej 
    642  1.16   mycroft 	return sys_sigreturn(p, (struct sys_sigreturn_args *)uap, retval);
    643  1.19  jonathan }
    644  1.19  jonathan 
    645  1.30  jonathan 
    646  1.32  jonathan int
    647  1.30  jonathan ultrix_sys_shmsys(p, v, retval)
    648  1.30  jonathan 	struct proc *p;
    649  1.30  jonathan 	void *v;
    650  1.30  jonathan 	register_t *retval;
    651  1.30  jonathan {
    652  1.30  jonathan 
    653  1.30  jonathan #ifdef SYSVSHM
    654  1.30  jonathan 
    655  1.30  jonathan 	/* Ultrix SVSHM weirndess: */
    656  1.30  jonathan 	struct ultrix_sys_shmsys_args *uap = v;
    657  1.30  jonathan 	struct sys_shmat_args shmat_args;
    658  1.30  jonathan 	struct sys_shmctl_args shmctl_args;
    659  1.30  jonathan 	struct sys_shmdt_args shmdt_args;
    660  1.30  jonathan 	struct sys_shmget_args shmget_args;
    661  1.30  jonathan 
    662  1.30  jonathan 
    663  1.30  jonathan 	switch (SCARG(uap, shmop)) {
    664  1.30  jonathan 	case 0:						/* Ultrix shmat() */
    665  1.30  jonathan 		SCARG(&shmat_args, shmid) = SCARG(uap, a2);
    666  1.30  jonathan 		SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
    667  1.30  jonathan 		SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
    668  1.30  jonathan 		return (sys_shmat(p, &shmat_args, retval));
    669  1.30  jonathan 
    670  1.30  jonathan 	case 1:						/* Ultrix shmctl() */
    671  1.30  jonathan 		SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
    672  1.30  jonathan 		SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
    673  1.30  jonathan 		SCARG(&shmctl_args, buf) = (struct shmid_ds *)SCARG(uap, a4);
    674  1.30  jonathan 		return (sys_shmctl(p, &shmctl_args, retval));
    675  1.30  jonathan 
    676  1.30  jonathan 	case 2:						/* Ultrix shmdt() */
    677  1.30  jonathan 		SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a2);
    678  1.30  jonathan 		return (sys_shmdt(p, &shmdt_args, retval));
    679  1.30  jonathan 
    680  1.30  jonathan 	case 3:						/* Ultrix shmget() */
    681  1.30  jonathan 		SCARG(&shmget_args, key) = SCARG(uap, a2);
    682  1.30  jonathan 		SCARG(&shmget_args, size) = SCARG(uap, a3);
    683  1.30  jonathan 		SCARG(&shmget_args, shmflg) = SCARG(uap, a4)
    684  1.30  jonathan 		    & (IPC_CREAT|IPC_EXCL|IPC_NOWAIT);
    685  1.30  jonathan 		return (sys_shmget(p, &shmget_args, retval));
    686  1.30  jonathan 
    687  1.30  jonathan 	default:
    688  1.30  jonathan 		return (EINVAL);
    689  1.30  jonathan 	}
    690  1.31  jonathan #else
    691  1.31  jonathan 	return (EOPNOTSUPP);
    692  1.30  jonathan #endif	/* SYSVSHM */
    693   1.1     glass }
    694