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