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