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