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