The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/compat/svr4/svr4_misc.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: ea48c20be0aea003eb8fd42c790f56c8


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.