Home | History | Annotate | Line # | Download | only in sunos
sunos_misc.c revision 1.99
      1 /*	$NetBSD: sunos_misc.c,v 1.99 1999/02/09 20:29:24 christos 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  *	@(#)sunos_misc.c	8.1 (Berkeley) 6/18/93
     45  *
     46  *	Header: sunos_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
     47  */
     48 
     49 /*
     50  * SunOS compatibility module.
     51  *
     52  * SunOS system calls that are implemented differently in BSD are
     53  * handled here.
     54  */
     55 
     56 #define COMPAT_SUNOS 1
     57 
     58 #include "opt_nfsserver.h"
     59 #include "fs_nfs.h"
     60 
     61 #include <sys/param.h>
     62 #include <sys/systm.h>
     63 #include <sys/namei.h>
     64 #include <sys/proc.h>
     65 #include <sys/dirent.h>
     66 #include <sys/file.h>
     67 #include <sys/stat.h>
     68 #include <sys/filedesc.h>
     69 #include <sys/ioctl.h>
     70 #include <sys/kernel.h>
     71 #include <sys/reboot.h>
     72 #include <sys/malloc.h>
     73 #include <sys/mbuf.h>
     74 #include <sys/mman.h>
     75 #include <sys/mount.h>
     76 #include <sys/ptrace.h>
     77 #include <sys/resource.h>
     78 #include <sys/resourcevar.h>
     79 #include <sys/signal.h>
     80 #include <sys/signalvar.h>
     81 #include <sys/socket.h>
     82 #include <sys/tty.h>
     83 #include <sys/vnode.h>
     84 #include <sys/uio.h>
     85 #include <sys/wait.h>
     86 #include <sys/utsname.h>
     87 #include <sys/unistd.h>
     88 #include <sys/syscallargs.h>
     89 #include <sys/conf.h>
     90 #include <sys/socketvar.h>
     91 #include <sys/exec.h>
     92 #include <sys/swap.h>
     93 
     94 #include <compat/sunos/sunos.h>
     95 #include <compat/sunos/sunos_syscallargs.h>
     96 #include <compat/sunos/sunos_util.h>
     97 #include <compat/sunos/sunos_dirent.h>
     98 
     99 #include <netinet/in.h>
    100 
    101 #include <miscfs/specfs/specdev.h>
    102 
    103 #include <nfs/rpcv2.h>
    104 #include <nfs/nfsproto.h>
    105 #include <nfs/nfs.h>
    106 #include <nfs/nfsmount.h>
    107 
    108 #include <vm/vm.h>
    109 
    110 static int sunstatfs __P((struct statfs *, caddr_t));
    111 
    112 int
    113 sunos_sys_stime(p, v, retval)
    114 	struct proc *p;
    115 	void *v;
    116 	register_t *retval;
    117 {
    118 	struct sunos_sys_stime_args *uap = v;
    119 	struct sys_settimeofday_args ap;
    120 	caddr_t sg = stackgap_init(p->p_emul);
    121 	struct timeval tv, *sgtvp;
    122 	int error;
    123 
    124 	error = copyin(SCARG(uap, tp), &tv.tv_sec, sizeof(tv.tv_sec));
    125 	if (error)
    126 		return error;
    127 	tv.tv_usec = 0;
    128 
    129 	SCARG(&ap, tv) = sgtvp = stackgap_alloc(&sg, sizeof(struct timeval));
    130 	SCARG(&ap, tzp) = NULL;
    131 
    132 	error = copyout(&tv, sgtvp, sizeof(struct timeval));
    133 	if (error)
    134 		return error;
    135 
    136 	return sys_settimeofday(p, &ap, retval);
    137 }
    138 
    139 int
    140 sunos_sys_wait4(p, v, retval)
    141 	struct proc *p;
    142 	void *v;
    143 	register_t *retval;
    144 {
    145 	struct sunos_sys_wait4_args *uap = v;
    146 	if (SCARG(uap, pid) == 0)
    147 		SCARG(uap, pid) = WAIT_ANY;
    148 	return (sys_wait4(p, uap, retval));
    149 }
    150 
    151 int
    152 sunos_sys_creat(p, v, retval)
    153 	struct proc *p;
    154 	void *v;
    155 	register_t *retval;
    156 {
    157 	struct sunos_sys_creat_args *uap = v;
    158 	struct sys_open_args ouap;
    159 
    160 	caddr_t sg = stackgap_init(p->p_emul);
    161 	SUNOS_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    162 
    163 	SCARG(&ouap, path) = SCARG(uap, path);
    164 	SCARG(&ouap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
    165 	SCARG(&ouap, mode) = SCARG(uap, mode);
    166 
    167 	return (sys_open(p, &ouap, retval));
    168 }
    169 
    170 int
    171 sunos_sys_access(p, v, retval)
    172 	struct proc *p;
    173 	void *v;
    174 	register_t *retval;
    175 {
    176 	struct sunos_sys_access_args *uap = v;
    177 	caddr_t sg = stackgap_init(p->p_emul);
    178 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    179 
    180 	return (sys_access(p, uap, retval));
    181 }
    182 
    183 int
    184 sunos_sys_stat(p, v, retval)
    185 	struct proc *p;
    186 	void *v;
    187 	register_t *retval;
    188 {
    189 	struct sunos_sys_stat_args *uap = v;
    190 	caddr_t sg = stackgap_init(p->p_emul);
    191 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    192 
    193 	return (compat_43_sys_stat(p, uap, retval));
    194 }
    195 
    196 int
    197 sunos_sys_lstat(p, v, retval)
    198 	struct proc *p;
    199 	void *v;
    200 	register_t *retval;
    201 {
    202 	struct sunos_sys_lstat_args *uap = v;
    203 	caddr_t sg = stackgap_init(p->p_emul);
    204 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    205 
    206 	return (compat_43_sys_lstat(p, uap, retval));
    207 }
    208 
    209 int
    210 sunos_sys_execv(p, v, retval)
    211 	struct proc *p;
    212 	void *v;
    213 	register_t *retval;
    214 {
    215 	struct sunos_sys_execv_args /* {
    216 		syscallarg(const char *) path;
    217 		syscallarg(char **) argv;
    218 	} */ *uap = v;
    219 	struct sys_execve_args ap;
    220 	caddr_t sg;
    221 
    222 	sg = stackgap_init(p->p_emul);
    223 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    224 
    225 	SCARG(&ap, path) = SCARG(uap, path);
    226 	SCARG(&ap, argp) = SCARG(uap, argp);
    227 	SCARG(&ap, envp) = NULL;
    228 
    229 	return (sys_execve(p, &ap, retval));
    230 }
    231 
    232 int
    233 sunos_sys_execve(p, v, retval)
    234 	struct proc *p;
    235 	void *v;
    236 	register_t *retval;
    237 {
    238 	struct sunos_sys_execve_args /* {
    239 		syscallarg(const char *) path;
    240 		syscallarg(char **) argv;
    241 		syscallarg(char **) envp;
    242 	} */ *uap = v;
    243 	struct sys_execve_args ap;
    244 	caddr_t sg;
    245 
    246 	sg = stackgap_init(p->p_emul);
    247 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    248 
    249 	SCARG(&ap, path) = SCARG(uap, path);
    250 	SCARG(&ap, argp) = SCARG(uap, argp);
    251 	SCARG(&ap, envp) = SCARG(uap, envp);
    252 
    253 	return (sys_execve(p, &ap, retval));
    254 }
    255 
    256 int
    257 sunos_sys_omsync(p, v, retval)
    258 	struct proc *p;
    259 	void *v;
    260 	register_t *retval;
    261 {
    262 	struct sunos_sys_omsync_args *uap = v;
    263 	struct sys___msync13_args ouap;
    264 
    265 	SCARG(&ouap, addr) = SCARG(uap, addr);
    266 	SCARG(&ouap, len) = SCARG(uap, len);
    267 	SCARG(&ouap, flags) = SCARG(uap, flags);
    268 
    269 	return (sys___msync13(p, &ouap, retval));
    270 }
    271 
    272 int
    273 sunos_sys_unmount(p, v, retval)
    274 	struct proc *p;
    275 	void *v;
    276 	register_t *retval;
    277 {
    278 	struct sunos_sys_unmount_args *uap = v;
    279 	struct sys_unmount_args ouap;
    280 
    281 	SCARG(&ouap, path) = SCARG(uap, path);
    282 	SCARG(&ouap, flags) = 0;
    283 
    284 	return (sys_unmount(p, &ouap, retval));
    285 }
    286 
    287 /*
    288  * Conversion table for SunOS NFS mount flags.
    289  */
    290 static struct {
    291 	int	sun_flg;
    292 	int	bsd_flg;
    293 } sunnfs_flgtab[] = {
    294 	{ SUNNFS_SOFT,		NFSMNT_SOFT },
    295 	{ SUNNFS_WSIZE,		NFSMNT_WSIZE },
    296 	{ SUNNFS_RSIZE,		NFSMNT_RSIZE },
    297 	{ SUNNFS_TIMEO,		NFSMNT_TIMEO },
    298 	{ SUNNFS_RETRANS,	NFSMNT_RETRANS },
    299 	{ SUNNFS_HOSTNAME,	0 },			/* Ignored */
    300 	{ SUNNFS_INT,		NFSMNT_INT },
    301 	{ SUNNFS_NOAC,		0 },			/* Ignored */
    302 	{ SUNNFS_ACREGMIN,	0 },			/* Ignored */
    303 	{ SUNNFS_ACREGMAX,	0 },			/* Ignored */
    304 	{ SUNNFS_ACDIRMIN,	0 },			/* Ignored */
    305 	{ SUNNFS_ACDIRMAX,	0 },			/* Ignored */
    306 	{ SUNNFS_SECURE,	0 },			/* Ignored */
    307 	{ SUNNFS_NOCTO,		0 },			/* Ignored */
    308 	{ SUNNFS_POSIX,		0 }			/* Ignored */
    309 };
    310 
    311 int
    312 sunos_sys_mount(p, v, retval)
    313 	struct proc *p;
    314 	void *v;
    315 	register_t *retval;
    316 {
    317 	struct sunos_sys_mount_args *uap = v;
    318 	int oflags = SCARG(uap, flags), nflags, error;
    319 	char fsname[MFSNAMELEN];
    320 	caddr_t sg = stackgap_init(p->p_emul);
    321 
    322 	if (oflags & (SUNM_NOSUB | SUNM_SYS5))
    323 		return (EINVAL);
    324 	if ((oflags & SUNM_NEWTYPE) == 0)
    325 		return (EINVAL);
    326 	nflags = 0;
    327 	if (oflags & SUNM_RDONLY)
    328 		nflags |= MNT_RDONLY;
    329 	if (oflags & SUNM_NOSUID)
    330 		nflags |= MNT_NOSUID;
    331 	if (oflags & SUNM_REMOUNT)
    332 		nflags |= MNT_UPDATE;
    333 	SCARG(uap, flags) = nflags;
    334 
    335 	error = copyinstr((caddr_t)SCARG(uap, type), fsname,
    336 	    sizeof fsname, (size_t *)0);
    337 	if (error)
    338 		return (error);
    339 
    340 	if (strncmp(fsname, "4.2", sizeof fsname) == 0) {
    341 		SCARG(uap, type) = stackgap_alloc(&sg, sizeof("ffs"));
    342 		error = copyout("ffs", SCARG(uap, type), sizeof("ffs"));
    343 		if (error)
    344 			return (error);
    345 	} else if (strncmp(fsname, "nfs", sizeof fsname) == 0) {
    346 		struct sunos_nfs_args sna;
    347 		struct sockaddr_in sain;
    348 		struct nfs_args na;
    349 		struct sockaddr sa;
    350 		int n;
    351 
    352 		error = copyin(SCARG(uap, data), &sna, sizeof sna);
    353 		if (error)
    354 			return (error);
    355 		error = copyin(sna.addr, &sain, sizeof sain);
    356 		if (error)
    357 			return (error);
    358 		memcpy(&sa, &sain, sizeof sa);
    359 		sa.sa_len = sizeof(sain);
    360 		SCARG(uap, data) = stackgap_alloc(&sg, sizeof(na));
    361 		na.version = NFS_ARGSVERSION;
    362 		na.addr = stackgap_alloc(&sg, sizeof(struct sockaddr));
    363 		na.addrlen = sizeof(struct sockaddr);
    364 		na.sotype = SOCK_DGRAM;
    365 		na.proto = IPPROTO_UDP;
    366 		na.fh = (void *)sna.fh;
    367 		na.fhsize = NFSX_V2FH;
    368 		na.flags = 0;
    369 		n = sizeof(sunnfs_flgtab) / sizeof(sunnfs_flgtab[0]);
    370 		while (--n >= 0)
    371 			if (sna.flags & sunnfs_flgtab[n].sun_flg)
    372 				na.flags |= sunnfs_flgtab[n].bsd_flg;
    373 		na.wsize = sna.wsize;
    374 		na.rsize = sna.rsize;
    375 		if (na.flags & NFSMNT_RSIZE) {
    376 			na.flags |= NFSMNT_READDIRSIZE;
    377 			na.readdirsize = na.rsize;
    378 		}
    379 		na.timeo = sna.timeo;
    380 		na.retrans = sna.retrans;
    381 		na.hostname = sna.hostname;
    382 
    383 		error = copyout(&sa, na.addr, sizeof sa);
    384 		if (error)
    385 			return (error);
    386 		error = copyout(&na, SCARG(uap, data), sizeof na);
    387 		if (error)
    388 			return (error);
    389 	}
    390 	return (sys_mount(p, (struct sys_mount_args *)uap, retval));
    391 }
    392 
    393 #if defined(NFS)
    394 int
    395 async_daemon(p, v, retval)
    396 	struct proc *p;
    397 	void *v;
    398 	register_t *retval;
    399 {
    400 	struct sys_nfssvc_args ouap;
    401 
    402 	SCARG(&ouap, flag) = NFSSVC_BIOD;
    403 	SCARG(&ouap, argp) = NULL;
    404 
    405 	return (sys_nfssvc(p, &ouap, retval));
    406 }
    407 #endif /* NFS */
    408 
    409 void	native_to_sunos_sigset __P((const sigset_t *, int *));
    410 void	sunos_to_native_sigset __P((const int, sigset_t *));
    411 
    412 __inline__ void
    413 native_to_sunos_sigset(ss, mask)
    414 	const sigset_t *ss;
    415 	int *mask;
    416 {
    417 	*mask = ss->__bits[0];
    418 }
    419 
    420 __inline__ void
    421 sunos_to_native_sigset(mask, ss)
    422 	const int mask;
    423 	sigset_t *ss;
    424 {
    425 
    426 	ss->__bits[0] = mask;
    427 	ss->__bits[1] = 0;
    428 	ss->__bits[2] = 0;
    429 	ss->__bits[3] = 0;
    430 }
    431 
    432 int
    433 sunos_sys_sigpending(p, v, retval)
    434 	struct proc *p;
    435 	void *v;
    436 	register_t *retval;
    437 {
    438 	struct sunos_sys_sigpending_args *uap = v;
    439 	sigset_t ss;
    440 	int mask;
    441 
    442 	sigpending1(p, &ss);
    443 	native_to_sunos_sigset(&ss, &mask);
    444 
    445 	return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
    446 }
    447 
    448 int
    449 sunos_sys_sigsuspend(p, v, retval)
    450 	register struct proc *p;
    451 	void *v;
    452 	register_t *retval;
    453 {
    454 	struct sunos_sys_sigsuspend_args /* {
    455 		syscallarg(int) mask;
    456 	} */ *uap = v;
    457 	int mask;
    458 	sigset_t ss;
    459 
    460 	mask = SCARG(uap, mask);
    461 	sunos_to_native_sigset(mask, &ss);
    462 	return (sigsuspend1(p, &ss));
    463 }
    464 
    465 /*
    466  * Read Sun-style directory entries.  We suck them into kernel space so
    467  * that they can be massaged before being copied out to user code.  Like
    468  * SunOS, we squish out `empty' entries.
    469  *
    470  * This is quite ugly, but what do you expect from compatibility code?
    471  */
    472 int
    473 sunos_sys_getdents(p, v, retval)
    474 	struct proc *p;
    475 	void *v;
    476 	register_t *retval;
    477 {
    478 	struct sunos_sys_getdents_args *uap = v;
    479 	struct dirent *bdp;
    480 	struct vnode *vp;
    481 	caddr_t inp, buf;	/* BSD-format */
    482 	int len, reclen;	/* BSD-format */
    483 	caddr_t outp;		/* Sun-format */
    484 	int resid, sunos_reclen;/* Sun-format */
    485 	struct file *fp;
    486 	struct uio auio;
    487 	struct iovec aiov;
    488 	struct sunos_dirent idb;
    489 	off_t off;			/* true file offset */
    490 	int buflen, error, eofflag;
    491 	off_t *cookiebuf, *cookie;
    492 	int ncookies;
    493 
    494 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
    495 		return (error);
    496 
    497 	if ((fp->f_flag & FREAD) == 0)
    498 		return (EBADF);
    499 
    500 	vp = (struct vnode *)fp->f_data;
    501 	if (vp->v_type != VDIR)
    502 		return (EINVAL);
    503 
    504 	buflen = min(MAXBSIZE, SCARG(uap, nbytes));
    505 	buf = malloc(buflen, M_TEMP, M_WAITOK);
    506 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    507 	off = fp->f_offset;
    508 again:
    509 	aiov.iov_base = buf;
    510 	aiov.iov_len = buflen;
    511 	auio.uio_iov = &aiov;
    512 	auio.uio_iovcnt = 1;
    513 	auio.uio_rw = UIO_READ;
    514 	auio.uio_segflg = UIO_SYSSPACE;
    515 	auio.uio_procp = p;
    516 	auio.uio_resid = buflen;
    517 	auio.uio_offset = off;
    518 	/*
    519 	 * First we read into the malloc'ed buffer, then
    520 	 * we massage it into user space, one record at a time.
    521 	 */
    522 	error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
    523 	    &ncookies);
    524 	if (error)
    525 		goto out;
    526 
    527 	inp = buf;
    528 	outp = SCARG(uap, buf);
    529 	resid = SCARG(uap, nbytes);
    530 	if ((len = buflen - auio.uio_resid) == 0)
    531 		goto eof;
    532 
    533 	for (cookie = cookiebuf; len > 0; len -= reclen) {
    534 		bdp = (struct dirent *)inp;
    535 		reclen = bdp->d_reclen;
    536 		if (reclen & 3)
    537 			panic("sunos_getdents");
    538 		if ((*cookie >> 32) != 0) {
    539 			compat_offseterr(vp, "sunos_getdents");
    540 			error = EINVAL;
    541 			goto out;
    542 		}
    543 		if (bdp->d_fileno == 0) {
    544 			inp += reclen;	/* it is a hole; squish it out */
    545 			off = *cookie++;
    546 			continue;
    547 		}
    548 		sunos_reclen = SUNOS_RECLEN(&idb, bdp->d_namlen);
    549 		if (reclen > len || resid < sunos_reclen) {
    550 			/* entry too big for buffer, so just stop */
    551 			outp++;
    552 			break;
    553 		}
    554 		off = *cookie++;	/* each entry points to next */
    555 		/*
    556 		 * Massage in place to make a Sun-shaped dirent (otherwise
    557 		 * we have to worry about touching user memory outside of
    558 		 * the copyout() call).
    559 		 */
    560 		idb.d_fileno = bdp->d_fileno;
    561 		idb.d_off = off;
    562 		idb.d_reclen = sunos_reclen;
    563 		idb.d_namlen = bdp->d_namlen;
    564 		strcpy(idb.d_name, bdp->d_name);
    565 		if ((error = copyout((caddr_t)&idb, outp, sunos_reclen)) != 0)
    566 			goto out;
    567 		/* advance past this real entry */
    568 		inp += reclen;
    569 		/* advance output past Sun-shaped entry */
    570 		outp += sunos_reclen;
    571 		resid -= sunos_reclen;
    572 	}
    573 
    574 	/* if we squished out the whole block, try again */
    575 	if (outp == SCARG(uap, buf))
    576 		goto again;
    577 	fp->f_offset = off;		/* update the vnode offset */
    578 
    579 eof:
    580 	*retval = SCARG(uap, nbytes) - resid;
    581 out:
    582 	VOP_UNLOCK(vp, 0);
    583 	free(cookiebuf, M_TEMP);
    584 	free(buf, M_TEMP);
    585 	return (error);
    586 }
    587 
    588 #define	SUNOS__MAP_NEW	0x80000000	/* if not, old mmap & cannot handle */
    589 
    590 int
    591 sunos_sys_mmap(p, v, retval)
    592 	register struct proc *p;
    593 	void *v;
    594 	register_t *retval;
    595 {
    596 	register struct sunos_sys_mmap_args *uap = v;
    597 	struct sys_mmap_args ouap;
    598 	register struct filedesc *fdp;
    599 	register struct file *fp;
    600 	register struct vnode *vp;
    601 
    602 	/*
    603 	 * Verify the arguments.
    604 	 */
    605 	if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
    606 		return (EINVAL);			/* XXX still needed? */
    607 
    608 	if ((SCARG(uap, flags) & SUNOS__MAP_NEW) == 0)
    609 		return (EINVAL);
    610 
    611 	SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUNOS__MAP_NEW;
    612 	SCARG(&ouap, addr) = SCARG(uap, addr);
    613 
    614 	if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 &&
    615 	    SCARG(&ouap, addr) != 0 &&
    616 	    SCARG(&ouap, addr) < (void *)round_page(p->p_vmspace->vm_daddr+MAXDSIZ))
    617 		SCARG(&ouap, addr) = (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ);
    618 
    619 	SCARG(&ouap, len) = SCARG(uap, len);
    620 	SCARG(&ouap, prot) = SCARG(uap, prot);
    621 	SCARG(&ouap, fd) = SCARG(uap, fd);
    622 	SCARG(&ouap, pos) = SCARG(uap, pos);
    623 
    624 	/*
    625 	 * Special case: if fd refers to /dev/zero, map as MAP_ANON.  (XXX)
    626 	 */
    627 	fdp = p->p_fd;
    628 	if ((unsigned)SCARG(&ouap, fd) < fdp->fd_nfiles &&		/*XXX*/
    629 	    (fp = fdp->fd_ofiles[SCARG(&ouap, fd)]) != NULL &&		/*XXX*/
    630 	    fp->f_type == DTYPE_VNODE &&				/*XXX*/
    631 	    (vp = (struct vnode *)fp->f_data)->v_type == VCHR &&	/*XXX*/
    632 	    iszerodev(vp->v_rdev)) {					/*XXX*/
    633 		SCARG(&ouap, flags) |= MAP_ANON;
    634 		SCARG(&ouap, fd) = -1;
    635 	}
    636 
    637 	return (sys_mmap(p, &ouap, retval));
    638 }
    639 
    640 #define	MC_SYNC		1
    641 #define	MC_LOCK		2
    642 #define	MC_UNLOCK	3
    643 #define	MC_ADVISE	4
    644 #define	MC_LOCKAS	5
    645 #define	MC_UNLOCKAS	6
    646 
    647 int
    648 sunos_sys_mctl(p, v, retval)
    649 	register struct proc *p;
    650 	void *v;
    651 	register_t *retval;
    652 {
    653 	register struct sunos_sys_mctl_args *uap = v;
    654 
    655 	switch (SCARG(uap, func)) {
    656 	case MC_ADVISE:		/* ignore for now */
    657 		return (0);
    658 	case MC_SYNC:		/* translate to msync */
    659 		return (sys___msync13(p, uap, retval));
    660 	default:
    661 		return (EINVAL);
    662 	}
    663 }
    664 
    665 int
    666 sunos_sys_setsockopt(p, v, retval)
    667 	struct proc *p;
    668 	void *v;
    669 	register_t *retval;
    670 {
    671 	register struct sunos_sys_setsockopt_args *uap = v;
    672 	struct file *fp;
    673 	struct mbuf *m = NULL;
    674 	int error;
    675 
    676 	if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
    677 		return (error);
    678 #define	SO_DONTLINGER (~SO_LINGER)
    679 	if (SCARG(uap, name) == SO_DONTLINGER) {
    680 		m = m_get(M_WAIT, MT_SOOPTS);
    681 		mtod(m, struct linger *)->l_onoff = 0;
    682 		m->m_len = sizeof(struct linger);
    683 		return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    684 		    SO_LINGER, m));
    685 	}
    686 	if (SCARG(uap, level) == IPPROTO_IP) {
    687 #define		SUNOS_IP_MULTICAST_IF		2
    688 #define		SUNOS_IP_MULTICAST_TTL		3
    689 #define		SUNOS_IP_MULTICAST_LOOP		4
    690 #define		SUNOS_IP_ADD_MEMBERSHIP		5
    691 #define		SUNOS_IP_DROP_MEMBERSHIP	6
    692 		static int ipoptxlat[] = {
    693 			IP_MULTICAST_IF,
    694 			IP_MULTICAST_TTL,
    695 			IP_MULTICAST_LOOP,
    696 			IP_ADD_MEMBERSHIP,
    697 			IP_DROP_MEMBERSHIP
    698 		};
    699 		if (SCARG(uap, name) >= SUNOS_IP_MULTICAST_IF &&
    700 		    SCARG(uap, name) <= SUNOS_IP_DROP_MEMBERSHIP) {
    701 			SCARG(uap, name) =
    702 			    ipoptxlat[SCARG(uap, name) - SUNOS_IP_MULTICAST_IF];
    703 		}
    704 	}
    705 	if (SCARG(uap, valsize) > MLEN)
    706 		return (EINVAL);
    707 	if (SCARG(uap, val)) {
    708 		m = m_get(M_WAIT, MT_SOOPTS);
    709 		error = copyin(SCARG(uap, val), mtod(m, caddr_t),
    710 		    (u_int)SCARG(uap, valsize));
    711 		if (error) {
    712 			(void) m_free(m);
    713 			return (error);
    714 		}
    715 		m->m_len = SCARG(uap, valsize);
    716 	}
    717 	return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    718 	    SCARG(uap, name), m));
    719 }
    720 
    721 int
    722 sunos_sys_fchroot(p, v, retval)
    723 	register struct proc *p;
    724 	void *v;
    725 	register_t *retval;
    726 {
    727 	register struct sunos_sys_fchroot_args *uap = v;
    728 	register struct filedesc *fdp = p->p_fd;
    729 	register struct vnode *vp;
    730 	struct file *fp;
    731 	int error;
    732 
    733 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
    734 		return (error);
    735 	if ((error = getvnode(fdp, SCARG(uap, fd), &fp)) != 0)
    736 		return (error);
    737 	vp = (struct vnode *)fp->f_data;
    738 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    739 	if (vp->v_type != VDIR)
    740 		error = ENOTDIR;
    741 	else
    742 		error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p);
    743 	VOP_UNLOCK(vp, 0);
    744 	if (error)
    745 		return (error);
    746 	VREF(vp);
    747 	if (fdp->fd_rdir != NULL)
    748 		vrele(fdp->fd_rdir);
    749 	fdp->fd_rdir = vp;
    750 	return (0);
    751 }
    752 
    753 /*
    754  * XXX: This needs cleaning up.
    755  */
    756 int
    757 sunos_sys_auditsys(p, v, retval)
    758 	struct proc *p;
    759 	void *v;
    760 	register_t *retval;
    761 {
    762 	return 0;
    763 }
    764 
    765 int
    766 sunos_sys_uname(p, v, retval)
    767 	struct proc *p;
    768 	void *v;
    769 	register_t *retval;
    770 {
    771 	struct sunos_sys_uname_args *uap = v;
    772 	struct sunos_utsname sut;
    773 	extern char ostype[], machine[], osrelease[];
    774 
    775 	memset(&sut, 0, sizeof(sut));
    776 
    777 	memcpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
    778 	memcpy(sut.nodename, hostname, sizeof(sut.nodename));
    779 	sut.nodename[sizeof(sut.nodename)-1] = '\0';
    780 	memcpy(sut.release, osrelease, sizeof(sut.release) - 1);
    781 	memcpy(sut.version, "1", sizeof(sut.version) - 1);
    782 	memcpy(sut.machine, machine, sizeof(sut.machine) - 1);
    783 
    784 	return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
    785 	    sizeof(struct sunos_utsname));
    786 }
    787 
    788 int
    789 sunos_sys_setpgrp(p, v, retval)
    790 	struct proc *p;
    791 	void *v;
    792 	register_t *retval;
    793 {
    794 	struct sunos_sys_setpgrp_args *uap = v;
    795 
    796 	/*
    797 	 * difference to our setpgid call is to include backwards
    798 	 * compatibility to pre-setsid() binaries. Do setsid()
    799 	 * instead of setpgid() in those cases where the process
    800 	 * tries to create a new session the old way.
    801 	 */
    802 	if (!SCARG(uap, pgid) &&
    803 	    (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
    804 		return sys_setsid(p, uap, retval);
    805 	else
    806 		return sys_setpgid(p, uap, retval);
    807 }
    808 
    809 int
    810 sunos_sys_open(p, v, retval)
    811 	struct proc *p;
    812 	void *v;
    813 	register_t *retval;
    814 {
    815 	struct sunos_sys_open_args *uap = v;
    816 	int l, r;
    817 	int noctty;
    818 	int ret;
    819 
    820 	caddr_t sg = stackgap_init(p->p_emul);
    821 
    822 	/* convert mode into NetBSD mode */
    823 	l = SCARG(uap, flags);
    824 	noctty = l & 0x8000;
    825 	r =	(l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
    826 	r |=	((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
    827 	r |=	((l & 0x0080) ? O_SHLOCK : 0);
    828 	r |=	((l & 0x0100) ? O_EXLOCK : 0);
    829 	r |=	((l & 0x2000) ? O_FSYNC : 0);
    830 
    831 	if (r & O_CREAT)
    832 		SUNOS_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    833 	else
    834 		SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    835 
    836 	SCARG(uap, flags) = r;
    837 	ret = sys_open(p, (struct sys_open_args *)uap, retval);
    838 
    839 	if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
    840 		struct filedesc *fdp = p->p_fd;
    841 		struct file *fp = fdp->fd_ofiles[*retval];
    842 
    843 		/* ignore any error, just give it a try */
    844 		if (fp->f_type == DTYPE_VNODE)
    845 			(fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
    846 	}
    847 	return ret;
    848 }
    849 
    850 #if defined (NFSSERVER)
    851 int
    852 sunos_sys_nfssvc(p, v, retval)
    853 	struct proc *p;
    854 	void *v;
    855 	register_t *retval;
    856 {
    857 #if 0
    858 	struct sunos_sys_nfssvc_args *uap = v;
    859 	struct emul *e = p->p_emul;
    860 	struct sys_nfssvc_args outuap;
    861 	struct sockaddr sa;
    862 	int error;
    863 	caddr_t sg = stackgap_init(p->p_emul);
    864 
    865 	memset(&outuap, 0, sizeof outuap);
    866 	SCARG(&outuap, fd) = SCARG(uap, fd);
    867 	SCARG(&outuap, mskval) = stackgap_alloc(&sg, sizeof(sa));
    868 	SCARG(&outuap, msklen) = sizeof(sa);
    869 	SCARG(&outuap, mtchval) = stackgap_alloc(&sg, sizeof(sa));
    870 	SCARG(&outuap, mtchlen) = sizeof(sa);
    871 
    872 	memset(&sa, 0, sizeof sa);
    873 	if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
    874 		return (error);
    875 	if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
    876 		return (error);
    877 
    878 	return nfssvc(p, &outuap, retval);
    879 #else
    880 	return (ENOSYS);
    881 #endif
    882 }
    883 #endif /* NFSSERVER */
    884 
    885 int
    886 sunos_sys_ustat(p, v, retval)
    887 	struct proc *p;
    888 	void *v;
    889 	register_t *retval;
    890 {
    891 	struct sunos_sys_ustat_args *uap = v;
    892 	struct sunos_ustat us;
    893 	int error;
    894 
    895 	memset(&us, 0, sizeof us);
    896 
    897 	/*
    898 	 * XXX: should set f_tfree and f_tinode at least
    899 	 * How do we translate dev -> fstat? (and then to sunos_ustat)
    900 	 */
    901 
    902 	if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
    903 		return (error);
    904 	return 0;
    905 }
    906 
    907 int
    908 sunos_sys_quotactl(p, v, retval)
    909 	struct proc *p;
    910 	void *v;
    911 	register_t *retval;
    912 {
    913 
    914 	return EINVAL;
    915 }
    916 
    917 int
    918 sunos_sys_vhangup(p, v, retval)
    919 	struct proc *p;
    920 	void *v;
    921 	register_t *retval;
    922 {
    923 	struct session *sp = p->p_session;
    924 
    925 	if (sp->s_ttyvp == 0)
    926 		return 0;
    927 
    928 	if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp)
    929 		pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
    930 
    931 	(void) ttywait(sp->s_ttyp);
    932 	if (sp->s_ttyvp)
    933 		VOP_REVOKE(sp->s_ttyvp, REVOKEALL);
    934 	if (sp->s_ttyvp)
    935 		vrele(sp->s_ttyvp);
    936 	sp->s_ttyvp = NULL;
    937 
    938 	return 0;
    939 }
    940 
    941 static int
    942 sunstatfs(sp, buf)
    943 	struct statfs *sp;
    944 	caddr_t buf;
    945 {
    946 	struct sunos_statfs ssfs;
    947 
    948 	memset(&ssfs, 0, sizeof ssfs);
    949 	ssfs.f_type = 0;
    950 	ssfs.f_bsize = sp->f_bsize;
    951 	ssfs.f_blocks = sp->f_blocks;
    952 	ssfs.f_bfree = sp->f_bfree;
    953 	ssfs.f_bavail = sp->f_bavail;
    954 	ssfs.f_files = sp->f_files;
    955 	ssfs.f_ffree = sp->f_ffree;
    956 	ssfs.f_fsid = sp->f_fsid;
    957 	return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
    958 }
    959 
    960 int
    961 sunos_sys_statfs(p, v, retval)
    962 	struct proc *p;
    963 	void *v;
    964 	register_t *retval;
    965 {
    966 	struct sunos_sys_statfs_args *uap = v;
    967 	register struct mount *mp;
    968 	register struct statfs *sp;
    969 	int error;
    970 	struct nameidata nd;
    971 
    972 	caddr_t sg = stackgap_init(p->p_emul);
    973 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    974 
    975 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    976 	if ((error = namei(&nd)) != 0)
    977 		return (error);
    978 	mp = nd.ni_vp->v_mount;
    979 	sp = &mp->mnt_stat;
    980 	vrele(nd.ni_vp);
    981 	if ((error = VFS_STATFS(mp, sp, p)) != 0)
    982 		return (error);
    983 	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
    984 	return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
    985 }
    986 
    987 int
    988 sunos_sys_fstatfs(p, v, retval)
    989 	struct proc *p;
    990 	void *v;
    991 	register_t *retval;
    992 {
    993 	struct sunos_sys_fstatfs_args *uap = v;
    994 	struct file *fp;
    995 	struct mount *mp;
    996 	register struct statfs *sp;
    997 	int error;
    998 
    999 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
   1000 		return (error);
   1001 	mp = ((struct vnode *)fp->f_data)->v_mount;
   1002 	sp = &mp->mnt_stat;
   1003 	if ((error = VFS_STATFS(mp, sp, p)) != 0)
   1004 		return (error);
   1005 	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
   1006 	return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
   1007 }
   1008 
   1009 int
   1010 sunos_sys_exportfs(p, v, retval)
   1011 	struct proc *p;
   1012 	void *v;
   1013 	register_t *retval;
   1014 {
   1015 	/*
   1016 	 * XXX: should perhaps translate into a mount(2)
   1017 	 * with MOUNT_EXPORT?
   1018 	 */
   1019 	return 0;
   1020 }
   1021 
   1022 int
   1023 sunos_sys_mknod(p, v, retval)
   1024 	struct proc *p;
   1025 	void *v;
   1026 	register_t *retval;
   1027 {
   1028 	struct sunos_sys_mknod_args *uap = v;
   1029 
   1030 	caddr_t sg = stackgap_init(p->p_emul);
   1031 	SUNOS_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
   1032 
   1033 	if (S_ISFIFO(SCARG(uap, mode)))
   1034 		return sys_mkfifo(p, uap, retval);
   1035 
   1036 	return sys_mknod(p, (struct sys_mknod_args *)uap, retval);
   1037 }
   1038 
   1039 #define SUNOS_SC_ARG_MAX	1
   1040 #define SUNOS_SC_CHILD_MAX	2
   1041 #define SUNOS_SC_CLK_TCK	3
   1042 #define SUNOS_SC_NGROUPS_MAX	4
   1043 #define SUNOS_SC_OPEN_MAX	5
   1044 #define SUNOS_SC_JOB_CONTROL	6
   1045 #define SUNOS_SC_SAVED_IDS	7
   1046 #define SUNOS_SC_VERSION	8
   1047 
   1048 int
   1049 sunos_sys_sysconf(p, v, retval)
   1050 	struct proc *p;
   1051 	void *v;
   1052 	register_t *retval;
   1053 {
   1054 	struct sunos_sys_sysconf_args *uap = v;
   1055 	extern int maxfiles;
   1056 
   1057 	switch(SCARG(uap, name)) {
   1058 	case SUNOS_SC_ARG_MAX:
   1059 		*retval = ARG_MAX;
   1060 		break;
   1061 	case SUNOS_SC_CHILD_MAX:
   1062 		*retval = maxproc;
   1063 		break;
   1064 	case SUNOS_SC_CLK_TCK:
   1065 		*retval = 60;		/* should this be `hz', ie. 100? */
   1066 		break;
   1067 	case SUNOS_SC_NGROUPS_MAX:
   1068 		*retval = NGROUPS_MAX;
   1069 		break;
   1070 	case SUNOS_SC_OPEN_MAX:
   1071 		*retval = maxfiles;
   1072 		break;
   1073 	case SUNOS_SC_JOB_CONTROL:
   1074 		*retval = 1;
   1075 		break;
   1076 	case SUNOS_SC_SAVED_IDS:
   1077 #ifdef _POSIX_SAVED_IDS
   1078 		*retval = 1;
   1079 #else
   1080 		*retval = 0;
   1081 #endif
   1082 		break;
   1083 	case SUNOS_SC_VERSION:
   1084 		*retval = 198808;
   1085 		break;
   1086 	default:
   1087 		return EINVAL;
   1088 	}
   1089 	return 0;
   1090 }
   1091 
   1092 #define SUNOS_RLIMIT_NOFILE	6	/* Other RLIMIT_* are the same */
   1093 #define SUNOS_RLIM_NLIMITS	7
   1094 
   1095 int
   1096 sunos_sys_getrlimit(p, v, retval)
   1097 	struct proc *p;
   1098 	void *v;
   1099 	register_t *retval;
   1100 {
   1101 	struct sunos_sys_getrlimit_args *uap = v;
   1102 
   1103 	if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
   1104 		return EINVAL;
   1105 
   1106 	if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
   1107 		SCARG(uap, which) = RLIMIT_NOFILE;
   1108 
   1109 	return compat_43_sys_getrlimit(p, uap, retval);
   1110 }
   1111 
   1112 int
   1113 sunos_sys_setrlimit(p, v, retval)
   1114 	struct proc *p;
   1115 	void *v;
   1116 	register_t *retval;
   1117 {
   1118 	struct sunos_sys_getrlimit_args *uap = v;
   1119 
   1120 	if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
   1121 		return EINVAL;
   1122 
   1123 	if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
   1124 		SCARG(uap, which) = RLIMIT_NOFILE;
   1125 
   1126 	return compat_43_sys_setrlimit(p, uap, retval);
   1127 }
   1128 
   1129 /* for the m68k machines */
   1130 #ifndef PT_GETFPREGS
   1131 #define PT_GETFPREGS -1
   1132 #endif
   1133 #ifndef PT_SETFPREGS
   1134 #define PT_SETFPREGS -1
   1135 #endif
   1136 
   1137 static int sreq2breq[] = {
   1138 	PT_TRACE_ME,    PT_READ_I,      PT_READ_D,      -1,
   1139 	PT_WRITE_I,     PT_WRITE_D,     -1,             PT_CONTINUE,
   1140 	PT_KILL,        -1,             PT_ATTACH,      PT_DETACH,
   1141 	PT_GETREGS,     PT_SETREGS,     PT_GETFPREGS,   PT_SETFPREGS
   1142 };
   1143 static int nreqs = sizeof(sreq2breq) / sizeof(sreq2breq[0]);
   1144 
   1145 int
   1146 sunos_sys_ptrace(p, v, retval)
   1147 	struct proc *p;
   1148 	void *v;
   1149 	register_t *retval;
   1150 {
   1151 	struct sunos_sys_ptrace_args *uap = v;
   1152 	struct sys_ptrace_args pa;
   1153 	int req;
   1154 
   1155 	req = SCARG(uap, req);
   1156 
   1157 	if (req < 0 || req >= nreqs)
   1158 		return (EINVAL);
   1159 
   1160 	req = sreq2breq[req];
   1161 	if (req == -1)
   1162 		return (EINVAL);
   1163 
   1164 	SCARG(&pa, req) = req;
   1165 	SCARG(&pa, pid) = (pid_t)SCARG(uap, pid);
   1166 	SCARG(&pa, addr) = (caddr_t)SCARG(uap, addr);
   1167 	SCARG(&pa, data) = SCARG(uap, data);
   1168 
   1169 	return sys_ptrace(p, &pa, retval);
   1170 }
   1171 
   1172 /*
   1173  * SunOS reboot system call (for compatibility).
   1174  * Sun lets you pass in a boot string which the PROM
   1175  * saves and provides to the next boot program.
   1176  */
   1177 
   1178 #define SUNOS_RB_ASKNAME	0x001
   1179 #define SUNOS_RB_SINGLE 	0x002
   1180 #define SUNOS_RB_NOSYNC		0x004
   1181 #define SUNOS_RB_HALT		0x008
   1182 #define SUNOS_RB_DUMP		0x080
   1183 #define	SUNOS_RB_STRING		0x200
   1184 
   1185 static struct sunos_howto_conv {
   1186 	int sun_howto;
   1187 	int bsd_howto;
   1188 } sunos_howto_conv[] = {
   1189 	{ SUNOS_RB_ASKNAME,	RB_ASKNAME },
   1190 	{ SUNOS_RB_SINGLE,	RB_SINGLE },
   1191 	{ SUNOS_RB_NOSYNC,	RB_NOSYNC },
   1192 	{ SUNOS_RB_HALT,	RB_HALT },
   1193 	{ SUNOS_RB_DUMP,	RB_DUMP },
   1194 	{ SUNOS_RB_STRING,	RB_STRING },
   1195 	{ 0x000,		0 },
   1196 };
   1197 
   1198 int
   1199 sunos_sys_reboot(p, v, retval)
   1200 	struct proc *p;
   1201 	void *v;
   1202 	register_t *retval;
   1203 {
   1204 	struct sunos_sys_reboot_args *uap = v;
   1205 	struct sys_reboot_args ua;
   1206 	struct sunos_howto_conv *convp;
   1207 	int error, bsd_howto, sun_howto;
   1208 	char *bootstr;
   1209 
   1210 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
   1211 		return (error);
   1212 
   1213 	/*
   1214 	 * Convert howto bits to BSD format.
   1215 	 */
   1216 	sun_howto = SCARG(uap, howto);
   1217 	bsd_howto = 0;
   1218 	convp = sunos_howto_conv;
   1219 	while (convp->sun_howto) {
   1220 		if (sun_howto & convp->sun_howto)
   1221 			bsd_howto |= convp->bsd_howto;
   1222 		convp++;
   1223 	}
   1224 
   1225 	/*
   1226 	 * Sun RB_STRING (Get user supplied bootstring.)
   1227 	 * If the machine supports passing a string to the
   1228 	 * next booted kernel.
   1229 	 */
   1230 	if (sun_howto & SUNOS_RB_STRING) {
   1231 		char bs[128];
   1232 
   1233 		error = copyinstr(SCARG(uap, bootstr), bs, sizeof(bs), 0);
   1234 
   1235 		if (error)
   1236 			bootstr = NULL;
   1237 		else
   1238 			bootstr = bs;
   1239 	} else
   1240 		bootstr = NULL;
   1241 
   1242 	SCARG(&ua, opt) = bsd_howto;
   1243 	SCARG(&ua, bootstr) = bootstr;
   1244 	sys_reboot(p, &ua, retval);
   1245 	return(0);
   1246 }
   1247 
   1248 /*
   1249  * Generalized interface signal handler, 4.3-compatible.
   1250  */
   1251 /* ARGSUSED */
   1252 int
   1253 sunos_sys_sigvec(p, v, retval)
   1254 	struct proc *p;
   1255 	void *v;
   1256 	register_t *retval;
   1257 {
   1258 	struct sunos_sys_sigvec_args /* {
   1259 		syscallarg(int) signum;
   1260 		syscallarg(struct sigvec *) nsv;
   1261 		syscallarg(struct sigvec *) osv;
   1262 	} */ *uap = v;
   1263 	struct sigvec nsv, osv;
   1264 	struct sigaction nsa, osa;
   1265 	int error;
   1266 /*XXX*/extern	void compat_43_sigvec_to_sigaction
   1267 		__P((const struct sigvec *, struct sigaction *));
   1268 /*XXX*/extern	void compat_43_sigaction_to_sigvec
   1269 		__P((const struct sigaction *, struct sigvec *));
   1270 
   1271 	if (SCARG(uap, nsv)) {
   1272 		error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
   1273 		if (error != 0)
   1274 			return (error);
   1275 
   1276 		/*
   1277 		 * SunOS uses the mask 0x0004 as SV_RESETHAND
   1278 		 * meaning: `reset to SIG_DFL on delivery'.
   1279 		 * We support only the bits in: 0xF
   1280 		 * (those bits are the same as ours)
   1281 		 */
   1282 		if (nsv.sv_flags & ~0xF)
   1283 			return (EINVAL);
   1284 
   1285 		compat_43_sigvec_to_sigaction(&nsv, &nsa);
   1286 	}
   1287 	error = sigaction1(p, SCARG(uap, signum),
   1288 			   SCARG(uap, nsv) ? &nsa : 0,
   1289 			   SCARG(uap, osv) ? &osa : 0);
   1290 	if (error != 0)
   1291 		return (error);
   1292 
   1293 	if (SCARG(uap, osv)) {
   1294 		compat_43_sigaction_to_sigvec(&osa, &osv);
   1295 		error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
   1296 		if (error != 0)
   1297 			return (error);
   1298 	}
   1299 
   1300 	return (0);
   1301 }
   1302