Home | History | Annotate | Line # | Download | only in ultrix
ultrix_misc.c revision 1.86
      1 /*	$NetBSD: ultrix_misc.c,v 1.86 2003/08/07 16:30:47 agc Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995, 1997 Jonathan Stone (hereinafter referred to as the author)
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Jonathan Stone for
     18  *      the NetBSD Project.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  */
     34 
     35 /*
     36  * Copyright (c) 1992, 1993
     37  *	The Regents of the University of California.  All rights reserved.
     38  *
     39  * This software was developed by the Computer Systems Engineering group
     40  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     41  * contributed to Berkeley.
     42  *
     43  * All advertising materials mentioning features or use of this software
     44  * must display the following acknowledgement:
     45  *	This product includes software developed by the University of
     46  *	California, Lawrence Berkeley Laboratory.
     47  *
     48  * Redistribution and use in source and binary forms, with or without
     49  * modification, are permitted provided that the following conditions
     50  * are met:
     51  * 1. Redistributions of source code must retain the above copyright
     52  *    notice, this list of conditions and the following disclaimer.
     53  * 2. Redistributions in binary form must reproduce the above copyright
     54  *    notice, this list of conditions and the following disclaimer in the
     55  *    documentation and/or other materials provided with the distribution.
     56  * 3. Neither the name of the University nor the names of its contributors
     57  *    may be used to endorse or promote products derived from this software
     58  *    without specific prior written permission.
     59  *
     60  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     61  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     62  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     63  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     64  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     65  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     66  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     67  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     68  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     69  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     70  * SUCH DAMAGE.
     71  *
     72  *
     73  *	@(#)sun_misc.c	8.1 (Berkeley) 6/18/93
     74  *
     75  * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
     76  */
     77 
     78 #include <sys/cdefs.h>
     79 __KERNEL_RCSID(0, "$NetBSD: ultrix_misc.c,v 1.86 2003/08/07 16:30:47 agc Exp $");
     80 
     81 #if defined(_KERNEL_OPT)
     82 #include "opt_nfsserver.h"
     83 #include "opt_sysv.h"
     84 #endif
     85 
     86 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     87 
     88 /*
     89  * Ultrix compatibility module.
     90  *
     91  * Ultrix system calls that are implemented differently in BSD are
     92  * handled here.
     93  */
     94 
     95 #if defined(_KERNEL_OPT)
     96 #include "fs_nfs.h"
     97 #endif
     98 
     99 #include <sys/param.h>
    100 #include <sys/systm.h>
    101 #include <sys/namei.h>
    102 #include <sys/dirent.h>
    103 #include <sys/proc.h>
    104 #include <sys/file.h>
    105 #include <sys/filedesc.h>
    106 #include <sys/kernel.h>
    107 #include <sys/exec.h>
    108 #include <sys/malloc.h>
    109 #include <sys/mbuf.h>
    110 #include <sys/mman.h>
    111 #include <sys/mount.h>
    112 #include <sys/resource.h>
    113 #include <sys/resourcevar.h>
    114 #include <sys/signal.h>
    115 #include <sys/signalvar.h>
    116 #include <sys/socket.h>
    117 #include <sys/vnode.h>
    118 #include <sys/uio.h>
    119 #include <sys/wait.h>
    120 #include <sys/utsname.h>
    121 #include <sys/unistd.h>
    122 #include <sys/ipc.h>
    123 
    124 #include <sys/sa.h>
    125 #include <sys/syscallargs.h>
    126 
    127 #include <compat/ultrix/ultrix_syscall.h>
    128 #include <compat/ultrix/ultrix_syscallargs.h>
    129 #include <compat/common/compat_util.h>
    130 
    131 #include <netinet/in.h>
    132 
    133 #include <miscfs/specfs/specdev.h>
    134 
    135 #include <nfs/rpcv2.h>
    136 #include <nfs/nfsproto.h>
    137 #include <nfs/nfs.h>
    138 
    139 #include <sys/socketvar.h>				/* sosetopt() */
    140 
    141 #include <compat/ultrix/ultrix_flock.h>
    142 
    143 #ifdef __mips
    144 #include <mips/cachectl.h>
    145 #endif
    146 
    147 static int ultrix_to_bsd_flock __P((struct ultrix_flock *, struct flock *));
    148 static void bsd_to_ultrix_flock __P((struct flock *, struct ultrix_flock *));
    149 
    150 extern struct sysent ultrix_sysent[];
    151 extern const char * const ultrix_syscallnames[];
    152 extern char ultrix_sigcode[], ultrix_esigcode[];
    153 #ifdef __HAVE_SYSCALL_INTERN
    154 void syscall_intern(struct proc *);
    155 #else
    156 void syscall __P((void));
    157 #endif
    158 
    159 const struct emul emul_ultrix = {
    160 	"ultrix",
    161 	"/emul/ultrix",
    162 #ifndef __HAVE_MINIMAL_EMUL
    163 	0,
    164 	NULL,
    165 	ULTRIX_SYS_syscall,
    166 	ULTRIX_SYS_NSYSENT,
    167 #endif
    168 	ultrix_sysent,
    169 	ultrix_syscallnames,
    170 	sendsig,
    171 	trapsignal,
    172 	ultrix_sigcode,
    173 	ultrix_esigcode,
    174 	setregs,
    175 	NULL,
    176 	NULL,
    177 	NULL,
    178 #ifdef __HAVE_SYSCALL_INTERN
    179 	syscall_intern,
    180 #else
    181 	syscall,
    182 #endif
    183 	NULL,
    184 	NULL,
    185 };
    186 
    187 #define GSI_PROG_ENV 1
    188 
    189 int
    190 ultrix_sys_getsysinfo(l, v, retval)
    191 	struct lwp *l;
    192 	void *v;
    193 	register_t *retval;
    194 {
    195 	struct ultrix_sys_getsysinfo_args *uap = v;
    196 	static short progenv = 0;
    197 
    198 	switch (SCARG(uap, op)) {
    199 		/* operations implemented: */
    200 	case GSI_PROG_ENV:
    201 		if (SCARG(uap, nbytes) < sizeof(short))
    202 			return EINVAL;
    203 		*retval = 1;
    204 		return (copyout(&progenv, SCARG(uap, buffer), sizeof(short)));
    205 	default:
    206 		*retval = 0; /* info unavail */
    207 		return 0;
    208 	}
    209 }
    210 
    211 int
    212 ultrix_sys_setsysinfo(l, v, retval)
    213 	struct lwp *l;
    214 	void *v;
    215 	register_t *retval;
    216 {
    217 
    218 #ifdef notyet
    219 	struct ultrix_sys_setsysinfo_args *uap = v;
    220 #endif
    221 
    222 	*retval = 0;
    223 	return 0;
    224 }
    225 
    226 int
    227 ultrix_sys_waitpid(l, v, retval)
    228 	struct lwp *l;
    229 	void *v;
    230 	register_t *retval;
    231 {
    232 	struct ultrix_sys_waitpid_args *uap = v;
    233 	struct sys_wait4_args ua;
    234 
    235 	SCARG(&ua, pid) = SCARG(uap, pid);
    236 	SCARG(&ua, status) = SCARG(uap, status);
    237 	SCARG(&ua, options) = SCARG(uap, options);
    238 	SCARG(&ua, rusage) = 0;
    239 
    240 	return (sys_wait4(l, &ua, retval));
    241 }
    242 
    243 int
    244 ultrix_sys_wait3(l, v, retval)
    245 	struct lwp *l;
    246 	void *v;
    247 	register_t *retval;
    248 {
    249 	struct ultrix_sys_wait3_args *uap = v;
    250 	struct sys_wait4_args ua;
    251 
    252 	SCARG(&ua, pid) = -1;
    253 	SCARG(&ua, status) = SCARG(uap, status);
    254 	SCARG(&ua, options) = SCARG(uap, options);
    255 	SCARG(&ua, rusage) = SCARG(uap, rusage);
    256 
    257 	return (sys_wait4(l, &ua, retval));
    258 }
    259 
    260 /*
    261  * Ultrix binaries pass in FD_MAX as the first arg to select().
    262  * On Ultrix, FD_MAX is 4096, which is more than the NetBSD sys_select()
    263  * can handle.
    264  * Since we can't have more than the (native) FD_MAX descriptors open,
    265  * limit nfds to at most FD_MAX.
    266  */
    267 int
    268 ultrix_sys_select(l, v, retval)
    269 	struct lwp *l;
    270 	void *v;
    271 	register_t *retval;
    272 {
    273 	struct sys_select_args *uap = v;
    274 	struct timeval atv;
    275 	int error;
    276 
    277 	/* Limit number of FDs selected on to the native maximum */
    278 
    279 	if (SCARG(uap, nd) > FD_SETSIZE)
    280 		SCARG(uap, nd) = FD_SETSIZE;
    281 
    282 	/* Check for negative timeval */
    283 	if (SCARG(uap, tv)) {
    284 		error = copyin((caddr_t)SCARG(uap, tv), (caddr_t)&atv,
    285 			       sizeof(atv));
    286 		if (error)
    287 			goto done;
    288 #ifdef DEBUG
    289 		/* Ultrix clients sometimes give negative timeouts? */
    290 		if (atv.tv_sec < 0 || atv.tv_usec < 0)
    291 			printf("ultrix select( %ld, %ld): negative timeout\n",
    292 			    atv.tv_sec, atv.tv_usec);
    293 #endif
    294 
    295 	}
    296 	error = sys_select(l, (void*) uap, retval);
    297 	if (error == EINVAL)
    298 		printf("ultrix select: bad args?\n");
    299 
    300 done:
    301 	return error;
    302 }
    303 
    304 #if defined(NFS)
    305 int
    306 async_daemon(l, v, retval)
    307 	struct lwp *l;
    308 	void *v;
    309 	register_t *retval;
    310 {
    311 	struct sys_nfssvc_args ouap;
    312 
    313 	SCARG(&ouap, flag) = NFSSVC_BIOD;
    314 	SCARG(&ouap, argp) = NULL;
    315 
    316 	return (sys_nfssvc(l, &ouap, retval));
    317 }
    318 #endif /* NFS */
    319 
    320 
    321 #define	SUN__MAP_NEW	0x80000000	/* if not, old mmap & cannot handle */
    322 
    323 int
    324 ultrix_sys_mmap(l, v, retval)
    325 	struct lwp *l;
    326 	void *v;
    327 	register_t *retval;
    328 {
    329 	struct ultrix_sys_mmap_args *uap = v;
    330 	struct sys_mmap_args ouap;
    331 
    332 	/*
    333 	 * Verify the arguments.
    334 	 */
    335 	if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
    336 		return (EINVAL);			/* XXX still needed? */
    337 
    338 	if ((SCARG(uap, flags) & SUN__MAP_NEW) == 0)
    339 		return (EINVAL);
    340 
    341 	SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUN__MAP_NEW;
    342 	SCARG(&ouap, addr) = SCARG(uap, addr);
    343 	SCARG(&ouap, len) = SCARG(uap, len);
    344 	SCARG(&ouap, prot) = SCARG(uap, prot);
    345 	SCARG(&ouap, fd) = SCARG(uap, fd);
    346 	SCARG(&ouap, pos) = SCARG(uap, pos);
    347 
    348 	return (sys_mmap(l, &ouap, retval));
    349 }
    350 
    351 int
    352 ultrix_sys_setsockopt(l, v, retval)
    353 	struct lwp *l;
    354 	void *v;
    355 	register_t *retval;
    356 {
    357 	struct ultrix_sys_setsockopt_args *uap = v;
    358 	struct proc *p = l->l_proc;
    359 	struct file *fp;
    360 	struct mbuf *m = NULL;
    361 	int error;
    362 
    363 	/* getsock() will use the descriptor for us */
    364 	if ((error = getsock(p->p_fd, SCARG(uap, s), &fp))  != 0)
    365 		return (error);
    366 #define	SO_DONTLINGER (~SO_LINGER)
    367 	if (SCARG(uap, name) == SO_DONTLINGER) {
    368 		m = m_get(M_WAIT, MT_SOOPTS);
    369 		mtod(m, struct linger *)->l_onoff = 0;
    370 		m->m_len = sizeof(struct linger);
    371 		error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    372 		    SO_LINGER, m);
    373 	}
    374 	if (SCARG(uap, level) == IPPROTO_IP) {
    375 #define		EMUL_IP_MULTICAST_IF		2
    376 #define		EMUL_IP_MULTICAST_TTL		3
    377 #define		EMUL_IP_MULTICAST_LOOP		4
    378 #define		EMUL_IP_ADD_MEMBERSHIP		5
    379 #define		EMUL_IP_DROP_MEMBERSHIP	6
    380 		static int ipoptxlat[] = {
    381 			IP_MULTICAST_IF,
    382 			IP_MULTICAST_TTL,
    383 			IP_MULTICAST_LOOP,
    384 			IP_ADD_MEMBERSHIP,
    385 			IP_DROP_MEMBERSHIP
    386 		};
    387 		if (SCARG(uap, name) >= EMUL_IP_MULTICAST_IF &&
    388 		    SCARG(uap, name) <= EMUL_IP_DROP_MEMBERSHIP) {
    389 			SCARG(uap, name) =
    390 			    ipoptxlat[SCARG(uap, name) - EMUL_IP_MULTICAST_IF];
    391 		}
    392 	}
    393 	if (SCARG(uap, valsize) > MLEN) {
    394 		error = EINVAL;
    395 		goto out;
    396 	}
    397 	if (SCARG(uap, val)) {
    398 		m = m_get(M_WAIT, MT_SOOPTS);
    399 		error = copyin(SCARG(uap, val), mtod(m, caddr_t),
    400 		    (u_int)SCARG(uap, valsize));
    401 		if (error) {
    402 			(void) m_free(m);
    403 			goto out;
    404 		}
    405 		m->m_len = SCARG(uap, valsize);
    406 	}
    407 	error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    408 	    SCARG(uap, name), m);
    409  out:
    410 	FILE_UNUSE(fp, p);
    411 	return (error);
    412 }
    413 
    414 #define	ULTRIX__SYS_NMLN	32
    415 
    416 struct ultrix_utsname {
    417 	char    sysname[ULTRIX__SYS_NMLN];
    418 	char    nodename[ULTRIX__SYS_NMLN];
    419 	char    release[ULTRIX__SYS_NMLN];
    420 	char    version[ULTRIX__SYS_NMLN];
    421 	char    machine[ULTRIX__SYS_NMLN];
    422 };
    423 
    424 int
    425 ultrix_sys_uname(l, v, retval)
    426 	struct lwp *l;
    427 	void *v;
    428 	register_t *retval;
    429 {
    430 	struct ultrix_sys_uname_args *uap = v;
    431 	struct ultrix_utsname sut;
    432 	const char *cp;
    433 	char *dp, *ep;
    434 
    435 	memset(&sut, 0, sizeof(sut));
    436 
    437 	strncpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
    438 	strncpy(sut.nodename, hostname, sizeof(sut.nodename) - 1);
    439 	strncpy(sut.release, osrelease, sizeof(sut.release) - 1);
    440 	dp = sut.version;
    441 	ep = &sut.version[sizeof(sut.version) - 1];
    442 	for (cp = version; *cp && *cp != '('; cp++)
    443 		;
    444 	for (cp++; *cp && *cp != ')' && dp < ep; cp++)
    445 		*dp++ = *cp;
    446 	for (; *cp && *cp != '#'; cp++)
    447 		;
    448 	for (; *cp && *cp != ':' && dp < ep; cp++)
    449 		*dp++ = *cp;
    450 	*dp = '\0';
    451 	strncpy(sut.machine, machine, sizeof(sut.machine) - 1);
    452 
    453 	return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
    454 	    sizeof(struct ultrix_utsname));
    455 }
    456 
    457 int
    458 ultrix_sys_setpgrp(l, v, retval)
    459 	struct lwp *l;
    460 	void *v;
    461 	register_t *retval;
    462 {
    463 	struct ultrix_sys_setpgrp_args *uap = v;
    464 	struct proc *p = l->l_proc;
    465 
    466 	/*
    467 	 * difference to our setpgid call is to include backwards
    468 	 * compatibility to pre-setsid() binaries. Do setsid()
    469 	 * instead of setpgid() in those cases where the process
    470 	 * tries to create a new session the old way.
    471 	 */
    472 	if (!SCARG(uap, pgid) &&
    473 	    (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
    474 		return sys_setsid(l, uap, retval);
    475 	else
    476 		return sys_setpgid(l, uap, retval);
    477 }
    478 
    479 #if defined (NFSSERVER)
    480 int
    481 ultrix_sys_nfssvc(l, v, retval)
    482 	struct lwp *l;
    483 	void *v;
    484 	register_t *retval;
    485 {
    486 
    487 #if 0	/* XXX */
    488 	struct ultrix_sys_nfssvc_args *uap = v;
    489 	struct emul *e = p->p_emul;
    490 	struct sys_nfssvc_args outuap;
    491 	struct sockaddr sa;
    492 	int error;
    493 	caddr_t sg = stackgap_init(p, 0);
    494 
    495 	memset(&outuap, 0, sizeof outuap);
    496 	SCARG(&outuap, fd) = SCARG(uap, fd);
    497 	SCARG(&outuap, mskval) = stackgap_alloc(p, &sg, sizeof sa);
    498 	SCARG(&outuap, msklen) = sizeof sa;
    499 	SCARG(&outuap, mtchval) = stackgap_alloc(p, &sg, sizeof sa);
    500 	SCARG(&outuap, mtchlen) = sizeof sa;
    501 
    502 	memset(&sa, 0, sizeof sa);
    503 	if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
    504 		return (error);
    505 	if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
    506 		return (error);
    507 
    508 	return nfssvc(l, &outuap, retval);
    509 #else
    510 	return (ENOSYS);
    511 #endif
    512 }
    513 #endif /* NFSSERVER */
    514 
    515 struct ultrix_ustat {
    516 	daddr_t	f_tfree;	/* total free */
    517 	ino_t	f_tinode;	/* total inodes free */
    518 	char	f_fname[6];	/* filsys name */
    519 	char	f_fpack[6];	/* filsys pack name */
    520 };
    521 
    522 int
    523 ultrix_sys_ustat(l, v, retval)
    524 	struct lwp *l;
    525 	void *v;
    526 	register_t *retval;
    527 {
    528 	struct ultrix_sys_ustat_args *uap = v;
    529 	struct ultrix_ustat us;
    530 	int error;
    531 
    532 	memset(&us, 0, sizeof us);
    533 
    534 	/*
    535 	 * XXX: should set f_tfree and f_tinode at least
    536 	 * How do we translate dev -> fstat? (and then to ultrix_ustat)
    537 	 */
    538 
    539 	if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
    540 		return (error);
    541 	return 0;
    542 }
    543 
    544 int
    545 ultrix_sys_quotactl(l, v, retval)
    546 	struct lwp *l;
    547 	void *v;
    548 	register_t *retval;
    549 {
    550 
    551 #ifdef notyet
    552 	struct ultrix_sys_quotactl_args *uap = v;
    553 #endif
    554 
    555 	return EINVAL;
    556 }
    557 
    558 int
    559 ultrix_sys_vhangup(l, v, retval)
    560 	struct lwp *l;
    561 	void *v;
    562 	register_t *retval;
    563 {
    564 
    565 	return 0;
    566 }
    567 
    568 
    569 /*
    570  * RISC Ultrix cache control syscalls
    571  */
    572 #ifdef __mips
    573 int
    574 ultrix_sys_cacheflush(l, v, retval)
    575 	struct lwp *l;
    576 	void *v;
    577 	register_t *retval;
    578 {
    579 	struct ultrix_sys_cacheflush_args /* {
    580 		syscallarg(void *) addr;
    581 		syscallarg(int) nbytes;
    582 		syscallarg(int) flag;
    583 	} */ *uap = v;
    584 	struct proc *p = l->l_proc;
    585 	vaddr_t va  = (vaddr_t)SCARG(uap, addr);
    586 	int nbytes     = SCARG(uap, nbytes);
    587 	int whichcache = SCARG(uap, whichcache);
    588 
    589 	return (mips_user_cacheflush(p, va, nbytes, whichcache));
    590 }
    591 
    592 
    593 int
    594 ultrix_sys_cachectl(l, v, retval)
    595 	struct lwp *l;
    596 	void *v;
    597 	register_t *retval;
    598 {
    599 	struct ultrix_sys_cachectl_args /* {
    600 		syscallarg(void *) addr;
    601 		syscallarg(int) nbytes;
    602 		syscallarg(int) cacheop;
    603 	} */ *uap = v;
    604 	struct proc *p = l->l_proc;
    605 	vaddr_t va  = (vaddr_t)SCARG(uap, addr);
    606 	int nbytes  = SCARG(uap, nbytes);
    607 	int cacheop = SCARG(uap, cacheop);
    608 
    609 	return mips_user_cachectl(p, va, nbytes, cacheop);
    610 }
    611 
    612 #endif	/* __mips */
    613 
    614 
    615 int
    616 ultrix_sys_exportfs(l, v, retval)
    617 	struct lwp *l;
    618 	void *v;
    619 	register_t *retval;
    620 {
    621 #ifdef notyet
    622 	struct ultrix_sys_exportfs_args *uap = v;
    623 #endif
    624 
    625 	/*
    626 	 * XXX: should perhaps translate into a mount(2)
    627 	 * with MOUNT_EXPORT?
    628 	 */
    629 	return 0;
    630 }
    631 
    632 int
    633 ultrix_sys_sigpending(l, v, retval)
    634 	struct lwp *l;
    635 	void *v;
    636 	register_t *retval;
    637 {
    638 	struct ultrix_sys_sigpending_args *uap = v;
    639 	sigset_t ss;
    640 	int mask;
    641 
    642 	sigpending1(l->l_proc, &ss);
    643 	mask = ss.__bits[0];
    644 
    645 	return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
    646 }
    647 
    648 int
    649 ultrix_sys_sigreturn(l, v, retval)
    650 	struct lwp *l;
    651 	void *v;
    652 	register_t *retval;
    653 {
    654 	struct ultrix_sys_sigreturn_args *uap = v;
    655 
    656 	/* struct sigcontext13 is close enough to Ultrix */
    657 
    658 	return (compat_13_sys_sigreturn(l, uap, retval));
    659 }
    660 
    661 int
    662 ultrix_sys_sigcleanup(l, v, retval)
    663 	struct lwp *l;
    664 	void *v;
    665 	register_t *retval;
    666 {
    667 	struct ultrix_sys_sigcleanup_args *uap = v;
    668 
    669 	/* struct sigcontext13 is close enough to Ultrix */
    670 
    671 	return (compat_13_sys_sigreturn(l, uap, retval));
    672 }
    673 
    674 int
    675 ultrix_sys_sigsuspend(l, v, retval)
    676 	struct lwp *l;
    677 	void *v;
    678 	register_t *retval;
    679 {
    680 	struct ultrix_sys_sigsuspend_args *uap = v;
    681 	int mask = SCARG(uap, mask);
    682 	sigset_t ss;
    683 
    684 	ss.__bits[0] = mask;
    685 	ss.__bits[1] = 0;
    686 	ss.__bits[2] = 0;
    687 	ss.__bits[3] = 0;
    688 
    689 	return (sigsuspend1(l->l_proc, &ss));
    690 }
    691 
    692 #define ULTRIX_SV_ONSTACK 0x0001  /* take signal on signal stack */
    693 #define ULTRIX_SV_INTERRUPT 0x0002  /* do not restart system on signal return */
    694 #define ULTRIX_SV_OLDSIG 0x1000  /* Emulate old signal() for POSIX */
    695 
    696 int
    697 ultrix_sys_sigvec(l, v, retval)
    698 	struct lwp *l;
    699 	void *v;
    700 	register_t *retval;
    701 {
    702 	struct ultrix_sys_sigvec_args *uap = v;
    703 	struct sigvec nsv, osv;
    704 	struct sigaction nsa, osa;
    705 	int error;
    706 
    707 	if (SCARG(uap, nsv)) {
    708 		error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
    709 		if (error)
    710 			return (error);
    711 		nsa.sa_handler = nsv.sv_handler;
    712 #if 0 /* documentation */
    713 		/* ONSTACK is identical */
    714 		nsa.sa_flags = nsv.sv_flags & ULTRIX_SV_ONSTACK;
    715 		if ((nsv.sv_flags & ULTRIX_SV_OLDSIG)
    716 		    /* old signal() - always restart */
    717 		    || (!(nsv.sv_flags & ULTRIX_SV_INTERRUPT))
    718 		    /* inverted meaning (same bit) */
    719 		    )
    720 			nsa.sa_flags |= SA_RESTART;
    721 #else /* optimized - assuming ULTRIX_SV_OLDSIG=>!ULTRIX_SV_INTERRUPT */
    722 		nsa.sa_flags = nsv.sv_flags & ~ULTRIX_SV_OLDSIG;
    723 		nsa.sa_flags ^= SA_RESTART;
    724 #endif
    725 		native_sigset13_to_sigset(&nsv.sv_mask, &nsa.sa_mask);
    726 	}
    727 	error = sigaction1(l->l_proc, SCARG(uap, signum),
    728 	    SCARG(uap, nsv) ? &nsa : 0, SCARG(uap, osv) ? &osa : 0,
    729 	    NULL, 0);
    730 	if (error)
    731 		return (error);
    732 	if (SCARG(uap, osv)) {
    733 		osv.sv_handler = osa.sa_handler;
    734 		osv.sv_flags = osa.sa_flags ^ SA_RESTART;
    735 		osv.sv_flags &= (ULTRIX_SV_ONSTACK | ULTRIX_SV_INTERRUPT);
    736 		native_sigset_to_sigset13(&osa.sa_mask, &osv.sv_mask);
    737 		error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
    738 		if (error)
    739 			return (error);
    740 	}
    741 	return (0);
    742 }
    743 
    744 int
    745 ultrix_sys_shmsys(l, v, retval)
    746 	struct lwp *l;
    747 	void *v;
    748 	register_t *retval;
    749 {
    750 
    751 #ifdef SYSVSHM
    752 
    753 	/* Ultrix SVSHM weirndess: */
    754 	struct ultrix_sys_shmsys_args *uap = v;
    755 	struct sys_shmat_args shmat_args;
    756 	struct compat_14_sys_shmctl_args shmctl_args;
    757 	struct sys_shmdt_args shmdt_args;
    758 	struct sys_shmget_args shmget_args;
    759 
    760 
    761 	switch (SCARG(uap, shmop)) {
    762 	case 0:						/* Ultrix shmat() */
    763 		SCARG(&shmat_args, shmid) = SCARG(uap, a2);
    764 		SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
    765 		SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
    766 		return (sys_shmat(l, &shmat_args, retval));
    767 
    768 	case 1:						/* Ultrix shmctl() */
    769 		SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
    770 		SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
    771 		SCARG(&shmctl_args, buf) = (struct shmid_ds14 *)SCARG(uap, a4);
    772 		return (compat_14_sys_shmctl(l, &shmctl_args, retval));
    773 
    774 	case 2:						/* Ultrix shmdt() */
    775 		SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a2);
    776 		return (sys_shmdt(l, &shmdt_args, retval));
    777 
    778 	case 3:						/* Ultrix shmget() */
    779 		SCARG(&shmget_args, key) = SCARG(uap, a2);
    780 		SCARG(&shmget_args, size) = SCARG(uap, a3);
    781 		SCARG(&shmget_args, shmflg) = SCARG(uap, a4)
    782 		    & (IPC_CREAT|IPC_EXCL|IPC_NOWAIT);
    783 		return (sys_shmget(l, &shmget_args, retval));
    784 
    785 	default:
    786 		return (EINVAL);
    787 	}
    788 #else
    789 	return (EOPNOTSUPP);
    790 #endif	/* SYSVSHM */
    791 }
    792 
    793 static int
    794 ultrix_to_bsd_flock(ufl, fl)
    795 	struct ultrix_flock *ufl;
    796 	struct flock *fl;
    797 {
    798 
    799 	fl->l_start = ufl->l_start;
    800 	fl->l_len = ufl->l_len;
    801 	fl->l_pid = ufl->l_pid;
    802 	fl->l_whence = ufl->l_whence;
    803 
    804 	switch (ufl->l_type) {
    805 	case ULTRIX_F_RDLCK:
    806 		fl->l_type = F_RDLCK;
    807 		break;
    808 	case ULTRIX_F_WRLCK:
    809 		fl->l_type = F_WRLCK;
    810 		break;
    811 	case ULTRIX_F_UNLCK:
    812 		fl->l_type = F_UNLCK;
    813 		break;
    814 	default:
    815 		return (EINVAL);
    816 	}
    817 
    818 	return (0);
    819 }
    820 
    821 static void
    822 bsd_to_ultrix_flock(fl, ufl)
    823 	struct flock *fl;
    824 	struct ultrix_flock *ufl;
    825 {
    826 
    827 	ufl->l_start = fl->l_start;
    828 	ufl->l_len = fl->l_len;
    829 	ufl->l_pid = fl->l_pid;
    830 	ufl->l_whence = fl->l_whence;
    831 
    832 	switch (fl->l_type) {
    833 	case F_RDLCK:
    834 		ufl->l_type = ULTRIX_F_RDLCK;
    835 		break;
    836 	case F_WRLCK:
    837 		ufl->l_type = ULTRIX_F_WRLCK;
    838 		break;
    839 	case F_UNLCK:
    840 		ufl->l_type = ULTRIX_F_UNLCK;
    841 		break;
    842 	}
    843 }
    844 
    845 int
    846 ultrix_sys_fcntl(l, v, retval)
    847 	struct lwp *l;
    848 	void *v;
    849 	register_t *retval;
    850 {
    851 	struct ultrix_sys_fcntl_args *uap = v;
    852 	struct proc *p = l->l_proc;
    853 	int error;
    854 	struct ultrix_flock ufl;
    855 	struct flock fl, *flp;
    856 	caddr_t sg;
    857 	struct sys_fcntl_args *args, fca;
    858 
    859 	switch (SCARG(uap, cmd)) {
    860 	case F_GETLK:
    861 	case F_SETLK:
    862 	case F_SETLKW:
    863 		error = copyin(SCARG(uap, arg), &ufl, sizeof(ufl));
    864 		if (error)
    865 			return (error);
    866 		error = ultrix_to_bsd_flock(&ufl, &fl);
    867 		if (error)
    868 			return (error);
    869 		sg = stackgap_init(p, 0);
    870 		flp = (struct flock *)stackgap_alloc(p, &sg, sizeof(*flp));
    871 		error = copyout(&fl, flp, sizeof(*flp));
    872 		if (error)
    873 			return (error);
    874 
    875 		SCARG(&fca, fd) = SCARG(uap, fd);
    876 		SCARG(&fca, cmd) = SCARG(uap, cmd);
    877 		SCARG(&fca, arg) = flp;
    878 		args = &fca;
    879 		break;
    880 	default:
    881 		args = v;
    882 		break;
    883 	}
    884 
    885 	error = sys_fcntl(l, args, retval);
    886 	if (error)
    887 		return (error);
    888 
    889 	switch (SCARG(uap, cmd)) {
    890 	case F_GETLK:
    891 		error = copyin(flp, &fl, sizeof(fl));
    892 		if (error)
    893 			return (error);
    894 		bsd_to_ultrix_flock(&fl, &ufl);
    895 		error = copyout(&ufl, SCARG(uap, arg), sizeof(ufl));
    896 		break;
    897 	}
    898 
    899 	return (error);
    900 }
    901