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