1 /* $NetBSD: ultrix_misc.c,v 1.57 2000/04/28 12:52:52 simonb Exp $ */ 2 3 /* 4 * Copyright (c) 1995, 1997 Jonathan Stone (hereinafter referred to as the author) 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Jonathan Stone for 18 * the NetBSD Project. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35 /* 36 * Copyright (c) 1992, 1993 37 * The Regents of the University of California. All rights reserved. 38 * 39 * This software was developed by the Computer Systems Engineering group 40 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 41 * contributed to Berkeley. 42 * 43 * All advertising materials mentioning features or use of this software 44 * must display the following acknowledgement: 45 * This product includes software developed by the University of 46 * California, Lawrence Berkeley Laboratory. 47 * 48 * Redistribution and use in source and binary forms, with or without 49 * modification, are permitted provided that the following conditions 50 * are met: 51 * 1. Redistributions of source code must retain the above copyright 52 * notice, this list of conditions and the following disclaimer. 53 * 2. Redistributions in binary form must reproduce the above copyright 54 * notice, this list of conditions and the following disclaimer in the 55 * documentation and/or other materials provided with the distribution. 56 * 3. All advertising materials mentioning features or use of this software 57 * must display the following acknowledgement: 58 * This product includes software developed by the University of 59 * California, Berkeley and its contributors. 60 * 4. Neither the name of the University nor the names of its contributors 61 * may be used to endorse or promote products derived from this software 62 * without specific prior written permission. 63 * 64 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 65 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 66 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 67 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 68 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 69 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 70 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 71 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 72 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 73 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 74 * SUCH DAMAGE. 75 * 76 * 77 * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93 78 * 79 * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp 80 */ 81 82 #include "opt_nfsserver.h" 83 #include "opt_sysv.h" 84 85 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 86 87 /* 88 * Ultrix compatibility module. 89 * 90 * Ultrix system calls that are implemented differently in BSD are 91 * handled here. 92 */ 93 94 #include "fs_nfs.h" 95 96 #include <sys/param.h> 97 #include <sys/systm.h> 98 #include <sys/namei.h> 99 #include <sys/dirent.h> 100 #include <sys/proc.h> 101 #include <sys/file.h> 102 #include <sys/filedesc.h> 103 #include <sys/kernel.h> 104 #include <sys/exec.h> 105 #include <sys/malloc.h> 106 #include <sys/mbuf.h> 107 #include <sys/mman.h> 108 #include <sys/mount.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/vnode.h> 115 #include <sys/uio.h> 116 #include <sys/wait.h> 117 #include <sys/utsname.h> 118 #include <sys/unistd.h> 119 #include <sys/ipc.h> 120 121 #include <sys/syscallargs.h> 122 123 #include <compat/ultrix/ultrix_syscall.h> 124 #include <compat/ultrix/ultrix_syscallargs.h> 125 #include <compat/common/compat_util.h> 126 127 #include <netinet/in.h> 128 129 #include <miscfs/specfs/specdev.h> 130 131 #include <nfs/rpcv2.h> 132 #include <nfs/nfsproto.h> 133 #include <nfs/nfs.h> 134 135 #include <vm/vm.h> /* pmap declarations */ 136 137 #include <sys/conf.h> /* iszerodev() */ 138 #include <sys/socketvar.h> /* sosetopt() */ 139 140 #include <compat/ultrix/ultrix_flock.h> 141 142 static int ultrix_to_bsd_flock __P((struct ultrix_flock *, struct flock *)); 143 static void bsd_to_ultrix_flock __P((struct flock *, struct ultrix_flock *)); 144 145 extern struct sysent ultrix_sysent[]; 146 extern char *ultrix_syscallnames[]; 147 148 149 /* 150 * Select the appropriate setregs callback for the target architecture. 151 */ 152 #ifdef __mips__ 153 #include <machine/ecoff_machdep.h> 154 #define ULTRIX_EXEC_SETREGS cpu_exec_ecoff_setregs 155 #endif /* mips */ 156 157 #ifdef __vax__ 158 #define ULTRIX_EXEC_SETREGS setregs 159 #endif /* vax */ 160 161 162 extern void ULTRIX_EXEC_SETREGS __P((struct proc *, struct exec_package *, 163 u_long)); 164 extern char ultrix_sigcode[], ultrix_esigcode[]; 165 166 struct emul emul_ultrix = { 167 "ultrix", 168 NULL, 169 sendsig, 170 ULTRIX_SYS_syscall, 171 ULTRIX_SYS_MAXSYSCALL, 172 ultrix_sysent, 173 ultrix_syscallnames, 174 0, 175 copyargs, 176 ULTRIX_EXEC_SETREGS, 177 ultrix_sigcode, 178 ultrix_esigcode, 179 }; 180 181 #define GSI_PROG_ENV 1 182 183 int 184 ultrix_sys_getsysinfo(p, v, retval) 185 struct proc *p; 186 void *v; 187 register_t *retval; 188 { 189 struct ultrix_sys_getsysinfo_args *uap = v; 190 static short progenv = 0; 191 192 switch (SCARG(uap, op)) { 193 /* operations implemented: */ 194 case GSI_PROG_ENV: 195 if (SCARG(uap, nbytes) < sizeof(short)) 196 return EINVAL; 197 *retval = 1; 198 return (copyout(&progenv, SCARG(uap, buffer), sizeof(short))); 199 default: 200 *retval = 0; /* info unavail */ 201 return 0; 202 } 203 } 204 205 int 206 ultrix_sys_setsysinfo(p, v, retval) 207 struct proc *p; 208 void *v; 209 register_t *retval; 210 { 211 212 #ifdef notyet 213 struct ultrix_sys_setsysinfo_args *uap = v; 214 #endif 215 216 *retval = 0; 217 return 0; 218 } 219 220 int 221 ultrix_sys_waitpid(p, v, retval) 222 struct proc *p; 223 void *v; 224 register_t *retval; 225 { 226 struct ultrix_sys_waitpid_args *uap = v; 227 struct sys_wait4_args ua; 228 229 SCARG(&ua, pid) = SCARG(uap, pid); 230 SCARG(&ua, status) = SCARG(uap, status); 231 SCARG(&ua, options) = SCARG(uap, options); 232 SCARG(&ua, rusage) = 0; 233 234 return (sys_wait4(p, &ua, retval)); 235 } 236 237 int 238 ultrix_sys_wait3(p, v, retval) 239 struct proc *p; 240 void *v; 241 register_t *retval; 242 { 243 struct ultrix_sys_wait3_args *uap = v; 244 struct sys_wait4_args ua; 245 246 SCARG(&ua, pid) = -1; 247 SCARG(&ua, status) = SCARG(uap, status); 248 SCARG(&ua, options) = SCARG(uap, options); 249 SCARG(&ua, rusage) = SCARG(uap, rusage); 250 251 return (sys_wait4(p, &ua, retval)); 252 } 253 254 /* 255 * Ultrix binaries pass in FD_MAX as the first arg to select(). 256 * On Ultrix, FD_MAX is 4096, which is more than the NetBSD sys_select() 257 * can handle. 258 * Since we can't have more than the (native) FD_MAX descriptors open, 259 * limit nfds to at most FD_MAX. 260 */ 261 int 262 ultrix_sys_select(p, v, retval) 263 struct proc *p; 264 void *v; 265 register_t *retval; 266 { 267 struct sys_select_args *uap = v; 268 struct timeval atv; 269 int error; 270 271 /* Limit number of FDs selected on to the native maximum */ 272 273 if (SCARG(uap, nd) > FD_SETSIZE) 274 SCARG(uap, nd) = FD_SETSIZE; 275 276 /* Check for negative timeval */ 277 if (SCARG(uap, tv)) { 278 error = copyin((caddr_t)SCARG(uap, tv), (caddr_t)&atv, 279 sizeof(atv)); 280 if (error) 281 goto done; 282 #ifdef DEBUG 283 /* Ultrix clients sometimes give negative timeouts? */ 284 if (atv.tv_sec < 0 || atv.tv_usec < 0) 285 printf("ultrix select( %ld, %ld): negative timeout\n", 286 atv.tv_sec, atv.tv_usec); 287 /*tvp = (timeval *)STACKGAPBASE;*/ 288 #endif 289 290 } 291 error = sys_select(p, (void*) uap, retval); 292 if (error == EINVAL) 293 printf("ultrix select: bad args?\n"); 294 295 done: 296 return error; 297 } 298 299 #if defined(NFS) 300 int 301 async_daemon(p, v, retval) 302 struct proc *p; 303 void *v; 304 register_t *retval; 305 { 306 struct sys_nfssvc_args ouap; 307 308 SCARG(&ouap, flag) = NFSSVC_BIOD; 309 SCARG(&ouap, argp) = NULL; 310 311 return (sys_nfssvc(p, &ouap, retval)); 312 } 313 #endif /* NFS */ 314 315 316 #define SUN__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */ 317 318 int 319 ultrix_sys_mmap(p, v, retval) 320 struct proc *p; 321 void *v; 322 register_t *retval; 323 { 324 struct ultrix_sys_mmap_args *uap = v; 325 struct sys_mmap_args ouap; 326 struct filedesc *fdp; 327 struct file *fp; 328 struct vnode *vp; 329 330 /* 331 * Verify the arguments. 332 */ 333 if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC)) 334 return (EINVAL); /* XXX still needed? */ 335 336 if ((SCARG(uap, flags) & SUN__MAP_NEW) == 0) 337 return (EINVAL); 338 339 SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUN__MAP_NEW; 340 SCARG(&ouap, addr) = SCARG(uap, addr); 341 342 if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 && 343 SCARG(&ouap, addr) != 0 && 344 SCARG(&ouap, addr) < (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ)) 345 SCARG(&ouap, addr) = (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ); 346 347 SCARG(&ouap, len) = SCARG(uap, len); 348 SCARG(&ouap, prot) = SCARG(uap, prot); 349 SCARG(&ouap, fd) = SCARG(uap, fd); 350 SCARG(&ouap, pos) = SCARG(uap, pos); 351 352 /* 353 * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX) 354 */ 355 fdp = p->p_fd; 356 if ((unsigned)SCARG(&ouap, fd) < fdp->fd_nfiles && /*XXX*/ 357 (fp = fdp->fd_ofiles[SCARG(&ouap, fd)]) != NULL && /*XXX*/ 358 fp->f_type == DTYPE_VNODE && /*XXX*/ 359 (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/ 360 iszerodev(vp->v_rdev)) { /*XXX*/ 361 SCARG(&ouap, flags) |= MAP_ANON; 362 SCARG(&ouap, fd) = -1; 363 } 364 365 return (sys_mmap(p, &ouap, retval)); 366 } 367 368 int 369 ultrix_sys_setsockopt(p, v, retval) 370 struct proc *p; 371 void *v; 372 register_t *retval; 373 { 374 struct ultrix_sys_setsockopt_args *uap = v; 375 struct file *fp; 376 struct mbuf *m = NULL; 377 int error; 378 379 /* getsock() will use the descriptor for us */ 380 if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) 381 return (error); 382 #define SO_DONTLINGER (~SO_LINGER) 383 if (SCARG(uap, name) == SO_DONTLINGER) { 384 m = m_get(M_WAIT, MT_SOOPTS); 385 mtod(m, struct linger *)->l_onoff = 0; 386 m->m_len = sizeof(struct linger); 387 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level), 388 SO_LINGER, m); 389 } 390 if (SCARG(uap, level) == IPPROTO_IP) { 391 #define EMUL_IP_MULTICAST_IF 2 392 #define EMUL_IP_MULTICAST_TTL 3 393 #define EMUL_IP_MULTICAST_LOOP 4 394 #define EMUL_IP_ADD_MEMBERSHIP 5 395 #define EMUL_IP_DROP_MEMBERSHIP 6 396 static int ipoptxlat[] = { 397 IP_MULTICAST_IF, 398 IP_MULTICAST_TTL, 399 IP_MULTICAST_LOOP, 400 IP_ADD_MEMBERSHIP, 401 IP_DROP_MEMBERSHIP 402 }; 403 if (SCARG(uap, name) >= EMUL_IP_MULTICAST_IF && 404 SCARG(uap, name) <= EMUL_IP_DROP_MEMBERSHIP) { 405 SCARG(uap, name) = 406 ipoptxlat[SCARG(uap, name) - EMUL_IP_MULTICAST_IF]; 407 } 408 } 409 if (SCARG(uap, valsize) > MLEN) { 410 error = EINVAL; 411 goto out; 412 } 413 if (SCARG(uap, val)) { 414 m = m_get(M_WAIT, MT_SOOPTS); 415 error = copyin(SCARG(uap, val), mtod(m, caddr_t), 416 (u_int)SCARG(uap, valsize)); 417 if (error) { 418 (void) m_free(m); 419 goto out; 420 } 421 m->m_len = SCARG(uap, valsize); 422 } 423 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level), 424 SCARG(uap, name), m); 425 out: 426 FILE_UNUSE(fp, p); 427 return (error); 428 } 429 430 #define ULTRIX__SYS_NMLN 32 431 432 struct ultrix_utsname { 433 char sysname[ULTRIX__SYS_NMLN]; 434 char nodename[ULTRIX__SYS_NMLN]; 435 char release[ULTRIX__SYS_NMLN]; 436 char version[ULTRIX__SYS_NMLN]; 437 char machine[ULTRIX__SYS_NMLN]; 438 }; 439 440 int 441 ultrix_sys_uname(p, v, retval) 442 struct proc *p; 443 void *v; 444 register_t *retval; 445 { 446 struct ultrix_sys_uname_args *uap = v; 447 struct ultrix_utsname sut; 448 char *cp, *dp, *ep; 449 450 memset(&sut, 0, sizeof(sut)); 451 452 strncpy(sut.sysname, ostype, sizeof(sut.sysname) - 1); 453 strncpy(sut.nodename, hostname, sizeof(sut.nodename) - 1); 454 strncpy(sut.release, osrelease, sizeof(sut.release) - 1); 455 dp = sut.version; 456 ep = &sut.version[sizeof(sut.version) - 1]; 457 for (cp = version; *cp && *cp != '('; cp++) 458 ; 459 for (cp++; *cp && *cp != ')' && dp < ep; cp++) 460 *dp++ = *cp; 461 for (; *cp && *cp != '#'; cp++) 462 ; 463 for (; *cp && *cp != ':' && dp < ep; cp++) 464 *dp++ = *cp; 465 *dp = '\0'; 466 strncpy(sut.machine, machine, sizeof(sut.machine) - 1); 467 468 return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name), 469 sizeof(struct ultrix_utsname)); 470 } 471 472 int 473 ultrix_sys_setpgrp(p, v, retval) 474 struct proc *p; 475 void *v; 476 register_t *retval; 477 { 478 struct ultrix_sys_setpgrp_args *uap = v; 479 480 /* 481 * difference to our setpgid call is to include backwards 482 * compatibility to pre-setsid() binaries. Do setsid() 483 * instead of setpgid() in those cases where the process 484 * tries to create a new session the old way. 485 */ 486 if (!SCARG(uap, pgid) && 487 (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid)) 488 return sys_setsid(p, uap, retval); 489 else 490 return sys_setpgid(p, uap, retval); 491 } 492 493 #if defined (NFSSERVER) 494 int 495 ultrix_sys_nfssvc(p, v, retval) 496 struct proc *p; 497 void *v; 498 register_t *retval; 499 { 500 501 #if 0 /* XXX */ 502 struct ultrix_sys_nfssvc_args *uap = v; 503 struct emul *e = p->p_emul; 504 struct sys_nfssvc_args outuap; 505 struct sockaddr sa; 506 int error; 507 508 memset(&outuap, 0, sizeof outuap); 509 SCARG(&outuap, fd) = SCARG(uap, fd); 510 SCARG(&outuap, mskval) = STACKGAPBASE; 511 SCARG(&outuap, msklen) = sizeof sa; 512 SCARG(&outuap, mtchval) = outuap.mskval + sizeof sa; 513 SCARG(&outuap, mtchlen) = sizeof sa; 514 515 memset(&sa, 0, sizeof sa); 516 if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen))) 517 return (error); 518 if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen))) 519 return (error); 520 521 return nfssvc(p, &outuap, retval); 522 #else 523 return (ENOSYS); 524 #endif 525 } 526 #endif /* NFSSERVER */ 527 528 struct ultrix_ustat { 529 daddr_t f_tfree; /* total free */ 530 ino_t f_tinode; /* total inodes free */ 531 char f_fname[6]; /* filsys name */ 532 char f_fpack[6]; /* filsys pack name */ 533 }; 534 535 int 536 ultrix_sys_ustat(p, v, retval) 537 struct proc *p; 538 void *v; 539 register_t *retval; 540 { 541 struct ultrix_sys_ustat_args *uap = v; 542 struct ultrix_ustat us; 543 int error; 544 545 memset(&us, 0, sizeof us); 546 547 /* 548 * XXX: should set f_tfree and f_tinode at least 549 * How do we translate dev -> fstat? (and then to ultrix_ustat) 550 */ 551 552 if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0) 553 return (error); 554 return 0; 555 } 556 557 int 558 ultrix_sys_quotactl(p, v, retval) 559 struct proc *p; 560 void *v; 561 register_t *retval; 562 { 563 564 #ifdef notyet 565 struct ultrix_sys_quotactl_args *uap = v; 566 #endif 567 568 return EINVAL; 569 } 570 571 int 572 ultrix_sys_vhangup(p, v, retval) 573 struct proc *p; 574 void *v; 575 register_t *retval; 576 { 577 578 return 0; 579 } 580 581 582 /* 583 * RISC Ultrix cache control syscalls 584 */ 585 #ifdef __mips 586 int 587 ultrix_sys_cacheflush(p, v, retval) 588 struct proc *p; 589 void *v; 590 register_t *retval; 591 { 592 struct ultrix_sys_cacheflush_args /* { 593 syscallarg(void *) addr; 594 syscallarg(int) nbytes; 595 syscallarg(int) flag; 596 } */ *uap = v; 597 vaddr_t va = (vaddr_t)SCARG(uap, addr); 598 int nbytes = SCARG(uap, nbytes); 599 int whichcache = SCARG(uap, whichcache); 600 601 return (mips_user_cacheflush(p, va, nbytes, whichcache)); 602 } 603 604 605 int 606 ultrix_sys_cachectl(p, v, retval) 607 struct proc *p; 608 void *v; 609 register_t *retval; 610 { 611 struct ultrix_sys_cachectl_args /* { 612 syscallarg(void *) addr; 613 syscallarg(int) nbytes; 614 syscallarg(int) cacheop; 615 } */ *uap = v; 616 vaddr_t va = (vaddr_t)SCARG(uap, addr); 617 int nbytes = SCARG(uap, nbytes); 618 int cacheop = SCARG(uap, cacheop); 619 620 return mips_user_cachectl(p, va, nbytes, cacheop); 621 } 622 623 #endif /* __mips */ 624 625 626 int 627 ultrix_sys_exportfs(p, v, retval) 628 struct proc *p; 629 void *v; 630 register_t *retval; 631 { 632 #ifdef notyet 633 struct ultrix_sys_exportfs_args *uap = v; 634 #endif 635 636 /* 637 * XXX: should perhaps translate into a mount(2) 638 * with MOUNT_EXPORT? 639 */ 640 return 0; 641 } 642 643 int 644 ultrix_sys_sigpending(p, v, retval) 645 struct proc *p; 646 void *v; 647 register_t *retval; 648 { 649 struct ultrix_sys_sigpending_args *uap = v; 650 sigset_t ss; 651 int mask; 652 653 sigpending1(p, &ss); 654 mask = ss.__bits[0]; 655 656 return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int))); 657 } 658 659 int 660 ultrix_sys_sigreturn(p, v, retval) 661 struct proc *p; 662 void *v; 663 register_t *retval; 664 { 665 struct ultrix_sys_sigreturn_args *uap = v; 666 667 /* struct sigcontext13 is close enough to Ultrix */ 668 669 return (compat_13_sys_sigreturn(p, uap, retval)); 670 } 671 672 int 673 ultrix_sys_sigcleanup(p, v, retval) 674 struct proc *p; 675 void *v; 676 register_t *retval; 677 { 678 struct ultrix_sys_sigcleanup_args *uap = v; 679 680 /* struct sigcontext13 is close enough to Ultrix */ 681 682 return (compat_13_sys_sigreturn(p, uap, retval)); 683 } 684 685 int 686 ultrix_sys_sigsuspend(p, v, retval) 687 struct proc *p; 688 void *v; 689 register_t *retval; 690 { 691 struct ultrix_sys_sigsuspend_args *uap = v; 692 int mask = SCARG(uap, mask); 693 sigset_t ss; 694 695 ss.__bits[0] = mask; 696 ss.__bits[1] = 0; 697 ss.__bits[2] = 0; 698 ss.__bits[3] = 0; 699 700 return (sigsuspend1(p, &ss)); 701 } 702 703 #define ULTRIX_SV_ONSTACK 0x0001 /* take signal on signal stack */ 704 #define ULTRIX_SV_INTERRUPT 0x0002 /* do not restart system on signal return */ 705 #define ULTRIX_SV_OLDSIG 0x1000 /* Emulate old signal() for POSIX */ 706 707 int 708 ultrix_sys_sigvec(p, v, retval) 709 struct proc *p; 710 void *v; 711 register_t *retval; 712 { 713 struct ultrix_sys_sigvec_args *uap = v; 714 struct sigvec nsv, osv; 715 struct sigaction nsa, osa; 716 int error; 717 718 if (SCARG(uap, nsv)) { 719 error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv)); 720 if (error) 721 return (error); 722 nsa.sa_handler = nsv.sv_handler; 723 #if 0 /* documentation */ 724 /* ONSTACK is identical */ 725 nsa.sa_flags = nsv.sv_flags & ULTRIX_SV_ONSTACK; 726 if ((nsv.sv_flags & ULTRIX_SV_OLDSIG) 727 /* old signal() - always restart */ 728 || (!(nsv.sv_flags & ULTRIX_SV_INTERRUPT)) 729 /* inverted meaning (same bit) */ 730 ) 731 nsa.sa_flags |= SA_RESTART; 732 #else /* optimized - assuming ULTRIX_SV_OLDSIG=>!ULTRIX_SV_INTERRUPT */ 733 nsa.sa_flags = nsv.sv_flags & ~ULTRIX_SV_OLDSIG; 734 nsa.sa_flags ^= SA_RESTART; 735 #endif 736 native_sigset13_to_sigset(&nsv.sv_mask, &nsa.sa_mask); 737 } 738 error = sigaction1(p, SCARG(uap, signum), 739 SCARG(uap, nsv) ? &nsa : 0, SCARG(uap, osv) ? &osa : 0); 740 if (error) 741 return (error); 742 if (SCARG(uap, osv)) { 743 osv.sv_handler = osa.sa_handler; 744 osv.sv_flags = osa.sa_flags ^ SA_RESTART; 745 osv.sv_flags &= (ULTRIX_SV_ONSTACK | ULTRIX_SV_INTERRUPT); 746 native_sigset_to_sigset13(&osa.sa_mask, &osv.sv_mask); 747 error = copyout(&osv, SCARG(uap, osv), sizeof(osv)); 748 if (error) 749 return (error); 750 } 751 return (0); 752 } 753 754 int 755 ultrix_sys_shmsys(p, v, retval) 756 struct proc *p; 757 void *v; 758 register_t *retval; 759 { 760 761 #ifdef SYSVSHM 762 763 /* Ultrix SVSHM weirndess: */ 764 struct ultrix_sys_shmsys_args *uap = v; 765 struct sys_shmat_args shmat_args; 766 struct compat_14_sys_shmctl_args shmctl_args; 767 struct sys_shmdt_args shmdt_args; 768 struct sys_shmget_args shmget_args; 769 770 771 switch (SCARG(uap, shmop)) { 772 case 0: /* Ultrix shmat() */ 773 SCARG(&shmat_args, shmid) = SCARG(uap, a2); 774 SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3); 775 SCARG(&shmat_args, shmflg) = SCARG(uap, a4); 776 return (sys_shmat(p, &shmat_args, retval)); 777 778 case 1: /* Ultrix shmctl() */ 779 SCARG(&shmctl_args, shmid) = SCARG(uap, a2); 780 SCARG(&shmctl_args, cmd) = SCARG(uap, a3); 781 SCARG(&shmctl_args, buf) = (struct shmid_ds14 *)SCARG(uap, a4); 782 return (compat_14_sys_shmctl(p, &shmctl_args, retval)); 783 784 case 2: /* Ultrix shmdt() */ 785 SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a2); 786 return (sys_shmdt(p, &shmdt_args, retval)); 787 788 case 3: /* Ultrix shmget() */ 789 SCARG(&shmget_args, key) = SCARG(uap, a2); 790 SCARG(&shmget_args, size) = SCARG(uap, a3); 791 SCARG(&shmget_args, shmflg) = SCARG(uap, a4) 792 & (IPC_CREAT|IPC_EXCL|IPC_NOWAIT); 793 return (sys_shmget(p, &shmget_args, retval)); 794 795 default: 796 return (EINVAL); 797 } 798 #else 799 return (EOPNOTSUPP); 800 #endif /* SYSVSHM */ 801 } 802 803 static int 804 ultrix_to_bsd_flock(ufl, fl) 805 struct ultrix_flock *ufl; 806 struct flock *fl; 807 { 808 809 fl->l_start = ufl->l_start; 810 fl->l_len = ufl->l_len; 811 fl->l_pid = ufl->l_pid; 812 fl->l_whence = ufl->l_whence; 813 814 switch (ufl->l_type) { 815 case ULTRIX_F_RDLCK: 816 fl->l_type = F_RDLCK; 817 break; 818 case ULTRIX_F_WRLCK: 819 fl->l_type = F_WRLCK; 820 break; 821 case ULTRIX_F_UNLCK: 822 fl->l_type = F_UNLCK; 823 break; 824 default: 825 return (EINVAL); 826 } 827 828 return (0); 829 } 830 831 static void 832 bsd_to_ultrix_flock(fl, ufl) 833 struct flock *fl; 834 struct ultrix_flock *ufl; 835 { 836 837 ufl->l_start = fl->l_start; 838 ufl->l_len = fl->l_len; 839 ufl->l_pid = fl->l_pid; 840 ufl->l_whence = fl->l_whence; 841 842 switch (fl->l_type) { 843 case F_RDLCK: 844 ufl->l_type = ULTRIX_F_RDLCK; 845 break; 846 case F_WRLCK: 847 ufl->l_type = ULTRIX_F_WRLCK; 848 break; 849 case F_UNLCK: 850 ufl->l_type = ULTRIX_F_UNLCK; 851 break; 852 } 853 } 854 855 int 856 ultrix_sys_fcntl(p, v, retval) 857 struct proc *p; 858 void *v; 859 register_t *retval; 860 { 861 struct ultrix_sys_fcntl_args *uap = v; 862 int error; 863 struct ultrix_flock ufl; 864 struct flock fl, *flp; 865 caddr_t sg; 866 struct sys_fcntl_args *args, fca; 867 868 switch (SCARG(uap, cmd)) { 869 case F_GETLK: 870 case F_SETLK: 871 case F_SETLKW: 872 error = copyin(SCARG(uap, arg), &ufl, sizeof(ufl)); 873 if (error) 874 return (error); 875 error = ultrix_to_bsd_flock(&ufl, &fl); 876 if (error) 877 return (error); 878 sg = stackgap_init(p->p_emul); 879 flp = (struct flock *)stackgap_alloc(&sg, sizeof(*flp)); 880 error = copyout(&fl, flp, sizeof(*flp)); 881 if (error) 882 return (error); 883 884 SCARG(&fca, fd) = SCARG(uap, fd); 885 SCARG(&fca, cmd) = SCARG(uap, cmd); 886 SCARG(&fca, arg) = flp; 887 args = &fca; 888 break; 889 default: 890 args = v; 891 break; 892 } 893 894 error = sys_fcntl(p, args, retval); 895 if (error) 896 return (error); 897 898 switch (SCARG(uap, cmd)) { 899 case F_GETLK: 900 error = copyin(flp, &fl, sizeof(fl)); 901 if (error) 902 return (error); 903 bsd_to_ultrix_flock(&fl, &ufl); 904 error = copyout(&ufl, SCARG(uap, arg), sizeof(ufl)); 905 break; 906 } 907 908 return (error); 909 } 910