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