Home | History | Annotate | Line # | Download | only in ultrix
ultrix_misc.c revision 1.22
      1 /*	$NetBSD: ultrix_misc.c,v 1.22 1996/04/07 16:38:03 jonathan Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1992, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This software was developed by the Computer Systems Engineering group
      8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  * contributed to Berkeley.
     10  *
     11  * All advertising materials mentioning features or use of this software
     12  * must display the following acknowledgement:
     13  *	This product includes software developed by the University of
     14  *	California, Lawrence Berkeley Laboratory.
     15  *
     16  * Redistribution and use in source and binary forms, with or without
     17  * modification, are permitted provided that the following conditions
     18  * are met:
     19  * 1. Redistributions of source code must retain the above copyright
     20  *    notice, this list of conditions and the following disclaimer.
     21  * 2. Redistributions in binary form must reproduce the above copyright
     22  *    notice, this list of conditions and the following disclaimer in the
     23  *    documentation and/or other materials provided with the distribution.
     24  * 3. All advertising materials mentioning features or use of this software
     25  *    must display the following acknowledgement:
     26  *	This product includes software developed by the University of
     27  *	California, Berkeley and its contributors.
     28  * 4. Neither the name of the University nor the names of its contributors
     29  *    may be used to endorse or promote products derived from this software
     30  *    without specific prior written permission.
     31  *
     32  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42  * SUCH DAMAGE.
     43  *
     44  *
     45  *	@(#)sun_misc.c	8.1 (Berkeley) 6/18/93
     46  *
     47  * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
     48  */
     49 
     50 /*
     51  * SunOS compatibility module.
     52  *
     53  * SunOS system calls that are implemented differently in BSD are
     54  * handled here.
     55  */
     56 
     57 #include <sys/param.h>
     58 #include <sys/systm.h>
     59 #include <sys/namei.h>
     60 #include <sys/dir.h>
     61 #include <sys/proc.h>
     62 #include <sys/file.h>
     63 #include <sys/filedesc.h>
     64 /*#include <sys/stat.h>*/
     65 /*#include <sys/ioctl.h>*/
     66 #include <sys/kernel.h>
     67 #include <sys/exec.h>
     68 #include <sys/malloc.h>
     69 #include <sys/mbuf.h>
     70 #include <sys/mman.h>
     71 #include <sys/mount.h>
     72 #include <sys/resource.h>
     73 #include <sys/resourcevar.h>
     74 #include <sys/signal.h>
     75 #include <sys/signalvar.h>
     76 #include <sys/socket.h>
     77 #include <sys/vnode.h>
     78 #include <sys/uio.h>
     79 #include <sys/wait.h>
     80 #include <sys/utsname.h>
     81 #include <sys/unistd.h>
     82 
     83 #include <sys/syscallargs.h>
     84 
     85 #include <compat/ultrix/ultrix_syscall.h>
     86 #include <compat/ultrix/ultrix_syscallargs.h>
     87 
     88 #include <netinet/in.h>
     89 
     90 #include <miscfs/specfs/specdev.h>
     91 
     92 #include <nfs/rpcv2.h>
     93 #include <nfs/nfsproto.h>
     94 #include <nfs/nfs.h>
     95 
     96 #include <vm/vm.h>
     97 
     98 extern struct sysent ultrix_sysent[];
     99 extern char *ultrix_syscallnames[];
    100 
    101 /*
    102  * Select the appropriate setregs callback for the target architecture.
    103  */
    104 #ifdef mips
    105 #define ULTRIX_EXEC_SETREGS cpu_exec_ecoff_setregs
    106 #endif /* mips */
    107 
    108 #ifdef vax
    109 #define ULTRIX_EXEC_SETREGS setregs
    110 #endif /* mips */
    111 
    112 
    113 extern void ULTRIX_EXEC_SETREGS __P((struct proc *, struct exec_package *,
    114 					u_long, register_t *));
    115 extern char sigcode[], esigcode[];
    116 
    117 struct emul emul_ultrix = {
    118 	"ultrix",
    119 	NULL,
    120 	sendsig,
    121 	ULTRIX_SYS_syscall,
    122 	ULTRIX_SYS_MAXSYSCALL,
    123 	ultrix_sysent,
    124 	ultrix_syscallnames,
    125 	0,
    126 	copyargs,
    127 	ULTRIX_EXEC_SETREGS,
    128 	sigcode,
    129 	esigcode,
    130 };
    131 
    132 #define GSI_PROG_ENV 1
    133 
    134 ultrix_sys_getsysinfo(p, v, retval)
    135 	struct proc *p;
    136 	void *v;
    137 	register_t *retval;
    138 {
    139 	struct ultrix_sys_getsysinfo_args *uap = v;
    140 	static short progenv = 0;
    141 
    142 	switch (SCARG(uap, op)) {
    143 		/* operations implemented: */
    144 	case GSI_PROG_ENV:
    145 		if (SCARG(uap, nbytes) < sizeof(short))
    146 			return EINVAL;
    147 		*retval = 1;
    148 		return (copyout(&progenv, SCARG(uap, buffer), sizeof(short)));
    149 	default:
    150 		*retval = 0; /* info unavail */
    151 		return 0;
    152 	}
    153 }
    154 
    155 ultrix_sys_setsysinfo(p, v, retval)
    156 	struct proc *p;
    157 	void *v;
    158 	register_t *retval;
    159 {
    160 	struct ultrix_sys_setsysinfo_args *uap = v;
    161 	*retval = 0;
    162 	return 0;
    163 }
    164 
    165 ultrix_sys_waitpid(p, v, retval)
    166 	struct proc *p;
    167 	void *v;
    168 	register_t *retval;
    169 {
    170 	struct ultrix_sys_waitpid_args *uap = v;
    171 	struct sys_wait4_args ua;
    172 
    173 	SCARG(&ua, pid) = SCARG(uap, pid);
    174 	SCARG(&ua, status) = SCARG(uap, status);
    175 	SCARG(&ua, options) = SCARG(uap, options);
    176 	SCARG(&ua, rusage) = 0;
    177 
    178 	return (sys_wait4(p, &ua, retval));
    179 }
    180 
    181 ultrix_sys_wait3(p, v, retval)
    182 	struct proc *p;
    183 	void *v;
    184 	register_t *retval;
    185 {
    186 	struct ultrix_sys_wait3_args *uap = v;
    187 	struct sys_wait4_args ua;
    188 
    189 	SCARG(&ua, pid) = -1;
    190 	SCARG(&ua, status) = SCARG(uap, status);
    191 	SCARG(&ua, options) = SCARG(uap, options);
    192 	SCARG(&ua, rusage) = SCARG(uap, rusage);
    193 
    194 	return (sys_wait4(p, &ua, retval));
    195 }
    196 
    197 /*
    198  * Ultrix binaries pass in FD_MAX as the first arg to select().
    199  * On Ultrix, that is 4096, which is more than the NetBSD sys_select()
    200  * can handle.
    201  */
    202 ultrix_sys_select(p, v, retval)
    203 	struct proc *p;
    204 	void *v;
    205 	register_t *retval;
    206 {
    207 	struct sys_select_args *uap = v;
    208 	struct timeval atv, *tvp;
    209 	int error;
    210 
    211 	/* Limit number of FDs selected on to the native maximum */
    212 
    213 	if (SCARG(uap, nd) > FD_SETSIZE)
    214 		SCARG(uap, nd) = FD_SETSIZE;
    215 
    216 	/* Check for negative timeval */
    217 	if (SCARG(uap, tv)) {
    218 		error = copyin((caddr_t)SCARG(uap, tv), (caddr_t)&atv,
    219 			       sizeof(atv));
    220 		if (error)
    221 			goto done;
    222 #ifdef DEBUG
    223 		/* Ultrix clients sometimes give negative timeouts? */
    224 		if (atv.tv_sec < 0 || atv.tv_usec < 0)
    225 			printf("ultrix select( %d, %d)\n",
    226 			       atv.tv_sec, atv.tv_usec);
    227 		/*tvp = (timeval *)STACKGAPBASE;*/
    228 #endif
    229 
    230 	}
    231 	error = sys_select(p, (void*) uap, retval);
    232 	if (error == EINVAL)
    233 		printf("ultrix select: bad args?\n");
    234 
    235 done:
    236 	return error;
    237 }
    238 
    239 #if defined(NFSCLIENT)
    240 async_daemon(p, v, retval)
    241 	struct proc *p;
    242 	void *v;
    243 	register_t *retval;
    244 {
    245 	struct sys_nfssvc_args ouap;
    246 
    247 	SCARG(&ouap, flag) = NFSSVC_BIOD;
    248 	SCARG(&ouap, argp) = NULL;
    249 
    250 	return (sys_nfssvc(p, &ouap, retval));
    251 }
    252 #endif /* NFSCLIENT */
    253 
    254 
    255 #define	SUN__MAP_NEW	0x80000000	/* if not, old mmap & cannot handle */
    256 
    257 int
    258 ultrix_sys_mmap(p, v, retval)
    259 	register struct proc *p;
    260 	void *v;
    261 	register_t *retval;
    262 {
    263 	register struct ultrix_sys_mmap_args *uap = v;
    264 	struct sys_mmap_args ouap;
    265 	register struct filedesc *fdp;
    266 	register struct file *fp;
    267 	register struct vnode *vp;
    268 
    269 	/*
    270 	 * Verify the arguments.
    271 	 */
    272 	if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
    273 		return (EINVAL);			/* XXX still needed? */
    274 
    275 	if ((SCARG(uap, flags) & SUN__MAP_NEW) == 0)
    276 		return (EINVAL);
    277 
    278 	SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUN__MAP_NEW;
    279 	SCARG(&ouap, addr) = SCARG(uap, addr);
    280 
    281 	if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 &&
    282 	    SCARG(&ouap, addr) != 0 &&
    283 	    SCARG(&ouap, addr) < (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ))
    284 		SCARG(&ouap, addr) = (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ);
    285 
    286 	SCARG(&ouap, len) = SCARG(uap, len);
    287 	SCARG(&ouap, prot) = SCARG(uap, prot);
    288 	SCARG(&ouap, fd) = SCARG(uap, fd);
    289 	SCARG(&ouap, pos) = SCARG(uap, pos);
    290 
    291 	/*
    292 	 * Special case: if fd refers to /dev/zero, map as MAP_ANON.  (XXX)
    293 	 */
    294 	fdp = p->p_fd;
    295 	if ((unsigned)SCARG(&ouap, fd) < fdp->fd_nfiles &&		/*XXX*/
    296 	    (fp = fdp->fd_ofiles[SCARG(&ouap, fd)]) != NULL &&		/*XXX*/
    297 	    fp->f_type == DTYPE_VNODE &&				/*XXX*/
    298 	    (vp = (struct vnode *)fp->f_data)->v_type == VCHR &&	/*XXX*/
    299 	    iszerodev(vp->v_rdev)) {					/*XXX*/
    300 		SCARG(&ouap, flags) |= MAP_ANON;
    301 		SCARG(&ouap, fd) = -1;
    302 	}
    303 
    304 	return (sys_mmap(p, &ouap, retval));
    305 }
    306 
    307 ultrix_sys_setsockopt(p, v, retval)
    308 	struct proc *p;
    309 	void *v;
    310 	register_t *retval;
    311 {
    312 	register struct ultrix_sys_setsockopt_args *uap = v;
    313 	struct file *fp;
    314 	struct mbuf *m = NULL;
    315 	int error;
    316 
    317 	if (error = getsock(p->p_fd, SCARG(uap, s), &fp))
    318 		return (error);
    319 #define	SO_DONTLINGER (~SO_LINGER)
    320 	if (SCARG(uap, name) == SO_DONTLINGER) {
    321 		m = m_get(M_WAIT, MT_SOOPTS);
    322 		if (m == NULL)
    323 			return (ENOBUFS);
    324 		mtod(m, struct linger *)->l_onoff = 0;
    325 		m->m_len = sizeof(struct linger);
    326 		return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    327 		    SO_LINGER, m));
    328 	}
    329 	if (SCARG(uap, valsize) > MLEN)
    330 		return (EINVAL);
    331 	if (SCARG(uap, val)) {
    332 		m = m_get(M_WAIT, MT_SOOPTS);
    333 		if (m == NULL)
    334 			return (ENOBUFS);
    335 		if (error = copyin(SCARG(uap, val), mtod(m, caddr_t),
    336 		    (u_int)SCARG(uap, valsize))) {
    337 			(void) m_free(m);
    338 			return (error);
    339 		}
    340 		m->m_len = SCARG(uap, valsize);
    341 	}
    342 	return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    343 	    SCARG(uap, name), m));
    344 }
    345 
    346 struct ultrix_utsname {
    347 	char    sysname[9];
    348 	char    nodename[9];
    349 	char    nodeext[65-9];
    350 	char    release[9];
    351 	char    version[9];
    352 	char    machine[9];
    353 };
    354 
    355 int
    356 ultrix_sys_uname(p, v, retval)
    357 	struct proc *p;
    358 	void *v;
    359 	register_t *retval;
    360 {
    361 	struct ultrix_sys_uname_args *uap = v;
    362 	struct ultrix_utsname sut;
    363 	extern char ostype[], machine[], osrelease[];
    364 
    365 	bzero(&sut, sizeof(sut));
    366 
    367 	bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1);
    368 	bcopy(hostname, sut.nodename, sizeof(sut.nodename));
    369 	sut.nodename[sizeof(sut.nodename)-1] = '\0';
    370 	bcopy(osrelease, sut.release, sizeof(sut.release) - 1);
    371 	bcopy("1", sut.version, sizeof(sut.version) - 1);
    372 	bcopy(machine, sut.machine, sizeof(sut.machine) - 1);
    373 
    374 	return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
    375 	    sizeof(struct ultrix_utsname));
    376 }
    377 
    378 int
    379 ultrix_sys_setpgrp(p, v, retval)
    380 	struct proc *p;
    381 	void *v;
    382 	register_t *retval;
    383 {
    384 	struct ultrix_sys_setpgrp_args *uap = v;
    385 
    386 	/*
    387 	 * difference to our setpgid call is to include backwards
    388 	 * compatibility to pre-setsid() binaries. Do setsid()
    389 	 * instead of setpgid() in those cases where the process
    390 	 * tries to create a new session the old way.
    391 	 */
    392 	if (!SCARG(uap, pgid) &&
    393 	    (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
    394 		return sys_setsid(p, uap, retval);
    395 	else
    396 		return sys_setpgid(p, uap, retval);
    397 }
    398 
    399 #if defined (NFSSERVER)
    400 int
    401 ultrix_sys_nfssvc(p, v, retval)
    402 	struct proc *p;
    403 	void *v;
    404 	register_t *retval;
    405 {
    406 	struct ultrix_sys_nfssvc_args *uap = v;
    407 	struct emul *e = p->p_emul;
    408 	struct sys_nfssvc_args outuap;
    409 	struct sockaddr sa;
    410 	int error;
    411 
    412 #if 0
    413 	bzero(&outuap, sizeof outuap);
    414 	SCARG(&outuap, fd) = SCARG(uap, fd);
    415 	SCARG(&outuap, mskval) = STACKGAPBASE;
    416 	SCARG(&outuap, msklen) = sizeof sa;
    417 	SCARG(&outuap, mtchval) = outuap.mskval + sizeof sa;
    418 	SCARG(&outuap, mtchlen) = sizeof sa;
    419 
    420 	bzero(&sa, sizeof sa);
    421 	if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
    422 		return (error);
    423 	if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
    424 		return (error);
    425 
    426 	return nfssvc(p, &outuap, retval);
    427 #else
    428 	return (ENOSYS);
    429 #endif
    430 }
    431 #endif /* NFSSERVER */
    432 
    433 struct ultrix_ustat {
    434 	daddr_t	f_tfree;	/* total free */
    435 	ino_t	f_tinode;	/* total inodes free */
    436 	char	f_fname[6];	/* filsys name */
    437 	char	f_fpack[6];	/* filsys pack name */
    438 };
    439 
    440 int
    441 ultrix_sys_ustat(p, v, retval)
    442 	struct proc *p;
    443 	void *v;
    444 	register_t *retval;
    445 {
    446 	struct ultrix_sys_ustat_args *uap = v;
    447 	struct ultrix_ustat us;
    448 	int error;
    449 
    450 	bzero(&us, sizeof us);
    451 
    452 	/*
    453 	 * XXX: should set f_tfree and f_tinode at least
    454 	 * How do we translate dev -> fstat? (and then to ultrix_ustat)
    455 	 */
    456 
    457 	if (error = copyout(&us, SCARG(uap, buf), sizeof us))
    458 		return (error);
    459 	return 0;
    460 }
    461 
    462 int
    463 ultrix_sys_quotactl(p, v, retval)
    464 	struct proc *p;
    465 	void *v;
    466 	register_t *retval;
    467 {
    468 	struct ultrix_sys_quotactl_args *uap = v;
    469 
    470 	return EINVAL;
    471 }
    472 
    473 int
    474 ultrix_sys_vhangup(p, v, retval)
    475 	struct proc *p;
    476 	void *v;
    477 	register_t *retval;
    478 {
    479 
    480 	return 0;
    481 }
    482 
    483 int
    484 ultrix_sys_exportfs(p, v, retval)
    485 	struct proc *p;
    486 	void *v;
    487 	register_t *retval;
    488 {
    489 	struct ultrix_sys_exportfs_args *uap = v;
    490 
    491 	/*
    492 	 * XXX: should perhaps translate into a mount(2)
    493 	 * with MOUNT_EXPORT?
    494 	 */
    495 	return 0;
    496 }
    497 
    498 int
    499 ultrix_sys_sigpending(p, v, retval)
    500 	struct proc *p;
    501 	void *v;
    502 	register_t *retval;
    503 {
    504 	struct ultrix_sys_sigpending_args *uap = v;
    505 	int mask = p->p_siglist & p->p_sigmask;
    506 
    507 	return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
    508 }
    509 
    510 int
    511 ultrix_sys_sigcleanup(p, v, retval)
    512 	struct proc *p;
    513 	void *v;
    514 	register_t *retval;
    515 {
    516 	struct ultrix_sys_sigcleanup_args *uap = v;
    517 
    518 	return sys_sigreturn(p, (struct sys_sigreturn_args *)uap, retval);
    519 }
    520 
    521 int
    522 ultrix_sys_sigreturn(p, v, retval)
    523 	struct proc *p;
    524 	void *v;
    525 	register_t *retval;
    526 {
    527 	struct ultrix_sys_sigcleanup_args *uap = v;
    528 
    529 #ifdef DEBUG
    530 	printf("ultrix sigreturn\n");
    531 #endif
    532 	return sys_sigreturn(p, (struct sys_sigreturn_args  *)uap, retval);
    533 }
    534