sunos32_misc.c revision 1.15 1 /* $NetBSD: sunos32_misc.c,v 1.15 2003/01/18 08:38:15 thorpej 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. All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by the University of
56 * California, Berkeley and its contributors.
57 * 4. Neither the name of the University nor the names of its contributors
58 * may be used to endorse or promote products derived from this software
59 * without specific prior written permission.
60 *
61 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
62 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
65 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
67 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71 * SUCH DAMAGE.
72 *
73 * @(#)sunos_misc.c 8.1 (Berkeley) 6/18/93
74 *
75 * Header: sunos_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
76 */
77
78 /*
79 * SunOS compatibility module, 64-bit kernel version
80 *
81 * SunOS system calls that are implemented differently in BSD are
82 * handled here.
83 */
84
85 #include <sys/cdefs.h>
86 __KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.15 2003/01/18 08:38:15 thorpej Exp $");
87
88 #define COMPAT_SUNOS 1
89
90 #if defined(_KERNEL_OPT)
91 #include "opt_nfsserver.h"
92 #include "opt_compat_43.h"
93 #include "opt_compat_netbsd.h"
94 #include "fs_nfs.h"
95 #endif
96
97 #include <sys/param.h>
98 #include <sys/systm.h>
99 #include <sys/namei.h>
100 #include <sys/proc.h>
101 #include <sys/dirent.h>
102 #include <sys/file.h>
103 #include <sys/stat.h>
104 #include <sys/filedesc.h>
105 #include <sys/ioctl.h>
106 #include <sys/kernel.h>
107 #include <sys/reboot.h>
108 #include <sys/malloc.h>
109 #include <sys/mbuf.h>
110 #include <sys/mman.h>
111 #include <sys/mount.h>
112 #include <sys/ptrace.h>
113 #include <sys/resource.h>
114 #include <sys/resourcevar.h>
115 #include <sys/signal.h>
116 #include <sys/signalvar.h>
117 #include <sys/socket.h>
118 #include <sys/tty.h>
119 #include <sys/vnode.h>
120 #include <sys/uio.h>
121 #include <sys/wait.h>
122 #include <sys/utsname.h>
123 #include <sys/unistd.h>
124 #include <sys/sa.h>
125 #include <sys/syscallargs.h>
126 #include <sys/conf.h>
127 #include <sys/socketvar.h>
128 #include <sys/exec.h>
129 #include <sys/swap.h>
130
131 #include <compat/netbsd32/netbsd32.h>
132 #include <compat/netbsd32/netbsd32_syscallargs.h>
133 #include <compat/sunos32/sunos32.h>
134 #include <compat/sunos32/sunos32_dirent.h>
135 #include <compat/sunos32/sunos32_syscallargs.h>
136 #include <compat/common/compat_util.h>
137
138 #include <netinet/in.h>
139
140 #include <miscfs/specfs/specdev.h>
141
142 #include <nfs/rpcv2.h>
143 #include <nfs/nfsproto.h>
144 #include <nfs/nfs.h>
145 #include <nfs/nfsmount.h>
146
147 static void sunos32_sigvec_to_sigaction(const struct netbsd32_sigvec *, struct sigaction *);
148 static void sunos32_sigvec_from_sigaction(struct netbsd32_sigvec *, const struct sigaction *);
149
150 static int sunstatfs __P((struct statfs *, caddr_t));
151
152 static void
153 sunos32_sigvec_to_sigaction(sv, sa)
154 const struct netbsd32_sigvec *sv;
155 struct sigaction *sa;
156 {
157 /*XXX*/ extern void compat_43_sigmask_to_sigset __P((const int *, sigset_t *));
158
159 sa->sa_handler = (void *)(u_long)sv->sv_handler;
160 compat_43_sigmask_to_sigset(&sv->sv_mask, &sa->sa_mask);
161 sa->sa_flags = sv->sv_flags ^ SA_RESTART;
162 }
163
164 static
165 void sunos32_sigvec_from_sigaction(sv, sa)
166 struct netbsd32_sigvec *sv;
167 const struct sigaction *sa;
168 {
169 /*XXX*/ extern void compat_43_sigset_to_sigmask __P((const sigset_t *, int *));
170
171 sv->sv_handler = (netbsd32_voidp)(u_long)sa->sa_handler;
172 compat_43_sigset_to_sigmask(&sa->sa_mask, &sv->sv_mask);
173 sv->sv_flags = sa->sa_flags ^ SA_RESTART;
174 }
175
176 int
177 sunos32_sys_stime(l, v, retval)
178 struct lwp *l;
179 void *v;
180 register_t *retval;
181 {
182 struct sunos32_sys_stime_args /* {
183 syscallarg(sunos32_time_tp) tp;
184 } */ *uap = v;
185 struct proc *p = l->l_proc;
186 struct sys_settimeofday_args ap;
187 caddr_t sg = stackgap_init(p, 0);
188 struct netbsd32_timeval ntv;
189 struct timeval tv, *sgtvp;
190 int error;
191
192 error = copyin((caddr_t)(u_long)SCARG(uap, tp), &ntv.tv_sec, sizeof(ntv.tv_sec));
193 if (error)
194 return error;
195 tv.tv_sec = ntv.tv_sec;
196 tv.tv_usec = 0;
197
198 SCARG(&ap, tv) = sgtvp = stackgap_alloc(p, &sg, sizeof(struct timeval));
199 SCARG(&ap, tzp) = NULL;
200
201 error = copyout(&tv, sgtvp, sizeof(struct timeval));
202 if (error)
203 return error;
204
205 return sys_settimeofday(l, &ap, retval);
206 }
207
208 int
209 sunos32_sys_wait4(l, v, retval)
210 struct lwp *l;
211 void *v;
212 register_t *retval;
213 {
214 struct sunos32_sys_wait4_args /* {
215 syscallarg(int) pid;
216 syscallarg(netbsd32_intp) status;
217 syscallarg(int) options;
218 syscallarg(netbsd32_rusagep_t) rusage;
219 } */ *uap = v;
220
221 if (SCARG(uap, pid) == 0)
222 SCARG(uap, pid) = WAIT_ANY;
223 return (netbsd32_wait4(l, uap, retval));
224 }
225
226 int
227 sunos32_sys_creat(l, v, retval)
228 struct lwp *l;
229 void *v;
230 register_t *retval;
231 {
232 struct sunos32_sys_creat_args /* {
233 syscallarg(const netbsd32_charp) path;
234 syscallarg(int) mode;
235 } */ *uap = v;
236 struct proc *p = l->l_proc;
237 struct sys_open_args ua;
238 caddr_t sg = stackgap_init(p, 0);
239
240 SUNOS32TOP_UAP(path, const char);
241 SCARG(&ua, flags) = O_WRONLY | O_CREAT | O_TRUNC;
242 SUNOS32TO64_UAP(mode);
243
244 SUNOS32_CHECK_ALT_CREAT(p, &sg, SCARG(&ua, path));
245
246 return (sys_open(l, &ua, retval));
247 }
248
249 int
250 sunos32_sys_access(l, v, retval)
251 struct lwp *l;
252 void *v;
253 register_t *retval;
254 {
255 struct sunos32_sys_access_args /* {
256 syscallarg(const netbsd32_charp) path;
257 syscallarg(int) flags;
258 } */ *uap = v;
259 struct proc *p = l->l_proc;
260 struct sys_access_args ua;
261 caddr_t sg = stackgap_init(p, 0);
262
263 SUNOS32TOP_UAP(path, const char);
264 SUNOS32TO64_UAP(flags);
265 SUNOS32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
266
267 return (sys_access(l, &ua, retval));
268 }
269
270 static __inline void sunos32_from___stat13 __P((struct stat *, struct netbsd32_stat43 *));
271
272 static __inline void
273 sunos32_from___stat13(sbp, sb32p)
274 struct stat *sbp;
275 struct netbsd32_stat43 *sb32p;
276 {
277 sb32p->st_dev = sbp->st_dev;
278 sb32p->st_ino = sbp->st_ino;
279 sb32p->st_mode = sbp->st_mode;
280 sb32p->st_nlink = sbp->st_nlink;
281 sb32p->st_uid = sbp->st_uid;
282 sb32p->st_gid = sbp->st_gid;
283 sb32p->st_rdev = sbp->st_rdev;
284 if (sbp->st_size < (quad_t)1 << 32)
285 sb32p->st_size = sbp->st_size;
286 else
287 sb32p->st_size = -2;
288 sb32p->st_atimespec.tv_sec = (netbsd32_time_t)sbp->st_atimespec.tv_sec;
289 sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
290 sb32p->st_mtimespec.tv_sec = (netbsd32_time_t)sbp->st_mtimespec.tv_sec;
291 sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
292 sb32p->st_ctimespec.tv_sec = (netbsd32_time_t)sbp->st_ctimespec.tv_sec;
293 sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
294 sb32p->st_blksize = sbp->st_blksize;
295 sb32p->st_blocks = sbp->st_blocks;
296 sb32p->st_flags = sbp->st_flags;
297 sb32p->st_gen = sbp->st_gen;
298 }
299
300
301 int
302 sunos32_sys_stat(l, v, retval)
303 struct lwp *l;
304 void *v;
305 register_t *retval;
306 {
307 struct sunos32_sys_stat_args /* {
308 syscallarg(const netbsd32_charp) path;
309 syscallarg(netbsd32_stat43p_t) ub;
310 } */ *uap = v;
311 struct proc *p = l->l_proc;
312 struct netbsd32_stat43 sb32;
313 struct stat sb;
314 struct nameidata nd;
315 caddr_t sg;
316 const char *path;
317 int error;
318
319 path = (char *)(u_long)SCARG(uap, path);
320 sg = stackgap_init(p, 0);
321 SUNOS32_CHECK_ALT_EXIST(p, &sg, path);
322
323 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, path, p);
324 if ((error = namei(&nd)) != 0)
325 return (error);
326 error = vn_stat(nd.ni_vp, &sb, p);
327 vput(nd.ni_vp);
328 if (error)
329 return (error);
330 sunos32_from___stat13(&sb, &sb32);
331 error = copyout((caddr_t)&sb32, (caddr_t)(u_long)SCARG(uap, ub), sizeof (sb32));
332 return (error);
333 }
334
335 int
336 sunos32_sys_lstat(l, v, retval)
337 struct lwp *l;
338 void *v;
339 register_t *retval;
340 {
341 struct sunos32_sys_lstat_args /* {
342 syscallarg(const netbsd32_charp) path;
343 syscallarg(netbsd32_stat43p_t) ub;
344 } */ *uap = v;
345 struct vnode *vp, *dvp;
346 struct proc *p = l->l_proc;
347 struct stat sb, sb1;
348 struct netbsd32_stat43 sb32;
349 int error;
350 struct nameidata nd;
351 int ndflags;
352 const char *path;
353 caddr_t sg;
354
355 path = (char *)(u_long)SCARG(uap, path);
356 sg = stackgap_init(p, 0);
357 SUNOS32_CHECK_ALT_EXIST(p, &sg, path);
358
359 ndflags = NOFOLLOW | LOCKLEAF | LOCKPARENT;
360 again:
361 NDINIT(&nd, LOOKUP, ndflags, UIO_USERSPACE, path, p);
362 if ((error = namei(&nd))) {
363 if (error == EISDIR && (ndflags & LOCKPARENT) != 0) {
364 /*
365 * Should only happen on '/'. Retry without LOCKPARENT;
366 * this is safe since the vnode won't be a VLNK.
367 */
368 ndflags &= ~LOCKPARENT;
369 goto again;
370 }
371 return (error);
372 }
373 /*
374 * For symbolic links, always return the attributes of its
375 * containing directory, except for mode, size, and links.
376 */
377 vp = nd.ni_vp;
378 dvp = nd.ni_dvp;
379 if (vp->v_type != VLNK) {
380 if ((ndflags & LOCKPARENT) != 0) {
381 if (dvp == vp)
382 vrele(dvp);
383 else
384 vput(dvp);
385 }
386 error = vn_stat(vp, &sb, p);
387 vput(vp);
388 if (error)
389 return (error);
390 } else {
391 error = vn_stat(dvp, &sb, p);
392 vput(dvp);
393 if (error) {
394 vput(vp);
395 return (error);
396 }
397 error = vn_stat(vp, &sb1, p);
398 vput(vp);
399 if (error)
400 return (error);
401 sb.st_mode &= ~S_IFDIR;
402 sb.st_mode |= S_IFLNK;
403 sb.st_nlink = sb1.st_nlink;
404 sb.st_size = sb1.st_size;
405 sb.st_blocks = sb1.st_blocks;
406 }
407 sunos32_from___stat13(&sb, &sb32);
408 error = copyout((caddr_t)&sb32, (caddr_t)(u_long)SCARG(uap, ub), sizeof (sb32));
409 return (error);
410 }
411
412 int
413 sunos32_sys_execv(l, v, retval)
414 struct lwp *l;
415 void *v;
416 register_t *retval;
417 {
418 struct sunos32_sys_execv_args /* {
419 syscallarg(const char *) path;
420 syscallarg(char **) argv;
421 } */ *uap = v;
422 struct proc *p = l->l_proc;
423 struct sys_execve_args ua;
424 caddr_t sg;
425
426 SUNOS32TOP_UAP(path, const char);
427 SUNOS32TOP_UAP(argp, char *);
428 SCARG(&ua, envp) = NULL;
429 sg = stackgap_init(p, 0);
430 SUNOS32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
431
432 return netbsd32_execve2(l, &ua, retval);
433 }
434
435 int
436 sunos32_sys_execve(l, v, retval)
437 struct lwp *l;
438 void *v;
439 register_t *retval;
440 {
441 struct sunos32_sys_execve_args /* {
442 syscallarg(const char *) path;
443 syscallarg(char **) argv;
444 syscallarg(char **) envp;
445 } */ *uap = v;
446 struct proc *p = l->l_proc;
447 struct sys_execve_args ua;
448 caddr_t sg;
449
450 SUNOS32TOP_UAP(path, const char);
451 SUNOS32TOP_UAP(argp, char *);
452 SUNOS32TOP_UAP(envp, char *);
453 sg = stackgap_init(p, 0);
454 SUNOS32_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
455
456 return netbsd32_execve2(l, &ua, retval);
457 }
458
459 int
460 sunos32_sys_omsync(l, v, retval)
461 struct lwp *l;
462 void *v;
463 register_t *retval;
464 {
465 struct sunos32_sys_omsync_args /* {
466 syscallarg(netbsd32_caddr_t) addr;
467 syscallarg(netbsd32_size_t) len;
468 syscallarg(int) flags;
469 } */ *uap = v;
470 struct netbsd32___msync13_args ouap;
471
472 SCARG(&ouap, addr) = SCARG(uap, addr);
473 SCARG(&ouap, len) = SCARG(uap, len);
474 SCARG(&ouap, flags) = SCARG(uap, flags);
475
476 return (netbsd32___msync13(l, &ouap, retval));
477 }
478
479 int
480 sunos32_sys_unmount(l, v, retval)
481 struct lwp *l;
482 void *v;
483 register_t *retval;
484 {
485 struct sunos32_sys_unmount_args /* {
486 syscallarg(netbsd32_charp) path;
487 } */ *uap = v;
488 struct sys_unmount_args ua;
489
490 SUNOS32TOP_UAP(path, const char);
491 SCARG(&ua, flags) = 0;
492
493 return (sys_unmount(l, &ua, retval));
494 }
495
496 /*
497 * Conversion table for SunOS NFS mount flags.
498 */
499 static struct {
500 int sun_flg;
501 int bsd_flg;
502 } sunnfs_flgtab[] = {
503 { SUNNFS_SOFT, NFSMNT_SOFT },
504 { SUNNFS_WSIZE, NFSMNT_WSIZE },
505 { SUNNFS_RSIZE, NFSMNT_RSIZE },
506 { SUNNFS_TIMEO, NFSMNT_TIMEO },
507 { SUNNFS_RETRANS, NFSMNT_RETRANS },
508 { SUNNFS_HOSTNAME, 0 }, /* Ignored */
509 { SUNNFS_INT, NFSMNT_INT },
510 { SUNNFS_NOAC, 0 }, /* Ignored */
511 { SUNNFS_ACREGMIN, 0 }, /* Ignored */
512 { SUNNFS_ACREGMAX, 0 }, /* Ignored */
513 { SUNNFS_ACDIRMIN, 0 }, /* Ignored */
514 { SUNNFS_ACDIRMAX, 0 }, /* Ignored */
515 { SUNNFS_SECURE, 0 }, /* Ignored */
516 { SUNNFS_NOCTO, 0 }, /* Ignored */
517 { SUNNFS_POSIX, 0 } /* Ignored */
518 };
519
520 int
521 sunos32_sys_mount(l, v, retval)
522 struct lwp *l;
523 void *v;
524 register_t *retval;
525 {
526 struct sunos32_sys_mount_args /* {
527 syscallarg(netbsd32_charp) type;
528 syscallarg(netbsd32_charp) path;
529 syscallarg(int) flags;
530 syscallarg(netbsd32_caddr_t) data;
531 } */ *uap = v;
532 struct proc *p = l->l_proc;
533 struct sys_mount_args ua;
534 int oflags = SCARG(uap, flags), nflags, error;
535 char fsname[MFSNAMELEN];
536 caddr_t sg = stackgap_init(p, 0);
537
538 if (oflags & (SUNM_NOSUB | SUNM_SYS5))
539 return (EINVAL);
540 if ((oflags & SUNM_NEWTYPE) == 0)
541 return (EINVAL);
542 nflags = 0;
543 if (oflags & SUNM_RDONLY)
544 nflags |= MNT_RDONLY;
545 if (oflags & SUNM_NOSUID)
546 nflags |= MNT_NOSUID;
547 if (oflags & SUNM_REMOUNT)
548 nflags |= MNT_UPDATE;
549 SCARG(uap, flags) = nflags;
550
551 error = copyinstr((caddr_t)(u_long)SCARG(uap, type), fsname,
552 sizeof fsname, (size_t *)0);
553 if (error)
554 return (error);
555
556 if (strncmp(fsname, "4.2", sizeof fsname) == 0) {
557 SCARG(uap, type) = (netbsd32_charp)(u_long)stackgap_alloc(p, &sg, sizeof("ffs"));
558 error = copyout("ffs", (caddr_t)(u_long)SCARG(uap, type), sizeof("ffs"));
559 if (error)
560 return (error);
561 } else if (strncmp(fsname, "nfs", sizeof fsname) == 0) {
562 struct sunos_nfs_args sna;
563 struct sockaddr_in sain;
564 struct nfs_args na; /* XXX */
565 struct sockaddr sa;
566 int n;
567
568 error = copyin((caddr_t)(u_long)SCARG(uap, data), &sna, sizeof sna);
569 if (error)
570 return (error);
571 error = copyin(sna.addr, &sain, sizeof sain);
572 if (error)
573 return (error);
574 memcpy(&sa, &sain, sizeof sa);
575 sa.sa_len = sizeof(sain);
576 SCARG(uap, data) = (netbsd32_charp)(u_long)stackgap_alloc(p, &sg, sizeof(na));
577 na.version = NFS_ARGSVERSION;
578 na.addr = stackgap_alloc(p, &sg, sizeof(struct sockaddr));
579 na.addrlen = sizeof(struct sockaddr);
580 na.sotype = SOCK_DGRAM;
581 na.proto = IPPROTO_UDP;
582 na.fh = (void *)sna.fh;
583 na.fhsize = NFSX_V2FH;
584 na.flags = 0;
585 n = sizeof(sunnfs_flgtab) / sizeof(sunnfs_flgtab[0]);
586 while (--n >= 0)
587 if (sna.flags & sunnfs_flgtab[n].sun_flg)
588 na.flags |= sunnfs_flgtab[n].bsd_flg;
589 na.wsize = sna.wsize;
590 na.rsize = sna.rsize;
591 if (na.flags & NFSMNT_RSIZE) {
592 na.flags |= NFSMNT_READDIRSIZE;
593 na.readdirsize = na.rsize;
594 }
595 na.timeo = sna.timeo;
596 na.retrans = sna.retrans;
597 na.hostname = (char *)(u_long)sna.hostname;
598
599 error = copyout(&sa, na.addr, sizeof sa);
600 if (error)
601 return (error);
602 error = copyout(&na, (caddr_t)(u_long)SCARG(uap, data), sizeof na);
603 if (error)
604 return (error);
605 }
606 SUNOS32TOP_UAP(type, const char);
607 SUNOS32TOP_UAP(path, const char);
608 SUNOS32TO64_UAP(flags);
609 SUNOS32TOP_UAP(data, void);
610 return (sys_mount(l, &ua, retval));
611 }
612
613 #if defined(NFS)
614 int
615 async_daemon(l, v, retval)
616 struct lwp *l;
617 void *v;
618 register_t *retval;
619 {
620 struct netbsd32_nfssvc_args ouap;
621
622 SCARG(&ouap, flag) = NFSSVC_BIOD;
623 SCARG(&ouap, argp) = NULL;
624
625 return (netbsd32_nfssvc(l, &ouap, retval));
626 }
627 #endif /* NFS */
628
629 void native_to_sunos_sigset __P((const sigset_t *, int *));
630 void sunos_to_native_sigset __P((const int, sigset_t *));
631
632 __inline__ void
633 native_to_sunos_sigset(ss, mask)
634 const sigset_t *ss;
635 int *mask;
636 {
637 *mask = ss->__bits[0];
638 }
639
640 __inline__ void
641 sunos_to_native_sigset(mask, ss)
642 const int mask;
643 sigset_t *ss;
644 {
645
646 ss->__bits[0] = mask;
647 ss->__bits[1] = 0;
648 ss->__bits[2] = 0;
649 ss->__bits[3] = 0;
650 }
651
652 int
653 sunos32_sys_sigpending(l, v, retval)
654 struct lwp *l;
655 void *v;
656 register_t *retval;
657 {
658 struct sunos32_sys_sigpending_args /* {
659 syscallarg(netbsd32_intp) mask;
660 } */ *uap = v;
661 struct proc *p = l->l_proc;
662 sigset_t ss;
663 int mask;
664
665 sigpending1(p, &ss);
666 native_to_sunos_sigset(&ss, &mask);
667
668 return (copyout((caddr_t)(u_long)&mask, (caddr_t)(u_long)SCARG(uap, mask), sizeof(int)));
669 }
670
671 int
672 sunos32_sys_sigsuspend(l, v, retval)
673 struct lwp *l;
674 void *v;
675 register_t *retval;
676 {
677 struct sunos32_sys_sigsuspend_args /* {
678 syscallarg(int) mask;
679 } */ *uap = v;
680 int mask;
681 struct proc *p = l->l_proc;
682 sigset_t ss;
683
684 mask = SCARG(uap, mask);
685 sunos_to_native_sigset(mask, &ss);
686 return (sigsuspend1(p, &ss));
687 }
688
689 /*
690 * Read Sun-style directory entries. We suck them into kernel space so
691 * that they can be massaged before being copied out to user code. Like
692 * SunOS, we squish out `empty' entries.
693 *
694 * This is quite ugly, but what do you expect from compatibility code?
695 */
696 int
697 sunos32_sys_getdents(l, v, retval)
698 struct lwp *l;
699 void *v;
700 register_t *retval;
701 {
702 struct sunos32_sys_getdents_args /* {
703 syscallarg(int) fd;
704 syscallarg(netbsd32_charp) buf;
705 syscallarg(int) nbytes;
706 } */ *uap = v;
707 struct proc *p = l->l_proc;
708 struct dirent *bdp;
709 struct vnode *vp;
710 caddr_t inp, buf; /* BSD-format */
711 int len, reclen; /* BSD-format */
712 caddr_t outp; /* Sun-format */
713 int resid, sunos_reclen;/* Sun-format */
714 struct file *fp;
715 struct uio auio;
716 struct iovec aiov;
717 struct sunos32_dirent idb;
718 off_t off; /* true file offset */
719 int buflen, error, eofflag;
720 off_t *cookiebuf, *cookie;
721 int ncookies;
722
723 /* getvnode() will use the descriptor for us */
724 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
725 return (error);
726
727 if ((fp->f_flag & FREAD) == 0) {
728 error = EBADF;
729 goto out1;
730 }
731
732 vp = (struct vnode *)fp->f_data;
733 if (vp->v_type != VDIR) {
734 error = EINVAL;
735 goto out1;
736 }
737
738 buflen = min(MAXBSIZE, SCARG(uap, nbytes));
739 buf = malloc(buflen, M_TEMP, M_WAITOK);
740 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
741 off = fp->f_offset;
742 again:
743 aiov.iov_base = buf;
744 aiov.iov_len = buflen;
745 auio.uio_iov = &aiov;
746 auio.uio_iovcnt = 1;
747 auio.uio_rw = UIO_READ;
748 auio.uio_segflg = UIO_SYSSPACE;
749 auio.uio_procp = p;
750 auio.uio_resid = buflen;
751 auio.uio_offset = off;
752 /*
753 * First we read into the malloc'ed buffer, then
754 * we massage it into user space, one record at a time.
755 */
756 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
757 &ncookies);
758 if (error)
759 goto out;
760
761 inp = buf;
762 outp = (caddr_t)(u_long)SCARG(uap, buf);
763 resid = SCARG(uap, nbytes);
764 if ((len = buflen - auio.uio_resid) == 0)
765 goto eof;
766
767 for (cookie = cookiebuf; len > 0; len -= reclen) {
768 bdp = (struct dirent *)inp;
769 reclen = bdp->d_reclen;
770 if (reclen & 3)
771 panic("sunos_getdents");
772 if ((*cookie >> 32) != 0) {
773 compat_offseterr(vp, "sunos_getdents");
774 error = EINVAL;
775 goto out;
776 }
777 if (bdp->d_fileno == 0) {
778 inp += reclen; /* it is a hole; squish it out */
779 off = *cookie++;
780 continue;
781 }
782 sunos_reclen = SUNOS32_RECLEN(&idb, bdp->d_namlen);
783 if (reclen > len || resid < sunos_reclen) {
784 /* entry too big for buffer, so just stop */
785 outp++;
786 break;
787 }
788 off = *cookie++; /* each entry points to next */
789 /*
790 * Massage in place to make a Sun-shaped dirent (otherwise
791 * we have to worry about touching user memory outside of
792 * the copyout() call).
793 */
794 idb.d_fileno = bdp->d_fileno;
795 idb.d_off = off;
796 idb.d_reclen = sunos_reclen;
797 idb.d_namlen = bdp->d_namlen;
798 strcpy(idb.d_name, bdp->d_name);
799 if ((error = copyout((caddr_t)&idb, outp, sunos_reclen)) != 0)
800 goto out;
801 /* advance past this real entry */
802 inp += reclen;
803 /* advance output past Sun-shaped entry */
804 outp += sunos_reclen;
805 resid -= sunos_reclen;
806 }
807
808 /* if we squished out the whole block, try again */
809 if (outp == (caddr_t)(u_long)SCARG(uap, buf))
810 goto again;
811 fp->f_offset = off; /* update the vnode offset */
812
813 eof:
814 *retval = SCARG(uap, nbytes) - resid;
815 out:
816 VOP_UNLOCK(vp, 0);
817 free(cookiebuf, M_TEMP);
818 free(buf, M_TEMP);
819 out1:
820 FILE_UNUSE(fp, p);
821 return (error);
822 }
823
824 #define SUNOS32__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
825
826 int
827 sunos32_sys_mmap(l, v, retval)
828 struct lwp *l;
829 void *v;
830 register_t *retval;
831 {
832 struct sunos32_sys_mmap_args /* {
833 syscallarg(netbsd32_voidp) addr;
834 syscallarg(netbsd32_size_t) len;
835 syscallarg(int) prot;
836 syscallarg(int) flags;
837 syscallarg(int) fd;
838 syscallarg(netbsd32_long) pos;
839 } */ *uap = v;
840 struct proc *p = l->l_proc;
841 struct sys_mmap_args ua;
842 struct filedesc *fdp;
843 struct file *fp;
844 struct vnode *vp;
845 void *rt;
846 int error;
847
848 /*
849 * Verify the arguments.
850 */
851 if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
852 return (EINVAL); /* XXX still needed? */
853
854 if ((SCARG(uap, flags) & SUNOS32__MAP_NEW) == 0)
855 return (EINVAL);
856
857 SUNOS32TOP_UAP(addr, void);
858 SUNOS32TOX_UAP(len, size_t);
859 SUNOS32TO64_UAP(prot);
860 SCARG(&ua, flags) = SCARG(uap, flags) & ~SUNOS32__MAP_NEW;
861 SUNOS32TO64_UAP(fd);
862 SCARG(&ua, pad) = 0;
863 SUNOS32TOX_UAP(pos, off_t);
864
865 if ((SCARG(&ua, flags) & MAP_FIXED) == 0 &&
866 SCARG(&ua, addr) != 0 &&
867 SCARG(&ua, addr) < (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ))
868 SCARG(&ua, addr) = (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ);
869
870 /*
871 * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX)
872 */
873 fdp = p->p_fd;
874 if ((fp = fd_getfile(fdp, SCARG(&ua, fd))) != NULL && /*XXX*/
875 fp->f_type == DTYPE_VNODE && /*XXX*/
876 (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/
877 vp->v_rdev == zerodev) { /*XXX*/
878 SCARG(&ua, flags) |= MAP_ANON;
879 SCARG(&ua, fd) = -1;
880 }
881
882 error = sys_mmap(l, &ua, (register_t *)&rt);
883 if ((long)rt > (long)UINT_MAX)
884 printf("sunos32_mmap: retval out of range: %p", rt);
885 *retval = (netbsd32_voidp)(u_long)rt;
886 return (error);
887 }
888
889 #define MC_SYNC 1
890 #define MC_LOCK 2
891 #define MC_UNLOCK 3
892 #define MC_ADVISE 4
893 #define MC_LOCKAS 5
894 #define MC_UNLOCKAS 6
895
896 int
897 sunos32_sys_mctl(l, v, retval)
898 struct lwp *l;
899 void *v;
900 register_t *retval;
901 {
902 struct sunos32_sys_mctl_args /* {
903 syscallarg(netbsd32_voidp) addr;
904 syscallarg(int) len;
905 syscallarg(int) func;
906 syscallarg(netbsd32_voidp) arg;
907 } */ *uap = v;
908
909 switch (SCARG(uap, func)) {
910 case MC_ADVISE: /* ignore for now */
911 return (0);
912 case MC_SYNC: /* translate to msync */
913 return (netbsd32___msync13(l, uap, retval));
914 default:
915 return (EINVAL);
916 }
917 }
918
919 int
920 sunos32_sys_setsockopt(l, v, retval)
921 struct lwp *l;
922 void *v;
923 register_t *retval;
924 {
925 struct sunos32_sys_setsockopt_args /* {
926 syscallarg(int) s;
927 syscallarg(int) level;
928 syscallarg(int) name;
929 syscallarg(netbsd32_caddr_t) val;
930 syscallarg(int) valsize;
931 } */ *uap = v;
932 struct proc *p = l->l_proc;
933 struct file *fp;
934 struct mbuf *m = NULL;
935 int error;
936
937 /* getsock() will use the descriptor for us */
938 if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
939 return (error);
940 #define SO_DONTLINGER (~SO_LINGER)
941 if (SCARG(uap, name) == SO_DONTLINGER) {
942 m = m_get(M_WAIT, MT_SOOPTS);
943 mtod(m, struct linger *)->l_onoff = 0;
944 m->m_len = sizeof(struct linger);
945 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
946 SO_LINGER, m);
947 goto out;
948 }
949 if (SCARG(uap, level) == IPPROTO_IP) {
950 #define SUNOS_IP_MULTICAST_IF 2
951 #define SUNOS_IP_MULTICAST_TTL 3
952 #define SUNOS_IP_MULTICAST_LOOP 4
953 #define SUNOS_IP_ADD_MEMBERSHIP 5
954 #define SUNOS_IP_DROP_MEMBERSHIP 6
955 static int ipoptxlat[] = {
956 IP_MULTICAST_IF,
957 IP_MULTICAST_TTL,
958 IP_MULTICAST_LOOP,
959 IP_ADD_MEMBERSHIP,
960 IP_DROP_MEMBERSHIP
961 };
962 if (SCARG(uap, name) >= SUNOS_IP_MULTICAST_IF &&
963 SCARG(uap, name) <= SUNOS_IP_DROP_MEMBERSHIP) {
964 SCARG(uap, name) =
965 ipoptxlat[SCARG(uap, name) - SUNOS_IP_MULTICAST_IF];
966 }
967 }
968 if (SCARG(uap, valsize) > MLEN) {
969 error = EINVAL;
970 goto out;
971 }
972 if (SCARG(uap, val)) {
973 m = m_get(M_WAIT, MT_SOOPTS);
974 error = copyin((caddr_t)(u_long)SCARG(uap, val), mtod(m, caddr_t),
975 (u_int)SCARG(uap, valsize));
976 if (error) {
977 (void) m_free(m);
978 goto out;
979 }
980 m->m_len = SCARG(uap, valsize);
981 }
982 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
983 SCARG(uap, name), m);
984 out:
985 FILE_UNUSE(fp, p);
986 return (error);
987 }
988
989 static __inline__ int sunos32_sys_socket_common(struct lwp *, register_t *,
990 int type);
991 static __inline__ int
992 sunos32_sys_socket_common(l, retval, type)
993 struct lwp *l;
994 register_t *retval;
995 int type;
996 {
997 struct socket *so;
998 struct proc *p = l->l_proc;
999 struct file *fp;
1000 int error, fd;
1001
1002 /* getsock() will use the descriptor for us */
1003 fd = (int)*retval;
1004 if ((error = getsock(p->p_fd, fd, &fp)) == 0) {
1005 so = (struct socket *)fp->f_data;
1006 if (type == SOCK_DGRAM)
1007 so->so_options |= SO_BROADCAST;
1008 }
1009 FILE_UNUSE(fp, p);
1010 return (error);
1011 }
1012
1013 int
1014 sunos32_sys_socket(l, v, retval)
1015 struct lwp *l;
1016 void *v;
1017 register_t *retval;
1018 {
1019 struct sunos32_sys_socket_args /* {
1020 syscallarg(int) domain;
1021 syscallarg(int) type;
1022 syscallarg(int) protocol;
1023 } */ *uap = v;
1024 int error;
1025
1026 error = netbsd32_socket(l, v, retval);
1027 if (error)
1028 return (error);
1029 return sunos32_sys_socket_common(l, retval, SCARG(uap, type));
1030 }
1031
1032 int
1033 sunos32_sys_socketpair(l, v, retval)
1034 struct lwp *l;
1035 void *v;
1036 register_t *retval;
1037 {
1038 struct sunos32_sys_socketpair_args /* {
1039 syscallarg(int) domain;
1040 syscallarg(int) type;
1041 syscallarg(int) protocol;
1042 syscallarg(int *) rsv;
1043 } */ *uap = v;
1044 int error;
1045
1046 error = netbsd32_socketpair(l, v, retval);
1047 if (error)
1048 return (error);
1049 return sunos32_sys_socket_common(l, retval, SCARG(uap, type));
1050 }
1051
1052
1053 /*
1054 * XXX: This needs cleaning up.
1055 */
1056 int
1057 sunos32_sys_auditsys(l, v, retval)
1058 struct lwp *l;
1059 void *v;
1060 register_t *retval;
1061 {
1062 return 0;
1063 }
1064
1065 int
1066 sunos32_sys_uname(l, v, retval)
1067 struct lwp *l;
1068 void *v;
1069 register_t *retval;
1070 {
1071 struct sunos32_sys_uname_args /* {
1072 syscallarg(sunos32_utsnamep_t) name;
1073 } */ *uap = v;
1074 struct sunos_utsname sut;
1075
1076 memset(&sut, 0, sizeof(sut));
1077
1078 memcpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
1079 memcpy(sut.nodename, hostname, sizeof(sut.nodename));
1080 sut.nodename[sizeof(sut.nodename)-1] = '\0';
1081 memcpy(sut.release, osrelease, sizeof(sut.release) - 1);
1082 memcpy(sut.version, "1", sizeof(sut.version) - 1);
1083 memcpy(sut.machine, machine, sizeof(sut.machine) - 1);
1084
1085 return copyout((caddr_t)&sut, (caddr_t)(u_long)SCARG(uap, name),
1086 sizeof(struct sunos_utsname));
1087 }
1088
1089 int
1090 sunos32_sys_setpgrp(l, v, retval)
1091 struct lwp *l;
1092 void *v;
1093 register_t *retval;
1094 {
1095 struct sunos32_sys_setpgrp_args /* {
1096 syscallarg(int) pid;
1097 syscallarg(int) pgid;
1098 } */ *uap = v;
1099 struct proc *p = l->l_proc;
1100
1101 /*
1102 * difference to our setpgid call is to include backwards
1103 * compatibility to pre-setsid() binaries. Do setsid()
1104 * instead of setpgid() in those cases where the process
1105 * tries to create a new session the old way.
1106 */
1107 if (!SCARG(uap, pgid) &&
1108 (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
1109 return sys_setsid(l, uap, retval);
1110 else
1111 return netbsd32_setpgid(l, uap, retval);
1112 }
1113
1114 int
1115 sunos32_sys_open(l, v, retval)
1116 struct lwp *l;
1117 void *v;
1118 register_t *retval;
1119 {
1120 struct sunos32_sys_open_args /* {
1121 syscallarg(const netbsd32_charp) path;
1122 syscallarg(int) flags;
1123 syscallarg(int) mode;
1124 } */ *uap = v;
1125 struct proc *p = l->l_proc;
1126 struct sys_open_args ua;
1127 int lf, r;
1128 int noctty;
1129 int ret;
1130 caddr_t sg = stackgap_init(p, 0);
1131
1132 /* convert mode into NetBSD mode */
1133 lf = SCARG(uap, flags);
1134 noctty = lf & 0x8000;
1135 r = (lf & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
1136 r |= ((lf & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
1137 r |= ((lf & 0x0080) ? O_SHLOCK : 0);
1138 r |= ((lf & 0x0100) ? O_EXLOCK : 0);
1139 r |= ((lf & 0x2000) ? O_FSYNC : 0);
1140
1141 SUNOS32TOP_UAP(path, const char);
1142 SCARG(&ua, flags) = r;
1143 SUNOS32TO64_UAP(mode);
1144
1145 if (r & O_CREAT)
1146 SUNOS32_CHECK_ALT_CREAT(p, &sg, SCARG(&ua, path));
1147 else
1148 SUNOS32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
1149
1150 ret = sys_open(l, &ua, retval);
1151
1152 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
1153 struct filedesc *fdp = p->p_fd;
1154 struct file *fp;
1155
1156 fp = fd_getfile(fdp, *retval);
1157
1158 /* ignore any error, just give it a try */
1159 if (fp != NULL && fp->f_type == DTYPE_VNODE)
1160 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
1161 }
1162 return ret;
1163 }
1164
1165 #if defined (NFSSERVER)
1166 int
1167 sunos32_sys_nfssvc(l, v, retval)
1168 struct lwp *l;
1169 void *v;
1170 register_t *retval;
1171 {
1172 #if 0
1173 struct sunos32_sys_nfssvc_args *uap = v;
1174 struct emul *e = p->p_emul;
1175 struct sys_nfssvc_args outuap;
1176 struct sockaddr sa;
1177 int error;
1178 caddr_t sg = stackgap_init(p, 0);
1179
1180 memset(&outuap, 0, sizeof outuap);
1181 SCARG(&outuap, fd) = SCARG(uap, fd);
1182 SCARG(&outuap, mskval) = stackgap_alloc(p, &sg, sizeof(sa));
1183 SCARG(&outuap, msklen) = sizeof(sa);
1184 SCARG(&outuap, mtchval) = stackgap_alloc(p, &sg, sizeof(sa));
1185 SCARG(&outuap, mtchlen) = sizeof(sa);
1186
1187 memset(&sa, 0, sizeof sa);
1188 if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
1189 return (error);
1190 if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
1191 return (error);
1192
1193 return nfssvc(l, &outuap, retval);
1194 #else
1195 return (ENOSYS);
1196 #endif
1197 }
1198 #endif /* NFSSERVER */
1199
1200 int
1201 sunos32_sys_ustat(l, v, retval)
1202 struct lwp *l;
1203 void *v;
1204 register_t *retval;
1205 {
1206 struct sunos32_sys_ustat_args /* {
1207 syscallarg(int) dev;
1208 syscallarg(sunos32_ustatp_t) buf;
1209 } */ *uap = v;
1210 struct sunos_ustat us;
1211 int error;
1212
1213 memset(&us, 0, sizeof us);
1214
1215 /*
1216 * XXX: should set f_tfree and f_tinode at least
1217 * How do we translate dev -> fstat? (and then to sunos_ustat)
1218 */
1219
1220 if ((error = copyout(&us, (caddr_t)(u_long)SCARG(uap, buf), sizeof us)) != 0)
1221 return (error);
1222 return 0;
1223 }
1224
1225 int
1226 sunos32_sys_quotactl(l, v, retval)
1227 struct lwp *l;
1228 void *v;
1229 register_t *retval;
1230 {
1231
1232 return EINVAL;
1233 }
1234
1235 int
1236 sunos32_sys_vhangup(l, v, retval)
1237 struct lwp *l;
1238 void *v;
1239 register_t *retval;
1240 {
1241 struct proc *p = l->l_proc;
1242 struct session *sp = p->p_session;
1243
1244 if (sp->s_ttyvp == 0)
1245 return 0;
1246
1247 if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp)
1248 pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
1249
1250 (void) ttywait(sp->s_ttyp);
1251 if (sp->s_ttyvp)
1252 VOP_REVOKE(sp->s_ttyvp, REVOKEALL);
1253 if (sp->s_ttyvp)
1254 vrele(sp->s_ttyvp);
1255 sp->s_ttyvp = NULL;
1256
1257 return 0;
1258 }
1259
1260 static int
1261 sunstatfs(sp, buf)
1262 struct statfs *sp;
1263 caddr_t buf;
1264 {
1265 struct sunos_statfs ssfs;
1266
1267 memset(&ssfs, 0, sizeof ssfs);
1268 ssfs.f_type = 0;
1269 ssfs.f_bsize = sp->f_bsize;
1270 ssfs.f_blocks = sp->f_blocks;
1271 ssfs.f_bfree = sp->f_bfree;
1272 ssfs.f_bavail = sp->f_bavail;
1273 ssfs.f_files = sp->f_files;
1274 ssfs.f_ffree = sp->f_ffree;
1275 ssfs.f_fsid = sp->f_fsid;
1276 return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
1277 }
1278
1279 int
1280 sunos32_sys_statfs(l, v, retval)
1281 struct lwp *l;
1282 void *v;
1283 register_t *retval;
1284 {
1285 struct sunos32_sys_statfs_args /* {
1286 syscallarg(const netbsd32_charp) path;
1287 syscallarg(sunos32_statfsp_t) buf;
1288 } */ *uap = v;
1289 struct proc *p = l->l_proc;
1290 struct mount *mp;
1291 struct statfs *sp;
1292 int error;
1293 struct nameidata nd;
1294
1295 caddr_t sg = stackgap_init(p, 0);
1296 SUNOS32_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
1297
1298 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, (caddr_t)(u_long)SCARG(uap, path), p);
1299 if ((error = namei(&nd)) != 0)
1300 return (error);
1301 mp = nd.ni_vp->v_mount;
1302 sp = &mp->mnt_stat;
1303 vrele(nd.ni_vp);
1304 if ((error = VFS_STATFS(mp, sp, p)) != 0)
1305 return (error);
1306 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
1307 return sunstatfs(sp, (caddr_t)(u_long)SCARG(uap, buf));
1308 }
1309
1310 int
1311 sunos32_sys_fstatfs(l, v, retval)
1312 struct lwp *l;
1313 void *v;
1314 register_t *retval;
1315 {
1316 struct sunos32_sys_fstatfs_args /* {
1317 syscallarg(int) fd;
1318 syscallarg(sunos32_statfsp_t) buf;
1319 } */ *uap = v;
1320 struct proc *p = l->l_proc;
1321 struct file *fp;
1322 struct mount *mp;
1323 struct statfs *sp;
1324 int error;
1325
1326 /* getvnode() will use the descriptor for us */
1327 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
1328 return (error);
1329 mp = ((struct vnode *)fp->f_data)->v_mount;
1330 sp = &mp->mnt_stat;
1331 if ((error = VFS_STATFS(mp, sp, p)) != 0)
1332 goto out;
1333 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
1334 error = sunstatfs(sp, (caddr_t)(u_long)SCARG(uap, buf));
1335 out:
1336 FILE_UNUSE(fp, p);
1337 return (error);
1338 }
1339
1340 int
1341 sunos32_sys_exportfs(l, v, retval)
1342 struct lwp *l;
1343 void *v;
1344 register_t *retval;
1345 {
1346 /*
1347 * XXX: should perhaps translate into a mount(2)
1348 * with MOUNT_EXPORT?
1349 */
1350 return 0;
1351 }
1352
1353 int
1354 sunos32_sys_mknod(l, v, retval)
1355 struct lwp *l;
1356 void *v;
1357 register_t *retval;
1358 {
1359 struct sunos32_sys_mknod_args /* {
1360 syscallarg(const netbsd32_charp) path;
1361 syscallarg(int) mode;
1362 syscallarg(int) dev;
1363 } */ *uap = v;
1364 struct proc *p = l->l_proc;
1365
1366 caddr_t sg = stackgap_init(p, 0);
1367 SUNOS32_CHECK_ALT_CREAT(p, &sg, SCARG(uap, 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 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 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