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