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