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