sunos32_misc.c revision 1.84 1 /* $NetBSD: sunos32_misc.c,v 1.84 2020/06/24 10:28:17 jdolecek 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.84 2020/06/24 10:28:17 jdolecek 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 stat sb;
298 struct netbsd32_stat43 sb32;
299 int error;
300
301 error = do_sys_stat(SCARG_P32(uap, path), NOFOLLOW, &sb);
302 if (error)
303 return error;
304
305 /*
306 * For symbolic links, SunOS returned the attributes of its
307 * containing directory, except for mode, size, and links.
308 * This is no longer emulated, the parent directory is not consulted.
309 */
310 sunos32_from___stat13(&sb, &sb32);
311 error = copyout((void *)&sb32, SCARG_P32(uap, ub), sizeof (sb32));
312 return (error);
313 }
314
315 static int
316 sunos32_execve_fetch_element(char * const *array, size_t index, char **value)
317 {
318 int error;
319 netbsd32_charp const *a32 = (void const *)array;
320 netbsd32_charp e;
321
322 error = copyin(a32 + index, &e, sizeof(e));
323 if (error)
324 return error;
325 *value = NETBSD32PTR64(e);
326 return 0;
327 }
328
329 int
330 sunos32_sys_execv(struct lwp *l, const struct sunos32_sys_execv_args *uap, register_t *retval)
331 {
332 /* {
333 syscallarg(const char *) path;
334 syscallarg(char **) argv;
335 } */
336 const char *path = SCARG_P32(uap, path);
337
338 return execve1(l, true, path, -1, SCARG_P32(uap, argp), NULL,
339 sunos32_execve_fetch_element);
340 }
341
342 int
343 sunos32_sys_execve(struct lwp *l, const struct sunos32_sys_execve_args *uap, register_t *retval)
344 {
345 /* {
346 syscallarg(const char *) path;
347 syscallarg(char **) argv;
348 syscallarg(char **) envp;
349 } */
350 const char *path = SCARG_P32(uap, path);
351
352 return execve1(l, true, path, -1, SCARG_P32(uap, argp),
353 SCARG_P32(uap, envp), sunos32_execve_fetch_element);
354 }
355
356 int
357 sunos32_sys_omsync(struct lwp *l, const struct sunos32_sys_omsync_args *uap, register_t *retval)
358 {
359 /* {
360 syscallarg(netbsd32_caddr_t) addr;
361 syscallarg(netbsd32_size_t) len;
362 syscallarg(int) flags;
363 } */
364 struct netbsd32___msync13_args ouap;
365
366 SCARG(&ouap, addr) = SCARG(uap, addr);
367 SCARG(&ouap, len) = SCARG(uap, len);
368 SCARG(&ouap, flags) = SCARG(uap, flags);
369
370 return (netbsd32___msync13(l, &ouap, retval));
371 }
372
373 int
374 sunos32_sys_unmount(struct lwp *l, const struct sunos32_sys_unmount_args *uap, register_t *retval)
375 {
376 /* {
377 syscallarg(netbsd32_charp) path;
378 } */
379 struct sys_unmount_args ua;
380
381 SUNOS32TOP_UAP(path, const char);
382 SCARG(&ua, flags) = 0;
383
384 return (sys_unmount(l, &ua, retval));
385 }
386
387 /*
388 * Conversion table for SunOS NFS mount flags.
389 */
390 static struct {
391 int sun_flg;
392 int bsd_flg;
393 } sunnfs_flgtab[] = {
394 { SUNNFS_SOFT, NFSMNT_SOFT },
395 { SUNNFS_WSIZE, NFSMNT_WSIZE },
396 { SUNNFS_RSIZE, NFSMNT_RSIZE },
397 { SUNNFS_TIMEO, NFSMNT_TIMEO },
398 { SUNNFS_RETRANS, NFSMNT_RETRANS },
399 { SUNNFS_HOSTNAME, 0 }, /* Ignored */
400 { SUNNFS_INT, NFSMNT_INT },
401 { SUNNFS_NOAC, 0 }, /* Ignored */
402 { SUNNFS_ACREGMIN, 0 }, /* Ignored */
403 { SUNNFS_ACREGMAX, 0 }, /* Ignored */
404 { SUNNFS_ACDIRMIN, 0 }, /* Ignored */
405 { SUNNFS_ACDIRMAX, 0 }, /* Ignored */
406 { SUNNFS_SECURE, 0 }, /* Ignored */
407 { SUNNFS_NOCTO, 0 }, /* Ignored */
408 { SUNNFS_POSIX, 0 } /* Ignored */
409 };
410
411 int
412 sunos32_sys_mount(struct lwp *l, const struct sunos32_sys_mount_args *uap, register_t *retval)
413 {
414 /* {
415 syscallarg(netbsd32_charp) type;
416 syscallarg(netbsd32_charp) path;
417 syscallarg(int) flags;
418 syscallarg(netbsd32_caddr_t) data;
419 } */
420 int oflags = SCARG(uap, flags), nflags, error;
421 char fsname[MFSNAMELEN];
422 register_t dummy;
423
424 if (oflags & (SUNM_NOSUB | SUNM_SYS5))
425 return (EINVAL);
426 if ((oflags & SUNM_NEWTYPE) == 0)
427 return (EINVAL);
428 nflags = 0;
429 if (oflags & SUNM_RDONLY)
430 nflags |= MNT_RDONLY;
431 if (oflags & SUNM_NOSUID)
432 nflags |= MNT_NOSUID;
433 if (oflags & SUNM_REMOUNT)
434 nflags |= MNT_UPDATE;
435
436 error = copyinstr(SCARG_P32(uap, type), fsname, sizeof fsname, NULL);
437 if (error)
438 return (error);
439
440 if (strncmp(fsname, "nfs", sizeof fsname) == 0) {
441 struct sunos_nfs_args sna;
442 struct nfs_args na; /* XXX */
443 int n;
444
445 error = copyin(SCARG_P32(uap, data), &sna, sizeof sna);
446 if (error)
447 return (error);
448 /* sa.sa_len = sizeof(sain); */
449 na.version = NFS_ARGSVERSION;
450 na.addr = (void *)sna.addr;
451 na.addrlen = sizeof(struct sockaddr);
452 na.sotype = SOCK_DGRAM;
453 na.proto = IPPROTO_UDP;
454 na.fh = sna.fh;
455 na.fhsize = NFSX_V2FH;
456 na.flags = 0;
457 n = sizeof(sunnfs_flgtab) / sizeof(sunnfs_flgtab[0]);
458 while (--n >= 0)
459 if (sna.flags & sunnfs_flgtab[n].sun_flg)
460 na.flags |= sunnfs_flgtab[n].bsd_flg;
461 na.wsize = sna.wsize;
462 na.rsize = sna.rsize;
463 if (na.flags & NFSMNT_RSIZE) {
464 na.flags |= NFSMNT_READDIRSIZE;
465 na.readdirsize = na.rsize;
466 }
467 na.timeo = sna.timeo;
468 na.retrans = sna.retrans;
469 na.hostname = (char *)(u_long)sna.hostname;
470
471 return do_sys_mount(l, "nfs", UIO_SYSSPACE,
472 SCARG_P32(uap, path), nflags, &na, UIO_SYSSPACE, sizeof na,
473 &dummy);
474 }
475
476 if (strcmp(fsname, "4.2") == 0)
477 strcpy(fsname, "ffs");
478
479 return do_sys_mount(l, fsname, UIO_SYSSPACE,
480 SCARG_P32(uap, path), nflags, SCARG_P32(uap, data), UIO_USERSPACE,
481 0, &dummy);
482 }
483
484 void native_to_sunos_sigset(const sigset_t *, int *);
485 void sunos_to_native_sigset(const int, sigset_t *);
486
487 inline void
488 native_to_sunos_sigset(const sigset_t *ss, int *mask)
489 {
490 *mask = ss->__bits[0];
491 }
492
493 inline void
494 sunos_to_native_sigset(const int mask, sigset_t *ss)
495 {
496
497 ss->__bits[0] = mask;
498 ss->__bits[1] = 0;
499 ss->__bits[2] = 0;
500 ss->__bits[3] = 0;
501 }
502
503 int
504 sunos32_sys_sigpending(struct lwp *l, const struct sunos32_sys_sigpending_args *uap, register_t *retval)
505 {
506 /* {
507 syscallarg(netbsd32_intp) mask;
508 } */
509 sigset_t ss;
510 int mask;
511
512 sigpending1(l, &ss);
513 native_to_sunos_sigset(&ss, &mask);
514
515 return (copyout((void *)(u_long)&mask, SCARG_P32(uap, mask), sizeof(int)));
516 }
517
518 int
519 sunos32_sys_sigsuspend(struct lwp *l, const struct sunos32_sys_sigsuspend_args *uap, register_t *retval)
520 {
521 /* {
522 syscallarg(int) mask;
523 } */
524 int mask;
525 sigset_t ss;
526
527 mask = SCARG(uap, mask);
528 sunos_to_native_sigset(mask, &ss);
529 return (sigsuspend1(l, &ss));
530 }
531
532 /*
533 * Read Sun-style directory entries. We suck them into kernel space so
534 * that they can be massaged before being copied out to user code. Like
535 * SunOS, we squish out `empty' entries.
536 *
537 * This is quite ugly, but what do you expect from compatibility code?
538 */
539 int
540 sunos32_sys_getdents(struct lwp *l, const struct sunos32_sys_getdents_args *uap, register_t *retval)
541 {
542 /* {
543 syscallarg(int) fd;
544 syscallarg(netbsd32_charp) buf;
545 syscallarg(int) nbytes;
546 } */
547 struct dirent *bdp;
548 struct vnode *vp;
549 char *inp, *sbuf; /* BSD-format */
550 int len, reclen; /* BSD-format */
551 char *outp; /* Sun-format */
552 int resid, sunos_reclen;/* Sun-format */
553 struct file *fp;
554 struct uio auio;
555 struct iovec aiov;
556 struct sunos32_dirent idb;
557 off_t off; /* true file offset */
558 int buflen, error, eofflag;
559 off_t *cookiebuf, *cookie;
560 int ncookies;
561
562 /* fd_getvnode() will use the descriptor for us */
563 if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
564 return (error);
565
566 if ((fp->f_flag & FREAD) == 0) {
567 error = EBADF;
568 goto out1;
569 }
570
571 vp = fp->f_vnode;
572 if (vp->v_type != VDIR) {
573 error = EINVAL;
574 goto out1;
575 }
576
577 buflen = uimin(MAXBSIZE, SCARG(uap, nbytes));
578 sbuf = malloc(buflen, M_TEMP, M_WAITOK);
579 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
580 off = fp->f_offset;
581 again:
582 aiov.iov_base = sbuf;
583 aiov.iov_len = buflen;
584 auio.uio_iov = &aiov;
585 auio.uio_iovcnt = 1;
586 auio.uio_rw = UIO_READ;
587 auio.uio_resid = buflen;
588 auio.uio_offset = off;
589 UIO_SETUP_SYSSPACE(&auio);
590 /*
591 * First we read into the malloc'ed buffer, then
592 * we massage it into user space, one record at a time.
593 */
594 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
595 &ncookies);
596 if (error)
597 goto out;
598
599 inp = sbuf;
600 outp = SCARG_P32(uap, buf);
601 resid = SCARG(uap, nbytes);
602 if ((len = buflen - auio.uio_resid) == 0)
603 goto eof;
604
605 for (cookie = cookiebuf; len > 0; len -= reclen) {
606 bdp = (struct dirent *)inp;
607 reclen = bdp->d_reclen;
608 if (reclen & 3) {
609 error = EIO;
610 goto out;
611 }
612 if (cookie && (*cookie >> 32) != 0) {
613 compat_offseterr(vp, "sunos_getdents");
614 error = EINVAL;
615 goto out;
616 }
617 if (bdp->d_fileno == 0) {
618 inp += reclen; /* it is a hole; squish it out */
619 if (cookie)
620 off = *cookie++;
621 else
622 off += reclen;
623 continue;
624 }
625 sunos_reclen = SUNOS32_RECLEN(&idb, bdp->d_namlen);
626 if (reclen > len || resid < sunos_reclen) {
627 /* entry too big for buffer, so just stop */
628 outp++;
629 break;
630 }
631 if (cookie)
632 off = *cookie++; /* each entry points to next */
633 else
634 off += reclen;
635 /*
636 * Massage in place to make a Sun-shaped dirent (otherwise
637 * we have to worry about touching user memory outside of
638 * the copyout() call).
639 */
640 idb.d_fileno = bdp->d_fileno;
641 idb.d_off = off;
642 idb.d_reclen = sunos_reclen;
643 idb.d_namlen = bdp->d_namlen;
644 strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
645 if ((error = copyout((void *)&idb, outp, sunos_reclen)) != 0)
646 goto out;
647 /* advance past this real entry */
648 inp += reclen;
649 /* advance output past Sun-shaped entry */
650 outp += sunos_reclen;
651 resid -= sunos_reclen;
652 }
653
654 /* if we squished out the whole block, try again */
655 if (outp == SCARG_P32(uap, buf)) {
656 if (cookiebuf)
657 free(cookiebuf, M_TEMP);
658 cookiebuf = NULL;
659 goto again;
660 }
661 fp->f_offset = off; /* update the vnode offset */
662
663 eof:
664 *retval = SCARG(uap, nbytes) - resid;
665 out:
666 VOP_UNLOCK(vp);
667 free(cookiebuf, M_TEMP);
668 free(sbuf, M_TEMP);
669 out1:
670 fd_putfile(SCARG(uap, fd));
671 return (error);
672 }
673
674 #define SUNOS32__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
675
676 int
677 sunos32_sys_mmap(struct lwp *l, const struct sunos32_sys_mmap_args *uap, register_t *retval)
678 {
679 /* {
680 syscallarg(netbsd32_voidp) addr;
681 syscallarg(netbsd32_size_t) len;
682 syscallarg(int) prot;
683 syscallarg(int) flags;
684 syscallarg(int) fd;
685 syscallarg(netbsd32_long) pos;
686 } */
687 struct sys_mmap_args ua;
688 int error;
689
690 /*
691 * Verify the arguments.
692 */
693 if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
694 return (EINVAL); /* XXX still needed? */
695
696 if ((SCARG(uap, flags) & SUNOS32__MAP_NEW) == 0)
697 return (EINVAL);
698
699 SUNOS32TOP_UAP(addr, void);
700 SUNOS32TOX_UAP(len, size_t);
701 SUNOS32TO64_UAP(prot);
702 SCARG(&ua, flags) = SCARG(uap, flags) & ~SUNOS32__MAP_NEW;
703 SUNOS32TO64_UAP(fd);
704 SCARG(&ua, PAD) = 0;
705 SUNOS32TOX_UAP(pos, off_t);
706
707 error = sys_mmap(l, &ua, retval);
708 if ((u_long)*retval > (u_long)UINT_MAX) {
709 printf("sunos32_mmap: retval out of range: 0x%lx\n",
710 (u_long)*retval);
711 /* Should try to recover and return an error here. */
712 }
713 return (error);
714 }
715
716 #define MC_SYNC 1
717 #define MC_LOCK 2
718 #define MC_UNLOCK 3
719 #define MC_ADVISE 4
720 #define MC_LOCKAS 5
721 #define MC_UNLOCKAS 6
722
723 int
724 sunos32_sys_mctl(struct lwp *l, const struct sunos32_sys_mctl_args *uap, register_t *retval)
725 {
726 /* {
727 syscallarg(netbsd32_voidp) addr;
728 syscallarg(int) len;
729 syscallarg(int) func;
730 syscallarg(netbsd32_voidp) arg;
731 } */
732
733 switch (SCARG(uap, func)) {
734 case MC_ADVISE: /* ignore for now */
735 return (0);
736 case MC_SYNC: /* translate to msync */
737 return (netbsd32___msync13(l, (const void *)uap, retval));
738 default:
739 return (EINVAL);
740 }
741 }
742
743 int
744 sunos32_sys_setsockopt(struct lwp *l, const struct sunos32_sys_setsockopt_args *uap, register_t *retval)
745 {
746 /* {
747 syscallarg(int) s;
748 syscallarg(int) level;
749 syscallarg(int) name;
750 syscallarg(netbsd32_caddr_t) val;
751 syscallarg(int) valsize;
752 } */
753 struct sockopt sopt;
754 struct socket *so;
755 int name = SCARG(uap, name);
756 int error;
757
758 /* fd_getsock() will use the descriptor for us */
759 if ((error = fd_getsock(SCARG(uap, s), &so)) != 0)
760 return (error);
761 #define SO_DONTLINGER (~SO_LINGER)
762 if (name == SO_DONTLINGER) {
763 struct linger lg;
764
765 lg.l_onoff = 0;
766 error = so_setsockopt(l, so, SCARG(uap, level), SO_LINGER,
767 &lg, sizeof(lg));
768 goto out;
769 }
770 if (SCARG(uap, level) == IPPROTO_IP) {
771 #define SUNOS_IP_MULTICAST_IF 2
772 #define SUNOS_IP_MULTICAST_TTL 3
773 #define SUNOS_IP_MULTICAST_LOOP 4
774 #define SUNOS_IP_ADD_MEMBERSHIP 5
775 #define SUNOS_IP_DROP_MEMBERSHIP 6
776 static const int ipoptxlat[] = {
777 IP_MULTICAST_IF,
778 IP_MULTICAST_TTL,
779 IP_MULTICAST_LOOP,
780 IP_ADD_MEMBERSHIP,
781 IP_DROP_MEMBERSHIP
782 };
783 if (name >= SUNOS_IP_MULTICAST_IF &&
784 name <= SUNOS_IP_DROP_MEMBERSHIP) {
785 name = ipoptxlat[name - SUNOS_IP_MULTICAST_IF];
786 }
787 }
788 if ((unsigned)SCARG(uap, valsize) > MLEN) {
789 error = EINVAL;
790 goto out;
791 }
792 sockopt_init(&sopt, SCARG(uap, level), name, SCARG(uap, valsize));
793 if (SCARG_P32(uap, val)) {
794 error = copyin(SCARG_P32(uap, val), sopt.sopt_data,
795 (u_int)SCARG(uap, valsize));
796 }
797 if (error == 0)
798 error = sosetopt(so, &sopt);
799 sockopt_destroy(&sopt);
800 out:
801 fd_putfile(SCARG(uap, s));
802 return (error);
803 }
804
805 static inline int sunos32_sys_socket_common(struct lwp *, register_t *,
806 int type);
807 static inline int
808 sunos32_sys_socket_common(struct lwp *l, register_t *retval, int type)
809 {
810 struct socket *so;
811 int error, fd;
812
813 /* fd_getsock() will use the descriptor for us */
814 fd = (int)*retval;
815 if ((error = fd_getsock(fd, &so)) == 0) {
816 if (type == SOCK_DGRAM)
817 so->so_options |= SO_BROADCAST;
818 fd_putfile(fd);
819 }
820 return (error);
821 }
822
823 int
824 sunos32_sys_socket(struct lwp *l, const struct sunos32_sys_socket_args *uap, register_t *retval)
825 {
826 /* {
827 syscallarg(int) domain;
828 syscallarg(int) type;
829 syscallarg(int) protocol;
830 } */
831 int error;
832
833 error = netbsd32___socket30(l, (const void *)uap, retval);
834 if (error)
835 return (error);
836 return sunos32_sys_socket_common(l, retval, SCARG(uap, type));
837 }
838
839 int
840 sunos32_sys_socketpair(struct lwp *l, const struct sunos32_sys_socketpair_args *uap, register_t *retval)
841 {
842 /* {
843 syscallarg(int) domain;
844 syscallarg(int) type;
845 syscallarg(int) protocol;
846 syscallarg(int *) rsv;
847 } */
848 int error;
849
850 error = netbsd32_socketpair(l, (const void *)uap, retval);
851 if (error)
852 return (error);
853 return sunos32_sys_socket_common(l, retval, SCARG(uap, type));
854 }
855
856
857 /*
858 * XXX: This needs cleaning up.
859 */
860 int
861 sunos32_sys_auditsys(struct lwp *l, const struct sunos32_sys_auditsys_args *uap, register_t *retval)
862 {
863 return 0;
864 }
865
866 int
867 sunos32_sys_uname(struct lwp *l, const struct sunos32_sys_uname_args *uap, register_t *retval)
868 {
869 /* {
870 syscallarg(sunos32_utsnamep_t) name;
871 } */
872 struct sunos_utsname sut;
873
874 memset(&sut, 0, sizeof(sut));
875
876 strlcpy(sut.sysname, ostype, sizeof(sut.sysname));
877 strlcpy(sut.nodename, hostname, sizeof(sut.nodename));
878 strlcpy(sut.release, osrelease, sizeof(sut.release));
879 strlcpy(sut.version, "1", sizeof(sut.version));
880 strlcpy(sut.machine, machine, sizeof(sut.machine));
881
882 return copyout(&sut, SCARG_P32(uap, name), sizeof(sut));
883 }
884
885 int
886 sunos32_sys_setpgrp(struct lwp *l, const struct sunos32_sys_setpgrp_args *uap, register_t *retval)
887 {
888 /* {
889 syscallarg(int) pid;
890 syscallarg(int) pgid;
891 } */
892 struct proc *p = l->l_proc;
893
894 /*
895 * difference to our setpgid call is to include backwards
896 * compatibility to pre-setsid() binaries. Do setsid()
897 * instead of setpgid() in those cases where the process
898 * tries to create a new session the old way.
899 */
900 if (!SCARG(uap, pgid) &&
901 (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
902 return sys_setsid(l, NULL, retval);
903 else
904 return netbsd32_setpgid(l, (const void *)uap, retval);
905 }
906
907 int
908 sunos32_sys_open(struct lwp *l, const struct sunos32_sys_open_args *uap, register_t *retval)
909 {
910 /* {
911 syscallarg(const netbsd32_charp) path;
912 syscallarg(int) flags;
913 syscallarg(int) mode;
914 } */
915 struct proc *p = l->l_proc;
916 struct sys_open_args ua;
917 int lf, r;
918 int noctty;
919 int ret;
920
921 /* convert mode into NetBSD mode */
922 lf = SCARG(uap, flags);
923 noctty = lf & 0x8000;
924 r = (lf & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
925 r |= ((lf & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
926 r |= ((lf & 0x0080) ? O_SHLOCK : 0);
927 r |= ((lf & 0x0100) ? O_EXLOCK : 0);
928 r |= ((lf & 0x2000) ? O_FSYNC : 0);
929
930 SUNOS32TOP_UAP(path, const char);
931 SCARG(&ua, flags) = r;
932 SUNOS32TO64_UAP(mode);
933
934 ret = sys_open(l, &ua, retval);
935
936 /* XXXSMP unlocked */
937 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_lflag & PL_CONTROLT)) {
938 file_t *fp;
939 int fd;
940
941 fd = (int)*retval;
942 fp = fd_getfile(fd);
943
944 /* ignore any error, just give it a try */
945 if (fp != NULL) {
946 if (fp->f_type == DTYPE_VNODE)
947 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, NULL);
948 fd_putfile(fd);
949 }
950 }
951 return ret;
952 }
953
954 int
955 sunos32_sys_ustat(struct lwp *l, const struct sunos32_sys_ustat_args *uap, register_t *retval)
956 {
957 /* {
958 syscallarg(int) dev;
959 syscallarg(sunos32_ustatp_t) buf;
960 } */
961 struct sunos_ustat us;
962 int error;
963
964 memset(&us, 0, sizeof us);
965
966 /*
967 * XXX: should set f_tfree and f_tinode at least
968 * How do we translate dev -> fstat? (and then to sunos_ustat)
969 */
970
971 if ((error = copyout(&us, SCARG_P32(uap, buf), sizeof us)) != 0)
972 return (error);
973 return 0;
974 }
975
976 int
977 sunos32_sys_quotactl(struct lwp *l, const struct sunos32_sys_quotactl_args *uap, register_t *retval)
978 {
979
980 return EINVAL;
981 }
982
983 int
984 sunos32_sys_vhangup(struct lwp *l, const void *v, register_t *retval)
985 {
986 struct proc *p = l->l_proc;
987 struct session *sp = p->p_session;
988
989 if (sp->s_ttyvp == 0)
990 return 0;
991
992 if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp)
993 pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
994
995 (void) ttywait(sp->s_ttyp);
996 if (sp->s_ttyvp)
997 VOP_REVOKE(sp->s_ttyvp, REVOKEALL);
998 if (sp->s_ttyvp)
999 vrele(sp->s_ttyvp);
1000 sp->s_ttyvp = NULL;
1001
1002 return 0;
1003 }
1004
1005 static int
1006 sunstatfs(struct statvfs *sp, void *sbuf)
1007 {
1008 struct sunos_statfs ssfs;
1009
1010 memset(&ssfs, 0, sizeof ssfs);
1011 ssfs.f_type = 0;
1012 ssfs.f_bsize = sp->f_bsize;
1013 ssfs.f_blocks = sp->f_blocks;
1014 ssfs.f_bfree = sp->f_bfree;
1015 ssfs.f_bavail = sp->f_bavail;
1016 ssfs.f_files = sp->f_files;
1017 ssfs.f_ffree = sp->f_ffree;
1018 ssfs.f_fsid = sp->f_fsidx;
1019 return copyout((void *)&ssfs, sbuf, sizeof ssfs);
1020 }
1021
1022 int
1023 sunos32_sys_statfs(struct lwp *l, const struct sunos32_sys_statfs_args *uap, register_t *retval)
1024 {
1025 /* {
1026 syscallarg(const netbsd32_charp) path;
1027 syscallarg(sunos32_statfsp_t) buf;
1028 } */
1029 struct statvfs *sp;
1030 int error;
1031
1032 sp = STATVFSBUF_GET();
1033 error = do_sys_pstatvfs(l, SCARG_P32(uap, path), 0, sp);
1034 if (error == 0)
1035 error = sunstatfs(sp, SCARG_P32(uap, buf));
1036 STATVFSBUF_PUT(sp);
1037 return error;
1038 }
1039
1040 int
1041 sunos32_sys_fstatfs(struct lwp *l, const struct sunos32_sys_fstatfs_args *uap, register_t *retval)
1042 {
1043 /* {
1044 syscallarg(int) fd;
1045 syscallarg(sunos32_statfsp_t) buf;
1046 } */
1047 struct statvfs *sp;
1048 int error;
1049
1050 sp = STATVFSBUF_GET();
1051 error = do_sys_fstatvfs(l, SCARG(uap, fd), 0, sp);
1052 if (error == 0)
1053 error = sunstatfs(sp, SCARG_P32(uap, buf));
1054 STATVFSBUF_PUT(sp);
1055 return error;
1056 }
1057
1058 int
1059 sunos32_sys_exportfs(struct lwp *l, const struct sunos32_sys_exportfs_args *uap, register_t *retval)
1060 {
1061 /*
1062 * XXX: should perhaps translate into a mount(2)
1063 * with MOUNT_EXPORT?
1064 */
1065 return 0;
1066 }
1067
1068 int
1069 sunos32_sys_mknod(struct lwp *l, const struct sunos32_sys_mknod_args *uap, register_t *retval)
1070 {
1071 /* {
1072 syscallarg(const netbsd32_charp) path;
1073 syscallarg(int) mode;
1074 syscallarg(int) dev;
1075 } */
1076
1077 if (S_ISFIFO(SCARG(uap, mode)))
1078 return netbsd32_mkfifo(l, (const struct netbsd32_mkfifo_args *)uap, retval);
1079
1080 return compat_50_netbsd32_mknod(l, (const struct compat_50_netbsd32_mknod_args *)uap, retval);
1081 }
1082
1083 #define SUNOS_SC_ARG_MAX 1
1084 #define SUNOS_SC_CHILD_MAX 2
1085 #define SUNOS_SC_CLK_TCK 3
1086 #define SUNOS_SC_NGROUPS_MAX 4
1087 #define SUNOS_SC_OPEN_MAX 5
1088 #define SUNOS_SC_JOB_CONTROL 6
1089 #define SUNOS_SC_SAVED_IDS 7
1090 #define SUNOS_SC_VERSION 8
1091
1092 int
1093 sunos32_sys_sysconf(struct lwp *l, const struct sunos32_sys_sysconf_args *uap, register_t *retval)
1094 {
1095 /* {
1096 syscallarg(int) name;
1097 } */
1098 extern u_int maxfiles;
1099
1100 switch(SCARG(uap, name)) {
1101 case SUNOS_SC_ARG_MAX:
1102 *retval = ARG_MAX;
1103 break;
1104 case SUNOS_SC_CHILD_MAX:
1105 *retval = maxproc;
1106 break;
1107 case SUNOS_SC_CLK_TCK:
1108 *retval = 60; /* should this be `hz', ie. 100? */
1109 break;
1110 case SUNOS_SC_NGROUPS_MAX:
1111 *retval = NGROUPS_MAX;
1112 break;
1113 case SUNOS_SC_OPEN_MAX:
1114 *retval = maxfiles;
1115 break;
1116 case SUNOS_SC_JOB_CONTROL:
1117 *retval = 1;
1118 break;
1119 case SUNOS_SC_SAVED_IDS:
1120 #ifdef _POSIX_SAVED_IDS
1121 *retval = 1;
1122 #else
1123 *retval = 0;
1124 #endif
1125 break;
1126 case SUNOS_SC_VERSION:
1127 *retval = 198808;
1128 break;
1129 default:
1130 return EINVAL;
1131 }
1132 return 0;
1133 }
1134
1135 #define SUNOS_RLIMIT_NOFILE 6 /* Other RLIMIT_* are the same */
1136 #define SUNOS_RLIM_NLIMITS 7
1137
1138 int
1139 sunos32_sys_getrlimit(struct lwp *l, const struct sunos32_sys_getrlimit_args *uap, register_t *retval)
1140 {
1141 /* {
1142 syscallarg(u_int) which;
1143 syscallarg(netbsd32_orlimitp_t) rlp;
1144 } */
1145 struct compat_43_netbsd32_ogetrlimit_args ua_43;
1146
1147 if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
1148 return EINVAL;
1149
1150 SCARG(&ua_43, which) = SCARG(uap, which) == SUNOS_RLIMIT_NOFILE ? RLIMIT_NOFILE : SCARG(uap, which);
1151 SCARG(&ua_43, rlp) = SCARG(uap, rlp);
1152
1153 return compat_43_netbsd32_ogetrlimit(l, &ua_43, retval);
1154 }
1155
1156 int
1157 sunos32_sys_setrlimit(struct lwp *l, const struct sunos32_sys_setrlimit_args *uap, register_t *retval)
1158 {
1159 /* {
1160 syscallarg(u_int) which;
1161 syscallarg(netbsd32_orlimitp_t) rlp;
1162 } */
1163 struct compat_43_netbsd32_osetrlimit_args ua_43;
1164
1165 if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
1166 return EINVAL;
1167
1168 SCARG(&ua_43, which) = SCARG(uap, which) == SUNOS_RLIMIT_NOFILE ? RLIMIT_NOFILE : SCARG(uap, which);
1169 SCARG(&ua_43, rlp) = SCARG(uap, rlp);
1170
1171 return compat_43_netbsd32_osetrlimit(l, &ua_43, retval);
1172 }
1173
1174 /* for the m68k machines */
1175 #ifndef PT_GETFPREGS
1176 #define PT_GETFPREGS -1
1177 #endif
1178 #ifndef PT_SETFPREGS
1179 #define PT_SETFPREGS -1
1180 #endif
1181
1182 static const int sreq2breq[] = {
1183 PT_TRACE_ME, PT_READ_I, PT_READ_D, -1,
1184 PT_WRITE_I, PT_WRITE_D, -1, PT_CONTINUE,
1185 PT_KILL, -1, PT_ATTACH, PT_DETACH,
1186 PT_GETREGS, PT_SETREGS, PT_GETFPREGS, PT_SETFPREGS
1187 };
1188 static const size_t nreqs = __arraycount(sreq2breq);
1189
1190 int
1191 sunos32_sys_ptrace(struct lwp *l, const struct sunos32_sys_ptrace_args *uap, register_t *retval)
1192 {
1193 /* {
1194 syscallarg(int) req;
1195 syscallarg(pid_t) pid;
1196 syscallarg(netbsd32_caddr_t) addr;
1197 syscallarg(int) data;
1198 syscallarg(netbsd32_charp) addr2;
1199 } */
1200 struct netbsd32_ptrace_args pa;
1201 int req;
1202
1203 #define sys_ptrace sysent[SYS_ptrace].sy_call
1204 if (sys_ptrace == sys_nosys)
1205 return ENOSYS;
1206
1207 req = SCARG(uap, req);
1208 if ((unsigned int)req >= nreqs)
1209 return (EINVAL);
1210
1211 req = sreq2breq[req];
1212 if (req == -1)
1213 return (EINVAL);
1214
1215 SCARG(&pa, req) = req;
1216 SCARG(&pa, pid) = (pid_t)SCARG(uap, pid);
1217 SCARG(&pa, addr) = SCARG(uap, addr);
1218 SCARG(&pa, data) = SCARG(uap, data);
1219
1220 return netbsd32_ptrace(l, &pa, retval);
1221 }
1222
1223 /*
1224 * SunOS reboot system call (for compatibility).
1225 * Sun lets you pass in a boot string which the PROM
1226 * saves and provides to the next boot program.
1227 */
1228
1229 #define SUNOS_RB_ASKNAME 0x001
1230 #define SUNOS_RB_SINGLE 0x002
1231 #define SUNOS_RB_NOSYNC 0x004
1232 #define SUNOS_RB_HALT 0x008
1233 #define SUNOS_RB_DUMP 0x080
1234 #define SUNOS_RB_STRING 0x200
1235
1236 static struct sunos_howto_conv {
1237 int sun_howto;
1238 int bsd_howto;
1239 } sunos_howto_conv[] = {
1240 { SUNOS_RB_ASKNAME, RB_ASKNAME },
1241 { SUNOS_RB_SINGLE, RB_SINGLE },
1242 { SUNOS_RB_NOSYNC, RB_NOSYNC },
1243 { SUNOS_RB_HALT, RB_HALT },
1244 { SUNOS_RB_DUMP, RB_DUMP },
1245 { SUNOS_RB_STRING, RB_STRING },
1246 { 0x000, 0 },
1247 };
1248
1249 int
1250 sunos32_sys_reboot(struct lwp *l, const struct sunos32_sys_reboot_args *uap, register_t *retval)
1251 {
1252 /* {
1253 syscallarg(int) howto;
1254 syscallarg(netbsd32_charp) bootstr;
1255 } */
1256 struct sys_reboot_args ua;
1257 struct sunos_howto_conv *convp;
1258 int error, bsd_howto, sun_howto;
1259 char *bootstr;
1260
1261 if ((error = kauth_authorize_system(l->l_cred,
1262 KAUTH_SYSTEM_REBOOT, 0, NULL, NULL, NULL)) != 0)
1263 return (error);
1264
1265 /*
1266 * Convert howto bits to BSD format.
1267 */
1268 sun_howto = SCARG(uap, howto);
1269 bsd_howto = 0;
1270 convp = sunos_howto_conv;
1271 while (convp->sun_howto) {
1272 if (sun_howto & convp->sun_howto)
1273 bsd_howto |= convp->bsd_howto;
1274 convp++;
1275 }
1276
1277 /*
1278 * Sun RB_STRING (Get user supplied bootstring.)
1279 * If the machine supports passing a string to the
1280 * next booted kernel.
1281 */
1282 if (sun_howto & SUNOS_RB_STRING)
1283 bootstr = SCARG_P32(uap, bootstr);
1284 else
1285 bootstr = NULL;
1286
1287 SCARG(&ua, opt) = bsd_howto;
1288 SCARG(&ua, bootstr) = bootstr;
1289 return (sys_reboot(l, &ua, retval));
1290 }
1291
1292 /*
1293 * Generalized interface signal handler, 4.3-compatible.
1294 */
1295 /* ARGSUSED */
1296 int
1297 sunos32_sys_sigvec(struct lwp *l, const struct sunos32_sys_sigvec_args *uap, register_t *retval)
1298 {
1299 /* {
1300 syscallarg(int) signum;
1301 syscallarg(struct sigvec *) nsv;
1302 syscallarg(struct sigvec *) osv;
1303 } */
1304 struct netbsd32_sigvec sv;
1305 struct sigaction nsa, osa;
1306 int error;
1307
1308 if (SCARG_P32(uap, nsv)) {
1309 error = copyin(SCARG_P32(uap, nsv), &sv, sizeof(sv));
1310 if (error != 0)
1311 return (error);
1312
1313 /*
1314 * SunOS uses the mask 0x0004 as SV_RESETHAND
1315 * meaning: `reset to SIG_DFL on delivery'.
1316 * We support only the bits in: 0xF
1317 * (those bits are the same as ours)
1318 */
1319 if (sv.sv_flags & ~0xF)
1320 return (EINVAL);
1321
1322 sunos32_sigvec_to_sigaction(&sv, &nsa);
1323 }
1324 error = sigaction1(l, SCARG(uap, signum),
1325 SCARG_P32(uap, nsv) ? &nsa : 0,
1326 SCARG_P32(uap, osv) ? &osa : 0,
1327 NULL, 0);
1328 if (error != 0)
1329 return (error);
1330
1331 if (SCARG_P32(uap, osv)) {
1332 sunos32_sigvec_from_sigaction(&sv, &osa);
1333 error = copyout(&sv, SCARG_P32(uap, osv), sizeof(sv));
1334 if (error != 0)
1335 return (error);
1336 }
1337
1338 return (0);
1339 }
1340