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