sunos32_misc.c revision 1.36 1 /* $NetBSD: sunos32_misc.c,v 1.36 2006/03/01 12:38:12 yamt Exp $ */
2 /* from :NetBSD: sunos_misc.c,v 1.107 2000/12/01 19:25:10 jdolecek Exp */
3
4 /*
5 * Copyright (c) 2001 Matthew R. Green
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 /*
33 * Copyright (c) 1992, 1993
34 * The Regents of the University of California. All rights reserved.
35 *
36 * This software was developed by the Computer Systems Engineering group
37 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
38 * contributed to Berkeley.
39 *
40 * All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Lawrence Berkeley Laboratory.
44 *
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
47 * are met:
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. Neither the name of the University nor the names of its contributors
54 * may be used to endorse or promote products derived from this software
55 * without specific prior written permission.
56 *
57 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
58 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
60 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
61 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
62 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
63 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
65 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67 * SUCH DAMAGE.
68 *
69 * @(#)sunos_misc.c 8.1 (Berkeley) 6/18/93
70 *
71 * Header: sunos_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
72 */
73
74 /*
75 * SunOS compatibility module, 64-bit kernel version
76 *
77 * SunOS system calls that are implemented differently in BSD are
78 * handled here.
79 */
80
81 #include <sys/cdefs.h>
82 __KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.36 2006/03/01 12:38:12 yamt Exp $");
83
84 #define COMPAT_SUNOS 1
85
86 #if defined(_KERNEL_OPT)
87 #include "opt_nfsserver.h"
88 #include "opt_compat_43.h"
89 #include "opt_compat_netbsd.h"
90 #include "fs_nfs.h"
91 #endif
92
93 #include <sys/param.h>
94 #include <sys/systm.h>
95 #include <sys/namei.h>
96 #include <sys/proc.h>
97 #include <sys/dirent.h>
98 #include <sys/file.h>
99 #include <sys/stat.h>
100 #include <sys/filedesc.h>
101 #include <sys/ioctl.h>
102 #include <sys/kernel.h>
103 #include <sys/reboot.h>
104 #include <sys/malloc.h>
105 #include <sys/mbuf.h>
106 #include <sys/mman.h>
107 #include <sys/mount.h>
108 #include <sys/ptrace.h>
109 #include <sys/resource.h>
110 #include <sys/resourcevar.h>
111 #include <sys/signal.h>
112 #include <sys/signalvar.h>
113 #include <sys/socket.h>
114 #include <sys/tty.h>
115 #include <sys/vnode.h>
116 #include <sys/uio.h>
117 #include <sys/wait.h>
118 #include <sys/utsname.h>
119 #include <sys/unistd.h>
120 #include <sys/sa.h>
121 #include <sys/syscallargs.h>
122 #include <sys/conf.h>
123 #include <sys/socketvar.h>
124 #include <sys/exec.h>
125 #include <sys/swap.h>
126
127 #include <compat/netbsd32/netbsd32.h>
128 #include <compat/netbsd32/netbsd32_syscallargs.h>
129 #include <compat/sunos32/sunos32.h>
130 #include <compat/sunos32/sunos32_dirent.h>
131 #include <compat/sunos32/sunos32_syscallargs.h>
132 #include <compat/common/compat_util.h>
133
134 #include <netinet/in.h>
135
136 #include <miscfs/specfs/specdev.h>
137
138 #include <nfs/rpcv2.h>
139 #include <nfs/nfsproto.h>
140 #include <nfs/nfs.h>
141 #include <nfs/nfsmount.h>
142
143 static void sunos32_sigvec_to_sigaction(const struct netbsd32_sigvec *, struct sigaction *);
144 static void sunos32_sigvec_from_sigaction(struct netbsd32_sigvec *, const struct sigaction *);
145
146 static int sunstatfs __P((struct statvfs *, caddr_t));
147
148 static void
149 sunos32_sigvec_to_sigaction(sv, sa)
150 const struct netbsd32_sigvec *sv;
151 struct sigaction *sa;
152 {
153 /*XXX*/ extern void compat_43_sigmask_to_sigset __P((const int *, sigset_t *));
154
155 sa->sa_handler = (void *)(u_long)sv->sv_handler;
156 compat_43_sigmask_to_sigset(&sv->sv_mask, &sa->sa_mask);
157 sa->sa_flags = sv->sv_flags ^ SA_RESTART;
158 }
159
160 static
161 void sunos32_sigvec_from_sigaction(sv, sa)
162 struct netbsd32_sigvec *sv;
163 const struct sigaction *sa;
164 {
165 /*XXX*/ extern void compat_43_sigset_to_sigmask __P((const sigset_t *, int *));
166
167 sv->sv_handler = (netbsd32_voidp)(u_long)sa->sa_handler;
168 compat_43_sigset_to_sigmask(&sa->sa_mask, &sv->sv_mask);
169 sv->sv_flags = sa->sa_flags ^ SA_RESTART;
170 }
171
172 int
173 sunos32_sys_stime(l, v, retval)
174 struct lwp *l;
175 void *v;
176 register_t *retval;
177 {
178 struct sunos32_sys_stime_args /* {
179 syscallarg(sunos32_time_tp) tp;
180 } */ *uap = v;
181 struct proc *p = l->l_proc;
182 struct sys_settimeofday_args ap;
183 caddr_t sg = stackgap_init(p, 0);
184 struct netbsd32_timeval ntv;
185 struct timeval tv, *sgtvp;
186 int error;
187
188 error = copyin((caddr_t)(u_long)SCARG(uap, tp), &ntv.tv_sec, sizeof(ntv.tv_sec));
189 if (error)
190 return error;
191 tv.tv_sec = ntv.tv_sec;
192 tv.tv_usec = 0;
193
194 SCARG(&ap, tv) = sgtvp = stackgap_alloc(p, &sg, sizeof(struct timeval));
195 SCARG(&ap, tzp) = NULL;
196
197 error = copyout(&tv, sgtvp, sizeof(struct timeval));
198 if (error)
199 return error;
200
201 return sys_settimeofday(l, &ap, retval);
202 }
203
204 int
205 sunos32_sys_wait4(l, v, retval)
206 struct lwp *l;
207 void *v;
208 register_t *retval;
209 {
210 struct sunos32_sys_wait4_args /* {
211 syscallarg(int) pid;
212 syscallarg(netbsd32_intp) status;
213 syscallarg(int) options;
214 syscallarg(netbsd32_rusagep_t) rusage;
215 } */ *uap = v;
216
217 if (SCARG(uap, pid) == 0)
218 SCARG(uap, pid) = WAIT_ANY;
219 return (netbsd32_wait4(l, uap, retval));
220 }
221
222 int
223 sunos32_sys_creat(l, v, retval)
224 struct lwp *l;
225 void *v;
226 register_t *retval;
227 {
228 struct sunos32_sys_creat_args /* {
229 syscallarg(const netbsd32_charp) path;
230 syscallarg(int) mode;
231 } */ *uap = v;
232 struct proc *p = l->l_proc;
233 struct sys_open_args ua;
234 caddr_t sg = stackgap_init(p, 0);
235
236 SUNOS32TOP_UAP(path, const char);
237 SCARG(&ua, flags) = O_WRONLY | O_CREAT | O_TRUNC;
238 SUNOS32TO64_UAP(mode);
239
240 SUNOS32_CHECK_ALT_CREAT(l, &sg, SCARG(&ua, path));
241
242 return (sys_open(l, &ua, retval));
243 }
244
245 int
246 sunos32_sys_access(l, v, retval)
247 struct lwp *l;
248 void *v;
249 register_t *retval;
250 {
251 struct sunos32_sys_access_args /* {
252 syscallarg(const netbsd32_charp) path;
253 syscallarg(int) flags;
254 } */ *uap = v;
255 struct proc *p = l->l_proc;
256 struct sys_access_args ua;
257 caddr_t sg = stackgap_init(p, 0);
258
259 SUNOS32TOP_UAP(path, const char);
260 SUNOS32TO64_UAP(flags);
261 SUNOS32_CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
262
263 return (sys_access(l, &ua, retval));
264 }
265
266 static inline void sunos32_from___stat13 __P((struct stat *, struct netbsd32_stat43 *));
267
268 static inline void
269 sunos32_from___stat13(sbp, sb32p)
270 struct stat *sbp;
271 struct netbsd32_stat43 *sb32p;
272 {
273 sb32p->st_dev = sbp->st_dev;
274 sb32p->st_ino = sbp->st_ino;
275 sb32p->st_mode = sbp->st_mode;
276 sb32p->st_nlink = sbp->st_nlink;
277 sb32p->st_uid = sbp->st_uid;
278 sb32p->st_gid = sbp->st_gid;
279 sb32p->st_rdev = sbp->st_rdev;
280 if (sbp->st_size < (quad_t)1 << 32)
281 sb32p->st_size = sbp->st_size;
282 else
283 sb32p->st_size = -2;
284 sb32p->st_atimespec.tv_sec = (netbsd32_time_t)sbp->st_atimespec.tv_sec;
285 sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
286 sb32p->st_mtimespec.tv_sec = (netbsd32_time_t)sbp->st_mtimespec.tv_sec;
287 sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
288 sb32p->st_ctimespec.tv_sec = (netbsd32_time_t)sbp->st_ctimespec.tv_sec;
289 sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
290 sb32p->st_blksize = sbp->st_blksize;
291 sb32p->st_blocks = sbp->st_blocks;
292 sb32p->st_flags = sbp->st_flags;
293 sb32p->st_gen = sbp->st_gen;
294 }
295
296
297 int
298 sunos32_sys_stat(l, v, retval)
299 struct lwp *l;
300 void *v;
301 register_t *retval;
302 {
303 struct sunos32_sys_stat_args /* {
304 syscallarg(const netbsd32_charp) path;
305 syscallarg(netbsd32_stat43p_t) ub;
306 } */ *uap = v;
307 struct proc *p = l->l_proc;
308 struct netbsd32_stat43 sb32;
309 struct stat sb;
310 struct nameidata nd;
311 caddr_t sg;
312 const char *path;
313 int error;
314
315 path = (char *)(u_long)SCARG(uap, path);
316 sg = stackgap_init(p, 0);
317 SUNOS32_CHECK_ALT_EXIST(l, &sg, path);
318
319 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, path, l);
320 if ((error = namei(&nd)) != 0)
321 return (error);
322 error = vn_stat(nd.ni_vp, &sb, l);
323 vput(nd.ni_vp);
324 if (error)
325 return (error);
326 sunos32_from___stat13(&sb, &sb32);
327 error = copyout((caddr_t)&sb32, (caddr_t)(u_long)SCARG(uap, ub), sizeof (sb32));
328 return (error);
329 }
330
331 int
332 sunos32_sys_lstat(l, v, retval)
333 struct lwp *l;
334 void *v;
335 register_t *retval;
336 {
337 struct sunos32_sys_lstat_args /* {
338 syscallarg(const netbsd32_charp) path;
339 syscallarg(netbsd32_stat43p_t) ub;
340 } */ *uap = v;
341 struct vnode *vp, *dvp;
342 struct proc *p = l->l_proc;
343 struct stat sb, sb1;
344 struct netbsd32_stat43 sb32;
345 int error;
346 struct nameidata nd;
347 int ndflags;
348 const char *path;
349 caddr_t sg;
350
351 path = (char *)(u_long)SCARG(uap, path);
352 sg = stackgap_init(p, 0);
353 SUNOS32_CHECK_ALT_EXIST(l, &sg, path);
354
355 ndflags = NOFOLLOW | LOCKLEAF | LOCKPARENT;
356 again:
357 NDINIT(&nd, LOOKUP, ndflags, UIO_USERSPACE, path, l);
358 if ((error = namei(&nd))) {
359 if (error == EISDIR && (ndflags & LOCKPARENT) != 0) {
360 /*
361 * Should only happen on '/'. Retry without LOCKPARENT;
362 * this is safe since the vnode won't be a VLNK.
363 */
364 ndflags &= ~LOCKPARENT;
365 goto again;
366 }
367 return (error);
368 }
369 /*
370 * For symbolic links, always return the attributes of its
371 * containing directory, except for mode, size, and links.
372 */
373 vp = nd.ni_vp;
374 dvp = nd.ni_dvp;
375 if (vp->v_type != VLNK) {
376 if ((ndflags & LOCKPARENT) != 0) {
377 if (dvp == vp)
378 vrele(dvp);
379 else
380 vput(dvp);
381 }
382 error = vn_stat(vp, &sb, l);
383 vput(vp);
384 if (error)
385 return (error);
386 } else {
387 error = vn_stat(dvp, &sb, l);
388 vput(dvp);
389 if (error) {
390 vput(vp);
391 return (error);
392 }
393 error = vn_stat(vp, &sb1, l);
394 vput(vp);
395 if (error)
396 return (error);
397 sb.st_mode &= ~S_IFDIR;
398 sb.st_mode |= S_IFLNK;
399 sb.st_nlink = sb1.st_nlink;
400 sb.st_size = sb1.st_size;
401 sb.st_blocks = sb1.st_blocks;
402 }
403 sunos32_from___stat13(&sb, &sb32);
404 error = copyout((caddr_t)&sb32, (caddr_t)(u_long)SCARG(uap, ub), sizeof (sb32));
405 return (error);
406 }
407
408 static int
409 sunos32_execve_fetch_element(char * const *array, size_t index, char **value)
410 {
411 int error;
412 netbsd32_charp const *a32 = (void const *)array;
413 netbsd32_charp e;
414
415 error = copyin(a32 + index, &e, sizeof(e));
416 if (error)
417 return error;
418 *value = (char *)(u_long)(u_int)e;
419 return 0;
420 }
421
422 int
423 sunos32_sys_execv(l, v, retval)
424 struct lwp *l;
425 void *v;
426 register_t *retval;
427 {
428 struct sunos32_sys_execv_args /* {
429 syscallarg(const char *) path;
430 syscallarg(char **) argv;
431 } */ *uap = v;
432 struct proc *p = l->l_proc;
433 const char *path = (const char *)(u_long)(u_int)SCARG(uap, path);
434 caddr_t sg;
435
436 sg = stackgap_init(p, 0);
437 SUNOS32_CHECK_ALT_EXIST(l, &sg, path);
438
439 return execve1(l, path, (char **)(u_long)(u_int)SCARG(uap, argp), NULL,
440 sunos32_execve_fetch_element);
441 }
442
443 int
444 sunos32_sys_execve(l, v, retval)
445 struct lwp *l;
446 void *v;
447 register_t *retval;
448 {
449 struct sunos32_sys_execve_args /* {
450 syscallarg(const char *) path;
451 syscallarg(char **) argv;
452 syscallarg(char **) envp;
453 } */ *uap = v;
454 struct proc *p = l->l_proc;
455 const char *path = (const char *)(u_long)(u_int)SCARG(uap, path);
456 caddr_t sg;
457
458 sg = stackgap_init(p, 0);
459 SUNOS32_CHECK_ALT_EXIST(l, &sg, path);
460
461 return execve1(l, path, (char **)(u_long)(u_int)SCARG(uap, argp),
462 (char **)(u_long)(u_int)SCARG(uap, envp),
463 sunos32_execve_fetch_element);
464 }
465
466 int
467 sunos32_sys_omsync(l, v, retval)
468 struct lwp *l;
469 void *v;
470 register_t *retval;
471 {
472 struct sunos32_sys_omsync_args /* {
473 syscallarg(netbsd32_caddr_t) addr;
474 syscallarg(netbsd32_size_t) len;
475 syscallarg(int) flags;
476 } */ *uap = v;
477 struct netbsd32___msync13_args ouap;
478
479 SCARG(&ouap, addr) = SCARG(uap, addr);
480 SCARG(&ouap, len) = SCARG(uap, len);
481 SCARG(&ouap, flags) = SCARG(uap, flags);
482
483 return (netbsd32___msync13(l, &ouap, retval));
484 }
485
486 int
487 sunos32_sys_unmount(l, v, retval)
488 struct lwp *l;
489 void *v;
490 register_t *retval;
491 {
492 struct sunos32_sys_unmount_args /* {
493 syscallarg(netbsd32_charp) path;
494 } */ *uap = v;
495 struct sys_unmount_args ua;
496
497 SUNOS32TOP_UAP(path, const char);
498 SCARG(&ua, flags) = 0;
499
500 return (sys_unmount(l, &ua, retval));
501 }
502
503 /*
504 * Conversion table for SunOS NFS mount flags.
505 */
506 static struct {
507 int sun_flg;
508 int bsd_flg;
509 } sunnfs_flgtab[] = {
510 { SUNNFS_SOFT, NFSMNT_SOFT },
511 { SUNNFS_WSIZE, NFSMNT_WSIZE },
512 { SUNNFS_RSIZE, NFSMNT_RSIZE },
513 { SUNNFS_TIMEO, NFSMNT_TIMEO },
514 { SUNNFS_RETRANS, NFSMNT_RETRANS },
515 { SUNNFS_HOSTNAME, 0 }, /* Ignored */
516 { SUNNFS_INT, NFSMNT_INT },
517 { SUNNFS_NOAC, 0 }, /* Ignored */
518 { SUNNFS_ACREGMIN, 0 }, /* Ignored */
519 { SUNNFS_ACREGMAX, 0 }, /* Ignored */
520 { SUNNFS_ACDIRMIN, 0 }, /* Ignored */
521 { SUNNFS_ACDIRMAX, 0 }, /* Ignored */
522 { SUNNFS_SECURE, 0 }, /* Ignored */
523 { SUNNFS_NOCTO, 0 }, /* Ignored */
524 { SUNNFS_POSIX, 0 } /* Ignored */
525 };
526
527 int
528 sunos32_sys_mount(l, v, retval)
529 struct lwp *l;
530 void *v;
531 register_t *retval;
532 {
533 struct sunos32_sys_mount_args /* {
534 syscallarg(netbsd32_charp) type;
535 syscallarg(netbsd32_charp) path;
536 syscallarg(int) flags;
537 syscallarg(netbsd32_caddr_t) data;
538 } */ *uap = v;
539 struct proc *p = l->l_proc;
540 struct sys_mount_args ua;
541 int oflags = SCARG(uap, flags), nflags, error;
542 char fsname[MFSNAMELEN];
543 caddr_t sg = stackgap_init(p, 0);
544
545 if (oflags & (SUNM_NOSUB | SUNM_SYS5))
546 return (EINVAL);
547 if ((oflags & SUNM_NEWTYPE) == 0)
548 return (EINVAL);
549 nflags = 0;
550 if (oflags & SUNM_RDONLY)
551 nflags |= MNT_RDONLY;
552 if (oflags & SUNM_NOSUID)
553 nflags |= MNT_NOSUID;
554 if (oflags & SUNM_REMOUNT)
555 nflags |= MNT_UPDATE;
556 SCARG(uap, flags) = nflags;
557
558 error = copyinstr((caddr_t)(u_long)SCARG(uap, type), fsname,
559 sizeof fsname, (size_t *)0);
560 if (error)
561 return (error);
562
563 if (strncmp(fsname, "4.2", sizeof fsname) == 0) {
564 SCARG(uap, type) = (netbsd32_charp)(u_long)stackgap_alloc(p, &sg, sizeof("ffs"));
565 error = copyout("ffs", (caddr_t)(u_long)SCARG(uap, type), sizeof("ffs"));
566 if (error)
567 return (error);
568 } else if (strncmp(fsname, "nfs", sizeof fsname) == 0) {
569 struct sunos_nfs_args sna;
570 struct sockaddr_in sain;
571 struct nfs_args na; /* XXX */
572 struct sockaddr sa;
573 int n;
574
575 error = copyin((caddr_t)(u_long)SCARG(uap, data), &sna, sizeof sna);
576 if (error)
577 return (error);
578 error = copyin(sna.addr, &sain, sizeof sain);
579 if (error)
580 return (error);
581 memcpy(&sa, &sain, sizeof sa);
582 sa.sa_len = sizeof(sain);
583 SCARG(uap, data) = (netbsd32_charp)(u_long)stackgap_alloc(p, &sg, sizeof(na));
584 na.version = NFS_ARGSVERSION;
585 na.addr = stackgap_alloc(p, &sg, sizeof(struct sockaddr));
586 na.addrlen = sizeof(struct sockaddr);
587 na.sotype = SOCK_DGRAM;
588 na.proto = IPPROTO_UDP;
589 na.fh = (void *)sna.fh;
590 na.fhsize = NFSX_V2FH;
591 na.flags = 0;
592 n = sizeof(sunnfs_flgtab) / sizeof(sunnfs_flgtab[0]);
593 while (--n >= 0)
594 if (sna.flags & sunnfs_flgtab[n].sun_flg)
595 na.flags |= sunnfs_flgtab[n].bsd_flg;
596 na.wsize = sna.wsize;
597 na.rsize = sna.rsize;
598 if (na.flags & NFSMNT_RSIZE) {
599 na.flags |= NFSMNT_READDIRSIZE;
600 na.readdirsize = na.rsize;
601 }
602 na.timeo = sna.timeo;
603 na.retrans = sna.retrans;
604 na.hostname = (char *)(u_long)sna.hostname;
605
606 error = copyout(&sa, na.addr, sizeof sa);
607 if (error)
608 return (error);
609 error = copyout(&na, (caddr_t)(u_long)SCARG(uap, data), sizeof na);
610 if (error)
611 return (error);
612 }
613 SUNOS32TOP_UAP(type, const char);
614 SUNOS32TOP_UAP(path, const char);
615 SUNOS32TO64_UAP(flags);
616 SUNOS32TOP_UAP(data, void);
617 return (sys_mount(l, &ua, retval));
618 }
619
620 #if defined(NFS)
621 int
622 async_daemon(l, v, retval)
623 struct lwp *l;
624 void *v;
625 register_t *retval;
626 {
627 struct netbsd32_nfssvc_args ouap;
628
629 SCARG(&ouap, flag) = NFSSVC_BIOD;
630 SCARG(&ouap, argp) = 0;
631
632 return (netbsd32_nfssvc(l, &ouap, retval));
633 }
634 #endif /* NFS */
635
636 void native_to_sunos_sigset __P((const sigset_t *, int *));
637 void sunos_to_native_sigset __P((const int, sigset_t *));
638
639 inline void
640 native_to_sunos_sigset(ss, mask)
641 const sigset_t *ss;
642 int *mask;
643 {
644 *mask = ss->__bits[0];
645 }
646
647 inline void
648 sunos_to_native_sigset(mask, ss)
649 const int mask;
650 sigset_t *ss;
651 {
652
653 ss->__bits[0] = mask;
654 ss->__bits[1] = 0;
655 ss->__bits[2] = 0;
656 ss->__bits[3] = 0;
657 }
658
659 int
660 sunos32_sys_sigpending(l, v, retval)
661 struct lwp *l;
662 void *v;
663 register_t *retval;
664 {
665 struct sunos32_sys_sigpending_args /* {
666 syscallarg(netbsd32_intp) mask;
667 } */ *uap = v;
668 struct proc *p = l->l_proc;
669 sigset_t ss;
670 int mask;
671
672 sigpending1(p, &ss);
673 native_to_sunos_sigset(&ss, &mask);
674
675 return (copyout((caddr_t)(u_long)&mask, (caddr_t)(u_long)SCARG(uap, mask), sizeof(int)));
676 }
677
678 int
679 sunos32_sys_sigsuspend(l, v, retval)
680 struct lwp *l;
681 void *v;
682 register_t *retval;
683 {
684 struct sunos32_sys_sigsuspend_args /* {
685 syscallarg(int) mask;
686 } */ *uap = v;
687 int mask;
688 struct proc *p = l->l_proc;
689 sigset_t ss;
690
691 mask = SCARG(uap, mask);
692 sunos_to_native_sigset(mask, &ss);
693 return (sigsuspend1(p, &ss));
694 }
695
696 /*
697 * Read Sun-style directory entries. We suck them into kernel space so
698 * that they can be massaged before being copied out to user code. Like
699 * SunOS, we squish out `empty' entries.
700 *
701 * This is quite ugly, but what do you expect from compatibility code?
702 */
703 int
704 sunos32_sys_getdents(l, v, retval)
705 struct lwp *l;
706 void *v;
707 register_t *retval;
708 {
709 struct sunos32_sys_getdents_args /* {
710 syscallarg(int) fd;
711 syscallarg(netbsd32_charp) buf;
712 syscallarg(int) nbytes;
713 } */ *uap = v;
714 struct proc *p = l->l_proc;
715 struct dirent *bdp;
716 struct vnode *vp;
717 caddr_t inp, sbuf; /* BSD-format */
718 int len, reclen; /* BSD-format */
719 caddr_t outp; /* Sun-format */
720 int resid, sunos_reclen;/* Sun-format */
721 struct file *fp;
722 struct uio auio;
723 struct iovec aiov;
724 struct sunos32_dirent idb;
725 off_t off; /* true file offset */
726 int buflen, error, eofflag;
727 off_t *cookiebuf, *cookie;
728 int ncookies;
729
730 /* getvnode() will use the descriptor for us */
731 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
732 return (error);
733
734 if ((fp->f_flag & FREAD) == 0) {
735 error = EBADF;
736 goto out1;
737 }
738
739 vp = (struct vnode *)fp->f_data;
740 if (vp->v_type != VDIR) {
741 error = EINVAL;
742 goto out1;
743 }
744
745 buflen = min(MAXBSIZE, SCARG(uap, nbytes));
746 sbuf = malloc(buflen, M_TEMP, M_WAITOK);
747 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
748 off = fp->f_offset;
749 again:
750 aiov.iov_base = sbuf;
751 aiov.iov_len = buflen;
752 auio.uio_iov = &aiov;
753 auio.uio_iovcnt = 1;
754 auio.uio_rw = UIO_READ;
755 auio.uio_resid = buflen;
756 auio.uio_offset = off;
757 UIO_SETUP_SYSSPACE(&auio);
758 /*
759 * First we read into the malloc'ed buffer, then
760 * we massage it into user space, one record at a time.
761 */
762 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
763 &ncookies);
764 if (error)
765 goto out;
766
767 inp = sbuf;
768 outp = (caddr_t)(u_long)SCARG(uap, buf);
769 resid = SCARG(uap, nbytes);
770 if ((len = buflen - auio.uio_resid) == 0)
771 goto eof;
772
773 for (cookie = cookiebuf; len > 0; len -= reclen) {
774 bdp = (struct dirent *)inp;
775 reclen = bdp->d_reclen;
776 if (reclen & 3)
777 panic("sunos_getdents");
778 if (cookie && (*cookie >> 32) != 0) {
779 compat_offseterr(vp, "sunos_getdents");
780 error = EINVAL;
781 goto out;
782 }
783 if (bdp->d_fileno == 0) {
784 inp += reclen; /* it is a hole; squish it out */
785 if (cookie)
786 off = *cookie++;
787 else
788 off += reclen;
789 continue;
790 }
791 sunos_reclen = SUNOS32_RECLEN(&idb, bdp->d_namlen);
792 if (reclen > len || resid < sunos_reclen) {
793 /* entry too big for buffer, so just stop */
794 outp++;
795 break;
796 }
797 if (cookie)
798 off = *cookie++; /* each entry points to next */
799 else
800 off += reclen;
801 /*
802 * Massage in place to make a Sun-shaped dirent (otherwise
803 * we have to worry about touching user memory outside of
804 * the copyout() call).
805 */
806 idb.d_fileno = bdp->d_fileno;
807 idb.d_off = off;
808 idb.d_reclen = sunos_reclen;
809 idb.d_namlen = bdp->d_namlen;
810 strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
811 if ((error = copyout((caddr_t)&idb, outp, sunos_reclen)) != 0)
812 goto out;
813 /* advance past this real entry */
814 inp += reclen;
815 /* advance output past Sun-shaped entry */
816 outp += sunos_reclen;
817 resid -= sunos_reclen;
818 }
819
820 /* if we squished out the whole block, try again */
821 if (outp == (caddr_t)(u_long)SCARG(uap, buf))
822 goto again;
823 fp->f_offset = off; /* update the vnode offset */
824
825 eof:
826 *retval = SCARG(uap, nbytes) - resid;
827 out:
828 VOP_UNLOCK(vp, 0);
829 free(cookiebuf, M_TEMP);
830 free(sbuf, M_TEMP);
831 out1:
832 FILE_UNUSE(fp, l);
833 return (error);
834 }
835
836 #define SUNOS32__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
837
838 int
839 sunos32_sys_mmap(l, v, retval)
840 struct lwp *l;
841 void *v;
842 register_t *retval;
843 {
844 struct sunos32_sys_mmap_args /* {
845 syscallarg(netbsd32_voidp) addr;
846 syscallarg(netbsd32_size_t) len;
847 syscallarg(int) prot;
848 syscallarg(int) flags;
849 syscallarg(int) fd;
850 syscallarg(netbsd32_long) pos;
851 } */ *uap = v;
852 struct sys_mmap_args ua;
853 int error;
854
855 /*
856 * Verify the arguments.
857 */
858 if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
859 return (EINVAL); /* XXX still needed? */
860
861 if ((SCARG(uap, flags) & SUNOS32__MAP_NEW) == 0)
862 return (EINVAL);
863
864 SUNOS32TOP_UAP(addr, void);
865 SUNOS32TOX_UAP(len, size_t);
866 SUNOS32TO64_UAP(prot);
867 SCARG(&ua, flags) = SCARG(uap, flags) & ~SUNOS32__MAP_NEW;
868 SUNOS32TO64_UAP(fd);
869 SCARG(&ua, pad) = 0;
870 SUNOS32TOX_UAP(pos, off_t);
871
872 error = sys_mmap(l, &ua, retval);
873 if ((u_long)*retval > (u_long)UINT_MAX) {
874 printf("sunos32_mmap: retval out of range: 0x%lx",
875 (u_long)*retval);
876 /* Should try to recover and return an error here. */
877 }
878 return (error);
879 }
880
881 #define MC_SYNC 1
882 #define MC_LOCK 2
883 #define MC_UNLOCK 3
884 #define MC_ADVISE 4
885 #define MC_LOCKAS 5
886 #define MC_UNLOCKAS 6
887
888 int
889 sunos32_sys_mctl(l, v, retval)
890 struct lwp *l;
891 void *v;
892 register_t *retval;
893 {
894 struct sunos32_sys_mctl_args /* {
895 syscallarg(netbsd32_voidp) addr;
896 syscallarg(int) len;
897 syscallarg(int) func;
898 syscallarg(netbsd32_voidp) arg;
899 } */ *uap = v;
900
901 switch (SCARG(uap, func)) {
902 case MC_ADVISE: /* ignore for now */
903 return (0);
904 case MC_SYNC: /* translate to msync */
905 return (netbsd32___msync13(l, uap, retval));
906 default:
907 return (EINVAL);
908 }
909 }
910
911 int
912 sunos32_sys_setsockopt(l, v, retval)
913 struct lwp *l;
914 void *v;
915 register_t *retval;
916 {
917 struct sunos32_sys_setsockopt_args /* {
918 syscallarg(int) s;
919 syscallarg(int) level;
920 syscallarg(int) name;
921 syscallarg(netbsd32_caddr_t) val;
922 syscallarg(int) valsize;
923 } */ *uap = v;
924 struct proc *p = l->l_proc;
925 struct file *fp;
926 struct mbuf *m = NULL;
927 int error;
928
929 /* getsock() will use the descriptor for us */
930 if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
931 return (error);
932 #define SO_DONTLINGER (~SO_LINGER)
933 if (SCARG(uap, name) == SO_DONTLINGER) {
934 m = m_get(M_WAIT, MT_SOOPTS);
935 mtod(m, struct linger *)->l_onoff = 0;
936 m->m_len = sizeof(struct linger);
937 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
938 SO_LINGER, m);
939 goto out;
940 }
941 if (SCARG(uap, level) == IPPROTO_IP) {
942 #define SUNOS_IP_MULTICAST_IF 2
943 #define SUNOS_IP_MULTICAST_TTL 3
944 #define SUNOS_IP_MULTICAST_LOOP 4
945 #define SUNOS_IP_ADD_MEMBERSHIP 5
946 #define SUNOS_IP_DROP_MEMBERSHIP 6
947 static const int ipoptxlat[] = {
948 IP_MULTICAST_IF,
949 IP_MULTICAST_TTL,
950 IP_MULTICAST_LOOP,
951 IP_ADD_MEMBERSHIP,
952 IP_DROP_MEMBERSHIP
953 };
954 if (SCARG(uap, name) >= SUNOS_IP_MULTICAST_IF &&
955 SCARG(uap, name) <= SUNOS_IP_DROP_MEMBERSHIP) {
956 SCARG(uap, name) =
957 ipoptxlat[SCARG(uap, name) - SUNOS_IP_MULTICAST_IF];
958 }
959 }
960 if (SCARG(uap, valsize) > MLEN) {
961 error = EINVAL;
962 goto out;
963 }
964 if (SCARG(uap, val)) {
965 m = m_get(M_WAIT, MT_SOOPTS);
966 error = copyin((caddr_t)(u_long)SCARG(uap, val), mtod(m, caddr_t),
967 (u_int)SCARG(uap, valsize));
968 if (error) {
969 (void) m_free(m);
970 goto out;
971 }
972 m->m_len = SCARG(uap, valsize);
973 }
974 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
975 SCARG(uap, name), m);
976 out:
977 FILE_UNUSE(fp, l);
978 return (error);
979 }
980
981 static inline int sunos32_sys_socket_common(struct lwp *, register_t *,
982 int type);
983 static inline int
984 sunos32_sys_socket_common(l, retval, type)
985 struct lwp *l;
986 register_t *retval;
987 int type;
988 {
989 struct socket *so;
990 struct proc *p = l->l_proc;
991 struct file *fp;
992 int error, fd;
993
994 /* getsock() will use the descriptor for us */
995 fd = (int)*retval;
996 if ((error = getsock(p->p_fd, fd, &fp)) == 0) {
997 so = (struct socket *)fp->f_data;
998 if (type == SOCK_DGRAM)
999 so->so_options |= SO_BROADCAST;
1000 }
1001 FILE_UNUSE(fp, l);
1002 return (error);
1003 }
1004
1005 int
1006 sunos32_sys_socket(l, v, retval)
1007 struct lwp *l;
1008 void *v;
1009 register_t *retval;
1010 {
1011 struct sunos32_sys_socket_args /* {
1012 syscallarg(int) domain;
1013 syscallarg(int) type;
1014 syscallarg(int) protocol;
1015 } */ *uap = v;
1016 int error;
1017
1018 error = netbsd32_socket(l, v, retval);
1019 if (error)
1020 return (error);
1021 return sunos32_sys_socket_common(l, retval, SCARG(uap, type));
1022 }
1023
1024 int
1025 sunos32_sys_socketpair(l, v, retval)
1026 struct lwp *l;
1027 void *v;
1028 register_t *retval;
1029 {
1030 struct sunos32_sys_socketpair_args /* {
1031 syscallarg(int) domain;
1032 syscallarg(int) type;
1033 syscallarg(int) protocol;
1034 syscallarg(int *) rsv;
1035 } */ *uap = v;
1036 int error;
1037
1038 error = netbsd32_socketpair(l, v, retval);
1039 if (error)
1040 return (error);
1041 return sunos32_sys_socket_common(l, retval, SCARG(uap, type));
1042 }
1043
1044
1045 /*
1046 * XXX: This needs cleaning up.
1047 */
1048 int
1049 sunos32_sys_auditsys(l, v, retval)
1050 struct lwp *l;
1051 void *v;
1052 register_t *retval;
1053 {
1054 return 0;
1055 }
1056
1057 int
1058 sunos32_sys_uname(l, v, retval)
1059 struct lwp *l;
1060 void *v;
1061 register_t *retval;
1062 {
1063 struct sunos32_sys_uname_args /* {
1064 syscallarg(sunos32_utsnamep_t) name;
1065 } */ *uap = v;
1066 struct sunos_utsname sut;
1067
1068 memset(&sut, 0, sizeof(sut));
1069
1070 memcpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
1071 memcpy(sut.nodename, hostname, sizeof(sut.nodename));
1072 sut.nodename[sizeof(sut.nodename)-1] = '\0';
1073 memcpy(sut.release, osrelease, sizeof(sut.release) - 1);
1074 memcpy(sut.version, "1", sizeof(sut.version) - 1);
1075 memcpy(sut.machine, machine, sizeof(sut.machine) - 1);
1076
1077 return copyout((caddr_t)&sut, (caddr_t)(u_long)SCARG(uap, name),
1078 sizeof(struct sunos_utsname));
1079 }
1080
1081 int
1082 sunos32_sys_setpgrp(l, v, retval)
1083 struct lwp *l;
1084 void *v;
1085 register_t *retval;
1086 {
1087 struct sunos32_sys_setpgrp_args /* {
1088 syscallarg(int) pid;
1089 syscallarg(int) pgid;
1090 } */ *uap = v;
1091 struct proc *p = l->l_proc;
1092
1093 /*
1094 * difference to our setpgid call is to include backwards
1095 * compatibility to pre-setsid() binaries. Do setsid()
1096 * instead of setpgid() in those cases where the process
1097 * tries to create a new session the old way.
1098 */
1099 if (!SCARG(uap, pgid) &&
1100 (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
1101 return sys_setsid(l, uap, retval);
1102 else
1103 return netbsd32_setpgid(l, uap, retval);
1104 }
1105
1106 int
1107 sunos32_sys_open(l, v, retval)
1108 struct lwp *l;
1109 void *v;
1110 register_t *retval;
1111 {
1112 struct sunos32_sys_open_args /* {
1113 syscallarg(const netbsd32_charp) path;
1114 syscallarg(int) flags;
1115 syscallarg(int) mode;
1116 } */ *uap = v;
1117 struct proc *p = l->l_proc;
1118 struct sys_open_args ua;
1119 int lf, r;
1120 int noctty;
1121 int ret;
1122 caddr_t sg = stackgap_init(p, 0);
1123
1124 /* convert mode into NetBSD mode */
1125 lf = SCARG(uap, flags);
1126 noctty = lf & 0x8000;
1127 r = (lf & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
1128 r |= ((lf & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
1129 r |= ((lf & 0x0080) ? O_SHLOCK : 0);
1130 r |= ((lf & 0x0100) ? O_EXLOCK : 0);
1131 r |= ((lf & 0x2000) ? O_FSYNC : 0);
1132
1133 SUNOS32TOP_UAP(path, const char);
1134 SCARG(&ua, flags) = r;
1135 SUNOS32TO64_UAP(mode);
1136
1137 if (r & O_CREAT)
1138 SUNOS32_CHECK_ALT_CREAT(l, &sg, SCARG(&ua, path));
1139 else
1140 SUNOS32_CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
1141
1142 ret = sys_open(l, &ua, retval);
1143
1144 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
1145 struct filedesc *fdp = p->p_fd;
1146 struct file *fp;
1147
1148 fp = fd_getfile(fdp, *retval);
1149
1150 /* ignore any error, just give it a try */
1151 if (fp != NULL && fp->f_type == DTYPE_VNODE)
1152 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, l);
1153 }
1154 return ret;
1155 }
1156
1157 #if defined (NFSSERVER)
1158 int
1159 sunos32_sys_nfssvc(l, v, retval)
1160 struct lwp *l;
1161 void *v;
1162 register_t *retval;
1163 {
1164 #if 0
1165 struct sunos32_sys_nfssvc_args *uap = v;
1166 struct emul *e = p->p_emul;
1167 struct sys_nfssvc_args outuap;
1168 struct sockaddr sa;
1169 int error;
1170 caddr_t sg = stackgap_init(p, 0);
1171
1172 memset(&outuap, 0, sizeof outuap);
1173 SCARG(&outuap, fd) = SCARG(uap, fd);
1174 SCARG(&outuap, mskval) = stackgap_alloc(p, &sg, sizeof(sa));
1175 SCARG(&outuap, msklen) = sizeof(sa);
1176 SCARG(&outuap, mtchval) = stackgap_alloc(p, &sg, sizeof(sa));
1177 SCARG(&outuap, mtchlen) = sizeof(sa);
1178
1179 memset(&sa, 0, sizeof sa);
1180 if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
1181 return (error);
1182 if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
1183 return (error);
1184
1185 return nfssvc(l, &outuap, retval);
1186 #else
1187 return (ENOSYS);
1188 #endif
1189 }
1190 #endif /* NFSSERVER */
1191
1192 int
1193 sunos32_sys_ustat(l, v, retval)
1194 struct lwp *l;
1195 void *v;
1196 register_t *retval;
1197 {
1198 struct sunos32_sys_ustat_args /* {
1199 syscallarg(int) dev;
1200 syscallarg(sunos32_ustatp_t) buf;
1201 } */ *uap = v;
1202 struct sunos_ustat us;
1203 int error;
1204
1205 memset(&us, 0, sizeof us);
1206
1207 /*
1208 * XXX: should set f_tfree and f_tinode at least
1209 * How do we translate dev -> fstat? (and then to sunos_ustat)
1210 */
1211
1212 if ((error = copyout(&us, (caddr_t)(u_long)SCARG(uap, buf), sizeof us)) != 0)
1213 return (error);
1214 return 0;
1215 }
1216
1217 int
1218 sunos32_sys_quotactl(l, v, retval)
1219 struct lwp *l;
1220 void *v;
1221 register_t *retval;
1222 {
1223
1224 return EINVAL;
1225 }
1226
1227 int
1228 sunos32_sys_vhangup(l, v, retval)
1229 struct lwp *l;
1230 void *v;
1231 register_t *retval;
1232 {
1233 struct proc *p = l->l_proc;
1234 struct session *sp = p->p_session;
1235
1236 if (sp->s_ttyvp == 0)
1237 return 0;
1238
1239 if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp)
1240 pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
1241
1242 (void) ttywait(sp->s_ttyp);
1243 if (sp->s_ttyvp)
1244 VOP_REVOKE(sp->s_ttyvp, REVOKEALL);
1245 if (sp->s_ttyvp)
1246 vrele(sp->s_ttyvp);
1247 sp->s_ttyvp = NULL;
1248
1249 return 0;
1250 }
1251
1252 static int
1253 sunstatfs(sp, sbuf)
1254 struct statvfs *sp;
1255 caddr_t sbuf;
1256 {
1257 struct sunos_statfs ssfs;
1258
1259 memset(&ssfs, 0, sizeof ssfs);
1260 ssfs.f_type = 0;
1261 ssfs.f_bsize = sp->f_bsize;
1262 ssfs.f_blocks = sp->f_blocks;
1263 ssfs.f_bfree = sp->f_bfree;
1264 ssfs.f_bavail = sp->f_bavail;
1265 ssfs.f_files = sp->f_files;
1266 ssfs.f_ffree = sp->f_ffree;
1267 ssfs.f_fsid = sp->f_fsidx;
1268 return copyout((caddr_t)&ssfs, sbuf, sizeof ssfs);
1269 }
1270
1271 int
1272 sunos32_sys_statfs(l, v, retval)
1273 struct lwp *l;
1274 void *v;
1275 register_t *retval;
1276 {
1277 struct sunos32_sys_statfs_args /* {
1278 syscallarg(const netbsd32_charp) path;
1279 syscallarg(sunos32_statfsp_t) buf;
1280 } */ *uap = v;
1281 struct proc *p = l->l_proc;
1282 struct mount *mp;
1283 struct statvfs *sp;
1284 int error;
1285 struct nameidata nd;
1286 struct sys_statvfs1_args ua;
1287 caddr_t sg;
1288
1289 sg = stackgap_init(p, 0);
1290 SUNOS32TOP_UAP(path, const char);
1291 SUNOS32_CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
1292
1293 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(&ua, path), l);
1294 if ((error = namei(&nd)) != 0)
1295 return (error);
1296 mp = nd.ni_vp->v_mount;
1297 sp = &mp->mnt_stat;
1298 vrele(nd.ni_vp);
1299 if ((error = VFS_STATVFS(mp, sp, l)) != 0)
1300 return (error);
1301 sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
1302 return sunstatfs(sp, (caddr_t)(u_long)SCARG(uap, buf));
1303 }
1304
1305 int
1306 sunos32_sys_fstatfs(l, v, retval)
1307 struct lwp *l;
1308 void *v;
1309 register_t *retval;
1310 {
1311 struct sunos32_sys_fstatfs_args /* {
1312 syscallarg(int) fd;
1313 syscallarg(sunos32_statfsp_t) buf;
1314 } */ *uap = v;
1315 struct proc *p = l->l_proc;
1316 struct file *fp;
1317 struct mount *mp;
1318 struct statvfs *sp;
1319 int error;
1320
1321 /* getvnode() will use the descriptor for us */
1322 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
1323 return (error);
1324 mp = ((struct vnode *)fp->f_data)->v_mount;
1325 sp = &mp->mnt_stat;
1326 if ((error = VFS_STATVFS(mp, sp, l)) != 0)
1327 goto out;
1328 sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
1329 error = sunstatfs(sp, (caddr_t)(u_long)SCARG(uap, buf));
1330 out:
1331 FILE_UNUSE(fp, l);
1332 return (error);
1333 }
1334
1335 int
1336 sunos32_sys_exportfs(l, v, retval)
1337 struct lwp *l;
1338 void *v;
1339 register_t *retval;
1340 {
1341 /*
1342 * XXX: should perhaps translate into a mount(2)
1343 * with MOUNT_EXPORT?
1344 */
1345 return 0;
1346 }
1347
1348 int
1349 sunos32_sys_mknod(l, v, retval)
1350 struct lwp *l;
1351 void *v;
1352 register_t *retval;
1353 {
1354 struct sunos32_sys_mknod_args /* {
1355 syscallarg(const netbsd32_charp) path;
1356 syscallarg(int) mode;
1357 syscallarg(int) dev;
1358 } */ *uap = v;
1359 struct proc *p = l->l_proc;
1360 struct sys_mknod_args ua;
1361 caddr_t sg;
1362
1363 sg = stackgap_init(p, 0);
1364 SUNOS32TOP_UAP(path, const char);
1365 SUNOS32TO64_UAP(mode);
1366 SUNOS32TO64_UAP(dev);
1367 SUNOS32_CHECK_ALT_CREAT(l, &sg, SCARG(&ua, path));
1368
1369 /* netbsd32_mkfifo/mknod to not do alt checking */
1370 if (S_ISFIFO(SCARG(uap, mode)))
1371 return netbsd32_mkfifo(l, (struct netbsd32_mkfifo_args *)uap, retval);
1372
1373 return netbsd32_mknod(l, (struct netbsd32_mknod_args *)uap, retval);
1374 }
1375
1376 #define SUNOS_SC_ARG_MAX 1
1377 #define SUNOS_SC_CHILD_MAX 2
1378 #define SUNOS_SC_CLK_TCK 3
1379 #define SUNOS_SC_NGROUPS_MAX 4
1380 #define SUNOS_SC_OPEN_MAX 5
1381 #define SUNOS_SC_JOB_CONTROL 6
1382 #define SUNOS_SC_SAVED_IDS 7
1383 #define SUNOS_SC_VERSION 8
1384
1385 int
1386 sunos32_sys_sysconf(l, v, retval)
1387 struct lwp *l;
1388 void *v;
1389 register_t *retval;
1390 {
1391 struct sunos32_sys_sysconf_args /* {
1392 syscallarg(int) name;
1393 } */ *uap = v;
1394 extern int maxfiles;
1395
1396 switch(SCARG(uap, name)) {
1397 case SUNOS_SC_ARG_MAX:
1398 *retval = ARG_MAX;
1399 break;
1400 case SUNOS_SC_CHILD_MAX:
1401 *retval = maxproc;
1402 break;
1403 case SUNOS_SC_CLK_TCK:
1404 *retval = 60; /* should this be `hz', ie. 100? */
1405 break;
1406 case SUNOS_SC_NGROUPS_MAX:
1407 *retval = NGROUPS_MAX;
1408 break;
1409 case SUNOS_SC_OPEN_MAX:
1410 *retval = maxfiles;
1411 break;
1412 case SUNOS_SC_JOB_CONTROL:
1413 *retval = 1;
1414 break;
1415 case SUNOS_SC_SAVED_IDS:
1416 #ifdef _POSIX_SAVED_IDS
1417 *retval = 1;
1418 #else
1419 *retval = 0;
1420 #endif
1421 break;
1422 case SUNOS_SC_VERSION:
1423 *retval = 198808;
1424 break;
1425 default:
1426 return EINVAL;
1427 }
1428 return 0;
1429 }
1430
1431 #define SUNOS_RLIMIT_NOFILE 6 /* Other RLIMIT_* are the same */
1432 #define SUNOS_RLIM_NLIMITS 7
1433
1434 int
1435 sunos32_sys_getrlimit(l, v, retval)
1436 struct lwp *l;
1437 void *v;
1438 register_t *retval;
1439 {
1440 struct sunos32_sys_getrlimit_args /* {
1441 syscallarg(u_int) which;
1442 syscallarg(netbsd32_orlimitp_t) rlp;
1443 } */ *uap = v;
1444
1445 if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
1446 return EINVAL;
1447
1448 if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
1449 SCARG(uap, which) = RLIMIT_NOFILE;
1450
1451 return compat_43_netbsd32_ogetrlimit(l, uap, retval);
1452 }
1453
1454 int
1455 sunos32_sys_setrlimit(l, v, retval)
1456 struct lwp *l;
1457 void *v;
1458 register_t *retval;
1459 {
1460 struct sunos32_sys_setrlimit_args /* {
1461 syscallarg(u_int) which;
1462 syscallarg(netbsd32_orlimitp_t) rlp;
1463 } */ *uap = v;
1464
1465 if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
1466 return EINVAL;
1467
1468 if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
1469 SCARG(uap, which) = RLIMIT_NOFILE;
1470
1471 return compat_43_netbsd32_osetrlimit(l, uap, retval);
1472 }
1473
1474 /* for the m68k machines */
1475 #ifndef PT_GETFPREGS
1476 #define PT_GETFPREGS -1
1477 #endif
1478 #ifndef PT_SETFPREGS
1479 #define PT_SETFPREGS -1
1480 #endif
1481
1482 static const int sreq2breq[] = {
1483 PT_TRACE_ME, PT_READ_I, PT_READ_D, -1,
1484 PT_WRITE_I, PT_WRITE_D, -1, PT_CONTINUE,
1485 PT_KILL, -1, PT_ATTACH, PT_DETACH,
1486 PT_GETREGS, PT_SETREGS, PT_GETFPREGS, PT_SETFPREGS
1487 };
1488 static const int nreqs = sizeof(sreq2breq) / sizeof(sreq2breq[0]);
1489
1490 int
1491 sunos32_sys_ptrace(l, v, retval)
1492 struct lwp *l;
1493 void *v;
1494 register_t *retval;
1495 {
1496 struct sunos32_sys_ptrace_args /* {
1497 syscallarg(int) req;
1498 syscallarg(pid_t) pid;
1499 syscallarg(netbsd32_caddr_t) addr;
1500 syscallarg(int) data;
1501 syscallarg(netbsd32_charp) addr2;
1502 } */ *uap = v;
1503 struct netbsd32_ptrace_args pa;
1504 int req;
1505
1506 req = SCARG(uap, req);
1507
1508 if (req < 0 || req >= nreqs)
1509 return (EINVAL);
1510
1511 req = sreq2breq[req];
1512 if (req == -1)
1513 return (EINVAL);
1514
1515 SCARG(&pa, req) = req;
1516 SCARG(&pa, pid) = (pid_t)SCARG(uap, pid);
1517 SCARG(&pa, addr) = SCARG(uap, addr);
1518 SCARG(&pa, data) = SCARG(uap, data);
1519
1520 return netbsd32_ptrace(l, &pa, retval);
1521 }
1522
1523 /*
1524 * SunOS reboot system call (for compatibility).
1525 * Sun lets you pass in a boot string which the PROM
1526 * saves and provides to the next boot program.
1527 */
1528
1529 #define SUNOS_RB_ASKNAME 0x001
1530 #define SUNOS_RB_SINGLE 0x002
1531 #define SUNOS_RB_NOSYNC 0x004
1532 #define SUNOS_RB_HALT 0x008
1533 #define SUNOS_RB_DUMP 0x080
1534 #define SUNOS_RB_STRING 0x200
1535
1536 static struct sunos_howto_conv {
1537 int sun_howto;
1538 int bsd_howto;
1539 } sunos_howto_conv[] = {
1540 { SUNOS_RB_ASKNAME, RB_ASKNAME },
1541 { SUNOS_RB_SINGLE, RB_SINGLE },
1542 { SUNOS_RB_NOSYNC, RB_NOSYNC },
1543 { SUNOS_RB_HALT, RB_HALT },
1544 { SUNOS_RB_DUMP, RB_DUMP },
1545 { SUNOS_RB_STRING, RB_STRING },
1546 { 0x000, 0 },
1547 };
1548
1549 int
1550 sunos32_sys_reboot(l, v, retval)
1551 struct lwp *l;
1552 void *v;
1553 register_t *retval;
1554 {
1555 struct sunos32_sys_reboot_args /* {
1556 syscallarg(int) howto;
1557 syscallarg(netbsd32_charp) bootstr;
1558 } */ *uap = v;
1559 struct proc *p = l->l_proc;
1560 struct sys_reboot_args ua;
1561 struct sunos_howto_conv *convp;
1562 int error, bsd_howto, sun_howto;
1563 char *bootstr;
1564
1565 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
1566 return (error);
1567
1568 /*
1569 * Convert howto bits to BSD format.
1570 */
1571 sun_howto = SCARG(uap, howto);
1572 bsd_howto = 0;
1573 convp = sunos_howto_conv;
1574 while (convp->sun_howto) {
1575 if (sun_howto & convp->sun_howto)
1576 bsd_howto |= convp->bsd_howto;
1577 convp++;
1578 }
1579
1580 /*
1581 * Sun RB_STRING (Get user supplied bootstring.)
1582 * If the machine supports passing a string to the
1583 * next booted kernel.
1584 */
1585 if (sun_howto & SUNOS_RB_STRING)
1586 bootstr = (char *)(u_long)SCARG(uap, bootstr);
1587 else
1588 bootstr = NULL;
1589
1590 SCARG(&ua, opt) = bsd_howto;
1591 SCARG(&ua, bootstr) = bootstr;
1592 return (sys_reboot(l, &ua, retval));
1593 }
1594
1595 /*
1596 * Generalized interface signal handler, 4.3-compatible.
1597 */
1598 /* ARGSUSED */
1599 int
1600 sunos32_sys_sigvec(l, v, retval)
1601 struct lwp *l;
1602 void *v;
1603 register_t *retval;
1604 {
1605 struct sunos32_sys_sigvec_args /* {
1606 syscallarg(int) signum;
1607 syscallarg(struct sigvec *) nsv;
1608 syscallarg(struct sigvec *) osv;
1609 } */ *uap = v;
1610 struct proc *p = l->l_proc;
1611 struct netbsd32_sigvec sv;
1612 struct sigaction nsa, osa;
1613 int error;
1614
1615 if (SCARG(uap, nsv)) {
1616 error = copyin((caddr_t)(u_long)SCARG(uap, nsv), &sv, sizeof(sv));
1617 if (error != 0)
1618 return (error);
1619
1620 /*
1621 * SunOS uses the mask 0x0004 as SV_RESETHAND
1622 * meaning: `reset to SIG_DFL on delivery'.
1623 * We support only the bits in: 0xF
1624 * (those bits are the same as ours)
1625 */
1626 if (sv.sv_flags & ~0xF)
1627 return (EINVAL);
1628
1629 sunos32_sigvec_to_sigaction(&sv, &nsa);
1630 }
1631 error = sigaction1(p, SCARG(uap, signum),
1632 SCARG(uap, nsv) ? &nsa : 0,
1633 SCARG(uap, osv) ? &osa : 0,
1634 NULL, 0);
1635 if (error != 0)
1636 return (error);
1637
1638 if (SCARG(uap, osv)) {
1639 sunos32_sigvec_from_sigaction(&sv, &osa);
1640 error = copyout(&sv, (caddr_t)(u_long)SCARG(uap, osv), sizeof(sv));
1641 if (error != 0)
1642 return (error);
1643 }
1644
1645 return (0);
1646 }
1647