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