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