xref: /netbsd-src/sys/compat/sunos/sunos_misc.c (revision b8c616269f5ebf18ab2e35cb8099d683130a177c)
1 /*	$NetBSD: sunos_misc.c,v 1.119 2003/01/29 07:00:37 atatat 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.119 2003/01/29 07:00:37 atatat 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 		strcpy(idb.d_name, bdp->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 
881 		/* ignore any error, just give it a try */
882 		if (fp != NULL && fp->f_type == DTYPE_VNODE)
883 			(fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
884 	}
885 	return ret;
886 }
887 
888 #if defined (NFSSERVER)
889 int
890 sunos_sys_nfssvc(l, v, retval)
891 	struct lwp *l;
892 	void *v;
893 	register_t *retval;
894 {
895 #if 0
896 	struct sunos_sys_nfssvc_args *uap = v;
897 	struct proc *p = l->l_proc;
898 	struct emul *e = p->p_emul;
899 	struct sys_nfssvc_args outuap;
900 	struct sockaddr sa;
901 	int error;
902 	caddr_t sg = stackgap_init(p, 0);
903 
904 	memset(&outuap, 0, sizeof outuap);
905 	SCARG(&outuap, fd) = SCARG(uap, fd);
906 	SCARG(&outuap, mskval) = stackgap_alloc(p, &sg, sizeof(sa));
907 	SCARG(&outuap, msklen) = sizeof(sa);
908 	SCARG(&outuap, mtchval) = stackgap_alloc(p, &sg, sizeof(sa));
909 	SCARG(&outuap, mtchlen) = sizeof(sa);
910 
911 	memset(&sa, 0, sizeof sa);
912 	if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
913 		return (error);
914 	if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
915 		return (error);
916 
917 	return nfssvc(l, &outuap, retval);
918 #else
919 	return (ENOSYS);
920 #endif
921 }
922 #endif /* NFSSERVER */
923 
924 int
925 sunos_sys_ustat(l, v, retval)
926 	struct lwp *l;
927 	void *v;
928 	register_t *retval;
929 {
930 	struct sunos_sys_ustat_args *uap = v;
931 	struct sunos_ustat us;
932 	int error;
933 
934 	memset(&us, 0, sizeof us);
935 
936 	/*
937 	 * XXX: should set f_tfree and f_tinode at least
938 	 * How do we translate dev -> fstat? (and then to sunos_ustat)
939 	 */
940 
941 	if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
942 		return (error);
943 	return 0;
944 }
945 
946 int
947 sunos_sys_quotactl(l, v, retval)
948 	struct lwp *l;
949 	void *v;
950 	register_t *retval;
951 {
952 
953 	return EINVAL;
954 }
955 
956 int
957 sunos_sys_vhangup(l, v, retval)
958 	struct lwp *l;
959 	void *v;
960 	register_t *retval;
961 {
962 	struct proc *p = l->l_proc;
963 	struct session *sp = p->p_session;
964 
965 	if (sp->s_ttyvp == 0)
966 		return 0;
967 
968 	if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp)
969 		pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
970 
971 	(void) ttywait(sp->s_ttyp);
972 	if (sp->s_ttyvp)
973 		VOP_REVOKE(sp->s_ttyvp, REVOKEALL);
974 	if (sp->s_ttyvp)
975 		vrele(sp->s_ttyvp);
976 	sp->s_ttyvp = NULL;
977 
978 	return 0;
979 }
980 
981 static int
982 sunstatfs(sp, buf)
983 	struct statfs *sp;
984 	caddr_t buf;
985 {
986 	struct sunos_statfs ssfs;
987 
988 	memset(&ssfs, 0, sizeof ssfs);
989 	ssfs.f_type = 0;
990 	ssfs.f_bsize = sp->f_bsize;
991 	ssfs.f_blocks = sp->f_blocks;
992 	ssfs.f_bfree = sp->f_bfree;
993 	ssfs.f_bavail = sp->f_bavail;
994 	ssfs.f_files = sp->f_files;
995 	ssfs.f_ffree = sp->f_ffree;
996 	ssfs.f_fsid = sp->f_fsid;
997 	return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
998 }
999 
1000 int
1001 sunos_sys_statfs(l, v, retval)
1002 	struct lwp *l;
1003 	void *v;
1004 	register_t *retval;
1005 {
1006 	struct sunos_sys_statfs_args *uap = v;
1007 	struct proc *p = l->l_proc;
1008 	struct mount *mp;
1009 	struct statfs *sp;
1010 	int error;
1011 	struct nameidata nd;
1012 
1013 	caddr_t sg = stackgap_init(p, 0);
1014 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
1015 
1016 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
1017 	if ((error = namei(&nd)) != 0)
1018 		return (error);
1019 	mp = nd.ni_vp->v_mount;
1020 	sp = &mp->mnt_stat;
1021 	vrele(nd.ni_vp);
1022 	if ((error = VFS_STATFS(mp, sp, p)) != 0)
1023 		return (error);
1024 	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
1025 	return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
1026 }
1027 
1028 int
1029 sunos_sys_fstatfs(l, v, retval)
1030 	struct lwp *l;
1031 	void *v;
1032 	register_t *retval;
1033 {
1034 	struct sunos_sys_fstatfs_args *uap = v;
1035 	struct proc *p = l->l_proc;
1036 	struct file *fp;
1037 	struct mount *mp;
1038 	struct statfs *sp;
1039 	int error;
1040 
1041 	/* getvnode() will use the descriptor for us */
1042 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
1043 		return (error);
1044 	mp = ((struct vnode *)fp->f_data)->v_mount;
1045 	sp = &mp->mnt_stat;
1046 	if ((error = VFS_STATFS(mp, sp, p)) != 0)
1047 		goto out;
1048 	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
1049 	error = sunstatfs(sp, (caddr_t)SCARG(uap, buf));
1050  out:
1051 	FILE_UNUSE(fp, p);
1052 	return (error);
1053 }
1054 
1055 int
1056 sunos_sys_exportfs(l, v, retval)
1057 	struct lwp *l;
1058 	void *v;
1059 	register_t *retval;
1060 {
1061 	/*
1062 	 * XXX: should perhaps translate into a mount(2)
1063 	 * with MOUNT_EXPORT?
1064 	 */
1065 	return 0;
1066 }
1067 
1068 int
1069 sunos_sys_mknod(l, v, retval)
1070 	struct lwp *l;
1071 	void *v;
1072 	register_t *retval;
1073 {
1074 	struct sunos_sys_mknod_args *uap = v;
1075 	struct proc *p = l->l_proc;
1076 
1077 	caddr_t sg = stackgap_init(p, 0);
1078 	CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
1079 
1080 	if (S_ISFIFO(SCARG(uap, mode)))
1081 		return sys_mkfifo(l, uap, retval);
1082 
1083 	return sys_mknod(l, (struct sys_mknod_args *)uap, retval);
1084 }
1085 
1086 #define SUNOS_SC_ARG_MAX	1
1087 #define SUNOS_SC_CHILD_MAX	2
1088 #define SUNOS_SC_CLK_TCK	3
1089 #define SUNOS_SC_NGROUPS_MAX	4
1090 #define SUNOS_SC_OPEN_MAX	5
1091 #define SUNOS_SC_JOB_CONTROL	6
1092 #define SUNOS_SC_SAVED_IDS	7
1093 #define SUNOS_SC_VERSION	8
1094 
1095 int
1096 sunos_sys_sysconf(l, v, retval)
1097 	struct lwp *l;
1098 	void *v;
1099 	register_t *retval;
1100 {
1101 	struct sunos_sys_sysconf_args *uap = v;
1102 	extern int maxfiles;
1103 
1104 	switch(SCARG(uap, name)) {
1105 	case SUNOS_SC_ARG_MAX:
1106 		*retval = ARG_MAX;
1107 		break;
1108 	case SUNOS_SC_CHILD_MAX:
1109 		*retval = maxproc;
1110 		break;
1111 	case SUNOS_SC_CLK_TCK:
1112 		*retval = 60;		/* should this be `hz', ie. 100? */
1113 		break;
1114 	case SUNOS_SC_NGROUPS_MAX:
1115 		*retval = NGROUPS_MAX;
1116 		break;
1117 	case SUNOS_SC_OPEN_MAX:
1118 		*retval = maxfiles;
1119 		break;
1120 	case SUNOS_SC_JOB_CONTROL:
1121 		*retval = 1;
1122 		break;
1123 	case SUNOS_SC_SAVED_IDS:
1124 #ifdef _POSIX_SAVED_IDS
1125 		*retval = 1;
1126 #else
1127 		*retval = 0;
1128 #endif
1129 		break;
1130 	case SUNOS_SC_VERSION:
1131 		*retval = 198808;
1132 		break;
1133 	default:
1134 		return EINVAL;
1135 	}
1136 	return 0;
1137 }
1138 
1139 #define SUNOS_RLIMIT_NOFILE	6	/* Other RLIMIT_* are the same */
1140 #define SUNOS_RLIM_NLIMITS	7
1141 
1142 int
1143 sunos_sys_getrlimit(l, v, retval)
1144 	struct lwp *l;
1145 	void *v;
1146 	register_t *retval;
1147 {
1148 	struct sunos_sys_getrlimit_args *uap = v;
1149 
1150 	if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
1151 		return EINVAL;
1152 
1153 	if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
1154 		SCARG(uap, which) = RLIMIT_NOFILE;
1155 
1156 	return compat_43_sys_getrlimit(l, uap, retval);
1157 }
1158 
1159 int
1160 sunos_sys_setrlimit(l, v, retval)
1161 	struct lwp *l;
1162 	void *v;
1163 	register_t *retval;
1164 {
1165 	struct sunos_sys_getrlimit_args *uap = v;
1166 
1167 	if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
1168 		return EINVAL;
1169 
1170 	if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
1171 		SCARG(uap, which) = RLIMIT_NOFILE;
1172 
1173 	return compat_43_sys_setrlimit(l, uap, retval);
1174 }
1175 
1176 /* for the m68k machines */
1177 #ifndef PT_GETFPREGS
1178 #define PT_GETFPREGS -1
1179 #endif
1180 #ifndef PT_SETFPREGS
1181 #define PT_SETFPREGS -1
1182 #endif
1183 
1184 static int sreq2breq[] = {
1185 	PT_TRACE_ME,    PT_READ_I,      PT_READ_D,      -1,
1186 	PT_WRITE_I,     PT_WRITE_D,     -1,             PT_CONTINUE,
1187 	PT_KILL,        -1,             PT_ATTACH,      PT_DETACH,
1188 	PT_GETREGS,     PT_SETREGS,     PT_GETFPREGS,   PT_SETFPREGS
1189 };
1190 static int nreqs = sizeof(sreq2breq) / sizeof(sreq2breq[0]);
1191 
1192 int
1193 sunos_sys_ptrace(l, v, retval)
1194 	struct lwp *l;
1195 	void *v;
1196 	register_t *retval;
1197 {
1198 	struct sunos_sys_ptrace_args *uap = v;
1199 	struct sys_ptrace_args pa;
1200 	int req;
1201 
1202 	req = SCARG(uap, req);
1203 
1204 	if (req < 0 || req >= nreqs)
1205 		return (EINVAL);
1206 
1207 	req = sreq2breq[req];
1208 	if (req == -1)
1209 		return (EINVAL);
1210 
1211 	SCARG(&pa, req) = req;
1212 	SCARG(&pa, pid) = (pid_t)SCARG(uap, pid);
1213 	SCARG(&pa, addr) = (caddr_t)SCARG(uap, addr);
1214 	SCARG(&pa, data) = SCARG(uap, data);
1215 
1216 	return sys_ptrace(l, &pa, retval);
1217 }
1218 
1219 /*
1220  * SunOS reboot system call (for compatibility).
1221  * Sun lets you pass in a boot string which the PROM
1222  * saves and provides to the next boot program.
1223  */
1224 
1225 #define SUNOS_RB_ASKNAME	0x001
1226 #define SUNOS_RB_SINGLE 	0x002
1227 #define SUNOS_RB_NOSYNC		0x004
1228 #define SUNOS_RB_HALT		0x008
1229 #define SUNOS_RB_DUMP		0x080
1230 #define	SUNOS_RB_STRING		0x200
1231 
1232 static struct sunos_howto_conv {
1233 	int sun_howto;
1234 	int bsd_howto;
1235 } sunos_howto_conv[] = {
1236 	{ SUNOS_RB_ASKNAME,	RB_ASKNAME },
1237 	{ SUNOS_RB_SINGLE,	RB_SINGLE },
1238 	{ SUNOS_RB_NOSYNC,	RB_NOSYNC },
1239 	{ SUNOS_RB_HALT,	RB_HALT },
1240 	{ SUNOS_RB_DUMP,	RB_DUMP },
1241 	{ SUNOS_RB_STRING,	RB_STRING },
1242 	{ 0x000,		0 },
1243 };
1244 
1245 int
1246 sunos_sys_reboot(l, v, retval)
1247 	struct lwp *l;
1248 	void *v;
1249 	register_t *retval;
1250 {
1251 	struct sunos_sys_reboot_args *uap = v;
1252 	struct proc *p = l->l_proc;
1253 	struct sys_reboot_args ua;
1254 	struct sunos_howto_conv *convp;
1255 	int error, bsd_howto, sun_howto;
1256 	char *bootstr;
1257 
1258 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
1259 		return (error);
1260 
1261 	/*
1262 	 * Convert howto bits to BSD format.
1263 	 */
1264 	sun_howto = SCARG(uap, howto);
1265 	bsd_howto = 0;
1266 	convp = sunos_howto_conv;
1267 	while (convp->sun_howto) {
1268 		if (sun_howto & convp->sun_howto)
1269 			bsd_howto |= convp->bsd_howto;
1270 		convp++;
1271 	}
1272 
1273 	/*
1274 	 * Sun RB_STRING (Get user supplied bootstring.)
1275 	 * If the machine supports passing a string to the
1276 	 * next booted kernel.
1277 	 */
1278 	if (sun_howto & SUNOS_RB_STRING) {
1279 		char bs[128];
1280 
1281 		error = copyinstr(SCARG(uap, bootstr), bs, sizeof(bs), 0);
1282 
1283 		if (error)
1284 			bootstr = NULL;
1285 		else
1286 			bootstr = bs;
1287 	} else
1288 		bootstr = NULL;
1289 
1290 	SCARG(&ua, opt) = bsd_howto;
1291 	SCARG(&ua, bootstr) = bootstr;
1292 	sys_reboot(l, &ua, retval);
1293 	return(0);
1294 }
1295 
1296 /*
1297  * Generalized interface signal handler, 4.3-compatible.
1298  */
1299 /* ARGSUSED */
1300 int
1301 sunos_sys_sigvec(l, v, retval)
1302 	struct lwp *l;
1303 	void *v;
1304 	register_t *retval;
1305 {
1306 	struct sunos_sys_sigvec_args /* {
1307 		syscallarg(int) signum;
1308 		syscallarg(struct sigvec *) nsv;
1309 		syscallarg(struct sigvec *) osv;
1310 	} */ *uap = v;
1311 	struct sigvec nsv, osv;
1312 	struct sigaction nsa, osa;
1313 	int error;
1314 /*XXX*/extern	void compat_43_sigvec_to_sigaction
1315 		__P((const struct sigvec *, struct sigaction *));
1316 /*XXX*/extern	void compat_43_sigaction_to_sigvec
1317 		__P((const struct sigaction *, struct sigvec *));
1318 
1319 	if (SCARG(uap, nsv)) {
1320 		error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
1321 		if (error != 0)
1322 			return (error);
1323 
1324 		/*
1325 		 * SunOS uses the mask 0x0004 as SV_RESETHAND
1326 		 * meaning: `reset to SIG_DFL on delivery'.
1327 		 * We support only the bits in: 0xF
1328 		 * (those bits are the same as ours)
1329 		 */
1330 		if (nsv.sv_flags & ~0xF)
1331 			return (EINVAL);
1332 
1333 		compat_43_sigvec_to_sigaction(&nsv, &nsa);
1334 	}
1335 	error = sigaction1(l->l_proc, SCARG(uap, signum),
1336 			   SCARG(uap, nsv) ? &nsa : 0,
1337 			   SCARG(uap, osv) ? &osa : 0,
1338 			   NULL, 0);
1339 	if (error != 0)
1340 		return (error);
1341 
1342 	if (SCARG(uap, osv)) {
1343 		compat_43_sigaction_to_sigvec(&osa, &osv);
1344 		error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
1345 		if (error != 0)
1346 			return (error);
1347 	}
1348 
1349 	return (0);
1350 }
1351