Home | History | Annotate | Line # | Download | only in ultrix
ultrix_misc.c revision 1.68.2.8
      1  1.68.2.8   nathanw /*	$NetBSD: ultrix_misc.c,v 1.68.2.8 2002/08/01 02:44:29 nathanw 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.68.2.3   nathanw 
     82  1.68.2.3   nathanw #include <sys/cdefs.h>
     83  1.68.2.8   nathanw __KERNEL_RCSID(0, "$NetBSD: ultrix_misc.c,v 1.68.2.8 2002/08/01 02:44:29 nathanw Exp $");
     84       1.1     glass 
     85  1.68.2.1   nathanw #if defined(_KERNEL_OPT)
     86      1.40    mhitch #include "opt_nfsserver.h"
     87      1.47      tron #include "opt_sysv.h"
     88      1.63  jdolecek #endif
     89      1.40    mhitch 
     90      1.38  jonathan #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     91      1.38  jonathan 
     92       1.1     glass /*
     93      1.49  sommerfe  * Ultrix compatibility module.
     94       1.1     glass  *
     95      1.49  sommerfe  * Ultrix system calls that are implemented differently in BSD are
     96       1.1     glass  * handled here.
     97       1.1     glass  */
     98      1.39   thorpej 
     99  1.68.2.1   nathanw #if defined(_KERNEL_OPT)
    100      1.39   thorpej #include "fs_nfs.h"
    101      1.63  jdolecek #endif
    102       1.1     glass 
    103       1.1     glass #include <sys/param.h>
    104       1.1     glass #include <sys/systm.h>
    105       1.1     glass #include <sys/namei.h>
    106      1.25   mycroft #include <sys/dirent.h>
    107       1.1     glass #include <sys/proc.h>
    108       1.1     glass #include <sys/file.h>
    109       1.1     glass #include <sys/filedesc.h>
    110       1.1     glass #include <sys/kernel.h>
    111       1.1     glass #include <sys/exec.h>
    112       1.1     glass #include <sys/malloc.h>
    113       1.1     glass #include <sys/mbuf.h>
    114       1.1     glass #include <sys/mman.h>
    115       1.1     glass #include <sys/mount.h>
    116       1.1     glass #include <sys/resource.h>
    117       1.1     glass #include <sys/resourcevar.h>
    118       1.1     glass #include <sys/signal.h>
    119       1.1     glass #include <sys/signalvar.h>
    120       1.1     glass #include <sys/socket.h>
    121       1.1     glass #include <sys/vnode.h>
    122       1.1     glass #include <sys/uio.h>
    123       1.1     glass #include <sys/wait.h>
    124       1.1     glass #include <sys/utsname.h>
    125       1.1     glass #include <sys/unistd.h>
    126      1.30  jonathan #include <sys/ipc.h>
    127      1.20  jonathan 
    128  1.68.2.6   nathanw #include <sys/sa.h>
    129      1.16   mycroft #include <sys/syscallargs.h>
    130      1.16   mycroft 
    131      1.16   mycroft #include <compat/ultrix/ultrix_syscall.h>
    132      1.16   mycroft #include <compat/ultrix/ultrix_syscallargs.h>
    133      1.30  jonathan #include <compat/common/compat_util.h>
    134       1.1     glass 
    135       1.1     glass #include <netinet/in.h>
    136       1.1     glass 
    137       1.1     glass #include <miscfs/specfs/specdev.h>
    138       1.1     glass 
    139       1.3     glass #include <nfs/rpcv2.h>
    140      1.21        pk #include <nfs/nfsproto.h>
    141       1.3     glass #include <nfs/nfs.h>
    142      1.11  christos 
    143      1.23  jonathan #include <sys/conf.h>					/* iszerodev() */
    144      1.23  jonathan #include <sys/socketvar.h>				/* sosetopt() */
    145      1.23  jonathan 
    146      1.52  drochner #include <compat/ultrix/ultrix_flock.h>
    147      1.67    simonb 
    148      1.67    simonb #ifdef __mips
    149      1.67    simonb #include <mips/cachectl.h>
    150      1.67    simonb #endif
    151      1.52  drochner 
    152      1.52  drochner static int ultrix_to_bsd_flock __P((struct ultrix_flock *, struct flock *));
    153      1.52  drochner static void bsd_to_ultrix_flock __P((struct flock *, struct ultrix_flock *));
    154      1.35  jonathan 
    155      1.11  christos extern struct sysent ultrix_sysent[];
    156      1.60    simonb extern const char * const ultrix_syscallnames[];
    157      1.45  drochner extern char ultrix_sigcode[], ultrix_esigcode[];
    158      1.68   thorpej #ifdef __HAVE_SYSCALL_INTERN
    159      1.68   thorpej void syscall_intern(struct proc *);
    160      1.68   thorpej #else
    161      1.65  jdolecek void syscall __P((void));
    162      1.68   thorpej #endif
    163      1.19  jonathan 
    164      1.61  jdolecek const struct emul emul_ultrix = {
    165      1.11  christos 	"ultrix",
    166      1.62  jdolecek 	"/emul/ultrix",
    167      1.68   thorpej #ifndef __HAVE_MINIMAL_EMUL
    168      1.66  jdolecek 	0,
    169      1.11  christos 	NULL,
    170      1.11  christos 	ULTRIX_SYS_syscall,
    171      1.11  christos 	ULTRIX_SYS_MAXSYSCALL,
    172      1.68   thorpej #endif
    173      1.11  christos 	ultrix_sysent,
    174      1.11  christos 	ultrix_syscallnames,
    175      1.66  jdolecek 	sendsig,
    176  1.68.2.1   nathanw 	trapsignal,
    177      1.45  drochner 	ultrix_sigcode,
    178      1.45  drochner 	ultrix_esigcode,
    179  1.68.2.2   nathanw 	setregs,
    180      1.64  jdolecek 	NULL,
    181      1.64  jdolecek 	NULL,
    182      1.64  jdolecek 	NULL,
    183      1.68   thorpej #ifdef __HAVE_SYSCALL_INTERN
    184      1.68   thorpej 	syscall_intern,
    185      1.68   thorpej #else
    186      1.68   thorpej 	syscall,
    187      1.68   thorpej #endif
    188      1.11  christos };
    189       1.1     glass 
    190       1.6     glass #define GSI_PROG_ENV 1
    191       1.6     glass 
    192      1.23  jonathan int
    193  1.68.2.4       wdk ultrix_sys_getsysinfo(l, v, retval)
    194  1.68.2.4       wdk 	struct lwp *l;
    195      1.15   thorpej 	void *v;
    196      1.16   mycroft 	register_t *retval;
    197       1.6     glass {
    198      1.16   mycroft 	struct ultrix_sys_getsysinfo_args *uap = v;
    199       1.6     glass 	static short progenv = 0;
    200       1.6     glass 
    201      1.16   mycroft 	switch (SCARG(uap, op)) {
    202       1.6     glass 		/* operations implemented: */
    203       1.6     glass 	case GSI_PROG_ENV:
    204      1.16   mycroft 		if (SCARG(uap, nbytes) < sizeof(short))
    205       1.6     glass 			return EINVAL;
    206       1.6     glass 		*retval = 1;
    207      1.16   mycroft 		return (copyout(&progenv, SCARG(uap, buffer), sizeof(short)));
    208       1.6     glass 	default:
    209       1.6     glass 		*retval = 0; /* info unavail */
    210       1.6     glass 		return 0;
    211       1.6     glass 	}
    212       1.6     glass }
    213       1.6     glass 
    214      1.23  jonathan int
    215  1.68.2.4       wdk ultrix_sys_setsysinfo(l, v, retval)
    216  1.68.2.4       wdk 	struct lwp *l;
    217      1.15   thorpej 	void *v;
    218      1.16   mycroft 	register_t *retval;
    219       1.6     glass {
    220      1.23  jonathan 
    221      1.23  jonathan #ifdef notyet
    222      1.16   mycroft 	struct ultrix_sys_setsysinfo_args *uap = v;
    223      1.23  jonathan #endif
    224      1.23  jonathan 
    225       1.6     glass 	*retval = 0;
    226       1.6     glass 	return 0;
    227       1.6     glass }
    228       1.6     glass 
    229      1.23  jonathan int
    230  1.68.2.4       wdk ultrix_sys_waitpid(l, v, retval)
    231  1.68.2.4       wdk 	struct lwp *l;
    232      1.15   thorpej 	void *v;
    233       1.7       cgd 	register_t *retval;
    234       1.1     glass {
    235      1.16   mycroft 	struct ultrix_sys_waitpid_args *uap = v;
    236      1.16   mycroft 	struct sys_wait4_args ua;
    237       1.1     glass 
    238      1.16   mycroft 	SCARG(&ua, pid) = SCARG(uap, pid);
    239      1.16   mycroft 	SCARG(&ua, status) = SCARG(uap, status);
    240      1.16   mycroft 	SCARG(&ua, options) = SCARG(uap, options);
    241      1.16   mycroft 	SCARG(&ua, rusage) = 0;
    242       1.1     glass 
    243  1.68.2.4       wdk 	return (sys_wait4(l, &ua, retval));
    244       1.2     glass }
    245       1.2     glass 
    246      1.23  jonathan int
    247  1.68.2.4       wdk ultrix_sys_wait3(l, v, retval)
    248  1.68.2.4       wdk 	struct lwp *l;
    249      1.15   thorpej 	void *v;
    250       1.7       cgd 	register_t *retval;
    251       1.2     glass {
    252      1.16   mycroft 	struct ultrix_sys_wait3_args *uap = v;
    253      1.16   mycroft 	struct sys_wait4_args ua;
    254       1.2     glass 
    255      1.16   mycroft 	SCARG(&ua, pid) = -1;
    256      1.16   mycroft 	SCARG(&ua, status) = SCARG(uap, status);
    257      1.16   mycroft 	SCARG(&ua, options) = SCARG(uap, options);
    258      1.16   mycroft 	SCARG(&ua, rusage) = SCARG(uap, rusage);
    259       1.1     glass 
    260  1.68.2.4       wdk 	return (sys_wait4(l, &ua, retval));
    261       1.1     glass }
    262       1.1     glass 
    263      1.20  jonathan /*
    264      1.20  jonathan  * Ultrix binaries pass in FD_MAX as the first arg to select().
    265      1.23  jonathan  * On Ultrix, FD_MAX is 4096, which is more than the NetBSD sys_select()
    266      1.20  jonathan  * can handle.
    267      1.23  jonathan  * Since we can't have more than the (native) FD_MAX descriptors open,
    268      1.23  jonathan  * limit nfds to at most FD_MAX.
    269      1.20  jonathan  */
    270      1.23  jonathan int
    271  1.68.2.4       wdk ultrix_sys_select(l, v, retval)
    272  1.68.2.4       wdk 	struct lwp *l;
    273      1.18  jonathan 	void *v;
    274      1.18  jonathan 	register_t *retval;
    275      1.18  jonathan {
    276      1.18  jonathan 	struct sys_select_args *uap = v;
    277      1.23  jonathan 	struct timeval atv;
    278      1.18  jonathan 	int error;
    279      1.18  jonathan 
    280      1.18  jonathan 	/* Limit number of FDs selected on to the native maximum */
    281      1.18  jonathan 
    282      1.18  jonathan 	if (SCARG(uap, nd) > FD_SETSIZE)
    283      1.18  jonathan 		SCARG(uap, nd) = FD_SETSIZE;
    284      1.18  jonathan 
    285      1.18  jonathan 	/* Check for negative timeval */
    286      1.18  jonathan 	if (SCARG(uap, tv)) {
    287      1.18  jonathan 		error = copyin((caddr_t)SCARG(uap, tv), (caddr_t)&atv,
    288      1.18  jonathan 			       sizeof(atv));
    289      1.18  jonathan 		if (error)
    290      1.18  jonathan 			goto done;
    291      1.18  jonathan #ifdef DEBUG
    292      1.18  jonathan 		/* Ultrix clients sometimes give negative timeouts? */
    293      1.18  jonathan 		if (atv.tv_sec < 0 || atv.tv_usec < 0)
    294      1.27  christos 			printf("ultrix select( %ld, %ld): negative timeout\n",
    295      1.26  christos 			    atv.tv_sec, atv.tv_usec);
    296      1.18  jonathan #endif
    297      1.18  jonathan 
    298      1.18  jonathan 	}
    299  1.68.2.4       wdk 	error = sys_select(l, (void*) uap, retval);
    300      1.18  jonathan 	if (error == EINVAL)
    301      1.27  christos 		printf("ultrix select: bad args?\n");
    302      1.18  jonathan 
    303      1.18  jonathan done:
    304      1.18  jonathan 	return error;
    305       1.1     glass }
    306       1.1     glass 
    307      1.29   thorpej #if defined(NFS)
    308      1.23  jonathan int
    309  1.68.2.4       wdk async_daemon(l, v, retval)
    310  1.68.2.4       wdk 	struct lwp *l;
    311      1.15   thorpej 	void *v;
    312       1.7       cgd 	register_t *retval;
    313       1.1     glass {
    314      1.16   mycroft 	struct sys_nfssvc_args ouap;
    315       1.1     glass 
    316      1.16   mycroft 	SCARG(&ouap, flag) = NFSSVC_BIOD;
    317      1.16   mycroft 	SCARG(&ouap, argp) = NULL;
    318       1.3     glass 
    319  1.68.2.4       wdk 	return (sys_nfssvc(l, &ouap, retval));
    320       1.3     glass }
    321      1.29   thorpej #endif /* NFS */
    322       1.3     glass 
    323       1.1     glass 
    324       1.1     glass #define	SUN__MAP_NEW	0x80000000	/* if not, old mmap & cannot handle */
    325       1.1     glass 
    326      1.20  jonathan int
    327  1.68.2.4       wdk ultrix_sys_mmap(l, v, retval)
    328  1.68.2.4       wdk 	struct lwp *l;
    329      1.15   thorpej 	void *v;
    330       1.7       cgd 	register_t *retval;
    331       1.1     glass {
    332      1.56  augustss 	struct ultrix_sys_mmap_args *uap = v;
    333  1.68.2.4       wdk 	struct proc *p = l->l_proc;
    334      1.16   mycroft 	struct sys_mmap_args ouap;
    335      1.56  augustss 	struct filedesc *fdp;
    336      1.56  augustss 	struct file *fp;
    337      1.56  augustss 	struct vnode *vp;
    338       1.1     glass 
    339       1.1     glass 	/*
    340       1.1     glass 	 * Verify the arguments.
    341       1.1     glass 	 */
    342      1.16   mycroft 	if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
    343       1.1     glass 		return (EINVAL);			/* XXX still needed? */
    344       1.1     glass 
    345      1.16   mycroft 	if ((SCARG(uap, flags) & SUN__MAP_NEW) == 0)
    346       1.1     glass 		return (EINVAL);
    347       1.1     glass 
    348      1.16   mycroft 	SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUN__MAP_NEW;
    349      1.16   mycroft 	SCARG(&ouap, addr) = SCARG(uap, addr);
    350      1.16   mycroft 
    351      1.16   mycroft 	if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 &&
    352      1.16   mycroft 	    SCARG(&ouap, addr) != 0 &&
    353      1.54    kleink 	    SCARG(&ouap, addr) < (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ))
    354      1.54    kleink 		SCARG(&ouap, addr) = (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ);
    355      1.16   mycroft 
    356      1.16   mycroft 	SCARG(&ouap, len) = SCARG(uap, len);
    357      1.16   mycroft 	SCARG(&ouap, prot) = SCARG(uap, prot);
    358      1.16   mycroft 	SCARG(&ouap, fd) = SCARG(uap, fd);
    359      1.16   mycroft 	SCARG(&ouap, pos) = SCARG(uap, pos);
    360       1.1     glass 
    361       1.1     glass 	/*
    362       1.1     glass 	 * Special case: if fd refers to /dev/zero, map as MAP_ANON.  (XXX)
    363       1.1     glass 	 */
    364       1.1     glass 	fdp = p->p_fd;
    365  1.68.2.1   nathanw 	if ((fp = fd_getfile(fdp, SCARG(&ouap, fd))) != NULL &&		/*XXX*/
    366       1.1     glass 	    fp->f_type == DTYPE_VNODE &&				/*XXX*/
    367       1.1     glass 	    (vp = (struct vnode *)fp->f_data)->v_type == VCHR &&	/*XXX*/
    368       1.1     glass 	    iszerodev(vp->v_rdev)) {					/*XXX*/
    369      1.16   mycroft 		SCARG(&ouap, flags) |= MAP_ANON;
    370      1.16   mycroft 		SCARG(&ouap, fd) = -1;
    371       1.1     glass 	}
    372       1.1     glass 
    373  1.68.2.4       wdk 	return (sys_mmap(l, &ouap, retval));
    374       1.1     glass }
    375       1.1     glass 
    376      1.23  jonathan int
    377  1.68.2.4       wdk ultrix_sys_setsockopt(l, v, retval)
    378  1.68.2.4       wdk 	struct lwp *l;
    379      1.15   thorpej 	void *v;
    380       1.7       cgd 	register_t *retval;
    381       1.1     glass {
    382      1.56  augustss 	struct ultrix_sys_setsockopt_args *uap = v;
    383  1.68.2.4       wdk 	struct proc *p = l->l_proc;
    384       1.1     glass 	struct file *fp;
    385       1.1     glass 	struct mbuf *m = NULL;
    386       1.1     glass 	int error;
    387       1.1     glass 
    388      1.51   thorpej 	/* getsock() will use the descriptor for us */
    389      1.23  jonathan 	if ((error = getsock(p->p_fd, SCARG(uap, s), &fp))  != 0)
    390       1.1     glass 		return (error);
    391       1.1     glass #define	SO_DONTLINGER (~SO_LINGER)
    392      1.16   mycroft 	if (SCARG(uap, name) == SO_DONTLINGER) {
    393       1.1     glass 		m = m_get(M_WAIT, MT_SOOPTS);
    394       1.1     glass 		mtod(m, struct linger *)->l_onoff = 0;
    395       1.1     glass 		m->m_len = sizeof(struct linger);
    396      1.51   thorpej 		error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    397      1.51   thorpej 		    SO_LINGER, m);
    398       1.1     glass 	}
    399      1.30  jonathan 	if (SCARG(uap, level) == IPPROTO_IP) {
    400      1.30  jonathan #define		EMUL_IP_MULTICAST_IF		2
    401      1.30  jonathan #define		EMUL_IP_MULTICAST_TTL		3
    402      1.30  jonathan #define		EMUL_IP_MULTICAST_LOOP		4
    403      1.30  jonathan #define		EMUL_IP_ADD_MEMBERSHIP		5
    404      1.30  jonathan #define		EMUL_IP_DROP_MEMBERSHIP	6
    405      1.30  jonathan 		static int ipoptxlat[] = {
    406      1.30  jonathan 			IP_MULTICAST_IF,
    407      1.30  jonathan 			IP_MULTICAST_TTL,
    408      1.30  jonathan 			IP_MULTICAST_LOOP,
    409      1.30  jonathan 			IP_ADD_MEMBERSHIP,
    410      1.30  jonathan 			IP_DROP_MEMBERSHIP
    411      1.30  jonathan 		};
    412      1.30  jonathan 		if (SCARG(uap, name) >= EMUL_IP_MULTICAST_IF &&
    413      1.30  jonathan 		    SCARG(uap, name) <= EMUL_IP_DROP_MEMBERSHIP) {
    414      1.30  jonathan 			SCARG(uap, name) =
    415      1.30  jonathan 			    ipoptxlat[SCARG(uap, name) - EMUL_IP_MULTICAST_IF];
    416      1.30  jonathan 		}
    417      1.30  jonathan 	}
    418      1.51   thorpej 	if (SCARG(uap, valsize) > MLEN) {
    419      1.51   thorpej 		error = EINVAL;
    420      1.51   thorpej 		goto out;
    421      1.51   thorpej 	}
    422      1.16   mycroft 	if (SCARG(uap, val)) {
    423       1.1     glass 		m = m_get(M_WAIT, MT_SOOPTS);
    424      1.30  jonathan 		error = copyin(SCARG(uap, val), mtod(m, caddr_t),
    425      1.30  jonathan 		    (u_int)SCARG(uap, valsize));
    426      1.30  jonathan 		if (error) {
    427       1.1     glass 			(void) m_free(m);
    428      1.51   thorpej 			goto out;
    429       1.1     glass 		}
    430      1.16   mycroft 		m->m_len = SCARG(uap, valsize);
    431       1.1     glass 	}
    432      1.51   thorpej 	error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    433      1.51   thorpej 	    SCARG(uap, name), m);
    434      1.51   thorpej  out:
    435      1.51   thorpej 	FILE_UNUSE(fp, p);
    436      1.51   thorpej 	return (error);
    437       1.1     glass }
    438       1.1     glass 
    439      1.57    simonb #define	ULTRIX__SYS_NMLN	32
    440      1.57    simonb 
    441      1.16   mycroft struct ultrix_utsname {
    442      1.57    simonb 	char    sysname[ULTRIX__SYS_NMLN];
    443      1.57    simonb 	char    nodename[ULTRIX__SYS_NMLN];
    444      1.57    simonb 	char    release[ULTRIX__SYS_NMLN];
    445      1.57    simonb 	char    version[ULTRIX__SYS_NMLN];
    446      1.57    simonb 	char    machine[ULTRIX__SYS_NMLN];
    447       1.1     glass };
    448       1.1     glass 
    449      1.20  jonathan int
    450  1.68.2.4       wdk ultrix_sys_uname(l, v, retval)
    451  1.68.2.4       wdk 	struct lwp *l;
    452      1.15   thorpej 	void *v;
    453       1.7       cgd 	register_t *retval;
    454       1.1     glass {
    455      1.16   mycroft 	struct ultrix_sys_uname_args *uap = v;
    456      1.16   mycroft 	struct ultrix_utsname sut;
    457      1.59  nisimura 	const char *cp;
    458      1.59  nisimura 	char *dp, *ep;
    459       1.1     glass 
    460      1.41     perry 	memset(&sut, 0, sizeof(sut));
    461       1.1     glass 
    462      1.57    simonb 	strncpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
    463      1.57    simonb 	strncpy(sut.nodename, hostname, sizeof(sut.nodename) - 1);
    464      1.57    simonb 	strncpy(sut.release, osrelease, sizeof(sut.release) - 1);
    465      1.59  nisimura 	dp = sut.version;
    466      1.59  nisimura 	ep = &sut.version[sizeof(sut.version) - 1];
    467      1.59  nisimura 	for (cp = version; *cp && *cp != '('; cp++)
    468      1.59  nisimura 		;
    469      1.59  nisimura 	for (cp++; *cp && *cp != ')' && dp < ep; cp++)
    470      1.59  nisimura 		*dp++ = *cp;
    471      1.59  nisimura 	for (; *cp && *cp != '#'; cp++)
    472      1.59  nisimura 		;
    473      1.59  nisimura 	for (; *cp && *cp != ':' && dp < ep; cp++)
    474      1.59  nisimura 		*dp++ = *cp;
    475      1.59  nisimura 	*dp = '\0';
    476      1.57    simonb 	strncpy(sut.machine, machine, sizeof(sut.machine) - 1);
    477       1.1     glass 
    478      1.16   mycroft 	return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
    479      1.16   mycroft 	    sizeof(struct ultrix_utsname));
    480       1.1     glass }
    481       1.1     glass 
    482       1.1     glass int
    483  1.68.2.4       wdk ultrix_sys_setpgrp(l, v, retval)
    484  1.68.2.4       wdk 	struct lwp *l;
    485      1.15   thorpej 	void *v;
    486       1.7       cgd 	register_t *retval;
    487       1.1     glass {
    488      1.16   mycroft 	struct ultrix_sys_setpgrp_args *uap = v;
    489  1.68.2.4       wdk 	struct proc *p = l->l_proc;
    490      1.15   thorpej 
    491       1.1     glass 	/*
    492       1.1     glass 	 * difference to our setpgid call is to include backwards
    493       1.1     glass 	 * compatibility to pre-setsid() binaries. Do setsid()
    494       1.1     glass 	 * instead of setpgid() in those cases where the process
    495       1.1     glass 	 * tries to create a new session the old way.
    496       1.1     glass 	 */
    497      1.16   mycroft 	if (!SCARG(uap, pgid) &&
    498      1.16   mycroft 	    (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
    499  1.68.2.4       wdk 		return sys_setsid(l, uap, retval);
    500       1.1     glass 	else
    501  1.68.2.4       wdk 		return sys_setpgid(l, uap, retval);
    502       1.1     glass }
    503       1.1     glass 
    504       1.1     glass #if defined (NFSSERVER)
    505      1.20  jonathan int
    506  1.68.2.4       wdk ultrix_sys_nfssvc(l, v, retval)
    507  1.68.2.4       wdk 	struct lwp *l;
    508      1.15   thorpej 	void *v;
    509       1.7       cgd 	register_t *retval;
    510       1.1     glass {
    511      1.23  jonathan 
    512      1.23  jonathan #if 0	/* XXX */
    513      1.16   mycroft 	struct ultrix_sys_nfssvc_args *uap = v;
    514      1.16   mycroft 	struct emul *e = p->p_emul;
    515      1.16   mycroft 	struct sys_nfssvc_args outuap;
    516       1.1     glass 	struct sockaddr sa;
    517       1.1     glass 	int error;
    518  1.68.2.5   nathanw 	caddr_t sg = stackgap_init(p, 0);
    519       1.1     glass 
    520      1.41     perry 	memset(&outuap, 0, sizeof outuap);
    521      1.16   mycroft 	SCARG(&outuap, fd) = SCARG(uap, fd);
    522  1.68.2.5   nathanw 	SCARG(&outuap, mskval) = stackgap_alloc(p, &sg, sizeof sa);
    523      1.16   mycroft 	SCARG(&outuap, msklen) = sizeof sa;
    524  1.68.2.5   nathanw 	SCARG(&outuap, mtchval) = stackgap_alloc(p, &sg, sizeof sa);
    525      1.16   mycroft 	SCARG(&outuap, mtchlen) = sizeof sa;
    526       1.1     glass 
    527      1.41     perry 	memset(&sa, 0, sizeof sa);
    528      1.16   mycroft 	if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
    529       1.1     glass 		return (error);
    530      1.16   mycroft 	if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
    531       1.1     glass 		return (error);
    532       1.1     glass 
    533  1.68.2.4       wdk 	return nfssvc(l, &outuap, retval);
    534      1.16   mycroft #else
    535      1.16   mycroft 	return (ENOSYS);
    536      1.16   mycroft #endif
    537       1.1     glass }
    538       1.1     glass #endif /* NFSSERVER */
    539       1.1     glass 
    540      1.16   mycroft struct ultrix_ustat {
    541       1.1     glass 	daddr_t	f_tfree;	/* total free */
    542       1.1     glass 	ino_t	f_tinode;	/* total inodes free */
    543       1.1     glass 	char	f_fname[6];	/* filsys name */
    544       1.1     glass 	char	f_fpack[6];	/* filsys pack name */
    545       1.1     glass };
    546      1.16   mycroft 
    547      1.20  jonathan int
    548  1.68.2.4       wdk ultrix_sys_ustat(l, v, retval)
    549  1.68.2.4       wdk 	struct lwp *l;
    550      1.15   thorpej 	void *v;
    551       1.7       cgd 	register_t *retval;
    552       1.1     glass {
    553      1.16   mycroft 	struct ultrix_sys_ustat_args *uap = v;
    554      1.16   mycroft 	struct ultrix_ustat us;
    555       1.1     glass 	int error;
    556       1.1     glass 
    557      1.41     perry 	memset(&us, 0, sizeof us);
    558       1.1     glass 
    559       1.1     glass 	/*
    560       1.1     glass 	 * XXX: should set f_tfree and f_tinode at least
    561      1.16   mycroft 	 * How do we translate dev -> fstat? (and then to ultrix_ustat)
    562       1.1     glass 	 */
    563       1.1     glass 
    564      1.23  jonathan 	if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
    565       1.1     glass 		return (error);
    566       1.1     glass 	return 0;
    567       1.1     glass }
    568       1.1     glass 
    569      1.20  jonathan int
    570  1.68.2.4       wdk ultrix_sys_quotactl(l, v, retval)
    571  1.68.2.4       wdk 	struct lwp *l;
    572      1.15   thorpej 	void *v;
    573       1.7       cgd 	register_t *retval;
    574       1.1     glass {
    575      1.23  jonathan 
    576      1.23  jonathan #ifdef notyet
    577      1.16   mycroft 	struct ultrix_sys_quotactl_args *uap = v;
    578      1.23  jonathan #endif
    579      1.15   thorpej 
    580       1.1     glass 	return EINVAL;
    581       1.1     glass }
    582       1.1     glass 
    583      1.20  jonathan int
    584  1.68.2.4       wdk ultrix_sys_vhangup(l, v, retval)
    585  1.68.2.4       wdk 	struct lwp *l;
    586      1.16   mycroft 	void *v;
    587       1.7       cgd 	register_t *retval;
    588       1.1     glass {
    589      1.16   mycroft 
    590       1.1     glass 	return 0;
    591       1.1     glass }
    592      1.35  jonathan 
    593      1.35  jonathan 
    594      1.35  jonathan /*
    595      1.35  jonathan  * RISC Ultrix cache control syscalls
    596      1.35  jonathan  */
    597      1.35  jonathan #ifdef __mips
    598      1.35  jonathan int
    599  1.68.2.4       wdk ultrix_sys_cacheflush(l, v, retval)
    600  1.68.2.4       wdk 	struct lwp *l;
    601      1.35  jonathan 	void *v;
    602      1.35  jonathan 	register_t *retval;
    603      1.35  jonathan {
    604      1.56  augustss 	struct ultrix_sys_cacheflush_args /* {
    605      1.35  jonathan 		syscallarg(void *) addr;
    606      1.35  jonathan 		syscallarg(int) nbytes;
    607      1.35  jonathan 		syscallarg(int) flag;
    608      1.35  jonathan 	} */ *uap = v;
    609  1.68.2.4       wdk 	struct proc *p = l->l_proc;
    610      1.56  augustss 	vaddr_t va  = (vaddr_t)SCARG(uap, addr);
    611      1.56  augustss 	int nbytes     = SCARG(uap, nbytes);
    612      1.56  augustss 	int whichcache = SCARG(uap, whichcache);
    613      1.35  jonathan 
    614      1.35  jonathan 	return (mips_user_cacheflush(p, va, nbytes, whichcache));
    615      1.35  jonathan }
    616      1.35  jonathan 
    617      1.35  jonathan 
    618      1.35  jonathan int
    619  1.68.2.4       wdk ultrix_sys_cachectl(l, v, retval)
    620  1.68.2.4       wdk 	struct lwp *l;
    621      1.35  jonathan 	void *v;
    622      1.35  jonathan 	register_t *retval;
    623      1.35  jonathan {
    624      1.56  augustss 	struct ultrix_sys_cachectl_args /* {
    625      1.35  jonathan 		syscallarg(void *) addr;
    626      1.35  jonathan 		syscallarg(int) nbytes;
    627      1.35  jonathan 		syscallarg(int) cacheop;
    628      1.35  jonathan 	} */ *uap = v;
    629  1.68.2.4       wdk 	struct proc *p = l->l_proc;
    630      1.56  augustss 	vaddr_t va  = (vaddr_t)SCARG(uap, addr);
    631      1.56  augustss 	int nbytes  = SCARG(uap, nbytes);
    632      1.56  augustss 	int cacheop = SCARG(uap, cacheop);
    633      1.35  jonathan 
    634      1.35  jonathan 	return mips_user_cachectl(p, va, nbytes, cacheop);
    635      1.35  jonathan }
    636      1.35  jonathan 
    637      1.35  jonathan #endif	/* __mips */
    638      1.35  jonathan 
    639       1.1     glass 
    640      1.20  jonathan int
    641  1.68.2.4       wdk ultrix_sys_exportfs(l, v, retval)
    642  1.68.2.4       wdk 	struct lwp *l;
    643      1.15   thorpej 	void *v;
    644       1.7       cgd 	register_t *retval;
    645       1.1     glass {
    646      1.23  jonathan #ifdef notyet
    647      1.16   mycroft 	struct ultrix_sys_exportfs_args *uap = v;
    648      1.23  jonathan #endif
    649      1.15   thorpej 
    650       1.1     glass 	/*
    651       1.1     glass 	 * XXX: should perhaps translate into a mount(2)
    652       1.1     glass 	 * with MOUNT_EXPORT?
    653       1.1     glass 	 */
    654       1.1     glass 	return 0;
    655       1.1     glass }
    656       1.1     glass 
    657      1.16   mycroft int
    658  1.68.2.4       wdk ultrix_sys_sigpending(l, v, retval)
    659  1.68.2.4       wdk 	struct lwp *l;
    660      1.19  jonathan 	void *v;
    661      1.19  jonathan 	register_t *retval;
    662      1.19  jonathan {
    663      1.19  jonathan 	struct ultrix_sys_sigpending_args *uap = v;
    664      1.43  drochner 	sigset_t ss;
    665      1.43  drochner 	int mask;
    666      1.43  drochner 
    667  1.68.2.4       wdk 	sigpending1(l->l_proc, &ss);
    668      1.43  drochner 	mask = ss.__bits[0];
    669      1.19  jonathan 
    670      1.19  jonathan 	return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
    671      1.19  jonathan }
    672      1.19  jonathan 
    673      1.19  jonathan int
    674  1.68.2.4       wdk ultrix_sys_sigreturn(l, v, retval)
    675  1.68.2.4       wdk 	struct lwp *l;
    676      1.44  drochner 	void *v;
    677      1.44  drochner 	register_t *retval;
    678      1.44  drochner {
    679      1.44  drochner 	struct ultrix_sys_sigreturn_args *uap = v;
    680      1.44  drochner 
    681      1.45  drochner 	/* struct sigcontext13 is close enough to Ultrix */
    682      1.45  drochner 
    683  1.68.2.4       wdk 	return (compat_13_sys_sigreturn(l, uap, retval));
    684      1.44  drochner }
    685      1.44  drochner 
    686      1.44  drochner int
    687  1.68.2.4       wdk ultrix_sys_sigcleanup(l, v, retval)
    688  1.68.2.4       wdk 	struct lwp *l;
    689      1.15   thorpej 	void *v;
    690      1.13    mellon 	register_t *retval;
    691      1.13    mellon {
    692      1.16   mycroft 	struct ultrix_sys_sigcleanup_args *uap = v;
    693      1.15   thorpej 
    694      1.45  drochner 	/* struct sigcontext13 is close enough to Ultrix */
    695      1.45  drochner 
    696  1.68.2.4       wdk 	return (compat_13_sys_sigreturn(l, uap, retval));
    697      1.44  drochner }
    698      1.44  drochner 
    699      1.44  drochner int
    700  1.68.2.4       wdk ultrix_sys_sigsuspend(l, v, retval)
    701  1.68.2.4       wdk 	struct lwp *l;
    702      1.44  drochner 	void *v;
    703      1.44  drochner 	register_t *retval;
    704      1.44  drochner {
    705      1.44  drochner 	struct ultrix_sys_sigsuspend_args *uap = v;
    706      1.44  drochner 	int mask = SCARG(uap, mask);
    707      1.44  drochner 	sigset_t ss;
    708      1.44  drochner 
    709      1.44  drochner 	ss.__bits[0] = mask;
    710      1.44  drochner 	ss.__bits[1] = 0;
    711      1.44  drochner 	ss.__bits[2] = 0;
    712      1.44  drochner 	ss.__bits[3] = 0;
    713      1.44  drochner 
    714  1.68.2.4       wdk 	return (sigsuspend1(l->l_proc, &ss));
    715      1.19  jonathan }
    716      1.19  jonathan 
    717      1.46  drochner #define ULTRIX_SV_ONSTACK 0x0001  /* take signal on signal stack */
    718      1.46  drochner #define ULTRIX_SV_INTERRUPT 0x0002  /* do not restart system on signal return */
    719      1.46  drochner #define ULTRIX_SV_OLDSIG 0x1000  /* Emulate old signal() for POSIX */
    720      1.46  drochner 
    721      1.46  drochner int
    722  1.68.2.4       wdk ultrix_sys_sigvec(l, v, retval)
    723  1.68.2.4       wdk 	struct lwp *l;
    724      1.46  drochner 	void *v;
    725      1.46  drochner 	register_t *retval;
    726      1.46  drochner {
    727      1.46  drochner 	struct ultrix_sys_sigvec_args *uap = v;
    728      1.46  drochner 	struct sigvec nsv, osv;
    729      1.46  drochner 	struct sigaction nsa, osa;
    730      1.46  drochner 	int error;
    731      1.46  drochner 
    732      1.46  drochner 	if (SCARG(uap, nsv)) {
    733      1.46  drochner 		error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
    734      1.46  drochner 		if (error)
    735      1.46  drochner 			return (error);
    736      1.46  drochner 		nsa.sa_handler = nsv.sv_handler;
    737      1.46  drochner #if 0 /* documentation */
    738      1.46  drochner 		/* ONSTACK is identical */
    739      1.46  drochner 		nsa.sa_flags = nsv.sv_flags & ULTRIX_SV_ONSTACK;
    740      1.46  drochner 		if ((nsv.sv_flags & ULTRIX_SV_OLDSIG)
    741      1.46  drochner 		    /* old signal() - always restart */
    742      1.46  drochner 		    || (!(nsv.sv_flags & ULTRIX_SV_INTERRUPT))
    743      1.46  drochner 		    /* inverted meaning (same bit) */
    744      1.46  drochner 		    )
    745      1.46  drochner 			nsa.sa_flags |= SA_RESTART;
    746      1.46  drochner #else /* optimized - assuming ULTRIX_SV_OLDSIG=>!ULTRIX_SV_INTERRUPT */
    747      1.46  drochner 		nsa.sa_flags = nsv.sv_flags & ~ULTRIX_SV_OLDSIG;
    748      1.46  drochner 		nsa.sa_flags ^= SA_RESTART;
    749      1.46  drochner #endif
    750      1.46  drochner 		native_sigset13_to_sigset(&nsv.sv_mask, &nsa.sa_mask);
    751      1.46  drochner 	}
    752  1.68.2.4       wdk 	error = sigaction1(l->l_proc, SCARG(uap, signum),
    753  1.68.2.8   nathanw 	    SCARG(uap, nsv) ? &nsa : 0, SCARG(uap, osv) ? &osa : 0,
    754  1.68.2.8   nathanw 	    NULL, 0);
    755      1.46  drochner 	if (error)
    756      1.46  drochner 		return (error);
    757      1.46  drochner 	if (SCARG(uap, osv)) {
    758      1.46  drochner 		osv.sv_handler = osa.sa_handler;
    759      1.46  drochner 		osv.sv_flags = osa.sa_flags ^ SA_RESTART;
    760      1.46  drochner 		osv.sv_flags &= (ULTRIX_SV_ONSTACK | ULTRIX_SV_INTERRUPT);
    761      1.46  drochner 		native_sigset_to_sigset13(&osa.sa_mask, &osv.sv_mask);
    762      1.46  drochner 		error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
    763      1.46  drochner 		if (error)
    764      1.46  drochner 			return (error);
    765      1.46  drochner 	}
    766      1.46  drochner 	return (0);
    767      1.46  drochner }
    768      1.30  jonathan 
    769      1.32  jonathan int
    770  1.68.2.4       wdk ultrix_sys_shmsys(l, v, retval)
    771  1.68.2.4       wdk 	struct lwp *l;
    772      1.30  jonathan 	void *v;
    773      1.30  jonathan 	register_t *retval;
    774      1.30  jonathan {
    775      1.30  jonathan 
    776      1.30  jonathan #ifdef SYSVSHM
    777      1.30  jonathan 
    778      1.30  jonathan 	/* Ultrix SVSHM weirndess: */
    779      1.30  jonathan 	struct ultrix_sys_shmsys_args *uap = v;
    780      1.30  jonathan 	struct sys_shmat_args shmat_args;
    781      1.53   thorpej 	struct compat_14_sys_shmctl_args shmctl_args;
    782      1.30  jonathan 	struct sys_shmdt_args shmdt_args;
    783      1.30  jonathan 	struct sys_shmget_args shmget_args;
    784      1.30  jonathan 
    785      1.30  jonathan 
    786      1.30  jonathan 	switch (SCARG(uap, shmop)) {
    787      1.30  jonathan 	case 0:						/* Ultrix shmat() */
    788      1.30  jonathan 		SCARG(&shmat_args, shmid) = SCARG(uap, a2);
    789      1.30  jonathan 		SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
    790      1.30  jonathan 		SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
    791  1.68.2.4       wdk 		return (sys_shmat(l, &shmat_args, retval));
    792      1.30  jonathan 
    793      1.30  jonathan 	case 1:						/* Ultrix shmctl() */
    794      1.30  jonathan 		SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
    795      1.30  jonathan 		SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
    796      1.53   thorpej 		SCARG(&shmctl_args, buf) = (struct shmid_ds14 *)SCARG(uap, a4);
    797  1.68.2.4       wdk 		return (compat_14_sys_shmctl(l, &shmctl_args, retval));
    798      1.30  jonathan 
    799      1.30  jonathan 	case 2:						/* Ultrix shmdt() */
    800      1.30  jonathan 		SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a2);
    801  1.68.2.4       wdk 		return (sys_shmdt(l, &shmdt_args, retval));
    802      1.30  jonathan 
    803      1.30  jonathan 	case 3:						/* Ultrix shmget() */
    804      1.30  jonathan 		SCARG(&shmget_args, key) = SCARG(uap, a2);
    805      1.30  jonathan 		SCARG(&shmget_args, size) = SCARG(uap, a3);
    806      1.30  jonathan 		SCARG(&shmget_args, shmflg) = SCARG(uap, a4)
    807      1.30  jonathan 		    & (IPC_CREAT|IPC_EXCL|IPC_NOWAIT);
    808  1.68.2.4       wdk 		return (sys_shmget(l, &shmget_args, retval));
    809      1.30  jonathan 
    810      1.30  jonathan 	default:
    811      1.30  jonathan 		return (EINVAL);
    812      1.30  jonathan 	}
    813      1.31  jonathan #else
    814      1.31  jonathan 	return (EOPNOTSUPP);
    815      1.30  jonathan #endif	/* SYSVSHM */
    816      1.52  drochner }
    817      1.52  drochner 
    818      1.52  drochner static int
    819      1.52  drochner ultrix_to_bsd_flock(ufl, fl)
    820      1.52  drochner 	struct ultrix_flock *ufl;
    821      1.52  drochner 	struct flock *fl;
    822      1.52  drochner {
    823      1.52  drochner 
    824      1.52  drochner 	fl->l_start = ufl->l_start;
    825      1.52  drochner 	fl->l_len = ufl->l_len;
    826      1.52  drochner 	fl->l_pid = ufl->l_pid;
    827      1.52  drochner 	fl->l_whence = ufl->l_whence;
    828      1.52  drochner 
    829      1.52  drochner 	switch (ufl->l_type) {
    830      1.52  drochner 	case ULTRIX_F_RDLCK:
    831      1.52  drochner 		fl->l_type = F_RDLCK;
    832      1.52  drochner 		break;
    833      1.52  drochner 	case ULTRIX_F_WRLCK:
    834      1.52  drochner 		fl->l_type = F_WRLCK;
    835      1.52  drochner 		break;
    836      1.52  drochner 	case ULTRIX_F_UNLCK:
    837      1.52  drochner 		fl->l_type = F_UNLCK;
    838      1.52  drochner 		break;
    839      1.52  drochner 	default:
    840      1.52  drochner 		return (EINVAL);
    841      1.52  drochner 	}
    842      1.52  drochner 
    843      1.52  drochner 	return (0);
    844      1.52  drochner }
    845      1.52  drochner 
    846      1.52  drochner static void
    847      1.52  drochner bsd_to_ultrix_flock(fl, ufl)
    848      1.52  drochner 	struct flock *fl;
    849      1.52  drochner 	struct ultrix_flock *ufl;
    850      1.52  drochner {
    851      1.52  drochner 
    852      1.52  drochner 	ufl->l_start = fl->l_start;
    853      1.52  drochner 	ufl->l_len = fl->l_len;
    854      1.52  drochner 	ufl->l_pid = fl->l_pid;
    855      1.52  drochner 	ufl->l_whence = fl->l_whence;
    856      1.52  drochner 
    857      1.52  drochner 	switch (fl->l_type) {
    858      1.52  drochner 	case F_RDLCK:
    859      1.52  drochner 		ufl->l_type = ULTRIX_F_RDLCK;
    860      1.52  drochner 		break;
    861      1.52  drochner 	case F_WRLCK:
    862      1.52  drochner 		ufl->l_type = ULTRIX_F_WRLCK;
    863      1.52  drochner 		break;
    864      1.52  drochner 	case F_UNLCK:
    865      1.52  drochner 		ufl->l_type = ULTRIX_F_UNLCK;
    866      1.52  drochner 		break;
    867      1.52  drochner 	}
    868      1.52  drochner }
    869      1.52  drochner 
    870      1.52  drochner int
    871  1.68.2.4       wdk ultrix_sys_fcntl(l, v, retval)
    872  1.68.2.4       wdk 	struct lwp *l;
    873      1.52  drochner 	void *v;
    874      1.52  drochner 	register_t *retval;
    875      1.52  drochner {
    876      1.52  drochner 	struct ultrix_sys_fcntl_args *uap = v;
    877  1.68.2.4       wdk 	struct proc *p = l->l_proc;
    878      1.52  drochner 	int error;
    879      1.52  drochner 	struct ultrix_flock ufl;
    880      1.52  drochner 	struct flock fl, *flp;
    881      1.52  drochner 	caddr_t sg;
    882      1.52  drochner 	struct sys_fcntl_args *args, fca;
    883      1.52  drochner 
    884      1.52  drochner 	switch (SCARG(uap, cmd)) {
    885      1.52  drochner 	case F_GETLK:
    886      1.52  drochner 	case F_SETLK:
    887      1.52  drochner 	case F_SETLKW:
    888      1.52  drochner 		error = copyin(SCARG(uap, arg), &ufl, sizeof(ufl));
    889      1.52  drochner 		if (error)
    890      1.52  drochner 			return (error);
    891      1.52  drochner 		error = ultrix_to_bsd_flock(&ufl, &fl);
    892      1.52  drochner 		if (error)
    893      1.52  drochner 			return (error);
    894  1.68.2.5   nathanw 		sg = stackgap_init(p, 0);
    895  1.68.2.5   nathanw 		flp = (struct flock *)stackgap_alloc(p, &sg, sizeof(*flp));
    896      1.52  drochner 		error = copyout(&fl, flp, sizeof(*flp));
    897      1.52  drochner 		if (error)
    898      1.52  drochner 			return (error);
    899      1.52  drochner 
    900      1.52  drochner 		SCARG(&fca, fd) = SCARG(uap, fd);
    901      1.52  drochner 		SCARG(&fca, cmd) = SCARG(uap, cmd);
    902      1.52  drochner 		SCARG(&fca, arg) = flp;
    903      1.52  drochner 		args = &fca;
    904      1.52  drochner 		break;
    905      1.52  drochner 	default:
    906      1.52  drochner 		args = v;
    907      1.52  drochner 		break;
    908      1.52  drochner 	}
    909      1.52  drochner 
    910  1.68.2.4       wdk 	error = sys_fcntl(l, args, retval);
    911      1.52  drochner 	if (error)
    912      1.52  drochner 		return (error);
    913      1.52  drochner 
    914      1.52  drochner 	switch (SCARG(uap, cmd)) {
    915      1.52  drochner 	case F_GETLK:
    916      1.52  drochner 		error = copyin(flp, &fl, sizeof(fl));
    917      1.52  drochner 		if (error)
    918      1.52  drochner 			return (error);
    919      1.52  drochner 		bsd_to_ultrix_flock(&fl, &ufl);
    920      1.52  drochner 		error = copyout(&ufl, SCARG(uap, arg), sizeof(ufl));
    921      1.52  drochner 		break;
    922      1.52  drochner 	}
    923      1.52  drochner 
    924      1.52  drochner 	return (error);
    925       1.1     glass }
    926