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