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