xref: /netbsd-src/sys/compat/sunos/sunos_misc.c (revision 001c68bd94f75ce9270b69227c4199fbf34ee396)
1 /*	$NetBSD: sunos_misc.c,v 1.124 2003/06/29 22:29:44 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 <sys/cdefs.h>
57 __KERNEL_RCSID(0, "$NetBSD: sunos_misc.c,v 1.124 2003/06/29 22:29:44 fvdl Exp $");
58 
59 #if defined(_KERNEL_OPT)
60 #include "opt_nfsserver.h"
61 #include "fs_nfs.h"
62 #endif
63 
64 #include <sys/param.h>
65 #include <sys/systm.h>
66 #include <sys/namei.h>
67 #include <sys/proc.h>
68 #include <sys/dirent.h>
69 #include <sys/file.h>
70 #include <sys/stat.h>
71 #include <sys/filedesc.h>
72 #include <sys/ioctl.h>
73 #include <sys/kernel.h>
74 #include <sys/reboot.h>
75 #include <sys/malloc.h>
76 #include <sys/mbuf.h>
77 #include <sys/mman.h>
78 #include <sys/mount.h>
79 #include <sys/ptrace.h>
80 #include <sys/resource.h>
81 #include <sys/resourcevar.h>
82 #include <sys/signal.h>
83 #include <sys/signalvar.h>
84 #include <sys/socket.h>
85 #include <sys/tty.h>
86 #include <sys/vnode.h>
87 #include <sys/uio.h>
88 #include <sys/wait.h>
89 #include <sys/utsname.h>
90 #include <sys/unistd.h>
91 #include <sys/sa.h>
92 #include <sys/syscallargs.h>
93 #include <sys/conf.h>
94 #include <sys/socketvar.h>
95 #include <sys/exec.h>
96 #include <sys/swap.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 statfs *, 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(p, &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(p, &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(p, &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(p, &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(p, &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(p, &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->l_proc, &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->l_proc, &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_segflg = UIO_SYSSPACE;
531 	auio.uio_procp = p;
532 	auio.uio_resid = buflen;
533 	auio.uio_offset = off;
534 	/*
535 	 * First we read into the malloc'ed buffer, then
536 	 * we massage it into user space, one record at a time.
537 	 */
538 	error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
539 	    &ncookies);
540 	if (error)
541 		goto out;
542 
543 	inp = buf;
544 	outp = SCARG(uap, buf);
545 	resid = SCARG(uap, nbytes);
546 	if ((len = buflen - auio.uio_resid) == 0)
547 		goto eof;
548 
549 	for (cookie = cookiebuf; len > 0; len -= reclen) {
550 		bdp = (struct dirent *)inp;
551 		reclen = bdp->d_reclen;
552 		if (reclen & 3)
553 			panic("sunos_getdents");
554 		if ((*cookie >> 32) != 0) {
555 			compat_offseterr(vp, "sunos_getdents");
556 			error = EINVAL;
557 			goto out;
558 		}
559 		if (bdp->d_fileno == 0) {
560 			inp += reclen;	/* it is a hole; squish it out */
561 			off = *cookie++;
562 			continue;
563 		}
564 		sunos_reclen = SUNOS_RECLEN(&idb, bdp->d_namlen);
565 		if (reclen > len || resid < sunos_reclen) {
566 			/* entry too big for buffer, so just stop */
567 			outp++;
568 			break;
569 		}
570 		off = *cookie++;	/* each entry points to next */
571 		/*
572 		 * Massage in place to make a Sun-shaped dirent (otherwise
573 		 * we have to worry about touching user memory outside of
574 		 * the copyout() call).
575 		 */
576 		idb.d_fileno = bdp->d_fileno;
577 		idb.d_off = off;
578 		idb.d_reclen = sunos_reclen;
579 		idb.d_namlen = bdp->d_namlen;
580 		strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
581 		if ((error = copyout((caddr_t)&idb, outp, sunos_reclen)) != 0)
582 			goto out;
583 		/* advance past this real entry */
584 		inp += reclen;
585 		/* advance output past Sun-shaped entry */
586 		outp += sunos_reclen;
587 		resid -= sunos_reclen;
588 	}
589 
590 	/* if we squished out the whole block, try again */
591 	if (outp == SCARG(uap, buf))
592 		goto again;
593 	fp->f_offset = off;		/* update the vnode offset */
594 
595 eof:
596 	*retval = SCARG(uap, nbytes) - resid;
597 out:
598 	VOP_UNLOCK(vp, 0);
599 	free(cookiebuf, M_TEMP);
600 	free(buf, M_TEMP);
601  out1:
602 	FILE_UNUSE(fp, p);
603 	return (error);
604 }
605 
606 #define	SUNOS__MAP_NEW	0x80000000	/* if not, old mmap & cannot handle */
607 
608 int
609 sunos_sys_mmap(l, v, retval)
610 	struct lwp *l;
611 	void *v;
612 	register_t *retval;
613 {
614 	struct sunos_sys_mmap_args *uap = v;
615 	struct sys_mmap_args ouap;
616 
617 	/*
618 	 * Verify the arguments.
619 	 */
620 	if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
621 		return (EINVAL);			/* XXX still needed? */
622 
623 	if ((SCARG(uap, flags) & SUNOS__MAP_NEW) == 0)
624 		return (EINVAL);
625 
626 	SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUNOS__MAP_NEW;
627 	SCARG(&ouap, addr) = SCARG(uap, addr);
628 	SCARG(&ouap, len) = SCARG(uap, len);
629 	SCARG(&ouap, prot) = SCARG(uap, prot);
630 	SCARG(&ouap, fd) = SCARG(uap, fd);
631 	SCARG(&ouap, pos) = SCARG(uap, pos);
632 
633 	return (sys_mmap(l, &ouap, retval));
634 }
635 
636 #define	MC_SYNC		1
637 #define	MC_LOCK		2
638 #define	MC_UNLOCK	3
639 #define	MC_ADVISE	4
640 #define	MC_LOCKAS	5
641 #define	MC_UNLOCKAS	6
642 
643 int
644 sunos_sys_mctl(l, v, retval)
645 	struct lwp *l;
646 	void *v;
647 	register_t *retval;
648 {
649 	struct sunos_sys_mctl_args *uap = v;
650 
651 	switch (SCARG(uap, func)) {
652 	case MC_ADVISE:		/* ignore for now */
653 		return (0);
654 	case MC_SYNC:		/* translate to msync */
655 		return (sys___msync13(l, uap, retval));
656 	default:
657 		return (EINVAL);
658 	}
659 }
660 
661 int
662 sunos_sys_setsockopt(l, v, retval)
663 	struct lwp *l;
664 	void *v;
665 	register_t *retval;
666 {
667 	struct sunos_sys_setsockopt_args *uap = v;
668 	struct proc *p = l->l_proc;
669 	struct file *fp;
670 	struct mbuf *m = NULL;
671 	int error;
672 
673 	/* getsock() will use the descriptor for us */
674 	if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
675 		return (error);
676 #define	SO_DONTLINGER (~SO_LINGER)
677 	if (SCARG(uap, name) == SO_DONTLINGER) {
678 		m = m_get(M_WAIT, MT_SOOPTS);
679 		mtod(m, struct linger *)->l_onoff = 0;
680 		m->m_len = sizeof(struct linger);
681 		error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
682 		    SO_LINGER, m);
683 		goto out;
684 	}
685 	if (SCARG(uap, level) == IPPROTO_IP) {
686 #define		SUNOS_IP_MULTICAST_IF		2
687 #define		SUNOS_IP_MULTICAST_TTL		3
688 #define		SUNOS_IP_MULTICAST_LOOP		4
689 #define		SUNOS_IP_ADD_MEMBERSHIP		5
690 #define		SUNOS_IP_DROP_MEMBERSHIP	6
691 		static int ipoptxlat[] = {
692 			IP_MULTICAST_IF,
693 			IP_MULTICAST_TTL,
694 			IP_MULTICAST_LOOP,
695 			IP_ADD_MEMBERSHIP,
696 			IP_DROP_MEMBERSHIP
697 		};
698 		if (SCARG(uap, name) >= SUNOS_IP_MULTICAST_IF &&
699 		    SCARG(uap, name) <= SUNOS_IP_DROP_MEMBERSHIP) {
700 			SCARG(uap, name) =
701 			    ipoptxlat[SCARG(uap, name) - SUNOS_IP_MULTICAST_IF];
702 		}
703 	}
704 	if (SCARG(uap, valsize) > MLEN) {
705 		error = EINVAL;
706 		goto out;
707 	}
708 	if (SCARG(uap, val)) {
709 		m = m_get(M_WAIT, MT_SOOPTS);
710 		error = copyin(SCARG(uap, val), mtod(m, caddr_t),
711 		    (u_int)SCARG(uap, valsize));
712 		if (error) {
713 			(void) m_free(m);
714 			goto out;
715 		}
716 		m->m_len = SCARG(uap, valsize);
717 	}
718 	error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
719 	    SCARG(uap, name), m);
720  out:
721 	FILE_UNUSE(fp, p);
722 	return (error);
723 }
724 
725 static __inline__ int sunos_sys_socket_common(struct lwp *, register_t *,
726 					      int type);
727 static __inline__ int
728 sunos_sys_socket_common(l, retval, type)
729 	struct lwp *l;
730 	register_t *retval;
731 	int type;
732 {
733 	struct socket *so;
734 	struct file *fp;
735 	int error, fd;
736 
737 	/* getsock() will use the descriptor for us */
738 	fd = (int)*retval;
739 	if ((error = getsock(l->l_proc->p_fd, fd, &fp)) == 0) {
740 		so = (struct socket *)fp->f_data;
741 		if (type == SOCK_DGRAM)
742 			so->so_options |= SO_BROADCAST;
743 	}
744 	FILE_UNUSE(fp, l->l_proc);
745 	return (error);
746 }
747 
748 int
749 sunos_sys_socket(l, v, retval)
750 	struct lwp *l;
751 	void *v;
752 	register_t *retval;
753 {
754 	struct sunos_sys_socket_args /* {
755 		syscallarg(int) domain;
756 		syscallarg(int) type;
757 		syscallarg(int) protocol;
758 	} */ *uap = v;
759 	int error;
760 
761 	error = sys_socket(l, v, retval);
762 	if (error)
763 		return (error);
764 	return sunos_sys_socket_common(l, retval, SCARG(uap, type));
765 }
766 
767 int
768 sunos_sys_socketpair(l, v, retval)
769 	struct lwp *l;
770 	void *v;
771 	register_t *retval;
772 {
773 	struct sunos_sys_socketpair_args /* {
774 		syscallarg(int) domain;
775 		syscallarg(int) type;
776 		syscallarg(int) protocol;
777 		syscallarg(int *) rsv;
778 	} */ *uap = v;
779 	int error;
780 
781 	error = sys_socketpair(l, v, retval);
782 	if (error)
783 		return (error);
784 	return sunos_sys_socket_common(l, retval, SCARG(uap, type));
785 }
786 
787 /*
788  * XXX: This needs cleaning up.
789  */
790 int
791 sunos_sys_auditsys(l, v, retval)
792 	struct lwp *l;
793 	void *v;
794 	register_t *retval;
795 {
796 	return 0;
797 }
798 
799 int
800 sunos_sys_uname(l, v, retval)
801 	struct lwp *l;
802 	void *v;
803 	register_t *retval;
804 {
805 	struct sunos_sys_uname_args *uap = v;
806 	struct sunos_utsname sut;
807 
808 	memset(&sut, 0, sizeof(sut));
809 
810 	memcpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
811 	memcpy(sut.nodename, hostname, sizeof(sut.nodename));
812 	sut.nodename[sizeof(sut.nodename)-1] = '\0';
813 	memcpy(sut.release, osrelease, sizeof(sut.release) - 1);
814 	memcpy(sut.version, "1", sizeof(sut.version) - 1);
815 	memcpy(sut.machine, machine, sizeof(sut.machine) - 1);
816 
817 	return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
818 	    sizeof(struct sunos_utsname));
819 }
820 
821 int
822 sunos_sys_setpgrp(l, v, retval)
823 	struct lwp *l;
824 	void *v;
825 	register_t *retval;
826 {
827 	struct sunos_sys_setpgrp_args *uap = v;
828 	struct proc *p = l->l_proc;
829 
830 	/*
831 	 * difference to our setpgid call is to include backwards
832 	 * compatibility to pre-setsid() binaries. Do setsid()
833 	 * instead of setpgid() in those cases where the process
834 	 * tries to create a new session the old way.
835 	 */
836 	if (!SCARG(uap, pgid) &&
837 	    (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
838 		return sys_setsid(l, uap, retval);
839 	else
840 		return sys_setpgid(l, uap, retval);
841 }
842 
843 int
844 sunos_sys_open(l, v, retval)
845 	struct lwp *l;
846 	void *v;
847 	register_t *retval;
848 {
849 	struct sunos_sys_open_args *uap = v;
850 	struct proc *p = l->l_proc;
851 	int smode, nmode;
852 	int noctty;
853 	int ret;
854 
855 	caddr_t sg = stackgap_init(p, 0);
856 
857 	/* convert mode into NetBSD mode */
858 	smode = SCARG(uap, flags);
859 	noctty = smode & 0x8000;
860 	nmode =	smode &
861 		(0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800);
862 	nmode |= ((smode & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
863 	nmode |= ((smode & 0x0080) ? O_SHLOCK : 0);
864 	nmode |= ((smode & 0x0100) ? O_EXLOCK : 0);
865 	nmode |= ((smode & 0x2000) ? O_FSYNC : 0);
866 
867 	if (nmode & O_CREAT)
868 		CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
869 	else
870 		CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
871 
872 	SCARG(uap, flags) = nmode;
873 	ret = sys_open(l, (struct sys_open_args *)uap, retval);
874 
875 	if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
876 		struct filedesc *fdp = p->p_fd;
877 		struct file *fp;
878 
879 		fp = fd_getfile(fdp, *retval);
880 		simple_unlock(&fp->f_slock);
881 
882 		/* ignore any error, just give it a try */
883 		if (fp != NULL && fp->f_type == DTYPE_VNODE)
884 			(fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
885 	}
886 	return ret;
887 }
888 
889 #if defined (NFSSERVER)
890 int
891 sunos_sys_nfssvc(l, v, retval)
892 	struct lwp *l;
893 	void *v;
894 	register_t *retval;
895 {
896 #if 0
897 	struct sunos_sys_nfssvc_args *uap = v;
898 	struct proc *p = l->l_proc;
899 	struct emul *e = p->p_emul;
900 	struct sys_nfssvc_args outuap;
901 	struct sockaddr sa;
902 	int error;
903 	caddr_t sg = stackgap_init(p, 0);
904 
905 	memset(&outuap, 0, sizeof outuap);
906 	SCARG(&outuap, fd) = SCARG(uap, fd);
907 	SCARG(&outuap, mskval) = stackgap_alloc(p, &sg, sizeof(sa));
908 	SCARG(&outuap, msklen) = sizeof(sa);
909 	SCARG(&outuap, mtchval) = stackgap_alloc(p, &sg, sizeof(sa));
910 	SCARG(&outuap, mtchlen) = sizeof(sa);
911 
912 	memset(&sa, 0, sizeof sa);
913 	if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
914 		return (error);
915 	if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
916 		return (error);
917 
918 	return nfssvc(l, &outuap, retval);
919 #else
920 	return (ENOSYS);
921 #endif
922 }
923 #endif /* NFSSERVER */
924 
925 int
926 sunos_sys_ustat(l, v, retval)
927 	struct lwp *l;
928 	void *v;
929 	register_t *retval;
930 {
931 	struct sunos_sys_ustat_args *uap = v;
932 	struct sunos_ustat us;
933 	int error;
934 
935 	memset(&us, 0, sizeof us);
936 
937 	/*
938 	 * XXX: should set f_tfree and f_tinode at least
939 	 * How do we translate dev -> fstat? (and then to sunos_ustat)
940 	 */
941 
942 	if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
943 		return (error);
944 	return 0;
945 }
946 
947 int
948 sunos_sys_quotactl(l, v, retval)
949 	struct lwp *l;
950 	void *v;
951 	register_t *retval;
952 {
953 
954 	return EINVAL;
955 }
956 
957 int
958 sunos_sys_vhangup(l, v, retval)
959 	struct lwp *l;
960 	void *v;
961 	register_t *retval;
962 {
963 	struct proc *p = l->l_proc;
964 	struct session *sp = p->p_session;
965 
966 	if (sp->s_ttyvp == 0)
967 		return 0;
968 
969 	if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp)
970 		pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
971 
972 	(void) ttywait(sp->s_ttyp);
973 	if (sp->s_ttyvp)
974 		VOP_REVOKE(sp->s_ttyvp, REVOKEALL);
975 	if (sp->s_ttyvp)
976 		vrele(sp->s_ttyvp);
977 	sp->s_ttyvp = NULL;
978 
979 	return 0;
980 }
981 
982 static int
983 sunstatfs(sp, buf)
984 	struct statfs *sp;
985 	caddr_t buf;
986 {
987 	struct sunos_statfs ssfs;
988 
989 	memset(&ssfs, 0, sizeof ssfs);
990 	ssfs.f_type = 0;
991 	ssfs.f_bsize = sp->f_bsize;
992 	ssfs.f_blocks = sp->f_blocks;
993 	ssfs.f_bfree = sp->f_bfree;
994 	ssfs.f_bavail = sp->f_bavail;
995 	ssfs.f_files = sp->f_files;
996 	ssfs.f_ffree = sp->f_ffree;
997 	ssfs.f_fsid = sp->f_fsid;
998 	return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
999 }
1000 
1001 int
1002 sunos_sys_statfs(l, v, retval)
1003 	struct lwp *l;
1004 	void *v;
1005 	register_t *retval;
1006 {
1007 	struct sunos_sys_statfs_args *uap = v;
1008 	struct proc *p = l->l_proc;
1009 	struct mount *mp;
1010 	struct statfs *sp;
1011 	int error;
1012 	struct nameidata nd;
1013 
1014 	caddr_t sg = stackgap_init(p, 0);
1015 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
1016 
1017 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
1018 	if ((error = namei(&nd)) != 0)
1019 		return (error);
1020 	mp = nd.ni_vp->v_mount;
1021 	sp = &mp->mnt_stat;
1022 	vrele(nd.ni_vp);
1023 	if ((error = VFS_STATFS(mp, sp, p)) != 0)
1024 		return (error);
1025 	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
1026 	return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
1027 }
1028 
1029 int
1030 sunos_sys_fstatfs(l, v, retval)
1031 	struct lwp *l;
1032 	void *v;
1033 	register_t *retval;
1034 {
1035 	struct sunos_sys_fstatfs_args *uap = v;
1036 	struct proc *p = l->l_proc;
1037 	struct file *fp;
1038 	struct mount *mp;
1039 	struct statfs *sp;
1040 	int error;
1041 
1042 	/* getvnode() will use the descriptor for us */
1043 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
1044 		return (error);
1045 	mp = ((struct vnode *)fp->f_data)->v_mount;
1046 	sp = &mp->mnt_stat;
1047 	if ((error = VFS_STATFS(mp, sp, p)) != 0)
1048 		goto out;
1049 	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
1050 	error = sunstatfs(sp, (caddr_t)SCARG(uap, buf));
1051  out:
1052 	FILE_UNUSE(fp, p);
1053 	return (error);
1054 }
1055 
1056 int
1057 sunos_sys_exportfs(l, v, retval)
1058 	struct lwp *l;
1059 	void *v;
1060 	register_t *retval;
1061 {
1062 	/*
1063 	 * XXX: should perhaps translate into a mount(2)
1064 	 * with MOUNT_EXPORT?
1065 	 */
1066 	return 0;
1067 }
1068 
1069 int
1070 sunos_sys_mknod(l, v, retval)
1071 	struct lwp *l;
1072 	void *v;
1073 	register_t *retval;
1074 {
1075 	struct sunos_sys_mknod_args *uap = v;
1076 	struct proc *p = l->l_proc;
1077 
1078 	caddr_t sg = stackgap_init(p, 0);
1079 	CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
1080 
1081 	if (S_ISFIFO(SCARG(uap, mode)))
1082 		return sys_mkfifo(l, uap, retval);
1083 
1084 	return sys_mknod(l, (struct sys_mknod_args *)uap, retval);
1085 }
1086 
1087 #define SUNOS_SC_ARG_MAX	1
1088 #define SUNOS_SC_CHILD_MAX	2
1089 #define SUNOS_SC_CLK_TCK	3
1090 #define SUNOS_SC_NGROUPS_MAX	4
1091 #define SUNOS_SC_OPEN_MAX	5
1092 #define SUNOS_SC_JOB_CONTROL	6
1093 #define SUNOS_SC_SAVED_IDS	7
1094 #define SUNOS_SC_VERSION	8
1095 
1096 int
1097 sunos_sys_sysconf(l, v, retval)
1098 	struct lwp *l;
1099 	void *v;
1100 	register_t *retval;
1101 {
1102 	struct sunos_sys_sysconf_args *uap = v;
1103 	extern int maxfiles;
1104 
1105 	switch(SCARG(uap, name)) {
1106 	case SUNOS_SC_ARG_MAX:
1107 		*retval = ARG_MAX;
1108 		break;
1109 	case SUNOS_SC_CHILD_MAX:
1110 		*retval = maxproc;
1111 		break;
1112 	case SUNOS_SC_CLK_TCK:
1113 		*retval = 60;		/* should this be `hz', ie. 100? */
1114 		break;
1115 	case SUNOS_SC_NGROUPS_MAX:
1116 		*retval = NGROUPS_MAX;
1117 		break;
1118 	case SUNOS_SC_OPEN_MAX:
1119 		*retval = maxfiles;
1120 		break;
1121 	case SUNOS_SC_JOB_CONTROL:
1122 		*retval = 1;
1123 		break;
1124 	case SUNOS_SC_SAVED_IDS:
1125 #ifdef _POSIX_SAVED_IDS
1126 		*retval = 1;
1127 #else
1128 		*retval = 0;
1129 #endif
1130 		break;
1131 	case SUNOS_SC_VERSION:
1132 		*retval = 198808;
1133 		break;
1134 	default:
1135 		return EINVAL;
1136 	}
1137 	return 0;
1138 }
1139 
1140 #define SUNOS_RLIMIT_NOFILE	6	/* Other RLIMIT_* are the same */
1141 #define SUNOS_RLIM_NLIMITS	7
1142 
1143 int
1144 sunos_sys_getrlimit(l, v, retval)
1145 	struct lwp *l;
1146 	void *v;
1147 	register_t *retval;
1148 {
1149 	struct sunos_sys_getrlimit_args *uap = v;
1150 
1151 	if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
1152 		return EINVAL;
1153 
1154 	if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
1155 		SCARG(uap, which) = RLIMIT_NOFILE;
1156 
1157 	return compat_43_sys_getrlimit(l, uap, retval);
1158 }
1159 
1160 int
1161 sunos_sys_setrlimit(l, v, retval)
1162 	struct lwp *l;
1163 	void *v;
1164 	register_t *retval;
1165 {
1166 	struct sunos_sys_getrlimit_args *uap = v;
1167 
1168 	if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
1169 		return EINVAL;
1170 
1171 	if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
1172 		SCARG(uap, which) = RLIMIT_NOFILE;
1173 
1174 	return compat_43_sys_setrlimit(l, uap, retval);
1175 }
1176 
1177 /* for the m68k machines */
1178 #ifndef PT_GETFPREGS
1179 #define PT_GETFPREGS -1
1180 #endif
1181 #ifndef PT_SETFPREGS
1182 #define PT_SETFPREGS -1
1183 #endif
1184 
1185 static int sreq2breq[] = {
1186 	PT_TRACE_ME,    PT_READ_I,      PT_READ_D,      -1,
1187 	PT_WRITE_I,     PT_WRITE_D,     -1,             PT_CONTINUE,
1188 	PT_KILL,        -1,             PT_ATTACH,      PT_DETACH,
1189 	PT_GETREGS,     PT_SETREGS,     PT_GETFPREGS,   PT_SETFPREGS
1190 };
1191 static int nreqs = sizeof(sreq2breq) / sizeof(sreq2breq[0]);
1192 
1193 int
1194 sunos_sys_ptrace(l, v, retval)
1195 	struct lwp *l;
1196 	void *v;
1197 	register_t *retval;
1198 {
1199 	struct sunos_sys_ptrace_args *uap = v;
1200 	struct sys_ptrace_args pa;
1201 	int req;
1202 
1203 	req = SCARG(uap, req);
1204 
1205 	if (req < 0 || req >= nreqs)
1206 		return (EINVAL);
1207 
1208 	req = sreq2breq[req];
1209 	if (req == -1)
1210 		return (EINVAL);
1211 
1212 	SCARG(&pa, req) = req;
1213 	SCARG(&pa, pid) = (pid_t)SCARG(uap, pid);
1214 	SCARG(&pa, addr) = (caddr_t)SCARG(uap, addr);
1215 	SCARG(&pa, data) = SCARG(uap, data);
1216 
1217 	return sys_ptrace(l, &pa, retval);
1218 }
1219 
1220 /*
1221  * SunOS reboot system call (for compatibility).
1222  * Sun lets you pass in a boot string which the PROM
1223  * saves and provides to the next boot program.
1224  */
1225 
1226 #define SUNOS_RB_ASKNAME	0x001
1227 #define SUNOS_RB_SINGLE 	0x002
1228 #define SUNOS_RB_NOSYNC		0x004
1229 #define SUNOS_RB_HALT		0x008
1230 #define SUNOS_RB_DUMP		0x080
1231 #define	SUNOS_RB_STRING		0x200
1232 
1233 static struct sunos_howto_conv {
1234 	int sun_howto;
1235 	int bsd_howto;
1236 } sunos_howto_conv[] = {
1237 	{ SUNOS_RB_ASKNAME,	RB_ASKNAME },
1238 	{ SUNOS_RB_SINGLE,	RB_SINGLE },
1239 	{ SUNOS_RB_NOSYNC,	RB_NOSYNC },
1240 	{ SUNOS_RB_HALT,	RB_HALT },
1241 	{ SUNOS_RB_DUMP,	RB_DUMP },
1242 	{ SUNOS_RB_STRING,	RB_STRING },
1243 	{ 0x000,		0 },
1244 };
1245 
1246 int
1247 sunos_sys_reboot(l, v, retval)
1248 	struct lwp *l;
1249 	void *v;
1250 	register_t *retval;
1251 {
1252 	struct sunos_sys_reboot_args *uap = v;
1253 	struct proc *p = l->l_proc;
1254 	struct sys_reboot_args ua;
1255 	struct sunos_howto_conv *convp;
1256 	int error, bsd_howto, sun_howto;
1257 	char *bootstr;
1258 
1259 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
1260 		return (error);
1261 
1262 	/*
1263 	 * Convert howto bits to BSD format.
1264 	 */
1265 	sun_howto = SCARG(uap, howto);
1266 	bsd_howto = 0;
1267 	convp = sunos_howto_conv;
1268 	while (convp->sun_howto) {
1269 		if (sun_howto & convp->sun_howto)
1270 			bsd_howto |= convp->bsd_howto;
1271 		convp++;
1272 	}
1273 
1274 	/*
1275 	 * Sun RB_STRING (Get user supplied bootstring.)
1276 	 * If the machine supports passing a string to the
1277 	 * next booted kernel.
1278 	 */
1279 	if (sun_howto & SUNOS_RB_STRING) {
1280 		char bs[128];
1281 
1282 		error = copyinstr(SCARG(uap, bootstr), bs, sizeof(bs), 0);
1283 
1284 		if (error)
1285 			bootstr = NULL;
1286 		else
1287 			bootstr = bs;
1288 	} else
1289 		bootstr = NULL;
1290 
1291 	SCARG(&ua, opt) = bsd_howto;
1292 	SCARG(&ua, bootstr) = bootstr;
1293 	sys_reboot(l, &ua, retval);
1294 	return(0);
1295 }
1296 
1297 /*
1298  * Generalized interface signal handler, 4.3-compatible.
1299  */
1300 /* ARGSUSED */
1301 int
1302 sunos_sys_sigvec(l, v, retval)
1303 	struct lwp *l;
1304 	void *v;
1305 	register_t *retval;
1306 {
1307 	struct sunos_sys_sigvec_args /* {
1308 		syscallarg(int) signum;
1309 		syscallarg(struct sigvec *) nsv;
1310 		syscallarg(struct sigvec *) osv;
1311 	} */ *uap = v;
1312 	struct sigvec nsv, osv;
1313 	struct sigaction nsa, osa;
1314 	int error;
1315 /*XXX*/extern	void compat_43_sigvec_to_sigaction
1316 		__P((const struct sigvec *, struct sigaction *));
1317 /*XXX*/extern	void compat_43_sigaction_to_sigvec
1318 		__P((const struct sigaction *, struct sigvec *));
1319 
1320 	if (SCARG(uap, nsv)) {
1321 		error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
1322 		if (error != 0)
1323 			return (error);
1324 
1325 		/*
1326 		 * SunOS uses the mask 0x0004 as SV_RESETHAND
1327 		 * meaning: `reset to SIG_DFL on delivery'.
1328 		 * We support only the bits in: 0xF
1329 		 * (those bits are the same as ours)
1330 		 */
1331 		if (nsv.sv_flags & ~0xF)
1332 			return (EINVAL);
1333 
1334 		compat_43_sigvec_to_sigaction(&nsv, &nsa);
1335 	}
1336 	error = sigaction1(l->l_proc, SCARG(uap, signum),
1337 			   SCARG(uap, nsv) ? &nsa : 0,
1338 			   SCARG(uap, osv) ? &osa : 0,
1339 			   NULL, 0);
1340 	if (error != 0)
1341 		return (error);
1342 
1343 	if (SCARG(uap, osv)) {
1344 		compat_43_sigaction_to_sigvec(&osa, &osv);
1345 		error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
1346 		if (error != 0)
1347 			return (error);
1348 	}
1349 
1350 	return (0);
1351 }
1352