svr4_misc.c revision 193013
1/*- 2 * Copyright (c) 1998 Mark Newton 3 * Copyright (c) 1994 Christos Zoulas 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28/* 29 * SVR4 compatibility module. 30 * 31 * SVR4 system calls that are implemented differently in BSD are 32 * handled here. 33 */ 34 35#include <sys/cdefs.h> 36__FBSDID("$FreeBSD: head/sys/compat/svr4/svr4_misc.c 193013 2009-05-29 05:51:19Z delphij $"); 37 38#include "opt_mac.h" 39 40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/dirent.h> 43#include <sys/fcntl.h> 44#include <sys/filedesc.h> 45#include <sys/imgact.h> 46#include <sys/kernel.h> 47#include <sys/lock.h> 48#include <sys/malloc.h> 49#include <sys/file.h> /* Must come after sys/malloc.h */ 50#include <sys/mman.h> 51#include <sys/mount.h> 52#include <sys/msg.h> 53#include <sys/mutex.h> 54#include <sys/namei.h> 55#include <sys/priv.h> 56#include <sys/proc.h> 57#include <sys/ptrace.h> 58#include <sys/resource.h> 59#include <sys/resourcevar.h> 60#include <sys/sem.h> 61#include <sys/signalvar.h> 62#include <sys/stat.h> 63#include <sys/sx.h> 64#include <sys/syscallsubr.h> 65#include <sys/sysproto.h> 66#include <sys/time.h> 67#include <sys/times.h> 68#include <sys/uio.h> 69#include <sys/vnode.h> 70#include <sys/wait.h> 71 72#include <compat/svr4/svr4.h> 73#include <compat/svr4/svr4_types.h> 74#include <compat/svr4/svr4_signal.h> 75#include <compat/svr4/svr4_proto.h> 76#include <compat/svr4/svr4_util.h> 77#include <compat/svr4/svr4_sysconfig.h> 78#include <compat/svr4/svr4_dirent.h> 79#include <compat/svr4/svr4_acl.h> 80#include <compat/svr4/svr4_ulimit.h> 81#include <compat/svr4/svr4_statvfs.h> 82#include <compat/svr4/svr4_hrt.h> 83#include <compat/svr4/svr4_mman.h> 84#include <compat/svr4/svr4_wait.h> 85 86#include <security/mac/mac_framework.h> 87 88#include <machine/vmparam.h> 89#include <vm/vm.h> 90#include <vm/vm_param.h> 91#include <vm/vm_map.h> 92#if defined(__FreeBSD__) 93#include <vm/uma.h> 94#include <vm/vm_extern.h> 95#endif 96 97#if defined(NetBSD) 98# if defined(UVM) 99# include <uvm/uvm_extern.h> 100# endif 101#endif 102 103#define BSD_DIRENT(cp) ((struct dirent *)(cp)) 104 105static int svr4_mknod(struct thread *, register_t *, char *, 106 svr4_mode_t, svr4_dev_t); 107 108static __inline clock_t timeval_to_clock_t(struct timeval *); 109static int svr4_setinfo (pid_t , struct rusage *, int, svr4_siginfo_t *); 110 111struct svr4_hrtcntl_args; 112static int svr4_hrtcntl (struct thread *, struct svr4_hrtcntl_args *, 113 register_t *); 114static void bsd_statfs_to_svr4_statvfs(const struct statfs *, 115 struct svr4_statvfs *); 116static void bsd_statfs_to_svr4_statvfs64(const struct statfs *, 117 struct svr4_statvfs64 *); 118static struct proc *svr4_pfind(pid_t pid); 119 120/* BOGUS noop */ 121#if defined(BOGUS) 122int 123svr4_sys_setitimer(td, uap) 124 register struct thread *td; 125 struct svr4_sys_setitimer_args *uap; 126{ 127 td->td_retval[0] = 0; 128 return 0; 129} 130#endif 131 132int 133svr4_sys_wait(td, uap) 134 struct thread *td; 135 struct svr4_sys_wait_args *uap; 136{ 137 int error, st, sig; 138 139 error = kern_wait(td, WAIT_ANY, &st, 0, NULL); 140 if (error) 141 return (error); 142 143 if (WIFSIGNALED(st)) { 144 sig = WTERMSIG(st); 145 if (sig >= 0 && sig < NSIG) 146 st = (st & ~0177) | SVR4_BSD2SVR4_SIG(sig); 147 } else if (WIFSTOPPED(st)) { 148 sig = WSTOPSIG(st); 149 if (sig >= 0 && sig < NSIG) 150 st = (st & ~0xff00) | (SVR4_BSD2SVR4_SIG(sig) << 8); 151 } 152 153 /* 154 * It looks like wait(2) on svr4/solaris/2.4 returns 155 * the status in retval[1], and the pid on retval[0]. 156 */ 157 td->td_retval[1] = st; 158 159 if (uap->status) 160 error = copyout(&st, uap->status, sizeof(st)); 161 162 return (error); 163} 164 165int 166svr4_sys_execv(td, uap) 167 struct thread *td; 168 struct svr4_sys_execv_args *uap; 169{ 170 struct image_args eargs; 171 char *path; 172 int error; 173 174 CHECKALTEXIST(td, uap->path, &path); 175 176 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp, NULL); 177 free(path, M_TEMP); 178 if (error == 0) 179 error = kern_execve(td, &eargs, NULL); 180 return (error); 181} 182 183int 184svr4_sys_execve(td, uap) 185 struct thread *td; 186 struct svr4_sys_execve_args *uap; 187{ 188 struct image_args eargs; 189 char *path; 190 int error; 191 192 CHECKALTEXIST(td, uap->path, &path); 193 194 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp, 195 uap->envp); 196 free(path, M_TEMP); 197 if (error == 0) 198 error = kern_execve(td, &eargs, NULL); 199 return (error); 200} 201 202int 203svr4_sys_time(td, v) 204 struct thread *td; 205 struct svr4_sys_time_args *v; 206{ 207 struct svr4_sys_time_args *uap = v; 208 int error = 0; 209 struct timeval tv; 210 211 microtime(&tv); 212 if (uap->t) 213 error = copyout(&tv.tv_sec, uap->t, 214 sizeof(*(uap->t))); 215 td->td_retval[0] = (int) tv.tv_sec; 216 217 return error; 218} 219 220 221/* 222 * Read SVR4-style directory entries. We suck them into kernel space so 223 * that they can be massaged before being copied out to user code. 224 * 225 * This code is ported from the Linux emulator: Changes to the VFS interface 226 * between FreeBSD and NetBSD have made it simpler to port it from there than 227 * to adapt the NetBSD version. 228 */ 229int 230svr4_sys_getdents64(td, uap) 231 struct thread *td; 232 struct svr4_sys_getdents64_args *uap; 233{ 234 register struct dirent *bdp; 235 struct vnode *vp; 236 caddr_t inp, buf; /* BSD-format */ 237 int len, reclen; /* BSD-format */ 238 caddr_t outp; /* SVR4-format */ 239 int resid, svr4reclen=0; /* SVR4-format */ 240 struct file *fp; 241 struct uio auio; 242 struct iovec aiov; 243 off_t off; 244 struct svr4_dirent64 svr4_dirent; 245 int buflen, error, eofflag, nbytes, justone, vfslocked; 246 u_long *cookies = NULL, *cookiep; 247 int ncookies; 248 249 DPRINTF(("svr4_sys_getdents64(%d, *, %d)\n", 250 uap->fd, uap->nbytes)); 251 if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) { 252 return (error); 253 } 254 255 if ((fp->f_flag & FREAD) == 0) { 256 fdrop(fp, td); 257 return (EBADF); 258 } 259 260 vp = fp->f_vnode; 261 vfslocked = VFS_LOCK_GIANT(vp->v_mount); 262 if (vp->v_type != VDIR) { 263 VFS_UNLOCK_GIANT(vfslocked); 264 fdrop(fp, td); 265 return (EINVAL); 266 } 267 268 nbytes = uap->nbytes; 269 if (nbytes == 1) { 270 nbytes = sizeof (struct svr4_dirent64); 271 justone = 1; 272 } 273 else 274 justone = 0; 275 276 off = fp->f_offset; 277#define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */ 278 buflen = max(DIRBLKSIZ, nbytes); 279 buflen = min(buflen, MAXBSIZE); 280 buf = malloc(buflen, M_TEMP, M_WAITOK); 281 vn_lock(vp, LK_SHARED | LK_RETRY); 282again: 283 aiov.iov_base = buf; 284 aiov.iov_len = buflen; 285 auio.uio_iov = &aiov; 286 auio.uio_iovcnt = 1; 287 auio.uio_rw = UIO_READ; 288 auio.uio_segflg = UIO_SYSSPACE; 289 auio.uio_td = td; 290 auio.uio_resid = buflen; 291 auio.uio_offset = off; 292 293 if (cookies) { 294 free(cookies, M_TEMP); 295 cookies = NULL; 296 } 297 298#ifdef MAC 299 error = mac_vnode_check_readdir(td->td_ucred, vp); 300 if (error) 301 goto out; 302#endif 303 304 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, 305 &ncookies, &cookies); 306 if (error) { 307 goto out; 308 } 309 310 inp = buf; 311 outp = (caddr_t) uap->dp; 312 resid = nbytes; 313 if ((len = buflen - auio.uio_resid) <= 0) { 314 goto eof; 315 } 316 317 cookiep = cookies; 318 319 if (cookies) { 320 /* 321 * When using cookies, the vfs has the option of reading from 322 * a different offset than that supplied (UFS truncates the 323 * offset to a block boundary to make sure that it never reads 324 * partway through a directory entry, even if the directory 325 * has been compacted). 326 */ 327 while (len > 0 && ncookies > 0 && *cookiep <= off) { 328 bdp = (struct dirent *) inp; 329 len -= bdp->d_reclen; 330 inp += bdp->d_reclen; 331 cookiep++; 332 ncookies--; 333 } 334 } 335 336 while (len > 0) { 337 if (cookiep && ncookies == 0) 338 break; 339 bdp = (struct dirent *) inp; 340 reclen = bdp->d_reclen; 341 if (reclen & 3) { 342 DPRINTF(("svr4_readdir: reclen=%d\n", reclen)); 343 error = EFAULT; 344 goto out; 345 } 346 347 if (bdp->d_fileno == 0) { 348 inp += reclen; 349 if (cookiep) { 350 off = *cookiep++; 351 ncookies--; 352 } else 353 off += reclen; 354 len -= reclen; 355 continue; 356 } 357 svr4reclen = SVR4_RECLEN(&svr4_dirent, bdp->d_namlen); 358 if (reclen > len || resid < svr4reclen) { 359 outp++; 360 break; 361 } 362 svr4_dirent.d_ino = (long) bdp->d_fileno; 363 if (justone) { 364 /* 365 * old svr4-style readdir usage. 366 */ 367 svr4_dirent.d_off = (svr4_off_t) svr4reclen; 368 svr4_dirent.d_reclen = (u_short) bdp->d_namlen; 369 } else { 370 svr4_dirent.d_off = (svr4_off_t)(off + reclen); 371 svr4_dirent.d_reclen = (u_short) svr4reclen; 372 } 373 strlcpy(svr4_dirent.d_name, bdp->d_name, sizeof(svr4_dirent.d_name)); 374 if ((error = copyout((caddr_t)&svr4_dirent, outp, svr4reclen))) 375 goto out; 376 inp += reclen; 377 if (cookiep) { 378 off = *cookiep++; 379 ncookies--; 380 } else 381 off += reclen; 382 outp += svr4reclen; 383 resid -= svr4reclen; 384 len -= reclen; 385 if (justone) 386 break; 387 } 388 389 if (outp == (caddr_t) uap->dp) 390 goto again; 391 fp->f_offset = off; 392 393 if (justone) 394 nbytes = resid + svr4reclen; 395 396eof: 397 td->td_retval[0] = nbytes - resid; 398out: 399 VOP_UNLOCK(vp, 0); 400 VFS_UNLOCK_GIANT(vfslocked); 401 fdrop(fp, td); 402 if (cookies) 403 free(cookies, M_TEMP); 404 free(buf, M_TEMP); 405 return error; 406} 407 408 409int 410svr4_sys_getdents(td, uap) 411 struct thread *td; 412 struct svr4_sys_getdents_args *uap; 413{ 414 struct dirent *bdp; 415 struct vnode *vp; 416 caddr_t inp, buf; /* BSD-format */ 417 int len, reclen; /* BSD-format */ 418 caddr_t outp; /* SVR4-format */ 419 int resid, svr4_reclen; /* SVR4-format */ 420 struct file *fp; 421 struct uio auio; 422 struct iovec aiov; 423 struct svr4_dirent idb; 424 off_t off; /* true file offset */ 425 int buflen, error, eofflag, vfslocked; 426 u_long *cookiebuf = NULL, *cookie; 427 int ncookies = 0, *retval = td->td_retval; 428 429 if (uap->nbytes < 0) 430 return (EINVAL); 431 432 if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) 433 return (error); 434 435 if ((fp->f_flag & FREAD) == 0) { 436 fdrop(fp, td); 437 return (EBADF); 438 } 439 440 vp = fp->f_vnode; 441 vfslocked = VFS_LOCK_GIANT(vp->v_mount); 442 if (vp->v_type != VDIR) { 443 VFS_UNLOCK_GIANT(vfslocked); 444 fdrop(fp, td); 445 return (EINVAL); 446 } 447 448 buflen = min(MAXBSIZE, uap->nbytes); 449 buf = malloc(buflen, M_TEMP, M_WAITOK); 450 vn_lock(vp, LK_SHARED | LK_RETRY); 451 off = fp->f_offset; 452again: 453 aiov.iov_base = buf; 454 aiov.iov_len = buflen; 455 auio.uio_iov = &aiov; 456 auio.uio_iovcnt = 1; 457 auio.uio_rw = UIO_READ; 458 auio.uio_segflg = UIO_SYSSPACE; 459 auio.uio_td = td; 460 auio.uio_resid = buflen; 461 auio.uio_offset = off; 462 463#ifdef MAC 464 error = mac_vnode_check_readdir(td->td_ucred, vp); 465 if (error) 466 goto out; 467#endif 468 469 /* 470 * First we read into the malloc'ed buffer, then 471 * we massage it into user space, one record at a time. 472 */ 473 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, 474 &cookiebuf); 475 if (error) { 476 goto out; 477 } 478 479 inp = buf; 480 outp = uap->buf; 481 resid = uap->nbytes; 482 if ((len = buflen - auio.uio_resid) == 0) 483 goto eof; 484 485 for (cookie = cookiebuf; len > 0; len -= reclen) { 486 bdp = (struct dirent *)inp; 487 reclen = bdp->d_reclen; 488 if (reclen & 3) 489 panic("svr4_sys_getdents64: bad reclen"); 490 if (cookie) 491 off = *cookie++; /* each entry points to the next */ 492 else 493 off += reclen; 494 if ((off >> 32) != 0) { 495 uprintf("svr4_sys_getdents64: dir offset too large for emulated program"); 496 error = EINVAL; 497 goto out; 498 } 499 if (bdp->d_fileno == 0) { 500 inp += reclen; /* it is a hole; squish it out */ 501 continue; 502 } 503 svr4_reclen = SVR4_RECLEN(&idb, bdp->d_namlen); 504 if (reclen > len || resid < svr4_reclen) { 505 /* entry too big for buffer, so just stop */ 506 outp++; 507 break; 508 } 509 /* 510 * Massage in place to make a SVR4-shaped dirent (otherwise 511 * we have to worry about touching user memory outside of 512 * the copyout() call). 513 */ 514 idb.d_ino = (svr4_ino_t)bdp->d_fileno; 515 idb.d_off = (svr4_off_t)off; 516 idb.d_reclen = (u_short)svr4_reclen; 517 strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name)); 518 if ((error = copyout((caddr_t)&idb, outp, svr4_reclen))) 519 goto out; 520 /* advance past this real entry */ 521 inp += reclen; 522 /* advance output past SVR4-shaped entry */ 523 outp += svr4_reclen; 524 resid -= svr4_reclen; 525 } 526 527 /* if we squished out the whole block, try again */ 528 if (outp == uap->buf) 529 goto again; 530 fp->f_offset = off; /* update the vnode offset */ 531 532eof: 533 *retval = uap->nbytes - resid; 534out: 535 VOP_UNLOCK(vp, 0); 536 VFS_UNLOCK_GIANT(vfslocked); 537 fdrop(fp, td); 538 if (cookiebuf) 539 free(cookiebuf, M_TEMP); 540 free(buf, M_TEMP); 541 return error; 542} 543 544 545int 546svr4_sys_mmap(td, uap) 547 struct thread *td; 548 struct svr4_sys_mmap_args *uap; 549{ 550 struct mmap_args mm; 551 int *retval; 552 553 retval = td->td_retval; 554#define _MAP_NEW 0x80000000 555 /* 556 * Verify the arguments. 557 */ 558 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) 559 return EINVAL; /* XXX still needed? */ 560 561 if (uap->len == 0) 562 return EINVAL; 563 564 mm.prot = uap->prot; 565 mm.len = uap->len; 566 mm.flags = uap->flags & ~_MAP_NEW; 567 mm.fd = uap->fd; 568 mm.addr = uap->addr; 569 mm.pos = uap->pos; 570 571 return mmap(td, &mm); 572} 573 574int 575svr4_sys_mmap64(td, uap) 576 struct thread *td; 577 struct svr4_sys_mmap64_args *uap; 578{ 579 struct mmap_args mm; 580 void *rp; 581 582#define _MAP_NEW 0x80000000 583 /* 584 * Verify the arguments. 585 */ 586 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) 587 return EINVAL; /* XXX still needed? */ 588 589 if (uap->len == 0) 590 return EINVAL; 591 592 mm.prot = uap->prot; 593 mm.len = uap->len; 594 mm.flags = uap->flags & ~_MAP_NEW; 595 mm.fd = uap->fd; 596 mm.addr = uap->addr; 597 mm.pos = uap->pos; 598 599 rp = (void *) round_page((vm_offset_t)(td->td_proc->p_vmspace->vm_daddr + maxdsiz)); 600 if ((mm.flags & MAP_FIXED) == 0 && 601 mm.addr != 0 && (void *)mm.addr < rp) 602 mm.addr = rp; 603 604 return mmap(td, &mm); 605} 606 607 608int 609svr4_sys_fchroot(td, uap) 610 struct thread *td; 611 struct svr4_sys_fchroot_args *uap; 612{ 613 struct filedesc *fdp = td->td_proc->p_fd; 614 struct vnode *vp; 615 struct file *fp; 616 int error, vfslocked; 617 618 if ((error = priv_check(td, PRIV_VFS_FCHROOT)) != 0) 619 return error; 620 if ((error = getvnode(fdp, uap->fd, &fp)) != 0) 621 return error; 622 vp = fp->f_vnode; 623 VREF(vp); 624 fdrop(fp, td); 625 vfslocked = VFS_LOCK_GIANT(vp->v_mount); 626 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); 627 error = change_dir(vp, td); 628 if (error) 629 goto fail; 630#ifdef MAC 631 error = mac_vnode_check_chroot(td->td_ucred, vp); 632 if (error) 633 goto fail; 634#endif 635 VOP_UNLOCK(vp, 0); 636 error = change_root(vp, td); 637 vrele(vp); 638 VFS_UNLOCK_GIANT(vfslocked); 639 return (error); 640fail: 641 vput(vp); 642 VFS_UNLOCK_GIANT(vfslocked); 643 return (error); 644} 645 646 647static int 648svr4_mknod(td, retval, path, mode, dev) 649 struct thread *td; 650 register_t *retval; 651 char *path; 652 svr4_mode_t mode; 653 svr4_dev_t dev; 654{ 655 char *newpath; 656 int error; 657 658 CHECKALTEXIST(td, path, &newpath); 659 660 if (S_ISFIFO(mode)) 661 error = kern_mkfifo(td, newpath, UIO_SYSSPACE, mode); 662 else 663 error = kern_mknod(td, newpath, UIO_SYSSPACE, mode, dev); 664 free(newpath, M_TEMP); 665 return (error); 666} 667 668 669int 670svr4_sys_mknod(td, uap) 671 register struct thread *td; 672 struct svr4_sys_mknod_args *uap; 673{ 674 int *retval = td->td_retval; 675 return svr4_mknod(td, retval, 676 uap->path, uap->mode, 677 (svr4_dev_t)svr4_to_bsd_odev_t(uap->dev)); 678} 679 680 681int 682svr4_sys_xmknod(td, uap) 683 struct thread *td; 684 struct svr4_sys_xmknod_args *uap; 685{ 686 int *retval = td->td_retval; 687 return svr4_mknod(td, retval, 688 uap->path, uap->mode, 689 (svr4_dev_t)svr4_to_bsd_dev_t(uap->dev)); 690} 691 692 693int 694svr4_sys_vhangup(td, uap) 695 struct thread *td; 696 struct svr4_sys_vhangup_args *uap; 697{ 698 return 0; 699} 700 701 702int 703svr4_sys_sysconfig(td, uap) 704 struct thread *td; 705 struct svr4_sys_sysconfig_args *uap; 706{ 707 int *retval; 708 709 retval = &(td->td_retval[0]); 710 711 switch (uap->name) { 712 case SVR4_CONFIG_NGROUPS: 713 *retval = NGROUPS_MAX; 714 break; 715 case SVR4_CONFIG_CHILD_MAX: 716 *retval = maxproc; 717 break; 718 case SVR4_CONFIG_OPEN_FILES: 719 *retval = maxfiles; 720 break; 721 case SVR4_CONFIG_POSIX_VER: 722 *retval = 198808; 723 break; 724 case SVR4_CONFIG_PAGESIZE: 725 *retval = PAGE_SIZE; 726 break; 727 case SVR4_CONFIG_CLK_TCK: 728 *retval = 60; /* should this be `hz', ie. 100? */ 729 break; 730 case SVR4_CONFIG_XOPEN_VER: 731 *retval = 2; /* XXX: What should that be? */ 732 break; 733 case SVR4_CONFIG_PROF_TCK: 734 *retval = 60; /* XXX: What should that be? */ 735 break; 736 case SVR4_CONFIG_NPROC_CONF: 737 *retval = 1; /* Only one processor for now */ 738 break; 739 case SVR4_CONFIG_NPROC_ONLN: 740 *retval = 1; /* And it better be online */ 741 break; 742 case SVR4_CONFIG_AIO_LISTIO_MAX: 743 case SVR4_CONFIG_AIO_MAX: 744 case SVR4_CONFIG_AIO_PRIO_DELTA_MAX: 745 *retval = 0; /* No aio support */ 746 break; 747 case SVR4_CONFIG_DELAYTIMER_MAX: 748 *retval = 0; /* No delaytimer support */ 749 break; 750 case SVR4_CONFIG_MQ_OPEN_MAX: 751 *retval = msginfo.msgmni; 752 break; 753 case SVR4_CONFIG_MQ_PRIO_MAX: 754 *retval = 0; /* XXX: Don't know */ 755 break; 756 case SVR4_CONFIG_RTSIG_MAX: 757 *retval = 0; 758 break; 759 case SVR4_CONFIG_SEM_NSEMS_MAX: 760 *retval = seminfo.semmni; 761 break; 762 case SVR4_CONFIG_SEM_VALUE_MAX: 763 *retval = seminfo.semvmx; 764 break; 765 case SVR4_CONFIG_SIGQUEUE_MAX: 766 *retval = 0; /* XXX: Don't know */ 767 break; 768 case SVR4_CONFIG_SIGRT_MIN: 769 case SVR4_CONFIG_SIGRT_MAX: 770 *retval = 0; /* No real time signals */ 771 break; 772 case SVR4_CONFIG_TIMER_MAX: 773 *retval = 3; /* XXX: real, virtual, profiling */ 774 break; 775#if defined(NOTYET) 776 case SVR4_CONFIG_PHYS_PAGES: 777#if defined(UVM) 778 *retval = uvmexp.free; /* XXX: free instead of total */ 779#else 780 *retval = cnt.v_free_count; /* XXX: free instead of total */ 781#endif 782 break; 783 case SVR4_CONFIG_AVPHYS_PAGES: 784#if defined(UVM) 785 *retval = uvmexp.active; /* XXX: active instead of avg */ 786#else 787 *retval = cnt.v_active_count; /* XXX: active instead of avg */ 788#endif 789 break; 790#endif /* NOTYET */ 791 case SVR4_CONFIG_COHERENCY: 792 *retval = 0; /* XXX */ 793 break; 794 case SVR4_CONFIG_SPLIT_CACHE: 795 *retval = 0; /* XXX */ 796 break; 797 case SVR4_CONFIG_ICACHESZ: 798 *retval = 256; /* XXX */ 799 break; 800 case SVR4_CONFIG_DCACHESZ: 801 *retval = 256; /* XXX */ 802 break; 803 case SVR4_CONFIG_ICACHELINESZ: 804 *retval = 64; /* XXX */ 805 break; 806 case SVR4_CONFIG_DCACHELINESZ: 807 *retval = 64; /* XXX */ 808 break; 809 case SVR4_CONFIG_ICACHEBLKSZ: 810 *retval = 64; /* XXX */ 811 break; 812 case SVR4_CONFIG_DCACHEBLKSZ: 813 *retval = 64; /* XXX */ 814 break; 815 case SVR4_CONFIG_DCACHETBLKSZ: 816 *retval = 64; /* XXX */ 817 break; 818 case SVR4_CONFIG_ICACHE_ASSOC: 819 *retval = 1; /* XXX */ 820 break; 821 case SVR4_CONFIG_DCACHE_ASSOC: 822 *retval = 1; /* XXX */ 823 break; 824 case SVR4_CONFIG_MAXPID: 825 *retval = PID_MAX; 826 break; 827 case SVR4_CONFIG_STACK_PROT: 828 *retval = PROT_READ|PROT_WRITE|PROT_EXEC; 829 break; 830 default: 831 return EINVAL; 832 } 833 return 0; 834} 835 836/* ARGSUSED */ 837int 838svr4_sys_break(td, uap) 839 struct thread *td; 840 struct svr4_sys_break_args *uap; 841{ 842 struct obreak_args ap; 843 844 ap.nsize = uap->nsize; 845 return (obreak(td, &ap)); 846} 847 848static __inline clock_t 849timeval_to_clock_t(tv) 850 struct timeval *tv; 851{ 852 return tv->tv_sec * hz + tv->tv_usec / (1000000 / hz); 853} 854 855 856int 857svr4_sys_times(td, uap) 858 struct thread *td; 859 struct svr4_sys_times_args *uap; 860{ 861 struct timeval tv, utime, stime, cutime, cstime; 862 struct tms tms; 863 struct proc *p; 864 int error; 865 866 p = td->td_proc; 867 PROC_LOCK(p); 868 PROC_SLOCK(p); 869 calcru(p, &utime, &stime); 870 PROC_SUNLOCK(p); 871 calccru(p, &cutime, &cstime); 872 PROC_UNLOCK(p); 873 874 tms.tms_utime = timeval_to_clock_t(&utime); 875 tms.tms_stime = timeval_to_clock_t(&stime); 876 877 tms.tms_cutime = timeval_to_clock_t(&cutime); 878 tms.tms_cstime = timeval_to_clock_t(&cstime); 879 880 error = copyout(&tms, uap->tp, sizeof(tms)); 881 if (error) 882 return (error); 883 884 microtime(&tv); 885 td->td_retval[0] = (int)timeval_to_clock_t(&tv); 886 return (0); 887} 888 889 890int 891svr4_sys_ulimit(td, uap) 892 struct thread *td; 893 struct svr4_sys_ulimit_args *uap; 894{ 895 int *retval = td->td_retval; 896 int error; 897 898 switch (uap->cmd) { 899 case SVR4_GFILLIM: 900 PROC_LOCK(td->td_proc); 901 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE) / 512; 902 PROC_UNLOCK(td->td_proc); 903 if (*retval == -1) 904 *retval = 0x7fffffff; 905 return 0; 906 907 case SVR4_SFILLIM: 908 { 909 struct rlimit krl; 910 911 krl.rlim_cur = uap->newlimit * 512; 912 PROC_LOCK(td->td_proc); 913 krl.rlim_max = lim_max(td->td_proc, RLIMIT_FSIZE); 914 PROC_UNLOCK(td->td_proc); 915 916 error = kern_setrlimit(td, RLIMIT_FSIZE, &krl); 917 if (error) 918 return error; 919 920 PROC_LOCK(td->td_proc); 921 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE); 922 PROC_UNLOCK(td->td_proc); 923 if (*retval == -1) 924 *retval = 0x7fffffff; 925 return 0; 926 } 927 928 case SVR4_GMEMLIM: 929 { 930 struct vmspace *vm = td->td_proc->p_vmspace; 931 register_t r; 932 933 PROC_LOCK(td->td_proc); 934 r = lim_cur(td->td_proc, RLIMIT_DATA); 935 PROC_UNLOCK(td->td_proc); 936 937 if (r == -1) 938 r = 0x7fffffff; 939 r += (long) vm->vm_daddr; 940 if (r < 0) 941 r = 0x7fffffff; 942 *retval = r; 943 return 0; 944 } 945 946 case SVR4_GDESLIM: 947 PROC_LOCK(td->td_proc); 948 *retval = lim_cur(td->td_proc, RLIMIT_NOFILE); 949 PROC_UNLOCK(td->td_proc); 950 if (*retval == -1) 951 *retval = 0x7fffffff; 952 return 0; 953 954 default: 955 return EINVAL; 956 } 957} 958 959static struct proc * 960svr4_pfind(pid) 961 pid_t pid; 962{ 963 struct proc *p; 964 965 /* look in the live processes */ 966 if ((p = pfind(pid)) == NULL) 967 /* look in the zombies */ 968 p = zpfind(pid); 969 970 return p; 971} 972 973 974int 975svr4_sys_pgrpsys(td, uap) 976 struct thread *td; 977 struct svr4_sys_pgrpsys_args *uap; 978{ 979 int *retval = td->td_retval; 980 struct proc *p = td->td_proc; 981 982 switch (uap->cmd) { 983 case 1: /* setpgrp() */ 984 /* 985 * SVR4 setpgrp() (which takes no arguments) has the 986 * semantics that the session ID is also created anew, so 987 * in almost every sense, setpgrp() is identical to 988 * setsid() for SVR4. (Under BSD, the difference is that 989 * a setpgid(0,0) will not create a new session.) 990 */ 991 setsid(td, NULL); 992 /*FALLTHROUGH*/ 993 994 case 0: /* getpgrp() */ 995 PROC_LOCK(p); 996 *retval = p->p_pgrp->pg_id; 997 PROC_UNLOCK(p); 998 return 0; 999 1000 case 2: /* getsid(pid) */ 1001 if (uap->pid == 0) 1002 PROC_LOCK(p); 1003 else if ((p = svr4_pfind(uap->pid)) == NULL) 1004 return ESRCH; 1005 /* 1006 * This has already been initialized to the pid of 1007 * the session leader. 1008 */ 1009 *retval = (register_t) p->p_session->s_sid; 1010 PROC_UNLOCK(p); 1011 return 0; 1012 1013 case 3: /* setsid() */ 1014 return setsid(td, NULL); 1015 1016 case 4: /* getpgid(pid) */ 1017 1018 if (uap->pid == 0) 1019 PROC_LOCK(p); 1020 else if ((p = svr4_pfind(uap->pid)) == NULL) 1021 return ESRCH; 1022 1023 *retval = (int) p->p_pgrp->pg_id; 1024 PROC_UNLOCK(p); 1025 return 0; 1026 1027 case 5: /* setpgid(pid, pgid); */ 1028 { 1029 struct setpgid_args sa; 1030 1031 sa.pid = uap->pid; 1032 sa.pgid = uap->pgid; 1033 return setpgid(td, &sa); 1034 } 1035 1036 default: 1037 return EINVAL; 1038 } 1039} 1040 1041struct svr4_hrtcntl_args { 1042 int cmd; 1043 int fun; 1044 int clk; 1045 svr4_hrt_interval_t * iv; 1046 svr4_hrt_time_t * ti; 1047}; 1048 1049 1050static int 1051svr4_hrtcntl(td, uap, retval) 1052 struct thread *td; 1053 struct svr4_hrtcntl_args *uap; 1054 register_t *retval; 1055{ 1056 switch (uap->fun) { 1057 case SVR4_HRT_CNTL_RES: 1058 DPRINTF(("htrcntl(RES)\n")); 1059 *retval = SVR4_HRT_USEC; 1060 return 0; 1061 1062 case SVR4_HRT_CNTL_TOFD: 1063 DPRINTF(("htrcntl(TOFD)\n")); 1064 { 1065 struct timeval tv; 1066 svr4_hrt_time_t t; 1067 if (uap->clk != SVR4_HRT_CLK_STD) { 1068 DPRINTF(("clk == %d\n", uap->clk)); 1069 return EINVAL; 1070 } 1071 if (uap->ti == NULL) { 1072 DPRINTF(("ti NULL\n")); 1073 return EINVAL; 1074 } 1075 microtime(&tv); 1076 t.h_sec = tv.tv_sec; 1077 t.h_rem = tv.tv_usec; 1078 t.h_res = SVR4_HRT_USEC; 1079 return copyout(&t, uap->ti, sizeof(t)); 1080 } 1081 1082 case SVR4_HRT_CNTL_START: 1083 DPRINTF(("htrcntl(START)\n")); 1084 return ENOSYS; 1085 1086 case SVR4_HRT_CNTL_GET: 1087 DPRINTF(("htrcntl(GET)\n")); 1088 return ENOSYS; 1089 default: 1090 DPRINTF(("Bad htrcntl command %d\n", uap->fun)); 1091 return ENOSYS; 1092 } 1093} 1094 1095 1096int 1097svr4_sys_hrtsys(td, uap) 1098 struct thread *td; 1099 struct svr4_sys_hrtsys_args *uap; 1100{ 1101 int *retval = td->td_retval; 1102 1103 switch (uap->cmd) { 1104 case SVR4_HRT_CNTL: 1105 return svr4_hrtcntl(td, (struct svr4_hrtcntl_args *) uap, 1106 retval); 1107 1108 case SVR4_HRT_ALRM: 1109 DPRINTF(("hrtalarm\n")); 1110 return ENOSYS; 1111 1112 case SVR4_HRT_SLP: 1113 DPRINTF(("hrtsleep\n")); 1114 return ENOSYS; 1115 1116 case SVR4_HRT_CAN: 1117 DPRINTF(("hrtcancel\n")); 1118 return ENOSYS; 1119 1120 default: 1121 DPRINTF(("Bad hrtsys command %d\n", uap->cmd)); 1122 return EINVAL; 1123 } 1124} 1125 1126 1127static int 1128svr4_setinfo(pid, ru, st, s) 1129 pid_t pid; 1130 struct rusage *ru; 1131 int st; 1132 svr4_siginfo_t *s; 1133{ 1134 svr4_siginfo_t i; 1135 int sig; 1136 1137 memset(&i, 0, sizeof(i)); 1138 1139 i.svr4_si_signo = SVR4_SIGCHLD; 1140 i.svr4_si_errno = 0; /* XXX? */ 1141 1142 i.svr4_si_pid = pid; 1143 if (ru) { 1144 i.svr4_si_stime = ru->ru_stime.tv_sec; 1145 i.svr4_si_utime = ru->ru_utime.tv_sec; 1146 } 1147 1148 if (WIFEXITED(st)) { 1149 i.svr4_si_status = WEXITSTATUS(st); 1150 i.svr4_si_code = SVR4_CLD_EXITED; 1151 } else if (WIFSTOPPED(st)) { 1152 sig = WSTOPSIG(st); 1153 if (sig >= 0 && sig < NSIG) 1154 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig); 1155 1156 if (i.svr4_si_status == SVR4_SIGCONT) 1157 i.svr4_si_code = SVR4_CLD_CONTINUED; 1158 else 1159 i.svr4_si_code = SVR4_CLD_STOPPED; 1160 } else { 1161 sig = WTERMSIG(st); 1162 if (sig >= 0 && sig < NSIG) 1163 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig); 1164 1165 if (WCOREDUMP(st)) 1166 i.svr4_si_code = SVR4_CLD_DUMPED; 1167 else 1168 i.svr4_si_code = SVR4_CLD_KILLED; 1169 } 1170 1171 DPRINTF(("siginfo [pid %ld signo %d code %d errno %d status %d]\n", 1172 i.svr4_si_pid, i.svr4_si_signo, i.svr4_si_code, i.svr4_si_errno, 1173 i.svr4_si_status)); 1174 1175 return copyout(&i, s, sizeof(i)); 1176} 1177 1178 1179int 1180svr4_sys_waitsys(td, uap) 1181 struct thread *td; 1182 struct svr4_sys_waitsys_args *uap; 1183{ 1184 struct rusage ru; 1185 pid_t pid; 1186 int nfound, status; 1187 int error, *retval = td->td_retval; 1188 struct proc *p, *q; 1189 1190 DPRINTF(("waitsys(%d, %d, %p, %x)\n", 1191 uap->grp, uap->id, 1192 uap->info, uap->options)); 1193 1194 q = td->td_proc; 1195 switch (uap->grp) { 1196 case SVR4_P_PID: 1197 pid = uap->id; 1198 break; 1199 1200 case SVR4_P_PGID: 1201 PROC_LOCK(q); 1202 pid = -q->p_pgid; 1203 PROC_UNLOCK(q); 1204 break; 1205 1206 case SVR4_P_ALL: 1207 pid = WAIT_ANY; 1208 break; 1209 1210 default: 1211 return EINVAL; 1212 } 1213 1214 /* Hand off the easy cases to kern_wait(). */ 1215 if (!(uap->options & (SVR4_WNOWAIT)) && 1216 (uap->options & (SVR4_WEXITED | SVR4_WTRAPPED))) { 1217 int options; 1218 1219 options = 0; 1220 if (uap->options & SVR4_WSTOPPED) 1221 options |= WUNTRACED; 1222 if (uap->options & SVR4_WCONTINUED) 1223 options |= WCONTINUED; 1224 if (uap->options & SVR4_WNOHANG) 1225 options |= WNOHANG; 1226 1227 error = kern_wait(td, pid, &status, options, &ru); 1228 if (error) 1229 return (error); 1230 if (uap->options & SVR4_WNOHANG && *retval == 0) 1231 error = svr4_setinfo(*retval, NULL, 0, uap->info); 1232 else 1233 error = svr4_setinfo(*retval, &ru, status, uap->info); 1234 *retval = 0; 1235 return (error); 1236 } 1237 1238 /* 1239 * Ok, handle the weird cases. Either WNOWAIT is set (meaning we 1240 * just want to see if there is a process to harvest, we don't 1241 * want to actually harvest it), or WEXIT and WTRAPPED are clear 1242 * meaning we want to ignore zombies. Either way, we don't have 1243 * to handle harvesting zombies here. We do have to duplicate the 1244 * other portions of kern_wait() though, especially for WCONTINUED 1245 * and WSTOPPED. 1246 */ 1247loop: 1248 nfound = 0; 1249 sx_slock(&proctree_lock); 1250 LIST_FOREACH(p, &q->p_children, p_sibling) { 1251 PROC_LOCK(p); 1252 if (pid != WAIT_ANY && 1253 p->p_pid != pid && p->p_pgid != -pid) { 1254 PROC_UNLOCK(p); 1255 DPRINTF(("pid %d pgid %d != %d\n", p->p_pid, 1256 p->p_pgid, pid)); 1257 continue; 1258 } 1259 if (p_canwait(td, p)) { 1260 PROC_UNLOCK(p); 1261 continue; 1262 } 1263 1264 nfound++; 1265 1266 PROC_SLOCK(p); 1267 /* 1268 * See if we have a zombie. If so, WNOWAIT should be set, 1269 * as otherwise we should have called kern_wait() up above. 1270 */ 1271 if ((p->p_state == PRS_ZOMBIE) && 1272 ((uap->options & (SVR4_WEXITED|SVR4_WTRAPPED)))) { 1273 PROC_SUNLOCK(p); 1274 KASSERT(uap->options & SVR4_WNOWAIT, 1275 ("WNOWAIT is clear")); 1276 1277 /* Found a zombie, so cache info in local variables. */ 1278 pid = p->p_pid; 1279 status = p->p_xstat; 1280 ru = p->p_ru; 1281 PROC_SLOCK(p); 1282 calcru(p, &ru.ru_utime, &ru.ru_stime); 1283 PROC_SUNLOCK(p); 1284 PROC_UNLOCK(p); 1285 sx_sunlock(&proctree_lock); 1286 1287 /* Copy the info out to userland. */ 1288 *retval = 0; 1289 DPRINTF(("found %d\n", pid)); 1290 return (svr4_setinfo(pid, &ru, status, uap->info)); 1291 } 1292 1293 /* 1294 * See if we have a stopped or continued process. 1295 * XXX: This duplicates the same code in kern_wait(). 1296 */ 1297 if ((p->p_flag & P_STOPPED_SIG) && 1298 (p->p_suspcount == p->p_numthreads) && 1299 (p->p_flag & P_WAITED) == 0 && 1300 (p->p_flag & P_TRACED || uap->options & SVR4_WSTOPPED)) { 1301 PROC_SUNLOCK(p); 1302 if (((uap->options & SVR4_WNOWAIT)) == 0) 1303 p->p_flag |= P_WAITED; 1304 sx_sunlock(&proctree_lock); 1305 pid = p->p_pid; 1306 status = W_STOPCODE(p->p_xstat); 1307 ru = p->p_ru; 1308 PROC_SLOCK(p); 1309 calcru(p, &ru.ru_utime, &ru.ru_stime); 1310 PROC_SUNLOCK(p); 1311 PROC_UNLOCK(p); 1312 1313 if (((uap->options & SVR4_WNOWAIT)) == 0) { 1314 PROC_LOCK(q); 1315 sigqueue_take(p->p_ksi); 1316 PROC_UNLOCK(q); 1317 } 1318 1319 *retval = 0; 1320 DPRINTF(("jobcontrol %d\n", pid)); 1321 return (svr4_setinfo(pid, &ru, status, uap->info)); 1322 } 1323 PROC_SUNLOCK(p); 1324 if (uap->options & SVR4_WCONTINUED && 1325 (p->p_flag & P_CONTINUED)) { 1326 sx_sunlock(&proctree_lock); 1327 if (((uap->options & SVR4_WNOWAIT)) == 0) 1328 p->p_flag &= ~P_CONTINUED; 1329 pid = p->p_pid; 1330 ru = p->p_ru; 1331 status = SIGCONT; 1332 PROC_SLOCK(p); 1333 calcru(p, &ru.ru_utime, &ru.ru_stime); 1334 PROC_SUNLOCK(p); 1335 PROC_UNLOCK(p); 1336 1337 if (((uap->options & SVR4_WNOWAIT)) == 0) { 1338 PROC_LOCK(q); 1339 sigqueue_take(p->p_ksi); 1340 PROC_UNLOCK(q); 1341 } 1342 1343 *retval = 0; 1344 DPRINTF(("jobcontrol %d\n", pid)); 1345 return (svr4_setinfo(pid, &ru, status, uap->info)); 1346 } 1347 PROC_UNLOCK(p); 1348 } 1349 1350 if (nfound == 0) { 1351 sx_sunlock(&proctree_lock); 1352 return (ECHILD); 1353 } 1354 1355 if (uap->options & SVR4_WNOHANG) { 1356 sx_sunlock(&proctree_lock); 1357 *retval = 0; 1358 return (svr4_setinfo(0, NULL, 0, uap->info)); 1359 } 1360 1361 PROC_LOCK(q); 1362 sx_sunlock(&proctree_lock); 1363 if (q->p_flag & P_STATCHILD) { 1364 q->p_flag &= ~P_STATCHILD; 1365 error = 0; 1366 } else 1367 error = msleep(q, &q->p_mtx, PWAIT | PCATCH, "svr4_wait", 0); 1368 PROC_UNLOCK(q); 1369 if (error) 1370 return error; 1371 goto loop; 1372} 1373 1374 1375static void 1376bsd_statfs_to_svr4_statvfs(bfs, sfs) 1377 const struct statfs *bfs; 1378 struct svr4_statvfs *sfs; 1379{ 1380 sfs->f_bsize = bfs->f_iosize; /* XXX */ 1381 sfs->f_frsize = bfs->f_bsize; 1382 sfs->f_blocks = bfs->f_blocks; 1383 sfs->f_bfree = bfs->f_bfree; 1384 sfs->f_bavail = bfs->f_bavail; 1385 sfs->f_files = bfs->f_files; 1386 sfs->f_ffree = bfs->f_ffree; 1387 sfs->f_favail = bfs->f_ffree; 1388 sfs->f_fsid = bfs->f_fsid.val[0]; 1389 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype)); 1390 sfs->f_flag = 0; 1391 if (bfs->f_flags & MNT_RDONLY) 1392 sfs->f_flag |= SVR4_ST_RDONLY; 1393 if (bfs->f_flags & MNT_NOSUID) 1394 sfs->f_flag |= SVR4_ST_NOSUID; 1395 sfs->f_namemax = MAXNAMLEN; 1396 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */ 1397 memset(sfs->f_filler, 0, sizeof(sfs->f_filler)); 1398} 1399 1400 1401static void 1402bsd_statfs_to_svr4_statvfs64(bfs, sfs) 1403 const struct statfs *bfs; 1404 struct svr4_statvfs64 *sfs; 1405{ 1406 sfs->f_bsize = bfs->f_iosize; /* XXX */ 1407 sfs->f_frsize = bfs->f_bsize; 1408 sfs->f_blocks = bfs->f_blocks; 1409 sfs->f_bfree = bfs->f_bfree; 1410 sfs->f_bavail = bfs->f_bavail; 1411 sfs->f_files = bfs->f_files; 1412 sfs->f_ffree = bfs->f_ffree; 1413 sfs->f_favail = bfs->f_ffree; 1414 sfs->f_fsid = bfs->f_fsid.val[0]; 1415 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype)); 1416 sfs->f_flag = 0; 1417 if (bfs->f_flags & MNT_RDONLY) 1418 sfs->f_flag |= SVR4_ST_RDONLY; 1419 if (bfs->f_flags & MNT_NOSUID) 1420 sfs->f_flag |= SVR4_ST_NOSUID; 1421 sfs->f_namemax = MAXNAMLEN; 1422 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */ 1423 memset(sfs->f_filler, 0, sizeof(sfs->f_filler)); 1424} 1425 1426 1427int 1428svr4_sys_statvfs(td, uap) 1429 struct thread *td; 1430 struct svr4_sys_statvfs_args *uap; 1431{ 1432 struct svr4_statvfs sfs; 1433 struct statfs bfs; 1434 char *path; 1435 int error; 1436 1437 CHECKALTEXIST(td, uap->path, &path); 1438 1439 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs); 1440 free(path, M_TEMP); 1441 if (error) 1442 return (error); 1443 bsd_statfs_to_svr4_statvfs(&bfs, &sfs); 1444 return copyout(&sfs, uap->fs, sizeof(sfs)); 1445} 1446 1447 1448int 1449svr4_sys_fstatvfs(td, uap) 1450 struct thread *td; 1451 struct svr4_sys_fstatvfs_args *uap; 1452{ 1453 struct svr4_statvfs sfs; 1454 struct statfs bfs; 1455 int error; 1456 1457 error = kern_fstatfs(td, uap->fd, &bfs); 1458 if (error) 1459 return (error); 1460 bsd_statfs_to_svr4_statvfs(&bfs, &sfs); 1461 return copyout(&sfs, uap->fs, sizeof(sfs)); 1462} 1463 1464 1465int 1466svr4_sys_statvfs64(td, uap) 1467 struct thread *td; 1468 struct svr4_sys_statvfs64_args *uap; 1469{ 1470 struct svr4_statvfs64 sfs; 1471 struct statfs bfs; 1472 char *path; 1473 int error; 1474 1475 CHECKALTEXIST(td, uap->path, &path); 1476 1477 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs); 1478 free(path, M_TEMP); 1479 if (error) 1480 return (error); 1481 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs); 1482 return copyout(&sfs, uap->fs, sizeof(sfs)); 1483} 1484 1485 1486int 1487svr4_sys_fstatvfs64(td, uap) 1488 struct thread *td; 1489 struct svr4_sys_fstatvfs64_args *uap; 1490{ 1491 struct svr4_statvfs64 sfs; 1492 struct statfs bfs; 1493 int error; 1494 1495 error = kern_fstatfs(td, uap->fd, &bfs); 1496 if (error) 1497 return (error); 1498 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs); 1499 return copyout(&sfs, uap->fs, sizeof(sfs)); 1500} 1501 1502int 1503svr4_sys_alarm(td, uap) 1504 struct thread *td; 1505 struct svr4_sys_alarm_args *uap; 1506{ 1507 struct itimerval itv, oitv; 1508 int error; 1509 1510 timevalclear(&itv.it_interval); 1511 itv.it_value.tv_sec = uap->sec; 1512 itv.it_value.tv_usec = 0; 1513 error = kern_setitimer(td, ITIMER_REAL, &itv, &oitv); 1514 if (error) 1515 return (error); 1516 if (oitv.it_value.tv_usec != 0) 1517 oitv.it_value.tv_sec++; 1518 td->td_retval[0] = oitv.it_value.tv_sec; 1519 return (0); 1520} 1521 1522int 1523svr4_sys_gettimeofday(td, uap) 1524 struct thread *td; 1525 struct svr4_sys_gettimeofday_args *uap; 1526{ 1527 if (uap->tp) { 1528 struct timeval atv; 1529 1530 microtime(&atv); 1531 return copyout(&atv, uap->tp, sizeof (atv)); 1532 } 1533 1534 return 0; 1535} 1536 1537int 1538svr4_sys_facl(td, uap) 1539 struct thread *td; 1540 struct svr4_sys_facl_args *uap; 1541{ 1542 int *retval; 1543 1544 retval = td->td_retval; 1545 *retval = 0; 1546 1547 switch (uap->cmd) { 1548 case SVR4_SYS_SETACL: 1549 /* We don't support acls on any filesystem */ 1550 return ENOSYS; 1551 1552 case SVR4_SYS_GETACL: 1553 return copyout(retval, &uap->num, 1554 sizeof(uap->num)); 1555 1556 case SVR4_SYS_GETACLCNT: 1557 return 0; 1558 1559 default: 1560 return EINVAL; 1561 } 1562} 1563 1564 1565int 1566svr4_sys_acl(td, uap) 1567 struct thread *td; 1568 struct svr4_sys_acl_args *uap; 1569{ 1570 /* XXX: for now the same */ 1571 return svr4_sys_facl(td, (struct svr4_sys_facl_args *)uap); 1572} 1573 1574int 1575svr4_sys_auditsys(td, uap) 1576 struct thread *td; 1577 struct svr4_sys_auditsys_args *uap; 1578{ 1579 /* 1580 * XXX: Big brother is *not* watching. 1581 */ 1582 return 0; 1583} 1584 1585int 1586svr4_sys_memcntl(td, uap) 1587 struct thread *td; 1588 struct svr4_sys_memcntl_args *uap; 1589{ 1590 switch (uap->cmd) { 1591 case SVR4_MC_SYNC: 1592 { 1593 struct msync_args msa; 1594 1595 msa.addr = uap->addr; 1596 msa.len = uap->len; 1597 msa.flags = (int)uap->arg; 1598 1599 return msync(td, &msa); 1600 } 1601 case SVR4_MC_ADVISE: 1602 { 1603 struct madvise_args maa; 1604 1605 maa.addr = uap->addr; 1606 maa.len = uap->len; 1607 maa.behav = (int)uap->arg; 1608 1609 return madvise(td, &maa); 1610 } 1611 case SVR4_MC_LOCK: 1612 case SVR4_MC_UNLOCK: 1613 case SVR4_MC_LOCKAS: 1614 case SVR4_MC_UNLOCKAS: 1615 return EOPNOTSUPP; 1616 default: 1617 return ENOSYS; 1618 } 1619} 1620 1621 1622int 1623svr4_sys_nice(td, uap) 1624 struct thread *td; 1625 struct svr4_sys_nice_args *uap; 1626{ 1627 struct setpriority_args ap; 1628 int error; 1629 1630 ap.which = PRIO_PROCESS; 1631 ap.who = 0; 1632 ap.prio = uap->prio; 1633 1634 if ((error = setpriority(td, &ap)) != 0) 1635 return error; 1636 1637 /* the cast is stupid, but the structures are the same */ 1638 if ((error = getpriority(td, (struct getpriority_args *)&ap)) != 0) 1639 return error; 1640 1641 return 0; 1642} 1643 1644int 1645svr4_sys_resolvepath(td, uap) 1646 struct thread *td; 1647 struct svr4_sys_resolvepath_args *uap; 1648{ 1649 struct nameidata nd; 1650 int error, *retval = td->td_retval; 1651 unsigned int ncopy; 1652 1653 NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME | MPSAFE, UIO_USERSPACE, 1654 uap->path, td); 1655 1656 if ((error = namei(&nd)) != 0) 1657 return (error); 1658 NDFREE(&nd, NDF_NO_FREE_PNBUF); 1659 VFS_UNLOCK_GIANT(NDHASGIANT(&nd)); 1660 1661 ncopy = min(uap->bufsiz, strlen(nd.ni_cnd.cn_pnbuf) + 1); 1662 if ((error = copyout(nd.ni_cnd.cn_pnbuf, uap->buf, ncopy)) != 0) 1663 goto bad; 1664 1665 *retval = ncopy; 1666bad: 1667 NDFREE(&nd, NDF_ONLY_PNBUF); 1668 return error; 1669} 1670