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