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