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