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