1 /* $NetBSD: sunos32_misc.c,v 1.28 2004/09/17 14:11:24 skrll 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.28 2004/09/17 14:11:24 skrll 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(uap, 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, buf; /* 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 buf = 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 = buf; 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 = buf; 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 >> 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 off = *cookie++; 776 continue; 777 } 778 sunos_reclen = SUNOS32_RECLEN(&idb, bdp->d_namlen); 779 if (reclen > len || resid < sunos_reclen) { 780 /* entry too big for buffer, so just stop */ 781 outp++; 782 break; 783 } 784 off = *cookie++; /* each entry points to next */ 785 /* 786 * Massage in place to make a Sun-shaped dirent (otherwise 787 * we have to worry about touching user memory outside of 788 * the copyout() call). 789 */ 790 idb.d_fileno = bdp->d_fileno; 791 idb.d_off = off; 792 idb.d_reclen = sunos_reclen; 793 idb.d_namlen = bdp->d_namlen; 794 strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name)); 795 if ((error = copyout((caddr_t)&idb, outp, sunos_reclen)) != 0) 796 goto out; 797 /* advance past this real entry */ 798 inp += reclen; 799 /* advance output past Sun-shaped entry */ 800 outp += sunos_reclen; 801 resid -= sunos_reclen; 802 } 803 804 /* if we squished out the whole block, try again */ 805 if (outp == (caddr_t)(u_long)SCARG(uap, buf)) 806 goto again; 807 fp->f_offset = off; /* update the vnode offset */ 808 809 eof: 810 *retval = SCARG(uap, nbytes) - resid; 811 out: 812 VOP_UNLOCK(vp, 0); 813 free(cookiebuf, M_TEMP); 814 free(buf, M_TEMP); 815 out1: 816 FILE_UNUSE(fp, p); 817 return (error); 818 } 819 820 #define SUNOS32__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */ 821 822 int 823 sunos32_sys_mmap(l, v, retval) 824 struct lwp *l; 825 void *v; 826 register_t *retval; 827 { 828 struct sunos32_sys_mmap_args /* { 829 syscallarg(netbsd32_voidp) addr; 830 syscallarg(netbsd32_size_t) len; 831 syscallarg(int) prot; 832 syscallarg(int) flags; 833 syscallarg(int) fd; 834 syscallarg(netbsd32_long) pos; 835 } */ *uap = v; 836 struct sys_mmap_args ua; 837 int error; 838 839 /* 840 * Verify the arguments. 841 */ 842 if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC)) 843 return (EINVAL); /* XXX still needed? */ 844 845 if ((SCARG(uap, flags) & SUNOS32__MAP_NEW) == 0) 846 return (EINVAL); 847 848 SUNOS32TOP_UAP(addr, void); 849 SUNOS32TOX_UAP(len, size_t); 850 SUNOS32TO64_UAP(prot); 851 SCARG(&ua, flags) = SCARG(uap, flags) & ~SUNOS32__MAP_NEW; 852 SUNOS32TO64_UAP(fd); 853 SCARG(&ua, pad) = 0; 854 SUNOS32TOX_UAP(pos, off_t); 855 856 error = sys_mmap(l, &ua, retval); 857 if ((u_long)*retval > (u_long)UINT_MAX) { 858 printf("sunos32_mmap: retval out of range: 0x%lx", 859 (u_long)*retval); 860 /* Should try to recover and return an error here. */ 861 } 862 return (error); 863 } 864 865 #define MC_SYNC 1 866 #define MC_LOCK 2 867 #define MC_UNLOCK 3 868 #define MC_ADVISE 4 869 #define MC_LOCKAS 5 870 #define MC_UNLOCKAS 6 871 872 int 873 sunos32_sys_mctl(l, v, retval) 874 struct lwp *l; 875 void *v; 876 register_t *retval; 877 { 878 struct sunos32_sys_mctl_args /* { 879 syscallarg(netbsd32_voidp) addr; 880 syscallarg(int) len; 881 syscallarg(int) func; 882 syscallarg(netbsd32_voidp) arg; 883 } */ *uap = v; 884 885 switch (SCARG(uap, func)) { 886 case MC_ADVISE: /* ignore for now */ 887 return (0); 888 case MC_SYNC: /* translate to msync */ 889 return (netbsd32___msync13(l, uap, retval)); 890 default: 891 return (EINVAL); 892 } 893 } 894 895 int 896 sunos32_sys_setsockopt(l, v, retval) 897 struct lwp *l; 898 void *v; 899 register_t *retval; 900 { 901 struct sunos32_sys_setsockopt_args /* { 902 syscallarg(int) s; 903 syscallarg(int) level; 904 syscallarg(int) name; 905 syscallarg(netbsd32_caddr_t) val; 906 syscallarg(int) valsize; 907 } */ *uap = v; 908 struct proc *p = l->l_proc; 909 struct file *fp; 910 struct mbuf *m = NULL; 911 int error; 912 913 /* getsock() will use the descriptor for us */ 914 if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) 915 return (error); 916 #define SO_DONTLINGER (~SO_LINGER) 917 if (SCARG(uap, name) == SO_DONTLINGER) { 918 m = m_get(M_WAIT, MT_SOOPTS); 919 mtod(m, struct linger *)->l_onoff = 0; 920 m->m_len = sizeof(struct linger); 921 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level), 922 SO_LINGER, m); 923 goto out; 924 } 925 if (SCARG(uap, level) == IPPROTO_IP) { 926 #define SUNOS_IP_MULTICAST_IF 2 927 #define SUNOS_IP_MULTICAST_TTL 3 928 #define SUNOS_IP_MULTICAST_LOOP 4 929 #define SUNOS_IP_ADD_MEMBERSHIP 5 930 #define SUNOS_IP_DROP_MEMBERSHIP 6 931 static const int ipoptxlat[] = { 932 IP_MULTICAST_IF, 933 IP_MULTICAST_TTL, 934 IP_MULTICAST_LOOP, 935 IP_ADD_MEMBERSHIP, 936 IP_DROP_MEMBERSHIP 937 }; 938 if (SCARG(uap, name) >= SUNOS_IP_MULTICAST_IF && 939 SCARG(uap, name) <= SUNOS_IP_DROP_MEMBERSHIP) { 940 SCARG(uap, name) = 941 ipoptxlat[SCARG(uap, name) - SUNOS_IP_MULTICAST_IF]; 942 } 943 } 944 if (SCARG(uap, valsize) > MLEN) { 945 error = EINVAL; 946 goto out; 947 } 948 if (SCARG(uap, val)) { 949 m = m_get(M_WAIT, MT_SOOPTS); 950 error = copyin((caddr_t)(u_long)SCARG(uap, val), mtod(m, caddr_t), 951 (u_int)SCARG(uap, valsize)); 952 if (error) { 953 (void) m_free(m); 954 goto out; 955 } 956 m->m_len = SCARG(uap, valsize); 957 } 958 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level), 959 SCARG(uap, name), m); 960 out: 961 FILE_UNUSE(fp, p); 962 return (error); 963 } 964 965 static __inline__ int sunos32_sys_socket_common(struct lwp *, register_t *, 966 int type); 967 static __inline__ int 968 sunos32_sys_socket_common(l, retval, type) 969 struct lwp *l; 970 register_t *retval; 971 int type; 972 { 973 struct socket *so; 974 struct proc *p = l->l_proc; 975 struct file *fp; 976 int error, fd; 977 978 /* getsock() will use the descriptor for us */ 979 fd = (int)*retval; 980 if ((error = getsock(p->p_fd, fd, &fp)) == 0) { 981 so = (struct socket *)fp->f_data; 982 if (type == SOCK_DGRAM) 983 so->so_options |= SO_BROADCAST; 984 } 985 FILE_UNUSE(fp, p); 986 return (error); 987 } 988 989 int 990 sunos32_sys_socket(l, v, retval) 991 struct lwp *l; 992 void *v; 993 register_t *retval; 994 { 995 struct sunos32_sys_socket_args /* { 996 syscallarg(int) domain; 997 syscallarg(int) type; 998 syscallarg(int) protocol; 999 } */ *uap = v; 1000 int error; 1001 1002 error = netbsd32_socket(l, v, retval); 1003 if (error) 1004 return (error); 1005 return sunos32_sys_socket_common(l, retval, SCARG(uap, type)); 1006 } 1007 1008 int 1009 sunos32_sys_socketpair(l, v, retval) 1010 struct lwp *l; 1011 void *v; 1012 register_t *retval; 1013 { 1014 struct sunos32_sys_socketpair_args /* { 1015 syscallarg(int) domain; 1016 syscallarg(int) type; 1017 syscallarg(int) protocol; 1018 syscallarg(int *) rsv; 1019 } */ *uap = v; 1020 int error; 1021 1022 error = netbsd32_socketpair(l, v, retval); 1023 if (error) 1024 return (error); 1025 return sunos32_sys_socket_common(l, retval, SCARG(uap, type)); 1026 } 1027 1028 1029 /* 1030 * XXX: This needs cleaning up. 1031 */ 1032 int 1033 sunos32_sys_auditsys(l, v, retval) 1034 struct lwp *l; 1035 void *v; 1036 register_t *retval; 1037 { 1038 return 0; 1039 } 1040 1041 int 1042 sunos32_sys_uname(l, v, retval) 1043 struct lwp *l; 1044 void *v; 1045 register_t *retval; 1046 { 1047 struct sunos32_sys_uname_args /* { 1048 syscallarg(sunos32_utsnamep_t) name; 1049 } */ *uap = v; 1050 struct sunos_utsname sut; 1051 1052 memset(&sut, 0, sizeof(sut)); 1053 1054 memcpy(sut.sysname, ostype, sizeof(sut.sysname) - 1); 1055 memcpy(sut.nodename, hostname, sizeof(sut.nodename)); 1056 sut.nodename[sizeof(sut.nodename)-1] = '\0'; 1057 memcpy(sut.release, osrelease, sizeof(sut.release) - 1); 1058 memcpy(sut.version, "1", sizeof(sut.version) - 1); 1059 memcpy(sut.machine, machine, sizeof(sut.machine) - 1); 1060 1061 return copyout((caddr_t)&sut, (caddr_t)(u_long)SCARG(uap, name), 1062 sizeof(struct sunos_utsname)); 1063 } 1064 1065 int 1066 sunos32_sys_setpgrp(l, v, retval) 1067 struct lwp *l; 1068 void *v; 1069 register_t *retval; 1070 { 1071 struct sunos32_sys_setpgrp_args /* { 1072 syscallarg(int) pid; 1073 syscallarg(int) pgid; 1074 } */ *uap = v; 1075 struct proc *p = l->l_proc; 1076 1077 /* 1078 * difference to our setpgid call is to include backwards 1079 * compatibility to pre-setsid() binaries. Do setsid() 1080 * instead of setpgid() in those cases where the process 1081 * tries to create a new session the old way. 1082 */ 1083 if (!SCARG(uap, pgid) && 1084 (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid)) 1085 return sys_setsid(l, uap, retval); 1086 else 1087 return netbsd32_setpgid(l, uap, retval); 1088 } 1089 1090 int 1091 sunos32_sys_open(l, v, retval) 1092 struct lwp *l; 1093 void *v; 1094 register_t *retval; 1095 { 1096 struct sunos32_sys_open_args /* { 1097 syscallarg(const netbsd32_charp) path; 1098 syscallarg(int) flags; 1099 syscallarg(int) mode; 1100 } */ *uap = v; 1101 struct proc *p = l->l_proc; 1102 struct sys_open_args ua; 1103 int lf, r; 1104 int noctty; 1105 int ret; 1106 caddr_t sg = stackgap_init(p, 0); 1107 1108 /* convert mode into NetBSD mode */ 1109 lf = SCARG(uap, flags); 1110 noctty = lf & 0x8000; 1111 r = (lf & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800)); 1112 r |= ((lf & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0); 1113 r |= ((lf & 0x0080) ? O_SHLOCK : 0); 1114 r |= ((lf & 0x0100) ? O_EXLOCK : 0); 1115 r |= ((lf & 0x2000) ? O_FSYNC : 0); 1116 1117 SUNOS32TOP_UAP(path, const char); 1118 SCARG(&ua, flags) = r; 1119 SUNOS32TO64_UAP(mode); 1120 1121 if (r & O_CREAT) 1122 SUNOS32_CHECK_ALT_CREAT(p, &sg, SCARG(&ua, path)); 1123 else 1124 SUNOS32_CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path)); 1125 1126 ret = sys_open(l, &ua, retval); 1127 1128 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) { 1129 struct filedesc *fdp = p->p_fd; 1130 struct file *fp; 1131 1132 fp = fd_getfile(fdp, *retval); 1133 1134 /* ignore any error, just give it a try */ 1135 if (fp != NULL && fp->f_type == DTYPE_VNODE) 1136 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p); 1137 } 1138 return ret; 1139 } 1140 1141 #if defined (NFSSERVER) 1142 int 1143 sunos32_sys_nfssvc(l, v, retval) 1144 struct lwp *l; 1145 void *v; 1146 register_t *retval; 1147 { 1148 #if 0 1149 struct sunos32_sys_nfssvc_args *uap = v; 1150 struct emul *e = p->p_emul; 1151 struct sys_nfssvc_args outuap; 1152 struct sockaddr sa; 1153 int error; 1154 caddr_t sg = stackgap_init(p, 0); 1155 1156 memset(&outuap, 0, sizeof outuap); 1157 SCARG(&outuap, fd) = SCARG(uap, fd); 1158 SCARG(&outuap, mskval) = stackgap_alloc(p, &sg, sizeof(sa)); 1159 SCARG(&outuap, msklen) = sizeof(sa); 1160 SCARG(&outuap, mtchval) = stackgap_alloc(p, &sg, sizeof(sa)); 1161 SCARG(&outuap, mtchlen) = sizeof(sa); 1162 1163 memset(&sa, 0, sizeof sa); 1164 if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen))) 1165 return (error); 1166 if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen))) 1167 return (error); 1168 1169 return nfssvc(l, &outuap, retval); 1170 #else 1171 return (ENOSYS); 1172 #endif 1173 } 1174 #endif /* NFSSERVER */ 1175 1176 int 1177 sunos32_sys_ustat(l, v, retval) 1178 struct lwp *l; 1179 void *v; 1180 register_t *retval; 1181 { 1182 struct sunos32_sys_ustat_args /* { 1183 syscallarg(int) dev; 1184 syscallarg(sunos32_ustatp_t) buf; 1185 } */ *uap = v; 1186 struct sunos_ustat us; 1187 int error; 1188 1189 memset(&us, 0, sizeof us); 1190 1191 /* 1192 * XXX: should set f_tfree and f_tinode at least 1193 * How do we translate dev -> fstat? (and then to sunos_ustat) 1194 */ 1195 1196 if ((error = copyout(&us, (caddr_t)(u_long)SCARG(uap, buf), sizeof us)) != 0) 1197 return (error); 1198 return 0; 1199 } 1200 1201 int 1202 sunos32_sys_quotactl(l, v, retval) 1203 struct lwp *l; 1204 void *v; 1205 register_t *retval; 1206 { 1207 1208 return EINVAL; 1209 } 1210 1211 int 1212 sunos32_sys_vhangup(l, v, retval) 1213 struct lwp *l; 1214 void *v; 1215 register_t *retval; 1216 { 1217 struct proc *p = l->l_proc; 1218 struct session *sp = p->p_session; 1219 1220 if (sp->s_ttyvp == 0) 1221 return 0; 1222 1223 if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp) 1224 pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1); 1225 1226 (void) ttywait(sp->s_ttyp); 1227 if (sp->s_ttyvp) 1228 VOP_REVOKE(sp->s_ttyvp, REVOKEALL); 1229 if (sp->s_ttyvp) 1230 vrele(sp->s_ttyvp); 1231 sp->s_ttyvp = NULL; 1232 1233 return 0; 1234 } 1235 1236 static int 1237 sunstatfs(sp, buf) 1238 struct statvfs *sp; 1239 caddr_t buf; 1240 { 1241 struct sunos_statfs ssfs; 1242 1243 memset(&ssfs, 0, sizeof ssfs); 1244 ssfs.f_type = 0; 1245 ssfs.f_bsize = sp->f_bsize; 1246 ssfs.f_blocks = sp->f_blocks; 1247 ssfs.f_bfree = sp->f_bfree; 1248 ssfs.f_bavail = sp->f_bavail; 1249 ssfs.f_files = sp->f_files; 1250 ssfs.f_ffree = sp->f_ffree; 1251 ssfs.f_fsid = sp->f_fsidx; 1252 return copyout((caddr_t)&ssfs, buf, sizeof ssfs); 1253 } 1254 1255 int 1256 sunos32_sys_statfs(l, v, retval) 1257 struct lwp *l; 1258 void *v; 1259 register_t *retval; 1260 { 1261 struct sunos32_sys_statfs_args /* { 1262 syscallarg(const netbsd32_charp) path; 1263 syscallarg(sunos32_statfsp_t) buf; 1264 } */ *uap = v; 1265 struct proc *p = l->l_proc; 1266 struct mount *mp; 1267 struct statvfs *sp; 1268 int error; 1269 struct nameidata nd; 1270 1271 caddr_t sg = stackgap_init(p, 0); 1272 SUNOS32_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path)); 1273 1274 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, (caddr_t)(u_long)SCARG(uap, path), p); 1275 if ((error = namei(&nd)) != 0) 1276 return (error); 1277 mp = nd.ni_vp->v_mount; 1278 sp = &mp->mnt_stat; 1279 vrele(nd.ni_vp); 1280 if ((error = VFS_STATVFS(mp, sp, p)) != 0) 1281 return (error); 1282 sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK; 1283 return sunstatfs(sp, (caddr_t)(u_long)SCARG(uap, buf)); 1284 } 1285 1286 int 1287 sunos32_sys_fstatfs(l, v, retval) 1288 struct lwp *l; 1289 void *v; 1290 register_t *retval; 1291 { 1292 struct sunos32_sys_fstatfs_args /* { 1293 syscallarg(int) fd; 1294 syscallarg(sunos32_statfsp_t) buf; 1295 } */ *uap = v; 1296 struct proc *p = l->l_proc; 1297 struct file *fp; 1298 struct mount *mp; 1299 struct statvfs *sp; 1300 int error; 1301 1302 /* getvnode() will use the descriptor for us */ 1303 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) 1304 return (error); 1305 mp = ((struct vnode *)fp->f_data)->v_mount; 1306 sp = &mp->mnt_stat; 1307 if ((error = VFS_STATVFS(mp, sp, p)) != 0) 1308 goto out; 1309 sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK; 1310 error = sunstatfs(sp, (caddr_t)(u_long)SCARG(uap, buf)); 1311 out: 1312 FILE_UNUSE(fp, p); 1313 return (error); 1314 } 1315 1316 int 1317 sunos32_sys_exportfs(l, v, retval) 1318 struct lwp *l; 1319 void *v; 1320 register_t *retval; 1321 { 1322 /* 1323 * XXX: should perhaps translate into a mount(2) 1324 * with MOUNT_EXPORT? 1325 */ 1326 return 0; 1327 } 1328 1329 int 1330 sunos32_sys_mknod(l, v, retval) 1331 struct lwp *l; 1332 void *v; 1333 register_t *retval; 1334 { 1335 struct sunos32_sys_mknod_args /* { 1336 syscallarg(const netbsd32_charp) path; 1337 syscallarg(int) mode; 1338 syscallarg(int) dev; 1339 } */ *uap = v; 1340 struct proc *p = l->l_proc; 1341 1342 caddr_t sg = stackgap_init(p, 0); 1343 SUNOS32_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path)); 1344 1345 /* netbsd32_mkfifo/mknod to not do alt checking */ 1346 if (S_ISFIFO(SCARG(uap, mode))) 1347 return netbsd32_mkfifo(l, (struct netbsd32_mkfifo_args *)uap, retval); 1348 1349 return netbsd32_mknod(l, (struct netbsd32_mknod_args *)uap, retval); 1350 } 1351 1352 #define SUNOS_SC_ARG_MAX 1 1353 #define SUNOS_SC_CHILD_MAX 2 1354 #define SUNOS_SC_CLK_TCK 3 1355 #define SUNOS_SC_NGROUPS_MAX 4 1356 #define SUNOS_SC_OPEN_MAX 5 1357 #define SUNOS_SC_JOB_CONTROL 6 1358 #define SUNOS_SC_SAVED_IDS 7 1359 #define SUNOS_SC_VERSION 8 1360 1361 int 1362 sunos32_sys_sysconf(l, v, retval) 1363 struct lwp *l; 1364 void *v; 1365 register_t *retval; 1366 { 1367 struct sunos32_sys_sysconf_args /* { 1368 syscallarg(int) name; 1369 } */ *uap = v; 1370 extern int maxfiles; 1371 1372 switch(SCARG(uap, name)) { 1373 case SUNOS_SC_ARG_MAX: 1374 *retval = ARG_MAX; 1375 break; 1376 case SUNOS_SC_CHILD_MAX: 1377 *retval = maxproc; 1378 break; 1379 case SUNOS_SC_CLK_TCK: 1380 *retval = 60; /* should this be `hz', ie. 100? */ 1381 break; 1382 case SUNOS_SC_NGROUPS_MAX: 1383 *retval = NGROUPS_MAX; 1384 break; 1385 case SUNOS_SC_OPEN_MAX: 1386 *retval = maxfiles; 1387 break; 1388 case SUNOS_SC_JOB_CONTROL: 1389 *retval = 1; 1390 break; 1391 case SUNOS_SC_SAVED_IDS: 1392 #ifdef _POSIX_SAVED_IDS 1393 *retval = 1; 1394 #else 1395 *retval = 0; 1396 #endif 1397 break; 1398 case SUNOS_SC_VERSION: 1399 *retval = 198808; 1400 break; 1401 default: 1402 return EINVAL; 1403 } 1404 return 0; 1405 } 1406 1407 #define SUNOS_RLIMIT_NOFILE 6 /* Other RLIMIT_* are the same */ 1408 #define SUNOS_RLIM_NLIMITS 7 1409 1410 int 1411 sunos32_sys_getrlimit(l, v, retval) 1412 struct lwp *l; 1413 void *v; 1414 register_t *retval; 1415 { 1416 struct sunos32_sys_getrlimit_args /* { 1417 syscallarg(u_int) which; 1418 syscallarg(netbsd32_orlimitp_t) rlp; 1419 } */ *uap = v; 1420 1421 if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS) 1422 return EINVAL; 1423 1424 if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE) 1425 SCARG(uap, which) = RLIMIT_NOFILE; 1426 1427 return compat_43_netbsd32_ogetrlimit(l, uap, retval); 1428 } 1429 1430 int 1431 sunos32_sys_setrlimit(l, v, retval) 1432 struct lwp *l; 1433 void *v; 1434 register_t *retval; 1435 { 1436 struct sunos32_sys_setrlimit_args /* { 1437 syscallarg(u_int) which; 1438 syscallarg(netbsd32_orlimitp_t) rlp; 1439 } */ *uap = v; 1440 1441 if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS) 1442 return EINVAL; 1443 1444 if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE) 1445 SCARG(uap, which) = RLIMIT_NOFILE; 1446 1447 return compat_43_netbsd32_osetrlimit(l, uap, retval); 1448 } 1449 1450 /* for the m68k machines */ 1451 #ifndef PT_GETFPREGS 1452 #define PT_GETFPREGS -1 1453 #endif 1454 #ifndef PT_SETFPREGS 1455 #define PT_SETFPREGS -1 1456 #endif 1457 1458 static const int sreq2breq[] = { 1459 PT_TRACE_ME, PT_READ_I, PT_READ_D, -1, 1460 PT_WRITE_I, PT_WRITE_D, -1, PT_CONTINUE, 1461 PT_KILL, -1, PT_ATTACH, PT_DETACH, 1462 PT_GETREGS, PT_SETREGS, PT_GETFPREGS, PT_SETFPREGS 1463 }; 1464 static const int nreqs = sizeof(sreq2breq) / sizeof(sreq2breq[0]); 1465 1466 int 1467 sunos32_sys_ptrace(l, v, retval) 1468 struct lwp *l; 1469 void *v; 1470 register_t *retval; 1471 { 1472 struct sunos32_sys_ptrace_args /* { 1473 syscallarg(int) req; 1474 syscallarg(pid_t) pid; 1475 syscallarg(netbsd32_caddr_t) addr; 1476 syscallarg(int) data; 1477 syscallarg(netbsd32_charp) addr2; 1478 } */ *uap = v; 1479 struct netbsd32_ptrace_args pa; 1480 int req; 1481 1482 req = SCARG(uap, req); 1483 1484 if (req < 0 || req >= nreqs) 1485 return (EINVAL); 1486 1487 req = sreq2breq[req]; 1488 if (req == -1) 1489 return (EINVAL); 1490 1491 SCARG(&pa, req) = req; 1492 SCARG(&pa, pid) = (pid_t)SCARG(uap, pid); 1493 SCARG(&pa, addr) = SCARG(uap, addr); 1494 SCARG(&pa, data) = SCARG(uap, data); 1495 1496 return netbsd32_ptrace(l, &pa, retval); 1497 } 1498 1499 /* 1500 * SunOS reboot system call (for compatibility). 1501 * Sun lets you pass in a boot string which the PROM 1502 * saves and provides to the next boot program. 1503 */ 1504 1505 #define SUNOS_RB_ASKNAME 0x001 1506 #define SUNOS_RB_SINGLE 0x002 1507 #define SUNOS_RB_NOSYNC 0x004 1508 #define SUNOS_RB_HALT 0x008 1509 #define SUNOS_RB_DUMP 0x080 1510 #define SUNOS_RB_STRING 0x200 1511 1512 static struct sunos_howto_conv { 1513 int sun_howto; 1514 int bsd_howto; 1515 } sunos_howto_conv[] = { 1516 { SUNOS_RB_ASKNAME, RB_ASKNAME }, 1517 { SUNOS_RB_SINGLE, RB_SINGLE }, 1518 { SUNOS_RB_NOSYNC, RB_NOSYNC }, 1519 { SUNOS_RB_HALT, RB_HALT }, 1520 { SUNOS_RB_DUMP, RB_DUMP }, 1521 { SUNOS_RB_STRING, RB_STRING }, 1522 { 0x000, 0 }, 1523 }; 1524 1525 int 1526 sunos32_sys_reboot(l, v, retval) 1527 struct lwp *l; 1528 void *v; 1529 register_t *retval; 1530 { 1531 struct sunos32_sys_reboot_args /* { 1532 syscallarg(int) howto; 1533 syscallarg(netbsd32_charp) bootstr; 1534 } */ *uap = v; 1535 struct proc *p = l->l_proc; 1536 struct sys_reboot_args ua; 1537 struct sunos_howto_conv *convp; 1538 int error, bsd_howto, sun_howto; 1539 char *bootstr; 1540 1541 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) 1542 return (error); 1543 1544 /* 1545 * Convert howto bits to BSD format. 1546 */ 1547 sun_howto = SCARG(uap, howto); 1548 bsd_howto = 0; 1549 convp = sunos_howto_conv; 1550 while (convp->sun_howto) { 1551 if (sun_howto & convp->sun_howto) 1552 bsd_howto |= convp->bsd_howto; 1553 convp++; 1554 } 1555 1556 /* 1557 * Sun RB_STRING (Get user supplied bootstring.) 1558 * If the machine supports passing a string to the 1559 * next booted kernel. 1560 */ 1561 if (sun_howto & SUNOS_RB_STRING) 1562 bootstr = (char *)(u_long)SCARG(uap, bootstr); 1563 else 1564 bootstr = NULL; 1565 1566 SCARG(&ua, opt) = bsd_howto; 1567 SCARG(&ua, bootstr) = bootstr; 1568 return (sys_reboot(l, &ua, retval)); 1569 } 1570 1571 /* 1572 * Generalized interface signal handler, 4.3-compatible. 1573 */ 1574 /* ARGSUSED */ 1575 int 1576 sunos32_sys_sigvec(l, v, retval) 1577 struct lwp *l; 1578 void *v; 1579 register_t *retval; 1580 { 1581 struct sunos32_sys_sigvec_args /* { 1582 syscallarg(int) signum; 1583 syscallarg(struct sigvec *) nsv; 1584 syscallarg(struct sigvec *) osv; 1585 } */ *uap = v; 1586 struct proc *p = l->l_proc; 1587 struct netbsd32_sigvec sv; 1588 struct sigaction nsa, osa; 1589 int error; 1590 1591 if (SCARG(uap, nsv)) { 1592 error = copyin((caddr_t)(u_long)SCARG(uap, nsv), &sv, sizeof(sv)); 1593 if (error != 0) 1594 return (error); 1595 1596 /* 1597 * SunOS uses the mask 0x0004 as SV_RESETHAND 1598 * meaning: `reset to SIG_DFL on delivery'. 1599 * We support only the bits in: 0xF 1600 * (those bits are the same as ours) 1601 */ 1602 if (sv.sv_flags & ~0xF) 1603 return (EINVAL); 1604 1605 sunos32_sigvec_to_sigaction(&sv, &nsa); 1606 } 1607 error = sigaction1(p, SCARG(uap, signum), 1608 SCARG(uap, nsv) ? &nsa : 0, 1609 SCARG(uap, osv) ? &osa : 0, 1610 NULL, 0); 1611 if (error != 0) 1612 return (error); 1613 1614 if (SCARG(uap, osv)) { 1615 sunos32_sigvec_from_sigaction(&sv, &osa); 1616 error = copyout(&sv, (caddr_t)(u_long)SCARG(uap, osv), sizeof(sv)); 1617 if (error != 0) 1618 return (error); 1619 } 1620 1621 return (0); 1622 } 1623