1 /* $NetBSD: sunos32_misc.c,v 1.83 2019/10/26 11:34:48 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.83 2019/10/26 11:34:48 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 strlcpy(sut.sysname, ostype, sizeof(sut.sysname)); 930 strlcpy(sut.nodename, hostname, sizeof(sut.nodename)); 931 strlcpy(sut.release, osrelease, sizeof(sut.release)); 932 strlcpy(sut.version, "1", sizeof(sut.version)); 933 strlcpy(sut.machine, machine, sizeof(sut.machine)); 934 935 return copyout(&sut, SCARG_P32(uap, name), sizeof(sut)); 936 } 937 938 int 939 sunos32_sys_setpgrp(struct lwp *l, const struct sunos32_sys_setpgrp_args *uap, register_t *retval) 940 { 941 /* { 942 syscallarg(int) pid; 943 syscallarg(int) pgid; 944 } */ 945 struct proc *p = l->l_proc; 946 947 /* 948 * difference to our setpgid call is to include backwards 949 * compatibility to pre-setsid() binaries. Do setsid() 950 * instead of setpgid() in those cases where the process 951 * tries to create a new session the old way. 952 */ 953 if (!SCARG(uap, pgid) && 954 (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid)) 955 return sys_setsid(l, NULL, retval); 956 else 957 return netbsd32_setpgid(l, (const void *)uap, retval); 958 } 959 960 int 961 sunos32_sys_open(struct lwp *l, const struct sunos32_sys_open_args *uap, register_t *retval) 962 { 963 /* { 964 syscallarg(const netbsd32_charp) path; 965 syscallarg(int) flags; 966 syscallarg(int) mode; 967 } */ 968 struct proc *p = l->l_proc; 969 struct sys_open_args ua; 970 int lf, r; 971 int noctty; 972 int ret; 973 974 /* convert mode into NetBSD mode */ 975 lf = SCARG(uap, flags); 976 noctty = lf & 0x8000; 977 r = (lf & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800)); 978 r |= ((lf & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0); 979 r |= ((lf & 0x0080) ? O_SHLOCK : 0); 980 r |= ((lf & 0x0100) ? O_EXLOCK : 0); 981 r |= ((lf & 0x2000) ? O_FSYNC : 0); 982 983 SUNOS32TOP_UAP(path, const char); 984 SCARG(&ua, flags) = r; 985 SUNOS32TO64_UAP(mode); 986 987 ret = sys_open(l, &ua, retval); 988 989 /* XXXSMP unlocked */ 990 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_lflag & PL_CONTROLT)) { 991 file_t *fp; 992 int fd; 993 994 fd = (int)*retval; 995 fp = fd_getfile(fd); 996 997 /* ignore any error, just give it a try */ 998 if (fp != NULL) { 999 if (fp->f_type == DTYPE_VNODE) 1000 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, NULL); 1001 fd_putfile(fd); 1002 } 1003 } 1004 return ret; 1005 } 1006 1007 int 1008 sunos32_sys_ustat(struct lwp *l, const struct sunos32_sys_ustat_args *uap, register_t *retval) 1009 { 1010 /* { 1011 syscallarg(int) dev; 1012 syscallarg(sunos32_ustatp_t) buf; 1013 } */ 1014 struct sunos_ustat us; 1015 int error; 1016 1017 memset(&us, 0, sizeof us); 1018 1019 /* 1020 * XXX: should set f_tfree and f_tinode at least 1021 * How do we translate dev -> fstat? (and then to sunos_ustat) 1022 */ 1023 1024 if ((error = copyout(&us, SCARG_P32(uap, buf), sizeof us)) != 0) 1025 return (error); 1026 return 0; 1027 } 1028 1029 int 1030 sunos32_sys_quotactl(struct lwp *l, const struct sunos32_sys_quotactl_args *uap, register_t *retval) 1031 { 1032 1033 return EINVAL; 1034 } 1035 1036 int 1037 sunos32_sys_vhangup(struct lwp *l, const void *v, register_t *retval) 1038 { 1039 struct proc *p = l->l_proc; 1040 struct session *sp = p->p_session; 1041 1042 if (sp->s_ttyvp == 0) 1043 return 0; 1044 1045 if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp) 1046 pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1); 1047 1048 (void) ttywait(sp->s_ttyp); 1049 if (sp->s_ttyvp) 1050 VOP_REVOKE(sp->s_ttyvp, REVOKEALL); 1051 if (sp->s_ttyvp) 1052 vrele(sp->s_ttyvp); 1053 sp->s_ttyvp = NULL; 1054 1055 return 0; 1056 } 1057 1058 static int 1059 sunstatfs(struct statvfs *sp, void *sbuf) 1060 { 1061 struct sunos_statfs ssfs; 1062 1063 memset(&ssfs, 0, sizeof ssfs); 1064 ssfs.f_type = 0; 1065 ssfs.f_bsize = sp->f_bsize; 1066 ssfs.f_blocks = sp->f_blocks; 1067 ssfs.f_bfree = sp->f_bfree; 1068 ssfs.f_bavail = sp->f_bavail; 1069 ssfs.f_files = sp->f_files; 1070 ssfs.f_ffree = sp->f_ffree; 1071 ssfs.f_fsid = sp->f_fsidx; 1072 return copyout((void *)&ssfs, sbuf, sizeof ssfs); 1073 } 1074 1075 int 1076 sunos32_sys_statfs(struct lwp *l, const struct sunos32_sys_statfs_args *uap, register_t *retval) 1077 { 1078 /* { 1079 syscallarg(const netbsd32_charp) path; 1080 syscallarg(sunos32_statfsp_t) buf; 1081 } */ 1082 struct statvfs *sp; 1083 int error; 1084 1085 sp = STATVFSBUF_GET(); 1086 error = do_sys_pstatvfs(l, SCARG_P32(uap, path), 0, sp); 1087 if (error == 0) 1088 error = sunstatfs(sp, SCARG_P32(uap, buf)); 1089 STATVFSBUF_PUT(sp); 1090 return error; 1091 } 1092 1093 int 1094 sunos32_sys_fstatfs(struct lwp *l, const struct sunos32_sys_fstatfs_args *uap, register_t *retval) 1095 { 1096 /* { 1097 syscallarg(int) fd; 1098 syscallarg(sunos32_statfsp_t) buf; 1099 } */ 1100 struct statvfs *sp; 1101 int error; 1102 1103 sp = STATVFSBUF_GET(); 1104 error = do_sys_fstatvfs(l, SCARG(uap, fd), 0, sp); 1105 if (error == 0) 1106 error = sunstatfs(sp, SCARG_P32(uap, buf)); 1107 STATVFSBUF_PUT(sp); 1108 return error; 1109 } 1110 1111 int 1112 sunos32_sys_exportfs(struct lwp *l, const struct sunos32_sys_exportfs_args *uap, register_t *retval) 1113 { 1114 /* 1115 * XXX: should perhaps translate into a mount(2) 1116 * with MOUNT_EXPORT? 1117 */ 1118 return 0; 1119 } 1120 1121 int 1122 sunos32_sys_mknod(struct lwp *l, const struct sunos32_sys_mknod_args *uap, register_t *retval) 1123 { 1124 /* { 1125 syscallarg(const netbsd32_charp) path; 1126 syscallarg(int) mode; 1127 syscallarg(int) dev; 1128 } */ 1129 1130 if (S_ISFIFO(SCARG(uap, mode))) 1131 return netbsd32_mkfifo(l, (const struct netbsd32_mkfifo_args *)uap, retval); 1132 1133 return compat_50_netbsd32_mknod(l, (const struct compat_50_netbsd32_mknod_args *)uap, retval); 1134 } 1135 1136 #define SUNOS_SC_ARG_MAX 1 1137 #define SUNOS_SC_CHILD_MAX 2 1138 #define SUNOS_SC_CLK_TCK 3 1139 #define SUNOS_SC_NGROUPS_MAX 4 1140 #define SUNOS_SC_OPEN_MAX 5 1141 #define SUNOS_SC_JOB_CONTROL 6 1142 #define SUNOS_SC_SAVED_IDS 7 1143 #define SUNOS_SC_VERSION 8 1144 1145 int 1146 sunos32_sys_sysconf(struct lwp *l, const struct sunos32_sys_sysconf_args *uap, register_t *retval) 1147 { 1148 /* { 1149 syscallarg(int) name; 1150 } */ 1151 extern u_int maxfiles; 1152 1153 switch(SCARG(uap, name)) { 1154 case SUNOS_SC_ARG_MAX: 1155 *retval = ARG_MAX; 1156 break; 1157 case SUNOS_SC_CHILD_MAX: 1158 *retval = maxproc; 1159 break; 1160 case SUNOS_SC_CLK_TCK: 1161 *retval = 60; /* should this be `hz', ie. 100? */ 1162 break; 1163 case SUNOS_SC_NGROUPS_MAX: 1164 *retval = NGROUPS_MAX; 1165 break; 1166 case SUNOS_SC_OPEN_MAX: 1167 *retval = maxfiles; 1168 break; 1169 case SUNOS_SC_JOB_CONTROL: 1170 *retval = 1; 1171 break; 1172 case SUNOS_SC_SAVED_IDS: 1173 #ifdef _POSIX_SAVED_IDS 1174 *retval = 1; 1175 #else 1176 *retval = 0; 1177 #endif 1178 break; 1179 case SUNOS_SC_VERSION: 1180 *retval = 198808; 1181 break; 1182 default: 1183 return EINVAL; 1184 } 1185 return 0; 1186 } 1187 1188 #define SUNOS_RLIMIT_NOFILE 6 /* Other RLIMIT_* are the same */ 1189 #define SUNOS_RLIM_NLIMITS 7 1190 1191 int 1192 sunos32_sys_getrlimit(struct lwp *l, const struct sunos32_sys_getrlimit_args *uap, register_t *retval) 1193 { 1194 /* { 1195 syscallarg(u_int) which; 1196 syscallarg(netbsd32_orlimitp_t) rlp; 1197 } */ 1198 struct compat_43_netbsd32_ogetrlimit_args ua_43; 1199 1200 if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS) 1201 return EINVAL; 1202 1203 SCARG(&ua_43, which) = SCARG(uap, which) == SUNOS_RLIMIT_NOFILE ? RLIMIT_NOFILE : SCARG(uap, which); 1204 SCARG(&ua_43, rlp) = SCARG(uap, rlp); 1205 1206 return compat_43_netbsd32_ogetrlimit(l, &ua_43, retval); 1207 } 1208 1209 int 1210 sunos32_sys_setrlimit(struct lwp *l, const struct sunos32_sys_setrlimit_args *uap, register_t *retval) 1211 { 1212 /* { 1213 syscallarg(u_int) which; 1214 syscallarg(netbsd32_orlimitp_t) rlp; 1215 } */ 1216 struct compat_43_netbsd32_osetrlimit_args ua_43; 1217 1218 if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS) 1219 return EINVAL; 1220 1221 SCARG(&ua_43, which) = SCARG(uap, which) == SUNOS_RLIMIT_NOFILE ? RLIMIT_NOFILE : SCARG(uap, which); 1222 SCARG(&ua_43, rlp) = SCARG(uap, rlp); 1223 1224 return compat_43_netbsd32_osetrlimit(l, &ua_43, retval); 1225 } 1226 1227 /* for the m68k machines */ 1228 #ifndef PT_GETFPREGS 1229 #define PT_GETFPREGS -1 1230 #endif 1231 #ifndef PT_SETFPREGS 1232 #define PT_SETFPREGS -1 1233 #endif 1234 1235 static const int sreq2breq[] = { 1236 PT_TRACE_ME, PT_READ_I, PT_READ_D, -1, 1237 PT_WRITE_I, PT_WRITE_D, -1, PT_CONTINUE, 1238 PT_KILL, -1, PT_ATTACH, PT_DETACH, 1239 PT_GETREGS, PT_SETREGS, PT_GETFPREGS, PT_SETFPREGS 1240 }; 1241 static const size_t nreqs = __arraycount(sreq2breq); 1242 1243 int 1244 sunos32_sys_ptrace(struct lwp *l, const struct sunos32_sys_ptrace_args *uap, register_t *retval) 1245 { 1246 /* { 1247 syscallarg(int) req; 1248 syscallarg(pid_t) pid; 1249 syscallarg(netbsd32_caddr_t) addr; 1250 syscallarg(int) data; 1251 syscallarg(netbsd32_charp) addr2; 1252 } */ 1253 struct netbsd32_ptrace_args pa; 1254 int req; 1255 1256 #define sys_ptrace sysent[SYS_ptrace].sy_call 1257 if (sys_ptrace == sys_nosys) 1258 return ENOSYS; 1259 1260 req = SCARG(uap, req); 1261 if ((unsigned int)req >= nreqs) 1262 return (EINVAL); 1263 1264 req = sreq2breq[req]; 1265 if (req == -1) 1266 return (EINVAL); 1267 1268 SCARG(&pa, req) = req; 1269 SCARG(&pa, pid) = (pid_t)SCARG(uap, pid); 1270 SCARG(&pa, addr) = SCARG(uap, addr); 1271 SCARG(&pa, data) = SCARG(uap, data); 1272 1273 return netbsd32_ptrace(l, &pa, retval); 1274 } 1275 1276 /* 1277 * SunOS reboot system call (for compatibility). 1278 * Sun lets you pass in a boot string which the PROM 1279 * saves and provides to the next boot program. 1280 */ 1281 1282 #define SUNOS_RB_ASKNAME 0x001 1283 #define SUNOS_RB_SINGLE 0x002 1284 #define SUNOS_RB_NOSYNC 0x004 1285 #define SUNOS_RB_HALT 0x008 1286 #define SUNOS_RB_DUMP 0x080 1287 #define SUNOS_RB_STRING 0x200 1288 1289 static struct sunos_howto_conv { 1290 int sun_howto; 1291 int bsd_howto; 1292 } sunos_howto_conv[] = { 1293 { SUNOS_RB_ASKNAME, RB_ASKNAME }, 1294 { SUNOS_RB_SINGLE, RB_SINGLE }, 1295 { SUNOS_RB_NOSYNC, RB_NOSYNC }, 1296 { SUNOS_RB_HALT, RB_HALT }, 1297 { SUNOS_RB_DUMP, RB_DUMP }, 1298 { SUNOS_RB_STRING, RB_STRING }, 1299 { 0x000, 0 }, 1300 }; 1301 1302 int 1303 sunos32_sys_reboot(struct lwp *l, const struct sunos32_sys_reboot_args *uap, register_t *retval) 1304 { 1305 /* { 1306 syscallarg(int) howto; 1307 syscallarg(netbsd32_charp) bootstr; 1308 } */ 1309 struct sys_reboot_args ua; 1310 struct sunos_howto_conv *convp; 1311 int error, bsd_howto, sun_howto; 1312 char *bootstr; 1313 1314 if ((error = kauth_authorize_system(l->l_cred, 1315 KAUTH_SYSTEM_REBOOT, 0, NULL, NULL, NULL)) != 0) 1316 return (error); 1317 1318 /* 1319 * Convert howto bits to BSD format. 1320 */ 1321 sun_howto = SCARG(uap, howto); 1322 bsd_howto = 0; 1323 convp = sunos_howto_conv; 1324 while (convp->sun_howto) { 1325 if (sun_howto & convp->sun_howto) 1326 bsd_howto |= convp->bsd_howto; 1327 convp++; 1328 } 1329 1330 /* 1331 * Sun RB_STRING (Get user supplied bootstring.) 1332 * If the machine supports passing a string to the 1333 * next booted kernel. 1334 */ 1335 if (sun_howto & SUNOS_RB_STRING) 1336 bootstr = SCARG_P32(uap, bootstr); 1337 else 1338 bootstr = NULL; 1339 1340 SCARG(&ua, opt) = bsd_howto; 1341 SCARG(&ua, bootstr) = bootstr; 1342 return (sys_reboot(l, &ua, retval)); 1343 } 1344 1345 /* 1346 * Generalized interface signal handler, 4.3-compatible. 1347 */ 1348 /* ARGSUSED */ 1349 int 1350 sunos32_sys_sigvec(struct lwp *l, const struct sunos32_sys_sigvec_args *uap, register_t *retval) 1351 { 1352 /* { 1353 syscallarg(int) signum; 1354 syscallarg(struct sigvec *) nsv; 1355 syscallarg(struct sigvec *) osv; 1356 } */ 1357 struct netbsd32_sigvec sv; 1358 struct sigaction nsa, osa; 1359 int error; 1360 1361 if (SCARG_P32(uap, nsv)) { 1362 error = copyin(SCARG_P32(uap, nsv), &sv, sizeof(sv)); 1363 if (error != 0) 1364 return (error); 1365 1366 /* 1367 * SunOS uses the mask 0x0004 as SV_RESETHAND 1368 * meaning: `reset to SIG_DFL on delivery'. 1369 * We support only the bits in: 0xF 1370 * (those bits are the same as ours) 1371 */ 1372 if (sv.sv_flags & ~0xF) 1373 return (EINVAL); 1374 1375 sunos32_sigvec_to_sigaction(&sv, &nsa); 1376 } 1377 error = sigaction1(l, SCARG(uap, signum), 1378 SCARG_P32(uap, nsv) ? &nsa : 0, 1379 SCARG_P32(uap, osv) ? &osa : 0, 1380 NULL, 0); 1381 if (error != 0) 1382 return (error); 1383 1384 if (SCARG_P32(uap, osv)) { 1385 sunos32_sigvec_from_sigaction(&sv, &osa); 1386 error = copyout(&sv, SCARG_P32(uap, osv), sizeof(sv)); 1387 if (error != 0) 1388 return (error); 1389 } 1390 1391 return (0); 1392 } 1393