Home | History | Annotate | Line # | Download | only in ultrix
ultrix_misc.c revision 1.112.2.3
      1  1.112.2.3      yamt /*	$NetBSD: ultrix_misc.c,v 1.112.2.3 2010/08/11 22:53:13 yamt 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.86       agc  * 3. Neither the name of the University nor the names of its contributors
     57        1.1     glass  *    may be used to endorse or promote products derived from this software
     58        1.1     glass  *    without specific prior written permission.
     59        1.1     glass  *
     60        1.1     glass  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     61        1.1     glass  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     62        1.1     glass  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     63        1.1     glass  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     64        1.1     glass  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     65        1.1     glass  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     66        1.1     glass  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     67        1.1     glass  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     68        1.1     glass  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     69        1.1     glass  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     70        1.1     glass  * SUCH DAMAGE.
     71        1.1     glass  *
     72        1.5       cgd  *
     73        1.1     glass  *	@(#)sun_misc.c	8.1 (Berkeley) 6/18/93
     74        1.1     glass  *
     75       1.98     perry  * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
     76        1.1     glass  */
     77       1.74     lukem 
     78       1.74     lukem #include <sys/cdefs.h>
     79  1.112.2.3      yamt __KERNEL_RCSID(0, "$NetBSD: ultrix_misc.c,v 1.112.2.3 2010/08/11 22:53:13 yamt Exp $");
     80        1.1     glass 
     81       1.69       mrg #if defined(_KERNEL_OPT)
     82       1.47      tron #include "opt_sysv.h"
     83       1.63  jdolecek #endif
     84       1.40    mhitch 
     85       1.38  jonathan #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     86       1.38  jonathan 
     87        1.1     glass /*
     88       1.49  sommerfe  * Ultrix compatibility module.
     89        1.1     glass  *
     90       1.49  sommerfe  * Ultrix system calls that are implemented differently in BSD are
     91        1.1     glass  * handled here.
     92        1.1     glass  */
     93       1.39   thorpej 
     94        1.1     glass #include <sys/param.h>
     95        1.1     glass #include <sys/systm.h>
     96        1.1     glass #include <sys/namei.h>
     97       1.25   mycroft #include <sys/dirent.h>
     98        1.1     glass #include <sys/proc.h>
     99        1.1     glass #include <sys/file.h>
    100        1.1     glass #include <sys/filedesc.h>
    101        1.1     glass #include <sys/kernel.h>
    102        1.1     glass #include <sys/exec.h>
    103        1.1     glass #include <sys/malloc.h>
    104        1.1     glass #include <sys/mbuf.h>
    105        1.1     glass #include <sys/mman.h>
    106        1.1     glass #include <sys/mount.h>
    107        1.1     glass #include <sys/resource.h>
    108        1.1     glass #include <sys/resourcevar.h>
    109        1.1     glass #include <sys/signal.h>
    110        1.1     glass #include <sys/signalvar.h>
    111        1.1     glass #include <sys/socket.h>
    112        1.1     glass #include <sys/vnode.h>
    113        1.1     glass #include <sys/uio.h>
    114        1.1     glass #include <sys/wait.h>
    115        1.1     glass #include <sys/utsname.h>
    116        1.1     glass #include <sys/unistd.h>
    117       1.30  jonathan #include <sys/ipc.h>
    118       1.20  jonathan 
    119       1.16   mycroft #include <sys/syscallargs.h>
    120       1.16   mycroft 
    121       1.99      fvdl #include <uvm/uvm_extern.h>
    122       1.99      fvdl 
    123       1.16   mycroft #include <compat/ultrix/ultrix_syscall.h>
    124       1.16   mycroft #include <compat/ultrix/ultrix_syscallargs.h>
    125       1.30  jonathan #include <compat/common/compat_util.h>
    126  1.112.2.1      yamt #include <compat/sys/time.h>
    127        1.1     glass 
    128        1.1     glass #include <netinet/in.h>
    129        1.1     glass 
    130        1.1     glass #include <miscfs/specfs/specdev.h>
    131        1.1     glass 
    132        1.3     glass #include <nfs/rpcv2.h>
    133       1.21        pk #include <nfs/nfsproto.h>
    134        1.3     glass #include <nfs/nfs.h>
    135       1.11  christos 
    136       1.23  jonathan #include <sys/socketvar.h>				/* sosetopt() */
    137       1.23  jonathan 
    138       1.52  drochner #include <compat/ultrix/ultrix_flock.h>
    139       1.67    simonb 
    140      1.103  christos #include <compat/sys/signal.h>
    141      1.103  christos #include <compat/sys/signalvar.h>
    142      1.103  christos 
    143       1.67    simonb #ifdef __mips
    144       1.67    simonb #include <mips/cachectl.h>
    145       1.96  drochner #include <mips/frame.h>
    146       1.67    simonb #endif
    147       1.52  drochner 
    148       1.93    simonb static int ultrix_to_bsd_flock(struct ultrix_flock *, struct flock *);
    149       1.93    simonb static void bsd_to_ultrix_flock(struct flock *, struct ultrix_flock *);
    150       1.35  jonathan 
    151       1.11  christos extern struct sysent ultrix_sysent[];
    152       1.60    simonb extern const char * const ultrix_syscallnames[];
    153       1.45  drochner extern char ultrix_sigcode[], ultrix_esigcode[];
    154       1.19  jonathan 
    155       1.87       chs struct uvm_object *emul_ultrix_object;
    156       1.87       chs 
    157      1.101  christos #ifndef __HAVE_SYSCALL_INTERN
    158      1.101  christos void	syscall(void);
    159      1.101  christos #endif
    160      1.101  christos 
    161  1.112.2.1      yamt struct emul emul_ultrix = {
    162  1.112.2.3      yamt 	.e_name =		"ultrix",
    163  1.112.2.3      yamt 	.e_path =		"/emul/ultrix",
    164       1.68   thorpej #ifndef __HAVE_MINIMAL_EMUL
    165  1.112.2.3      yamt 	.e_flags =		0,
    166  1.112.2.3      yamt 	.e_errno =		NULL,
    167  1.112.2.3      yamt 	.e_nosys =		ULTRIX_SYS_syscall,
    168  1.112.2.3      yamt 	.e_nsysent =		ULTRIX_SYS_NSYSENT,
    169  1.112.2.3      yamt #endif
    170  1.112.2.3      yamt 	.e_sysent =		ultrix_sysent,
    171  1.112.2.3      yamt #ifdef SYSCALL_DEBUG
    172  1.112.2.3      yamt 	.e_syscallnames =	ultrix_syscallnames,
    173  1.112.2.3      yamt #else
    174  1.112.2.3      yamt 	.e_syscallnames =	NULL,
    175       1.68   thorpej #endif
    176       1.97  drochner #ifdef __mips
    177  1.112.2.3      yamt 	.e_sendsig =		sendsig_sigcontext,
    178       1.97  drochner #else /* vax */
    179  1.112.2.3      yamt 	.e_sendsig =		sendsig,
    180       1.97  drochner #endif
    181  1.112.2.3      yamt 	.e_trapsignal =		trapsignal,
    182  1.112.2.3      yamt 	.e_tracesig =		NULL,
    183  1.112.2.3      yamt 	.e_sigcode =		ultrix_sigcode,
    184  1.112.2.3      yamt 	.e_esigcode =		ultrix_esigcode,
    185  1.112.2.3      yamt 	.e_sigobject =		&emul_ultrix_object,
    186  1.112.2.3      yamt 	.e_setregs =		setregs,
    187  1.112.2.3      yamt 	.e_proc_exec =		NULL,
    188  1.112.2.3      yamt 	.e_proc_fork =		NULL,
    189  1.112.2.3      yamt 	.e_proc_exit =		NULL,
    190  1.112.2.3      yamt 	.e_lwp_fork =		NULL,
    191  1.112.2.3      yamt 	.e_lwp_exit =		NULL,
    192       1.68   thorpej #ifdef __HAVE_SYSCALL_INTERN
    193  1.112.2.3      yamt 	.e_syscall_intern =	syscall_intern,
    194       1.68   thorpej #else
    195  1.112.2.3      yamt 	.e_syscall_intern =	syscall,
    196       1.68   thorpej #endif
    197  1.112.2.3      yamt 	.e_sysctlovly =		NULL,
    198  1.112.2.3      yamt 	.e_fault =		NULL,
    199  1.112.2.3      yamt 	.e_vm_default_addr =	uvm_default_mapaddr,
    200  1.112.2.3      yamt 	.e_usertrap =		NULL,
    201  1.112.2.3      yamt 	.e_sa =			NULL,
    202  1.112.2.3      yamt 	.e_ucsize =		0,
    203  1.112.2.3      yamt 	.e_startlwp =		NULL
    204       1.11  christos };
    205        1.1     glass 
    206        1.6     glass #define GSI_PROG_ENV 1
    207        1.6     glass 
    208       1.23  jonathan int
    209      1.109       dsl ultrix_sys_getsysinfo(struct lwp *l, const struct ultrix_sys_getsysinfo_args *uap, register_t *retval)
    210        1.6     glass {
    211        1.6     glass 	static short progenv = 0;
    212        1.6     glass 
    213       1.16   mycroft 	switch (SCARG(uap, op)) {
    214        1.6     glass 		/* operations implemented: */
    215        1.6     glass 	case GSI_PROG_ENV:
    216       1.16   mycroft 		if (SCARG(uap, nbytes) < sizeof(short))
    217        1.6     glass 			return EINVAL;
    218        1.6     glass 		*retval = 1;
    219      1.110  christos 		return copyout(&progenv, SCARG(uap, buffer), sizeof(progenv));
    220        1.6     glass 	default:
    221        1.6     glass 		*retval = 0; /* info unavail */
    222        1.6     glass 		return 0;
    223        1.6     glass 	}
    224        1.6     glass }
    225        1.6     glass 
    226       1.23  jonathan int
    227      1.109       dsl ultrix_sys_setsysinfo(struct lwp *l, const struct ultrix_sys_setsysinfo_args *uap, register_t *retval)
    228        1.6     glass {
    229       1.23  jonathan 
    230        1.6     glass 	*retval = 0;
    231        1.6     glass 	return 0;
    232        1.6     glass }
    233        1.6     glass 
    234       1.23  jonathan int
    235      1.109       dsl ultrix_sys_waitpid(struct lwp *l, const struct ultrix_sys_waitpid_args *uap, register_t *retval)
    236        1.1     glass {
    237  1.112.2.1      yamt 	struct compat_50_sys_wait4_args ap;
    238        1.1     glass 
    239      1.110  christos 	SCARG(&ap, pid) = SCARG(uap, pid);
    240      1.110  christos 	SCARG(&ap, status) = SCARG(uap, status);
    241      1.110  christos 	SCARG(&ap, options) = SCARG(uap, options);
    242      1.110  christos 	SCARG(&ap, rusage) = 0;
    243        1.1     glass 
    244  1.112.2.1      yamt 	return compat_50_sys_wait4(l, &ap, retval);
    245        1.2     glass }
    246        1.2     glass 
    247       1.23  jonathan int
    248      1.109       dsl ultrix_sys_wait3(struct lwp *l, const struct ultrix_sys_wait3_args *uap, register_t *retval)
    249        1.2     glass {
    250  1.112.2.1      yamt 	struct compat_50_sys_wait4_args ap;
    251        1.2     glass 
    252      1.110  christos 	SCARG(&ap, pid) = -1;
    253      1.110  christos 	SCARG(&ap, status) = SCARG(uap, status);
    254      1.110  christos 	SCARG(&ap, options) = SCARG(uap, options);
    255      1.110  christos 	SCARG(&ap, rusage) = SCARG(uap, rusage);
    256        1.1     glass 
    257  1.112.2.1      yamt 	return compat_50_sys_wait4(l, &ap, retval);
    258        1.1     glass }
    259        1.1     glass 
    260       1.20  jonathan /*
    261       1.20  jonathan  * Ultrix binaries pass in FD_MAX as the first arg to select().
    262       1.23  jonathan  * On Ultrix, FD_MAX is 4096, which is more than the NetBSD sys_select()
    263       1.20  jonathan  * can handle.
    264       1.98     perry  * Since we can't have more than the (native) FD_MAX descriptors open,
    265       1.23  jonathan  * limit nfds to at most FD_MAX.
    266       1.20  jonathan  */
    267       1.23  jonathan int
    268      1.110  christos ultrix_sys_select(struct lwp *l, const struct ultrix_sys_select_args *uap, register_t *retval)
    269       1.18  jonathan {
    270  1.112.2.1      yamt 	struct timeval50 atv;
    271       1.18  jonathan 	int error;
    272  1.112.2.1      yamt 	struct compat_50_sys_select_args ap;
    273       1.18  jonathan 
    274       1.18  jonathan 	/* Limit number of FDs selected on to the native maximum */
    275       1.18  jonathan 
    276       1.18  jonathan 	if (SCARG(uap, nd) > FD_SETSIZE)
    277      1.110  christos 		SCARG(&ap, nd) = FD_SETSIZE;
    278      1.110  christos 	else
    279      1.110  christos 		SCARG(&ap, nd) = SCARG(uap, nd);
    280       1.18  jonathan 
    281      1.110  christos 	SCARG(&ap, in) = SCARG(uap, in);
    282      1.110  christos 	SCARG(&ap, ou) = SCARG(uap, ou);
    283      1.110  christos 	SCARG(&ap, ex) = SCARG(uap, ex);
    284      1.110  christos 	SCARG(&ap, tv) = SCARG(uap, tv);
    285       1.18  jonathan 	/* Check for negative timeval */
    286      1.110  christos 	if (SCARG(&ap, tv)) {
    287      1.110  christos 		error = copyin(SCARG(uap, tv), &atv, sizeof(atv));
    288       1.18  jonathan 		if (error)
    289       1.18  jonathan 			goto done;
    290       1.18  jonathan #ifdef DEBUG
    291       1.18  jonathan 		/* Ultrix clients sometimes give negative timeouts? */
    292       1.18  jonathan 		if (atv.tv_sec < 0 || atv.tv_usec < 0)
    293       1.27  christos 			printf("ultrix select( %ld, %ld): negative timeout\n",
    294       1.26  christos 			    atv.tv_sec, atv.tv_usec);
    295       1.18  jonathan #endif
    296       1.18  jonathan 
    297       1.18  jonathan 	}
    298  1.112.2.1      yamt 	error = compat_50_sys_select(l, &ap, retval);
    299       1.18  jonathan 	if (error == EINVAL)
    300       1.27  christos 		printf("ultrix select: bad args?\n");
    301       1.18  jonathan 
    302       1.18  jonathan done:
    303       1.18  jonathan 	return error;
    304        1.1     glass }
    305        1.1     glass 
    306        1.1     glass 
    307        1.1     glass #define	SUN__MAP_NEW	0x80000000	/* if not, old mmap & cannot handle */
    308        1.1     glass 
    309       1.20  jonathan int
    310      1.109       dsl ultrix_sys_mmap(struct lwp *l, const struct ultrix_sys_mmap_args *uap, register_t *retval)
    311        1.1     glass {
    312       1.16   mycroft 	struct sys_mmap_args ouap;
    313        1.1     glass 
    314        1.1     glass 	/*
    315        1.1     glass 	 * Verify the arguments.
    316        1.1     glass 	 */
    317       1.16   mycroft 	if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
    318      1.110  christos 		return EINVAL;			/* XXX still needed? */
    319        1.1     glass 
    320       1.16   mycroft 	if ((SCARG(uap, flags) & SUN__MAP_NEW) == 0)
    321      1.110  christos 		return EINVAL;
    322        1.1     glass 
    323       1.16   mycroft 	SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUN__MAP_NEW;
    324       1.16   mycroft 	SCARG(&ouap, addr) = SCARG(uap, addr);
    325       1.16   mycroft 	SCARG(&ouap, len) = SCARG(uap, len);
    326       1.16   mycroft 	SCARG(&ouap, prot) = SCARG(uap, prot);
    327       1.16   mycroft 	SCARG(&ouap, fd) = SCARG(uap, fd);
    328       1.16   mycroft 	SCARG(&ouap, pos) = SCARG(uap, pos);
    329        1.1     glass 
    330      1.110  christos 	return sys_mmap(l, &ouap, retval);
    331        1.1     glass }
    332        1.1     glass 
    333       1.23  jonathan int
    334      1.109       dsl ultrix_sys_setsockopt(struct lwp *l, const struct ultrix_sys_setsockopt_args *uap, register_t *retval)
    335        1.1     glass {
    336  1.112.2.1      yamt 	struct sockopt sopt;
    337      1.111        ad 	struct socket *so;
    338        1.1     glass 	int error;
    339      1.110  christos 	struct sys_setsockopt_args ap;
    340      1.110  christos 
    341      1.110  christos 	SCARG(&ap, s) = SCARG(uap, s);
    342      1.110  christos 	SCARG(&ap, level) = SCARG(uap, level);
    343      1.110  christos 	SCARG(&ap, name) = SCARG(uap, name);
    344      1.110  christos 	SCARG(&ap, val) = SCARG(uap, val);
    345      1.110  christos 	SCARG(&ap, valsize) = SCARG(uap, valsize);
    346        1.1     glass 
    347  1.112.2.1      yamt 	/* fd_getsock() will use the descriptor for us */
    348      1.111        ad 	if ((error = fd_getsock(SCARG(&ap, s), &so))  != 0)
    349      1.110  christos 		return error;
    350        1.1     glass #define	SO_DONTLINGER (~SO_LINGER)
    351      1.110  christos 	if (SCARG(&ap, name) == SO_DONTLINGER) {
    352  1.112.2.1      yamt 		struct linger lg;
    353  1.112.2.1      yamt 
    354  1.112.2.1      yamt 		lg.l_onoff = 0;
    355  1.112.2.1      yamt 		error = so_setsockopt(l, so, SCARG(&ap, level), SO_LINGER,
    356  1.112.2.1      yamt 		    &lg, sizeof(lg));
    357  1.112.2.1      yamt 		goto out;
    358        1.1     glass 	}
    359      1.110  christos 	if (SCARG(&ap, level) == IPPROTO_IP) {
    360       1.30  jonathan #define		EMUL_IP_MULTICAST_IF		2
    361       1.30  jonathan #define		EMUL_IP_MULTICAST_TTL		3
    362       1.30  jonathan #define		EMUL_IP_MULTICAST_LOOP		4
    363       1.30  jonathan #define		EMUL_IP_ADD_MEMBERSHIP		5
    364       1.30  jonathan #define		EMUL_IP_DROP_MEMBERSHIP	6
    365       1.94      matt 		static const int ipoptxlat[] = {
    366       1.30  jonathan 			IP_MULTICAST_IF,
    367       1.30  jonathan 			IP_MULTICAST_TTL,
    368       1.30  jonathan 			IP_MULTICAST_LOOP,
    369       1.30  jonathan 			IP_ADD_MEMBERSHIP,
    370       1.30  jonathan 			IP_DROP_MEMBERSHIP
    371       1.30  jonathan 		};
    372      1.110  christos 		if (SCARG(&ap, name) >= EMUL_IP_MULTICAST_IF &&
    373      1.110  christos 		    SCARG(&ap, name) <= EMUL_IP_DROP_MEMBERSHIP) {
    374      1.110  christos 			SCARG(&ap, name) =
    375      1.110  christos 			    ipoptxlat[SCARG(&ap, name) - EMUL_IP_MULTICAST_IF];
    376       1.30  jonathan 		}
    377       1.30  jonathan 	}
    378      1.110  christos 	if (SCARG(&ap, valsize) > MLEN) {
    379       1.51   thorpej 		error = EINVAL;
    380       1.51   thorpej 		goto out;
    381       1.51   thorpej 	}
    382  1.112.2.1      yamt 	sockopt_init(&sopt, SCARG(&ap, level), SCARG(&ap, name),
    383  1.112.2.1      yamt 	    SCARG(&ap, valsize));
    384      1.110  christos 	if (SCARG(&ap, val)) {
    385  1.112.2.1      yamt 		error = copyin(SCARG(&ap, val), sopt.sopt_data,
    386      1.110  christos 		    (u_int)SCARG(&ap, valsize));
    387        1.1     glass 	}
    388  1.112.2.1      yamt 	if (error == 0)
    389  1.112.2.1      yamt 		error = sosetopt(so, &sopt);
    390  1.112.2.1      yamt 	sockopt_destroy(&sopt);
    391       1.51   thorpej  out:
    392      1.111        ad  	fd_putfile(SCARG(uap, s));
    393      1.110  christos 	return error;
    394        1.1     glass }
    395        1.1     glass 
    396       1.57    simonb #define	ULTRIX__SYS_NMLN	32
    397       1.57    simonb 
    398       1.16   mycroft struct ultrix_utsname {
    399       1.57    simonb 	char    sysname[ULTRIX__SYS_NMLN];
    400       1.57    simonb 	char    nodename[ULTRIX__SYS_NMLN];
    401       1.57    simonb 	char    release[ULTRIX__SYS_NMLN];
    402       1.57    simonb 	char    version[ULTRIX__SYS_NMLN];
    403       1.57    simonb 	char    machine[ULTRIX__SYS_NMLN];
    404        1.1     glass };
    405        1.1     glass 
    406       1.20  jonathan int
    407      1.109       dsl ultrix_sys_uname(struct lwp *l, const struct ultrix_sys_uname_args *uap, register_t *retval)
    408        1.1     glass {
    409       1.16   mycroft 	struct ultrix_utsname sut;
    410       1.59  nisimura 	const char *cp;
    411       1.59  nisimura 	char *dp, *ep;
    412        1.1     glass 
    413       1.41     perry 	memset(&sut, 0, sizeof(sut));
    414        1.1     glass 
    415       1.57    simonb 	strncpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
    416       1.57    simonb 	strncpy(sut.nodename, hostname, sizeof(sut.nodename) - 1);
    417       1.57    simonb 	strncpy(sut.release, osrelease, sizeof(sut.release) - 1);
    418       1.59  nisimura 	dp = sut.version;
    419       1.59  nisimura 	ep = &sut.version[sizeof(sut.version) - 1];
    420       1.59  nisimura 	for (cp = version; *cp && *cp != '('; cp++)
    421       1.59  nisimura 		;
    422       1.59  nisimura 	for (cp++; *cp && *cp != ')' && dp < ep; cp++)
    423       1.59  nisimura 		*dp++ = *cp;
    424       1.59  nisimura 	for (; *cp && *cp != '#'; cp++)
    425       1.59  nisimura 		;
    426       1.59  nisimura 	for (; *cp && *cp != ':' && dp < ep; cp++)
    427       1.59  nisimura 		*dp++ = *cp;
    428       1.59  nisimura 	*dp = '\0';
    429       1.57    simonb 	strncpy(sut.machine, machine, sizeof(sut.machine) - 1);
    430        1.1     glass 
    431      1.110  christos 	return copyout(&sut, SCARG(uap, name), sizeof(sut));
    432        1.1     glass }
    433        1.1     glass 
    434        1.1     glass int
    435      1.109       dsl ultrix_sys_setpgrp(struct lwp *l, const struct ultrix_sys_setpgrp_args *uap, register_t *retval)
    436        1.1     glass {
    437       1.81   thorpej 	struct proc *p = l->l_proc;
    438      1.110  christos 	struct sys_setpgid_args ap;
    439       1.15   thorpej 
    440      1.110  christos 	SCARG(&ap, pid) = SCARG(uap, pid);
    441      1.110  christos 	SCARG(&ap, pgid) = SCARG(uap, pgid);
    442        1.1     glass 	/*
    443        1.1     glass 	 * difference to our setpgid call is to include backwards
    444        1.1     glass 	 * compatibility to pre-setsid() binaries. Do setsid()
    445        1.1     glass 	 * instead of setpgid() in those cases where the process
    446        1.1     glass 	 * tries to create a new session the old way.
    447        1.1     glass 	 */
    448      1.110  christos 	if (!SCARG(&ap, pgid) &&
    449      1.110  christos 	    (!SCARG(&ap, pid) || SCARG(&ap, pid) == p->p_pid))
    450      1.110  christos 		return sys_setsid(l, &ap, retval);
    451        1.1     glass 	else
    452      1.110  christos 		return sys_setpgid(l, &ap, retval);
    453        1.1     glass }
    454        1.1     glass 
    455       1.16   mycroft struct ultrix_ustat {
    456        1.1     glass 	daddr_t	f_tfree;	/* total free */
    457      1.102  christos 	uint32_t f_tinode;	/* total inodes free */
    458        1.1     glass 	char	f_fname[6];	/* filsys name */
    459        1.1     glass 	char	f_fpack[6];	/* filsys pack name */
    460        1.1     glass };
    461       1.16   mycroft 
    462       1.20  jonathan int
    463      1.109       dsl ultrix_sys_ustat(struct lwp *l, const struct ultrix_sys_ustat_args *uap, register_t *retval)
    464        1.1     glass {
    465       1.16   mycroft 	struct ultrix_ustat us;
    466        1.1     glass 	int error;
    467        1.1     glass 
    468       1.41     perry 	memset(&us, 0, sizeof us);
    469        1.1     glass 
    470        1.1     glass 	/*
    471        1.1     glass 	 * XXX: should set f_tfree and f_tinode at least
    472       1.16   mycroft 	 * How do we translate dev -> fstat? (and then to ultrix_ustat)
    473        1.1     glass 	 */
    474        1.1     glass 
    475       1.23  jonathan 	if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
    476      1.110  christos 		return error;
    477        1.1     glass 	return 0;
    478        1.1     glass }
    479        1.1     glass 
    480       1.20  jonathan int
    481      1.109       dsl ultrix_sys_quotactl(struct lwp *l, const struct ultrix_sys_quotactl_args *uap, register_t *retval)
    482        1.1     glass {
    483       1.23  jonathan 
    484        1.1     glass 	return EINVAL;
    485        1.1     glass }
    486        1.1     glass 
    487       1.20  jonathan int
    488      1.110  christos ultrix_sys_vhangup(struct lwp *l, const void *uap, register_t *retval)
    489        1.1     glass {
    490       1.16   mycroft 
    491        1.1     glass 	return 0;
    492        1.1     glass }
    493       1.35  jonathan 
    494       1.35  jonathan 
    495       1.35  jonathan /*
    496       1.35  jonathan  * RISC Ultrix cache control syscalls
    497       1.35  jonathan  */
    498       1.35  jonathan #ifdef __mips
    499       1.35  jonathan int
    500      1.109       dsl ultrix_sys_cacheflush(struct lwp *l, const struct ultrix_sys_cacheflush_args *uap, register_t *retval)
    501       1.35  jonathan {
    502      1.109       dsl 	/* {
    503       1.35  jonathan 		syscallarg(void *) addr;
    504       1.95     david 		syscallarg(unsigned) nbytes;
    505       1.35  jonathan 		syscallarg(int) flag;
    506      1.109       dsl 	} */
    507       1.81   thorpej 	struct proc *p = l->l_proc;
    508       1.56  augustss 	vaddr_t va  = (vaddr_t)SCARG(uap, addr);
    509       1.56  augustss 	int nbytes     = SCARG(uap, nbytes);
    510       1.56  augustss 	int whichcache = SCARG(uap, whichcache);
    511       1.35  jonathan 
    512      1.110  christos 	return mips_user_cacheflush(p, va, nbytes, whichcache);
    513       1.35  jonathan }
    514       1.35  jonathan 
    515       1.35  jonathan 
    516       1.35  jonathan int
    517      1.109       dsl ultrix_sys_cachectl(struct lwp *l, const struct ultrix_sys_cachectl_args *uap, register_t *retval)
    518       1.35  jonathan {
    519      1.109       dsl 	/* {
    520       1.35  jonathan 		syscallarg(void *) addr;
    521       1.35  jonathan 		syscallarg(int) nbytes;
    522       1.35  jonathan 		syscallarg(int) cacheop;
    523      1.109       dsl 	} */
    524       1.81   thorpej 	struct proc *p = l->l_proc;
    525       1.56  augustss 	vaddr_t va  = (vaddr_t)SCARG(uap, addr);
    526       1.56  augustss 	int nbytes  = SCARG(uap, nbytes);
    527       1.56  augustss 	int cacheop = SCARG(uap, cacheop);
    528       1.35  jonathan 
    529       1.35  jonathan 	return mips_user_cachectl(p, va, nbytes, cacheop);
    530       1.35  jonathan }
    531       1.35  jonathan 
    532       1.35  jonathan #endif	/* __mips */
    533       1.35  jonathan 
    534        1.1     glass 
    535       1.20  jonathan int
    536      1.109       dsl ultrix_sys_exportfs(struct lwp *l, const struct ultrix_sys_exportfs_args *uap, register_t *retval)
    537        1.1     glass {
    538       1.15   thorpej 
    539        1.1     glass 	/*
    540        1.1     glass 	 * XXX: should perhaps translate into a mount(2)
    541        1.1     glass 	 * with MOUNT_EXPORT?
    542        1.1     glass 	 */
    543        1.1     glass 	return 0;
    544        1.1     glass }
    545        1.1     glass 
    546       1.16   mycroft int
    547      1.109       dsl ultrix_sys_sigpending(struct lwp *l, const struct ultrix_sys_sigpending_args *uap, register_t *retval)
    548       1.19  jonathan {
    549       1.43  drochner 	sigset_t ss;
    550       1.43  drochner 	int mask;
    551       1.43  drochner 
    552      1.105        ad 	sigpending1(l, &ss);
    553       1.43  drochner 	mask = ss.__bits[0];
    554       1.19  jonathan 
    555      1.110  christos 	return copyout(&mask, SCARG(uap, mask), sizeof(int));
    556       1.19  jonathan }
    557       1.19  jonathan 
    558       1.19  jonathan int
    559      1.109       dsl ultrix_sys_sigreturn(struct lwp *l, const struct ultrix_sys_sigreturn_args *uap, register_t *retval)
    560       1.44  drochner {
    561      1.110  christos 	/* struct sigcontext13 is close enough to Ultrix */
    562      1.110  christos 	struct compat_13_sys_sigreturn_args ap;
    563       1.44  drochner 
    564      1.110  christos 	SCARG(&ap, sigcntxp) = (void *)SCARG(uap, sigcntxp);
    565       1.45  drochner 
    566      1.110  christos 	return compat_13_sys_sigreturn(l, &ap, retval);
    567       1.44  drochner }
    568       1.44  drochner 
    569       1.44  drochner int
    570      1.109       dsl ultrix_sys_sigcleanup(struct lwp *l, const struct ultrix_sys_sigcleanup_args *uap, register_t *retval)
    571       1.13    mellon {
    572       1.15   thorpej 
    573       1.45  drochner 	/* struct sigcontext13 is close enough to Ultrix */
    574      1.110  christos 	struct compat_13_sys_sigreturn_args ap;
    575       1.45  drochner 
    576      1.110  christos 	SCARG(&ap, sigcntxp) = (void *)SCARG(uap, sigcntxp);
    577      1.110  christos 
    578      1.110  christos 	return compat_13_sys_sigreturn(l, &ap, retval);
    579       1.44  drochner }
    580       1.44  drochner 
    581       1.44  drochner int
    582      1.109       dsl ultrix_sys_sigsuspend(struct lwp *l, const struct ultrix_sys_sigsuspend_args *uap, register_t *retval)
    583       1.44  drochner {
    584       1.44  drochner 	int mask = SCARG(uap, mask);
    585       1.44  drochner 	sigset_t ss;
    586       1.44  drochner 
    587       1.44  drochner 	ss.__bits[0] = mask;
    588       1.44  drochner 	ss.__bits[1] = 0;
    589       1.44  drochner 	ss.__bits[2] = 0;
    590       1.44  drochner 	ss.__bits[3] = 0;
    591       1.44  drochner 
    592      1.110  christos 	return sigsuspend1(l, &ss);
    593       1.19  jonathan }
    594       1.19  jonathan 
    595       1.46  drochner #define ULTRIX_SV_ONSTACK 0x0001  /* take signal on signal stack */
    596       1.46  drochner #define ULTRIX_SV_INTERRUPT 0x0002  /* do not restart system on signal return */
    597       1.46  drochner #define ULTRIX_SV_OLDSIG 0x1000  /* Emulate old signal() for POSIX */
    598       1.46  drochner 
    599       1.46  drochner int
    600      1.109       dsl ultrix_sys_sigvec(struct lwp *l, const struct ultrix_sys_sigvec_args *uap, register_t *retval)
    601       1.46  drochner {
    602       1.46  drochner 	struct sigvec nsv, osv;
    603       1.46  drochner 	struct sigaction nsa, osa;
    604       1.46  drochner 	int error;
    605       1.46  drochner 
    606       1.46  drochner 	if (SCARG(uap, nsv)) {
    607       1.46  drochner 		error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
    608       1.46  drochner 		if (error)
    609      1.110  christos 			return error;
    610       1.46  drochner 		nsa.sa_handler = nsv.sv_handler;
    611       1.46  drochner #if 0 /* documentation */
    612       1.46  drochner 		/* ONSTACK is identical */
    613       1.46  drochner 		nsa.sa_flags = nsv.sv_flags & ULTRIX_SV_ONSTACK;
    614       1.46  drochner 		if ((nsv.sv_flags & ULTRIX_SV_OLDSIG)
    615       1.46  drochner 		    /* old signal() - always restart */
    616       1.46  drochner 		    || (!(nsv.sv_flags & ULTRIX_SV_INTERRUPT))
    617       1.46  drochner 		    /* inverted meaning (same bit) */
    618       1.46  drochner 		    )
    619       1.46  drochner 			nsa.sa_flags |= SA_RESTART;
    620       1.46  drochner #else /* optimized - assuming ULTRIX_SV_OLDSIG=>!ULTRIX_SV_INTERRUPT */
    621       1.46  drochner 		nsa.sa_flags = nsv.sv_flags & ~ULTRIX_SV_OLDSIG;
    622       1.46  drochner 		nsa.sa_flags ^= SA_RESTART;
    623       1.46  drochner #endif
    624       1.46  drochner 		native_sigset13_to_sigset(&nsv.sv_mask, &nsa.sa_mask);
    625       1.46  drochner 	}
    626      1.105        ad 	error = sigaction1(l, SCARG(uap, signum),
    627       1.77   thorpej 	    SCARG(uap, nsv) ? &nsa : 0, SCARG(uap, osv) ? &osa : 0,
    628       1.77   thorpej 	    NULL, 0);
    629       1.46  drochner 	if (error)
    630      1.110  christos 		return error;
    631       1.46  drochner 	if (SCARG(uap, osv)) {
    632       1.46  drochner 		osv.sv_handler = osa.sa_handler;
    633       1.46  drochner 		osv.sv_flags = osa.sa_flags ^ SA_RESTART;
    634       1.46  drochner 		osv.sv_flags &= (ULTRIX_SV_ONSTACK | ULTRIX_SV_INTERRUPT);
    635       1.46  drochner 		native_sigset_to_sigset13(&osa.sa_mask, &osv.sv_mask);
    636       1.46  drochner 		error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
    637       1.46  drochner 		if (error)
    638      1.110  christos 			return error;
    639       1.46  drochner 	}
    640      1.110  christos 	return 0;
    641       1.46  drochner }
    642       1.30  jonathan 
    643       1.32  jonathan int
    644      1.109       dsl ultrix_sys_shmsys(struct lwp *l, const struct ultrix_sys_shmsys_args *uap, register_t *retval)
    645       1.30  jonathan {
    646       1.30  jonathan 
    647       1.30  jonathan #ifdef SYSVSHM
    648       1.30  jonathan 	/* Ultrix SVSHM weirndess: */
    649       1.30  jonathan 	struct sys_shmat_args shmat_args;
    650       1.53   thorpej 	struct compat_14_sys_shmctl_args shmctl_args;
    651       1.30  jonathan 	struct sys_shmdt_args shmdt_args;
    652       1.30  jonathan 	struct sys_shmget_args shmget_args;
    653       1.30  jonathan 
    654       1.30  jonathan 
    655       1.30  jonathan 	switch (SCARG(uap, shmop)) {
    656       1.30  jonathan 	case 0:						/* Ultrix shmat() */
    657       1.30  jonathan 		SCARG(&shmat_args, shmid) = SCARG(uap, a2);
    658       1.30  jonathan 		SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
    659       1.30  jonathan 		SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
    660      1.110  christos 		return sys_shmat(l, &shmat_args, retval);
    661       1.30  jonathan 
    662       1.30  jonathan 	case 1:						/* Ultrix shmctl() */
    663       1.30  jonathan 		SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
    664       1.30  jonathan 		SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
    665       1.53   thorpej 		SCARG(&shmctl_args, buf) = (struct shmid_ds14 *)SCARG(uap, a4);
    666      1.110  christos 		return compat_14_sys_shmctl(l, &shmctl_args, retval);
    667       1.30  jonathan 
    668       1.30  jonathan 	case 2:						/* Ultrix shmdt() */
    669       1.30  jonathan 		SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a2);
    670      1.110  christos 		return sys_shmdt(l, &shmdt_args, retval);
    671       1.30  jonathan 
    672       1.30  jonathan 	case 3:						/* Ultrix shmget() */
    673       1.30  jonathan 		SCARG(&shmget_args, key) = SCARG(uap, a2);
    674       1.30  jonathan 		SCARG(&shmget_args, size) = SCARG(uap, a3);
    675       1.30  jonathan 		SCARG(&shmget_args, shmflg) = SCARG(uap, a4)
    676       1.30  jonathan 		    & (IPC_CREAT|IPC_EXCL|IPC_NOWAIT);
    677      1.110  christos 		return sys_shmget(l, &shmget_args, retval);
    678       1.30  jonathan 
    679       1.30  jonathan 	default:
    680      1.110  christos 		return EINVAL;
    681       1.30  jonathan 	}
    682       1.31  jonathan #else
    683      1.110  christos 	return EOPNOTSUPP;
    684       1.30  jonathan #endif	/* SYSVSHM */
    685       1.52  drochner }
    686       1.52  drochner 
    687       1.52  drochner static int
    688       1.93    simonb ultrix_to_bsd_flock(struct ultrix_flock *ufl, struct flock *fl)
    689       1.52  drochner {
    690       1.52  drochner 
    691       1.52  drochner 	fl->l_start = ufl->l_start;
    692       1.52  drochner 	fl->l_len = ufl->l_len;
    693       1.52  drochner 	fl->l_pid = ufl->l_pid;
    694       1.52  drochner 	fl->l_whence = ufl->l_whence;
    695       1.52  drochner 
    696       1.52  drochner 	switch (ufl->l_type) {
    697       1.52  drochner 	case ULTRIX_F_RDLCK:
    698       1.52  drochner 		fl->l_type = F_RDLCK;
    699       1.52  drochner 		break;
    700       1.52  drochner 	case ULTRIX_F_WRLCK:
    701       1.52  drochner 		fl->l_type = F_WRLCK;
    702       1.52  drochner 		break;
    703       1.52  drochner 	case ULTRIX_F_UNLCK:
    704       1.52  drochner 		fl->l_type = F_UNLCK;
    705       1.52  drochner 		break;
    706       1.52  drochner 	default:
    707      1.110  christos 		return EINVAL;
    708       1.52  drochner 	}
    709       1.52  drochner 
    710      1.110  christos 	return 0;
    711       1.52  drochner }
    712       1.52  drochner 
    713       1.52  drochner static void
    714       1.93    simonb bsd_to_ultrix_flock(struct flock *fl, struct ultrix_flock *ufl)
    715       1.52  drochner {
    716       1.52  drochner 
    717       1.52  drochner 	ufl->l_start = fl->l_start;
    718       1.52  drochner 	ufl->l_len = fl->l_len;
    719       1.52  drochner 	ufl->l_pid = fl->l_pid;
    720       1.52  drochner 	ufl->l_whence = fl->l_whence;
    721       1.52  drochner 
    722       1.52  drochner 	switch (fl->l_type) {
    723       1.52  drochner 	case F_RDLCK:
    724       1.52  drochner 		ufl->l_type = ULTRIX_F_RDLCK;
    725       1.52  drochner 		break;
    726       1.52  drochner 	case F_WRLCK:
    727       1.52  drochner 		ufl->l_type = ULTRIX_F_WRLCK;
    728       1.52  drochner 		break;
    729       1.52  drochner 	case F_UNLCK:
    730       1.52  drochner 		ufl->l_type = ULTRIX_F_UNLCK;
    731       1.52  drochner 		break;
    732       1.52  drochner 	}
    733       1.52  drochner }
    734       1.52  drochner 
    735       1.52  drochner int
    736      1.109       dsl ultrix_sys_fcntl(struct lwp *l, const struct ultrix_sys_fcntl_args *uap, register_t *retval)
    737       1.52  drochner {
    738       1.52  drochner 	int error;
    739       1.52  drochner 	struct ultrix_flock ufl;
    740      1.107       dsl 	struct flock fl;
    741       1.52  drochner 
    742       1.52  drochner 	switch (SCARG(uap, cmd)) {
    743       1.52  drochner 	case F_GETLK:
    744       1.52  drochner 	case F_SETLK:
    745       1.52  drochner 	case F_SETLKW:
    746       1.52  drochner 		error = copyin(SCARG(uap, arg), &ufl, sizeof(ufl));
    747       1.52  drochner 		if (error)
    748      1.110  christos 			return error;
    749       1.52  drochner 		error = ultrix_to_bsd_flock(&ufl, &fl);
    750       1.52  drochner 		if (error)
    751      1.110  christos 			return error;
    752      1.111        ad 		error = do_fcntl_lock(SCARG(uap, fd), SCARG(uap, cmd), &fl);
    753      1.107       dsl 		if (SCARG(uap, cmd) != F_GETLK || error != 0)
    754      1.107       dsl 			return error;
    755      1.107       dsl 		bsd_to_ultrix_flock(&fl, &ufl);
    756      1.107       dsl 		return copyout(&ufl, SCARG(uap, arg), sizeof(ufl));
    757       1.52  drochner 
    758       1.52  drochner 	default:
    759       1.52  drochner 		break;
    760       1.52  drochner 	}
    761       1.52  drochner 
    762      1.109       dsl 	return sys_fcntl(l, (const void *)uap, retval);
    763        1.1     glass }
    764