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