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